@fireproof/core 0.20.0-dev-preview-17 → 0.20.0-dev-preview-19
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/index.cjs +107 -128
- package/index.cjs.map +1 -1
- package/index.d.cts +102 -93
- package/index.d.ts +102 -93
- package/index.js +107 -128
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +1 -1
- package/tests/blockstore/interceptor-gateway.test.ts +17 -17
- package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +7 -6
- package/tests/blockstore/keyed-crypto.test.ts +14 -13
- package/tests/blockstore/store.test.ts +19 -11
- package/tests/fireproof/all-gateway.test.ts +67 -60
package/index.js
CHANGED
@@ -685,7 +685,7 @@ var KeyBag = class {
|
|
685
685
|
name,
|
686
686
|
key
|
687
687
|
};
|
688
|
-
const bag = await this.rt.
|
688
|
+
const bag = await this.rt.getBagProvider();
|
689
689
|
this.logger.Debug().Str("name", name).Msg("setNamedKey");
|
690
690
|
await bag.set(name, item);
|
691
691
|
return await this.toKeyWithFingerPrint(item.key);
|
@@ -710,7 +710,7 @@ var KeyBag = class {
|
|
710
710
|
async getNamedKey(name, failIfNotFound = false) {
|
711
711
|
const id = this.rt.sthis.nextId(4).str;
|
712
712
|
return this._seq.add(async () => {
|
713
|
-
const bag = await this.rt.
|
713
|
+
const bag = await this.rt.getBagProvider();
|
714
714
|
const named = await bag.get(name);
|
715
715
|
if (named) {
|
716
716
|
const fpr = await this.toKeyWithFingerPrint(named.key);
|
@@ -813,7 +813,7 @@ function defaultKeyBagOpts(sthis, kbo) {
|
|
813
813
|
sthis,
|
814
814
|
logger,
|
815
815
|
keyLength: kbo.keyLength || 16,
|
816
|
-
|
816
|
+
getBagProvider: () => kitem.factory(url, sthis),
|
817
817
|
id: () => {
|
818
818
|
return url.toString();
|
819
819
|
}
|
@@ -1207,21 +1207,17 @@ var DefSerdeGateway = class {
|
|
1207
1207
|
this.subscribeFn = /* @__PURE__ */ new Map();
|
1208
1208
|
this.gw = gw;
|
1209
1209
|
}
|
1210
|
-
|
1211
|
-
start(sthis, baseURL, loader) {
|
1210
|
+
start({ loader: { sthis } }, baseURL) {
|
1212
1211
|
return this.gw.start(baseURL, sthis);
|
1213
1212
|
}
|
1214
|
-
|
1215
|
-
async buildUrl(sthis, baseUrl, key, loader) {
|
1213
|
+
async buildUrl({ loader: { sthis } }, baseUrl, key) {
|
1216
1214
|
return this.gw.buildUrl(baseUrl, key, sthis);
|
1217
1215
|
}
|
1218
|
-
|
1219
|
-
async close(sthis, uri, loader) {
|
1216
|
+
async close({ loader: { sthis } }, uri) {
|
1220
1217
|
return this.gw.close(uri, sthis);
|
1221
1218
|
}
|
1222
|
-
|
1223
|
-
|
1224
|
-
const rUint8 = await fpSerialize(sthis, env);
|
1219
|
+
async put({ loader: { sthis }, encoder }, url, env) {
|
1220
|
+
const rUint8 = await fpSerialize(sthis, env, encoder);
|
1225
1221
|
if (rUint8.isErr()) return rUint8;
|
1226
1222
|
const ret = this.gw.put(url, rUint8.Ok(), sthis);
|
1227
1223
|
if (env.type === "meta" /* META */) {
|
@@ -1231,13 +1227,12 @@ var DefSerdeGateway = class {
|
|
1231
1227
|
}
|
1232
1228
|
return ret;
|
1233
1229
|
}
|
1234
|
-
|
1235
|
-
async get(sthis, url, loader) {
|
1230
|
+
async get({ loader: { sthis }, decoder }, url) {
|
1236
1231
|
const res = await this.gw.get(url, sthis);
|
1237
1232
|
if (res.isErr()) return Result7.Err(res.Err());
|
1238
|
-
return fpDeserialize(sthis, url, res);
|
1233
|
+
return fpDeserialize(sthis, url, res, decoder);
|
1239
1234
|
}
|
1240
|
-
async subscribe(sthis, url, callback
|
1235
|
+
async subscribe({ loader: { sthis }, decoder }, url, callback) {
|
1241
1236
|
if (!this.gw.subscribe) {
|
1242
1237
|
this.subscribeFn.set(url.toString(), callback);
|
1243
1238
|
return Result7.Ok(() => {
|
@@ -1247,7 +1242,7 @@ var DefSerdeGateway = class {
|
|
1247
1242
|
const unreg = await this.gw.subscribe(
|
1248
1243
|
url,
|
1249
1244
|
(raw2) => {
|
1250
|
-
fpDeserialize(sthis, url, Result7.Ok(raw2)).then((res) => {
|
1245
|
+
fpDeserialize(sthis, url, Result7.Ok(raw2), decoder).then((res) => {
|
1251
1246
|
if (res.isErr()) return;
|
1252
1247
|
callback(res.Ok());
|
1253
1248
|
});
|
@@ -1256,16 +1251,13 @@ var DefSerdeGateway = class {
|
|
1256
1251
|
);
|
1257
1252
|
return unreg;
|
1258
1253
|
}
|
1259
|
-
|
1260
|
-
async delete(sthis, url, loader) {
|
1254
|
+
async delete({ loader: { sthis } }, url) {
|
1261
1255
|
return this.gw.delete(url, sthis);
|
1262
1256
|
}
|
1263
|
-
|
1264
|
-
async destroy(sthis, baseURL, loader) {
|
1257
|
+
async destroy({ loader: { sthis } }, baseURL) {
|
1265
1258
|
return this.gw.destroy(baseURL, sthis);
|
1266
1259
|
}
|
1267
|
-
|
1268
|
-
async getPlain(sthis, iurl, key, loader) {
|
1260
|
+
async getPlain({ loader: { sthis } }, iurl, key) {
|
1269
1261
|
return this.gw.getPlain(iurl, key, sthis);
|
1270
1262
|
}
|
1271
1263
|
};
|
@@ -2439,7 +2431,7 @@ var Loader = class {
|
|
2439
2431
|
async carStore() {
|
2440
2432
|
return this._carStore.once(
|
2441
2433
|
async () => this.ebOpts.storeRuntime.makeDataStore({
|
2442
|
-
sthis: this.sthis,
|
2434
|
+
// sthis: this.sthis,
|
2443
2435
|
gatewayInterceptor: this.ebOpts.gatewayInterceptor,
|
2444
2436
|
url: this.ebOpts.storeUrls.data,
|
2445
2437
|
// keybag: await this.keyBag(),
|
@@ -2450,7 +2442,7 @@ var Loader = class {
|
|
2450
2442
|
async fileStore() {
|
2451
2443
|
return this._fileStore.once(
|
2452
2444
|
async () => this.ebOpts.storeRuntime.makeDataStore({
|
2453
|
-
sthis: this.sthis,
|
2445
|
+
// sthis: this.sthis,
|
2454
2446
|
gatewayInterceptor: this.ebOpts.gatewayInterceptor,
|
2455
2447
|
url: this.ebOpts.storeUrls.file,
|
2456
2448
|
// keybag: await this.keyBag(),
|
@@ -2461,7 +2453,7 @@ var Loader = class {
|
|
2461
2453
|
async WALStore() {
|
2462
2454
|
return this._WALStore.once(
|
2463
2455
|
async () => this.ebOpts.storeRuntime.makeWALStore({
|
2464
|
-
sthis: this.sthis,
|
2456
|
+
// sthis: this.sthis,
|
2465
2457
|
gatewayInterceptor: this.ebOpts.gatewayInterceptor,
|
2466
2458
|
url: this.ebOpts.storeUrls.wal,
|
2467
2459
|
// keybag: await this.keyBag(),
|
@@ -2472,7 +2464,7 @@ var Loader = class {
|
|
2472
2464
|
async metaStore() {
|
2473
2465
|
return this._metaStore.once(
|
2474
2466
|
async () => this.ebOpts.storeRuntime.makeMetaStore({
|
2475
|
-
sthis: this.sthis,
|
2467
|
+
// sthis: this.sthis,
|
2476
2468
|
gatewayInterceptor: this.ebOpts.gatewayInterceptor,
|
2477
2469
|
url: this.ebOpts.storeUrls.meta,
|
2478
2470
|
// keybag: await this.keyBag(),
|
@@ -2952,35 +2944,35 @@ import pMap from "p-map";
|
|
2952
2944
|
// src/blockstore/interceptor-gateway.ts
|
2953
2945
|
import { Result as Result8 } from "@adviser/cement";
|
2954
2946
|
var PassThroughGateway = class {
|
2955
|
-
async buildUrl(
|
2947
|
+
async buildUrl(ctx, url, key) {
|
2956
2948
|
const op = { url, key };
|
2957
2949
|
return Result8.Ok({ op });
|
2958
2950
|
}
|
2959
|
-
async start(
|
2951
|
+
async start(ctx, url) {
|
2960
2952
|
const op = { url };
|
2961
2953
|
return Result8.Ok({ op });
|
2962
2954
|
}
|
2963
|
-
async close(
|
2955
|
+
async close(ctx, url) {
|
2964
2956
|
const op = { url };
|
2965
2957
|
return Result8.Ok({ op });
|
2966
2958
|
}
|
2967
|
-
async delete(
|
2959
|
+
async delete(ctx, url) {
|
2968
2960
|
const op = { url };
|
2969
2961
|
return Result8.Ok({ op });
|
2970
2962
|
}
|
2971
|
-
async destroy(
|
2963
|
+
async destroy(ctx, url) {
|
2972
2964
|
const op = { url };
|
2973
2965
|
return Result8.Ok({ op });
|
2974
2966
|
}
|
2975
|
-
async put(
|
2967
|
+
async put(ctx, url, body) {
|
2976
2968
|
const op = { url, body };
|
2977
2969
|
return Result8.Ok({ op });
|
2978
2970
|
}
|
2979
|
-
async get(
|
2971
|
+
async get(ctx, url) {
|
2980
2972
|
const op = { url };
|
2981
2973
|
return Result8.Ok({ op });
|
2982
2974
|
}
|
2983
|
-
async subscribe(
|
2975
|
+
async subscribe(ctx, url, callback) {
|
2984
2976
|
const op = { url, callback };
|
2985
2977
|
return Result8.Ok({ op });
|
2986
2978
|
}
|
@@ -2991,8 +2983,8 @@ var InterceptorGateway = class {
|
|
2991
2983
|
this.innerGW = innerGW;
|
2992
2984
|
this.interceptor = interceptor || passThrougthGateway;
|
2993
2985
|
}
|
2994
|
-
async buildUrl(
|
2995
|
-
const rret = await this.interceptor.buildUrl(
|
2986
|
+
async buildUrl(ctx, baseUrl, key) {
|
2987
|
+
const rret = await this.interceptor.buildUrl(ctx, baseUrl, key);
|
2996
2988
|
if (rret.isErr()) {
|
2997
2989
|
return Result8.Err(rret.Err());
|
2998
2990
|
}
|
@@ -3000,10 +2992,10 @@ var InterceptorGateway = class {
|
|
3000
2992
|
if (ret.stop && ret.value) {
|
3001
2993
|
return ret.value;
|
3002
2994
|
}
|
3003
|
-
return this.innerGW.buildUrl(
|
2995
|
+
return this.innerGW.buildUrl(ctx, ret.op.url, ret.op.key);
|
3004
2996
|
}
|
3005
|
-
async destroy(
|
3006
|
-
const rret = await this.interceptor.destroy(
|
2997
|
+
async destroy(ctx, iurl) {
|
2998
|
+
const rret = await this.interceptor.destroy(ctx, iurl);
|
3007
2999
|
if (rret.isErr()) {
|
3008
3000
|
return Result8.Err(rret.Err());
|
3009
3001
|
}
|
@@ -3011,10 +3003,10 @@ var InterceptorGateway = class {
|
|
3011
3003
|
if (ret.stop && ret.value) {
|
3012
3004
|
return ret.value;
|
3013
3005
|
}
|
3014
|
-
return this.innerGW.destroy(
|
3006
|
+
return this.innerGW.destroy(ctx, ret.op.url);
|
3015
3007
|
}
|
3016
|
-
async start(
|
3017
|
-
const rret = await this.interceptor.start(
|
3008
|
+
async start(ctx, url) {
|
3009
|
+
const rret = await this.interceptor.start(ctx, url);
|
3018
3010
|
if (rret.isErr()) {
|
3019
3011
|
return Result8.Err(rret.Err());
|
3020
3012
|
}
|
@@ -3022,10 +3014,10 @@ var InterceptorGateway = class {
|
|
3022
3014
|
if (ret.stop && ret.value) {
|
3023
3015
|
return ret.value;
|
3024
3016
|
}
|
3025
|
-
return await this.innerGW.start(
|
3017
|
+
return await this.innerGW.start(ctx, ret.op.url);
|
3026
3018
|
}
|
3027
|
-
async close(
|
3028
|
-
const rret = await this.interceptor.close(
|
3019
|
+
async close(ctx, url) {
|
3020
|
+
const rret = await this.interceptor.close(ctx, url);
|
3029
3021
|
if (rret.isErr()) {
|
3030
3022
|
return Result8.Err(rret.Err());
|
3031
3023
|
}
|
@@ -3033,10 +3025,10 @@ var InterceptorGateway = class {
|
|
3033
3025
|
if (ret.stop && ret.value) {
|
3034
3026
|
return ret.value;
|
3035
3027
|
}
|
3036
|
-
return await this.innerGW.close(
|
3028
|
+
return await this.innerGW.close(ctx, ret.op.url);
|
3037
3029
|
}
|
3038
|
-
async put(
|
3039
|
-
const rret = await this.interceptor.put(
|
3030
|
+
async put(ctx, url, fpEnv) {
|
3031
|
+
const rret = await this.interceptor.put(ctx, url, fpEnv);
|
3040
3032
|
if (rret.isErr()) {
|
3041
3033
|
return Result8.Err(rret.Err());
|
3042
3034
|
}
|
@@ -3044,10 +3036,10 @@ var InterceptorGateway = class {
|
|
3044
3036
|
if (ret.stop && ret.value) {
|
3045
3037
|
return ret.value;
|
3046
3038
|
}
|
3047
|
-
return this.innerGW.put(
|
3039
|
+
return this.innerGW.put(ctx, ret.op.url, ret.op.body);
|
3048
3040
|
}
|
3049
|
-
async get(
|
3050
|
-
const rret = await this.interceptor.get(
|
3041
|
+
async get(ctx, url) {
|
3042
|
+
const rret = await this.interceptor.get(ctx, url);
|
3051
3043
|
if (rret.isErr()) {
|
3052
3044
|
return Result8.Err(rret.Err());
|
3053
3045
|
}
|
@@ -3055,13 +3047,13 @@ var InterceptorGateway = class {
|
|
3055
3047
|
if (ret.stop && ret.value) {
|
3056
3048
|
return ret.value;
|
3057
3049
|
}
|
3058
|
-
return this.innerGW.get(
|
3050
|
+
return this.innerGW.get(ctx, ret.op.url);
|
3059
3051
|
}
|
3060
|
-
async subscribe(
|
3052
|
+
async subscribe(ctx, url, callback) {
|
3061
3053
|
if (!this.innerGW.subscribe) {
|
3062
|
-
return Result8.Err(sthis.logger.Error().Url(url).Msg("subscribe not supported").AsError());
|
3054
|
+
return Result8.Err(ctx.loader.sthis.logger.Error().Url(url).Msg("subscribe not supported").AsError());
|
3063
3055
|
}
|
3064
|
-
const rret = await this.interceptor.subscribe(
|
3056
|
+
const rret = await this.interceptor.subscribe(ctx, url, callback);
|
3065
3057
|
if (rret.isErr()) {
|
3066
3058
|
return Result8.Err(rret.Err());
|
3067
3059
|
}
|
@@ -3069,10 +3061,10 @@ var InterceptorGateway = class {
|
|
3069
3061
|
if (ret.stop && ret.value) {
|
3070
3062
|
return ret.value;
|
3071
3063
|
}
|
3072
|
-
return this.innerGW.subscribe(
|
3064
|
+
return this.innerGW.subscribe(ctx, ret.op.url, ret.op.callback);
|
3073
3065
|
}
|
3074
|
-
async delete(
|
3075
|
-
const rret = await this.interceptor.delete(
|
3066
|
+
async delete(ctx, url) {
|
3067
|
+
const rret = await this.interceptor.delete(ctx, url);
|
3076
3068
|
if (rret.isErr()) {
|
3077
3069
|
return Result8.Err(rret.Err());
|
3078
3070
|
}
|
@@ -3080,10 +3072,10 @@ var InterceptorGateway = class {
|
|
3080
3072
|
if (ret.stop && ret.value) {
|
3081
3073
|
return ret.value;
|
3082
3074
|
}
|
3083
|
-
return this.innerGW.delete(
|
3075
|
+
return this.innerGW.delete(ctx, url);
|
3084
3076
|
}
|
3085
|
-
async getPlain(
|
3086
|
-
return this.innerGW.getPlain(
|
3077
|
+
async getPlain(ctx, url, key) {
|
3078
|
+
return this.innerGW.getPlain(ctx, url, key);
|
3087
3079
|
}
|
3088
3080
|
};
|
3089
3081
|
|
@@ -3129,7 +3121,7 @@ var BaseStoreImpl = class {
|
|
3129
3121
|
async start() {
|
3130
3122
|
this.logger.Debug().Str("storeType", this.storeType).Msg("starting-gateway-pre");
|
3131
3123
|
this._url = this._url.build().setParam("store" /* STORE */, this.storeType).URI();
|
3132
|
-
const res = await this.gateway.start(this.
|
3124
|
+
const res = await this.gateway.start({ loader: this.loader }, this._url);
|
3133
3125
|
if (res.isErr()) {
|
3134
3126
|
this.logger.Error().Result("gw-start", res).Msg("started-gateway");
|
3135
3127
|
return res;
|
@@ -3194,18 +3186,13 @@ var MetaStoreImpl = class extends BaseStoreImpl {
|
|
3194
3186
|
) {
|
3195
3187
|
this.onStarted(async () => {
|
3196
3188
|
this.logger.Debug().Str("url", this.url().toString()).Msg("Subscribing to the gateway");
|
3197
|
-
opts.gateway.subscribe
|
3198
|
-
this.
|
3199
|
-
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3204
|
-
);
|
3205
|
-
this.updateParentsFromDbMetas(dbMetas);
|
3206
|
-
},
|
3207
|
-
this.loader
|
3208
|
-
);
|
3189
|
+
opts.gateway.subscribe({ loader: this.loader }, this.url(), async ({ payload: dbMetas }) => {
|
3190
|
+
this.logger.Debug().Msg("Received message from gateway");
|
3191
|
+
await Promise.all(
|
3192
|
+
dbMetas.map((dbMeta) => this.loader.taskManager?.handleEvent(dbMeta.eventCid, dbMeta.parents, dbMeta.dbMeta))
|
3193
|
+
);
|
3194
|
+
this.updateParentsFromDbMetas(dbMetas);
|
3195
|
+
});
|
3209
3196
|
});
|
3210
3197
|
}
|
3211
3198
|
}
|
@@ -3226,11 +3213,11 @@ var MetaStoreImpl = class extends BaseStoreImpl {
|
|
3226
3213
|
// }
|
3227
3214
|
async load() {
|
3228
3215
|
const branch = "main";
|
3229
|
-
const url = await this.gateway.buildUrl(this.
|
3216
|
+
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), branch);
|
3230
3217
|
if (url.isErr()) {
|
3231
3218
|
throw this.logger.Error().Result("buildUrl", url).Str("branch", branch).Msg("got error from gateway.buildUrl").AsError();
|
3232
3219
|
}
|
3233
|
-
const rfpEnv = await this.gateway.get(this.
|
3220
|
+
const rfpEnv = await this.gateway.get({ loader: this.loader }, url.Ok());
|
3234
3221
|
if (rfpEnv.isErr()) {
|
3235
3222
|
if (isNotFoundError(rfpEnv)) {
|
3236
3223
|
return void 0;
|
@@ -3245,33 +3232,28 @@ var MetaStoreImpl = class extends BaseStoreImpl {
|
|
3245
3232
|
async save(meta, branch) {
|
3246
3233
|
branch = branch || "main";
|
3247
3234
|
this.logger.Debug().Str("branch", branch).Any("meta", meta).Msg("saving meta");
|
3248
|
-
const url = await this.gateway.buildUrl(this.
|
3235
|
+
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), branch);
|
3249
3236
|
if (url.isErr()) {
|
3250
3237
|
throw this.logger.Error().Err(url.Err()).Str("branch", branch).Msg("got error from gateway.buildUrl").AsError();
|
3251
3238
|
}
|
3252
3239
|
const dbMetaEvent = await createDbMetaEvent(this.sthis, meta, this.parents);
|
3253
|
-
const res = await this.gateway.put(
|
3254
|
-
|
3255
|
-
|
3256
|
-
|
3257
|
-
type: "meta",
|
3258
|
-
payload: [dbMetaEvent]
|
3259
|
-
},
|
3260
|
-
this.loader
|
3261
|
-
);
|
3240
|
+
const res = await this.gateway.put({ loader: this.loader }, url.Ok(), {
|
3241
|
+
type: "meta",
|
3242
|
+
payload: [dbMetaEvent]
|
3243
|
+
});
|
3262
3244
|
if (res.isErr()) {
|
3263
3245
|
throw this.logger.Error().Err(res.Err()).Msg("got error from gateway.put").AsError();
|
3264
3246
|
}
|
3265
3247
|
return res;
|
3266
3248
|
}
|
3267
3249
|
async close() {
|
3268
|
-
await this.gateway.close(this.
|
3250
|
+
await this.gateway.close({ loader: this.loader }, this.url());
|
3269
3251
|
this._onClosed.forEach((fn) => fn());
|
3270
3252
|
return Result9.Ok(void 0);
|
3271
3253
|
}
|
3272
3254
|
async destroy() {
|
3273
3255
|
this.logger.Debug().Msg("destroy");
|
3274
|
-
return this.gateway.destroy(this.
|
3256
|
+
return this.gateway.destroy({ loader: this.loader }, this.url());
|
3275
3257
|
}
|
3276
3258
|
};
|
3277
3259
|
var DataStoreImpl = class extends BaseStoreImpl {
|
@@ -3281,11 +3263,11 @@ var DataStoreImpl = class extends BaseStoreImpl {
|
|
3281
3263
|
}
|
3282
3264
|
async load(cid) {
|
3283
3265
|
this.logger.Debug().Any("cid", cid).Msg("loading");
|
3284
|
-
const url = await this.gateway.buildUrl(this.
|
3266
|
+
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), cid.toString());
|
3285
3267
|
if (url.isErr()) {
|
3286
3268
|
throw this.logger.Error().Err(url.Err()).Str("cid", cid.toString()).Msg("got error from gateway.buildUrl").AsError();
|
3287
3269
|
}
|
3288
|
-
const res = await this.gateway.get(this.
|
3270
|
+
const res = await this.gateway.get({ loader: this.loader }, url.Ok());
|
3289
3271
|
if (res.isErr()) {
|
3290
3272
|
throw res.Err();
|
3291
3273
|
}
|
@@ -3302,7 +3284,7 @@ var DataStoreImpl = class extends BaseStoreImpl {
|
|
3302
3284
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
3303
3285
|
async save(car, opts) {
|
3304
3286
|
this.logger.Debug().Any("cid", car.cid.toString()).Msg("saving");
|
3305
|
-
const url = await this.gateway.buildUrl(this.
|
3287
|
+
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), car.cid.toString());
|
3306
3288
|
if (url.isErr()) {
|
3307
3289
|
throw this.logger.Error().Err(url.Err()).Ref("cid", car.cid).Msg("got error from gateway.buildUrl").AsError();
|
3308
3290
|
}
|
@@ -3321,27 +3303,27 @@ var DataStoreImpl = class extends BaseStoreImpl {
|
|
3321
3303
|
if (fpMsg.isErr()) {
|
3322
3304
|
throw this.logger.Error().Err(fpMsg).Msg("got error from FPMsg2Car").AsError();
|
3323
3305
|
}
|
3324
|
-
const res = await this.gateway.put(this.
|
3306
|
+
const res = await this.gateway.put({ loader: this.loader }, url.Ok(), fpMsg.Ok());
|
3325
3307
|
if (res.isErr()) {
|
3326
3308
|
throw this.logger.Error().Err(res.Err()).Msg("got error from gateway.put").AsError();
|
3327
3309
|
}
|
3328
3310
|
return res.Ok();
|
3329
3311
|
}
|
3330
3312
|
async remove(cid) {
|
3331
|
-
const url = await this.gateway.buildUrl(this.
|
3313
|
+
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), cid.toString());
|
3332
3314
|
if (url.isErr()) {
|
3333
3315
|
return url;
|
3334
3316
|
}
|
3335
|
-
return this.gateway.delete(this.
|
3317
|
+
return this.gateway.delete({ loader: this.loader }, url.Ok());
|
3336
3318
|
}
|
3337
3319
|
async close() {
|
3338
|
-
await this.gateway.close(this.
|
3320
|
+
await this.gateway.close({ loader: this.loader }, this.url());
|
3339
3321
|
this._onClosed.forEach((fn) => fn());
|
3340
3322
|
return Result9.Ok(void 0);
|
3341
3323
|
}
|
3342
3324
|
destroy() {
|
3343
3325
|
this.logger.Debug().Msg("destroy");
|
3344
|
-
return this.gateway.destroy(this.
|
3326
|
+
return this.gateway.destroy({ loader: this.loader }, this.url());
|
3345
3327
|
}
|
3346
3328
|
};
|
3347
3329
|
var WALStoreImpl = class extends BaseStoreImpl {
|
@@ -3497,11 +3479,11 @@ var WALStoreImpl = class extends BaseStoreImpl {
|
|
3497
3479
|
}
|
3498
3480
|
async load() {
|
3499
3481
|
this.logger.Debug().Msg("loading");
|
3500
|
-
const filepath = await this.gateway.buildUrl(this.
|
3482
|
+
const filepath = await this.gateway.buildUrl({ loader: this.loader }, this.url(), "main");
|
3501
3483
|
if (filepath.isErr()) {
|
3502
3484
|
throw this.logger.Error().Err(filepath.Err()).Url(this.url()).Msg("error building url").AsError();
|
3503
3485
|
}
|
3504
|
-
const bytes = await this.gateway.get(this.
|
3486
|
+
const bytes = await this.gateway.get({ loader: this.loader }, filepath.Ok());
|
3505
3487
|
if (bytes.isErr()) {
|
3506
3488
|
if (isNotFoundError(bytes)) {
|
3507
3489
|
return void 0;
|
@@ -3514,64 +3496,59 @@ var WALStoreImpl = class extends BaseStoreImpl {
|
|
3514
3496
|
return bytes.Ok().payload;
|
3515
3497
|
}
|
3516
3498
|
async save(state) {
|
3517
|
-
const filepath = await this.gateway.buildUrl(this.
|
3499
|
+
const filepath = await this.gateway.buildUrl({ loader: this.loader }, this.url(), "main");
|
3518
3500
|
if (filepath.isErr()) {
|
3519
3501
|
throw this.logger.Error().Err(filepath.Err()).Url(this.url()).Msg("error building url").AsError();
|
3520
3502
|
}
|
3521
|
-
const res = await this.gateway.put(
|
3522
|
-
|
3523
|
-
|
3524
|
-
|
3525
|
-
type: "wal",
|
3526
|
-
payload: state
|
3527
|
-
},
|
3528
|
-
this.loader
|
3529
|
-
);
|
3503
|
+
const res = await this.gateway.put({ loader: this.loader }, filepath.Ok(), {
|
3504
|
+
type: "wal",
|
3505
|
+
payload: state
|
3506
|
+
});
|
3530
3507
|
if (res.isErr()) {
|
3531
3508
|
throw this.logger.Error().Err(res.Err()).Str("filePath", filepath.Ok().toString()).Msg("error saving").AsError();
|
3532
3509
|
}
|
3533
3510
|
}
|
3534
3511
|
async close() {
|
3535
|
-
await this.gateway.close(this.
|
3512
|
+
await this.gateway.close({ loader: this.loader }, this.url());
|
3536
3513
|
this._onClosed.forEach((fn) => fn());
|
3537
3514
|
return Result9.Ok(void 0);
|
3538
3515
|
}
|
3539
3516
|
destroy() {
|
3540
3517
|
this.logger.Debug().Msg("destroy");
|
3541
|
-
return this.gateway.destroy(this.
|
3518
|
+
return this.gateway.destroy({ loader: this.loader }, this.url());
|
3542
3519
|
}
|
3543
3520
|
};
|
3544
3521
|
|
3545
3522
|
// src/blockstore/store-factory.ts
|
3546
3523
|
var onceGateway = new KeyedResolvOnce3();
|
3547
3524
|
var gatewayInstances = new KeyedResolvOnce3();
|
3548
|
-
async function getStartedGateway(
|
3525
|
+
async function getStartedGateway(ctx, url) {
|
3549
3526
|
return onceGateway.get(url.toString()).once(async () => {
|
3550
3527
|
const item = getGatewayFactoryItem(url.protocol);
|
3551
3528
|
if (item) {
|
3552
3529
|
const ret = {
|
3553
3530
|
url,
|
3554
3531
|
...await gatewayInstances.get(url.protocol).once(async () => ({})),
|
3555
|
-
gateway: await item.serdegateway(sthis)
|
3532
|
+
gateway: await item.serdegateway(ctx.loader.sthis)
|
3556
3533
|
};
|
3557
|
-
const res = await ret.gateway.start(
|
3534
|
+
const res = await ret.gateway.start(ctx, url);
|
3558
3535
|
if (res.isErr()) {
|
3559
|
-
return Result10.Err(sthis.logger.Error().Result("start", res).Msg("start failed").AsError());
|
3536
|
+
return Result10.Err(ctx.loader.sthis.logger.Error().Result("start", res).Msg("start failed").AsError());
|
3560
3537
|
}
|
3561
3538
|
ret.url = res.Ok();
|
3562
3539
|
return Result10.Ok(ret);
|
3563
3540
|
}
|
3564
|
-
return Result10.Err(sthis.logger.Warn().Url(url).Msg("unsupported protocol").AsError());
|
3541
|
+
return Result10.Err(ctx.loader.sthis.logger.Warn().Url(url).Msg("unsupported protocol").AsError());
|
3565
3542
|
});
|
3566
3543
|
}
|
3567
3544
|
async function dataStoreFactory(sfi) {
|
3568
3545
|
const storeUrl = sfi.url.build().setParam("store" /* STORE */, "data").URI();
|
3569
|
-
const rgateway = await getStartedGateway(sfi
|
3546
|
+
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3570
3547
|
if (rgateway.isErr()) {
|
3571
|
-
throw sfi.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
3548
|
+
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
3572
3549
|
}
|
3573
3550
|
const gateway = rgateway.Ok();
|
3574
|
-
const store = new DataStoreImpl(sfi.sthis, gateway.url, {
|
3551
|
+
const store = new DataStoreImpl(sfi.loader.sthis, gateway.url, {
|
3575
3552
|
gateway: gateway.gateway,
|
3576
3553
|
gatewayInterceptor: sfi.gatewayInterceptor,
|
3577
3554
|
loader: sfi.loader
|
@@ -3580,12 +3557,12 @@ async function dataStoreFactory(sfi) {
|
|
3580
3557
|
}
|
3581
3558
|
async function metaStoreFactory(sfi) {
|
3582
3559
|
const storeUrl = sfi.url.build().setParam("store" /* STORE */, "meta").URI();
|
3583
|
-
const rgateway = await getStartedGateway(sfi
|
3560
|
+
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3584
3561
|
if (rgateway.isErr()) {
|
3585
|
-
throw sfi.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
3562
|
+
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
3586
3563
|
}
|
3587
3564
|
const gateway = rgateway.Ok();
|
3588
|
-
const store = new MetaStoreImpl(sfi.sthis, gateway.url, {
|
3565
|
+
const store = new MetaStoreImpl(sfi.loader.sthis, gateway.url, {
|
3589
3566
|
gateway: gateway.gateway,
|
3590
3567
|
gatewayInterceptor: sfi.gatewayInterceptor,
|
3591
3568
|
loader: sfi.loader
|
@@ -3594,12 +3571,12 @@ async function metaStoreFactory(sfi) {
|
|
3594
3571
|
}
|
3595
3572
|
async function WALStoreFactory(sfi) {
|
3596
3573
|
const storeUrl = sfi.url.build().setParam("store" /* STORE */, "wal").URI();
|
3597
|
-
const rgateway = await getStartedGateway(sfi
|
3574
|
+
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3598
3575
|
if (rgateway.isErr()) {
|
3599
|
-
throw sfi.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
3576
|
+
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
3600
3577
|
}
|
3601
3578
|
const gateway = rgateway.Ok();
|
3602
|
-
const store = new WALStoreImpl(sfi.sthis, gateway.url, {
|
3579
|
+
const store = new WALStoreImpl(sfi.loader.sthis, gateway.url, {
|
3603
3580
|
gateway: gateway.gateway,
|
3604
3581
|
gatewayInterceptor: sfi.gatewayInterceptor,
|
3605
3582
|
loader: sfi.loader
|
@@ -3726,7 +3703,7 @@ var ConnectionBase = class {
|
|
3726
3703
|
this.loader = loader;
|
3727
3704
|
await this.onConnect();
|
3728
3705
|
const metaUrl = this.url.build().defParam("store" /* STORE */, "meta").URI();
|
3729
|
-
const rgateway = await getStartedGateway(loader
|
3706
|
+
const rgateway = await getStartedGateway({ loader }, metaUrl);
|
3730
3707
|
if (rgateway.isErr())
|
3731
3708
|
throw this.logger.Error().Result("err", rgateway).Url(metaUrl).Msg("connectMeta: gateway is required").AsError();
|
3732
3709
|
const dbName = metaUrl.getParam("name" /* NAME */);
|
@@ -3762,7 +3739,7 @@ var ConnectionBase = class {
|
|
3762
3739
|
if (!loader) throw this.logger.Error().Msg("connectStorage: loader is required").AsError();
|
3763
3740
|
this.loader = loader;
|
3764
3741
|
const dataUrl = this.url.build().defParam("store" /* STORE */, "data").URI();
|
3765
|
-
const rgateway = await getStartedGateway(loader
|
3742
|
+
const rgateway = await getStartedGateway({ loader }, dataUrl);
|
3766
3743
|
if (rgateway.isErr())
|
3767
3744
|
throw this.logger.Error().Result("err", rgateway).Url(dataUrl).Msg("connectStorage: gateway is required").AsError();
|
3768
3745
|
const name = dataUrl.getParam("name" /* NAME */);
|
@@ -4665,6 +4642,8 @@ import { runtimeFn as runtimeFn4 } from "@adviser/cement";
|
|
4665
4642
|
var gateways_exports = {};
|
4666
4643
|
__export(gateways_exports, {
|
4667
4644
|
DefSerdeGateway: () => DefSerdeGateway,
|
4645
|
+
dbMetaEvent2Serialized: () => dbMetaEvent2Serialized,
|
4646
|
+
decode2DbMetaEvents: () => decode2DbMetaEvents,
|
4668
4647
|
file: () => file_exports,
|
4669
4648
|
fpDeserialize: () => fpDeserialize,
|
4670
4649
|
fpSerialize: () => fpSerialize,
|
@@ -4680,7 +4659,7 @@ __export(file_exports, {
|
|
4680
4659
|
|
4681
4660
|
// src/version.ts
|
4682
4661
|
var PACKAGE_VERSION = Object.keys({
|
4683
|
-
"0.20.0-dev-preview-
|
4662
|
+
"0.20.0-dev-preview-19": "xxxx"
|
4684
4663
|
})[0];
|
4685
4664
|
export {
|
4686
4665
|
CRDTImpl,
|