@dxos/plugin-wnfs 0.8.4-main.9735255 → 0.8.4-main.9be5663bfe

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 (149) hide show
  1. package/dist/lib/browser/chunk-BM3MEFES.mjs +69 -0
  2. package/dist/lib/browser/chunk-BM3MEFES.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-NCTUASHL.mjs → chunk-N6Y4QPNF.mjs} +15 -32
  4. package/dist/lib/browser/chunk-N6Y4QPNF.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-VXUCZHVZ.mjs +69 -0
  6. package/dist/lib/browser/chunk-VXUCZHVZ.mjs.map +7 -0
  7. package/dist/lib/browser/create-NOHKWE67.mjs +24 -0
  8. package/dist/lib/browser/create-NOHKWE67.mjs.map +7 -0
  9. package/dist/lib/browser/create-file-N7ADCFOF.mjs +49 -0
  10. package/dist/lib/browser/create-file-N7ADCFOF.mjs.map +7 -0
  11. package/dist/lib/browser/index.mjs +71 -70
  12. package/dist/lib/browser/index.mjs.map +4 -4
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/browser/operations/index.mjs +13 -0
  15. package/dist/lib/browser/operations/index.mjs.map +7 -0
  16. package/dist/lib/browser/types/index.mjs +3 -5
  17. package/dist/lib/browser/upload-DA7GBOXF.mjs +42 -0
  18. package/dist/lib/browser/upload-DA7GBOXF.mjs.map +7 -0
  19. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  20. package/dist/types/src/capabilities/blockstore.d.ts +5 -0
  21. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -0
  22. package/dist/types/src/capabilities/file-uploader.d.ts +6 -0
  23. package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -0
  24. package/dist/types/src/capabilities/index.d.ts +7 -5
  25. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  26. package/dist/types/src/capabilities/markdown.d.ts +5 -0
  27. package/dist/types/src/capabilities/markdown.d.ts.map +1 -0
  28. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  29. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  30. package/dist/types/src/capabilities/react-surface.d.ts +5 -0
  31. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  32. package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
  33. package/dist/types/src/components/FileInput/index.d.ts +2 -0
  34. package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
  35. package/dist/types/src/components/FilePreview/FilePreview.d.ts +12 -0
  36. package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
  37. package/dist/types/src/components/FilePreview/index.d.ts +2 -0
  38. package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
  39. package/dist/types/src/components/index.d.ts +1 -1
  40. package/dist/types/src/components/index.d.ts.map +1 -1
  41. package/dist/types/src/containers/FileContainer/FileContainer.d.ts +7 -0
  42. package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
  43. package/dist/types/src/containers/FileContainer/index.d.ts +2 -0
  44. package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -0
  45. package/dist/types/src/containers/index.d.ts +3 -0
  46. package/dist/types/src/containers/index.d.ts.map +1 -0
  47. package/dist/types/src/extensions/image.d.ts +1 -1
  48. package/dist/types/src/extensions/image.d.ts.map +1 -1
  49. package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
  50. package/dist/types/src/helpers/load.d.ts +1 -1
  51. package/dist/types/src/helpers/load.d.ts.map +1 -1
  52. package/dist/types/src/helpers/upload.d.ts +1 -1
  53. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  54. package/dist/types/src/operations/create-file.d.ts +5 -0
  55. package/dist/types/src/operations/create-file.d.ts.map +1 -0
  56. package/dist/types/src/operations/create.d.ts +5 -0
  57. package/dist/types/src/operations/create.d.ts.map +1 -0
  58. package/dist/types/src/operations/definitions.d.ts +38 -0
  59. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  60. package/dist/types/src/operations/index.d.ts +4 -0
  61. package/dist/types/src/operations/index.d.ts.map +1 -0
  62. package/dist/types/src/operations/upload.d.ts +5 -0
  63. package/dist/types/src/operations/upload.d.ts.map +1 -0
  64. package/dist/types/src/translations.d.ts +13 -12
  65. package/dist/types/src/translations.d.ts.map +1 -1
  66. package/dist/types/src/types/File.d.ts +1 -1
  67. package/dist/types/src/types/File.d.ts.map +1 -1
  68. package/dist/types/src/types/types.d.ts +1 -104
  69. package/dist/types/src/types/types.d.ts.map +1 -1
  70. package/dist/types/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +47 -30
  72. package/src/WnfsPlugin.tsx +36 -36
  73. package/src/blockstore.ts +1 -1
  74. package/src/capabilities/{blockstore/blockstore.ts → blockstore.ts} +4 -3
  75. package/src/capabilities/{file-uploader/file-uploader.ts → file-uploader.ts} +6 -5
  76. package/src/capabilities/index.ts +11 -5
  77. package/src/capabilities/{markdown/markdown.ts → markdown.ts} +3 -2
  78. package/src/capabilities/operation-handler.ts +16 -0
  79. package/src/capabilities/{react-surface/react-surface.tsx → react-surface.tsx} +13 -11
  80. package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +5 -5
  81. package/src/components/FileInput/index.ts +5 -0
  82. package/src/components/FilePreview/FilePreview.tsx +43 -0
  83. package/src/components/FilePreview/index.ts +5 -0
  84. package/src/components/index.ts +1 -4
  85. package/src/{components → containers/FileContainer}/FileContainer.tsx +12 -11
  86. package/src/containers/FileContainer/index.ts +5 -0
  87. package/src/containers/index.ts +7 -0
  88. package/src/extensions/image.stories.tsx +9 -10
  89. package/src/extensions/image.tsx +2 -1
  90. package/src/helpers/load.ts +6 -6
  91. package/src/helpers/upload.ts +3 -3
  92. package/src/meta.ts +1 -1
  93. package/src/operations/create-file.ts +31 -0
  94. package/src/operations/create.ts +22 -0
  95. package/src/operations/definitions.ts +41 -0
  96. package/src/operations/index.ts +13 -0
  97. package/src/operations/upload.ts +29 -0
  98. package/src/translations.ts +13 -12
  99. package/src/types/File.ts +6 -2
  100. package/src/types/capabilities.ts +3 -3
  101. package/src/types/types.ts +3 -59
  102. package/dist/lib/browser/FileContainer-O5YFSIWV.mjs +0 -91
  103. package/dist/lib/browser/FileContainer-O5YFSIWV.mjs.map +0 -7
  104. package/dist/lib/browser/blockstore-KKFOALUH.mjs +0 -191
  105. package/dist/lib/browser/blockstore-KKFOALUH.mjs.map +0 -7
  106. package/dist/lib/browser/chunk-GXXEH7H6.mjs +0 -154
  107. package/dist/lib/browser/chunk-GXXEH7H6.mjs.map +0 -7
  108. package/dist/lib/browser/chunk-NCTUASHL.mjs.map +0 -7
  109. package/dist/lib/browser/file-uploader-BUHAXRSV.mjs +0 -34
  110. package/dist/lib/browser/file-uploader-BUHAXRSV.mjs.map +0 -7
  111. package/dist/lib/browser/markdown-BRT2MN6C.mjs +0 -201
  112. package/dist/lib/browser/markdown-BRT2MN6C.mjs.map +0 -7
  113. package/dist/lib/browser/operation-resolver-F6GUL54A.mjs +0 -99
  114. package/dist/lib/browser/operation-resolver-F6GUL54A.mjs.map +0 -7
  115. package/dist/lib/browser/react-surface-UNAYSIAC.mjs +0 -81
  116. package/dist/lib/browser/react-surface-UNAYSIAC.mjs.map +0 -7
  117. package/dist/types/src/capabilities/blockstore/blockstore.d.ts +0 -5
  118. package/dist/types/src/capabilities/blockstore/blockstore.d.ts.map +0 -1
  119. package/dist/types/src/capabilities/blockstore/index.d.ts +0 -3
  120. package/dist/types/src/capabilities/blockstore/index.d.ts.map +0 -1
  121. package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts +0 -5
  122. package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts.map +0 -1
  123. package/dist/types/src/capabilities/file-uploader/index.d.ts +0 -3
  124. package/dist/types/src/capabilities/file-uploader/index.d.ts.map +0 -1
  125. package/dist/types/src/capabilities/markdown/index.d.ts +0 -3
  126. package/dist/types/src/capabilities/markdown/index.d.ts.map +0 -1
  127. package/dist/types/src/capabilities/markdown/markdown.d.ts +0 -5
  128. package/dist/types/src/capabilities/markdown/markdown.d.ts.map +0 -1
  129. package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
  130. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
  131. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
  132. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
  133. package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
  134. package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
  135. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
  136. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
  137. package/dist/types/src/components/FileContainer.d.ts +0 -7
  138. package/dist/types/src/components/FileContainer.d.ts.map +0 -1
  139. package/dist/types/src/components/FileInput.d.ts.map +0 -1
  140. package/dist/types/src/components/FilePreview.d.ts +0 -11
  141. package/dist/types/src/components/FilePreview.d.ts.map +0 -1
  142. package/src/capabilities/blockstore/index.ts +0 -7
  143. package/src/capabilities/file-uploader/index.ts +0 -7
  144. package/src/capabilities/markdown/index.ts +0 -7
  145. package/src/capabilities/operation-resolver/index.ts +0 -7
  146. package/src/capabilities/operation-resolver/operation-resolver.ts +0 -62
  147. package/src/capabilities/react-surface/index.ts +0 -7
  148. package/src/components/FilePreview.tsx +0 -23
  149. /package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +0 -0
