@dxos/plugin-wnfs 0.8.3 → 0.8.4-main.f9ba587

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 (66) hide show
  1. package/dist/lib/browser/{FileContainer-7YOCEQ6P.mjs → FileContainer-Q4GUPBVD.mjs} +12 -11
  2. package/dist/lib/browser/FileContainer-Q4GUPBVD.mjs.map +7 -0
  3. package/dist/lib/browser/{blockstore-UT7233RJ.mjs → blockstore-KQO2NTVM.mjs} +7 -7
  4. package/dist/lib/browser/chunk-BANMVVJV.mjs +16 -0
  5. package/dist/lib/browser/{chunk-SCL6PT4P.mjs → chunk-GVBV2QWA.mjs} +4 -4
  6. package/dist/lib/browser/{chunk-DL7BBH57.mjs → chunk-KZANQHJY.mjs} +3 -3
  7. package/dist/lib/browser/{chunk-PHTWWADN.mjs → chunk-VDDGZWAY.mjs} +2 -2
  8. package/dist/lib/browser/{chunk-YYAW4U6J.mjs → chunk-VRRXG6IB.mjs} +6 -6
  9. package/dist/lib/browser/{file-uploader-RHINBPDQ.mjs → file-uploader-JA55DPMW.mjs} +4 -4
  10. package/dist/lib/browser/index.mjs +10 -10
  11. package/dist/lib/browser/index.mjs.map +3 -3
  12. package/dist/lib/browser/{intent-resolver-JDRRPIZC.mjs → intent-resolver-YM6QRFIH.mjs} +6 -6
  13. package/dist/lib/browser/{markdown-BWBHUHHH.mjs → markdown-6VH477GB.mjs} +7 -7
  14. package/dist/lib/browser/meta.json +1 -1
  15. package/dist/lib/browser/{react-surface-6GM4J4YG.mjs → react-surface-XAHVMWIH.mjs} +9 -9
  16. package/dist/lib/browser/types/index.mjs +2 -2
  17. package/dist/lib/node-esm/FileContainer-22IPNDDA.mjs +108 -0
  18. package/dist/lib/node-esm/FileContainer-22IPNDDA.mjs.map +7 -0
  19. package/dist/lib/node-esm/blockstore-7KQTFHK5.mjs +192 -0
  20. package/dist/lib/node-esm/blockstore-7KQTFHK5.mjs.map +7 -0
  21. package/dist/lib/node-esm/chunk-47QYKNA6.mjs +17 -0
  22. package/dist/lib/node-esm/chunk-47QYKNA6.mjs.map +7 -0
  23. package/dist/lib/node-esm/chunk-BM37ZAHF.mjs +65 -0
  24. package/dist/lib/node-esm/chunk-BM37ZAHF.mjs.map +7 -0
  25. package/dist/lib/node-esm/chunk-CGW32EZB.mjs +161 -0
  26. package/dist/lib/node-esm/chunk-CGW32EZB.mjs.map +7 -0
  27. package/dist/lib/node-esm/chunk-DWYM7FD7.mjs +18 -0
  28. package/dist/lib/node-esm/chunk-DWYM7FD7.mjs.map +7 -0
  29. package/dist/lib/node-esm/chunk-YTWL64Z6.mjs +17 -0
  30. package/dist/lib/node-esm/chunk-YTWL64Z6.mjs.map +7 -0
  31. package/dist/lib/node-esm/file-uploader-WGDG2YV5.mjs +30 -0
  32. package/dist/lib/node-esm/file-uploader-WGDG2YV5.mjs.map +7 -0
  33. package/dist/lib/node-esm/index.mjs +117 -0
  34. package/dist/lib/node-esm/index.mjs.map +7 -0
  35. package/dist/lib/node-esm/intent-resolver-5QOT2SLD.mjs +50 -0
  36. package/dist/lib/node-esm/intent-resolver-5QOT2SLD.mjs.map +7 -0
  37. package/dist/lib/node-esm/markdown-R4PBXDJO.mjs +197 -0
  38. package/dist/lib/node-esm/markdown-R4PBXDJO.mjs.map +7 -0
  39. package/dist/lib/node-esm/meta.json +1 -0
  40. package/dist/lib/node-esm/react-surface-HAOUJUXJ.mjs +89 -0
  41. package/dist/lib/node-esm/react-surface-HAOUJUXJ.mjs.map +7 -0
  42. package/dist/lib/node-esm/types/index.mjs +11 -0
  43. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  44. package/dist/types/src/components/FileContainer.d.ts +4 -3
  45. package/dist/types/src/components/FileContainer.d.ts.map +1 -1
  46. package/dist/types/src/components/index.d.ts +1 -4
  47. package/dist/types/src/components/index.d.ts.map +1 -1
  48. package/dist/types/src/translations.d.ts +11 -11
  49. package/dist/types/src/translations.d.ts.map +1 -1
  50. package/dist/types/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +24 -26
  52. package/src/WnfsPlugin.tsx +1 -1
  53. package/src/components/FileContainer.tsx +6 -1
  54. package/src/translations.ts +6 -4
  55. package/dist/lib/browser/FileContainer-7YOCEQ6P.mjs.map +0 -7
  56. package/dist/lib/browser/chunk-WJVYRUYQ.mjs +0 -16
  57. /package/dist/lib/browser/{blockstore-UT7233RJ.mjs.map → blockstore-KQO2NTVM.mjs.map} +0 -0
  58. /package/dist/lib/browser/{chunk-WJVYRUYQ.mjs.map → chunk-BANMVVJV.mjs.map} +0 -0
  59. /package/dist/lib/browser/{chunk-SCL6PT4P.mjs.map → chunk-GVBV2QWA.mjs.map} +0 -0
  60. /package/dist/lib/browser/{chunk-DL7BBH57.mjs.map → chunk-KZANQHJY.mjs.map} +0 -0
  61. /package/dist/lib/browser/{chunk-PHTWWADN.mjs.map → chunk-VDDGZWAY.mjs.map} +0 -0
  62. /package/dist/lib/browser/{chunk-YYAW4U6J.mjs.map → chunk-VRRXG6IB.mjs.map} +0 -0
  63. /package/dist/lib/browser/{file-uploader-RHINBPDQ.mjs.map → file-uploader-JA55DPMW.mjs.map} +0 -0
  64. /package/dist/lib/browser/{intent-resolver-JDRRPIZC.mjs.map → intent-resolver-YM6QRFIH.mjs.map} +0 -0
  65. /package/dist/lib/browser/{markdown-BWBHUHHH.mjs.map → markdown-6VH477GB.mjs.map} +0 -0
  66. /package/dist/lib/browser/{react-surface-6GM4J4YG.mjs.map → react-surface-XAHVMWIH.mjs.map} +0 -0
