@fireproof/core 0.20.0-dev-preview-57 → 0.20.0-dev-preview-60
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 +125 -101
- package/index.cjs.map +1 -1
- package/index.d.cts +7 -4
- package/index.d.ts +7 -4
- package/index.js +47 -23
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +3 -3
- package/react/index.cjs +91 -91
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +13 -41
- package/react/index.d.ts +13 -41
- package/react/index.js +90 -90
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/fireproof/attachable.test.ts +1 -2
- package/tests/fireproof/crdt.test.ts +14 -4
- package/tests/react/use-fireproof-db-switch.test.tsx +91 -0
- package/tests/react/{useFireproof.test.tsx → use-fireproof.test.tsx} +92 -13
- package/tests/setup.file.ts +1 -0
- package/tests/setup.indexeddb.ts +9 -0
- package/tests/setup.memory.ts +2 -0
- package/tests/vitest.file.config.ts +14 -0
- package/tests/vitest.indexeddb.config.ts +37 -0
- package/tests/vitest.memory.config.ts +25 -0
package/index.cjs
CHANGED
@@ -68,6 +68,7 @@ __export(index_exports, {
|
|
68
68
|
ps: () => protocols_exports,
|
69
69
|
rt: () => runtime_exports,
|
70
70
|
runtime: () => runtime_exports,
|
71
|
+
setPresetEnv: () => setPresetEnv,
|
71
72
|
storeType2DataMetaWal: () => storeType2DataMetaWal,
|
72
73
|
throwFalsy: () => throwFalsy,
|
73
74
|
toSortedArray: () => toSortedArray,
|
@@ -186,15 +187,21 @@ var SuperThisImpl = class _SuperThisImpl {
|
|
186
187
|
});
|
187
188
|
}
|
188
189
|
};
|
189
|
-
function presetEnv() {
|
190
|
+
function presetEnv(ipreset) {
|
191
|
+
let preset = {};
|
192
|
+
if (ipreset instanceof Map) {
|
193
|
+
preset = Object.fromEntries(ipreset.entries());
|
194
|
+
} else if (typeof ipreset === "object" && ipreset !== null) {
|
195
|
+
preset = ipreset;
|
196
|
+
}
|
190
197
|
const penv = new Map([
|
191
198
|
// ["FP_DEBUG", "xxx"],
|
192
199
|
// ["FP_ENV", "development"],
|
193
200
|
...Array.from(
|
194
|
-
Object.entries(
|
195
|
-
|
196
|
-
|
197
|
-
)
|
201
|
+
Object.entries({
|
202
|
+
...setPresetEnv({}),
|
203
|
+
...preset
|
204
|
+
})
|
198
205
|
)
|
199
206
|
// .map(([k, v]) => [k, v as string])
|
200
207
|
]);
|
@@ -231,7 +238,7 @@ function onSuperThis(fn) {
|
|
231
238
|
function ensureSuperThis(osthis) {
|
232
239
|
const env = (0, import_cement.envFactory)({
|
233
240
|
symbol: osthis?.env?.symbol || "FP_ENV",
|
234
|
-
presetEnv: osthis?.env?.presetEnv
|
241
|
+
presetEnv: presetEnv(osthis?.env?.presetEnv)
|
235
242
|
});
|
236
243
|
const ret = new SuperThisImpl({
|
237
244
|
logger: osthis?.logger || globalLogger(),
|
@@ -497,6 +504,14 @@ function ensureURIDefaults(sthis, name, curi, uri, store, ctx) {
|
|
497
504
|
}
|
498
505
|
return ret.URI();
|
499
506
|
}
|
507
|
+
function setPresetEnv(o, symbol = "FP_PRESET_ENV") {
|
508
|
+
const key = Symbol.for(symbol);
|
509
|
+
const env = globalThis[key] ?? {};
|
510
|
+
for (const [k, v] of Object.entries(o)) {
|
511
|
+
env[k] = v;
|
512
|
+
}
|
513
|
+
return env;
|
514
|
+
}
|
500
515
|
|
501
516
|
// src/write-queue.ts
|
502
517
|
var import_cement2 = require("@adviser/cement");
|
@@ -1889,7 +1904,7 @@ var Index = class {
|
|
1889
1904
|
this.mapFnString = "";
|
1890
1905
|
this.byKey = new IndexTree();
|
1891
1906
|
this.byId = new IndexTree();
|
1892
|
-
this.includeDocsDefault =
|
1907
|
+
this.includeDocsDefault = true;
|
1893
1908
|
this.logger = ensureLogger(sthis, "Index");
|
1894
1909
|
this.blockstore = crdt.indexBlockstore;
|
1895
1910
|
this.crdt = crdt;
|
@@ -5283,7 +5298,7 @@ __export(runtime_exports, {
|
|
5283
5298
|
keysByFingerprint: () => keysByFingerprint,
|
5284
5299
|
mf: () => wait_pr_multiformats_exports,
|
5285
5300
|
registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
|
5286
|
-
runtimeFn: () =>
|
5301
|
+
runtimeFn: () => import_cement28.runtimeFn,
|
5287
5302
|
sts: () => sts_service_exports,
|
5288
5303
|
toKeyWithFingerPrint: () => toKeyWithFingerPrint
|
5289
5304
|
});
|
@@ -5335,7 +5350,7 @@ var SessionTokenService = class _SessionTokenService {
|
|
5335
5350
|
}
|
5336
5351
|
};
|
5337
5352
|
}
|
5338
|
-
static async createFromEnv(sp = {}
|
5353
|
+
static async createFromEnv(sthis, sp = {}) {
|
5339
5354
|
let envToken = sthis.env.get(sp.privateEnvKey ?? envKeyDefaults.SECRET);
|
5340
5355
|
if (!envToken) {
|
5341
5356
|
envToken = sthis.env.get(sp.publicEnvKey ?? envKeyDefaults.PUBLIC);
|
@@ -5394,7 +5409,7 @@ var SessionTokenService = class _SessionTokenService {
|
|
5394
5409
|
};
|
5395
5410
|
|
5396
5411
|
// src/runtime/index.ts
|
5397
|
-
var
|
5412
|
+
var import_cement28 = require("@adviser/cement");
|
5398
5413
|
|
5399
5414
|
// src/runtime/gateways/index.ts
|
5400
5415
|
var gateways_exports = {};
|
@@ -5423,7 +5438,7 @@ __export(gateway_exports2, {
|
|
5423
5438
|
registerFireproofCloudStoreProtocol: () => registerFireproofCloudStoreProtocol,
|
5424
5439
|
toCloud: () => toCloud
|
5425
5440
|
});
|
5426
|
-
var
|
5441
|
+
var import_cement27 = require("@adviser/cement");
|
5427
5442
|
|
5428
5443
|
// src/protocols/cloud/msg-types.ts
|
5429
5444
|
var VERSION = "FP-MSG-1.0";
|
@@ -5745,6 +5760,14 @@ function toHttpProtocol(uri) {
|
|
5745
5760
|
}
|
5746
5761
|
return toFix.URI();
|
5747
5762
|
}
|
5763
|
+
function ensurePath(uri, fp) {
|
5764
|
+
const path = uri.pathname.replace(/\/$/, "").replace(/^\//, "");
|
5765
|
+
const buri = uri.build();
|
5766
|
+
if (path === "") {
|
5767
|
+
buri.appendRelative(fp);
|
5768
|
+
}
|
5769
|
+
return buri.toString();
|
5770
|
+
}
|
5748
5771
|
var HttpConnection = class extends MsgRawConnectionBase {
|
5749
5772
|
constructor(sthis, uris, msgP, exGestalt) {
|
5750
5773
|
super(sthis, exGestalt);
|
@@ -5833,7 +5856,7 @@ var HttpConnection = class extends MsgRawConnectionBase {
|
|
5833
5856
|
const rRes = await (0, import_cement23.exception2Result)(
|
5834
5857
|
() => timeout(
|
5835
5858
|
this.msgP.timeout,
|
5836
|
-
fetch(url.cleaned
|
5859
|
+
fetch(ensurePath(url.cleaned, "fp"), {
|
5837
5860
|
method: "PUT",
|
5838
5861
|
headers: headers.AsHeaderInit(),
|
5839
5862
|
body: rReqBody.Ok()
|
@@ -5854,7 +5877,7 @@ var HttpConnection = class extends MsgRawConnectionBase {
|
|
5854
5877
|
this,
|
5855
5878
|
req,
|
5856
5879
|
this.logger.Error().Any(url).Str("status", res.status.toString()).Str("statusText", res.statusText).Msg("HTTP Error").AsError(),
|
5857
|
-
await res.text()
|
5880
|
+
await res.text().catch(() => "no body")
|
5858
5881
|
)
|
5859
5882
|
);
|
5860
5883
|
}
|
@@ -6189,11 +6212,12 @@ var Msger = class _Msger {
|
|
6189
6212
|
static async openWS(sthis, url, msgP, exGestalt) {
|
6190
6213
|
let ws;
|
6191
6214
|
url = url.build().setParam("random", sthis.nextId().str).URI();
|
6215
|
+
const wsUrl = ensurePath(url, "ws");
|
6192
6216
|
if ((0, import_cement25.runtimeFn)().isNodeIsh) {
|
6193
6217
|
const { WebSocket: WebSocket2 } = await import("ws");
|
6194
|
-
ws = new WebSocket2(
|
6218
|
+
ws = new WebSocket2(wsUrl);
|
6195
6219
|
} else {
|
6196
|
-
ws = new WebSocket(
|
6220
|
+
ws = new WebSocket(wsUrl);
|
6197
6221
|
}
|
6198
6222
|
return import_cement25.Result.Ok(new WSConnection(sthis, ws, msgP, exGestalt));
|
6199
6223
|
}
|
@@ -6295,14 +6319,13 @@ function buildResDelData(msgCtx, req, ctx) {
|
|
6295
6319
|
}
|
6296
6320
|
|
6297
6321
|
// src/protocols/cloud/msg-types-meta.ts
|
6298
|
-
var import_cement26 = require("@adviser/cement");
|
6299
6322
|
function buildReqPutMeta(sthis, auth, signedUrlParams, meta, gwCtx) {
|
6300
6323
|
return {
|
6301
6324
|
auth,
|
6302
6325
|
tid: sthis.nextId().str,
|
6303
6326
|
type: "reqPutMeta",
|
6304
6327
|
...gwCtx,
|
6305
|
-
version:
|
6328
|
+
version: VERSION,
|
6306
6329
|
methodParams: {
|
6307
6330
|
method: "PUT",
|
6308
6331
|
store: "meta"
|
@@ -6325,7 +6348,7 @@ function buildResPutMeta(_msgCtx, req, meta, signedUrl) {
|
|
6325
6348
|
tenant: req.tenant,
|
6326
6349
|
type: "resPutMeta",
|
6327
6350
|
signedUrl,
|
6328
|
-
version:
|
6351
|
+
version: VERSION
|
6329
6352
|
};
|
6330
6353
|
}
|
6331
6354
|
function MsgIsResPutMeta(qs) {
|
@@ -6340,7 +6363,7 @@ function buildBindGetMeta(sthis, auth, params, gwCtx) {
|
|
6340
6363
|
tid: sthis.nextId().str,
|
6341
6364
|
...gwCtx,
|
6342
6365
|
type: "bindGetMeta",
|
6343
|
-
version:
|
6366
|
+
version: VERSION,
|
6344
6367
|
params
|
6345
6368
|
};
|
6346
6369
|
}
|
@@ -6355,7 +6378,7 @@ function buildEventGetMeta(_msgCtx, req, meta, gwCtx, signedUrl) {
|
|
6355
6378
|
type: "eventGetMeta",
|
6356
6379
|
params: req.params,
|
6357
6380
|
methodParams: { method: "GET", store: "meta" },
|
6358
|
-
version:
|
6381
|
+
version: VERSION
|
6359
6382
|
};
|
6360
6383
|
}
|
6361
6384
|
function MsgIsEventGetMeta(qs) {
|
@@ -6370,7 +6393,7 @@ function buildReqDelMeta(sthis, auth, params, gwCtx, meta) {
|
|
6370
6393
|
params,
|
6371
6394
|
meta,
|
6372
6395
|
type: "reqDelMeta",
|
6373
|
-
version:
|
6396
|
+
version: VERSION
|
6374
6397
|
// params: signedUrlParams,
|
6375
6398
|
};
|
6376
6399
|
}
|
@@ -6388,7 +6411,7 @@ function buildResDelMeta(req, params, signedUrl) {
|
|
6388
6411
|
tenant: req.tenant,
|
6389
6412
|
type: "resDelMeta",
|
6390
6413
|
// key: req.key,
|
6391
|
-
version:
|
6414
|
+
version: VERSION
|
6392
6415
|
};
|
6393
6416
|
}
|
6394
6417
|
function MsgIsResDelMeta(qs) {
|
@@ -6396,7 +6419,7 @@ function MsgIsResDelMeta(qs) {
|
|
6396
6419
|
}
|
6397
6420
|
|
6398
6421
|
// src/runtime/meta-key-hack.ts
|
6399
|
-
var
|
6422
|
+
var import_cement26 = require("@adviser/cement");
|
6400
6423
|
function fromV1toV2SerializedMetaKey(v1s, keys = []) {
|
6401
6424
|
const res = v1s.reduce(
|
6402
6425
|
(acc, v1) => {
|
@@ -6449,7 +6472,7 @@ function toV2SerializedMetaKey(or) {
|
|
6449
6472
|
async function V2SerializedMetaKeyExtractKey(ctx, v2) {
|
6450
6473
|
const kb = await ctx.loader.keyBag();
|
6451
6474
|
if (!kb) {
|
6452
|
-
return Promise.resolve(
|
6475
|
+
return Promise.resolve(import_cement26.Result.Err(new Error("missing keybag")));
|
6453
6476
|
}
|
6454
6477
|
const dataUrl = await ctx.loader.attachedStores.local().active.car.url();
|
6455
6478
|
const keyName = dataUrl.getParam(PARAM.STORE_KEY);
|
@@ -6468,19 +6491,19 @@ async function V2SerializedMetaKeyExtractKey(ctx, v2) {
|
|
6468
6491
|
}
|
6469
6492
|
}
|
6470
6493
|
}
|
6471
|
-
return Promise.resolve(
|
6494
|
+
return Promise.resolve(import_cement26.Result.Ok(v2.metas));
|
6472
6495
|
}
|
6473
6496
|
async function decodeAsToSerializedMeta(ctx, raw2) {
|
6474
|
-
const rJsObj = (0,
|
6497
|
+
const rJsObj = (0, import_cement26.exception2Result)(() => JSON.parse(ctx.loader.sthis.txt.decode(raw2)));
|
6475
6498
|
if (rJsObj.isErr()) {
|
6476
|
-
return
|
6499
|
+
return import_cement26.Result.Err(rJsObj);
|
6477
6500
|
}
|
6478
6501
|
const v2 = toV2SerializedMetaKey(rJsObj.unwrap());
|
6479
6502
|
const metas = await V2SerializedMetaKeyExtractKey(ctx, v2);
|
6480
6503
|
if (metas.isErr()) {
|
6481
|
-
return
|
6504
|
+
return import_cement26.Result.Err(metas);
|
6482
6505
|
}
|
6483
|
-
return
|
6506
|
+
return import_cement26.Result.Ok({
|
6484
6507
|
metas: metas.Ok(),
|
6485
6508
|
keys: v2.keys
|
6486
6509
|
});
|
@@ -6494,13 +6517,13 @@ function addKeyToDbMetaDecoder(ctx) {
|
|
6494
6517
|
meta: async (sthis, raw2) => {
|
6495
6518
|
const r = await decodeAsToSerializedMeta(ctx, raw2);
|
6496
6519
|
if (r.isErr()) {
|
6497
|
-
return Promise.resolve(
|
6520
|
+
return Promise.resolve(import_cement26.Result.Err(r));
|
6498
6521
|
}
|
6499
6522
|
if (lastDecodedMetas.length > 2) {
|
6500
6523
|
lastDecodedMetas.shift();
|
6501
6524
|
}
|
6502
6525
|
lastDecodedMetas.push(r.Ok());
|
6503
|
-
return Promise.resolve(
|
6526
|
+
return Promise.resolve(import_cement26.Result.Ok(r.Ok().metas));
|
6504
6527
|
}
|
6505
6528
|
}
|
6506
6529
|
};
|
@@ -6509,15 +6532,15 @@ async function wrapEncode(ctx, payload, fn) {
|
|
6509
6532
|
const carStore = ctx.loader.attachedStores.local().active.car;
|
6510
6533
|
const kb = await ctx.loader.keyBag();
|
6511
6534
|
if (!kb) {
|
6512
|
-
return Promise.resolve(
|
6535
|
+
return Promise.resolve(import_cement26.Result.Err(new Error("missing keybag")));
|
6513
6536
|
}
|
6514
6537
|
const keyName = carStore.url().getParam(PARAM.STORE_KEY) ?? "";
|
6515
6538
|
const rKex = await kb.getNamedKey(keyName);
|
6516
6539
|
if (rKex.isErr()) {
|
6517
|
-
return Promise.resolve(
|
6540
|
+
return Promise.resolve(import_cement26.Result.Err(rKex.Err()));
|
6518
6541
|
}
|
6519
6542
|
const keyMaterials = await rKex.Ok().asKeysItem().then((i) => Object.values(i.keys).map((i2) => i2.key));
|
6520
|
-
return Promise.resolve(
|
6543
|
+
return Promise.resolve(import_cement26.Result.Ok(fn(payload, keyMaterials)));
|
6521
6544
|
}
|
6522
6545
|
function encodeAsV1SerializedMetaKey(ctx, payload) {
|
6523
6546
|
return wrapEncode(ctx, payload, (payload2, keyM) => payload2.map((p) => ({ ...p, key: keyM })));
|
@@ -6546,15 +6569,15 @@ function addKeyToDbMetaEncoder(ctx, version) {
|
|
6546
6569
|
obj = await encodeAsV2SerializedMetaKey(ctx, payload);
|
6547
6570
|
break;
|
6548
6571
|
default:
|
6549
|
-
return Promise.resolve(
|
6572
|
+
return Promise.resolve(import_cement26.Result.Err(`unknown version:[${version}]`));
|
6550
6573
|
}
|
6551
6574
|
if (obj.isErr()) {
|
6552
|
-
return Promise.resolve(
|
6575
|
+
return Promise.resolve(import_cement26.Result.Err(obj));
|
6553
6576
|
}
|
6554
6577
|
try {
|
6555
|
-
return Promise.resolve(
|
6578
|
+
return Promise.resolve(import_cement26.Result.Ok(sthis.txt.encode(JSON.stringify(obj.Ok()))));
|
6556
6579
|
} catch (e) {
|
6557
|
-
return Promise.resolve(
|
6580
|
+
return Promise.resolve(import_cement26.Result.Err(e));
|
6558
6581
|
}
|
6559
6582
|
}
|
6560
6583
|
}
|
@@ -6598,7 +6621,7 @@ var AddKeyToDbMetaGateway = class {
|
|
6598
6621
|
};
|
6599
6622
|
|
6600
6623
|
// src/runtime/gateways/cloud/gateway.ts
|
6601
|
-
var
|
6624
|
+
var VERSION2 = "v0.1-fp-cloud";
|
6602
6625
|
var BaseGateway = class {
|
6603
6626
|
constructor(sthis, module2) {
|
6604
6627
|
this.sthis = sthis;
|
@@ -6606,12 +6629,12 @@ var BaseGateway = class {
|
|
6606
6629
|
}
|
6607
6630
|
async buildReqSignedUrl(type, method, store, uri, conn) {
|
6608
6631
|
const rParams = uri.getParamsResult({
|
6609
|
-
key:
|
6610
|
-
store:
|
6611
|
-
path:
|
6612
|
-
tenant:
|
6613
|
-
name:
|
6614
|
-
index:
|
6632
|
+
key: import_cement27.param.REQUIRED,
|
6633
|
+
store: import_cement27.param.REQUIRED,
|
6634
|
+
path: import_cement27.param.OPTIONAL,
|
6635
|
+
tenant: import_cement27.param.REQUIRED,
|
6636
|
+
name: import_cement27.param.REQUIRED,
|
6637
|
+
index: import_cement27.param.OPTIONAL
|
6615
6638
|
});
|
6616
6639
|
if (rParams.isErr()) {
|
6617
6640
|
return buildErrorMsg(this, {}, rParams.Err());
|
@@ -6642,7 +6665,7 @@ var BaseGateway = class {
|
|
6642
6665
|
...params,
|
6643
6666
|
key: params.key
|
6644
6667
|
},
|
6645
|
-
version:
|
6668
|
+
version: VERSION2
|
6646
6669
|
};
|
6647
6670
|
}
|
6648
6671
|
async getReqSignedUrl(type, method, store, waitForFn, uri, conn) {
|
@@ -6654,7 +6677,7 @@ var BaseGateway = class {
|
|
6654
6677
|
}
|
6655
6678
|
async putObject(uri, uploadUrl, body, conn) {
|
6656
6679
|
this.logger.Debug().Any("url", { uploadUrl, uri }).Msg("put-fetch-url");
|
6657
|
-
const rUpload = await (0,
|
6680
|
+
const rUpload = await (0, import_cement27.exception2Result)(async () => fetch(uploadUrl, { method: "PUT", body }));
|
6658
6681
|
if (rUpload.isErr()) {
|
6659
6682
|
return this.logger.Error().Url(uploadUrl, "uploadUrl").Err(rUpload).Msg("Error in put fetch").ResultError();
|
6660
6683
|
}
|
@@ -6664,39 +6687,39 @@ var BaseGateway = class {
|
|
6664
6687
|
if (uri.getParam("testMode")) {
|
6665
6688
|
conn.citem.trackPuts.add(uri.toString());
|
6666
6689
|
}
|
6667
|
-
return
|
6690
|
+
return import_cement27.Result.Ok(void 0);
|
6668
6691
|
}
|
6669
6692
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
6670
6693
|
async getObject(uri, downloadUrl, _conn) {
|
6671
6694
|
this.logger.Debug().Any("url", { downloadUrl, uri }).Msg("get-fetch-url");
|
6672
|
-
const rDownload = await (0,
|
6695
|
+
const rDownload = await (0, import_cement27.exception2Result)(async () => fetch(downloadUrl.toString(), { method: "GET" }));
|
6673
6696
|
if (rDownload.isErr()) {
|
6674
6697
|
return this.logger.Error().Url(downloadUrl, "uploadUrl").Err(rDownload).Msg("Error in get downloadUrl").ResultError();
|
6675
6698
|
}
|
6676
6699
|
const download = rDownload.Ok();
|
6677
6700
|
if (!download.ok) {
|
6678
6701
|
if (download.status === 404) {
|
6679
|
-
return
|
6702
|
+
return import_cement27.Result.Err(new NotFoundError("Not found"));
|
6680
6703
|
}
|
6681
6704
|
return this.logger.Error().Url(downloadUrl, "uploadUrl").Err(rDownload).Msg("Error in get fetch").ResultError();
|
6682
6705
|
}
|
6683
|
-
return
|
6706
|
+
return import_cement27.Result.Ok((0, import_cement27.to_uint8)(await download.arrayBuffer()));
|
6684
6707
|
}
|
6685
6708
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
6686
6709
|
async delObject(uri, deleteUrl, _conn) {
|
6687
6710
|
this.logger.Debug().Any("url", { deleteUrl, uri }).Msg("get-fetch-url");
|
6688
|
-
const rDelete = await (0,
|
6711
|
+
const rDelete = await (0, import_cement27.exception2Result)(async () => fetch(deleteUrl.toString(), { method: "DELETE" }));
|
6689
6712
|
if (rDelete.isErr()) {
|
6690
6713
|
return this.logger.Error().Url(deleteUrl, "deleteUrl").Err(rDelete).Msg("Error in get deleteURL").ResultError();
|
6691
6714
|
}
|
6692
6715
|
const download = rDelete.Ok();
|
6693
6716
|
if (!download.ok) {
|
6694
6717
|
if (download.status === 404) {
|
6695
|
-
return
|
6718
|
+
return import_cement27.Result.Err(new NotFoundError("Not found"));
|
6696
6719
|
}
|
6697
6720
|
return this.logger.Error().Url(deleteUrl, "deleteUrl").Err(rDelete).Msg("Error in del fetch").ResultError();
|
6698
6721
|
}
|
6699
|
-
return
|
6722
|
+
return import_cement27.Result.Ok(void 0);
|
6700
6723
|
}
|
6701
6724
|
};
|
6702
6725
|
var DataGateway = class extends BaseGateway {
|
@@ -6739,15 +6762,15 @@ var DataGateway = class extends BaseGateway {
|
|
6739
6762
|
};
|
6740
6763
|
function getGwCtx(conn, uri) {
|
6741
6764
|
const rParams = uri.getParamsResult({
|
6742
|
-
tid:
|
6743
|
-
tenant:
|
6744
|
-
ledger:
|
6765
|
+
tid: import_cement27.param.OPTIONAL,
|
6766
|
+
tenant: import_cement27.param.REQUIRED,
|
6767
|
+
ledger: import_cement27.param.REQUIRED
|
6745
6768
|
});
|
6746
6769
|
if (rParams.isErr()) {
|
6747
|
-
return
|
6770
|
+
return import_cement27.Result.Err(rParams);
|
6748
6771
|
}
|
6749
6772
|
const r = rParams.Ok();
|
6750
|
-
return
|
6773
|
+
return import_cement27.Result.Ok({
|
6751
6774
|
tid: r.tid,
|
6752
6775
|
conn,
|
6753
6776
|
tenant: {
|
@@ -6767,11 +6790,11 @@ var MetaGateway = class extends BaseGateway {
|
|
6767
6790
|
}
|
6768
6791
|
const rGwCtx = getGwCtx(ctx.conn.conn.Ok().conn, uri);
|
6769
6792
|
if (rGwCtx.isErr()) {
|
6770
|
-
return
|
6793
|
+
return import_cement27.Result.Err(rGwCtx);
|
6771
6794
|
}
|
6772
6795
|
const rAuthType = await ctx.conn.conn.Ok().authType();
|
6773
6796
|
if (rAuthType.isErr()) {
|
6774
|
-
return
|
6797
|
+
return import_cement27.Result.Err(rAuthType);
|
6775
6798
|
}
|
6776
6799
|
const res = await ctx.conn.conn.Ok().request(buildBindGetMeta(ctx.loader.sthis, rAuthType.Ok(), reqSignedUrl.params, rGwCtx.Ok()), {
|
6777
6800
|
waitFor: MsgIsEventGetMeta
|
@@ -6782,9 +6805,9 @@ var MetaGateway = class extends BaseGateway {
|
|
6782
6805
|
const rV2Meta = await V2SerializedMetaKeyExtractKey(ctx, res.meta);
|
6783
6806
|
const rMeta = await decode2DbMetaEvents(ctx.loader.sthis, rV2Meta);
|
6784
6807
|
if (rMeta.isErr()) {
|
6785
|
-
return
|
6808
|
+
return import_cement27.Result.Err(rMeta);
|
6786
6809
|
}
|
6787
|
-
return
|
6810
|
+
return import_cement27.Result.Ok({
|
6788
6811
|
type: "meta",
|
6789
6812
|
payload: rMeta.Ok()
|
6790
6813
|
});
|
@@ -6797,11 +6820,11 @@ var MetaGateway = class extends BaseGateway {
|
|
6797
6820
|
}
|
6798
6821
|
const rGwCtx = getGwCtx(ctx.conn.conn.Ok().conn, uri);
|
6799
6822
|
if (rGwCtx.isErr()) {
|
6800
|
-
return
|
6823
|
+
return import_cement27.Result.Err(rGwCtx);
|
6801
6824
|
}
|
6802
6825
|
const rAuthType = await ctx.conn.conn.Ok().authType();
|
6803
6826
|
if (rAuthType.isErr()) {
|
6804
|
-
return
|
6827
|
+
return import_cement27.Result.Err(rAuthType);
|
6805
6828
|
}
|
6806
6829
|
const serializedMeta = await dbMetaEvent2Serialized(ctx.loader.sthis, meta.payload);
|
6807
6830
|
const rKeyedMeta = await encodeAsV2SerializedMetaKey(ctx, serializedMeta);
|
@@ -6815,7 +6838,7 @@ var MetaGateway = class extends BaseGateway {
|
|
6815
6838
|
if (MsgIsError(resMsg)) {
|
6816
6839
|
return this.logger.Error().Err(resMsg).Msg("Error in buildResSignedUrl").ResultError();
|
6817
6840
|
}
|
6818
|
-
return
|
6841
|
+
return import_cement27.Result.Ok(void 0);
|
6819
6842
|
}
|
6820
6843
|
async delete(ctx, uri) {
|
6821
6844
|
const reqSignedUrl = await this.getReqSignedUrl("reqDelMeta", "DELETE", "meta", MsgIsResDelData, uri, ctx.conn);
|
@@ -6824,11 +6847,11 @@ var MetaGateway = class extends BaseGateway {
|
|
6824
6847
|
}
|
6825
6848
|
const rGwCtx = getGwCtx(ctx.conn.conn.Ok().conn, uri);
|
6826
6849
|
if (rGwCtx.isErr()) {
|
6827
|
-
return
|
6850
|
+
return import_cement27.Result.Err(rGwCtx);
|
6828
6851
|
}
|
6829
6852
|
const rAuthType = await ctx.conn.conn.Ok().authType();
|
6830
6853
|
if (rAuthType.isErr()) {
|
6831
|
-
return
|
6854
|
+
return import_cement27.Result.Err(rAuthType);
|
6832
6855
|
}
|
6833
6856
|
const reqDelMeta = buildReqDelMeta(ctx.loader.sthis, rAuthType.Ok(), reqSignedUrl.params, rGwCtx.Ok());
|
6834
6857
|
const resMsg = await ctx.conn.conn.Ok().request(reqDelMeta, {
|
@@ -6837,7 +6860,7 @@ var MetaGateway = class extends BaseGateway {
|
|
6837
6860
|
if (MsgIsError(resMsg)) {
|
6838
6861
|
return this.logger.Error().Err(resMsg).Msg("Error in buildResSignedUrl").ResultError();
|
6839
6862
|
}
|
6840
|
-
return
|
6863
|
+
return import_cement27.Result.Ok(void 0);
|
6841
6864
|
}
|
6842
6865
|
};
|
6843
6866
|
var WALGateway = class extends BaseGateway {
|
@@ -6852,40 +6875,40 @@ var WALGateway = class extends BaseGateway {
|
|
6852
6875
|
name: 0
|
6853
6876
|
});
|
6854
6877
|
if (rKey.isErr()) {
|
6855
|
-
return
|
6878
|
+
return import_cement27.Result.Err(rKey.Err());
|
6856
6879
|
}
|
6857
6880
|
const { name, key } = rKey.Ok();
|
6858
|
-
return
|
6881
|
+
return import_cement27.Result.Ok(`${name}:${key}`);
|
6859
6882
|
}
|
6860
6883
|
async get(ctx, uri) {
|
6861
6884
|
const rKey = this.getWalKeyFromUri(uri);
|
6862
6885
|
if (rKey.isErr()) {
|
6863
|
-
return
|
6886
|
+
return import_cement27.Result.Err(rKey.Err());
|
6864
6887
|
}
|
6865
6888
|
const wal = this.wals.get(rKey.Ok());
|
6866
6889
|
if (!wal) {
|
6867
|
-
return
|
6890
|
+
return import_cement27.Result.Err(new NotFoundError("Not found"));
|
6868
6891
|
}
|
6869
|
-
return
|
6892
|
+
return import_cement27.Result.Ok(wal);
|
6870
6893
|
}
|
6871
6894
|
async put(ctx, uri, body) {
|
6872
6895
|
const rKey = this.getWalKeyFromUri(uri);
|
6873
6896
|
if (rKey.isErr()) {
|
6874
|
-
return
|
6897
|
+
return import_cement27.Result.Err(rKey.Err());
|
6875
6898
|
}
|
6876
6899
|
this.wals.set(rKey.Ok(), body);
|
6877
|
-
return
|
6900
|
+
return import_cement27.Result.Ok(void 0);
|
6878
6901
|
}
|
6879
6902
|
async delete(ctx, uri) {
|
6880
6903
|
const rKey = this.getWalKeyFromUri(uri);
|
6881
6904
|
if (rKey.isErr()) {
|
6882
|
-
return
|
6905
|
+
return import_cement27.Result.Err(rKey.Err());
|
6883
6906
|
}
|
6884
6907
|
this.wals.delete(rKey.Ok());
|
6885
|
-
return
|
6908
|
+
return import_cement27.Result.Ok(void 0);
|
6886
6909
|
}
|
6887
6910
|
};
|
6888
|
-
var storeTypedGateways = new
|
6911
|
+
var storeTypedGateways = new import_cement27.KeyedResolvOnce();
|
6889
6912
|
function getStoreTypeGateway(sthis, uri) {
|
6890
6913
|
const store = uri.getParam("store");
|
6891
6914
|
switch (store) {
|
@@ -6913,7 +6936,7 @@ var FireproofCloudGateway = class {
|
|
6913
6936
|
});
|
6914
6937
|
}
|
6915
6938
|
async buildUrl(ctx, baseUrl, key) {
|
6916
|
-
return
|
6939
|
+
return import_cement27.Result.Ok(baseUrl.build().setParam("key", key).URI());
|
6917
6940
|
}
|
6918
6941
|
async start(ctx, uri) {
|
6919
6942
|
await this.sthis.start();
|
@@ -6921,22 +6944,22 @@ var FireproofCloudGateway = class {
|
|
6921
6944
|
if (rName.isErr()) {
|
6922
6945
|
return this.logger.Error().Err(rName).Msg("name not found").ResultError();
|
6923
6946
|
}
|
6924
|
-
const ret = uri.build().defParam("version",
|
6947
|
+
const ret = uri.build().defParam("version", VERSION2);
|
6925
6948
|
ret.defParam("protocol", "wss");
|
6926
6949
|
const retURI = ret.URI();
|
6927
6950
|
const matchURI = connectionURI(retURI);
|
6928
6951
|
this.#connectionURIs.set(matchURI.toString(), {
|
6929
6952
|
uri: matchURI,
|
6930
6953
|
matchRes: matchURI.match(matchURI),
|
6931
|
-
connection: new
|
6954
|
+
connection: new import_cement27.ResolveOnce(),
|
6932
6955
|
trackPuts: /* @__PURE__ */ new Set()
|
6933
6956
|
});
|
6934
|
-
return
|
6957
|
+
return import_cement27.Result.Ok(retURI);
|
6935
6958
|
}
|
6936
6959
|
async get(ctx, uri) {
|
6937
6960
|
const conn = await this.getCloudConnectionItem(uri);
|
6938
6961
|
if (conn.conn.isErr()) {
|
6939
|
-
return
|
6962
|
+
return import_cement27.Result.Err(conn.conn);
|
6940
6963
|
}
|
6941
6964
|
const ret = await getStoreTypeGateway(ctx.loader.sthis, uri).get({ ...ctx, conn }, uri);
|
6942
6965
|
return ret;
|
@@ -6979,7 +7002,7 @@ var FireproofCloudGateway = class {
|
|
6979
7002
|
const rAuth = await conn.msgConnAuth();
|
6980
7003
|
await conn.close(rAuth.Ok());
|
6981
7004
|
this.#connectionURIs.delete(rConn.citem.uri.toString());
|
6982
|
-
return
|
7005
|
+
return import_cement27.Result.Ok(void 0);
|
6983
7006
|
}
|
6984
7007
|
// fireproof://localhost:1999/?name=test-public-api&protocol=ws&store=meta
|
6985
7008
|
async getCloudConnection(uri) {
|
@@ -7005,11 +7028,11 @@ var FireproofCloudGateway = class {
|
|
7005
7028
|
}
|
7006
7029
|
const conn = await bestMatch.connection.once(async () => {
|
7007
7030
|
const rParams = uri.getParamsResult({
|
7008
|
-
name:
|
7031
|
+
name: import_cement27.param.REQUIRED,
|
7009
7032
|
protocol: "https",
|
7010
|
-
store:
|
7011
|
-
storekey:
|
7012
|
-
tenant:
|
7033
|
+
store: import_cement27.param.REQUIRED,
|
7034
|
+
storekey: import_cement27.param.OPTIONAL,
|
7035
|
+
tenant: import_cement27.param.REQUIRED
|
7013
7036
|
});
|
7014
7037
|
if (rParams.isErr()) {
|
7015
7038
|
return this.logger.Error().Url(uri).Err(rParams).Msg("getCloudConnection:err").ResultError();
|
@@ -7017,16 +7040,16 @@ var FireproofCloudGateway = class {
|
|
7017
7040
|
const params = rParams.Ok();
|
7018
7041
|
const rAuth = await authTypeFromUri(this.logger, uri);
|
7019
7042
|
if (rAuth.isErr()) {
|
7020
|
-
return
|
7043
|
+
return import_cement27.Result.Err(rAuth);
|
7021
7044
|
}
|
7022
7045
|
const qOpen = buildReqOpen(this.sthis, rAuth.Ok(), {});
|
7023
7046
|
const cUrl = uri.build().protocol(params.protocol).cleanParams().URI();
|
7024
7047
|
return Msger.connect(this.sthis, rAuth.Ok(), cUrl, qOpen);
|
7025
7048
|
});
|
7026
7049
|
if (conn.isErr()) {
|
7027
|
-
return { conn:
|
7050
|
+
return { conn: import_cement27.Result.Err(conn), citem: bestMatch };
|
7028
7051
|
}
|
7029
|
-
return { conn:
|
7052
|
+
return { conn: import_cement27.Result.Ok(conn.Ok().attachAuth(() => authTypeFromUri(this.logger, uri))), citem: bestMatch };
|
7030
7053
|
}
|
7031
7054
|
// private notifySubscribers(data: Uint8Array, callbacks: ((msg: Uint8Array) => void)[] = []): void {
|
7032
7055
|
// for (const cb of callbacks) {
|
@@ -7039,28 +7062,28 @@ var FireproofCloudGateway = class {
|
|
7039
7062
|
// }
|
7040
7063
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
7041
7064
|
async subscribe(ctx, url, callback) {
|
7042
|
-
return
|
7065
|
+
return import_cement27.Result.Err(new Error("Not implemented"));
|
7043
7066
|
}
|
7044
7067
|
async destroy(ctx, uri) {
|
7045
7068
|
const item = await this.getCloudConnectionItem(uri);
|
7046
7069
|
if (item.conn.isErr()) {
|
7047
7070
|
return item.conn;
|
7048
7071
|
}
|
7049
|
-
await Promise.all(Array.from(item.citem.trackPuts).map(async (k) => this.delete(ctx,
|
7050
|
-
return
|
7072
|
+
await Promise.all(Array.from(item.citem.trackPuts).map(async (k) => this.delete(ctx, import_cement27.URI.from(k))));
|
7073
|
+
return import_cement27.Result.Ok(void 0);
|
7051
7074
|
}
|
7052
7075
|
async getPlain() {
|
7053
|
-
return
|
7076
|
+
return import_cement27.Result.Err(new Error("Not implemented"));
|
7054
7077
|
}
|
7055
7078
|
};
|
7056
|
-
var onceRegisterFireproofCloudStoreProtocol = new
|
7079
|
+
var onceRegisterFireproofCloudStoreProtocol = new import_cement27.KeyedResolvOnce();
|
7057
7080
|
function registerFireproofCloudStoreProtocol(protocol = "fpcloud:") {
|
7058
7081
|
return onceRegisterFireproofCloudStoreProtocol.get(protocol).once(() => {
|
7059
|
-
|
7082
|
+
import_cement27.URI.protocolHasHostpart(protocol);
|
7060
7083
|
return registerStoreProtocol({
|
7061
7084
|
protocol,
|
7062
7085
|
defaultURI() {
|
7063
|
-
return
|
7086
|
+
return import_cement27.URI.from("fpcloud://fireproof.cloud/");
|
7064
7087
|
},
|
7065
7088
|
serdegateway: async (sthis) => {
|
7066
7089
|
return new FireproofCloudGateway(sthis);
|
@@ -7070,7 +7093,7 @@ function registerFireproofCloudStoreProtocol(protocol = "fpcloud:") {
|
|
7070
7093
|
}
|
7071
7094
|
registerFireproofCloudStoreProtocol();
|
7072
7095
|
function toCloud(url) {
|
7073
|
-
const urlObj =
|
7096
|
+
const urlObj = import_cement27.URI.from(url);
|
7074
7097
|
if (urlObj.protocol !== "fpcloud:") {
|
7075
7098
|
throw new Error("url must have fireproof protocol");
|
7076
7099
|
}
|
@@ -7169,6 +7192,7 @@ __export(cloud_exports, {
|
|
7169
7192
|
coerceFPStoreTypes: () => coerceFPStoreTypes,
|
7170
7193
|
defaultGestalt: () => defaultGestalt,
|
7171
7194
|
defaultMsgParams: () => defaultMsgParams,
|
7195
|
+
ensurePath: () => ensurePath,
|
7172
7196
|
isAuthTypeFPCloud: () => isAuthTypeFPCloud,
|
7173
7197
|
isAuthTypeFPCloudJWK: () => isAuthTypeFPCloudJWK,
|
7174
7198
|
isProtocolCapabilities: () => isProtocolCapabilities,
|
@@ -7239,6 +7263,6 @@ function buildResDelWAL(msgCtx, req, ctx) {
|
|
7239
7263
|
|
7240
7264
|
// src/version.ts
|
7241
7265
|
var PACKAGE_VERSION = Object.keys({
|
7242
|
-
"0.20.0-dev-preview-
|
7266
|
+
"0.20.0-dev-preview-60": "xxxx"
|
7243
7267
|
})[0];
|
7244
7268
|
//# sourceMappingURL=index.cjs.map
|