@warp-drive-mirror/experiments 0.2.4-alpha.3 → 0.2.4-alpha.5
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.
package/dist/data-worker.js
CHANGED
package/dist/data-worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-worker.js","sources":["../src/data-worker/worker.ts","../src/data-worker/utils.ts","../src/data-worker/cache-handler.ts"],"sourcesContent":["import type { Future, ResponseInfo, StructuredDataDocument } from '@ember-data-mirror/request';\nimport type Store from '@ember-data-mirror/store';\n\nimport { DocumentStorage } from '../document-storage';\nimport type { AbortEventData, RequestEventData, ThreadInitEventData, WorkerThreadEvent } from './types';\n\nconst WorkerScope = (globalThis as unknown as { SharedWorkerGlobalScope: FunctionConstructor }).SharedWorkerGlobalScope;\n\nexport class DataWorker {\n declare store: Store;\n declare threads: Map<string, MessagePort>;\n declare pending: Map<string, Map<number, Future<unknown>>>;\n declare isSharedWorker: boolean;\n declare options: { persisted: boolean; scope?: string };\n declare storage: DocumentStorage;\n\n constructor(UserStore: typeof Store, options?: { persisted: boolean; scope?: string }) {\n // disable if running on main thread\n if (typeof window !== 'undefined') {\n return;\n }\n this.store = new UserStore();\n this.threads = new Map();\n this.pending = new Map();\n this.options = Object.assign({ persisted: false, scope: '' }, options);\n this.isSharedWorker = WorkerScope && globalThis instanceof WorkerScope;\n this.initialize();\n }\n\n initialize() {\n // enable the CacheHandler to access the worker\n (this.store as unknown as { _worker: DataWorker })._worker = this;\n if (this.options.persisted) {\n // will be accessed by the worker's CacheHandler off of store\n this.storage = new DocumentStorage({ scope: this.options.scope });\n }\n if (this.isSharedWorker) {\n (globalThis as unknown as { onconnect: typeof globalThis.onmessage }).onconnect = (e) => {\n const port = e.ports[0];\n port.onmessage = (event: MessageEvent<ThreadInitEventData>) => {\n const { type } = event.data;\n\n switch (type) {\n case 'connect':\n this.setupThread(event.data.thread, port);\n break;\n }\n };\n port.start();\n };\n } else {\n globalThis.onmessage = (event: MessageEvent<ThreadInitEventData>) => {\n const { type } = event.data;\n\n switch (type) {\n case 'connect':\n this.setupThread(event.data.thread, event.ports[0]);\n break;\n }\n };\n }\n }\n\n setupThread(thread: string, port: MessagePort) {\n this.threads.set(thread, port);\n this.pending.set(thread, new Map());\n port.onmessage = (event: WorkerThreadEvent) => {\n if (event.type === 'close') {\n this.threads.delete(thread);\n return;\n }\n\n const { type } = event.data;\n switch (type) {\n case 'abort':\n this.abortRequest(event.data);\n break;\n case 'request':\n void this.request(prepareRequest(event.data));\n break;\n }\n };\n }\n\n abortRequest(event: AbortEventData) {\n const { thread, id } = event;\n const future = this.pending.get(thread)!.get(id);\n\n if (future) {\n future.abort();\n this.pending.get(thread)!.delete(id);\n }\n }\n\n async request(event: RequestEventData) {\n const { thread, id, data } = event;\n\n try {\n const future = this.store.request(data);\n this.pending.get(thread)!.set(id, future);\n\n const result = await future;\n\n this.threads.get(thread)?.postMessage({ type: 'success-response', id, thread, data: prepareResponse(result) });\n } catch (error) {\n if (isAbortError(error)) return;\n\n this.threads.get(thread)?.postMessage({ type: 'error-response', id, thread, data: error });\n } finally {\n this.pending.get(thread)!.delete(id);\n }\n }\n}\n\ntype Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\nfunction softCloneResponse(response: Response | ResponseInfo | null) {\n if (!response) return null;\n\n const clone: Partial<Mutable<Response>> = {};\n\n if (response.headers) {\n clone.headers = Array.from(response.headers as unknown as Iterable<[string, string][]>) as unknown as Headers;\n }\n\n clone.ok = response.ok;\n clone.redirected = response.redirected;\n clone.status = response.status;\n clone.statusText = response.statusText;\n clone.type = response.type;\n clone.url = response.url;\n\n return clone;\n}\n\nfunction isAbortError(error: unknown): error is Error {\n return error instanceof Error && error.name === 'AbortError';\n}\n\nfunction prepareResponse<T>(result: StructuredDataDocument<T>) {\n const newResponse = {\n response: softCloneResponse(result.response),\n content: result.content,\n };\n\n return newResponse;\n}\n\nfunction prepareRequest(event: RequestEventData) {\n if (event.data.headers) {\n event.data.headers = new Headers(event.data.headers);\n }\n\n return event;\n}\n","import type Store from '@ember-data-mirror/store';\nimport type { StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type {\n ImmutableCreateRequestOptions,\n ImmutableDeleteRequestOptions,\n ImmutableRequestInfo,\n ImmutableUpdateRequestOptions,\n StructuredDataDocument,\n} from '@warp-drive-mirror/core-types/request';\nimport type { ApiError } from '@warp-drive-mirror/core-types/spec/error';\n\nexport const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);\n\n/**\n * In a Worker, any time we are asked to make a request, data needs to be returned.\n * background requests are ergo no different than foreground requests.\n * @internal\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 cacheOptions?.backgroundReload ||\n !hasCachedValue ||\n (store.lifetimes && identifier\n ? store.lifetimes.isHardExpired(identifier, store) || store.lifetimes.isSoftExpired(identifier, store)\n : 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\nfunction isAggregateError(error: Error & { errors?: ApiError[] }): error is AggregateError & { errors: ApiError[] } {\n return error instanceof AggregateError || (error.name === 'AggregateError' && Array.isArray(error.errors));\n}\n\ntype 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","import type { CacheHandler as CacheHandlerType, Future, NextFn } from '@ember-data-mirror/request';\nimport type Store from '@ember-data-mirror/store';\nimport type { StoreRequestContext } from '@ember-data-mirror/store';\nimport { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\nimport type { ExistingRecordIdentifier, StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type {\n StructuredDataDocument,\n StructuredDocument,\n StructuredErrorDocument,\n} from '@warp-drive-mirror/core-types/request';\nimport { SkipCache } from '@warp-drive-mirror/core-types/request';\nimport type {\n ResourceDataDocument,\n ResourceDocument,\n ResourceErrorDocument,\n} from '@warp-drive-mirror/core-types/spec/document';\nimport type { ApiError } from '@warp-drive-mirror/core-types/spec/error';\nimport type { ExistingResourceObject } from '@warp-drive-mirror/core-types/spec/json-api-raw';\n\nimport { calcShouldFetch, cloneError, isCacheAffecting, isMutation } from './utils';\nimport type { DataWorker } from './worker';\n\n/**\n * A simplified CacheHandler that hydrates ResourceDataDocuments from the cache\n * with their referenced resources.\n *\n * @typedoc\n */\nexport const CacheHandler: CacheHandlerType = {\n request<T>(context: StoreRequestContext, next: NextFn<T>): 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 const peeked = identifier ? store.cache.peekRequest(identifier) : null;\n\n if (identifier && !peeked) {\n // if we are using persisted cache, we should attempt to populate the in-memory cache now\n const worker = (store as unknown as { _worker: DataWorker })._worker;\n if (worker?.storage) {\n return worker.storage\n .getDocument(identifier)\n .then((document) => {\n if (document) {\n store.cache.put(document);\n }\n return completeRequest(identifier, store, context, next);\n })\n .catch((e) => {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Unable to retrieve document from persisted storage', e);\n }\n return completeRequest(identifier, store, context, next);\n });\n }\n }\n\n return completeRequest(identifier, store, context, next);\n },\n};\n\nfunction completeRequest<T>(\n identifier: StableDocumentIdentifier | null,\n store: Store,\n context: StoreRequestContext,\n next: NextFn<T>\n) {\n const peeked = identifier ? store.cache.peekRequest(identifier) : null;\n // In a Worker, any time we are asked to make a request, data needs to be returned.\n // background requests are ergo no different than foreground requests.\n if (calcShouldFetch(store, context.request, !!peeked, identifier)) {\n return fetchContentAndHydrate(next, context, identifier);\n }\n\n assert(`Expected a peeked request to be present`, peeked);\n context.setResponse(peeked.response);\n\n if ('error' in peeked) {\n throw peeked;\n }\n\n return maybeUpdateObjects<T>(store, peeked.content as ResourceDataDocument);\n}\n\nfunction maybeUpdateObjects<T>(store: Store, document: ResourceDataDocument | null): T {\n if (!document) {\n return document as T;\n }\n\n if (Array.isArray(document.data)) {\n const data = document.data.map((identifier) => {\n return store.cache.peek(identifier);\n });\n\n return Object.assign({}, document, { data }) as T;\n } else {\n const data = (document.data ? store.cache.peek(document.data) : null) as T;\n return Object.assign({}, document, { data }) as T;\n }\n}\n\nfunction maybeUpdatePersistedCache(\n store: Store,\n document: StructuredDocument<ResourceDocument<ExistingRecordIdentifier>> | null,\n resourceDocument?: ResourceDataDocument\n) {\n const worker = (store as unknown as { _worker: DataWorker })._worker;\n\n if (!worker?.storage) {\n return;\n }\n\n if (!document && resourceDocument) {\n // we have resources to update but not a full request to cache\n void worker.storage.putResources(resourceDocument, (resourceIdentifier) => {\n return store.cache.peek(resourceIdentifier) as ExistingResourceObject;\n });\n } else if (document) {\n void worker.storage.putDocument(document, (resourceIdentifier) => {\n return store.cache.peek(resourceIdentifier) as ExistingResourceObject;\n });\n }\n}\n\nfunction updateCacheForSuccess<T>(\n store: Store,\n request: StoreRequestContext['request'],\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 maybeUpdatePersistedCache(store, null, response);\n }\n } else {\n response = store.cache.put(document) as ResourceDataDocument;\n\n if (response.lid) {\n const identifier = store.identifierCache.getOrCreateDocumentIdentifier(request);\n const full = store.cache.peekRequest(identifier!);\n maybeUpdatePersistedCache(store, full);\n }\n }\n return maybeUpdateObjects(store, response);\n}\n\nfunction handleFetchSuccess<T>(\n store: Store,\n request: StoreRequestContext['request'],\n identifier: StableDocumentIdentifier | null,\n document: StructuredDataDocument<T>\n): T {\n let response: ResourceDataDocument;\n store._join(() => {\n response = updateCacheForSuccess<T>(store, request, document) as ResourceDataDocument;\n });\n\n if (store.lifetimes?.didRequest) {\n store.lifetimes.didRequest(request, document.response, identifier, store);\n }\n\n return response! as T;\n}\n\nfunction updateCacheForError<T>(\n store: Store,\n request: StoreRequestContext['request'],\n error: StructuredErrorDocument<T>\n) {\n if (isMutation(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 = request.data?.record || request.records?.[0];\n\n store.cache.commitWasRejected(record, errors);\n } else {\n const identifier = store.identifierCache.getOrCreateDocumentIdentifier(request);\n if (identifier) {\n maybeUpdatePersistedCache(store, error as StructuredErrorDocument<ResourceErrorDocument>);\n }\n return store.cache.put(error) as ResourceErrorDocument;\n }\n}\n\nfunction handleFetchError<T>(\n store: Store,\n request: StoreRequestContext['request'],\n identifier: StableDocumentIdentifier | null,\n error: StructuredErrorDocument<T>\n): never {\n if (request.signal?.aborted) {\n throw error;\n }\n let response: ResourceErrorDocument | undefined;\n store._join(() => {\n response = updateCacheForError(store, request, error);\n });\n\n if (identifier && store.lifetimes?.didRequest) {\n store.lifetimes.didRequest(request, error.response, identifier, store);\n }\n\n if (isMutation(request)) {\n throw error;\n }\n\n const newError = cloneError(error);\n newError.content = response!;\n throw newError;\n}\n\nfunction fetchContentAndHydrate<T>(\n next: NextFn<T>,\n context: StoreRequestContext,\n identifier: StableDocumentIdentifier | null\n): Promise<T> {\n const { request } = context;\n const { store } = context.request;\n\n if (isMutation(request)) {\n // TODO should we handle multiple records in request.records by iteratively calling willCommit for each\n const record = request.data?.record || request.records?.[0];\n assert(`Expected to receive a list of records included in the ${request.op} request`, record);\n if (record) {\n store.cache.willCommit(record, context);\n }\n }\n\n if (store.lifetimes?.willRequest) {\n store.lifetimes.willRequest(request, identifier, store);\n }\n\n return next(request).then(\n (document) => handleFetchSuccess(store, request, identifier, document),\n (error: StructuredErrorDocument<T>) => handleFetchError(store, request, identifier, error)\n );\n}\n"],"names":["WorkerScope","globalThis","SharedWorkerGlobalScope","DataWorker","constructor","UserStore","options","window","store","threads","Map","pending","Object","assign","persisted","scope","isSharedWorker","initialize","_worker","storage","DocumentStorage","onconnect","e","port","ports","onmessage","event","type","data","setupThread","thread","start","set","delete","abortRequest","request","prepareRequest","id","future","get","abort","result","postMessage","prepareResponse","error","isAbortError","softCloneResponse","response","clone","headers","Array","from","ok","redirected","status","statusText","url","Error","name","newResponse","content","Headers","MUTATION_OPS","Set","calcShouldFetch","hasCachedValue","identifier","cacheOptions","op","has","reload","backgroundReload","lifetimes","isHardExpired","isSoftExpired","isMutation","Boolean","isCacheAffecting","document","keys","length","isAggregateError","AggregateError","isArray","errors","cloneError","isAggregate","cloned","structuredClone","message","stack","CacheHandler","context","next","SkipCache","identifierCache","getOrCreateDocumentIdentifier","peeked","cache","peekRequest","worker","getDocument","then","put","completeRequest","catch","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","console","log","fetchContentAndHydrate","test","setResponse","maybeUpdateObjects","map","peek","maybeUpdatePersistedCache","resourceDocument","putResources","resourceIdentifier","putDocument","updateCacheForSuccess","record","records","didCommit","lid","full","handleFetchSuccess","_join","didRequest","updateCacheForError","undefined","commitWasRejected","handleFetchError","signal","aborted","newError","willCommit","willRequest"],"mappings":";;;;AAMA,MAAMA,WAAW,GAAIC,UAAU,CAAiEC,uBAAuB;AAEhH,MAAMC,UAAU,CAAC;AAQtBC,EAAAA,WAAWA,CAACC,SAAuB,EAAEC,OAAgD,EAAE;AACrF;AACA,IAAA,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;AACjC,MAAA;AACF;AACA,IAAA,IAAI,CAACC,KAAK,GAAG,IAAIH,SAAS,EAAE;AAC5B,IAAA,IAAI,CAACI,OAAO,GAAG,IAAIC,GAAG,EAAE;AACxB,IAAA,IAAI,CAACC,OAAO,GAAG,IAAID,GAAG,EAAE;AACxB,IAAA,IAAI,CAACJ,OAAO,GAAGM,MAAM,CAACC,MAAM,CAAC;AAAEC,MAAAA,SAAS,EAAE,KAAK;AAAEC,MAAAA,KAAK,EAAE;KAAI,EAAET,OAAO,CAAC;AACtE,IAAA,IAAI,CAACU,cAAc,GAAGhB,WAAW,IAAIC,UAAU,YAAYD,WAAW;IACtE,IAAI,CAACiB,UAAU,EAAE;AACnB;AAEAA,EAAAA,UAAUA,GAAG;AACX;AACC,IAAA,IAAI,CAACT,KAAK,CAAwCU,OAAO,GAAG,IAAI;AACjE,IAAA,IAAI,IAAI,CAACZ,OAAO,CAACQ,SAAS,EAAE;AAC1B;AACA,MAAA,IAAI,CAACK,OAAO,GAAG,IAAIC,eAAe,CAAC;AAAEL,QAAAA,KAAK,EAAE,IAAI,CAAC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AAAA,IAAA,EAAA;AAAA,QAAA,MAAA,IAAAzD,KAAA,CAAO,CAAA,sDAAA,EAAyDtB,OAAO,CAACiC,EAAE,CAAU,QAAA,CAAA,CAAA;AAAA;AAAA,KAAA,EAAEyD,MAAM,CAAA,GAAA,EAAA;AAC5F,IAAA,IAAIA,MAAM,EAAE;MACVrH,KAAK,CAAC0F,KAAK,CAAC0C,UAAU,CAACf,MAAM,EAAEjC,OAAO,CAAC;AACzC;AACF;AAEA,EAAA,IAAIpF,KAAK,CAACgE,SAAS,EAAEqE,WAAW,EAAE;IAChCrI,KAAK,CAACgE,SAAS,CAACqE,WAAW,CAAC1G,OAAO,EAAE+B,UAAU,EAAE1D,KAAK,CAAC;AACzD;AAEA,EAAA,OAAOqF,IAAI,CAAC1D,OAAO,CAAC,CAACmE,IAAI,CACtBxB,QAAQ,IAAKoD,kBAAkB,CAAC1H,KAAK,EAAE2B,OAAO,EAAE+B,UAAU,EAAEY,QAAQ,CAAC,EACrElC,KAAiC,IAAK4F,gBAAgB,CAAChI,KAAK,EAAE2B,OAAO,EAAE+B,UAAU,EAAEtB,KAAK,CAC3F,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"data-worker.js","sources":["../src/data-worker/worker.ts","../src/data-worker/utils.ts","../src/data-worker/cache-handler.ts"],"sourcesContent":["import type { Future, ResponseInfo, StructuredDataDocument } from '@ember-data-mirror/request';\nimport type Store from '@ember-data-mirror/store';\n\nimport { DocumentStorage } from '../document-storage';\nimport type { AbortEventData, RequestEventData, ThreadInitEventData, WorkerThreadEvent } from './types';\n\nconst WorkerScope = (globalThis as unknown as { SharedWorkerGlobalScope: FunctionConstructor }).SharedWorkerGlobalScope;\n\nexport class DataWorker {\n declare store: Store;\n declare threads: Map<string, MessagePort>;\n declare pending: Map<string, Map<number, Future<unknown>>>;\n declare isSharedWorker: boolean;\n declare options: { persisted: boolean; scope?: string };\n declare storage: DocumentStorage;\n\n constructor(UserStore: typeof Store, options?: { persisted: boolean; scope?: string }) {\n // disable if running on main thread\n if (typeof window !== 'undefined') {\n return;\n }\n this.store = new UserStore();\n this.threads = new Map();\n this.pending = new Map();\n this.options = Object.assign({ persisted: false, scope: '' }, options);\n this.isSharedWorker = WorkerScope && globalThis instanceof WorkerScope;\n this.initialize();\n }\n\n initialize() {\n // enable the CacheHandler to access the worker\n (this.store as unknown as { _worker: DataWorker })._worker = this;\n if (this.options.persisted) {\n // will be accessed by the worker's CacheHandler off of store\n this.storage = new DocumentStorage({ scope: this.options.scope });\n }\n if (this.isSharedWorker) {\n (globalThis as unknown as { onconnect: typeof globalThis.onmessage }).onconnect = (e) => {\n const port = e.ports[0];\n port.onmessage = (event: MessageEvent<ThreadInitEventData>) => {\n const { type } = event.data;\n\n switch (type) {\n case 'connect':\n this.setupThread(event.data.thread, port);\n break;\n }\n };\n port.start();\n };\n } else {\n globalThis.onmessage = (event: MessageEvent<ThreadInitEventData>) => {\n const { type } = event.data;\n\n switch (type) {\n case 'connect':\n this.setupThread(event.data.thread, event.ports[0]);\n break;\n }\n };\n }\n }\n\n setupThread(thread: string, port: MessagePort) {\n this.threads.set(thread, port);\n this.pending.set(thread, new Map());\n port.onmessage = (event: WorkerThreadEvent) => {\n if (event.type === 'close') {\n this.threads.delete(thread);\n return;\n }\n\n const { type } = event.data;\n switch (type) {\n case 'abort':\n this.abortRequest(event.data);\n break;\n case 'request':\n void this.request(prepareRequest(event.data));\n break;\n }\n };\n }\n\n abortRequest(event: AbortEventData) {\n const { thread, id } = event;\n const future = this.pending.get(thread)!.get(id);\n\n if (future) {\n future.abort();\n this.pending.get(thread)!.delete(id);\n }\n }\n\n async request(event: RequestEventData) {\n const { thread, id, data } = event;\n\n try {\n const future = this.store.request(data);\n this.pending.get(thread)!.set(id, future);\n\n const result = await future;\n\n this.threads.get(thread)?.postMessage({ type: 'success-response', id, thread, data: prepareResponse(result) });\n } catch (error) {\n if (isAbortError(error)) return;\n\n this.threads.get(thread)?.postMessage({ type: 'error-response', id, thread, data: error });\n } finally {\n this.pending.get(thread)!.delete(id);\n }\n }\n}\n\ntype Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\nfunction softCloneResponse(response: Response | ResponseInfo | null) {\n if (!response) return null;\n\n const clone: Partial<Mutable<Response>> = {};\n\n if (response.headers) {\n clone.headers = Array.from(response.headers as unknown as Iterable<[string, string][]>) as unknown as Headers;\n }\n\n clone.ok = response.ok;\n clone.redirected = response.redirected;\n clone.status = response.status;\n clone.statusText = response.statusText;\n clone.type = response.type;\n clone.url = response.url;\n\n return clone;\n}\n\nfunction isAbortError(error: unknown): error is Error {\n return error instanceof Error && error.name === 'AbortError';\n}\n\nfunction prepareResponse<T>(result: StructuredDataDocument<T>) {\n const newResponse = {\n response: softCloneResponse(result.response),\n content: result.content,\n };\n\n return newResponse;\n}\n\nfunction prepareRequest(event: RequestEventData) {\n if (event.data.headers) {\n event.data.headers = new Headers(event.data.headers);\n }\n\n return event;\n}\n","import type Store from '@ember-data-mirror/store';\nimport type { StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type {\n ImmutableCreateRequestOptions,\n ImmutableDeleteRequestOptions,\n ImmutableRequestInfo,\n ImmutableUpdateRequestOptions,\n StructuredDataDocument,\n} from '@warp-drive-mirror/core-types/request';\nimport type { ApiError } from '@warp-drive-mirror/core-types/spec/error';\n\nexport const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);\n\n/**\n * In a Worker, any time we are asked to make a request, data needs to be returned.\n * background requests are ergo no different than foreground requests.\n * @internal\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 cacheOptions?.backgroundReload ||\n !hasCachedValue ||\n (store.lifetimes && identifier\n ? store.lifetimes.isHardExpired(identifier, store) || store.lifetimes.isSoftExpired(identifier, store)\n : 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\nfunction isAggregateError(error: Error & { errors?: ApiError[] }): error is AggregateError & { errors: ApiError[] } {\n return error instanceof AggregateError || (error.name === 'AggregateError' && Array.isArray(error.errors));\n}\n\ntype 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","import type { CacheHandler as CacheHandlerType, Future, NextFn } from '@ember-data-mirror/request';\nimport type Store from '@ember-data-mirror/store';\nimport type { StoreRequestContext } from '@ember-data-mirror/store';\nimport { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\nimport type { ExistingRecordIdentifier, StableDocumentIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type {\n StructuredDataDocument,\n StructuredDocument,\n StructuredErrorDocument,\n} from '@warp-drive-mirror/core-types/request';\nimport { SkipCache } from '@warp-drive-mirror/core-types/request';\nimport type {\n ResourceDataDocument,\n ResourceDocument,\n ResourceErrorDocument,\n} from '@warp-drive-mirror/core-types/spec/document';\nimport type { ApiError } from '@warp-drive-mirror/core-types/spec/error';\nimport type { ExistingResourceObject } from '@warp-drive-mirror/core-types/spec/json-api-raw';\n\nimport { calcShouldFetch, cloneError, isCacheAffecting, isMutation } from './utils';\nimport type { DataWorker } from './worker';\n\n/**\n * A simplified CacheHandler that hydrates ResourceDataDocuments from the cache\n * with their referenced resources.\n *\n */\nexport const CacheHandler: CacheHandlerType = {\n request<T>(context: StoreRequestContext, next: NextFn<T>): 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 const peeked = identifier ? store.cache.peekRequest(identifier) : null;\n\n if (identifier && !peeked) {\n // if we are using persisted cache, we should attempt to populate the in-memory cache now\n const worker = (store as unknown as { _worker: DataWorker })._worker;\n if (worker?.storage) {\n return worker.storage\n .getDocument(identifier)\n .then((document) => {\n if (document) {\n store.cache.put(document);\n }\n return completeRequest(identifier, store, context, next);\n })\n .catch((e) => {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Unable to retrieve document from persisted storage', e);\n }\n return completeRequest(identifier, store, context, next);\n });\n }\n }\n\n return completeRequest(identifier, store, context, next);\n },\n};\n\nfunction completeRequest<T>(\n identifier: StableDocumentIdentifier | null,\n store: Store,\n context: StoreRequestContext,\n next: NextFn<T>\n) {\n const peeked = identifier ? store.cache.peekRequest(identifier) : null;\n // In a Worker, any time we are asked to make a request, data needs to be returned.\n // background requests are ergo no different than foreground requests.\n if (calcShouldFetch(store, context.request, !!peeked, identifier)) {\n return fetchContentAndHydrate(next, context, identifier);\n }\n\n assert(`Expected a peeked request to be present`, peeked);\n context.setResponse(peeked.response);\n\n if ('error' in peeked) {\n throw peeked;\n }\n\n return maybeUpdateObjects<T>(store, peeked.content as ResourceDataDocument);\n}\n\nfunction maybeUpdateObjects<T>(store: Store, document: ResourceDataDocument | null): T {\n if (!document) {\n return document as T;\n }\n\n if (Array.isArray(document.data)) {\n const data = document.data.map((identifier) => {\n return store.cache.peek(identifier);\n });\n\n return Object.assign({}, document, { data }) as T;\n } else {\n const data = (document.data ? store.cache.peek(document.data) : null) as T;\n return Object.assign({}, document, { data }) as T;\n }\n}\n\nfunction maybeUpdatePersistedCache(\n store: Store,\n document: StructuredDocument<ResourceDocument<ExistingRecordIdentifier>> | null,\n resourceDocument?: ResourceDataDocument\n) {\n const worker = (store as unknown as { _worker: DataWorker })._worker;\n\n if (!worker?.storage) {\n return;\n }\n\n if (!document && resourceDocument) {\n // we have resources to update but not a full request to cache\n void worker.storage.putResources(resourceDocument, (resourceIdentifier) => {\n return store.cache.peek(resourceIdentifier) as ExistingResourceObject;\n });\n } else if (document) {\n void worker.storage.putDocument(document, (resourceIdentifier) => {\n return store.cache.peek(resourceIdentifier) as ExistingResourceObject;\n });\n }\n}\n\nfunction updateCacheForSuccess<T>(\n store: Store,\n request: StoreRequestContext['request'],\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 maybeUpdatePersistedCache(store, null, response);\n }\n } else {\n response = store.cache.put(document) as ResourceDataDocument;\n\n if (response.lid) {\n const identifier = store.identifierCache.getOrCreateDocumentIdentifier(request);\n const full = store.cache.peekRequest(identifier!);\n maybeUpdatePersistedCache(store, full);\n }\n }\n return maybeUpdateObjects(store, response);\n}\n\nfunction handleFetchSuccess<T>(\n store: Store,\n request: StoreRequestContext['request'],\n identifier: StableDocumentIdentifier | null,\n document: StructuredDataDocument<T>\n): T {\n let response: ResourceDataDocument;\n store._join(() => {\n response = updateCacheForSuccess<T>(store, request, document) as ResourceDataDocument;\n });\n\n if (store.lifetimes?.didRequest) {\n store.lifetimes.didRequest(request, document.response, identifier, store);\n }\n\n return response! as T;\n}\n\nfunction updateCacheForError<T>(\n store: Store,\n request: StoreRequestContext['request'],\n error: StructuredErrorDocument<T>\n) {\n if (isMutation(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 = request.data?.record || request.records?.[0];\n\n store.cache.commitWasRejected(record, errors);\n } else {\n const identifier = store.identifierCache.getOrCreateDocumentIdentifier(request);\n if (identifier) {\n maybeUpdatePersistedCache(store, error as StructuredErrorDocument<ResourceErrorDocument>);\n }\n return store.cache.put(error) as ResourceErrorDocument;\n }\n}\n\nfunction handleFetchError<T>(\n store: Store,\n request: StoreRequestContext['request'],\n identifier: StableDocumentIdentifier | null,\n error: StructuredErrorDocument<T>\n): never {\n if (request.signal?.aborted) {\n throw error;\n }\n let response: ResourceErrorDocument | undefined;\n store._join(() => {\n response = updateCacheForError(store, request, error);\n });\n\n if (identifier && store.lifetimes?.didRequest) {\n store.lifetimes.didRequest(request, error.response, identifier, store);\n }\n\n if (isMutation(request)) {\n throw error;\n }\n\n const newError = cloneError(error);\n newError.content = response!;\n throw newError;\n}\n\nfunction fetchContentAndHydrate<T>(\n next: NextFn<T>,\n context: StoreRequestContext,\n identifier: StableDocumentIdentifier | null\n): Promise<T> {\n const { request } = context;\n const { store } = context.request;\n\n if (isMutation(request)) {\n // TODO should we handle multiple records in request.records by iteratively calling willCommit for each\n const record = request.data?.record || request.records?.[0];\n assert(`Expected to receive a list of records included in the ${request.op} request`, record);\n if (record) {\n store.cache.willCommit(record, context);\n }\n }\n\n if (store.lifetimes?.willRequest) {\n store.lifetimes.willRequest(request, identifier, store);\n }\n\n return next(request).then(\n (document) => handleFetchSuccess(store, request, identifier, document),\n (error: StructuredErrorDocument<T>) => handleFetchError(store, request, identifier, error)\n );\n}\n"],"names":["WorkerScope","globalThis","SharedWorkerGlobalScope","DataWorker","constructor","UserStore","options","window","store","threads","Map","pending","Object","assign","persisted","scope","isSharedWorker","initialize","_worker","storage","DocumentStorage","onconnect","e","port","ports","onmessage","event","type","data","setupThread","thread","start","set","delete","abortRequest","request","prepareRequest","id","future","get","abort","result","postMessage","prepareResponse","error","isAbortError","softCloneResponse","response","clone","headers","Array","from","ok","redirected","status","statusText","url","Error","name","newResponse","content","Headers","MUTATION_OPS","Set","calcShouldFetch","hasCachedValue","identifier","cacheOptions","op","has","reload","backgroundReload","lifetimes","isHardExpired","isSoftExpired","isMutation","Boolean","isCacheAffecting","document","keys","length","isAggregateError","AggregateError","isArray","errors","cloneError","isAggregate","cloned","structuredClone","message","stack","CacheHandler","context","next","SkipCache","identifierCache","getOrCreateDocumentIdentifier","peeked","cache","peekRequest","worker","getDocument","then","put","completeRequest","catch","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","console","log","fetchContentAndHydrate","test","setResponse","maybeUpdateObjects","map","peek","maybeUpdatePersistedCache","resourceDocument","putResources","resourceIdentifier","putDocument","updateCacheForSuccess","record","records","didCommit","lid","full","handleFetchSuccess","_join","didRequest","updateCacheForError","undefined","commitWasRejected","handleFetchError","signal","aborted","newError","willCommit","willRequest"],"mappings":";;;;AAMA,MAAMA,WAAW,GAAIC,UAAU,CAAiEC,uBAAuB;AAEhH,MAAMC,UAAU,CAAC;AAQtBC,EAAAA,WAAWA,CAACC,SAAuB,EAAEC,OAAgD,EAAE;AACrF;AACA,IAAA,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;AACjC,MAAA;AACF;AACA,IAAA,IAAI,CAACC,KAAK,GAAG,IAAIH,SAAS,EAAE;AAC5B,IAAA,IAAI,CAACI,OAAO,GAAG,IAAIC,GAAG,EAAE;AACxB,IAAA,IAAI,CAACC,OAAO,GAAG,IAA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-fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-fetch.js","sources":["../src/image-worker/fetch.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"image-fetch.js","sources":["../src/image-worker/fetch.ts"],"sourcesContent":["import type { Deferred } from '@ember-data-mirror/request';\nimport { createDeferred } from '@ember-data-mirror/request';\nimport { TESTING } from '@warp-drive-mirror/build-config/env';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\n\nimport type { MainThreadEvent, RequestEventData } from './types';\n\nexport interface FastBoot {\n require(moduleName: string): unknown;\n isFastBoot: boolean;\n request: Request;\n}\n\nconst isServerEnv = typeof FastBoot !== 'undefined';\n\nexport class ImageFetch {\n declare worker: Worker | SharedWorker;\n declare threadId: string;\n declare pending: Map<string, Deferred<string>>;\n declare channel: MessageChannel;\n declare cache: Map<string, string>;\n\n constructor(worker: Worker | SharedWorker | null) {\n this.threadId = isServerEnv ? '' : crypto.randomUUID();\n this.pending = new Map();\n this.cache = new Map();\n\n const isTesting = TESTING ? true : false;\n assert(`Expected a SharedWorker instance`, isTesting || isServerEnv || worker instanceof SharedWorker);\n this.worker = worker as SharedWorker;\n\n if (!isServerEnv) {\n const fn = (event: MainThreadEvent) => {\n const { type, url } = event.data;\n const deferred = this.cleanupRequest(url);\n if (!deferred) {\n return;\n }\n\n if (type === 'success-response') {\n deferred.resolve(url);\n return;\n }\n\n if (type === 'error-response') {\n deferred.reject(null);\n return;\n }\n };\n\n if (worker instanceof SharedWorker) {\n worker.port.postMessage({ type: 'connect', thread: this.threadId });\n worker.port.onmessage = fn;\n } else if (worker) {\n this.channel = new MessageChannel();\n worker.postMessage({ type: 'connect', thread: this.threadId }, [this.channel.port2]);\n\n this.channel.port1.onmessage = fn;\n }\n }\n }\n\n cleanupRequest(url: string) {\n const deferred = this.pending.get(url);\n this.pending.delete(url);\n\n return deferred;\n }\n\n _send(event: RequestEventData) {\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);\n }\n\n load(url: string) {\n if (isServerEnv) {\n return Promise.resolve(url);\n }\n\n const objectUrl = this.cache.get(url);\n if (objectUrl) {\n return Promise.resolve(objectUrl);\n }\n\n const deferred = createDeferred<string>();\n this.pending.set(url, deferred);\n this._send({ type: 'load', thread: this.threadId, url });\n return deferred.promise;\n }\n}\n"],"names":["isServerEnv","FastBoot","ImageFetch","constructor","worker","threadId","crypto","randomUUID","pending","Map","cache","isTesting","macroCondition","getGlobalConfig","WarpDrive","env","TESTING","DEBUG","test","Error","SharedWorker","fn","event","type","url","data","deferred","cleanupRequest","resolve","reject","port","postMessage","thread","onmessage","channel","MessageChannel","port2","port1","get","delete","_send","load","Promise","objectUrl","createDeferred","set","promise"],"mappings":";;;AAaA,MAAMA,WAAW,GAAG,OAAOC,QAAQ,KAAK,WAAW;AAE5C,MAAMC,UAAU,CAAC;EAOtBC,WAAWA,CAACC,MAAoC,EAAE;IAChD,IAAI,CAACC,QAAQ,GAAGL,WAAW,GAAG,EAAE,GAAGM,MAAM,CAACC,UAAU,EAAE;AACtD,IAAA,IAAI,CAACC,OAAO,GAAG,IAAIC,GAAG,EAAE;AACxB,IAAA,IAAI,CAACC,KAAK,GAAG,IAAID,GAAG,EAAE;AAEtB,IAAA,MAAME,SAAS,GAAGC,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAC,OAAA,CAAU,GAAA,IAAI,GAAG,KAAK;IACxCJ,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAE,KAAA,CAAA,GAAA,CAAAC,IAAA,IAAA;AAAA,MAAA,IAAA,CAAAA,IAAA,EAAA;QAAA,MAAAC,IAAAA,KAAA,CAAO,CAAkC,gCAAA,CAAA,CAAA;AAAA;AAAA,KAAA,EAAER,SAAS,IAAIX,WAAW,IAAII,MAAM,YAAYgB,YAAY,CAAA,GAAA,EA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AChB,OAAO,CAAC+B,MAAM,CAACf,GAAG,CAAC;AAExB,IAAA,OAAOE,QAAQ;AACjB;EAEAc,KAAKA,CAAClB,KAAuB,EAAE;AAC7B;IACA,IAAI,CAAClB,MAAM,YAAYgB,YAAY,GAAG,IAAI,CAAChB,MAAM,CAAC0B,IAAI,CAACC,WAAW,CAACT,KAAK,CAAC,GAAG,IAAI,CAACY,OAAO,CAACG,KAAK,CAACN,WAAW,CAACT,KAAK,CAAC;AACnH;EAEAmB,IAAIA,CAACjB,GAAW,EAAE;AAChB,IAAA,IAAIxB,WAAW,EAAE;AACf,MAAA,OAAO0C,OAAO,CAACd,OAAO,CAACJ,GAAG,CAAC;AAC7B;IAEA,MAAMmB,SAAS,GAAG,IAAI,CAACjC,KAAK,CAAC4B,GAAG,CAACd,GAAG,CAAC;AACrC,IAAA,IAAImB,SAAS,EAAE;AACb,MAAA,OAAOD,OAAO,CAACd,OAAO,CAACe,SAAS,CAAC;AACnC;AAEA,IAAA,MAAMjB,QAAQ,GAAGkB,cAAc,EAAU;IACzC,IAAI,CAACpC,OAAO,CAACqC,GAAG,CAACrB,GAAG,EAAEE,QAAQ,CAAC;IAC/B,IAAI,CAACc,KAAK,CAAC;AAAEjB,MAAAA,IAAI,EAAE,MAAM;MAAES,MAAM,EAAE,IAAI,CAAC3B,QAAQ;AAAEmB,MAAAA;AAAI,KAAC,CAAC;IACxD,OAAOE,QAAQ,CAACoB,OAAO;AACzB;AACF;;;;"}
|
package/dist/persisted-cache.js
CHANGED
|
@@ -33,7 +33,6 @@ class PersistedCache {
|
|
|
33
33
|
* a `content` member and therefor must not assume the existence
|
|
34
34
|
* of `request` and `response` on the document.
|
|
35
35
|
*
|
|
36
|
-
* @method put
|
|
37
36
|
* @param {StructuredDocument} doc
|
|
38
37
|
* @return {ResourceDocument}
|
|
39
38
|
* @internal
|
|
@@ -73,7 +72,6 @@ class PersistedCache {
|
|
|
73
72
|
* Note: currently the only valid operation is a MergeOperation
|
|
74
73
|
* which occurs when a collision of identifiers is detected.
|
|
75
74
|
*
|
|
76
|
-
* @method patch
|
|
77
75
|
* @internal
|
|
78
76
|
* @param op the operation to perform
|
|
79
77
|
* @return {void}
|
|
@@ -86,7 +84,6 @@ class PersistedCache {
|
|
|
86
84
|
* Update resource data with a local mutation. Currently supports operations
|
|
87
85
|
* on relationships only.
|
|
88
86
|
*
|
|
89
|
-
* @method mutate
|
|
90
87
|
* @internal
|
|
91
88
|
* @param mutation
|
|
92
89
|
*/
|
|
@@ -121,7 +118,6 @@ class PersistedCache {
|
|
|
121
118
|
* of the Graph handling necessary entanglements and
|
|
122
119
|
* notifications for relational data.
|
|
123
120
|
*
|
|
124
|
-
* @method peek
|
|
125
121
|
* @internal
|
|
126
122
|
* @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
|
|
127
123
|
* @return {ResourceDocument | ResourceBlob | null} the known resource data
|
|
@@ -158,7 +154,6 @@ class PersistedCache {
|
|
|
158
154
|
* of the Graph handling necessary entanglements and
|
|
159
155
|
* notifications for relational data.
|
|
160
156
|
*
|
|
161
|
-
* @method peek
|
|
162
157
|
* @internal
|
|
163
158
|
* @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
|
|
164
159
|
* @return {ResourceDocument | ResourceBlob | null} the known resource data
|
|
@@ -172,7 +167,6 @@ class PersistedCache {
|
|
|
172
167
|
* Peek the Cache for the existing request data associated with
|
|
173
168
|
* a cacheable request
|
|
174
169
|
*
|
|
175
|
-
* @method peekRequest
|
|
176
170
|
* @param {StableDocumentIdentifier}
|
|
177
171
|
* @return {StableDocumentIdentifier | null}
|
|
178
172
|
* @internal
|
|
@@ -184,7 +178,6 @@ class PersistedCache {
|
|
|
184
178
|
/**
|
|
185
179
|
* Push resource data from a remote source into the cache for this identifier
|
|
186
180
|
*
|
|
187
|
-
* @method upsert
|
|
188
181
|
* @internal
|
|
189
182
|
* @param identifier
|
|
190
183
|
* @param data
|
|
@@ -205,9 +198,8 @@ class PersistedCache {
|
|
|
205
198
|
* preferring instead to fork at the Store level, which will
|
|
206
199
|
* utilize this method to fork the cache.
|
|
207
200
|
*
|
|
208
|
-
* @method fork
|
|
209
201
|
* @internal
|
|
210
|
-
* @return Promise<Cache>
|
|
202
|
+
* @return {Promise<Cache>}
|
|
211
203
|
*/
|
|
212
204
|
fork() {
|
|
213
205
|
return this._cache.fork();
|
|
@@ -220,10 +212,9 @@ class PersistedCache {
|
|
|
220
212
|
* preferring instead to merge at the Store level, which will
|
|
221
213
|
* utilize this method to merge the caches.
|
|
222
214
|
*
|
|
223
|
-
* @method merge
|
|
224
215
|
* @param {Cache} cache
|
|
225
216
|
* @internal
|
|
226
|
-
* @return Promise<void>
|
|
217
|
+
* @return {Promise<void>}
|
|
227
218
|
*/
|
|
228
219
|
merge(cache) {
|
|
229
220
|
return this._cache.merge(cache);
|
|
@@ -259,7 +250,6 @@ class PersistedCache {
|
|
|
259
250
|
* }
|
|
260
251
|
* ```
|
|
261
252
|
*
|
|
262
|
-
* @method diff
|
|
263
253
|
* @internal
|
|
264
254
|
*/
|
|
265
255
|
diff() {
|
|
@@ -274,7 +264,6 @@ class PersistedCache {
|
|
|
274
264
|
* which may be fed back into a new instance of the same Cache
|
|
275
265
|
* via `cache.hydrate`.
|
|
276
266
|
*
|
|
277
|
-
* @method dump
|
|
278
267
|
* @return {Promise<ReadableStream>}
|
|
279
268
|
* @internal
|
|
280
269
|
*/
|
|
@@ -294,7 +283,6 @@ class PersistedCache {
|
|
|
294
283
|
* behavior supports optimizing pre/fetching of data for route transitions
|
|
295
284
|
* via data-only SSR modes.
|
|
296
285
|
*
|
|
297
|
-
* @method hydrate
|
|
298
286
|
* @param {ReadableStream} stream
|
|
299
287
|
* @return {Promise<void>}
|
|
300
288
|
* @internal
|
|
@@ -315,7 +303,6 @@ class PersistedCache {
|
|
|
315
303
|
* It returns properties from options that should be set on the record during the create
|
|
316
304
|
* process. This return value behavior is deprecated.
|
|
317
305
|
*
|
|
318
|
-
* @method clientDidCreate
|
|
319
306
|
* @internal
|
|
320
307
|
* @param identifier
|
|
321
308
|
* @param options
|
|
@@ -328,7 +315,6 @@ class PersistedCache {
|
|
|
328
315
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
329
316
|
* will be part of a save transaction.
|
|
330
317
|
*
|
|
331
|
-
* @method willCommit
|
|
332
318
|
* @internal
|
|
333
319
|
* @param identifier
|
|
334
320
|
*/
|
|
@@ -340,7 +326,6 @@ class PersistedCache {
|
|
|
340
326
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
341
327
|
* was successfully updated as part of a save transaction.
|
|
342
328
|
*
|
|
343
|
-
* @method didCommit
|
|
344
329
|
* @internal
|
|
345
330
|
* @param identifier
|
|
346
331
|
* @param data
|
|
@@ -353,7 +338,6 @@ class PersistedCache {
|
|
|
353
338
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
354
339
|
* was update via a save transaction failed.
|
|
355
340
|
*
|
|
356
|
-
* @method commitWasRejected
|
|
357
341
|
* @internal
|
|
358
342
|
* @param identifier
|
|
359
343
|
* @param errors
|
|
@@ -366,7 +350,6 @@ class PersistedCache {
|
|
|
366
350
|
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
367
351
|
* should be cleared.
|
|
368
352
|
*
|
|
369
|
-
* @method unloadRecord
|
|
370
353
|
* @internal
|
|
371
354
|
* @param identifier
|
|
372
355
|
*/
|
|
@@ -380,7 +363,6 @@ class PersistedCache {
|
|
|
380
363
|
/**
|
|
381
364
|
* Retrieve the data for an attribute from the cache
|
|
382
365
|
*
|
|
383
|
-
* @method getAttr
|
|
384
366
|
* @internal
|
|
385
367
|
* @param identifier
|
|
386
368
|
* @param propertyName
|
|
@@ -393,7 +375,6 @@ class PersistedCache {
|
|
|
393
375
|
/**
|
|
394
376
|
* Retrieve the remote state for an attribute from the cache
|
|
395
377
|
*
|
|
396
|
-
* @method getAttr
|
|
397
378
|
* @internal
|
|
398
379
|
* @param identifier
|
|
399
380
|
* @param propertyName
|
|
@@ -406,7 +387,6 @@ class PersistedCache {
|
|
|
406
387
|
/**
|
|
407
388
|
* Mutate the data for an attribute in the cache
|
|
408
389
|
*
|
|
409
|
-
* @method setAttr
|
|
410
390
|
* @internal
|
|
411
391
|
* @param identifier
|
|
412
392
|
* @param propertyName
|
|
@@ -419,7 +399,6 @@ class PersistedCache {
|
|
|
419
399
|
/**
|
|
420
400
|
* Query the cache for the changed attributes of a resource.
|
|
421
401
|
*
|
|
422
|
-
* @method changedAttrs
|
|
423
402
|
* @internal
|
|
424
403
|
* @param identifier
|
|
425
404
|
* @return
|
|
@@ -431,7 +410,6 @@ class PersistedCache {
|
|
|
431
410
|
/**
|
|
432
411
|
* Query the cache for whether any mutated attributes exist
|
|
433
412
|
*
|
|
434
|
-
* @method hasChangedAttrs
|
|
435
413
|
* @internal
|
|
436
414
|
* @param identifier
|
|
437
415
|
* @return {Boolean}
|
|
@@ -443,7 +421,6 @@ class PersistedCache {
|
|
|
443
421
|
/**
|
|
444
422
|
* Tell the cache to discard any uncommitted mutations to attributes
|
|
445
423
|
*
|
|
446
|
-
* @method rollbackAttrs
|
|
447
424
|
* @internal
|
|
448
425
|
* @param identifier
|
|
449
426
|
* @return the names of attributes that were restored
|
|
@@ -474,7 +451,6 @@ class PersistedCache {
|
|
|
474
451
|
};
|
|
475
452
|
```
|
|
476
453
|
*
|
|
477
|
-
* @method changedRelationships
|
|
478
454
|
* @public
|
|
479
455
|
* @param {StableRecordIdentifier} identifier
|
|
480
456
|
* @return {Map<string, RelationshipDiff>}
|
|
@@ -486,7 +462,6 @@ class PersistedCache {
|
|
|
486
462
|
/**
|
|
487
463
|
* Query the cache for whether any mutated attributes exist
|
|
488
464
|
*
|
|
489
|
-
* @method hasChangedRelationships
|
|
490
465
|
* @public
|
|
491
466
|
* @param {StableRecordIdentifier} identifier
|
|
492
467
|
* @return {Boolean}
|
|
@@ -502,7 +477,6 @@ class PersistedCache {
|
|
|
502
477
|
*
|
|
503
478
|
* This method is a candidate to become a mutation
|
|
504
479
|
*
|
|
505
|
-
* @method rollbackRelationships
|
|
506
480
|
* @public
|
|
507
481
|
* @param {StableRecordIdentifier} identifier
|
|
508
482
|
* @return {String[]} the names of relationships that were restored
|
|
@@ -517,7 +491,6 @@ class PersistedCache {
|
|
|
517
491
|
/**
|
|
518
492
|
* Query the cache for the current state of a relationship property
|
|
519
493
|
*
|
|
520
|
-
* @method getRelationship
|
|
521
494
|
* @internal
|
|
522
495
|
* @param identifier
|
|
523
496
|
* @param propertyName
|
|
@@ -530,7 +503,6 @@ class PersistedCache {
|
|
|
530
503
|
/**
|
|
531
504
|
* Query the remote state for the current state of a relationship property
|
|
532
505
|
*
|
|
533
|
-
* @method getRelationship
|
|
534
506
|
* @internal
|
|
535
507
|
* @param identifier
|
|
536
508
|
* @param propertyName
|
|
@@ -547,7 +519,6 @@ class PersistedCache {
|
|
|
547
519
|
* Update the cache state for the given resource to be marked as locally deleted,
|
|
548
520
|
* or remove such a mark.
|
|
549
521
|
*
|
|
550
|
-
* @method setIsDeleted
|
|
551
522
|
* @internal
|
|
552
523
|
* @param identifier
|
|
553
524
|
* @param isDeleted
|
|
@@ -559,7 +530,6 @@ class PersistedCache {
|
|
|
559
530
|
/**
|
|
560
531
|
* Query the cache for any validation errors applicable to the given resource.
|
|
561
532
|
*
|
|
562
|
-
* @method getErrors
|
|
563
533
|
* @internal
|
|
564
534
|
* @param identifier
|
|
565
535
|
* @return
|
|
@@ -571,7 +541,6 @@ class PersistedCache {
|
|
|
571
541
|
/**
|
|
572
542
|
* Query the cache for whether a given resource has any available data
|
|
573
543
|
*
|
|
574
|
-
* @method isEmpty
|
|
575
544
|
* @internal
|
|
576
545
|
* @param identifier
|
|
577
546
|
* @return {Boolean}
|
|
@@ -584,7 +553,6 @@ class PersistedCache {
|
|
|
584
553
|
* Query the cache for whether a given resource was created locally and not
|
|
585
554
|
* yet persisted.
|
|
586
555
|
*
|
|
587
|
-
* @method isNew
|
|
588
556
|
* @internal
|
|
589
557
|
* @param identifier
|
|
590
558
|
* @return {Boolean}
|
|
@@ -597,7 +565,6 @@ class PersistedCache {
|
|
|
597
565
|
* Query the cache for whether a given resource is marked as deleted (but not
|
|
598
566
|
* necessarily persisted yet).
|
|
599
567
|
*
|
|
600
|
-
* @method isDeleted
|
|
601
568
|
* @internal
|
|
602
569
|
* @param identifier
|
|
603
570
|
* @return {Boolean}
|
|
@@ -610,7 +577,6 @@ class PersistedCache {
|
|
|
610
577
|
* Query the cache for whether a given resource has been deleted and that deletion
|
|
611
578
|
* has also been persisted.
|
|
612
579
|
*
|
|
613
|
-
* @method isDeletionCommitted
|
|
614
580
|
* @internal
|
|
615
581
|
* @param identifier
|
|
616
582
|
* @return {Boolean}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persisted-cache.js","sources":["../src/persisted-cache/cache.ts"],"sourcesContent":["import type { StableRecordIdentifier } from '@warp-drive-mirror/core-types';\nimport type { Cache, ChangedAttributesHash, RelationshipDiff } from '@warp-drive-mirror/core-types/cache';\nimport type { ResourceBlob } from '@warp-drive-mirror/core-types/cache/aliases';\nimport type { Change } from '@warp-drive-mirror/core-types/cache/change';\nimport type { Mutation } from '@warp-drive-mirror/core-types/cache/mutations';\nimport type { Operation } from '@warp-drive-mirror/core-types/cache/operations';\nimport type { CollectionRelationship, ResourceRelationship } from '@warp-drive-mirror/core-types/cache/relationship';\nimport type { StableDocumentIdentifier, StableExistingRecordIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type { Value } from '@warp-drive-mirror/core-types/json/raw';\nimport type { TypeFromInstanceOrString } from '@warp-drive-mirror/core-types/record';\nimport type { RequestContext, StructuredDataDocument, StructuredDocument } from '@warp-drive-mirror/core-types/request';\nimport type { ResourceDocument, SingleResourceDataDocument } from '@warp-drive-mirror/core-types/spec/document';\nimport type { ApiError } from '@warp-drive-mirror/core-types/spec/error';\n/**\n * The PersistedCache wraps a Cache to enhance it with\n * Persisted Storage capabilities.\n *\n * @class PersistedCache\n * @internal\n */\nexport class PersistedCache implements Cache {\n declare _cache: Cache;\n declare _db: IDBDatabase;\n declare version: '2';\n\n constructor(cache: Cache, db: IDBDatabase) {\n this.version = '2';\n this._cache = cache;\n this._db = db;\n }\n\n // Cache Management\n // ================\n\n /**\n * Cache the response to a request\n *\n * Unlike `store.push` which has UPSERT\n * semantics, `put` has `replace` semantics similar to\n * the `http` method `PUT`\n *\n * the individually cacheabl\n * e resource data it may contain\n * should upsert, but the document data surrounding it should\n * fully replace any existing information\n *\n * Note that in order to support inserting arbitrary data\n * to the cache that did not originate from a request `put`\n * should expect to sometimes encounter a document with only\n * a `content` member and therefor must not assume the existence\n * of `request` and `response` on the document.\n *\n * @method put\n * @param {StructuredDocument} doc\n * @return {ResourceDocument}\n * @internal\n */\n put<T>(doc: StructuredDocument<T> | { content: T }): ResourceDocument {\n const result = this._cache.put(doc);\n\n if (!result.lid) {\n return result;\n }\n\n const transaction = this._db.transaction(['request', 'resource'], 'readwrite', { durability: 'relaxed' });\n const request = this._cache.peekRequest({ lid: result.lid })!;\n\n const requests = transaction.objectStore('request');\n const resources = transaction.objectStore('resource');\n\n requests.put(request);\n\n if ('data' in result && result.data) {\n const resourceData: StableExistingRecordIdentifier[] = Array.isArray(result.data) ? result.data : [result.data];\n resourceData.forEach((identifier) => {\n resources.put(this._cache.peek(identifier), identifier.lid);\n });\n }\n\n if ('included' in result && result.included) {\n const included: StableExistingRecordIdentifier[] = result.included;\n included.forEach((identifier) => {\n resources.put(this._cache.peek(identifier), identifier.lid);\n });\n }\n\n return result;\n }\n\n /**\n * Perform an operation on the cache to update the remote state.\n *\n * Note: currently the only valid operation is a MergeOperation\n * which occurs when a collision of identifiers is detected.\n *\n * @method patch\n * @internal\n * @param op the operation to perform\n * @return {void}\n */\n patch(op: Operation): void {\n this._cache.patch(op);\n }\n\n /**\n * Update resource data with a local mutation. Currently supports operations\n * on relationships only.\n *\n * @method mutate\n * @internal\n * @param mutation\n */\n mutate(mutation: Mutation): void {\n this._cache.mutate(mutation);\n }\n\n /**\n * Peek resource data from the Cache.\n *\n * In development, if the return value\n * is JSON the return value\n * will be deep-cloned and deep-frozen\n * to prevent mutation thereby enforcing cache\n * Immutability.\n *\n * This form of peek is useful for implementations\n * that want to feed raw-data from cache to the UI\n * or which want to interact with a blob of data\n * directly from the presentation cache.\n *\n * An implementation might want to do this because\n * de-referencing records which read from their own\n * blob is generally safer because the record does\n * not require retainining connections to the Store\n * and Cache to present data on a per-field basis.\n *\n * This generally takes the place of `getAttr` as\n * an API and may even take the place of `getRelationship`\n * depending on implementation specifics, though this\n * latter usage is less recommended due to the advantages\n * of the Graph handling necessary entanglements and\n * notifications for relational data.\n *\n * @method peek\n * @internal\n * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier\n * @return {ResourceDocument | ResourceBlob | null} the known resource data\n */\n peek<T = unknown>(identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>): T | null;\n peek(identifier: StableDocumentIdentifier): ResourceDocument | null;\n peek(identifier: StableRecordIdentifier | StableDocumentIdentifier): unknown {\n return this._cache.peek(identifier);\n }\n\n /**\n * Peek resource data from the Cache.\n *\n * In development, if the return value\n * is JSON the return value\n * will be deep-cloned and deep-frozen\n * to prevent mutation thereby enforcing cache\n * Immutability.\n *\n * This form of peek is useful for implementations\n * that want to feed raw-data from cache to the UI\n * or which want to interact with a blob of data\n * directly from the presentation cache.\n *\n * An implementation might want to do this because\n * de-referencing records which read from their own\n * blob is generally safer because the record does\n * not require retainining connections to the Store\n * and Cache to present data on a per-field basis.\n *\n * This generally takes the place of `getAttr` as\n * an API and may even take the place of `getRelationship`\n * depending on implementation specifics, though this\n * latter usage is less recommended due to the advantages\n * of the Graph handling necessary entanglements and\n * notifications for relational data.\n *\n * @method peek\n * @internal\n * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier\n * @return {ResourceDocument | ResourceBlob | null} the known resource data\n */\n peekRemoteState<T = unknown>(identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>): T | null;\n peekRemoteState(identifier: StableDocumentIdentifier): ResourceDocument | null;\n peekRemoteState(identifier: StableRecordIdentifier | StableDocumentIdentifier): unknown {\n return this._cache.peekRemoteState(identifier);\n }\n\n /**\n * Peek the Cache for the existing request data associated with\n * a cacheable request\n *\n * @method peekRequest\n * @param {StableDocumentIdentifier}\n * @return {StableDocumentIdentifier | null}\n * @internal\n */\n peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null {\n return this._cache.peekRequest(identifier);\n }\n\n /**\n * Push resource data from a remote source into the cache for this identifier\n *\n * @method upsert\n * @internal\n * @param identifier\n * @param data\n * @param hasRecord\n * @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned\n */\n upsert(identifier: StableRecordIdentifier, data: ResourceBlob, hasRecord: boolean): void | string[] {\n return this._cache.upsert(identifier, data, hasRecord);\n }\n\n // Cache Forking Support\n // =====================\n\n /**\n * Create a fork of the cache from the current state.\n *\n * Applications should typically not call this method themselves,\n * preferring instead to fork at the Store level, which will\n * utilize this method to fork the cache.\n *\n * @method fork\n * @internal\n * @return Promise<Cache>\n */\n fork(): Promise<Cache> {\n return this._cache.fork();\n }\n\n /**\n * Merge a fork back into a parent Cache.\n *\n * Applications should typically not call this method themselves,\n * preferring instead to merge at the Store level, which will\n * utilize this method to merge the caches.\n *\n * @method merge\n * @param {Cache} cache\n * @internal\n * @return Promise<void>\n */\n merge(cache: Cache): Promise<void> {\n return this._cache.merge(cache);\n }\n\n /**\n * Generate the list of changes applied to all\n * record in the store.\n *\n * Each individual resource or document that has\n * been mutated should be described as an individual\n * `Change` entry in the returned array.\n *\n * A `Change` is described by an object containing up to\n * three properties: (1) the `identifier` of the entity that\n * changed; (2) the `op` code of that change being one of\n * `upsert` or `remove`, and if the op is `upsert` a `patch`\n * containing the data to merge into the cache for the given\n * entity.\n *\n * This `patch` is opaque to the Store but should be understood\n * by the Cache and may expect to be utilized by an Adapter\n * when generating data during a `save` operation.\n *\n * It is generally recommended that the `patch` contain only\n * the updated state, ignoring fields that are unchanged\n *\n * ```ts\n * interface Change {\n * identifier: StableRecordIdentifier | StableDocumentIdentifier;\n * op: 'upsert' | 'remove';\n * patch?: unknown;\n * }\n * ```\n *\n * @method diff\n * @internal\n */\n diff(): Promise<Change[]> {\n return this._cache.diff();\n }\n\n // SSR Support\n // ===========\n\n /**\n * Serialize the entire contents of the Cache into a Stream\n * which may be fed back into a new instance of the same Cache\n * via `cache.hydrate`.\n *\n * @method dump\n * @return {Promise<ReadableStream>}\n * @internal\n */\n dump(): Promise<ReadableStream<unknown>> {\n return this._cache.dump();\n }\n\n /**\n * hydrate a Cache from a Stream with content previously serialized\n * from another instance of the same Cache, resolving when hydration\n * is complete.\n *\n * This method should expect to be called both in the context of restoring\n * the Cache during application rehydration after SSR **AND** at unknown\n * times during the lifetime of an already booted application when it is\n * desired to bulk-load additional information into the cache. This latter\n * behavior supports optimizing pre/fetching of data for route transitions\n * via data-only SSR modes.\n *\n * @method hydrate\n * @param {ReadableStream} stream\n * @return {Promise<void>}\n * @internal\n */\n hydrate(stream: ReadableStream<unknown>): Promise<void> {\n return this._cache.hydrate(stream);\n }\n\n // Cache\n // =====\n\n // Resource Support\n // ================\n\n /**\n * [LIFECYLCE] Signal to the cache that a new record has been instantiated on the client\n *\n * It returns properties from options that should be set on the record during the create\n * process. This return value behavior is deprecated.\n *\n * @method clientDidCreate\n * @internal\n * @param identifier\n * @param options\n */\n clientDidCreate(identifier: StableRecordIdentifier, options?: Record<string, unknown>): Record<string, unknown> {\n return this._cache.clientDidCreate(identifier, options);\n }\n\n /**\n * [LIFECYCLE] Signals to the cache that a resource\n * will be part of a save transaction.\n *\n * @method willCommit\n * @internal\n * @param identifier\n */\n willCommit(identifier: StableRecordIdentifier, context: RequestContext): void {\n this._cache.willCommit(identifier, context);\n }\n\n /**\n * [LIFECYCLE] Signals to the cache that a resource\n * was successfully updated as part of a save transaction.\n *\n * @method didCommit\n * @internal\n * @param identifier\n * @param data\n */\n didCommit(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument {\n return this._cache.didCommit(identifier, result);\n }\n\n /**\n * [LIFECYCLE] Signals to the cache that a resource\n * was update via a save transaction failed.\n *\n * @method commitWasRejected\n * @internal\n * @param identifier\n * @param errors\n */\n commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void {\n this._cache.commitWasRejected(identifier, errors);\n }\n\n /**\n * [LIFECYCLE] Signals to the cache that all data for a resource\n * should be cleared.\n *\n * @method unloadRecord\n * @internal\n * @param identifier\n */\n unloadRecord(identifier: StableRecordIdentifier): void {\n this._cache.unloadRecord(identifier);\n }\n\n // Granular Resource Data APIs\n // ===========================\n\n /**\n * Retrieve the data for an attribute from the cache\n *\n * @method getAttr\n * @internal\n * @param identifier\n * @param propertyName\n * @return {unknown}\n */\n getAttr(identifier: StableRecordIdentifier, field: string): Value | undefined {\n return this._cache.getAttr(identifier, field);\n }\n\n /**\n * Retrieve the remote state for an attribute from the cache\n *\n * @method getAttr\n * @internal\n * @param identifier\n * @param propertyName\n * @return {unknown}\n */\n getRemoteAttr(identifier: StableRecordIdentifier, field: string): Value | undefined {\n return this._cache.getRemoteAttr(identifier, field);\n }\n\n /**\n * Mutate the data for an attribute in the cache\n *\n * @method setAttr\n * @internal\n * @param identifier\n * @param propertyName\n * @param value\n */\n setAttr(identifier: StableRecordIdentifier, propertyName: string, value: Value): void {\n this._cache.setAttr(identifier, propertyName, value);\n }\n\n /**\n * Query the cache for the changed attributes of a resource.\n *\n * @method changedAttrs\n * @internal\n * @param identifier\n * @return\n */\n changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash {\n return this._cache.changedAttrs(identifier);\n }\n\n /**\n * Query the cache for whether any mutated attributes exist\n *\n * @method hasChangedAttrs\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n hasChangedAttrs(identifier: StableRecordIdentifier): boolean {\n return this._cache.hasChangedAttrs(identifier);\n }\n\n /**\n * Tell the cache to discard any uncommitted mutations to attributes\n *\n * @method rollbackAttrs\n * @internal\n * @param identifier\n * @return the names of attributes that were restored\n */\n rollbackAttrs(identifier: StableRecordIdentifier): string[] {\n return this._cache.rollbackAttrs(identifier);\n }\n\n /**\n * Query the cache for the changes to relationships of a resource.\n *\n * Returns a map of relationship names to RelationshipDiff objects.\n *\n * ```ts\n * type RelationshipDiff =\n | {\n kind: 'collection';\n remoteState: StableRecordIdentifier[];\n additions: Set<StableRecordIdentifier>;\n removals: Set<StableRecordIdentifier>;\n localState: StableRecordIdentifier[];\n reordered: boolean;\n }\n | {\n kind: 'resource';\n remoteState: StableRecordIdentifier | null;\n localState: StableRecordIdentifier | null;\n };\n ```\n *\n * @method changedRelationships\n * @public\n * @param {StableRecordIdentifier} identifier\n * @return {Map<string, RelationshipDiff>}\n */\n changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff> {\n return this._cache.changedRelationships(identifier);\n }\n\n /**\n * Query the cache for whether any mutated attributes exist\n *\n * @method hasChangedRelationships\n * @public\n * @param {StableRecordIdentifier} identifier\n * @return {Boolean}\n */\n hasChangedRelationships(identifier: StableRecordIdentifier): boolean {\n return this._cache.hasChangedRelationships(identifier);\n }\n\n /**\n * Tell the cache to discard any uncommitted mutations to relationships.\n *\n * This will also discard the change on any appropriate inverses.\n *\n * This method is a candidate to become a mutation\n *\n * @method rollbackRelationships\n * @public\n * @param {StableRecordIdentifier} identifier\n * @return {String[]} the names of relationships that were restored\n */\n rollbackRelationships(identifier: StableRecordIdentifier): string[] {\n return this._cache.rollbackRelationships(identifier);\n }\n\n // Relationships\n // =============\n\n /**\n * Query the cache for the current state of a relationship property\n *\n * @method getRelationship\n * @internal\n * @param identifier\n * @param propertyName\n * @return resource relationship object\n */\n getRelationship(\n identifier: StableRecordIdentifier,\n field: string,\n isCollection?: boolean\n ): ResourceRelationship | CollectionRelationship {\n return this._cache.getRelationship(identifier, field, isCollection);\n }\n\n /**\n * Query the remote state for the current state of a relationship property\n *\n * @method getRelationship\n * @internal\n * @param identifier\n * @param propertyName\n * @return resource relationship object\n */\n getRemoteRelationship(\n identifier: StableRecordIdentifier,\n field: string,\n isCollection?: boolean\n ): ResourceRelationship | CollectionRelationship {\n return this._cache.getRemoteRelationship(identifier, field, isCollection);\n }\n\n // Resource State\n // ===============\n\n /**\n * Update the cache state for the given resource to be marked as locally deleted,\n * or remove such a mark.\n *\n * @method setIsDeleted\n * @internal\n * @param identifier\n * @param isDeleted\n */\n setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void {\n this._cache.setIsDeleted(identifier, isDeleted);\n }\n\n /**\n * Query the cache for any validation errors applicable to the given resource.\n *\n * @method getErrors\n * @internal\n * @param identifier\n * @return\n */\n getErrors(identifier: StableRecordIdentifier): ApiError[] {\n return this._cache.getErrors(identifier);\n }\n\n /**\n * Query the cache for whether a given resource has any available data\n *\n * @method isEmpty\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n isEmpty(identifier: StableRecordIdentifier): boolean {\n return this._cache.isEmpty(identifier);\n }\n\n /**\n * Query the cache for whether a given resource was created locally and not\n * yet persisted.\n *\n * @method isNew\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n isNew(identifier: StableRecordIdentifier): boolean {\n return this._cache.isNew(identifier);\n }\n\n /**\n * Query the cache for whether a given resource is marked as deleted (but not\n * necessarily persisted yet).\n *\n * @method isDeleted\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n isDeleted(identifier: StableRecordIdentifier): boolean {\n return this._cache.isDeleted(identifier);\n }\n\n /**\n * Query the cache for whether a given resource has been deleted and that deletion\n * has also been persisted.\n *\n * @method isDeletionCommitted\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n isDeletionCommitted(identifier: StableRecordIdentifier): boolean {\n return this._cache.isDeletionCommitted(identifier);\n }\n}\n"],"names":["PersistedCache","constructor","cache","db","version","_cache","_db","put","doc","result","lid","transaction","durability","request","peekRequest","requests","objectStore","resources","data","resourceData","Array","isArray","forEach","identifier","peek","included","patch","op","mutate","mutation","peekRemoteState","upsert","hasRecord","fork","merge","diff","dump","hydrate","stream","clientDidCreate","options","willCommit","context","didCommit","commitWasRejected","errors","unloadRecord","getAttr","field","getRemoteAttr","setAttr","propertyName","value","changedAttrs","hasChangedAttrs","rollbackAttrs","changedRelationships","hasChangedRelationships","rollbackRelationships","getRelationship","isCollection","getRemoteRelationship","setIsDeleted","isDeleted","getErrors","isEmpty","isNew","isDeletionCommitted"],"mappings":"AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc,CAAkB;AAK3CC,EAAAA,WAAWA,CAACC,KAAY,EAAEC,EAAe,EAAE;IACzC,IAAI,CAACC,OAAO,GAAG,GAAG;IAClB,IAAI,CAACC,MAAM,GAAGH,KAAK;IACnB,IAAI,CAACI,GAAG,GAAGH,EAAE;AACf;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEI,GAAGA,CAAIC,GAA2C,EAAoB;IACpE,MAAMC,MAAM,GAAG,IAAI,CAACJ,MAAM,CAACE,GAAG,CAACC,GAAG,CAAC;AAEnC,IAAA,IAAI,CAACC,MAAM,CAACC,GAAG,EAAE;AACf,MAAA,OAAOD,MAAM;AACf;AAEA,IAAA,MAAME,WAAW,GAAG,IAAI,CAACL,GAAG,CAACK,WAAW,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE,WAAW,EAAE;AAAEC,MAAAA,UAAU,EAAE;AAAU,KAAC,CAAC;AACzG,IAAA,MAAMC,OAAO,GAAG,IAAI,CAACR,MAAM,CAACS,WAAW,CAAC;MAAEJ,GAAG,EAAED,MAAM,CAACC;AAAI,KAAC,CAAE;AAE7D,IAAA,MAAMK,QAAQ,GAAGJ,WAAW,CAACK,WAAW,CAAC,SAAS,CAAC;AACnD,IAAA,MAAMC,SAAS,GAAGN,WAAW,CAACK,WAAW,CAAC,UAAU,CAAC;AAErDD,IAAAA,QAAQ,CAACR,GAAG,CAACM,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A;AACA;;EAGEL,IAAIA,CAACD,UAA6D,EAAW;AAC3E,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACmB,IAAI,CAACD,UAAU,CAAC;AACrC;;AAEA;AACF;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;AACA;;EAGEO,eAAeA,CAACP,UAA6D,EAAW;AACtF,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACyB,eAAe,CAACP,UAAU,CAAC;AAChD;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACET,WAAWA,CAACS,UAAoC,EAA+C;AAC7F,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACS,WAAW,CAACS,UAAU,CAAC;AAC5C;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEQ,EAAAA,MAAMA,CAACR,UAAkC,EAAEL,IAAkB,EAAEc,SAAkB,EAAmB;IAClG,OAAO,IAAI,CAAC3B,MAAM,CAAC0B,MAAM,CAACR,UAAU,EAAEL,IAAI,EAAEc,SAAS,CAAC;AACxD;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,IAAIA,GAAmB;AACrB,IAAA,OAAO,IAAI,CAAC5B,MAAM,CAAC4B,IAAI,EAAE;AAC3B;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,KAAKA,CAAChC,KAAY,EAAiB;AACjC,IAAA,OAAO,IAAI,CAACG,MAAM,CAAC6B,KAAK,CAAChC,KAAK,CAAC;AACjC;;AAEA;AACF;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;AAC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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEiC,oBAAoBA,CAACjC,UAAkC,EAAiC;AACtF,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACmD,oBAAoB,CAACjC,UAAU,CAAC;AACrD;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEkC,uBAAuBA,CAAClC,UAAkC,EAAW;AACnE,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACoD,uBAAuB,CAAClC,UAAU,CAAC;AACxD;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEmC,qBAAqBA,CAACnC,UAAkC,EAAY;AAClE,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACqD,qBAAqB,CAACnC,UAAU,CAAC;AACtD;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEoC,EAAAA,eAAeA,CACbpC,UAAkC,EAClCyB,KAAa,EACbY,YAAsB,EACyB;IAC/C,OAAO,IAAI,CAACvD,MAAM,CAACsD,eAAe,CAACpC,UAAU,EAAEyB,KAAK,EAAEY,YAAY,CAAC;AACrE;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,qBAAqBA,CACnBtC,UAAkC,EAClCyB,KAAa,EACbY,YAAsB,EACyB;IAC/C,OAAO,IAAI,CAACvD,MAAM,CAACwD,qBAAqB,CAACtC,UAAU,EAAEyB,KAAK,EAAEY,YAAY,CAAC;AAC3E;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEE,EAAAA,YAAYA,CAACvC,UAAkC,EAAEwC,SAAkB,EAAQ;IACzE,IAAI,CAAC1D,MAAM,CAACyD,YAAY,CAACvC,UAAU,EAAEwC,SAAS,CAAC;AACjD;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,SAASA,CAACzC,UAAkC,EAAc;AACxD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC2D,SAAS,CAACzC,UAAU,CAAC;AAC1C;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE0C,OAAOA,CAAC1C,UAAkC,EAAW;AACnD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC4D,OAAO,CAAC1C,UAAU,CAAC;AACxC;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE2C,KAAKA,CAAC3C,UAAkC,EAAW;AACjD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC6D,KAAK,CAAC3C,UAAU,CAAC;AACtC;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEwC,SAASA,CAACxC,UAAkC,EAAW;AACrD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC0D,SAAS,CAACxC,UAAU,CAAC;AAC1C;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE4C,mBAAmBA,CAAC5C,UAAkC,EAAW;AAC/D,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC8D,mBAAmB,CAAC5C,UAAU,CAAC;AACpD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"persisted-cache.js","sources":["../src/persisted-cache/cache.ts"],"sourcesContent":["import type { StableRecordIdentifier } from '@warp-drive-mirror/core-types';\nimport type { Cache, ChangedAttributesHash, RelationshipDiff } from '@warp-drive-mirror/core-types/cache';\nimport type { ResourceBlob } from '@warp-drive-mirror/core-types/cache/aliases';\nimport type { Change } from '@warp-drive-mirror/core-types/cache/change';\nimport type { Mutation } from '@warp-drive-mirror/core-types/cache/mutations';\nimport type { Operation } from '@warp-drive-mirror/core-types/cache/operations';\nimport type { CollectionRelationship, ResourceRelationship } from '@warp-drive-mirror/core-types/cache/relationship';\nimport type { StableDocumentIdentifier, StableExistingRecordIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type { Value } from '@warp-drive-mirror/core-types/json/raw';\nimport type { TypeFromInstanceOrString } from '@warp-drive-mirror/core-types/record';\nimport type { RequestContext, StructuredDataDocument, StructuredDocument } from '@warp-drive-mirror/core-types/request';\nimport type { ResourceDocument, SingleResourceDataDocument } from '@warp-drive-mirror/core-types/spec/document';\nimport type { ApiError } from '@warp-drive-mirror/core-types/spec/error';\n/**\n * The PersistedCache wraps a Cache to enhance it with\n * Persisted Storage capabilities.\n *\n * @class PersistedCache\n * @internal\n */\nexport class PersistedCache implements Cache {\n declare _cache: Cache;\n declare _db: IDBDatabase;\n declare version: '2';\n\n constructor(cache: Cache, db: IDBDatabase) {\n this.version = '2';\n this._cache = cache;\n this._db = db;\n }\n\n // Cache Management\n // ================\n\n /**\n * Cache the response to a request\n *\n * Unlike `store.push` which has UPSERT\n * semantics, `put` has `replace` semantics similar to\n * the `http` method `PUT`\n *\n * the individually cacheabl\n * e resource data it may contain\n * should upsert, but the document data surrounding it should\n * fully replace any existing information\n *\n * Note that in order to support inserting arbitrary data\n * to the cache that did not originate from a request `put`\n * should expect to sometimes encounter a document with only\n * a `content` member and therefor must not assume the existence\n * of `request` and `response` on the document.\n *\n * @param {StructuredDocument} doc\n * @return {ResourceDocument}\n * @internal\n */\n put<T>(doc: StructuredDocument<T> | { content: T }): ResourceDocument {\n const result = this._cache.put(doc);\n\n if (!result.lid) {\n return result;\n }\n\n const transaction = this._db.transaction(['request', 'resource'], 'readwrite', { durability: 'relaxed' });\n const request = this._cache.peekRequest({ lid: result.lid })!;\n\n const requests = transaction.objectStore('request');\n const resources = transaction.objectStore('resource');\n\n requests.put(request);\n\n if ('data' in result && result.data) {\n const resourceData: StableExistingRecordIdentifier[] = Array.isArray(result.data) ? result.data : [result.data];\n resourceData.forEach((identifier) => {\n resources.put(this._cache.peek(identifier), identifier.lid);\n });\n }\n\n if ('included' in result && result.included) {\n const included: StableExistingRecordIdentifier[] = result.included;\n included.forEach((identifier) => {\n resources.put(this._cache.peek(identifier), identifier.lid);\n });\n }\n\n return result;\n }\n\n /**\n * Perform an operation on the cache to update the remote state.\n *\n * Note: currently the only valid operation is a MergeOperation\n * which occurs when a collision of identifiers is detected.\n *\n * @internal\n * @param op the operation to perform\n * @return {void}\n */\n patch(op: Operation): void {\n this._cache.patch(op);\n }\n\n /**\n * Update resource data with a local mutation. Currently supports operations\n * on relationships only.\n *\n * @internal\n * @param mutation\n */\n mutate(mutation: Mutation): void {\n this._cache.mutate(mutation);\n }\n\n /**\n * Peek resource data from the Cache.\n *\n * In development, if the return value\n * is JSON the return value\n * will be deep-cloned and deep-frozen\n * to prevent mutation thereby enforcing cache\n * Immutability.\n *\n * This form of peek is useful for implementations\n * that want to feed raw-data from cache to the UI\n * or which want to interact with a blob of data\n * directly from the presentation cache.\n *\n * An implementation might want to do this because\n * de-referencing records which read from their own\n * blob is generally safer because the record does\n * not require retainining connections to the Store\n * and Cache to present data on a per-field basis.\n *\n * This generally takes the place of `getAttr` as\n * an API and may even take the place of `getRelationship`\n * depending on implementation specifics, though this\n * latter usage is less recommended due to the advantages\n * of the Graph handling necessary entanglements and\n * notifications for relational data.\n *\n * @internal\n * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier\n * @return {ResourceDocument | ResourceBlob | null} the known resource data\n */\n peek<T = unknown>(identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>): T | null;\n peek(identifier: StableDocumentIdentifier): ResourceDocument | null;\n peek(identifier: StableRecordIdentifier | StableDocumentIdentifier): unknown {\n return this._cache.peek(identifier);\n }\n\n /**\n * Peek resource data from the Cache.\n *\n * In development, if the return value\n * is JSON the return value\n * will be deep-cloned and deep-frozen\n * to prevent mutation thereby enforcing cache\n * Immutability.\n *\n * This form of peek is useful for implementations\n * that want to feed raw-data from cache to the UI\n * or which want to interact with a blob of data\n * directly from the presentation cache.\n *\n * An implementation might want to do this because\n * de-referencing records which read from their own\n * blob is generally safer because the record does\n * not require retainining connections to the Store\n * and Cache to present data on a per-field basis.\n *\n * This generally takes the place of `getAttr` as\n * an API and may even take the place of `getRelationship`\n * depending on implementation specifics, though this\n * latter usage is less recommended due to the advantages\n * of the Graph handling necessary entanglements and\n * notifications for relational data.\n *\n * @internal\n * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier\n * @return {ResourceDocument | ResourceBlob | null} the known resource data\n */\n peekRemoteState<T = unknown>(identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>): T | null;\n peekRemoteState(identifier: StableDocumentIdentifier): ResourceDocument | null;\n peekRemoteState(identifier: StableRecordIdentifier | StableDocumentIdentifier): unknown {\n return this._cache.peekRemoteState(identifier);\n }\n\n /**\n * Peek the Cache for the existing request data associated with\n * a cacheable request\n *\n * @param {StableDocumentIdentifier}\n * @return {StableDocumentIdentifier | null}\n * @internal\n */\n peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null {\n return this._cache.peekRequest(identifier);\n }\n\n /**\n * Push resource data from a remote source into the cache for this identifier\n *\n * @internal\n * @param identifier\n * @param data\n * @param hasRecord\n * @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned\n */\n upsert(identifier: StableRecordIdentifier, data: ResourceBlob, hasRecord: boolean): void | string[] {\n return this._cache.upsert(identifier, data, hasRecord);\n }\n\n // Cache Forking Support\n // =====================\n\n /**\n * Create a fork of the cache from the current state.\n *\n * Applications should typically not call this method themselves,\n * preferring instead to fork at the Store level, which will\n * utilize this method to fork the cache.\n *\n * @internal\n * @return {Promise<Cache>}\n */\n fork(): Promise<Cache> {\n return this._cache.fork();\n }\n\n /**\n * Merge a fork back into a parent Cache.\n *\n * Applications should typically not call this method themselves,\n * preferring instead to merge at the Store level, which will\n * utilize this method to merge the caches.\n *\n * @param {Cache} cache\n * @internal\n * @return {Promise<void>}\n */\n merge(cache: Cache): Promise<void> {\n return this._cache.merge(cache);\n }\n\n /**\n * Generate the list of changes applied to all\n * record in the store.\n *\n * Each individual resource or document that has\n * been mutated should be described as an individual\n * `Change` entry in the returned array.\n *\n * A `Change` is described by an object containing up to\n * three properties: (1) the `identifier` of the entity that\n * changed; (2) the `op` code of that change being one of\n * `upsert` or `remove`, and if the op is `upsert` a `patch`\n * containing the data to merge into the cache for the given\n * entity.\n *\n * This `patch` is opaque to the Store but should be understood\n * by the Cache and may expect to be utilized by an Adapter\n * when generating data during a `save` operation.\n *\n * It is generally recommended that the `patch` contain only\n * the updated state, ignoring fields that are unchanged\n *\n * ```ts\n * interface Change {\n * identifier: StableRecordIdentifier | StableDocumentIdentifier;\n * op: 'upsert' | 'remove';\n * patch?: unknown;\n * }\n * ```\n *\n * @internal\n */\n diff(): Promise<Change[]> {\n return this._cache.diff();\n }\n\n // SSR Support\n // ===========\n\n /**\n * Serialize the entire contents of the Cache into a Stream\n * which may be fed back into a new instance of the same Cache\n * via `cache.hydrate`.\n *\n * @return {Promise<ReadableStream>}\n * @internal\n */\n dump(): Promise<ReadableStream<unknown>> {\n return this._cache.dump();\n }\n\n /**\n * hydrate a Cache from a Stream with content previously serialized\n * from another instance of the same Cache, resolving when hydration\n * is complete.\n *\n * This method should expect to be called both in the context of restoring\n * the Cache during application rehydration after SSR **AND** at unknown\n * times during the lifetime of an already booted application when it is\n * desired to bulk-load additional information into the cache. This latter\n * behavior supports optimizing pre/fetching of data for route transitions\n * via data-only SSR modes.\n *\n * @param {ReadableStream} stream\n * @return {Promise<void>}\n * @internal\n */\n hydrate(stream: ReadableStream<unknown>): Promise<void> {\n return this._cache.hydrate(stream);\n }\n\n // Cache\n // =====\n\n // Resource Support\n // ================\n\n /**\n * [LIFECYLCE] Signal to the cache that a new record has been instantiated on the client\n *\n * It returns properties from options that should be set on the record during the create\n * process. This return value behavior is deprecated.\n *\n * @internal\n * @param identifier\n * @param options\n */\n clientDidCreate(identifier: StableRecordIdentifier, options?: Record<string, unknown>): Record<string, unknown> {\n return this._cache.clientDidCreate(identifier, options);\n }\n\n /**\n * [LIFECYCLE] Signals to the cache that a resource\n * will be part of a save transaction.\n *\n * @internal\n * @param identifier\n */\n willCommit(identifier: StableRecordIdentifier, context: RequestContext): void {\n this._cache.willCommit(identifier, context);\n }\n\n /**\n * [LIFECYCLE] Signals to the cache that a resource\n * was successfully updated as part of a save transaction.\n *\n * @internal\n * @param identifier\n * @param data\n */\n didCommit(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument {\n return this._cache.didCommit(identifier, result);\n }\n\n /**\n * [LIFECYCLE] Signals to the cache that a resource\n * was update via a save transaction failed.\n *\n * @internal\n * @param identifier\n * @param errors\n */\n commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void {\n this._cache.commitWasRejected(identifier, errors);\n }\n\n /**\n * [LIFECYCLE] Signals to the cache that all data for a resource\n * should be cleared.\n *\n * @internal\n * @param identifier\n */\n unloadRecord(identifier: StableRecordIdentifier): void {\n this._cache.unloadRecord(identifier);\n }\n\n // Granular Resource Data APIs\n // ===========================\n\n /**\n * Retrieve the data for an attribute from the cache\n *\n * @internal\n * @param identifier\n * @param propertyName\n * @return {unknown}\n */\n getAttr(identifier: StableRecordIdentifier, field: string): Value | undefined {\n return this._cache.getAttr(identifier, field);\n }\n\n /**\n * Retrieve the remote state for an attribute from the cache\n *\n * @internal\n * @param identifier\n * @param propertyName\n * @return {unknown}\n */\n getRemoteAttr(identifier: StableRecordIdentifier, field: string): Value | undefined {\n return this._cache.getRemoteAttr(identifier, field);\n }\n\n /**\n * Mutate the data for an attribute in the cache\n *\n * @internal\n * @param identifier\n * @param propertyName\n * @param value\n */\n setAttr(identifier: StableRecordIdentifier, propertyName: string, value: Value): void {\n this._cache.setAttr(identifier, propertyName, value);\n }\n\n /**\n * Query the cache for the changed attributes of a resource.\n *\n * @internal\n * @param identifier\n * @return\n */\n changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash {\n return this._cache.changedAttrs(identifier);\n }\n\n /**\n * Query the cache for whether any mutated attributes exist\n *\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n hasChangedAttrs(identifier: StableRecordIdentifier): boolean {\n return this._cache.hasChangedAttrs(identifier);\n }\n\n /**\n * Tell the cache to discard any uncommitted mutations to attributes\n *\n * @internal\n * @param identifier\n * @return the names of attributes that were restored\n */\n rollbackAttrs(identifier: StableRecordIdentifier): string[] {\n return this._cache.rollbackAttrs(identifier);\n }\n\n /**\n * Query the cache for the changes to relationships of a resource.\n *\n * Returns a map of relationship names to RelationshipDiff objects.\n *\n * ```ts\n * type RelationshipDiff =\n | {\n kind: 'collection';\n remoteState: StableRecordIdentifier[];\n additions: Set<StableRecordIdentifier>;\n removals: Set<StableRecordIdentifier>;\n localState: StableRecordIdentifier[];\n reordered: boolean;\n }\n | {\n kind: 'resource';\n remoteState: StableRecordIdentifier | null;\n localState: StableRecordIdentifier | null;\n };\n ```\n *\n * @public\n * @param {StableRecordIdentifier} identifier\n * @return {Map<string, RelationshipDiff>}\n */\n changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff> {\n return this._cache.changedRelationships(identifier);\n }\n\n /**\n * Query the cache for whether any mutated attributes exist\n *\n * @public\n * @param {StableRecordIdentifier} identifier\n * @return {Boolean}\n */\n hasChangedRelationships(identifier: StableRecordIdentifier): boolean {\n return this._cache.hasChangedRelationships(identifier);\n }\n\n /**\n * Tell the cache to discard any uncommitted mutations to relationships.\n *\n * This will also discard the change on any appropriate inverses.\n *\n * This method is a candidate to become a mutation\n *\n * @public\n * @param {StableRecordIdentifier} identifier\n * @return {String[]} the names of relationships that were restored\n */\n rollbackRelationships(identifier: StableRecordIdentifier): string[] {\n return this._cache.rollbackRelationships(identifier);\n }\n\n // Relationships\n // =============\n\n /**\n * Query the cache for the current state of a relationship property\n *\n * @internal\n * @param identifier\n * @param propertyName\n * @return resource relationship object\n */\n getRelationship(\n identifier: StableRecordIdentifier,\n field: string,\n isCollection?: boolean\n ): ResourceRelationship | CollectionRelationship {\n return this._cache.getRelationship(identifier, field, isCollection);\n }\n\n /**\n * Query the remote state for the current state of a relationship property\n *\n * @internal\n * @param identifier\n * @param propertyName\n * @return resource relationship object\n */\n getRemoteRelationship(\n identifier: StableRecordIdentifier,\n field: string,\n isCollection?: boolean\n ): ResourceRelationship | CollectionRelationship {\n return this._cache.getRemoteRelationship(identifier, field, isCollection);\n }\n\n // Resource State\n // ===============\n\n /**\n * Update the cache state for the given resource to be marked as locally deleted,\n * or remove such a mark.\n *\n * @internal\n * @param identifier\n * @param isDeleted\n */\n setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void {\n this._cache.setIsDeleted(identifier, isDeleted);\n }\n\n /**\n * Query the cache for any validation errors applicable to the given resource.\n *\n * @internal\n * @param identifier\n * @return\n */\n getErrors(identifier: StableRecordIdentifier): ApiError[] {\n return this._cache.getErrors(identifier);\n }\n\n /**\n * Query the cache for whether a given resource has any available data\n *\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n isEmpty(identifier: StableRecordIdentifier): boolean {\n return this._cache.isEmpty(identifier);\n }\n\n /**\n * Query the cache for whether a given resource was created locally and not\n * yet persisted.\n *\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n isNew(identifier: StableRecordIdentifier): boolean {\n return this._cache.isNew(identifier);\n }\n\n /**\n * Query the cache for whether a given resource is marked as deleted (but not\n * necessarily persisted yet).\n *\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n isDeleted(identifier: StableRecordIdentifier): boolean {\n return this._cache.isDeleted(identifier);\n }\n\n /**\n * Query the cache for whether a given resource has been deleted and that deletion\n * has also been persisted.\n *\n * @internal\n * @param identifier\n * @return {Boolean}\n */\n isDeletionCommitted(identifier: StableRecordIdentifier): boolean {\n return this._cache.isDeletionCommitted(identifier);\n }\n}\n"],"names":["PersistedCache","constructor","cache","db","version","_cache","_db","put","doc","result","lid","transaction","durability","request","peekRequest","requests","objectStore","resources","data","resourceData","Array","isArray","forEach","identifier","peek","included","patch","op","mutate","mutation","peekRemoteState","upsert","hasRecord","fork","merge","diff","dump","hydrate","stream","clientDidCreate","options","willCommit","context","didCommit","commitWasRejected","errors","unloadRecord","getAttr","field","getRemoteAttr","setAttr","propertyName","value","changedAttrs","hasChangedAttrs","rollbackAttrs","changedRelationships","hasChangedRelationships","rollbackRelationships","getRelationship","isCollection","getRemoteRelationship","setIsDeleted","isDeleted","getErrors","isEmpty","isNew","isDeletionCommitted"],"mappings":"AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc,CAAkB;AAK3CC,EAAAA,WAAWA,CAACC,KAAY,EAAEC,EAAe,EAAE;IACzC,IAAI,CAACC,OAAO,GAAG,GAAG;IAClB,IAAI,CAACC,MAAM,GAAGH,KAAK;IACnB,IAAI,CAACI,GAAG,GAAGH,EAAE;AACf;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEI,GAAGA,CAAIC,GAA2C,EAAoB;IACpE,MAAMC,MAAM,GAAG,IAAI,CAACJ,MAAM,CAACE,GAAG,CAACC,GAAG,CAAC;AAEnC,IAAA,IAAI,CAACC,MAAM,CAACC,GAAG,EAAE;AACf,MAAA,OAAOD,MAAM;AACf;AAEA,IAAA,MAAME,WAAW,GAAG,IAAI,CAACL,GAAG,CAACK,WAAW,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE,WAAW,EAAE;AAAEC,MAAAA,UAAU,EAAE;AAAU,KAAC,CAAC;AACzG,IAAA,MAAMC,OAAO,GAAG,IAAI,CAACR,MAAM,CAACS,WAAW,CAAC;MAAEJ,GAAG,EAAED,MAAM,CAACC;AAAI,KAAC,CAAE;AAE7D,IAAA,MAAMK,QAAQ,GAAGJ,WAAW,CAACK,WAAW,CAAC,SAAS,CAAC;AACnD,IAAA,MAAMC,SAAS,GAAGN,WAAW,CAACK,WAAW,CAAC,UAAU,CAAC;AAErDD,IAAAA,QAAQ,CAACR,GAAG,CAACM,OAAO,CAAC;AAErB,IAAA,IAAI,MAAM,IAAIJ,MAAM,IAA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AAClB,MAAM,CAACmB,IAAI,CAACD,UAAU,CAAC;AACrC;;AAEA;AACF;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;;EAGEO,eAAeA,CAACP,UAA6D,EAAW;AACtF,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACyB,eAAe,CAACP,UAAU,CAAC;AAChD;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACET,WAAWA,CAACS,UAAoC,EAA+C;AAC7F,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACS,WAAW,CAACS,UAAU,CAAC;AAC5C;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEQ,EAAAA,MAAMA,CAACR,UAAkC,EAAEL,IAAkB,EAAEc,SAAkB,EAAmB;IAClG,OAAO,IAAI,CAAC3B,MAAM,CAAC0B,MAAM,CAACR,UAAU,EAAEL,IAAI,EAAEc,SAAS,CAAC;AACxD;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,IAAIA,GAAmB;AACrB,IAAA,OAAO,IAAI,CAAC5B,MAAM,CAAC4B,IAAI,EAAE;AAC3B;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,KAAKA,CAAChC,KAAY,EAAiB;AACjC,IAAA,OAAO,IAAI,CAACG,MAAM,CAAC6B,KAAK,CAAChC,KAAK,CAAC;AACjC;;AAEA;AACF;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;AACA;AACEiC,EAAAA,IAAIA,GAAsB;AACxB,IAAA,OAAO,IAAI,CAAC9B,MAAM,CAAC8B,IAAI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EAAW;AACnD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC4D,OAAO,CAAC1C,UAAU,CAAC;AACxC;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE2C,KAAKA,CAAC3C,UAAkC,EAAW;AACjD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC6D,KAAK,CAAC3C,UAAU,CAAC;AACtC;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEwC,SAASA,CAACxC,UAAkC,EAAW;AACrD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC0D,SAAS,CAACxC,UAAU,CAAC;AAC1C;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE4C,mBAAmBA,CAAC5C,UAAkC,EAAW;AAC/D,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC8D,mBAAmB,CAAC5C,UAAU,CAAC;AACpD;AACF;;;;"}
|
package/dist/worker-fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-fetch.js","sources":["../src/data-worker/fetch.ts"],"sourcesContent":["import type { RequestInfo } from '@ember-data-mirror/request';\nimport { createDeferred } from '@ember-data-mirror/request';\nimport type { Context } from '@ember-data-mirror/request/-private/context';\nimport type { Deferred, Future, NextFn } from '@ember-data-mirror/request/-private/types';\nimport { TESTING } from '@warp-drive-mirror/build-config/env';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\nimport type { ApiError } from '@warp-drive-mirror/core-types/spec/error';\n\nimport type { AbortEventData, MainThreadEvent, RequestEventData } from './types';\n\nexport interface FastBoot {\n require(moduleName: string): unknown;\n isFastBoot: boolean;\n request: Request;\n}\n\ndeclare global {\n const FastBoot: undefined | FastBoot;\n}\n\nconst isServerEnv = typeof FastBoot !== 'undefined';\n\nfunction isAggregateError(error: Error & { errors?: ApiError[] }): error is AggregateError & { errors: ApiError[] } {\n return error instanceof AggregateError || (error.name === 'AggregateError' && Array.isArray(error.errors));\n}\n\ntype RobustError = Error & { error: string | object; errors?: ApiError[]; content?: unknown };\n\nfunction stitchTrace(stack: string, origin: string) {\n if (origin.startsWith('Error\\n')) {\n return origin.slice(6) + '\\n' + stack;\n }\n return origin + '\\n' + stack;\n}\n\nfunction cloneError(error: RobustError, stack: string) {\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 = stitchTrace(error.stack || '', stack);\n cloned.error = error.error;\n\n // copy over enumerable properties\n Object.assign(cloned, error);\n\n return cloned;\n}\n\nexport class WorkerFetch {\n declare worker: Worker | SharedWorker;\n declare threadId: string;\n declare pending: Map<\n number,\n { context: Context; signal: AbortSignal | null; abortFn: () => void; deferred: Deferred<unknown>; stack: string }\n >;\n declare channel: MessageChannel;\n\n constructor(worker: Worker | SharedWorker | null) {\n this.threadId = isServerEnv ? '' : crypto.randomUUID();\n this.pending = new Map();\n\n const isTesting = TESTING ? true : false;\n assert(`Expected a SharedWorker instance`, isTesting || isServerEnv || worker instanceof SharedWorker);\n this.worker = worker as SharedWorker;\n\n if (!isServerEnv) {\n const fn = (event: MainThreadEvent<unknown>) => {\n const { type, id, data } = event.data;\n const info = this.cleanupRequest(id);\n\n // typically this means the request was aborted\n if (!info) {\n return;\n }\n\n if (type === 'success-response') {\n const { deferred } = info;\n\n const { response, content } = data;\n\n if (response) {\n (response as { headers: Headers }).headers = new Headers(response.headers);\n info.context.setResponse(new Response(null, response));\n }\n\n deferred.resolve(content);\n return;\n }\n\n if (type === 'error-response') {\n const { deferred, stack } = info;\n\n deferred.reject(cloneError(data, stack));\n return;\n }\n };\n\n if (worker instanceof SharedWorker) {\n worker.port.postMessage({ type: 'connect', thread: this.threadId });\n worker.port.onmessage = fn;\n } else if (worker) {\n this.channel = new MessageChannel();\n worker.postMessage({ type: 'connect', thread: this.threadId }, [this.channel.port2]);\n\n this.channel.port1.onmessage = fn;\n }\n }\n }\n\n cleanupRequest(id: number) {\n const info = this.pending.get(id);\n this.pending.delete(id);\n\n if (info?.signal) {\n info.signal.removeEventListener('abort', info.abortFn);\n }\n\n return info;\n }\n\n send(event: RequestEventData | AbortEventData) {\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);\n }\n\n request<T>(context: Context, next: NextFn<T>): Promise<T> | Future<T> {\n if (isServerEnv) {\n return next(context.request);\n }\n\n const deferred = createDeferred<T>();\n const { signal, request } = prepareRequest(context.request);\n const abortFn = signal\n ? () => {\n deferred.reject(enhanceReason(signal.reason as string));\n this.send({ type: 'abort', thread: this.threadId, id: context.id, data: signal.reason as string });\n this.cleanupRequest(context.id);\n }\n : () => {\n return;\n };\n\n signal?.addEventListener('abort', abortFn);\n\n try {\n throw new Error();\n } catch (e: unknown) {\n this.pending.set(context.id, {\n context,\n deferred,\n signal,\n abortFn,\n stack: (e as Error).stack!,\n });\n }\n\n this.send({\n type: 'request',\n thread: this.threadId,\n id: context.id,\n data: request,\n });\n\n return deferred.promise;\n }\n}\n\nexport function enhanceReason(reason?: string) {\n return new DOMException(reason || 'The user aborted a request.', 'AbortError');\n}\n\nfunction prepareRequest(request: Context['request']): { signal: AbortSignal | null; request: RequestInfo } {\n const { signal, headers } = request;\n const requestCopy = Object.assign({}, request) as RequestInfo;\n\n delete requestCopy.store;\n\n if (signal instanceof AbortSignal) {\n delete requestCopy.signal;\n }\n\n if (headers instanceof Headers) {\n requestCopy.headers = Array.from(headers as unknown as Iterable<[string, string][]>) as unknown as Headers;\n }\n\n return { signal: signal || null, request: requestCopy };\n}\n"],"names":["isServerEnv","FastBoot","isAggregateError","error","AggregateError","name","Array","isArray","errors","stitchTrace","stack","origin","startsWith","slice","cloneError","isAggregate","cloned","structuredClone","message","Error","Object","assign","WorkerFetch","constructor","worker","threadId","crypto","randomUUID","pending","Map","isTesting","macroCondition","getGlobalConfig","WarpDrive","env","TESTING","DEBUG","test","SharedWorker","fn","event","type","id","data","info","cleanupRequest","deferred","response","content","headers","Headers","context","setResponse","Response","resolve","reject","port","postMessage","thread","onmessage","channel","MessageChannel","port2","port1","get","delete","signal","removeEventListener","abortFn","send","request","next","createDeferred","prepareRequest","enhanceReason","reason","addEventListener","e","set","promise","DOMException","requestCopy","store","AbortSignal","from"],"mappings":";;;AAoBA,MAAMA,WAAW,GAAG,OAAOC,QAAQ,KAAK,WAAW;AAEnD,SAASC,gBAAgBA,CAACC,KAAsC,EAAoD;AAClH,EAAA,OAAOA,KAAK,YAAYC,cAAc,IAAKD,KAAK,CAACE,IAAI,KAAK,gBAAgB,IAAIC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAACK,MAAM,CAAE;AAC5G;AAIA,SAASC,WAAWA,CAACC,KAAa,EAAEC,MAAc,EAAE;AAClD,EAAA,IAAIA,MAAM,CAACC,UAAU,CAAC,SAAS,CAAC,EAAE;IAChC,OAAOD,MAAM,CAACE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,GAAGH,KAAK;AACvC;AACA,EAAA,OAAOC,MAAM,GAAG,IAAI,GAAGD,KAAK;AAC9B;AAEA,SAASI,UAAUA,CAACX,KAAkB,EAAEO,KAAa,EAAE;AACrD,EAAA,MAAMK,WAAW,GAAGb,gBAAgB,CAACC,KAAK,CAAC;EAE3C,MAAMa,MAAM,GACVD,WAAW,GAAG,IAAIX,cAAc,CAACa,eAAe,CAACd,KAAK,CAACK,MAAM,CAAC,EAAEL,KAAK,CAACe,OAAO,CAAC,GAAG,IAAIC,KAAK,CAAChB,KAAK,CAACe,OAAO,CAC1F;AAChBF,EAAAA,MAAM,CAACN,KAAK,GAAGD,WAAW,CAACN,KAAK,CAACO,KAAK,IAAI,EAAE,EAAEA,KAAK,CAAC;AACpDM,EAAAA,MAAM,CAACb,KAAK,GAAGA,KAAK,CAACA,KAAK;;AAE1B;AACAiB,EAAAA,MAAM,CAACC,MAAM,CAACL,MAAM,EAAEb,KAAK,CAAC;AAE5B,EAAA,OA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;QAC3BS,OAAO;QACPL,QAAQ;QACRoB,MAAM;QACNE,OAAO;QACP1D,KAAK,EAAGmE,CAAC,CAAWnE;AACtB,OAAC,CAAC;AACJ;IAEA,IAAI,CAAC2D,IAAI,CAAC;AACR5B,MAAAA,IAAI,EAAE,SAAS;MACfiB,MAAM,EAAE,IAAI,CAACjC,QAAQ;MACrBiB,EAAE,EAAES,OAAO,CAACT,EAAE;AACdC,MAAAA,IAAI,EAAE2B;AACR,KAAC,CAAC;IAEF,OAAOxB,QAAQ,CAACiC,OAAO;AACzB;AACF;AAEO,SAASL,aAAaA,CAACC,MAAe,EAAE;EAC7C,OAAO,IAAIK,YAAY,CAACL,MAAM,IAAI,6BAA6B,EAAE,YAAY,CAAC;AAChF;AAEA,SAASF,cAAcA,CAACH,OAA2B,EAAwD;EACzG,MAAM;IAAEJ,MAAM;AAAEjB,IAAAA;AAAQ,GAAC,GAAGqB,OAAO;EACnC,MAAMW,WAAW,GAAG7D,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEiD,OAAO,CAAgB;EAE7D,OAAOW,WAAW,CAACC,KAAK;EAExB,IAAIhB,MAAM,YAAYiB,WAAW,EAAE;IACjC,OAAOF,WAAW,CAACf,MAAM;AAC3B;EAEA,IAAIjB,OAAO,YAAYC,OAAO,EAAE;IAC9B+B,WAAW,CAAChC,OAAO,GAAG3C,KAAK,CAAC8E,IAAI,CAACnC,OAAkD,CAAuB;AAC5G;EAEA,OAAO;IAAEiB,MAAM,EAAEA,MAAM,IAAI,IAAI;AAAEI,IAAAA,OAAO,EAAEW;GAAa;AACzD;;;;"}
|
|
1
|
+
{"version":3,"file":"worker-fetch.js","sources":["../src/data-worker/fetch.ts"],"sourcesContent":["import type { Context, Deferred, Future, NextFn, RequestInfo } from '@ember-data-mirror/request';\nimport { createDeferred } from '@ember-data-mirror/request';\nimport { TESTING } from '@warp-drive-mirror/build-config/env';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\nimport type { ApiError } from '@warp-drive-mirror/core-types/spec/error';\n\nimport type { AbortEventData, MainThreadEvent, RequestEventData } from './types';\n\nconst isServerEnv = typeof FastBoot !== 'undefined';\n\nfunction isAggregateError(error: Error & { errors?: ApiError[] }): error is AggregateError & { errors: ApiError[] } {\n return error instanceof AggregateError || (error.name === 'AggregateError' && Array.isArray(error.errors));\n}\n\ntype RobustError = Error & { error: string | object; errors?: ApiError[]; content?: unknown };\n\nfunction stitchTrace(stack: string, origin: string) {\n if (origin.startsWith('Error\\n')) {\n return origin.slice(6) + '\\n' + stack;\n }\n return origin + '\\n' + stack;\n}\n\nfunction cloneError(error: RobustError, stack: string) {\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 = stitchTrace(error.stack || '', stack);\n cloned.error = error.error;\n\n // copy over enumerable properties\n Object.assign(cloned, error);\n\n return cloned;\n}\n\nexport class WorkerFetch {\n declare worker: Worker | SharedWorker;\n declare threadId: string;\n declare pending: Map<\n number,\n { context: Context; signal: AbortSignal | null; abortFn: () => void; deferred: Deferred<unknown>; stack: string }\n >;\n declare channel: MessageChannel;\n\n constructor(worker: Worker | SharedWorker | null) {\n this.threadId = isServerEnv ? '' : crypto.randomUUID();\n this.pending = new Map();\n\n const isTesting = TESTING ? true : false;\n assert(`Expected a SharedWorker instance`, isTesting || isServerEnv || worker instanceof SharedWorker);\n this.worker = worker as SharedWorker;\n\n if (!isServerEnv) {\n const fn = (event: MainThreadEvent<unknown>) => {\n const { type, id, data } = event.data;\n const info = this.cleanupRequest(id);\n\n // typically this means the request was aborted\n if (!info) {\n return;\n }\n\n if (type === 'success-response') {\n const { deferred } = info;\n\n const { response, content } = data;\n\n if (response) {\n (response as { headers: Headers }).headers = new Headers(response.headers);\n info.context.setResponse(new Response(null, response));\n }\n\n deferred.resolve(content);\n return;\n }\n\n if (type === 'error-response') {\n const { deferred, stack } = info;\n\n deferred.reject(cloneError(data, stack));\n return;\n }\n };\n\n if (worker instanceof SharedWorker) {\n worker.port.postMessage({ type: 'connect', thread: this.threadId });\n worker.port.onmessage = fn;\n } else if (worker) {\n this.channel = new MessageChannel();\n worker.postMessage({ type: 'connect', thread: this.threadId }, [this.channel.port2]);\n\n this.channel.port1.onmessage = fn;\n }\n }\n }\n\n cleanupRequest(id: number) {\n const info = this.pending.get(id);\n this.pending.delete(id);\n\n if (info?.signal) {\n info.signal.removeEventListener('abort', info.abortFn);\n }\n\n return info;\n }\n\n send(event: RequestEventData | AbortEventData) {\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);\n }\n\n request<T>(context: Context, next: NextFn<T>): Promise<T> | Future<T> {\n if (isServerEnv) {\n return next(context.request);\n }\n\n const deferred = createDeferred<T>();\n const { signal, request } = prepareRequest(context.request);\n const abortFn = signal\n ? () => {\n deferred.reject(enhanceReason(signal.reason as string));\n this.send({ type: 'abort', thread: this.threadId, id: context.id, data: signal.reason as string });\n this.cleanupRequest(context.id);\n }\n : () => {\n return;\n };\n\n signal?.addEventListener('abort', abortFn);\n\n try {\n throw new Error();\n } catch (e: unknown) {\n this.pending.set(context.id, {\n context,\n deferred,\n signal,\n abortFn,\n stack: (e as Error).stack!,\n });\n }\n\n this.send({\n type: 'request',\n thread: this.threadId,\n id: context.id,\n data: request,\n });\n\n return deferred.promise;\n }\n}\n\nexport function enhanceReason(reason?: string) {\n return new DOMException(reason || 'The user aborted a request.', 'AbortError');\n}\n\nfunction prepareRequest(request: Context['request']): { signal: AbortSignal | null; request: RequestInfo } {\n const { signal, headers } = request;\n const requestCopy = Object.assign({}, request) as RequestInfo;\n\n delete requestCopy.store;\n\n if (signal instanceof AbortSignal) {\n delete requestCopy.signal;\n }\n\n if (headers instanceof Headers) {\n requestCopy.headers = Array.from(headers as unknown as Iterable<[string, string][]>) as unknown as Headers;\n }\n\n return { signal: signal || null, request: requestCopy };\n}\n"],"names":["isServerEnv","FastBoot","isAggregateError","error","AggregateError","name","Array","isArray","errors","stitchTrace","stack","origin","startsWith","slice","cloneError","isAggregate","cloned","structuredClone","message","Error","Object","assign","WorkerFetch","constructor","worker","threadId","crypto","randomUUID","pending","Map","isTesting","macroCondition","getGlobalConfig","WarpDrive","env","TESTING","DEBUG","test","SharedWorker","fn","event","type","id","data","info","cleanupRequest","deferred","response","content","headers","Headers","context","setResponse","Response","resolve","reject","port","postMessage","thread","onmessage","channel","MessageChannel","port2","port1","get","delete","signal","removeEventListener","abortFn","send","request","next","createDeferred","prepareRequest","enhanceReason","reason","addEventListener","e","set","promise","DOMException","requestCopy","store","AbortSignal","from"],"mappings":";;;AAQA,MAAMA,WAAW,GAAG,OAAOC,QAAQ,KAAK,WAAW;AAEnD,SAASC,gBAAgBA,CAACC,KAAsC,EAAoD;AAClH,EAAA,OAAOA,KAAK,YAAYC,cAAc,IAAKD,KAAK,CAACE,IAAI,KAAK,gBAAgB,IAAIC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAACK,MAAM,CAAE;AAC5G;AAIA,SAASC,WAAWA,CAACC,KAAa,EAAEC,MAAc,EAAE;AAClD,EAAA,IAAIA,MAAM,CAACC,UAAU,CAAC,SAAS,CAAC,EAAE;IAChC,OAAOD,MAAM,CAACE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,GAAGH,KAAK;AACvC;AACA,EAAA,OAAOC,MAAM,GAAG,IAAI,GAAGD,KAAK;AAC9B;AAEA,SAASI,UAAUA,CAACX,KAAkB,EAAEO,KAAa,EAAE;AACrD,EAAA,MAAMK,WAAW,GAAGb,gBAAgB,CAACC,KAAK,CAAC;EAE3C,MAAMa,MAAM,GACVD,WAAW,GAAG,IAAIX,cAAc,CAACa,eAAe,CAACd,KAAK,CAACK,MAAM,CAAC,EAAEL,KAAK,CAACe,OAAO,CAAC,GAAG,IAAIC,KAAK,CAAChB,KAAK,CAACe,OAAO,CAC1F;AAChBF,EAAAA,MAAM,CAACN,KAAK,GA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7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive-mirror/experiments",
|
|
3
3
|
"description": "Experimental features for EmberData/WarpDrive",
|
|
4
|
-
"version": "0.2.4-alpha.
|
|
4
|
+
"version": "0.2.4-alpha.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chris Thoburn <runspired@users.noreply.github.com>",
|
|
7
7
|
"repository": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@sqlite.org/sqlite-wasm": "3.46.0-build2",
|
|
44
|
-
"@ember-data-mirror/request": "5.6.0-alpha.
|
|
45
|
-
"@ember-data-mirror/request-utils": "5.6.0-alpha.
|
|
46
|
-
"@ember-data-mirror/store": "5.6.0-alpha.
|
|
47
|
-
"@warp-drive-mirror/core-types": "5.6.0-alpha.
|
|
44
|
+
"@ember-data-mirror/request": "5.6.0-alpha.5",
|
|
45
|
+
"@ember-data-mirror/request-utils": "5.6.0-alpha.5",
|
|
46
|
+
"@ember-data-mirror/store": "5.6.0-alpha.5",
|
|
47
|
+
"@warp-drive-mirror/core-types": "5.6.0-alpha.5"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"@sqlite.org/sqlite-wasm": {
|
|
@@ -53,27 +53,24 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@embroider/macros": "^1.16.12",
|
|
56
|
-
"@warp-drive-mirror/build-config": "5.6.0-alpha.
|
|
56
|
+
"@warp-drive-mirror/build-config": "5.6.0-alpha.5"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@babel/core": "^7.26.10",
|
|
60
60
|
"@babel/plugin-transform-typescript": "^7.27.0",
|
|
61
61
|
"@babel/preset-env": "^7.26.9",
|
|
62
62
|
"@babel/preset-typescript": "^7.27.0",
|
|
63
|
-
"@ember-data-mirror/request": "5.6.0-alpha.
|
|
64
|
-
"@ember-data-mirror/request-utils": "5.6.0-alpha.
|
|
65
|
-
"@ember-data-mirror/store": "5.6.0-alpha.
|
|
63
|
+
"@ember-data-mirror/request": "5.6.0-alpha.5",
|
|
64
|
+
"@ember-data-mirror/request-utils": "5.6.0-alpha.5",
|
|
65
|
+
"@ember-data-mirror/store": "5.6.0-alpha.5",
|
|
66
66
|
"@glimmer/component": "^2.0.0",
|
|
67
|
-
"@warp-drive-mirror/core-types": "5.6.0-alpha.
|
|
68
|
-
"@warp-drive/internal-config": "5.6.0-alpha.
|
|
67
|
+
"@warp-drive-mirror/core-types": "5.6.0-alpha.5",
|
|
68
|
+
"@warp-drive/internal-config": "5.6.0-alpha.5",
|
|
69
69
|
"ember-source": "~6.3.0",
|
|
70
70
|
"@sqlite.org/sqlite-wasm": "3.46.0-build2",
|
|
71
71
|
"typescript": "^5.8.3",
|
|
72
72
|
"vite": "^5.4.15"
|
|
73
73
|
},
|
|
74
|
-
"engines": {
|
|
75
|
-
"node": ">= 18.20.8"
|
|
76
|
-
},
|
|
77
74
|
"volta": {
|
|
78
75
|
"extends": "../../../../../../package.json"
|
|
79
76
|
},
|