@@ -0,0 +1,65 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ WNFS_PLUGIN
4
+ } from "./chunk-47QYKNA6.mjs";
5
+
6
+ // src/types/file.ts
7
+ import { Schema } from "effect";
8
+ import { TypedObject } from "@dxos/echo-schema";
9
+ var FileType = class extends TypedObject({
10
+ typename: "dxos.org/type/File",
11
+ version: "0.1.0"
12
+ })({
13
+ name: Schema.optional(Schema.String),
14
+ type: Schema.String,
15
+ cid: Schema.String,
16
+ timestamp: Schema.optional(Schema.String)
17
+ }) {
18
+ };
19
+
20
+ // src/types/types.ts
21
+ import { Schema as Schema2 } from "effect";
22
+ import { FileInfoSchema } from "@dxos/app-framework";
23
+ import { SpaceSchema } from "@dxos/react-client/echo";
24
+ (function(WnfsAction2) {
25
+ class Create extends Schema2.TaggedClass()(`${WNFS_PLUGIN}/action/create`, {
26
+ input: FileInfoSchema.pick("name", "type", "cid").pipe(Schema2.required),
27
+ output: Schema2.Struct({
28
+ object: FileType
29
+ })
30
+ }) {
31
+ }
32
+ WnfsAction2.Create = Create;
33
+ WnfsAction2.UploadAnnotationId = Symbol.for(`${WNFS_PLUGIN}/annotation/upload`);
34
+ WnfsAction2.UploadFileSchema = Schema2.Struct({
35
+ file: Schema2.instanceOf(File).annotations({
36
+ [WnfsAction2.UploadAnnotationId]: {
37
+ // Accept file types.
38
+ "image/*": [
39
+ ".jpg",
40
+ ".jpeg",
41
+ ".png",
42
+ ".gif"
43
+ ],
44
+ "application/pdf": [
45
+ ".pdf"
46
+ ]
47
+ }
48
+ })
49
+ });
50
+ class Upload extends Schema2.TaggedClass()(`${WNFS_PLUGIN}/action/upload`, {
51
+ input: Schema2.extend(WnfsAction2.UploadFileSchema, Schema2.Struct({
52
+ space: SpaceSchema
53
+ })),
54
+ output: Schema2.required(FileInfoSchema)
55
+ }) {
56
+ }
57
+ WnfsAction2.Upload = Upload;
58
+ })(WnfsAction || (WnfsAction = {}));
59
+ var WnfsAction;
60
+
61
+ export {
62
+ FileType,
63
+ WnfsAction
64
+ };
65
+ //# sourceMappingURL=chunk-BM37ZAHF.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types/file.ts", "../../../src/types/types.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { TypedObject } from '@dxos/echo-schema';\n\nexport class FileType extends TypedObject({\n typename: 'dxos.org/type/File',\n version: '0.1.0',\n})({\n name: Schema.optional(Schema.String),\n type: Schema.String,\n cid: Schema.String,\n timestamp: Schema.optional(Schema.String),\n}) {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { FileInfoSchema } from '@dxos/app-framework';\nimport { SpaceSchema } from '@dxos/react-client/echo';\n\nimport { FileType } from './file';\nimport { WNFS_PLUGIN } from '../meta';\n\nexport namespace WnfsAction {\n export class Create extends Schema.TaggedClass<Create>()(`${WNFS_PLUGIN}/action/create`, {\n input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),\n output: Schema.Struct({\n object: FileType,\n }),\n }) {}\n\n export const UploadAnnotationId = Symbol.for(`${WNFS_PLUGIN}/annotation/upload`);\n\n export const UploadFileSchema = Schema.Struct({\n file: Schema.instanceOf(File).annotations({\n [UploadAnnotationId]: {\n // Accept file types.\n 'image/*': ['.jpg', '.jpeg', '.png', '.gif'],\n 'application/pdf': ['.pdf'],\n // TODO(wittjosiah): Add more file types.\n },\n }),\n });\n\n export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;\n\n export class Upload extends Schema.TaggedClass<Upload>()(`${WNFS_PLUGIN}/action/upload`, {\n input: Schema.extend(UploadFileSchema, Schema.Struct({ space: SpaceSchema })),\n output: Schema.required(FileInfoSchema),\n }) {}\n}\n"],
5
+ "mappings": ";;;;;;AAIA,SAASA,cAAc;AAEvB,SAASC,mBAAmB;AAErB,IAAMC,WAAN,cAAuBC,YAAY;EACxCC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,MAAMC,OAAOC,SAASD,OAAOE,MAAM;EACnCC,MAAMH,OAAOE;EACbE,KAAKJ,OAAOE;EACZG,WAAWL,OAAOC,SAASD,OAAOE,MAAM;AAC1C,CAAA,EAAA;AAAI;;;ACZJ,SAASI,UAAAA,eAAc;AAEvB,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB;UAKXC,aAAAA;EACR,MAAMC,eAAeC,QAAOC,YAAW,EAAW,GAAGC,WAAAA,kBAA6B;IACvFC,OAAOC,eAAeC,KAAK,QAAQ,QAAQ,KAAA,EAAOC,KAAKN,QAAOO,QAAQ;IACtEC,QAAQR,QAAOS,OAAO;MACpBC,QAAQC;IACV,CAAA;EACF,CAAA,EAAA;EAAI;cALSZ,SAAAA;cAOAa,qBAAqBC,OAAOC,IAAI,GAAGZ,WAAAA,oBAA+B;cAElEa,mBAAmBf,QAAOS,OAAO;IAC5CO,MAAMhB,QAAOiB,WAAWC,IAAAA,EAAMC,YAAY;MACxC,CAAArB,YAACc,kBAAAA,GAAqB;;QAEpB,WAAW;UAAC;UAAQ;UAAS;UAAQ;;QACrC,mBAAmB;UAAC;;MAEtB;IACF,CAAA;EACF,CAAA;EAIO,MAAMQ,eAAepB,QAAOC,YAAW,EAAW,GAAGC,WAAAA,kBAA6B;IACvFC,OAAOH,QAAOqB,OAAMvB,YAACiB,kBAAkBf,QAAOS,OAAO;MAAEa,OAAOC;IAAY,CAAA,CAAA;IAC1Ef,QAAQR,QAAOO,SAASH,cAAAA;EAC1B,CAAA,EAAA;EAAI;cAHSgB,SAAAA;AAIf,GA3BiBtB,eAAAA,aAAAA,CAAAA,EAAAA;;",
6
+ "names": ["Schema", "TypedObject", "FileType", "TypedObject", "typename", "version", "name", "Schema", "optional", "String", "type", "cid", "timestamp", "Schema", "FileInfoSchema", "SpaceSchema", "WnfsAction", "Create", "Schema", "TaggedClass", "WNFS_PLUGIN", "input", "FileInfoSchema", "pick", "pipe", "required", "output", "Struct", "object", "FileType", "UploadAnnotationId", "Symbol", "for", "UploadFileSchema", "file", "instanceOf", "File", "annotations", "Upload", "extend", "space", "SpaceSchema"]
7
+ }
@@ -0,0 +1,161 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/helpers/common.ts
4
+ import { CID } from "multiformats/cid";
5
+ import { sha256 } from "multiformats/hashes/sha2";
6
+ import * as crypto from "@dxos/crypto";
7
+ var filePath = (fileName, space) => {
8
+ return [
9
+ "spaces",
10
+ space.id,
11
+ "files",
12
+ fileName
13
+ ];
14
+ };
15
+ var Rng = class {
16
+ randomBytes(count) {
17
+ return new Uint8Array(crypto.randomBytes(count));
18
+ }
19
+ };
20
+ var store = (blockstore) => {
21
+ const getBlock = async (cid) => {
22
+ const decodedCid = CID.decode(cid);
23
+ return await blockstore.get(decodedCid);
24
+ };
25
+ const hasBlock = async (cid) => {
26
+ const decodedCid = CID.decode(cid);
27
+ return await blockstore.has(decodedCid);
28
+ };
29
+ const putBlockKeyed = async (cid, bytes) => {
30
+ const decodedCid = CID.decode(cid);
31
+ await blockstore.put(decodedCid, bytes);
32
+ };
33
+ const putBlock = async (bytes, codec) => {
34
+ const hash = await sha256.digest(bytes);
35
+ const cid = CID.create(1, codec, hash);
36
+ await blockstore.put(cid, bytes);
37
+ return cid.bytes;
38
+ };
39
+ return {
40
+ getBlock,
41
+ hasBlock,
42
+ putBlockKeyed,
43
+ putBlock
44
+ };
45
+ };
46
+ var storeName = () => "dxos/wnfs";
47
+
48
+ // src/helpers/load.ts
49
+ import { CID as CID2 } from "multiformats";
50
+ import * as Uint8Arrays from "uint8arrays";
51
+ import { AccessKey, PrivateForest, PrivateDirectory, PrivateNode } from "wnfs";
52
+ var loadWnfs = async ({ space, blockstore, instances }) => {
53
+ if (space.properties.wnfs_access_key !== void 0 && space.properties.wnfs_private_forest_cid !== void 0) {
54
+ delete space.properties.wnfs_access_key;
55
+ delete space.properties.wnfs_private_forest_cid;
56
+ }
57
+ const cacheKey = space.properties.wnfs?.privateForestCid;
58
+ if (instances?.[cacheKey]) {
59
+ return instances[cacheKey];
60
+ }
61
+ const exists = !!space.properties.wnfs;
62
+ const instance = exists ? await loadWnfsDir(blockstore, space) : await createWnfsDir(blockstore, space);
63
+ if (instances) {
64
+ instances[cacheKey] = instance;
65
+ }
66
+ return instance;
67
+ };
68
+ var createWnfsDir = async (blockstore, space) => {
69
+ const wnfsStore = store(blockstore);
70
+ const rng = new Rng();
71
+ const forest = new PrivateForest(rng);
72
+ const dirResult = await PrivateDirectory.newAndStore(forest.emptyName(), /* @__PURE__ */ new Date(), forest, wnfsStore, rng);
73
+ const dir = dirResult.rootDir;
74
+ const [accessKeyRaw, newForest] = await dir.asNode().store(dirResult.forest, wnfsStore, rng);
75
+ const cidBytes = await newForest.store(wnfsStore);
76
+ space.properties.wnfs = {
77
+ accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), "base64"),
78
+ privateForestCid: CID2.decode(cidBytes).toString()
79
+ };
80
+ return {
81
+ directory: dir,
82
+ forest: newForest
83
+ };
84
+ };
85
+ var loadWnfsDir = async (blockstore, space) => {
86
+ const wnfsStore = store(blockstore);
87
+ const accessKey = AccessKey.fromBytes(Uint8Arrays.fromString(space.properties.wnfs.accessKey, "base64"));
88
+ const forest = await PrivateForest.load(CID2.parse(space.properties.wnfs.privateForestCid).bytes, wnfsStore);
89
+ const node = await PrivateNode.load(accessKey, forest, wnfsStore);
90
+ return {
91
+ directory: node.asDir(),
92
+ forest
93
+ };
94
+ };
95
+
96
+ // src/helpers/wnfs-url.ts
97
+ var wnfsUrl = (filePath2) => {
98
+ return "wnfs://" + filePath2.map((f) => encodeURIComponent(f)).join("/");
99
+ };
100
+ var getPathFromUrl = (wnfsUrl2) => wnfsUrl2.replace(/^wnfs:\/\//, "").split("/").map((p) => decodeURIComponent(p));
101
+ var getBlobUrl = async ({ wnfsUrl: wnfsUrl2, blockstore, forest, directory, type }) => {
102
+ const path = getPathFromUrl(wnfsUrl2);
103
+ const wnfsStore = store(blockstore);
104
+ const { result } = await directory.read(path, true, forest, wnfsStore);
105
+ const blob = new Blob([
106
+ result
107
+ ], {
108
+ type
109
+ });
110
+ return URL.createObjectURL(blob);
111
+ };
112
+
113
+ // src/helpers/upload.ts
114
+ import { CID as CID3 } from "multiformats";
115
+ import * as Raw from "multiformats/codecs/raw";
116
+ import { sha256 as sha2562 } from "multiformats/hashes/sha2";
117
+ import { log } from "@dxos/log";
118
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/helpers/upload.ts";
119
+ var upload = async ({ file, blockstore, instances, space }) => {
120
+ const { directory, forest } = await loadWnfs({
121
+ blockstore,
122
+ instances,
123
+ space
124
+ });
125
+ const wnfsStore = store(blockstore);
126
+ const bytes = new Uint8Array(await file.arrayBuffer());
127
+ const hash = await sha2562.digest(bytes);
128
+ const cid = CID3.create(1, Raw.code, hash);
129
+ const path = filePath(cid.toString(), space);
130
+ const result = await directory.write(path, true, bytes, /* @__PURE__ */ new Date(), forest, wnfsStore, new Rng());
131
+ const [_, updatedForest] = await result.rootDir.store(result.forest, wnfsStore, new Rng());
132
+ const cidBytes = await updatedForest.store(wnfsStore);
133
+ space.properties.wnfs.privateForestCid = CID3.decode(cidBytes).toString();
134
+ const info = {
135
+ name: file.name,
136
+ type: file.type,
137
+ url: wnfsUrl(path),
138
+ cid: cid.toString()
139
+ };
140
+ log("upload", {
141
+ file,
142
+ info
143
+ }, {
144
+ F: __dxlog_file,
145
+ L: 58,
146
+ S: void 0,
147
+ C: (f, a) => f(...a)
148
+ });
149
+ return info;
150
+ };
151
+
152
+ export {
153
+ filePath,
154
+ storeName,
155
+ loadWnfs,
156
+ wnfsUrl,
157
+ getPathFromUrl,
158
+ getBlobUrl,
159
+ upload
160
+ };
161
+ //# sourceMappingURL=chunk-CGW32EZB.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/common.ts", "../../../src/helpers/load.ts", "../../../src/helpers/wnfs-url.ts", "../../../src/helpers/upload.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats/cid';\nimport { sha256 } from 'multiformats/hashes/sha2';\nimport { type BlockStore as WnfsBlockStore } from 'wnfs';\n\nimport * as crypto from '@dxos/crypto';\nimport { type Space } from '@dxos/react-client/echo';\n\n//\n// PATH\n//\n\nexport const filePath = (fileName: string, space: Space) => {\n return ['spaces', space.id, 'files', fileName];\n};\n\n//\n// RNG\n//\n\nexport class Rng {\n randomBytes(count: number): Uint8Array {\n return new Uint8Array(crypto.randomBytes(count));\n }\n}\n\n//\n// STORE\n//\n\nexport const store = (blockstore: Blockstore): WnfsBlockStore => {\n const getBlock = async (cid: Uint8Array): Promise<Uint8Array | undefined> => {\n const decodedCid = CID.decode(cid);\n return await blockstore.get(decodedCid);\n };\n\n const hasBlock = async (cid: Uint8Array): Promise<boolean> => {\n const decodedCid = CID.decode(cid);\n return await blockstore.has(decodedCid);\n };\n\n const putBlockKeyed = async (cid: Uint8Array, bytes: Uint8Array): Promise<void> => {\n const decodedCid = CID.decode(cid);\n await blockstore.put(decodedCid, bytes);\n };\n\n // Don't hash blocks with the rs-wnfs default Blake 3, sha256 has better support.\n const putBlock = async (bytes: Uint8Array, codec: number): Promise<Uint8Array> => {\n const hash = await sha256.digest(bytes);\n const cid = CID.create(1, codec, hash);\n await blockstore.put(cid, bytes);\n return cid.bytes;\n };\n\n return { getBlock, hasBlock, putBlockKeyed, putBlock };\n};\n\nexport const storeName = () => 'dxos/wnfs';\n\n//\n// OTHER\n//\n\nexport const readFile = (file: File): Promise<Uint8Array> => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = (event) => {\n const result = event.target?.result;\n if (result === null || result === undefined || typeof result === 'string') {\n reject(new Error('Expected an ArrayBuffer'));\n return;\n }\n resolve(new Uint8Array(result));\n };\n reader.onerror = (err) => {\n reject(err);\n };\n reader.readAsArrayBuffer(file);\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats';\nimport * as Uint8Arrays from 'uint8arrays';\nimport { AccessKey, PrivateForest, PrivateDirectory, PrivateNode } from 'wnfs';\n\nimport { type Space } from '@dxos/react-client/echo';\n\nimport { Rng, store } from './common';\nimport { type WnfsCapabilities } from '../capabilities';\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.\n if (space.properties.wnfs_access_key !== undefined && space.properties.wnfs_private_forest_cid !== undefined) {\n delete space.properties.wnfs_access_key;\n delete space.properties.wnfs_private_forest_cid;\n }\n\n const cacheKey = space.properties.wnfs?.privateForestCid;\n if (instances?.[cacheKey]) {\n return instances[cacheKey];\n }\n\n const exists = !!space.properties.wnfs;\n const instance = exists ? await loadWnfsDir(blockstore, space) : await createWnfsDir(blockstore, space);\n if (instances) {\n instances[cacheKey] = instance;\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 space.properties.wnfs = {\n accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),\n privateForestCid: CID.decode(cidBytes).toString(),\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 accessKey = AccessKey.fromBytes(Uint8Arrays.fromString(space.properties.wnfs.accessKey, 'base64'));\n const forest: PrivateForest = await PrivateForest.load(\n CID.parse(space.properties.wnfs.privateForestCid).bytes,\n wnfsStore,\n );\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 getBlobUrl = async ({\n wnfsUrl,\n blockstore,\n forest,\n directory,\n type,\n}: {\n wnfsUrl: string;\n blockstore: Blockstore;\n forest: PrivateForest;\n directory: PrivateDirectory;\n type?: string;\n}) => {\n const path = getPathFromUrl(wnfsUrl);\n const wnfsStore = store(blockstore);\n const { result } = await directory.read(path, true, forest, wnfsStore);\n const blob = new Blob([result], { type });\n return URL.createObjectURL(blob);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\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 { log } from '@dxos/log';\n\nimport { Rng, filePath, store } from './common';\nimport { loadWnfs } from './load';\nimport { wnfsUrl } from './wnfs-url';\nimport { type WnfsCapabilities } from '../capabilities';\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 space.properties.wnfs.privateForestCid = CID.decode(cidBytes).toString();\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"],
5
+ "mappings": "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",
6
+ "names": ["CID", "sha256", "crypto", "filePath", "fileName", "space", "id", "Rng", "randomBytes", "count", "Uint8Array", "store", "blockstore", "getBlock", "cid", "decodedCid", "CID", "decode", "get", "hasBlock", "has", "putBlockKeyed", "bytes", "put", "putBlock", "codec", "hash", "sha256", "digest", "create", "storeName", "CID", "Uint8Arrays", "AccessKey", "PrivateForest", "PrivateDirectory", "PrivateNode", "loadWnfs", "space", "blockstore", "instances", "properties", "wnfs_access_key", "undefined", "wnfs_private_forest_cid", "cacheKey", "wnfs", "privateForestCid", "exists", "instance", "loadWnfsDir", "createWnfsDir", "wnfsStore", "store", "rng", "Rng", "forest", "PrivateForest", "dirResult", "PrivateDirectory", "newAndStore", "emptyName", "Date", "dir", "rootDir", "accessKeyRaw", "newForest", "asNode", "cidBytes", "accessKey", "toString", "toBytes", "CID", "decode", "directory", "AccessKey", "fromBytes", "fromString", "load", "parse", "bytes", "node", "PrivateNode", "asDir", "wnfsUrl", "filePath", "map", "f", "encodeURIComponent", "join", "getPathFromUrl", "replace", "split", "p", "decodeURIComponent", "getBlobUrl", "blockstore", "forest", "directory", "type", "path", "wnfsStore", "store", "result", "read", "blob", "Blob", "URL", "createObjectURL", "CID", "Raw", "sha256", "log", "upload", "file", "blockstore", "instances", "space", "directory", "forest", "loadWnfs", "wnfsStore", "store", "bytes", "Uint8Array", "arrayBuffer", "hash", "sha256", "digest", "cid", "CID", "create", "code", "path", "filePath", "toString", "result", "write", "Date", "Rng", "_", "updatedForest", "rootDir", "cidBytes", "properties", "wnfs", "privateForestCid", "decode", "info", "name", "type", "url", "wnfsUrl", "log"]
7
+ }
@@ -0,0 +1,18 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/capabilities/index.ts
4
+ import { lazy } from "@dxos/app-framework";
5
+ var Blockstore = lazy(() => import("./blockstore-7KQTFHK5.mjs"));
6
+ var FileUploader = lazy(() => import("./file-uploader-WGDG2YV5.mjs"));
7
+ var IntentResolver = lazy(() => import("./intent-resolver-5QOT2SLD.mjs"));
8
+ var Markdown = lazy(() => import("./markdown-R4PBXDJO.mjs"));
9
+ var ReactSurface = lazy(() => import("./react-surface-HAOUJUXJ.mjs"));
10
+
11
+ export {
12
+ Blockstore,
13
+ FileUploader,
14
+ IntentResolver,
15
+ Markdown,
16
+ ReactSurface
17
+ };
18
+ //# sourceMappingURL=chunk-DWYM7FD7.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/capabilities/index.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { lazy } from '@dxos/app-framework';\n\nexport const Blockstore = lazy(() => import('./blockstore'));\nexport const FileUploader = lazy(() => import('./file-uploader'));\nexport const IntentResolver = lazy(() => import('./intent-resolver'));\nexport const Markdown = lazy(() => import('./markdown'));\nexport const ReactSurface = lazy(() => import('./react-surface'));\n\nexport * from './capabilities';\n"],
5
+ "mappings": ";;;AAIA,SAASA,YAAY;AAEd,IAAMC,aAAaC,KAAK,MAAM,OAAO,2BAAA,CAAA;AACrC,IAAMC,eAAeD,KAAK,MAAM,OAAO,8BAAA,CAAA;AACvC,IAAME,iBAAiBF,KAAK,MAAM,OAAO,gCAAA,CAAA;AACzC,IAAMG,WAAWH,KAAK,MAAM,OAAO,yBAAA,CAAA;AACnC,IAAMI,eAAeJ,KAAK,MAAM,OAAO,8BAAA,CAAA;",
6
+ "names": ["lazy", "Blockstore", "lazy", "FileUploader", "IntentResolver", "Markdown", "ReactSurface"]
7
+ }
@@ -0,0 +1,17 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ WNFS_PLUGIN
4
+ } from "./chunk-47QYKNA6.mjs";
5
+
6
+ // src/capabilities/capabilities.ts
7
+ import { defineCapability } from "@dxos/app-framework";
8
+ (function(WnfsCapabilities2) {
9
+ WnfsCapabilities2.Blockstore = defineCapability(`${WNFS_PLUGIN}/capability/blockstore`);
10
+ WnfsCapabilities2.Instances = defineCapability(`${WNFS_PLUGIN}/capability/instances`);
11
+ })(WnfsCapabilities || (WnfsCapabilities = {}));
12
+ var WnfsCapabilities;
13
+
14
+ export {
15
+ WnfsCapabilities
16
+ };
17
+ //# sourceMappingURL=chunk-YTWL64Z6.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/capabilities/capabilities.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Blockstore } from 'interface-blockstore';\nimport { type PrivateDirectory, type PrivateForest } from 'wnfs';\n\nimport { defineCapability } from '@dxos/app-framework';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { WNFS_PLUGIN } from '../meta';\n\nexport namespace WnfsCapabilities {\n export const Blockstore = defineCapability<Blockstore>(`${WNFS_PLUGIN}/capability/blockstore`);\n\n export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;\n export const Instances = defineCapability<Instances>(`${WNFS_PLUGIN}/capability/instances`);\n}\n"],
5
+ "mappings": ";;;;;;AAOA,SAASA,wBAAwB;UAKhBC,mBAAAA;oBACFC,aAAaC,iBAA6B,GAAGC,WAAAA,wBAAmC;oBAGhFC,YAAYF,iBAA4B,GAAGC,WAAAA,uBAAkC;AAC5F,GALiBH,qBAAAA,mBAAAA,CAAAA,EAAAA;;",
6
+ "names": ["defineCapability", "WnfsCapabilities", "Blockstore", "defineCapability", "WNFS_PLUGIN", "Instances"]
7
+ }
@@ -0,0 +1,30 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ WnfsAction
4
+ } from "./chunk-BM37ZAHF.mjs";
5
+ import "./chunk-47QYKNA6.mjs";
6
+
7
+ // src/capabilities/file-uploader.ts
8
+ import { Effect, pipe } from "effect";
9
+ import { Capabilities, chain, contributes, createIntent } from "@dxos/app-framework";
10
+ import { SpaceAction } from "@dxos/plugin-space/types";
11
+ var file_uploader_default = (context) => {
12
+ return contributes(Capabilities.FileUploader, (file, space) => {
13
+ const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);
14
+ const program = Effect.gen(function* () {
15
+ const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, {
16
+ file,
17
+ space
18
+ }));
19
+ yield* dispatch(pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, {
20
+ target: space
21
+ })));
22
+ return fileInfo;
23
+ });
24
+ return Effect.runPromise(program);
25
+ });
26
+ };
27
+ export {
28
+ file_uploader_default as default
29
+ };
30
+ //# sourceMappingURL=file-uploader-WGDG2YV5.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/capabilities/file-uploader.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Effect, pipe } from 'effect';\n\nimport { Capabilities, chain, contributes, createIntent, type PluginContext } from '@dxos/app-framework';\nimport { SpaceAction } from '@dxos/plugin-space/types';\n\nimport { WnfsAction } from '../types';\n\nexport default (context: PluginContext) => {\n return contributes(Capabilities.FileUploader, (file, space) => {\n const { dispatch } = context.getCapability(Capabilities.IntentDispatcher);\n\n const program = Effect.gen(function* () {\n const fileInfo = yield* dispatch(createIntent(WnfsAction.Upload, { file, space }));\n yield* dispatch(pipe(createIntent(WnfsAction.Create, fileInfo), chain(SpaceAction.AddObject, { target: space })));\n return fileInfo;\n });\n\n return Effect.runPromise(program);\n });\n};\n"],
5
+ "mappings": ";;;;;;;AAIA,SAASA,QAAQC,YAAY;AAE7B,SAASC,cAAcC,OAAOC,aAAaC,oBAAwC;AACnF,SAASC,mBAAmB;AAI5B,IAAA,wBAAe,CAACC,YAAAA;AACd,SAAOC,YAAYC,aAAaC,cAAc,CAACC,MAAMC,UAAAA;AACnD,UAAM,EAAEC,SAAQ,IAAKN,QAAQO,cAAcL,aAAaM,gBAAgB;AAExE,UAAMC,UAAUC,OAAOC,IAAI,aAAA;AACzB,YAAMC,WAAW,OAAON,SAASO,aAAaC,WAAWC,QAAQ;QAAEX;QAAMC;MAAM,CAAA,CAAA;AAC/E,aAAOC,SAASU,KAAKH,aAAaC,WAAWG,QAAQL,QAAAA,GAAWM,MAAMC,YAAYC,WAAW;QAAEC,QAAQhB;MAAM,CAAA,CAAA,CAAA;AAC7G,aAAOO;IACT,CAAA;AAEA,WAAOF,OAAOY,WAAWb,OAAAA;EAC3B,CAAA;AACF;",
6
+ "names": ["Effect", "pipe", "Capabilities", "chain", "contributes", "createIntent", "SpaceAction", "context", "contributes", "Capabilities", "FileUploader", "file", "space", "dispatch", "getCapability", "IntentDispatcher", "program", "Effect", "gen", "fileInfo", "createIntent", "WnfsAction", "Upload", "pipe", "Create", "chain", "SpaceAction", "AddObject", "target", "runPromise"]
7
+ }
@@ -0,0 +1,117 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ Blockstore,
4
+ FileUploader,
5
+ IntentResolver,
6
+ Markdown,
7
+ ReactSurface
8
+ } from "./chunk-DWYM7FD7.mjs";
9
+ import {
10
+ WnfsCapabilities
11
+ } from "./chunk-YTWL64Z6.mjs";
12
+ import {
13
+ FileType,
14
+ WnfsAction
15
+ } from "./chunk-BM37ZAHF.mjs";
16
+ import {
17
+ WNFS_PLUGIN,
18
+ meta
19
+ } from "./chunk-47QYKNA6.mjs";
20
+
21
+ // src/WnfsPlugin.tsx
22
+ import { pipe } from "effect";
23
+ import { Capabilities, Events, chain, contributes, createIntent, defineModule, definePlugin } from "@dxos/app-framework";
24
+ import { ClientEvents } from "@dxos/plugin-client";
25
+ import { MarkdownEvents } from "@dxos/plugin-markdown";
26
+ import { SpaceCapabilities } from "@dxos/plugin-space";
27
+ import { defineObjectForm } from "@dxos/plugin-space/types";
28
+
29
+ // src/translations.ts
30
+ var translations = [
31
+ {
32
+ "en-US": {
33
+ [FileType.typename]: {
34
+ "typename label": "File",
35
+ "object name placeholder": "New file"
36
+ },
37
+ [meta.id]: {
38
+ "plugin name": "Files",
39
+ "delete object label": "Delete",
40
+ "file input placeholder": "Drop a file here, or click to select a file"
41
+ }
42
+ }
43
+ }
44
+ ];
45
+
46
+ // src/WnfsPlugin.tsx
47
+ var WnfsPlugin = () => definePlugin(meta, [
48
+ defineModule({
49
+ id: `${meta.id}/module/blockstore`,
50
+ activatesOn: ClientEvents.ClientReady,
51
+ activate: Blockstore
52
+ }),
53
+ defineModule({
54
+ id: `${meta.id}/module/instances`,
55
+ activatesOn: ClientEvents.ClientReady,
56
+ activate: () => {
57
+ const instances = {};
58
+ return contributes(WnfsCapabilities.Instances, instances);
59
+ }
60
+ }),
61
+ defineModule({
62
+ id: `${meta.id}/module/translations`,
63
+ activatesOn: Events.SetupTranslations,
64
+ activate: () => contributes(Capabilities.Translations, translations)
65
+ }),
66
+ defineModule({
67
+ id: `${meta.id}/module/metadata`,
68
+ activatesOn: Events.SetupMetadata,
69
+ activate: () => contributes(Capabilities.Metadata, {
70
+ id: FileType.typename,
71
+ metadata: {
72
+ label: (object) => object instanceof FileType ? object.name : void 0,
73
+ // TODO(wittjosiah): Would be nice if icon could change based on the type of the file.
74
+ icon: "ph--file--regular"
75
+ }
76
+ })
77
+ }),
78
+ defineModule({
79
+ id: `${meta.id}/module/object-form`,
80
+ activatesOn: ClientEvents.SetupSchema,
81
+ activate: () => contributes(SpaceCapabilities.ObjectForm, defineObjectForm({
82
+ objectSchema: FileType,
83
+ formSchema: WnfsAction.UploadFileSchema,
84
+ getIntent: (props, options) => pipe(createIntent(WnfsAction.Upload, {
85
+ ...props,
86
+ space: options.space
87
+ }), chain(WnfsAction.Create, {}))
88
+ }))
89
+ }),
90
+ defineModule({
91
+ id: `${meta.id}/module/file-uploader`,
92
+ activatesOn: ClientEvents.ClientReady,
93
+ activate: FileUploader
94
+ }),
95
+ defineModule({
96
+ id: `${meta.id}/module/markdown`,
97
+ activatesOn: MarkdownEvents.SetupExtensions,
98
+ activate: Markdown
99
+ }),
100
+ defineModule({
101
+ id: `${meta.id}/module/react-surface`,
102
+ activatesOn: Events.SetupReactSurface,
103
+ activate: ReactSurface
104
+ }),
105
+ defineModule({
106
+ id: `${meta.id}/module/intent-resolver`,
107
+ activatesOn: Events.SetupIntentResolver,
108
+ activate: IntentResolver
109
+ })
110
+ ]);
111
+ export {
112
+ WNFS_PLUGIN,
113
+ WnfsCapabilities,
114
+ WnfsPlugin,
115
+ meta
116
+ };
117
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/WnfsPlugin.tsx", "../../../src/translations.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { pipe } from 'effect';\n\nimport {\n Capabilities,\n Events,\n chain,\n contributes,\n createIntent,\n defineModule,\n definePlugin,\n} from '@dxos/app-framework';\nimport { ClientEvents } from '@dxos/plugin-client';\nimport { MarkdownEvents } from '@dxos/plugin-markdown';\nimport { SpaceCapabilities } from '@dxos/plugin-space';\nimport { defineObjectForm } from '@dxos/plugin-space/types';\n\nimport { Blockstore, FileUploader, IntentResolver, Markdown, ReactSurface, WnfsCapabilities } from './capabilities';\nimport { meta } from './meta';\nimport { translations } from './translations';\nimport { FileType, WnfsAction } from './types';\n\nexport const WnfsPlugin = () =>\n definePlugin(meta, [\n defineModule({\n id: `${meta.id}/module/blockstore`,\n activatesOn: ClientEvents.ClientReady,\n activate: Blockstore,\n }),\n defineModule({\n id: `${meta.id}/module/instances`,\n activatesOn: ClientEvents.ClientReady,\n activate: () => {\n const instances: WnfsCapabilities.Instances = {};\n return contributes(WnfsCapabilities.Instances, instances);\n },\n }),\n defineModule({\n id: `${meta.id}/module/translations`,\n activatesOn: Events.SetupTranslations,\n activate: () => contributes(Capabilities.Translations, translations),\n }),\n defineModule({\n id: `${meta.id}/module/metadata`,\n activatesOn: Events.SetupMetadata,\n activate: () =>\n contributes(Capabilities.Metadata, {\n id: FileType.typename,\n metadata: {\n label: (object: any) => (object instanceof FileType ? object.name : undefined),\n // TODO(wittjosiah): Would be nice if icon could change based on the type of the file.\n icon: 'ph--file--regular',\n },\n }),\n }),\n defineModule({\n id: `${meta.id}/module/object-form`,\n activatesOn: ClientEvents.SetupSchema,\n activate: () =>\n contributes(\n SpaceCapabilities.ObjectForm,\n defineObjectForm({\n objectSchema: FileType,\n formSchema: WnfsAction.UploadFileSchema,\n getIntent: (props, options) =>\n pipe(createIntent(WnfsAction.Upload, { ...props, space: options.space }), chain(WnfsAction.Create, {})),\n }),\n ),\n }),\n defineModule({\n id: `${meta.id}/module/file-uploader`,\n activatesOn: ClientEvents.ClientReady,\n activate: FileUploader,\n }),\n defineModule({\n id: `${meta.id}/module/markdown`,\n activatesOn: MarkdownEvents.SetupExtensions,\n activate: Markdown,\n }),\n defineModule({\n id: `${meta.id}/module/react-surface`,\n activatesOn: Events.SetupReactSurface,\n activate: ReactSurface,\n }),\n defineModule({\n id: `${meta.id}/module/intent-resolver`,\n activatesOn: Events.SetupIntentResolver,\n activate: IntentResolver,\n }),\n ]);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Resource } from '@dxos/react-ui';\n\nimport { meta } from './meta';\nimport { FileType } from './types';\n\nexport const translations = [\n {\n 'en-US': {\n [FileType.typename]: {\n 'typename label': 'File',\n 'object name placeholder': 'New file',\n },\n [meta.id]: {\n 'plugin name': 'Files',\n 'delete object label': 'Delete',\n 'file input placeholder': 'Drop a file here, or click to select a file',\n },\n },\n },\n] as const satisfies Resource[];\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAIA,SAASA,YAAY;AAErB,SACEC,cACAC,QACAC,OACAC,aACAC,cACAC,cACAC,oBACK;AACP,SAASC,oBAAoB;AAC7B,SAASC,sBAAsB;AAC/B,SAASC,yBAAyB;AAClC,SAASC,wBAAwB;;;ACT1B,IAAMC,eAAe;EAC1B;IACE,SAAS;MACP,CAACC,SAASC,QAAQ,GAAG;QACnB,kBAAkB;QAClB,2BAA2B;MAC7B;MACA,CAACC,KAAKC,EAAE,GAAG;QACT,eAAe;QACf,uBAAuB;QACvB,0BAA0B;MAC5B;IACF;EACF;;;;ADGK,IAAMC,aAAa,MACxBC,aAAaC,MAAM;EACjBC,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaC,aAAaC;IAC1BC,UAAUC;EACZ,CAAA;EACAN,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaC,aAAaC;IAC1BC,UAAU,MAAA;AACR,YAAME,YAAwC,CAAC;AAC/C,aAAOC,YAAYC,iBAAiBC,WAAWH,SAAAA;IACjD;EACF,CAAA;EACAP,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaS,OAAOC;IACpBP,UAAU,MAAMG,YAAYK,aAAaC,cAAcC,YAAAA;EACzD,CAAA;EACAf,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaS,OAAOK;IACpBX,UAAU,MACRG,YAAYK,aAAaI,UAAU;MACjChB,IAAIiB,SAASC;MACbC,UAAU;QACRC,OAAO,CAACC,WAAiBA,kBAAkBJ,WAAWI,OAAOC,OAAOC;;QAEpEC,MAAM;MACR;IACF,CAAA;EACJ,CAAA;EACAzB,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaC,aAAauB;IAC1BrB,UAAU,MACRG,YACEmB,kBAAkBC,YAClBC,iBAAiB;MACfC,cAAcZ;MACda,YAAYC,WAAWC;MACvBC,WAAW,CAACC,OAAOC,YACjBC,KAAKC,aAAaN,WAAWO,QAAQ;QAAE,GAAGJ;QAAOK,OAAOJ,QAAQI;MAAM,CAAA,GAAIC,MAAMT,WAAWU,QAAQ,CAAC,CAAA,CAAA;IACxG,CAAA,CAAA;EAEN,CAAA;EACA1C,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaC,aAAaC;IAC1BC,UAAUsC;EACZ,CAAA;EACA3C,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAa0C,eAAeC;IAC5BxC,UAAUyC;EACZ,CAAA;EACA9C,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaS,OAAOoC;IACpB1C,UAAU2C;EACZ,CAAA;EACAhD,aAAa;IACXC,IAAI,GAAGF,KAAKE,EAAE;IACdC,aAAaS,OAAOsC;IACpB5C,UAAU6C;EACZ,CAAA;CACD;",
6
+ "names": ["pipe", "Capabilities", "Events", "chain", "contributes", "createIntent", "defineModule", "definePlugin", "ClientEvents", "MarkdownEvents", "SpaceCapabilities", "defineObjectForm", "translations", "FileType", "typename", "meta", "id", "WnfsPlugin", "definePlugin", "meta", "defineModule", "id", "activatesOn", "ClientEvents", "ClientReady", "activate", "Blockstore", "instances", "contributes", "WnfsCapabilities", "Instances", "Events", "SetupTranslations", "Capabilities", "Translations", "translations", "SetupMetadata", "Metadata", "FileType", "typename", "metadata", "label", "object", "name", "undefined", "icon", "SetupSchema", "SpaceCapabilities", "ObjectForm", "defineObjectForm", "objectSchema", "formSchema", "WnfsAction", "UploadFileSchema", "getIntent", "props", "options", "pipe", "createIntent", "Upload", "space", "chain", "Create", "FileUploader", "MarkdownEvents", "SetupExtensions", "Markdown", "SetupReactSurface", "ReactSurface", "SetupIntentResolver", "IntentResolver"]
7
+ }
@@ -0,0 +1,50 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ upload
4
+ } from "./chunk-CGW32EZB.mjs";
5
+ import {
6
+ WnfsCapabilities
7
+ } from "./chunk-YTWL64Z6.mjs";
8
+ import {
9
+ FileType,
10
+ WnfsAction
11
+ } from "./chunk-BM37ZAHF.mjs";
12
+ import "./chunk-47QYKNA6.mjs";
13
+
14
+ // src/capabilities/intent-resolver.ts
15
+ import { contributes, Capabilities, createResolver } from "@dxos/app-framework";
16
+ import { Obj } from "@dxos/echo";
17
+ var intent_resolver_default = (context) => contributes(Capabilities.IntentResolver, [
18
+ // TODO(wittjosiah): Deleting the object doesn't delete the wnfs blob.
19
+ // Consider ways to trigger blob deletion based on object deletion and/or adding file system manager.
20
+ createResolver({
21
+ intent: WnfsAction.Create,
22
+ resolve: ({ name, type, cid }) => ({
23
+ data: {
24
+ object: Obj.make(FileType, {
25
+ name,
26
+ type,
27
+ cid
28
+ })
29
+ }
30
+ })
31
+ }),
32
+ createResolver({
33
+ intent: WnfsAction.Upload,
34
+ resolve: async ({ file, space }) => {
35
+ const blockstore = context.getCapability(WnfsCapabilities.Blockstore);
36
+ const info = await upload({
37
+ file,
38
+ blockstore,
39
+ space
40
+ });
41
+ return {
42
+ data: info
43
+ };
44
+ }
45
+ })
46
+ ]);
47
+ export {
48
+ intent_resolver_default as default
49
+ };
50
+ //# sourceMappingURL=intent-resolver-5QOT2SLD.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/capabilities/intent-resolver.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { contributes, Capabilities, createResolver, type PluginContext } from '@dxos/app-framework';\nimport { Obj } from '@dxos/echo';\n\nimport { WnfsCapabilities } from './capabilities';\nimport { upload } from '../helpers';\nimport { FileType, WnfsAction } from '../types';\n\nexport default (context: PluginContext) =>\n contributes(Capabilities.IntentResolver, [\n // TODO(wittjosiah): Deleting the object doesn't delete the wnfs blob.\n // Consider ways to trigger blob deletion based on object deletion and/or adding file system manager.\n createResolver({\n intent: WnfsAction.Create,\n resolve: ({ name, type, cid }) => ({\n data: {\n object: Obj.make(FileType, { name, type, cid }),\n },\n }),\n }),\n createResolver({\n intent: WnfsAction.Upload,\n resolve: async ({ file, space }) => {\n const blockstore = context.getCapability(WnfsCapabilities.Blockstore);\n const info = await upload({ file, blockstore, space });\n return { data: info };\n },\n }),\n ]);\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAIA,SAASA,aAAaC,cAAcC,sBAA0C;AAC9E,SAASC,WAAW;AAMpB,IAAA,0BAAe,CAACC,YACdC,YAAYC,aAAaC,gBAAgB;;;EAGvCC,eAAe;IACbC,QAAQC,WAAWC;IACnBC,SAAS,CAAC,EAAEC,MAAMC,MAAMC,IAAG,OAAQ;MACjCC,MAAM;QACJC,QAAQC,IAAIC,KAAKC,UAAU;UAAEP;UAAMC;UAAMC;QAAI,CAAA;MAC/C;IACF;EACF,CAAA;EACAP,eAAe;IACbC,QAAQC,WAAWW;IACnBT,SAAS,OAAO,EAAEU,MAAMC,MAAK,MAAE;AAC7B,YAAMC,aAAapB,QAAQqB,cAAcC,iBAAiBC,UAAU;AACpE,YAAMC,OAAO,MAAMC,OAAO;QAAEP;QAAME;QAAYD;MAAM,CAAA;AACpD,aAAO;QAAEP,MAAMY;MAAK;IACtB;EACF,CAAA;CACD;",
6
+ "names": ["contributes", "Capabilities", "createResolver", "Obj", "context", "contributes", "Capabilities", "IntentResolver", "createResolver", "intent", "WnfsAction", "Create", "resolve", "name", "type", "cid", "data", "object", "Obj", "make", "FileType", "Upload", "file", "space", "blockstore", "getCapability", "WnfsCapabilities", "Blockstore", "info", "upload"]
7
+ }