@warp-drive-mirror/experiments 0.0.1 → 0.1.0-alpha.134

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/data-worker.js +4 -4
  2. package/dist/data-worker.js.map +1 -1
  3. package/dist/image-fetch.js +2 -2
  4. package/dist/image-fetch.js.map +1 -1
  5. package/dist/index-Cn3o840t.js +2 -2
  6. package/dist/index-Cn3o840t.js.map +1 -1
  7. package/dist/persisted-cache.js +19 -19
  8. package/dist/persisted-cache.js.map +1 -1
  9. package/dist/worker-fetch.js +2 -2
  10. package/dist/worker-fetch.js.map +1 -1
  11. package/package.json +18 -19
  12. package/unstable-preview-types/data-worker/cache-handler.d.ts +0 -11
  13. package/unstable-preview-types/data-worker/cache-handler.d.ts.map +0 -1
  14. package/unstable-preview-types/data-worker/fetch.d.ts +0 -37
  15. package/unstable-preview-types/data-worker/fetch.d.ts.map +0 -1
  16. package/unstable-preview-types/data-worker/types.d.ts +0 -34
  17. package/unstable-preview-types/data-worker/types.d.ts.map +0 -1
  18. package/unstable-preview-types/data-worker/utils.d.ts +0 -23
  19. package/unstable-preview-types/data-worker/utils.d.ts.map +0 -1
  20. package/unstable-preview-types/data-worker/worker.d.ts +0 -26
  21. package/unstable-preview-types/data-worker/worker.d.ts.map +0 -1
  22. package/unstable-preview-types/data-worker.d.ts +0 -5
  23. package/unstable-preview-types/data-worker.d.ts.map +0 -1
  24. package/unstable-preview-types/document-storage/index.d.ts +0 -93
  25. package/unstable-preview-types/document-storage/index.d.ts.map +0 -1
  26. package/unstable-preview-types/document-storage.d.ts +0 -4
  27. package/unstable-preview-types/document-storage.d.ts.map +0 -1
  28. package/unstable-preview-types/image-fetch.d.ts +0 -4
  29. package/unstable-preview-types/image-fetch.d.ts.map +0 -1
  30. package/unstable-preview-types/image-worker/fetch.d.ts +0 -21
  31. package/unstable-preview-types/image-worker/fetch.d.ts.map +0 -1
  32. package/unstable-preview-types/image-worker/types.d.ts +0 -24
  33. package/unstable-preview-types/image-worker/types.d.ts.map +0 -1
  34. package/unstable-preview-types/image-worker/worker.d.ts +0 -20
  35. package/unstable-preview-types/image-worker/worker.d.ts.map +0 -1
  36. package/unstable-preview-types/image-worker.d.ts +0 -4
  37. package/unstable-preview-types/image-worker.d.ts.map +0 -1
  38. package/unstable-preview-types/index.d.ts +0 -18
  39. package/unstable-preview-types/persisted-cache/cache.d.ts +0 -433
  40. package/unstable-preview-types/persisted-cache/cache.d.ts.map +0 -1
  41. package/unstable-preview-types/persisted-cache/db.d.ts +0 -25
  42. package/unstable-preview-types/persisted-cache/db.d.ts.map +0 -1
  43. package/unstable-preview-types/persisted-cache/fetch.d.ts +0 -11
  44. package/unstable-preview-types/persisted-cache/fetch.d.ts.map +0 -1
  45. package/unstable-preview-types/persisted-cache.d.ts +0 -4
  46. package/unstable-preview-types/persisted-cache.d.ts.map +0 -1
  47. package/unstable-preview-types/worker-fetch.d.ts +0 -4
  48. package/unstable-preview-types/worker-fetch.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"persisted-cache.js","sources":["../src/persisted-cache/cache.ts"],"sourcesContent":["import type { StableRecordIdentifier } from '@warp-drive/core-types';\nimport type { Cache, ChangedAttributesHash, RelationshipDiff } from '@warp-drive/core-types/cache';\nimport type { ResourceBlob } from '@warp-drive/core-types/cache/aliases';\nimport type { Change } from '@warp-drive/core-types/cache/change';\nimport type { Mutation } from '@warp-drive/core-types/cache/mutations';\nimport type { Operation } from '@warp-drive/core-types/cache/operations';\nimport type { CollectionRelationship, ResourceRelationship } from '@warp-drive/core-types/cache/relationship';\nimport type { StableDocumentIdentifier, StableExistingRecordIdentifier } from '@warp-drive/core-types/identifier';\nimport type { Value } from '@warp-drive/core-types/json/raw';\nimport type { TypeFromInstanceOrString } from '@warp-drive/core-types/record';\nimport type { RequestContext, StructuredDataDocument, StructuredDocument } from '@warp-drive/core-types/request';\nimport type { ResourceDocument, SingleResourceDataDocument } from '@warp-drive/core-types/spec/document';\nimport type { ApiError } from '@warp-drive/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 * @returns {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 * @returns {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 * @returns {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 the Cache for the existing request data associated with\n * a cacheable request\n *\n * @method peekRequest\n * @param {StableDocumentIdentifier}\n * @returns {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 * @returns {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 * @returns 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 * @returns 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 * @returns {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 * @returns {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 * @returns {unknown}\n */\n getAttr(identifier: StableRecordIdentifier, field: string): Value | undefined {\n return this._cache.getAttr(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 * @returns\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 * @returns {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 * @returns 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 * @returns 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 // 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 * @returns\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 * @returns {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 * @returns {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 * @returns {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 * @returns {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","upsert","hasRecord","fork","merge","diff","dump","hydrate","stream","clientDidCreate","options","willCommit","context","didCommit","commitWasRejected","errors","unloadRecord","getAttr","field","setAttr","propertyName","value","changedAttrs","hasChangedAttrs","rollbackAttrs","changedRelationships","hasChangedRelationships","rollbackRelationships","getRelationship","isCollection","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,CAAA;IAClB,IAAI,CAACC,MAAM,GAAGH,KAAK,CAAA;IACnB,IAAI,CAACI,GAAG,GAAGH,EAAE,CAAA;AACf,GAAA;;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,CAAA;AAEnC,IAAA,IAAI,CAACC,MAAM,CAACC,GAAG,EAAE;AACf,MAAA,OAAOD,MAAM,CAAA;AACf,KAAA;AAEA,IAAA,MAAME,WAAW,GAAG,IAAI,CAACL,GAAG,CAACK,WAAW,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE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GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEiB,KAAKA,CAACC,EAAa,EAAQ;AACzB,IAAA,IAAI,CAACtB,MAAM,CAACqB,KAAK,CAACC,EAAE,CAAC,CAAA;AACvB,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,MAAMA,CAACC,QAAkB,EAAQ;AAC/B,IAAA,IAAI,CAACxB,MAAM,CAACuB,MAAM,CAACC,QAAQ,CAAC,CAAA;AAC9B,GAAA;;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;;EAGEL,IAAIA,CAACD,UAA6D,EAAW;AAC3E,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACmB,IAAI,CAACD,UAAU,CAAC,CAAA;AACrC,GAAA;;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,CAAA;AAC5C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEO,EAAAA,MAAMA,CAACP,UAAkC,EAAEL,IAAkB,EAAEa,SAAkB,EAAmB;IAClG,OAAO,IAAI,CAAC1B,MAAM,CAACyB,MAAM,CAACP,UAAU,EAAEL,IAAI,EAAEa,SAAS,CAAC,CAAA;AACxD,GAAA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,IAAIA,GAAmB;AACrB,IAAA,OAAO,IAAI,CAAC3B,MAAM,CAAC2B,IAAI,EAAE,CAAA;AAC3B,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,KAAKA,CAAC/B,KAAY,EAAiB;AACjC,IAAA,OAAO,IAAI,CAACG,MAAM,CAAC4B,KAAK,CAAC/B,KAAK,CAAC,CAAA;AACjC,GAAA;;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;AACEgC,EAAAA,IAAIA,GAAsB;AACxB,IAAA,OAAO,IAAI,CAAC7B,MAAM,CAAC6B,IAAI,EAAE,CAAA;AAC3B,GAAA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,IAAIA,GAAqC;AACvC,IAAA,OAAO,IAAI,CAAC9B,MAAM,CAAC8B,IAAI,EAAE,CAAA;AAC3B,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,OAAOA,CAACC,MAA+B,EAAiB;AACtD,IAAA,OAAO,IAAI,CAAChC,MAAM,CAAC+B,OAAO,CAACC,MAAM,CAAC,CAAA;AACpC,GAAA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,eAAeA,CAACf,UAAkC,EAAEgB,OAAiC,EAA2B;IAC9G,OAAO,IAAI,CAAClC,MAAM,CAACiC,eAAe,CAACf,UAAU,EAAEgB,OAAO,CAAC,CAAA;AACzD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,UAAUA,CAACjB,UAAkC,EAAEkB,OAAuB,EAAQ;IAC5E,IAAI,CAACpC,MAAM,CAACmC,UAAU,CAACjB,UAAU,EAAEkB,OAAO,CAAC,CAAA;AAC7C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;A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,MAAM,CAAC+C,eAAe,CAAC7B,UAAU,CAAC,CAAA;AAChD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE8B,aAAaA,CAAC9B,UAAkC,EAAY;AAC1D,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACgD,aAAa,CAAC9B,UAAU,CAAC,CAAA;AAC9C,GAAA;;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;EACE+B,oBAAoBA,CAAC/B,UAAkC,EAAiC;AACtF,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACiD,oBAAoB,CAAC/B,UAAU,CAAC,CAAA;AACrD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEgC,uBAAuBA,CAAChC,UAAkC,EAAW;AACnE,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACkD,uBAAuB,CAAChC,UAAU,CAAC,CAAA;AACxD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEiC,qBAAqBA,CAACjC,UAAkC,EAAY;AAClE,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACmD,qBAAqB,CAACjC,UAAU,CAAC,CAAA;AACtD,GAAA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEkC,EAAAA,eAAeA,CACblC,UAAkC,EAClCwB,KAAa,EACbW,YAAsB,EACyB;IAC/C,OAAO,IAAI,CAACrD,MAAM,CAACoD,eAAe,CAAClC,UAAU,EAAEwB,KAAK,EAAEW,YAAY,CAAC,CAAA;AACrE,GAAA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,YAAYA,CAACpC,UAAkC,EAAEqC,SAAkB,EAAQ;IACzE,IAAI,CAACvD,MAAM,CAACsD,YAAY,CAACpC,UAAU,EAAEqC,SAAS,CAAC,CAAA;AACjD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,SAASA,CAACtC,UAAkC,EAAc;AACxD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACwD,SAAS,CAACtC,UAAU,CAAC,CAAA;AAC1C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEuC,OAAOA,CAACvC,UAAkC,EAAW;AACnD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACyD,OAAO,CAACvC,UAAU,CAAC,CAAA;AACxC,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEwC,KAAKA,CAACxC,UAAkC,EAAW;AACjD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC0D,KAAK,CAACxC,UAAU,CAAC,CAAA;AACtC,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEqC,SAASA,CAACrC,UAAkC,EAAW;AACrD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACuD,SAAS,CAACrC,UAAU,CAAC,CAAA;AAC1C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEyC,mBAAmBA,CAACzC,UAAkC,EAAW;AAC/D,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC2D,mBAAmB,CAACzC,UAAU,CAAC,CAAA;AACpD,GAAA;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 * @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 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 * 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 // 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","upsert","hasRecord","fork","merge","diff","dump","hydrate","stream","clientDidCreate","options","willCommit","context","didCommit","commitWasRejected","errors","unloadRecord","getAttr","field","setAttr","propertyName","value","changedAttrs","hasChangedAttrs","rollbackAttrs","changedRelationships","hasChangedRelationships","rollbackRelationships","getRelationship","isCollection","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,CAAA;IAClB,IAAI,CAACC,MAAM,GAAGH,KAAK,CAAA;IACnB,IAAI,CAACI,GAAG,GAAGH,EAAE,CAAA;AACf,GAAA;;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,CAAI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M,CAACP,UAAU,EAAEL,IAAI,EAAEa,SAAS,CAAC,CAAA;AACxD,GAAA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,IAAIA,GAAmB;AACrB,IAAA,OAAO,IAAI,CAAC3B,MAAM,CAAC2B,IAAI,EAAE,CAAA;AAC3B,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,KAAKA,CAAC/B,KAAY,EAAiB;AACjC,IAAA,OAAO,IAAI,CAACG,MAAM,CAAC4B,KAAK,CAAC/B,KAAK,CAAC,CAAA;AACjC,GAAA;;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;AACEgC,EAAAA,IAAIA,GAAsB;AACxB,IAAA,OAAO,IAAI,CAAC7B,MAAM,CAAC6B,IAAI,EAAE,CAAA;AAC3B,GAAA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,IAAIA,GAAqC;AACvC,IAAA,OAAO,IAAI,CAAC9B,MAAM,CAAC8B,IAAI,EAAE,CAAA;AAC3B,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,OAAOA,CAACC,MAA+B,EAAiB;AACtD,IAAA,OAAO,IAAI,CAAChC,MAAM,CAAC+B,OAAO,CAACC,MAAM,CAAC,CAAA;AACpC,GAAA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,eAAeA,CAACf,UAAkC,EAAEgB,OAAiC,EAA2B;IAC9G,OAAO,IAAI,CAAClC,MAAM,CAAC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AACtD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,YAAYA,CAAC5B,UAAkC,EAAyB;AACtE,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC8C,YAAY,CAAC5B,UAAU,CAAC,CAAA;AAC7C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE6B,eAAeA,CAAC7B,UAAkC,EAAW;AAC3D,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC+C,eAAe,CAAC7B,UAAU,CAAC,CAAA;AAChD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE8B,aAAaA,CAAC9B,UAAkC,EAAY;AAC1D,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACgD,aAAa,CAAC9B,UAAU,CAAC,CAAA;AAC9C,GAAA;;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;EACE+B,oBAAoBA,CAAC/B,UAAkC,EAAiC;AACtF,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACiD,oBAAoB,CAAC/B,UAAU,CAAC,CAAA;AACrD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEgC,uBAAuBA,CAAChC,UAAkC,EAAW;AACnE,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACkD,uBAAuB,CAAChC,UAAU,CAAC,CAAA;AACxD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEiC,qBAAqBA,CAACjC,UAAkC,EAAY;AAClE,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACmD,qBAAqB,CAACjC,UAAU,CAAC,CAAA;AACtD,GAAA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEkC,EAAAA,eAAeA,CACblC,UAAkC,EAClCwB,KAAa,EACbW,YAAsB,EACyB;IAC/C,OAAO,IAAI,CAACrD,MAAM,CAACoD,eAAe,CAAClC,UAAU,EAAEwB,KAAK,EAAEW,YAAY,CAAC,CAAA;AACrE,GAAA;;AAEA;AACA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,YAAYA,CAACpC,UAAkC,EAAEqC,SAAkB,EAAQ;IACzE,IAAI,CAACvD,MAAM,CAACsD,YAAY,CAACpC,UAAU,EAAEqC,SAAS,CAAC,CAAA;AACjD,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,SAASA,CAACtC,UAAkC,EAAc;AACxD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACwD,SAAS,CAACtC,UAAU,CAAC,CAAA;AAC1C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEuC,OAAOA,CAACvC,UAAkC,EAAW;AACnD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACyD,OAAO,CAACvC,UAAU,CAAC,CAAA;AACxC,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEwC,KAAKA,CAACxC,UAAkC,EAAW;AACjD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC0D,KAAK,CAACxC,UAAU,CAAC,CAAA;AACtC,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEqC,SAASA,CAACrC,UAAkC,EAAW;AACrD,IAAA,OAAO,IAAI,CAAClB,MAAM,CAACuD,SAAS,CAACrC,UAAU,CAAC,CAAA;AAC1C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEyC,mBAAmBA,CAACzC,UAAkC,EAAW;AAC/D,IAAA,OAAO,IAAI,CAAClB,MAAM,CAAC2D,mBAAmB,CAACzC,UAAU,CAAC,CAAA;AACpD,GAAA;AACF;;;;"}
