@dxos/plugin-wnfs 0.8.4-main.4a85c3132b → 0.8.4-main.4f23b4e393
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/README.md +1 -1
- package/dist/lib/{browser/FileContainer-EILNV5LV.mjs → neutral/FileContainer-YXSTSMA6.mjs} +9 -25
- package/dist/lib/neutral/FileContainer-YXSTSMA6.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/{browser/blockstore-Q66HQJ4Q.mjs → neutral/blockstore-3NLSWC7Z.mjs} +7 -8
- 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/chunk-UC4HMNZZ.mjs → neutral/chunk-7KFJ6LYH.mjs} +36 -21
- package/dist/lib/neutral/chunk-7KFJ6LYH.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-LHUHUCBD.mjs +18 -0
- 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/{browser/chunk-HXVPBJ3A.mjs → neutral/components/index.mjs} +25 -18
- 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/neutral/create-4ERE5CA4.mjs +23 -0
- package/dist/lib/neutral/create-4ERE5CA4.mjs.map +7 -0
- package/dist/lib/neutral/create-file-RAHDIJVU.mjs +40 -0
- 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/{browser/file-uploader-QL4DTOMM.mjs → neutral/file-uploader-WOF3H3FN.mjs} +5 -6
- package/dist/lib/neutral/file-uploader-WOF3H3FN.mjs.map +7 -0
- package/dist/lib/neutral/helpers/index.mjs +26 -0
- package/dist/lib/neutral/helpers/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +40 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/{browser/markdown-AYCVG6TJ.mjs → neutral/markdown-I4FYAUCA.mjs} +25 -22
- 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/{browser/react-surface-3LKVDPH7.mjs → neutral/react-surface-S4FB2UJ2.mjs} +22 -29
- package/dist/lib/neutral/react-surface-S4FB2UJ2.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +30 -0
- 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/neutral/upload-VA5CSUEP.mjs +33 -0
- package/dist/lib/neutral/upload-VA5CSUEP.mjs.map +7 -0
- package/dist/types/src/WnfsPlugin.d.ts +1 -0
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/WnfsPlugin.node.d.ts +4 -0
- package/dist/types/src/WnfsPlugin.node.d.ts.map +1 -0
- package/dist/types/src/WnfsPlugin.test.d.ts +2 -0
- package/dist/types/src/WnfsPlugin.test.d.ts.map +1 -0
- package/dist/types/src/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/blockstore.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/file-uploader.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +13 -5
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/markdown.d.ts +6 -0
- package/dist/types/src/capabilities/markdown.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
- package/dist/types/src/components/FileInput/index.d.ts +2 -0
- package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
- package/dist/types/src/components/FilePreview/FilePreview.d.ts +12 -0
- package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
- package/dist/types/src/components/FilePreview/index.d.ts +2 -0
- package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts +3 -3
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -1
- package/dist/types/src/containers/FileContainer/index.d.ts +1 -2
- package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -1
- package/dist/types/src/extensions/image.d.ts +1 -1
- package/dist/types/src/extensions/image.d.ts.map +1 -1
- package/dist/types/src/extensions/image.stories.d.ts.map +1 -1
- package/dist/types/src/helpers/common.d.ts.map +1 -1
- package/dist/types/src/helpers/load.d.ts +1 -1
- package/dist/types/src/helpers/load.d.ts.map +1 -1
- package/dist/types/src/helpers/upload.d.ts +1 -1
- package/dist/types/src/helpers/upload.d.ts.map +1 -1
- package/dist/types/src/helpers/wnfs-url.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/operations/create-file.d.ts +5 -0
- package/dist/types/src/operations/create-file.d.ts.map +1 -0
- package/dist/types/src/operations/create.d.ts +5 -0
- package/dist/types/src/operations/create.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/upload.d.ts +5 -0
- package/dist/types/src/operations/upload.d.ts.map +1 -0
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +24 -15
- package/dist/types/src/translations.d.ts.map +1 -1
- 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/types/WnfsOperation.d.ts +38 -0
- 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/src/types/types.d.ts +1 -104
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +94 -46
- package/src/WnfsPlugin.node.ts +19 -0
- package/src/WnfsPlugin.test.ts +27 -0
- package/src/WnfsPlugin.tsx +9 -35
- package/src/blockstore.ts +1 -1
- package/src/capabilities/{blockstore/blockstore.ts → blockstore.ts} +3 -2
- package/src/capabilities/create-object.ts +33 -0
- package/src/capabilities/{file-uploader/file-uploader.ts → file-uploader.ts} +2 -2
- package/src/capabilities/index.ts +12 -5
- package/src/capabilities/markdown.ts +38 -0
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/{react-surface/react-surface.tsx → react-surface.tsx} +23 -14
- package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +3 -3
- package/src/components/FileInput/index.ts +5 -0
- package/src/components/FilePreview/FilePreview.tsx +43 -0
- package/src/components/FilePreview/index.ts +5 -0
- package/src/containers/FileContainer/FileContainer.tsx +7 -8
- package/src/containers/FileContainer/index.ts +1 -3
- package/src/extensions/image.stories.tsx +6 -7
- package/src/extensions/image.tsx +2 -1
- package/src/helpers/load.ts +6 -6
- package/src/helpers/upload.ts +3 -3
- package/src/index.ts +2 -2
- package/src/meta.ts +1 -1
- package/src/operations/create-file.ts +30 -0
- package/src/operations/create.ts +21 -0
- package/src/operations/index.ts +11 -0
- package/src/operations/upload.ts +28 -0
- package/src/plugin.ts +11 -0
- package/src/translations.ts +14 -13
- package/src/types/WnfsCapabilities.ts +18 -0
- package/src/types/{File.ts → WnfsFile.ts} +11 -5
- package/src/types/WnfsOperation.ts +44 -0
- package/src/types/index.ts +4 -2
- package/src/types/types.ts +3 -60
- package/dist/lib/browser/FileContainer-EILNV5LV.mjs.map +0 -7
- package/dist/lib/browser/blockstore-Q66HQJ4Q.mjs.map +0 -7
- package/dist/lib/browser/chunk-BXGCJRL2.mjs +0 -155
- package/dist/lib/browser/chunk-BXGCJRL2.mjs.map +0 -7
- package/dist/lib/browser/chunk-HXVPBJ3A.mjs.map +0 -7
- package/dist/lib/browser/chunk-UC4HMNZZ.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-QL4DTOMM.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -117
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/markdown-AYCVG6TJ.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/operation-resolver-YYWUF6EY.mjs +0 -99
- package/dist/lib/browser/operation-resolver-YYWUF6EY.mjs.map +0 -7
- package/dist/lib/browser/react-surface-3LKVDPH7.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -13
- package/dist/types/src/capabilities/blockstore/blockstore.d.ts.map +0 -1
- package/dist/types/src/capabilities/blockstore/index.d.ts +0 -3
- package/dist/types/src/capabilities/blockstore/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts.map +0 -1
- package/dist/types/src/capabilities/file-uploader/index.d.ts +0 -3
- package/dist/types/src/capabilities/file-uploader/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/markdown/index.d.ts +0 -3
- package/dist/types/src/capabilities/markdown/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/markdown/markdown.d.ts +0 -5
- package/dist/types/src/capabilities/markdown/markdown.d.ts.map +0 -1
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/FileInput.d.ts.map +0 -1
- package/dist/types/src/components/FilePreview.d.ts +0 -11
- package/dist/types/src/components/FilePreview.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/capabilities/blockstore/index.ts +0 -7
- package/src/capabilities/file-uploader/index.ts +0 -7
- package/src/capabilities/markdown/index.ts +0 -7
- package/src/capabilities/markdown/markdown.ts +0 -33
- package/src/capabilities/operation-resolver/index.ts +0 -7
- package/src/capabilities/operation-resolver/operation-resolver.ts +0 -62
- package/src/capabilities/react-surface/index.ts +0 -7
- package/src/components/FilePreview.tsx +0 -23
- package/src/types/capabilities.ts +0 -18
- /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/types/src/capabilities/{blockstore/blockstore.d.ts → blockstore.d.ts} +0 -0
- /package/dist/types/src/capabilities/{file-uploader/file-uploader.d.ts → file-uploader.d.ts} +0 -0
- /package/dist/types/src/capabilities/{react-surface/react-surface.d.ts → react-surface.d.ts} +0 -0
- /package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +0 -0
|
@@ -6,12 +6,12 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import type { Blockstore } from 'interface-blockstore';
|
|
7
7
|
import React, { type ChangeEvent, useEffect, useState } from 'react';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
11
11
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
12
12
|
import { useThemeContext } from '@dxos/react-ui';
|
|
13
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
13
|
import { useTextEditor } from '@dxos/react-ui-editor';
|
|
14
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
15
15
|
import {
|
|
16
16
|
createBasicExtensions,
|
|
17
17
|
createMarkdownExtensions,
|
|
@@ -22,16 +22,15 @@ import {
|
|
|
22
22
|
|
|
23
23
|
import { create as createBlockstore } from '../blockstore';
|
|
24
24
|
import { upload } from '../helpers';
|
|
25
|
-
|
|
26
25
|
import { image } from './image';
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
const initialValue =
|
|
27
|
+
random.seed(1);
|
|
28
|
+
const initialValue = random.lorem.paragraphs(100);
|
|
30
29
|
const instances = {};
|
|
31
30
|
|
|
32
31
|
const DefaultStory = () => {
|
|
33
32
|
const { themeMode } = useThemeContext();
|
|
34
|
-
const space =
|
|
33
|
+
const [space] = useSpaces();
|
|
35
34
|
const [blockstore, setBlockstore] = useState<Blockstore>();
|
|
36
35
|
|
|
37
36
|
useEffect(() => {
|
package/src/extensions/image.tsx
CHANGED
|
@@ -15,8 +15,9 @@ import { focusField } from '@dxos/ui-editor';
|
|
|
15
15
|
import { defaultTx } from '@dxos/ui-theme';
|
|
16
16
|
import { type MaybePromise } from '@dxos/util';
|
|
17
17
|
|
|
18
|
+
import { type WnfsCapabilities } from '#types';
|
|
19
|
+
|
|
18
20
|
import { getBlobUrl, getPathFromUrl, loadWnfs } from '../helpers';
|
|
19
|
-
import { type WnfsCapabilities } from '../types';
|
|
20
21
|
|
|
21
22
|
const WAIT_UNTIL_LOADER = 1500;
|
|
22
23
|
|
package/src/helpers/load.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from 'wnfs';
|
|
|
10
10
|
import { Obj } from '@dxos/echo';
|
|
11
11
|
import { type Space } from '@dxos/react-client/echo';
|
|
12
12
|
|
|
13
|
-
import { type WnfsCapabilities } from '
|
|
13
|
+
import { type WnfsCapabilities } from '#types';
|
|
14
14
|
|
|
15
15
|
import { Rng, store } from './common';
|
|
16
16
|
|
|
@@ -30,9 +30,9 @@ export const loadWnfs = async ({
|
|
|
30
30
|
// TODO(wittjosiah): Remove.
|
|
31
31
|
// Delete old properties if they exist.
|
|
32
32
|
if (space.properties.wnfs_access_key !== undefined && space.properties.wnfs_private_forest_cid !== undefined) {
|
|
33
|
-
Obj.
|
|
34
|
-
delete
|
|
35
|
-
delete
|
|
33
|
+
Obj.update(space.properties, (obj) => {
|
|
34
|
+
delete obj['wnfs_access_key'];
|
|
35
|
+
delete obj['wnfs_private_forest_cid'];
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -68,8 +68,8 @@ const createWnfsDir = async (blockstore: Blockstore, space: Space) => {
|
|
|
68
68
|
|
|
69
69
|
const cidBytes = await newForest.store(wnfsStore);
|
|
70
70
|
|
|
71
|
-
Obj.
|
|
72
|
-
|
|
71
|
+
Obj.update(space.properties, (obj) => {
|
|
72
|
+
obj.wnfs = {
|
|
73
73
|
accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),
|
|
74
74
|
privateForestCid: CID.decode(cidBytes).toString(),
|
|
75
75
|
};
|
package/src/helpers/upload.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { Space } from '@dxos/client/echo';
|
|
|
11
11
|
import { Obj } from '@dxos/echo';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
|
|
14
|
-
import { type WnfsCapabilities } from '
|
|
14
|
+
import { type WnfsCapabilities } from '#types';
|
|
15
15
|
|
|
16
16
|
import { Rng, filePath, store } from './common';
|
|
17
17
|
import { loadWnfs } from './load';
|
|
@@ -47,8 +47,8 @@ export const upload = async ({
|
|
|
47
47
|
const cidBytes = await updatedForest.store(wnfsStore);
|
|
48
48
|
|
|
49
49
|
// Update the forest pointer on the associated space.
|
|
50
|
-
Obj.
|
|
51
|
-
|
|
50
|
+
Obj.update(space.properties, (obj) => {
|
|
51
|
+
obj.wnfs.privateForestCid = CID.decode(cidBytes).toString();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
// Generate `wnfs://` URL & return the info.
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type Plugin } from '@dxos/app-framework';
|
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
8
|
export const meta: Plugin.Meta = {
|
|
9
|
-
id: 'dxos.
|
|
9
|
+
id: 'org.dxos.plugin.wnfs',
|
|
10
10
|
name: 'WNFS',
|
|
11
11
|
description: trim`
|
|
12
12
|
Decentralized file storage using the Web Native File System protocol.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
10
|
+
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
11
|
+
|
|
12
|
+
import { upload } from '../helpers';
|
|
13
|
+
import { WnfsCapabilities, WnfsFile, WnfsOperation } from '../types';
|
|
14
|
+
|
|
15
|
+
const handler: Operation.WithHandler<typeof WnfsOperation.CreateFile> = WnfsOperation.CreateFile.pipe(
|
|
16
|
+
Operation.withHandler(
|
|
17
|
+
Effect.fnUntraced(function* ({ file, db }) {
|
|
18
|
+
const client = yield* Capability.get(ClientCapabilities.Client);
|
|
19
|
+
const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
|
|
20
|
+
const space = client.spaces.get(db.spaceId);
|
|
21
|
+
invariant(space, 'Space not found');
|
|
22
|
+
const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
|
|
23
|
+
return {
|
|
24
|
+
object: WnfsFile.make({ name: info.name, type: info.type, cid: info.cid }),
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export default handler;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
|
+
|
|
9
|
+
import { WnfsFile, WnfsOperation } from '../types';
|
|
10
|
+
|
|
11
|
+
const handler: Operation.WithHandler<typeof WnfsOperation.Create> = WnfsOperation.Create.pipe(
|
|
12
|
+
Operation.withHandler(
|
|
13
|
+
Effect.fnUntraced(function* ({ name, type, cid }) {
|
|
14
|
+
return {
|
|
15
|
+
object: WnfsFile.make({ name, type, cid }),
|
|
16
|
+
};
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export default handler;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
10
|
+
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
11
|
+
|
|
12
|
+
import { upload } from '../helpers';
|
|
13
|
+
import { WnfsCapabilities, WnfsOperation } from '../types';
|
|
14
|
+
|
|
15
|
+
const handler: Operation.WithHandler<typeof WnfsOperation.Upload> = WnfsOperation.Upload.pipe(
|
|
16
|
+
Operation.withHandler(
|
|
17
|
+
Effect.fnUntraced(function* ({ file, db }) {
|
|
18
|
+
const client = yield* Capability.get(ClientCapabilities.Client);
|
|
19
|
+
const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
|
|
20
|
+
const space = client.spaces.get(db.spaceId);
|
|
21
|
+
invariant(space, 'Space not found');
|
|
22
|
+
const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
|
|
23
|
+
return info;
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export default handler;
|
package/src/plugin.ts
ADDED
package/src/translations.ts
CHANGED
|
@@ -4,25 +4,26 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
import { meta } from '
|
|
8
|
-
import { WnfsFile } from '
|
|
7
|
+
import { meta } from '#meta';
|
|
8
|
+
import { WnfsFile } from '#types';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
12
12
|
'en-US': {
|
|
13
|
-
[WnfsFile.
|
|
14
|
-
'typename
|
|
15
|
-
'typename
|
|
16
|
-
'typename
|
|
17
|
-
'typename
|
|
18
|
-
'object
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'object
|
|
13
|
+
[WnfsFile.WnfsFile.typename]: {
|
|
14
|
+
'typename.label': 'File',
|
|
15
|
+
'typename.label_zero': 'Files',
|
|
16
|
+
'typename.label_one': 'File',
|
|
17
|
+
'typename.label_other': 'Files',
|
|
18
|
+
'object-name.placeholder': 'New file',
|
|
19
|
+
'add-object.label': 'Add file',
|
|
20
|
+
'rename-object.label': 'Rename file',
|
|
21
|
+
'delete-object.label': 'Delete file',
|
|
22
|
+
'object-deleted.label': 'File deleted',
|
|
22
23
|
},
|
|
23
24
|
[meta.id]: {
|
|
24
|
-
'plugin
|
|
25
|
-
'file
|
|
25
|
+
'plugin.name': 'Files',
|
|
26
|
+
'file-input.placeholder': 'Drop a file here, or click to select a file',
|
|
26
27
|
},
|
|
27
28
|
},
|
|
28
29
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import { type Blockstore as BlockstoreInterface } from 'interface-blockstore';
|
|
8
|
+
import { type PrivateDirectory, type PrivateForest } from 'wnfs';
|
|
9
|
+
|
|
10
|
+
import { Capability } from '@dxos/app-framework';
|
|
11
|
+
import { type SpaceId } from '@dxos/keys';
|
|
12
|
+
|
|
13
|
+
import { meta } from '#meta';
|
|
14
|
+
|
|
15
|
+
export const Blockstore = Capability.make<BlockstoreInterface>(`${meta.id}.capability.blockstore`);
|
|
16
|
+
|
|
17
|
+
export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;
|
|
18
|
+
export const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);
|
|
@@ -2,23 +2,29 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
5
7
|
import * as Schema from 'effect/Schema';
|
|
6
8
|
|
|
7
|
-
import { Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { Annotation, Obj, Type } from '@dxos/echo';
|
|
8
10
|
import { FormInputAnnotation } from '@dxos/echo/internal';
|
|
9
11
|
|
|
10
|
-
export const
|
|
12
|
+
export const WnfsFile = Schema.Struct({
|
|
11
13
|
name: Schema.String.pipe(Schema.optional),
|
|
12
14
|
type: Schema.String.pipe(FormInputAnnotation.set(false)),
|
|
13
15
|
cid: Schema.String.pipe(FormInputAnnotation.set(false)),
|
|
14
16
|
timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
15
17
|
}).pipe(
|
|
16
18
|
Type.object({
|
|
17
|
-
typename: 'dxos.
|
|
19
|
+
typename: 'org.dxos.type.file',
|
|
18
20
|
version: '0.1.0',
|
|
19
21
|
}),
|
|
22
|
+
Annotation.IconAnnotation.set({
|
|
23
|
+
icon: 'ph--file--regular',
|
|
24
|
+
hue: 'teal',
|
|
25
|
+
}),
|
|
20
26
|
);
|
|
21
27
|
|
|
22
|
-
export type
|
|
28
|
+
export type WnfsFile = Schema.Schema.Type<typeof WnfsFile>;
|
|
23
29
|
|
|
24
|
-
export const make = (props: Obj.MakeProps<typeof
|
|
30
|
+
export const make = (props: Obj.MakeProps<typeof WnfsFile>) => Obj.make(WnfsFile, props);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
|
|
9
|
+
import { Capability } from '@dxos/app-framework';
|
|
10
|
+
import { FileInfoSchema } from '@dxos/app-toolkit';
|
|
11
|
+
import { Operation } from '@dxos/compute';
|
|
12
|
+
import { Database } from '@dxos/echo';
|
|
13
|
+
|
|
14
|
+
import { meta } from '#meta';
|
|
15
|
+
|
|
16
|
+
import { WnfsAction } from './types';
|
|
17
|
+
import * as WnfsFile from './WnfsFile';
|
|
18
|
+
|
|
19
|
+
const WNFS_OPERATION = `${meta.id}.operation`;
|
|
20
|
+
|
|
21
|
+
export const Create = Operation.make({
|
|
22
|
+
meta: { key: `${WNFS_OPERATION}.create`, name: 'Create WNFS File' },
|
|
23
|
+
services: [Capability.Service],
|
|
24
|
+
input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
|
|
25
|
+
output: Schema.Struct({
|
|
26
|
+
object: WnfsFile.WnfsFile,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const Upload = Operation.make({
|
|
31
|
+
meta: { key: `${WNFS_OPERATION}.upload`, name: 'Upload File' },
|
|
32
|
+
services: [Capability.Service],
|
|
33
|
+
input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
|
|
34
|
+
output: Schema.required(FileInfoSchema),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const CreateFile = Operation.make({
|
|
38
|
+
meta: { key: `${WNFS_OPERATION}.create-file`, name: 'Create File' },
|
|
39
|
+
services: [Capability.Service],
|
|
40
|
+
input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
|
|
41
|
+
output: Schema.Struct({
|
|
42
|
+
object: WnfsFile.WnfsFile,
|
|
43
|
+
}),
|
|
44
|
+
});
|
package/src/types/index.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './capabilities';
|
|
6
|
-
export * as WnfsFile from './File';
|
|
7
5
|
export * from './types';
|
|
6
|
+
|
|
7
|
+
export * as WnfsCapabilities from './WnfsCapabilities';
|
|
8
|
+
export * as WnfsFile from './WnfsFile';
|
|
9
|
+
export * as WnfsOperation from './WnfsOperation';
|
package/src/types/types.ts
CHANGED
|
@@ -4,22 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { FileInfoSchema } from '@dxos/app-toolkit';
|
|
9
|
-
import { Database } from '@dxos/echo';
|
|
10
|
-
import { Collection } from '@dxos/echo';
|
|
11
|
-
import { Operation } from '@dxos/operation';
|
|
12
|
-
import { SpaceSchema } from '@dxos/react-client/echo';
|
|
13
|
-
|
|
14
|
-
import { meta } from '../meta';
|
|
15
|
-
|
|
16
|
-
import * as File from './File';
|
|
7
|
+
import { meta } from '#meta';
|
|
17
8
|
|
|
18
9
|
export namespace WnfsAction {
|
|
19
|
-
export const UploadAnnotationId = Symbol.for(`${meta.id}
|
|
10
|
+
export const UploadAnnotationId = Symbol.for(`${meta.id}.annotation.upload`);
|
|
20
11
|
|
|
21
12
|
export const UploadFileSchema = Schema.Struct({
|
|
22
|
-
file: Schema.instanceOf(File
|
|
13
|
+
file: Schema.instanceOf(File).annotations({
|
|
23
14
|
[UploadAnnotationId]: {
|
|
24
15
|
// Accept file types.
|
|
25
16
|
'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
|
|
@@ -31,51 +22,3 @@ export namespace WnfsAction {
|
|
|
31
22
|
|
|
32
23
|
export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;
|
|
33
24
|
}
|
|
34
|
-
|
|
35
|
-
const WNFS_OPERATION = `${meta.id}/operation`;
|
|
36
|
-
|
|
37
|
-
export namespace WnfsOperation {
|
|
38
|
-
export const OnCreateSpace = Operation.make({
|
|
39
|
-
meta: { key: `${WNFS_OPERATION}/on-create-space`, name: 'On Create Space' },
|
|
40
|
-
services: [Capability.Service],
|
|
41
|
-
schema: {
|
|
42
|
-
input: Schema.Struct({
|
|
43
|
-
space: SpaceSchema,
|
|
44
|
-
rootCollection: Collection.Collection,
|
|
45
|
-
isDefault: Schema.optional(Schema.Boolean),
|
|
46
|
-
}),
|
|
47
|
-
output: Schema.Void,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export const Create = Operation.make({
|
|
52
|
-
meta: { key: `${WNFS_OPERATION}/create`, name: 'Create WNFS File' },
|
|
53
|
-
services: [Capability.Service],
|
|
54
|
-
schema: {
|
|
55
|
-
input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
|
|
56
|
-
output: Schema.Struct({
|
|
57
|
-
object: File.File,
|
|
58
|
-
}),
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export const Upload = Operation.make({
|
|
63
|
-
meta: { key: `${WNFS_OPERATION}/upload`, name: 'Upload File' },
|
|
64
|
-
services: [Capability.Service],
|
|
65
|
-
schema: {
|
|
66
|
-
input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
|
|
67
|
-
output: Schema.required(FileInfoSchema),
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
export const CreateFile = Operation.make({
|
|
72
|
-
meta: { key: `${WNFS_OPERATION}/create-file`, name: 'Create File' },
|
|
73
|
-
services: [Capability.Service],
|
|
74
|
-
schema: {
|
|
75
|
-
input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
|
|
76
|
-
output: Schema.Struct({
|
|
77
|
-
object: File.File,
|
|
78
|
-
}),
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/containers/FileContainer/FileContainer.tsx", "../../../src/containers/FileContainer/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport { useCapability } from '@dxos/app-framework/ui';\nimport { type SurfaceComponentProps } 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 { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../../helpers';\nimport { WnfsCapabilities, type WnfsFile } from '../../types';\n\nexport type FileContainerProps = SurfaceComponentProps<WnfsFile.File>;\n\nexport const FileContainer = ({ role, subject: file }: FileContainerProps) => {\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-article'>\n <Panel.Content asChild>\n <Panel.Content asChild>\n <FilePreview type={file.type} url={blobUrl} />\n </Panel.Content>\n </Panel.Content>\n </Panel.Root>\n );\n};\n\nexport default FileContainer;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { FileContainer } from './FileContainer';\n\nexport default FileContainer;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;AAIA,OAAOA,SAASC,gBAAgB;AAEhC,SAASC,qBAAqB;AAE9B,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,OAAOC,sBAAsB;;AAQ/B,IAAMC,gBAAgB,CAAC,EAAEC,MAAMC,SAASC,KAAI,MAAsB;AACvE,QAAMC,aAAaC,cAAcC,iBAAiBC,UAAU;AAC5D,QAAMC,YAAYH,cAAcC,iBAAiBG,SAAS;AAC1D,QAAM,CAACC,SAASC,UAAAA,IAAcC,SAAAA;AAE9BC,iBAAe,YAAA;AACb,UAAMC,QAAQC,SAASZ,IAAAA;AACvBa,cAAUF,OAAAA,QAAAA;;;;;;;;;AACV,UAAM,EAAEG,WAAWC,OAAM,IAAK,MAAMC,SAAS;MAC3Cf;MACAI;MACAM;IACF,CAAA;AACA,UAAMM,OAAOC,SAASlB,KAAKmB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,UAAMU,MAAM,MAAMC,WAAW;MAC3BC,SAASA,QAAQN,IAAAA;MACjBhB;MACAa;MACAC;MACAS,MAAMxB,KAAKwB;IACb,CAAA;AACAhB,eAAWa,GAAAA;EACb,GAAG;IAACrB;GAAK;AAET,MAAI,CAACO,SAAS;AACZ,WAAO;EACT;AAEA,SACE,sBAAA,cAACkB,MAAMC,MAAI;IAAC5B;IAAY6B,WAAU;KAChC,sBAAA,cAACF,MAAMG,SAAO;IAACC,SAAAA;KACb,sBAAA,cAACJ,MAAMG,SAAO;IAACC,SAAAA;KACb,sBAAA,cAACC,aAAAA;IAAYN,MAAMxB,KAAKwB;IAAMH,KAAKd;;AAK7C;;;ACjDA,IAAA,wBAAewB;",
|
|
6
|
-
"names": ["React", "useState", "useCapability", "invariant", "getSpace", "Panel", "useAsyncEffect", "FileContainer", "role", "subject", "file", "blockstore", "useCapability", "WnfsCapabilities", "Blockstore", "instances", "Instances", "blobUrl", "setBlobUrl", "useState", "useAsyncEffect", "space", "getSpace", "invariant", "directory", "forest", "loadWnfs", "path", "filePath", "cid", "toString", "url", "getBlobUrl", "wnfsUrl", "type", "Panel", "Root", "className", "Content", "asChild", "FilePreview", "FileContainer"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/blockstore/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 * as Blockstore from '../../blockstore';\nimport { WnfsCapabilities } from '../../types';\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": "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",
|
|
6
|
-
"names": ["Effect", "Capability", "ClientCapabilities", "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
|
-
}
|