@warp-drive/core 5.6.0-alpha.11 → 5.6.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { getOrSetGlobal, peekTransient, setTransient } from "./types/-private.js";
1
+ import { getOrSetGlobal, peekTransient, setTransient } from './types/-private.js';
2
2
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
3
3
  const ARRAY_SIGNAL = getOrSetGlobal('#[]', Symbol('#[]'));
4
4
  const OBJECT_SIGNAL = getOrSetGlobal('#{}', Symbol('#{}'));
@@ -1 +1 @@
1
- {"version":3,"file":"configure-Bz49BEZQ.js","sources":["../src/store/-private/new-core-tmp/reactivity/configure.ts"],"sourcesContent":["import { assert } from '@warp-drive/core/build-config/macros';\n\nimport { getOrSetGlobal, peekTransient, setTransient } from '../../../../types/-private.ts';\n\nexport const ARRAY_SIGNAL = getOrSetGlobal('#[]', Symbol('#[]'));\nexport const OBJECT_SIGNAL = getOrSetGlobal('#{}', Symbol('#{}'));\n\n/**\n * Requirements:\n *\n * Signal:\n *\n * - signal: a way of creating a reference that we can dirty when we desire to notify\n * - @signal: a way of creating an accessor on an object that subscribes to a signal on access\n * and notifies the signal on set, or of upgrading a descriptor to be such an accessor\n * - defineSignal: a way of creating a signal on an object\n * - notifySignal: a way of notifying the underlying signal that it has been dirtied\n * - peekSignal: a way of inspecting the signal without notifying it\n *\n * - gate: a memoized getter function that re-runs when on access if its signal is dirty\n * conceptually, a gate is a tightly coupled signal and memo\n * - @gate: a way of creating a gate on an object or upgrading a descriptor with a getter\n * to be a gate\n * - defineGate: a way of creating a gate on an object\n * - notifySignal: a way of notifying the signal for a gate that it has been dirtied\n *\n * - memo:\n * - @memo: a way of creating a memoized getter on an object or upgrading a descriptor with a getter\n * to be a memo\n * - defineMemo: a way of creating a memo on an object\n *\n * - signalStore: storage bucket for signals associated to an object\n * - withSignalStore: a way of pre-creating a signal store on an object\n *\n *\n * @internal\n */\n\n/**\n * An Opaque type that represents a framework specific or TC39 signal.\n *\n * It may be an array of signals or a single signal.\n *\n * @internal\n */\nexport type SignalRef = unknown;\n/**\n * The hooks which MUST be configured in order to use this library,\n * either for framework specfic signals or TC39 signals.\n *\n * Support for multiple frameworks simultaneously can be done via\n * this abstraction by returning multiple signals from the `createSignal`\n * method, and consuming the correct one via the correct framework via\n * the `consumeSignal` and `notifySignal` methods.\n *\n */\nexport interface SignalHooks<T = SignalRef> {\n createSignal: (obj: object, key: string | symbol) => T;\n consumeSignal: (signal: T) => void;\n notifySignal: (signal: T) => void;\n createMemo: <F>(obj: object, key: string | symbol, fn: () => F) => () => F;\n willSyncFlushWatchers: () => boolean;\n waitFor?: <K>(promise: Promise<K>) => Promise<K>;\n}\n\nexport interface HooksOptions {\n wellknown: {\n Array: symbol | string;\n };\n}\n\n/**\n * Configures the signals implementation to use. Supports multiple\n * implementations simultaneously.\n *\n * @public\n * @param buildConfig - a function that takes options and returns a configuration object\n */\nexport function setupSignals<T>(buildConfig: (options: HooksOptions) => SignalHooks<T>) {\n // We want to assert this but can't because too many package manager\n // and bundler bugs exist that cause this to be called multiple times\n // for what should be a single call.\n // assert(`Cannot override configured signal hooks`, peekTransient('signalHooks') === null);\n const hooks = buildConfig({\n wellknown: {\n Array: ARRAY_SIGNAL,\n },\n });\n setTransient('signalHooks', hooks);\n}\n\n/**\n * Internal method for consuming the configured `createSignal` hook\n *\n * @internal\n */\nexport function createSignal(obj: object, key: string | symbol): SignalRef {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.createSignal(obj, key);\n}\n\n/**\n * Internal method for consuming the configured `consumeSignal` hook\n *\n * @internal\n */\nexport function consumeSignal(signal: SignalRef) {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.consumeSignal(signal);\n}\n\n/**\n * Internal method for consuming the configured `notifySignal` hook\n *\n * @internal\n */\nexport function notifySignal(signal: SignalRef) {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.notifySignal(signal);\n}\n\nexport function createMemo<T>(object: object, key: string | symbol, fn: () => T): () => T {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.createMemo(object, key, fn);\n}\n\nexport function willSyncFlushWatchers(): boolean {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.willSyncFlushWatchers();\n}\n\nexport function waitFor<K>(promise: Promise<K>): Promise<K> {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n\n if (signalHooks?.waitFor) {\n return signalHooks.waitFor(promise);\n }\n return promise;\n}\n"],"names":["ARRAY_SIGNAL","getOrSetGlobal","Symbol","OBJECT_SIGNAL","setupSignals","buildConfig","hooks","wellknown","Array","setTransient","createSignal","obj","key","signalHooks","peekTransient","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","consumeSignal","signal","notifySignal","createMemo","object","fn","willSyncFlushWatchers","waitFor","promise"],"mappings":";;;AAIO,MAAMA,YAAY,GAAGC,cAAc,CAAC,KAAK,EAAEC,MAAM,CAAC,KAAK,CAAC;AACxD,MAAMC,aAAa,GAAGF,cAAc,CAAC,KAAK,EAAEC,MAAM,CAAC,KAAK,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAAIC,WAAsD,EAAE;AACtF;AACA;AACA;AACA;EACA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AAO,EAAE;AACxB,IAAA,OAAOhB,WAAW,CAACgB,OAAO,CAACC,OAAO,CAAC;AACrC;AACA,EAAA,OAAOA,OAAO;AAChB;;;;"}
1
+ {"version":3,"file":"configure-BgaZESRo.js","sources":["../src/store/-private/new-core-tmp/reactivity/configure.ts"],"sourcesContent":["import { assert } from '@warp-drive/core/build-config/macros';\n\nimport { getOrSetGlobal, peekTransient, setTransient } from '../../../../types/-private.ts';\n\nexport const ARRAY_SIGNAL = getOrSetGlobal('#[]', Symbol('#[]'));\nexport const OBJECT_SIGNAL = getOrSetGlobal('#{}', Symbol('#{}'));\n\n/**\n * Requirements:\n *\n * Signal:\n *\n * - signal: a way of creating a reference that we can dirty when we desire to notify\n * - @signal: a way of creating an accessor on an object that subscribes to a signal on access\n * and notifies the signal on set, or of upgrading a descriptor to be such an accessor\n * - defineSignal: a way of creating a signal on an object\n * - notifySignal: a way of notifying the underlying signal that it has been dirtied\n * - peekSignal: a way of inspecting the signal without notifying it\n *\n * - gate: a memoized getter function that re-runs when on access if its signal is dirty\n * conceptually, a gate is a tightly coupled signal and memo\n * - @gate: a way of creating a gate on an object or upgrading a descriptor with a getter\n * to be a gate\n * - defineGate: a way of creating a gate on an object\n * - notifySignal: a way of notifying the signal for a gate that it has been dirtied\n *\n * - memo:\n * - @memo: a way of creating a memoized getter on an object or upgrading a descriptor with a getter\n * to be a memo\n * - defineMemo: a way of creating a memo on an object\n *\n * - signalStore: storage bucket for signals associated to an object\n * - withSignalStore: a way of pre-creating a signal store on an object\n *\n *\n * @internal\n */\n\n/**\n * An Opaque type that represents a framework specific or TC39 signal.\n *\n * It may be an array of signals or a single signal.\n *\n * @internal\n */\nexport type SignalRef = unknown;\n/**\n * The hooks which MUST be configured in order to use this library,\n * either for framework specfic signals or TC39 signals.\n *\n * Support for multiple frameworks simultaneously can be done via\n * this abstraction by returning multiple signals from the `createSignal`\n * method, and consuming the correct one via the correct framework via\n * the `consumeSignal` and `notifySignal` methods.\n *\n */\nexport interface SignalHooks<T = SignalRef> {\n createSignal: (obj: object, key: string | symbol) => T;\n consumeSignal: (signal: T) => void;\n notifySignal: (signal: T) => void;\n createMemo: <F>(obj: object, key: string | symbol, fn: () => F) => () => F;\n willSyncFlushWatchers: () => boolean;\n waitFor?: <K>(promise: Promise<K>) => Promise<K>;\n}\n\nexport interface HooksOptions {\n wellknown: {\n Array: symbol | string;\n };\n}\n\n/**\n * Configures the signals implementation to use. Supports multiple\n * implementations simultaneously.\n *\n * @public\n * @param buildConfig - a function that takes options and returns a configuration object\n */\nexport function setupSignals<T>(buildConfig: (options: HooksOptions) => SignalHooks<T>) {\n // We want to assert this but can't because too many package manager\n // and bundler bugs exist that cause this to be called multiple times\n // for what should be a single call.\n // assert(`Cannot override configured signal hooks`, peekTransient('signalHooks') === null);\n const hooks = buildConfig({\n wellknown: {\n Array: ARRAY_SIGNAL,\n },\n });\n setTransient('signalHooks', hooks);\n}\n\n/**\n * Internal method for consuming the configured `createSignal` hook\n *\n * @internal\n */\nexport function createSignal(obj: object, key: string | symbol): SignalRef {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.createSignal(obj, key);\n}\n\n/**\n * Internal method for consuming the configured `consumeSignal` hook\n *\n * @internal\n */\nexport function consumeSignal(signal: SignalRef) {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.consumeSignal(signal);\n}\n\n/**\n * Internal method for consuming the configured `notifySignal` hook\n *\n * @internal\n */\nexport function notifySignal(signal: SignalRef) {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.notifySignal(signal);\n}\n\nexport function createMemo<T>(object: object, key: string | symbol, fn: () => T): () => T {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.createMemo(object, key, fn);\n}\n\nexport function willSyncFlushWatchers(): boolean {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n assert(`Signal hooks not configured`, signalHooks);\n return signalHooks.willSyncFlushWatchers();\n}\n\nexport function waitFor<K>(promise: Promise<K>): Promise<K> {\n const signalHooks: SignalHooks | null = peekTransient('signalHooks');\n\n if (signalHooks?.waitFor) {\n return signalHooks.waitFor(promise);\n }\n return promise;\n}\n"],"names":["ARRAY_SIGNAL","getOrSetGlobal","Symbol","OBJECT_SIGNAL","setupSignals","buildConfig","hooks","wellknown","Array","setTransient","createSignal","obj","key","signalHooks","peekTransient","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","consumeSignal","signal","notifySignal","createMemo","object","fn","willSyncFlushWatchers","waitFor","promise"],"mappings":";;;AAIO,MAAMA,YAAY,GAAGC,cAAc,CAAC,KAAK,EAAEC,MAAM,CAAC,KAAK,CAAC;AACxD,MAAMC,aAAa,GAAGF,cAAc,CAAC,KAAK,EAAEC,MAAM,CAAC,KAAK,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAAIC,WAAsD,EAAE;AACtF;AACA;AACA;AACA;EACA,MAAMC,KAAK,GAAGD,WAAW,CAAC;AACxBE,IAAAA,SAAS,EAAE;AACTC,MAAAA,KAAK,EAAER;AACT;AACF,GAAC,CAAC;AACFS,EAAAA,YAAY,CAAC,aAAa,EAAEH,KAAK,CAAC;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASI,YAAYA,CAACC,GAAW,EAAEC,GAAoB,EAAa;AACzE,EAAA,MAAMC,WAA+B,GAAGC,aAAa,CA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IC,MAAc,EAAEd,GAAoB,EAAEe,EAAW,EAAW;AACxF,EAAA,MAAMd,WAA+B,GAAGC,aAAa,CAAC,aAAa,CAAC;EACpEC,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAA,GAAA,CAAAC,IAAA,IAAA;AAAA,IAAA,IAAA,CAAAA,IAAA,EAAA;MAAA,MAAAC,IAAAA,KAAA,CAAO,CAA6B,2BAAA,CAAA,CAAA;AAAA;AAAA,GAAA,EAAER,WAAW,CAAA,GAAA,EAAA;EACjD,OAAOA,WAAW,CAACY,UAAU,CAACC,MAAM,EAAEd,GAAG,EAAEe,EAAE,CAAC;AAChD;AAEO,SAASC,qBAAqBA,GAAY;AAC/C,EAAA,MAAMf,WAA+B,GAAGC,aAAa,CAAC,aAAa,CAAC;EACpEC,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAA,GAAA,CAAAC,IAAA,IAAA;AAAA,IAAA,IAAA,CAAAA,IAAA,EAAA;MAAA,MAAAC,IAAAA,KAAA,CAAO,CAA6B,2BAAA,CAAA,CAAA;AAAA;AAAA,GAAA,EAAER,WAAW,CAAA,GAAA,EAAA;AACjD,EAAA,OAAOA,WAAW,CAACe,qBAAqB,EAAE;AAC5C;AAEO,SAASC,OAAOA,CAAIC,OAAmB,EAAc;AAC1D,EAAA,MAAMjB,WAA+B,GAAGC,aAAa,CAAC,aAAa,CAAC;EAEpE,IAAID,WAAW,EAAEgB,OAAO,EAAE;AACxB,IAAA,OAAOhB,WAAW,CAACgB,OAAO,CAACC,OAAO,CAAC;AACrC;AACA,EAAA,OAAOA,OAAO;AAChB;;;;"}
package/dist/configure.js CHANGED
@@ -1 +1 @@
1
- export { s as setupSignals } from "./configure-Bz49BEZQ.js";
1
+ export { s as setupSignals } from "./configure-BgaZESRo.js";
@@ -1,5 +1,5 @@
1
- import { STRUCTURED, IS_FUTURE, SkipCache } from "./types/request.js";
2
- import { getOrSetGlobal, getOrSetUniversal } from "./types/-private.js";
1
+ import { STRUCTURED, IS_FUTURE, SkipCache } from './types/request.js';
2
+ import { getOrSetGlobal, getOrSetUniversal } from './types/-private.js';
3
3
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
4
  const BODY_TYPES = {
5
5
  type: 'string',
@@ -1 +1 @@
1
- {"version":3,"file":"context-DE5sFezZ.js","sources":["../src/request/-private/debug.ts","../src/request/-private/promise-cache.ts","../src/request/-private/utils.ts","../src/request/-private/future.ts","../src/request/-private/context.ts"],"sourcesContent":["import { DEBUG } from '@warp-drive/core/build-config/env';\n\nimport { getOrSetGlobal } from '../../types/-private';\nimport type { ImmutableHeaders, RequestInfo } from '../../types/request';\nimport { Context, upgradeHeaders } from './context';\n\nconst BODY_TYPES = {\n type: 'string',\n klass: ['Blob', 'ArrayBuffer', 'TypedArray', 'DataView', 'FormData', 'URLSearchParams', 'ReadableStream'],\n};\nconst ValidKeys = new Map<string, string | string[] | typeof BODY_TYPES>([\n ['duplex', ['half']],\n ['records', 'array'],\n ['data', 'json'],\n ['body', BODY_TYPES],\n ['disableTestWaiter', 'boolean'],\n ['options', 'object'],\n ['cacheOptions', 'object'],\n ['op', 'string'],\n ['store', 'object'],\n ['url', 'string'],\n ['cache', ['default', 'force-cache', 'no-cache', 'no-store', 'only-if-cached', 'reload']],\n ['credentials', ['include', 'omit', 'same-origin']],\n [\n 'destination',\n [\n '',\n 'object',\n 'audio',\n 'audioworklet',\n 'document',\n 'embed',\n 'font',\n 'frame',\n 'iframe',\n 'image',\n 'manifest',\n 'paintworklet',\n 'report',\n 'script',\n 'sharedworker',\n 'style',\n 'track',\n 'video',\n 'worker',\n 'xslt',\n ],\n ],\n ['headers', 'headers'],\n ['integrity', 'string'],\n ['keepalive', 'boolean'],\n ['method', ['QUERY', 'GET', 'PUT', 'PATCH', 'DELETE', 'POST', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE']],\n ['mode', ['same-origin', 'cors', 'navigate', 'no-cors']],\n ['redirect', ['error', 'follow', 'manual']],\n ['referrer', 'string'],\n ['signal', 'AbortSignal'],\n ['controller', 'AbortController'],\n [\n 'referrerPolicy',\n [\n '',\n 'same-origin',\n 'no-referrer',\n 'no-referrer-when-downgrade',\n 'origin',\n 'origin-when-cross-origin',\n 'strict-origin',\n 'strict-origin-when-cross-origin',\n 'unsafe-url',\n ],\n ],\n]);\n\nconst IS_FROZEN = getOrSetGlobal('IS_FROZEN', Symbol('FROZEN'));\nconst IS_COLLECTION = getOrSetGlobal('IS_COLLECTION', Symbol.for('Collection'));\n\nfunction freezeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders {\n headers.delete =\n headers.set =\n headers.append =\n () => {\n throw new Error(`Cannot Mutate Immutatable Headers, use headers.clone to get a copy`);\n };\n upgradeHeaders(headers);\n return headers as ImmutableHeaders;\n}\n\nexport function deepFreeze<T = unknown>(value: T): T {\n if (value && (value as { [IS_FROZEN]?: true })[IS_FROZEN]) {\n return value;\n }\n const _type = typeof value;\n switch (_type) {\n case 'boolean':\n case 'string':\n case 'number':\n case 'symbol':\n case 'undefined':\n case 'bigint':\n return value;\n case 'function':\n throw new Error(`Cannot deep-freeze a function`);\n case 'object': {\n const _niceType = niceTypeOf(value);\n switch (_niceType) {\n case 'array': {\n if ((value as unknown[] & { [IS_COLLECTION]?: true })[IS_COLLECTION]) {\n return value;\n }\n const arr = (value as unknown[]).map(deepFreeze);\n arr[IS_FROZEN as unknown as number] = true;\n return Object.freeze(arr) as T;\n }\n case 'null':\n return value;\n case 'object':\n Object.keys(value as Record<string, unknown>).forEach((key) => {\n try {\n (value as Record<string, unknown>)[key] = deepFreeze((value as Record<string, unknown>)[key]) as object;\n } catch {\n // continue\n }\n });\n (value as Record<string | symbol, unknown>)[IS_FROZEN] = true;\n return Object.freeze(value);\n case 'headers':\n return freezeHeaders(value as Headers) as T;\n case 'Collection':\n case 'Store':\n case 'AbortSignal':\n return value;\n case 'date':\n case 'map':\n case 'set':\n case 'error':\n case 'stream':\n default:\n // console.log(`Cannot deep-freeze ${_niceType}`);\n return value;\n }\n }\n }\n}\n\nfunction isMaybeContext(request: unknown) {\n if (request && typeof request === 'object') {\n const keys = Object.keys(request);\n if (keys.length === 1 && keys[0] === 'request') {\n return true;\n }\n }\n return false;\n}\n\nfunction niceTypeOf(v: unknown) {\n if (v === null) {\n return 'null';\n }\n if (typeof v === 'string') {\n return v ? 'non-empty-string' : 'empty-string';\n }\n if (!v) {\n return typeof v;\n }\n if (Array.isArray(v)) {\n return 'array';\n }\n if (v instanceof Date) {\n return 'date';\n }\n if (v instanceof Map) {\n return 'map';\n }\n if (v instanceof Set) {\n return 'set';\n }\n if (v instanceof Error) {\n return 'error';\n }\n if (v instanceof ReadableStream || v instanceof WritableStream || v instanceof TransformStream) {\n return 'stream';\n }\n if (v instanceof Headers) {\n return 'headers';\n }\n if (typeof v === 'object' && v.constructor && v.constructor.name !== 'Object') {\n return v.constructor.name;\n }\n return typeof v;\n}\n\nfunction validateKey(key: string, value: unknown, errors: string[]) {\n const schema = ValidKeys.get(key);\n if (!schema && !IgnoredKeys.has(key)) {\n errors.push(`InvalidKey: '${key}'`);\n return;\n }\n if (schema) {\n if (schema === BODY_TYPES) {\n if (typeof value === 'string' || value instanceof ReadableStream) {\n return;\n }\n const type = niceTypeOf(value);\n if (schema.klass.includes(type)) {\n return;\n }\n errors.push(\n `InvalidValue: key 'body' should be a string or one of '${schema.klass.join(\"', '\")}', received ${\n '<a value of type ' + niceTypeOf(value) + '>'\n }`\n );\n return;\n }\n if (Array.isArray(schema)) {\n if (!schema.includes(value as string)) {\n errors.push(\n `InvalidValue: key ${key} should be one of '${schema.join(\"', '\")}', received ${\n typeof value === 'string' ? value : '<a value of type ' + niceTypeOf(value) + '>'\n }`\n );\n }\n return;\n } else if (schema === 'json') {\n try {\n JSON.stringify(value);\n } catch (e) {\n errors.push(\n `InvalidValue: key ${key} should be a JSON serializable value, but failed to serialize with Error - ${\n (e as Error).message\n }`\n );\n }\n return;\n } else if (schema === 'headers') {\n if (!(value instanceof Headers)) {\n errors.push(`InvalidValue: key ${key} should be an instance of Headers, received ${niceTypeOf(value)}`);\n }\n return;\n } else if (schema === 'record') {\n const _type = typeof value;\n // record must extend plain object or Object.create(null)\n if (!value || _type !== 'object' || (value.constructor && value.constructor !== Object)) {\n errors.push(\n `InvalidValue: key ${key} should be a dictionary of string keys to string values, received ${niceTypeOf(\n value\n )}`\n );\n return;\n }\n const keys = Object.keys(value);\n keys.forEach((k) => {\n const v: unknown = (value as Record<string, unknown>)[k];\n if (typeof k !== 'string') {\n errors.push(`\\tThe key ${String(k)} on ${key} should be a string key`);\n } else if (typeof v !== 'string') {\n errors.push(`\\tThe value of ${key}.${k} should be a string not ${niceTypeOf(v)}`);\n }\n });\n return;\n } else if (schema === 'string') {\n if (typeof value !== 'string' || value.length === 0) {\n errors.push(\n `InvalidValue: key ${key} should be a non-empty string, received ${\n typeof value === 'string' ? \"''\" : typeof value\n }`\n );\n }\n return;\n } else if (schema === 'object') {\n if (!value || Array.isArray(value) || typeof value !== 'object') {\n errors.push(`InvalidValue: key ${key} should be an object`);\n }\n return;\n } else if (schema === 'boolean') {\n if (typeof value !== 'boolean') {\n errors.push(`InvalidValue: key ${key} should be a boolean, received ${typeof value}`);\n }\n return;\n } else if (schema === 'array') {\n if (!Array.isArray(value)) {\n errors.push(`InvalidValue: key ${key} should be an array, received ${typeof value}`);\n }\n return;\n }\n }\n}\n\nconst IgnoredKeys = new Set<string>([]);\n\nexport function assertValidRequest(\n request: RequestInfo | Context,\n isTopLevel: boolean\n): asserts request is RequestInfo {\n if (DEBUG) {\n // handle basic shape\n if (!request) {\n throw new Error(\n `Expected ${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>) to be called with a request, but none was provided.`\n );\n }\n if (Array.isArray(request) || typeof request !== 'object') {\n throw new Error(\n `The \\`request\\` passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` should be an object, received \\`${niceTypeOf(request)}\\``\n );\n }\n if (Object.keys(request).length === 0) {\n throw new Error(\n `The \\`request\\` passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` was empty (\\`{}\\`). Requests need at least one valid key.`\n );\n }\n\n // handle accidentally passing context entirely\n if (request instanceof Context) {\n throw new Error(\n `Expected a request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` but received the previous handler's context instead`\n );\n }\n // handle Object.assign({}, context);\n if (isMaybeContext(request)) {\n throw new Error(\n `Expected a request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` but received an object with a request key instead.`\n );\n }\n\n // handle schema\n const keys = Object.keys(request) as Array<keyof RequestInfo>;\n const validationErrors: string[] = [];\n const isLegacyRequest = Boolean('op' in request && !request.url);\n keys.forEach((key) => {\n if (isLegacyRequest && key === 'data') {\n return;\n }\n validateKey(key, request[key], validationErrors);\n });\n if (validationErrors.length) {\n const error: Error & { errors: string[] } = new Error(\n `Invalid Request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\`.\\n\\nThe following issues were found:\\n\\n\\t${validationErrors.join('\\n\\t')}`\n ) as Error & { errors: string[] };\n error.errors = validationErrors;\n throw error;\n }\n }\n}\n","import { getOrSetUniversal } from '../../types/-private';\n\nexport type CacheResult<T = unknown, E = unknown> = { isError: true; result: E } | { isError: false; result: T };\n\nexport type Awaitable<T = unknown, E = unknown> = {\n then: (onFulfilled: (value: T) => unknown, onRejected: (reason: E) => unknown) => unknown;\n catch: (onRejected: (reason: E) => unknown) => unknown;\n finally: (onFinally: () => unknown) => unknown;\n};\n\nexport const PromiseCache = getOrSetUniversal('PromiseCache', new WeakMap<Awaitable, CacheResult>());\nexport const RequestMap = getOrSetUniversal('RequestMap', new Map<number, CacheResult>());\n\nexport function setRequestResult(requestId: number, result: CacheResult) {\n RequestMap.set(requestId, result);\n}\nexport function clearRequestResult(requestId: number) {\n RequestMap.delete(requestId);\n}\nexport function getRequestResult(requestId: number): CacheResult | undefined {\n return RequestMap.get(requestId);\n}\n\nexport function setPromiseResult(promise: Promise<unknown> | Awaitable, result: CacheResult) {\n PromiseCache.set(promise, result);\n}\n\nexport function getPromiseResult<T, E>(promise: Promise<T> | Awaitable<T, E>): CacheResult<T, E> | undefined {\n return PromiseCache.get(promise) as CacheResult<T, E> | undefined;\n}\n","import { DEBUG } from '@warp-drive/core/build-config/env';\n\nimport { getOrSetGlobal } from '../../types/-private';\nimport type {\n RequestInfo,\n StructuredDataDocument,\n StructuredDocument,\n StructuredErrorDocument,\n} from '../../types/request';\nimport { STRUCTURED } from '../../types/request';\nimport { Context, ContextOwner } from './context';\nimport { assertValidRequest } from './debug';\nimport { createFuture, isFuture } from './future';\nimport { setRequestResult } from './promise-cache';\nimport type { DeferredFuture, Future, GodContext, Handler } from './types';\n\nexport const IS_CACHE_HANDLER = getOrSetGlobal('IS_CACHE_HANDLER', Symbol('IS_CACHE_HANDLER'));\nexport function curryFuture<T>(owner: ContextOwner, inbound: Future<T>, outbound: DeferredFuture<T>): Future<T> {\n owner.setStream(inbound.getStream());\n\n inbound.then(\n (doc: StructuredDataDocument<T>) => {\n const document = {\n [STRUCTURED]: true as const,\n request: owner.request,\n response: doc.response,\n content: doc.content,\n };\n outbound.resolve(document);\n },\n (error: Error & StructuredErrorDocument) => {\n if (isDoc(error)) {\n owner.setStream(owner.god.stream);\n }\n if (!error || !(error instanceof Error)) {\n try {\n throw new Error(error ? error : `Request Rejected with an Unknown Error`);\n } catch (e: unknown) {\n if (error && typeof error === 'object') {\n Object.assign(e as Error, error);\n (e as Error & StructuredErrorDocument).message =\n (error as Error).message || `Request Rejected with an Unknown Error`;\n }\n error = e as Error & StructuredErrorDocument;\n }\n }\n\n error[STRUCTURED] = true;\n error.request = owner.request;\n error.response = owner.getResponse();\n error.error = error.error || error.message;\n\n outbound.reject(error);\n }\n );\n return outbound.promise;\n}\n\nfunction isDoc<T>(doc: T | StructuredDataDocument<T>): doc is StructuredDataDocument<T> {\n return doc && (doc as StructuredDataDocument<T>)[STRUCTURED] === true;\n}\n\nfunction ensureDoc<T>(owner: ContextOwner, content: T | Error, isError: boolean): StructuredDocument<T> {\n if (isDoc(content)) {\n return content as StructuredDocument<T>;\n }\n\n if (isError) {\n return {\n [STRUCTURED]: true,\n request: owner.request,\n response: owner.getResponse(),\n error: content as Error,\n } as StructuredErrorDocument<T>;\n }\n\n return {\n [STRUCTURED]: true,\n request: owner.request,\n response: owner.getResponse(),\n content: content as T,\n };\n}\n\nexport interface HttpErrorProps extends DOMException {\n code: number;\n name: string;\n status: number;\n statusText: string;\n isRequestError: boolean;\n}\n\nexport function enhanceReason(reason?: string): DOMException {\n return new DOMException(reason || 'The user aborted a request.', 'AbortError');\n}\n\nexport function handleOutcome<T>(\n owner: ContextOwner,\n inbound: Promise<T | StructuredDataDocument<T>>,\n outbound: DeferredFuture<T>\n): Future<T> {\n inbound.then(\n (content: T | StructuredDataDocument<T>) => {\n if (owner.controller.signal.aborted) {\n // the next function did not respect the signal, we handle it here\n outbound.reject(enhanceReason(owner.controller.signal.reason as string));\n return;\n }\n if (isDoc(content)) {\n owner.setStream(owner.god.stream);\n content = content.content;\n }\n const document = {\n [STRUCTURED]: true as const,\n request: owner.request,\n response: owner.getResponse(),\n content,\n };\n outbound.resolve(document);\n },\n (error: Error & StructuredErrorDocument) => {\n if (isDoc(error)) {\n owner.setStream(owner.god.stream);\n }\n if (!error || !(error instanceof Error)) {\n try {\n throw new Error(error ? error : `Request Rejected with an Unknown Error`);\n } catch (e: unknown) {\n if (error && typeof error === 'object') {\n Object.assign(e as Error, error);\n (e as Error & StructuredErrorDocument).message =\n (error as Error).message || `Request Rejected with an Unknown Error`;\n }\n error = e as Error & StructuredErrorDocument;\n }\n }\n\n error[STRUCTURED] = true;\n error.request = owner.request;\n error.response = owner.getResponse();\n error.error = error.error || error.message;\n outbound.reject(error);\n }\n );\n return outbound.promise;\n}\n\nfunction isCacheHandler(handler: Handler & { [IS_CACHE_HANDLER]?: boolean }, index: number): boolean {\n return index === 0 && Boolean(handler[IS_CACHE_HANDLER]);\n}\n\nexport function executeNextHandler<T>(\n wares: Readonly<Handler[]>,\n request: RequestInfo,\n i: number,\n god: GodContext\n): Future<T> {\n if (DEBUG) {\n if (i === wares.length) {\n throw new Error(`No handler was able to handle this request.`);\n }\n assertValidRequest(request, false);\n }\n const owner = new ContextOwner(request, god, i === 0);\n\n function next(r: RequestInfo): Future<T> {\n owner.nextCalled++;\n return executeNextHandler(wares, r, i + 1, god);\n }\n\n const _isCacheHandler = isCacheHandler(wares[i], i);\n const context = new Context(owner, _isCacheHandler);\n let outcome: Promise<T | StructuredDataDocument<T>> | Future<T>;\n try {\n outcome = wares[i].request<T>(context, next);\n if (_isCacheHandler) {\n context._finalize();\n }\n if (!!outcome && _isCacheHandler) {\n if (!(outcome instanceof Promise)) {\n setRequestResult(owner.requestId, { isError: false, result: ensureDoc(owner, outcome, false) });\n outcome = Promise.resolve(outcome);\n }\n } else if (DEBUG) {\n if (!outcome || (!(outcome instanceof Promise) && !(typeof outcome === 'object' && 'then' in outcome))) {\n // eslint-disable-next-line no-console\n console.log({ request, handler: wares[i], outcome });\n if (outcome === undefined) {\n throw new Error(`Expected handler.request to return a promise, instead received undefined.`);\n }\n throw new Error(`Expected handler.request to return a promise, instead received a synchronous value.`);\n }\n }\n } catch (e) {\n if (_isCacheHandler) {\n setRequestResult(owner.requestId, { isError: true, result: ensureDoc(owner, e, true) });\n }\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n outcome = Promise.reject<StructuredDataDocument<T>>(e);\n }\n const future = createFuture<T>(owner);\n\n if (isFuture<T>(outcome)) {\n return curryFuture(owner, outcome, future);\n }\n\n return handleOutcome(owner, outcome, future);\n}\n","import { IS_FUTURE, type StructuredDocument } from '../../types/request';\nimport type { ContextOwner } from './context';\nimport type { Deferred, DeferredFuture, Future } from './types';\nimport { enhanceReason } from './utils';\n\nexport function isFuture<T>(maybe: unknown): maybe is Future<T> {\n return Boolean(maybe && maybe instanceof Promise && (maybe as Future<T>)[IS_FUTURE] === true);\n}\n\nexport function createDeferred<T>(): Deferred<T> {\n let resolve!: (v: T) => void;\n let reject!: (v: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { resolve, reject, promise };\n}\n\nexport function upgradePromise<T>(promise: Promise<StructuredDocument<T>>, future: Future<T>): Future<T> {\n (promise as Future<T>)[IS_FUTURE] = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).getStream = future.getStream;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).abort = future.abort;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).onFinalize = future.onFinalize;\n (promise as Future<T>).id = future.id;\n (promise as Future<T>).lid = future.lid;\n\n return promise as Future<T>;\n}\n\nexport function createFuture<T>(owner: ContextOwner): DeferredFuture<T> {\n const deferred = createDeferred<T>() as unknown as DeferredFuture<T>;\n let { promise } = deferred;\n let cbs: Array<() => void> | undefined;\n promise = promise.finally(() => {\n owner.resolveStream();\n if (cbs) {\n cbs.forEach((cb) => cb());\n }\n }) as Future<T>;\n promise.onFinalize = (fn: () => void) => {\n cbs = cbs || [];\n cbs.push(fn);\n };\n promise[IS_FUTURE] = true;\n promise.getStream = () => {\n return owner.getStream();\n };\n promise.abort = (reason?: string) => {\n owner.abort(enhanceReason(reason));\n };\n promise.id = owner.requestId;\n promise.lid = owner.god.identifier;\n\n deferred.promise = promise;\n return deferred;\n}\n","import { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport type { StableDocumentIdentifier } from '../../types/identifier';\nimport type { ImmutableHeaders, ImmutableRequestInfo, RequestInfo, ResponseInfo } from '../../types/request';\nimport { SkipCache } from '../../types/request';\nimport { deepFreeze } from './debug';\nimport { createDeferred } from './future';\nimport type { DeferredStream, GodContext } from './types';\n\nexport function upgradeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders {\n (headers as ImmutableHeaders).clone = () => {\n return new Headers(headers);\n };\n (headers as ImmutableHeaders).toJSON = () => {\n return Array.from(headers as unknown as Iterable<[string, string]>);\n };\n return headers as ImmutableHeaders;\n}\n\nexport function cloneResponseProperties(response: Response): ResponseInfo {\n const { headers, ok, redirected, status, statusText, type, url } = response;\n upgradeHeaders(headers);\n return {\n headers: headers as ImmutableHeaders,\n ok,\n redirected,\n status,\n statusText,\n type,\n url,\n };\n}\n\nexport class ContextOwner {\n hasSetStream = false;\n hasSetResponse = false;\n hasSubscribers = false;\n stream: DeferredStream = createDeferred<ReadableStream | null>();\n response: ResponseInfo | null = null;\n declare request: ImmutableRequestInfo;\n declare enhancedRequest: ImmutableRequestInfo;\n nextCalled = 0;\n declare god: GodContext;\n declare controller: AbortController;\n declare requestId: number;\n declare isRoot: boolean;\n\n constructor(request: RequestInfo, god: GodContext, isRoot = false) {\n this.isRoot = isRoot;\n this.requestId = god.id;\n this.controller = request.controller || god.controller;\n this.stream.promise.sizeHint = 0;\n\n if (request.controller) {\n if (request.controller !== god.controller) {\n god.controller.signal.addEventListener('abort', () => {\n this.controller.abort(god.controller.signal.reason);\n });\n }\n delete request.controller;\n }\n let enhancedRequest: ImmutableRequestInfo = Object.assign(\n { signal: this.controller.signal },\n request\n ) as ImmutableRequestInfo;\n if (DEBUG) {\n if (!request?.cacheOptions?.[SkipCache]) {\n request = deepFreeze(request) as ImmutableRequestInfo;\n enhancedRequest = deepFreeze(enhancedRequest);\n }\n } else {\n if (request.headers) {\n upgradeHeaders(request.headers);\n }\n }\n this.enhancedRequest = enhancedRequest;\n this.request = request as ImmutableRequestInfo;\n this.god = god;\n this.stream.promise = this.stream.promise.then((stream: ReadableStream | null) => {\n if (this.god.stream === stream && this.hasSubscribers) {\n this.god.stream = null;\n }\n return stream;\n });\n }\n\n get hasRequestedStream(): boolean {\n return this.god.hasRequestedStream;\n }\n\n getResponse(): ResponseInfo | null {\n if (this.hasSetResponse) {\n return this.response;\n }\n if (this.nextCalled === 1) {\n return this.god.response;\n }\n return null;\n }\n getStream(): Promise<ReadableStream | null> {\n if (this.isRoot) {\n this.god.hasRequestedStream = true;\n }\n if (!this.hasSetResponse) {\n const hint = this.god.response?.headers?.get('content-length');\n this.stream.promise.sizeHint = hint ? parseInt(hint, 10) : 0;\n }\n this.hasSubscribers = true;\n return this.stream.promise;\n }\n abort(reason: DOMException) {\n this.controller.abort(reason);\n }\n\n setStream(stream: ReadableStream | Promise<ReadableStream | null> | null) {\n if (!this.hasSetStream) {\n this.hasSetStream = true;\n\n if (!(stream instanceof Promise)) {\n this.god.stream = stream;\n }\n // @ts-expect-error\n this.stream.resolve(stream);\n }\n }\n\n resolveStream() {\n this.setStream(this.nextCalled === 1 ? this.god.stream : null);\n }\n\n setResponse(response: ResponseInfo | Response | null) {\n if (this.hasSetResponse) {\n if (DEBUG) {\n throw new Error(`Cannot setResponse when a response has already been set`);\n }\n return;\n }\n this.hasSetResponse = true;\n if (response instanceof Response) {\n // TODO potentially avoid cloning in prod\n let responseData = cloneResponseProperties(response);\n\n if (DEBUG) {\n responseData = deepFreeze(responseData);\n }\n this.response = responseData;\n this.god.response = responseData;\n const sizeHint = response.headers?.get('content-length');\n this.stream.promise.sizeHint = sizeHint ? parseInt(sizeHint, 10) : 0;\n } else {\n this.response = response;\n this.god.response = response;\n }\n }\n}\n\nexport class Context {\n #owner: ContextOwner;\n declare request: ImmutableRequestInfo;\n declare id: number;\n declare private _isCacheHandler: boolean;\n declare private _finalized: boolean;\n\n constructor(owner: ContextOwner, isCacheHandler: boolean) {\n this.id = owner.requestId;\n this.#owner = owner;\n this.request = owner.enhancedRequest;\n this._isCacheHandler = isCacheHandler;\n this._finalized = false;\n }\n setStream(stream: ReadableStream | Promise<ReadableStream | null>) {\n this.#owner.setStream(stream);\n }\n setResponse(response: ResponseInfo | Response | null) {\n this.#owner.setResponse(response);\n }\n\n setIdentifier(identifier: StableDocumentIdentifier) {\n assert(\n `setIdentifier may only be used synchronously from a CacheHandler`,\n identifier && this._isCacheHandler && !this._finalized\n );\n this.#owner.god.identifier = identifier;\n }\n\n get hasRequestedStream() {\n return this.#owner.hasRequestedStream;\n }\n\n _finalize() {\n this._finalized = true;\n }\n}\nexport type HandlerRequestContext = Context;\n"],"names":["BODY_TYPES","type","klass","ValidKeys","Map","IS_FROZEN","getOrSetGlobal","Symbol","IS_COLLECTION","for","freezeHeaders","headers","delete","set","append","Error","upgradeHeaders","deepFreeze","value","_type","_niceType","niceTypeOf","arr","map","Object","freeze","keys","forEach","key","isMaybeContext","request","length","v","Array","isArray","Date","Set","ReadableStream","WritableStream","TransformStream","Headers","constructor","name","validateKey","errors","schema","get","IgnoredKeys","has","push","includes","join","JSON","stringify","e","message","k","String","assertValidRequest","isTopLevel","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","Context","validationErrors","isLegacyRequest","Boolean","url","error","PromiseCache","getOrSetUniversal","WeakMap","RequestMap","setRequestResult","requestId","result","clearRequestResult","getRequestResult","setPromiseResult","promise","getPromiseResult","IS_CACHE_HANDLER","curryFuture","owner","inbound","outbound","setStream","getStream","then","doc","document","STRUCTURED","response","content","resolve","isDoc","god","stream","assign","getResponse","reject","ensureDoc","isError","enhanceReason","reason","DOMException","handleOutcome","controller","signal","aborted","isCacheHandler","handler","index","executeNextHandler","wares","i","ContextOwner","next","r","nextCalled","_isCacheHandler","context","outcome","_finalize","Promise","console","log","undefined","future","createFuture","isFuture","maybe","IS_FUTURE","createDeferred","res","rej","upgradePromise","abort","onFinalize","id","lid","deferred","cbs","finally","resolveStream","cb","fn","identifier","clone","toJSON","from","cloneResponseProperties","ok","redirected","status","statusText","hasSetStream","hasSetResponse","hasSubscribers","isRoot","sizeHint","addEventListener","enhancedRequest","cacheOptions","SkipCache","hasRequestedStream","hint","parseInt","setResponse","Response","responseData","_finalized","setIdentifier","test"],"mappings":";;;;AAMA,MAAMA,UAAU,GAAG;AACjBC,EAAAA,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A,CAAA,GAAA,CAAA+G,IAAA,IAAA;AAAA,MAAA,IAAA,CAAAA,IAAA,EAAA;QAAA,MAAAhK,IAAAA,KAAA,CACE,CAAkE,gEAAA,CAAA,CAAA;AAAA;KAClEsI,EAAAA,UAAU,IAAI,IAAI,CAAC3B,eAAe,IAAI,CAAC,IAAI,CAACmD,UAAU,CAAA,GAAA,EAAA;IAExD,IAAI,CAAC,MAAM,CAAC3E,GAAG,CAACmD,UAAU,GAAGA,UAAU;AACzC;EAEA,IAAIkB,kBAAkBA,GAAG;AACvB,IAAA,OAAO,IAAI,CAAC,MAAM,CAACA,kBAAkB;AACvC;AAEA1C,EAAAA,SAASA,GAAG;IACV,IAAI,CAACgD,UAAU,GAAG,IAAI;AACxB;AACF;;;;"}
1
+ {"version":3,"file":"context-COmAnXUQ.js","sources":["../src/request/-private/debug.ts","../src/request/-private/promise-cache.ts","../src/request/-private/utils.ts","../src/request/-private/future.ts","../src/request/-private/context.ts"],"sourcesContent":["import { DEBUG } from '@warp-drive/core/build-config/env';\n\nimport { getOrSetGlobal } from '../../types/-private';\nimport type { ImmutableHeaders, RequestInfo } from '../../types/request';\nimport { Context, upgradeHeaders } from './context';\n\nconst BODY_TYPES = {\n type: 'string',\n klass: ['Blob', 'ArrayBuffer', 'TypedArray', 'DataView', 'FormData', 'URLSearchParams', 'ReadableStream'],\n};\nconst ValidKeys = new Map<string, string | string[] | typeof BODY_TYPES>([\n ['duplex', ['half']],\n ['records', 'array'],\n ['data', 'json'],\n ['body', BODY_TYPES],\n ['disableTestWaiter', 'boolean'],\n ['options', 'object'],\n ['cacheOptions', 'object'],\n ['op', 'string'],\n ['store', 'object'],\n ['url', 'string'],\n ['cache', ['default', 'force-cache', 'no-cache', 'no-store', 'only-if-cached', 'reload']],\n ['credentials', ['include', 'omit', 'same-origin']],\n [\n 'destination',\n [\n '',\n 'object',\n 'audio',\n 'audioworklet',\n 'document',\n 'embed',\n 'font',\n 'frame',\n 'iframe',\n 'image',\n 'manifest',\n 'paintworklet',\n 'report',\n 'script',\n 'sharedworker',\n 'style',\n 'track',\n 'video',\n 'worker',\n 'xslt',\n ],\n ],\n ['headers', 'headers'],\n ['integrity', 'string'],\n ['keepalive', 'boolean'],\n ['method', ['QUERY', 'GET', 'PUT', 'PATCH', 'DELETE', 'POST', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE']],\n ['mode', ['same-origin', 'cors', 'navigate', 'no-cors']],\n ['redirect', ['error', 'follow', 'manual']],\n ['referrer', 'string'],\n ['signal', 'AbortSignal'],\n ['controller', 'AbortController'],\n [\n 'referrerPolicy',\n [\n '',\n 'same-origin',\n 'no-referrer',\n 'no-referrer-when-downgrade',\n 'origin',\n 'origin-when-cross-origin',\n 'strict-origin',\n 'strict-origin-when-cross-origin',\n 'unsafe-url',\n ],\n ],\n]);\n\nconst IS_FROZEN = getOrSetGlobal('IS_FROZEN', Symbol('FROZEN'));\nconst IS_COLLECTION = getOrSetGlobal('IS_COLLECTION', Symbol.for('Collection'));\n\nfunction freezeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders {\n headers.delete =\n headers.set =\n headers.append =\n () => {\n throw new Error(`Cannot Mutate Immutatable Headers, use headers.clone to get a copy`);\n };\n upgradeHeaders(headers);\n return headers as ImmutableHeaders;\n}\n\nexport function deepFreeze<T = unknown>(value: T): T {\n if (value && (value as { [IS_FROZEN]?: true })[IS_FROZEN]) {\n return value;\n }\n const _type = typeof value;\n switch (_type) {\n case 'boolean':\n case 'string':\n case 'number':\n case 'symbol':\n case 'undefined':\n case 'bigint':\n return value;\n case 'function':\n throw new Error(`Cannot deep-freeze a function`);\n case 'object': {\n const _niceType = niceTypeOf(value);\n switch (_niceType) {\n case 'array': {\n if ((value as unknown[] & { [IS_COLLECTION]?: true })[IS_COLLECTION]) {\n return value;\n }\n const arr = (value as unknown[]).map(deepFreeze);\n arr[IS_FROZEN as unknown as number] = true;\n return Object.freeze(arr) as T;\n }\n case 'null':\n return value;\n case 'object':\n Object.keys(value as Record<string, unknown>).forEach((key) => {\n try {\n (value as Record<string, unknown>)[key] = deepFreeze((value as Record<string, unknown>)[key]) as object;\n } catch {\n // continue\n }\n });\n (value as Record<string | symbol, unknown>)[IS_FROZEN] = true;\n return Object.freeze(value);\n case 'headers':\n return freezeHeaders(value as Headers) as T;\n case 'Collection':\n case 'Store':\n case 'AbortSignal':\n return value;\n case 'date':\n case 'map':\n case 'set':\n case 'error':\n case 'stream':\n default:\n // console.log(`Cannot deep-freeze ${_niceType}`);\n return value;\n }\n }\n }\n}\n\nfunction isMaybeContext(request: unknown) {\n if (request && typeof request === 'object') {\n const keys = Object.keys(request);\n if (keys.length === 1 && keys[0] === 'request') {\n return true;\n }\n }\n return false;\n}\n\nfunction niceTypeOf(v: unknown) {\n if (v === null) {\n return 'null';\n }\n if (typeof v === 'string') {\n return v ? 'non-empty-string' : 'empty-string';\n }\n if (!v) {\n return typeof v;\n }\n if (Array.isArray(v)) {\n return 'array';\n }\n if (v instanceof Date) {\n return 'date';\n }\n if (v instanceof Map) {\n return 'map';\n }\n if (v instanceof Set) {\n return 'set';\n }\n if (v instanceof Error) {\n return 'error';\n }\n if (v instanceof ReadableStream || v instanceof WritableStream || v instanceof TransformStream) {\n return 'stream';\n }\n if (v instanceof Headers) {\n return 'headers';\n }\n if (typeof v === 'object' && v.constructor && v.constructor.name !== 'Object') {\n return v.constructor.name;\n }\n return typeof v;\n}\n\nfunction validateKey(key: string, value: unknown, errors: string[]) {\n const schema = ValidKeys.get(key);\n if (!schema && !IgnoredKeys.has(key)) {\n errors.push(`InvalidKey: '${key}'`);\n return;\n }\n if (schema) {\n if (schema === BODY_TYPES) {\n if (typeof value === 'string' || value instanceof ReadableStream) {\n return;\n }\n const type = niceTypeOf(value);\n if (schema.klass.includes(type)) {\n return;\n }\n errors.push(\n `InvalidValue: key 'body' should be a string or one of '${schema.klass.join(\"', '\")}', received ${\n '<a value of type ' + niceTypeOf(value) + '>'\n }`\n );\n return;\n }\n if (Array.isArray(schema)) {\n if (!schema.includes(value as string)) {\n errors.push(\n `InvalidValue: key ${key} should be one of '${schema.join(\"', '\")}', received ${\n typeof value === 'string' ? value : '<a value of type ' + niceTypeOf(value) + '>'\n }`\n );\n }\n return;\n } else if (schema === 'json') {\n try {\n JSON.stringify(value);\n } catch (e) {\n errors.push(\n `InvalidValue: key ${key} should be a JSON serializable value, but failed to serialize with Error - ${\n (e as Error).message\n }`\n );\n }\n return;\n } else if (schema === 'headers') {\n if (!(value instanceof Headers)) {\n errors.push(`InvalidValue: key ${key} should be an instance of Headers, received ${niceTypeOf(value)}`);\n }\n return;\n } else if (schema === 'record') {\n const _type = typeof value;\n // record must extend plain object or Object.create(null)\n if (!value || _type !== 'object' || (value.constructor && value.constructor !== Object)) {\n errors.push(\n `InvalidValue: key ${key} should be a dictionary of string keys to string values, received ${niceTypeOf(\n value\n )}`\n );\n return;\n }\n const keys = Object.keys(value);\n keys.forEach((k) => {\n const v: unknown = (value as Record<string, unknown>)[k];\n if (typeof k !== 'string') {\n errors.push(`\\tThe key ${String(k)} on ${key} should be a string key`);\n } else if (typeof v !== 'string') {\n errors.push(`\\tThe value of ${key}.${k} should be a string not ${niceTypeOf(v)}`);\n }\n });\n return;\n } else if (schema === 'string') {\n if (typeof value !== 'string' || value.length === 0) {\n errors.push(\n `InvalidValue: key ${key} should be a non-empty string, received ${\n typeof value === 'string' ? \"''\" : typeof value\n }`\n );\n }\n return;\n } else if (schema === 'object') {\n if (!value || Array.isArray(value) || typeof value !== 'object') {\n errors.push(`InvalidValue: key ${key} should be an object`);\n }\n return;\n } else if (schema === 'boolean') {\n if (typeof value !== 'boolean') {\n errors.push(`InvalidValue: key ${key} should be a boolean, received ${typeof value}`);\n }\n return;\n } else if (schema === 'array') {\n if (!Array.isArray(value)) {\n errors.push(`InvalidValue: key ${key} should be an array, received ${typeof value}`);\n }\n return;\n }\n }\n}\n\nconst IgnoredKeys = new Set<string>([]);\n\nexport function assertValidRequest(\n request: RequestInfo | Context,\n isTopLevel: boolean\n): asserts request is RequestInfo {\n if (DEBUG) {\n // handle basic shape\n if (!request) {\n throw new Error(\n `Expected ${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>) to be called with a request, but none was provided.`\n );\n }\n if (Array.isArray(request) || typeof request !== 'object') {\n throw new Error(\n `The \\`request\\` passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` should be an object, received \\`${niceTypeOf(request)}\\``\n );\n }\n if (Object.keys(request).length === 0) {\n throw new Error(\n `The \\`request\\` passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` was empty (\\`{}\\`). Requests need at least one valid key.`\n );\n }\n\n // handle accidentally passing context entirely\n if (request instanceof Context) {\n throw new Error(\n `Expected a request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` but received the previous handler's context instead`\n );\n }\n // handle Object.assign({}, context);\n if (isMaybeContext(request)) {\n throw new Error(\n `Expected a request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\` but received an object with a request key instead.`\n );\n }\n\n // handle schema\n const keys = Object.keys(request) as Array<keyof RequestInfo>;\n const validationErrors: string[] = [];\n const isLegacyRequest = Boolean('op' in request && !request.url);\n keys.forEach((key) => {\n if (isLegacyRequest && key === 'data') {\n return;\n }\n validateKey(key, request[key], validationErrors);\n });\n if (validationErrors.length) {\n const error: Error & { errors: string[] } = new Error(\n `Invalid Request passed to \\`${\n isTopLevel ? 'RequestManager.request' : 'next'\n }(<request>)\\`.\\n\\nThe following issues were found:\\n\\n\\t${validationErrors.join('\\n\\t')}`\n ) as Error & { errors: string[] };\n error.errors = validationErrors;\n throw error;\n }\n }\n}\n","import { getOrSetUniversal } from '../../types/-private';\n\nexport type CacheResult<T = unknown, E = unknown> = { isError: true; result: E } | { isError: false; result: T };\n\nexport type Awaitable<T = unknown, E = unknown> = {\n then: (onFulfilled: (value: T) => unknown, onRejected: (reason: E) => unknown) => unknown;\n catch: (onRejected: (reason: E) => unknown) => unknown;\n finally: (onFinally: () => unknown) => unknown;\n};\n\nexport const PromiseCache = getOrSetUniversal('PromiseCache', new WeakMap<Awaitable, CacheResult>());\nexport const RequestMap = getOrSetUniversal('RequestMap', new Map<number, CacheResult>());\n\nexport function setRequestResult(requestId: number, result: CacheResult) {\n RequestMap.set(requestId, result);\n}\nexport function clearRequestResult(requestId: number) {\n RequestMap.delete(requestId);\n}\nexport function getRequestResult(requestId: number): CacheResult | undefined {\n return RequestMap.get(requestId);\n}\n\nexport function setPromiseResult(promise: Promise<unknown> | Awaitable, result: CacheResult) {\n PromiseCache.set(promise, result);\n}\n\nexport function getPromiseResult<T, E>(promise: Promise<T> | Awaitable<T, E>): CacheResult<T, E> | undefined {\n return PromiseCache.get(promise) as CacheResult<T, E> | undefined;\n}\n","import { DEBUG } from '@warp-drive/core/build-config/env';\n\nimport { getOrSetGlobal } from '../../types/-private';\nimport type {\n RequestInfo,\n StructuredDataDocument,\n StructuredDocument,\n StructuredErrorDocument,\n} from '../../types/request';\nimport { STRUCTURED } from '../../types/request';\nimport { Context, ContextOwner } from './context';\nimport { assertValidRequest } from './debug';\nimport { createFuture, isFuture } from './future';\nimport { setRequestResult } from './promise-cache';\nimport type { DeferredFuture, Future, GodContext, Handler } from './types';\n\nexport const IS_CACHE_HANDLER = getOrSetGlobal('IS_CACHE_HANDLER', Symbol('IS_CACHE_HANDLER'));\nexport function curryFuture<T>(owner: ContextOwner, inbound: Future<T>, outbound: DeferredFuture<T>): Future<T> {\n owner.setStream(inbound.getStream());\n\n inbound.then(\n (doc: StructuredDataDocument<T>) => {\n const document = {\n [STRUCTURED]: true as const,\n request: owner.request,\n response: doc.response,\n content: doc.content,\n };\n outbound.resolve(document);\n },\n (error: Error & StructuredErrorDocument) => {\n if (isDoc(error)) {\n owner.setStream(owner.god.stream);\n }\n if (!error || !(error instanceof Error)) {\n try {\n throw new Error(error ? error : `Request Rejected with an Unknown Error`);\n } catch (e: unknown) {\n if (error && typeof error === 'object') {\n Object.assign(e as Error, error);\n (e as Error & StructuredErrorDocument).message =\n (error as Error).message || `Request Rejected with an Unknown Error`;\n }\n error = e as Error & StructuredErrorDocument;\n }\n }\n\n error[STRUCTURED] = true;\n error.request = owner.request;\n error.response = owner.getResponse();\n error.error = error.error || error.message;\n\n outbound.reject(error);\n }\n );\n return outbound.promise;\n}\n\nfunction isDoc<T>(doc: T | StructuredDataDocument<T>): doc is StructuredDataDocument<T> {\n return doc && (doc as StructuredDataDocument<T>)[STRUCTURED] === true;\n}\n\nfunction ensureDoc<T>(owner: ContextOwner, content: T | Error, isError: boolean): StructuredDocument<T> {\n if (isDoc(content)) {\n return content as StructuredDocument<T>;\n }\n\n if (isError) {\n return {\n [STRUCTURED]: true,\n request: owner.request,\n response: owner.getResponse(),\n error: content as Error,\n } as StructuredErrorDocument<T>;\n }\n\n return {\n [STRUCTURED]: true,\n request: owner.request,\n response: owner.getResponse(),\n content: content as T,\n };\n}\n\nexport interface HttpErrorProps extends DOMException {\n code: number;\n name: string;\n status: number;\n statusText: string;\n isRequestError: boolean;\n}\n\nexport function enhanceReason(reason?: string): DOMException {\n return new DOMException(reason || 'The user aborted a request.', 'AbortError');\n}\n\nexport function handleOutcome<T>(\n owner: ContextOwner,\n inbound: Promise<T | StructuredDataDocument<T>>,\n outbound: DeferredFuture<T>\n): Future<T> {\n inbound.then(\n (content: T | StructuredDataDocument<T>) => {\n if (owner.controller.signal.aborted) {\n // the next function did not respect the signal, we handle it here\n outbound.reject(enhanceReason(owner.controller.signal.reason as string));\n return;\n }\n if (isDoc(content)) {\n owner.setStream(owner.god.stream);\n content = content.content;\n }\n const document = {\n [STRUCTURED]: true as const,\n request: owner.request,\n response: owner.getResponse(),\n content,\n };\n outbound.resolve(document);\n },\n (error: Error & StructuredErrorDocument) => {\n if (isDoc(error)) {\n owner.setStream(owner.god.stream);\n }\n if (!error || !(error instanceof Error)) {\n try {\n throw new Error(error ? error : `Request Rejected with an Unknown Error`);\n } catch (e: unknown) {\n if (error && typeof error === 'object') {\n Object.assign(e as Error, error);\n (e as Error & StructuredErrorDocument).message =\n (error as Error).message || `Request Rejected with an Unknown Error`;\n }\n error = e as Error & StructuredErrorDocument;\n }\n }\n\n error[STRUCTURED] = true;\n error.request = owner.request;\n error.response = owner.getResponse();\n error.error = error.error || error.message;\n outbound.reject(error);\n }\n );\n return outbound.promise;\n}\n\nfunction isCacheHandler(handler: Handler & { [IS_CACHE_HANDLER]?: boolean }, index: number): boolean {\n return index === 0 && Boolean(handler[IS_CACHE_HANDLER]);\n}\n\nexport function executeNextHandler<T>(\n wares: Readonly<Handler[]>,\n request: RequestInfo,\n i: number,\n god: GodContext\n): Future<T> {\n if (DEBUG) {\n if (i === wares.length) {\n throw new Error(`No handler was able to handle this request.`);\n }\n assertValidRequest(request, false);\n }\n const owner = new ContextOwner(request, god, i === 0);\n\n function next(r: RequestInfo): Future<T> {\n owner.nextCalled++;\n return executeNextHandler(wares, r, i + 1, god);\n }\n\n const _isCacheHandler = isCacheHandler(wares[i], i);\n const context = new Context(owner, _isCacheHandler);\n let outcome: Promise<T | StructuredDataDocument<T>> | Future<T>;\n try {\n outcome = wares[i].request<T>(context, next);\n if (_isCacheHandler) {\n context._finalize();\n }\n if (!!outcome && _isCacheHandler) {\n if (!(outcome instanceof Promise)) {\n setRequestResult(owner.requestId, { isError: false, result: ensureDoc(owner, outcome, false) });\n outcome = Promise.resolve(outcome);\n }\n } else if (DEBUG) {\n if (!outcome || (!(outcome instanceof Promise) && !(typeof outcome === 'object' && 'then' in outcome))) {\n // eslint-disable-next-line no-console\n console.log({ request, handler: wares[i], outcome });\n if (outcome === undefined) {\n throw new Error(`Expected handler.request to return a promise, instead received undefined.`);\n }\n throw new Error(`Expected handler.request to return a promise, instead received a synchronous value.`);\n }\n }\n } catch (e) {\n if (_isCacheHandler) {\n setRequestResult(owner.requestId, { isError: true, result: ensureDoc(owner, e, true) });\n }\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n outcome = Promise.reject<StructuredDataDocument<T>>(e);\n }\n const future = createFuture<T>(owner);\n\n if (isFuture<T>(outcome)) {\n return curryFuture(owner, outcome, future);\n }\n\n return handleOutcome(owner, outcome, future);\n}\n","import { IS_FUTURE, type StructuredDocument } from '../../types/request';\nimport type { ContextOwner } from './context';\nimport type { Deferred, DeferredFuture, Future } from './types';\nimport { enhanceReason } from './utils';\n\nexport function isFuture<T>(maybe: unknown): maybe is Future<T> {\n return Boolean(maybe && maybe instanceof Promise && (maybe as Future<T>)[IS_FUTURE] === true);\n}\n\nexport function createDeferred<T>(): Deferred<T> {\n let resolve!: (v: T) => void;\n let reject!: (v: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { resolve, reject, promise };\n}\n\nexport function upgradePromise<T>(promise: Promise<StructuredDocument<T>>, future: Future<T>): Future<T> {\n (promise as Future<T>)[IS_FUTURE] = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).getStream = future.getStream;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).abort = future.abort;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n (promise as Future<T>).onFinalize = future.onFinalize;\n (promise as Future<T>).id = future.id;\n (promise as Future<T>).lid = future.lid;\n\n return promise as Future<T>;\n}\n\nexport function createFuture<T>(owner: ContextOwner): DeferredFuture<T> {\n const deferred = createDeferred<T>() as unknown as DeferredFuture<T>;\n let { promise } = deferred;\n let cbs: Array<() => void> | undefined;\n promise = promise.finally(() => {\n owner.resolveStream();\n if (cbs) {\n cbs.forEach((cb) => cb());\n }\n }) as Future<T>;\n promise.onFinalize = (fn: () => void) => {\n cbs = cbs || [];\n cbs.push(fn);\n };\n promise[IS_FUTURE] = true;\n promise.getStream = () => {\n return owner.getStream();\n };\n promise.abort = (reason?: string) => {\n owner.abort(enhanceReason(reason));\n };\n promise.id = owner.requestId;\n promise.lid = owner.god.identifier;\n\n deferred.promise = promise;\n return deferred;\n}\n","import { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport type { StableDocumentIdentifier } from '../../types/identifier';\nimport type { ImmutableHeaders, ImmutableRequestInfo, RequestInfo, ResponseInfo } from '../../types/request';\nimport { SkipCache } from '../../types/request';\nimport { deepFreeze } from './debug';\nimport { createDeferred } from './future';\nimport type { DeferredStream, GodContext } from './types';\n\nexport function upgradeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders {\n (headers as ImmutableHeaders).clone = () => {\n return new Headers(headers);\n };\n (headers as ImmutableHeaders).toJSON = () => {\n return Array.from(headers as unknown as Iterable<[string, string]>);\n };\n return headers as ImmutableHeaders;\n}\n\nexport function cloneResponseProperties(response: Response): ResponseInfo {\n const { headers, ok, redirected, status, statusText, type, url } = response;\n upgradeHeaders(headers);\n return {\n headers: headers as ImmutableHeaders,\n ok,\n redirected,\n status,\n statusText,\n type,\n url,\n };\n}\n\nexport class ContextOwner {\n hasSetStream = false;\n hasSetResponse = false;\n hasSubscribers = false;\n stream: DeferredStream = createDeferred<ReadableStream | null>();\n response: ResponseInfo | null = null;\n declare request: ImmutableRequestInfo;\n declare enhancedRequest: ImmutableRequestInfo;\n nextCalled = 0;\n declare god: GodContext;\n declare controller: AbortController;\n declare requestId: number;\n declare isRoot: boolean;\n\n constructor(request: RequestInfo, god: GodContext, isRoot = false) {\n this.isRoot = isRoot;\n this.requestId = god.id;\n this.controller = request.controller || god.controller;\n this.stream.promise.sizeHint = 0;\n\n if (request.controller) {\n if (request.controller !== god.controller) {\n god.controller.signal.addEventListener('abort', () => {\n this.controller.abort(god.controller.signal.reason);\n });\n }\n delete request.controller;\n }\n let enhancedRequest: ImmutableRequestInfo = Object.assign(\n { signal: this.controller.signal },\n request\n ) as ImmutableRequestInfo;\n if (DEBUG) {\n if (!request?.cacheOptions?.[SkipCache]) {\n request = deepFreeze(request) as ImmutableRequestInfo;\n enhancedRequest = deepFreeze(enhancedRequest);\n }\n } else {\n if (request.headers) {\n upgradeHeaders(request.headers);\n }\n }\n this.enhancedRequest = enhancedRequest;\n this.request = request as ImmutableRequestInfo;\n this.god = god;\n this.stream.promise = this.stream.promise.then((stream: ReadableStream | null) => {\n if (this.god.stream === stream && this.hasSubscribers) {\n this.god.stream = null;\n }\n return stream;\n });\n }\n\n get hasRequestedStream(): boolean {\n return this.god.hasRequestedStream;\n }\n\n getResponse(): ResponseInfo | null {\n if (this.hasSetResponse) {\n return this.response;\n }\n if (this.nextCalled === 1) {\n return this.god.response;\n }\n return null;\n }\n getStream(): Promise<ReadableStream | null> {\n if (this.isRoot) {\n this.god.hasRequestedStream = true;\n }\n if (!this.hasSetResponse) {\n const hint = this.god.response?.headers?.get('content-length');\n this.stream.promise.sizeHint = hint ? parseInt(hint, 10) : 0;\n }\n this.hasSubscribers = true;\n return this.stream.promise;\n }\n abort(reason: DOMException) {\n this.controller.abort(reason);\n }\n\n setStream(stream: ReadableStream | Promise<ReadableStream | null> | null) {\n if (!this.hasSetStream) {\n this.hasSetStream = true;\n\n if (!(stream instanceof Promise)) {\n this.god.stream = stream;\n }\n // @ts-expect-error\n this.stream.resolve(stream);\n }\n }\n\n resolveStream() {\n this.setStream(this.nextCalled === 1 ? this.god.stream : null);\n }\n\n setResponse(response: ResponseInfo | Response | null) {\n if (this.hasSetResponse) {\n if (DEBUG) {\n throw new Error(`Cannot setResponse when a response has already been set`);\n }\n return;\n }\n this.hasSetResponse = true;\n if (response instanceof Response) {\n // TODO potentially avoid cloning in prod\n let responseData = cloneResponseProperties(response);\n\n if (DEBUG) {\n responseData = deepFreeze(responseData);\n }\n this.response = responseData;\n this.god.response = responseData;\n const sizeHint = response.headers?.get('content-length');\n this.stream.promise.sizeHint = sizeHint ? parseInt(sizeHint, 10) : 0;\n } else {\n this.response = response;\n this.god.response = response;\n }\n }\n}\n\nexport class Context {\n #owner: ContextOwner;\n declare request: ImmutableRequestInfo;\n declare id: number;\n declare private _isCacheHandler: boolean;\n declare private _finalized: boolean;\n\n constructor(owner: ContextOwner, isCacheHandler: boolean) {\n this.id = owner.requestId;\n this.#owner = owner;\n this.request = owner.enhancedRequest;\n this._isCacheHandler = isCacheHandler;\n this._finalized = false;\n }\n setStream(stream: ReadableStream | Promise<ReadableStream | null>) {\n this.#owner.setStream(stream);\n }\n setResponse(response: ResponseInfo | Response | null) {\n this.#owner.setResponse(response);\n }\n\n setIdentifier(identifier: StableDocumentIdentifier) {\n assert(\n `setIdentifier may only be used synchronously from a CacheHandler`,\n identifier && this._isCacheHandler && !this._finalized\n );\n this.#owner.god.identifier = identifier;\n }\n\n get hasRequestedStream() {\n return this.#owner.hasRequestedStream;\n }\n\n _finalize() {\n this._finalized = true;\n }\n}\nexport type HandlerRequestContext = Context;\n"],"names":["BODY_TYPES","type","klass","ValidKeys","Map","IS_FROZEN","getOrSetGlobal","Symbol","IS_COLLECTION","for","freezeHeaders","headers","delete","set","append","Error","upgradeHeaders","deepFreeze","value","_type","_niceType","niceTypeOf","arr","map","Object","freeze","keys","forEach","key","isMaybeContext","request","length","v","Array","isArray","Date","Set","ReadableStream","WritableStream","TransformStream","Headers","constructor","name","validateKey","errors","schema","get","IgnoredKeys","has","push","includes","join","JSON","stringify","e","message","k","String","assertValidRequest","isTopLevel","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","Context","validationErrors","isLegacyRequest","Boolean","url","error","PromiseCache","getOrSetUniversal","WeakMap","RequestMap","setRequestResult","requestId","result","clearRequestResult","getRequestResult","setPromiseResult","promise","getPromiseResult","IS_CACHE_HANDLER","curryFuture","owner","inbound","outbound","setStream","getStream","then","doc","document","STRUCTURED","response","content","resolve","isDoc","god","stream","assign","getResponse","reject","ensureDoc","isError","enhanceReason","reason","DOMException","handleOutcome","controller","signal","aborted","isCacheHandler","handler","index","executeNextHandler","wares","i","ContextOwner","next","r","nextCalled","_isCacheHandler","context","outcome","_finalize","Promise","console","log","undefined","future","createFuture","isFuture","maybe","IS_FUTURE","createDeferred","res","rej","upgradePromise","abort","onFinalize","id","lid","deferred","cbs","finally","resolveStream","cb","fn","identifier","clone","toJSON","from","cloneResponseProperties","ok","redirected","status","statusText","hasSetStream","hasSetResponse","hasSubscribers","isRoot","sizeHint","addEventListener","enhancedRequest","cacheOptions","SkipCache","hasRequestedStream","hint","parseInt","setResponse","Response","responseData","_finalized","setIdentifier","test"],"mappings":";;;;AAMA,MAAMA,UAAU,GAAG;AACjBC,EAAAA,IAAI,EAAE,QAAQ;AACdC,EAAAA,KAAK,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB;AAC1G,CAAC;AACD,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAgD,CACvE,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,EACpB,CAAC,SAAS,EAAE,OAAO,CAAC,EACpB,CAAC,MAAM,EAAE,MAAM,CAAC,EAChB,CAAC,MAAM,EAAEJ,UAAU,CAAC,EACpB,CAAC,mBAAmB,EAAE,SAAS,CAAC,EAChC,CAAC,SAAS,EAAE,QAAQ,CAAC,EACrB,CAAC,cAAc,EAAE,QAAQ,CAAC,EAC1B,CAAC,IAAI,EAAE,QAAQ,CAAC,EAChB,CAAC,OAAO,EAAE,QAAQ,CAAC,EACnB,CAAC,KAAK,EAAE,QAAQ,CAAC,EACjB,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAC,EACzF,CAAC,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,EACnD,CACE,aAAa,EACb,CACE,EAAE,EACF,QAAQ,EACR,OAAO,EACP,cAAc,EACd,UAAU,EACV,OAAO,EACP,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,UAAU,EACV,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,OAAO,EACP,OAAO,EACP,OAA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ACX,SAAS,CAACW,MAAM,CAAC;AAC/B;EACAuE,WAAWA,CAAC5E,QAAwC,EAAE;AACpD,IAAA,IAAI,CAAC,MAAM,CAAC4E,WAAW,CAAC5E,QAAQ,CAAC;AACnC;EAEAgF,aAAaA,CAACzB,UAAoC,EAAE;IAClDzF,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAA,GAAA,CAAA+G,IAAA,IAAA;AAAA,MAAA,IAAA,CAAAA,IAAA,EAAA;QAAA,MAAAhK,IAAAA,KAAA,CACE,CAAkE,gEAAA,CAAA,CAAA;AAAA;KAClEsI,EAAAA,UAAU,IAAI,IAAI,CAAC3B,eAAe,IAAI,CAAC,IAAI,CAACmD,UAAU,CAAA,GAAA,EAAA;IAExD,IAAI,CAAC,MAAM,CAAC3E,GAAG,CAACmD,UAAU,GAAGA,UAAU;AACzC;EAEA,IAAIkB,kBAAkBA,GAAG;AACvB,IAAA,OAAO,IAAI,CAAC,MAAM,CAACA,kBAAkB;AACvC;AAEA1C,EAAAA,SAASA,GAAG;IACV,IAAI,CAACgD,UAAU,GAAG,IAAI;AACxB;AACF;;;;"}
@@ -1,10 +1,10 @@
1
1
  import { deprecate, warn } from '@ember/debug';
2
- import { p as peekCache } from "../request-state-Bv5CY_H0.js";
3
- import "../types/request.js";
2
+ import { p as peekCache } from "../request-state-DgwTEXLU.js";
3
+ import '../types/request.js';
4
4
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
5
- import "../utils/string.js";
6
- import "../configure-Bz49BEZQ.js";
7
- import { getOrSetGlobal, peekTransient, setTransient } from "../types/-private.js";
5
+ import '../utils/string.js';
6
+ import "../configure-BgaZESRo.js";
7
+ import { getOrSetGlobal, peekTransient, setTransient } from '../types/-private.js';
8
8
  function coerceId(id) {
9
9
  if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_ID)) {
10
10
  let normalized;
@@ -1,5 +1,5 @@
1
- import { G as ReactiveDocument } from "./request-state-Bv5CY_H0.js";
2
- import { SkipCache, EnableHydration } from "./types/request.js";
1
+ import { G as ReactiveDocument } from "./request-state-DgwTEXLU.js";
2
+ import { SkipCache, EnableHydration } from './types/request.js';
3
3
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
4
  const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);