@@ -24,8 +24,8 @@ class WorkerFetch {
24
24
  constructor(worker) {
25
25
  this.threadId = isServerEnv ? '' : crypto.randomUUID();
26
26
  this.pending = new Map();
27
- const isTesting = macroCondition(getGlobalConfig().WarpDrive.env.TESTING) ? true : false;
28
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
27
+ const isTesting = macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING) ? true : false;
28
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
29
29
  if (!test) {
30
30
  throw new Error(`Expected a SharedWorker instance`);
31
31
  }
@@ -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/build-config/env';\nimport { assert } from '@warp-drive/build-config/macros';\nimport type { ApiError } from '@warp-drive/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.entries()) 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","entries"],"mappings":";;;AAoBA,MAAMA,WAAW,GAAG,OAAOC,QAAQ,KAAK,WAAW,CAAA;AAEnD,SAASC,gBAAgBA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AAI;AAAEI,IAAAA,OAAO,EAAEW,WAAAA;GAAa,CAAA;AACzD;;;;"}
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.entries()) 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","entries"],"mappings":";;;AAoBA,MAAMA,WAAW,GAAG,OAAOC,QAAQ,KAAK,WAAW,CAAA;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,CAAA;AAC5G,CAAA;AAIA,SAASC,WAAWA,CAACC,KAAa,EAAEC,MAAc,EAAE;AAClD,EAAA,IAAIA,MAAM,CAACC,UAAU,CAAC,SAAS,C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A;AACJ,KAAA;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,OAAAA;AACR,KAAC,CAAC,CAAA;IAEF,OAAOxB,QAAQ,CAACiC,OAAO,CAAA;AACzB,GAAA;AACF,CAAA;AAEO,SAASL,aAAaA,CAACC,MAAe,EAAE;EAC7C,OAAO,IAAIK,YAAY,CAACL,MAAM,IAAI,6BAA6B,EAAE,YAAY,CAAC,CAAA;AAChF,CAAA;AAEA,SAASF,cAAcA,CAACH,OAA2B,EAAwD;EACzG,MAAM;IAAEJ,MAAM;AAAEjB,IAAAA,OAAAA;AAAQ,GAAC,GAAGqB,OAAO,CAAA;EACnC,MAAMW,WAAW,GAAG7D,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEiD,OAAO,CAAgB,CAAA;EAE7D,OAAOW,WAAW,CAACC,KAAK,CAAA;EAExB,IAAIhB,MAAM,YAAYiB,WAAW,EAAE;IACjC,OAAOF,WAAW,CAACf,MAAM,CAAA;AAC3B,GAAA;EAEA,IAAIjB,OAAO,YAAYC,OAAO,EAAE;AAC9B+B,IAAAA,WAAW,CAAChC,OAAO,GAAG3C,KAAK,CAAC8E,IAAI,CAACnC,OAAO,CAACoC,OAAO,EAAE,CAAuB,CAAA;AAC3E,GAAA;EAEA,OAAO;IAAEnB,MAAM,EAAEA,MAAM,IAAI,IAAI;AAAEI,IAAAA,OAAO,EAAEW,WAAAA;GAAa,CAAA;AACzD;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@warp-drive-mirror/experiments",
3
3
  "description": "Experimental features for EmberData/WarpDrive",
