@dxos/plugin-wnfs 0.11.0 → 0.12.0-next-bbabc02363f18d7643ea4160e3a7a7809870fd0d

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 (70) hide show
  1. package/dist/lib/WnfsCapabilities.mjs +23 -0
  2. package/dist/lib/WnfsCapabilities.mjs.map +1 -0
  3. package/dist/lib/WnfsEvents.mjs +15 -0
  4. package/dist/lib/WnfsEvents.mjs.map +1 -0
  5. package/dist/lib/WnfsPlugin.mjs +4 -15
  6. package/dist/lib/WnfsPlugin.mjs.map +1 -1
  7. package/dist/lib/WnfsPlugin.node.mjs +1 -1
  8. package/dist/lib/WnfsPlugin.node.mjs.map +1 -1
  9. package/dist/lib/WnfsPlugin.workerd.mjs +1 -1
  10. package/dist/lib/WnfsPlugin.workerd.mjs.map +1 -1
  11. package/dist/lib/capabilities.mjs +19 -3
  12. package/dist/lib/capabilities.mjs.map +1 -1
  13. package/dist/lib/chunk-blob-backend.mjs +16 -15
  14. package/dist/lib/chunk-blob-backend.mjs.map +1 -1
  15. package/dist/lib/chunk-dependencies.mjs +7 -5
  16. package/dist/lib/chunk-dependencies.mjs.map +1 -1
  17. package/dist/lib/chunk-helpers.mjs +1 -1
  18. package/dist/lib/chunk-helpers.mjs.map +1 -1
  19. package/dist/lib/chunk-meta.mjs +1 -1
  20. package/dist/lib/chunk-meta.mjs.map +1 -1
  21. package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
  22. package/dist/lib/index.mjs +2 -1
  23. package/dist/lib/plugin.mjs +1 -1
  24. package/dist/lib/plugin.mjs.map +1 -1
  25. package/dist/types/src/WnfsPlugin.d.ts +1 -1
  26. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  27. package/dist/types/src/WnfsPlugin.node.d.ts +1 -1
  28. package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -1
  29. package/dist/types/src/WnfsPlugin.workerd.d.ts +1 -1
  30. package/dist/types/src/WnfsPlugin.workerd.d.ts.map +1 -1
  31. package/dist/types/src/capabilities/blob-backend.d.ts +3 -3
  32. package/dist/types/src/capabilities/blob-backend.d.ts.map +1 -1
  33. package/dist/types/src/capabilities/dependencies.d.ts +2 -2
  34. package/dist/types/src/capabilities/dependencies.d.ts.map +1 -1
  35. package/dist/types/src/capabilities/index.d.ts +3 -3
  36. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  37. package/dist/types/src/helpers/load.d.ts +1 -1
  38. package/dist/types/src/helpers/load.d.ts.map +1 -1
  39. package/dist/types/src/helpers/upload.d.ts +1 -1
  40. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  41. package/dist/types/src/index.d.ts +2 -1
  42. package/dist/types/src/index.d.ts.map +1 -1
  43. package/dist/types/src/plugin.d.ts +1 -1
  44. package/dist/types/src/plugin.d.ts.map +1 -1
  45. package/dist/types/src/types/WnfsCapabilities.d.ts +3 -3
  46. package/dist/types/src/types/WnfsCapabilities.d.ts.map +1 -1
  47. package/dist/types/src/types/WnfsEvents.d.ts +5 -8
  48. package/dist/types/src/types/WnfsEvents.d.ts.map +1 -1
  49. package/dist/types/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +41 -28
  51. package/src/WnfsPlugin.node.ts +1 -1
  52. package/src/WnfsPlugin.tsx +13 -19
  53. package/src/WnfsPlugin.workerd.ts +1 -1
  54. package/src/capabilities/blob-backend.test.ts +1 -1
  55. package/src/capabilities/blob-backend.ts +13 -17
  56. package/src/capabilities/dependencies.ts +9 -7
  57. package/src/capabilities/index.ts +26 -3
  58. package/src/helpers/load.ts +1 -2
  59. package/src/helpers/upload.ts +1 -2
  60. package/src/index.ts +2 -1
  61. package/src/meta.ts +1 -1
  62. package/src/plugin.ts +1 -1
  63. package/src/types/WnfsCapabilities.ts +3 -3
  64. package/src/types/WnfsEvents.ts +5 -8
  65. package/dist/lib/chunk-types.mjs +0 -46
  66. package/dist/lib/chunk-types.mjs.map +0 -1
  67. package/dist/lib/types.mjs +0 -2
  68. package/dist/types/src/types/index.d.ts +0 -3
  69. package/dist/types/src/types/index.d.ts.map +0 -1
  70. package/src/types/index.ts +0 -6
@@ -0,0 +1,23 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import * as Capability from "@dxos/app-framework/Capability";
3
+ import { meta } from "#meta";
4
+ //#region src/types/WnfsCapabilities.ts
5
+ var WnfsCapabilities_exports = /* @__PURE__ */ __exportAll({
6
+ Blockstore: () => Blockstore,
7
+ Instances: () => Instances,
8
+ WNFS_BACKEND: () => WNFS_BACKEND,
9
+ WNFS_SCHEME: () => WNFS_SCHEME
10
+ });
11
+ var Blockstore = Capability.makeSingleton()(`${meta.profile.key}.capability.blockstore`);
12
+ var Instances = Capability.makeSingleton()(`${meta.profile.key}.capability.instances`);
13
+ /**
14
+ * Name this extension registers its `BlobBackend` under on the ECHO Hypergraph. Core packages
15
+ * (`@dxos/echo`, `@dxos/echo-client`, `@dxos/client`) never reference this constant.
16
+ */
17
+ var WNFS_BACKEND = "wnfs";
18
+ /** URI scheme this extension's `BlobBackend` resolves at read time. */
19
+ var WNFS_SCHEME = "wnfs";
20
+ //#endregion
21
+ export { Blockstore, Instances, WNFS_BACKEND, WNFS_SCHEME, WnfsCapabilities_exports as t };
22
+
23
+ //# sourceMappingURL=WnfsCapabilities.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WnfsCapabilities.mjs","names":[],"sources":["../../src/types/WnfsCapabilities.ts"],"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 * as Capability from '@dxos/app-framework/Capability';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { meta } from '#meta';\n\nexport const Blockstore = Capability.makeSingleton<BlockstoreInterface>()(`${meta.profile.key}.capability.blockstore`);\n\nexport type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;\nexport const Instances = Capability.makeSingleton<Instances>()(`${meta.profile.key}.capability.instances`);\n\n/**\n * Name this extension registers its `BlobBackend` under on the ECHO Hypergraph. Core packages\n * (`@dxos/echo`, `@dxos/echo-client`, `@dxos/client`) never reference this constant.\n */\nexport const WNFS_BACKEND = 'wnfs';\n\n/** URI scheme this extension's `BlobBackend` resolves at read time. */\nexport const WNFS_SCHEME = 'wnfs';\n"],"mappings":";;;;;;;;;;AAcA,IAAa,aAAa,WAAW,cAAmC,CAAC,CAAC,GAAG,KAAK,QAAQ,IAAI,uBAAuB;AAGrH,IAAa,YAAY,WAAW,cAAyB,CAAC,CAAC,GAAG,KAAK,QAAQ,IAAI,sBAAsB;;;;;AAMzG,IAAa,eAAe;;AAG5B,IAAa,cAAc"}
@@ -0,0 +1,15 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { meta } from "#meta";
3
+ import * as ActivationEvent from "@dxos/app-framework/ActivationEvent";
4
+ //#region src/types/WnfsEvents.ts
5
+ var WnfsEvents_exports = /* @__PURE__ */ __exportAll({ Start: () => Start });
6
+ /**
7
+ * The feature's start event: the plugin's start-gated modules (and cross-plugin
8
+ * contributions consumed by this feature) activate here. Fired on demand and by the
9
+ * host's idle trickle.
10
+ */
11
+ var Start = ActivationEvent.pluginStart(meta.profile.key);
12
+ //#endregion
13
+ export { Start, WnfsEvents_exports as t };
14
+
15
+ //# sourceMappingURL=WnfsEvents.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WnfsEvents.mjs","names":[],"sources":["../../src/types/WnfsEvents.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as ActivationEvent from '@dxos/app-framework/ActivationEvent';\n\nimport { meta } from '#meta';\n\n/**\n * The feature's start event: the plugin's start-gated modules (and cross-plugin\n * contributions consumed by this feature) activate here. Fired on demand and by the\n * host's idle trickle.\n */\nexport const Start = ActivationEvent.pluginStart(meta.profile.key);\n"],"mappings":";;;;;;;;;;AAeA,IAAa,QAAQ,gBAAgB,YAAY,KAAK,QAAQ,GAAG"}
@@ -1,27 +1,16 @@
1
- import { Plugin } from "@dxos/app-framework";
1
+ import * as Plugin from "@dxos/app-framework/Plugin";
2
2
  import { meta } from "#meta";
3
- import { AppPlugin } from "@dxos/app-toolkit";
4
- import { ClientEvents } from "@dxos/plugin-client";
3
+ import * as AppCapability from "@dxos/app-toolkit/AppCapability";
5
4
  import { BlobBackend, Dependencies } from "#capabilities";
6
5
  import { translations } from "#translations";
7
- import { WnfsEvents } from "#types";
8
6
  //#endregion
9
7
  //#region src/WnfsPlugin.tsx
