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

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.
Files changed (30) hide show
  1. package/declarations/graph/-private/edges/implicit.d.ts +30 -0
  2. package/declarations/graph/-private/edges/implicit.d.ts.map +1 -1
  3. package/declarations/graph/-private/graph.d.ts.map +1 -1
  4. package/declarations/request/-private/fetch.d.ts +8 -16
  5. package/declarations/request/-private/fetch.d.ts.map +1 -1
  6. package/dist/{configure-Bz49BEZQ.js → configure-BgaZESRo.js} +1 -1
  7. package/dist/{configure-Bz49BEZQ.js.map → configure-BgaZESRo.js.map} +1 -1
  8. package/dist/configure.js +1 -1
  9. package/dist/{context-DE5sFezZ.js → context-COmAnXUQ.js} +2 -2
  10. package/dist/{context-DE5sFezZ.js.map → context-COmAnXUQ.js.map} +1 -1
  11. package/dist/graph/-private.js +37 -29
  12. package/dist/graph/-private.js.map +1 -1
  13. package/dist/{handler-DYUefHNU.js → handler-cHghx9Y9.js} +2 -2
  14. package/dist/{handler-DYUefHNU.js.map → handler-cHghx9Y9.js.map} +1 -1
  15. package/dist/index.js +15 -24
  16. package/dist/index.js.map +1 -1
  17. package/dist/reactive/-private.js +1 -1
  18. package/dist/reactive.js +9 -9
  19. package/dist/{request-state-Bv5CY_H0.js → request-state-DgwTEXLU.js} +7 -7
  20. package/dist/{request-state-Bv5CY_H0.js.map → request-state-DgwTEXLU.js.map} +1 -1
  21. package/dist/request.js +1 -1
  22. package/dist/store/-private.js +3 -3
  23. package/dist/store.js +1 -1
  24. package/dist/{symbols-DyqeYQTe.js → symbols-BmDcn6hS.js} +1 -1
  25. package/dist/{symbols-DyqeYQTe.js.map → symbols-BmDcn6hS.js.map} +1 -1
  26. package/dist/types/-private.js +1 -1
  27. package/dist/types/request.js +1 -1
  28. package/dist/types/runtime.js +1 -1
  29. package/dist/types/symbols.js +1 -1
  30. package/package.json +3 -3
@@ -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,IAA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O,CAAC,CAACwG,IAAI,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,SA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;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;;;;"}
package/dist/index.js CHANGED
@@ -1,25 +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";
10
-
11
- /**
12
- * A basic Fetch Handler which converts a request into a
13
- * `fetch` call presuming the response to be `json`.
14
- *
15
- * ```ts
16
- * import Fetch from '@ember-data/request/fetch';
17
- *
18
- * manager.use([Fetch]);
19
- * ```
20
- *
21
- * @module
22
- */
9
+ import './utils/string.js';
23
10
 
24
11
  // Lazily close over fetch to avoid breaking Mirage
