@dxos/plugin-wnfs 0.8.4-main.abd8ff62ef → 0.8.4-main.bc2380dfbc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/neutral/FileArticle-B3NF2VKL.mjs +58 -0
- package/dist/lib/neutral/FileArticle-B3NF2VKL.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.mjs +50 -0
- package/dist/lib/neutral/WnfsPlugin.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs +23 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.workerd.mjs +21 -0
- package/dist/lib/neutral/WnfsPlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/blockstore-3NLSWC7Z.mjs +190 -0
- package/dist/lib/neutral/blockstore-3NLSWC7Z.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +19 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/{browser/index.mjs → neutral/chunk-LHUHUCBD.mjs} +1 -13
- package/dist/lib/neutral/chunk-LHUHUCBD.mjs.map +7 -0
- package/dist/lib/neutral/chunk-UIZBWELF.mjs +8 -0
- package/dist/lib/neutral/chunk-UIZBWELF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-VWVCHTUK.mjs +125 -0
- package/dist/lib/neutral/chunk-VWVCHTUK.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +63 -0
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +9 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/{browser/create-QRLX4IMZ.mjs → neutral/create-4ERE5CA4.mjs} +6 -8
- package/dist/lib/neutral/create-4ERE5CA4.mjs.map +7 -0
- package/dist/lib/{browser/create-file-INAT56PX.mjs → neutral/create-file-RAHDIJVU.mjs} +11 -13
- package/dist/lib/neutral/create-file-RAHDIJVU.mjs.map +7 -0
- package/dist/lib/neutral/create-object-7PJC47BB.mjs +33 -0
- package/dist/lib/neutral/create-object-7PJC47BB.mjs.map +7 -0
- package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs +34 -0
- package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +40 -0
- package/dist/lib/neutral/markdown-I4FYAUCA.mjs +204 -0
- package/dist/lib/neutral/markdown-I4FYAUCA.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/operation-handler-NPYSIPMR.mjs +13 -0
- package/dist/lib/neutral/operation-handler-NPYSIPMR.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +8 -0
- package/dist/lib/neutral/operations/index.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-6QHCDYC3.mjs +53 -0
- package/dist/lib/neutral/react-surface-6QHCDYC3.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/translations.mjs +1 -1
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +14 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/lib/{browser/upload-ZQI66T4Y.mjs → neutral/upload-VA5CSUEP.mjs} +9 -11
- package/dist/lib/neutral/upload-VA5CSUEP.mjs.map +7 -0
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -1
- package/dist/types/src/WnfsPlugin.workerd.d.ts +4 -0
- package/dist/types/src/WnfsPlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/capabilities/create-object.d.ts +11 -0
- package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +7 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/markdown.d.ts +1 -1
- package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
- package/dist/types/src/containers/FileArticle/FileArticle.d.ts +7 -0
- package/dist/types/src/containers/FileArticle/FileArticle.d.ts.map +1 -0
- package/dist/types/src/containers/FileArticle/index.d.ts +2 -0
- package/dist/types/src/containers/FileArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +1 -1
- package/dist/types/src/containers/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/operations/create-file.d.ts +2 -2
- package/dist/types/src/operations/create-file.d.ts.map +1 -1
- package/dist/types/src/operations/create.d.ts +2 -2
- package/dist/types/src/operations/create.d.ts.map +1 -1
- package/dist/types/src/operations/index.d.ts +0 -1
- package/dist/types/src/operations/index.d.ts.map +1 -1
- package/dist/types/src/operations/upload.d.ts +2 -2
- package/dist/types/src/operations/upload.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/types/WnfsCapabilities.d.ts +11 -0
- package/dist/types/src/types/WnfsCapabilities.d.ts.map +1 -0
- package/dist/types/src/types/{File.d.ts → WnfsFile.d.ts} +4 -4
- package/dist/types/src/types/WnfsFile.d.ts.map +1 -0
- package/dist/types/src/{operations/definitions.d.ts → types/WnfsOperation.d.ts} +1 -1
- package/dist/types/src/types/WnfsOperation.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +3 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +87 -61
- package/src/WnfsPlugin.node.ts +4 -32
- package/src/WnfsPlugin.test.ts +3 -3
- package/src/WnfsPlugin.tsx +6 -32
- package/src/WnfsPlugin.workerd.ts +18 -0
- package/src/capabilities/blockstore.ts +1 -1
- package/src/capabilities/create-object.ts +33 -0
- package/src/capabilities/file-uploader.ts +2 -2
- package/src/capabilities/index.ts +1 -0
- package/src/capabilities/markdown.ts +1 -1
- package/src/capabilities/react-surface.tsx +5 -5
- package/src/containers/{FileContainer/FileContainer.tsx → FileArticle/FileArticle.tsx} +3 -3
- package/src/containers/FileArticle/index.ts +5 -0
- package/src/containers/index.ts +1 -1
- package/src/index.ts +2 -8
- package/src/operations/create-file.ts +3 -4
- package/src/operations/create.ts +2 -3
- package/src/operations/index.ts +0 -2
- package/src/operations/upload.ts +3 -4
- package/src/plugin.ts +11 -0
- package/src/translations.ts +1 -1
- package/src/types/WnfsCapabilities.ts +18 -0
- package/src/types/{File.ts → WnfsFile.ts} +5 -3
- package/src/{operations/definitions.ts → types/WnfsOperation.ts} +6 -3
- package/src/types/index.ts +4 -2
- package/dist/lib/browser/chunk-4D4K5JCC.mjs +0 -66
- package/dist/lib/browser/chunk-4D4K5JCC.mjs.map +0 -7
- package/dist/lib/browser/chunk-DK62NQ5T.mjs +0 -71
- package/dist/lib/browser/chunk-DK62NQ5T.mjs.map +0 -7
- package/dist/lib/browser/create-QRLX4IMZ.mjs.map +0 -7
- package/dist/lib/browser/create-file-INAT56PX.mjs.map +0 -7
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/operations/index.mjs +0 -14
- package/dist/lib/browser/operations/index.mjs.map +0 -7
- package/dist/lib/browser/translations.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -12
- package/dist/lib/browser/upload-ZQI66T4Y.mjs.map +0 -7
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts +0 -7
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +0 -1
- package/dist/types/src/containers/FileContainer/index.d.ts +0 -2
- package/dist/types/src/containers/FileContainer/index.d.ts.map +0 -1
- package/dist/types/src/operations/definitions.d.ts.map +0 -1
- package/dist/types/src/types/File.d.ts.map +0 -1
- package/dist/types/src/types/capabilities.d.ts +0 -13
- package/dist/types/src/types/capabilities.d.ts.map +0 -1
- package/src/containers/FileContainer/index.ts +0 -5
- package/src/types/capabilities.ts +0 -18
- /package/dist/lib/{browser → neutral}/chunk-7KFJ6LYH.mjs +0 -0
- /package/dist/lib/{browser → neutral}/chunk-7KFJ6LYH.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
- /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/helpers/index.mjs +0 -0
- /package/dist/lib/{browser → neutral}/helpers/index.mjs.map +0 -0
- /package/dist/lib/{browser/types → neutral}/index.mjs.map +0 -0
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2024 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -12,4 +12,4 @@ Plugin that allows for data to be stored on WNFS.
|
|
|
12
12
|
|
|
13
13
|
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
14
14
|
|
|
15
|
-
License: [
|
|
15
|
+
License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2024 © DXOS
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
filePath,
|
|
3
|
+
getBlobUrl,
|
|
4
|
+
loadWnfs,
|
|
5
|
+
wnfsUrl
|
|
6
|
+
} from "./chunk-7KFJ6LYH.mjs";
|
|
7
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
8
|
+
|
|
9
|
+
// src/containers/FileArticle/FileArticle.tsx
|
|
10
|
+
import React, { useState } from "react";
|
|
11
|
+
import { useCapability } from "@dxos/app-framework/ui";
|
|
12
|
+
import { invariant } from "@dxos/invariant";
|
|
13
|
+
import { getSpace } from "@dxos/react-client/echo";
|
|
14
|
+
import { Panel, useAsyncEffect } from "@dxos/react-ui";
|
|
15
|
+
import { FilePreview } from "#components";
|
|
16
|
+
import { WnfsCapabilities } from "#types";
|
|
17
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/containers/FileArticle/FileArticle.tsx";
|
|
18
|
+
var FileArticle = ({ role, subject: file }) => {
|
|
19
|
+
const blockstore = useCapability(WnfsCapabilities.Blockstore);
|
|
20
|
+
const instances = useCapability(WnfsCapabilities.Instances);
|
|
21
|
+
const [blobUrl, setBlobUrl] = useState();
|
|
22
|
+
useAsyncEffect(async () => {
|
|
23
|
+
const space = getSpace(file);
|
|
24
|
+
invariant(space, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 18, S: void 0, A: ["space", ""] });
|
|
25
|
+
const { directory, forest } = await loadWnfs({
|
|
26
|
+
blockstore,
|
|
27
|
+
instances,
|
|
28
|
+
space
|
|
29
|
+
});
|
|
30
|
+
const path = filePath(file.cid.toString(), space);
|
|
31
|
+
const url = await getBlobUrl({
|
|
32
|
+
wnfsUrl: wnfsUrl(path),
|
|
33
|
+
blockstore,
|
|
34
|
+
directory,
|
|
35
|
+
forest,
|
|
36
|
+
type: file.type
|
|
37
|
+
});
|
|
38
|
+
setBlobUrl(url);
|
|
39
|
+
}, [
|
|
40
|
+
file
|
|
41
|
+
]);
|
|
42
|
+
if (!blobUrl) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return /* @__PURE__ */ React.createElement(Panel.Root, {
|
|
46
|
+
role,
|
|
47
|
+
className: "dx-document"
|
|
48
|
+
}, /* @__PURE__ */ React.createElement(Panel.Content, {
|
|
49
|
+
asChild: true
|
|
50
|
+
}, /* @__PURE__ */ React.createElement(FilePreview, {
|
|
51
|
+
type: file.type,
|
|
52
|
+
url: blobUrl
|
|
53
|
+
})));
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
FileArticle as default
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=FileArticle-B3NF2VKL.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/containers/FileArticle/FileArticle.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport { useCapability } from '@dxos/app-framework/ui';\nimport { type AppSurface } from '@dxos/app-toolkit/ui';\nimport { invariant } from '@dxos/invariant';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { Panel, useAsyncEffect } from '@dxos/react-ui';\n\nimport { FilePreview } from '#components';\nimport { WnfsCapabilities, type WnfsFile } from '#types';\n\nimport { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../../helpers';\n\nexport type FileArticleProps = AppSurface.ObjectArticleProps<WnfsFile.WnfsFile>;\n\nexport const FileArticle = ({ role, subject: file }: FileArticleProps) => {\n const blockstore = useCapability(WnfsCapabilities.Blockstore);\n const instances = useCapability(WnfsCapabilities.Instances);\n const [blobUrl, setBlobUrl] = useState<string>();\n\n useAsyncEffect(async () => {\n const space = getSpace(file);\n invariant(space);\n const { directory, forest } = await loadWnfs({\n blockstore,\n instances,\n space,\n });\n const path = filePath(file.cid.toString(), space);\n const url = await getBlobUrl({\n wnfsUrl: wnfsUrl(path),\n blockstore,\n directory,\n forest,\n type: file.type,\n });\n setBlobUrl(url);\n }, [file]);\n\n if (!blobUrl) {\n return null;\n }\n\n return (\n <Panel.Root role={role} className='dx-document'>\n <Panel.Content asChild>\n <FilePreview type={file.type} url={blobUrl} />\n </Panel.Content>\n </Panel.Root>\n );\n};\n\nexport default FileArticle;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAIA,OAAOA,SAASC,gBAAgB;AAEhC,SAASC,qBAAqB;AAE9B,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,OAAOC,sBAAsB;AAEtC,SAASC,mBAAmB;AAC5B,SAASC,wBAAuC;AAMhD,IAAA,eAAaC;AAEX,IAAMC,cAAYC,CAAAA,EAAAA,MAAcC,SAAAA,KAAAA,MAAiBC;AACjD,QAAM,aAAUC,cAAcC,iBAAAA,UAAAA;AAE9BC,QAAAA,YAAe,cAAA,iBAAA,SAAA;QACb,CAAA,SAAMC,UAAQC,IAASC,SAAAA;iBACbF,YAAAA;AACV,UAAM,QAAEG,SAAWC,IAAQ;cACzBC,OAAAA,QAAAA,EAAAA,YAAAA,YAAAA,GAAAA,cAAAA,GAAAA,IAAAA,GAAAA,QAAAA,GAAAA,CAAAA,SAAAA,EAAAA,EAAAA,CAAAA;UACAZ,EAAAA,WAAAA,OAAAA,IAAAA,MAAAA,SAAAA;MACAO;MACF;MACA;IACA,CAAA;UACEM,OAASA,SAAQC,KAAAA,IAAAA,SAAAA,GAAAA,KAAAA;UACjBF,MAAAA,MAAAA,WAAAA;MACAF,SAAAA,QAAAA,IAAAA;MACAC;MACAI;MACF;MACAX,MAAAA,KAAWY;IACV,CAAA;AAACP,eAAAA,GAAAA;KAAK;IAEL;;AAEJ,MAAA,CAAA,SAAA;AAEA,WAAA;;SACoC,sBAAA,cAAA,MAAA,MAAA;;IACjBQ,WAAAA;KACb,sBAAA,cAACC,MAAAA,SAAAA;IAAYH,SAAMN;KAAgBU,sBAAAA,cAAAA,aAAAA;;IAIzC,KAAA;EAEF,CAAA,CAAA,CAAA;;",
|
|
6
|
+
"names": ["React", "useState", "useCapability", "invariant", "getSpace", "Panel", "useAsyncEffect", "FilePreview", "WnfsCapabilities", "FileArticle", "instances", "useCapability", "WnfsCapabilities", "Instances", "setBlobUrl", "useState", "useAsyncEffect", "space", "getSpace", "file", "directory", "forest", "blockstore", "wnfsUrl", "path", "type", "url", "asChild", "FilePreview", "blobUrl"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
2
|
+
|
|
3
|
+
// src/WnfsPlugin.tsx
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import { Capability, Plugin } from "@dxos/app-framework";
|
|
6
|
+
import { AppPlugin } from "@dxos/app-toolkit";
|
|
7
|
+
import { ClientEvents } from "@dxos/plugin-client";
|
|
8
|
+
import { MarkdownEvents } from "@dxos/plugin-markdown";
|
|
9
|
+
import { Blockstore, CreateObject, FileUploader, Markdown, OperationHandler, ReactSurface } from "#capabilities";
|
|
10
|
+
import { meta } from "#meta";
|
|
11
|
+
import { translations } from "#translations";
|
|
12
|
+
import { WnfsCapabilities, WnfsFile } from "#types";
|
|
13
|
+
var WnfsPlugin = Plugin.define(meta).pipe(AppPlugin.addCreateObjectModule({
|
|
14
|
+
activate: CreateObject
|
|
15
|
+
}), AppPlugin.addOperationHandlerModule({
|
|
16
|
+
activate: OperationHandler
|
|
17
|
+
}), AppPlugin.addSchemaModule({
|
|
18
|
+
schema: [
|
|
19
|
+
WnfsFile.WnfsFile
|
|
20
|
+
]
|
|
21
|
+
}), AppPlugin.addSurfaceModule({
|
|
22
|
+
activate: ReactSurface
|
|
23
|
+
}), AppPlugin.addTranslationsModule({
|
|
24
|
+
translations
|
|
25
|
+
}), Plugin.addModule({
|
|
26
|
+
id: "blockstore",
|
|
27
|
+
activatesOn: ClientEvents.ClientReady,
|
|
28
|
+
activate: Blockstore
|
|
29
|
+
}), Plugin.addModule({
|
|
30
|
+
id: "instances",
|
|
31
|
+
activatesOn: ClientEvents.ClientReady,
|
|
32
|
+
activate: () => Effect.sync(() => {
|
|
33
|
+
const instances = {};
|
|
34
|
+
return Capability.contributes(WnfsCapabilities.Instances, instances);
|
|
35
|
+
})
|
|
36
|
+
}), Plugin.addModule({
|
|
37
|
+
id: "file-uploader",
|
|
38
|
+
activatesOn: ClientEvents.ClientReady,
|
|
39
|
+
activate: FileUploader
|
|
40
|
+
}), Plugin.addModule({
|
|
41
|
+
id: "markdown",
|
|
42
|
+
activatesOn: MarkdownEvents.SetupExtensions,
|
|
43
|
+
activate: Markdown
|
|
44
|
+
}), Plugin.make);
|
|
45
|
+
var WnfsPlugin_default = WnfsPlugin;
|
|
46
|
+
export {
|
|
47
|
+
WnfsPlugin,
|
|
48
|
+
WnfsPlugin_default as default
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=WnfsPlugin.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/WnfsPlugin.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability, Plugin } from '@dxos/app-framework';\nimport { AppPlugin } from '@dxos/app-toolkit';\nimport { ClientEvents } from '@dxos/plugin-client';\nimport { MarkdownEvents } from '@dxos/plugin-markdown';\n\nimport { Blockstore, CreateObject, FileUploader, Markdown, OperationHandler, ReactSurface } from '#capabilities';\nimport { meta } from '#meta';\nimport { translations } from '#translations';\nimport { WnfsCapabilities, WnfsFile } from '#types';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(\n AppPlugin.addCreateObjectModule({ activate: CreateObject }),\n AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),\n AppPlugin.addSchemaModule({ schema: [WnfsFile.WnfsFile] }),\n AppPlugin.addSurfaceModule({ activate: ReactSurface }),\n AppPlugin.addTranslationsModule({ translations }),\n Plugin.addModule({\n id: 'blockstore',\n activatesOn: ClientEvents.ClientReady,\n activate: Blockstore,\n }),\n Plugin.addModule({\n id: 'instances',\n activatesOn: ClientEvents.ClientReady,\n activate: () =>\n Effect.sync(() => {\n const instances: WnfsCapabilities.Instances = {};\n return Capability.contributes(WnfsCapabilities.Instances, instances);\n }),\n }),\n Plugin.addModule({\n id: 'file-uploader',\n activatesOn: ClientEvents.ClientReady,\n activate: FileUploader,\n }),\n Plugin.addModule({\n id: 'markdown',\n activatesOn: MarkdownEvents.SetupExtensions,\n activate: Markdown,\n }),\n Plugin.make,\n);\n\nexport default WnfsPlugin;\n"],
|
|
5
|
+
"mappings": ";;;AAIA,YAAYA,YAAY;AAExB,SAASC,YAAYC,cAAc;AACnC,SAASC,iBAAiB;AAC1B,SAASC,oBAAoB;AAC7B,SAASC,sBAAsB;AAE/B,SAASC,YAAYC,cAAcC,cAAcC,UAAUC,kBAAkBC,oBAAoB;AACjG,SAASC,YAAY;AACrB,SAASC,oBAAoB;AAC7B,SAASC,kBAAkBC,gBAAgB;AAEpC,IAAMC,aAAad,OAAOe,OAAOL,IAAAA,EAAMM,KAC5Cf,UAAUgB,sBAAsB;EAAEC,UAAUb;AAAa,CAAA,GACzDJ,UAAUkB,0BAA0B;EAAED,UAAUV;AAAiB,CAAA,GACjEP,UAAUmB,gBAAgB;EAAEC,QAAQ;IAACR,SAASA;;AAAU,CAAA,GACxDZ,UAAUqB,iBAAiB;EAAEJ,UAAUT;AAAa,CAAA,GACpDR,UAAUsB,sBAAsB;EAAEZ;AAAa,CAAA,GAC/CX,OAAOwB,UAAU;EACfC,IAAI;EACJC,aAAaxB,aAAayB;EAC1BT,UAAUd;AACZ,CAAA,GACAJ,OAAOwB,UAAU;EACfC,IAAI;EACJC,aAAaxB,aAAayB;EAC1BT,UAAU,MACDU,YAAK,MAAA;AACV,UAAMC,YAAwC,CAAC;AAC/C,WAAO9B,WAAW+B,YAAYlB,iBAAiBmB,WAAWF,SAAAA;EAC5D,CAAA;AACJ,CAAA,GACA7B,OAAOwB,UAAU;EACfC,IAAI;EACJC,aAAaxB,aAAayB;EAC1BT,UAAUZ;AACZ,CAAA,GACAN,OAAOwB,UAAU;EACfC,IAAI;EACJC,aAAavB,eAAe6B;EAC5Bd,UAAUX;AACZ,CAAA,GACAP,OAAOiC,IAAI;AAGb,IAAA,qBAAenB;",
|
|
6
|
+
"names": ["Effect", "Capability", "Plugin", "AppPlugin", "ClientEvents", "MarkdownEvents", "Blockstore", "CreateObject", "FileUploader", "Markdown", "OperationHandler", "ReactSurface", "meta", "translations", "WnfsCapabilities", "WnfsFile", "WnfsPlugin", "define", "pipe", "addCreateObjectModule", "activate", "addOperationHandlerModule", "addSchemaModule", "schema", "addSurfaceModule", "addTranslationsModule", "addModule", "id", "activatesOn", "ClientReady", "sync", "instances", "contributes", "Instances", "SetupExtensions", "make"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
2
|
+
|
|
3
|
+
// src/WnfsPlugin.node.ts
|
|
4
|
+
import { Plugin } from "@dxos/app-framework";
|
|
5
|
+
import { AppPlugin } from "@dxos/app-toolkit";
|
|
6
|
+
import { CreateObject, OperationHandler } from "#capabilities";
|
|
7
|
+
import { meta } from "#meta";
|
|
8
|
+
import { WnfsFile } from "#types";
|
|
9
|
+
var WnfsPlugin = Plugin.define(meta).pipe(AppPlugin.addCreateObjectModule({
|
|
10
|
+
activate: CreateObject
|
|
11
|
+
}), AppPlugin.addOperationHandlerModule({
|
|
12
|
+
activate: OperationHandler
|
|
13
|
+
}), AppPlugin.addSchemaModule({
|
|
14
|
+
schema: [
|
|
15
|
+
WnfsFile.WnfsFile
|
|
16
|
+
]
|
|
17
|
+
}), Plugin.make);
|
|
18
|
+
var WnfsPlugin_node_default = WnfsPlugin;
|
|
19
|
+
export {
|
|
20
|
+
WnfsPlugin,
|
|
21
|
+
WnfsPlugin_node_default as default
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=WnfsPlugin.node.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/WnfsPlugin.node.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppPlugin } from '@dxos/app-toolkit';\n\nimport { CreateObject, OperationHandler } from '#capabilities';\nimport { meta } from '#meta';\nimport { WnfsFile } from '#types';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(\n AppPlugin.addCreateObjectModule({ activate: CreateObject }),\n AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),\n AppPlugin.addSchemaModule({ schema: [WnfsFile.WnfsFile] }),\n Plugin.make,\n);\n\nexport default WnfsPlugin;\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,cAAc;AACvB,SAASC,iBAAiB;AAE1B,SAASC,cAAcC,wBAAwB;AAC/C,SAASC,YAAY;AACrB,SAASC,gBAAgB;AAElB,IAAMC,aAAaN,OAAOO,OAAOH,IAAAA,EAAMI,KAC5CP,UAAUQ,sBAAsB;EAAEC,UAAUR;AAAa,CAAA,GACzDD,UAAUU,0BAA0B;EAAED,UAAUP;AAAiB,CAAA,GACjEF,UAAUW,gBAAgB;EAAEC,QAAQ;IAACR,SAASA;;AAAU,CAAA,GACxDL,OAAOc,IAAI;AAGb,IAAA,0BAAeR;",
|
|
6
|
+
"names": ["Plugin", "AppPlugin", "CreateObject", "OperationHandler", "meta", "WnfsFile", "WnfsPlugin", "define", "pipe", "addCreateObjectModule", "activate", "addOperationHandlerModule", "addSchemaModule", "schema", "make"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
2
|
+
|
|
3
|
+
// src/WnfsPlugin.workerd.ts
|
|
4
|
+
import { Plugin } from "@dxos/app-framework";
|
|
5
|
+
import { AppPlugin } from "@dxos/app-toolkit";
|
|
6
|
+
import { OperationHandler } from "#capabilities";
|
|
7
|
+
import { meta } from "#meta";
|
|
8
|
+
import { WnfsFile } from "#types";
|
|
9
|
+
var WnfsPlugin = Plugin.define(meta).pipe(AppPlugin.addOperationHandlerModule({
|
|
10
|
+
activate: OperationHandler
|
|
11
|
+
}), AppPlugin.addSchemaModule({
|
|
12
|
+
schema: [
|
|
13
|
+
WnfsFile.WnfsFile
|
|
14
|
+
]
|
|
15
|
+
}), Plugin.make);
|
|
16
|
+
var WnfsPlugin_workerd_default = WnfsPlugin;
|
|
17
|
+
export {
|
|
18
|
+
WnfsPlugin,
|
|
19
|
+
WnfsPlugin_workerd_default as default
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=WnfsPlugin.workerd.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/WnfsPlugin.workerd.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppPlugin } from '@dxos/app-toolkit';\n\nimport { OperationHandler } from '#capabilities';\nimport { meta } from '#meta';\nimport { WnfsFile } from '#types';\n\nexport const WnfsPlugin = Plugin.define(meta).pipe(\n AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),\n AppPlugin.addSchemaModule({ schema: [WnfsFile.WnfsFile] }),\n Plugin.make,\n);\n\nexport default WnfsPlugin;\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,cAAc;AACvB,SAASC,iBAAiB;AAE1B,SAASC,wBAAwB;AACjC,SAASC,YAAY;AACrB,SAASC,gBAAgB;AAElB,IAAMC,aAAaL,OAAOM,OAAOH,IAAAA,EAAMI,KAC5CN,UAAUO,0BAA0B;EAAEC,UAAUP;AAAiB,CAAA,GACjED,UAAUS,gBAAgB;EAAEC,QAAQ;IAACP,SAASA;;AAAU,CAAA,GACxDJ,OAAOY,IAAI;AAGb,IAAA,6BAAeP;",
|
|
6
|
+
"names": ["Plugin", "AppPlugin", "OperationHandler", "meta", "WnfsFile", "WnfsPlugin", "define", "pipe", "addOperationHandlerModule", "activate", "addSchemaModule", "schema", "make"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
storeName
|
|
3
|
+
} from "./chunk-7KFJ6LYH.mjs";
|
|
4
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
5
|
+
|
|
6
|
+
// src/capabilities/blockstore.ts
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import { Capability } from "@dxos/app-framework";
|
|
9
|
+
import { ClientCapabilities } from "@dxos/plugin-client";
|
|
10
|
+
import { WnfsCapabilities } from "#types";
|
|
11
|
+
|
|
12
|
+
// src/blockstore.ts
|
|
13
|
+
import { CarWriter } from "@ipld/car";
|
|
14
|
+
import { BaseBlockstore } from "blockstore-core";
|
|
15
|
+
import { IDBBlockstore } from "blockstore-idb";
|
|
16
|
+
import debounce from "debounce";
|
|
17
|
+
import * as IDB from "idb-keyval";
|
|
18
|
+
import all from "it-all";
|
|
19
|
+
import { CID } from "multiformats";
|
|
20
|
+
import * as Uint8Arrays from "uint8arrays";
|
|
21
|
+
var create = (apiHost) => {
|
|
22
|
+
return new MixedBlockstore(apiHost);
|
|
23
|
+
};
|
|
24
|
+
var MixedBlockstore = class extends BaseBlockstore {
|
|
25
|
+
#apiHost;
|
|
26
|
+
#localStore;
|
|
27
|
+
#isConnected;
|
|
28
|
+
#flushQueue;
|
|
29
|
+
#queue;
|
|
30
|
+
constructor(apiHost) {
|
|
31
|
+
super();
|
|
32
|
+
this.#apiHost = apiHost ? apiHost.replace(/\/?$/, "") : void 0;
|
|
33
|
+
this.#localStore = new IDBBlockstore(storeName());
|
|
34
|
+
this.#isConnected = navigator.onLine;
|
|
35
|
+
this.#queue = [];
|
|
36
|
+
this.#flushQueue = debounce(this.#flushQueueInt, 5e3);
|
|
37
|
+
}
|
|
38
|
+
async open() {
|
|
39
|
+
await this.#localStore.open();
|
|
40
|
+
await this.#restoreQueue();
|
|
41
|
+
window.addEventListener("offline", async () => {
|
|
42
|
+
this.#isConnected = false;
|
|
43
|
+
});
|
|
44
|
+
window.addEventListener("online", async () => {
|
|
45
|
+
this.#isConnected = true;
|
|
46
|
+
this.#flushQueue();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
url(apiHost, cid) {
|
|
50
|
+
const path = cid ? cid.toString() : "";
|
|
51
|
+
return `${apiHost}/api/file${path.length ? "/" + path : ""}`;
|
|
52
|
+
}
|
|
53
|
+
// BLOCKSTORE IMPLEMENTATION
|
|
54
|
+
async delete(key) {
|
|
55
|
+
await this.#localStore.delete(key);
|
|
56
|
+
if (this.#isConnected && this.#apiHost) {
|
|
57
|
+
await fetch(this.url(this.#apiHost, key), {
|
|
58
|
+
method: "DELETE"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async get(key) {
|
|
63
|
+
if (await this.#localStore.has(key)) {
|
|
64
|
+
return await this.#localStore.get(key);
|
|
65
|
+
}
|
|
66
|
+
if (this.#isConnected && this.#apiHost) {
|
|
67
|
+
const block = await fetch(this.url(this.#apiHost, key), {
|
|
68
|
+
method: "GET"
|
|
69
|
+
}).then((r) => r.arrayBuffer()).then((r) => new Uint8Array(r));
|
|
70
|
+
await this.#localStore.put(key, block);
|
|
71
|
+
return block;
|
|
72
|
+
}
|
|
73
|
+
return await this.#localStore.get(key);
|
|
74
|
+
}
|
|
75
|
+
async has(key) {
|
|
76
|
+
if (await this.#localStore.has(key)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (this.#isConnected && this.#apiHost) {
|
|
80
|
+
return await fetch(this.url(this.#apiHost, key), {
|
|
81
|
+
method: "HEAD"
|
|
82
|
+
}).then((r) => r.ok);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
async put(key, val) {
|
|
87
|
+
await this.#localStore.put(key, val);
|
|
88
|
+
await this.#addToQueue(key);
|
|
89
|
+
this.#flushQueue();
|
|
90
|
+
return key;
|
|
91
|
+
}
|
|
92
|
+
async destroy() {
|
|
93
|
+
await this.#localStore.destroy();
|
|
94
|
+
}
|
|
95
|
+
// REMOTE
|
|
96
|
+
async putRemote(key, val) {
|
|
97
|
+
if (this.#apiHost) {
|
|
98
|
+
await fetch(this.url(this.#apiHost, key), {
|
|
99
|
+
method: "POST",
|
|
100
|
+
body: val
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async putCarRemote(car) {
|
|
105
|
+
if (this.#apiHost) {
|
|
106
|
+
await fetch(this.url(this.#apiHost), {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: {
|
|
109
|
+
"Content-Type": "application/vnd.ipld.car"
|
|
110
|
+
},
|
|
111
|
+
body: car
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// QUEUE
|
|
116
|
+
queueCacheName = `${storeName()}.state.queue`;
|
|
117
|
+
async #addToQueue(key) {
|
|
118
|
+
await this.#saveQueue([
|
|
119
|
+
...this.#queue,
|
|
120
|
+
key.toString()
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
async #flushQueueInt() {
|
|
124
|
+
if (!this.#isConnected || !this.#apiHost) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const keys = [
|
|
128
|
+
...this.#queue
|
|
129
|
+
];
|
|
130
|
+
if (keys.length === 0) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const blocks = await Promise.all(keys.map(async (key) => {
|
|
134
|
+
const cid = CID.parse(key);
|
|
135
|
+
const bytes = await this.#localStore.get(cid);
|
|
136
|
+
return {
|
|
137
|
+
cid,
|
|
138
|
+
bytes
|
|
139
|
+
};
|
|
140
|
+
}));
|
|
141
|
+
const car = await this.#createCar(blocks);
|
|
142
|
+
await this.putCarRemote(car);
|
|
143
|
+
const queue = [
|
|
144
|
+
...this.#queue
|
|
145
|
+
].filter((k) => {
|
|
146
|
+
if (keys.includes(k)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
});
|
|
151
|
+
await this.#saveQueue(queue);
|
|
152
|
+
}
|
|
153
|
+
async #restoreQueue() {
|
|
154
|
+
const fromCache = await IDB.get(this.queueCacheName);
|
|
155
|
+
if (fromCache && Array.isArray(fromCache)) {
|
|
156
|
+
this.#queue = fromCache;
|
|
157
|
+
this.#flushQueue();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async #saveQueue(items) {
|
|
161
|
+
const arr = [
|
|
162
|
+
...items
|
|
163
|
+
];
|
|
164
|
+
this.#queue = arr;
|
|
165
|
+
await IDB.set(this.queueCacheName, arr);
|
|
166
|
+
}
|
|
167
|
+
// 🛠️
|
|
168
|
+
async #createCar(blocks) {
|
|
169
|
+
const { writer, out } = CarWriter.create();
|
|
170
|
+
const outPromise = all(out);
|
|
171
|
+
await Promise.all(blocks.map((block) => {
|
|
172
|
+
return writer.put(block);
|
|
173
|
+
}));
|
|
174
|
+
await writer.close();
|
|
175
|
+
return Uint8Arrays.concat(await outPromise);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// src/capabilities/blockstore.ts
|
|
180
|
+
var blockstore_default = Capability.makeModule(Effect.fnUntraced(function* () {
|
|
181
|
+
const client = yield* Capability.get(ClientCapabilities.Client);
|
|
182
|
+
const apiHost = client.config.values.runtime?.services?.edge?.url || "http://localhost:8787";
|
|
183
|
+
const blockstore = create(apiHost);
|
|
184
|
+
yield* Effect.tryPromise(() => blockstore.open());
|
|
185
|
+
return Capability.contributes(WnfsCapabilities.Blockstore, blockstore);
|
|
186
|
+
}));
|
|
187
|
+
export {
|
|
188
|
+
blockstore_default as default
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=blockstore-3NLSWC7Z.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/capabilities/blockstore.ts", "../../../src/blockstore.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capability } from '@dxos/app-framework';\nimport { ClientCapabilities } from '@dxos/plugin-client';\n\nimport { WnfsCapabilities } from '#types';\n\nimport * as Blockstore from '../blockstore';\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n const client = yield* Capability.get(ClientCapabilities.Client);\n const apiHost = client.config.values.runtime?.services?.edge?.url || 'http://localhost:8787';\n const blockstore = Blockstore.create(apiHost);\n yield* Effect.tryPromise(() => blockstore.open());\n\n return Capability.contributes(WnfsCapabilities.Blockstore, blockstore);\n }),\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CarWriter } from '@ipld/car';\nimport type { Block } from '@ipld/car/reader';\nimport { BaseBlockstore } from 'blockstore-core';\nimport { IDBBlockstore } from 'blockstore-idb';\nimport debounce from 'debounce';\nimport * as IDB from 'idb-keyval';\nimport all from 'it-all';\nimport { CID } from 'multiformats';\nimport * as Uint8Arrays from 'uint8arrays';\n\nimport { storeName } from './helpers';\n\nexport const create = (apiHost?: string) => {\n return new MixedBlockstore(apiHost);\n};\n\n/**\n * A blockstore that communicates with the DXOS blob service,\n * and which uses an indexedDB blockstore as a client cache.\n */\nexport class MixedBlockstore extends BaseBlockstore {\n readonly #apiHost: string | undefined;\n readonly #localStore: IDBBlockstore;\n\n #isConnected: boolean;\n #flushQueue: () => void;\n #queue: string[];\n\n constructor(apiHost?: string) {\n super();\n\n this.#apiHost = apiHost ? apiHost.replace(/\\/?$/, '') : undefined;\n this.#localStore = new IDBBlockstore(storeName());\n this.#isConnected = navigator.onLine;\n this.#queue = [];\n\n this.#flushQueue = debounce(this.#flushQueueInt, 5000);\n }\n\n async open(): Promise<void> {\n await this.#localStore.open();\n await this.#restoreQueue();\n\n window.addEventListener('offline', async () => {\n this.#isConnected = false;\n });\n\n window.addEventListener('online', async () => {\n this.#isConnected = true;\n this.#flushQueue();\n });\n }\n\n url(apiHost: string, cid?: CID): string {\n const path = cid ? cid.toString() : '';\n return `${apiHost}/api/file${path.length ? '/' + path : ''}`;\n }\n\n // BLOCKSTORE IMPLEMENTATION\n\n override async delete(key: CID): Promise<void> {\n await this.#localStore.delete(key);\n\n if (this.#isConnected && this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'DELETE',\n });\n }\n }\n\n override async get(key: CID): Promise<Uint8Array> {\n if (await this.#localStore.has(key)) {\n return await this.#localStore.get(key);\n }\n\n if (this.#isConnected && this.#apiHost) {\n const block = await fetch(this.url(this.#apiHost, key), {\n method: 'GET',\n })\n .then((r) => r.arrayBuffer())\n .then((r) => new Uint8Array(r));\n\n // Make sure it is cached locally\n await this.#localStore.put(key, block);\n\n return block;\n }\n\n return await this.#localStore.get(key);\n }\n\n override async has(key: CID): Promise<boolean> {\n if (await this.#localStore.has(key)) {\n return true;\n }\n\n if (this.#isConnected && this.#apiHost) {\n return await fetch(this.url(this.#apiHost, key), {\n method: 'HEAD',\n }).then((r) => r.ok);\n }\n\n return false;\n }\n\n override async put(key: CID, val: Uint8Array): Promise<CID> {\n await this.#localStore.put(key, val);\n\n await this.#addToQueue(key);\n this.#flushQueue();\n\n return key;\n }\n\n async destroy(): Promise<void> {\n await this.#localStore.destroy();\n }\n\n // REMOTE\n\n async putRemote(key: CID, val: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'POST',\n body: val as Uint8Array<ArrayBuffer>,\n });\n }\n }\n\n async putCarRemote(car: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost), {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/vnd.ipld.car',\n },\n body: car as Uint8Array<ArrayBuffer>,\n });\n }\n }\n\n // QUEUE\n\n readonly queueCacheName = `${storeName()}.state.queue`;\n\n async #addToQueue(key: CID): Promise<void> {\n await this.#saveQueue([...this.#queue, key.toString()]);\n }\n\n async #flushQueueInt(): Promise<void> {\n if (!this.#isConnected || !this.#apiHost) {\n return;\n }\n\n const keys = [...this.#queue];\n if (keys.length === 0) {\n return;\n }\n\n // Collect blocks\n const blocks = await Promise.all(\n keys.map(async (key) => {\n const cid = CID.parse(key);\n const bytes = await this.#localStore.get(cid);\n return { cid, bytes };\n }),\n );\n\n // Create & submit CAR\n const car = await this.#createCar(blocks);\n await this.putCarRemote(car);\n\n // Adjust queue\n const queue = [...this.#queue].filter((k) => {\n if (keys.includes(k)) {\n return false;\n }\n\n return true;\n });\n\n await this.#saveQueue(queue);\n }\n\n async #restoreQueue(): Promise<void> {\n const fromCache = await IDB.get(this.queueCacheName);\n if (fromCache && Array.isArray(fromCache)) {\n this.#queue = fromCache;\n this.#flushQueue();\n }\n }\n\n async #saveQueue(items: string[]): Promise<void> {\n const arr = [...items];\n this.#queue = arr;\n await IDB.set(this.queueCacheName, arr);\n }\n\n // 🛠️\n\n async #createCar(blocks: Block[]): Promise<Uint8Array> {\n const { writer, out } = CarWriter.create();\n const outPromise = all(out);\n\n await Promise.all(\n blocks.map((block) => {\n return writer.put(block);\n }),\n );\n\n await writer.close();\n return Uint8Arrays.concat(await outPromise);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,kBAAkB;AAC3B,SAASC,0BAA0B;AAEnC,SAASC,wBAAwB;;;ACLjC,SAASC,iBAAiB;AAE1B,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB;AAC9B,OAAOC,cAAc;AACrB,YAAYC,SAAS;AACrB,OAAOC,SAAS;AAChB,SAASC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AAA;EAClC;AACF;;;AD5MA,IAAA,qBAAeG,WAAWC,WACjBC,kBAAW,aAAA;AAChB,QAAMC,SAAS,OAAOH,WAAWI,IAAIC,mBAAmBC,MAAM;AAC9D,QAAMC,UAAUJ,OAAOK,OAAOC,OAAOC,SAASC,UAAUC,MAAMC,OAAO;AACrE,QAAMC,aAAwBC,OAAOR,OAAAA;AACrC,SAAcS,kBAAW,MAAMF,WAAWG,KAAI,CAAA;AAE9C,SAAOjB,WAAWkB,YAAYC,iBAAiBC,YAAYN,UAAAA;AAC7D,CAAA,CAAA;",
|
|
6
|
+
"names": ["Effect", "Capability", "ClientCapabilities", "WnfsCapabilities", "CarWriter", "BaseBlockstore", "IDBBlockstore", "debounce", "IDB", "all", "CID", "Uint8Arrays", "create", "apiHost", "MixedBlockstore", "BaseBlockstore", "replace", "undefined", "IDBBlockstore", "storeName", "navigator", "onLine", "debounce", "open", "window", "addEventListener", "url", "cid", "path", "toString", "length", "delete", "key", "fetch", "method", "get", "has", "block", "then", "r", "arrayBuffer", "Uint8Array", "put", "ok", "val", "destroy", "putRemote", "body", "putCarRemote", "car", "headers", "queueCacheName", "keys", "blocks", "Promise", "all", "map", "CID", "parse", "bytes", "queue", "filter", "k", "includes", "fromCache", "Array", "isArray", "items", "arr", "set", "writer", "out", "CarWriter", "outPromise", "close", "concat", "Capability", "makeModule", "fnUntraced", "client", "get", "ClientCapabilities", "Client", "apiHost", "config", "values", "runtime", "services", "edge", "url", "blockstore", "create", "tryPromise", "open", "contributes", "WnfsCapabilities", "Blockstore"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "../chunk-J5LGTIGS.mjs";
|
|
2
|
+
|
|
3
|
+
// src/capabilities/index.ts
|
|
4
|
+
import { Capability } from "@dxos/app-framework";
|
|
5
|
+
var Blockstore = Capability.lazy("Blockstore", () => import("../blockstore-3NLSWC7Z.mjs"));
|
|
6
|
+
var CreateObject = Capability.lazy("CreateObject", () => import("../create-object-7PJC47BB.mjs"));
|
|
7
|
+
var FileUploader = Capability.lazy("FileUploader", () => import("../file-uploader-WOF3H3FN.mjs"));
|
|
8
|
+
var Markdown = Capability.lazy("Markdown", () => import("../markdown-I4FYAUCA.mjs"));
|
|
9
|
+
var OperationHandler = Capability.lazy("OperationHandler", () => import("../operation-handler-NPYSIPMR.mjs"));
|
|
10
|
+
var ReactSurface = Capability.lazy("ReactSurface", () => import("../react-surface-6QHCDYC3.mjs"));
|
|
11
|
+
export {
|
|
12
|
+
Blockstore,
|
|
13
|
+
CreateObject,
|
|
14
|
+
FileUploader,
|
|
15
|
+
Markdown,
|
|
16
|
+
OperationHandler,
|
|
17
|
+
ReactSurface
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/capabilities/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capability } from '@dxos/app-framework';\nimport { OperationHandlerSet } from '@dxos/compute';\n\nexport const Blockstore = Capability.lazy('Blockstore', () => import('./blockstore'));\nexport const CreateObject = Capability.lazy('CreateObject', () => import('./create-object'));\nexport const FileUploader = Capability.lazy('FileUploader', () => import('./file-uploader'));\nexport const Markdown = Capability.lazy('Markdown', () => import('./markdown'));\nexport const OperationHandler = Capability.lazy<OperationHandlerSet.OperationHandlerSet>(\n 'OperationHandler',\n () => import('./operation-handler'),\n);\nexport const ReactSurface = Capability.lazy('ReactSurface', () => import('./react-surface'));\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,kBAAkB;AAGpB,IAAMC,aAAaD,WAAWE,KAAK,cAAc,MAAM,OAAO,4BAAA,CAAA;AAC9D,IAAMC,eAAeH,WAAWE,KAAK,gBAAgB,MAAM,OAAO,+BAAA,CAAA;AAClE,IAAME,eAAeJ,WAAWE,KAAK,gBAAgB,MAAM,OAAO,+BAAA,CAAA;AAClE,IAAMG,WAAWL,WAAWE,KAAK,YAAY,MAAM,OAAO,0BAAA,CAAA;AAC1D,IAAMI,mBAAmBN,WAAWE,KACzC,oBACA,MAAM,OAAO,mCAAA,CAAA;AAER,IAAMK,eAAeP,WAAWE,KAAK,gBAAgB,MAAM,OAAO,+BAAA,CAAA;",
|
|
6
|
+
"names": ["Capability", "Blockstore", "lazy", "CreateObject", "FileUploader", "Markdown", "OperationHandler", "ReactSurface"]
|
|
7
|
+
}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WnfsCapabilities
|
|
3
|
-
} from "./chunk-4D4K5JCC.mjs";
|
|
4
|
-
import "./chunk-J5LGTIGS.mjs";
|
|
5
|
-
|
|
6
|
-
// src/index.ts
|
|
7
|
-
import { Plugin } from "@dxos/app-framework";
|
|
8
|
-
|
|
9
1
|
// src/meta.ts
|
|
10
2
|
import { trim } from "@dxos/util";
|
|
11
3
|
var meta = {
|
|
@@ -20,11 +12,7 @@ var meta = {
|
|
|
20
12
|
source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs"
|
|
21
13
|
};
|
|
22
14
|
|
|
23
|
-
// src/index.ts
|
|
24
|
-
var WnfsPlugin = Plugin.lazy(meta, () => import("#plugin"));
|
|
25
15
|
export {
|
|
26
|
-
WnfsCapabilities,
|
|
27
|
-
WnfsPlugin,
|
|
28
16
|
meta
|
|
29
17
|
};
|
|
30
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=chunk-LHUHUCBD.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/meta.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Plugin } from '@dxos/app-framework';\nimport { trim } from '@dxos/util';\n\nexport const meta: Plugin.Meta = {\n id: 'org.dxos.plugin.wnfs',\n name: 'WNFS',\n description: trim`\n Decentralized file storage using the Web Native File System protocol.\n Store and sync files with end-to-end encryption across devices without central servers.\n `,\n icon: 'ph--file-cloud--regular',\n iconHue: 'teal',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',\n};\n"],
|
|
5
|
+
"mappings": ";AAKA,SAASA,YAAY;AAEd,IAAMC,OAAoB;EAC/BC,IAAI;EACJC,MAAM;EACNC,aAAaJ;;;;EAIbK,MAAM;EACNC,SAAS;EACTC,QAAQ;AACV;",
|
|
6
|
+
"names": ["trim", "meta", "id", "name", "description", "icon", "iconHue", "source"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// src/operations/index.ts
|
|
2
|
+
import { OperationHandlerSet } from "@dxos/compute";
|
|
3
|
+
var WnfsOperationHandlerSet = OperationHandlerSet.lazy(() => import("./create-4ERE5CA4.mjs"), () => import("./create-file-RAHDIJVU.mjs"), () => import("./upload-VA5CSUEP.mjs"));
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
WnfsOperationHandlerSet
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=chunk-UIZBWELF.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/operations/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { OperationHandlerSet } from '@dxos/compute';\n\nexport const WnfsOperationHandlerSet = OperationHandlerSet.lazy(\n () => import('./create'),\n () => import('./create-file'),\n () => import('./upload'),\n);\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,2BAA2B;AAE7B,IAAMC,0BAA0BD,oBAAoBE,KACzD,MAAM,OAAO,uBAAA,GACb,MAAM,OAAO,4BAAA,GACb,MAAM,OAAO,uBAAA,CAAA;",
|
|
6
|
+
"names": ["OperationHandlerSet", "WnfsOperationHandlerSet", "lazy"]
|
|
7
|
+
}
|