@dxos/plugin-wnfs 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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 (144) 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-D6VTEQIE.mjs → chunk-N6Y4QPNF.mjs} +23 -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 +92 -91
  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 +4 -3
  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 +2 -1
  20. package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
  21. package/dist/types/src/capabilities/blockstore.d.ts +3 -2
  22. package/dist/types/src/capabilities/blockstore.d.ts.map +1 -1
  23. package/dist/types/src/capabilities/file-uploader.d.ts +4 -2
  24. package/dist/types/src/capabilities/file-uploader.d.ts.map +1 -1
  25. package/dist/types/src/capabilities/index.d.ts +7 -6
  26. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  27. package/dist/types/src/capabilities/markdown.d.ts +3 -2
  28. package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
  29. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  30. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  31. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  32. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  33. package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
  34. package/dist/types/src/components/FileInput/index.d.ts +2 -0
  35. package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
  36. package/dist/types/src/components/FilePreview/FilePreview.d.ts +16 -0
  37. package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
  38. package/dist/types/src/components/FilePreview/index.d.ts +2 -0
  39. package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
  40. package/dist/types/src/components/index.d.ts +1 -1
  41. package/dist/types/src/components/index.d.ts.map +1 -1
  42. package/dist/types/src/containers/FileContainer/FileContainer.d.ts +7 -0
  43. package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
  44. package/dist/types/src/containers/FileContainer/index.d.ts +2 -0
  45. package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -0
  46. package/dist/types/src/containers/index.d.ts +3 -0
  47. package/dist/types/src/containers/index.d.ts.map +1 -0
  48. package/dist/types/src/extensions/image.d.ts +1 -1
  49. package/dist/types/src/extensions/image.d.ts.map +1 -1
  50. package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
  51. package/dist/types/src/helpers/load.d.ts +1 -1
  52. package/dist/types/src/helpers/load.d.ts.map +1 -1
  53. package/dist/types/src/helpers/upload.d.ts +1 -1
  54. package/dist/types/src/helpers/upload.d.ts.map +1 -1
  55. package/dist/types/src/index.d.ts +1 -1
  56. package/dist/types/src/index.d.ts.map +1 -1
  57. package/dist/types/src/meta.d.ts +2 -2
  58. package/dist/types/src/meta.d.ts.map +1 -1
  59. package/dist/types/src/operations/create-file.d.ts +5 -0
  60. package/dist/types/src/operations/create-file.d.ts.map +1 -0
  61. package/dist/types/src/operations/create.d.ts +5 -0
  62. package/dist/types/src/operations/create.d.ts.map +1 -0
  63. package/dist/types/src/operations/definitions.d.ts +38 -0
  64. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  65. package/dist/types/src/operations/index.d.ts +4 -0
  66. package/dist/types/src/operations/index.d.ts.map +1 -0
  67. package/dist/types/src/operations/upload.d.ts +5 -0
  68. package/dist/types/src/operations/upload.d.ts.map +1 -0
  69. package/dist/types/src/translations.d.ts +13 -9
  70. package/dist/types/src/translations.d.ts.map +1 -1
  71. package/dist/types/src/types/File.d.ts +11 -11
  72. package/dist/types/src/types/File.d.ts.map +1 -1
  73. package/dist/types/src/{capabilities → types}/capabilities.d.ts +3 -2
  74. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  75. package/dist/types/src/types/index.d.ts +1 -0
  76. package/dist/types/src/types/index.d.ts.map +1 -1
  77. package/dist/types/src/types/types.d.ts +4 -50
  78. package/dist/types/src/types/types.d.ts.map +1 -1
  79. package/dist/types/tsconfig.tsbuildinfo +1 -1
  80. package/package.json +59 -36
  81. package/src/WnfsPlugin.tsx +53 -73
  82. package/src/blockstore.ts +1 -1
  83. package/src/capabilities/blockstore.ts +15 -11
  84. package/src/capabilities/file-uploader.ts +24 -17
  85. package/src/capabilities/index.ts +10 -8
  86. package/src/capabilities/markdown.ts +22 -14
  87. package/src/capabilities/operation-handler.ts +16 -0
  88. package/src/capabilities/react-surface.tsx +40 -34
  89. package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +6 -6
  90. package/src/components/FileInput/index.ts +5 -0
  91. package/src/components/FilePreview/FilePreview.tsx +43 -0
  92. package/src/components/FilePreview/index.ts +5 -0
  93. package/src/components/index.ts +1 -4
  94. package/src/{components → containers/FileContainer}/FileContainer.tsx +13 -15
  95. package/src/containers/FileContainer/index.ts +5 -0
  96. package/src/containers/index.ts +7 -0
  97. package/src/extensions/image.stories.tsx +8 -9
  98. package/src/extensions/image.tsx +4 -3
  99. package/src/helpers/load.ts +12 -7
  100. package/src/helpers/upload.ts +5 -2
  101. package/src/index.ts +1 -1
  102. package/src/meta.ts +3 -3
  103. package/src/operations/create-file.ts +31 -0
  104. package/src/operations/create.ts +22 -0
  105. package/src/operations/definitions.ts +41 -0
  106. package/src/operations/index.ts +13 -0
  107. package/src/operations/upload.ts +29 -0
  108. package/src/translations.ts +13 -9
  109. package/src/types/File.ts +11 -7
  110. package/src/{capabilities → types}/capabilities.ts +4 -4
  111. package/src/types/index.ts +1 -0
  112. package/src/types/types.ts +3 -20
  113. package/dist/lib/browser/FileContainer-LLNI7WXR.mjs +0 -103
  114. package/dist/lib/browser/FileContainer-LLNI7WXR.mjs.map +0 -7
  115. package/dist/lib/browser/blockstore-2JFU4NBU.mjs +0 -191
  116. package/dist/lib/browser/blockstore-2JFU4NBU.mjs.map +0 -7
  117. package/dist/lib/browser/chunk-CWMKN2F6.mjs +0 -71
  118. package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +0 -7
  119. package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
  120. package/dist/lib/browser/chunk-F4QHZWQD.mjs +0 -16
  121. package/dist/lib/browser/chunk-F4QHZWQD.mjs.map +0 -7
  122. package/dist/lib/browser/chunk-OGPGLJCV.mjs +0 -25
  123. package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +0 -7
  124. package/dist/lib/browser/chunk-ZFPJA5F4.mjs +0 -16
  125. package/dist/lib/browser/chunk-ZFPJA5F4.mjs.map +0 -7
  126. package/dist/lib/browser/file-uploader-W6TJLAAK.mjs +0 -30
  127. package/dist/lib/browser/file-uploader-W6TJLAAK.mjs.map +0 -7
  128. package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs +0 -48
  129. package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +0 -7
  130. package/dist/lib/browser/markdown-WYQDCVFQ.mjs +0 -198
  131. package/dist/lib/browser/markdown-WYQDCVFQ.mjs.map +0 -7
  132. package/dist/lib/browser/react-surface-DMU47U3X.mjs +0 -88
  133. package/dist/lib/browser/react-surface-DMU47U3X.mjs.map +0 -7
  134. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  135. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  136. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  137. package/dist/types/src/components/FileContainer.d.ts +0 -9
  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/intent-resolver.ts +0 -32
  143. package/src/components/FilePreview.tsx +0 -23
  144. /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,16 +48,18 @@ 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";