10
- var WnfsPlugin = Plugin.define(meta).pipe(AppPlugin.addTranslationsModule({ translations }), Plugin.addModule({
11
- id: "dependencies",
12
- activatesOn: ClientEvents.ClientReady,
13
- firesAfterActivation: [WnfsEvents.DependenciesReady],
14
- activate: Dependencies
15
- }), Plugin.addModule({
16
- id: "blob-backend",
17
- activatesOn: WnfsEvents.DependenciesReady,
18
- activate: BlobBackend
19
- }), AppPlugin.addPluginAssetModule({ asset: {
8
+ var WnfsPlugin = Plugin.define(meta).pipe(Plugin.addModule(AppCapability.translations(translations)), Plugin.addModule(Dependencies), Plugin.addModule(BlobBackend), Plugin.addModule(AppCapability.pluginAsset({
20
9
  pluginId: meta.profile.key,
21
10
  path: "PLUGIN.mdl",
22
11
  content: "---\nid: org.dxos.plugin.wnfs\nname: WnfsPlugin\nversion: 0.2.0\n---\n\nA decentralized file storage plugin for `DXOS` Composer built on the Web Native File System (WNFS) protocol.\n\nWNFS provides a content-addressed, end-to-end encrypted private file system using a cryptographic \"dark forest\"\nstructure. Files are stored as IPLD blocks referenced by CID, replicated to a DXOS edge blob service, and\ncached locally in IndexedDB. The plugin registers a `BlobBackend` (schemes: `['wnfs']`) on the ECHO Hypergraph\nvia `client.graph.registerBlobBackend`, and contributes a matching `FileCapabilities.Backend` descriptor\n(`{ storage: 'wnfs' }`) so `plugin-file` — and any plugin built on it, e.g. `plugin-gallery` — can\nupload files and resolve `wnfs://` URIs uniformly via the core `Blob.fromBytes`/`Blob.url`/`Blob.read` API,\nwithout knowing the underlying storage layer. Uploads are scoped to a DXOS Space; the private forest root CID\nis persisted on the space's ECHO properties and updated atomically on every write.\n\n## Extensions\n\nThe following extension dialects are used in this document.\nEach extension is defined in the Appendix or resolved via its URI.\n\n| Term | URI |\n|-------------|--------------------------------|\n| `type` | `org.dxos.mdl.type@1.0` |\n| `feat` | `org.dxos.mdl.feat@1.0` |\n| `test` | `org.dxos.mdl.test@1.0` |\n| `component` | `org.dxos.mdl.component@1.0` |\n| `op` | `org.dxos.mdl.op@1.0` |\n\n## Types\n\n```mdl\ntype Cid\n desc: A content-addressed identifier encoded as a base-32 multibase string (CIDv1, sha2-256).\n fields:\n value: string\n```\n\n```mdl\ntype WnfsPath\n desc: A WNFS path encoded as a wnfs:// URL; segments are percent-encoded.\n fields:\n url: string # wnfs://spaces/<spaceId>/files/<cid>\n```\n\n```mdl\ntype FileInfo\n desc: |\n Internal return value of the `upload` helper. Only `.url` is surfaced to the outside world,\n as the `uri` field of the `BlobBackend.put` PutResponse.\n fields:\n name: string # Original file name\n type: string # MIME type\n url: WnfsPath # wnfs:// URL for later retrieval\n cid: Cid # Raw content CID of the file bytes\n```\n\n```mdl\ntype BlockstoreState\n desc: Runtime state of the MixedBlockstore.\n fields:\n isConnected: boolean # Online / offline status\n queueLength: number # Blocks pending remote flush\n apiHost: string # DXOS edge service base URL\n```\n\n```mdl\ntype WnfsInstances\n desc: In-memory cache mapping forest CID → loaded PrivateDirectory/PrivateForest pair.\n fields:\n entries: Record<string, WnfsInstance>\n```\n\n```mdl\ntype WnfsInstance\n desc: A loaded WNFS private file system rooted at a specific forest CID.\n fields:\n directory: PrivateDirectory\n forest: PrivateForest\n```\n\n## Operations\n\nPure operations — no external effects.\n\n```mdl\nop wnfsUrl\n desc: Encodes a WNFS path array into a wnfs:// URL with percent-encoded segments.\n input:\n filePath: string[]\n output: string\n```\n\n```mdl\nop getPathFromUrl\n desc: Decodes a wnfs:// URL back into a path segment array.\n input:\n wnfsUrl: string\n output: string[]\n```\n\nBlobBackend implementation — registered on the ECHO Hypergraph, dispatched to by core `Blob.fromBytes` /\n`Blob.read` / `Blob.exists` / `Blob.url` whenever a Blob's storage or URI scheme resolves to `wnfs`.\n\n```mdl\nop wnfsBlobPut\n desc: |\n Implements BlobBackend.put. Resolves the target Space from spaceId, wraps the given bytes in a\n browser File (named `name ?? contentHash`), and delegates to the uploadFile op. Returns\n { uri: info.url } (a wnfs:// URL) as the PutResponse.\n input:\n spaceId: SpaceId\n data: Uint8Array\n contentType?: string\n contentHash: string # sha256 hex digest, computed by the core BlobManager; not re-verified here\n name?: string\n output: { uri: string }\n effects: [fs:read, echo:write, http:post]\n errors:\n SpaceNotFound: no space matching spaceId is currently open (invariant failure)\n```\n\n```mdl\nop wnfsBlobGet\n desc: |\n Implements BlobBackend.get. Resolves the Space from spaceId, loads or reuses the cached\n WnfsInstance, and reads the file bytes at the given wnfs:// URI (via getPathFromUrl + directory.read).\n input:\n spaceId: SpaceId\n uri: string\n output: Uint8Array | undefined\n effects: [fs:read, http:get]\n note: Returns undefined (never throws) if the space is not open or the read fails for any reason.\n```\n\n```mdl\nop wnfsBlobHas\n desc: Implements BlobBackend.has by delegating to the same read path as wnfsBlobGet and checking for a defined result.\n input:\n spaceId: SpaceId\n uri: string\n output: boolean\n```\n\n```mdl\nop wnfsBlobGetUrl\n desc: |\n Implements BlobBackend.getUrl. Resolves the Space, loads or reuses the cached WnfsInstance,\n reads the file bytes, wraps them in a Blob, and returns an object URL for in-browser display.\n input:\n spaceId: SpaceId\n uri: string\n contentType?: string\n output: string | undefined\n effects: [fs:read, http:get]\n note: Returns undefined (never throws) if the space is not open or reading fails.\n```\n\nEffectful operations underlying the BlobBackend implementation above.\n\n```mdl\nop uploadFile\n desc: |\n Reads a File, writes its bytes into the WNFS private directory at a\n CID-derived path, persists the updated forest pointer to the space's\n ECHO properties, and returns FileInfo.\n input:\n file: File\n space: Space\n output: FileInfo\n effects: [fs:read, echo:write, http:post]\n errors:\n SpaceNotFound: no space matching the given spaceId\n BlockstoreError: local or remote block I/O failure\n note: |\n Uses sha256 for block hashing (not the rs-wnfs default Blake3) for\n broader runtime support. Writes are atomic from ECHO's perspective:\n the forest CID property is only updated after the forest is stored.\n```\n\n```mdl\nop flushBlockQueue\n desc: |\n Drains the pending-upload queue by assembling a CAR archive and POSTing\n it to the edge blob service. Called automatically (debounced 5 s) on\n block writes and on the browser `online` event.\n input:\n blockstore: Blockstore\n output: void\n effects: [http:post]\n errors:\n NetworkError: remote POST failed\n note: Queue is persisted to IndexedDB so pending blocks survive page reloads.\n```\n\n## Features\n\n```mdl\nfeat F-1: Upload File\n\n req F-1.1:\n when: core Blob.fromBytes routes to the 'wnfs' storage (i.e. BlobBackend.put is invoked\n for this backend)\n then: the file is written to the WNFS private directory and stored in the blockstore;\n wnfsBlobPut returns { uri } to the caller\n\n req F-1.2:\n when: the write succeeds\n then: the space's ECHO properties are updated with the new privateForestCid\n\n req F-1.3:\n when: the upload completes\n then: the returned uri is a wnfs:// URL, embedded by core Blob.ts as the Blob object's\n `data.uri` (an `external` BlobData variant)\n```\n\n```mdl\nfeat F-2: Resolve wnfs:// blobs\n\n req F-2.1:\n when: a Blob's URI scheme is 'wnfs' (i.e. this plugin's registered schemes include it)\n then: core Blob.read / Blob.exists / Blob.url dispatch to this plugin's BlobBackend\n\n req F-2.2:\n when: BlobBackend.get or .has is called with a wnfs:// uri\n then: loads or reuses a cached WnfsInstance for the space and reads the file bytes\n\n req F-2.3:\n when: BlobBackend.getUrl is called with a wnfs:// uri\n then: bytes are read and wrapped in a blob: object URL for in-browser display\n\n req F-2.4:\n when: the space is not open, or reading/writing fails\n then: get/has/getUrl resolve to undefined/false rather than throwing; put rejects\n```\n\n```mdl\nfeat F-3: Blockstore Sync\n\n req F-3.1:\n when: a block is written via blockstore.put\n then: the block is saved to IndexedDB and added to the upload queue\n\n req F-3.2:\n when: the browser is online and the queue is non-empty\n then: blocks are batched into a CAR archive and flushed to the edge service\n\n req F-3.3:\n when: the browser goes offline\n then: the queue is persisted to IndexedDB; no upload is attempted\n\n req F-3.4:\n when: the browser comes back online\n then: the flush is triggered automatically\n\n req F-3.5:\n when: a block is requested via blockstore.get and is present in IndexedDB\n then: the block is returned from the local cache without a network request\n\n req F-3.6:\n when: a block is not in IndexedDB and the browser is online\n then: the block is fetched from the edge service and cached locally\n```\n\n```mdl\nfeat F-4: Space-Scoped Private File System\n\n req F-4.1:\n when: a space has no existing WNFS properties\n then: a new PrivateForest and PrivateDirectory are created and stored\n\n req F-4.2:\n when: a space already has a privateForestCid\n then: the existing forest and directory are loaded from the blockstore\n\n req F-4.3:\n when: a WnfsInstance is already cached for the current forest CID\n then: the cached instance is reused without reloading from the blockstore\n\n req F-4.4:\n when: legacy snake_case WNFS properties are found on a space\n then: they are deleted and replaced with the current camelCase schema\n tags: [migration]\n```\n\n## Acceptance\n\n```mdl\ntest T-1: Upload creates a wnfs:// blob\n given: an active space and this plugin's BlobBackend registered on the ECHO Hypergraph\n when: Blob.fromBytes is called with storage: 'wnfs'\n then:\n - the resulting Blob's data.uri starts with wnfs://\n - space.properties.wnfs.privateForestCid is set\n - block for the file is present in the local IndexedDB blockstore\n```\n\n```mdl\ntest T-2: Resolve uploaded blob via getUrl\n given: a blob was previously uploaded and its data.uri (a wnfs:// URI) is known\n when: BlobBackend.getUrl(spaceId, uri, contentType) is called\n then:\n - a blob: object URL is returned\n - the URL can be used as an img src\n```\n\n```mdl\ntest T-3: get/has/getUrl return undefined/false when the space is not open\n given: a wnfs:// URI whose space is not currently open\n when: BlobBackend.get, .has, or .getUrl is called\n then: undefined (or false for .has) is returned; no error is thrown\n```\n\n```mdl\ntest T-4: Blockstore offline queuing\n given: the browser is offline\n when: a block is written to the blockstore\n then:\n - block is saved to IndexedDB\n - queue length increases by 1\n - no HTTP request is made\n```\n\n```mdl\ntest T-5: Blockstore queue flushes on reconnect\n given: blocks are queued while offline\n when: the browser comes back online\n then:\n - a CAR archive containing all queued blocks is POSTed to the edge service\n - the queue is cleared\n```\n\n```mdl\ntest T-6: New space initializes WNFS directory\n given: a space with no WNFS properties\n when: loadWnfs is called for that space\n then:\n - a new PrivateForest and PrivateDirectory are created\n - space.properties.wnfs.privateForestCid is populated\n```\n\n```mdl\ntest T-7: WnfsInstance cache hit\n given: a WnfsInstance is cached for the current forest CID\n when: loadWnfs is called again for the same space\n then: the cached instance is returned; no blockstore reads occur\n```\n\n---\n\n## Appendix: Extension Definitions\n\nExtension block types used in this document are defined below using\nthe core `ext` primitive — the only construct the base language provides.\n\n```mdl\next type\n uri: org.dxos.mdl.type@1.0\n desc: A named data structure with typed fields and optional literals.\n fields:\n desc?: Prose\n fields?: FieldMap # name[?]: TypeExpr (# inline comment)\n literals?: UnionList # a | b | c\n extends?: TypeRef[]\n```\n\n```mdl\next feat\n uri: org.dxos.mdl.feat@1.0\n desc: A named feature grouping one or more requirements.\n fields:\n desc?: Prose\n req: RequirementList\n nesting: self # feat blocks may contain feat blocks\n```\n\n```mdl\next test\n uri: org.dxos.mdl.test@1.0\n desc: An acceptance scenario expressed as given / when / then steps.\n fields:\n given?: Step | Step[]\n when?: Step | Step[]\n then: Step | Step[]\n tags?: TagList\n```\n\n```mdl\next component\n uri: org.dxos.mdl.component@1.0\n desc: A UI component with props, internal state, slots, actions, and events.\n fields:\n desc?: Prose\n props?: FieldMap # external inputs (immutable inside component)\n state?: FieldMap # internal reactive state\n slots?: FieldMap # named ReactNode injection points\n actions?: ActionMap # methods the component exposes or handles\n emits?: EventMap # events the component raises to its parent\n layout?: CodeBlock # ASCII sketch of visual structure (non-normative)\n```\n\n```mdl\next op\n uri: org.dxos.mdl.op@1.0\n desc: |\n A named operation with typed inputs, outputs, and declared errors.\n Pure ops have no effects or requires. Effectful ops declare both.\n fields:\n desc?: Prose\n input?: FieldMap # named input parameters\n output?: TypeExpr # return type\n errors?: ErrorMap # name: Prose (when this error occurs)\n effects?: EffectList # echo:read | echo:write | http | fs | ...\n requires?: ServiceList # injected service dependencies\n note?: Prose # implementation guidance (non-normative)\n```\n",
23
12
  mimeType: "application/x-mdl"
24
- } }), Plugin.make);
13
+ })), Plugin.make);
25
14
  //#endregion