4
- "version": "0.0.1",
4
+ "version": "0.1.0-alpha.134",
5
5
  "license": "MIT",
6
6
  "author": "Chris Thoburn <runspired@users.noreply.github.com>",
7
7
  "repository": {
@@ -33,24 +33,18 @@
33
33
  },
34
34
  "files": [
35
35
  "dist",
36
- "unstable-preview-types",
37
36
  "CHANGELOG.md",
38
37
  "README.md",
39
38
  "LICENSE.md",
40
39
  "NCC-1701-a-blue.svg",
41
40
  "NCC-1701-a.svg"
42
41
  ],
43
- "scripts": {
44
- "lint": "eslint . --quiet --cache --cache-strategy=content --report-unused-disable-directives",
45
- "build:pkg": "vite build;",
46
- "sync-hardlinks": "bun run sync-dependencies-meta-injected"
47
- },
48
42
  "peerDependencies": {
49
43
  "@sqlite.org/sqlite-wasm": "3.46.0-build2",
50
- "@ember-data-mirror/request": "5.3.9",
51
- "@ember-data-mirror/request-utils": "5.3.9",
52
- "@ember-data-mirror/store": "5.3.9",
53
- "@warp-drive/core-types": "0.0.0-beta.12"
44
+ "@ember-data-mirror/request": "5.4.0-alpha.134",
45
+ "@ember-data-mirror/request-utils": "5.4.0-alpha.134",
46
+ "@ember-data-mirror/store": "5.4.0-alpha.134",
47
+ "@warp-drive-mirror/core-types": "5.4.0-alpha.134"
54
48
  },
