@fireproof/core 0.20.0-dev-preview-62 → 0.20.0
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/deno.json +2 -2
- package/index.cjs +41 -82
- package/index.cjs.map +1 -1
- package/index.d.cts +5 -9
- package/index.d.ts +5 -9
- package/index.js +41 -82
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +3 -6
- package/react/index.cjs +22 -23
- package/react/index.cjs.map +1 -1
- package/react/index.js +22 -23
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/loader.test.ts +1 -1
- package/tests/blockstore/store.test.ts +4 -9
- package/tests/fireproof/attachable.test.ts +3 -3
- package/tests/react/use-fireproof-db-switch.test.tsx +91 -0
- package/cli/main.js +0 -26114
package/index.d.cts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Logger, Future, URI, CryptoRuntime, ResolveOnce, Result, ResolveSeq, CTCryptoKey, CoerceURI, Promisable, LRUSet, Env, EnvFactoryOpts, MatchResult, runtimeFn } from '@adviser/cement';
|
2
|
-
import { EventLink } from '@
|
3
|
-
import { Operation } from '@
|
2
|
+
import { EventLink } from '@web3-storage/pail/clock/api';
|
3
|
+
import { Operation } from '@web3-storage/pail/crdt/api';
|
4
4
|
import { Version, Block as Block$1, UnknownLink, CID, ByteView, ArrayBufferView, Link, MultihashHasher, BlockView } from 'multiformats';
|
5
|
-
import { BlockFetcher as BlockFetcher$1 } from '@
|
6
|
-
import { EventBlock } from '@
|
5
|
+
import { BlockFetcher as BlockFetcher$1 } from '@web3-storage/pail/api';
|
6
|
+
import { EventBlock } from '@web3-storage/pail/clock';
|
7
7
|
import { ProllyNode as ProllyNode$1 } from 'prolly-trees/db-index';
|
8
8
|
import { Block as Block$2 } from 'multiformats/block';
|
9
9
|
import * as jose from 'jose';
|
@@ -223,10 +223,7 @@ declare function coerceIntoUint8(raw: ToUInt8): Result<Uint8Array>;
|
|
223
223
|
declare function coercePromiseIntoUint8(raw: PromiseToUInt8): Promise<Result<Uint8Array>>;
|
224
224
|
declare function makeName(fnString: string): string;
|
225
225
|
declare function storeType2DataMetaWal(store: StoreType): "data" | "wal" | "meta";
|
226
|
-
declare function ensureURIDefaults(sthis: SuperThis,
|
227
|
-
name: string;
|
228
|
-
local?: string;
|
229
|
-
}, curi: CoerceURI | undefined, uri: URI, store: StoreType, ctx?: Partial<{
|
226
|
+
declare function ensureURIDefaults(sthis: SuperThis, name: string, curi: CoerceURI | undefined, uri: URI, store: StoreType, ctx?: Partial<{
|
230
227
|
readonly idx: boolean;
|
231
228
|
readonly file: boolean;
|
232
229
|
}>): URI;
|
@@ -1202,7 +1199,6 @@ declare const PARAM: {
|
|
1202
1199
|
CAR_COMPACT_CACHE_SIZE: string;
|
1203
1200
|
CAR_META_CACHE_SIZE: string;
|
1204
1201
|
GENESIS_CID: string;
|
1205
|
-
LOCAL_NAME: string;
|
1206
1202
|
};
|
1207
1203
|
type PARAMS = (typeof PARAM)[keyof typeof PARAM];
|
1208
1204
|
declare function throwFalsy<T>(value: T | Falsy): T;
|
package/index.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Logger, Future, URI, CryptoRuntime, ResolveOnce, Result, ResolveSeq, CTCryptoKey, CoerceURI, Promisable, LRUSet, Env, EnvFactoryOpts, MatchResult, runtimeFn } from '@adviser/cement';
|
2
|
-
import { EventLink } from '@
|
3
|
-
import { Operation } from '@
|
2
|
+
import { EventLink } from '@web3-storage/pail/clock/api';
|
3
|
+
import { Operation } from '@web3-storage/pail/crdt/api';
|
4
4
|
import { Version, Block as Block$1, UnknownLink, CID, ByteView, ArrayBufferView, Link, MultihashHasher, BlockView } from 'multiformats';
|
5
|
-
import { BlockFetcher as BlockFetcher$1 } from '@
|
6
|
-
import { EventBlock } from '@
|
5
|
+
import { BlockFetcher as BlockFetcher$1 } from '@web3-storage/pail/api';
|
6
|
+
import { EventBlock } from '@web3-storage/pail/clock';
|
7
7
|
import { ProllyNode as ProllyNode$1 } from 'prolly-trees/db-index';
|
8
8
|
import { Block as Block$2 } from 'multiformats/block';
|
9
9
|
import * as jose from 'jose';
|
@@ -223,10 +223,7 @@ declare function coerceIntoUint8(raw: ToUInt8): Result<Uint8Array>;
|
|
223
223
|
declare function coercePromiseIntoUint8(raw: PromiseToUInt8): Promise<Result<Uint8Array>>;
|
224
224
|
declare function makeName(fnString: string): string;
|
225
225
|
declare function storeType2DataMetaWal(store: StoreType): "data" | "wal" | "meta";
|
226
|
-
declare function ensureURIDefaults(sthis: SuperThis,
|
227
|
-
name: string;
|
228
|
-
local?: string;
|
229
|
-
}, curi: CoerceURI | undefined, uri: URI, store: StoreType, ctx?: Partial<{
|
226
|
+
declare function ensureURIDefaults(sthis: SuperThis, name: string, curi: CoerceURI | undefined, uri: URI, store: StoreType, ctx?: Partial<{
|
230
227
|
readonly idx: boolean;
|
231
228
|
readonly file: boolean;
|
232
229
|
}>): URI;
|
@@ -1202,7 +1199,6 @@ declare const PARAM: {
|
|
1202
1199
|
CAR_COMPACT_CACHE_SIZE: string;
|
1203
1200
|
CAR_META_CACHE_SIZE: string;
|
1204
1201
|
GENESIS_CID: string;
|
1205
|
-
LOCAL_NAME: string;
|
1206
1202
|
};
|
1207
1203
|
type PARAMS = (typeof PARAM)[keyof typeof PARAM];
|
1208
1204
|
declare function throwFalsy<T>(value: T | Falsy): T;
|
package/index.js
CHANGED
@@ -23,7 +23,7 @@ import {
|
|
23
23
|
|
24
24
|
// src/types.ts
|
25
25
|
function isFalsy(value) {
|
26
|
-
return value === false
|
26
|
+
return value === false && value === null && value === void 0;
|
27
27
|
}
|
28
28
|
var PARAM = {
|
29
29
|
SUFFIX: "suffix",
|
@@ -51,8 +51,7 @@ var PARAM = {
|
|
51
51
|
CAR_CACHE_SIZE: "carCacheSize",
|
52
52
|
CAR_COMPACT_CACHE_SIZE: "carCompactCacheSize",
|
53
53
|
CAR_META_CACHE_SIZE: "carMetaCacheSize",
|
54
|
-
GENESIS_CID: "baembeiarootfireproofgenesisblockaaaafireproofgenesisblocka"
|
55
|
-
LOCAL_NAME: "localName"
|
54
|
+
GENESIS_CID: "baembeiarootfireproofgenesisblockaaaafireproofgenesisblocka"
|
56
55
|
// FS = "fs",
|
57
56
|
};
|
58
57
|
function throwFalsy(value) {
|
@@ -427,11 +426,11 @@ function storeType2DataMetaWal(store) {
|
|
427
426
|
throw new Error(`unknown store ${store}`);
|
428
427
|
}
|
429
428
|
}
|
430
|
-
function ensureURIDefaults(sthis,
|
429
|
+
function ensureURIDefaults(sthis, name, curi, uri, store, ctx) {
|
431
430
|
ctx = ctx || {};
|
432
|
-
const ret = (curi ? URI.from(curi) : uri).build().setParam(PARAM.STORE, store).defParam(PARAM.NAME,
|
433
|
-
if (
|
434
|
-
ret.
|
431
|
+
const ret = (curi ? URI.from(curi) : uri).build().setParam(PARAM.STORE, store).defParam(PARAM.NAME, name);
|
432
|
+
if (!ret.hasParam(PARAM.NAME)) {
|
433
|
+
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("Ledger name is required").AsError();
|
435
434
|
}
|
436
435
|
if (ctx.idx) {
|
437
436
|
ret.defParam(PARAM.INDEX, "idx");
|
@@ -1239,13 +1238,6 @@ import { Result as Result5 } from "@adviser/cement";
|
|
1239
1238
|
var MEMORY_VERSION = "v0.19-memory";
|
1240
1239
|
|
1241
1240
|
// src/runtime/gateways/memory/gateway.ts
|
1242
|
-
function cleanURI(uri) {
|
1243
|
-
return uri.build().cleanParams(
|
1244
|
-
PARAM.VERSION,
|
1245
|
-
// PARAM.STORE,
|
1246
|
-
PARAM.LOCAL_NAME
|
1247
|
-
).URI();
|
1248
|
-
}
|
1249
1241
|
var MemoryGateway = class {
|
1250
1242
|
// readonly logger: Logger;
|
1251
1243
|
constructor(sthis, memorys) {
|
@@ -1263,33 +1255,33 @@ var MemoryGateway = class {
|
|
1263
1255
|
return Promise.resolve(Result5.Ok(void 0));
|
1264
1256
|
}
|
1265
1257
|
destroy(baseUrl) {
|
1266
|
-
const keyUrl =
|
1267
|
-
const match = keyUrl.match(keyUrl);
|
1258
|
+
const keyUrl = baseUrl.toString();
|
1268
1259
|
for (const key of this.memorys.keys()) {
|
1269
|
-
if (
|
1260
|
+
if (key.startsWith(keyUrl)) {
|
1270
1261
|
this.memorys.delete(key);
|
1271
1262
|
}
|
1272
1263
|
}
|
1264
|
+
this.memorys.clear();
|
1273
1265
|
return Promise.resolve(Result5.Ok(void 0));
|
1274
1266
|
}
|
1275
1267
|
async put(url, bytes) {
|
1276
|
-
this.memorys.set(
|
1268
|
+
this.memorys.set(url.toString(), bytes);
|
1277
1269
|
return Result5.Ok(void 0);
|
1278
1270
|
}
|
1279
1271
|
// get could return a NotFoundError if the key is not found
|
1280
1272
|
get(url) {
|
1281
|
-
const x = this.memorys.get(
|
1273
|
+
const x = this.memorys.get(url.toString());
|
1282
1274
|
if (!x) {
|
1283
1275
|
return Promise.resolve(Result5.Err(new NotFoundError(`not found: ${url.toString()}`)));
|
1284
1276
|
}
|
1285
1277
|
return Promise.resolve(Result5.Ok(x));
|
1286
1278
|
}
|
1287
1279
|
delete(url) {
|
1288
|
-
this.memorys.delete(
|
1280
|
+
this.memorys.delete(url.toString());
|
1289
1281
|
return Promise.resolve(Result5.Ok(void 0));
|
1290
1282
|
}
|
1291
1283
|
async getPlain(url, key) {
|
1292
|
-
const x = this.memorys.get(
|
1284
|
+
const x = this.memorys.get(url.build().setParam(PARAM.KEY, key).toString());
|
1293
1285
|
if (!x) {
|
1294
1286
|
return Result5.Err(new NotFoundError("not found"));
|
1295
1287
|
}
|
@@ -1317,7 +1309,7 @@ function File2FPMsg(fpfile) {
|
|
1317
1309
|
|
1318
1310
|
// src/runtime/gateways/fp-envelope-serialize.ts
|
1319
1311
|
import { exception2Result as exception2Result3, Result as Result7 } from "@adviser/cement";
|
1320
|
-
import { decodeEventBlock, EventBlock } from "@
|
1312
|
+
import { decodeEventBlock, EventBlock } from "@web3-storage/pail/clock";
|
1321
1313
|
import { base64pad } from "multiformats/bases/base64";
|
1322
1314
|
import { CID as CID2 } from "multiformats";
|
1323
1315
|
import { fromJSON } from "multiformats/link";
|
@@ -2298,7 +2290,7 @@ async function parseCarFile(reader, logger) {
|
|
2298
2290
|
}
|
2299
2291
|
|
2300
2292
|
// src/blockstore/transaction.ts
|
2301
|
-
import { MemoryBlockstore } from "@
|
2293
|
+
import { MemoryBlockstore } from "@web3-storage/pail/block";
|
2302
2294
|
import { toCryptoRuntime as toCryptoRuntime3 } from "@adviser/cement";
|
2303
2295
|
var CarTransactionImpl = class {
|
2304
2296
|
#memblock = new MemoryBlockstore();
|
@@ -2972,44 +2964,19 @@ var AttachedRemotesImpl = class {
|
|
2972
2964
|
const gws = {
|
2973
2965
|
car: {
|
2974
2966
|
...gwp.car,
|
2975
|
-
url: ensureURIDefaults(
|
2976
|
-
this.loadable.sthis,
|
2977
|
-
{ name: attached.name, local: this._local?.gatewayUrls.car.url.getParam(PARAM.NAME) },
|
2978
|
-
void 0,
|
2979
|
-
URI9.from(gwp.car.url),
|
2980
|
-
"car"
|
2981
|
-
)
|
2967
|
+
url: ensureURIDefaults(this.loadable.sthis, attached.name, gwp.car.url, URI9.from(gwp.car.url), "car")
|
2982
2968
|
},
|
2983
2969
|
file: {
|
2984
2970
|
...gwp.file,
|
2985
|
-
url: ensureURIDefaults(
|
2986
|
-
this.loadable.sthis,
|
2987
|
-
{ name: attached.name, local: this._local?.gatewayUrls.file.url.getParam(PARAM.NAME) },
|
2988
|
-
void 0,
|
2989
|
-
URI9.from(gwp.file.url),
|
2990
|
-
"file",
|
2991
|
-
{ file: true }
|
2992
|
-
)
|
2971
|
+
url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, URI9.from(gwp.file.url), "file", { file: true })
|
2993
2972
|
},
|
2994
2973
|
meta: {
|
2995
2974
|
...gwp.meta,
|
2996
|
-
url: ensureURIDefaults(
|
2997
|
-
this.loadable.sthis,
|
2998
|
-
{ name: attached.name, local: this._local?.gatewayUrls.meta.url.getParam(PARAM.NAME) },
|
2999
|
-
void 0,
|
3000
|
-
URI9.from(gwp.meta.url),
|
3001
|
-
"meta"
|
3002
|
-
)
|
2975
|
+
url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, URI9.from(gwp.meta.url), "meta")
|
3003
2976
|
},
|
3004
2977
|
wal: gwp.wal ? {
|
3005
2978
|
...gwp.wal,
|
3006
|
-
url: ensureURIDefaults(
|
3007
|
-
this.loadable.sthis,
|
3008
|
-
{ name: attached.name, local: this._local?.gatewayUrls.wal?.url.getParam(PARAM.NAME) },
|
3009
|
-
void 0,
|
3010
|
-
URI9.from(gwp.wal.url),
|
3011
|
-
"wal"
|
3012
|
-
)
|
2979
|
+
url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, URI9.from(gwp.wal.url), "wal")
|
3013
2980
|
} : void 0
|
3014
2981
|
};
|
3015
2982
|
const key = JSON.stringify(
|
@@ -3034,7 +3001,7 @@ var AttachedRemotesImpl = class {
|
|
3034
3001
|
);
|
3035
3002
|
if (result.stores.wal) {
|
3036
3003
|
if (this._local) {
|
3037
|
-
throw this.loadable.sthis.logger.Error().
|
3004
|
+
throw this.loadable.sthis.logger.Error().Msg("local store could only set once").AsError();
|
3038
3005
|
}
|
3039
3006
|
this._local = result;
|
3040
3007
|
}
|
@@ -3101,11 +3068,10 @@ var Loader = class {
|
|
3101
3068
|
if (!at.stores.wal) {
|
3102
3069
|
try {
|
3103
3070
|
const dbMeta = await at.stores.meta.load();
|
3104
|
-
if (Array.isArray(dbMeta)) {
|
3105
|
-
|
3106
|
-
} else if (!isFalsy(dbMeta)) {
|
3107
|
-
throw this.logger.Error().Any({ dbMeta }).Msg("missing dbMeta").AsError();
|
3071
|
+
if (!Array.isArray(dbMeta)) {
|
3072
|
+
throw this.logger.Error().Msg("missing dbMeta").AsError();
|
3108
3073
|
}
|
3074
|
+
await this.handleDbMetasFromStore(dbMeta, this.attachedStores.activate(at.stores));
|
3109
3075
|
} catch (e) {
|
3110
3076
|
this.logger.Error().Err(e).Msg("error attaching store");
|
3111
3077
|
at.detach();
|
@@ -3627,7 +3593,7 @@ async function keyedCryptoFactory(url, kb, sthis) {
|
|
3627
3593
|
}
|
3628
3594
|
|
3629
3595
|
// src/blockstore/store.ts
|
3630
|
-
import { EventBlock as EventBlock2 } from "@
|
3596
|
+
import { EventBlock as EventBlock2 } from "@web3-storage/pail/clock";
|
3631
3597
|
import { format as format2 } from "@ipld/dag-json";
|
3632
3598
|
import pRetry from "p-retry";
|
3633
3599
|
import pMap from "p-map";
|
@@ -4377,9 +4343,9 @@ var URIInterceptor = class _URIInterceptor extends PassThroughGateway {
|
|
4377
4343
|
import { parse as parse2 } from "multiformats/link";
|
4378
4344
|
import { sha256 as hasher6 } from "multiformats/hashes/sha2";
|
4379
4345
|
import * as codec2 from "@ipld/dag-cbor";
|
4380
|
-
import { put, get, entries, root } from "@
|
4381
|
-
import { EventFetcher, vis } from "@
|
4382
|
-
import * as Batch from "@
|
4346
|
+
import { put, get, entries, root } from "@web3-storage/pail/crdt";
|
4347
|
+
import { EventFetcher, vis } from "@web3-storage/pail/clock";
|
4348
|
+
import * as Batch from "@web3-storage/pail/crdt/batch";
|
4383
4349
|
function time(tag) {
|
4384
4350
|
}
|
4385
4351
|
function timeEnd(tag) {
|
@@ -4691,8 +4657,8 @@ async function getBlock(blocks, cidString) {
|
|
4691
4657
|
}
|
4692
4658
|
|
4693
4659
|
// src/crdt-clock.ts
|
4694
|
-
import { advance } from "@
|
4695
|
-
import { root as root2 } from "@
|
4660
|
+
import { advance } from "@web3-storage/pail/clock";
|
4661
|
+
import { root as root2 } from "@web3-storage/pail/crdt";
|
4696
4662
|
import { ResolveOnce as ResolveOnce5 } from "@adviser/cement";
|
4697
4663
|
|
4698
4664
|
// src/apply-head-queue.ts
|
@@ -5234,26 +5200,19 @@ function toStoreURIRuntime(sthis, name, sopts) {
|
|
5234
5200
|
const base = URI13.from(sopts.base);
|
5235
5201
|
return {
|
5236
5202
|
idx: {
|
5237
|
-
car: ensureURIDefaults(sthis,
|
5238
|
-
file: ensureURIDefaults(
|
5239
|
-
|
5240
|
-
|
5241
|
-
|
5242
|
-
|
5243
|
-
|
5244
|
-
{
|
5245
|
-
file: true,
|
5246
|
-
idx: true
|
5247
|
-
}
|
5248
|
-
),
|
5249
|
-
meta: ensureURIDefaults(sthis, { name }, sopts.idx?.meta ?? sopts.data?.meta, base, "meta", { idx: true }),
|
5250
|
-
wal: ensureURIDefaults(sthis, { name }, sopts.idx?.wal ?? sopts.data?.wal, base, "wal", { idx: true })
|
5203
|
+
car: ensureURIDefaults(sthis, name, sopts.idx?.car ?? sopts.data?.car, base, "car", { idx: true }),
|
5204
|
+
file: ensureURIDefaults(sthis, name, sopts.idx?.file ?? sopts.idx?.car ?? sopts.data?.file ?? sopts.data?.car, base, "file", {
|
5205
|
+
file: true,
|
5206
|
+
idx: true
|
5207
|
+
}),
|
5208
|
+
meta: ensureURIDefaults(sthis, name, sopts.idx?.meta ?? sopts.data?.meta, base, "meta", { idx: true }),
|
5209
|
+
wal: ensureURIDefaults(sthis, name, sopts.idx?.wal ?? sopts.data?.wal, base, "wal", { idx: true })
|
5251
5210
|
},
|
5252
5211
|
data: {
|
5253
|
-
car: ensureURIDefaults(sthis,
|
5254
|
-
file: ensureURIDefaults(sthis,
|
5255
|
-
meta: ensureURIDefaults(sthis,
|
5256
|
-
wal: ensureURIDefaults(sthis,
|
5212
|
+
car: ensureURIDefaults(sthis, name, sopts.data?.car, base, "car"),
|
5213
|
+
file: ensureURIDefaults(sthis, name, sopts.data?.file ?? sopts.data?.car, base, "file", { file: true }),
|
5214
|
+
meta: ensureURIDefaults(sthis, name, sopts.data?.meta, base, "meta"),
|
5215
|
+
wal: ensureURIDefaults(sthis, name, sopts.data?.wal, base, "wal")
|
5257
5216
|
}
|
5258
5217
|
};
|
5259
5218
|
}
|
@@ -7259,7 +7218,7 @@ function buildResDelWAL(msgCtx, req, ctx) {
|
|
7259
7218
|
|
7260
7219
|
// src/version.ts
|
7261
7220
|
var PACKAGE_VERSION = Object.keys({
|
7262
|
-
"0.20.0
|
7221
|
+
"0.20.0": "xxxx"
|
7263
7222
|
})[0];
|
7264
7223
|
export {
|
7265
7224
|
CRDTImpl,
|