@@ -0,0 +1,69 @@
1
+ import {
2
+ File_exports,
3
+ WnfsAction,
4
+ __export
5
+ } from "./chunk-VXUCZHVZ.mjs";
6
+
7
+ // src/operations/definitions.ts
8
+ var definitions_exports = {};
9
+ __export(definitions_exports, {
10
+ Create: () => Create,
11
+ CreateFile: () => CreateFile,
12
+ Upload: () => Upload
13
+ });
14
+ import * as Schema from "effect/Schema";
15
+ import { Capability } from "@dxos/app-framework";
16
+ import { FileInfoSchema } from "@dxos/app-toolkit";
17
+ import { Database } from "@dxos/echo";
18
+ import { Operation } from "@dxos/operation";
19
+ import { meta } from "#meta";
20
+ var WNFS_OPERATION = `${meta.id}.operation`;
21
+ var Create = Operation.make({
22
+ meta: {
23
+ key: `${WNFS_OPERATION}.create`,
24
+ name: "Create WNFS File"
25
+ },
26
+ services: [
27
+ Capability.Service
28
+ ],
29
+ input: FileInfoSchema.pick("name", "type", "cid").pipe(Schema.required),
30
+ output: Schema.Struct({
31
+ object: File_exports.File
32
+ })
33
+ });
34
+ var Upload = Operation.make({
35
+ meta: {
36
+ key: `${WNFS_OPERATION}.upload`,
37
+ name: "Upload File"
38
+ },
39
+ services: [
40
+ Capability.Service
41
+ ],
42
+ input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({
43
+ db: Database.Database
44
+ })),
45
+ output: Schema.required(FileInfoSchema)
46
+ });
47
+ var CreateFile = Operation.make({
48
+ meta: {
49
+ key: `${WNFS_OPERATION}.create-file`,
50
+ name: "Create File"
51
+ },
52
+ services: [
53
+ Capability.Service
54
+ ],
55
+ input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({
56
+ db: Database.Database
57
+ })),
58
+ output: Schema.Struct({
59
+ object: File_exports.File
60
+ })
61
+ });
62
+
63
+ export {
64
+ Create,
65
+ Upload,
66
+ CreateFile,
67
+ definitions_exports
68
+ };
69
+ //# sourceMappingURL=chunk-BM3MEFES.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/operations/definitions.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Capability } from '@dxos/app-framework';\nimport { FileInfoSchema } from '@dxos/app-toolkit';\nimport { Database } from '@dxos/echo';\nimport { Operation } from '@dxos/operation';\n\nimport { meta } from '#meta';\n\nimport { WnfsFile, WnfsAction } from '../types';\n\nconst WNFS_OPERATION = `${meta.id}.operation`;\n\nexport const Create = Operation.make({\n meta: { key: `${WNFS_OPERATION}.create`, name: 'Create WNFS File' },\n services: [Capability.Service],\n input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),\n output: Schema.Struct({\n object: WnfsFile.File,\n }),\n});\n\nexport const Upload = Operation.make({\n meta: { key: `${WNFS_OPERATION}.upload`, name: 'Upload File' },\n services: [Capability.Service],\n input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),\n output: Schema.required(FileInfoSchema),\n});\n\nexport const CreateFile = Operation.make({\n meta: { key: `${WNFS_OPERATION}.create-file`, name: 'Create File' },\n services: [Capability.Service],\n input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),\n output: Schema.Struct({\n object: WnfsFile.File,\n }),\n});\n"],
5
+ "mappings": ";;;;;;;AAAA;;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,kBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAE1B,SAASC,YAAY;AAIrB,IAAMC,iBAAiB,GAAGC,KAAKC,EAAE;AAE1B,IAAMC,SAASC,UAAUC,KAAK;EACnCJ,MAAM;IAAEK,KAAK,GAAGN,cAAAA;IAAyBO,MAAM;EAAmB;EAClEC,UAAU;IAACC,WAAWC;;EACtBC,OAAOC,eAAeC,KAAK,QAAQ,QAAQ,KAAA,EAAOC,KAAYC,eAAQ;EACtEC,QAAeC,cAAO;IACpBC,QAAQC,aAASC;EACnB,CAAA;AACF,CAAA;AAEO,IAAMC,SAASjB,UAAUC,KAAK;EACnCJ,MAAM;IAAEK,KAAK,GAAGN,cAAAA;IAAyBO,MAAM;EAAc;EAC7DC,UAAU;IAACC,WAAWC;;EACtBC,OAAcW,cAAOC,WAAWC,kBAAyBP,cAAO;IAAEQ,IAAIC,SAASA;EAAS,CAAA,CAAA;EACxFV,QAAeD,gBAASH,cAAAA;AAC1B,CAAA;AAEO,IAAMe,aAAavB,UAAUC,KAAK;EACvCJ,MAAM;IAAEK,KAAK,GAAGN,cAAAA;IAA8BO,MAAM;EAAc;EAClEC,UAAU;IAACC,WAAWC;;EACtBC,OAAcW,cAAOC,WAAWC,kBAAyBP,cAAO;IAAEQ,IAAIC,SAASA;EAAS,CAAA,CAAA;EACxFV,QAAeC,cAAO;IACpBC,QAAQC,aAASC;EACnB,CAAA;AACF,CAAA;",
6
+ "names": ["Schema", "Capability", "FileInfoSchema", "Database", "Operation", "meta", "WNFS_OPERATION", "meta", "id", "Create", "Operation", "make", "key", "name", "services", "Capability", "Service", "input", "FileInfoSchema", "pick", "pipe", "required", "output", "Struct", "object", "WnfsFile", "File", "Upload", "extend", "WnfsAction", "UploadFileSchema", "db", "Database", "CreateFile"]
7
+ }
@@ -1,3 +1,10 @@
1
+ // src/helpers/upload.ts
2
+ import { CID as CID3 } from "multiformats";
3
+ import * as Raw from "multiformats/codecs/raw";
4
+ import { sha256 as sha2562 } from "multiformats/hashes/sha2";
5
+ import { Obj as Obj2 } from "@dxos/echo";
6
+ import { log } from "@dxos/log";
7
+
1
8
  // src/helpers/common.ts