55
49
  "peerDependenciesMeta": {
56
50
  "@sqlite.org/sqlite-wasm": {
@@ -59,24 +53,24 @@
59
53
  },
60
54
  "dependencies": {
61
55
  "@embroider/macros": "^1.16.6",
62
- "@warp-drive/build-config": "0.0.0-beta.7"
56
+ "@warp-drive-mirror/build-config": "5.4.0-alpha.134"
63
57
  },
64
58
  "devDependencies": {
65
59
  "@babel/core": "^7.24.5",
66
60
  "@babel/plugin-transform-typescript": "^7.24.5",
67
61
  "@babel/preset-env": "^7.24.5",
68
62
  "@babel/preset-typescript": "^7.24.1",
69
- "@ember-data-mirror/request": "5.3.9",
70
- "@ember-data-mirror/request-utils": "5.3.9",
71
- "@ember-data-mirror/store": "5.3.9",
72
- "@ember-data-mirror/tracking": "5.3.9",
63
+ "@ember-data-mirror/request": "5.4.0-alpha.134",
64
+ "@ember-data-mirror/request-utils": "5.4.0-alpha.134",
65
+ "@ember-data-mirror/store": "5.4.0-alpha.134",
66
+ "@ember-data-mirror/tracking": "5.4.0-alpha.134",
73
67
  "@glimmer/component": "^1.1.2",
74
- "@warp-drive/core-types": "0.0.0-beta.12",
75
- "@warp-drive/internal-config": "5.3.9",
68
+ "@warp-drive-mirror/core-types": "5.4.0-alpha.134",
69
+ "@warp-drive/internal-config": "5.4.0-alpha.134",
76
70
  "ember-source": "~5.12.0",
77
71
  "pnpm-sync-dependencies-meta-injected": "0.0.14",
78
72
  "@sqlite.org/sqlite-wasm": "3.46.0-build2",
79
- "typescript": "^5.4.5",
73
+ "typescript": "^5.7.2",
80
74
  "vite": "^5.2.11"
81
75
  },
82
76
  "engines": {
@@ -84,5 +78,10 @@
84
78
  },
85
79
  "volta": {
86
80
  "extends": "../../../../../../package.json"
81
+ },
82
+ "scripts": {
83
+ "lint": "eslint . --quiet --cache --cache-strategy=content",
84
+ "build:pkg": "vite build;",
85
+ "sync-hardlinks": "bun run sync-dependencies-meta-injected"
87
86
  }
88
87
  }
