@fireproof/core 0.19.111 → 0.19.112-dev-web
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/{chunk-OFGPKRCM.js → chunk-GZANCVTS.js} +3 -1
- package/chunk-GZANCVTS.js.map +1 -0
- package/{chunk-WS3YRPIA.js → chunk-LNFBDD6E.js} +4 -4
- package/chunk-LNFBDD6E.js.map +1 -0
- package/deno.json +1 -2
- package/{gateway-H7UD6TNB.js → gateway@skip-esm-O655UEIP.js} +3 -3
- package/gateway@skip-esm-O655UEIP.js.map +1 -0
- package/{gateway-5FCWPX5W.js → gateway@skip-iife-OZ2V32XH.js} +5 -5
- package/gateway@skip-iife-OZ2V32XH.js.map +1 -0
- package/index.cjs +32 -30
- package/index.cjs.map +1 -1
- package/index.global.js +417 -178
- package/index.global.js.map +1 -1
- package/index.js +11 -11
- package/index.js.map +1 -1
- package/{key-bag-file-WADZBHYG.js → key-bag-file-4TYN2H7F.js} +3 -3
- package/{key-bag-indexdb-PGVAI3FJ.js → key-bag-indexdb-JEOAS4WM.js} +3 -3
- package/{mem-filesystem-YPPJV7Q2.js → mem-filesystem@skip-iife-CJI7IIKV.js} +4 -4
- package/mem-filesystem@skip-iife-CJI7IIKV.js.map +1 -0
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/metafile-iife.json +1 -1
- package/{node-filesystem-INX4ZTHE.js → node-filesystem@skip-iife-O74VAABQ.js} +4 -4
- package/node-filesystem@skip-iife-O74VAABQ.js.map +1 -0
- package/package.json +15 -6
- package/tests/blockstore/keyed-crypto.test.ts +2 -2
- package/tests/blockstore/store.test.ts +3 -5
- package/tests/fireproof/all-gateway.test.ts +11 -9
- package/{utils-QO2HIWGI.js → utils-L7MUZUJX.js} +3 -3
- package/web/bundle-not-impl-UH74NK5L.js +5 -0
- package/web/bundle-not-impl-UH74NK5L.js.map +1 -0
- package/web/chunk-2DC5ZIR4.js +7 -0
- package/web/chunk-2DC5ZIR4.js.map +1 -0
- package/web/chunk-Q5W7UNMP.js +292 -0
- package/web/chunk-Q5W7UNMP.js.map +1 -0
- package/web/chunk-S4HRSKEO.js +75 -0
- package/web/chunk-S4HRSKEO.js.map +1 -0
- package/web/gateway@skip-esm-GI5PRACF.js +165 -0
- package/web/gateway@skip-esm-GI5PRACF.js.map +1 -0
- package/web/index.cjs +4138 -0
- package/web/index.cjs.map +1 -0
- package/web/index.d.cts +1139 -0
- package/web/index.d.ts +1139 -0
- package/web/index.js +3478 -0
- package/web/index.js.map +1 -0
- package/web/key-bag-file-4SJQGORQ.js +54 -0
- package/web/key-bag-file-4SJQGORQ.js.map +1 -0
- package/web/key-bag-indexdb-GSQOUUVQ.js +50 -0
- package/web/key-bag-indexdb-GSQOUUVQ.js.map +1 -0
- package/web/metafile-cjs.json +1 -0
- package/web/metafile-esm.json +1 -0
- package/web/utils-EFZJNXH5.js +14 -0
- package/web/utils-EFZJNXH5.js.map +1 -0
- package/chunk-OFGPKRCM.js.map +0 -1
- package/chunk-WS3YRPIA.js.map +0 -1
- package/gateway-5FCWPX5W.js.map +0 -1
- package/gateway-H7UD6TNB.js.map +0 -1
- package/mem-filesystem-YPPJV7Q2.js.map +0 -1
- package/node-filesystem-INX4ZTHE.js.map +0 -1
- /package/{key-bag-file-WADZBHYG.js.map → key-bag-file-4TYN2H7F.js.map} +0 -0
- /package/{key-bag-indexdb-PGVAI3FJ.js.map → key-bag-indexdb-JEOAS4WM.js.map} +0 -0
- /package/{utils-QO2HIWGI.js.map → utils-L7MUZUJX.js.map} +0 -0
@@ -1,9 +1,9 @@
|
|
1
1
|
import {
|
2
2
|
toArrayBuffer
|
3
|
-
} from "./chunk-
|
4
|
-
import "./chunk-
|
3
|
+
} from "./chunk-LNFBDD6E.js";
|
4
|
+
import "./chunk-GZANCVTS.js";
|
5
5
|
|
6
|
-
// src/runtime/gateways/file/node-filesystem.ts
|
6
|
+
// src/runtime/gateways/file/node-filesystem@skip-iife.ts
|
7
7
|
import { runtimeFn } from "@adviser/cement";
|
8
8
|
var NodeFileSystem = class {
|
9
9
|
async start() {
|
@@ -42,4 +42,4 @@ var NodeFileSystem = class {
|
|
42
42
|
export {
|
43
43
|
NodeFileSystem
|
44
44
|
};
|
45
|
-
//# sourceMappingURL=node-filesystem-
|
45
|
+
//# sourceMappingURL=node-filesystem@skip-iife-O74VAABQ.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/gateways/file/node-filesystem@skip-iife.ts"],"sourcesContent":["import type { PathLike, MakeDirectoryOptions, Stats, ObjectEncodingOptions } from \"node:fs\";\nimport type { mkdir, readdir, rm, copyFile, readFile, stat, unlink, writeFile } from \"node:fs/promises\";\nimport { toArrayBuffer } from \"./utils.js\";\nimport { SysFileSystem } from \"../../../types.js\";\nimport { runtimeFn } from \"@adviser/cement\";\n\nexport class NodeFileSystem implements SysFileSystem {\n fs?: {\n mkdir: typeof mkdir;\n readdir: typeof readdir;\n rm: typeof rm;\n copyFile: typeof copyFile;\n readFile: typeof readFile;\n stat: typeof stat;\n unlink: typeof unlink;\n writeFile: typeof writeFile;\n };\n\n async start(): Promise<SysFileSystem> {\n this.fs = await import(\"node:fs/promises\");\n return this;\n }\n async mkdir(path: PathLike, options?: { recursive: boolean }): Promise<string | undefined> {\n return this.fs?.mkdir(path, options);\n }\n async readdir(path: PathLike, options?: ObjectEncodingOptions): Promise<string[]> {\n return this.fs?.readdir(path, options) as Promise<string[]>;\n }\n async rm(path: PathLike, options?: MakeDirectoryOptions & { recursive: boolean }): Promise<void> {\n return this.fs?.rm(path, options);\n }\n async copyFile(source: PathLike, destination: PathLike): Promise<void> {\n return this.fs?.copyFile(source, destination);\n }\n async readfile(path: PathLike, options?: { encoding: BufferEncoding; flag?: string }): Promise<Uint8Array> {\n const ret = (await this.fs?.readFile(path, options)) as Buffer;\n return toArrayBuffer(ret);\n }\n stat(path: PathLike): Promise<Stats> {\n return this.fs?.stat(path) as Promise<Stats>;\n }\n async unlink(path: PathLike): Promise<void> {\n return this.fs?.unlink(path);\n }\n async writefile(path: PathLike, data: Uint8Array | string): Promise<void> {\n if (runtimeFn().isDeno) {\n return this.fs?.writeFile(path, data);\n }\n return this.fs?.writeFile(path, Buffer.from(data));\n }\n}\n\n// import { type NodeMap, join } from \"../../sys-container.js\";\n// import type { ObjectEncodingOptions, PathLike } from \"fs\";\n// import * as fs from \"fs/promises\";\n// import * as path from \"path\";\n// import * as os from \"os\";\n// import * as url from \"url\";\n// import { toArrayBuffer } from \"./utils.js\";\n\n// export async function createNodeSysContainer(): Promise<NodeMap> {\n// // const nodePath = \"node:path\";\n// // const nodeOS = \"node:os\";\n// // const nodeURL = \"node:url\";\n// // const nodeFS = \"node:fs\";\n// // const fs = (await import(\"node:fs\")).promises;\n// // const assert = \"assert\";\n// // const path = await import(\"node:path\");\n// return {\n// state: \"node\",\n// ...path,\n// // ...(await import(\"node:os\")),\n// // ...(await import(\"node:url\")),\n// ...os,\n// ...url,\n// ...fs,\n// join,\n// stat: fs.stat as NodeMap[\"stat\"],\n// readdir: fs.readdir as NodeMap[\"readdir\"],\n// readfile: async (path: PathLike, options?: ObjectEncodingOptions): Promise<Uint8Array> => {\n// const rs = await fs.readFile(path, options);\n// return toArrayBuffer(rs);\n// },\n// writefile: fs.writeFile as NodeMap[\"writefile\"],\n// };\n// }\n"],"mappings":";;;;;;AAIA,SAAS,iBAAiB;AAEnB,IAAM,iBAAN,MAA8C;AAAA,EAYnD,MAAM,QAAgC;AACpC,SAAK,KAAK,MAAM,OAAO,kBAAkB;AACzC,WAAO;AAAA,EACT;AAAA,EACA,MAAM,MAAM,MAAgB,SAA+D;AACzF,WAAO,KAAK,IAAI,MAAM,MAAM,OAAO;AAAA,EACrC;AAAA,EACA,MAAM,QAAQ,MAAgB,SAAoD;AAChF,WAAO,KAAK,IAAI,QAAQ,MAAM,OAAO;AAAA,EACvC;AAAA,EACA,MAAM,GAAG,MAAgB,SAAwE;AAC/F,WAAO,KAAK,IAAI,GAAG,MAAM,OAAO;AAAA,EAClC;AAAA,EACA,MAAM,SAAS,QAAkB,aAAsC;AACrE,WAAO,KAAK,IAAI,SAAS,QAAQ,WAAW;AAAA,EAC9C;AAAA,EACA,MAAM,SAAS,MAAgB,SAA4E;AACzG,UAAM,MAAO,MAAM,KAAK,IAAI,SAAS,MAAM,OAAO;AAClD,WAAO,cAAc,GAAG;AAAA,EAC1B;AAAA,EACA,KAAK,MAAgC;AACnC,WAAO,KAAK,IAAI,KAAK,IAAI;AAAA,EAC3B;AAAA,EACA,MAAM,OAAO,MAA+B;AAC1C,WAAO,KAAK,IAAI,OAAO,IAAI;AAAA,EAC7B;AAAA,EACA,MAAM,UAAU,MAAgB,MAA0C;AACxE,QAAI,UAAU,EAAE,QAAQ;AACtB,aAAO,KAAK,IAAI,UAAU,MAAM,IAAI;AAAA,IACtC;AACA,WAAO,KAAK,IAAI,UAAU,MAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACnD;AACF;","names":[]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fireproof/core",
|
3
|
-
"version": "0.19.
|
3
|
+
"version": "0.19.112-dev-web",
|
4
4
|
"description": "Live database for the web.",
|
5
5
|
"type": "module",
|
6
6
|
"module": "./index.js",
|
@@ -13,6 +13,18 @@
|
|
13
13
|
"require": "./index.cjs",
|
14
14
|
"script": "./index.global.js",
|
15
15
|
"types": "./index.d.ts"
|
16
|
+
},
|
17
|
+
"./node": {
|
18
|
+
"import": "./index.js",
|
19
|
+
"require": "./index.cjs",
|
20
|
+
"script": "./index.global.js",
|
21
|
+
"types": "./index.d.ts"
|
22
|
+
},
|
23
|
+
"./web": {
|
24
|
+
"import": "./web/index.js",
|
25
|
+
"require": "./web/index.cjs",
|
26
|
+
"script": "./web/index.global.js",
|
27
|
+
"types": "./web/index.d.ts"
|
16
28
|
}
|
17
29
|
},
|
18
30
|
"keywords": [
|
@@ -42,11 +54,9 @@
|
|
42
54
|
"url": "https://github.com/fireproof-storage/fireproof/issues"
|
43
55
|
},
|
44
56
|
"devDependencies": {},
|
45
|
-
"peerDependencies": {
|
46
|
-
"react": ">=18.0.0"
|
47
|
-
},
|
57
|
+
"peerDependencies": {},
|
48
58
|
"dependencies": {
|
49
|
-
"@adviser/cement": "^0.2.
|
59
|
+
"@adviser/cement": "^0.2.36",
|
50
60
|
"multiformats": "^13.3.0",
|
51
61
|
"@ipld/unixfs": "^3.0.0",
|
52
62
|
"@ipld/car": "^5.3.2",
|
@@ -60,7 +70,6 @@
|
|
60
70
|
"ipfs-unixfs-exporter": "^13.6.1",
|
61
71
|
"memfs": "^4.12.0",
|
62
72
|
"p-limit": "^6.1.0",
|
63
|
-
"react": "^18.3.1",
|
64
73
|
"p-map": "^7.0.2",
|
65
74
|
"p-retry": "^6.2.0"
|
66
75
|
},
|
@@ -96,10 +96,10 @@ describe("KeyBag", () => {
|
|
96
96
|
const { sysFS } = await p._prepare(name);
|
97
97
|
|
98
98
|
diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
|
99
|
-
return JSON.parse(
|
99
|
+
return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeyItem;
|
100
100
|
});
|
101
101
|
diskBag2 = await sysFS.readfile((await p._prepare(name2)).fName).then((data) => {
|
102
|
-
return JSON.parse(
|
102
|
+
return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeyItem;
|
103
103
|
});
|
104
104
|
}
|
105
105
|
expect(await kb.toKeyWithFingerPrint(diskBag.key)).toEqual(res);
|
@@ -2,8 +2,6 @@ import { CID } from "multiformats";
|
|
2
2
|
import { bs, NotFoundError, SuperThis } from "@fireproof/core";
|
3
3
|
import { mockSuperThis } from "../helpers";
|
4
4
|
|
5
|
-
const decoder = new TextDecoder("utf-8");
|
6
|
-
|
7
5
|
function runtime(sthis: SuperThis) {
|
8
6
|
return bs.toStoreRuntime({}, sthis);
|
9
7
|
}
|
@@ -46,7 +44,7 @@ describe("DataStore", function () {
|
|
46
44
|
};
|
47
45
|
await store.save(car);
|
48
46
|
const data = await raw.get(store.url(), car.cid.toString());
|
49
|
-
expect(
|
47
|
+
expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
|
50
48
|
});
|
51
49
|
});
|
52
50
|
|
@@ -76,7 +74,7 @@ describe("DataStore with a saved car", function () {
|
|
76
74
|
|
77
75
|
it("should have a car", async function () {
|
78
76
|
const data = await raw.get(store.url(), car.cid.toString());
|
79
|
-
expect(
|
77
|
+
expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
|
80
78
|
});
|
81
79
|
|
82
80
|
it("should load a car", async function () {
|
@@ -153,7 +151,7 @@ describe("MetaStore with a saved header", function () {
|
|
153
151
|
|
154
152
|
it("should have a header", async function () {
|
155
153
|
const bytes = await raw.get(store.url(), "main");
|
156
|
-
const data =
|
154
|
+
const data = sthis.txt.decode(bytes);
|
157
155
|
expect(data).toMatch(/parents/);
|
158
156
|
const header = JSON.parse(data)[0];
|
159
157
|
expect(header).toBeDefined();
|
@@ -2,6 +2,7 @@ import { Database, bs } from "@fireproof/core";
|
|
2
2
|
import { URI } from "@adviser/cement";
|
3
3
|
|
4
4
|
import { fileContent } from "./cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js";
|
5
|
+
import { mockSuperThis } from "../helpers.js";
|
5
6
|
|
6
7
|
function customExpect(value: unknown, matcher: (val: unknown) => void, message: string): void {
|
7
8
|
try {
|
@@ -36,6 +37,8 @@ describe("noop Gateway", function () {
|
|
36
37
|
let fileGateway: ExtendedGateway;
|
37
38
|
let walGateway: ExtendedGateway;
|
38
39
|
|
40
|
+
const sthis = mockSuperThis();
|
41
|
+
|
39
42
|
afterEach(async function () {
|
40
43
|
await db.close();
|
41
44
|
await db.destroy();
|
@@ -218,8 +221,7 @@ describe("noop Gateway", function () {
|
|
218
221
|
noLoaderOps: [],
|
219
222
|
fileOperations: [],
|
220
223
|
});
|
221
|
-
const
|
222
|
-
const walTestData = walEncoder.encode(walTestDataString);
|
224
|
+
const walTestData = sthis.txt.encode(walTestDataString);
|
223
225
|
const walPutResult = await walGateway?.put(walUrl?.Ok(), walTestData);
|
224
226
|
expect(walPutResult?.Ok()).toBeFalsy();
|
225
227
|
});
|
@@ -233,12 +235,11 @@ describe("noop Gateway", function () {
|
|
233
235
|
noLoaderOps: [],
|
234
236
|
fileOperations: [],
|
235
237
|
});
|
236
|
-
const
|
237
|
-
const walTestData = walEncoder.encode(walTestDataString);
|
238
|
+
const walTestData = sthis.txt.encode(walTestDataString);
|
238
239
|
await walGateway?.put(walUrl?.Ok(), walTestData);
|
239
240
|
const walGetResult = await walGateway?.get(walUrl?.Ok());
|
240
241
|
const okResult = walGetResult?.Ok();
|
241
|
-
const decodedResult =
|
242
|
+
const decodedResult = sthis.txt.decode(okResult);
|
242
243
|
expect(decodedResult).toEqual(walTestDataString);
|
243
244
|
});
|
244
245
|
|
@@ -251,8 +252,7 @@ describe("noop Gateway", function () {
|
|
251
252
|
noLoaderOps: [],
|
252
253
|
fileOperations: [],
|
253
254
|
});
|
254
|
-
const
|
255
|
-
const walTestData = walEncoder.encode(walTestDataString);
|
255
|
+
const walTestData = sthis.txt.encode(walTestDataString);
|
256
256
|
await walGateway?.put(walUrl?.Ok(), walTestData);
|
257
257
|
const walDeleteResult = await walGateway?.delete(walUrl?.Ok());
|
258
258
|
expect(walDeleteResult?.Ok()).toBeFalsy();
|
@@ -302,6 +302,7 @@ describe("noop Gateway subscribe", function () {
|
|
302
302
|
let metaStore: ExtendedStore;
|
303
303
|
|
304
304
|
let metaGateway: ExtendedGateway;
|
305
|
+
const sthis = mockSuperThis();
|
305
306
|
|
306
307
|
afterEach(async function () {
|
307
308
|
await db.close();
|
@@ -325,7 +326,7 @@ describe("noop Gateway subscribe", function () {
|
|
325
326
|
resolve = r;
|
326
327
|
});
|
327
328
|
const metaSubscribeResult = await metaGateway?.subscribe?.(metaUrl?.Ok(), async (data: Uint8Array) => {
|
328
|
-
const decodedData =
|
329
|
+
const decodedData = sthis.txt.decode(data);
|
329
330
|
expect(decodedData).toContain("[]");
|
330
331
|
didCall = true;
|
331
332
|
resolve();
|
@@ -351,6 +352,7 @@ describe("Gateway", function () {
|
|
351
352
|
let metaGateway: ExtendedGateway;
|
352
353
|
// let fileGateway: ExtendedGateway;
|
353
354
|
// let walGateway: ExtendedGateway;
|
355
|
+
const sthis = mockSuperThis();
|
354
356
|
|
355
357
|
afterEach(async function () {
|
356
358
|
await db.close();
|
@@ -380,7 +382,7 @@ describe("Gateway", function () {
|
|
380
382
|
await metaGateway?.start(metaStore?._url);
|
381
383
|
const metaGetResult = await metaGateway?.get(metaUrl?.Ok());
|
382
384
|
const metaGetResultOk = metaGetResult?.Ok();
|
383
|
-
const decodedMetaGetResultOk =
|
385
|
+
const decodedMetaGetResultOk = sthis.txt.decode(metaGetResultOk);
|
384
386
|
expect(decodedMetaGetResultOk).toContain("parents");
|
385
387
|
});
|
386
388
|
|
@@ -3,12 +3,12 @@ import {
|
|
3
3
|
getFileSystem,
|
4
4
|
getPath,
|
5
5
|
toArrayBuffer
|
6
|
-
} from "./chunk-
|
7
|
-
import "./chunk-
|
6
|
+
} from "./chunk-LNFBDD6E.js";
|
7
|
+
import "./chunk-GZANCVTS.js";
|
8
8
|
export {
|
9
9
|
getFileName,
|
10
10
|
getFileSystem,
|
11
11
|
getPath,
|
12
12
|
toArrayBuffer
|
13
13
|
};
|
14
|
-
//# sourceMappingURL=utils-
|
14
|
+
//# sourceMappingURL=utils-L7MUZUJX.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/bundle-not-impl.ts"],"sourcesContent":["const err = new Error(\"store-file not implemented\");\n// eslint-disable-next-line no-console\nconsole.error(err.stack);\nthrow err;\n"],"mappings":";AAAA,IAAM,MAAM,IAAI,MAAM,4BAA4B;AAElD,QAAQ,MAAM,IAAI,KAAK;AACvB,MAAM;","names":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/gateways/indexdb/version.ts"],"sourcesContent":["export const INDEXDB_VERSION = \"v0.19-indexdb\";\n"],"mappings":";AAAO,IAAM,kBAAkB;","names":[]}
|
@@ -0,0 +1,292 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __export = (target, all) => {
|
3
|
+
for (var name in all)
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
5
|
+
};
|
6
|
+
|
7
|
+
// src/utils.ts
|
8
|
+
import {
|
9
|
+
LoggerImpl,
|
10
|
+
IsLogger,
|
11
|
+
Result,
|
12
|
+
ResolveOnce,
|
13
|
+
isURL,
|
14
|
+
URI,
|
15
|
+
runtimeFn,
|
16
|
+
envFactory,
|
17
|
+
toCryptoRuntime,
|
18
|
+
JSONFormatter,
|
19
|
+
YAMLFormatter
|
20
|
+
} from "@adviser/cement";
|
21
|
+
import { base58btc } from "multiformats/bases/base58";
|
22
|
+
var globalLogger = new LoggerImpl();
|
23
|
+
var registerFP_DEBUG = new ResolveOnce();
|
24
|
+
var superThis = class _superThis {
|
25
|
+
constructor(opts) {
|
26
|
+
this.logger = opts.logger;
|
27
|
+
this.env = opts.env;
|
28
|
+
this.crypto = opts.crypto;
|
29
|
+
this.pathOps = opts.pathOps;
|
30
|
+
this.txt = opts.txt;
|
31
|
+
this.ctx = { ...opts.ctx };
|
32
|
+
}
|
33
|
+
nextId(bytes = 6) {
|
34
|
+
const bin = this.crypto.randomBytes(bytes);
|
35
|
+
return {
|
36
|
+
str: base58btc.encode(bin),
|
37
|
+
bin
|
38
|
+
};
|
39
|
+
}
|
40
|
+
timeOrderedNextId(now) {
|
41
|
+
now = typeof now === "number" ? now : (/* @__PURE__ */ new Date()).getTime();
|
42
|
+
const t = (281474976710656 + now).toString(16).replace(/^1/, "");
|
43
|
+
const bin = this.crypto.randomBytes(10);
|
44
|
+
bin[1] = bin[1] & 240 | (bin[1] | 8 && 11);
|
45
|
+
const hex = Array.from(bin).map((i) => i.toString(16).padStart(2, "0")).join("");
|
46
|
+
return {
|
47
|
+
str: `${t.slice(0, 8)}-${t.slice(8)}-7${hex.slice(0, 3)}-${hex.slice(3, 7)}-${hex.slice(7, 19)}`
|
48
|
+
};
|
49
|
+
}
|
50
|
+
start() {
|
51
|
+
return Promise.resolve();
|
52
|
+
}
|
53
|
+
clone(override) {
|
54
|
+
return new _superThis({
|
55
|
+
logger: override.logger || this.logger,
|
56
|
+
env: envFactory(override.env) || this.env,
|
57
|
+
crypto: override.crypto || this.crypto,
|
58
|
+
pathOps: override.pathOps || this.pathOps,
|
59
|
+
txt: override.txt || this.txt,
|
60
|
+
ctx: { ...this.ctx, ...override.ctx }
|
61
|
+
});
|
62
|
+
}
|
63
|
+
};
|
64
|
+
function presetEnv() {
|
65
|
+
const penv = new Map([
|
66
|
+
// ["FP_DEBUG", "xxx"],
|
67
|
+
// ["FP_ENV", "development"],
|
68
|
+
...Array.from(
|
69
|
+
Object.entries(
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
71
|
+
globalThis[Symbol.for("FP_PRESET_ENV")] || {}
|
72
|
+
)
|
73
|
+
)
|
74
|
+
// .map(([k, v]) => [k, v as string])
|
75
|
+
]);
|
76
|
+
return penv;
|
77
|
+
}
|
78
|
+
var pathOpsImpl = class {
|
79
|
+
join(...paths) {
|
80
|
+
return paths.map((i) => i.replace(/\/+$/, "")).join("/");
|
81
|
+
}
|
82
|
+
dirname(path) {
|
83
|
+
return path.split("/").slice(0, -1).join("/");
|
84
|
+
}
|
85
|
+
// homedir() {
|
86
|
+
// throw new Error("SysContainer:homedir is not available in seeded state");
|
87
|
+
// }
|
88
|
+
};
|
89
|
+
var pathOps = new pathOpsImpl();
|
90
|
+
var txtOps = {
|
91
|
+
// eslint-disable-next-line no-restricted-globals
|
92
|
+
encode: (input) => new TextEncoder().encode(input),
|
93
|
+
// eslint-disable-next-line no-restricted-globals
|
94
|
+
decode: (input) => new TextDecoder().decode(input)
|
95
|
+
};
|
96
|
+
function ensureSuperThis(osthis) {
|
97
|
+
const env = envFactory({
|
98
|
+
symbol: osthis?.env?.symbol || "FP_ENV",
|
99
|
+
presetEnv: osthis?.env?.presetEnv || presetEnv()
|
100
|
+
});
|
101
|
+
return new superThis({
|
102
|
+
logger: osthis?.logger || globalLogger,
|
103
|
+
env,
|
104
|
+
crypto: osthis?.crypto || toCryptoRuntime(),
|
105
|
+
ctx: osthis?.ctx || {},
|
106
|
+
pathOps,
|
107
|
+
txt: osthis?.txt || txtOps
|
108
|
+
});
|
109
|
+
}
|
110
|
+
function ensureSuperLog(sthis, componentName, ctx) {
|
111
|
+
return sthis.clone({
|
112
|
+
logger: ensureLogger(sthis, componentName, ctx)
|
113
|
+
});
|
114
|
+
}
|
115
|
+
function ensureLogger(sthis, componentName, ctx) {
|
116
|
+
let logger = globalLogger;
|
117
|
+
if (IsLogger(sthis)) {
|
118
|
+
logger = sthis;
|
119
|
+
} else if (sthis && IsLogger(sthis.logger)) {
|
120
|
+
logger = sthis.logger;
|
121
|
+
}
|
122
|
+
const cLogger = logger.With().Module(componentName);
|
123
|
+
const debug = [];
|
124
|
+
let exposeStack = false;
|
125
|
+
if (ctx) {
|
126
|
+
if ("debug" in ctx) {
|
127
|
+
if (typeof ctx.debug === "string" && ctx.debug.length > 0) {
|
128
|
+
debug.push(ctx.debug);
|
129
|
+
} else {
|
130
|
+
debug.push(componentName);
|
131
|
+
}
|
132
|
+
delete ctx.debug;
|
133
|
+
}
|
134
|
+
if ("exposeStack" in ctx) {
|
135
|
+
exposeStack = true;
|
136
|
+
delete ctx.exposeStack;
|
137
|
+
}
|
138
|
+
if ("this" in ctx) {
|
139
|
+
cLogger.Str("this", sthis.nextId(4).str);
|
140
|
+
delete ctx.this;
|
141
|
+
}
|
142
|
+
for (const [key, value] of Object.entries(ctx)) {
|
143
|
+
switch (typeof value) {
|
144
|
+
case "string":
|
145
|
+
cLogger.Str(key, value);
|
146
|
+
break;
|
147
|
+
case "number":
|
148
|
+
cLogger.Uint64(key, value);
|
149
|
+
break;
|
150
|
+
default:
|
151
|
+
if (value instanceof Date) {
|
152
|
+
cLogger.Str(key, value.toISOString());
|
153
|
+
} else if (isURL(value)) {
|
154
|
+
cLogger.Str(key, value.toString());
|
155
|
+
} else if (typeof value === "function") {
|
156
|
+
cLogger.Ref(key, value);
|
157
|
+
} else {
|
158
|
+
cLogger.Any(key, value);
|
159
|
+
}
|
160
|
+
break;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
registerFP_DEBUG.once(async () => {
|
165
|
+
sthis.env.onSet(
|
166
|
+
(key, value) => {
|
167
|
+
switch (key) {
|
168
|
+
case "FP_FORMAT": {
|
169
|
+
switch (value) {
|
170
|
+
case "jsonice":
|
171
|
+
logger.SetFormatter(new JSONFormatter(logger.TxtEnDe(), 2));
|
172
|
+
break;
|
173
|
+
case "yaml":
|
174
|
+
logger.SetFormatter(new YAMLFormatter(logger.TxtEnDe(), 2));
|
175
|
+
break;
|
176
|
+
case "json":
|
177
|
+
default:
|
178
|
+
logger.SetFormatter(new JSONFormatter(logger.TxtEnDe()));
|
179
|
+
break;
|
180
|
+
}
|
181
|
+
break;
|
182
|
+
}
|
183
|
+
case "FP_DEBUG":
|
184
|
+
logger.SetDebug(value || []);
|
185
|
+
break;
|
186
|
+
case "FP_STACK":
|
187
|
+
logger.SetExposeStack(!!value);
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
},
|
191
|
+
"FP_FORMAT",
|
192
|
+
"FP_DEBUG",
|
193
|
+
"FP_STACK"
|
194
|
+
);
|
195
|
+
}).finally(() => {
|
196
|
+
});
|
197
|
+
if (debug.length > 0) {
|
198
|
+
logger.SetDebug(debug);
|
199
|
+
}
|
200
|
+
if (exposeStack) {
|
201
|
+
logger.SetExposeStack(true);
|
202
|
+
}
|
203
|
+
const out = cLogger.Logger();
|
204
|
+
return out;
|
205
|
+
}
|
206
|
+
function getStore(url, sthis, joiner) {
|
207
|
+
const store = url.getParam("store");
|
208
|
+
switch (store) {
|
209
|
+
case "data":
|
210
|
+
case "wal":
|
211
|
+
case "meta":
|
212
|
+
break;
|
213
|
+
default:
|
214
|
+
throw sthis.logger.Error().Url(url).Msg(`store not found`).AsError();
|
215
|
+
}
|
216
|
+
let name = store;
|
217
|
+
if (url.hasParam("index")) {
|
218
|
+
name = joiner(url.getParam("index") || "idx", name);
|
219
|
+
}
|
220
|
+
return { store, name };
|
221
|
+
}
|
222
|
+
function getKey(url, logger) {
|
223
|
+
const result = url.getParam("key");
|
224
|
+
if (!result) throw logger.Error().Str("url", url.toString()).Msg(`key not found`).AsError();
|
225
|
+
return result;
|
226
|
+
}
|
227
|
+
function getName(sthis, url) {
|
228
|
+
let result = url.getParam("name");
|
229
|
+
if (!result) {
|
230
|
+
result = sthis.pathOps.dirname(url.pathname);
|
231
|
+
if (result.length === 0) {
|
232
|
+
throw sthis.logger.Error().Str("url", url.toString()).Msg(`name not found`).AsError();
|
233
|
+
}
|
234
|
+
}
|
235
|
+
return result;
|
236
|
+
}
|
237
|
+
async function exceptionWrapper(fn) {
|
238
|
+
return fn().catch((e) => Result.Err(e));
|
239
|
+
}
|
240
|
+
var NotFoundError = class extends Error {
|
241
|
+
constructor() {
|
242
|
+
super(...arguments);
|
243
|
+
this.code = "ENOENT";
|
244
|
+
}
|
245
|
+
};
|
246
|
+
function isNotFoundError(e) {
|
247
|
+
if (Result.Is(e)) {
|
248
|
+
if (e.isOk()) return false;
|
249
|
+
e = e.Err();
|
250
|
+
}
|
251
|
+
if (e.code === "ENOENT") return true;
|
252
|
+
return false;
|
253
|
+
}
|
254
|
+
function dataDir(sthis, name, base) {
|
255
|
+
if (!base) {
|
256
|
+
if (!runtimeFn().isBrowser) {
|
257
|
+
const home = sthis.env.get("HOME") || "./";
|
258
|
+
base = sthis.env.get("FP_STORAGE_URL") || `file://${sthis.pathOps.join(home, ".fireproof")}`;
|
259
|
+
} else {
|
260
|
+
base = sthis.env.get("FP_STORAGE_URL") || `indexdb://fp`;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
return URI.from(base.toString()).build().setParam("name", name || "").URI();
|
264
|
+
}
|
265
|
+
function UInt8ArrayEqual(a, b) {
|
266
|
+
if (a.length !== b.length) {
|
267
|
+
return false;
|
268
|
+
}
|
269
|
+
for (let i = 0; i < a.length; i++) {
|
270
|
+
if (a[i] !== b[i]) {
|
271
|
+
return false;
|
272
|
+
}
|
273
|
+
}
|
274
|
+
return true;
|
275
|
+
}
|
276
|
+
|
277
|
+
export {
|
278
|
+
__export,
|
279
|
+
Result,
|
280
|
+
ensureSuperThis,
|
281
|
+
ensureSuperLog,
|
282
|
+
ensureLogger,
|
283
|
+
getStore,
|
284
|
+
getKey,
|
285
|
+
getName,
|
286
|
+
exceptionWrapper,
|
287
|
+
NotFoundError,
|
288
|
+
isNotFoundError,
|
289
|
+
dataDir,
|
290
|
+
UInt8ArrayEqual
|
291
|
+
};
|
292
|
+
//# sourceMappingURL=chunk-Q5W7UNMP.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/utils.ts"],"sourcesContent":["import {\n Logger,\n LoggerImpl,\n IsLogger,\n Result,\n ResolveOnce,\n isURL,\n URI,\n CoerceURI,\n runtimeFn,\n envFactory,\n Env,\n toCryptoRuntime,\n CryptoRuntime,\n JSONFormatter,\n YAMLFormatter,\n} from \"@adviser/cement\";\nimport { PathOps, StoreType, SuperThis, SuperThisOpts, TextEndeCoder } from \"./types\";\nimport { base58btc } from \"multiformats/bases/base58\";\n\nexport type { Logger };\nexport { Result };\n\nconst globalLogger: Logger = new LoggerImpl();\n\nconst registerFP_DEBUG = new ResolveOnce();\n\ninterface superThisOpts {\n readonly logger: Logger;\n readonly env: Env;\n readonly pathOps: PathOps;\n readonly crypto: CryptoRuntime;\n readonly ctx: Record<string, unknown>;\n readonly txt: TextEndeCoder;\n}\n\nclass superThis implements SuperThis {\n readonly logger: Logger;\n readonly env: Env;\n readonly pathOps: PathOps;\n readonly ctx: Record<string, unknown>;\n readonly txt: TextEndeCoder;\n readonly crypto: CryptoRuntime;\n\n constructor(opts: superThisOpts) {\n this.logger = opts.logger;\n this.env = opts.env;\n this.crypto = opts.crypto;\n this.pathOps = opts.pathOps;\n this.txt = opts.txt;\n this.ctx = { ...opts.ctx };\n // console.log(\"superThis\", this);\n }\n\n nextId(bytes = 6): { str: string; bin: Uint8Array } {\n const bin = this.crypto.randomBytes(bytes);\n return {\n str: base58btc.encode(bin),\n bin,\n };\n }\n\n timeOrderedNextId(now?: number): { str: string } {\n now = typeof now === \"number\" ? now : new Date().getTime();\n // 49th bit\n const t = (0x1000000000000 + now).toString(16).replace(/^1/, \"\");\n const bin = this.crypto.randomBytes(10);\n bin[1] = (bin[1] & 0xf0) | (bin[1] | 0x08 && 0x0b);\n const hex = Array.from(bin)\n .map((i) => i.toString(16).padStart(2, \"0\"))\n .join(\"\");\n return {\n str: `${t.slice(0, 8)}-${t.slice(8)}-7${hex.slice(0, 3)}-${hex.slice(3, 7)}-${hex.slice(7, 19)}`,\n };\n }\n\n start(): Promise<void> {\n return Promise.resolve();\n }\n\n clone(override: Partial<SuperThisOpts>): SuperThis {\n return new superThis({\n logger: override.logger || this.logger,\n env: envFactory(override.env) || this.env,\n crypto: override.crypto || this.crypto,\n pathOps: override.pathOps || this.pathOps,\n txt: override.txt || this.txt,\n ctx: { ...this.ctx, ...override.ctx },\n });\n }\n}\n\n// const pathOps =\nfunction presetEnv() {\n const penv = new Map([\n // [\"FP_DEBUG\", \"xxx\"],\n // [\"FP_ENV\", \"development\"],\n ...Array.from(\n Object.entries(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ((globalThis as any)[Symbol.for(\"FP_PRESET_ENV\")] || {}) as Record<string, string>,\n ),\n ), // .map(([k, v]) => [k, v as string])\n ]);\n // console.log(\">>>>>>\", penv)\n return penv;\n}\n// const envImpl = envFactory({\n// symbol: \"FP_ENV\",\n// presetEnv: presetEnv(),\n// });\nclass pathOpsImpl implements PathOps {\n join(...paths: string[]): string {\n return paths.map((i) => i.replace(/\\/+$/, \"\")).join(\"/\");\n }\n dirname(path: string) {\n return path.split(\"/\").slice(0, -1).join(\"/\");\n }\n // homedir() {\n // throw new Error(\"SysContainer:homedir is not available in seeded state\");\n // }\n}\nconst pathOps = new pathOpsImpl();\nconst txtOps = {\n // eslint-disable-next-line no-restricted-globals\n encode: (input: string) => new TextEncoder().encode(input),\n // eslint-disable-next-line no-restricted-globals\n decode: (input: Uint8Array) => new TextDecoder().decode(input),\n};\n\nexport function ensureSuperThis(osthis?: Partial<SuperThisOpts>): SuperThis {\n const env = envFactory({\n symbol: osthis?.env?.symbol || \"FP_ENV\",\n presetEnv: osthis?.env?.presetEnv || presetEnv(),\n });\n return new superThis({\n logger: osthis?.logger || globalLogger,\n env,\n crypto: osthis?.crypto || toCryptoRuntime(),\n ctx: osthis?.ctx || {},\n pathOps,\n txt: osthis?.txt || txtOps,\n });\n}\n\n// // eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function ensureSuperLog(sthis: SuperThis, componentName: string, ctx?: Record<string, unknown>): SuperThis {\n return sthis.clone({\n logger: ensureLogger(sthis, componentName, ctx),\n });\n}\n\nexport function ensureLogger(\n sthis: SuperThis /* Partial<LoggerOpts> | Logger */,\n componentName: string,\n ctx?: Record<string, unknown>,\n): Logger {\n // if (!opts?.logger) {\n // throw new Error(\"logger is required\");\n // }\n let logger = globalLogger;\n if (IsLogger(sthis)) {\n logger = sthis;\n } else if (sthis && IsLogger(sthis.logger)) {\n logger = sthis.logger;\n }\n const cLogger = logger.With().Module(componentName); //.Str(\"this\", uuidv7());\n const debug: string[] = [];\n let exposeStack = false;\n if (ctx) {\n if (\"debug\" in ctx) {\n if (typeof ctx.debug === \"string\" && ctx.debug.length > 0) {\n debug.push(ctx.debug);\n } else {\n debug.push(componentName);\n }\n delete ctx.debug;\n }\n if (\"exposeStack\" in ctx) {\n exposeStack = true;\n delete ctx.exposeStack;\n }\n if (\"this\" in ctx) {\n cLogger.Str(\"this\", sthis.nextId(4).str);\n delete ctx.this;\n }\n for (const [key, value] of Object.entries(ctx)) {\n switch (typeof value) {\n case \"string\":\n cLogger.Str(key, value);\n break;\n case \"number\":\n cLogger.Uint64(key, value);\n break;\n default:\n if (value instanceof Date) {\n cLogger.Str(key, value.toISOString());\n } else if (isURL(value)) {\n cLogger.Str(key, value.toString());\n } else if (typeof value === \"function\") {\n cLogger.Ref(key, value);\n } else {\n cLogger.Any(key, value);\n }\n break;\n }\n }\n }\n registerFP_DEBUG\n .once(async () => {\n // console.log(\"registerFP_DEBUG\", SysContainer.env)\n sthis.env.onSet(\n (key, value) => {\n // console.log(\"FP_DEBUG\", key, value, debug)\n switch (key) {\n case \"FP_FORMAT\": {\n switch (value) {\n case \"jsonice\":\n logger.SetFormatter(new JSONFormatter(logger.TxtEnDe(), 2));\n break;\n case \"yaml\":\n logger.SetFormatter(new YAMLFormatter(logger.TxtEnDe(), 2));\n break;\n case \"json\":\n default:\n logger.SetFormatter(new JSONFormatter(logger.TxtEnDe()));\n break;\n }\n break;\n }\n case \"FP_DEBUG\":\n logger.SetDebug(value || []);\n break;\n case \"FP_STACK\":\n logger.SetExposeStack(!!value);\n break;\n }\n },\n \"FP_FORMAT\",\n \"FP_DEBUG\",\n \"FP_STACK\",\n );\n })\n .finally(() => {\n /* do nothing */\n });\n\n if (debug.length > 0) {\n logger.SetDebug(debug);\n }\n if (exposeStack) {\n logger.SetExposeStack(true);\n }\n const out = cLogger.Logger();\n // out.Debug().Msg(\"logger ready\");\n return out;\n}\n\nexport type Joiner = (...toJoin: string[]) => string;\n\nexport interface Store {\n readonly store: StoreType;\n readonly name: string;\n}\n\nexport function getStore(url: URI, sthis: SuperThis, joiner: Joiner): Store {\n const store = url.getParam(\"store\");\n switch (store) {\n case \"data\":\n case \"wal\":\n case \"meta\":\n break;\n default:\n throw sthis.logger.Error().Url(url).Msg(`store not found`).AsError();\n }\n let name: string = store;\n if (url.hasParam(\"index\")) {\n name = joiner(url.getParam(\"index\") || \"idx\", name);\n }\n return { store, name };\n}\n\nexport function getKey(url: URI, logger: Logger): string {\n const result = url.getParam(\"key\");\n if (!result) throw logger.Error().Str(\"url\", url.toString()).Msg(`key not found`).AsError();\n return result;\n}\n\nexport function getName(sthis: SuperThis, url: URI): string {\n let result = url.getParam(\"name\");\n if (!result) {\n result = sthis.pathOps.dirname(url.pathname);\n if (result.length === 0) {\n throw sthis.logger.Error().Str(\"url\", url.toString()).Msg(`name not found`).AsError();\n }\n }\n return result;\n}\n\n// export function exception2Result<T = void>(fn: () => Promise<T>): Promise<Result<T>> {\n// return fn()\n// .then((value) => Result.Ok(value))\n// .catch((e) => Result.Err(e));\n// }\n\nexport async function exceptionWrapper<T, E extends Error>(fn: () => Promise<Result<T, E>>): Promise<Result<T, E>> {\n return fn().catch((e) => Result.Err(e));\n}\n\n// // the big side effect party --- hate it\n// export function sanitizeURL(url: URL) {\n// url.searchParams.sort();\n// // const searchParams = Object.entries(url.searchParams).sort(([a], [b]) => a.localeCompare(b));\n// // console.log(\"searchParams\", searchParams);\n// // for (const [key] of searchParams) {\n// // url.searchParams.delete(key);\n// // }\n// // for (const [key, value] of searchParams) {\n// // url.searchParams.set(key, value);\n// // }\n// }\n\nexport class NotFoundError extends Error {\n readonly code = \"ENOENT\";\n}\n\nexport function isNotFoundError(e: Error | Result<unknown> | unknown): e is NotFoundError {\n if (Result.Is(e)) {\n if (e.isOk()) return false;\n e = e.Err();\n }\n if ((e as NotFoundError).code === \"ENOENT\") return true;\n return false;\n}\n\nexport function dataDir(sthis: SuperThis, name?: string, base?: CoerceURI): URI {\n if (!base) {\n if (!runtimeFn().isBrowser) {\n const home = sthis.env.get(\"HOME\") || \"./\";\n base = sthis.env.get(\"FP_STORAGE_URL\") || `file://${sthis.pathOps.join(home, \".fireproof\")}`;\n } else {\n base = sthis.env.get(\"FP_STORAGE_URL\") || `indexdb://fp`;\n }\n }\n return URI.from(base.toString())\n .build()\n .setParam(\"name\", name || \"\")\n .URI();\n}\n\nexport function UInt8ArrayEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";;;;;;;AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,iBAAiB;AAK1B,IAAM,eAAuB,IAAI,WAAW;AAE5C,IAAM,mBAAmB,IAAI,YAAY;AAWzC,IAAM,YAAN,MAAM,WAA+B;AAAA,EAQnC,YAAY,MAAqB;AAC/B,SAAK,SAAS,KAAK;AACnB,SAAK,MAAM,KAAK;AAChB,SAAK,SAAS,KAAK;AACnB,SAAK,UAAU,KAAK;AACpB,SAAK,MAAM,KAAK;AAChB,SAAK,MAAM,EAAE,GAAG,KAAK,IAAI;AAAA,EAE3B;AAAA,EAEA,OAAO,QAAQ,GAAqC;AAClD,UAAM,MAAM,KAAK,OAAO,YAAY,KAAK;AACzC,WAAO;AAAA,MACL,KAAK,UAAU,OAAO,GAAG;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,kBAAkB,KAA+B;AAC/C,UAAM,OAAO,QAAQ,WAAW,OAAM,oBAAI,KAAK,GAAE,QAAQ;AAEzD,UAAM,KAAK,kBAAkB,KAAK,SAAS,EAAE,EAAE,QAAQ,MAAM,EAAE;AAC/D,UAAM,MAAM,KAAK,OAAO,YAAY,EAAE;AACtC,QAAI,CAAC,IAAK,IAAI,CAAC,IAAI,OAAS,IAAI,CAAC,IAAI,KAAQ;AAC7C,UAAM,MAAM,MAAM,KAAK,GAAG,EACvB,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAC1C,KAAK,EAAE;AACV,WAAO;AAAA,MACL,KAAK,GAAG,EAAE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AG,CAAC,GAAG;AAChB,QAAI,EAAE,KAAK,EAAG,QAAO;AACrB,QAAI,EAAE,IAAI;AAAA,EACZ;AACA,MAAK,EAAoB,SAAS,SAAU,QAAO;AACnD,SAAO;AACT;AAEO,SAAS,QAAQ,OAAkB,MAAe,MAAuB;AAC9E,MAAI,CAAC,MAAM;AACT,QAAI,CAAC,UAAU,EAAE,WAAW;AAC1B,YAAM,OAAO,MAAM,IAAI,IAAI,MAAM,KAAK;AACtC,aAAO,MAAM,IAAI,IAAI,gBAAgB,KAAK,UAAU,MAAM,QAAQ,KAAK,MAAM,YAAY,CAAC;AAAA,IAC5F,OAAO;AACL,aAAO,MAAM,IAAI,IAAI,gBAAgB,KAAK;AAAA,IAC5C;AAAA,EACF;AACA,SAAO,IAAI,KAAK,KAAK,SAAS,CAAC,EAC5B,MAAM,EACN,SAAS,QAAQ,QAAQ,EAAE,EAC3B,IAAI;AACT;AAEO,SAAS,gBAAgB,GAAe,GAAwB;AACrE,MAAI,EAAE,WAAW,EAAE,QAAQ;AACzB,WAAO;AAAA,EACT;AACA,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG;AACjB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import {
|
2
|
+
getStore
|
3
|
+
} from "./chunk-Q5W7UNMP.js";
|
4
|
+
|
5
|
+
// src/runtime/gateways/file/utils.ts
|
6
|
+
async function getFileSystem(url) {
|
7
|
+
const name = url.getParam("fs");
|
8
|
+
let fs;
|
9
|
+
switch (name) {
|
10
|
+
case "mem":
|
11
|
+
{
|
12
|
+
const { MemFileSystem } = await import("./bundle-not-impl-UH74NK5L.js");
|
13
|
+
fs = new MemFileSystem();
|
14
|
+
}
|
15
|
+
break;
|
16
|
+
// case 'deno': {
|
17
|
+
// const { DenoFileSystem } = await import("./deno-filesystem.js");
|
18
|
+
// fs = new DenoFileSystem();
|
19
|
+
// break;
|
20
|
+
// }
|
21
|
+
case "node": {
|
22
|
+
const { NodeFileSystem } = await import("./bundle-not-impl-UH74NK5L.js");
|
23
|
+
fs = new NodeFileSystem();
|
24
|
+
break;
|
25
|
+
}
|
26
|
+
case "sys":
|
27
|
+
default: {
|
28
|
+
return getFileSystem(url.build().setParam("fs", "node").URI());
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return fs.start();
|
32
|
+
}
|
33
|
+
function getPath(url, sthis) {
|
34
|
+
const basePath = url.pathname;
|
35
|
+
const name = url.getParam("name");
|
36
|
+
if (name) {
|
37
|
+
const version = url.getParam("version");
|
38
|
+
if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();
|
39
|
+
return sthis.pathOps.join(basePath, version, name);
|
40
|
+
}
|
41
|
+
return sthis.pathOps.join(basePath);
|
42
|
+
}
|
43
|
+
function getFileName(url, sthis) {
|
44
|
+
const key = url.getParam("key");
|
45
|
+
if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
|
46
|
+
const res = getStore(url, sthis, (...a) => a.join("-"));
|
47
|
+
switch (res.store) {
|
48
|
+
case "data":
|
49
|
+
return sthis.pathOps.join(res.name, key + ".car");
|
50
|
+
case "wal":
|
51
|
+
case "meta":
|
52
|
+
return sthis.pathOps.join(res.name, key + ".json");
|
53
|
+
default:
|
54
|
+
throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();
|
55
|
+
}
|
56
|
+
}
|
57
|
+
function toArrayBuffer(buffer) {
|
58
|
+
if (typeof buffer === "string") {
|
59
|
+
buffer = Buffer.from(buffer);
|
60
|
+
}
|
61
|
+
const ab = new ArrayBuffer(buffer.length);
|
62
|
+
const view = new Uint8Array(ab);
|
63
|
+
for (let i = 0; i < buffer.length; ++i) {
|
64
|
+
view[i] = buffer[i];
|
65
|
+
}
|
66
|
+
return view;
|
67
|
+
}
|
68
|
+
|
69
|
+
export {
|
70
|
+
getFileSystem,
|
71
|
+
getPath,
|
72
|
+
getFileName,
|
73
|
+
toArrayBuffer
|
74
|
+
};
|
75
|
+
//# sourceMappingURL=chunk-S4HRSKEO.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/gateways/file/utils.ts"],"sourcesContent":["import { URI } from \"@adviser/cement\";\nimport { getStore } from \"../../../utils.js\";\nimport { SuperThis, SysFileSystem } from \"../../../types.js\";\n\nexport async function getFileSystem(url: URI): Promise<SysFileSystem> {\n const name = url.getParam(\"fs\");\n let fs: SysFileSystem;\n switch (name) {\n case \"mem\":\n {\n const { MemFileSystem } = await import(\"./mem-filesystem@skip-iife.js\");\n fs = new MemFileSystem();\n }\n break;\n // case 'deno': {\n // const { DenoFileSystem } = await import(\"./deno-filesystem.js\");\n // fs = new DenoFileSystem();\n // break;\n // }\n case \"node\": {\n const { NodeFileSystem } = await import(\"./node-filesystem@skip-iife.js\");\n fs = new NodeFileSystem();\n break;\n }\n case \"sys\":\n default: {\n // if (runtimeFn().isDeno) {\n // return getFileSystem(url.build().setParam(\"fs\", \"deno\").URI());\n // } else {\n return getFileSystem(url.build().setParam(\"fs\", \"node\").URI());\n // }\n }\n }\n return fs.start();\n}\n\nexport function getPath(url: URI, sthis: SuperThis): string {\n const basePath = url.pathname;\n // .toString()\n // .replace(new RegExp(`^${url.protocol}//`), \"\")\n // .replace(/\\?.*$/, \"\");\n const name = url.getParam(\"name\");\n if (name) {\n const version = url.getParam(\"version\");\n if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();\n return sthis.pathOps.join(basePath, version, name);\n }\n return sthis.pathOps.join(basePath);\n}\n\nexport function getFileName(url: URI, sthis: SuperThis): string {\n const key = url.getParam(\"key\");\n if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();\n const res = getStore(url, sthis, (...a: string[]) => a.join(\"-\"));\n switch (res.store) {\n case \"data\":\n return sthis.pathOps.join(res.name, key + \".car\");\n case \"wal\":\n case \"meta\":\n return sthis.pathOps.join(res.name, key + \".json\");\n default:\n throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();\n }\n}\n\nexport function toArrayBuffer(buffer: Buffer | string): Uint8Array {\n if (typeof buffer === \"string\") {\n buffer = Buffer.from(buffer);\n }\n const ab = new ArrayBuffer(buffer.length);\n const view = new Uint8Array(ab);\n for (let i = 0; i < buffer.length; ++i) {\n view[i] = buffer[i];\n }\n return view;\n}\n"],"mappings":";;;;;AAIA,eAAsB,cAAc,KAAkC;AACpE,QAAM,OAAO,IAAI,SAAS,IAAI;AAC9B,MAAI;AACJ,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH;AACE,cAAM,EAAE,cAAc,IAAI,MAAM,OAAO,+BAA+B;AACtE,aAAK,IAAI,cAAc;AAAA,MACzB;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMF,KAAK,QAAQ;AACX,YAAM,EAAE,eAAe,IAAI,MAAM,OAAO,+BAAgC;AACxE,WAAK,IAAI,eAAe;AACxB;AAAA,IACF;AAAA,IACA,KAAK;AAAA,IACL,SAAS;AAIP,aAAO,cAAc,IAAI,MAAM,EAAE,SAAS,MAAM,MAAM,EAAE,IAAI,CAAC;AAAA,IAE/D;AAAA,EACF;AACA,SAAO,GAAG,MAAM;AAClB;AAEO,SAAS,QAAQ,KAAU,OAA0B;AAC1D,QAAM,WAAW,IAAI;AAIrB,QAAM,OAAO,IAAI,SAAS,MAAM;AAChC,MAAI,MAAM;AACR,UAAM,UAAU,IAAI,SAAS,SAAS;AACtC,QAAI,CAAC,QAAS,OAAM,MAAM,OAAO,MAAM,EAAE,IAAI,GAAG,EAAE,IAAI,mBAAmB,EAAE,QAAQ;AACnF,WAAO,MAAM,QAAQ,KAAK,UAAU,SAAS,IAAI;AAAA,EACnD;AACA,SAAO,MAAM,QAAQ,KAAK,QAAQ;AACpC;AAEO,SAAS,YAAY,KAAU,OAA0B;AAC9D,QAAM,MAAM,IAAI,SAAS,KAAK;AAC9B,MA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