5
5
  function calcShouldFetch(store, request, hasCachedValue, identifier) {
@@ -1 +1 @@
1
- {"version":3,"file":"handler-DYUefHNU.js","sources":["../src/store/-private/cache-handler/utils.ts","../src/store/-private/cache-handler/handler.ts"],"sourcesContent":["import type { StableDocumentIdentifier } from '../../../types/identifier.ts';\nimport type {\n ImmutableCreateRequestOptions,\n ImmutableDeleteRequestOptions,\n ImmutableRequestInfo,\n ImmutableUpdateRequestOptions,\n StructuredDataDocument,\n} from '../../../types/request.ts';\nimport type { ResourceDataDocument, ResourceErrorDocument } from '../../../types/spec/document.ts';\nimport type { ApiError } from '../../../types/spec/error.ts';\nimport type { Store } from '../store-service.ts';\n\nexport const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);\n\nexport function calcShouldFetch(\n store: Store,\n request: ImmutableRequestInfo,\n hasCachedValue: boolean,\n identifier: StableDocumentIdentifier | null\n): boolean {\n const { cacheOptions } = request;\n return (\n (request.op && MUTATION_OPS.has(request.op)) ||\n cacheOptions?.reload ||\n !hasCachedValue ||\n (store.lifetimes && identifier ? store.lifetimes.isHardExpired(identifier, store) : false)\n );\n}\n\nexport function calcShouldBackgroundFetch(\n store: Store,\n request: ImmutableRequestInfo,\n willFetch: boolean,\n identifier: StableDocumentIdentifier | null\n): boolean {\n const { cacheOptions } = request;\n return (\n !willFetch &&\n (cacheOptions?.backgroundReload ||\n (store.lifetimes && identifier ? store.lifetimes.isSoftExpired(identifier, store) : false))\n );\n}\n\nexport function isMutation(\n request: Partial<ImmutableRequestInfo>\n): request is ImmutableUpdateRequestOptions | ImmutableCreateRequestOptions | ImmutableDeleteRequestOptions {\n return Boolean(request.op && MUTATION_OPS.has(request.op));\n}\n\nexport function isCacheAffecting<T>(document: StructuredDataDocument<T>): boolean {\n if (!isMutation(document.request)) {\n return true;\n }\n // a mutation combined with a 204 has no cache impact when no known records were involved\n // a createRecord with a 201 with an empty response and no known records should similarly\n // have no cache impact\n\n if (document.request.op === 'createRecord' && document.response?.status === 201) {\n return document.content ? Object.keys(document.content).length > 0 : false;\n }\n\n return document.response?.status !== 204;\n}\n\nexport function isAggregateError(\n error: Error & { errors?: ApiError[] }\n): error is AggregateError & { errors: ApiError[] } {\n return error instanceof AggregateError || (error.name === 'AggregateError' && Array.isArray(error.errors));\n}\n\nexport type RobustError = Error & { error: string | object; errors?: ApiError[]; content?: unknown };\n\n// TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them\nexport function cloneError(error: RobustError) {\n const isAggregate = isAggregateError(error);\n\n const cloned = (\n isAggregate ? new AggregateError(structuredClone(error.errors), error.message) : new Error(error.message)\n ) as RobustError;\n cloned.stack = error.stack!;\n cloned.error = error.error;\n\n // copy over enumerable properties\n Object.assign(cloned, error);\n\n return cloned;\n}\n\nexport function isErrorDocument(\n document: ResourceDataDocument | ResourceErrorDocument\n): document is ResourceErrorDocument {\n return 'errors' in document;\n}\n\nexport function getPriority(\n identifier: StableDocumentIdentifier | null,\n deduped: Map<StableDocumentIdentifier, { priority: { blocking: boolean } }>,\n priority: { blocking: boolean }\n) {\n if (identifier) {\n const existing = deduped.get(identifier);\n if (existing) {\n return existing.priority;\n }\n }\n return priority;\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\n\nimport { ReactiveDocument } from '../../../reactive/-private/document.ts';\nimport type { CacheHandler as CacheHandlerType, Future, ManagedRequestPriority, NextFn } from '../../../request.ts';\nimport type { StableDocumentIdentifier } from '../../../types/identifier.ts';\nimport type {\n ImmutableRequestInfo,\n RequestContext,\n StructuredDataDocument,\n StructuredErrorDocument,\n} from '../../../types/request.ts';\nimport { EnableHydration, SkipCache } from '../../../types/request.ts';\nimport type { ResourceDataDocument, ResourceDocument, ResourceErrorDocument } from '../../../types/spec/document.ts';\nimport type { ApiError } from '../../../types/spec/error.ts';\nimport type { ResourceIdentifierObject } from '../../../types/spec/json-api-raw.ts';\nimport type { RequestSignature } from '../../../types/symbols.ts';\nimport type { Store } from '../store-service.ts';\nimport {\n calcShouldBackgroundFetch,\n calcShouldFetch,\n cloneError,\n getPriority,\n isCacheAffecting,\n isMutation,\n} from './utils.ts';\n\nexport type LooseStoreRequestInfo<RT = unknown, T = unknown> = Omit<\n ImmutableRequestInfo<RT, T>,\n 'records' | 'headers' | typeof RequestSignature\n> & {\n records?: ResourceIdentifierObject[];\n headers?: Headers;\n};\n\nexport type StoreRequestInput<RT = unknown, T = unknown> = ImmutableRequestInfo<RT, T> | LooseStoreRequestInfo<RT, T>;\n\nexport interface StoreRequestContext extends RequestContext {\n request: ImmutableRequestInfo & { store: Store };\n}\n\n/**\n * A CacheHandler that adds support for using an WarpDrive Cache with a RequestManager.\n *\n * This handler will only run when a request has supplied a `store` instance. Requests\n * issued by the store via `store.request()` will automatically have the `store` instance\n * attached to the request.\n *\n * ```ts\n * requestManager.request({\n * store: store,\n * url: '/api/posts',\n * method: 'GET'\n * });\n * ```\n *\n * When this handler elects to handle a request, it will return the raw `StructuredDocument`\n * unless the request has `[EnableHydration]` set to `true`. In this case, the handler will\n * return a `Document` instance that will automatically update the UI when the cache is updated\n * in the future and will hydrate any identifiers in the StructuredDocument into Record instances.\n *\n * When issuing a request via the store, [EnableHydration] is automatically set to `true`. This\n * means that if desired you can issue requests that utilize the cache without needing to also\n * utilize Record instances if desired.\n *\n * Said differently, you could elect to issue all requests via a RequestManager, without ever using\n * the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not\n * necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature\n * approach of WarpDrive allows for this flexibility.\n *\n * ```ts\n * import { EnableHydration } from '@warp-drive/core/types/request';\n *\n * requestManager.request({\n * store: store,\n * url: '/api/posts',\n * method: 'GET',\n * [EnableHydration]: true\n * });\n *\n */\nexport const CacheHandler: CacheHandlerType = {\n request<T>(\n context: StoreRequestContext & { setIdentifier(identifier: StableDocumentIdentifier): void },\n next: NextFn<T>\n ): Promise<T | StructuredDataDocument<T>> | Future<T> | T {\n // if we have no cache or no cache-key skip cache handling\n if (!context.request.store || context.request.cacheOptions?.[SkipCache]) {\n return next(context.request);\n }\n\n const { store } = context.request;\n const identifier = store.identifierCache.getOrCreateDocumentIdentifier(context.request);\n\n if (identifier) {\n context.setIdentifier(identifier);\n }\n\n // used to dedupe existing requests that match\n const DEDUPE = store.requestManager._deduped;\n const activeRequest = identifier && DEDUPE.get(identifier);\n const peeked = identifier ? store.cache.peekRequest(identifier) : null;\n\n // determine if we should skip cache\n if (calcShouldFetch(store, context.request, !!peeked, identifier)) {\n if (activeRequest) {\n activeRequest.priority = { blocking: true };\n return activeRequest.promise as Promise<T>;\n }\n let promise = fetchContentAndHydrate(next, context, identifier, { blocking: true });\n if (identifier) {\n promise = promise.finally(() => {\n DEDUPE.delete(identifier);\n store.notifications.notify(identifier, 'state');\n });\n DEDUPE.set(identifier, { priority: { blocking: true }, promise });\n store.notifications.notify(identifier, 'state');\n }\n return promise;\n }\n\n // if we have not skipped cache, determine if we should update behind the scenes\n if (calcShouldBackgroundFetch(store, context.request, false, identifier)) {\n let promise = activeRequest?.promise || fetchContentAndHydrate(next, context, identifier, { blocking: false });\n if (identifier && !activeRequest) {\n promise = promise.finally(() => {\n DEDUPE.delete(identifier);\n store.notifications.notify(identifier, 'state');\n });\n DEDUPE.set(identifier, { priority: { blocking: false }, promise });\n store.notifications.notify(identifier, 'state');\n }\n store.requestManager._pending.set(context.id, promise);\n }\n\n assert(`Expected a peeked request to be present`, peeked);\n\n const shouldHydrate: boolean = context.request[EnableHydration] || false;\n context.setResponse(peeked.response);\n\n if ('error' in peeked) {\n const content = shouldHydrate\n ? maybeUpdateUiObjects<T>(store, context.request, { shouldHydrate, identifier }, peeked.content)\n : peeked.content;\n const newError = cloneError(peeked);\n newError.content = content as object;\n throw newError;\n }\n\n const result = shouldHydrate\n ? (maybeUpdateUiObjects<T>(store, context.request, { shouldHydrate, identifier }, peeked.content) as T)\n : (peeked.content as T);\n\n return result;\n },\n};\n\ntype HydrationOptions = {\n shouldHydrate?: boolean;\n identifier: StableDocumentIdentifier | null;\n};\n\ntype UpdateOptions = HydrationOptions & {\n priority: ManagedRequestPriority;\n};\n\nfunction maybeUpdateUiObjects<T>(\n store: Store,\n request: ImmutableRequestInfo,\n options: HydrationOptions,\n document: ResourceDocument | null | undefined\n): ReactiveDocument<T> | ResourceDocument | null {\n const { identifier } = options;\n\n if (!document || !options.shouldHydrate) {\n assert(`The CacheHandler expected response content but none was found`, !options.shouldHydrate);\n return document ?? null;\n }\n\n if (identifier) {\n return store._instanceCache.getDocument<T>(identifier);\n }\n\n // if we don't have an identifier, we give the document\n // its own local cache\n return new ReactiveDocument<T>(store, null, {\n request,\n document,\n });\n}\n\nfunction updateCacheForSuccess<T>(\n store: Store,\n request: StoreRequestContext['request'],\n options: HydrationOptions,\n document: StructuredDataDocument<T>\n) {\n let response: ResourceDataDocument | null = null;\n if (isMutation(request)) {\n const record = request.data?.record || request.records?.[0];\n if (record) {\n response = store.cache.didCommit(record, document) as ResourceDataDocument;\n\n // a mutation combined with a 204 has no cache impact when no known records were involved\n // a createRecord with a 201 with an empty response and no known records should similarly\n // have no cache impact\n } else if (isCacheAffecting(document)) {\n response = store.cache.put(document) as ResourceDataDocument;\n }\n } else {\n response = store.cache.put(document) as ResourceDataDocument;\n }\n return maybeUpdateUiObjects(store, request, options, response);\n}\n\nfunction handleFetchSuccess<T>(\n store: Store,\n context: StoreRequestContext,\n options: UpdateOptions,\n document: StructuredDataDocument<T>\n): ResourceDataDocument | void {\n const { request } = context;\n store.requestManager._pending.delete(context.id);\n store._enableAsyncFlush = true;\n let response: ResourceDataDocument;\n store._join(() => {\n response = updateCacheForSuccess<T>(store, request, options, document) as ResourceDataDocument;\n });\n store._enableAsyncFlush = null;\n\n if (store.lifetimes?.didRequest) {\n store.lifetimes.didRequest(context.request, document.response, options.identifier, store);\n }\n\n const finalPriority = getPriority(options.identifier, store.requestManager._deduped, options.priority);\n if (finalPriority.blocking) {\n return response!;\n } else {\n store.notifications._flush();\n }\n}\n\nfunction updateCacheForError<T>(\n store: Store,\n context: StoreRequestContext,\n options: HydrationOptions,\n error: StructuredErrorDocument<T>\n) {\n let response: ResourceErrorDocument | undefined;\n if (isMutation(context.request)) {\n // TODO similar to didCommit we should spec this to be similar to cache.put for handling full response\n // currently we let the response remain undefiend.\n const errors =\n error &&\n error.content &&\n typeof error.content === 'object' &&\n 'errors' in error.content &&\n Array.isArray(error.content.errors)\n ? (error.content.errors as ApiError[])\n : undefined;\n\n const record = context.request.data?.record || context.request.records?.[0];\n\n store.cache.commitWasRejected(record, errors);\n } else {\n response = store.cache.put(error) as ResourceErrorDocument;\n return maybeUpdateUiObjects(store, context.request, options, response);\n }\n}\n\nfunction handleFetchError<T>(\n store: Store,\n context: StoreRequestContext,\n options: UpdateOptions,\n error: StructuredErrorDocument<T>\n): ResourceErrorDocument | void {\n store.requestManager._pending.delete(context.id);\n if (context.request.signal?.aborted) {\n throw error;\n }\n store._enableAsyncFlush = true;\n let response: ResourceErrorDocument | undefined;\n store._join(() => {\n response = updateCacheForError(store, context, options, error) as ResourceErrorDocument;\n });\n store._enableAsyncFlush = null;\n\n if (options.identifier && store.lifetimes?.didRequest) {\n store.lifetimes.didRequest(context.request, error.response, options.identifier, store);\n }\n\n if (isMutation(context.request)) {\n throw error;\n }\n\n const finalPriority = getPriority(options.identifier, store.requestManager._deduped, options.priority);\n if (finalPriority.blocking) {\n const newError = cloneError(error);\n newError.content = response!;\n throw newError;\n } else {\n store.notifications._flush();\n }\n}\n\nfunction fetchContentAndHydrate<T>(\n next: NextFn<T>,\n context: StoreRequestContext,\n identifier: StableDocumentIdentifier | null,\n priority: { blocking: boolean }\n): Promise<T> {\n const { store } = context.request;\n const shouldHydrate: boolean = context.request[EnableHydration] || false;\n const options = { shouldHydrate, identifier, priority };\n\n let isMut = false;\n if (isMutation(context.request)) {\n isMut = true;\n // TODO should we handle multiple records in request.records by iteratively calling willCommit for each\n const record = context.request.data?.record || context.request.records?.[0];\n assert(\n `Expected to receive a list of records included in the ${context.request.op} request`,\n record || !shouldHydrate\n );\n if (record) {\n store.cache.willCommit(record, context);\n }\n }\n\n if (store.lifetimes?.willRequest) {\n store.lifetimes.willRequest(context.request, identifier, store);\n }\n\n const promise = next(context.request).then(\n (document) => {\n return handleFetchSuccess(store, context, options, document);\n },\n (error: StructuredErrorDocument<T>) => {\n return handleFetchError(store, context, options, error);\n }\n ) as Promise<T>;\n\n if (!isMut) {\n return promise;\n }\n assert(`Expected a mutation`, isMutation(context.request));\n\n // for mutations we need to enqueue the promise with the requestStateService\n // TODO should we enque a request per record in records?\n const record = context.request.data?.record || context.request.records?.[0];\n\n return store._requestCache._enqueue(promise, {\n data: [{ op: 'saveRecord', recordIdentifier: record, options: undefined }],\n });\n}\n"],"names":["MUTATION_OPS","Set","calcShouldFetch","store","request","hasCachedValue","identifier","cacheOptions","op","has","reload","lifetimes","isHardExpired","calcShouldBackgroundFetch","willFetch","backgroundReload","isSoftExpired","isMutation","Boolean","isCacheAffecting","document","response","status","content","Object","keys","length","isAggregateError","error","AggregateError","name","Array","isArray","errors","cloneError","isAggregate","cloned","structuredClone","message","Error","stack","assign","getPriority","deduped","priority","existing","get","CacheHandler","context","next","SkipCache","identifierCache","getOrCreateDocumentIdentifier","setIdentifier","DEDUPE","requestManager","_deduped","activeRequest","peeked","cache","peekRequest","blocking","promise","fetchContentAndHydrate","finally","delete","notifications","notify","set","_pending","id","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","shouldHydrate","EnableHydration","setResponse","maybeUpdateUiObjects","newError","result","options","_instanceCache","getDocument","ReactiveDocument","updateCacheForSuccess","record","data","records","didCommit","put","handleFetchSuccess","_enableAsyncFlush","_join","didRequest","finalPriority","_flush","updateCacheForError","undefined","commitWasRejected","handleFetchError","signal","aborted","isMut","willCommit","willRequest","then","_requestCache","_enqueue","recordIdentifier"],"mappings":";;;;AAYO,MAAMA,YAAY,GAAG,IAAIC,GAAG,CAAC,CAAC,cAAc,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;AAE9E,SAASC,eAAeA,CAC7BC,KAAY,EACZC,OAA6B,EAC7BC,cAAuB,EACvBC,UAA2C,EAClC;EACT,MAAM;AAAEC,IAAAA;AAAa,GAAC,GAAGH,OAAO;AAChC,EAAA,OACGA,OAAO,CAACI,EAAE,IAAIR,YAAY,CAACS,GAAG,CAACL,OAAO,CAACI,EAAE,CAAC,IAC3CD,YAAY,EAAEG,MAAM,IACpB,CAACL,cAAc,KACdF,KAAK,CAACQ,SAAS,IAAIL,UAAU,GAAGH,KAAK,CAACQ,SAAS,CAACC,aAAa,CAACN,UAAU,EAAEH,KAAK,CAAC,GAAG,KAAK,CAAC;AAE9F;AAEO,SAASU,yBAAyBA,CACvCV,KAAY,EACZC,OAA6B,EAC7BU,SAAkB,EAClBR,UAA2C,EAClC;EACT,MAAM;AAAEC,IAAAA;AAAa,GAAC,GAAGH,OAAO;EAChC,OACY,CACTG,YAAY,EAAEQ,gBAAgB,KAC5BZ,KAAK,CAACQ,SAAS,IAAIL,UAAU,GAAGH,KAAK,CAACQ,SAAS,CAACK,aAAa,CAACV,UAAU,EAAEH,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AAEjG;AAEO,SAASc,UAAUA,CACxBb,OAAsC,EACoE;AAC1G,EAAA,OAAOc,OAAO,CAACd,OAAO,CAACI,EAAE,IAAIR,YAAY,CAACS,GAAG,CAACL,OAAO,CAACI,EAAE,CAAC,CAAC;AAC5D;AAEO,SAASW,gBAAgBA,CAAIC,QAAmC,EAAW;AAChF,EAAA,IAAI,CAACH,UAAU,CAACG,QAAQ,CAAChB,OAAO,CAAC,EAAE;AACjC,IAAA,OAAO,IAAI;AAC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AAI,CACvCxF,QAAQ,IAAK;IACZ,OAAOyE,kBAAkB,CAAC1F,KAAK,EAAE6C,OAAO,EAAEmC,OAAO,EAAE/D,QAAQ,CAAC;GAC7D,EACAQ,KAAiC,IAAK;IACrC,OAAO0E,gBAAgB,CAACnG,KAAK,EAAE6C,OAAO,EAAEmC,OAAO,EAAEvD,KAAK,CAAC;AACzD,GACF,CAAe;EAEf,IAAI,CAAC6E,KAAK,EAAE;AACV,IAAA,OAAO3C,OAAO;AAChB;EACAS,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAA,GAAA,CAAAC,IAAA,IAAA;AAAA,IAAA,IAAA,CAAAA,IAAA,EAAA;MAAA,MAAArC,IAAAA,KAAA,CAAO,CAAqB,mBAAA,CAAA,CAAA;AAAA;AAAA,GAAA,EAAEtB,UAAU,CAAC+B,OAAO,CAAC5C,OAAO,CAAC,CAAA,GAAA,EAAA;;AAEzD;AACA;AACA,EAAA,MAAMoF,MAAM,GAAGxC,OAAO,CAAC5C,OAAO,CAACqF,IAAI,EAAED,MAAM,IAAIxC,OAAO,CAAC5C,OAAO,CAACsF,OAAO,GAAG,CAAC,CAAC;AAE3E,EAAA,OAAOvF,KAAK,CAAC0G,aAAa,CAACC,QAAQ,CAAChD,OAAO,EAAE;AAC3C2B,IAAAA,IAAI,EAAE,CAAC;AAAEjF,MAAAA,EAAE,EAAE,YAAY;AAAEuG,MAAAA,gBAAgB,EAAEvB,MAAM;AAAEL,MAAAA,OAAO,EAAEiB;KAAW;AAC3E,GAAC,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"handler-cHghx9Y9.js","sources":["../src/store/-private/cache-handler/utils.ts","../src/store/-private/cache-handler/handler.ts"],"sourcesContent":["import type { StableDocumentIdentifier } from '../../../types/identifier.ts';\nimport type {\n ImmutableCreateRequestOptions,\n ImmutableDeleteRequestOptions,\n ImmutableRequestInfo,\n ImmutableUpdateRequestOptions,\n StructuredDataDocument,\n} from '../../../types/request.ts';\nimport type { ResourceDataDocument, ResourceErrorDocument } from '../../../types/spec/document.ts';\nimport type { ApiError } from '../../../types/spec/error.ts';\nimport type { Store } from '../store-service.ts';\n\nexport const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);\n\nexport function calcShouldFetch(\n store: Store,\n request: ImmutableRequestInfo,\n hasCachedValue: boolean,\n identifier: StableDocumentIdentifier | null\n): boolean {\n const { cacheOptions } = request;\n return (\n (request.op && MUTATION_OPS.has(request.op)) ||\n cacheOptions?.reload ||\n !hasCachedValue ||\n (store.lifetimes && identifier ? store.lifetimes.isHardExpired(identifier, store) : false)\n );\n}\n\nexport function calcShouldBackgroundFetch(\n store: Store,\n request: ImmutableRequestInfo,\n willFetch: boolean,\n identifier: StableDocumentIdentifier | null\n): boolean {\n const { cacheOptions } = request;\n return (\n !willFetch &&\n (cacheOptions?.backgroundReload ||\n (store.lifetimes && identifier ? store.lifetimes.isSoftExpired(identifier, store) : false))\n );\n}\n\nexport function isMutation(\n request: Partial<ImmutableRequestInfo>\n): request is ImmutableUpdateRequestOptions | ImmutableCreateRequestOptions | ImmutableDeleteRequestOptions {\n return Boolean(request.op && MUTATION_OPS.has(request.op));\n}\n\nexport function isCacheAffecting<T>(document: StructuredDataDocument<T>): boolean {\n if (!isMutation(document.request)) {\n return true;\n }\n // a mutation combined with a 204 has no cache impact when no known records were involved\n // a createRecord with a 201 with an empty response and no known records should similarly\n // have no cache impact\n\n if (document.request.op === 'createRecord' && document.response?.status === 201) {\n return document.content ? Object.keys(document.content).length > 0 : false;\n }\n\n return document.response?.status !== 204;\n}\n\nexport function isAggregateError(\n error: Error & { errors?: ApiError[] }\n): error is AggregateError & { errors: ApiError[] } {\n return error instanceof AggregateError || (error.name === 'AggregateError' && Array.isArray(error.errors));\n}\n\nexport type RobustError = Error & { error: string | object; errors?: ApiError[]; content?: unknown };\n\n// TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them\nexport function cloneError(error: RobustError) {\n const isAggregate = isAggregateError(error);\n\n const cloned = (\n isAggregate ? new AggregateError(structuredClone(error.errors), error.message) : new Error(error.message)\n ) as RobustError;\n cloned.stack = error.stack!;\n cloned.error = error.error;\n\n // copy over enumerable properties\n Object.assign(cloned, error);\n\n return cloned;\n}\n\nexport function isErrorDocument(\n document: ResourceDataDocument | ResourceErrorDocument\n): document is ResourceErrorDocument {\n return 'errors' in document;\n}\n\nexport function getPriority(\n identifier: StableDocumentIdentifier | null,\n deduped: Map<StableDocumentIdentifier, { priority: { blocking: boolean } }>,\n priority: { blocking: boolean }\n) {\n if (identifier) {\n const existing = deduped.get(identifier);\n if (existing) {\n return existing.priority;\n }\n }\n return priority;\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\n\nimport { ReactiveDocument } from '../../../reactive/-private/document.ts';\nimport type { CacheHandler as CacheHandlerType, Future, ManagedRequestPriority, NextFn } from '../../../request.ts';\nimport type { StableDocumentIdentifier } from '../../../types/identifier.ts';\nimport type {\n ImmutableRequestInfo,\n RequestContext,\n StructuredDataDocument,\n StructuredErrorDocument,\n} from '../../../types/request.ts';\nimport { EnableHydration, SkipCache } from '../../../types/request.ts';\nimport type { ResourceDataDocument, ResourceDocument, ResourceErrorDocument } from '../../../types/spec/document.ts';\nimport type { ApiError } from '../../../types/spec/error.ts';\nimport type { ResourceIdentifierObject } from '../../../types/spec/json-api-raw.ts';\nimport type { RequestSignature } from '../../../types/symbols.ts';\nimport type { Store } from '../store-service.ts';\nimport {\n calcShouldBackgroundFetch,\n calcShouldFetch,\n cloneError,\n getPriority,\n isCacheAffecting,\n isMutation,\n} from './utils.ts';\n\nexport type LooseStoreRequestInfo<RT = unknown, T = unknown> = Omit<\n ImmutableRequestInfo<RT, T>,\n 'records' | 'headers' | typeof RequestSignature\n> & {\n records?: ResourceIdentifierObject[];\n headers?: Headers;\n};\n\nexport type StoreRequestInput<RT = unknown, T = unknown> = ImmutableRequestInfo<RT, T> | LooseStoreRequestInfo<RT, T>;\n\nexport interface StoreRequestContext extends RequestContext {\n request: ImmutableRequestInfo & { store: Store };\n}\n\n/**\n * A CacheHandler that adds support for using an WarpDrive Cache with a RequestManager.\n *\n * This handler will only run when a request has supplied a `store` instance. Requests\n * issued by the store via `store.request()` will automatically have the `store` instance\n * attached to the request.\n *\n * ```ts\n * requestManager.request({\n * store: store,\n * url: '/api/posts',\n * method: 'GET'\n * });\n * ```\n *\n * When this handler elects to handle a request, it will return the raw `StructuredDocument`\n * unless the request has `[EnableHydration]` set to `true`. In this case, the handler will\n * return a `Document` instance that will automatically update the UI when the cache is updated\n * in the future and will hydrate any identifiers in the StructuredDocument into Record instances.\n *\n * When issuing a request via the store, [EnableHydration] is automatically set to `true`. This\n * means that if desired you can issue requests that utilize the cache without needing to also\n * utilize Record instances if desired.\n *\n * Said differently, you could elect to issue all requests via a RequestManager, without ever using\n * the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not\n * necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature\n * approach of WarpDrive allows for this flexibility.\n *\n * ```ts\n * import { EnableHydration } from '@warp-drive/core/types/request';\n *\n * requestManager.request({\n * store: store,\n * url: '/api/posts',\n * method: 'GET',\n * [EnableHydration]: true\n * });\n *\n */\nexport const CacheHandler: CacheHandlerType = {\n request<T>(\n context: StoreRequestContext & { setIdentifier(identifier: StableDocumentIdentifier): void },\n next: NextFn<T>\n ): Promise<T | StructuredDataDocument<T>> | Future<T> | T {\n // if we have no cache or no cache-key skip cache handling\n if (!context.request.store || context.request.cacheOptions?.[SkipCache]) {\n return next(context.request);\n }\n\n const { store } = context.request;\n const identifier = store.identifierCache.getOrCreateDocumentIdentifier(context.request);\n\n if (identifier) {\n context.setIdentifier(identifier);\n }\n\n // used to dedupe existing requests that match\n const DEDUPE = store.requestManager._deduped;\n const activeRequest = identifier && DEDUPE.get(identifier);\n const peeked = identifier ? store.cache.peekRequest(identifier) : null;\n\n // determine if we should skip cache\n if (calcShouldFetch(store, context.request, !!peeked, identifier)) {\n if (activeRequest) {\n activeRequest.priority = { blocking: true };\n return activeRequest.promise as Promise<T>;\n }\n let promise = fetchContentAndHydrate(next, context, identifier, { blocking: true });\n if (identifier) {\n promise = promise.finally(() => {\n DEDUPE.delete(identifier);\n store.notifications.notify(identifier, 'state');\n });\n DEDUPE.set(identifier, { priority: { blocking: true }, promise });\n store.notifications.notify(identifier, 'state');\n }\n return promise;\n }\n\n // if we have not skipped cache, determine if we should update behind the scenes\n if (calcShouldBackgroundFetch(store, context.request, false, identifier)) {\n let promise = activeRequest?.promise || fetchContentAndHydrate(next, context, identifier, { blocking: false });\n if (identifier && !activeRequest) {\n promise = promise.finally(() => {\n DEDUPE.delete(identifier);\n store.notifications.notify(identifier, 'state');\n });\n DEDUPE.set(identifier, { priority: { blocking: false }, promise });\n store.notifications.notify(identifier, 'state');\n }\n store.requestManager._pending.set(context.id, promise);\n }\n\n assert(`Expected a peeked request to be present`, peeked);\n\n const shouldHydrate: boolean = context.request[EnableHydration] || false;\n context.setResponse(peeked.response);\n\n if ('error' in peeked) {\n const content = shouldHydrate\n ? maybeUpdateUiObjects<T>(store, context.request, { shouldHydrate, identifier }, peeked.content)\n : peeked.content;\n const newError = cloneError(peeked);\n newError.content = content as object;\n throw newError;\n }\n\n const result = shouldHydrate\n ? (maybeUpdateUiObjects<T>(store, context.request, { shouldHydrate, identifier }, peeked.content) as T)\n : (peeked.content as T);\n\n return result;\n },\n};\n\ntype HydrationOptions = {\n shouldHydrate?: boolean;\n identifier: StableDocumentIdentifier | null;\n};\n\ntype UpdateOptions = HydrationOptions & {\n priority: ManagedRequestPriority;\n};\n\nfunction maybeUpdateUiObjects<T>(\n store: Store,\n request: ImmutableRequestInfo,\n options: HydrationOptions,\n document: ResourceDocument | null | undefined\n): ReactiveDocument<T> | ResourceDocument | null {\n const { identifier } = options;\n\n if (!document || !options.shouldHydrate) {\n assert(`The CacheHandler expected response content but none was found`, !options.shouldHydrate);\n return document ?? null;\n }\n\n if (identifier) {\n return store._instanceCache.getDocument<T>(identifier);\n }\n\n // if we don't have an identifier, we give the document\n // its own local cache\n return new ReactiveDocument<T>(store, null, {\n request,\n document,\n });\n}\n\nfunction updateCacheForSuccess<T>(\n store: Store,\n request: StoreRequestContext['request'],\n options: HydrationOptions,\n document: StructuredDataDocument<T>\n) {\n let response: ResourceDataDocument | null = null;\n if (isMutation(request)) {\n const record = request.data?.record || request.records?.[0];\n if (record) {\n response = store.cache.didCommit(record, document) as ResourceDataDocument;\n\n // a mutation combined with a 204 has no cache impact when no known records were involved\n // a createRecord with a 201 with an empty response and no known records should similarly\n // have no cache impact\n } else if (isCacheAffecting(document)) {\n response = store.cache.put(document) as ResourceDataDocument;\n }\n } else {\n response = store.cache.put(document) as ResourceDataDocument;\n }\n return maybeUpdateUiObjects(store, request, options, response);\n}\n\nfunction handleFetchSuccess<T>(\n store: Store,\n context: StoreRequestContext,\n options: UpdateOptions,\n document: StructuredDataDocument<T>\n): ResourceDataDocument | void {\n const { request } = context;\n store.requestManager._pending.delete(context.id);\n store._enableAsyncFlush = true;\n let response: ResourceDataDocument;\n store._join(() => {\n response = updateCacheForSuccess<T>(store, request, options, document) as ResourceDataDocument;\n });\n store._enableAsyncFlush = null;\n\n if (store.lifetimes?.didRequest) {\n store.lifetimes.didRequest(context.request, document.response, options.identifier, store);\n }\n\n const finalPriority = getPriority(options.identifier, store.requestManager._deduped, options.priority);\n if (finalPriority.blocking) {\n return response!;\n } else {\n store.notifications._flush();\n }\n}\n\nfunction updateCacheForError<T>(\n store: Store,\n context: StoreRequestContext,\n options: HydrationOptions,\n error: StructuredErrorDocument<T>\n) {\n let response: ResourceErrorDocument | undefined;\n if (isMutation(context.request)) {\n // TODO similar to didCommit we should spec this to be similar to cache.put for handling full response\n // currently we let the response remain undefiend.\n const errors =\n error &&\n error.content &&\n typeof error.content === 'object' &&\n 'errors' in error.content &&\n Array.isArray(error.content.errors)\n ? (error.content.errors as ApiError[])\n : undefined;\n\n const record = context.request.data?.record || context.request.records?.[0];\n\n store.cache.commitWasRejected(record, errors);\n } else {\n response = store.cache.put(error) as ResourceErrorDocument;\n return maybeUpdateUiObjects(store, context.request, options, response);\n }\n}\n\nfunction handleFetchError<T>(\n store: Store,\n context: StoreRequestContext,\n options: UpdateOptions,\n error: StructuredErrorDocument<T>\n): ResourceErrorDocument | void {\n store.requestManager._pending.delete(context.id);\n if (context.request.signal?.aborted) {\n throw error;\n }\n store._enableAsyncFlush = true;\n let response: ResourceErrorDocument | undefined;\n store._join(() => {\n response = updateCacheForError(store, context, options, error) as ResourceErrorDocument;\n });\n store._enableAsyncFlush = null;\n\n if (options.identifier && store.lifetimes?.didRequest) {\n store.lifetimes.didRequest(context.request, error.response, options.identifier, store);\n }\n\n if (isMutation(context.request)) {\n throw error;\n }\n\n const finalPriority = getPriority(options.identifier, store.requestManager._deduped, options.priority);\n if (finalPriority.blocking) {\n const newError = cloneError(error);\n newError.content = response!;\n throw newError;\n } else {\n store.notifications._flush();\n }\n}\n\nfunction fetchContentAndHydrate<T>(\n next: NextFn<T>,\n context: StoreRequestContext,\n identifier: StableDocumentIdentifier | null,\n priority: { blocking: boolean }\n): Promise<T> {\n const { store } = context.request;\n const shouldHydrate: boolean = context.request[EnableHydration] || false;\n const options = { shouldHydrate, identifier, priority };\n\n let isMut = false;\n if (isMutation(context.request)) {\n isMut = true;\n // TODO should we handle multiple records in request.records by iteratively calling willCommit for each\n const record = context.request.data?.record || context.request.records?.[0];\n assert(\n `Expected to receive a list of records included in the ${context.request.op} request`,\n record || !shouldHydrate\n );\n if (record) {\n store.cache.willCommit(record, context);\n }\n }\n\n if (store.lifetimes?.willRequest) {\n store.lifetimes.willRequest(context.request, identifier, store);\n }\n\n const promise = next(context.request).then(\n (document) => {\n return handleFetchSuccess(store, context, options, document);\n },\n (error: StructuredErrorDocument<T>) => {\n return handleFetchError(store, context, options, error);\n }\n ) as Promise<T>;\n\n if (!isMut) {\n return promise;\n }\n assert(`Expected a mutation`, isMutation(context.request));\n\n // for mutations we need to enqueue the promise with the requestStateService\n // TODO should we enque a request per record in records?\n const record = context.request.data?.record || context.request.records?.[0];\n\n return store._requestCache._enqueue(promise, {\n data: [{ op: 'saveRecord', recordIdentifier: record, options: undefined }],\n });\n}\n"],"names":["MUTATION_OPS","Set","calcShouldFetch","store","request","hasCachedValue","identifier","cacheOptions","op","has","reload","lifetimes","isHardExpired","calcShouldBackgroundFetch","willFetch","backgroundReload","isSoftExpired","isMutation","Boolean","isCacheAffecting","document","response","status","content","Object","keys","length","isAggregateError","error","AggregateError","name","Array","isArray","errors","cloneError","isAggregate","cloned","structuredClone","message","Error","stack","assign","getPriority","deduped","priority","existing","get","CacheHandler","context","next","SkipCache","identifierCache","getOrCreateDocumentIdentifier","setIdentifier","DEDUPE","requestManager","_deduped","activeRequest","peeked","cache","peekRequest","blocking","promise","fetchContentAndHydrate","finally","delete","notifications","notify","set","_pending","id","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","shouldHydrate","EnableHydration","setResponse","maybeUpdateUiObjects","newError","result","options","_instanceCache","getDocument","ReactiveDocument","updateCacheForSuccess","record","data","records","didCommit","put","handleFetchSuccess","_enableAsyncFlush","_join","didRequest","finalPriority","_flush","updateCacheForError","undefined","commitWasRejected","handleFetchError","signal","aborted","isMut","willCommit","willRequest","then","_requestCache","_enqueue","recordIdentifier"],"mappings":";;;;AAYO,MAAMA,YAAY,GAAG,IAAIC,GAAG,CAAC,CAAC,cAAc,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;AAE9E,SAASC,eAAeA,CAC7BC,KAAY,EACZC,OAA6B,EAC7BC,cAAuB,EACvBC,UAA2C,EAClC;EACT,MAAM;AAAEC,IAAAA;AAAa,GAAC,GAAGH,OAAO;AAChC,EAAA,OACGA,OAAO,CAACI,EAAE,IAAIR,YAAY,CAACS,GAAG,CAACL,OAAO,CAACI,EAAE,CAAC,IAC3CD,YAAY,EAAEG,MAAM,IACpB,CAACL,cAAc,KACdF,KAAK,CAACQ,SAAS,IAAIL,UAAU,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A,EAAEtB,UAAU,CAAC+B,OAAO,CAAC5C,OAAO,CAAC,CAAA,GAAA,EAAA;;AAEzD;AACA;AACA,EAAA,MAAMoF,MAAM,GAAGxC,OAAO,CAAC5C,OAAO,CAACqF,IAAI,EAAED,MAAM,IAAIxC,OAAO,CAAC5C,OAAO,CAACsF,OAAO,GAAG,CAAC,CAAC;AAE3E,EAAA,OAAOvF,KAAK,CAAC0G,aAAa,CAACC,QAAQ,CAAChD,OAAO,EAAE;AAC3C2B,IAAAA,IAAI,EAAE,CAAC;AAAEjF,MAAAA,EAAE,EAAE,YAAY;AAAEuG,MAAAA,gBAAgB,EAAEvB,MAAM;AAAEL,MAAAA,OAAO,EAAEiB;KAAW;AAC3E,GAAC,CAAC;AACJ;;;;"}
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { setLogging, getRuntimeConfig } from "./types/runtime.js";
2
- import { a as cloneResponseProperties, I as IS_CACHE_HANDLER, b as assertValidRequest, e as executeNextHandler, d as getRequestResult, u as upgradePromise, s as setPromiseResult, f as clearRequestResult } from "./context-DE5sFezZ.js";
1
+ import { setLogging, getRuntimeConfig } from './types/runtime.js';
2
+ import { a as cloneResponseProperties, I as IS_CACHE_HANDLER, b as assertValidRequest, e as executeNextHandler, d as getRequestResult, u as upgradePromise, s as setPromiseResult, f as clearRequestResult } from "./context-COmAnXUQ.js";
3
3
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
- import { w as waitFor } from "./configure-Bz49BEZQ.js";
5
- import { peekUniversalTransient, setUniversalTransient } from "./types/-private.js";
6
- export { S as Store, r as recordIdentifierFor, K as setIdentifierForgetMethod, H as setIdentifierGenerationMethod, L as setIdentifierResetMethod, J as setIdentifierUpdateMethod, N as setKeyInfoForResource, s as storeFor } from "./request-state-Bv5CY_H0.js";
7
- export { C as CacheHandler } from "./handler-DYUefHNU.js";
4
+ import { w as waitFor } from "./configure-BgaZESRo.js";
5
+ import { peekUniversalTransient, setUniversalTransient } from './types/-private.js';
6
+ export { S as Store, r as recordIdentifierFor, K as setIdentifierForgetMethod, H as setIdentifierGenerationMethod, L as setIdentifierResetMethod, J as setIdentifierUpdateMethod, N as setKeyInfoForResource, s as storeFor } from "./request-state-DgwTEXLU.js";
7
+ export { C as CacheHandler } from "./handler-cHghx9Y9.js";
8
8
  import '@ember/debug';
9
- import "./utils/string.js";
9
+ import './utils/string.js';
10
10
 
11
11
  /**
12
12
  * A basic Fetch Handler which converts a request into a
@@ -1 +1 @@
1
- export { E as Editable, L as Legacy } from "../symbols-DyqeYQTe.js";
1
+ export { E as Editable, L as Legacy } from "../symbols-BmDcn6hS.js";
package/dist/reactive.js CHANGED
@@ -1,14 +1,14 @@
1
- import { isResourceSchema } from "./types/schema/fields.js";
2
- import { B as withSignalStore, w as entangleSignal, E as consumeInternalSignal, d as SOURCE$1, f as fastPush, x as defineSignal, l as RelatedCollection, F as getOrCreateInternalSignal, D as notifyInternalSignal, z as Signals, h as setRecordIdentifier, r as recordIdentifierFor } from "./request-state-Bv5CY_H0.js";
3
- import { EnableHydration, STRUCTURED } from "./types/request.js";
1
+ import { isResourceSchema } from './types/schema/fields.js';
2
+ import { B as withSignalStore, w as entangleSignal, E as consumeInternalSignal, d as SOURCE$1, f as fastPush, x as defineSignal, l as RelatedCollection, F as getOrCreateInternalSignal, D as notifyInternalSignal, z as Signals, h as setRecordIdentifier, r as recordIdentifierFor } from "./request-state-DgwTEXLU.js";
3
+ import { EnableHydration, STRUCTURED } from './types/request.js';
4
4
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
5
5
  import { deprecate } from '@ember/debug';
6
- import "./utils/string.js";
7
- import { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, c as createMemo } from "./configure-Bz49BEZQ.js";
8
- import { RecordStore, Type } from "./types/symbols.js";
9
- import { getOrSetGlobal } from "./types/-private.js";
10
- import { S as SOURCE, E as Editable, L as Legacy, I as Identifier, P as Parent, a as EmbeddedPath, D as Destroy, C as Checkout, b as EmbeddedType } from "./symbols-DyqeYQTe.js";
11
- import "./index.js";
6
+ import './utils/string.js';
7
+ import { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, c as createMemo } from "./configure-BgaZESRo.js";
8
+ import { RecordStore, Type } from './types/symbols.js';
9
+ import { getOrSetGlobal } from './types/-private.js';
10
+ import { S as SOURCE, E as Editable, L as Legacy, I as Identifier, P as Parent, a as EmbeddedPath, D as Destroy, C as Checkout, b as EmbeddedType } from "./symbols-BmDcn6hS.js";
11
+ import './index.js';
12
12
  const ARRAY_GETTER_METHODS = new Set([Symbol.iterator, 'concat', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'reduce', 'reduceRight', 'slice', 'some', 'values']);
13
13
  // const ARRAY_SETTER_METHODS = new Set<KeyType>(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
14
14
  const SYNC_PROPS = new Set(['[]', 'length']);
@@ -1,12 +1,12 @@
1
1
  import { deprecate, warn } from '@ember/debug';
2
2
  import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
3
- import { withBrand, EnableHydration, SkipCache } from "./types/request.js";
4
- import { setLogging, getRuntimeConfig } from "./types/runtime.js";
5
- import { getOrSetGlobal, peekTransient, setTransient } from "./types/-private.js";
6
- import { a as createSignal, b as consumeSignal, n as notifySignal, c as createMemo, d as willSyncFlushWatchers, A as ARRAY_SIGNAL } from "./configure-Bz49BEZQ.js";
7
- import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_IDENTIFIER_BUCKET, DEBUG_CLIENT_ORIGINATED } from "./types/identifier.js";
8
- import { dasherize } from "./utils/string.js";
9
- import { g as getPromiseResult, s as setPromiseResult } from "./context-DE5sFezZ.js";
3
+ import { withBrand, EnableHydration, SkipCache } from './types/request.js';
4
+ import { setLogging, getRuntimeConfig } from './types/runtime.js';
5
+ import { getOrSetGlobal, peekTransient, setTransient } from './types/-private.js';
6
+ import { a as createSignal, b as consumeSignal, n as notifySignal, c as createMemo, d as willSyncFlushWatchers, A as ARRAY_SIGNAL } from "./configure-BgaZESRo.js";
7
+ import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_IDENTIFIER_BUCKET, DEBUG_CLIENT_ORIGINATED } from './types/identifier.js';
8
+ import { dasherize } from './utils/string.js';
9
+ import { g as getPromiseResult, s as setPromiseResult } from "./context-COmAnXUQ.js";
10
10
  function coerceId(id) {
11
11
  if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_ID)) {
12
12
  let normalized;