@warp-drive-mirror/experiments 0.2.4-alpha.1 → 0.2.4-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon-main.cjs +1 -1
- package/declarations/data-worker/cache-handler.d.ts +8 -0
- package/declarations/data-worker/cache-handler.d.ts.map +1 -0
- package/declarations/data-worker/fetch.d.ts +26 -0
- package/declarations/data-worker/fetch.d.ts.map +1 -0
- package/declarations/data-worker/types.d.ts +32 -0
- package/declarations/data-worker/types.d.ts.map +1 -0
- package/declarations/data-worker/utils.d.ts +21 -0
- package/declarations/data-worker/utils.d.ts.map +1 -0
- package/declarations/data-worker/worker.d.ts +24 -0
- package/declarations/data-worker/worker.d.ts.map +1 -0
- package/declarations/data-worker.d.ts +3 -0
- package/declarations/data-worker.d.ts.map +1 -0
- package/declarations/document-storage/index.d.ts +91 -0
- package/declarations/document-storage/index.d.ts.map +1 -0
- package/declarations/document-storage.d.ts +2 -0
- package/declarations/document-storage.d.ts.map +1 -0
- package/declarations/image-fetch.d.ts +2 -0
- package/declarations/image-fetch.d.ts.map +1 -0
- package/declarations/image-worker/fetch.d.ts +19 -0
- package/declarations/image-worker/fetch.d.ts.map +1 -0
- package/declarations/image-worker/types.d.ts +22 -0
- package/declarations/image-worker/types.d.ts.map +1 -0
- package/declarations/image-worker/worker.d.ts +18 -0
- package/declarations/image-worker/worker.d.ts.map +1 -0
- package/declarations/image-worker.d.ts +2 -0
- package/declarations/image-worker.d.ts.map +1 -0
- package/declarations/persisted-cache/cache.d.ts +450 -0
- package/declarations/persisted-cache/cache.d.ts.map +1 -0
- package/declarations/persisted-cache/db.d.ts +21 -0
- package/declarations/persisted-cache/db.d.ts.map +1 -0
- package/declarations/persisted-cache/fetch.d.ts +10 -0
- package/declarations/persisted-cache/fetch.d.ts.map +1 -0
- package/declarations/persisted-cache.d.ts +2 -0
- package/declarations/persisted-cache.d.ts.map +1 -0
- package/declarations/worker-fetch.d.ts +2 -0
- package/declarations/worker-fetch.d.ts.map +1 -0
- package/dist/data-worker.js +1 -2
- package/dist/data-worker.js.map +1 -1
- package/dist/image-fetch.js +3 -1
- package/dist/image-fetch.js.map +1 -1
- package/dist/index-CGCX7hY2.js.map +1 -1
- package/dist/persisted-cache.js +2 -36
- package/dist/persisted-cache.js.map +1 -1
- package/dist/worker-fetch.js +3 -1
- package/dist/worker-fetch.js.map +1 -1
- package/package.json +13 -18
|
@@ -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,OAAO,CAAC;AAErB,IAAA,IAAI,MAAM,IAAIJ,MAAM,IAAIA,MAAM,CAACS,IAAI,EAAE;AACnC,MAAA,MAAMC,YAA8C,GAAGC,KAAK,CAACC,OAAO,CAACZ,M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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;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;AACA;AACA;AACA;AACA;AACEiC,EAAAA,IAAIA,GAAsB;AACxB,IAAA,OAAO,IAAI,CAAC9B,MAAM,CAAC8B,IAAI,EAAE;AAC3B;;AAEA;AACA;;AAEA;AACF;AACA;A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A;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 { 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 {\n StableDocumentIdentifier,\n StableExistingRecordIdentifier,\n StableRecordIdentifier,\n} 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","is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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,EAAE;AAC3B;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,IAAIA,GAAqC;AACvC,IAAA,OAAO,IAAI,CAAC/B,MAAM,CAAC+B,IAAI,EAAE;AAC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AW;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
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { createDeferred } from '@
|
|
1
|
+
import { createDeferred } from '@warp-drive-mirror/core/request';
|
|
2
2
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
3
|
+
|
|
4
|
+
// @ts-expect-error untyped global
|
|
3
5
|
const isServerEnv = typeof FastBoot !== 'undefined';
|
|
4
6
|
function isAggregateError(error) {
|
|
5
7
|
return error instanceof AggregateError || error.name === 'AggregateError' && Array.isArray(error.errors);
|
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,I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["import { TESTING } from '@warp-drive-mirror/core/build-config/env';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { Context, Deferred, Future, NextFn } from '@warp-drive-mirror/core/request';\nimport { createDeferred } from '@warp-drive-mirror/core/request';\nimport type { RequestInfo } from '@warp-drive-mirror/core/types/request';\nimport type { ApiError } from '@warp-drive-mirror/core/types/spec/error';\n\nimport type { AbortEventData, MainThreadEvent, RequestEventData } from './types';\n\n// @ts-expect-error untyped global\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":";;;AASA;AACA,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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O,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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,46 @@
|
|
|
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.12",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chris Thoburn <runspired@users.noreply.github.com>",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+ssh://git@github.com:emberjs/data.git",
|
|
10
|
-
"directory": "packages/experiments"
|
|
10
|
+
"directory": "warp-drive-packages/experiments"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/emberjs/data",
|
|
13
13
|
"bugs": "https://github.com/emberjs/data/issues",
|
|
14
14
|
"exports": {
|
|
15
15
|
"./persisted-cache": {
|
|
16
|
+
"types": "./declarations/persisted-cache.d.ts",
|
|
16
17
|
"default": "./dist/persisted-cache.js"
|
|
17
18
|
},
|
|
18
19
|
"./document-storage": {
|
|
20
|
+
"types": "./declarations/document-storage.d.ts",
|
|
19
21
|
"default": "./dist/document-storage.js"
|
|
20
22
|
},
|
|
21
23
|
"./data-worker": {
|
|
24
|
+
"types": "./declarations/data-worker.d.ts",
|
|
22
25
|
"default": "./dist/data-worker.js"
|
|
23
26
|
},
|
|
24
27
|
"./worker-fetch": {
|
|
28
|
+
"types": "./declarations/worker-fetch.d.ts",
|
|
25
29
|
"default": "./dist/worker-fetch.js"
|
|
26
30
|
},
|
|
27
31
|
"./image-worker": {
|
|
32
|
+
"types": "./declarations/image-worker.d.ts",
|
|
28
33
|
"default": "./dist/image-worker.js"
|
|
29
34
|
},
|
|
30
35
|
"./image-fetch": {
|
|
36
|
+
"types": "./declarations/image-fetch.d.ts",
|
|
31
37
|
"default": "./dist/image-fetch.js"
|
|
32
38
|
}
|
|
33
39
|
},
|
|
34
40
|
"files": [
|
|
35
41
|
"addon-main.cjs",
|
|
36
42
|
"dist",
|
|
43
|
+
"declarations",
|
|
37
44
|
"CHANGELOG.md",
|
|
38
45
|
"README.md",
|
|
39
46
|
"LICENSE.md",
|
|
@@ -41,10 +48,7 @@
|
|
|
41
48
|
],
|
|
42
49
|
"peerDependencies": {
|
|
43
50
|
"@sqlite.org/sqlite-wasm": "3.46.0-build2",
|
|
44
|
-
"@
|
|
45
|
-
"@ember-data-mirror/request-utils": "5.6.0-alpha.1",
|
|
46
|
-
"@ember-data-mirror/store": "5.6.0-alpha.1",
|
|
47
|
-
"@warp-drive-mirror/core-types": "5.6.0-alpha.1"
|
|
51
|
+
"@warp-drive-mirror/core": "5.6.0-alpha.12"
|
|
48
52
|
},
|
|
49
53
|
"peerDependenciesMeta": {
|
|
50
54
|
"@sqlite.org/sqlite-wasm": {
|
|
@@ -52,28 +56,19 @@
|
|
|
52
56
|
}
|
|
53
57
|
},
|
|
54
58
|
"dependencies": {
|
|
55
|
-
"@embroider/macros": "^1.16.12"
|
|
56
|
-
"@warp-drive-mirror/build-config": "5.6.0-alpha.1"
|
|
59
|
+
"@embroider/macros": "^1.16.12"
|
|
57
60
|
},
|
|
58
61
|
"devDependencies": {
|
|
59
62
|
"@babel/core": "^7.26.10",
|
|
60
63
|
"@babel/plugin-transform-typescript": "^7.27.0",
|
|
61
64
|
"@babel/preset-env": "^7.26.9",
|
|
62
65
|
"@babel/preset-typescript": "^7.27.0",
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
65
|
-
"@ember-data-mirror/store": "5.6.0-alpha.1",
|
|
66
|
-
"@glimmer/component": "^2.0.0",
|
|
67
|
-
"@warp-drive-mirror/core-types": "5.6.0-alpha.1",
|
|
68
|
-
"@warp-drive/internal-config": "5.6.0-alpha.1",
|
|
69
|
-
"ember-source": "~6.3.0",
|
|
66
|
+
"@warp-drive/internal-config": "5.6.0-alpha.12",
|
|
67
|
+
"@warp-drive-mirror/core": "5.6.0-alpha.12",
|
|
70
68
|
"@sqlite.org/sqlite-wasm": "3.46.0-build2",
|
|
71
69
|
"typescript": "^5.8.3",
|
|
72
70
|
"vite": "^5.4.15"
|
|
73
71
|
},
|
|
74
|
-
"engines": {
|
|
75
|
-
"node": ">= 18.20.8"
|
|
76
|
-
},
|
|
77
72
|
"volta": {
|
|
78
73
|
"extends": "../../../../../../package.json"
|
|
79
74
|
},
|