@dxos/plugin-wnfs 0.8.4-main.7996785055 → 0.8.4-main.8baae0fced
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 +2 -2
- package/dist/lib/neutral/WnfsPlugin.mjs +39 -0
- package/dist/lib/neutral/WnfsPlugin.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs +12 -0
- package/dist/lib/neutral/WnfsPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/WnfsPlugin.workerd.mjs +12 -0
- package/dist/lib/neutral/WnfsPlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/backend-DHBQUTPC.mjs +47 -0
- package/dist/lib/neutral/backend-DHBQUTPC.mjs.map +7 -0
- package/dist/lib/{browser/blockstore-TUV5YIC5.mjs → neutral/blockstore-3NLSWC7Z.mjs} +6 -7
- package/dist/lib/neutral/blockstore-3NLSWC7Z.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +13 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/{browser/chunk-A7ETWNGC.mjs → neutral/chunk-7KFJ6LYH.mjs} +32 -17
- package/dist/lib/neutral/chunk-7KFJ6LYH.mjs.map +7 -0
- package/dist/lib/neutral/chunk-EKFVDDRY.mjs +26 -0
- package/dist/lib/neutral/chunk-EKFVDDRY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-QODCKFTY.mjs +19 -0
- package/dist/lib/neutral/chunk-QODCKFTY.mjs.map +7 -0
- package/dist/lib/neutral/helpers/index.mjs +26 -0
- package/dist/lib/neutral/index.mjs +34 -0
- package/dist/lib/neutral/index.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/plugin.mjs +12 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +17 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +8 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/lib/neutral/url-resolver-UD3ZP77Y.mjs +47 -0
- package/dist/lib/neutral/url-resolver-UD3ZP77Y.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/WnfsPlugin.workerd.d.ts +4 -0
- package/dist/types/src/WnfsPlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/blockstore.d.ts.map +1 -1
- package/dist/types/src/capabilities/backend.d.ts +7 -0
- package/dist/types/src/capabilities/backend.d.ts.map +1 -0
- package/dist/types/src/capabilities/blockstore.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -5
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/url-resolver.d.ts +7 -0
- package/dist/types/src/capabilities/url-resolver.d.ts.map +1 -0
- 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/meta.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +3 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +2 -16
- 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/index.d.ts +1 -3
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +96 -49
- package/src/WnfsPlugin.node.ts +11 -0
- package/src/WnfsPlugin.test.ts +20 -0
- package/src/WnfsPlugin.tsx +11 -40
- package/src/WnfsPlugin.workerd.ts +11 -0
- package/src/capabilities/backend.ts +43 -0
- package/src/capabilities/{blockstore/blockstore.ts → blockstore.ts} +3 -2
- package/src/capabilities/index.ts +14 -5
- package/src/capabilities/url-resolver.ts +44 -0
- package/src/helpers/load.ts +3 -3
- package/src/helpers/upload.ts +2 -2
- package/src/index.ts +2 -2
- package/src/meta.ts +4 -0
- package/src/plugin.ts +9 -0
- package/src/translations.ts +2 -15
- package/src/types/WnfsCapabilities.ts +18 -0
- package/src/types/index.ts +1 -3
- package/dist/lib/browser/FileContainer-TFENLFD5.mjs +0 -72
- package/dist/lib/browser/FileContainer-TFENLFD5.mjs.map +0 -7
- package/dist/lib/browser/blockstore-TUV5YIC5.mjs.map +0 -7
- package/dist/lib/browser/chunk-3I3QQNA3.mjs +0 -84
- package/dist/lib/browser/chunk-3I3QQNA3.mjs.map +0 -7
- package/dist/lib/browser/chunk-A7ETWNGC.mjs.map +0 -7
- package/dist/lib/browser/chunk-CXWUR7YI.mjs +0 -8
- package/dist/lib/browser/chunk-CXWUR7YI.mjs.map +0 -7
- package/dist/lib/browser/chunk-HXGK35WW.mjs +0 -65
- package/dist/lib/browser/chunk-HXGK35WW.mjs.map +0 -7
- package/dist/lib/browser/chunk-QE7ZSOYG.mjs +0 -69
- package/dist/lib/browser/chunk-QE7ZSOYG.mjs.map +0 -7
- package/dist/lib/browser/create-WQ6CUUDN.mjs +0 -24
- package/dist/lib/browser/create-WQ6CUUDN.mjs.map +0 -7
- package/dist/lib/browser/create-file-NGKX6CFL.mjs +0 -49
- package/dist/lib/browser/create-file-NGKX6CFL.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-THECEDM2.mjs +0 -37
- package/dist/lib/browser/file-uploader-THECEDM2.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -124
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/markdown-IEDBXCLX.mjs +0 -201
- package/dist/lib/browser/markdown-IEDBXCLX.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/operation-handler-YAYDKG7R.mjs +0 -16
- package/dist/lib/browser/operation-handler-YAYDKG7R.mjs.map +0 -7
- package/dist/lib/browser/operations/index.mjs +0 -12
- package/dist/lib/browser/react-surface-UGRUPU56.mjs +0 -60
- package/dist/lib/browser/react-surface-UGRUPU56.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -11
- package/dist/lib/browser/upload-42ZL2AE4.mjs +0 -42
- package/dist/lib/browser/upload-42ZL2AE4.mjs.map +0 -7
- 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 +0 -6
- 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-handler/index.d.ts +0 -4
- package/dist/types/src/capabilities/operation-handler/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/operation-handler/operation-handler.d.ts +0 -6
- package/dist/types/src/capabilities/operation-handler/operation-handler.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 +0 -5
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/FileInput/FileInput.d.ts +0 -8
- package/dist/types/src/components/FileInput/FileInput.d.ts.map +0 -1
- package/dist/types/src/components/FileInput/index.d.ts +0 -2
- package/dist/types/src/components/FileInput/index.d.ts.map +0 -1
- package/dist/types/src/components/FilePreview/FilePreview.d.ts +0 -16
- package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +0 -1
- package/dist/types/src/components/FilePreview/index.d.ts +0 -2
- package/dist/types/src/components/FilePreview/index.d.ts.map +0 -1
- package/dist/types/src/components/index.d.ts +0 -3
- package/dist/types/src/components/index.d.ts.map +0 -1
- 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 -3
- package/dist/types/src/containers/FileContainer/index.d.ts.map +0 -1
- package/dist/types/src/containers/index.d.ts +0 -3
- package/dist/types/src/containers/index.d.ts.map +0 -1
- package/dist/types/src/extensions/image.d.ts +0 -14
- package/dist/types/src/extensions/image.d.ts.map +0 -1
- package/dist/types/src/extensions/image.stories.d.ts +0 -11
- package/dist/types/src/extensions/image.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/index.d.ts +0 -2
- package/dist/types/src/extensions/index.d.ts.map +0 -1
- package/dist/types/src/operations/create-file.d.ts +0 -5
- package/dist/types/src/operations/create-file.d.ts.map +0 -1
- package/dist/types/src/operations/create.d.ts +0 -5
- package/dist/types/src/operations/create.d.ts.map +0 -1
- package/dist/types/src/operations/definitions.d.ts +0 -38
- package/dist/types/src/operations/definitions.d.ts.map +0 -1
- package/dist/types/src/operations/index.d.ts +0 -4
- package/dist/types/src/operations/index.d.ts.map +0 -1
- package/dist/types/src/operations/upload.d.ts +0 -5
- package/dist/types/src/operations/upload.d.ts.map +0 -1
- package/dist/types/src/types/File.d.ts +0 -16
- 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/dist/types/src/types/types.d.ts +0 -9
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/src/capabilities/blockstore/index.ts +0 -7
- package/src/capabilities/file-uploader/file-uploader.ts +0 -34
- 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-handler/index.ts +0 -11
- package/src/capabilities/operation-handler/operation-handler.ts +0 -16
- package/src/capabilities/react-surface/index.ts +0 -7
- package/src/capabilities/react-surface/react-surface.tsx +0 -51
- package/src/components/FileInput/FileInput.tsx +0 -47
- package/src/components/FileInput/index.ts +0 -5
- package/src/components/FilePreview/FilePreview.tsx +0 -43
- package/src/components/FilePreview/index.ts +0 -5
- package/src/components/index.ts +0 -6
- package/src/containers/FileContainer/FileContainer.tsx +0 -56
- package/src/containers/FileContainer/index.ts +0 -7
- package/src/containers/index.ts +0 -7
- package/src/extensions/image.stories.tsx +0 -104
- package/src/extensions/image.tsx +0 -203
- package/src/extensions/index.ts +0 -5
- package/src/operations/create-file.ts +0 -32
- package/src/operations/create.ts +0 -23
- package/src/operations/definitions.ts +0 -40
- package/src/operations/index.ts +0 -13
- package/src/operations/upload.ts +0 -30
- package/src/types/File.ts +0 -28
- package/src/types/capabilities.ts +0 -18
- package/src/types/types.ts +0 -24
- /package/dist/lib/{browser/operations/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/{browser/types → neutral/helpers}/index.mjs.map +0 -0
- /package/dist/types/src/capabilities/{blockstore/blockstore.d.ts → blockstore.d.ts} +0 -0
|
@@ -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-document'>\n <Panel.Content asChild>\n <FilePreview type={file.type} url={blobUrl} />\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,cAACC,aAAAA;IAAYN,MAAMxB,KAAKwB;IAAMH,KAAKd;;AAI3C;;;AC/CA,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": ";;;;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,kBAAkB;AAC3B,SAASC,0BAA0B;;;ACHnC,SAASC,iBAAiB;AAE1B,SAASC,sBAAsB;AAC/B,SAASC,qBAAqB;AAC9B,OAAOC,cAAc;AACrB,YAAYC,SAAS;AACrB,OAAOC,SAAS;AAChB,SAASC,WAAW;AACpB,YAAYC,iBAAiB;AAItB,IAAMC,SAAS,CAACC,YAAAA;AACrB,SAAO,IAAIC,gBAAgBD,OAAAA;AAC7B;AAMO,IAAMC,kBAAN,cAA8BC,eAAAA;EAC1B;EACA;EAET;EACA;EACA;EAEA,YAAYF,SAAkB;AAC5B,UAAK;AAEL,SAAK,WAA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OAAOR,OAAAA;AACrC,SAAcS,kBAAW,MAAMF,WAAWG,KAAI,CAAA;AAE9C,SAAOjB,WAAWkB,YAAYC,iBAAiBC,YAAYN,UAAAA;AAC7D,CAAA,CAAA;",
|
|
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
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
|
|
10
|
-
// src/meta.ts
|
|
11
|
-
import { trim } from "@dxos/util";
|
|
12
|
-
var meta = {
|
|
13
|
-
id: "org.dxos.plugin.wnfs",
|
|
14
|
-
name: "WNFS",
|
|
15
|
-
description: trim`
|
|
16
|
-
Decentralized file storage using the Web Native File System protocol.
|
|
17
|
-
Store and sync files with end-to-end encryption across devices without central servers.
|
|
18
|
-
`,
|
|
19
|
-
icon: "ph--file-cloud--regular",
|
|
20
|
-
iconHue: "teal",
|
|
21
|
-
source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs"
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// src/types/capabilities.ts
|
|
25
|
-
(function(WnfsCapabilities2) {
|
|
26
|
-
WnfsCapabilities2.Blockstore = Capability.make(`${meta.id}.capability.blockstore`);
|
|
27
|
-
WnfsCapabilities2.Instances = Capability.make(`${meta.id}.capability.instances`);
|
|
28
|
-
})(WnfsCapabilities || (WnfsCapabilities = {}));
|
|
29
|
-
var WnfsCapabilities;
|
|
30
|
-
|
|
31
|
-
// src/types/File.ts
|
|
32
|
-
var File_exports = {};
|
|
33
|
-
__export(File_exports, {
|
|
34
|
-
File: () => File2,
|
|
35
|
-
make: () => make
|
|
36
|
-
});
|
|
37
|
-
import * as Schema from "effect/Schema";
|
|
38
|
-
import { Annotation, Obj, Type } from "@dxos/echo";
|
|
39
|
-
import { FormInputAnnotation } from "@dxos/echo/internal";
|
|
40
|
-
var File2 = Schema.Struct({
|
|
41
|
-
name: Schema.String.pipe(Schema.optional),
|
|
42
|
-
type: Schema.String.pipe(FormInputAnnotation.set(false)),
|
|
43
|
-
cid: Schema.String.pipe(FormInputAnnotation.set(false)),
|
|
44
|
-
timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional)
|
|
45
|
-
}).pipe(Type.object({
|
|
46
|
-
typename: "org.dxos.type.file",
|
|
47
|
-
version: "0.1.0"
|
|
48
|
-
}), Annotation.IconAnnotation.set({
|
|
49
|
-
icon: "ph--file--regular",
|
|
50
|
-
hue: "teal"
|
|
51
|
-
}));
|
|
52
|
-
var make = (props) => Obj.make(File2, props);
|
|
53
|
-
|
|
54
|
-
// src/types/types.ts
|
|
55
|
-
import * as Schema2 from "effect/Schema";
|
|
56
|
-
(function(WnfsAction2) {
|
|
57
|
-
WnfsAction2.UploadAnnotationId = /* @__PURE__ */ Symbol.for(`${meta.id}.annotation.upload`);
|
|
58
|
-
WnfsAction2.UploadFileSchema = Schema2.Struct({
|
|
59
|
-
file: Schema2.instanceOf(File).annotations({
|
|
60
|
-
[WnfsAction2.UploadAnnotationId]: {
|
|
61
|
-
// Accept file types.
|
|
62
|
-
"image/*": [
|
|
63
|
-
".jpg",
|
|
64
|
-
".jpeg",
|
|
65
|
-
".png",
|
|
66
|
-
".gif"
|
|
67
|
-
],
|
|
68
|
-
"application/pdf": [
|
|
69
|
-
".pdf"
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
});
|
|
74
|
-
})(WnfsAction || (WnfsAction = {}));
|
|
75
|
-
var WnfsAction;
|
|
76
|
-
|
|
77
|
-
export {
|
|
78
|
-
__export,
|
|
79
|
-
meta,
|
|
80
|
-
WnfsCapabilities,
|
|
81
|
-
File_exports,
|
|
82
|
-
WnfsAction
|
|
83
|
-
};
|
|
84
|
-
//# sourceMappingURL=chunk-3I3QQNA3.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types/capabilities.ts", "../../../src/meta.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 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", "//\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;;;ACF3B,SAASC,YAAY;AAEd,IAAMC,OAAoB;EAC/BC,IAAI;EACJC,MAAM;EACNC,aAAaC;;;;EAIbC,MAAM;EACNC,SAAS;EACTC,QAAQ;AACV;;;UDLiBC,mBAAAA;oBACFC,aAAaC,WAAWC,KAAiB,GAAGC,KAAKC,EAAE,wBAAwB;oBAG3EC,YAAYJ,WAAWC,KAAgB,GAAGC,KAAKC,EAAE,uBAAuB;AACvF,GALiBL,qBAAAA,mBAAAA,CAAAA,EAAAA;;;;AEZjB;;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;UAIPC,aAAAA;cACFC,qBAAqBC,uBAAOC,IAAI,GAAGC,KAAKC,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", "trim", "meta", "id", "name", "description", "trim", "icon", "iconHue", "source", "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", "WnfsAction", "UploadAnnotationId", "Symbol", "for", "meta", "id", "UploadFileSchema", "Struct", "file", "instanceOf", "File", "annotations"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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;AACpB,SAASC,cAAc;AAGvB,YAAYC,YAAY;AAOjB,IAAMC,WAAW,CAACC,UAAkBC,UAAAA;AACzC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B,UAAUmB,MAAMJ,MAAM,MAAMV,OAAO,oBAAIe,KAAAA,GAAQnB,QAAQE,WAAW,IAAIkB,IAAAA,CAAAA;AAI3F,QAAM,CAACC,GAAGC,aAAAA,IAAiB,MAAML,OAAOM,QAAQpB,MAAMc,OAAOjB,QAAQE,WAAW,IAAIkB,IAAAA,CAAAA;AACpF,QAAMI,WAAW,MAAMF,cAAcnB,MAAMD,SAAAA;AAG3CuB,EAAAA,KAAIC,OAAO5B,MAAM6B,YAAY,CAACC,QAAAA;AAC5BA,QAAIC,KAAKC,mBAAmBnB,KAAIoB,OAAOP,QAAAA,EAAUR,SAAQ;EAC3D,CAAA;AAGA,QAAMgB,OAAO;IACXC,MAAMtC,KAAKsC;IACXC,MAAMvC,KAAKuC;IACXC,KAAKC,QAAQtB,IAAAA;IACbJ,KAAKA,IAAIM,SAAQ;EACnB;AAEAqB,MAAI,UAAU;IAAE1C;IAAMqC;EAAK,GAAA;;;;;;AAC3B,SAAOA;AACT;",
|
|
6
|
-
"names": ["CID", "Raw", "sha256", "Obj", "log", "CID", "sha256", "crypto", "filePath", "fileName", "space", "id", "Rng", "randomBytes", "count", "Uint8Array", "store", "blockstore", "getBlock", "cid", "decodedCid", "CID", "decode", "get", "hasBlock", "has", "putBlockKeyed", "bytes", "put", "putBlock", "codec", "hash", "sha256", "digest", "create", "storeName", "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", "getPathFromUrl", "replace", "split", "p", "decodeURIComponent", "getBlobUrl", "blockstore", "forest", "directory", "type", "path", "wnfsStore", "store", "result", "read", "blob", "Blob", "URL", "createObjectURL", "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
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// src/operations/index.ts
|
|
2
|
-
import { OperationHandlerSet } from "@dxos/operation";
|
|
3
|
-
var WnfsOperationHandlerSet = OperationHandlerSet.lazy(() => import("./create-WQ6CUUDN.mjs"), () => import("./create-file-NGKX6CFL.mjs"), () => import("./upload-42ZL2AE4.mjs"));
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
WnfsOperationHandlerSet
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=chunk-CXWUR7YI.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/operations/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { OperationHandlerSet } from '@dxos/operation';\n\nexport * as WnfsOperation from './definitions';\n\nexport const WnfsOperationHandlerSet = OperationHandlerSet.lazy(\n () => import('./create'),\n () => import('./create-file'),\n () => import('./upload'),\n);\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,2BAA2B;AAI7B,IAAMC,0BAA0BC,oBAAoBC,KACzD,MAAM,OAAO,uBAAA,GACb,MAAM,OAAO,4BAAA,GACb,MAAM,OAAO,uBAAA,CAAA;",
|
|
6
|
-
"names": ["OperationHandlerSet", "WnfsOperationHandlerSet", "OperationHandlerSet", "lazy"]
|
|
7
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WnfsAction,
|
|
3
|
-
meta
|
|
4
|
-
} from "./chunk-3I3QQNA3.mjs";
|
|
5
|
-
|
|
6
|
-
// src/components/FileInput/FileInput.tsx
|
|
7
|
-
import React, { useCallback } from "react";
|
|
8
|
-
import { useDropzone } from "react-dropzone";
|
|
9
|
-
import { findAnnotation } from "@dxos/effect";
|
|
10
|
-
import { useTranslation } from "@dxos/react-ui";
|
|
11
|
-
import { mx } from "@dxos/ui-theme";
|
|
12
|
-
var FileInput = ({ schema, onChange }) => {
|
|
13
|
-
const { t } = useTranslation(meta.id);
|
|
14
|
-
const accept = findAnnotation(schema.ast, WnfsAction.UploadAnnotationId);
|
|
15
|
-
const onDropAccepted = useCallback((files) => onChange?.(files[0]), [
|
|
16
|
-
onChange
|
|
17
|
-
]);
|
|
18
|
-
const { acceptedFiles, getRootProps, getInputProps, isFocused, isDragAccept, isDragReject } = useDropzone({
|
|
19
|
-
multiple: false,
|
|
20
|
-
accept,
|
|
21
|
-
onDropAccepted
|
|
22
|
-
});
|
|
23
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
24
|
-
...getRootProps(),
|
|
25
|
-
className: mx("flex flex-col items-center p-8 border border-separator", isFocused && "focus-ring", isDragAccept && "bg-attention-surface", isDragReject && "border-rose-fill")
|
|
26
|
-
}, /* @__PURE__ */ React.createElement("input", getInputProps()), acceptedFiles[0] ? /* @__PURE__ */ React.createElement("p", null, acceptedFiles[0].name) : /* @__PURE__ */ React.createElement("p", null, t("file input placeholder")));
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// src/components/FilePreview/FilePreview.tsx
|
|
30
|
-
import React2 from "react";
|
|
31
|
-
import { composable, composableProps } from "@dxos/ui-theme";
|
|
32
|
-
var FilePreview = composable(({ type, url, children, ...props }, forwardedRef) => {
|
|
33
|
-
if (type.startsWith("image/")) {
|
|
34
|
-
return /* @__PURE__ */ React2.createElement("img", {
|
|
35
|
-
...composableProps(props, {
|
|
36
|
-
classNames: "h-full w-full object-contain"
|
|
37
|
-
}),
|
|
38
|
-
src: url,
|
|
39
|
-
ref: forwardedRef
|
|
40
|
-
});
|
|
41
|
-
} else if (type.startsWith("video/")) {
|
|
42
|
-
return /* @__PURE__ */ React2.createElement("video", {
|
|
43
|
-
...composableProps(props, {
|
|
44
|
-
classNames: "h-full w-full object-contain"
|
|
45
|
-
}),
|
|
46
|
-
src: url,
|
|
47
|
-
controls: true,
|
|
48
|
-
ref: forwardedRef
|
|
49
|
-
});
|
|
50
|
-
} else {
|
|
51
|
-
return /* @__PURE__ */ React2.createElement("iframe", {
|
|
52
|
-
...composableProps(props, {
|
|
53
|
-
classNames: "h-full w-full overflow-auto"
|
|
54
|
-
}),
|
|
55
|
-
src: url,
|
|
56
|
-
ref: forwardedRef
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
export {
|
|
62
|
-
FileInput,
|
|
63
|
-
FilePreview
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=chunk-HXGK35WW.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/FileInput/FileInput.tsx", "../../../src/components/FilePreview/FilePreview.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\nimport React, { useCallback } from 'react';\nimport { useDropzone } from 'react-dropzone';\n\nimport { findAnnotation } from '@dxos/effect';\nimport { useTranslation } from '@dxos/react-ui';\nimport { mx } from '@dxos/ui-theme';\n\nimport { meta } from '../../meta';\nimport { WnfsAction } from '../../types';\n\nexport type FileInputProps = {\n schema: Schema.Schema.Any;\n onChange: (file: File) => void;\n};\n\nexport const FileInput = ({ schema, onChange }: FileInputProps) => {\n const { t } = useTranslation(meta.id);\n const accept = findAnnotation<Record<string, string[]>>(schema.ast, WnfsAction.UploadAnnotationId);\n\n const onDropAccepted = useCallback((files: File[]) => onChange?.(files[0]), [onChange]);\n\n const { acceptedFiles, getRootProps, getInputProps, isFocused, isDragAccept, isDragReject } = useDropzone({\n multiple: false,\n accept,\n onDropAccepted,\n });\n\n return (\n <div\n {...getRootProps()}\n className={mx(\n 'flex flex-col items-center p-8 border border-separator',\n isFocused && 'focus-ring',\n isDragAccept && 'bg-attention-surface',\n isDragReject && 'border-rose-fill',\n )}\n >\n <input {...getInputProps()} />\n {acceptedFiles[0] ? <p>{acceptedFiles[0].name}</p> : <p>{t('file input placeholder')}</p>}\n </div>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { ForwardedRef } from 'react';\n\nimport { composable, composableProps } from '@dxos/ui-theme';\n\nexport type FilePreviewProps = { type: string; url: string };\n\n/**\n * File/content preview iframe.\n */\nexport const FilePreview = composable<HTMLElement, FilePreviewProps>(\n ({ type, url, children, ...props }, forwardedRef) => {\n if (type.startsWith('image/')) {\n return (\n <img\n {...composableProps(props, { classNames: 'h-full w-full object-contain' })}\n src={url}\n ref={forwardedRef as ForwardedRef<HTMLImageElement>}\n />\n );\n } else if (type.startsWith('video/')) {\n return (\n <video\n {...composableProps(props, { classNames: 'h-full w-full object-contain' })}\n src={url}\n controls\n ref={forwardedRef as ForwardedRef<HTMLVideoElement>}\n />\n );\n } else {\n return (\n <iframe\n {...composableProps(props, { classNames: 'h-full w-full overflow-auto' })}\n src={url}\n ref={forwardedRef as ForwardedRef<HTMLIFrameElement>}\n />\n );\n }\n },\n);\n"],
|
|
5
|
-
"mappings": ";;;;;;AAKA,OAAOA,SAASC,mBAAmB;AACnC,SAASC,mBAAmB;AAE5B,SAASC,sBAAsB;AAC/B,SAASC,sBAAsB;AAC/B,SAASC,UAAU;AAUZ,IAAMC,YAAY,CAAC,EAAEC,QAAQC,SAAQ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AKT;MACLU,KAAKP;;EAGX;AACF,CAAA;",
|
|
6
|
-
"names": ["React", "useCallback", "useDropzone", "findAnnotation", "useTranslation", "mx", "FileInput", "schema", "onChange", "t", "useTranslation", "meta", "id", "accept", "findAnnotation", "ast", "WnfsAction", "UploadAnnotationId", "onDropAccepted", "useCallback", "files", "acceptedFiles", "getRootProps", "getInputProps", "isFocused", "isDragAccept", "isDragReject", "useDropzone", "multiple", "div", "className", "mx", "input", "p", "name", "React", "composable", "composableProps", "FilePreview", "composable", "type", "url", "children", "props", "forwardedRef", "startsWith", "React", "img", "composableProps", "classNames", "src", "ref", "video", "controls", "iframe"]
|
|
7
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
File_exports,
|
|
3
|
-
WnfsAction,
|
|
4
|
-
__export,
|
|
5
|
-
meta
|
|
6
|
-
} from "./chunk-3I3QQNA3.mjs";
|
|
7
|
-
|
|
8
|
-
// src/operations/definitions.ts
|
|
9
|
-
var definitions_exports = {};
|
|
10
|
-
__export(definitions_exports, {
|
|
11
|
-
Create: () => Create,
|
|
12
|
-
CreateFile: () => CreateFile,
|
|
13
|
-
Upload: () => Upload
|
|
14
|
-
});
|
|
15
|
-
import * as Schema from "effect/Schema";
|
|
16
|
-
import { Capability } from "@dxos/app-framework";
|
|
17
|
-
import { FileInfoSchema } from "@dxos/app-toolkit";
|
|
18
|
-
import { Database } from "@dxos/echo";
|
|
19
|
-
import { Operation } from "@dxos/operation";
|
|
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-QE7ZSOYG.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
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';\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;AAK1B,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", "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,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Create
|
|
3
|
-
} from "./chunk-QE7ZSOYG.mjs";
|
|
4
|
-
import {
|
|
5
|
-
File_exports
|
|
6
|
-
} from "./chunk-3I3QQNA3.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-WQ6CUUDN.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
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';\n\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;AAM1B,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
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
upload
|
|
3
|
-
} from "./chunk-A7ETWNGC.mjs";
|
|
4
|
-
import {
|
|
5
|
-
CreateFile
|
|
6
|
-
} from "./chunk-QE7ZSOYG.mjs";
|
|
7
|
-
import {
|
|
8
|
-
File_exports,
|
|
9
|
-
WnfsCapabilities
|
|
10
|
-
} from "./chunk-3I3QQNA3.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";
|
|
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: 23,
|
|
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-NGKX6CFL.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
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';\n\nimport { upload } from '../helpers';\nimport { WnfsCapabilities, WnfsFile } from '../types';\n\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;;AAOnC,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,37 +0,0 @@
|
|
|
1
|
-
import "./chunk-CXWUR7YI.mjs";
|
|
2
|
-
import {
|
|
3
|
-
definitions_exports
|
|
4
|
-
} from "./chunk-QE7ZSOYG.mjs";
|
|
5
|
-
import "./chunk-3I3QQNA3.mjs";
|
|
6
|
-
|
|
7
|
-
// src/capabilities/file-uploader/file-uploader.ts
|
|
8
|
-
import * as Effect from "effect/Effect";
|
|
9
|
-
import { Capabilities, Capability } from "@dxos/app-framework";
|
|
10
|
-
import { AppCapabilities } from "@dxos/app-toolkit";
|
|
11
|
-
import { runAndForwardErrors } from "@dxos/effect";
|
|
12
|
-
import { SpaceOperation } from "@dxos/plugin-space/operations";
|
|
13
|
-
var file_uploader_default = Capability.makeModule(Effect.fnUntraced(function* () {
|
|
14
|
-
const capabilities = yield* Capability.Service;
|
|
15
|
-
return Capability.contributes(AppCapabilities.FileUploader, (db, file) => {
|
|
16
|
-
const { invoke } = capabilities.get(Capabilities.OperationInvoker);
|
|
17
|
-
const program = Effect.gen(function* () {
|
|
18
|
-
const fileInfo = yield* invoke(definitions_exports.Upload, {
|
|
19
|
-
db,
|
|
20
|
-
file
|
|
21
|
-
});
|
|
22
|
-
const createResult = yield* invoke(definitions_exports.Create, fileInfo);
|
|
23
|
-
if (createResult?.object) {
|
|
24
|
-
yield* invoke(SpaceOperation.AddObject, {
|
|
25
|
-
target: db,
|
|
26
|
-
object: createResult.object
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return fileInfo;
|
|
30
|
-
});
|
|
31
|
-
return runAndForwardErrors(program);
|
|
32
|
-
});
|
|
33
|
-
}));
|
|
34
|
-
export {
|
|
35
|
-
file_uploader_default as default
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=file-uploader-THECEDM2.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/file-uploader/file-uploader.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport { Capabilities, Capability } from '@dxos/app-framework';\nimport { AppCapabilities } from '@dxos/app-toolkit';\nimport { runAndForwardErrors } from '@dxos/effect';\nimport { SpaceOperation } from '@dxos/plugin-space/operations';\n\nimport { WnfsOperation } from '../../operations';\n\nexport default Capability.makeModule(\n Effect.fnUntraced(function* () {\n // Get context for lazy capability access in callbacks.\n const capabilities = yield* Capability.Service;\n\n return Capability.contributes(AppCapabilities.FileUploader, (db, file) => {\n const { invoke } = capabilities.get(Capabilities.OperationInvoker);\n const program = Effect.gen(function* () {\n const fileInfo = yield* invoke(WnfsOperation.Upload, { db, file });\n const createResult = yield* invoke(WnfsOperation.Create, fileInfo);\n if (createResult?.object) {\n yield* invoke(SpaceOperation.AddObject, { target: db, object: createResult.object });\n }\n\n return fileInfo;\n });\n\n return runAndForwardErrors(program);\n });\n }),\n);\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,cAAcC,kBAAkB;AACzC,SAASC,uBAAuB;AAChC,SAASC,2BAA2B;AACpC,SAASC,sBAAsB;AAI/B,IAAA,wBAAeC,WAAWC,WACjBC,kBAAW,aAAA;AAEhB,QAAMC,eAAe,OAAOH,WAAWI;AAEvC,SAAOJ,WAAWK,YAAYC,gBAAgBC,cAAc,CAACC,IAAIC,SAAAA;AAC/D,UAAM,EAAEC,OAAM,IAAKP,aAAaQ,IAAIC,aAAaC,gBAAgB;AACjE,UAAMC,UAAiBC,WAAI,aAAA;AACzB,YAAMC,WAAW,OAAON,OAAOO,oBAAcC,QAAQ;QAAEV;QAAIC;MAAK,CAAA;AAChE,YAAMU,eAAe,OAAOT,OAAOO,oBAAcG,QAAQJ,QAAAA;AACzD,UAAIG,cAAcE,QAAQ;AACxB,eAAOX,OAAOY,eAAeC,WAAW;UAAEC,QAAQhB;UAAIa,QAAQF,aAAaE;QAAO,CAAA;MACpF;AAEA,aAAOL;IACT,CAAA;AAEA,WAAOS,oBAAoBX,OAAAA;EAC7B,CAAA;AACF,CAAA,CAAA;",
|
|
6
|
-
"names": ["Effect", "Capabilities", "Capability", "AppCapabilities", "runAndForwardErrors", "SpaceOperation", "Capability", "makeModule", "fnUntraced", "capabilities", "Service", "contributes", "AppCapabilities", "FileUploader", "db", "file", "invoke", "get", "Capabilities", "OperationInvoker", "program", "gen", "fileInfo", "WnfsOperation", "Upload", "createResult", "Create", "object", "SpaceOperation", "AddObject", "target", "runAndForwardErrors"]
|
|
7
|
-
}
|