2
9
  import { CID } from "multiformats/cid";
3
10
  import { sha256 } from "multiformats/hashes/sha2";
@@ -41,7 +48,6 @@ var store = (blockstore) => {
41
48
  putBlock
42
49
  };
43
50
  };
44
- var storeName = () => "dxos/wnfs";
45
51
 
46
52
  // src/helpers/load.ts
47
53
  import { CID as CID2 } from "multiformats";
@@ -50,9 +56,9 @@ import { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from "wnfs";
50
56
  import { Obj } from "@dxos/echo";
51
57
  var loadWnfs = async ({ space, blockstore, instances }) => {
52
58
  if (space.properties.wnfs_access_key !== void 0 && space.properties.wnfs_private_forest_cid !== void 0) {
53
- Obj.change(space.properties, (p) => {
54
- delete p["wnfs_access_key"];
55
- delete p["wnfs_private_forest_cid"];
59
+ Obj.change(space.properties, (obj) => {
60
+ delete obj["wnfs_access_key"];
61
+ delete obj["wnfs_private_forest_cid"];
56
62
  });
57
63
  }
58
64
  const cacheKey = space.properties.wnfs?.privateForestCid;
@@ -74,8 +80,8 @@ var createWnfsDir = async (blockstore, space) => {
74
80
  const dir = dirResult.rootDir;
75
81
  const [accessKeyRaw, newForest] = await dir.asNode().store(dirResult.forest, wnfsStore, rng);
76
82
  const cidBytes = await newForest.store(wnfsStore);
77
- Obj.change(space.properties, (p) => {
78
- p.wnfs = {
83
+ Obj.change(space.properties, (obj) => {
84
+ obj.wnfs = {
79
85
  accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), "base64"),
80
86
  privateForestCid: CID2.decode(cidBytes).toString()
81
87
  };
@@ -100,25 +106,8 @@ var loadWnfsDir = async (blockstore, space) => {
100
106
  var wnfsUrl = (filePath2) => {
101
107
  return "wnfs://" + filePath2.map((f) => encodeURIComponent(f)).join("/");
102
108
  };
103
- var getPathFromUrl = (wnfsUrl2) => wnfsUrl2.replace(/^wnfs:\/\//, "").split("/").map((p) => decodeURIComponent(p));
104
- var getBlobUrl = async ({ wnfsUrl: wnfsUrl2, blockstore, forest, directory, type }) => {
105
- const path = getPathFromUrl(wnfsUrl2);
106
- const wnfsStore = store(blockstore);
107
- const { result } = await directory.read(path, true, forest, wnfsStore);
108
- const blob = new Blob([
109
- result
110
- ], {
111
- type
112
- });
113
- return URL.createObjectURL(blob);
114
- };
115
109
 
116
110
  // src/helpers/upload.ts
117
- import { CID as CID3 } from "multiformats";
118
- import * as Raw from "multiformats/codecs/raw";
119
- import { sha256 as sha2562 } from "multiformats/hashes/sha2";
120
- import { Obj as Obj2 } from "@dxos/echo";
121
- import { log } from "@dxos/log";
122
111
  var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/helpers/upload.ts";
123
112
  var upload = async ({ file, blockstore, instances, space }) => {
124
113
  const { directory, forest } = await loadWnfs({
@@ -134,8 +123,8 @@ var upload = async ({ file, blockstore, instances, space }) => {
134
123
  const result = await directory.write(path, true, bytes, /* @__PURE__ */ new Date(), forest, wnfsStore, new Rng());
135
124
  const [_, updatedForest] = await result.rootDir.store(result.forest, wnfsStore, new Rng());
136
125
  const cidBytes = await updatedForest.store(wnfsStore);
137
- Obj2.change(space.properties, (p) => {
138
- p.wnfs.privateForestCid = CID3.decode(cidBytes).toString();
126
+ Obj2.change(space.properties, (obj) => {
127
+ obj.wnfs.privateForestCid = CID3.decode(cidBytes).toString();
139
128
  });
140
129
  const info = {
141
130
  name: file.name,
@@ -156,12 +145,6 @@ var upload = async ({ file, blockstore, instances, space }) => {
156
145
  };
157
146
 
158
147
  export {
159
- filePath,
160
- storeName,
161
- loadWnfs,
162
- wnfsUrl,
163
- getPathFromUrl,
164
- getBlobUrl,
165
148
  upload
166
149
  };
167
- //# sourceMappingURL=chunk-NCTUASHL.mjs.map
150
+ //# sourceMappingURL=chunk-N6Y4QPNF.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/upload.ts", "../../../src/helpers/common.ts", "../../../src/helpers/load.ts", "../../../src/helpers/wnfs-url.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { CID } from 'multiformats';\nimport * as Raw from 'multiformats/codecs/raw';\nimport { sha256 } from 'multiformats/hashes/sha2';\n\nimport type { Space } from '@dxos/client/echo';\nimport { Obj } from '@dxos/echo';\nimport { log } from '@dxos/log';\n\nimport { type WnfsCapabilities } from '#types';\n\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 Obj.change(space.properties, (obj) => {\n obj.wnfs.privateForestCid = CID.decode(cidBytes).toString();\n });\n\n // Generate `wnfs://` URL & return the info.\n const info = {\n name: file.name,\n type: file.type,\n url: wnfsUrl(path),\n cid: cid.toString(),\n };\n\n log('upload', { file, info });\n return info;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Blockstore } from 'interface-blockstore';\nimport { 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, PrivateDirectory, PrivateForest, PrivateNode } from 'wnfs';\n\nimport { Obj } from '@dxos/echo';\nimport { type Space } from '@dxos/react-client/echo';\n\nimport { type WnfsCapabilities } from '#types';\n\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.\n if (space.properties.wnfs_access_key !== undefined && space.properties.wnfs_private_forest_cid !== undefined) {\n Obj.change(space.properties, (obj) => {\n delete obj['wnfs_access_key'];\n delete obj['wnfs_private_forest_cid'];\n });\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 Obj.change(space.properties, (obj) => {\n obj.wnfs = {\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 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"],
5
+ "mappings": ";AAKA,SA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,OAAO5B,MAAM6B,YAAY,CAACC,QAAAA;AAC5BA,QAAIC,KAAKC,mBAAmBnB,KAAIoB,OAAOP,QAAAA,EAAUR,SAAQ;EAC3D,CAAA;AAGA,QAAMgB,OAAO;IACXC,MAAMtC,KAAKsC;IACXC,MAAMvC,KAAKuC;IACXC,KAAKC,QAAQtB,IAAAA;IACbJ,KAAKA,IAAIM,SAAQ;EACnB;AAEAqB,MAAI,UAAU;IAAE1C;IAAMqC;EAAK,GAAA;;;;;;AAC3B,SAAOA;AACT;",
6
+ "names": ["CID", "Raw", "sha256", "Obj", "log", "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", "CID", "Uint8Arrays", "AccessKey", "PrivateDirectory", "PrivateForest", "PrivateNode", "Obj", "loadWnfs", "space", "blockstore", "instances", "properties", "wnfs_access_key", "undefined", "wnfs_private_forest_cid", "Obj", "change", "obj", "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", "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", "Obj", "change", "properties", "obj", "wnfs", "privateForestCid", "decode", "info", "name", "type", "url", "wnfsUrl", "log"]
7
+ }
@@ -0,0 +1,69 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/types/capabilities.ts
8
+ import { Capability } from "@dxos/app-framework";
9
+ import { meta } from "#meta";
10
+ (function(WnfsCapabilities2) {
11
+ WnfsCapabilities2.Blockstore = Capability.make(`${meta.id}.capability.blockstore`);
12
+ WnfsCapabilities2.Instances = Capability.make(`${meta.id}.capability.instances`);
13
+ })(WnfsCapabilities || (WnfsCapabilities = {}));
14
+ var WnfsCapabilities;
15
+
16
+ // src/types/File.ts
17
+ var File_exports = {};
18
+ __export(File_exports, {
19
+ File: () => File2,
20
+ make: () => make
21
+ });
22
+ import * as Schema from "effect/Schema";
23
+ import { Annotation, Obj, Type } from "@dxos/echo";
24
+ import { FormInputAnnotation } from "@dxos/echo/internal";
25
+ var File2 = Schema.Struct({
26
+ name: Schema.String.pipe(Schema.optional),
27
+ type: Schema.String.pipe(FormInputAnnotation.set(false)),
28
+ cid: Schema.String.pipe(FormInputAnnotation.set(false)),
29
+ timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional)
30
+ }).pipe(Type.object({
31
+ typename: "org.dxos.type.file",
32
+ version: "0.1.0"
33
+ }), Annotation.IconAnnotation.set({
34
+ icon: "ph--file--regular",
35
+ hue: "teal"
36
+ }));
37
+ var make = (props) => Obj.make(File2, props);
38
+
39
+ // src/types/types.ts
40
+ import * as Schema2 from "effect/Schema";
41
+ import { meta as meta2 } from "#meta";
42
+ (function(WnfsAction2) {
43
+ WnfsAction2.UploadAnnotationId = /* @__PURE__ */ Symbol.for(`${meta2.id}.annotation.upload`);
44
+ WnfsAction2.UploadFileSchema = Schema2.Struct({
45
+ file: Schema2.instanceOf(File).annotations({
46
+ [WnfsAction2.UploadAnnotationId]: {
47
+ // Accept file types.
48
+ "image/*": [
49
+ ".jpg",
50
+ ".jpeg",
51
+ ".png",
52
+ ".gif"
53
+ ],
54
+ "application/pdf": [
55
+ ".pdf"
56
+ ]
57
+ }
58
+ })
59
+ });
60
+ })(WnfsAction || (WnfsAction = {}));
61
+ var WnfsAction;
62
+
63
+ export {
64
+ __export,
65
+ WnfsCapabilities,
66
+ File_exports,
67
+ WnfsAction
68
+ };
69
+ //# sourceMappingURL=chunk-VXUCZHVZ.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types/capabilities.ts", "../../../src/types/File.ts", "../../../src/types/types.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 { Capability } from '@dxos/app-framework';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { meta } from '#meta';\n\nexport namespace WnfsCapabilities {\n export const Blockstore = Capability.make<Blockstore>(`${meta.id}.capability.blockstore`);\n\n export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;\n export const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation, Obj, Type } from '@dxos/echo';\nimport { FormInputAnnotation } from '@dxos/echo/internal';\n\nexport const File = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n type: Schema.String.pipe(FormInputAnnotation.set(false)),\n cid: Schema.String.pipe(FormInputAnnotation.set(false)),\n timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),\n}).pipe(\n Type.object({\n typename: 'org.dxos.type.file',\n version: '0.1.0',\n }),\n Annotation.IconAnnotation.set({\n icon: 'ph--file--regular',\n hue: 'teal',\n }),\n);\n\nexport type File = Schema.Schema.Type<typeof File>;\n\nexport const make = (props: Obj.MakeProps<typeof File>) => Obj.make(File, props);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { meta } from '#meta';\n\nexport namespace WnfsAction {\n export const UploadAnnotationId = Symbol.for(`${meta.id}.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"],
5
+ "mappings": ";;;;;;;AAOA,SAASA,kBAAkB;AAG3B,SAASC,YAAY;UAEJC,mBAAAA;oBACFC,aAAaC,WAAWC,KAAiB,GAAGC,KAAKC,EAAE,wBAAwB;oBAG3EC,YAAYJ,WAAWC,KAAgB,GAAGC,KAAKC,EAAE,uBAAuB;AACvF,GALiBL,qBAAAA,mBAAAA,CAAAA,EAAAA;;;;ACZjB;;cAAAO;EAAA;;AAIA,YAAYC,YAAY;AAExB,SAASC,YAAYC,KAAKC,YAAY;AACtC,SAASC,2BAA2B;AAE7B,IAAMC,QAAcC,cAAO;EAChCC,MAAaC,cAAOC,KAAYC,eAAQ;EACxCC,MAAaH,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,CAAA;EACjDC,KAAYN,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,CAAA;EAChDE,WAAkBP,cAAOC,KAAKG,oBAAoBC,IAAI,KAAA,GAAeH,eAAQ;AAC/E,CAAA,EAAGD,KACDO,KAAKC,OAAO;EACVC,UAAU;EACVC,SAAS;AACX,CAAA,GACAC,WAAWC,eAAeR,IAAI;EAC5BS,MAAM;EACNC,KAAK;AACP,CAAA,CAAA;AAKK,IAAMC,OAAO,CAACC,UAAsCC,IAAIF,KAAKnB,OAAMoB,KAAAA;;;ACvB1E,YAAYE,aAAY;AAExB,SAASC,QAAAA,aAAY;UAEJC,aAAAA;cACFC,qBAAqBC,uBAAOC,IAAI,GAAGC,MAAKC,EAAE,oBAAoB;cAE9DC,mBAA0BC,eAAO;IAC5CC,MAAaC,mBAAWC,IAAAA,EAAMC,YAAY;MACxC,CAAAX,YAACC,kBAAAA,GAAqB;;QAEpB,WAAW;UAAC;UAAQ;UAAS;UAAQ;;QACrC,mBAAmB;UAAC;;MAEtB;IACF,CAAA;EACF,CAAA;AAGF,GAfiBD,eAAAA,aAAAA,CAAAA,EAAAA;;",
6
+ "names": ["Capability", "meta", "WnfsCapabilities", "Blockstore", "Capability", "make", "meta", "id", "Instances", "File", "Schema", "Annotation", "Obj", "Type", "FormInputAnnotation", "File", "Struct", "name", "String", "pipe", "optional", "type", "FormInputAnnotation", "set", "cid", "timestamp", "Type", "object", "typename", "version", "Annotation", "IconAnnotation", "icon", "hue", "make", "props", "Obj", "Schema", "meta", "WnfsAction", "UploadAnnotationId", "Symbol", "for", "meta", "id", "UploadFileSchema", "Struct", "file", "instanceOf", "File", "annotations"]
7
+ }
@@ -0,0 +1,24 @@
1
+ import {
2
+ Create
3
+ } from "./chunk-BM3MEFES.mjs";
4
+ import {
5
+ File_exports
6
+ } from "./chunk-VXUCZHVZ.mjs";
7
+
8
+ // src/operations/create.ts
9
+ import * as Effect from "effect/Effect";
10
+ import { Operation } from "@dxos/operation";
11
+ var handler = Create.pipe(Operation.withHandler(Effect.fnUntraced(function* ({ name, type, cid }) {
12
+ return {
13
+ object: File_exports.make({
14
+ name,
15
+ type,
16
+ cid
17
+ })
18
+ };
19
+ })));
20
+ var create_default = handler;
21
+ export {
22
+ create_default as default
23
+ };
24
+ //# sourceMappingURL=create-NOHKWE67.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/operations/create.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Operation } from '@dxos/operation';\n\nimport { WnfsFile } from '../types';\nimport { Create } from './definitions';\n\nconst handler: Operation.WithHandler<typeof Create> = Create.pipe(\n Operation.withHandler(\n Effect.fnUntraced(function* ({ name, type, cid }) {\n return {\n object: WnfsFile.make({ name, type, cid }),\n };\n }),\n ),\n);\n\nexport default handler;\n"],
5
+ "mappings": ";;;;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,iBAAiB;AAK1B,IAAMC,UAAgDC,OAAOC,KAC3DC,UAAUC,YACDC,kBAAW,WAAW,EAAEC,MAAMC,MAAMC,IAAG,GAAE;AAC9C,SAAO;IACLC,QAAQC,aAASC,KAAK;MAAEL;MAAMC;MAAMC;IAAI,CAAA;EAC1C;AACF,CAAA,CAAA,CAAA;AAIJ,IAAA,iBAAeR;",
6
+ "names": ["Effect", "Operation", "handler", "Create", "pipe", "Operation", "withHandler", "fnUntraced", "name", "type", "cid", "object", "WnfsFile", "make"]
7
+ }
@@ -0,0 +1,49 @@
1
+ import {
2
+ upload
3
+ } from "./chunk-N6Y4QPNF.mjs";
4
+ import {
5
+ CreateFile
6
+ } from "./chunk-BM3MEFES.mjs";
7
+ import {
8
+ File_exports,
9
+ WnfsCapabilities
10
+ } from "./chunk-VXUCZHVZ.mjs";
11
+
12
+ // src/operations/create-file.ts
13
+ import * as Effect from "effect/Effect";
14
+ import { Capability } from "@dxos/app-framework";
15
+ import { invariant } from "@dxos/invariant";
16
+ import { Operation } from "@dxos/operation";
17
+ import { ClientCapabilities } from "@dxos/plugin-client/types";
18
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/operations/create-file.ts";
19
+ var handler = CreateFile.pipe(Operation.withHandler(Effect.fnUntraced(function* ({ file, db }) {
20
+ const client = yield* Capability.get(ClientCapabilities.Client);
21
+ const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
22
+ const space = client.spaces.get(db.spaceId);
23
+ invariant(space, "Space not found", {
24
+ F: __dxlog_file,
25
+ L: 22,
26
+ S: this,
27
+ A: [
28
+ "space",
29
+ "'Space not found'"
30
+ ]
31
+ });
32
+ const info = yield* Effect.promise(() => upload({
33
+ file,
34
+ blockstore,
35
+ space
36
+ }));
37
+ return {
38
+ object: File_exports.make({
39
+ name: info.name,
40
+ type: info.type,
41
+ cid: info.cid
42
+ })
43
+ };
44
+ })));
45
+ var create_file_default = handler;
46
+ export {
47
+ create_file_default as default
48
+ };
49
+ //# sourceMappingURL=create-file-N7ADCFOF.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/operations/create-file.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability } from '@dxos/app-framework';\nimport { invariant } from '@dxos/invariant';\nimport { Operation } from '@dxos/operation';\nimport { ClientCapabilities } from '@dxos/plugin-client/types';\n\nimport { upload } from '../helpers';\nimport { WnfsCapabilities, WnfsFile } from '../types';\nimport { CreateFile } from './definitions';\n\nconst handler: Operation.WithHandler<typeof CreateFile> = CreateFile.pipe(\n Operation.withHandler(\n Effect.fnUntraced(function* ({ file, db }) {\n const client = yield* Capability.get(ClientCapabilities.Client);\n const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);\n const space = client.spaces.get(db.spaceId);\n invariant(space, 'Space not found');\n const info = yield* Effect.promise(() => upload({ file, blockstore, space }));\n return {\n object: WnfsFile.make({ name: info.name, type: info.type, cid: info.cid }),\n };\n }),\n ),\n);\n\nexport default handler;\n"],
5
+ "mappings": ";;;;;;;;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAC1B,SAASC,0BAA0B;;AAMnC,IAAMC,UAAoDC,WAAWC,KACnEC,UAAUC,YACDC,kBAAW,WAAW,EAAEC,MAAMC,GAAE,GAAE;AACvC,QAAMC,SAAS,OAAOC,WAAWC,IAAIC,mBAAmBC,MAAM;AAC9D,QAAMC,aAAa,OAAOJ,WAAWC,IAAII,iBAAiBC,UAAU;AACpE,QAAMC,QAAQR,OAAOS,OAAOP,IAAIH,GAAGW,OAAO;AAC1CC,YAAUH,OAAO,mBAAA;;;;;;;;;AACjB,QAAMI,OAAO,OAAcC,eAAQ,MAAMC,OAAO;IAAEhB;IAAMO;IAAYG;EAAM,CAAA,CAAA;AAC1E,SAAO;IACLO,QAAQC,aAASC,KAAK;MAAEC,MAAMN,KAAKM;MAAMC,MAAMP,KAAKO;MAAMC,KAAKR,KAAKQ;IAAI,CAAA;EAC1E;AACF,CAAA,CAAA,CAAA;AAIJ,IAAA,sBAAe5B;",
6
+ "names": ["Effect", "Capability", "invariant", "Operation", "ClientCapabilities", "handler", "CreateFile", "pipe", "Operation", "withHandler", "fnUntraced", "file", "db", "client", "Capability", "get", "ClientCapabilities", "Client", "blockstore", "WnfsCapabilities", "Blockstore", "space", "spaces", "spaceId", "invariant", "info", "promise", "upload", "object", "WnfsFile", "make", "name", "type", "cid"]
7
+ }
@@ -1,100 +1,105 @@
1
1
  import {
2
- File_exports,
3
- WnfsAction,
4
- WnfsCapabilities,
5
- WnfsOperation,
6
- meta
7
- } from "./chunk-GXXEH7H6.mjs";
2
+ WnfsCapabilities
3
+ } from "./chunk-VXUCZHVZ.mjs";
4
+
5
+ // src/meta.ts
6
+ import { trim } from "@dxos/util";
7
+ var meta = {
8
+ id: "org.dxos.plugin.wnfs",
9
+ name: "WNFS",
10
+ description: trim`
11
+ Decentralized file storage using the Web Native File System protocol.
12
+ Store and sync files with end-to-end encryption across devices without central servers.
13
+ `,
14
+ icon: "ph--file-cloud--regular",
15
+ iconHue: "teal",
16
+ source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs"
17
+ };
8
18
 
9
19
  // src/WnfsPlugin.tsx
10
20
  import * as Effect from "effect/Effect";
11
- import { Capability as Capability6, Common, Plugin } from "@dxos/app-framework";
21
+ import * as Option from "effect/Option";
22
+ import { Capability, Plugin } from "@dxos/app-framework";
23
+ import { AppPlugin } from "@dxos/app-toolkit";
24
+ import { Annotation } from "@dxos/echo";
12
25
  import { Operation } from "@dxos/operation";
13
- import { ClientEvents } from "@dxos/plugin-client";
26
+ import { ClientEvents } from "@dxos/plugin-client/types";
14
27
  import { MarkdownEvents } from "@dxos/plugin-markdown";
15
- import { SpaceCapabilities, SpaceEvents } from "@dxos/plugin-space";
16
-
17
- // src/capabilities/blockstore/index.ts
18
- import { Capability } from "@dxos/app-framework";
19
- var Blockstore = Capability.lazy("Blockstore", () => import("./blockstore-KKFOALUH.mjs"));
20
-
21
- // src/capabilities/file-uploader/index.ts
22
- import { Capability as Capability2 } from "@dxos/app-framework";
23
- var FileUploader = Capability2.lazy("FileUploader", () => import("./file-uploader-BUHAXRSV.mjs"));
24
-
25
- // src/capabilities/markdown/index.ts
26
- import { Capability as Capability3 } from "@dxos/app-framework";
27
- var Markdown = Capability3.lazy("Markdown", () => import("./markdown-BRT2MN6C.mjs"));
28
-
29
- // src/capabilities/operation-resolver/index.ts
30
- import { Capability as Capability4 } from "@dxos/app-framework";
31
- var OperationResolver = Capability4.lazy("OperationResolver", () => import("./operation-resolver-F6GUL54A.mjs"));
32
-
33
- // src/capabilities/react-surface/index.ts
34
- import { Capability as Capability5 } from "@dxos/app-framework";
35
- var ReactSurface = Capability5.lazy("ReactSurface", () => import("./react-surface-UNAYSIAC.mjs"));
28
+ import { SpaceOperation } from "@dxos/plugin-space/operations";
29
+ import { Blockstore, FileUploader, Markdown, OperationHandler, ReactSurface } from "#capabilities";
30
+ import { meta as meta3 } from "#meta";
31
+ import { WnfsOperation } from "#operations";
32
+ import { WnfsAction, WnfsCapabilities as WnfsCapabilities2, WnfsFile as WnfsFile2 } from "#types";
36
33
 
37
34
  // src/translations.ts
35
+ import { meta as meta2 } from "#meta";
36
+ import { WnfsFile } from "#types";
38
37
  var translations = [
39
38
  {
40
39
  "en-US": {
41
- [File_exports.File.typename]: {
42
- "typename label": "File",
43
- "typename label_zero": "Files",
44
- "typename label_one": "File",
45
- "typename label_other": "Files",
46
- "object name placeholder": "New file",
47
- "rename object label": "Rename file",
48
- "delete object label": "Delete file",
49
- "object deleted label": "File deleted"
40
+ [WnfsFile.File.typename]: {
41
+ "typename.label": "File",
42
+ "typename.label_zero": "Files",
43
+ "typename.label_one": "File",
44
+ "typename.label_other": "Files",
45
+ "object-name.placeholder": "New file",
46
+ "add-object.label": "Add file",
47
+ "rename-object.label": "Rename file",
48
+ "delete-object.label": "Delete file",
49
+ "object-deleted.label": "File deleted"
50
50
  },
51
- [meta.id]: {
52
- "plugin name": "Files",
53
- "file input placeholder": "Drop a file here, or click to select a file"
51
+ [meta2.id]: {
52
+ "plugin.name": "Files",
53
+ "file-input.placeholder": "Drop a file here, or click to select a file"
54
54
  }
55
55
  }
56
56
  }
57
57
  ];
58
58
 
59
59
  // src/WnfsPlugin.tsx
60
- var WnfsPlugin = Plugin.define(meta).pipe(Plugin.addModule({
61
- id: "blockstore",
62
- activatesOn: ClientEvents.ClientReady,
63
- activate: Blockstore
64
- }), Plugin.addModule({
65
- id: "instances",
66
- activatesOn: ClientEvents.ClientReady,
67
- activate: () => Effect.sync(() => {
68
- const instances = {};
69
- return Capability6.contributes(WnfsCapabilities.Instances, instances);
70
- })
71
- }), Common.Plugin.addTranslationsModule({
72
- translations
73
- }), Common.Plugin.addMetadataModule({
60
+ var WnfsPlugin = Plugin.define(meta3).pipe(AppPlugin.addMetadataModule({
74
61
  metadata: {
75
- id: File_exports.File.typename,
62
+ id: WnfsFile2.File.typename,
76
63
  metadata: {
77
64
  // TODO(wittjosiah): Would be nice if icon could change based on the type of the file.
78
- icon: "ph--file--regular",
79
- iconHue: "teal",
65
+ icon: Annotation.IconAnnotation.get(WnfsFile2.File).pipe(Option.getOrThrow).icon,
66
+ iconHue: Annotation.IconAnnotation.get(WnfsFile2.File).pipe(Option.getOrThrow).hue ?? "white",
80
67
  inputSchema: WnfsAction.UploadFileSchema,
81
- createObject: (props, { db }) => Effect.gen(function* () {
68
+ createObject: (props, options) => Effect.gen(function* () {
82
69
  const { object } = yield* Operation.invoke(WnfsOperation.CreateFile, {
83
70
  ...props,
84
- db
71
+ db: options.db
72
+ });
73
+ return yield* Operation.invoke(SpaceOperation.AddObject, {
74
+ object,
75
+ target: options.target,
76
+ hidden: true,
77
+ targetNodeId: options.targetNodeId
85
78
  });
86
- return object;
87
79
  })
88
80
  }
89
81
  }
90
- }), Common.Plugin.addSchemaModule({
82
+ }), AppPlugin.addOperationHandlerModule({
83
+ activate: OperationHandler
84
+ }), AppPlugin.addSchemaModule({
91
85
  schema: [
92
- File_exports.File
86
+ WnfsFile2.File
93
87
  ]
88
+ }), AppPlugin.addSurfaceModule({
89
+ activate: ReactSurface
90
+ }), AppPlugin.addTranslationsModule({
91
+ translations
92
+ }), Plugin.addModule({
93
+ id: "blockstore",
94
+ activatesOn: ClientEvents.ClientReady,
95
+ activate: Blockstore
94
96
  }), Plugin.addModule({
95
- id: "on-space-created",
96
- activatesOn: SpaceEvents.SpaceCreated,
97
- activate: () => Effect.succeed(Capability6.contributes(SpaceCapabilities.OnCreateSpace, (params) => Operation.invoke(WnfsOperation.OnCreateSpace, params)))
97
+ id: "instances",
98
+ activatesOn: ClientEvents.ClientReady,
99
+ activate: () => Effect.sync(() => {
100
+ const instances = {};
101
+ return Capability.contributes(WnfsCapabilities2.Instances, instances);
102
+ })
98
103
  }), Plugin.addModule({
99
104
  id: "file-uploader",
100
105
  activatesOn: ClientEvents.ClientReady,
@@ -103,10 +108,6 @@ var WnfsPlugin = Plugin.define(meta).pipe(Plugin.addModule({
103
108
  id: "markdown",
104
109
  activatesOn: MarkdownEvents.SetupExtensions,
105
110
  activate: Markdown
106
- }), Common.Plugin.addSurfaceModule({
107
- activate: ReactSurface
108
- }), Common.Plugin.addOperationResolverModule({
109
- activate: OperationResolver
110
111
  }), Plugin.make);
111
112
  export {
112
113
  WnfsCapabilities,