25
12
  const _fetch = typeof fetch !== 'undefined' ? (...args) => fetch(...args) : typeof FastBoot !== 'undefined' ? (...args) => FastBoot.require('node-fetch')(...args) : () => {
@@ -40,16 +27,20 @@ const MUTATION_OPS = new Set(['updateRecord', 'createRecord', 'deleteRecord']);
40
27
  const ERROR_STATUS_CODE_FOR = new Map([[400, 'Bad Request'], [401, 'Unauthorized'], [402, 'Payment Required'], [403, 'Forbidden'], [404, 'Not Found'], [405, 'Method Not Allowed'], [406, 'Not Acceptable'], [407, 'Proxy Authentication Required'], [408, 'Request Timeout'], [409, 'Conflict'], [410, 'Gone'], [411, 'Length Required'], [412, 'Precondition Failed'], [413, 'Payload Too Large'], [414, 'URI Too Long'], [415, 'Unsupported Media Type'], [416, 'Range Not Satisfiable'], [417, 'Expectation Failed'], [419, 'Page Expired'], [420, 'Enhance Your Calm'], [421, 'Misdirected Request'], [422, 'Unprocessable Entity'], [423, 'Locked'], [424, 'Failed Dependency'], [425, 'Too Early'], [426, 'Upgrade Required'], [428, 'Precondition Required'], [429, 'Too Many Requests'], [430, 'Request Header Fields Too Large'], [431, 'Request Header Fields Too Large'], [450, 'Blocked By Windows Parental Controls'], [451, 'Unavailable For Legal Reasons'], [500, 'Internal Server Error'], [501, 'Not Implemented'], [502, 'Bad Gateway'], [503, 'Service Unavailable'], [504, 'Gateway Timeout'], [505, 'HTTP Version Not Supported'], [506, 'Variant Also Negotiates'], [507, 'Insufficient Storage'], [508, 'Loop Detected'], [509, 'Bandwidth Limit Exceeded'], [510, 'Not Extended'], [511, 'Network Authentication Required']]);
41
28
 
42
29
  /**
43
- * A basic handler which converts a request into a
30
+ * ```ts
31
+ * import { Fetch } from '@warp-drive/core';
32
+ * ```
33
+ *
34
+ * A basic Fetch Handler which converts a request into a
44
35
  * `fetch` call presuming the response to be `json`.
45
36
  *
46
37
  * ```ts
47
- * import Fetch from '@ember-data/request/fetch';
38
+ * import { RequestManager, Fetch } from '@warp-drive/core';
48
39
  *
49
- * manager.use([Fetch]);
40
+ * const manager = new RequestManager()
41
+ * .use([Fetch]);
50
42
  * ```
51
43
  *
52
- * @class Fetch
53
44
  * @public
54
45
  */
55
46
  const Fetch = {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/request/-private/fetch.ts","../src/request/-private/manager.ts","../src/index.ts"],"sourcesContent":["/**\n * A basic Fetch Handler which converts a request into a\n * `fetch` call presuming the response to be `json`.\n *\n * ```ts\n * import Fetch from '@ember-data/request/fetch';\n *\n * manager.use([Fetch]);\n * ```\n *\n * @module\n */\n\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport { cloneResponseProperties, type Context } from './context';\nimport type { HttpErrorProps } from './utils';\n\ninterface FastbootRequest extends Request {\n protocol: string;\n host: string;\n}\nexport interface FastBoot {\n require(moduleName: string): unknown;\n isFastBoot: boolean;\n request: FastbootRequest;\n}\n\n// Lazily close over fetch to avoid breaking Mirage\nconst _fetch: typeof fetch =\n typeof fetch !== 'undefined'\n ? (...args) => fetch(...args)\n : typeof FastBoot !== 'undefined'\n ? (...args) => ((FastBoot as FastBoot).require('node-fetch') as typeof fetch)(...args)\n : ((() => {\n throw new Error('No Fetch Implementation Found');\n }) as typeof fetch);\n\n// clones a response in a way that should still\n// allow it to stream\nfunction cloneResponse(response: Response, overrides: Partial<Response>) {\n const props = cloneResponseProperties(response);\n return new Response(response.body, Object.assign(props, overrides));\n}\n\nlet IS_MAYBE_MIRAGE = () => false;\nif (DEBUG) {\n IS_MAYBE_MIRAGE = () =>\n Boolean(\n typeof window !== 'undefined' &&\n ((window as { server?: { pretender: unknown } }).server?.pretender ||\n window.fetch.toString().replace(/\\s+/g, '') !== 'function fetch() { [native code] }'.replace(/\\s+/g, ''))\n );\n}\n\nconst MUTATION_OPS = new Set(['updateRecord', 'createRecord', 'deleteRecord']);\nconst ERROR_STATUS_CODE_FOR = new Map([\n [400, 'Bad Request'],\n [401, 'Unauthorized'],\n [402, 'Payment Required'],\n [403, 'Forbidden'],\n [404, 'Not Found'],\n [405, 'Method Not Allowed'],\n [406, 'Not Acceptable'],\n [407, 'Proxy Authentication Required'],\n [408, 'Request Timeout'],\n [409, 'Conflict'],\n [410, 'Gone'],\n [411, 'Length Required'],\n [412, 'Precondition Failed'],\n [413, 'Payload Too Large'],\n [414, 'URI Too Long'],\n [415, 'Unsupported Media Type'],\n [416, 'Range Not Satisfiable'],\n [417, 'Expectation Failed'],\n [419, 'Page Expired'],\n [420, 'Enhance Your Calm'],\n [421, 'Misdirected Request'],\n [422, 'Unprocessable Entity'],\n [423, 'Locked'],\n [424, 'Failed Dependency'],\n [425, 'Too Early'],\n [426, 'Upgrade Required'],\n [428, 'Precondition Required'],\n [429, 'Too Many Requests'],\n [430, 'Request Header Fields Too Large'],\n [431, 'Request Header Fields Too Large'],\n [450, 'Blocked By Windows Parental Controls'],\n [451, 'Unavailable For Legal Reasons'],\n [500, 'Internal Server Error'],\n [501, 'Not Implemented'],\n [502, 'Bad Gateway'],\n [503, 'Service Unavailable'],\n [504, 'Gateway Timeout'],\n [505, 'HTTP Version Not Supported'],\n [506, 'Variant Also Negotiates'],\n [507, 'Insufficient Storage'],\n [508, 'Loop Detected'],\n [509, 'Bandwidth Limit Exceeded'],\n [510, 'Not Extended'],\n [511, 'Network Authentication Required'],\n]);\n\n/**\n * A basic handler which converts a request into a\n * `fetch` call presuming the response to be `json`.\n *\n * ```ts\n * import Fetch from '@ember-data/request/fetch';\n *\n * manager.use([Fetch]);\n * ```\n *\n * @class Fetch\n * @public\n */\nconst Fetch = {\n async request<T>(context: Context): Promise<T> {\n let response: Response;\n\n try {\n assert(\n 'The Fetch handler expects the request to have a URL, none was provided.',\n context.request.url && typeof context.request.url === 'string'\n );\n response = await _fetch(context.request.url, context.request);\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') {\n (e as HttpErrorProps).statusText = 'Aborted';\n (e as HttpErrorProps).status = 20;\n (e as HttpErrorProps).isRequestError = true;\n } else {\n (e as HttpErrorProps).statusText = 'Unknown Network Error';\n (e as HttpErrorProps).status = 0;\n (e as HttpErrorProps).isRequestError = true;\n }\n throw e;\n }\n\n const isError = !response.ok || response.status >= 400;\n const op = context.request.op;\n const isMutationOp = Boolean(op && MUTATION_OPS.has(op));\n\n if (!isError && !isMutationOp && response.status !== 204 && !response.headers.has('date')) {\n if (IS_MAYBE_MIRAGE()) {\n response.headers.set('date', new Date().toUTCString());\n } else {\n const headers = new Headers(response.headers);\n headers.set('date', new Date().toUTCString());\n response = cloneResponse(response, {\n headers,\n });\n }\n }\n\n context.setResponse(response);\n\n if (response.status === 204) {\n return null as T;\n }\n\n let text = '';\n // if we are in a mirage context, we cannot support streaming\n if (IS_MAYBE_MIRAGE()) {\n text = await response.text();\n } else {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let isStreaming = context.hasRequestedStream;\n let stream: TransformStream | null = isStreaming ? new TransformStream() : null;\n let writer = stream?.writable.getWriter();\n\n if (isStreaming) {\n // Listen for the abort event on the AbortSignal\n context.request.signal?.addEventListener('abort', () => {\n if (!isStreaming) {\n return;\n }\n void stream!.writable.abort('Request Aborted');\n void stream!.readable.cancel('Request Aborted');\n });\n context.setStream(stream!.readable);\n }\n\n while (true) {\n // we manually read the stream instead of using `response.json()`\n // or `response.text()` because if we need to stream the body\n // we need to be able to pass the stream along efficiently.\n const { done, value } = await reader.read();\n if (done) {\n if (isStreaming) {\n isStreaming = false;\n await writer!.ready;\n await writer!.close();\n }\n break;\n }\n text += decoder.decode(value, { stream: true });\n\n // if we are streaming, we want to pass the stream along\n if (isStreaming) {\n await writer!.ready;\n await writer!.write(value);\n } else if (context.hasRequestedStream) {\n const encode = new TextEncoder();\n isStreaming = true;\n stream = new TransformStream();\n // Listen for the abort event on the AbortSignal\n // eslint-disable-next-line @typescript-eslint/no-loop-func\n context.request.signal?.addEventListener('abort', () => {\n if (!isStreaming) {\n return;\n }\n void stream!.writable.abort('Request Aborted');\n void stream!.readable.cancel('Request Aborted');\n });\n context.setStream(stream.readable);\n writer = stream.writable.getWriter();\n await writer.ready;\n await writer.write(encode.encode(text));\n await writer.ready;\n await writer.write(value);\n }\n }\n\n if (isStreaming) {\n isStreaming = false;\n await writer!.ready;\n await writer!.close();\n }\n }\n // if we are an error, we will want to throw\n if (isError) {\n let errorPayload: object | undefined;\n try {\n errorPayload = JSON.parse(text) as object;\n } catch {\n // void;\n }\n // attempt errors discovery\n const errors = Array.isArray(errorPayload)\n ? errorPayload\n : isDict(errorPayload) && Array.isArray(errorPayload.errors)\n ? errorPayload.errors\n : null;\n\n const statusText = response.statusText || ERROR_STATUS_CODE_FOR.get(response.status) || 'Unknown Request Error';\n const msg = `[${response.status} ${statusText}] ${context.request.method ?? 'GET'} (${response.type}) - ${\n response.url\n }`;\n\n const error = (errors ? new AggregateError(errors, msg) : new Error(msg)) as Error & {\n content: object | undefined;\n } & HttpErrorProps;\n error.status = response.status;\n error.statusText = statusText;\n error.isRequestError = true;\n error.code = error.status;\n error.name = error.statusText.replaceAll(' ', '') + 'Error';\n error.content = errorPayload;\n throw error;\n } else {\n return JSON.parse(text) as T;\n }\n },\n};\n\nfunction isDict(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object';\n}\n\nexport { Fetch };\n","import { DEBUG, TESTING } from '@warp-drive/core/build-config/env';\n\nimport { waitFor } from '../../store/-private/new-core-tmp/reactivity/configure';\nimport { peekUniversalTransient, setUniversalTransient } from '../../types/-private';\nimport type { StableDocumentIdentifier } from '../../types/identifier';\nimport type { RequestInfo, StructuredErrorDocument } from '../../types/request';\nimport { assertValidRequest } from './debug';\nimport { upgradePromise } from './future';\nimport { clearRequestResult, getRequestResult, setPromiseResult } from './promise-cache';\nimport type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from './types';\nimport { executeNextHandler, IS_CACHE_HANDLER } from './utils';\n\n/**\n * ## Import\n *\n * ```js\n * import { RequestManager } from '@warp-drive/core';\n * ```\n *\n * For complete usage guide see the [RequestManager Documentation](/guides/).\n *\n * ## How It Works\n *\n * ```ts\n * interface RequestManager {\n * request<T>(req: RequestInfo): Future<T>;\n * }\n * ```\n *\n * A RequestManager provides a request/response flow in which configured\n * handlers are successively given the opportunity to handle, modify, or\n * pass-along a request.\n *\n * <img src=\"/images/handlers-all-labeled.gif\" alt=\"RequestManager Flow Animation\" width=\"100%\" />\n *\n * For example:\n *\n * ::: code-group\n *\n * ```ts [Setup.ts]\n * import { RequestManager, Fetch } from '@warp-drive/core';\n * import { AutoCompress } from '@warp-drive/utilities/handlers';\n * import Auth from 'ember-simple-auth/handler';\n *\n * // ... create manager\n * const manager = new RequestManager()\n * .use([Auth, new AutoCompress(), Fetch]); // [!code focus]\n * ```\n *\n * ```ts [Usage.ts]\n * import Config from './config';\n *\n * const { apiUrl } = Config;\n *\n * // ... execute a request\n * const response = await manager.request({\n * url: `${apiUrl}/users`\n * });\n * ```\n *\n * :::\n *\n * ### Futures\n *\n * The return value of `manager.request` is a `Future`, which allows\n * access to limited information about the request while it is still\n * pending and fulfills with the final state when the request completes.\n *\n * A `Future` is cancellable via `abort`.\n *\n * Handlers may optionally expose a `ReadableStream` to the `Future` for\n * streaming data; however, when doing so the future should not resolve\n * until the response stream is fully read.\n *\n * ```ts\n * interface Future<T> extends Promise<StructuredDocument<T>> {\n * abort(): void;\n *\n * async getStream(): ReadableStream | null;\n * }\n * ```\n *\n * ### StructuredDocuments\n *\n * A Future resolves with a `StructuredDataDocument` or rejects with a `StructuredErrorDocument`.\n *\n * ```ts\n * interface StructuredDataDocument<T> {\n * request: ImmutableRequestInfo;\n * response: ImmutableResponseInfo;\n * content: T;\n * }\n * interface StructuredErrorDocument extends Error {\n * request: ImmutableRequestInfo;\n * response: ImmutableResponseInfo;\n * error: string | object;\n * }\n * type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;\n * ```\n *\n * @class RequestManager\n * @public\n */\nexport class RequestManager {\n #handlers: Handler[] = [];\n /** @internal */\n declare _hasCacheHandler: boolean;\n /**\n * A map of pending requests from request.id to their\n * associated CacheHandler promise.\n *\n * This queue is managed by the CacheHandler\n *\n * @internal\n */\n declare _pending: Map<number, Promise<unknown>>;\n /** @internal */\n declare _deduped: Map<StableDocumentIdentifier, { priority: ManagedRequestPriority; promise: Promise<unknown> }>;\n\n constructor(options?: GenericCreateArgs) {\n Object.assign(this, options);\n this._pending = new Map();\n this._deduped = new Map();\n }\n\n /**\n * Register a handler to use for primary cache intercept.\n *\n * Only one such handler may exist. If using the same\n * RequestManager as the Store instance the Store\n * registers itself as a Cache handler.\n *\n * @public\n */\n useCache(cacheHandler: CacheHandler & { [IS_CACHE_HANDLER]?: true }): this {\n if (DEBUG) {\n if (this._hasCacheHandler) {\n throw new Error(`\\`RequestManager.useCache(<handler>)\\` May only be invoked once.`);\n }\n if (Object.isFrozen(this.#handlers)) {\n throw new Error(\n `\\`RequestManager.useCache(<handler>)\\` May only be invoked prior to any request having been made.`\n );\n }\n this._hasCacheHandler = true;\n }\n cacheHandler[IS_CACHE_HANDLER] = true;\n this.#handlers.unshift(cacheHandler as Handler);\n return this;\n }\n\n /**\n * Register handler(s) to use when a request is issued.\n *\n * Handlers will be invoked in the order they are registered.\n * Each Handler is given the opportunity to handle the request,\n * curry the request, or pass along a modified request.\n *\n * @public\n * @param {Handler[]} newHandlers\n * @return {ThisType}\n */\n use(newHandlers: Handler[]): this {\n const handlers = this.#handlers;\n if (DEBUG) {\n if (Object.isFrozen(handlers)) {\n throw new Error(`Cannot add a Handler to a RequestManager after a request has been made`);\n }\n if (!Array.isArray(newHandlers)) {\n throw new Error(\n `\\`RequestManager.use(<Handler[]>)\\` expects an array of handlers, but was called with \\`${typeof newHandlers}\\``\n );\n }\n newHandlers.forEach((handler, index) => {\n if (\n !handler ||\n (typeof handler !== 'function' && typeof handler !== 'object') ||\n typeof handler.request !== 'function'\n ) {\n throw new Error(\n `\\`RequestManager.use(<Handler[]>)\\` expected to receive an array of handler objects with request methods, by the handler at index ${index} does not conform.`\n );\n }\n });\n }\n handlers.push(...newHandlers);\n return this;\n }\n\n /**\n * Issue a Request.\n *\n * Returns a Future that fulfills with a StructuredDocument\n *\n * @public\n * @param {RequestInfo} request\n * @return {Future}\n */\n request<RT, T = unknown>(request: RequestInfo<RT, T>): Future<RT> {\n const handlers = this.#handlers;\n if (DEBUG) {\n if (!Object.isFrozen(handlers)) {\n Object.freeze(handlers);\n }\n assertValidRequest(request, true);\n }\n\n const controller = request.controller || new AbortController();\n if (request.controller) {\n delete request.controller;\n }\n\n const requestId = peekUniversalTransient<number>('REQ_ID') ?? 0;\n setUniversalTransient('REQ_ID', requestId + 1);\n\n const context = {\n controller,\n response: null,\n stream: null,\n hasRequestedStream: false,\n id: requestId,\n identifier: null,\n };\n const promise = executeNextHandler<RT>(handlers, request, 0, context);\n\n // the cache handler will set the result of the request synchronously\n // if it is able to fulfill the request from the cache\n const cacheResult = getRequestResult(requestId);\n\n if (TESTING) {\n if (!request.disableTestWaiter) {\n const newPromise = waitFor(promise);\n const finalPromise = upgradePromise(\n newPromise.then(\n (result) => {\n setPromiseResult(finalPromise, { isError: false, result });\n clearRequestResult(requestId);\n return result;\n },\n (error: StructuredErrorDocument) => {\n setPromiseResult(finalPromise, { isError: true, result: error });\n clearRequestResult(requestId);\n throw error;\n }\n ),\n promise\n );\n\n if (cacheResult) {\n setPromiseResult(finalPromise, cacheResult);\n }\n\n return finalPromise;\n }\n }\n\n // const promise1 = store.request(myRequest);\n // const promise2 = store.request(myRequest);\n // promise1 === promise2; // false\n // either we need to make promise1 === promise2, or we need to make sure that\n // we need to have a way to key from request to result\n // such that we can lookup the result here and return it if it exists\n const finalPromise = upgradePromise(\n promise.then(\n (result) => {\n setPromiseResult(finalPromise, { isError: false, result });\n clearRequestResult(requestId);\n return result;\n },\n (error: StructuredErrorDocument) => {\n setPromiseResult(finalPromise, { isError: true, result: error });\n clearRequestResult(requestId);\n throw error;\n }\n ),\n promise\n );\n\n if (cacheResult) {\n setPromiseResult(finalPromise, cacheResult);\n }\n\n return finalPromise;\n }\n\n /**\n * This method exists so that the RequestManager can be created\n * can be created by container/factory systems that expect to\n * call a static `create` method to instantiate the class.\n *\n * Using `new RequestManager()` directly is preferred.\n *\n * @private\n */\n static create(options?: GenericCreateArgs) {\n return new this(options);\n }\n}\n","/**\n * @module\n * @mergeModuleWith <project>\n */\n\nimport type { ReactiveDocument } from './reactive/-private/document.ts';\nimport { getRuntimeConfig, setLogging } from './types/runtime.ts';\n\nexport { Fetch } from './request/-private/fetch.ts';\nexport { RequestManager } from './request/-private/manager.ts';\n\n// @ts-expect-error adding to globalThis\nglobalThis.setWarpDriveLogging = setLogging;\n\n// @ts-expect-error adding to globalThis\nglobalThis.getWarpDriveRuntimeConfig = getRuntimeConfig;\n\nexport {\n Store,\n type StoreRequestContext,\n CacheHandler,\n type CachePolicy,\n type StoreRequestInput,\n recordIdentifierFor,\n storeFor,\n} from './store/-private.ts';\n\n/**\n * @deprecated use `ReactiveDocument` instead\n */\nexport type Document<T> = ReactiveDocument<T>;\n\nexport type {\n DocumentCacheOperation,\n CacheOperation,\n NotificationType,\n} from './store/-private/managers/notification-manager.ts';\n\nexport {\n setIdentifierGenerationMethod,\n setIdentifierUpdateMethod,\n setIdentifierForgetMethod,\n setIdentifierResetMethod,\n setKeyInfoForResource,\n} from './store/-private/caches/identifier-cache.ts';\n"],"names":["_fetch","fetch","args","FastBoot","require","Error","cloneResponse","response","overrides","props","cloneResponseProperties","Response","body","Object","assign","IS_MAYBE_MIRAGE","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","Boolean","window","server","pretender","toString","replace","MUTATION_OPS","Set","ERROR_STATUS_CODE_FOR","Map","Fetch","request","context","test","url","e","DOMException","name","statusText","status","isRequestError","isError","ok","op","isMutationOp","has","headers","set","Date","toUTCString","Headers","setResponse","text","reader","getReader","decoder","TextDecoder","isStreaming","hasRequestedStream","stream","TransformStream","writer","writable","getWriter","signal","addEventListener","abort","readable","cancel","setStream","done","value","read","ready","close","decode","write","encode","TextEncoder","errorPayload","JSON","parse","errors","Array","isArray","isDict","get","msg","method","type","error","AggregateError","code","replaceAll","content","v","RequestManager","constructor","options","_pending","_deduped","useCache","cacheHandler","_hasCacheHandler","isFrozen","IS_CACHE_HANDLER","unshift","use","newHandlers","handlers","forEach","handler","index","push","freeze","assertValidRequest","controller","AbortController","requestId","peekUniversalTransient","setUniversalTransient","id","identifier","promise","executeNextHandler","cacheResult","getRequestResult","TESTING","disableTestWaiter","newPromise","waitFor","finalPromise","upgradePromise","then","result","setPromiseResult","clearRequestResult","create","globalThis","setWarpDriveLogging","setLogging","getWarpDriveRuntimeConfig","getRuntimeConfig"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA;AACA,MAAMA,MAAoB,GACxB,OAAOC,KAAK,KAAK,WAAW,GACxB,CAAC,GAAGC,IAAI,KAAKD,KAAK,CAAC,GAAGC,IAAI,CAAC,GAC3B,OAAOC,QAAQ,KAAK,WAAW,GAC7B,CAAC,GAAGD,IAAI,KAAOC,QAAQ,CAAcC,OAAO,CAAC,YAAY,CAAC,CAAkB,GAAGF,IAAI,CAAC,GAClF,MAAM;AACN,EAAA,MAA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B,CAACJ,YAAY,EAAE;AAAE1F,QAAAA,OAAO,EAAE,KAAK;AAAE6F,QAAAA;AAAO,OAAC,CAAC;MAC1DE,kBAAkB,CAAClB,SAAS,CAAC;AAC7B,MAAA,OAAOgB,MAAM;KACd,EACA5C,KAA8B,IAAK;MAClC6C,gBAAgB,CAACJ,YAAY,EAAE;AAAE1F,QAAAA,OAAO,EAAE,IAAI;AAAE6F,QAAAA,MAAM,EAAE5C;AAAM,OAAC,CAAC;MAChE8C,kBAAkB,CAAClB,SAAS,CAAC;AAC7B,MAAA,MAAM5B,KAAK;KAEf,CAAC,EACDiC,OACF,CAAC;AAED,IAAA,IAAIE,WAAW,EAAE;AACfU,MAAAA,gBAAgB,CAACJ,YAAY,EAAEN,WAAW,CAAC;AAC7C;AAEA,IAAA,OAAOM,YAAY;AACrB;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOM,MAAMA,CAACvC,OAA2B,EAAE;AACzC,IAAA,OAAO,IAAI,IAAI,CAACA,OAAO,CAAC;AAC1B;AACF;;ACzSA;AACA;AACA;AACA;;;AAQA;AACAwC,UAAU,CAACC,mBAAmB,GAAGC,UAAU;;AAE3C;AACAF,UAAU,CAACG,yBAAyB,GAAGC,gBAAgB;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/request/-private/fetch.ts","../src/request/-private/manager.ts","../src/index.ts"],"sourcesContent":["import { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\n\nimport { cloneResponseProperties, type Context } from './context';\nimport type { HttpErrorProps } from './utils';\n\ninterface FastbootRequest extends Request {\n protocol: string;\n host: string;\n}\nexport interface FastBoot {\n require(moduleName: string): unknown;\n isFastBoot: boolean;\n request: FastbootRequest;\n}\n\n// Lazily close over fetch to avoid breaking Mirage\nconst _fetch: typeof fetch =\n typeof fetch !== 'undefined'\n ? (...args) => fetch(...args)\n : typeof FastBoot !== 'undefined'\n ? (...args) => ((FastBoot as FastBoot).require('node-fetch') as typeof fetch)(...args)\n : ((() => {\n throw new Error('No Fetch Implementation Found');\n }) as typeof fetch);\n\n// clones a response in a way that should still\n// allow it to stream\nfunction cloneResponse(response: Response, overrides: Partial<Response>) {\n const props = cloneResponseProperties(response);\n return new Response(response.body, Object.assign(props, overrides));\n}\n\nlet IS_MAYBE_MIRAGE = () => false;\nif (DEBUG) {\n IS_MAYBE_MIRAGE = () =>\n Boolean(\n typeof window !== 'undefined' &&\n ((window as { server?: { pretender: unknown } }).server?.pretender ||\n window.fetch.toString().replace(/\\s+/g, '') !== 'function fetch() { [native code] }'.replace(/\\s+/g, ''))\n );\n}\n\nconst MUTATION_OPS = new Set(['updateRecord', 'createRecord', 'deleteRecord']);\nconst ERROR_STATUS_CODE_FOR = new Map([\n [400, 'Bad Request'],\n [401, 'Unauthorized'],\n [402, 'Payment Required'],\n [403, 'Forbidden'],\n [404, 'Not Found'],\n [405, 'Method Not Allowed'],\n [406, 'Not Acceptable'],\n [407, 'Proxy Authentication Required'],\n [408, 'Request Timeout'],\n [409, 'Conflict'],\n [410, 'Gone'],\n [411, 'Length Required'],\n [412, 'Precondition Failed'],\n [413, 'Payload Too Large'],\n [414, 'URI Too Long'],\n [415, 'Unsupported Media Type'],\n [416, 'Range Not Satisfiable'],\n [417, 'Expectation Failed'],\n [419, 'Page Expired'],\n [420, 'Enhance Your Calm'],\n [421, 'Misdirected Request'],\n [422, 'Unprocessable Entity'],\n [423, 'Locked'],\n [424, 'Failed Dependency'],\n [425, 'Too Early'],\n [426, 'Upgrade Required'],\n [428, 'Precondition Required'],\n [429, 'Too Many Requests'],\n [430, 'Request Header Fields Too Large'],\n [431, 'Request Header Fields Too Large'],\n [450, 'Blocked By Windows Parental Controls'],\n [451, 'Unavailable For Legal Reasons'],\n [500, 'Internal Server Error'],\n [501, 'Not Implemented'],\n [502, 'Bad Gateway'],\n [503, 'Service Unavailable'],\n [504, 'Gateway Timeout'],\n [505, 'HTTP Version Not Supported'],\n [506, 'Variant Also Negotiates'],\n [507, 'Insufficient Storage'],\n [508, 'Loop Detected'],\n [509, 'Bandwidth Limit Exceeded'],\n [510, 'Not Extended'],\n [511, 'Network Authentication Required'],\n]);\n\n/**\n * ```ts\n * import { Fetch } from '@warp-drive/core';\n * ```\n *\n * A basic Fetch Handler which converts a request into a\n * `fetch` call presuming the response to be `json`.\n *\n * ```ts\n * import { RequestManager, Fetch } from '@warp-drive/core';\n *\n * const manager = new RequestManager()\n * .use([Fetch]);\n * ```\n *\n * @public\n */\nconst Fetch = {\n async request<T>(context: Context): Promise<T> {\n let response: Response;\n\n try {\n assert(\n 'The Fetch handler expects the request to have a URL, none was provided.',\n context.request.url && typeof context.request.url === 'string'\n );\n response = await _fetch(context.request.url, context.request);\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') {\n (e as HttpErrorProps).statusText = 'Aborted';\n (e as HttpErrorProps).status = 20;\n (e as HttpErrorProps).isRequestError = true;\n } else {\n (e as HttpErrorProps).statusText = 'Unknown Network Error';\n (e as HttpErrorProps).status = 0;\n (e as HttpErrorProps).isRequestError = true;\n }\n throw e;\n }\n\n const isError = !response.ok || response.status >= 400;\n const op = context.request.op;\n const isMutationOp = Boolean(op && MUTATION_OPS.has(op));\n\n if (!isError && !isMutationOp && response.status !== 204 && !response.headers.has('date')) {\n if (IS_MAYBE_MIRAGE()) {\n response.headers.set('date', new Date().toUTCString());\n } else {\n const headers = new Headers(response.headers);\n headers.set('date', new Date().toUTCString());\n response = cloneResponse(response, {\n headers,\n });\n }\n }\n\n context.setResponse(response);\n\n if (response.status === 204) {\n return null as T;\n }\n\n let text = '';\n // if we are in a mirage context, we cannot support streaming\n if (IS_MAYBE_MIRAGE()) {\n text = await response.text();\n } else {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let isStreaming = context.hasRequestedStream;\n let stream: TransformStream | null = isStreaming ? new TransformStream() : null;\n let writer = stream?.writable.getWriter();\n\n if (isStreaming) {\n // Listen for the abort event on the AbortSignal\n context.request.signal?.addEventListener('abort', () => {\n if (!isStreaming) {\n return;\n }\n void stream!.writable.abort('Request Aborted');\n void stream!.readable.cancel('Request Aborted');\n });\n context.setStream(stream!.readable);\n }\n\n while (true) {\n // we manually read the stream instead of using `response.json()`\n // or `response.text()` because if we need to stream the body\n // we need to be able to pass the stream along efficiently.\n const { done, value } = await reader.read();\n if (done) {\n if (isStreaming) {\n isStreaming = false;\n await writer!.ready;\n await writer!.close();\n }\n break;\n }\n text += decoder.decode(value, { stream: true });\n\n // if we are streaming, we want to pass the stream along\n if (isStreaming) {\n await writer!.ready;\n await writer!.write(value);\n } else if (context.hasRequestedStream) {\n const encode = new TextEncoder();\n isStreaming = true;\n stream = new TransformStream();\n // Listen for the abort event on the AbortSignal\n // eslint-disable-next-line @typescript-eslint/no-loop-func\n context.request.signal?.addEventListener('abort', () => {\n if (!isStreaming) {\n return;\n }\n void stream!.writable.abort('Request Aborted');\n void stream!.readable.cancel('Request Aborted');\n });\n context.setStream(stream.readable);\n writer = stream.writable.getWriter();\n await writer.ready;\n await writer.write(encode.encode(text));\n await writer.ready;\n await writer.write(value);\n }\n }\n\n if (isStreaming) {\n isStreaming = false;\n await writer!.ready;\n await writer!.close();\n }\n }\n // if we are an error, we will want to throw\n if (isError) {\n let errorPayload: object | undefined;\n try {\n errorPayload = JSON.parse(text) as object;\n } catch {\n // void;\n }\n // attempt errors discovery\n const errors = Array.isArray(errorPayload)\n ? errorPayload\n : isDict(errorPayload) && Array.isArray(errorPayload.errors)\n ? errorPayload.errors\n : null;\n\n const statusText = response.statusText || ERROR_STATUS_CODE_FOR.get(response.status) || 'Unknown Request Error';\n const msg = `[${response.status} ${statusText}] ${context.request.method ?? 'GET'} (${response.type}) - ${\n response.url\n }`;\n\n const error = (errors ? new AggregateError(errors, msg) : new Error(msg)) as Error & {\n content: object | undefined;\n } & HttpErrorProps;\n error.status = response.status;\n error.statusText = statusText;\n error.isRequestError = true;\n error.code = error.status;\n error.name = error.statusText.replaceAll(' ', '') + 'Error';\n error.content = errorPayload;\n throw error;\n } else {\n return JSON.parse(text) as T;\n }\n },\n};\n\nfunction isDict(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object';\n}\n\nexport { Fetch };\n","import { DEBUG, TESTING } from '@warp-drive/core/build-config/env';\n\nimport { waitFor } from '../../store/-private/new-core-tmp/reactivity/configure';\nimport { peekUniversalTransient, setUniversalTransient } from '../../types/-private';\nimport type { StableDocumentIdentifier } from '../../types/identifier';\nimport type { RequestInfo, StructuredErrorDocument } from '../../types/request';\nimport { assertValidRequest } from './debug';\nimport { upgradePromise } from './future';\nimport { clearRequestResult, getRequestResult, setPromiseResult } from './promise-cache';\nimport type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from './types';\nimport { executeNextHandler, IS_CACHE_HANDLER } from './utils';\n\n/**\n * ## Import\n *\n * ```js\n * import { RequestManager } from '@warp-drive/core';\n * ```\n *\n * For complete usage guide see the [RequestManager Documentation](/guides/).\n *\n * ## How It Works\n *\n * ```ts\n * interface RequestManager {\n * request<T>(req: RequestInfo): Future<T>;\n * }\n * ```\n *\n * A RequestManager provides a request/response flow in which configured\n * handlers are successively given the opportunity to handle, modify, or\n * pass-along a request.\n *\n * <img src=\"/images/handlers-all-labeled.gif\" alt=\"RequestManager Flow Animation\" width=\"100%\" />\n *\n * For example:\n *\n * ::: code-group\n *\n * ```ts [Setup.ts]\n * import { RequestManager, Fetch } from '@warp-drive/core';\n * import { AutoCompress } from '@warp-drive/utilities/handlers';\n * import Auth from 'ember-simple-auth/handler';\n *\n * // ... create manager\n * const manager = new RequestManager()\n * .use([Auth, new AutoCompress(), Fetch]); // [!code focus]\n * ```\n *\n * ```ts [Usage.ts]\n * import Config from './config';\n *\n * const { apiUrl } = Config;\n *\n * // ... execute a request\n * const response = await manager.request({\n * url: `${apiUrl}/users`\n * });\n * ```\n *\n * :::\n *\n * ### Futures\n *\n * The return value of `manager.request` is a `Future`, which allows\n * access to limited information about the request while it is still\n * pending and fulfills with the final state when the request completes.\n *\n * A `Future` is cancellable via `abort`.\n *\n * Handlers may optionally expose a `ReadableStream` to the `Future` for\n * streaming data; however, when doing so the future should not resolve\n * until the response stream is fully read.\n *\n * ```ts\n * interface Future<T> extends Promise<StructuredDocument<T>> {\n * abort(): void;\n *\n * async getStream(): ReadableStream | null;\n * }\n * ```\n *\n * ### StructuredDocuments\n *\n * A Future resolves with a `StructuredDataDocument` or rejects with a `StructuredErrorDocument`.\n *\n * ```ts\n * interface StructuredDataDocument<T> {\n * request: ImmutableRequestInfo;\n * response: ImmutableResponseInfo;\n * content: T;\n * }\n * interface StructuredErrorDocument extends Error {\n * request: ImmutableRequestInfo;\n * response: ImmutableResponseInfo;\n * error: string | object;\n * }\n * type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;\n * ```\n *\n * @class RequestManager\n * @public\n */\nexport class RequestManager {\n #handlers: Handler[] = [];\n /** @internal */\n declare _hasCacheHandler: boolean;\n /**\n * A map of pending requests from request.id to their\n * associated CacheHandler promise.\n *\n * This queue is managed by the CacheHandler\n *\n * @internal\n */\n declare _pending: Map<number, Promise<unknown>>;\n /** @internal */\n declare _deduped: Map<StableDocumentIdentifier, { priority: ManagedRequestPriority; promise: Promise<unknown> }>;\n\n constructor(options?: GenericCreateArgs) {\n Object.assign(this, options);\n this._pending = new Map();\n this._deduped = new Map();\n }\n\n /**\n * Register a handler to use for primary cache intercept.\n *\n * Only one such handler may exist. If using the same\n * RequestManager as the Store instance the Store\n * registers itself as a Cache handler.\n *\n * @public\n */\n useCache(cacheHandler: CacheHandler & { [IS_CACHE_HANDLER]?: true }): this {\n if (DEBUG) {\n if (this._hasCacheHandler) {\n throw new Error(`\\`RequestManager.useCache(<handler>)\\` May only be invoked once.`);\n }\n if (Object.isFrozen(this.#handlers)) {\n throw new Error(\n `\\`RequestManager.useCache(<handler>)\\` May only be invoked prior to any request having been made.`\n );\n }\n this._hasCacheHandler = true;\n }\n cacheHandler[IS_CACHE_HANDLER] = true;\n this.#handlers.unshift(cacheHandler as Handler);\n return this;\n }\n\n /**\n * Register handler(s) to use when a request is issued.\n *\n * Handlers will be invoked in the order they are registered.\n * Each Handler is given the opportunity to handle the request,\n * curry the request, or pass along a modified request.\n *\n * @public\n * @param {Handler[]} newHandlers\n * @return {ThisType}\n */\n use(newHandlers: Handler[]): this {\n const handlers = this.#handlers;\n if (DEBUG) {\n if (Object.isFrozen(handlers)) {\n throw new Error(`Cannot add a Handler to a RequestManager after a request has been made`);\n }\n if (!Array.isArray(newHandlers)) {\n throw new Error(\n `\\`RequestManager.use(<Handler[]>)\\` expects an array of handlers, but was called with \\`${typeof newHandlers}\\``\n );\n }\n newHandlers.forEach((handler, index) => {\n if (\n !handler ||\n (typeof handler !== 'function' && typeof handler !== 'object') ||\n typeof handler.request !== 'function'\n ) {\n throw new Error(\n `\\`RequestManager.use(<Handler[]>)\\` expected to receive an array of handler objects with request methods, by the handler at index ${index} does not conform.`\n );\n }\n });\n }\n handlers.push(...newHandlers);\n return this;\n }\n\n /**\n * Issue a Request.\n *\n * Returns a Future that fulfills with a StructuredDocument\n *\n * @public\n * @param {RequestInfo} request\n * @return {Future}\n */\n request<RT, T = unknown>(request: RequestInfo<RT, T>): Future<RT> {\n const handlers = this.#handlers;\n if (DEBUG) {\n if (!Object.isFrozen(handlers)) {\n Object.freeze(handlers);\n }\n assertValidRequest(request, true);\n }\n\n const controller = request.controller || new AbortController();\n if (request.controller) {\n delete request.controller;\n }\n\n const requestId = peekUniversalTransient<number>('REQ_ID') ?? 0;\n setUniversalTransient('REQ_ID', requestId + 1);\n\n const context = {\n controller,\n response: null,\n stream: null,\n hasRequestedStream: false,\n id: requestId,\n identifier: null,\n };\n const promise = executeNextHandler<RT>(handlers, request, 0, context);\n\n // the cache handler will set the result of the request synchronously\n // if it is able to fulfill the request from the cache\n const cacheResult = getRequestResult(requestId);\n\n if (TESTING) {\n if (!request.disableTestWaiter) {\n const newPromise = waitFor(promise);\n const finalPromise = upgradePromise(\n newPromise.then(\n (result) => {\n setPromiseResult(finalPromise, { isError: false, result });\n clearRequestResult(requestId);\n return result;\n },\n (error: StructuredErrorDocument) => {\n setPromiseResult(finalPromise, { isError: true, result: error });\n clearRequestResult(requestId);\n throw error;\n }\n ),\n promise\n );\n\n if (cacheResult) {\n setPromiseResult(finalPromise, cacheResult);\n }\n\n return finalPromise;\n }\n }\n\n // const promise1 = store.request(myRequest);\n // const promise2 = store.request(myRequest);\n // promise1 === promise2; // false\n // either we need to make promise1 === promise2, or we need to make sure that\n // we need to have a way to key from request to result\n // such that we can lookup the result here and return it if it exists\n const finalPromise = upgradePromise(\n promise.then(\n (result) => {\n setPromiseResult(finalPromise, { isError: false, result });\n clearRequestResult(requestId);\n return result;\n },\n (error: StructuredErrorDocument) => {\n setPromiseResult(finalPromise, { isError: true, result: error });\n clearRequestResult(requestId);\n throw error;\n }\n ),\n promise\n );\n\n if (cacheResult) {\n setPromiseResult(finalPromise, cacheResult);\n }\n\n return finalPromise;\n }\n\n /**\n * This method exists so that the RequestManager can be created\n * can be created by container/factory systems that expect to\n * call a static `create` method to instantiate the class.\n *\n * Using `new RequestManager()` directly is preferred.\n *\n * @private\n */\n static create(options?: GenericCreateArgs) {\n return new this(options);\n }\n}\n","/**\n * @module\n * @mergeModuleWith <project>\n */\n\nimport type { ReactiveDocument } from './reactive/-private/document.ts';\nimport { getRuntimeConfig, setLogging } from './types/runtime.ts';\n\nexport { Fetch } from './request/-private/fetch.ts';\nexport { RequestManager } from './request/-private/manager.ts';\n\n// @ts-expect-error adding to globalThis\nglobalThis.setWarpDriveLogging = setLogging;\n\n// @ts-expect-error adding to globalThis\nglobalThis.getWarpDriveRuntimeConfig = getRuntimeConfig;\n\nexport {\n Store,\n type StoreRequestContext,\n CacheHandler,\n type CachePolicy,\n type StoreRequestInput,\n recordIdentifierFor,\n storeFor,\n} from './store/-private.ts';\n\n/**\n * @deprecated use `ReactiveDocument` instead\n */\nexport type Document<T> = ReactiveDocument<T>;\n\nexport type {\n DocumentCacheOperation,\n CacheOperation,\n NotificationType,\n} from './store/-private/managers/notification-manager.ts';\n\nexport {\n setIdentifierGenerationMethod,\n setIdentifierUpdateMethod,\n setIdentifierForgetMethod,\n setIdentifierResetMethod,\n setKeyInfoForResource,\n} from './store/-private/caches/identifier-cache.ts';\n"],"names":["_fetch","fetch","args","FastBoot","require","Error","cloneResponse","response","overrides","props","cloneResponseProperties","Response","body","Object","assign","IS_MAYBE_MIRAGE","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","Boolean","window","server","pretender","toString","replace","MUTATION_OPS","Set","ERROR_STATUS_CODE_FOR","Map","Fetch","request","context","test","url","e","DOMException","name","statusText","status","isRequestError","isError","ok","op","isMutationOp","has","headers","set","Date","toUTCString","Headers","setResponse","text","reader","getReader","decoder","TextDecoder","isStreaming","hasRequestedStream","stream","TransformStream","writer","writable","getWriter","signal","addEventListener","abort","readable","cancel","setStream","done","value","read","ready","close","decode","write","encode","TextEncoder","errorPayload","JSON","parse","errors","Array","isArray","isDict","get","msg","method","type","error","AggregateError","code","replaceAll","content","v","RequestManager","constructor","options","_pending","_deduped","useCache","cacheHandler","_hasCacheHandler","isFrozen","IS_CACHE_HANDLER","unshift","use","newHandlers","handlers","forEach","handler","index","push","freeze","assertValidRequest","controller","AbortController","requestId","peekUniversalTransient","setUniversalTransient","id","identifier","promise","executeNextHandler","cacheResult","getRequestResult","TESTING","disableTestWaiter","newPromise","waitFor","finalPromise","upgradePromise","then","result","setPromiseResult","clearRequestResult","create","globalThis","setWarpDriveLogging","setLogging","getWarpDriveRuntimeConfig","getRuntimeConfig"],"mappings":";;;;;;;;;;AAgBA;AACA,MAAMA,MAAoB,GACxB,OAAOC,KAAK,KAAK,WAAW,GACxB,CAAC,GAAGC,IAAI,KAAKD,KAAK,CAAC,GAAGC,IAAI,CAAC,GAC3B,OAAOC,QAAQ,KAAK,WAAW,GAC7B,CAAC,GAAGD,IAAI,KAAOC,QAAQ,CAAcC,OAAO,CAAC,YAAY,CA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,YAAY,GAAGC,cAAc,CACjCT,OAAO,CAACU,IAAI,CACTC,MAAM,IAAK;MACVC,gBAAgB,CAACJ,YAAY,EAAE;AAAE1F,QAAAA,OAAO,EAAE,KAAK;AAAE6F,QAAAA;AAAO,OAAC,CAAC;MAC1DE,kBAAkB,CAAClB,SAAS,CAAC;AAC7B,MAAA,OAAOgB,MAAM;KACd,EACA5C,KAA8B,IAAK;MAClC6C,gBAAgB,CAACJ,YAAY,EAAE;AAAE1F,QAAAA,OAAO,EAAE,IAAI;AAAE6F,QAAAA,MAAM,EAAE5C;AAAM,OAAC,CAAC;MAChE8C,kBAAkB,CAAClB,SAAS,CAAC;AAC7B,MAAA,MAAM5B,KAAK;KAEf,CAAC,EACDiC,OACF,CAAC;AAED,IAAA,IAAIE,WAAW,EAAE;AACfU,MAAAA,gBAAgB,CAACJ,YAAY,EAAEN,WAAW,CAAC;AAC7C;AAEA,IAAA,OAAOM,YAAY;AACrB;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOM,MAAMA,CAACvC,OAA2B,EAAE;AACzC,IAAA,OAAO,IAAI,IAAI,CAACA,OAAO,CAAC;AAC1B;AACF;;ACzSA;AACA;AACA;AACA;;;AAQA;AACAwC,UAAU,CAACC,mBAAmB,GAAGC,UAAU;;AAE3C;AACAF,UAAU,CAACG,yBAAyB,GAAGC,gBAAgB;;;;"}
@@ -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;