48
54
  import * as Uint8Arrays from "uint8arrays";
49
55
  import { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from "wnfs";
56
+ import { Obj } from "@dxos/echo";
50
57
  var loadWnfs = async ({ space, blockstore, instances }) => {
51
58
  if (space.properties.wnfs_access_key !== void 0 && space.properties.wnfs_private_forest_cid !== void 0) {
52
- delete space.properties.wnfs_access_key;
53
- delete space.properties.wnfs_private_forest_cid;
59
+ Obj.change(space.properties, (obj) => {
60
+ delete obj["wnfs_access_key"];
61
+ delete obj["wnfs_private_forest_cid"];
62
+ });
54
63
  }
55
64
  const cacheKey = space.properties.wnfs?.privateForestCid;
56
65
  if (instances?.[cacheKey]) {
@@ -71,10 +80,12 @@ var createWnfsDir = async (blockstore, space) => {
71
80
  const dir = dirResult.rootDir;
72
81
  const [accessKeyRaw, newForest] = await dir.asNode().store(dirResult.forest, wnfsStore, rng);
73
82
  const cidBytes = await newForest.store(wnfsStore);
74
- space.properties.wnfs = {
75
- accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), "base64"),
76
- privateForestCid: CID2.decode(cidBytes).toString()
77
- };
83
+ Obj.change(space.properties, (obj) => {
84
+ obj.wnfs = {
85
+ accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), "base64"),
86
+ privateForestCid: CID2.decode(cidBytes).toString()
87
+ };
88
+ });
78
89
  return {
79
90
  directory: dir,
80
91
  forest: newForest
@@ -95,24 +106,8 @@ var loadWnfsDir = async (blockstore, space) => {
95
106
  var wnfsUrl = (filePath2) => {
96
107
  return "wnfs://" + filePath2.map((f) => encodeURIComponent(f)).join("/");
97
108
  };
98
- var getPathFromUrl = (wnfsUrl2) => wnfsUrl2.replace(/^wnfs:\/\//, "").split("/").map((p) => decodeURIComponent(p));
99
- var getBlobUrl = async ({ wnfsUrl: wnfsUrl2, blockstore, forest, directory, type }) => {
100
- const path = getPathFromUrl(wnfsUrl2);
101
- const wnfsStore = store(blockstore);
102
- const { result } = await directory.read(path, true, forest, wnfsStore);
103
- const blob = new Blob([
104
- result
105
- ], {
106
- type
107
- });
108
- return URL.createObjectURL(blob);
109
- };
110
109
 
111
110
  // src/helpers/upload.ts
112
- import { CID as CID3 } from "multiformats";
113
- import * as Raw from "multiformats/codecs/raw";
114
- import { sha256 as sha2562 } from "multiformats/hashes/sha2";
115
- import { log } from "@dxos/log";
116
111
  var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/helpers/upload.ts";
117
112
  var upload = async ({ file, blockstore, instances, space }) => {
118
113
  const { directory, forest } = await loadWnfs({
@@ -128,7 +123,9 @@ var upload = async ({ file, blockstore, instances, space }) => {
128
123
  const result = await directory.write(path, true, bytes, /* @__PURE__ */ new Date(), forest, wnfsStore, new Rng());
129
124
  const [_, updatedForest] = await result.rootDir.store(result.forest, wnfsStore, new Rng());
130
125
  const cidBytes = await updatedForest.store(wnfsStore);
131
- space.properties.wnfs.privateForestCid = CID3.decode(cidBytes).toString();
126
+ Obj2.change(space.properties, (obj) => {
127
+ obj.wnfs.privateForestCid = CID3.decode(cidBytes).toString();
128
+ });
132
129
  const info = {
133
130
  name: file.name,
134
131
  type: file.type,
@@ -140,7 +137,7 @@ var upload = async ({ file, blockstore, instances, space }) => {
140
137
  info
141
138
  }, {
142
139
  F: __dxlog_file,
143
- L: 59,
140
+ L: 62,
144
141
  S: void 0,
145
142
  C: (f, a) => f(...a)
146
143
  });
@@ -148,12 +145,6 @@ var upload = async ({ file, blockstore, instances, space }) => {
148
145
  };
149
146
 
150
147
  export {
151
- filePath,
152
- storeName,
153
- loadWnfs,
154
- wnfsUrl,
155
- getPathFromUrl,
156
- getBlobUrl,
157
148
  upload
158
149
  };
159
- //# sourceMappingURL=chunk-D6VTEQIE.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,SAASA,OAAAA,YAAW;AACpB,YAAYC,SAAS;AACrB,SAASC,UAAAA,eAAc;AAGvB,SAASC,OAAAA,YAAW;AACpB,SAASC,WAAW;;;ACNpB,SAASC,WAAW;A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AAMgB,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,113 +1,114 @@
1
- import {
2
- Blockstore,
3
- FileUploader,
4
- IntentResolver,
5
- Markdown,
6
- ReactSurface
7
- } from "./chunk-ZFPJA5F4.mjs";
8
1
  import {
9
2
  WnfsCapabilities
10
- } from "./chunk-F4QHZWQD.mjs";
11
- import {
12
- File_exports,
13
- WnfsAction
14
- } from "./chunk-CWMKN2F6.mjs";
15
- import {
16
- meta
17
- } from "./chunk-OGPGLJCV.mjs";
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
+ };
18
18
 
19
19
  // src/WnfsPlugin.tsx
20
- import * as Function from "effect/Function";
21
- import { Capabilities, Events, chain, contributes, createIntent, defineModule, definePlugin } from "@dxos/app-framework";
22
- import { ClientEvents } from "@dxos/plugin-client";
20
+ import * as Effect from "effect/Effect";
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";
25
+ import { Operation } from "@dxos/operation";
26
+ import { ClientEvents } from "@dxos/plugin-client/types";
23
27
  import { MarkdownEvents } from "@dxos/plugin-markdown";
24
- import { SpaceCapabilities } from "@dxos/plugin-space";
25
- import { defineObjectForm } from "@dxos/plugin-space/types";
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";
26
33
 
27
34
  // src/translations.ts
35
+ import { meta as meta2 } from "#meta";
36
+ import { WnfsFile } from "#types";
28
37
  var translations = [
29
38
  {
30
39
  "en-US": {
31
- [File_exports.File.typename]: {
32
- "typename label": "File",
33
- "object name placeholder": "New file",
34
- "rename object label": "Rename file",
35
- "delete object label": "Delete file"
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"
36
50
  },
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"
51
+ [meta2.id]: {
52
+ "plugin.name": "Files",
53
+ "file-input.placeholder": "Drop a file here, or click to select a file"
41
54
  }
42
55
  }
43
56
  }
44
57
  ];
45
58
 
46
59
  // 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);
60
+ var WnfsPlugin = Plugin.define(meta3).pipe(AppPlugin.addMetadataModule({
61
+ metadata: {
62
+ id: WnfsFile2.File.typename,
63
+ metadata: {
64
+ // TODO(wittjosiah): Would be nice if icon could change based on the type of the file.
65
+ icon: Annotation.IconAnnotation.get(WnfsFile2.File).pipe(Option.getOrThrow).icon,
66
+ iconHue: Annotation.IconAnnotation.get(WnfsFile2.File).pipe(Option.getOrThrow).hue ?? "white",
67
+ inputSchema: WnfsAction.UploadFileSchema,
68
+ createObject: (props, options) => Effect.gen(function* () {
69
+ const { object } = yield* Operation.invoke(WnfsOperation.CreateFile, {
70
+ ...props,
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
78
+ });
79
+ })
59
80
  }
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: File_exports.File.typename,
71
- metadata: {
72
- // TODO(wittjosiah): Would be nice if icon could change based on the type of the file.
73
- icon: "ph--file--regular",
74
- iconHue: "teal"
75
- }
76
- })
77
- }),
78
- defineModule({
79
- id: `${meta.id}/module/object-form`,
80
- activatesOn: ClientEvents.SetupSchema,
81
- activate: () => contributes(SpaceCapabilities.ObjectForm, defineObjectForm({
82
- objectSchema: File_exports.File,
83
- formSchema: WnfsAction.UploadFileSchema,
84
- getIntent: (props, options) => Function.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
81
+ }
82
+ }), AppPlugin.addOperationHandlerModule({
83
+ activate: OperationHandler
84
+ }), AppPlugin.addSchemaModule({
85
+ schema: [
86
+ WnfsFile2.File
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
96
+ }), Plugin.addModule({
97
+ id: "instances",
98
+ activatesOn: ClientEvents.ClientReady,
99
+ activate: () => Effect.sync(() => {
100
+ const instances = {};
101
+ return Capability.contributes(WnfsCapabilities2.Instances, instances);
109
102
  })
110
- ]);
103
+ }), Plugin.addModule({
104
+ id: "file-uploader",
105
+ activatesOn: ClientEvents.ClientReady,
106
+ activate: FileUploader
107
+ }), Plugin.addModule({
108
+ id: "markdown",
109
+ activatesOn: MarkdownEvents.SetupExtensions,
110
+ activate: Markdown
111
+ }), Plugin.make);
111
112
  export {
112
113
  WnfsCapabilities,
113
114
  WnfsPlugin,