26
15
  export { WnfsPlugin, WnfsPlugin as default };
27
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"WnfsPlugin.mjs","names":[],"sources":["../../src/WnfsPlugin.tsx"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppPlugin } from '@dxos/app-toolkit';\nimport { ClientEvents } from '@dxos/plugin-client';\n\nimport { BlobBackend, Dependencies } from '#capabilities';\nimport { meta } from '#meta';\nimport { translations } from '#translations';\nimport { WnfsEvents } from '#types';\n\n// eslint-disable-next-line import/no-relative-packages\nimport pluginSpec from '../PLUGIN.mdl?raw';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(\n AppPlugin.addTranslationsModule({ translations }),\n Plugin.addModule({\n id: 'dependencies',\n activatesOn: ClientEvents.ClientReady,\n firesAfterActivation: [WnfsEvents.DependenciesReady],\n activate: Dependencies,\n }),\n Plugin.addModule({\n id: 'blob-backend',\n activatesOn: WnfsEvents.DependenciesReady,\n activate: BlobBackend,\n }),\n AppPlugin.addPluginAssetModule({\n asset: { pluginId: meta.profile.key, path: 'PLUGIN.mdl', content: pluginSpec, mimeType: 'application/x-mdl' },\n }),\n Plugin.make,\n);\n\nexport default WnfsPlugin;\n"],"mappings":";;;;;;;;;AAgBA,IAAa,aAAa,OAAO,OAAO,IAAI,CAAC,CAAC,KAC5C,UAAU,sBAAsB,EAAE,aAAa,CAAC,GAChD,OAAO,UAAU;CACf,IAAI;CACJ,aAAa,aAAa;CAC1B,sBAAsB,CAAC,WAAW,iBAAiB;CACnD,UAAU;AACZ,CAAC,GACD,OAAO,UAAU;CACf,IAAI;CACJ,aAAa,WAAW;CACxB,UAAU;AACZ,CAAC,GACD,UAAU,qBAAqB,EAC7B,OAAO;CAAE,UAAU,KAAK,QAAQ;CAAK,MAAM;CAAc,SAAS;CAAY,UAAU;AAAoB,EAC9G,CAAC,GACD,OAAO,IACT"}
1
+ {"version":3,"file":"WnfsPlugin.mjs","names":[],"sources":["../../src/WnfsPlugin.tsx"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Plugin from '@dxos/app-framework/Plugin';\nimport * as AppCapability from '@dxos/app-toolkit/AppCapability';\n\nimport { BlobBackend, Dependencies } from '#capabilities';\nimport { meta } from '#meta';\nimport { translations } from '#translations';\n\n// eslint-disable-next-line import/no-relative-packages\nimport pluginSpec from '../PLUGIN.mdl?raw';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(\n Plugin.addModule(AppCapability.translations(translations)),\n Plugin.addModule(Dependencies),\n Plugin.addModule(BlobBackend),\n Plugin.addModule(\n AppCapability.pluginAsset({\n pluginId: meta.profile.key,\n path: 'PLUGIN.mdl',\n content: pluginSpec,\n mimeType: 'application/x-mdl',\n }),\n ),\n Plugin.make,\n);\n\nexport default WnfsPlugin;\n"],"mappings":";;;;;;;AAcA,IAAa,aAAa,OAAO,OAAO,IAAI,CAAC,CAAC,KAC5C,OAAO,UAAU,cAAc,aAAa,YAAY,CAAC,GACzD,OAAO,UAAU,YAAY,GAC7B,OAAO,UAAU,WAAW,GAC5B,OAAO,UACL,cAAc,YAAY;CACxB,UAAU,KAAK,QAAQ;CACvB,MAAM;CACN,SAAS;CACT,UAAU;AACZ,CAAC,CACH,GACA,OAAO,IACT"}
@@ -1,4 +1,4 @@
1
- import { Plugin } from "@dxos/app-framework";
1
+ import * as Plugin from "@dxos/app-framework/Plugin";
2
2
  import { meta } from "#meta";
3
3
  //#region src/WnfsPlugin.node.ts
4
4
  var WnfsPlugin = Plugin.define(meta).pipe(Plugin.make);
@@ -1 +1 @@
1
- {"version":3,"file":"WnfsPlugin.node.mjs","names":[],"sources":["../../src/WnfsPlugin.node.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\n\nimport { meta } from '#meta';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(Plugin.make);\n\nexport default WnfsPlugin;\n"],"mappings":";;;AAQA,IAAa,aAAa,OAAO,OAAO,IAAI,CAAC,CAAC,KAAK,OAAO,IAAI"}
1
+ {"version":3,"file":"WnfsPlugin.node.mjs","names":[],"sources":["../../src/WnfsPlugin.node.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Plugin from '@dxos/app-framework/Plugin';\n\nimport { meta } from '#meta';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(Plugin.make);\n\nexport default WnfsPlugin;\n"],"mappings":";;;AAQA,IAAa,aAAa,OAAO,OAAO,IAAI,CAAC,CAAC,KAAK,OAAO,IAAI"}
@@ -1,4 +1,4 @@
1
- import { Plugin } from "@dxos/app-framework";
1
+ import * as Plugin from "@dxos/app-framework/Plugin";
2
2
  import { meta } from "#meta";
3
3
  //#region src/WnfsPlugin.workerd.ts
4
4
  var WnfsPlugin = Plugin.define(meta).pipe(Plugin.make);
@@ -1 +1 @@
1
- {"version":3,"file":"WnfsPlugin.workerd.mjs","names":[],"sources":["../../src/WnfsPlugin.workerd.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\n\nimport { meta } from '#meta';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(Plugin.make);\n\nexport default WnfsPlugin;\n"],"mappings":";;;AAQA,IAAa,aAAa,OAAO,OAAO,IAAI,CAAC,CAAC,KAAK,OAAO,IAAI"}
1
+ {"version":3,"file":"WnfsPlugin.workerd.mjs","names":[],"sources":["../../src/WnfsPlugin.workerd.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Plugin from '@dxos/app-framework/Plugin';\n\nimport { meta } from '#meta';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(Plugin.make);\n\nexport default WnfsPlugin;\n"],"mappings":";;;AAQA,IAAa,aAAa,OAAO,OAAO,IAAI,CAAC,CAAC,KAAK,OAAO,IAAI"}
@@ -1,7 +1,23 @@
1
- import { Capability } from "@dxos/app-framework";
1
+ import { Blockstore, Instances } from "./WnfsCapabilities.mjs";
2
+ import * as Capability from "@dxos/app-framework/Capability";
3
+ import * as ClientCapabilities from "@dxos/plugin-client/ClientCapabilities";
4
+ import * as FileCapabilities from "@dxos/plugin-file/FileCapabilities";
5
+ import * as FileEvents from "@dxos/plugin-file/FileEvents";
2
6
  //#region src/capabilities/index.ts
3
- var BlobBackend = Capability.lazy("BlobBackend", () => import("./chunk-blob-backend.mjs"));
4
- var Dependencies = Capability.lazy("Dependencies", () => import("./chunk-dependencies.mjs"));
7
+ var BlobBackend = Capability.lazyModule("BlobBackend", {
8
+ requires: [
9
+ ClientCapabilities.Client,
10
+ Blockstore,
11
+ Instances
12
+ ],
13
+ provides: [FileCapabilities.Backend],
14
+ activatesOn: FileEvents.Start
15
+ }, () => import("./chunk-blob-backend.mjs"));
16
+ var Dependencies = Capability.lazyModule("Dependencies", {
17
+ requires: [ClientCapabilities.Client],
18
+ provides: [Blockstore, Instances],
19
+ activatesOn: FileEvents.Start
20
+ }, () => import("./chunk-dependencies.mjs"));
5
21
  //#endregion
6
22
  export { BlobBackend, Dependencies };
7
23
 
@@ -1 +1 @@
1
- {"version":3,"file":"capabilities.mjs","names":[],"sources":["../../src/capabilities/index.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capability } from '@dxos/app-framework';\n\nexport const BlobBackend = Capability.lazy('BlobBackend', () => import('./blob-backend'));\n\nexport const Dependencies = Capability.lazy('Dependencies', () => import('./dependencies'));\n"],"mappings":";;AAMA,IAAa,cAAc,WAAW,KAAK,qBAAqB,OAAO,2BAAiB;AAExF,IAAa,eAAe,WAAW,KAAK,sBAAsB,OAAO,2BAAiB"}
1
+ {"version":3,"file":"capabilities.mjs","names":[],"sources":["../../src/capabilities/index.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Capability from '@dxos/app-framework/Capability';\nimport * as ClientCapabilities from '@dxos/plugin-client/ClientCapabilities';\nimport * as FileCapabilities from '@dxos/plugin-file/FileCapabilities';\nimport * as FileEvents from '@dxos/plugin-file/FileEvents';\n\nimport * as WnfsCapabilities from '../types/WnfsCapabilities';\n\nexport const BlobBackend = Capability.lazyModule(\n 'BlobBackend',\n {\n requires: [ClientCapabilities.Client, WnfsCapabilities.Blockstore, WnfsCapabilities.Instances],\n provides: [FileCapabilities.Backend],\n activatesOn: FileEvents.Start,\n },\n () => import('./blob-backend'),\n);\n\nexport const Dependencies = Capability.lazyModule(\n 'Dependencies',\n {\n requires: [ClientCapabilities.Client],\n // The file plugin's start, not wnfs's own: wnfs contributes no surface, so nothing would\n // ever fire its own start — and these are exactly the requires of the blob backend below.\n provides: [WnfsCapabilities.Blockstore, WnfsCapabilities.Instances],\n activatesOn: FileEvents.Start,\n },\n () => import('./dependencies'),\n);\n"],"mappings":";;;;;;AAWA,IAAa,cAAc,WAAW,WACpC,eACA;CACE,UAAU;EAAC,mBAAmB;EAAQ;EAA6B;CAA0B;CAC7F,UAAU,CAAC,iBAAiB,OAAO;CACnC,aAAa,WAAW;AAC1B,SACM,OAAO,2BACf;AAEA,IAAa,eAAe,WAAW,WACrC,gBACA;CACE,UAAU,CAAC,mBAAmB,MAAM;CAGpC,UAAU,CAAC,YAA6B,SAA0B;CAClE,aAAa,WAAW;AAC1B,SACM,OAAO,2BACf"}
@@ -1,11 +1,11 @@
1
1
  import { i as readWnfsFile, n as getBlobUrl, o as loadWnfs, t as upload } from "./chunk-helpers.mjs";
2
+ import { Blockstore, Instances, WNFS_BACKEND, WNFS_SCHEME } from "./WnfsCapabilities.mjs";
2
3
  import { log } from "@dxos/log";
3
- import { Capability } from "@dxos/app-framework";
4
- import { ClientCapabilities } from "@dxos/plugin-client";
5
- import { WnfsCapabilities } from "#types";
4
+ import * as Capability from "@dxos/app-framework/Capability";
5
+ import * as ClientCapabilities from "@dxos/plugin-client/ClientCapabilities";
6
+ import * as FileCapabilities from "@dxos/plugin-file/FileCapabilities";
6
7
  import * as Effect from "effect/Effect";
7
8
  import { invariant } from "@dxos/invariant";
8
- import { FileCapabilities } from "@dxos/plugin-file/types";
9
9
  //#region src/capabilities/blob-backend.ts
10
10
  var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/capabilities/blob-backend.ts";
11
11
  /**
@@ -39,20 +39,20 @@ var createWnfsBlobBackend = ({ client, blockstore, instances }) => {
39
39
  }, {
40
40
  "~LogMeta": "~LogMeta",
41
41
  F: __dxlog_file,
42
- L: 44,
42
+ L: 43,
43
43
  S: void 0
44
44
  });
45
45
  return;
46
46
  }
47
47
  };
48
48
  return {
49
- schemes: [WnfsCapabilities.WNFS_SCHEME],
49
+ schemes: [WNFS_SCHEME],
50
50
  put: async ({ spaceId, data, contentType, contentHash, name }) => {
51
51
  const space = client.spaces.get(spaceId);
52
52
  invariant(space, "Space not found", {
53
53
  "~LogMeta": "~LogMeta",
54
54
  F: __dxlog_file,
55
- L: 54,
55
+ L: 53,
56
56
  S: void 0,
57
57
  A: ["space", "'Space not found'"]
58
58
  });
@@ -89,7 +89,7 @@ var createWnfsBlobBackend = ({ client, blockstore, instances }) => {
89
89
  }, {
90
90
  "~LogMeta": "~LogMeta",
91
91
  F: __dxlog_file,
92
- L: 76,
92
+ L: 75,
93
93
  S: void 0
94
94
  });
95
95
  return;
@@ -98,19 +98,20 @@ var createWnfsBlobBackend = ({ client, blockstore, instances }) => {
98
98
  };
99
99
  };
100
100
  var blob_backend_default = Capability.makeModule(Effect.fnUntraced(function* () {
101
- const client = yield* Capability.get(ClientCapabilities.Client);
102
- const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
103
- const instances = yield* Capability.get(WnfsCapabilities.Instances);
104
- const cleanup = client.graph.registerBlobBackend(WnfsCapabilities.WNFS_BACKEND, createWnfsBlobBackend({
101
+ const client = yield* ClientCapabilities.Client;
102
+ const blockstore = yield* Blockstore;
103
+ const instances = yield* Instances;
104
+ const cleanup = client.graph.registerBlobBackend(WNFS_BACKEND, createWnfsBlobBackend({
105
105
  client,
106
106
  blockstore,
107
107
  instances
108
108
  }));
109
- return Capability.contributes(FileCapabilities.Backend, {
109
+ yield* Effect.addFinalizer(() => Effect.sync(() => cleanup()));
110
+ return Capability.contribute(FileCapabilities.Backend, {
110
111
  name: "WNFS",
111
112
  description: "Decentralized, end-to-end encrypted storage via Web Native File System.",
112
- storage: WnfsCapabilities.WNFS_BACKEND
113
- }, () => Effect.sync(() => cleanup()));
113
+ storage: WNFS_BACKEND
114
+ });
114
115
  }));
115
116
  //#endregion
116
117
  export { createWnfsBlobBackend, blob_backend_default as default };
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-blob-backend.mjs","names":[],"sources":["../../src/capabilities/blob-backend.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport type { Blockstore } from 'interface-blockstore';\n\nimport { Capability } from '@dxos/app-framework';\nimport { type Client } from '@dxos/client';\nimport { type BlobBackend } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { type SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ClientCapabilities } from '@dxos/plugin-client';\nimport { FileCapabilities } from '@dxos/plugin-file/types';\n\nimport { WnfsCapabilities } from '#types';\n\nimport { getBlobUrl, loadWnfs, readWnfsFile, upload } from '../helpers';\n\ninterface CreateWnfsBlobBackendOptions {\n client: Client;\n blockstore: Blockstore;\n instances?: WnfsCapabilities.Instances;\n}\n\n/**\n * Blob backend that stores bytes in a space's WNFS private forest, addressed by `wnfs://…` URIs.\n * The underlying WASM bindings (`directory.read`) don't expose a distinct not-found error type, so\n * `readBytes`/`getUrl` can't tell a missing path from a genuine transport/blockstore failure —\n * both are logged and reported as a miss (`undefined`) rather than risk rethrowing on the common\n * missing-file path.\n */\nexport const createWnfsBlobBackend = ({ client, blockstore, instances }: CreateWnfsBlobBackendOptions): BlobBackend => {\n const readBytes = async (spaceId: SpaceId, uri: string) => {\n const space = client.spaces.get(spaceId);\n if (!space) {\n return undefined;\n }\n try {\n const { directory, forest } = await loadWnfs({ blockstore, instances, space });\n return await readWnfsFile({ wnfsUrl: uri, blockstore, forest, directory });\n } catch (error) {\n log.warn('failed to read wnfs blob', { spaceId, uri, error });\n return undefined;\n }\n };\n\n return {\n schemes: [WnfsCapabilities.WNFS_SCHEME],\n\n put: async ({ spaceId, data, contentType, contentHash, name }) => {\n const space = client.spaces.get(spaceId);\n invariant(space, 'Space not found');\n // `Uint8Array` is generic over `ArrayBufferLike` (incl. `SharedArrayBuffer`) while DOM's\n // `BlobPart` only covers `ArrayBuffer`-backed views — a gap between the DOM lib types and\n // the TS standard lib, not fixable by typing `data` differently.\n const file = new File([data as BlobPart], name ?? contentHash, { type: contentType });\n const info = await upload({ file, blockstore, instances, space });\n return { uri: info.url };\n },\n\n get: async ({ spaceId, uri }) => readBytes(spaceId, uri),\n\n has: async ({ spaceId, uri }) => (await readBytes(spaceId, uri)) !== undefined,\n\n getUrl: async ({ spaceId, uri, contentType }) => {\n const space = client.spaces.get(spaceId);\n if (!space) {\n return undefined;\n }\n try {\n const { directory, forest } = await loadWnfs({ blockstore, instances, space });\n return await getBlobUrl({ wnfsUrl: uri, blockstore, directory, forest, type: contentType });\n } catch (error) {\n log.warn('failed to resolve wnfs blob url', { spaceId, uri, error });\n return undefined;\n }\n },\n };\n};\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n const client = yield* Capability.get(ClientCapabilities.Client);\n const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);\n const instances = yield* Capability.get(WnfsCapabilities.Instances);\n\n const cleanup = client.graph.registerBlobBackend(\n WnfsCapabilities.WNFS_BACKEND,\n createWnfsBlobBackend({ client, blockstore, instances }),\n );\n\n return Capability.contributes(\n FileCapabilities.Backend,\n {\n name: 'WNFS',\n description: 'Decentralized, end-to-end encrypted storage via Web Native File System.',\n storage: WnfsCapabilities.WNFS_BACKEND,\n },\n () => Effect.sync(() => cleanup()),\n );\n }),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;AAiCA,IAAa,yBAAyB,EAAE,QAAQ,YAAY,gBAA2D;CACrH,MAAM,YAAY,OAAO,SAAkB,QAAgB;EACzD,MAAM,QAAQ,OAAO,OAAO,IAAI,OAAO;EACvC,IAAI,CAAC,OACH;EAEF,IAAI;GACF,MAAM,EAAE,WAAW,WAAW,MAAM,SAAS;IAAE;IAAY;IAAW;GAAM,CAAC;GAC7E,OAAO,MAAM,aAAa;IAAE,SAAS;IAAK;IAAY;IAAQ;GAAU,CAAC;EAC3E,SAAS,OAAO;GACd,IAAI,KAAK,4BAA4B;IAAE;IAAS;IAAK;GAAM,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;GAC5D;EACF;CACF;CAEA,OAAO;EACL,SAAS,CAAC,iBAAiB,WAAW;EAEtC,KAAK,OAAO,EAAE,SAAS,MAAM,aAAa,aAAa,WAAW;GAChE,MAAM,QAAQ,OAAO,OAAO,IAAI,OAAO;GACvC,UAAU,OAAO,mBAAgB;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;IAAA,GAAA,CAAA,SAAA,mBAAA;GAAA,CAAC;GAMlC,OAAO,EAAE,MAAK,MADK,OAAO;IAAE,MAAA,IADX,KAAK,CAAC,IAAgB,GAAG,QAAQ,aAAa,EAAE,MAAM,YAAY,CACvD;IAAM;IAAY;IAAW;GAAM,CAAC,EAAA,CAC7C,IAAI;EACzB;EAEA,KAAK,OAAO,EAAE,SAAS,UAAU,UAAU,SAAS,GAAG;EAEvD,KAAK,OAAO,EAAE,SAAS,UAAW,MAAM,UAAU,SAAS,GAAG,MAAO,KAAA;EAErE,QAAQ,OAAO,EAAE,SAAS,KAAK,kBAAkB;GAC/C,MAAM,QAAQ,OAAO,OAAO,IAAI,OAAO;GACvC,IAAI,CAAC,OACH;GAEF,IAAI;IACF,MAAM,EAAE,WAAW,WAAW,MAAM,SAAS;KAAE;KAAY;KAAW;IAAM,CAAC;IAC7E,OAAO,MAAM,WAAW;KAAE,SAAS;KAAK;KAAY;KAAW;KAAQ,MAAM;IAAY,CAAC;GAC5F,SAAS,OAAO;IACd,IAAI,KAAK,mCAAmC;KAAE;KAAS;KAAK;IAAM,GAAA;KAAA,YAAA;KAAA,GAAA;KAAA,GAAA;KAAA,GAAA,KAAA;IAAA,CAAC;IACnE;GACF;EACF;CACF;AACF;AAEA,IAAA,uBAAe,WAAW,WACxB,OAAO,WAAW,aAAa;CAC7B,MAAM,SAAS,OAAO,WAAW,IAAI,mBAAmB,MAAM;CAC9D,MAAM,aAAa,OAAO,WAAW,IAAI,iBAAiB,UAAU;CACpE,MAAM,YAAY,OAAO,WAAW,IAAI,iBAAiB,SAAS;CAElE,MAAM,UAAU,OAAO,MAAM,oBAC3B,iBAAiB,cACjB,sBAAsB;EAAE;EAAQ;EAAY;CAAU,CAAC,CACzD;CAEA,OAAO,WAAW,YAChB,iBAAiB,SACjB;EACE,MAAM;EACN,aAAa;EACb,SAAS,iBAAiB;CAC5B,SACM,OAAO,WAAW,QAAQ,CAAC,CACnC;AACF,CAAC,CACH"}
1
+ {"version":3,"file":"chunk-blob-backend.mjs","names":[],"sources":["../../src/capabilities/blob-backend.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport type { Blockstore } from 'interface-blockstore';\n\nimport * as Capability from '@dxos/app-framework/Capability';\nimport { type Client } from '@dxos/client';\nimport { type BlobBackend } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { type SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport * as ClientCapabilities from '@dxos/plugin-client/ClientCapabilities';\nimport * as FileCapabilities from '@dxos/plugin-file/FileCapabilities';\n\nimport { getBlobUrl, loadWnfs, readWnfsFile, upload } from '../helpers';\nimport * as WnfsCapabilities from '../types/WnfsCapabilities';\n\ninterface CreateWnfsBlobBackendOptions {\n client: Client;\n blockstore: Blockstore;\n instances?: WnfsCapabilities.Instances;\n}\n\n/**\n * Blob backend that stores bytes in a space's WNFS private forest, addressed by `wnfs://…` URIs.\n * The underlying WASM bindings (`directory.read`) don't expose a distinct not-found error type, so\n * `readBytes`/`getUrl` can't tell a missing path from a genuine transport/blockstore failure —\n * both are logged and reported as a miss (`undefined`) rather than risk rethrowing on the common\n * missing-file path.\n */\nexport const createWnfsBlobBackend = ({ client, blockstore, instances }: CreateWnfsBlobBackendOptions): BlobBackend => {\n const readBytes = async (spaceId: SpaceId, uri: string) => {\n const space = client.spaces.get(spaceId);\n if (!space) {\n return undefined;\n }\n try {\n const { directory, forest } = await loadWnfs({ blockstore, instances, space });\n return await readWnfsFile({ wnfsUrl: uri, blockstore, forest, directory });\n } catch (error) {\n log.warn('failed to read wnfs blob', { spaceId, uri, error });\n return undefined;\n }\n };\n\n return {\n schemes: [WnfsCapabilities.WNFS_SCHEME],\n\n put: async ({ spaceId, data, contentType, contentHash, name }) => {\n const space = client.spaces.get(spaceId);\n invariant(space, 'Space not found');\n // `Uint8Array` is generic over `ArrayBufferLike` (incl. `SharedArrayBuffer`) while DOM's\n // `BlobPart` only covers `ArrayBuffer`-backed views — a gap between the DOM lib types and\n // the TS standard lib, not fixable by typing `data` differently.\n const file = new File([data as BlobPart], name ?? contentHash, { type: contentType });\n const info = await upload({ file, blockstore, instances, space });\n return { uri: info.url };\n },\n\n get: async ({ spaceId, uri }) => readBytes(spaceId, uri),\n\n has: async ({ spaceId, uri }) => (await readBytes(spaceId, uri)) !== undefined,\n\n getUrl: async ({ spaceId, uri, contentType }) => {\n const space = client.spaces.get(spaceId);\n if (!space) {\n return undefined;\n }\n try {\n const { directory, forest } = await loadWnfs({ blockstore, instances, space });\n return await getBlobUrl({ wnfsUrl: uri, blockstore, directory, forest, type: contentType });\n } catch (error) {\n log.warn('failed to resolve wnfs blob url', { spaceId, uri, error });\n return undefined;\n }\n },\n };\n};\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n const client = yield* ClientCapabilities.Client;\n const blockstore = yield* WnfsCapabilities.Blockstore;\n const instances = yield* WnfsCapabilities.Instances;\n\n const cleanup = client.graph.registerBlobBackend(\n WnfsCapabilities.WNFS_BACKEND,\n createWnfsBlobBackend({ client, blockstore, instances }),\n );\n\n yield* Effect.addFinalizer(() => Effect.sync(() => cleanup()));\n return Capability.contribute(FileCapabilities.Backend, {\n name: 'WNFS',\n description: 'Decentralized, end-to-end encrypted storage via Web Native File System.',\n storage: WnfsCapabilities.WNFS_BACKEND,\n });\n }),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,IAAa,yBAAyB,EAAE,QAAQ,YAAY,gBAA2D;CACrH,MAAM,YAAY,OAAO,SAAkB,QAAgB;EACzD,MAAM,QAAQ,OAAO,OAAO,IAAI,OAAO;EACvC,IAAI,CAAC,OACH;EAEF,IAAI;GACF,MAAM,EAAE,WAAW,WAAW,MAAM,SAAS;IAAE;IAAY;IAAW;GAAM,CAAC;GAC7E,OAAO,MAAM,aAAa;IAAE,SAAS;IAAK;IAAY;IAAQ;GAAU,CAAC;EAC3E,SAAS,OAAO;GACd,IAAI,KAAK,4BAA4B;IAAE;IAAS;IAAK;GAAM,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;GAC5D;EACF;CACF;CAEA,OAAO;EACL,SAAS,CAAC,WAA4B;EAEtC,KAAK,OAAO,EAAE,SAAS,MAAM,aAAa,aAAa,WAAW;GAChE,MAAM,QAAQ,OAAO,OAAO,IAAI,OAAO;GACvC,UAAU,OAAO,mBAAgB;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;IAAA,GAAA,CAAA,SAAA,mBAAA;GAAA,CAAC;GAM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formats";
3
4
  import * as Uint8Arrays from "uint8arrays";
4
- import { Capability } from "@dxos/app-framework";
5
- import { ClientCapabilities } from "@dxos/plugin-client";
6
- import { WnfsCapabilities } from "#types";
5
+ import * as Capability from "@dxos/app-framework/Capability";
6
+ import * as ClientCapabilities from "@dxos/plugin-client/ClientCapabilities";
7
7
  import * as Effect from "effect/Effect";
8
8
  import { CarWriter } from "@ipld/car";
9
9
  import { BaseBlockstore } from "blockstore-core";
@@ -136,9 +136,11 @@ var MixedBlockstore = class extends BaseBlockstore {
136
136
  //#endregion
137
137
  //#region src/capabilities/dependencies.ts
138
138
  var dependencies_default = Capability.makeModule(Effect.fnUntraced(function* () {
139
- const blockstore = create((yield* Capability.get(ClientCapabilities.Client)).config.values.runtime?.services?.edge?.url || "http://localhost:8787");
139
+ const client = yield* ClientCapabilities.Client;
140
+ yield* Effect.promise(() => client.waitUntilInitialized());
141
+ const blockstore = create(client.config.values.runtime?.services?.edge?.url || "http://localhost:8787");
140
142
  yield* Effect.tryPromise(() => blockstore.open());
141
- return [Capability.contributes(WnfsCapabilities.Blockstore, blockstore), Capability.contributes(WnfsCapabilities.Instances, {})];
143
+ return [Capability.contribute(Blockstore, blockstore), Capability.contribute(Instances, {})];
142
144
  }));
143
145
  //#endregion
144
146
  export { dependencies_default as default };
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-dependencies.mjs","names":[],"sources":["../../src/blockstore.ts","../../src/capabilities/dependencies.ts"],"sourcesContent":["//\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","//\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 const instances: WnfsCapabilities.Instances = {};\n\n return [\n Capability.contributes(WnfsCapabilities.Blockstore, blockstore),\n Capability.contributes(WnfsCapabilities.Instances, instances),\n ];\n }),\n);\n"],"mappings":";;;;;;;;;;;;;;AAgBA,IAAa,UAAU,YAAqB;CAC1C,OAAO,IAAI,gBAAgB,OAAO;AACpC;;;;;AAMA,IAAa,kBAAb,cAAqC,eAAe;CAClD;CACA;CAEA;CACA;CACA;CAEA,YAAY,SAAkB;EAC5B,MAAM;EAEN,KAAK,WAAW,UAAU,QAAQ,QAAQ,QAAQ,EAAE,IAAI,KAAA;EACxD,KAAK,cAAc,IAAI,cAAc,UAAU,CAAC;EAChD,KAAK,eAAe,UAAU;EAC9B,KAAK,SAAS,CAAC;EAEf,KAAK,cAAc,SAAS,KAAK,gBAAgB,GAAI;CACvD;CAEA,MAAM,OAAsB;EAC1B,MAAM,KAAK,YAAY,KAAK;EAC5B,MAAM,KAAK,cAAc;EAEzB,OAAO,iBAAiB,WAAW,YAAY;GAC7C,KAAK,eAAe;EACtB,CAAC;EAED,OAAO,iBAAiB,UAAU,YAAY;GAC5C,KAAK,eAAe;GACpB,KAAK,YAAY;EACnB,CAAC;CACH;CAEA,IAAI,SAAiB,KAAmB;EACtC,MAAM,OAAO,MAAM,IAAI,SAAS,IAAI;EACpC,OAAO,GAAG,QAAQ,WAAW,KAAK,SAAS,MAAM,OAAO;CAC1D;CAIA,MAAe,OAAO,KAAyB;EAC7C,MA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,IACZ,OAAO,KAAK,UAAU;GACpB,OAAO,OAAO,IAAI,KAAK;EACzB,CAAC,CACH;EAEA,MAAM,OAAO,MAAM;EACnB,OAAO,YAAY,OAAO,MAAM,UAAU;CAC5C;AACF;;;AC5MA,IAAA,uBAAe,WAAW,WACxB,OAAO,WAAW,aAAa;CAG7B,MAAM,aAAa,QADH,OADM,WAAW,IAAI,mBAAmB,MAAM,EAAA,CACvC,OAAO,OAAO,SAAS,UAAU,MAAM,OAAO,uBACzB;CAC5C,OAAO,OAAO,iBAAiB,WAAW,KAAK,CAAC;CAIhD,OAAO,CACL,WAAW,YAAY,iBAAiB,YAAY,UAAU,GAC9D,WAAW,YAAY,iBAAiB,WAAW,CAAA,CAAS,CAC9D;AACF,CAAC,CACH"}
1
+ {"version":3,"file":"chunk-dependencies.mjs","names":[],"sources":["../../src/blockstore.ts","../../src/capabilities/dependencies.ts"],"sourcesContent":["//\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","//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport * as Capability from '@dxos/app-framework/Capability';\nimport * as ClientCapabilities from '@dxos/plugin-client/ClientCapabilities';\n\nimport * as Blockstore from '../blockstore';\nimport * as WnfsCapabilities from '../types/WnfsCapabilities';\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n const client = yield* ClientCapabilities.Client;\n // `config` is initialized-only, and this event wave can land before the forked client\n // initialization completes.\n yield* Effect.promise(() => client.waitUntilInitialized());\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 const instances: WnfsCapabilities.Instances = {};\n\n return [\n Capability.contribute(WnfsCapabilities.Blockstore, blockstore),\n Capability.contribute(WnfsCapabilities.Instances, instances),\n ];\n }),\n);\n"],"mappings":";;;;;;;;;;;;;;AAgBA,IAAa,UAAU,YAAqB;CAC1C,OAAO,IAAI,gBAAgB,OAAO;AACpC;;;;;AAMA,IAAa,kBAAb,cAAqC,eAAe;CAClD;CACA;CAEA;CACA;CACA;CAEA,YAAY,SAAkB;EAC5B,MAAM;EAEN,KAAK,WAAW,UAAU,QAAQ,QAAQ,QAAQ,EAAE,IAAI,KAAA;EACxD,KAAK,cAAc,IAAI,cAAc,UAAU,CAAC;EAChD,KAAK,eAAe,UAAU;EAC9B,KAAK,SAAS,CAAC;EAEf,KAAK,cAAc,SAAS,KAAK,gBAAgB,GAAI;CACvD;CAEA,MAAM,OAAsB;EAC1B,MAAM,KAAK,YAAY,KAAK;EAC5B,MAAM,KAAK,cAAc;EAEzB,OAAO,iBAAiB,WAAW,YAAY;GAC7C,KAAK,eAAe;EACtB,CAAC;EAED,OAAO,iBAAiB,UAAU,YAAY;GAC5C,KAAK,eAAe;GACpB,KAAK,YAAY;EACnB,CAAC;CACH;CAEA,IAAI,SAAiB,KAAmB;EACtC,MAAM,OAAO,MAAM,IAAI,SAAS,IAAI;EACpC,OAAO,GAAG,QAAQ,WAAW,KAAK,SAAS,MAAM,OAAO;CAC1D;CAIA,MAAe,OAAO,KAAyB;EAC7C,MAAM,KAAK,YAAY,OAAO,GAAG;EAEjC,IAAI,KAAK,gBAAgB,KAAK,UAC5B,MAAM,MAAM,KAAK,IAAI,KAAK,UAAU,GAAG,GAAG,EACxC,QAAQ,SACV,CAAC;CAEL;CAEA,MAAe,IAAI,KAA+B;EAChD,IAAI,MAAM,KAAK,YAAY,IAAI,GAAG,GAChC,OAAO,MAAM,KAAK,YAAY,IAAI,G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cAAc,OAAO,qBAAqB,CAAC;CAEzD,MAAM,aAAa,OADH,OAAO,OAAO,OAAO,SAAS,UAAU,MAAM,OAAO,uBACzB;CAC5C,OAAO,OAAO,iBAAiB,WAAW,KAAK,CAAC;CAIhD,OAAO,CACL,WAAW,WAAW,YAA6B,UAAU,GAC7D,WAAW,WAAW,WAA4B,CAAA,CAAS,CAC7D;AACF,CAAC,CACH"}
@@ -187,7 +187,7 @@ var upload = async ({ file, blockstore, instances, space }) => {
187
187
  }, {
188
188
  "~LogMeta": "~LogMeta",
189
189
  F: __dxlog_file,
190
- L: 71,
190
+ L: 70,
191
191
  S: void 0
192
192
  });
193
193
  return info;
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-helpers.mjs","names":[],"sources":["../../src/annotations.ts","../../src/helpers/common.ts","../../src/helpers/load.ts","../../src/helpers/wnfs-url.ts","../../src/helpers/upload.ts"],"sourcesContent":["//\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 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 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 readWnfsFile = async ({\n wnfsUrl,\n blockstore,\n forest,\n directory,\n}: {\n wnfsUrl: string;\n blockstore: Blockstore;\n forest: PrivateForest;\n directory: PrivateDirectory;\n}): Promise<Uint8Array> => {\n const path = getPathFromUrl(wnfsUrl);\n const wnfsStore = store(blockstore);\n const { result } = await directory.read(path, true, forest, wnfsStore);\n return result;\n};\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 result = await readWnfsFile({ wnfsUrl, blockstore, forest, directory });\n // `Uint8Array` is generic over `ArrayBufferLike` (incl. `SharedArrayBuffer`) while DOM's\n // `BlobPart` only covers `ArrayBuffer`-backed views — a gap between the DOM lib types and the\n // TS standard lib, not fixable by typing `result` differently.\n const blob = new Blob([result as BlobPart], { type });\n return URL.createObjectURL(blob);\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"],"mappings":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GAAA;EAAA,YAAA;EAAA,GAAA;EAAA,GAAA;EAAA,GAAA,KAAA;CAAA,CAAC;CAC5B,OAAO;AACT"}
1
+ {"version":3,"file":"chunk-helpers.mjs","names":[],"sources":["../../src/annotations.ts","../../src/helpers/common.ts","../../src/helpers/load.ts","../../src/helpers/wnfs-url.ts","../../src/helpers/upload.ts"],"sourcesContent":["//\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 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 { WnfsStateAnnotation } from '../annotations';\nimport type * as WnfsCapabilities from '../types/WnfsCapabilities';\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 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 readWnfsFile = async ({\n wnfsUrl,\n blockstore,\n forest,\n directory,\n}: {\n wnfsUrl: string;\n blockstore: Blockstore;\n forest: PrivateForest;\n directory: PrivateDirectory;\n}): Promise<Uint8Array> => {\n const path = getPathFromUrl(wnfsUrl);\n const wnfsStore = store(blockstore);\n const { result } = await directory.read(path, true, forest, wnfsStore);\n return result;\n};\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 result = await readWnfsFile({ wnfsUrl, blockstore, forest, directory });\n // `Uint8Array` is generic over `ArrayBufferLike` (incl. `SharedArrayBuffer`) while DOM's\n // `BlobPart` only covers `ArrayBuffer`-backed views — a gap between the DOM lib types and the\n // TS standard lib, not fixable by typing `result` differently.\n const blob = new Blob([result as BlobPart], { type });\n return URL.createObjectURL(blob);\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 { WnfsStateAnnotation } from '../annotations';\nimport type * as WnfsCapabilities from '../types/WnfsCapabilities';\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"],"mappings":";;;;;;;;;;;;;AASA,IAAa,sBAAsB,WAAW,KAAK;CACjD,IAAI;CACJ,QAAQ,OAAO,OAAO;EACpB,WAAW,OAAO;EAClB,kBAAkB,OAAO;CAC3B,CAAC;AACH,CAAC;;;ACCD,IAAa,YAAY,UAAkB,UAAiB;CAC1D,OAAO;EAAC;EAAU,MAAM;EAAI;EAAS;CAAQ;AAC/C;AAMA,IAAa,MAAb,MAAiB;CACf,YAAY,OAA2B;EACrC,OAAO,IAAI,WAAW,OAAO,Y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;CAAM,CAAC;CAC7E,MAAM,YAAY,MAAM,UAAU;CAElC,MAAM,QAAQ,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC;CACrD,MAAM,OAAO,MAAM,OAAO,OAAO,KAAK;CACtC,MAAM,MAAM,MAAI,OAAO,GAAG,IAAI,MAAM,IAAI;CAExC,MAAM,OAAO,SAAS,IAAI,SAAS,GAAG,KAAK;CAI3C,MAAM,SAAS,MAAM,UAAU,MAAM,MAAM,MAAM,uBAAO,IAAI,KAAK,GAAG,QAAQ,WAAW,IAAI,IAAI,CAAC;CAIhG,MAAM,CAAC,GAAG,iBAAiB,MAAM,OAAO,QAAQ,MAAM,OAAO,QAAQ,WAAW,IAAI,IAAI,CAAC;CACzF,MAAM,WAAW,MAAM,cAAc,MAAM,SAAS;CAGpD,MAAM,eAAe,WAAW,IAAI,MAAM,YAAY,mBAAmB,CAAC,CAAC,KAAK,OAAO,cAAc;CACrG,IAAI,CAAC,cACH,MAAM,IAAI,MAAM,wEAAwE;CAE1F,IAAI,OAAO,MAAM,aAAa,eAAe;EAC3C,WAAW,IAAI,YAAY,qBAAqB;GAC9C,GAAG;GACH,kBAAkB,MAAI,OAAO,QAAQ,CAAC,CAAC,SAAS;EAClD,CAAC;CACH,CAAC;CAGD,MAAM,OAAO;EACX,MAAM,KAAK;EACX,MAAM,KAAK;EACX,KAAK,QAAQ,IAAI;EACjB,KAAK,IAAI,SAAS;CACpB;CAEA,IAAI,UAAU;EAAE;EAAM;CAAK,GAAA;EAAA,YAAA;EAAA,GAAA;EAAA,GAAA;EAAA,GAAA,KAAA;CAAA,CAAC;CAC5B,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { Plugin } from "@dxos/app-framework";
1
+ import * as Plugin from "@dxos/app-framework/Plugin";
2
2
  import { Config2 } from "@dxos/app-framework/config";
3
3
  import { trim } from "@dxos/util";
4
4
  //#region dx.config.ts
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-meta.mjs","names":[],"sources":["../../dx.config.ts","../../src/meta.ts"],"sourcesContent":["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Config2 } from '@dxos/app-framework/config';\nimport { trim } from '@dxos/util';\n\nexport default Config2.make({\n plugin: {\n key: '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 a \\`BlobBackend\\` on the ECHO Hypergraph (and a matching \\`FileCapabilities.Backend\\`\n descriptor) so any plugin that uses \\`plugin-file\\` (e.g. \\`plugin-studio\\`) can upload files and resolve\n \\`wnfs://\\` URLs without coupling to the storage implementation. The blockstore automatically queues\n blocks while offline and flushes them when connectivity is restored.\n `,\n icon: { key: 'ph--file-cloud--regular', hue: 'teal' },\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n spec: 'PLUGIN.mdl',\n tags: ['labs'],\n dependsOn: ['org.dxos.plugin.file'],\n },\n});\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\n\nimport config from '../dx.config';\n\nexport const meta = Plugin.getMetaFromConfig(config);\n"],"mappings":";;;;AAOA,IAAA,oBAAe,QAAQ,KAAK,EAC1B,QAAQ;CACN,KAAK;CACL,MAAM;CACN,QAAQ;CACR,aAAa,IAAI;;;;;;;;;;;;;;CAcjB,MAAM;EAAE,KAAK;EAA2B,KAAK;CAAO;CACpD,QAAQ;CACR,MAAM;CACN,MAAM,CAAC,MAAM;CACb,WAAW,CAAC,sBAAsB;AACpC,EACF,CAAC;;;ACxBD,IAAa,OAAO,OAAO,kBAAkB,iBAAM"}
1
+ {"version":3,"file":"chunk-meta.mjs","names":[],"sources":["../../dx.config.ts","../../src/meta.ts"],"sourcesContent":["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Config2 } from '@dxos/app-framework/config';\nimport { trim } from '@dxos/util';\n\nexport default Config2.make({\n plugin: {\n key: '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 a \\`BlobBackend\\` on the ECHO Hypergraph (and a matching \\`FileCapabilities.Backend\\`\n descriptor) so any plugin that uses \\`plugin-file\\` (e.g. \\`plugin-studio\\`) can upload files and resolve\n \\`wnfs://\\` URLs without coupling to the storage implementation. The blockstore automatically queues\n blocks while offline and flushes them when connectivity is restored.\n `,\n icon: { key: 'ph--file-cloud--regular', hue: 'teal' },\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n spec: 'PLUGIN.mdl',\n tags: ['labs'],\n dependsOn: ['org.dxos.plugin.file'],\n },\n});\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport * as Plugin from '@dxos/app-framework/Plugin';\n\nimport config from '../dx.config';\n\nexport const meta = Plugin.getMetaFromConfig(config);\n"],"mappings":";;;;AAOA,IAAA,oBAAe,QAAQ,KAAK,EAC1B,QAAQ;CACN,KAAK;CACL,MAAM;CACN,QAAQ;CACR,aAAa,IAAI;;;;;;;;;;;;;;CAcjB,MAAM;EAAE,KAAK;EAA2B,KAAK;CAAO;CACpD,QAAQ;CACR,MAAM;CACN,MAAM,CAAC,MAAM;CACb,WAAW,CAAC,sBAAsB;AACpC,EACF,CAAC;;;ACxBD,IAAa,OAAO,OAAO,kBAAkB,iBAAM"}
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };
@@ -1,4 +1,5 @@
1
- import { n as WnfsCapabilities_exports, t as WnfsEvents_exports } from "./chunk-types.mjs";
2
1
  import { a as wnfsUrl, c as filePath, d as storeName, f as WnfsStateAnnotation, i as readWnfsFile, l as readFile, n as getBlobUrl, o as loadWnfs, r as getPathFromUrl, s as Rng, t as upload, u as store } from "./chunk-helpers.mjs";
3
2
  import { t as meta } from "./chunk-meta.mjs";
3
+ import { t as WnfsCapabilities_exports } from "./WnfsCapabilities.mjs";
4
+ import { t as WnfsEvents_exports } from "./WnfsEvents.mjs";
4
5
  export { Rng, WnfsCapabilities_exports as WnfsCapabilities, WnfsEvents_exports as WnfsEvents, WnfsStateAnnotation, filePath, getBlobUrl, getPathFromUrl, loadWnfs, meta, readFile, readWnfsFile, store, storeName, upload, wnfsUrl };
@@ -1,5 +1,5 @@
1
1
  import { t as meta } from "./chunk-meta.mjs";
2
- import { Plugin } from "@dxos/app-framework";
2
+ import * as Plugin from "@dxos/app-framework/Plugin";
3
3
  //#region src/plugin.ts
4
4
  var WnfsPlugin = Plugin.lazy(meta, () => import("#plugin"));
5
5
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/plugin.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\n\nimport { meta } from './meta';\n\nexport const WnfsPlugin = Plugin.lazy(meta, () => import('#plugin'));\n"],"mappings":";;;AAQA,IAAa,aAAa,OAAO,KAAK,YAAY,OAAO,UAAU"}
1
+ {"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/plugin.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Plugin from '@dxos/app-framework/Plugin';\n\nimport { meta } from './meta';\n\nexport const WnfsPlugin = Plugin.lazy(meta, () => import('#plugin'));\n"],"mappings":";;;AAQA,IAAa,aAAa,OAAO,KAAK,YAAY,OAAO,UAAU"}
@@ -1,4 +1,4 @@
1
- import { Plugin } from '@dxos/app-framework';
1
+ import * as Plugin from '@dxos/app-framework/Plugin';
2
2
  export declare const WnfsPlugin: Plugin.PluginFactory<void>;
3
3
  export default WnfsPlugin;
4
4
  //# sourceMappingURL=WnfsPlugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WnfsPlugin.d.ts","sourceRoot":"","sources":["../../../src/WnfsPlugin.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAY7C,eAAO,MAAM,UAAU,4BAiBtB,CAAC;eAEa,UAAU"}
1
+ {"version":3,"file":"WnfsPlugin.d.ts","sourceRoot":"","sources":["../../../src/WnfsPlugin.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AAUrD,eAAO,MAAM,UAAU,4BAatB,CAAC;eAEa,UAAU"}
@@ -1,4 +1,4 @@
1
- import { Plugin } from '@dxos/app-framework';
1
+ import * as Plugin from '@dxos/app-framework/Plugin';
2
2
  export declare const WnfsPlugin: Plugin.PluginFactory<void>;
3
3
  export default WnfsPlugin;
4
4
  //# sourceMappingURL=WnfsPlugin.node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WnfsPlugin.node.d.ts","sourceRoot":"","sources":["../../../src/WnfsPlugin.node.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAI7C,eAAO,MAAM,UAAU,4BAAwC,CAAC;eAEjD,UAAU"}
1
+ {"version":3,"file":"WnfsPlugin.node.d.ts","sourceRoot":"","sources":["../../../src/WnfsPlugin.node.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AAIrD,eAAO,MAAM,UAAU,4BAAwC,CAAC;eAEjD,UAAU"}
@@ -1,4 +1,4 @@
1
- import { Plugin } from '@dxos/app-framework';
1
+ import * as Plugin from '@dxos/app-framework/Plugin';
2
2
  export declare const WnfsPlugin: Plugin.PluginFactory<void>;
3
3
  export default WnfsPlugin;
4
4
  //# sourceMappingURL=WnfsPlugin.workerd.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WnfsPlugin.workerd.d.ts","sourceRoot":"","sources":["../../../src/WnfsPlugin.workerd.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAI7C,eAAO,MAAM,UAAU,4BAAwC,CAAC;eAEjD,UAAU"}
1
+ {"version":3,"file":"WnfsPlugin.workerd.d.ts","sourceRoot":"","sources":["../../../src/WnfsPlugin.workerd.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AAIrD,eAAO,MAAM,UAAU,4BAAwC,CAAC;eAEjD,UAAU"}
@@ -1,9 +1,9 @@
1
1
  import * as Effect from 'effect/Effect';
2
2
  import type { Blockstore } from 'interface-blockstore';
3
- import { Capability } from '@dxos/app-framework';
3
+ import * as Capability from '@dxos/app-framework/Capability';
4
4
  import { type Client } from '@dxos/client';
5
5
  import { type BlobBackend } from '@dxos/echo-protocol';
6
- import { WnfsCapabilities } from '#types';
6
+ import * as WnfsCapabilities from '../types/WnfsCapabilities';
7
7
  interface CreateWnfsBlobBackendOptions {
8
8
  client: Client;
9
9
  blockstore: Blockstore;
@@ -17,6 +17,6 @@ interface CreateWnfsBlobBackendOptions {
17
17
  * missing-file path.
18
18
  */
19
19
  export declare const createWnfsBlobBackend: ({ client, blockstore, instances }: CreateWnfsBlobBackendOptions) => BlobBackend;
20
- declare const _default: (props: void) => Effect.Effect<Capability.Any, Error, import("effect/Scope").Scope | Capability.Service>;
20
+ declare const _default: (props: void) => Effect.Effect<Capability.Contribution<Capability.CapabilityIdentifier<`${string}.capability.backend`, "multi">>, never, Capability.CapabilityIdentifier<`${string}.capability.blockstore`, "single"> | Capability.CapabilityIdentifier<`${string}.capability.client`, "single"> | Capability.CapabilityIdentifier<`${string}.capability.instances`, "single"> | import("effect/Scope").Scope>;
21
21
  export default _default;
22
22
  //# sourceMappingURL=blob-backend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"blob-backend.d.ts","sourceRoot":"","sources":["../../../../src/capabilities/blob-backend.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAOvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAI1C,UAAU,4BAA4B;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC;CACxC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,sCAAuC,4BAA4B,KAAG,WA+CvG,CAAC"}
1
+ {"version":3,"file":"blob-backend.d.ts","sourceRoot":"","sources":["../../../../src/capabilities/blob-backend.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,KAAK,UAAU,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAQvD,OAAO,KAAK,gBAAgB,MAAM,2BAA2B,CAAC;AAE9D,UAAU,4BAA4B;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC;CACxC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,sCAAuC,4BAA4B,KAAG,WA+CvG,CAAC"}