@@ -1,11 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/data-worker/cache-handler' {
2
- import type { CacheHandler as CacheHandlerType } from '@ember-data-mirror/request';
3
- /**
4
- * A simplified CacheHandler that hydrates ResourceDataDocuments from the cache
5
- * with their referenced resources.
6
- *
7
- * @typedoc
8
- */
9
- export const CacheHandler: CacheHandlerType;
10
- }
11
- //# sourceMappingURL=cache-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache-handler.d.ts","sourceRoot":"","sources":["../../src/data-worker/cache-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAkB,MAAM,qBAAqB,CAAC;AAuB5F;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,gBAmC1B,CAAC"}
@@ -1,37 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/data-worker/fetch' {
2
- import type { Context } from '@ember-data-mirror/request/-private/context';
3
- import type { Deferred, Future, NextFn } from '@ember-data-mirror/request/-private/types';
4
- import type { AbortEventData, RequestEventData } from '@warp-drive-mirror/experiments/data-worker/types';
5
- export interface FastBoot {
6
- require(moduleName: string): unknown;
7
- isFastBoot: boolean;
8
- request: Request;
9
- }
10
- global {
11
- const FastBoot: undefined | FastBoot;
12
- }
13
- export class WorkerFetch {
14
- worker: Worker | SharedWorker;
15
- threadId: string;
16
- pending: Map<number, {
17
- context: Context;
18
- signal: AbortSignal | null;
19
- abortFn: () => void;
20
- deferred: Deferred<unknown>;
21
- stack: string;
22
- }>;
23
- channel: MessageChannel;
24
- constructor(worker: Worker | SharedWorker | null);
25
- cleanupRequest(id: number): {
26
- context: Context;
27
- signal: AbortSignal | null;
28
- abortFn: () => void;
29
- deferred: Deferred<unknown>;
30
- stack: string;
31
- } | undefined;
32
- send(event: RequestEventData | AbortEventData): void;
33
- request<T>(context: Context, next: NextFn<T>): Promise<T> | Future<T>;
34
- }
35
- export function enhanceReason(reason?: string): DOMException;
36
- }
37
- //# sourceMappingURL=fetch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/data-worker/fetch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAKnF,OAAO,KAAK,EAAE,cAAc,EAAmB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjF,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAC;CACtC;AAgCD,qBAAa,WAAW;IACd,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,GAAG,CAClB,MAAM,EACN;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,IAAI,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAClH,CAAC;IACM,OAAO,EAAE,cAAc,CAAC;gBAEpB,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAoDhD,cAAc,CAAC,EAAE,EAAE,MAAM;;;;;;;IAWzB,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,cAAc;IAK7C,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;CAwCtE;AAED,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,gBAE5C"}
@@ -1,34 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/data-worker/types' {
2
- import type { RequestInfo, StructuredDataDocument, StructuredErrorDocument } from '@ember-data-mirror/request';
3
- export type SuccessResponseEventData<T> = {
4
- type: 'success-response';
5
- thread: string;
6
- id: number;
7
- data: StructuredDataDocument<T>;
8
- };
9
- export type ErrorResponseEventData<T> = {
10
- type: 'error-response';
11
- thread: string;
12
- id: number;
13
- data: StructuredErrorDocument<T>;
14
- };
15
- export type RequestEventData = {
16
- type: 'request';
17
- thread: string;
18
- id: number;
19
- data: RequestInfo;
20
- };
21
- export type AbortEventData = {
22
- type: 'abort';
23
- thread: string;
24
- id: number;
25
- data: string;
26
- };
27
- export type ThreadInitEventData = {
28
- type: 'connect';
29
- thread: string;
30
- };
31
- export type MainThreadEvent<T> = MessageEvent<SuccessResponseEventData<T> | ErrorResponseEventData<T>>;
32
- export type WorkerThreadEvent = MessageEvent<RequestEventData> | MessageEvent<ThreadInitEventData> | MessageEvent<AbortEventData>;
33
- }
34
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/data-worker/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAExG,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI;IACxC,IAAI,EAAE,kBAAkB,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI;IACtC,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,YAAY,CAAC,wBAAwB,CAAC,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC;AACvG,MAAM,MAAM,iBAAiB,GACzB,YAAY,CAAC,gBAAgB,CAAC,GAC9B,YAAY,CAAC,mBAAmB,CAAC,GACjC,YAAY,CAAC,cAAc,CAAC,CAAC"}
@@ -1,23 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/data-worker/utils' {
2
- import type Store from '@ember-data-mirror/store';
3
- import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier';
4
- import type { ImmutableCreateRequestOptions, ImmutableDeleteRequestOptions, ImmutableRequestInfo, ImmutableUpdateRequestOptions, StructuredDataDocument } from '@warp-drive/core-types/request';
5
- import type { ApiError } from '@warp-drive/core-types/spec/error';
6
- export const MUTATION_OPS: Set<string>;
7
- /**
8
- * In a Worker, any time we are asked to make a request, data needs to be returned.
9
- * background requests are ergo no different than foreground requests.
10
- * @internal
11
- */
12
- export function calcShouldFetch(store: Store, request: ImmutableRequestInfo, hasCachedValue: boolean, identifier: StableDocumentIdentifier | null): boolean;
13
- export function isMutation(request: Partial<ImmutableRequestInfo>): request is ImmutableUpdateRequestOptions | ImmutableCreateRequestOptions | ImmutableDeleteRequestOptions;
14
- export function isCacheAffecting<T>(document: StructuredDataDocument<T>): boolean;
15
- type RobustError = Error & {
16
- error: string | object;
17
- errors?: ApiError[];
18
- content?: unknown;
19
- };
20
- export function cloneError(error: RobustError): RobustError;
21
- export {};
22
- }
23
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/data-worker/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,EACV,6BAA6B,EAC7B,6BAA6B,EAC7B,oBAAoB,EACpB,6BAA6B,EAC7B,sBAAsB,EACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAElE,eAAO,MAAM,YAAY,aAA4D,CAAC;AAEtF;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,oBAAoB,EAC7B,cAAc,EAAE,OAAO,EACvB,UAAU,EAAE,wBAAwB,GAAG,IAAI,GAC1C,OAAO,CAWT;AAED,wBAAgB,UAAU,CACxB,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,GACrC,OAAO,IAAI,6BAA6B,GAAG,6BAA6B,GAAG,6BAA6B,CAE1G;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,OAAO,CAahF;AAMD,KAAK,WAAW,GAAG,KAAK,GAAG;IAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAG9F,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,eAa5C"}
@@ -1,26 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/data-worker/worker' {
2
- import type { Future } from '@ember-data-mirror/request';
3
- import type Store from '@ember-data-mirror/store';
4
- import { DocumentStorage } from '@warp-drive-mirror/experiments/document-storage';
5
- import type { AbortEventData, RequestEventData } from '@warp-drive-mirror/experiments/data-worker/types';
6
- export class DataWorker {
7
- store: Store;
8
- threads: Map<string, MessagePort>;
9
- pending: Map<string, Map<number, Future<unknown>>>;
10
- isSharedWorker: boolean;
11
- options: {
12
- persisted: boolean;
13
- scope?: string;
14
- };
15
- storage: DocumentStorage;
16
- constructor(UserStore: typeof Store, options?: {
17
- persisted: boolean;
18
- scope?: string;
19
- });
20
- initialize(): void;
21
- setupThread(thread: string, port: MessagePort): void;
22
- abortRequest(event: AbortEventData): void;
23
- request(event: RequestEventData): Promise<void>;
24
- }
25
- }
26
- //# sourceMappingURL=worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/data-worker/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAwC,MAAM,qBAAqB,CAAC;AACxF,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAA0C,MAAM,SAAS,CAAC;AAIxG,qBAAa,UAAU;IACb,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAClC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACnD,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,OAAO,EAAE,eAAe,CAAC;gBAErB,SAAS,EAAE,OAAO,KAAK,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAarF,UAAU;IAkCV,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW;IAqB7C,YAAY,CAAC,KAAK,EAAE,cAAc;IAU5B,OAAO,CAAC,KAAK,EAAE,gBAAgB;CAkBtC"}
@@ -1,5 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/data-worker' {
2
- export { DataWorker } from '@warp-drive-mirror/experiments/data-worker/worker';
3
- export { CacheHandler } from '@warp-drive-mirror/experiments/data-worker/cache-handler';
4
- }
5
- //# sourceMappingURL=data-worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-worker.d.ts","sourceRoot":"","sources":["../src/data-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC"}
@@ -1,93 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/document-storage' {
2
- import type { StructuredDocument } from '@ember-data-mirror/request';
3
- import type { ExistingRecordIdentifier } from '@warp-drive/core-types/identifier';
4
- import type { ResourceDataDocument, ResourceDocument } from '@warp-drive/core-types/spec/document';
5
- import type { ExistingResourceObject } from '@warp-drive/core-types/spec/json-api-raw';
6
- export const WARP_DRIVE_STORAGE_FILE_NAME = "warp-drive_document-storage";
7
- export const WARP_DRIVE_STORAGE_VERSION = 1;
8
- export type DocumentStorageOptions = {
9
- /**
10
- * The scope of the storage. This is used to enable multiple distinct
11
- * storage areas within the same origin.
12
- *
13
- * One use case for this is to have a separate storage area for each
14
- * user credential. So for instance, in applications that allow a single
15
- * user to have multiple accounts, each account can have its own storage!
16
- */
17
- scope: string;
18
- /**
19
- * When set to true, if other instances of the storage are created with
20
- * the same scope, they will not share the same in-memory cache and BroadcastChannel.
21
- *
22
- * This is mostly useful for testing purposes to replicate the behavior of
23
- * multiple tabs or workers.
24
- */
25
- isolated: boolean;
26
- };
27
- /**
28
- * DocumentStorage is specifically designed around WarpDrive Cache and Request concepts.
29
- *
30
- * CacheFileDocument is a StructuredDocument (request response) whose `content` is
31
- * the ResourceDocument returned by inserting the request into a Store's Cache.
32
- */
33
- type CacheFileDocument = StructuredDocument<ResourceDocument<ExistingRecordIdentifier>>;
34
- /**
35
- * A CacheDocument is a reconstructed request response that rehydrates ResourceDocument
36
- * with the associated resources based on their identifiers.
37
- */
38
- type CacheDocument = StructuredDocument<ResourceDocument<ExistingResourceObject>>;
39
- type DocumentIdentifier = {
40
- lid: string;
41
- };
42
- type MemCache = {
43
- documents: Map<string, CacheFileDocument>;
44
- resources: Map<string, ExistingResourceObject>;
45
- };
46
- class InternalDocumentStorage {
47
- readonly options: DocumentStorageOptions;
48
- _fileHandle: Promise<FileSystemFileHandle>;
49
- _channel: BroadcastChannel;
50
- _invalidated: boolean;
51
- _lastModified: number;
52
- _cache: MemCache | null;
53
- _filePromise: Promise<MemCache> | null;
54
- constructor(options: DocumentStorageOptions);
55
- _onMessage(_event: MessageEvent): void;
56
- _open(scope: string): Promise<FileSystemFileHandle>;
57
- _read(): Promise<MemCache>;
58
- _patch(documentKey: string, document: CacheFileDocument, updatedResources: Map<string, ExistingResourceObject>): Promise<void>;
59
- getDocument(key: DocumentIdentifier): Promise<CacheDocument | null>;
60
- putDocument(document: CacheFileDocument, resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject): Promise<void>;
61
- _getResources(document: ResourceDataDocument<ExistingRecordIdentifier>, resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject, resources?: Map<string, ExistingResourceObject>): Map<string, ExistingResourceObject>;
62
- putResources(document: ResourceDataDocument<ExistingRecordIdentifier>, resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject): Promise<void>;
63
- clear(reset?: boolean): Promise<void>;
64
- }
65
- /**
66
- * DocumentStorage is a wrapper around the StorageManager API that provides
67
- * a simple interface for reading and updating documents and requests.
68
- *
69
- * Some goals for this experiment:
70
- *
71
- * - optimize for storing requests/documents
72
- * - optimize for storing resources
73
- * - optimize for looking up resources associated to a document
74
- * - optimize for notifying cross-tab when data is updated
75
- *
76
- * optional features:
77
- *
78
- * - support for offline mode
79
- * - ?? support for relationship based cache traversal
80
- * - a way to index records by type + another field (e.g updatedAt/createAt/name)
81
- * such that simple queries can be done without having to scan all records
82
- */
83
- export class DocumentStorage {
84
- readonly _storage: InternalDocumentStorage;
85
- constructor(options?: Partial<DocumentStorageOptions>);
86
- getDocument(key: DocumentIdentifier): Promise<CacheDocument | null>;
87
- putDocument(document: CacheFileDocument, resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject): Promise<void>;
88
- putResources(document: ResourceDataDocument<ExistingRecordIdentifier>, resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject): Promise<void>;
89
- clear(reset?: boolean): Promise<void>;
90
- }
91
- export {};
92
- }
93
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/document-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA6B,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACnG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAEvF,eAAO,MAAM,4BAA4B,gCAAgC,CAAC;AAC1E,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AACF;;;;;GAKG;AACH,KAAK,iBAAiB,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,CAAC,CAAC;AACxF;;;GAGG;AACH,KAAK,aAAa,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,CAAC,CAAC;AAMlF,KAAK,kBAAkB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,KAAK,QAAQ,GAAG;IACd,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC1C,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;CAChD,CAAC;AAEF,cAAM,uBAAuB;IAC3B,SAAiB,OAAO,EAAE,sBAAsB,CAAC;IACzC,WAAW,EAAE,OAAO,CAAC,oBAAoB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GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAInE,WAAW,CACT,QAAQ,EAAE,iBAAiB,EAC3B,iBAAiB,EAAE,CAAC,kBAAkB,EAAE,wBAAwB,KAAK,sBAAsB,GAC1F,OAAO,CAAC,IAAI,CAAC;IAIhB,YAAY,CACV,QAAQ,EAAE,oBAAoB,CAAC,wBAAwB,CAAC,EACxD,iBAAiB,EAAE,CAAC,kBAAkB,EAAE,wBAAwB,KAAK,sBAAsB,GAC1F,OAAO,CAAC,IAAI,CAAC;IAIhB,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO;CAGtB"}
@@ -1,4 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/document-storage' {
2
- export { DocumentStorage } from '@warp-drive-mirror/experiments/document-storage/index';
3
- }
4
- //# sourceMappingURL=document-storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-storage.d.ts","sourceRoot":"","sources":["../src/document-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1,4 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/image-fetch' {
2
- export { ImageFetch } from '@warp-drive-mirror/experiments/image-worker/fetch';
3
- }
4
- //# sourceMappingURL=image-fetch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"image-fetch.d.ts","sourceRoot":"","sources":["../src/image-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,21 +0,0 @@
1
- declare module '@warp-drive-mirror/experiments/image-worker/fetch' {
2
- import type { Deferred } from '@ember-data-mirror/request/-private/types';
3
- import type { RequestEventData } from '@warp-drive-mirror/experiments/image-worker/types';
4
- export interface FastBoot {
5
- require(moduleName: string): unknown;
6
- isFastBoot: boolean;
7
- request: Request;
8
- }
9
- export class ImageFetch {
10
- worker: Worker | SharedWorker;
11
- threadId: string;
12
- pending: Map<string, Deferred<string>>;
13
- channel: MessageChannel;
14
- cache: Map<string, string>;
15
- constructor(worker: Worker | SharedWorker | null);
16
- cleanupRequest(url: string): Deferred<string> | undefined;
17
- _send(event: RequestEventData): void;
18
- load(url: string): Promise<string>;
19
- }
20
- }
21
- //# sourceMappingURL=fetch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/image-worker/fetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAInE,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB;AAID,qBAAa,UAAU;IACb,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACvC,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAEvB,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAwChD,cAAc,CAAC,GAAG,EAAE,MAAM;IAO1B,KAAK,CAAC,KAAK,EAAE,gBAAgB;IAK7B,IAAI,CAAC,GAAG,EAAE,MAAM;CAejB"}