@le-space/orbitdb-storage-bridge 0.22.0 → 0.22.1
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/lib/backends/storacha.js
CHANGED
|
@@ -17,11 +17,8 @@
|
|
|
17
17
|
* @see {@link ../../docs/STORAGE-BACKENDS.md} for what replaced it
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import * as Client from "@storacha/client";
|
|
21
|
-
import { StoreMemory } from "@storacha/client/stores/memory";
|
|
22
|
-
import { Signer } from "@storacha/client/principal/ed25519";
|
|
23
|
-
import * as Proof from "@storacha/client/proof";
|
|
24
20
|
import { CID } from "multiformats/cid";
|
|
21
|
+
import { loadStorachaClient } from "../storacha-client.js";
|
|
25
22
|
import { defineBackend, handleId, BackendError } from "./types.js";
|
|
26
23
|
|
|
27
24
|
/**
|
|
@@ -61,6 +58,7 @@ async function resolveClient(options) {
|
|
|
61
58
|
);
|
|
62
59
|
}
|
|
63
60
|
|
|
61
|
+
const { Client, StoreMemory, Signer, Proof } = await loadStorachaClient();
|
|
64
62
|
const clientOptions = {
|
|
65
63
|
principal: Signer.parse(options.storachaKey),
|
|
66
64
|
store: new StoreMemory(),
|
|
@@ -34,6 +34,7 @@ import { readBlockBytes } from "./block-bytes.js";
|
|
|
34
34
|
// every vintage look for it.
|
|
35
35
|
import { extractDatabaseBlocks } from "./extract-blocks.js";
|
|
36
36
|
import { resolveBackend } from "./backends/resolve.js";
|
|
37
|
+
import { loadStorachaClient } from "./storacha-client.js";
|
|
37
38
|
|
|
38
39
|
export { extractDatabaseBlocks };
|
|
39
40
|
|
|
@@ -100,34 +101,6 @@ export function extractManifestCID(databaseAddress) {
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
|
|
103
|
-
/**
|
|
104
|
-
* The Storacha client, loaded when first needed and never at import time.
|
|
105
|
-
* `@storacha/client` is an optional peer dependency: without it the main
|
|
106
|
-
* entry still loads, and only the Storacha paths fail, here, with a message
|
|
107
|
-
* that names the package.
|
|
108
|
-
*
|
|
109
|
-
* @returns {Promise<{Client: object, StoreMemory: Function, Signer: {parse: Function}, Proof: {parse: Function}}>}
|
|
110
|
-
*/
|
|
111
|
-
async function loadStorachaClient() {
|
|
112
|
-
try {
|
|
113
|
-
const [Client, { StoreMemory }, { Signer }, Proof] = await Promise.all([
|
|
114
|
-
import("@storacha/client"),
|
|
115
|
-
import("@storacha/client/stores/memory"),
|
|
116
|
-
import("@storacha/client/principal/ed25519"),
|
|
117
|
-
import("@storacha/client/proof"),
|
|
118
|
-
]);
|
|
119
|
-
return { Client, StoreMemory, Signer, Proof };
|
|
120
|
-
} catch (error) {
|
|
121
|
-
if (error?.code === "ERR_MODULE_NOT_FOUND" || error?.code === "MODULE_NOT_FOUND") {
|
|
122
|
-
throw new Error(
|
|
123
|
-
"The Storacha backend needs @storacha/client, an optional peer dependency since 0.22.0: npm install @storacha/client",
|
|
124
|
-
{ cause: error },
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
104
|
/**
|
|
132
105
|
* Initialize Storacha client with credentials
|
|
133
106
|
*
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Storacha client, loaded when first needed and never at import time.
|
|
3
|
+
*
|
|
4
|
+
* `@storacha/client` is an optional peer dependency since 0.22.0. A static
|
|
5
|
+
* `import` of it anywhere under lib/ would break a consumer's bundle: Vite and
|
|
6
|
+
* Rollup follow dynamic imports into chunks and resolve their named imports at
|
|
7
|
+
* build time, so even a driver that is only ever `import()`ed — `resolve.js`
|
|
8
|
+
* reaches `backends/storacha.js` that way — fails the build of an application
|
|
9
|
+
* that never chose Storacha. So the client is imported here, dynamically, and
|
|
10
|
+
* nowhere else; without the package the Storacha paths fail at the call, with
|
|
11
|
+
* a message that names it. test/no-static-storacha-import.test.js keeps it so.
|
|
12
|
+
*
|
|
13
|
+
* @returns {Promise<{ Client: typeof import("@storacha/client"), StoreMemory: Function, Signer: { parse: Function }, Proof: { parse: Function } }>}
|
|
14
|
+
*/
|
|
15
|
+
export async function loadStorachaClient() {
|
|
16
|
+
try {
|
|
17
|
+
const [Client, { StoreMemory }, { Signer }, Proof] = await Promise.all([
|
|
18
|
+
import("@storacha/client"),
|
|
19
|
+
import("@storacha/client/stores/memory"),
|
|
20
|
+
import("@storacha/client/principal/ed25519"),
|
|
21
|
+
import("@storacha/client/proof"),
|
|
22
|
+
]);
|
|
23
|
+
return { Client, StoreMemory, Signer, Proof };
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (
|
|
26
|
+
error?.code === "ERR_MODULE_NOT_FOUND" ||
|
|
27
|
+
error?.code === "MODULE_NOT_FOUND"
|
|
28
|
+
) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"The Storacha backend needs @storacha/client, an optional peer dependency since 0.22.0: npm install @storacha/client",
|
|
31
|
+
{ cause: error },
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/orbitdb-storage-bridge",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "Back up, restore and replicate OrbitDB databases through pluggable storage backends, with hash and identity preservation",
|
|
5
5
|
"main": "lib/orbitdb-storacha-bridge.js",
|
|
6
6
|
"svelte": "dist/components/",
|