update
This commit is contained in:
@@ -0,0 +1,296 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
'use strict';
|
||||
|
||||
/*<replacement>*/
|
||||
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
/*</replacement>*/
|
||||
|
||||
var isEncoding = Buffer.isEncoding || function (encoding) {
|
||||
encoding = '' + encoding;
|
||||
switch (encoding && encoding.toLowerCase()) {
|
||||
case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
function _normalizeEncoding(enc) {
|
||||
if (!enc) return 'utf8';
|
||||
var retried;
|
||||
while (true) {
|
||||
switch (enc) {
|
||||
case 'utf8':
|
||||
case 'utf-8':
|
||||
return 'utf8';
|
||||
case 'ucs2':
|
||||
case 'ucs-2':
|
||||
case 'utf16le':
|
||||
case 'utf-16le':
|
||||
return 'utf16le';
|
||||
case 'latin1':
|
||||
case 'binary':
|
||||
return 'latin1';
|
||||
case 'base64':
|
||||
case 'ascii':
|
||||
case 'hex':
|
||||
return enc;
|
||||
default:
|
||||
if (retried) return; // undefined
|
||||
enc = ('' + enc).toLowerCase();
|
||||
retried = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Do not cache `Buffer.isEncoding` when checking encoding names as some
|
||||
// modules monkey-patch it to support additional encodings
|
||||
function normalizeEncoding(enc) {
|
||||
var nenc = _normalizeEncoding(enc);
|
||||
if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
||||
return nenc || enc;
|
||||
}
|
||||
|
||||
// StringDecoder provides an interface for efficiently splitting a series of
|
||||
// buffers into a series of JS strings without breaking apart multi-byte
|
||||
// characters.
|
||||
exports.StringDecoder = StringDecoder;
|
||||
function StringDecoder(encoding) {
|
||||
this.encoding = normalizeEncoding(encoding);
|
||||
var nb;
|
||||
switch (this.encoding) {
|
||||
case 'utf16le':
|
||||
this.text = utf16Text;
|
||||
this.end = utf16End;
|
||||
nb = 4;
|
||||
break;
|
||||
case 'utf8':
|
||||
this.fillLast = utf8FillLast;
|
||||
nb = 4;
|
||||
break;
|
||||
case 'base64':
|
||||
this.text = base64Text;
|
||||
this.end = base64End;
|
||||
nb = 3;
|
||||
break;
|
||||
default:
|
||||
this.write = simpleWrite;
|
||||
this.end = simpleEnd;
|
||||
return;
|
||||
}
|
||||
this.lastNeed = 0;
|
||||
this.lastTotal = 0;
|
||||
this.lastChar = Buffer.allocUnsafe(nb);
|
||||
}
|
||||
|
||||
StringDecoder.prototype.write = function (buf) {
|
||||
if (buf.length === 0) return '';
|
||||
var r;
|
||||
var i;
|
||||
if (this.lastNeed) {
|
||||
r = this.fillLast(buf);
|
||||
if (r === undefined) return '';
|
||||
i = this.lastNeed;
|
||||
this.lastNeed = 0;
|
||||
} else {
|
||||
i = 0;
|
||||
}
|
||||
if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
||||
return r || '';
|
||||
};
|
||||
|
||||
StringDecoder.prototype.end = utf8End;
|
||||
|
||||
// Returns only complete characters in a Buffer
|
||||
StringDecoder.prototype.text = utf8Text;
|
||||
|
||||
// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
|
||||
StringDecoder.prototype.fillLast = function (buf) {
|
||||
if (this.lastNeed <= buf.length) {
|
||||
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
||||
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
||||
}
|
||||
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
||||
this.lastNeed -= buf.length;
|
||||
};
|
||||
|
||||
// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
|
||||
// continuation byte. If an invalid byte is detected, -2 is returned.
|
||||
function utf8CheckByte(byte) {
|
||||
if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
|
||||
return byte >> 6 === 0x02 ? -1 : -2;
|
||||
}
|
||||
|
||||
// Checks at most 3 bytes at the end of a Buffer in order to detect an
|
||||
// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
|
||||
// needed to complete the UTF-8 character (if applicable) are returned.
|
||||
function utf8CheckIncomplete(self, buf, i) {
|
||||
var j = buf.length - 1;
|
||||
if (j < i) return 0;
|
||||
var nb = utf8CheckByte(buf[j]);
|
||||
if (nb >= 0) {
|
||||
if (nb > 0) self.lastNeed = nb - 1;
|
||||
return nb;
|
||||
}
|
||||
if (--j < i || nb === -2) return 0;
|
||||
nb = utf8CheckByte(buf[j]);
|
||||
if (nb >= 0) {
|
||||
if (nb > 0) self.lastNeed = nb - 2;
|
||||
return nb;
|
||||
}
|
||||
if (--j < i || nb === -2) return 0;
|
||||
nb = utf8CheckByte(buf[j]);
|
||||
if (nb >= 0) {
|
||||
if (nb > 0) {
|
||||
if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Validates as many continuation bytes for a multi-byte UTF-8 character as
|
||||
// needed or are available. If we see a non-continuation byte where we expect
|
||||
// one, we "replace" the validated continuation bytes we've seen so far with
|
||||
// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
|
||||
// behavior. The continuation byte check is included three times in the case
|
||||
// where all of the continuation bytes for a character exist in the same buffer.
|
||||
// It is also done this way as a slight performance increase instead of using a
|
||||
// loop.
|
||||
function utf8CheckExtraBytes(self, buf, p) {
|
||||
if ((buf[0] & 0xC0) !== 0x80) {
|
||||
self.lastNeed = 0;
|
||||
return '\ufffd';
|
||||
}
|
||||
if (self.lastNeed > 1 && buf.length > 1) {
|
||||
if ((buf[1] & 0xC0) !== 0x80) {
|
||||
self.lastNeed = 1;
|
||||
return '\ufffd';
|
||||
}
|
||||
if (self.lastNeed > 2 && buf.length > 2) {
|
||||
if ((buf[2] & 0xC0) !== 0x80) {
|
||||
self.lastNeed = 2;
|
||||
return '\ufffd';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
|
||||
function utf8FillLast(buf) {
|
||||
var p = this.lastTotal - this.lastNeed;
|
||||
var r = utf8CheckExtraBytes(this, buf, p);
|
||||
if (r !== undefined) return r;
|
||||
if (this.lastNeed <= buf.length) {
|
||||
buf.copy(this.lastChar, p, 0, this.lastNeed);
|
||||
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
||||
}
|
||||
buf.copy(this.lastChar, p, 0, buf.length);
|
||||
this.lastNeed -= buf.length;
|
||||
}
|
||||
|
||||
// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
|
||||
// partial character, the character's bytes are buffered until the required
|
||||
// number of bytes are available.
|
||||
function utf8Text(buf, i) {
|
||||
var total = utf8CheckIncomplete(this, buf, i);
|
||||
if (!this.lastNeed) return buf.toString('utf8', i);
|
||||
this.lastTotal = total;
|
||||
var end = buf.length - (total - this.lastNeed);
|
||||
buf.copy(this.lastChar, 0, end);
|
||||
return buf.toString('utf8', i, end);
|
||||
}
|
||||
|
||||
// For UTF-8, a replacement character is added when ending on a partial
|
||||
// character.
|
||||
function utf8End(buf) {
|
||||
var r = buf && buf.length ? this.write(buf) : '';
|
||||
if (this.lastNeed) return r + '\ufffd';
|
||||
return r;
|
||||
}
|
||||
|
||||
// UTF-16LE typically needs two bytes per character, but even if we have an even
|
||||
// number of bytes available, we need to check if we end on a leading/high
|
||||
// surrogate. In that case, we need to wait for the next two bytes in order to
|
||||
// decode the last character properly.
|
||||
function utf16Text(buf, i) {
|
||||
if ((buf.length - i) % 2 === 0) {
|
||||
var r = buf.toString('utf16le', i);
|
||||
if (r) {
|
||||
var c = r.charCodeAt(r.length - 1);
|
||||
if (c >= 0xD800 && c <= 0xDBFF) {
|
||||
this.lastNeed = 2;
|
||||
this.lastTotal = 4;
|
||||
this.lastChar[0] = buf[buf.length - 2];
|
||||
this.lastChar[1] = buf[buf.length - 1];
|
||||
return r.slice(0, -1);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
this.lastNeed = 1;
|
||||
this.lastTotal = 2;
|
||||
this.lastChar[0] = buf[buf.length - 1];
|
||||
return buf.toString('utf16le', i, buf.length - 1);
|
||||
}
|
||||
|
||||
// For UTF-16LE we do not explicitly append special replacement characters if we
|
||||
// end on a partial character, we simply let v8 handle that.
|
||||
function utf16End(buf) {
|
||||
var r = buf && buf.length ? this.write(buf) : '';
|
||||
if (this.lastNeed) {
|
||||
var end = this.lastTotal - this.lastNeed;
|
||||
return r + this.lastChar.toString('utf16le', 0, end);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
function base64Text(buf, i) {
|
||||
var n = (buf.length - i) % 3;
|
||||
if (n === 0) return buf.toString('base64', i);
|
||||
this.lastNeed = 3 - n;
|
||||
this.lastTotal = 3;
|
||||
if (n === 1) {
|
||||
this.lastChar[0] = buf[buf.length - 1];
|
||||
} else {
|
||||
this.lastChar[0] = buf[buf.length - 2];
|
||||
this.lastChar[1] = buf[buf.length - 1];
|
||||
}
|
||||
return buf.toString('base64', i, buf.length - n);
|
||||
}
|
||||
|
||||
function base64End(buf) {
|
||||
var r = buf && buf.length ? this.write(buf) : '';
|
||||
if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
|
||||
return r;
|
||||
}
|
||||
|
||||
// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
|
||||
function simpleWrite(buf) {
|
||||
return buf.toString(this.encoding);
|
||||
}
|
||||
|
||||
function simpleEnd(buf) {
|
||||
return buf && buf.length ? this.write(buf) : '';
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
import { Store } from './store'
|
||||
import { __derivedToStore, __storeToDerived } from './scheduler'
|
||||
import type { Listener } from './types'
|
||||
|
||||
export type UnwrapDerivedOrStore<T> =
|
||||
T extends Derived<infer InnerD>
|
||||
? InnerD
|
||||
: T extends Store<infer InnerS>
|
||||
? InnerS
|
||||
: never
|
||||
|
||||
type UnwrapReadonlyDerivedOrStoreArray<
|
||||
TArr extends ReadonlyArray<Derived<any> | Store<any>>,
|
||||
> = TArr extends readonly [infer Head, ...infer Tail]
|
||||
? Head extends Derived<any> | Store<any>
|
||||
? Tail extends ReadonlyArray<Derived<any> | Store<any>>
|
||||
? [UnwrapDerivedOrStore<Head>, ...UnwrapReadonlyDerivedOrStoreArray<Tail>]
|
||||
: []
|
||||
: []
|
||||
: []
|
||||
|
||||
// Can't have currVal, as it's being evaluated from the current derived fn
|
||||
export interface DerivedFnProps<
|
||||
TArr extends ReadonlyArray<Derived<any> | Store<any>> = ReadonlyArray<any>,
|
||||
TUnwrappedArr extends
|
||||
UnwrapReadonlyDerivedOrStoreArray<TArr> = UnwrapReadonlyDerivedOrStoreArray<TArr>,
|
||||
> {
|
||||
// `undefined` if it's the first run
|
||||
/**
|
||||
* `undefined` if it's the first run
|
||||
* @privateRemarks this also cannot be typed as TState, as it breaks the inferencing of the function's return type when an argument is used - even with `NoInfer` usage
|
||||
*/
|
||||
prevVal: unknown | undefined
|
||||
prevDepVals: TUnwrappedArr | undefined
|
||||
currDepVals: TUnwrappedArr
|
||||
}
|
||||
|
||||
export interface DerivedOptions<
|
||||
TState,
|
||||
TArr extends ReadonlyArray<Derived<any> | Store<any>> = ReadonlyArray<any>,
|
||||
> {
|
||||
onSubscribe?: (
|
||||
listener: Listener<TState>,
|
||||
derived: Derived<TState>,
|
||||
) => () => void
|
||||
onUpdate?: () => void
|
||||
deps: TArr
|
||||
/**
|
||||
* Values of the `deps` from before and after the current invocation of `fn`
|
||||
*/
|
||||
fn: (props: DerivedFnProps<TArr>) => TState
|
||||
}
|
||||
|
||||
export class Derived<
|
||||
TState,
|
||||
const TArr extends ReadonlyArray<
|
||||
Derived<any> | Store<any>
|
||||
> = ReadonlyArray<any>,
|
||||
> {
|
||||
listeners = new Set<Listener<TState>>()
|
||||
state: TState
|
||||
prevState: TState | undefined
|
||||
options: DerivedOptions<TState, TArr>
|
||||
|
||||
/**
|
||||
* Functions representing the subscriptions. Call a function to cleanup
|
||||
* @private
|
||||
*/
|
||||
_subscriptions: Array<() => void> = []
|
||||
|
||||
lastSeenDepValues: Array<unknown> = []
|
||||
getDepVals = () => {
|
||||
const prevDepVals = [] as Array<unknown>
|
||||
const currDepVals = [] as Array<unknown>
|
||||
for (const dep of this.options.deps) {
|
||||
prevDepVals.push(dep.prevState)
|
||||
currDepVals.push(dep.state)
|
||||
}
|
||||
this.lastSeenDepValues = currDepVals
|
||||
return {
|
||||
prevDepVals,
|
||||
currDepVals,
|
||||
prevVal: this.prevState ?? undefined,
|
||||
}
|
||||
}
|
||||
|
||||
constructor(options: DerivedOptions<TState, TArr>) {
|
||||
this.options = options
|
||||
this.state = options.fn({
|
||||
prevDepVals: undefined,
|
||||
prevVal: undefined,
|
||||
currDepVals: this.getDepVals().currDepVals as never,
|
||||
})
|
||||
}
|
||||
|
||||
registerOnGraph(
|
||||
deps: ReadonlyArray<Derived<any> | Store<any>> = this.options.deps,
|
||||
) {
|
||||
for (const dep of deps) {
|
||||
if (dep instanceof Derived) {
|
||||
// First register the intermediate derived value if it's not already registered
|
||||
dep.registerOnGraph()
|
||||
// Then register this derived with the dep's underlying stores
|
||||
this.registerOnGraph(dep.options.deps)
|
||||
} else if (dep instanceof Store) {
|
||||
// Register the derived as related derived to the store
|
||||
let relatedLinkedDerivedVals = __storeToDerived.get(dep)
|
||||
if (!relatedLinkedDerivedVals) {
|
||||
relatedLinkedDerivedVals = new Set()
|
||||
__storeToDerived.set(dep, relatedLinkedDerivedVals)
|
||||
}
|
||||
relatedLinkedDerivedVals.add(this as never)
|
||||
|
||||
// Register the store as a related store to this derived
|
||||
let relatedStores = __derivedToStore.get(this as never)
|
||||
if (!relatedStores) {
|
||||
relatedStores = new Set()
|
||||
__derivedToStore.set(this as never, relatedStores)
|
||||
}
|
||||
relatedStores.add(dep)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unregisterFromGraph(
|
||||
deps: ReadonlyArray<Derived<any> | Store<any>> = this.options.deps,
|
||||
) {
|
||||
for (const dep of deps) {
|
||||
if (dep instanceof Derived) {
|
||||
this.unregisterFromGraph(dep.options.deps)
|
||||
} else if (dep instanceof Store) {
|
||||
const relatedLinkedDerivedVals = __storeToDerived.get(dep)
|
||||
if (relatedLinkedDerivedVals) {
|
||||
relatedLinkedDerivedVals.delete(this as never)
|
||||
}
|
||||
|
||||
const relatedStores = __derivedToStore.get(this as never)
|
||||
if (relatedStores) {
|
||||
relatedStores.delete(dep)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recompute = () => {
|
||||
this.prevState = this.state
|
||||
const { prevDepVals, currDepVals, prevVal } = this.getDepVals()
|
||||
this.state = this.options.fn({
|
||||
prevDepVals: prevDepVals as never,
|
||||
currDepVals: currDepVals as never,
|
||||
prevVal,
|
||||
})
|
||||
|
||||
this.options.onUpdate?.()
|
||||
}
|
||||
|
||||
checkIfRecalculationNeededDeeply = () => {
|
||||
for (const dep of this.options.deps) {
|
||||
if (dep instanceof Derived) {
|
||||
dep.checkIfRecalculationNeededDeeply()
|
||||
}
|
||||
}
|
||||
let shouldRecompute = false
|
||||
const lastSeenDepValues = this.lastSeenDepValues
|
||||
const { currDepVals } = this.getDepVals()
|
||||
for (let i = 0; i < currDepVals.length; i++) {
|
||||
if (currDepVals[i] !== lastSeenDepValues[i]) {
|
||||
shouldRecompute = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldRecompute) {
|
||||
this.recompute()
|
||||
}
|
||||
}
|
||||
|
||||
mount = () => {
|
||||
this.registerOnGraph()
|
||||
this.checkIfRecalculationNeededDeeply()
|
||||
|
||||
return () => {
|
||||
this.unregisterFromGraph()
|
||||
for (const cleanup of this._subscriptions) {
|
||||
cleanup()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscribe = (listener: Listener<TState>) => {
|
||||
this.listeners.add(listener)
|
||||
const unsub = this.options.onSubscribe?.(listener, this)
|
||||
return () => {
|
||||
this.listeners.delete(listener)
|
||||
unsub?.()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) 2011-2022 Isaac Z. Schlueter, Ben Noordhuis, and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
@@ -0,0 +1,54 @@
|
||||
export { default as invariant } from 'tiny-invariant';
|
||||
export { default as warning } from 'tiny-warning';
|
||||
export { defer, TSR_DEFERRED_PROMISE, isMatch, joinPaths, cleanPath, trimPathLeft, trimPathRight, trimPath, resolvePath, parsePathname, interpolatePath, matchPathname, removeBasepath, matchByPath, encode, decode, rootRouteId, defaultSerializeError, defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith, escapeJSON, // SSR
|
||||
pick, functionalUpdate, replaceEqualDeep, isPlainObject, isPlainArray, deepEqual, shallow, createControlledPromise, retainSearchParams, stripSearchParams, } from '@tanstack/router-core';
|
||||
export type { AnyRoute, StartSerializer, Serializable, SerializerParse, SerializerParseBy, SerializerStringify, SerializerStringifyBy, DeferredPromiseState, DeferredPromise, ParsedLocation, ParsePathParams, RemoveTrailingSlashes, RemoveLeadingSlashes, ActiveOptions, Segment, ResolveRelativePath, RootRouteId, AnyPathParams, ResolveParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn, SearchFilter, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, TrimPath, TrimPathLeft, TrimPathRight, ParseSplatParams, SplatParams, StringifyParamsFn, ParamsOptions, InferAllParams, InferAllContext, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, ResolveLoaderData, ResolveRouteContext, SearchSerializer, SearchParser, TrailingSlashOption, ExtractedEntry, ExtractedStream, ExtractedPromise, StreamState, Manifest, RouterManagedTag, ControlledPromise, Constrain, Expand, MergeAll, Assign, IntersectAssign, ResolveValidatorInput, ResolveValidatorOutput, Register, AnyValidator, DefaultValidator, ValidatorFn, AnySchema, AnyValidatorAdapter, AnyValidatorFn, AnyValidatorObj, ResolveValidatorInputFn, ResolveValidatorOutputFn, ResolveSearchValidatorInput, ResolveSearchValidatorInputFn, Validator, ValidatorAdapter, ValidatorObj, FileRoutesByPath, RouteById, RootRouteOptions, SerializerExtensions, } from '@tanstack/router-core';
|
||||
export type * from './serializer.js';
|
||||
export { createHistory, createBrowserHistory, createHashHistory, createMemoryHistory, } from '@tanstack/history';
|
||||
export type { BlockerFn, HistoryLocation, RouterHistory, ParsedPath, HistoryState, } from '@tanstack/history';
|
||||
export { useAwaited, Await } from './awaited.js';
|
||||
export type { AwaitOptions } from './awaited.js';
|
||||
export { CatchBoundary, ErrorComponent } from './CatchBoundary.js';
|
||||
export { FileRoute, createFileRoute, FileRouteLoader, LazyRoute, createLazyRoute, createLazyFileRoute, } from './fileRoute.js';
|
||||
export * from './history.js';
|
||||
export { lazyRouteComponent } from './lazyRouteComponent.js';
|
||||
export { useLinkProps, createLink, Link, linkOptions } from './link.js';
|
||||
export type { InferDescendantToPaths, RelativeToPath, RelativeToParentPath, RelativeToCurrentPath, AbsoluteToPath, RelativeToPathAutoComplete, NavigateOptions, ToOptions, ToMaskOptions, ToSubOptions, ResolveRoute, SearchParamOptions, PathParamOptions, ToPathOption, LinkOptions, MakeOptionalPathParams, FileRouteTypes, RouteContextParameter, BeforeLoadContextParameter, ResolveAllContext, ResolveAllParamsFromParent, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, RouteIds, NavigateFn, BuildLocationFn, FullSearchSchemaOption, MakeRemountDepsOptionsUnion, RemountDepsOptions, ResolveFullPath, AnyRouteWithContext, AnyRouterWithContext, CommitLocationOptions, MatchLocation, UseNavigateResult, AnyRedirect, Redirect, ResolvedRedirect, MakeRouteMatch, MakeRouteMatchUnion, RouteMatch, AnyRouteMatch, RouteContextFn, RouteContextOptions, BeforeLoadFn, BeforeLoadContextOptions, ContextOptions, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, RouteLoaderFn, LoaderFnContext, LazyRouteOptions, AnyRouter, RegisteredRouter, RouterContextOptions, ControllablePromise, InjectedHtmlEntry, RouterOptions, RouterErrorSerializer, RouterState, ListenerFn, BuildNextOptions, RouterConstructorOptions, RouterEvents, RouterEvent, RouterListener, RouteConstraints, RouteMask, MatchRouteOptions, } from '@tanstack/router-core';
|
||||
export type { UseLinkPropsOptions, ActiveLinkOptions, LinkProps, LinkComponent, LinkComponentProps, CreateLinkProps, } from './link.js';
|
||||
export { Matches, useMatchRoute, MatchRoute, useMatches, useParentMatches, useChildMatches, } from './Matches.js';
|
||||
export type { UseMatchRouteOptions, MakeMatchRouteOptions } from './Matches.js';
|
||||
export { matchContext } from './matchContext.js';
|
||||
export { Match, Outlet } from './Match.js';
|
||||
export { useMatch } from './useMatch.js';
|
||||
export { useLoaderDeps } from './useLoaderDeps.js';
|
||||
export { useLoaderData } from './useLoaderData.js';
|
||||
export { redirect, isRedirect } from '@tanstack/router-core';
|
||||
export { RouteApi, getRouteApi, Route, createRoute, RootRoute, rootRouteWithContext, createRootRoute, createRootRouteWithContext, createRouteMask, NotFoundRoute, } from './route.js';
|
||||
export type { AnyRootRoute, ReactNode, SyncRouteComponent, AsyncRouteComponent, RouteComponent, ErrorRouteComponent, NotFoundRouteComponent, } from './route.js';
|
||||
export { createRouter, Router } from './router.js';
|
||||
export { componentTypes, lazyFn, SearchParamError, PathParamError, getInitialRouterState, } from '@tanstack/router-core';
|
||||
export { RouterProvider, RouterContextProvider } from './RouterProvider.js';
|
||||
export type { RouterProps } from './RouterProvider.js';
|
||||
export { useElementScrollRestoration, ScrollRestoration, } from './ScrollRestoration.js';
|
||||
export type { UseBlockerOpts, ShouldBlockFn } from './useBlocker.js';
|
||||
export { useBlocker, Block } from './useBlocker.js';
|
||||
export { useNavigate, Navigate } from './useNavigate.js';
|
||||
export { useParams } from './useParams.js';
|
||||
export { useSearch } from './useSearch.js';
|
||||
export { getRouterContext, } from './routerContext.js';
|
||||
export { useRouteContext } from './useRouteContext.js';
|
||||
export { useRouter } from './useRouter.js';
|
||||
export { useRouterState } from './useRouterState.js';
|
||||
export { useLocation } from './useLocation.js';
|
||||
export { useCanGoBack } from './useCanGoBack.js';
|
||||
export { useLayoutEffect, // SSR
|
||||
useStableCallback, } from './utils.js';
|
||||
export { CatchNotFound, DefaultGlobalNotFound } from './not-found.js';
|
||||
export { notFound, isNotFound } from '@tanstack/router-core';
|
||||
export type { NotFoundError } from '@tanstack/router-core';
|
||||
export type { ValidateLinkOptions, InferStructuralSharing, ValidateUseSearchOptions, ValidateUseParamsOptions, ValidateLinkOptionsArray, } from './typePrimitives.js';
|
||||
export type { ValidateFromPath, ValidateToPath, ValidateSearch, ValidateParams, InferFrom, InferTo, InferMaskTo, InferMaskFrom, ValidateNavigateOptions, ValidateNavigateOptionsArray, ValidateRedirectOptions, ValidateRedirectOptionsArray, ValidateId, InferStrict, InferShouldThrow, InferSelected, ValidateUseSearchResult, ValidateUseParamsResult, } from '@tanstack/router-core';
|
||||
export { ScriptOnce } from './ScriptOnce.js';
|
||||
export { Asset } from './Asset.js';
|
||||
export { HeadContent } from './HeadContent.js';
|
||||
export { Scripts } from './Scripts.js';
|
||||
@@ -0,0 +1,19 @@
|
||||
// Standard YAML's JSON schema.
|
||||
// http://www.yaml.org/spec/1.2/spec.html#id2803231
|
||||
//
|
||||
// NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
|
||||
// So, this schema is not such strict as defined in the YAML specification.
|
||||
// It allows numbers in binary notaion, use `Null` and `NULL` as `null`, etc.
|
||||
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
module.exports = require('./failsafe').extend({
|
||||
implicit: [
|
||||
require('../type/null'),
|
||||
require('../type/bool'),
|
||||
require('../type/int'),
|
||||
require('../type/float')
|
||||
]
|
||||
});
|
||||
@@ -0,0 +1,144 @@
|
||||
'use strict'
|
||||
|
||||
let { existsSync, readFileSync } = require('fs')
|
||||
let { dirname, join } = require('path')
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
|
||||
function fromBase64(str) {
|
||||
if (Buffer) {
|
||||
return Buffer.from(str, 'base64').toString()
|
||||
} else {
|
||||
/* c8 ignore next 2 */
|
||||
return window.atob(str)
|
||||
}
|
||||
}
|
||||
|
||||
class PreviousMap {
|
||||
constructor(css, opts) {
|
||||
if (opts.map === false) return
|
||||
this.loadAnnotation(css)
|
||||
this.inline = this.startWith(this.annotation, 'data:')
|
||||
|
||||
let prev = opts.map ? opts.map.prev : undefined
|
||||
let text = this.loadMap(opts.from, prev)
|
||||
if (!this.mapFile && opts.from) {
|
||||
this.mapFile = opts.from
|
||||
}
|
||||
if (this.mapFile) this.root = dirname(this.mapFile)
|
||||
if (text) this.text = text
|
||||
}
|
||||
|
||||
consumer() {
|
||||
if (!this.consumerCache) {
|
||||
this.consumerCache = new SourceMapConsumer(this.text)
|
||||
}
|
||||
return this.consumerCache
|
||||
}
|
||||
|
||||
decodeInline(text) {
|
||||
let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
|
||||
let baseUri = /^data:application\/json;base64,/
|
||||
let charsetUri = /^data:application\/json;charset=utf-?8,/
|
||||
let uri = /^data:application\/json,/
|
||||
|
||||
let uriMatch = text.match(charsetUri) || text.match(uri)
|
||||
if (uriMatch) {
|
||||
return decodeURIComponent(text.substr(uriMatch[0].length))
|
||||
}
|
||||
|
||||
let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri)
|
||||
if (baseUriMatch) {
|
||||
return fromBase64(text.substr(baseUriMatch[0].length))
|
||||
}
|
||||
|
||||
let encoding = text.match(/data:application\/json;([^,]+),/)[1]
|
||||
throw new Error('Unsupported source map encoding ' + encoding)
|
||||
}
|
||||
|
||||
getAnnotationURL(sourceMapString) {
|
||||
return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
|
||||
}
|
||||
|
||||
isMap(map) {
|
||||
if (typeof map !== 'object') return false
|
||||
return (
|
||||
typeof map.mappings === 'string' ||
|
||||
typeof map._mappings === 'string' ||
|
||||
Array.isArray(map.sections)
|
||||
)
|
||||
}
|
||||
|
||||
loadAnnotation(css) {
|
||||
let comments = css.match(/\/\*\s*# sourceMappingURL=/g)
|
||||
if (!comments) return
|
||||
|
||||
// sourceMappingURLs from comments, strings, etc.
|
||||
let start = css.lastIndexOf(comments.pop())
|
||||
let end = css.indexOf('*/', start)
|
||||
|
||||
if (start > -1 && end > -1) {
|
||||
// Locate the last sourceMappingURL to avoid pickin
|
||||
this.annotation = this.getAnnotationURL(css.substring(start, end))
|
||||
}
|
||||
}
|
||||
|
||||
loadFile(path) {
|
||||
this.root = dirname(path)
|
||||
if (existsSync(path)) {
|
||||
this.mapFile = path
|
||||
return readFileSync(path, 'utf-8').toString().trim()
|
||||
}
|
||||
}
|
||||
|
||||
loadMap(file, prev) {
|
||||
if (prev === false) return false
|
||||
|
||||
if (prev) {
|
||||
if (typeof prev === 'string') {
|
||||
return prev
|
||||
} else if (typeof prev === 'function') {
|
||||
let prevPath = prev(file)
|
||||
if (prevPath) {
|
||||
let map = this.loadFile(prevPath)
|
||||
if (!map) {
|
||||
throw new Error(
|
||||
'Unable to load previous source map: ' + prevPath.toString()
|
||||
)
|
||||
}
|
||||
return map
|
||||
}
|
||||
} else if (prev instanceof SourceMapConsumer) {
|
||||
return SourceMapGenerator.fromSourceMap(prev).toString()
|
||||
} else if (prev instanceof SourceMapGenerator) {
|
||||
return prev.toString()
|
||||
} else if (this.isMap(prev)) {
|
||||
return JSON.stringify(prev)
|
||||
} else {
|
||||
throw new Error(
|
||||
'Unsupported previous source map format: ' + prev.toString()
|
||||
)
|
||||
}
|
||||
} else if (this.inline) {
|
||||
return this.decodeInline(this.annotation)
|
||||
} else if (this.annotation) {
|
||||
let map = this.annotation
|
||||
if (file) map = join(dirname(file), map)
|
||||
return this.loadFile(map)
|
||||
}
|
||||
}
|
||||
|
||||
startWith(string, start) {
|
||||
if (!string) return false
|
||||
return string.substr(0, start.length) === start
|
||||
}
|
||||
|
||||
withContent() {
|
||||
return !!(
|
||||
this.consumer().sourcesContent &&
|
||||
this.consumer().sourcesContent.length > 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PreviousMap
|
||||
PreviousMap.default = PreviousMap
|
||||
@@ -0,0 +1,131 @@
|
||||
# fast-json-stable-stringify
|
||||
|
||||
Deterministic `JSON.stringify()` - a faster version of [@substack](https://github.com/substack)'s json-stable-strigify without [jsonify](https://github.com/substack/jsonify).
|
||||
|
||||
You can also pass in a custom comparison function.
|
||||
|
||||
[](https://travis-ci.org/epoberezkin/fast-json-stable-stringify)
|
||||
[](https://coveralls.io/github/epoberezkin/fast-json-stable-stringify?branch=master)
|
||||
|
||||
# example
|
||||
|
||||
``` js
|
||||
var stringify = require('fast-json-stable-stringify');
|
||||
var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
|
||||
console.log(stringify(obj));
|
||||
```
|
||||
|
||||
output:
|
||||
|
||||
```
|
||||
{"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}
|
||||
```
|
||||
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var stringify = require('fast-json-stable-stringify')
|
||||
```
|
||||
|
||||
## var str = stringify(obj, opts)
|
||||
|
||||
Return a deterministic stringified string `str` from the object `obj`.
|
||||
|
||||
|
||||
## options
|
||||
|
||||
### cmp
|
||||
|
||||
If `opts` is given, you can supply an `opts.cmp` to have a custom comparison
|
||||
function for object keys. Your function `opts.cmp` is called with these
|
||||
parameters:
|
||||
|
||||
``` js
|
||||
opts.cmp({ key: akey, value: avalue }, { key: bkey, value: bvalue })
|
||||
```
|
||||
|
||||
For example, to sort on the object key names in reverse order you could write:
|
||||
|
||||
``` js
|
||||
var stringify = require('fast-json-stable-stringify');
|
||||
|
||||
var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
|
||||
var s = stringify(obj, function (a, b) {
|
||||
return a.key < b.key ? 1 : -1;
|
||||
});
|
||||
console.log(s);
|
||||
```
|
||||
|
||||
which results in the output string:
|
||||
|
||||
```
|
||||
{"c":8,"b":[{"z":6,"y":5,"x":4},7],"a":3}
|
||||
```
|
||||
|
||||
Or if you wanted to sort on the object values in reverse order, you could write:
|
||||
|
||||
```
|
||||
var stringify = require('fast-json-stable-stringify');
|
||||
|
||||
var obj = { d: 6, c: 5, b: [{z:3,y:2,x:1},9], a: 10 };
|
||||
var s = stringify(obj, function (a, b) {
|
||||
return a.value < b.value ? 1 : -1;
|
||||
});
|
||||
console.log(s);
|
||||
```
|
||||
|
||||
which outputs:
|
||||
|
||||
```
|
||||
{"d":6,"c":5,"b":[{"z":3,"y":2,"x":1},9],"a":10}
|
||||
```
|
||||
|
||||
### cycles
|
||||
|
||||
Pass `true` in `opts.cycles` to stringify circular property as `__cycle__` - the result will not be a valid JSON string in this case.
|
||||
|
||||
TypeError will be thrown in case of circular object without this option.
|
||||
|
||||
|
||||
# install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install fast-json-stable-stringify
|
||||
```
|
||||
|
||||
|
||||
# benchmark
|
||||
|
||||
To run benchmark (requires Node.js 6+):
|
||||
```
|
||||
node benchmark
|
||||
```
|
||||
|
||||
Results:
|
||||
```
|
||||
fast-json-stable-stringify x 17,189 ops/sec ±1.43% (83 runs sampled)
|
||||
json-stable-stringify x 13,634 ops/sec ±1.39% (85 runs sampled)
|
||||
fast-stable-stringify x 20,212 ops/sec ±1.20% (84 runs sampled)
|
||||
faster-stable-stringify x 15,549 ops/sec ±1.12% (84 runs sampled)
|
||||
The fastest is fast-stable-stringify
|
||||
```
|
||||
|
||||
|
||||
## Enterprise support
|
||||
|
||||
fast-json-stable-stringify package is a part of [Tidelift enterprise subscription](https://tidelift.com/subscription/pkg/npm-fast-json-stable-stringify?utm_source=npm-fast-json-stable-stringify&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - it provides a centralised commercial support to open-source software users, in addition to the support provided by software maintainers.
|
||||
|
||||
|
||||
## Security contact
|
||||
|
||||
To report a security vulnerability, please use the
|
||||
[Tidelift security contact](https://tidelift.com/security).
|
||||
Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues.
|
||||
|
||||
|
||||
# license
|
||||
|
||||
[MIT](https://github.com/epoberezkin/fast-json-stable-stringify/blob/master/LICENSE)
|
||||
@@ -0,0 +1,49 @@
|
||||
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
|
||||
export * from "@tanstack/store";
|
||||
function useStore(store, selector = (d) => d) {
|
||||
const slice = useSyncExternalStoreWithSelector(
|
||||
store.subscribe,
|
||||
() => store.state,
|
||||
() => store.state,
|
||||
selector,
|
||||
shallow
|
||||
);
|
||||
return slice;
|
||||
}
|
||||
function shallow(objA, objB) {
|
||||
if (Object.is(objA, objB)) {
|
||||
return true;
|
||||
}
|
||||
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
|
||||
return false;
|
||||
}
|
||||
if (objA instanceof Map && objB instanceof Map) {
|
||||
if (objA.size !== objB.size) return false;
|
||||
for (const [k, v] of objA) {
|
||||
if (!objB.has(k) || !Object.is(v, objB.get(k))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (objA instanceof Set && objB instanceof Set) {
|
||||
if (objA.size !== objB.size) return false;
|
||||
for (const v of objA) {
|
||||
if (!objB.has(v)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const keysA = Object.keys(objA);
|
||||
if (keysA.length !== Object.keys(objB).length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < keysA.length; i++) {
|
||||
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
export {
|
||||
shallow,
|
||||
useStore
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Tailwind Labs, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,26 @@
|
||||
import { NavigateOptions, ToOptions } from './link.js';
|
||||
import { ParsedLocation } from './location.js';
|
||||
import { RoutePaths } from './routeInfo.js';
|
||||
import { AnyRouter, RegisteredRouter, ViewTransitionOptions } from './router.js';
|
||||
export interface MatchLocation {
|
||||
to?: string | number | null;
|
||||
fuzzy?: boolean;
|
||||
caseSensitive?: boolean;
|
||||
from?: string;
|
||||
}
|
||||
export interface CommitLocationOptions {
|
||||
replace?: boolean;
|
||||
resetScroll?: boolean;
|
||||
hashScrollIntoView?: boolean | ScrollIntoViewOptions;
|
||||
viewTransition?: boolean | ViewTransitionOptions;
|
||||
/**
|
||||
* @deprecated All navigations use React transitions under the hood now
|
||||
**/
|
||||
startTransition?: boolean;
|
||||
ignoreBlocker?: boolean;
|
||||
}
|
||||
export type NavigateFn = <TRouter extends RegisteredRouter, TTo extends string | undefined, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void> | void;
|
||||
export type BuildLocationFn = <TRouter extends AnyRouter, TTo extends string | undefined, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = ''>(opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
||||
leaveParams?: boolean;
|
||||
_includeValidateSearch?: boolean;
|
||||
}) => ParsedLocation;
|
||||
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"name": "ignore",
|
||||
"version": "5.3.2",
|
||||
"description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.",
|
||||
"files": [
|
||||
"legacy.js",
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"LICENSE-MIT"
|
||||
],
|
||||
"scripts": {
|
||||
"prepublishOnly": "npm run build",
|
||||
"build": "babel -o legacy.js index.js",
|
||||
"test:lint": "eslint .",
|
||||
"test:tsc": "tsc ./test/ts/simple.ts --lib ES6",
|
||||
"test:ts": "node ./test/ts/simple.js",
|
||||
"tap": "tap --reporter classic",
|
||||
"test:git": "npm run tap test/git-check-ignore.js",
|
||||
"test:ignore": "npm run tap test/ignore.js",
|
||||
"test:ignore:only": "IGNORE_ONLY_IGNORES=1 npm run tap test/ignore.js",
|
||||
"test:others": "npm run tap test/others.js",
|
||||
"test:cases": "npm run tap test/*.js -- --coverage",
|
||||
"test:no-coverage": "npm run tap test/*.js -- --no-check-coverage",
|
||||
"test:only": "npm run test:lint && npm run test:tsc && npm run test:ts && npm run test:cases",
|
||||
"test": "npm run test:only",
|
||||
"test:win32": "IGNORE_TEST_WIN32=1 npm run test",
|
||||
"report": "tap --coverage-report=html",
|
||||
"posttest": "npm run report && codecov"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:kaelzhang/node-ignore.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ignore",
|
||||
".gitignore",
|
||||
"gitignore",
|
||||
"npmignore",
|
||||
"rules",
|
||||
"manager",
|
||||
"filter",
|
||||
"regexp",
|
||||
"regex",
|
||||
"fnmatch",
|
||||
"glob",
|
||||
"asterisks",
|
||||
"regular-expression"
|
||||
],
|
||||
"author": "kael",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/kaelzhang/node-ignore/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.22.9",
|
||||
"@babel/core": "^7.22.9",
|
||||
"@babel/preset-env": "^7.22.9",
|
||||
"codecov": "^3.8.2",
|
||||
"debug": "^4.3.4",
|
||||
"eslint": "^8.46.0",
|
||||
"eslint-config-ostai": "^3.0.0",
|
||||
"eslint-plugin-import": "^2.28.0",
|
||||
"mkdirp": "^3.0.1",
|
||||
"pre-suf": "^1.1.1",
|
||||
"rimraf": "^6.0.1",
|
||||
"spawn-sync": "^2.0.0",
|
||||
"tap": "^16.3.9",
|
||||
"tmp": "0.2.3",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
var looseEnvify = require('./');
|
||||
var fs = require('fs');
|
||||
|
||||
if (process.argv[2]) {
|
||||
fs.createReadStream(process.argv[2], {encoding: 'utf8'})
|
||||
.pipe(looseEnvify(process.argv[2]))
|
||||
.pipe(process.stdout);
|
||||
} else {
|
||||
process.stdin.resume()
|
||||
process.stdin
|
||||
.pipe(looseEnvify(__filename))
|
||||
.pipe(process.stdout);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import Document from './document.js'
|
||||
import LazyResult from './lazy-result.js'
|
||||
import NoWorkResult from './no-work-result.js'
|
||||
import {
|
||||
AcceptedPlugin,
|
||||
Plugin,
|
||||
ProcessOptions,
|
||||
TransformCallback,
|
||||
Transformer
|
||||
} from './postcss.js'
|
||||
import Result from './result.js'
|
||||
import Root from './root.js'
|
||||
|
||||
declare namespace Processor {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
export { Processor_ as default }
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains plugins to process CSS. Create one `Processor` instance,
|
||||
* initialize its plugins, and then use that instance on numerous CSS files.
|
||||
*
|
||||
* ```js
|
||||
* const processor = postcss([autoprefixer, postcssNested])
|
||||
* processor.process(css1).then(result => console.log(result.css))
|
||||
* processor.process(css2).then(result => console.log(result.css))
|
||||
* ```
|
||||
*/
|
||||
declare class Processor_ {
|
||||
/**
|
||||
* Plugins added to this processor.
|
||||
*
|
||||
* ```js
|
||||
* const processor = postcss([autoprefixer, postcssNested])
|
||||
* processor.plugins.length //=> 2
|
||||
* ```
|
||||
*/
|
||||
plugins: (Plugin | TransformCallback | Transformer)[]
|
||||
|
||||
/**
|
||||
* Current PostCSS version.
|
||||
*
|
||||
* ```js
|
||||
* if (result.processor.version.split('.')[0] !== '6') {
|
||||
* throw new Error('This plugin works only with PostCSS 6')
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
version: string
|
||||
|
||||
/**
|
||||
* @param plugins PostCSS plugins
|
||||
*/
|
||||
constructor(plugins?: readonly AcceptedPlugin[])
|
||||
|
||||
/**
|
||||
* Parses source CSS and returns a `LazyResult` Promise proxy.
|
||||
* Because some plugins can be asynchronous it doesn’t make
|
||||
* any transformations. Transformations will be applied
|
||||
* in the `LazyResult` methods.
|
||||
*
|
||||
* ```js
|
||||
* processor.process(css, { from: 'a.css', to: 'a.out.css' })
|
||||
* .then(result => {
|
||||
* console.log(result.css)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @param css String with input CSS or any object with a `toString()` method,
|
||||
* like a Buffer. Optionally, send a `Result` instance
|
||||
* and the processor will take the `Root` from it.
|
||||
* @param opts Options.
|
||||
* @return Promise proxy.
|
||||
*/
|
||||
process(
|
||||
css: { toString(): string } | LazyResult | Result | Root | string
|
||||
): LazyResult | NoWorkResult
|
||||
process<RootNode extends Document | Root = Root>(
|
||||
css: { toString(): string } | LazyResult | Result | Root | string,
|
||||
options: ProcessOptions<RootNode>
|
||||
): LazyResult<RootNode>
|
||||
|
||||
/**
|
||||
* Adds a plugin to be used as a CSS processor.
|
||||
*
|
||||
* PostCSS plugin can be in 4 formats:
|
||||
* * A plugin in `Plugin` format.
|
||||
* * A plugin creator function with `pluginCreator.postcss = true`.
|
||||
* PostCSS will call this function without argument to get plugin.
|
||||
* * A function. PostCSS will pass the function a {@link Root}
|
||||
* as the first argument and current `Result` instance
|
||||
* as the second.
|
||||
* * Another `Processor` instance. PostCSS will copy plugins
|
||||
* from that instance into this one.
|
||||
*
|
||||
* Plugins can also be added by passing them as arguments when creating
|
||||
* a `postcss` instance (see [`postcss(plugins)`]).
|
||||
*
|
||||
* Asynchronous plugins should return a `Promise` instance.
|
||||
*
|
||||
* ```js
|
||||
* const processor = postcss()
|
||||
* .use(autoprefixer)
|
||||
* .use(postcssNested)
|
||||
* ```
|
||||
*
|
||||
* @param plugin PostCSS plugin or `Processor` with plugins.
|
||||
* @return Current processor to make methods chain.
|
||||
*/
|
||||
use(plugin: AcceptedPlugin): this
|
||||
}
|
||||
|
||||
declare class Processor extends Processor_ {}
|
||||
|
||||
export = Processor
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "beep-boop",
|
||||
"version": "1.2.3",
|
||||
"homepage": "https://github.com/substack/beep-boop/issues"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
var Type = require('../type');
|
||||
|
||||
function resolveYamlBoolean(data) {
|
||||
if (data === null) return false;
|
||||
|
||||
var max = data.length;
|
||||
|
||||
return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
|
||||
(max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
|
||||
}
|
||||
|
||||
function constructYamlBoolean(data) {
|
||||
return data === 'true' ||
|
||||
data === 'True' ||
|
||||
data === 'TRUE';
|
||||
}
|
||||
|
||||
function isBoolean(object) {
|
||||
return Object.prototype.toString.call(object) === '[object Boolean]';
|
||||
}
|
||||
|
||||
module.exports = new Type('tag:yaml.org,2002:bool', {
|
||||
kind: 'scalar',
|
||||
resolve: resolveYamlBoolean,
|
||||
construct: constructYamlBoolean,
|
||||
predicate: isBoolean,
|
||||
represent: {
|
||||
lowercase: function (object) { return object ? 'true' : 'false'; },
|
||||
uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
|
||||
camelcase: function (object) { return object ? 'True' : 'False'; }
|
||||
},
|
||||
defaultStyle: 'lowercase'
|
||||
});
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @fileoverview Rule to flag references to undeclared variables.
|
||||
* @author Mark Macdonald
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks if the given node is the argument of a typeof operator.
|
||||
* @param {ASTNode} node The AST node being checked.
|
||||
* @returns {boolean} Whether or not the node is the argument of a typeof operator.
|
||||
*/
|
||||
function hasTypeOfOperator(node) {
|
||||
const parent = node.parent;
|
||||
|
||||
return parent.type === "UnaryExpression" && parent.operator === "typeof";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
|
||||
defaultOptions: [
|
||||
{
|
||||
typeof: false,
|
||||
},
|
||||
],
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Disallow the use of undeclared variables unless mentioned in `/*global */` comments",
|
||||
recommended: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-undef",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
typeof: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
messages: {
|
||||
undef: "'{{name}}' is not defined.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const [{ typeof: considerTypeOf }] = context.options;
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
return {
|
||||
"Program:exit"(node) {
|
||||
const globalScope = sourceCode.getScope(node);
|
||||
|
||||
globalScope.through.forEach(ref => {
|
||||
const identifier = ref.identifier;
|
||||
|
||||
if (!considerTypeOf && hasTypeOfOperator(identifier)) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node: identifier,
|
||||
messageId: "undef",
|
||||
data: identifier,
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
export default function makeCancellablePromise(promise) {
|
||||
var isCancelled = false;
|
||||
var wrappedPromise = new Promise(function (resolve, reject) {
|
||||
promise
|
||||
.then(function (value) { return !isCancelled && resolve(value); })
|
||||
.catch(function (error) { return !isCancelled && reject(error); });
|
||||
});
|
||||
return {
|
||||
promise: wrappedPromise,
|
||||
cancel: function () {
|
||||
isCancelled = true;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_applyDecoratedDescriptor","target","property","decorators","descriptor","context","desc","Object","keys","forEach","key","enumerable","configurable","initializer","writable","slice","reverse","reduce","decorator","value","call","defineProperty"],"sources":["../../src/helpers/applyDecoratedDescriptor.ts"],"sourcesContent":["/* @minVersion 7.0.0-beta.0 */\n\ninterface DescriptorWithInitializer extends PropertyDescriptor {\n initializer?: () => any;\n}\n\ndeclare const Object: Omit<typeof globalThis.Object, \"keys\"> & {\n keys<T>(o: T): Array<keyof T>;\n};\n\nexport default function _applyDecoratedDescriptor<T>(\n target: T,\n property: PropertyKey,\n decorators: ((\n t: T,\n p: PropertyKey,\n desc: DescriptorWithInitializer,\n ) => any)[],\n descriptor: DescriptorWithInitializer,\n context: DecoratorContext,\n) {\n var desc: DescriptorWithInitializer = {};\n Object.keys(descriptor).forEach(function (key) {\n desc[key] = descriptor[key];\n });\n desc.enumerable = !!desc.enumerable;\n desc.configurable = !!desc.configurable;\n if (\"value\" in desc || desc.initializer) {\n desc.writable = true;\n }\n\n desc = decorators\n .slice()\n .reverse()\n .reduce(function (desc, decorator) {\n return decorator(target, property, desc) || desc;\n }, desc);\n\n if (context && desc.initializer !== void 0) {\n desc.value = desc.initializer ? desc.initializer.call(context) : void 0;\n desc.initializer = void 0;\n }\n\n if (desc.initializer === void 0) {\n Object.defineProperty(target, property, desc);\n return null;\n }\n\n return desc;\n}\n"],"mappings":";;;;;;AAUe,SAASA,yBAAyBA,CAC/CC,MAAS,EACTC,QAAqB,EACrBC,UAIW,EACXC,UAAqC,EACrCC,OAAyB,EACzB;EACA,IAAIC,IAA+B,GAAG,CAAC,CAAC;EACxCC,MAAM,CAACC,IAAI,CAACJ,UAAU,CAAC,CAACK,OAAO,CAAC,UAAUC,GAAG,EAAE;IAC7CJ,IAAI,CAACI,GAAG,CAAC,GAAGN,UAAU,CAACM,GAAG,CAAC;EAC7B,CAAC,CAAC;EACFJ,IAAI,CAACK,UAAU,GAAG,CAAC,CAACL,IAAI,CAACK,UAAU;EACnCL,IAAI,CAACM,YAAY,GAAG,CAAC,CAACN,IAAI,CAACM,YAAY;EACvC,IAAI,OAAO,IAAIN,IAAI,IAAIA,IAAI,CAACO,WAAW,EAAE;IACvCP,IAAI,CAACQ,QAAQ,GAAG,IAAI;EACtB;EAEAR,IAAI,GAAGH,UAAU,CACdY,KAAK,CAAC,CAAC,CACPC,OAAO,CAAC,CAAC,CACTC,MAAM,CAAC,UAAUX,IAAI,EAAEY,SAAS,EAAE;IACjC,OAAOA,SAAS,CAACjB,MAAM,EAAEC,QAAQ,EAAEI,IAAI,CAAC,IAAIA,IAAI;EAClD,CAAC,EAAEA,IAAI,CAAC;EAEV,IAAID,OAAO,IAAIC,IAAI,CAACO,WAAW,KAAK,KAAK,CAAC,EAAE;IAC1CP,IAAI,CAACa,KAAK,GAAGb,IAAI,CAACO,WAAW,GAAGP,IAAI,CAACO,WAAW,CAACO,IAAI,CAACf,OAAO,CAAC,GAAG,KAAK,CAAC;IACvEC,IAAI,CAACO,WAAW,GAAG,KAAK,CAAC;EAC3B;EAEA,IAAIP,IAAI,CAACO,WAAW,KAAK,KAAK,CAAC,EAAE;IAC/BN,MAAM,CAACc,cAAc,CAACpB,MAAM,EAAEC,QAAQ,EAAEI,IAAI,CAAC;IAC7C,OAAO,IAAI;EACb;EAEA,OAAOA,IAAI;AACb","ignoreList":[]}
|
||||
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.resolveBrowserslistConfigFile = resolveBrowserslistConfigFile;
|
||||
exports.resolveTargets = resolveTargets;
|
||||
function _helperCompilationTargets() {
|
||||
const data = require("@babel/helper-compilation-targets");
|
||||
_helperCompilationTargets = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function resolveBrowserslistConfigFile(browserslistConfigFile, configFilePath) {
|
||||
return undefined;
|
||||
}
|
||||
function resolveTargets(options, root) {
|
||||
const optTargets = options.targets;
|
||||
let targets;
|
||||
if (typeof optTargets === "string" || Array.isArray(optTargets)) {
|
||||
targets = {
|
||||
browsers: optTargets
|
||||
};
|
||||
} else if (optTargets) {
|
||||
if ("esmodules" in optTargets) {
|
||||
targets = Object.assign({}, optTargets, {
|
||||
esmodules: "intersect"
|
||||
});
|
||||
} else {
|
||||
targets = optTargets;
|
||||
}
|
||||
}
|
||||
return (0, _helperCompilationTargets().default)(targets, {
|
||||
ignoreBrowserslistConfig: true,
|
||||
browserslistEnv: options.browserslistEnv
|
||||
});
|
||||
}
|
||||
0 && 0;
|
||||
|
||||
//# sourceMappingURL=resolve-targets-browser.js.map
|
||||
@@ -0,0 +1,207 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.encode = exports.decode = void 0;
|
||||
const flatten_js_1 = require("./flatten.js");
|
||||
const unflatten_js_1 = require("./unflatten.js");
|
||||
const utils_js_1 = require("./utils.js");
|
||||
async function decode(readable, options) {
|
||||
const { plugins } = options ?? {};
|
||||
const done = new utils_js_1.Deferred();
|
||||
const reader = readable
|
||||
.pipeThrough((0, utils_js_1.createLineSplittingTransform)())
|
||||
.getReader();
|
||||
const decoder = {
|
||||
values: [],
|
||||
hydrated: [],
|
||||
deferred: {},
|
||||
plugins,
|
||||
};
|
||||
const decoded = await decodeInitial.call(decoder, reader);
|
||||
let donePromise = done.promise;
|
||||
if (decoded.done) {
|
||||
done.resolve();
|
||||
}
|
||||
else {
|
||||
donePromise = decodeDeferred
|
||||
.call(decoder, reader)
|
||||
.then(done.resolve)
|
||||
.catch((reason) => {
|
||||
for (const deferred of Object.values(decoder.deferred)) {
|
||||
deferred.reject(reason);
|
||||
}
|
||||
done.reject(reason);
|
||||
});
|
||||
}
|
||||
return {
|
||||
done: donePromise.then(() => reader.closed),
|
||||
value: decoded.value,
|
||||
};
|
||||
}
|
||||
exports.decode = decode;
|
||||
async function decodeInitial(reader) {
|
||||
const read = await reader.read();
|
||||
if (!read.value) {
|
||||
throw new SyntaxError();
|
||||
}
|
||||
let line;
|
||||
try {
|
||||
line = JSON.parse(read.value);
|
||||
}
|
||||
catch (reason) {
|
||||
throw new SyntaxError();
|
||||
}
|
||||
return {
|
||||
done: read.done,
|
||||
value: unflatten_js_1.unflatten.call(this, line),
|
||||
};
|
||||
}
|
||||
async function decodeDeferred(reader) {
|
||||
let read = await reader.read();
|
||||
while (!read.done) {
|
||||
if (!read.value)
|
||||
continue;
|
||||
const line = read.value;
|
||||
switch (line[0]) {
|
||||
case utils_js_1.TYPE_PROMISE: {
|
||||
const colonIndex = line.indexOf(":");
|
||||
const deferredId = Number(line.slice(1, colonIndex));
|
||||
const deferred = this.deferred[deferredId];
|
||||
if (!deferred) {
|
||||
throw new Error(`Deferred ID ${deferredId} not found in stream`);
|
||||
}
|
||||
const lineData = line.slice(colonIndex + 1);
|
||||
let jsonLine;
|
||||
try {
|
||||
jsonLine = JSON.parse(lineData);
|
||||
}
|
||||
catch (reason) {
|
||||
throw new SyntaxError();
|
||||
}
|
||||
const value = unflatten_js_1.unflatten.call(this, jsonLine);
|
||||
deferred.resolve(value);
|
||||
break;
|
||||
}
|
||||
case utils_js_1.TYPE_ERROR: {
|
||||
const colonIndex = line.indexOf(":");
|
||||
const deferredId = Number(line.slice(1, colonIndex));
|
||||
const deferred = this.deferred[deferredId];
|
||||
if (!deferred) {
|
||||
throw new Error(`Deferred ID ${deferredId} not found in stream`);
|
||||
}
|
||||
const lineData = line.slice(colonIndex + 1);
|
||||
let jsonLine;
|
||||
try {
|
||||
jsonLine = JSON.parse(lineData);
|
||||
}
|
||||
catch (reason) {
|
||||
throw new SyntaxError();
|
||||
}
|
||||
const value = unflatten_js_1.unflatten.call(this, jsonLine);
|
||||
deferred.reject(value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new SyntaxError();
|
||||
}
|
||||
read = await reader.read();
|
||||
}
|
||||
}
|
||||
function encode(input, options) {
|
||||
const { plugins, postPlugins, signal } = options ?? {};
|
||||
const encoder = {
|
||||
deferred: {},
|
||||
index: 0,
|
||||
indices: new Map(),
|
||||
stringified: [],
|
||||
plugins,
|
||||
postPlugins,
|
||||
signal,
|
||||
};
|
||||
const textEncoder = new TextEncoder();
|
||||
let lastSentIndex = 0;
|
||||
const readable = new ReadableStream({
|
||||
async start(controller) {
|
||||
const id = flatten_js_1.flatten.call(encoder, input);
|
||||
if (Array.isArray(id)) {
|
||||
throw new Error("This should never happen");
|
||||
}
|
||||
if (id < 0) {
|
||||
controller.enqueue(textEncoder.encode(`${id}\n`));
|
||||
}
|
||||
else {
|
||||
controller.enqueue(textEncoder.encode(`[${encoder.stringified.join(",")}]\n`));
|
||||
lastSentIndex = encoder.stringified.length - 1;
|
||||
}
|
||||
const seenPromises = new WeakSet();
|
||||
while (Object.keys(encoder.deferred).length > 0) {
|
||||
for (const [deferredId, deferred] of Object.entries(encoder.deferred)) {
|
||||
if (seenPromises.has(deferred))
|
||||
continue;
|
||||
seenPromises.add((encoder.deferred[Number(deferredId)] = raceSignal(deferred, encoder.signal)
|
||||
.then((resolved) => {
|
||||
const id = flatten_js_1.flatten.call(encoder, resolved);
|
||||
if (Array.isArray(id)) {
|
||||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:[["${utils_js_1.TYPE_PREVIOUS_RESOLVED}",${id[0]}]]\n`));
|
||||
encoder.index++;
|
||||
lastSentIndex++;
|
||||
}
|
||||
else if (id < 0) {
|
||||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:${id}\n`));
|
||||
}
|
||||
else {
|
||||
const values = encoder.stringified
|
||||
.slice(lastSentIndex + 1)
|
||||
.join(",");
|
||||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:[${values}]\n`));
|
||||
lastSentIndex = encoder.stringified.length - 1;
|
||||
}
|
||||
}, (reason) => {
|
||||
if (!reason ||
|
||||
typeof reason !== "object" ||
|
||||
!(reason instanceof Error)) {
|
||||
reason = new Error("An unknown error occurred");
|
||||
}
|
||||
const id = flatten_js_1.flatten.call(encoder, reason);
|
||||
if (Array.isArray(id)) {
|
||||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:[["${utils_js_1.TYPE_PREVIOUS_RESOLVED}",${id[0]}]]\n`));
|
||||
encoder.index++;
|
||||
lastSentIndex++;
|
||||
}
|
||||
else if (id < 0) {
|
||||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:${id}\n`));
|
||||
}
|
||||
else {
|
||||
const values = encoder.stringified
|
||||
.slice(lastSentIndex + 1)
|
||||
.join(",");
|
||||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:[${values}]\n`));
|
||||
lastSentIndex = encoder.stringified.length - 1;
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
delete encoder.deferred[Number(deferredId)];
|
||||
})));
|
||||
}
|
||||
await Promise.race(Object.values(encoder.deferred));
|
||||
}
|
||||
await Promise.all(Object.values(encoder.deferred));
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
return readable;
|
||||
}
|
||||
exports.encode = encode;
|
||||
function raceSignal(promise, signal) {
|
||||
if (!signal)
|
||||
return promise;
|
||||
if (signal.aborted)
|
||||
return Promise.reject(signal.reason || new Error("Signal was aborted."));
|
||||
const abort = new Promise((resolve, reject) => {
|
||||
signal.addEventListener("abort", (event) => {
|
||||
reject(signal.reason || new Error("Signal was aborted."));
|
||||
});
|
||||
promise.then(resolve).catch(reject);
|
||||
});
|
||||
abort.catch(() => { });
|
||||
return Promise.race([abort, promise]);
|
||||
}
|
||||
Reference in New Issue
Block a user