@warp-drive-mirror/experiments 0.1.0-alpha.142 → 0.1.0-alpha.144

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.
Binary file
Binary file
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 324 32">
2
+ <path fill="#110819"
3
+ d="M321.58 29.54a41.7 41.7 0 0 1-7.26 1.72c-2.4.36-4.87.53-7.4.53-3.21 0-6.09-.34-8.6-1.03a18.5 18.5 0 0 1-6.34-3.03 13.07 13.07 0 0 1-3.94-4.83c-.9-1.9-1.35-4.06-1.35-6.47a14.32 14.32 0 0 1 5.22-11.19 18.14 18.14 0 0 1 6.06-3.3c2.36-.81 5-1.21 7.9-1.21 2.68 0 5.13.36 7.35 1.1 2.24.71 4.15 1.78 5.74 3.2a14.28 14.28 0 0 1 3.72 5.24 18.12 18.12 0 0 1 1.33 7.17v1.98h-29.1a7.5 7.5 0 0 0 1.28 2.56c.6.77 1.4 1.43 2.42 1.97 1.02.55 2.27.97 3.74 1.27 1.5.3 3.27.45 5.33.45a35.35 35.35 0 0 0 8.23-.96c1.22-.3 2.31-.64 3.29-1 .99-.35 1.78-.7 2.38-1.07v6.9Zm-5.5-15.96a6.73 6.73 0 0 0-.66-2.26 5.82 5.82 0 0 0-1.72-2.13 9.46 9.46 0 0 0-3.1-1.54 15.6 15.6 0 0 0-4.77-.63c-1.79 0-3.33.23-4.64.67-1.3.44-2.4 1-3.29 1.65a8.37 8.37 0 0 0-2.04 2.13c-.48.76-.8 1.46-.94 2.1h21.16ZM271.84 31h-9.28L247.63 1.48h8.9l10.74 22.22 10.72-22.22h8.9L271.83 31ZM234.8 31V1.48h7.97V31h-7.97ZM229.73 8.16l-.94-.28c-.4-.13-.88-.25-1.42-.36a17.88 17.88 0 0 0-3.8-.45c-1.44 0-2.78.18-4.02.53-1.23.35-2.39.81-3.46 1.4a19.48 19.48 0 0 0-3 1.98c-.92.73-1.77 1.48-2.54 2.25V31h-7.97V1.48h7.97v4.8c.96-.72 1.94-1.41 2.94-2.07a25.36 25.36 0 0 1 3.16-1.78 18.9 18.9 0 0 1 3.48-1.23 15.39 15.39 0 0 1 5.44-.39 25 25 0 0 1 4.16.67v6.68ZM197.05 16.22c0 1.89-.2 3.57-.62 5.05a12.7 12.7 0 0 1-1.76 3.82 11.07 11.07 0 0 1-2.7 2.77 13.77 13.77 0 0 1-3.51 1.83c-1.29.46-2.68.8-4.17 1-1.49.21-3.04.31-4.66.31H160.9V1.48h18.69c1.62 0 3.17.1 4.66.32 1.49.2 2.88.53 4.17 1 1.3.45 2.48 1.06 3.54 1.82 1.06.74 1.96 1.67 2.7 2.77a12.7 12.7 0 0 1 1.77 3.82c.42 1.46.62 3.13.62 5Zm-8.03 0c0-1.42-.19-2.65-.56-3.7a5.64 5.64 0 0 0-1.76-2.57 7.66 7.66 0 0 0-3.16-1.53c-1.3-.34-2.9-.52-4.77-.52h-9.9v16.68h9.9c1.88 0 3.47-.17 4.77-.5a7.86 7.86 0 0 0 3.16-1.54c.81-.7 1.4-1.58 1.76-2.63.37-1.04.56-2.27.56-3.7ZM153.98 10.55c0 1.47-.25 2.78-.73 3.9a6.82 6.82 0 0 1-2.26 2.86 10.95 10.95 0 0 1-4 1.77 25.6 25.6 0 0 1-5.86.58h-13.26V31h-2.68V1.48h15.94c2.3 0 4.25.2 5.87.6 1.63.39 2.96.96 4 1.72a6.67 6.67 0 0 1 2.25 2.84c.48 1.13.73 2.43.73 3.9Zm-2.77 0c0-1.4-.24-2.54-.71-3.4a4.53 4.53 0 0 0-2.15-1.97c-.96-.48-2.19-.8-3.68-.95a50.43 50.43 0 0 0-5.26-.24h-11.54v13.15h11.54l2.51.02c.9 0 1.8-.04 2.67-.12.87-.1 1.7-.27 2.5-.5.8-.24 1.5-.6 2.1-1.1a5.05 5.05 0 0 0 1.46-1.9 7 7 0 0 0 .56-3ZM119.76 3.76c-.41-.13-1-.27-1.74-.41-.73-.16-1.67-.24-2.83-.24-1.6 0-3.12.2-4.54.6a17.94 17.94 0 0 0-7.28 3.96 23.73 23.73 0 0 0-2.8 2.83V31H97.9V1.48h2.69V7.5c.96-1 2-1.9 3.11-2.73a21.54 21.54 0 0 1 7.48-3.53 17.47 17.47 0 0 1 5.6-.47c.4.02.77.04 1.1.09a16.6 16.6 0 0 1 1.9.26v2.64ZM85.52 31v-3.27c-1.03.56-2.2 1.08-3.53 1.55a40.4 40.4 0 0 1-13.13 2.3c-1.91 0-3.64-.17-5.17-.52a12.2 12.2 0 0 1-3.87-1.52A7.38 7.38 0 0 1 57.37 27a7.06 7.06 0 0 1-.86-3.52c0-1.32.33-2.48 1-3.48a8.81 8.81 0 0 1 2.85-2.64c1.23-.76 2.71-1.4 4.45-1.91 1.74-.53 3.7-.98 5.84-1.34 2.15-.37 4.47-.67 6.96-.9 2.5-.24 5.14-.44 7.9-.6v-2.26c0-.91-.16-1.72-.5-2.42a5.54 5.54 0 0 0-1.45-1.83 7.97 7.97 0 0 0-2.17-1.31c-.83-.36-1.73-.65-2.7-.86a33.97 33.97 0 0 0-13.54.21c-1.03.25-2.02.53-2.96.86-.95.33-1.9.68-2.86 1.06V2.92c1.99-.53 4.1-.99 6.36-1.38 2.26-.4 4.66-.6 7.2-.6 2.14 0 4.15.19 6.01.56 1.86.36 3.48.94 4.86 1.74A9.16 9.16 0 0 1 87 6.36a8.55 8.55 0 0 1 1.18 4.62V31h-2.66Zm0-16c-4.69.25-8.69.62-12.01 1.09-3.31.47-6.02 1.05-8.12 1.74-2.1.69-3.66 1.49-4.64 2.4a4.18 4.18 0 0 0-1.46 3.12c0 .95.23 1.78.7 2.52a5.86 5.86 0 0 0 2.09 1.84c.9.49 2 .86 3.29 1.12 1.28.24 2.73.37 4.34.37a29.36 29.36 0 0 0 5.95-.6 36.6 36.6 0 0 0 5.71-1.57c.86-.32 1.64-.66 2.34-1.01a11.3 11.3 0 0 0 1.8-1.1v-9.93ZM28.65 1.48l10.53 27.37L50.09 1.48h2.99L41.2 31h-4L26.84 4.34 16.51 31h-4L.63 1.48h2.99l10.91 27.37 10.5-27.37h3.62Z" />
4
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 324 32">
2
+ <path fill="#FFC474"
3
+ d="M321.58 29.54a41.7 41.7 0 0 1-7.26 1.72c-2.4.36-4.87.53-7.4.53-3.21 0-6.09-.34-8.6-1.03a18.5 18.5 0 0 1-6.34-3.03 13.07 13.07 0 0 1-3.94-4.83c-.9-1.9-1.35-4.06-1.35-6.47a14.32 14.32 0 0 1 5.22-11.19 18.14 18.14 0 0 1 6.06-3.3c2.36-.81 5-1.21 7.9-1.21 2.68 0 5.13.36 7.35 1.1 2.24.71 4.15 1.78 5.74 3.2a14.28 14.28 0 0 1 3.72 5.24 18.12 18.12 0 0 1 1.33 7.17v1.98h-29.1a7.5 7.5 0 0 0 1.28 2.56c.6.77 1.4 1.43 2.42 1.97 1.02.55 2.27.97 3.74 1.27 1.5.3 3.27.45 5.33.45a35.35 35.35 0 0 0 8.23-.96c1.22-.3 2.31-.64 3.29-1 .99-.35 1.78-.7 2.38-1.07v6.9Zm-5.5-15.96a6.73 6.73 0 0 0-.66-2.26 5.82 5.82 0 0 0-1.72-2.13 9.46 9.46 0 0 0-3.1-1.54 15.6 15.6 0 0 0-4.77-.63c-1.79 0-3.33.23-4.64.67-1.3.44-2.4 1-3.29 1.65a8.37 8.37 0 0 0-2.04 2.13c-.48.76-.8 1.46-.94 2.1h21.16ZM271.84 31h-9.28L247.63 1.48h8.9l10.74 22.22 10.72-22.22h8.9L271.83 31ZM234.8 31V1.48h7.97V31h-7.97ZM229.73 8.16l-.94-.28c-.4-.13-.88-.25-1.42-.36a17.88 17.88 0 0 0-3.8-.45c-1.44 0-2.78.18-4.02.53-1.23.35-2.39.81-3.46 1.4a19.48 19.48 0 0 0-3 1.98c-.92.73-1.77 1.48-2.54 2.25V31h-7.97V1.48h7.97v4.8c.96-.72 1.94-1.41 2.94-2.07a25.36 25.36 0 0 1 3.16-1.78 18.9 18.9 0 0 1 3.48-1.23 15.39 15.39 0 0 1 5.44-.39 25 25 0 0 1 4.16.67v6.68ZM197.05 16.22c0 1.89-.2 3.57-.62 5.05a12.7 12.7 0 0 1-1.76 3.82 11.07 11.07 0 0 1-2.7 2.77 13.77 13.77 0 0 1-3.51 1.83c-1.29.46-2.68.8-4.17 1-1.49.21-3.04.31-4.66.31H160.9V1.48h18.69c1.62 0 3.17.1 4.66.32 1.49.2 2.88.53 4.17 1 1.3.45 2.48 1.06 3.54 1.82 1.06.74 1.96 1.67 2.7 2.77a12.7 12.7 0 0 1 1.77 3.82c.42 1.46.62 3.13.62 5Zm-8.03 0c0-1.42-.19-2.65-.56-3.7a5.64 5.64 0 0 0-1.76-2.57 7.66 7.66 0 0 0-3.16-1.53c-1.3-.34-2.9-.52-4.77-.52h-9.9v16.68h9.9c1.88 0 3.47-.17 4.77-.5a7.86 7.86 0 0 0 3.16-1.54c.81-.7 1.4-1.58 1.76-2.63.37-1.04.56-2.27.56-3.7ZM153.98 10.55c0 1.47-.25 2.78-.73 3.9a6.82 6.82 0 0 1-2.26 2.86 10.95 10.95 0 0 1-4 1.77 25.6 25.6 0 0 1-5.86.58h-13.26V31h-2.68V1.48h15.94c2.3 0 4.25.2 5.87.6 1.63.39 2.96.96 4 1.72a6.67 6.67 0 0 1 2.25 2.84c.48 1.13.73 2.43.73 3.9Zm-2.77 0c0-1.4-.24-2.54-.71-3.4a4.53 4.53 0 0 0-2.15-1.97c-.96-.48-2.19-.8-3.68-.95a50.43 50.43 0 0 0-5.26-.24h-11.54v13.15h11.54l2.51.02c.9 0 1.8-.04 2.67-.12.87-.1 1.7-.27 2.5-.5.8-.24 1.5-.6 2.1-1.1a5.05 5.05 0 0 0 1.46-1.9 7 7 0 0 0 .56-3ZM119.76 3.76c-.41-.13-1-.27-1.74-.41-.73-.16-1.67-.24-2.83-.24-1.6 0-3.12.2-4.54.6a17.94 17.94 0 0 0-7.28 3.96 23.73 23.73 0 0 0-2.8 2.83V31H97.9V1.48h2.69V7.5c.96-1 2-1.9 3.11-2.73a21.54 21.54 0 0 1 7.48-3.53 17.47 17.47 0 0 1 5.6-.47c.4.02.77.04 1.1.09a16.6 16.6 0 0 1 1.9.26v2.64ZM85.52 31v-3.27c-1.03.56-2.2 1.08-3.53 1.55a40.4 40.4 0 0 1-13.13 2.3c-1.91 0-3.64-.17-5.17-.52a12.2 12.2 0 0 1-3.87-1.52A7.38 7.38 0 0 1 57.37 27a7.06 7.06 0 0 1-.86-3.52c0-1.32.33-2.48 1-3.48a8.81 8.81 0 0 1 2.85-2.64c1.23-.76 2.71-1.4 4.45-1.91 1.74-.53 3.7-.98 5.84-1.34 2.15-.37 4.47-.67 6.96-.9 2.5-.24 5.14-.44 7.9-.6v-2.26c0-.91-.16-1.72-.5-2.42a5.54 5.54 0 0 0-1.45-1.83 7.97 7.97 0 0 0-2.17-1.31c-.83-.36-1.73-.65-2.7-.86a33.97 33.97 0 0 0-13.54.21c-1.03.25-2.02.53-2.96.86-.95.33-1.9.68-2.86 1.06V2.92c1.99-.53 4.1-.99 6.36-1.38 2.26-.4 4.66-.6 7.2-.6 2.14 0 4.15.19 6.01.56 1.86.36 3.48.94 4.86 1.74A9.16 9.16 0 0 1 87 6.36a8.55 8.55 0 0 1 1.18 4.62V31h-2.66Zm0-16c-4.69.25-8.69.62-12.01 1.09-3.31.47-6.02 1.05-8.12 1.74-2.1.69-3.66 1.49-4.64 2.4a4.18 4.18 0 0 0-1.46 3.12c0 .95.23 1.78.7 2.52a5.86 5.86 0 0 0 2.09 1.84c.9.49 2 .86 3.29 1.12 1.28.24 2.73.37 4.34.37a29.36 29.36 0 0 0 5.95-.6 36.6 36.6 0 0 0 5.71-1.57c.86-.32 1.64-.66 2.34-1.01a11.3 11.3 0 0 0 1.8-1.1v-9.93ZM28.65 1.48l10.53 27.37L50.09 1.48h2.99L41.2 31h-4L26.84 4.34 16.51 31h-4L.63 1.48h2.99l10.91 27.37 10.5-27.37h3.62Z" />
4
+ </svg>
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.1.0-alpha.142",
4
+ "version": "0.1.0-alpha.144",
5
5
  "license": "MIT",
