@fireproof/core 0.20.0-dev-preview-18 → 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 CHANGED
@@ -1255,21 +1255,17 @@ var DefSerdeGateway = class {
1255
1255
  this.subscribeFn = /* @__PURE__ */ new Map();
1256
1256
  this.gw = gw;
1257
1257
  }
1258
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1259
- start(sthis, baseURL, loader) {
1258
+ start({ loader: { sthis } }, baseURL) {
1260
1259
  return this.gw.start(baseURL, sthis);
1261
1260
  }
1262
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1263
- async buildUrl(sthis, baseUrl, key, loader) {
1261
+ async buildUrl({ loader: { sthis } }, baseUrl, key) {
1264
1262
  return this.gw.buildUrl(baseUrl, key, sthis);
1265
1263
  }
1266
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1267
- async close(sthis, uri, loader) {
1264
+ async close({ loader: { sthis } }, uri) {
1268
1265
  return this.gw.close(uri, sthis);
1269
1266
  }
1270
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1271
- async put(sthis, url, env, loader) {
1272
- const rUint8 = await fpSerialize(sthis, env);
1267
+ async put({ loader: { sthis }, encoder }, url, env) {
1268
+ const rUint8 = await fpSerialize(sthis, env, encoder);
1273
1269
  if (rUint8.isErr()) return rUint8;
1274
1270
  const ret = this.gw.put(url, rUint8.Ok(), sthis);
1275
1271
  if (env.type === "meta" /* META */) {
@@ -1279,13 +1275,12 @@ var DefSerdeGateway = class {
1279
1275
  }
1280
1276
  return ret;
1281
1277
  }
1282
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1283
- async get(sthis, url, loader) {
1278
+ async get({ loader: { sthis }, decoder }, url) {
1284
1279
  const res = await this.gw.get(url, sthis);
1285
1280
  if (res.isErr()) return import_cement9.Result.Err(res.Err());
1286
- return fpDeserialize(sthis, url, res);
1281
+ return fpDeserialize(sthis, url, res, decoder);
1287
1282
  }
1288
- async subscribe(sthis, url, callback, loader) {
1283
+ async subscribe({ loader: { sthis }, decoder }, url, callback) {
1289
1284
  if (!this.gw.subscribe) {
1290
1285
  this.subscribeFn.set(url.toString(), callback);
1291
1286
  return import_cement9.Result.Ok(() => {
@@ -1295,7 +1290,7 @@ var DefSerdeGateway = class {
1295
1290
  const unreg = await this.gw.subscribe(
1296
1291
  url,
1297
1292
  (raw2) => {
1298
- fpDeserialize(sthis, url, import_cement9.Result.Ok(raw2)).then((res) => {
1293
+ fpDeserialize(sthis, url, import_cement9.Result.Ok(raw2), decoder).then((res) => {
1299
1294
  if (res.isErr()) return;
1300
1295
  callback(res.Ok());
1301
1296
  });
@@ -1304,16 +1299,13 @@ var DefSerdeGateway = class {
1304
1299
  );
1305
1300
  return unreg;
1306
1301
  }
1307
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1308
- async delete(sthis, url, loader) {
1302
+ async delete({ loader: { sthis } }, url) {
1309
1303
  return this.gw.delete(url, sthis);
1310
1304
  }
1311
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1312
- async destroy(sthis, baseURL, loader) {
1305
+ async destroy({ loader: { sthis } }, baseURL) {
1313
1306
  return this.gw.destroy(baseURL, sthis);
1314
1307
  }
1315
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1316
- async getPlain(sthis, iurl, key, loader) {
1308
+ async getPlain({ loader: { sthis } }, iurl, key) {
1317
1309
  return this.gw.getPlain(iurl, key, sthis);
1318
1310
  }
1319
1311
  };
@@ -2487,7 +2479,7 @@ var Loader = class {
2487
2479
  async carStore() {
2488
2480
  return this._carStore.once(
2489
2481
  async () => this.ebOpts.storeRuntime.makeDataStore({
2490
- sthis: this.sthis,
2482
+ // sthis: this.sthis,
2491
2483
  gatewayInterceptor: this.ebOpts.gatewayInterceptor,
2492
2484
  url: this.ebOpts.storeUrls.data,
2493
2485
  // keybag: await this.keyBag(),
@@ -2498,7 +2490,7 @@ var Loader = class {
2498
2490
  async fileStore() {
2499
2491
  return this._fileStore.once(
2500
2492
  async () => this.ebOpts.storeRuntime.makeDataStore({
2501
- sthis: this.sthis,
2493
+ // sthis: this.sthis,
2502
2494
  gatewayInterceptor: this.ebOpts.gatewayInterceptor,
2503
2495
  url: this.ebOpts.storeUrls.file,
2504
2496
  // keybag: await this.keyBag(),
@@ -2509,7 +2501,7 @@ var Loader = class {
2509
2501
  async WALStore() {
2510
2502
  return this._WALStore.once(
2511
2503
  async () => this.ebOpts.storeRuntime.makeWALStore({
2512
- sthis: this.sthis,
2504
+ // sthis: this.sthis,
2513
2505
  gatewayInterceptor: this.ebOpts.gatewayInterceptor,
2514
2506
  url: this.ebOpts.storeUrls.wal,
2515
2507
  // keybag: await this.keyBag(),
@@ -2520,7 +2512,7 @@ var Loader = class {
2520
2512
  async metaStore() {
2521
2513
  return this._metaStore.once(
2522
2514
  async () => this.ebOpts.storeRuntime.makeMetaStore({
2523
- sthis: this.sthis,
2515
+ // sthis: this.sthis,
2524
2516
  gatewayInterceptor: this.ebOpts.gatewayInterceptor,
2525
2517
  url: this.ebOpts.storeUrls.meta,
2526
2518
  // keybag: await this.keyBag(),
@@ -3000,35 +2992,35 @@ var import_p_map = __toESM(require("p-map"), 1);
3000
2992
  // src/blockstore/interceptor-gateway.ts
3001
2993
  var import_cement14 = require("@adviser/cement");
3002
2994
  var PassThroughGateway = class {
3003
- async buildUrl(sthis, url, key) {
2995
+ async buildUrl(ctx, url, key) {
3004
2996
  const op = { url, key };
3005
2997
  return import_cement14.Result.Ok({ op });
3006
2998
  }
3007
- async start(sthis, url) {
2999
+ async start(ctx, url) {
3008
3000
  const op = { url };
3009
3001
  return import_cement14.Result.Ok({ op });
3010
3002
  }
3011
- async close(sthis, url) {
3003
+ async close(ctx, url) {
3012
3004
  const op = { url };
3013
3005
  return import_cement14.Result.Ok({ op });
3014
3006
  }
3015
- async delete(sthis, url) {
3007
+ async delete(ctx, url) {
3016
3008
  const op = { url };
3017
3009
  return import_cement14.Result.Ok({ op });
3018
3010
  }
3019
- async destroy(sthis, url) {
3011
+ async destroy(ctx, url) {
3020
3012
  const op = { url };
3021
3013
  return import_cement14.Result.Ok({ op });
3022
3014
  }
3023
- async put(sthis, url, body) {
3015
+ async put(ctx, url, body) {
3024
3016
  const op = { url, body };
3025
3017
  return import_cement14.Result.Ok({ op });
3026
3018
  }
3027
- async get(sthis, url) {
3019
+ async get(ctx, url) {
3028
3020
  const op = { url };
3029
3021
  return import_cement14.Result.Ok({ op });
3030
3022
  }
3031
- async subscribe(sthis, url, callback) {
3023
+ async subscribe(ctx, url, callback) {
3032
3024
  const op = { url, callback };
3033
3025
  return import_cement14.Result.Ok({ op });
3034
3026
  }
@@ -3039,8 +3031,8 @@ var InterceptorGateway = class {
3039
3031
  this.innerGW = innerGW;
3040
3032
  this.interceptor = interceptor || passThrougthGateway;
3041
3033
  }
3042
- async buildUrl(sthis, baseUrl, key, loader) {
3043
- const rret = await this.interceptor.buildUrl(sthis, baseUrl, key, loader);
3034
+ async buildUrl(ctx, baseUrl, key) {
3035
+ const rret = await this.interceptor.buildUrl(ctx, baseUrl, key);
3044
3036
  if (rret.isErr()) {
3045
3037
  return import_cement14.Result.Err(rret.Err());
3046
3038
  }
@@ -3048,10 +3040,10 @@ var InterceptorGateway = class {
3048
3040
  if (ret.stop && ret.value) {
3049
3041
  return ret.value;
3050
3042
  }
3051
- return this.innerGW.buildUrl(sthis, ret.op.url, ret.op.key, loader);
3043
+ return this.innerGW.buildUrl(ctx, ret.op.url, ret.op.key);
3052
3044
  }
3053
- async destroy(sthis, iurl, loader) {
3054
- const rret = await this.interceptor.destroy(sthis, iurl, loader);
3045
+ async destroy(ctx, iurl) {
3046
+ const rret = await this.interceptor.destroy(ctx, iurl);
3055
3047
  if (rret.isErr()) {
3056
3048
  return import_cement14.Result.Err(rret.Err());
3057
3049
  }
@@ -3059,10 +3051,10 @@ var InterceptorGateway = class {
3059
3051
  if (ret.stop && ret.value) {
3060
3052
  return ret.value;
3061
3053
  }
3062
- return this.innerGW.destroy(sthis, ret.op.url, loader);
3054
+ return this.innerGW.destroy(ctx, ret.op.url);
3063
3055
  }
3064
- async start(sthis, url, loader) {
3065
- const rret = await this.interceptor.start(sthis, url, loader);
3056
+ async start(ctx, url) {
3057
+ const rret = await this.interceptor.start(ctx, url);
3066
3058
  if (rret.isErr()) {
3067
3059
  return import_cement14.Result.Err(rret.Err());
3068
3060
  }
@@ -3070,10 +3062,10 @@ var InterceptorGateway = class {
3070
3062
  if (ret.stop && ret.value) {
3071
3063
  return ret.value;
3072
3064
  }
3073
- return await this.innerGW.start(sthis, ret.op.url, loader);
3065
+ return await this.innerGW.start(ctx, ret.op.url);
3074
3066
  }
3075
- async close(sthis, url, loader) {
3076
- const rret = await this.interceptor.close(sthis, url, loader);
3067
+ async close(ctx, url) {
3068
+ const rret = await this.interceptor.close(ctx, url);
3077
3069
  if (rret.isErr()) {
3078
3070
  return import_cement14.Result.Err(rret.Err());
3079
3071
  }
@@ -3081,10 +3073,10 @@ var InterceptorGateway = class {
3081
3073
  if (ret.stop && ret.value) {
3082
3074
  return ret.value;
3083
3075
  }
3084
- return await this.innerGW.close(sthis, ret.op.url, loader);
3076
+ return await this.innerGW.close(ctx, ret.op.url);
3085
3077
  }
3086
- async put(sthis, url, fpEnv, loader) {
3087
- const rret = await this.interceptor.put(sthis, url, fpEnv, loader);
3078
+ async put(ctx, url, fpEnv) {
3079
+ const rret = await this.interceptor.put(ctx, url, fpEnv);
3088
3080
  if (rret.isErr()) {
3089
3081
  return import_cement14.Result.Err(rret.Err());
3090
3082
  }
@@ -3092,10 +3084,10 @@ var InterceptorGateway = class {
3092
3084
  if (ret.stop && ret.value) {
3093
3085
  return ret.value;
3094
3086
  }
3095
- return this.innerGW.put(sthis, ret.op.url, ret.op.body, loader);
3087
+ return this.innerGW.put(ctx, ret.op.url, ret.op.body);
3096
3088
  }
3097
- async get(sthis, url, loader) {
3098
- const rret = await this.interceptor.get(sthis, url, loader);
3089
+ async get(ctx, url) {
3090
+ const rret = await this.interceptor.get(ctx, url);
3099
3091
  if (rret.isErr()) {
3100
3092
  return import_cement14.Result.Err(rret.Err());
3101
3093
  }
@@ -3103,13 +3095,13 @@ var InterceptorGateway = class {
3103
3095
  if (ret.stop && ret.value) {
3104
3096
  return ret.value;
3105
3097
  }
3106
- return this.innerGW.get(sthis, ret.op.url, loader);
3098
+ return this.innerGW.get(ctx, ret.op.url);
3107
3099
  }
3108
- async subscribe(sthis, url, callback, loader) {
3100
+ async subscribe(ctx, url, callback) {
3109
3101
  if (!this.innerGW.subscribe) {
3110
- return import_cement14.Result.Err(sthis.logger.Error().Url(url).Msg("subscribe not supported").AsError());
3102
+ return import_cement14.Result.Err(ctx.loader.sthis.logger.Error().Url(url).Msg("subscribe not supported").AsError());
3111
3103
  }
3112
- const rret = await this.interceptor.subscribe(sthis, url, callback, loader);
3104
+ const rret = await this.interceptor.subscribe(ctx, url, callback);
3113
3105
  if (rret.isErr()) {
3114
3106
  return import_cement14.Result.Err(rret.Err());
3115
3107
  }
@@ -3117,10 +3109,10 @@ var InterceptorGateway = class {
3117
3109
  if (ret.stop && ret.value) {
3118
3110
  return ret.value;
3119
3111
  }
3120
- return this.innerGW.subscribe(sthis, ret.op.url, ret.op.callback, loader);
3112
+ return this.innerGW.subscribe(ctx, ret.op.url, ret.op.callback);
3121
3113
  }
3122
- async delete(sthis, url, loader) {
3123
- const rret = await this.interceptor.delete(sthis, url, loader);
3114
+ async delete(ctx, url) {
3115
+ const rret = await this.interceptor.delete(ctx, url);
3124
3116
  if (rret.isErr()) {
3125
3117
  return import_cement14.Result.Err(rret.Err());
3126
3118
  }
@@ -3128,10 +3120,10 @@ var InterceptorGateway = class {
3128
3120
  if (ret.stop && ret.value) {
3129
3121
  return ret.value;
3130
3122
  }
3131
- return this.innerGW.delete(sthis, url, loader);
3123
+ return this.innerGW.delete(ctx, url);
3132
3124
  }
3133
- async getPlain(sthis, url, key, loader) {
3134
- return this.innerGW.getPlain(sthis, url, key, loader);
3125
+ async getPlain(ctx, url, key) {
3126
+ return this.innerGW.getPlain(ctx, url, key);
3135
3127
  }
3136
3128
  };
3137
3129
 
@@ -3177,7 +3169,7 @@ var BaseStoreImpl = class {
3177
3169
  async start() {
3178
3170
  this.logger.Debug().Str("storeType", this.storeType).Msg("starting-gateway-pre");
3179
3171
  this._url = this._url.build().setParam("store" /* STORE */, this.storeType).URI();
3180
- const res = await this.gateway.start(this.sthis, this._url, this.loader);
3172
+ const res = await this.gateway.start({ loader: this.loader }, this._url);
3181
3173
  if (res.isErr()) {
3182
3174
  this.logger.Error().Result("gw-start", res).Msg("started-gateway");
3183
3175
  return res;
@@ -3242,18 +3234,13 @@ var MetaStoreImpl = class extends BaseStoreImpl {
3242
3234
  ) {
3243
3235
  this.onStarted(async () => {
3244
3236
  this.logger.Debug().Str("url", this.url().toString()).Msg("Subscribing to the gateway");
3245
- opts.gateway.subscribe?.(
3246
- this.sthis,
3247
- this.url(),
3248
- async ({ payload: dbMetas }) => {
3249
- this.logger.Debug().Msg("Received message from gateway");
3250
- await Promise.all(
3251
- dbMetas.map((dbMeta) => this.loader.taskManager?.handleEvent(dbMeta.eventCid, dbMeta.parents, dbMeta.dbMeta))
3252
- );
3253
- this.updateParentsFromDbMetas(dbMetas);
3254
- },
3255
- this.loader
3256
- );
3237
+ opts.gateway.subscribe({ loader: this.loader }, this.url(), async ({ payload: dbMetas }) => {
3238
+ this.logger.Debug().Msg("Received message from gateway");
3239
+ await Promise.all(
3240
+ dbMetas.map((dbMeta) => this.loader.taskManager?.handleEvent(dbMeta.eventCid, dbMeta.parents, dbMeta.dbMeta))
3241
+ );
3242
+ this.updateParentsFromDbMetas(dbMetas);
3243
+ });
3257
3244
  });
3258
3245
  }
3259
3246
  }
@@ -3274,11 +3261,11 @@ var MetaStoreImpl = class extends BaseStoreImpl {
3274
3261
  // }
3275
3262
  async load() {
3276
3263
  const branch = "main";
3277
- const url = await this.gateway.buildUrl(this.sthis, this.url(), branch, this.loader);
3264
+ const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), branch);
3278
3265
  if (url.isErr()) {
3279
3266
  throw this.logger.Error().Result("buildUrl", url).Str("branch", branch).Msg("got error from gateway.buildUrl").AsError();
3280
3267
  }
3281
- const rfpEnv = await this.gateway.get(this.sthis, url.Ok(), this.loader);
3268
+ const rfpEnv = await this.gateway.get({ loader: this.loader }, url.Ok());
3282
3269
  if (rfpEnv.isErr()) {
3283
3270
  if (isNotFoundError(rfpEnv)) {
3284
3271
  return void 0;
@@ -3293,33 +3280,28 @@ var MetaStoreImpl = class extends BaseStoreImpl {
3293
3280
  async save(meta, branch) {
3294
3281
  branch = branch || "main";
3295
3282
  this.logger.Debug().Str("branch", branch).Any("meta", meta).Msg("saving meta");
3296
- const url = await this.gateway.buildUrl(this.sthis, this.url(), branch, this.loader);
3283
+ const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), branch);
3297
3284
  if (url.isErr()) {
3298
3285
  throw this.logger.Error().Err(url.Err()).Str("branch", branch).Msg("got error from gateway.buildUrl").AsError();
3299
3286
  }
3300
3287
  const dbMetaEvent = await createDbMetaEvent(this.sthis, meta, this.parents);
3301
- const res = await this.gateway.put(
3302
- this.sthis,
3303
- url.Ok(),
3304
- {
3305
- type: "meta",
3306
- payload: [dbMetaEvent]
3307
- },
3308
- this.loader
3309
- );
3288
+ const res = await this.gateway.put({ loader: this.loader }, url.Ok(), {
3289
+ type: "meta",
3290
+ payload: [dbMetaEvent]
3291
+ });
3310
3292
  if (res.isErr()) {
3311
3293
  throw this.logger.Error().Err(res.Err()).Msg("got error from gateway.put").AsError();
3312
3294
  }
3313
3295
  return res;
3314
3296
  }
3315
3297
  async close() {
3316
- await this.gateway.close(this.sthis, this.url(), this.loader);
3298
+ await this.gateway.close({ loader: this.loader }, this.url());
3317
3299
  this._onClosed.forEach((fn) => fn());
3318
3300
  return import_cement15.Result.Ok(void 0);
3319
3301
  }
3320
3302
  async destroy() {
3321
3303
  this.logger.Debug().Msg("destroy");
3322
- return this.gateway.destroy(this.sthis, this.url(), this.loader);
3304
+ return this.gateway.destroy({ loader: this.loader }, this.url());
3323
3305
  }
3324
3306
  };
3325
3307
  var DataStoreImpl = class extends BaseStoreImpl {
@@ -3329,11 +3311,11 @@ var DataStoreImpl = class extends BaseStoreImpl {
3329
3311
  }
3330
3312
  async load(cid) {
3331
3313
  this.logger.Debug().Any("cid", cid).Msg("loading");
3332
- const url = await this.gateway.buildUrl(this.sthis, this.url(), cid.toString(), this.loader);
3314
+ const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), cid.toString());
3333
3315
  if (url.isErr()) {
3334
3316
  throw this.logger.Error().Err(url.Err()).Str("cid", cid.toString()).Msg("got error from gateway.buildUrl").AsError();
3335
3317
  }
3336
- const res = await this.gateway.get(this.sthis, url.Ok(), this.loader);
3318
+ const res = await this.gateway.get({ loader: this.loader }, url.Ok());
3337
3319
  if (res.isErr()) {
3338
3320
  throw res.Err();
3339
3321
  }
@@ -3350,7 +3332,7 @@ var DataStoreImpl = class extends BaseStoreImpl {
3350
3332
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3351
3333
  async save(car, opts) {
3352
3334
  this.logger.Debug().Any("cid", car.cid.toString()).Msg("saving");
3353
- const url = await this.gateway.buildUrl(this.sthis, this.url(), car.cid.toString(), this.loader);
3335
+ const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), car.cid.toString());
3354
3336
  if (url.isErr()) {
3355
3337
  throw this.logger.Error().Err(url.Err()).Ref("cid", car.cid).Msg("got error from gateway.buildUrl").AsError();
3356
3338
  }
@@ -3369,27 +3351,27 @@ var DataStoreImpl = class extends BaseStoreImpl {
3369
3351
  if (fpMsg.isErr()) {
3370
3352
  throw this.logger.Error().Err(fpMsg).Msg("got error from FPMsg2Car").AsError();
3371
3353
  }
3372
- const res = await this.gateway.put(this.sthis, url.Ok(), fpMsg.Ok(), this.loader);
3354
+ const res = await this.gateway.put({ loader: this.loader }, url.Ok(), fpMsg.Ok());
3373
3355
  if (res.isErr()) {
3374
3356
  throw this.logger.Error().Err(res.Err()).Msg("got error from gateway.put").AsError();
3375
3357
  }
3376
3358
  return res.Ok();
3377
3359
  }
3378
3360
  async remove(cid) {
3379
- const url = await this.gateway.buildUrl(this.sthis, this.url(), cid.toString(), this.loader);
3361
+ const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), cid.toString());
3380
3362
  if (url.isErr()) {
3381
3363
  return url;
3382
3364
  }
3383
- return this.gateway.delete(this.sthis, url.Ok(), this.loader);
3365
+ return this.gateway.delete({ loader: this.loader }, url.Ok());
3384
3366
  }
3385
3367
  async close() {
3386
- await this.gateway.close(this.sthis, this.url(), this.loader);
3368
+ await this.gateway.close({ loader: this.loader }, this.url());
3387
3369
  this._onClosed.forEach((fn) => fn());
3388
3370
  return import_cement15.Result.Ok(void 0);
3389
3371
  }
3390
3372
  destroy() {
3391
3373
  this.logger.Debug().Msg("destroy");
3392
- return this.gateway.destroy(this.sthis, this.url(), this.loader);
3374
+ return this.gateway.destroy({ loader: this.loader }, this.url());
3393
3375
  }
3394
3376
  };
3395
3377
  var WALStoreImpl = class extends BaseStoreImpl {
@@ -3545,11 +3527,11 @@ var WALStoreImpl = class extends BaseStoreImpl {
3545
3527
  }
3546
3528
  async load() {
3547
3529
  this.logger.Debug().Msg("loading");
3548
- const filepath = await this.gateway.buildUrl(this.sthis, this.url(), "main", this.loader);
3530
+ const filepath = await this.gateway.buildUrl({ loader: this.loader }, this.url(), "main");
3549
3531
  if (filepath.isErr()) {
3550
3532
  throw this.logger.Error().Err(filepath.Err()).Url(this.url()).Msg("error building url").AsError();
3551
3533
  }
3552
- const bytes = await this.gateway.get(this.sthis, filepath.Ok(), this.loader);
3534
+ const bytes = await this.gateway.get({ loader: this.loader }, filepath.Ok());
3553
3535
  if (bytes.isErr()) {
3554
3536
  if (isNotFoundError(bytes)) {
3555
3537
  return void 0;
@@ -3562,64 +3544,59 @@ var WALStoreImpl = class extends BaseStoreImpl {
3562
3544
  return bytes.Ok().payload;
3563
3545
  }
3564
3546
  async save(state) {
3565
- const filepath = await this.gateway.buildUrl(this.sthis, this.url(), "main", this.loader);
3547
+ const filepath = await this.gateway.buildUrl({ loader: this.loader }, this.url(), "main");
3566
3548
  if (filepath.isErr()) {
3567
3549
  throw this.logger.Error().Err(filepath.Err()).Url(this.url()).Msg("error building url").AsError();
3568
3550
  }
3569
- const res = await this.gateway.put(
3570
- this.sthis,
3571
- filepath.Ok(),
3572
- {
3573
- type: "wal",
3574
- payload: state
3575
- },
3576
- this.loader
3577
- );
3551
+ const res = await this.gateway.put({ loader: this.loader }, filepath.Ok(), {
3552
+ type: "wal",
3553
+ payload: state
3554
+ });
3578
3555
  if (res.isErr()) {
3579
3556
  throw this.logger.Error().Err(res.Err()).Str("filePath", filepath.Ok().toString()).Msg("error saving").AsError();
3580
3557
  }
3581
3558
  }
3582
3559
  async close() {
3583
- await this.gateway.close(this.sthis, this.url(), this.loader);
3560
+ await this.gateway.close({ loader: this.loader }, this.url());
3584
3561
  this._onClosed.forEach((fn) => fn());
3585
3562
  return import_cement15.Result.Ok(void 0);
3586
3563
  }
3587
3564
  destroy() {
3588
3565
  this.logger.Debug().Msg("destroy");
3589
- return this.gateway.destroy(this.sthis, this.url(), this.loader);
3566
+ return this.gateway.destroy({ loader: this.loader }, this.url());
3590
3567
  }
3591
3568
  };
3592
3569
 
3593
3570
  // src/blockstore/store-factory.ts
3594
3571
  var onceGateway = new import_cement16.KeyedResolvOnce();
3595
3572
  var gatewayInstances = new import_cement16.KeyedResolvOnce();
3596
- async function getStartedGateway(sthis, url) {
3573
+ async function getStartedGateway(ctx, url) {
3597
3574
  return onceGateway.get(url.toString()).once(async () => {
3598
3575
  const item = getGatewayFactoryItem(url.protocol);
3599
3576
  if (item) {
3600
3577
  const ret = {
3601
3578
  url,
3602
3579
  ...await gatewayInstances.get(url.protocol).once(async () => ({})),
3603
- gateway: await item.serdegateway(sthis)
3580
+ gateway: await item.serdegateway(ctx.loader.sthis)
3604
3581
  };
3605
- const res = await ret.gateway.start(sthis, url);
3582
+ const res = await ret.gateway.start(ctx, url);
3606
3583
  if (res.isErr()) {
3607
- return import_cement16.Result.Err(sthis.logger.Error().Result("start", res).Msg("start failed").AsError());
3584
+ return import_cement16.Result.Err(ctx.loader.sthis.logger.Error().Result("start", res).Msg("start failed").AsError());
3608
3585
  }
3609
3586
  ret.url = res.Ok();
3610
3587
  return import_cement16.Result.Ok(ret);
3611
3588
  }
3612
- return import_cement16.Result.Err(sthis.logger.Warn().Url(url).Msg("unsupported protocol").AsError());
3589
+ return import_cement16.Result.Err(ctx.loader.sthis.logger.Warn().Url(url).Msg("unsupported protocol").AsError());
3613
3590
  });
3614
3591
  }
3615
3592
  async function dataStoreFactory(sfi) {
3616
3593
  const storeUrl = sfi.url.build().setParam("store" /* STORE */, "data").URI();
3617
- const rgateway = await getStartedGateway(sfi.sthis, storeUrl);
3594
+ const rgateway = await getStartedGateway(sfi, storeUrl);
3618
3595
  if (rgateway.isErr()) {
3619
- throw sfi.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
3596
+ throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
3620
3597
  }
3621
3598
  const gateway = rgateway.Ok();
3622
- const store = new DataStoreImpl(sfi.sthis, gateway.url, {
3599
+ const store = new DataStoreImpl(sfi.loader.sthis, gateway.url, {
3623
3600
  gateway: gateway.gateway,
3624
3601
  gatewayInterceptor: sfi.gatewayInterceptor,
3625
3602
  loader: sfi.loader
@@ -3628,12 +3605,12 @@ async function dataStoreFactory(sfi) {
3628
3605
  }
3629
3606
  async function metaStoreFactory(sfi) {
3630
3607
  const storeUrl = sfi.url.build().setParam("store" /* STORE */, "meta").URI();
3631
- const rgateway = await getStartedGateway(sfi.sthis, storeUrl);
3608
+ const rgateway = await getStartedGateway(sfi, storeUrl);
3632
3609
  if (rgateway.isErr()) {
3633
- throw sfi.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
3610
+ throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
3634
3611
  }
3635
3612
  const gateway = rgateway.Ok();
3636
- const store = new MetaStoreImpl(sfi.sthis, gateway.url, {
3613
+ const store = new MetaStoreImpl(sfi.loader.sthis, gateway.url, {
3637
3614
  gateway: gateway.gateway,
3638
3615
  gatewayInterceptor: sfi.gatewayInterceptor,
3639
3616
  loader: sfi.loader
@@ -3642,12 +3619,12 @@ async function metaStoreFactory(sfi) {
3642
3619
  }
3643
3620
  async function WALStoreFactory(sfi) {
3644
3621
  const storeUrl = sfi.url.build().setParam("store" /* STORE */, "wal").URI();
3645
- const rgateway = await getStartedGateway(sfi.sthis, storeUrl);
3622
+ const rgateway = await getStartedGateway(sfi, storeUrl);
3646
3623
  if (rgateway.isErr()) {
3647
- throw sfi.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
3624
+ throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
3648
3625
  }
3649
3626
  const gateway = rgateway.Ok();
3650
- const store = new WALStoreImpl(sfi.sthis, gateway.url, {
3627
+ const store = new WALStoreImpl(sfi.loader.sthis, gateway.url, {
3651
3628
  gateway: gateway.gateway,
3652
3629
  gatewayInterceptor: sfi.gatewayInterceptor,
3653
3630
  loader: sfi.loader
@@ -3774,7 +3751,7 @@ var ConnectionBase = class {
3774
3751
  this.loader = loader;
3775
3752
  await this.onConnect();
3776
3753
  const metaUrl = this.url.build().defParam("store" /* STORE */, "meta").URI();
3777
- const rgateway = await getStartedGateway(loader.sthis, metaUrl);
3754
+ const rgateway = await getStartedGateway({ loader }, metaUrl);
3778
3755
  if (rgateway.isErr())
3779
3756
  throw this.logger.Error().Result("err", rgateway).Url(metaUrl).Msg("connectMeta: gateway is required").AsError();
3780
3757
  const dbName = metaUrl.getParam("name" /* NAME */);
@@ -3810,7 +3787,7 @@ var ConnectionBase = class {
3810
3787
  if (!loader) throw this.logger.Error().Msg("connectStorage: loader is required").AsError();
3811
3788
  this.loader = loader;
3812
3789
  const dataUrl = this.url.build().defParam("store" /* STORE */, "data").URI();
3813
- const rgateway = await getStartedGateway(loader.sthis, dataUrl);
3790
+ const rgateway = await getStartedGateway({ loader }, dataUrl);
3814
3791
  if (rgateway.isErr())
3815
3792
  throw this.logger.Error().Result("err", rgateway).Url(dataUrl).Msg("connectStorage: gateway is required").AsError();
3816
3793
  const name = dataUrl.getParam("name" /* NAME */);
@@ -4730,6 +4707,6 @@ __export(file_exports, {
4730
4707
 
4731
4708
  // src/version.ts
4732
4709
  var PACKAGE_VERSION = Object.keys({
4733
- "0.20.0-dev-preview-18": "xxxx"
4710
+ "0.20.0-dev-preview-19": "xxxx"
4734
4711
  })[0];
4735
4712
  //# sourceMappingURL=index.cjs.map