@dxos/plugin-wnfs 0.8.4-main.fd6878d → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/PLUGIN.mdl +371 -0
- package/README.md +2 -2
- package/dist/lib/neutral/WnfsPlugin.mjs +51 -0
- package/dist/lib/neutral/WnfsPlugin.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs +12 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.workerd.mjs +12 -0
- package/dist/lib/neutral/WnfsPlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/backend-4HPTHS33.mjs +47 -0
- package/dist/lib/neutral/backend-4HPTHS33.mjs.map +7 -0
- package/dist/lib/{browser/blockstore-PSYZCC2O.mjs → neutral/blockstore-U6SPNL2C.mjs} +12 -13
- package/dist/lib/neutral/blockstore-U6SPNL2C.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +13 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-KUQHRT52.mjs +39 -0
- package/dist/lib/neutral/chunk-KUQHRT52.mjs.map +7 -0
- package/dist/lib/{browser/chunk-D6VTEQIE.mjs → neutral/chunk-L33MOD23.mjs} +85 -25
- package/dist/lib/neutral/chunk-L33MOD23.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QODCKFTY.mjs +19 -0
- package/dist/lib/neutral/chunk-QODCKFTY.mjs.map +7 -0
- package/dist/lib/neutral/helpers/index.mjs +26 -0
- package/dist/lib/neutral/helpers/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +36 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +12 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +17 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +8 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/lib/neutral/url-resolver-BIRH7WHL.mjs +47 -0
- package/dist/lib/neutral/url-resolver-BIRH7WHL.mjs.map +7 -0
- package/dist/types/src/WnfsPlugin.d.ts +3 -1
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/WnfsPlugin.node.d.ts +4 -0
- package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -0
- package/dist/types/src/WnfsPlugin.test.d.ts +2 -0
- package/dist/types/src/WnfsPlugin.test.d.ts.map +1 -0
- package/dist/types/src/WnfsPlugin.workerd.d.ts +4 -0
- package/dist/types/src/WnfsPlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/annotations.d.ts +7 -0
- package/dist/types/src/annotations.d.ts.map +1 -0
- package/dist/types/src/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/backend.d.ts +7 -0
- package/dist/types/src/capabilities/backend.d.ts.map +1 -0
- package/dist/types/src/capabilities/blockstore.d.ts +3 -2
- package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +5 -6
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/url-resolver.d.ts +7 -0
- package/dist/types/src/capabilities/url-resolver.d.ts.map +1 -0
- package/dist/types/src/helpers/common.d.ts.map +1 -1
- package/dist/types/src/helpers/load.d.ts +1 -1
- package/dist/types/src/helpers/load.d.ts.map +1 -1
- package/dist/types/src/helpers/upload.d.ts +1 -1
- package/dist/types/src/helpers/upload.d.ts.map +1 -1
- package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +3 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +2 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/WnfsCapabilities.d.ts +11 -0
- package/dist/types/src/types/WnfsCapabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +86 -51
- package/src/WnfsPlugin.node.ts +11 -0
- package/src/WnfsPlugin.test.ts +20 -0
- package/src/WnfsPlugin.tsx +42 -84
- package/src/WnfsPlugin.workerd.ts +11 -0
- package/src/annotations.ts +16 -0
- package/src/blockstore.ts +1 -1
- package/src/capabilities/backend.ts +43 -0
- package/src/capabilities/blockstore.ts +14 -10
- package/src/capabilities/index.ts +12 -7
- package/src/capabilities/url-resolver.ts +44 -0
- package/src/helpers/load.ts +37 -18
- package/src/helpers/upload.ts +14 -2
- package/src/index.ts +3 -2
- package/src/meta.ts +26 -7
- package/src/plugin.ts +9 -0
- package/src/translations.ts +2 -11
- package/src/types/WnfsCapabilities.ts +18 -0
- package/src/types/index.ts +1 -2
- package/src/vite-env.d.ts +10 -0
- package/dist/lib/browser/FileContainer-LTKYOYSO.mjs +0 -105
- package/dist/lib/browser/FileContainer-LTKYOYSO.mjs.map +0 -7
- package/dist/lib/browser/blockstore-PSYZCC2O.mjs.map +0 -7
- package/dist/lib/browser/chunk-CW4BENRQ.mjs +0 -64
- package/dist/lib/browser/chunk-CW4BENRQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-KZANQHJY.mjs +0 -16
- package/dist/lib/browser/chunk-KZANQHJY.mjs.map +0 -7
- package/dist/lib/browser/chunk-VDDGZWAY.mjs +0 -15
- package/dist/lib/browser/chunk-VDDGZWAY.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZMH2OULB.mjs +0 -16
- package/dist/lib/browser/chunk-ZMH2OULB.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-YRZPRETS.mjs +0 -29
- package/dist/lib/browser/file-uploader-YRZPRETS.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -118
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-CKGJNE6P.mjs +0 -49
- package/dist/lib/browser/intent-resolver-CKGJNE6P.mjs.map +0 -7
- package/dist/lib/browser/markdown-RAGCVYGE.mjs +0 -198
- package/dist/lib/browser/markdown-RAGCVYGE.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-HGWZDLP2.mjs +0 -88
- package/dist/lib/browser/react-surface-HGWZDLP2.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -10
- package/dist/types/src/capabilities/capabilities.d.ts +0 -12
- package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/types/src/capabilities/file-uploader.d.ts +0 -4
- package/dist/types/src/capabilities/file-uploader.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/markdown.d.ts +0 -4
- package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/FileContainer.d.ts +0 -9
- package/dist/types/src/components/FileContainer.d.ts.map +0 -1
- package/dist/types/src/components/FileInput.d.ts +0 -8
- package/dist/types/src/components/FileInput.d.ts.map +0 -1
- package/dist/types/src/components/FilePreview.d.ts +0 -11
- package/dist/types/src/components/FilePreview.d.ts.map +0 -1
- package/dist/types/src/components/index.d.ts +0 -3
- package/dist/types/src/components/index.d.ts.map +0 -1
- package/dist/types/src/extensions/image.d.ts +0 -14
- package/dist/types/src/extensions/image.d.ts.map +0 -1
- package/dist/types/src/extensions/image.stories.d.ts +0 -10
- package/dist/types/src/extensions/image.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/index.d.ts +0 -2
- package/dist/types/src/extensions/index.d.ts.map +0 -1
- package/dist/types/src/types/file.d.ts +0 -16
- package/dist/types/src/types/file.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -51
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/src/capabilities/capabilities.ts +0 -18
- package/src/capabilities/file-uploader.ts +0 -24
- package/src/capabilities/intent-resolver.ts +0 -33
- package/src/capabilities/markdown.ts +0 -26
- package/src/capabilities/react-surface.tsx +0 -45
- package/src/components/FileContainer.tsx +0 -52
- package/src/components/FileInput.tsx +0 -47
- package/src/components/FilePreview.tsx +0 -23
- package/src/components/index.ts +0 -9
- package/src/extensions/image.stories.tsx +0 -101
- package/src/extensions/image.tsx +0 -203
- package/src/extensions/index.ts +0 -5
- package/src/types/file.ts +0 -17
- package/src/types/types.ts +0 -41
- /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
upload
|
|
3
|
+
} from "./chunk-L33MOD23.mjs";
|
|
4
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
5
|
+
|
|
6
|
+
// src/capabilities/backend.ts
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import { Capability } from "@dxos/app-framework";
|
|
9
|
+
import { invariant } from "@dxos/invariant";
|
|
10
|
+
import { ClientCapabilities } from "@dxos/plugin-client";
|
|
11
|
+
import { FileCapabilities } from "@dxos/plugin-file/types";
|
|
12
|
+
import { File } from "@dxos/types";
|
|
13
|
+
import { WnfsCapabilities } from "#types";
|
|
14
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/capabilities/backend.ts";
|
|
15
|
+
var WNFS_BACKEND_ID = "wnfs";
|
|
16
|
+
var backend_default = Capability.makeModule(Effect.fnUntraced(function* () {
|
|
17
|
+
const capabilities = yield* Capability.Service;
|
|
18
|
+
return Capability.contributes(FileCapabilities.Backend, {
|
|
19
|
+
id: WNFS_BACKEND_ID,
|
|
20
|
+
name: "WNFS",
|
|
21
|
+
description: "Decentralized, end-to-end encrypted storage via Web Native File System.",
|
|
22
|
+
upload: async (file, db) => {
|
|
23
|
+
const client = capabilities.get(ClientCapabilities.Client);
|
|
24
|
+
const blockstore = capabilities.get(WnfsCapabilities.Blockstore);
|
|
25
|
+
const instances = capabilities.get(WnfsCapabilities.Instances);
|
|
26
|
+
const space = client.spaces.get(db.spaceId);
|
|
27
|
+
invariant(space, "Space not found", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 24, S: this, A: ["space", "'Space not found'"] });
|
|
28
|
+
const info = await upload({
|
|
29
|
+
file,
|
|
30
|
+
blockstore,
|
|
31
|
+
instances,
|
|
32
|
+
space
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
name: info.name,
|
|
36
|
+
type: info.type,
|
|
37
|
+
size: file.size,
|
|
38
|
+
data: File.externalData(info.url, info.cid)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}));
|
|
43
|
+
export {
|
|
44
|
+
WNFS_BACKEND_ID,
|
|
45
|
+
backend_default as default
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=backend-4HPTHS33.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/capabilities/backend.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability } from '@dxos/app-framework';\nimport { invariant } from '@dxos/invariant';\nimport { ClientCapabilities } from '@dxos/plugin-client';\nimport { FileCapabilities } from '@dxos/plugin-file/types';\nimport { File } from '@dxos/types';\n\nimport { WnfsCapabilities } from '#types';\n\nimport { upload } from '../helpers';\n\nexport const WNFS_BACKEND_ID = 'wnfs';\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n const capabilities = yield* Capability.Service;\n\n return Capability.contributes(FileCapabilities.Backend, {\n id: WNFS_BACKEND_ID,\n name: 'WNFS',\n description: 'Decentralized, end-to-end encrypted storage via Web Native File System.',\n upload: async (file, db) => {\n const client = capabilities.get(ClientCapabilities.Client);\n const blockstore = capabilities.get(WnfsCapabilities.Blockstore);\n const instances = capabilities.get(WnfsCapabilities.Instances);\n const space = client.spaces.get(db.spaceId);\n invariant(space, 'Space not found');\n const info = await upload({ file, blockstore, instances, space });\n return {\n name: info.name,\n type: info.type,\n size: file.size,\n data: File.externalData(info.url, info.cid),\n };\n },\n });\n }),\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,0BAA0B;AACnC,SAASC,wBAAwB;AACjC,SAASC,YAAY;AAErB,SAASC,wBAAwB;AAIjC,IAAA,eAAaC;AAIT,IAAMC,kBAAe;IAErB,kBAAOC,WAAWC,WAAYC,kBAAiBC,aAAS;QACtDC,eAAIN,OAAAA,WAAAA;SACJO,WAAM,YAAA,iBAAA,SAAA;IACNC,IAAAA;IACAC,MAAAA;iBACQC;YACN,OAAMC,MAAAA,OAAaV;AACnB,YAAMW,SAAAA,aAAYX,IAAaY,mBAAIC,MAAiBC;AACpD,YAAMC,aAAQN,aAAkBO,IAAGC,iBAAO,UAAA;AAC1CC,YAAAA,YAAiB,aAAA,IAAA,iBAAA,SAAA;AACjB,YAAMC,QAAO,OAAMX,OAAO,IAAA,GAAA,OAAA;gBAAEY,OAAAA,mBAAAA,EAAAA,YAAAA,YAAAA,GAAAA,cAAAA,GAAAA,IAAAA,GAAAA,MAAAA,GAAAA,CAAAA,SAAAA,mBAAAA,EAAAA,CAAAA;YAAMV,OAAAA,MAAAA,OAAAA;QAAYC;QAAWI;QAAM;QAC/D;;aAEEM;QACAC,MAAMF,KAAKE;QACXC,MAAMC,KAAKC;QACb,MAAA,KAAA;QACF,MAAA,KAAA,aAAA,KAAA,KAAA,KAAA,GAAA;MACF;IAEF;;;",
|
|
6
|
+
"names": ["Effect", "Capability", "invariant", "ClientCapabilities", "FileCapabilities", "File", "WnfsCapabilities", "WNFS_BACKEND_ID", "capabilities", "Capability", "contributes", "FileCapabilities", "Backend", "id", "name", "description", "upload", "client", "blockstore", "instances", "get", "WnfsCapabilities", "Instances", "space", "db", "spaceId", "invariant", "info", "file", "type", "size", "data", "File", "externalData"]
|
|
7
|
+
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
storeName
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import
|
|
5
|
-
WnfsCapabilities
|
|
6
|
-
} from "./chunk-KZANQHJY.mjs";
|
|
7
|
-
import "./chunk-VDDGZWAY.mjs";
|
|
3
|
+
} from "./chunk-L33MOD23.mjs";
|
|
4
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
8
5
|
|
|
9
6
|
// src/capabilities/blockstore.ts
|
|
10
|
-
import
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import { Capability } from "@dxos/app-framework";
|
|
11
9
|
import { ClientCapabilities } from "@dxos/plugin-client";
|
|
10
|
+
import { WnfsCapabilities } from "#types";
|
|
12
11
|
|
|
13
12
|
// src/blockstore.ts
|
|
14
13
|
import { CarWriter } from "@ipld/car";
|
|
@@ -114,7 +113,7 @@ var MixedBlockstore = class extends BaseBlockstore {
|
|
|
114
113
|
}
|
|
115
114
|
}
|
|
116
115
|
// QUEUE
|
|
117
|
-
queueCacheName = `${storeName()}
|
|
116
|
+
queueCacheName = `${storeName()}.state.queue`;
|
|
118
117
|
async #addToQueue(key) {
|
|
119
118
|
await this.#saveQueue([
|
|
120
119
|
...this.#queue,
|
|
@@ -178,14 +177,14 @@ var MixedBlockstore = class extends BaseBlockstore {
|
|
|
178
177
|
};
|
|
179
178
|
|
|
180
179
|
// src/capabilities/blockstore.ts
|
|
181
|
-
var blockstore_default =
|
|
182
|
-
const client =
|
|
180
|
+
var blockstore_default = Capability.makeModule(Effect.fnUntraced(function* () {
|
|
181
|
+
const client = yield* Capability.get(ClientCapabilities.Client);
|
|
183
182
|
const apiHost = client.config.values.runtime?.services?.edge?.url || "http://localhost:8787";
|
|
184
183
|
const blockstore = create(apiHost);
|
|
185
|
-
|
|
186
|
-
return contributes(WnfsCapabilities.Blockstore, blockstore);
|
|
187
|
-
};
|
|
184
|
+
yield* Effect.tryPromise(() => blockstore.open());
|
|
185
|
+
return Capability.contributes(WnfsCapabilities.Blockstore, blockstore);
|
|
186
|
+
}));
|
|
188
187
|
export {
|
|
189
188
|
blockstore_default as default
|
|
190
189
|
};
|
|
191
|
-
//# sourceMappingURL=blockstore-
|
|
190
|
+
//# sourceMappingURL=blockstore-U6SPNL2C.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/capabilities/blockstore.ts", "../../../src/blockstore.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability } from '@dxos/app-framework';\nimport { ClientCapabilities } from '@dxos/plugin-client';\n\nimport { WnfsCapabilities } from '#types';\n\nimport * as Blockstore from '../blockstore';\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n const client = yield* Capability.get(ClientCapabilities.Client);\n const apiHost = client.config.values.runtime?.services?.edge?.url || 'http://localhost:8787';\n const blockstore = Blockstore.create(apiHost);\n yield* Effect.tryPromise(() => blockstore.open());\n\n return Capability.contributes(WnfsCapabilities.Blockstore, blockstore);\n }),\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CarWriter } from '@ipld/car';\nimport type { Block } from '@ipld/car/reader';\nimport { BaseBlockstore } from 'blockstore-core';\nimport { IDBBlockstore } from 'blockstore-idb';\nimport debounce from 'debounce';\nimport * as IDB from 'idb-keyval';\nimport all from 'it-all';\nimport { CID } from 'multiformats';\nimport * as Uint8Arrays from 'uint8arrays';\n\nimport { storeName } from './helpers';\n\nexport const create = (apiHost?: string) => {\n return new MixedBlockstore(apiHost);\n};\n\n/**\n * A blockstore that communicates with the DXOS blob service,\n * and which uses an indexedDB blockstore as a client cache.\n */\nexport class MixedBlockstore extends BaseBlockstore {\n readonly #apiHost: string | undefined;\n readonly #localStore: IDBBlockstore;\n\n #isConnected: boolean;\n #flushQueue: () => void;\n #queue: string[];\n\n constructor(apiHost?: string) {\n super();\n\n this.#apiHost = apiHost ? apiHost.replace(/\\/?$/, '') : undefined;\n this.#localStore = new IDBBlockstore(storeName());\n this.#isConnected = navigator.onLine;\n this.#queue = [];\n\n this.#flushQueue = debounce(this.#flushQueueInt, 5000);\n }\n\n async open(): Promise<void> {\n await this.#localStore.open();\n await this.#restoreQueue();\n\n window.addEventListener('offline', async () => {\n this.#isConnected = false;\n });\n\n window.addEventListener('online', async () => {\n this.#isConnected = true;\n this.#flushQueue();\n });\n }\n\n url(apiHost: string, cid?: CID): string {\n const path = cid ? cid.toString() : '';\n return `${apiHost}/api/file${path.length ? '/' + path : ''}`;\n }\n\n // BLOCKSTORE IMPLEMENTATION\n\n override async delete(key: CID): Promise<void> {\n await this.#localStore.delete(key);\n\n if (this.#isConnected && this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'DELETE',\n });\n }\n }\n\n override async get(key: CID): Promise<Uint8Array> {\n if (await this.#localStore.has(key)) {\n return await this.#localStore.get(key);\n }\n\n if (this.#isConnected && this.#apiHost) {\n const block = await fetch(this.url(this.#apiHost, key), {\n method: 'GET',\n })\n .then((r) => r.arrayBuffer())\n .then((r) => new Uint8Array(r));\n\n // Make sure it is cached locally\n await this.#localStore.put(key, block);\n\n return block;\n }\n\n return await this.#localStore.get(key);\n }\n\n override async has(key: CID): Promise<boolean> {\n if (await this.#localStore.has(key)) {\n return true;\n }\n\n if (this.#isConnected && this.#apiHost) {\n return await fetch(this.url(this.#apiHost, key), {\n method: 'HEAD',\n }).then((r) => r.ok);\n }\n\n return false;\n }\n\n override async put(key: CID, val: Uint8Array): Promise<CID> {\n await this.#localStore.put(key, val);\n\n await this.#addToQueue(key);\n this.#flushQueue();\n\n return key;\n }\n\n async destroy(): Promise<void> {\n await this.#localStore.destroy();\n }\n\n // REMOTE\n\n async putRemote(key: CID, val: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'POST',\n body: val as Uint8Array<ArrayBuffer>,\n });\n }\n }\n\n async putCarRemote(car: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost), {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/vnd.ipld.car',\n },\n body: car as Uint8Array<ArrayBuffer>,\n });\n }\n }\n\n // QUEUE\n\n readonly queueCacheName = `${storeName()}.state.queue`;\n\n async #addToQueue(key: CID): Promise<void> {\n await this.#saveQueue([...this.#queue, key.toString()]);\n }\n\n async #flushQueueInt(): Promise<void> {\n if (!this.#isConnected || !this.#apiHost) {\n return;\n }\n\n const keys = [...this.#queue];\n if (keys.length === 0) {\n return;\n }\n\n // Collect blocks\n const blocks = await Promise.all(\n keys.map(async (key) => {\n const cid = CID.parse(key);\n const bytes = await this.#localStore.get(cid);\n return { cid, bytes };\n }),\n );\n\n // Create & submit CAR\n const car = await this.#createCar(blocks);\n await this.putCarRemote(car);\n\n // Adjust queue\n const queue = [...this.#queue].filter((k) => {\n if (keys.includes(k)) {\n return false;\n }\n\n return true;\n });\n\n await this.#saveQueue(queue);\n }\n\n async #restoreQueue(): Promise<void> {\n const fromCache = await IDB.get(this.queueCacheName);\n if (fromCache && Array.isArray(fromCache)) {\n this.#queue = fromCache;\n this.#flushQueue();\n }\n }\n\n async #saveQueue(items: string[]): Promise<void> {\n const arr = [...items];\n this.#queue = arr;\n await IDB.set(this.queueCacheName, arr);\n }\n\n // 🛠️\n\n async #createCar(blocks: Block[]): Promise<Uint8Array> {\n const { writer, out } = CarWriter.create();\n const outPromise = all(out);\n\n await Promise.all(\n blocks.map((block) => {\n return writer.put(block);\n }),\n );\n\n await writer.close();\n return Uint8Arrays.concat(await outPromise);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,kBAAkB;AAC3B,SAASC,0BAA0B;AAEnC,SAASC,wBAAwB;;;ACLjC,SAASC,iBAAiB;AAE1B,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB;AAC9B,OAAOC,cAAc;AACrB,YAAYC,SAAS;AACrB,OAAOC,SAAS;AAChB,SAASC,WAAW;AACpB,YAAYC,iBAAiB;AAItB,IAAMC,SAAS,CAACC,YAAAA;AACrB,SAAO,IAAIC,gBAAgBD,OAAAA;AAC7B;AAMO,IAAMC,kBAAN,cAA8BC,eAAAA;EAC1B;EACA;EAET;EACA;EACA;EAEA,YAAYF,SAAkB;AAC5B,UAAK;AAEL,SAAK,WAAWA,UAAUA,QAAQG,QAAQ,QAAQ,EAAA,IAAMC;AACxD,SAAK,cAAc,IAAIC,cAAcC,UAAAA,CAAAA;AACrC,SAAK,eAAeC,UAAUC;AAC9B,SAAK,SAAS,CAAA;AAEd,SAAK,cAAcC,SAAS,KAAK,gBAAgB,GAAA;EACnD;EAEA,MAAMC,OAAsB;AAC1B,UAAM,KAAK,YAAYA,KAAI;AAC3B,UAAM,KAAK,cAAa;AAExBC,WAAOC,iBAAiB,WAAW,YAAA;AACjC,WAAK,eAAe;IACtB,CAAA;AAEAD,WAAOC,iBAAiB,UAAU,YAAA;AAChC,WAAK,eAAe;AACpB,WAAK,YAAW;IAClB,CAAA;EACF;EAEAC,IAAIb,SAAiBc,KAAmB;AACtC,UAAMC,OAAOD,MAAMA,IAAIE,SAAQ,IAAK;AACpC,WAAO,GAA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a,aAAaC,MAAMC,QAAQF,SAAAA,GAAY;AACzC,WAAK,SAASA;AACd,WAAK,YAAW;IAClB;EACF;EAEA,MAAM,WAAWG,OAAe;AAC9B,UAAMC,MAAM;SAAID;;AAChB,SAAK,SAASC;AACd,UAAUC,QAAI,KAAKlB,gBAAgBiB,GAAAA;EACrC;;EAIA,MAAM,WAAWf,QAAe;AAC9B,UAAM,EAAEiB,QAAQC,IAAG,IAAKC,UAAU5D,OAAM;AACxC,UAAM6D,aAAalB,IAAIgB,GAAAA;AAEvB,UAAMjB,QAAQC,IACZF,OAAOG,IAAI,CAACnB,UAAAA;AACV,aAAOiC,OAAO5B,IAAIL,KAAAA;IACpB,CAAA,CAAA;AAGF,UAAMiC,OAAOI,MAAK;AAClB,WAAmBC,mBAAO,MAAMF,UAAAA;EAClC;AACF;;;AD5MA,IAAA,qBAAeG,WAAWC,WACjBC,kBAAW,aAAA;AAChB,QAAMC,SAAS,OAAOH,WAAWI,IAAIC,mBAAmBC,MAAM;AAC9D,QAAMC,UAAUJ,OAAOK,OAAOC,OAAOC,SAASC,UAAUC,MAAMC,OAAO;AACrE,QAAMC,aAAwBC,OAAOR,OAAAA;AACrC,SAAcS,kBAAW,MAAMF,WAAWG,KAAI,CAAA;AAE9C,SAAOjB,WAAWkB,YAAYC,iBAAiBC,YAAYN,UAAAA;AAC7D,CAAA,CAAA;",
|
|
6
|
+
"names": ["Effect", "Capability", "ClientCapabilities", "WnfsCapabilities", "CarWriter", "BaseBlockstore", "IDBBlockstore", "debounce", "IDB", "all", "CID", "Uint8Arrays", "create", "apiHost", "MixedBlockstore", "BaseBlockstore", "replace", "undefined", "IDBBlockstore", "storeName", "navigator", "onLine", "debounce", "open", "window", "addEventListener", "url", "cid", "path", "toString", "length", "delete", "key", "fetch", "method", "get", "has", "block", "then", "r", "arrayBuffer", "Uint8Array", "put", "ok", "val", "destroy", "putRemote", "body", "putCarRemote", "car", "headers", "queueCacheName", "keys", "blocks", "Promise", "all", "map", "CID", "parse", "bytes", "queue", "filter", "k", "includes", "fromCache", "Array", "isArray", "items", "arr", "set", "writer", "out", "CarWriter", "outPromise", "close", "concat", "Capability", "makeModule", "fnUntraced", "client", "get", "ClientCapabilities", "Client", "apiHost", "config", "values", "runtime", "services", "edge", "url", "blockstore", "create", "tryPromise", "open", "contributes", "WnfsCapabilities", "Blockstore"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "../chunk-J5LGTIGS.mjs";
|
|
2
|
+
|
|
3
|
+
// src/capabilities/index.ts
|
|
4
|
+
import { Capability } from "@dxos/app-framework";
|
|
5
|
+
var Backend = Capability.lazy("Backend", () => import("../backend-4HPTHS33.mjs"));
|
|
6
|
+
var Blockstore = Capability.lazy("Blockstore", () => import("../blockstore-U6SPNL2C.mjs"));
|
|
7
|
+
var UrlResolver = Capability.lazy("UrlResolver", () => import("../url-resolver-BIRH7WHL.mjs"));
|
|
8
|
+
export {
|
|
9
|
+
Backend,
|
|
10
|
+
Blockstore,
|
|
11
|
+
UrlResolver
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/capabilities/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capability } from '@dxos/app-framework';\nimport { type FileCapabilities } from '@dxos/plugin-file/types';\n\nexport const Backend: Capability.LazyCapability<\n void,\n Capability.Capability<Capability.InterfaceDef<FileCapabilities.Backend>>\n> = Capability.lazy('Backend', () => import('./backend'));\n\nexport const Blockstore = Capability.lazy('Blockstore', () => import('./blockstore'));\n\nexport const UrlResolver: Capability.LazyCapability<\n void,\n Capability.Capability<Capability.InterfaceDef<FileCapabilities.UrlResolver>>\n> = Capability.lazy('UrlResolver', () => import('./url-resolver'));\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,kBAAkB;AAGpB,IAAMC,UAGTD,WAAWE,KAAK,WAAW,MAAM,OAAO,yBAAA,CAAA;AAErC,IAAMC,aAAaH,WAAWE,KAAK,cAAc,MAAM,OAAO,4BAAA,CAAA;AAE9D,IAAME,cAGTJ,WAAWE,KAAK,eAAe,MAAM,OAAO,8BAAA,CAAA;",
|
|
6
|
+
"names": ["Capability", "Backend", "lazy", "Blockstore", "UrlResolver"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/meta.ts
|
|
2
|
+
import { Plugin } from "@dxos/app-framework";
|
|
3
|
+
import { DXN } from "@dxos/keys";
|
|
4
|
+
import { meta as fileMeta } from "@dxos/plugin-file";
|
|
5
|
+
import { trim } from "@dxos/util";
|
|
6
|
+
var meta = Plugin.makeMeta({
|
|
7
|
+
key: DXN.make("org.dxos.plugin.wnfs"),
|
|
8
|
+
name: "WNFS",
|
|
9
|
+
author: "DXOS",
|
|
10
|
+
description: trim`
|
|
11
|
+
Decentralized, end-to-end encrypted file storage for DXOS Composer built on the Web Native File System (WNFS) protocol.
|
|
12
|
+
|
|
13
|
+
WNFS organizes files inside a cryptographic "dark forest" — a content-addressed private file system
|
|
14
|
+
where each write produces a new immutable root CID. Files are stored as IPLD blocks (CIDv1, sha2-256),
|
|
15
|
+
cached locally in IndexedDB, and asynchronously replicated to the DXOS edge blob service as CAR archives.
|
|
16
|
+
Uploads and reads are scoped to a DXOS Space; the forest root CID is persisted atomically on the
|
|
17
|
+
space's ECHO properties so the file system state survives across sessions and devices.
|
|
18
|
+
|
|
19
|
+
The plugin registers as a \`FileCapabilities.Backend\` and \`FileCapabilities.UrlResolver\` so any plugin
|
|
20
|
+
that uses \`plugin-file\` (e.g. \`plugin-gallery\`) can upload files and resolve \`wnfs://\` URLs without
|
|
21
|
+
coupling to the storage implementation. The blockstore automatically queues blocks while offline and
|
|
22
|
+
flushes them when connectivity is restored.
|
|
23
|
+
`,
|
|
24
|
+
icon: "ph--file-cloud--regular",
|
|
25
|
+
iconHue: "teal",
|
|
26
|
+
source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs",
|
|
27
|
+
spec: "PLUGIN.mdl",
|
|
28
|
+
tags: [
|
|
29
|
+
"labs"
|
|
30
|
+
],
|
|
31
|
+
dependsOn: [
|
|
32
|
+
fileMeta.id
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
meta
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-KUQHRT52.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/meta.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { DXN } from '@dxos/keys';\nimport { meta as fileMeta } from '@dxos/plugin-file';\nimport { trim } from '@dxos/util';\n\nexport const meta = Plugin.makeMeta({\n key: DXN.make('org.dxos.plugin.wnfs'),\n name: 'WNFS',\n author: 'DXOS',\n description: trim`\n Decentralized, end-to-end encrypted file storage for DXOS Composer built on the Web Native File System (WNFS) protocol.\n\n WNFS organizes files inside a cryptographic \"dark forest\" — a content-addressed private file system\n where each write produces a new immutable root CID. Files are stored as IPLD blocks (CIDv1, sha2-256),\n cached locally in IndexedDB, and asynchronously replicated to the DXOS edge blob service as CAR archives.\n Uploads and reads are scoped to a DXOS Space; the forest root CID is persisted atomically on the\n space's ECHO properties so the file system state survives across sessions and devices.\n\n The plugin registers as a \\`FileCapabilities.Backend\\` and \\`FileCapabilities.UrlResolver\\` so any plugin\n that uses \\`plugin-file\\` (e.g. \\`plugin-gallery\\`) can upload files and resolve \\`wnfs://\\` URLs without\n coupling to the storage implementation. The blockstore automatically queues blocks while offline and\n flushes them when connectivity is restored.\n `,\n icon: 'ph--file-cloud--regular',\n iconHue: 'teal',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n spec: 'PLUGIN.mdl',\n tags: ['labs'],\n dependsOn: [fileMeta.id],\n});\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,cAAc;AACvB,SAASC,WAAW;AACpB,SAASC,QAAQC,gBAAgB;AACjC,SAASC,YAAY;AAEd,IAAMF,OAAOF,OAAOK,SAAS;EAClCC,KAAKL,IAAIM,KAAK,sBAAA;EACdC,MAAM;EACNC,QAAQ;EACRC,aAAaN;;;;;;;;;;;;;;EAcbO,MAAM;EACNC,SAAS;EACTC,QAAQ;EACRC,MAAM;EACNC,MAAM;IAAC;;EACPC,WAAW;IAACb,SAASc;;AACvB,CAAA;",
|
|
6
|
+
"names": ["Plugin", "DXN", "meta", "fileMeta", "trim", "makeMeta", "key", "make", "name", "author", "description", "icon", "iconHue", "source", "spec", "tags", "dependsOn", "id"]
|
|
7
|
+
}
|
|
@@ -42,24 +42,69 @@ var store = (blockstore) => {
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
var storeName = () => "dxos/wnfs";
|
|
45
|
+
var readFile = (file) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const reader = new FileReader();
|
|
48
|
+
reader.onload = (event) => {
|
|
49
|
+
const result = event.target?.result;
|
|
50
|
+
if (result === null || result === void 0 || typeof result === "string") {
|
|
51
|
+
reject(new Error("Expected an ArrayBuffer"));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
resolve(new Uint8Array(result));
|
|
55
|
+
};
|
|
56
|
+
reader.onerror = (err) => {
|
|
57
|
+
reject(err);
|
|
58
|
+
};
|
|
59
|
+
reader.readAsArrayBuffer(file);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
45
62
|
|
|
46
63
|
// src/helpers/load.ts
|
|
64
|
+
import * as Option from "effect/Option";
|
|
47
65
|
import { CID as CID2 } from "multiformats";
|
|
48
66
|
import * as Uint8Arrays from "uint8arrays";
|
|
49
67
|
import { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from "wnfs";
|
|
68
|
+
import { Annotation as Annotation2, Obj } from "@dxos/echo";
|
|
69
|
+
|
|
70
|
+
// src/annotations.ts
|
|
71
|
+
import * as Schema from "effect/Schema";
|
|
72
|
+
import { Annotation } from "@dxos/echo";
|
|
73
|
+
var WnfsStateAnnotation = Annotation.make({
|
|
74
|
+
id: "org.dxos.plugin.wnfs.state",
|
|
75
|
+
schema: Schema.Struct({
|
|
76
|
+
accessKey: Schema.String,
|
|
77
|
+
privateForestCid: Schema.String
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// src/helpers/load.ts
|
|
50
82
|
var loadWnfs = async ({ space, blockstore, instances }) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
83
|
+
const propsAny = space.properties;
|
|
84
|
+
if (propsAny.wnfs_access_key !== void 0 && propsAny.wnfs_private_forest_cid !== void 0) {
|
|
85
|
+
Obj.update(space.properties, (obj) => {
|
|
86
|
+
delete obj["wnfs_access_key"];
|
|
87
|
+
delete obj["wnfs_private_forest_cid"];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (propsAny.wnfs !== void 0 && Option.isNone(Annotation2.get(space.properties, WnfsStateAnnotation))) {
|
|
91
|
+
Obj.update(space.properties, (properties) => {
|
|
92
|
+
Annotation2.set(properties, WnfsStateAnnotation, propsAny.wnfs);
|
|
93
|
+
delete properties["wnfs"];
|
|
94
|
+
});
|
|
54
95
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
96
|
+
const wnfsState = Annotation2.get(space.properties, WnfsStateAnnotation).pipe(Option.getOrUndefined);
|
|
97
|
+
const cacheKey = wnfsState?.privateForestCid;
|
|
98
|
+
if (cacheKey && instances?.[cacheKey]) {
|
|
57
99
|
return instances[cacheKey];
|
|
58
100
|
}
|
|
59
|
-
const exists = !!
|
|
101
|
+
const exists = !!wnfsState;
|
|
60
102
|
const instance = exists ? await loadWnfsDir(blockstore, space) : await createWnfsDir(blockstore, space);
|
|
61
103
|
if (instances) {
|
|
62
|
-
|
|
104
|
+
const newCacheKey = Annotation2.get(space.properties, WnfsStateAnnotation).pipe(Option.getOrUndefined)?.privateForestCid;
|
|
105
|
+
if (newCacheKey) {
|
|
106
|
+
instances[newCacheKey] = instance;
|
|
107
|
+
}
|
|
63
108
|
}
|
|
64
109
|
return instance;
|
|
65
110
|
};
|
|
@@ -71,10 +116,12 @@ var createWnfsDir = async (blockstore, space) => {
|
|
|
71
116
|
const dir = dirResult.rootDir;
|
|
72
117
|
const [accessKeyRaw, newForest] = await dir.asNode().store(dirResult.forest, wnfsStore, rng);
|
|
73
118
|
const cidBytes = await newForest.store(wnfsStore);
|
|
74
|
-
space.properties
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
119
|
+
Obj.update(space.properties, (properties) => {
|
|
120
|
+
Annotation2.set(properties, WnfsStateAnnotation, {
|
|
121
|
+
accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), "base64"),
|
|
122
|
+
privateForestCid: CID2.decode(cidBytes).toString()
|
|
123
|
+
});
|
|
124
|
+
});
|
|
78
125
|
return {
|
|
79
126
|
directory: dir,
|
|
80
127
|
forest: newForest
|
|
@@ -82,8 +129,9 @@ var createWnfsDir = async (blockstore, space) => {
|
|
|
82
129
|
};
|
|
83
130
|
var loadWnfsDir = async (blockstore, space) => {
|
|
84
131
|
const wnfsStore = store(blockstore);
|
|
85
|
-
const
|
|
86
|
-
const
|
|
132
|
+
const wnfsState = Annotation2.get(space.properties, WnfsStateAnnotation).pipe(Option.getOrUndefined);
|
|
133
|
+
const accessKey = AccessKey.fromBytes(Uint8Arrays.fromString(wnfsState.accessKey, "base64"));
|
|
134
|
+
const forest = await PrivateForest.load(CID2.parse(wnfsState.privateForestCid).bytes, wnfsStore);
|
|
87
135
|
const node = await PrivateNode.load(accessKey, forest, wnfsStore);
|
|
88
136
|
return {
|
|
89
137
|
directory: node.asDir(),
|
|
@@ -91,6 +139,14 @@ var loadWnfsDir = async (blockstore, space) => {
|
|
|
91
139
|
};
|
|
92
140
|
};
|
|
93
141
|
|
|
142
|
+
// src/helpers/upload.ts
|
|
143
|
+
import * as Option2 from "effect/Option";
|
|
144
|
+
import { CID as CID3 } from "multiformats";
|
|
145
|
+
import * as Raw from "multiformats/codecs/raw";
|
|
146
|
+
import { sha256 as sha2562 } from "multiformats/hashes/sha2";
|
|
147
|
+
import { Annotation as Annotation3, Obj as Obj2 } from "@dxos/echo";
|
|
148
|
+
import { log } from "@dxos/log";
|
|
149
|
+
|
|
94
150
|
// src/helpers/wnfs-url.ts
|
|
95
151
|
var wnfsUrl = (filePath2) => {
|
|
96
152
|
return "wnfs://" + filePath2.map((f) => encodeURIComponent(f)).join("/");
|
|
@@ -109,10 +165,6 @@ var getBlobUrl = async ({ wnfsUrl: wnfsUrl2, blockstore, forest, directory, type
|
|
|
109
165
|
};
|
|
110
166
|
|
|
111
167
|
// src/helpers/upload.ts
|
|
112
|
-
import { CID as CID3 } from "multiformats";
|
|
113
|
-
import * as Raw from "multiformats/codecs/raw";
|
|
114
|
-
import { sha256 as sha2562 } from "multiformats/hashes/sha2";
|
|
115
|
-
import { log } from "@dxos/log";
|
|
116
168
|
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/helpers/upload.ts";
|
|
117
169
|
var upload = async ({ file, blockstore, instances, space }) => {
|
|
118
170
|
const { directory, forest } = await loadWnfs({
|
|
@@ -128,7 +180,16 @@ var upload = async ({ file, blockstore, instances, space }) => {
|
|
|
128
180
|
const result = await directory.write(path, true, bytes, /* @__PURE__ */ new Date(), forest, wnfsStore, new Rng());
|
|
129
181
|
const [_, updatedForest] = await result.rootDir.store(result.forest, wnfsStore, new Rng());
|
|
130
182
|
const cidBytes = await updatedForest.store(wnfsStore);
|
|
131
|
-
|
|
183
|
+
const currentState = Annotation3.get(space.properties, WnfsStateAnnotation).pipe(Option2.getOrUndefined);
|
|
184
|
+
if (!currentState) {
|
|
185
|
+
throw new Error("WnfsStateAnnotation missing after loadWnfs; cannot persist forest CID.");
|
|
186
|
+
}
|
|
187
|
+
Obj2.update(space.properties, (properties) => {
|
|
188
|
+
Annotation3.set(properties, WnfsStateAnnotation, {
|
|
189
|
+
...currentState,
|
|
190
|
+
privateForestCid: CID3.decode(cidBytes).toString()
|
|
191
|
+
});
|
|
192
|
+
});
|
|
132
193
|
const info = {
|
|
133
194
|
name: file.name,
|
|
134
195
|
type: file.type,
|
|
@@ -138,22 +199,21 @@ var upload = async ({ file, blockstore, instances, space }) => {
|
|
|
138
199
|
log("upload", {
|
|
139
200
|
file,
|
|
140
201
|
info
|
|
141
|
-
}, {
|
|
142
|
-
F: __dxlog_file,
|
|
143
|
-
L: 59,
|
|
144
|
-
S: void 0,
|
|
145
|
-
C: (f, a) => f(...a)
|
|
146
|
-
});
|
|
202
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 50, S: void 0 });
|
|
147
203
|
return info;
|
|
148
204
|
};
|
|
149
205
|
|
|
150
206
|
export {
|
|
207
|
+
WnfsStateAnnotation,
|
|
151
208
|
filePath,
|
|
209
|
+
Rng,
|
|
210
|
+
store,
|
|
152
211
|
storeName,
|
|
212
|
+
readFile,
|
|
153
213
|
loadWnfs,
|
|
154
214
|
wnfsUrl,
|
|
155
215
|
getPathFromUrl,
|
|
156
216
|
getBlobUrl,
|
|
157
217
|
upload
|
|
158
218
|
};
|
|
159
|
-
//# sourceMappingURL=chunk-
|
|
219
|
+
//# sourceMappingURL=chunk-L33MOD23.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/common.ts", "../../../src/helpers/load.ts", "../../../src/annotations.ts", "../../../src/helpers/upload.ts", "../../../src/helpers/wnfs-url.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats/cid';\nimport { sha256 } from 'multiformats/hashes/sha2';\nimport { type BlockStore as WnfsBlockStore } from 'wnfs';\n\nimport * as crypto from '@dxos/crypto';\nimport { type Space } from '@dxos/react-client/echo';\n\n//\n// PATH\n//\n\nexport const filePath = (fileName: string, space: Space) => {\n return ['spaces', space.id, 'files', fileName];\n};\n\n//\n// RNG\n//\n\nexport class Rng {\n randomBytes(count: number): Uint8Array {\n return new Uint8Array(crypto.randomBytes(count));\n }\n}\n\n//\n// STORE\n//\n\nexport const store = (blockstore: Blockstore): WnfsBlockStore => {\n const getBlock = async (cid: Uint8Array): Promise<Uint8Array | undefined> => {\n const decodedCid = CID.decode(cid);\n return await blockstore.get(decodedCid);\n };\n\n const hasBlock = async (cid: Uint8Array): Promise<boolean> => {\n const decodedCid = CID.decode(cid);\n return await blockstore.has(decodedCid);\n };\n\n const putBlockKeyed = async (cid: Uint8Array, bytes: Uint8Array): Promise<void> => {\n const decodedCid = CID.decode(cid);\n await blockstore.put(decodedCid, bytes);\n };\n\n // Don't hash blocks with the rs-wnfs default Blake 3, sha256 has better support.\n const putBlock = async (bytes: Uint8Array, codec: number): Promise<Uint8Array> => {\n const hash = await sha256.digest(bytes);\n const cid = CID.create(1, codec, hash);\n await blockstore.put(cid, bytes);\n return cid.bytes;\n };\n\n return { getBlock, hasBlock, putBlockKeyed, putBlock };\n};\n\nexport const storeName = () => 'dxos/wnfs';\n\n//\n// OTHER\n//\n\nexport const readFile = (file: File): Promise<Uint8Array> => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = (event) => {\n const result = event.target?.result;\n if (result === null || result === undefined || typeof result === 'string') {\n reject(new Error('Expected an ArrayBuffer'));\n return;\n }\n resolve(new Uint8Array(result));\n };\n reader.onerror = (err) => {\n reject(err);\n };\n reader.readAsArrayBuffer(file);\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats';\nimport * as Uint8Arrays from 'uint8arrays';\nimport { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from 'wnfs';\n\nimport { Annotation, Obj } from '@dxos/echo';\nimport { type Space } from '@dxos/react-client/echo';\n\nimport { type WnfsCapabilities } from '#types';\n\nimport { WnfsStateAnnotation } from '../annotations';\nimport { Rng, store } from './common';\n\n//\n// LOAD\n//\n\nexport const loadWnfs = async ({\n space,\n blockstore,\n instances,\n}: {\n space: Space;\n blockstore: Blockstore;\n instances?: WnfsCapabilities.Instances;\n}) => {\n // TODO(wittjosiah): Remove.\n // Delete old properties if they exist (pre-DX-971 migration cleanup).\n const propsAny = space.properties as any;\n if (propsAny.wnfs_access_key !== undefined && propsAny.wnfs_private_forest_cid !== undefined) {\n Obj.update(space.properties, (obj) => {\n delete (obj as any)['wnfs_access_key'];\n delete (obj as any)['wnfs_private_forest_cid'];\n });\n }\n // Migrate legacy wnfs data key to annotation.\n if (propsAny.wnfs !== undefined && Option.isNone(Annotation.get(space.properties, WnfsStateAnnotation))) {\n Obj.update(space.properties, (properties) => {\n Annotation.set(properties, WnfsStateAnnotation, propsAny.wnfs);\n delete (properties as any)['wnfs'];\n });\n }\n\n const wnfsState = Annotation.get(space.properties, WnfsStateAnnotation).pipe(Option.getOrUndefined);\n const cacheKey = wnfsState?.privateForestCid as any;\n if (cacheKey && instances?.[cacheKey]) {\n return instances[cacheKey];\n }\n\n const exists = !!wnfsState;\n const instance = exists ? await loadWnfsDir(blockstore, space) : await createWnfsDir(blockstore, space);\n if (instances) {\n // Re-read after createWnfsDir so newly created instances are cached under the real CID.\n const newCacheKey = Annotation.get(space.properties, WnfsStateAnnotation).pipe(Option.getOrUndefined)\n ?.privateForestCid as any;\n if (newCacheKey) {\n instances[newCacheKey] = instance;\n }\n }\n\n return instance;\n};\n\n//\n// PRIVATE\n//\n\nconst createWnfsDir = async (blockstore: Blockstore, space: Space) => {\n const wnfsStore = store(blockstore);\n const rng = new Rng();\n const forest = new PrivateForest(rng);\n\n const dirResult = await PrivateDirectory.newAndStore(forest.emptyName(), new Date(), forest, wnfsStore, rng);\n const dir = dirResult.rootDir as PrivateDirectory;\n\n const [accessKeyRaw, newForest]: [AccessKey, PrivateForest] = await dir\n .asNode()\n .store(dirResult.forest as PrivateForest, wnfsStore, rng);\n\n const cidBytes = await newForest.store(wnfsStore);\n\n Obj.update(space.properties, (properties) => {\n Annotation.set(properties, WnfsStateAnnotation, {\n accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),\n privateForestCid: CID.decode(cidBytes).toString(),\n });\n });\n\n return {\n directory: dir,\n forest: newForest,\n };\n};\n\nconst loadWnfsDir = async (blockstore: Blockstore, space: Space) => {\n const wnfsStore = store(blockstore);\n\n const wnfsState = Annotation.get(space.properties, WnfsStateAnnotation).pipe(Option.getOrUndefined)!;\n const accessKey = AccessKey.fromBytes(Uint8Arrays.fromString(wnfsState.accessKey, 'base64'));\n const forest: PrivateForest = await PrivateForest.load(CID.parse(wnfsState.privateForestCid).bytes, wnfsStore);\n const node: PrivateNode = await PrivateNode.load(accessKey, forest, wnfsStore);\n\n return {\n directory: node.asDir(),\n forest,\n };\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation } from '@dxos/echo';\n\n/** WNFS filesystem state stored on space properties meta. */\nexport const WnfsStateAnnotation = Annotation.make({\n id: 'org.dxos.plugin.wnfs.state',\n schema: Schema.Struct({\n accessKey: Schema.String,\n privateForestCid: Schema.String,\n }),\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats';\nimport * as Raw from 'multiformats/codecs/raw';\nimport { sha256 } from 'multiformats/hashes/sha2';\n\nimport type { Space } from '@dxos/client/echo';\nimport { Annotation, Obj } from '@dxos/echo';\nimport { log } from '@dxos/log';\n\nimport { type WnfsCapabilities } from '#types';\n\nimport { WnfsStateAnnotation } from '../annotations';\nimport { Rng, filePath, store } from './common';\nimport { loadWnfs } from './load';\nimport { wnfsUrl } from './wnfs-url';\n\nexport const upload = async ({\n file,\n blockstore,\n instances,\n space,\n}: {\n file: File;\n blockstore: Blockstore;\n instances?: WnfsCapabilities.Instances;\n space: Space;\n}) => {\n const { directory, forest } = await loadWnfs({ blockstore, instances, space });\n const wnfsStore = store(blockstore);\n\n const bytes = new Uint8Array(await file.arrayBuffer());\n const hash = await sha256.digest(bytes);\n const cid = CID.create(1, Raw.code, hash);\n\n const path = filePath(cid.toString(), space);\n\n // Given the root directory of the private file system,\n // write the file contents to `path` in said directory.\n const result = await directory.write(path, true, bytes, new Date(), forest, wnfsStore, new Rng());\n\n // Given the new immutable instance of the root directory after writing to it,\n // **store** the changes in the \"dark forest\" and the associated (block) store.\n const [_, updatedForest] = await result.rootDir.store(result.forest, wnfsStore, new Rng());\n const cidBytes = await updatedForest.store(wnfsStore);\n\n // Update the forest pointer on the associated space.\n const currentState = Annotation.get(space.properties, WnfsStateAnnotation).pipe(Option.getOrUndefined);\n if (!currentState) {\n throw new Error('WnfsStateAnnotation missing after loadWnfs; cannot persist forest CID.');\n }\n Obj.update(space.properties, (properties) => {\n Annotation.set(properties, WnfsStateAnnotation, {\n ...currentState,\n privateForestCid: CID.decode(cidBytes).toString(),\n });\n });\n\n // Generate `wnfs://` URL & return the info.\n const info = {\n name: file.name,\n type: file.type,\n url: wnfsUrl(path),\n cid: cid.toString(),\n };\n\n log('upload', { file, info });\n return info;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { type PrivateDirectory, type PrivateForest } from 'wnfs';\n\nimport { store } from './common';\n\nexport const wnfsUrl = (filePath: string[]) => {\n return 'wnfs://' + filePath.map((f) => encodeURIComponent(f)).join('/');\n};\n\nexport const getPathFromUrl = (wnfsUrl: string) =>\n wnfsUrl\n .replace(/^wnfs:\\/\\//, '')\n .split('/')\n .map((p) => decodeURIComponent(p));\n\nexport const getBlobUrl = async ({\n wnfsUrl,\n blockstore,\n forest,\n directory,\n type,\n}: {\n wnfsUrl: string;\n blockstore: Blockstore;\n forest: PrivateForest;\n directory: PrivateDirectory;\n type?: string;\n}) => {\n const path = getPathFromUrl(wnfsUrl);\n const wnfsStore = store(blockstore);\n const { result } = await directory.read(path, true, forest, wnfsStore);\n const blob = new Blob([result], { type });\n return URL.createObjectURL(blob);\n};\n"],
|
|
5
|
+
"mappings": ";AAKA,SAASA,WAAW;AACpB,SAASC,cAAc;AAGvB,YAAYC,YAAY;AAOjB,IAAMC,WAAW,CAACC,UAAkBC,UAAAA;AACzC,SAAO;IAAC;IAAUA,MAAMC;IAAI;IAASF;;AACvC;AAMO,IAAMG,MAAN,MAAMA;EACXC,YAAYC,OAA2B;AACrC,WAAO,IAAIC,WAAkBF,mBAAYC,KAAAA,CAAAA;EAC3C;AACF;AAMO,IAAME,QAAQ,CAACC,eAAAA;AACpB,QAAMC,WAAW,OAAOC,QAAAA;AACtB,UAAMC,aAAaf,IAAIgB,OAAOF,GAAAA;AAC9B,WAAO,MAAMF,WAAWK,IAAIF,UAAAA;EAC9B;AAEA,QAAMG,WAAW,OAAOJ,QAAAA;AACtB,UAAMC,aAAaf,IAAIgB,OAAOF,GAAAA;AAC9B,WAAO,MAAMF,WAAWO,IAAIJ,UAAAA;EAC9B;AAEA,QAAMK,gBAAgB,OAAON,KAAiBO,UAAAA;AAC5C,UAAMN,aAAaf,IAAIgB,OAAOF,GAAAA;AAC9B,UAAMF,WAAWU,IAAIP,YAAYM,KAAAA;EACnC;AAGA,QAAME,WAAW,OAAOF,OAAmBG,UAAAA;AACzC,UAAMC,OAAO,MAAMxB,OAAOyB,OAAOL,KAAAA;AACjC,UAAMP,MAAMd,IAAI2B,OAAO,GAAGH,OAAOC,IAAAA;AACjC,UAAMb,WAAWU,IAAIR,KAAKO,KAAAA;AAC1B,WAAOP,IAAIO;EACb;AAEA,SAAO;IAAER;IAAUK;IAAUE;IAAeG;EAAS;AACvD;AAEO,IAAMK,YAAY,MAAM;AAMxB,I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int8Array", "store", "blockstore", "getBlock", "cid", "decodedCid", "decode", "get", "hasBlock", "has", "putBlockKeyed", "bytes", "put", "putBlock", "codec", "hash", "digest", "create", "storeName", "readFile", "file", "Promise", "resolve", "reject", "reader", "FileReader", "onload", "event", "result", "target", "undefined", "Error", "onerror", "err", "readAsArrayBuffer", "Option", "CID", "Uint8Arrays", "AccessKey", "PrivateDirectory", "PrivateForest", "PrivateNode", "Annotation", "Obj", "Schema", "Annotation", "WnfsStateAnnotation", "make", "id", "schema", "Struct", "accessKey", "String", "privateForestCid", "loadWnfs", "space", "blockstore", "instances", "propsAny", "properties", "wnfs_access_key", "undefined", "wnfs_private_forest_cid", "Obj", "update", "obj", "wnfs", "isNone", "Annotation", "get", "WnfsStateAnnotation", "set", "wnfsState", "pipe", "getOrUndefined", "cacheKey", "privateForestCid", "exists", "instance", "loadWnfsDir", "createWnfsDir", "newCacheKey", "wnfsStore", "store", "rng", "Rng", "forest", "PrivateForest", "dirResult", "PrivateDirectory", "newAndStore", "emptyName", "Date", "dir", "rootDir", "accessKeyRaw", "newForest", "asNode", "cidBytes", "accessKey", "toString", "toBytes", "CID", "decode", "directory", "AccessKey", "fromBytes", "fromString", "load", "parse", "bytes", "node", "PrivateNode", "asDir", "Option", "CID", "Raw", "sha256", "Annotation", "Obj", "log", "wnfsUrl", "filePath", "map", "f", "encodeURIComponent", "join", "getPathFromUrl", "replace", "split", "p", "decodeURIComponent", "getBlobUrl", "blockstore", "forest", "directory", "type", "path", "wnfsStore", "store", "result", "read", "blob", "Blob", "URL", "createObjectURL", "upload", "blockstore", "instances", "space", "hash", "sha256", "bytes", "cid", "CID", "create", "Raw", "path", "filePath", "toString", "currentState", "Annotation", "properties", "update", "privateForestCid", "decode", "type", "file", "url", "wnfsUrl", "info"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
4
|
+
|
|
5
|
+
// src/types/WnfsCapabilities.ts
|
|
6
|
+
var WnfsCapabilities_exports = {};
|
|
7
|
+
__export(WnfsCapabilities_exports, {
|
|
8
|
+
Blockstore: () => Blockstore,
|
|
9
|
+
Instances: () => Instances
|
|
10
|
+
});
|
|
11
|
+
import { Capability } from "@dxos/app-framework";
|
|
12
|
+
import { meta } from "#meta";
|
|
13
|
+
var Blockstore = Capability.make(`${meta.id}.capability.blockstore`);
|
|
14
|
+
var Instances = Capability.make(`${meta.id}.capability.instances`);
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
WnfsCapabilities_exports
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-QODCKFTY.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/WnfsCapabilities.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { type Blockstore as BlockstoreInterface } from 'interface-blockstore';\nimport { type PrivateDirectory, type PrivateForest } from 'wnfs';\n\nimport { Capability } from '@dxos/app-framework';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { meta } from '#meta';\n\nexport const Blockstore = Capability.make<BlockstoreInterface>(`${meta.id}.capability.blockstore`);\n\nexport type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;\nexport const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA;;;;;AASA,SAASA,kBAAkB;AAG3B,SAASC,YAAY;AAEd,IAAMC,aAAaF,WAAWG,KAA0B,GAAGF,KAAKG,EAAE,wBAAwB;AAG1F,IAAMC,YAAYL,WAAWG,KAAgB,GAAGF,KAAKG,EAAE,uBAAuB;",
|
|
6
|
+
"names": ["Capability", "meta", "Blockstore", "make", "id", "Instances"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Rng,
|
|
3
|
+
filePath,
|
|
4
|
+
getBlobUrl,
|
|
5
|
+
getPathFromUrl,
|
|
6
|
+
loadWnfs,
|
|
7
|
+
readFile,
|
|
8
|
+
store,
|
|
9
|
+
storeName,
|
|
10
|
+
upload,
|
|
11
|
+
wnfsUrl
|
|
12
|
+
} from "../chunk-L33MOD23.mjs";
|
|
13
|
+
import "../chunk-J5LGTIGS.mjs";
|
|
14
|
+
export {
|
|
15
|
+
Rng,
|
|
16
|
+
filePath,
|
|
17
|
+
getBlobUrl,
|
|
18
|
+
getPathFromUrl,
|
|
19
|
+
loadWnfs,
|
|
20
|
+
readFile,
|
|
21
|
+
store,
|
|
22
|
+
storeName,
|
|
23
|
+
upload,
|
|
24
|
+
wnfsUrl
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WnfsCapabilities_exports
|
|
3
|
+
} from "./chunk-QODCKFTY.mjs";
|
|
4
|
+
import {
|
|
5
|
+
Rng,
|
|
6
|
+
WnfsStateAnnotation,
|
|
7
|
+
filePath,
|
|
8
|
+
getBlobUrl,
|
|
9
|
+
getPathFromUrl,
|
|
10
|
+
loadWnfs,
|
|
11
|
+
readFile,
|
|
12
|
+
store,
|
|
13
|
+
storeName,
|
|
14
|
+
upload,
|
|
15
|
+
wnfsUrl
|
|
16
|
+
} from "./chunk-L33MOD23.mjs";
|
|
17
|
+
import {
|
|
18
|
+
meta
|
|
19
|
+
} from "./chunk-KUQHRT52.mjs";
|
|
20
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
21
|
+
export {
|
|
22
|
+
Rng,
|
|
23
|
+
WnfsCapabilities_exports as WnfsCapabilities,
|
|
24
|
+
WnfsStateAnnotation,
|
|
25
|
+
filePath,
|
|
26
|
+
getBlobUrl,
|
|
27
|
+
getPathFromUrl,
|
|
28
|
+
loadWnfs,
|
|
29
|
+
meta,
|
|
30
|
+
readFile,
|
|
31
|
+
store,
|
|
32
|
+
storeName,
|
|
33
|
+
upload,
|
|
34
|
+
wnfsUrl
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.mjs.map
|