@warp-drive-mirror/experiments 0.0.1-alpha.97

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 (41) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +9 -0
  3. package/NCC-1701-a-blue.svg +4 -0
  4. package/NCC-1701-a.svg +4 -0
  5. package/README.md +33 -0
  6. package/dist/data-worker.js +281 -0
  7. package/dist/data-worker.js.map +1 -0
  8. package/dist/document-storage.js +243 -0
  9. package/dist/document-storage.js.map +1 -0
  10. package/dist/persisted-cache.js +559 -0
  11. package/dist/persisted-cache.js.map +1 -0
  12. package/dist/worker-fetch.js +149 -0
  13. package/dist/worker-fetch.js.map +1 -0
  14. package/package.json +82 -0
  15. package/unstable-preview-types/data-worker/cache-handler.d.ts +11 -0
  16. package/unstable-preview-types/data-worker/cache-handler.d.ts.map +1 -0
  17. package/unstable-preview-types/data-worker/fetch.d.ts +37 -0
  18. package/unstable-preview-types/data-worker/fetch.d.ts.map +1 -0
  19. package/unstable-preview-types/data-worker/types.d.ts +34 -0
  20. package/unstable-preview-types/data-worker/types.d.ts.map +1 -0
  21. package/unstable-preview-types/data-worker/utils.d.ts +23 -0
  22. package/unstable-preview-types/data-worker/utils.d.ts.map +1 -0
  23. package/unstable-preview-types/data-worker/worker.d.ts +16 -0
  24. package/unstable-preview-types/data-worker/worker.d.ts.map +1 -0
  25. package/unstable-preview-types/data-worker.d.ts +5 -0
  26. package/unstable-preview-types/data-worker.d.ts.map +1 -0
  27. package/unstable-preview-types/document-storage/index.d.ts +90 -0
  28. package/unstable-preview-types/document-storage/index.d.ts.map +1 -0
  29. package/unstable-preview-types/document-storage.d.ts +4 -0
  30. package/unstable-preview-types/document-storage.d.ts.map +1 -0
  31. package/unstable-preview-types/index.d.ts +13 -0
  32. package/unstable-preview-types/persisted-cache/cache.d.ts +433 -0
  33. package/unstable-preview-types/persisted-cache/cache.d.ts.map +1 -0
  34. package/unstable-preview-types/persisted-cache/db.d.ts +25 -0
  35. package/unstable-preview-types/persisted-cache/db.d.ts.map +1 -0
  36. package/unstable-preview-types/persisted-cache/fetch.d.ts +11 -0
  37. package/unstable-preview-types/persisted-cache/fetch.d.ts.map +1 -0
  38. package/unstable-preview-types/persisted-cache.d.ts +4 -0
  39. package/unstable-preview-types/persisted-cache.d.ts.map +1 -0
  40. package/unstable-preview-types/worker-fetch.d.ts +4 -0
  41. package/unstable-preview-types/worker-fetch.d.ts.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-storage.js","sources":["../src/document-storage/index.ts"],"sourcesContent":["import type { StructuredDocument } from '@ember-data-mirror/request';\nimport type { ExistingRecordIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type { ResourceDataDocument, ResourceDocument } from '@warp-drive-mirror/core-types/spec/document';\nimport type { ExistingResourceObject } from '@warp-drive-mirror/core-types/spec/json-api-raw';\n\nexport const WARP_DRIVE_STORAGE_FILE_NAME = 'warp-drive_document-storage';\nexport const WARP_DRIVE_STORAGE_VERSION = 1;\n\nexport type DocumentStorageOptions = {\n /**\n * The scope of the storage. This is used to enable multiple distinct\n * storage areas within the same origin.\n *\n * One use case for this is to have a separate storage area for each\n * user credential. So for instance, in applications that allow a single\n * user to have multiple accounts, each account can have its own storage!\n */\n scope: string;\n /**\n * When set to true, if other instances of the storage are created with\n * the same scope, they will not share the same in-memory cache and BroadcastChannel.\n *\n * This is mostly useful for testing purposes to replicate the behavior of\n * multiple tabs or workers.\n */\n isolated: boolean;\n};\n/**\n * DocumentStorage is specifically designed around WarpDrive Cache and Request concepts.\n *\n * CacheFileDocument is a StructuredDocument (request response) whose `content` is\n * the ResourceDocument returned by inserting the request into a Store's Cache.\n */\ntype CacheFileDocument = StructuredDocument<ResourceDocument<ExistingRecordIdentifier>>;\n/**\n * A CacheDocument is a reconstructed request response that rehydrates ResourceDocument\n * with the associated resources based on their identifiers.\n */\ntype CacheDocument = StructuredDocument<ResourceDocument<ExistingResourceObject>>;\ntype CacheResourceEntry = [string, ExistingResourceObject];\ntype CacheFile = {\n documents: [string, CacheFileDocument][];\n resources: CacheResourceEntry[];\n};\ntype DocumentIdentifier = { lid: string };\n\ntype MemCache = {\n documents: Map<string, CacheFileDocument>;\n resources: Map<string, ExistingResourceObject>;\n};\n\nclass InternalDocumentStorage {\n declare readonly options: DocumentStorageOptions;\n declare _fileHandle: Promise<FileSystemFileHandle>;\n declare _channel: BroadcastChannel;\n declare _invalidated: boolean;\n declare _lastModified: number;\n declare _cache: MemCache | null;\n declare _filePromise: Promise<MemCache> | null;\n\n constructor(options: DocumentStorageOptions) {\n this.options = options;\n\n this._lastModified = 0;\n this._invalidated = true;\n this._fileHandle = this._open(options.scope);\n this._channel = Object.assign(new BroadcastChannel(options.scope), {\n onmessage: this._onMessage.bind(this),\n });\n }\n\n _onMessage(_event: MessageEvent) {\n this._invalidated = true;\n }\n\n async _open(scope: string) {\n const directoryHandle = await navigator.storage.getDirectory();\n const fileHandle = await directoryHandle.getFileHandle(scope, { create: true });\n return fileHandle;\n }\n\n async _read(): Promise<MemCache> {\n if (this._filePromise) {\n return this._filePromise;\n }\n\n if (this._invalidated) {\n const updateFile = async () => {\n const fileHandle = await this._fileHandle;\n const file = await fileHandle.getFile();\n\n const lastModified = file.lastModified;\n if (lastModified === this._lastModified && this._cache) {\n return this._cache;\n }\n\n const contents = await file.text();\n const cache = contents ? (JSON.parse(contents) as CacheFile) : ({ documents: [], resources: [] } as CacheFile);\n\n const documents = new Map(cache.documents);\n const resources = new Map(cache.resources);\n\n const cacheMap = { documents, resources };\n this._cache = cacheMap;\n this._invalidated = false;\n this._lastModified = lastModified;\n return cacheMap;\n };\n this._filePromise = updateFile();\n await this._filePromise;\n this._filePromise = null;\n }\n\n return this._cache!;\n }\n\n async _patch(\n documentKey: string,\n document: CacheFileDocument,\n updatedResources: Map<string, ExistingResourceObject>\n ) {\n const fileHandle = await this._fileHandle;\n // secure a lock before getting latest state\n const writable = await fileHandle.createWritable();\n\n const cache = await this._read();\n cache.documents.set(documentKey, document);\n updatedResources.forEach((resource, key) => {\n cache.resources.set(key, resource);\n });\n\n const documents = [...cache.documents.entries()];\n const resources = [...cache.resources.entries()];\n const cacheFile: CacheFile = {\n documents,\n resources,\n };\n\n await writable.write(JSON.stringify(cacheFile));\n await writable.close();\n this._channel.postMessage({ type: 'patch', key: documentKey, resources: [...updatedResources.keys()] });\n }\n\n async getDocument(key: DocumentIdentifier): Promise<CacheDocument | null> {\n const cache = await this._read();\n // clone the document to avoid leaking the internal cache\n const document = structuredClone(cache.documents.get(key.lid));\n\n if (!document) {\n return null;\n }\n\n // expand the document with the resources\n if (document.content) {\n if (docHasData(document.content)) {\n let data: ExistingResourceObject | ExistingResourceObject[] | null = null;\n if (Array.isArray(document.content.data)) {\n data = document.content.data.map((resourceIdentifier) => {\n const resource = cache.resources.get(resourceIdentifier.lid);\n if (!resource) {\n throw new Error(`Resource not found for ${resourceIdentifier.lid}`);\n }\n\n // clone the resource to avoid leaking the internal cache\n return structuredClone(resource);\n });\n } else if (document.content.data) {\n const resource = cache.resources.get(document.content.data.lid);\n if (!resource) {\n throw new Error(`Resource not found for ${document.content.data.lid}`);\n }\n\n // clone the resource to avoid leaking the internal cache\n data = structuredClone(resource);\n }\n\n if (document.content.included) {\n const included = document.content.included.map((resourceIdentifier) => {\n const resource = cache.resources.get(resourceIdentifier.lid);\n if (!resource) {\n throw new Error(`Resource not found for ${resourceIdentifier.lid}`);\n }\n\n // clone the resource to avoid leaking the internal cache\n return structuredClone(resource);\n });\n document.content.included = included as ExistingRecordIdentifier[];\n }\n\n document.content.data = data as unknown as ResourceDataDocument<ExistingRecordIdentifier>['data'];\n }\n }\n\n return document as CacheDocument;\n }\n\n async putDocument(\n document: CacheFileDocument,\n resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject\n ): Promise<void> {\n const resources = new Map<string, ExistingResourceObject>();\n\n if (!document.content) {\n throw new Error(`Document content is missing, only finalized documents can be stored`);\n }\n\n if (!document.content.lid) {\n throw new Error(`Document content is missing a lid, only documents with a cache-key can be stored`);\n }\n\n if (docHasData(document.content)) {\n if (Array.isArray(document.content.data)) {\n document.content.data.forEach((resourceIdentifier) => {\n const resource = resourceCollector(resourceIdentifier);\n resources.set(resourceIdentifier.lid, structuredClone(resource));\n });\n } else if (document.content.data) {\n const resource = resourceCollector(document.content.data);\n resources.set(document.content.data.lid, structuredClone(resource));\n }\n\n if (document.content.included) {\n document.content.included.forEach((resourceIdentifier) => {\n const resource = resourceCollector(resourceIdentifier);\n resources.set(resourceIdentifier.lid, structuredClone(resource));\n });\n }\n }\n\n await this._patch(document.content.lid, structuredClone(document), resources);\n }\n\n async clear(reset?: boolean) {\n const fileHandle = await this._fileHandle;\n const writable = await fileHandle.createWritable();\n await writable.write('');\n await writable.close();\n\n this._invalidated = true;\n this._lastModified = 0;\n this._cache = null;\n this._filePromise = null;\n this._channel.postMessage({ type: 'clear' });\n\n if (!reset) {\n this._channel.close();\n this._channel = null as unknown as BroadcastChannel;\n\n if (!this.options.isolated) {\n Storages.delete(this.options.scope);\n }\n }\n }\n}\n\nfunction docHasData<T>(doc: ResourceDocument<T>): doc is ResourceDataDocument<T> {\n return 'data' in doc;\n}\n\nconst Storages = new Map<string, WeakRef<InternalDocumentStorage>>();\n\n/**\n * DocumentStorage is a wrapper around the StorageManager API that provides\n * a simple interface for reading and updating documents and requests.\n *\n * Some goals for this experiment:\n *\n * - optimize for storing requests/documents\n * - optimize for storing resources\n * - optimize for looking up resources associated to a document\n * - optimize for notifying cross-tab when data is updated\n *\n * optional features:\n *\n * - support for offline mode\n * - ?? support for relationship based cache traversal\n * - a way to index records by type + another field (e.g updatedAt/createAt/name)\n * such that simple queries can be done without having to scan all records\n */\nexport class DocumentStorage {\n declare readonly _storage: InternalDocumentStorage;\n\n constructor(options: Partial<DocumentStorageOptions> = {}) {\n options.isolated = options.isolated ?? false;\n options.scope = options.scope ?? 'default';\n\n const fileName = `${WARP_DRIVE_STORAGE_FILE_NAME}@version_${WARP_DRIVE_STORAGE_VERSION}:${options.scope}`;\n if (!options.isolated && Storages.has(fileName)) {\n const storage = Storages.get(fileName);\n if (storage) {\n this._storage = storage.deref()!;\n return;\n }\n }\n\n const storage = new InternalDocumentStorage({ scope: fileName, isolated: options.isolated });\n this._storage = storage;\n if (!options.isolated) {\n Storages.set(fileName, new WeakRef(storage));\n }\n }\n\n getDocument(key: DocumentIdentifier): Promise<CacheDocument | null> {\n return this._storage.getDocument(key);\n }\n\n putDocument(\n document: CacheFileDocument,\n resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject\n ): Promise<void> {\n return this._storage.putDocument(document, resourceCollector);\n }\n\n clear(reset?: boolean) {\n return this._storage.clear(reset);\n }\n}\n"],"names":["WARP_DRIVE_STORAGE_FILE_NAME","WARP_DRIVE_STORAGE_VERSION","InternalDocumentStorage","constructor","options","_lastModified","_invalidated","_fileHandle","_open","scope","_channel","Object","assign","BroadcastChannel","onmessage","_onMessage","bind","_event","directoryHandle","navigator","storage","getDirectory","fileHandle","getFileHandle","create","_read","_filePromise","updateFile","file","getFile","lastModified","_cache","contents","text","cache","JSON","parse","documents","resources","Map","cacheMap","_patch","documentKey","document","updatedResources","writable","createWritable","set","forEach","resource","key","entries","cacheFile","write","stringify","close","postMessage","type","keys","getDocument","structuredClone","get","lid","content","docHasData","data","Array","isArray","map","resourceIdentifier","Error","included","putDocument","resourceCollector","clear","reset","isolated","Storages","delete","doc","DocumentStorage","fileName","has","_storage","deref","WeakRef"],"mappings":"AAKO,MAAMA,4BAA4B,GAAG,6BAA6B,CAAA;AAClE,MAAMC,0BAA0B,GAAG,CAAC,CAAA;;AAqB3C;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAcA,MAAMC,uBAAuB,CAAC;EAS5BC,WAAWA,CAACC,OAA+B,EAAE;IAC3C,IAAI,CAACA,OAAO,GAAGA,OAAO,CAAA;IAEtB,IAAI,CAACC,aAAa,G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AAC,CAAA;AACtC,MAAA,IAAI7D,OAAO,EAAE;AACX,QAAA,IAAI,CAAC+D,QAAQ,GAAG/D,OAAO,CAACgE,KAAK,EAAG,CAAA;AAChC,QAAA,OAAA;AACF,OAAA;AACF,KAAA;AAEA,IAAA,MAAMhE,OAAO,GAAG,IAAIlB,uBAAuB,CAAC;AAAEO,MAAAA,KAAK,EAAEwE,QAAQ;MAAEL,QAAQ,EAAExE,OAAO,CAACwE,QAAAA;AAAS,KAAC,CAAC,CAAA;IAC5F,IAAI,CAACO,QAAQ,GAAG/D,OAAO,CAAA;AACvB,IAAA,IAAI,CAAChB,OAAO,CAACwE,QAAQ,EAAE;MACrBC,QAAQ,CAAC9B,GAAG,CAACkC,QAAQ,EAAE,IAAII,OAAO,CAACjE,OAAO,CAAC,CAAC,CAAA;AAC9C,KAAA;AACF,GAAA;EAEAuC,WAAWA,CAACT,GAAuB,EAAiC;AAClE,IAAA,OAAO,IAAI,CAACiC,QAAQ,CAACxB,WAAW,CAACT,GAAG,CAAC,CAAA;AACvC,GAAA;AAEAsB,EAAAA,WAAWA,CACT7B,QAA2B,EAC3B8B,iBAA2F,EAC5E;IACf,OAAO,IAAI,CAACU,QAAQ,CAACX,WAAW,CAAC7B,QAAQ,EAAE8B,iBAAiB,CAAC,CAAA;AAC/D,GAAA;EAEAC,KAAKA,CAACC,KAAe,EAAE;AACrB,IAAA,OAAO,IAAI,CAACQ,QAAQ,CAACT,KAAK,CAACC,KAAK,CAAC,CAAA;AACnC,GAAA;AACF;;;;"}
@@ -0,0 +1,559 @@
1
+ /**
2
+ * The PersistedCache wraps a Cache to enhance it with
3
+ * Persisted Storage capabilities.
4
+ *
5
+ * @class PersistedCache
6
+ * @internal
7
+ */
8
+ class PersistedCache {
9
+ constructor(cache, db) {
10
+ this.version = '2';
11
+ this._cache = cache;
12
+ this._db = db;
13
+ }
14
+
15
+ // Cache Management
16
+ // ================
17
+
18
+ /**
19
+ * Cache the response to a request
20
+ *
21
+ * Unlike `store.push` which has UPSERT
22
+ * semantics, `put` has `replace` semantics similar to
23
+ * the `http` method `PUT`
24
+ *
25
+ * the individually cacheabl
26
+ * e resource data it may contain
27
+ * should upsert, but the document data surrounding it should
28
+ * fully replace any existing information
29
+ *
30
+ * Note that in order to support inserting arbitrary data
31
+ * to the cache that did not originate from a request `put`
32
+ * should expect to sometimes encounter a document with only
33
+ * a `content` member and therefor must not assume the existence
34
+ * of `request` and `response` on the document.
35
+ *
36
+ * @method put
37
+ * @param {StructuredDocument} doc
38
+ * @returns {ResourceDocument}
39
+ * @internal
40
+ */
41
+ put(doc) {
42
+ const result = this._cache.put(doc);
43
+ if (!result.lid) {
44
+ return result;
45
+ }
46
+ const transaction = this._db.transaction(['request', 'resource'], 'readwrite', {
47
+ durability: 'relaxed'
48
+ });
49
+ const request = this._cache.peekRequest({
50
+ lid: result.lid
51
+ });
52
+ const requests = transaction.objectStore('request');
53
+ const resources = transaction.objectStore('resource');
54
+ requests.put(request);
55
+ if ('data' in result && result.data) {
56
+ const resourceData = Array.isArray(result.data) ? result.data : [result.data];
57
+ resourceData.forEach(identifier => {
58
+ resources.put(this._cache.peek(identifier), identifier.lid);
59
+ });
60
+ }
61
+ if ('included' in result && result.included) {
62
+ const included = result.included;
63
+ included.forEach(identifier => {
64
+ resources.put(this._cache.peek(identifier), identifier.lid);
65
+ });
66
+ }
67
+ return result;
68
+ }
69
+
70
+ /**
71
+ * Perform an operation on the cache to update the remote state.
72
+ *
73
+ * Note: currently the only valid operation is a MergeOperation
74
+ * which occurs when a collision of identifiers is detected.
75
+ *
76
+ * @method patch
77
+ * @internal
78
+ * @param op the operation to perform
79
+ * @returns {void}
80
+ */
81
+ patch(op) {
82
+ this._cache.patch(op);
83
+ }
84
+
85
+ /**
86
+ * Update resource data with a local mutation. Currently supports operations
87
+ * on relationships only.
88
+ *
89
+ * @method mutate
90
+ * @internal
91
+ * @param mutation
92
+ */
93
+ mutate(mutation) {
94
+ this._cache.mutate(mutation);
95
+ }
96
+
97
+ /**
98
+ * Peek resource data from the Cache.
99
+ *
100
+ * In development, if the return value
101
+ * is JSON the return value
102
+ * will be deep-cloned and deep-frozen
103
+ * to prevent mutation thereby enforcing cache
104
+ * Immutability.
105
+ *
106
+ * This form of peek is useful for implementations
107
+ * that want to feed raw-data from cache to the UI
108
+ * or which want to interact with a blob of data
109
+ * directly from the presentation cache.
110
+ *
111
+ * An implementation might want to do this because
112
+ * de-referencing records which read from their own
113
+ * blob is generally safer because the record does
114
+ * not require retainining connections to the Store
115
+ * and Cache to present data on a per-field basis.
116
+ *
117
+ * This generally takes the place of `getAttr` as
118
+ * an API and may even take the place of `getRelationship`
119
+ * depending on implementation specifics, though this
120
+ * latter usage is less recommended due to the advantages
121
+ * of the Graph handling necessary entanglements and
122
+ * notifications for relational data.
123
+ *
124
+ * @method peek
125
+ * @internal
126
+ * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
127
+ * @returns {ResourceDocument | ResourceBlob | null} the known resource data
128
+ */
129
+
130
+ peek(identifier) {
131
+ return this._cache.peek(identifier);
132
+ }
133
+
134
+ /**
135
+ * Peek the Cache for the existing request data associated with
136
+ * a cacheable request
137
+ *
138
+ * @method peekRequest
139
+ * @param {StableDocumentIdentifier}
140
+ * @returns {StableDocumentIdentifier | null}
141
+ * @internal
142
+ */
143
+ peekRequest(identifier) {
144
+ return this._cache.peekRequest(identifier);
145
+ }
146
+
147
+ /**
148
+ * Push resource data from a remote source into the cache for this identifier
149
+ *
150
+ * @method upsert
151
+ * @internal
152
+ * @param identifier
153
+ * @param data
154
+ * @param hasRecord
155
+ * @returns {void | string[]} if `hasRecord` is true then calculated key changes should be returned
156
+ */
157
+ upsert(identifier, data, hasRecord) {
158
+ return this._cache.upsert(identifier, data, hasRecord);
159
+ }
160
+
161
+ // Cache Forking Support
162
+ // =====================
163
+
164
+ /**
165
+ * Create a fork of the cache from the current state.
166
+ *
167
+ * Applications should typically not call this method themselves,
168
+ * preferring instead to fork at the Store level, which will
169
+ * utilize this method to fork the cache.
170
+ *
171
+ * @method fork
172
+ * @internal
173
+ * @returns Promise<Cache>
174
+ */
175
+ fork() {
176
+ return this._cache.fork();
177
+ }
178
+
179
+ /**
180
+ * Merge a fork back into a parent Cache.
181
+ *
182
+ * Applications should typically not call this method themselves,
183
+ * preferring instead to merge at the Store level, which will
184
+ * utilize this method to merge the caches.
185
+ *
186
+ * @method merge
187
+ * @param {Cache} cache
188
+ * @internal
189
+ * @returns Promise<void>
190
+ */
191
+ merge(cache) {
192
+ return this._cache.merge(cache);
193
+ }
194
+
195
+ /**
196
+ * Generate the list of changes applied to all
197
+ * record in the store.
198
+ *
199
+ * Each individual resource or document that has
200
+ * been mutated should be described as an individual
201
+ * `Change` entry in the returned array.
202
+ *
203
+ * A `Change` is described by an object containing up to
204
+ * three properties: (1) the `identifier` of the entity that
205
+ * changed; (2) the `op` code of that change being one of
206
+ * `upsert` or `remove`, and if the op is `upsert` a `patch`
207
+ * containing the data to merge into the cache for the given
208
+ * entity.
209
+ *
210
+ * This `patch` is opaque to the Store but should be understood
211
+ * by the Cache and may expect to be utilized by an Adapter
212
+ * when generating data during a `save` operation.
213
+ *
214
+ * It is generally recommended that the `patch` contain only
215
+ * the updated state, ignoring fields that are unchanged
216
+ *
217
+ * ```ts
218
+ * interface Change {
219
+ * identifier: StableRecordIdentifier | StableDocumentIdentifier;
220
+ * op: 'upsert' | 'remove';
221
+ * patch?: unknown;
222
+ * }
223
+ * ```
224
+ *
225
+ * @method diff
226
+ * @internal
227
+ */
228
+ diff() {
229
+ return this._cache.diff();
230
+ }
231
+
232
+ // SSR Support
233
+ // ===========
234
+
235
+ /**
236
+ * Serialize the entire contents of the Cache into a Stream
237
+ * which may be fed back into a new instance of the same Cache
238
+ * via `cache.hydrate`.
239
+ *
240
+ * @method dump
241
+ * @returns {Promise<ReadableStream>}
242
+ * @internal
243
+ */
244
+ dump() {
245
+ return this._cache.dump();
246
+ }
247
+
248
+ /**
249
+ * hydrate a Cache from a Stream with content previously serialized
250
+ * from another instance of the same Cache, resolving when hydration
251
+ * is complete.
252
+ *
253
+ * This method should expect to be called both in the context of restoring
254
+ * the Cache during application rehydration after SSR **AND** at unknown
255
+ * times during the lifetime of an already booted application when it is
256
+ * desired to bulk-load additional information into the cache. This latter
257
+ * behavior supports optimizing pre/fetching of data for route transitions
258
+ * via data-only SSR modes.
259
+ *
260
+ * @method hydrate
261
+ * @param {ReadableStream} stream
262
+ * @returns {Promise<void>}
263
+ * @internal
264
+ */
265
+ hydrate(stream) {
266
+ return this._cache.hydrate(stream);
267
+ }
268
+
269
+ // Cache
270
+ // =====
271
+
272
+ // Resource Support
273
+ // ================
274
+
275
+ /**
276
+ * [LIFECYLCE] Signal to the cache that a new record has been instantiated on the client
277
+ *
278
+ * It returns properties from options that should be set on the record during the create
279
+ * process. This return value behavior is deprecated.
280
+ *
281
+ * @method clientDidCreate
282
+ * @internal
283
+ * @param identifier
284
+ * @param options
285
+ */
286
+ clientDidCreate(identifier, options) {
287
+ return this._cache.clientDidCreate(identifier, options);
288
+ }
289
+
290
+ /**
291
+ * [LIFECYCLE] Signals to the cache that a resource
292
+ * will be part of a save transaction.
293
+ *
294
+ * @method willCommit
295
+ * @internal
296
+ * @param identifier
297
+ */
298
+ willCommit(identifier, context) {
299
+ this._cache.willCommit(identifier, context);
300
+ }
301
+
302
+ /**
303
+ * [LIFECYCLE] Signals to the cache that a resource
304
+ * was successfully updated as part of a save transaction.
305
+ *
306
+ * @method didCommit
307
+ * @internal
308
+ * @param identifier
309
+ * @param data
310
+ */
311
+ didCommit(identifier, result) {
312
+ return this._cache.didCommit(identifier, result);
313
+ }
314
+
315
+ /**
316
+ * [LIFECYCLE] Signals to the cache that a resource
317
+ * was update via a save transaction failed.
318
+ *
319
+ * @method commitWasRejected
320
+ * @internal
321
+ * @param identifier
322
+ * @param errors
323
+ */
324
+ commitWasRejected(identifier, errors) {
325
+ this._cache.commitWasRejected(identifier, errors);
326
+ }
327
+
328
+ /**
329
+ * [LIFECYCLE] Signals to the cache that all data for a resource
330
+ * should be cleared.
331
+ *
332
+ * @method unloadRecord
333
+ * @internal
334
+ * @param identifier
335
+ */
336
+ unloadRecord(identifier) {
337
+ this._cache.unloadRecord(identifier);
338
+ }
339
+
340
+ // Granular Resource Data APIs
341
+ // ===========================
342
+
343
+ /**
344
+ * Retrieve the data for an attribute from the cache
345
+ *
346
+ * @method getAttr
347
+ * @internal
348
+ * @param identifier
349
+ * @param propertyName
350
+ * @returns {unknown}
351
+ */
352
+ getAttr(identifier, field) {
353
+ return this._cache.getAttr(identifier, field);
354
+ }
355
+
356
+ /**
357
+ * Mutate the data for an attribute in the cache
358
+ *
359
+ * @method setAttr
360
+ * @internal
361
+ * @param identifier
362
+ * @param propertyName
363
+ * @param value
364
+ */
365
+ setAttr(identifier, propertyName, value) {
366
+ this._cache.setAttr(identifier, propertyName, value);
367
+ }
368
+
369
+ /**
370
+ * Query the cache for the changed attributes of a resource.
371
+ *
372
+ * @method changedAttrs
373
+ * @internal
374
+ * @param identifier
375
+ * @returns
376
+ */
377
+ changedAttrs(identifier) {
378
+ return this._cache.changedAttrs(identifier);
379
+ }
380
+
381
+ /**
382
+ * Query the cache for whether any mutated attributes exist
383
+ *
384
+ * @method hasChangedAttrs
385
+ * @internal
386
+ * @param identifier
387
+ * @returns {boolean}
388
+ */
389
+ hasChangedAttrs(identifier) {
390
+ return this._cache.hasChangedAttrs(identifier);
391
+ }
392
+
393
+ /**
394
+ * Tell the cache to discard any uncommitted mutations to attributes
395
+ *
396
+ * @method rollbackAttrs
397
+ * @internal
398
+ * @param identifier
399
+ * @returns the names of attributes that were restored
400
+ */
401
+ rollbackAttrs(identifier) {
402
+ return this._cache.rollbackAttrs(identifier);
403
+ }
404
+
405
+ /**
406
+ * Query the cache for the changes to relationships of a resource.
407
+ *
408
+ * Returns a map of relationship names to RelationshipDiff objects.
409
+ *
410
+ * ```ts
411
+ * type RelationshipDiff =
412
+ | {
413
+ kind: 'collection';
414
+ remoteState: StableRecordIdentifier[];
415
+ additions: Set<StableRecordIdentifier>;
416
+ removals: Set<StableRecordIdentifier>;
417
+ localState: StableRecordIdentifier[];
418
+ reordered: boolean;
419
+ }
420
+ | {
421
+ kind: 'resource';
422
+ remoteState: StableRecordIdentifier | null;
423
+ localState: StableRecordIdentifier | null;
424
+ };
425
+ ```
426
+ *
427
+ * @method changedRelationships
428
+ * @public
429
+ * @param {StableRecordIdentifier} identifier
430
+ * @return {Map<string, RelationshipDiff>}
431
+ */
432
+ changedRelationships(identifier) {
433
+ return this._cache.changedRelationships(identifier);
434
+ }
435
+
436
+ /**
437
+ * Query the cache for whether any mutated attributes exist
438
+ *
439
+ * @method hasChangedRelationships
440
+ * @public
441
+ * @param {StableRecordIdentifier} identifier
442
+ * @return {boolean}
443
+ */
444
+ hasChangedRelationships(identifier) {
445
+ return this._cache.hasChangedRelationships(identifier);
446
+ }
447
+
448
+ /**
449
+ * Tell the cache to discard any uncommitted mutations to relationships.
450
+ *
451
+ * This will also discard the change on any appropriate inverses.
452
+ *
453
+ * This method is a candidate to become a mutation
454
+ *
455
+ * @method rollbackRelationships
456
+ * @public
457
+ * @param {StableRecordIdentifier} identifier
458
+ * @return {string[]} the names of relationships that were restored
459
+ */
460
+ rollbackRelationships(identifier) {
461
+ return this._cache.rollbackRelationships(identifier);
462
+ }
463
+
464
+ // Relationships
465
+ // =============
466
+
467
+ /**
468
+ * Query the cache for the current state of a relationship property
469
+ *
470
+ * @method getRelationship
471
+ * @internal
472
+ * @param identifier
473
+ * @param propertyName
474
+ * @returns resource relationship object
475
+ */
476
+ getRelationship(identifier, field, isCollection) {
477
+ return this._cache.getRelationship(identifier, field, isCollection);
478
+ }
479
+
480
+ // Resource State
481
+ // ===============
482
+
483
+ /**
484
+ * Update the cache state for the given resource to be marked as locally deleted,
485
+ * or remove such a mark.
486
+ *
487
+ * @method setIsDeleted
488
+ * @internal
489
+ * @param identifier
490
+ * @param isDeleted
491
+ */
492
+ setIsDeleted(identifier, isDeleted) {
493
+ this._cache.setIsDeleted(identifier, isDeleted);
494
+ }
495
+
496
+ /**
497
+ * Query the cache for any validation errors applicable to the given resource.
498
+ *
499
+ * @method getErrors
500
+ * @internal
501
+ * @param identifier
502
+ * @returns
503
+ */
504
+ getErrors(identifier) {
505
+ return this._cache.getErrors(identifier);
506
+ }
507
+
508
+ /**
509
+ * Query the cache for whether a given resource has any available data
510
+ *
511
+ * @method isEmpty
512
+ * @internal
513
+ * @param identifier
514
+ * @returns {boolean}
515
+ */
516
+ isEmpty(identifier) {
517
+ return this._cache.isEmpty(identifier);
518
+ }
519
+
520
+ /**
521
+ * Query the cache for whether a given resource was created locally and not
522
+ * yet persisted.
523
+ *
524
+ * @method isNew
525
+ * @internal
526
+ * @param identifier
527
+ * @returns {boolean}
528
+ */
529
+ isNew(identifier) {
530
+ return this._cache.isNew(identifier);
531
+ }
532
+
533
+ /**
534
+ * Query the cache for whether a given resource is marked as deleted (but not
535
+ * necessarily persisted yet).
536
+ *
537
+ * @method isDeleted
538
+ * @internal
539
+ * @param identifier
540
+ * @returns {boolean}
541
+ */
542
+ isDeleted(identifier) {
543
+ return this._cache.isDeleted(identifier);
544
+ }
545
+
546
+ /**
547
+ * Query the cache for whether a given resource has been deleted and that deletion
548
+ * has also been persisted.
549
+ *
550
+ * @method isDeletionCommitted
551
+ * @internal
552
+ * @param identifier
553
+ * @returns {boolean}
554
+ */
555
+ isDeletionCommitted(identifier) {
556
+ return this._cache.isDeletionCommitted(identifier);
557
+ }
558
+ }
559
+ export { PersistedCache };
@@ -0,0 +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 * @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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AEa,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,UAA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