6
6
  "author": "Chris Thoburn <runspired@users.noreply.github.com>",
7
7
  "repository": {
@@ -36,15 +36,14 @@
36
36
  "CHANGELOG.md",
37
37
  "README.md",
38
38
  "LICENSE.md",
39
- "NCC-1701-a-blue.svg",
40
- "NCC-1701-a.svg"
39
+ "logos"
41
40
  ],
42
41
  "peerDependencies": {
43
42
  "@sqlite.org/sqlite-wasm": "3.46.0-build2",
44
- "@ember-data-mirror/request": "5.4.0-alpha.142",
45
- "@ember-data-mirror/request-utils": "5.4.0-alpha.142",
46
- "@ember-data-mirror/store": "5.4.0-alpha.142",
47
- "@warp-drive-mirror/core-types": "5.4.0-alpha.142"
43
+ "@ember-data-mirror/request": "5.4.0-alpha.144",
44
+ "@ember-data-mirror/request-utils": "5.4.0-alpha.144",
45
+ "@ember-data-mirror/store": "5.4.0-alpha.144",
46
+ "@warp-drive-mirror/core-types": "5.4.0-alpha.144"
48
47
  },
49
48
  "peerDependenciesMeta": {
50
49
  "@sqlite.org/sqlite-wasm": {
@@ -53,20 +52,20 @@
53
52
  },
54
53
  "dependencies": {
55
54
  "@embroider/macros": "^1.16.11",
56
- "@warp-drive-mirror/build-config": "5.4.0-alpha.142"
55
+ "@warp-drive-mirror/build-config": "5.4.0-alpha.144"
57
56
  },
58
57
  "devDependencies": {
59
58
  "@babel/core": "^7.26.9",
60
59
  "@babel/plugin-transform-typescript": "^7.26.8",
61
60
  "@babel/preset-env": "^7.26.9",
62
61
  "@babel/preset-typescript": "^7.26.0",
63
- "@ember-data-mirror/request": "5.4.0-alpha.142",
64
- "@ember-data-mirror/request-utils": "5.4.0-alpha.142",
65
- "@ember-data-mirror/store": "5.4.0-alpha.142",
66
- "@ember-data-mirror/tracking": "5.4.0-alpha.142",
62
+ "@ember-data-mirror/request": "5.4.0-alpha.144",
63
+ "@ember-data-mirror/request-utils": "5.4.0-alpha.144",
64
+ "@ember-data-mirror/store": "5.4.0-alpha.144",
65
+ "@ember-data-mirror/tracking": "5.4.0-alpha.144",
67
66
  "@glimmer/component": "^1.1.2",
68
- "@warp-drive-mirror/core-types": "5.4.0-alpha.142",
69
- "@warp-drive/internal-config": "5.4.0-alpha.142",
67
+ "@warp-drive-mirror/core-types": "5.4.0-alpha.144",
68
+ "@warp-drive/internal-config": "5.4.0-alpha.144",
70
69
  "ember-source": "~5.12.0",
71
70
  "@sqlite.org/sqlite-wasm": "3.46.0-build2",
72
71
  "typescript": "^5.8.2",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-Cn3o840t.js","sources":["../src/document-storage/index.ts"],"sourcesContent":["import type { RequestInfo, ResponseInfo, StructuredDocument } from '@ember-data-mirror/request';\nimport type { StoreRequestContext } from '@ember-data-mirror/store';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\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 = safeDocumentHydrate(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 this._getResources(document.content, resourceCollector, resources);\n }\n\n await this._patch(document.content.lid, safeDocumentSerialize(document), resources);\n }\n\n _getResources(\n document: ResourceDataDocument<ExistingRecordIdentifier>,\n resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject,\n resources: Map<string, ExistingResourceObject> = new Map<string, ExistingResourceObject>()\n ) {\n if (Array.isArray(document.data)) {\n document.data.forEach((resourceIdentifier) => {\n const resource = resourceCollector(resourceIdentifier);\n resources.set(resourceIdentifier.lid, structuredClone(resource));\n });\n } else if (document.data) {\n const resource = resourceCollector(document.data);\n resources.set(document.data.lid, structuredClone(resource));\n }\n\n if (document.included) {\n document.included.forEach((resourceIdentifier) => {\n const resource = resourceCollector(resourceIdentifier);\n resources.set(resourceIdentifier.lid, structuredClone(resource));\n });\n }\n\n return resources;\n }\n\n async putResources(\n document: ResourceDataDocument<ExistingRecordIdentifier>,\n resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => 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 const updatedResources = this._getResources(document, resourceCollector);\n\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: null, resources: [...updatedResources.keys()] });\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 safeDocumentSerialize<T>(document: T): T {\n assert(`Expected to receive a document`, document && typeof document === 'object');\n const doc = document as unknown as {\n request?: StoreRequestContext['request'];\n response?: Response;\n content?: unknown;\n };\n const newDoc: { request?: unknown; response?: unknown; content?: unknown } = {};\n if ('request' in doc) {\n newDoc.request = prepareRequest(doc.request!);\n }\n if ('response' in doc) {\n newDoc.response = prepareResponse(doc.response!);\n }\n\n if ('content' in doc) {\n newDoc.content = structuredClone(doc.content);\n }\n\n return newDoc as T;\n}\n\nfunction prepareRequest(request: StoreRequestContext['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 requestCopy;\n}\n\ntype Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\nfunction prepareResponse(response: Response | ResponseInfo | null) {\n if (!response) return null;\n\n const clone: Partial<Mutable<Response>> = {};\n\n if (response.headers) {\n clone.headers = Array.from(response.headers.entries()) as unknown as Headers;\n }\n\n clone.ok = response.ok;\n clone.redirected = response.redirected;\n clone.status = response.status;\n clone.statusText = response.statusText;\n clone.type = response.type;\n clone.url = response.url;\n\n return clone;\n}\n\nfunction safeDocumentHydrate<T>(document: T): T {\n assert(`Expected to receive a document`, document && typeof document === 'object');\n const doc = document as unknown as {\n request?: Request | StoreRequestContext['request'];\n response?: Response;\n content?: unknown;\n };\n const newDoc: { request?: StoreRequestContext['request'] | Request; response?: Response; content?: unknown } = {};\n\n if ('request' in doc) {\n const headers = new Headers(doc.request!.headers);\n const req = Object.assign({}, doc.request, { headers });\n newDoc.request = new Request(doc.request!.url ?? '', req);\n }\n\n if ('response' in doc) {\n const headers = new Headers(doc.response!.headers);\n const resp = Object.assign({}, doc.response, { headers });\n newDoc.response = new Response(null, resp);\n }\n\n if ('content' in doc) {\n newDoc.content = structuredClone(doc.content);\n }\n\n return newDoc as T;\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 putResources(\n document: ResourceDataDocument<ExistingRecordIdentifier>,\n resourceCollector: (resourceIdentifier: ExistingRecordIdentifier) => ExistingResourceObject\n ): Promise<void> {\n return this._storage.putResources(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","safeDocumentHydrate","get","lid","content","docHasData","data","Array","isArray","map","resourceIdentifier","Error","structuredClone","included","putDocument","resourceCollector","_getResources","safeDocumentSerialize","putResources","clear","reset","isolated","Storages","delete","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","doc","newDoc","request","prepareRequest","response","prepareResponse","signal","headers","requestCopy","store","AbortSignal","Headers","from","clone","ok","redirected","status","statusText","url","req","Request","resp","Response","DocumentStorage","fileName","has","_storage","deref","WeakRef"],"mappings":";;AAOO,MAAMA,4BAA4B,GAAG,6BAA6B;AAClE,MAAMC,0BAA0B,GAAG,CAAC;;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;IAEtB,IAAI,CAACC,aAAa,GAAG,CAAC;IACtB,IAAI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