@fireproof/core 0.19.120 → 0.19.121
Sign up to get free protection for your applications and to get access to all the features.
- package/deno.json +2 -2
- package/index.cjs +624 -1026
- package/index.cjs.map +1 -1
- package/index.d.cts +26 -60
- package/index.d.ts +26 -60
- package/index.js +394 -97
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.cjs +374 -0
- package/node/index.cjs.map +1 -0
- package/node/index.d.cts +43 -0
- package/node/index.d.ts +43 -0
- package/node/index.js +279 -0
- package/node/index.js.map +1 -0
- package/node/{mem-filesystem.js → mem-filesystem-LPPT7QV5.js} +1 -1
- package/node/metafile-cjs.json +1 -1
- package/node/metafile-esm.json +1 -1
- package/package.json +16 -14
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +4 -33
- package/react/index.d.ts +4 -33
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/keyed-crypto.test.ts +4 -2
- package/tests/fireproof/config.test.ts +133 -142
- package/web/{gateway-impl.cjs → index.cjs} +58 -9
- package/web/index.cjs.map +1 -0
- package/web/index.d.cts +44 -0
- package/web/index.d.ts +44 -0
- package/web/{gateway-impl.js → index.js} +52 -5
- package/web/index.js.map +1 -0
- package/web/metafile-cjs.json +1 -1
- package/web/metafile-esm.json +1 -1
- package/chunk-7EWIAXTM.js +0 -7
- package/chunk-7EWIAXTM.js.map +0 -1
- package/chunk-F4FC6B2T.js +0 -63
- package/chunk-F4FC6B2T.js.map +0 -1
- package/chunk-PZ5AY32C.js +0 -10
- package/chunk-PZ5AY32C.js.map +0 -1
- package/chunk-RXC4JGJT.js +0 -301
- package/chunk-RXC4JGJT.js.map +0 -1
- package/gateway-C62S56GY.js +0 -66
- package/gateway-C62S56GY.js.map +0 -1
- package/gateway-VVS4QWDA.js +0 -145
- package/gateway-VVS4QWDA.js.map +0 -1
- package/key-bag-file-PWZ3QE7B.js +0 -55
- package/key-bag-file-PWZ3QE7B.js.map +0 -1
- package/key-bag-indexdb-SYG3YD4D.js +0 -51
- package/key-bag-indexdb-SYG3YD4D.js.map +0 -1
- package/node/mem-filesystem.cjs +0 -72
- package/node/mem-filesystem.cjs.map +0 -1
- package/node/mem-filesystem.d.cts +0 -25
- package/node/mem-filesystem.d.ts +0 -25
- package/node/node-filesystem.cjs +0 -86
- package/node/node-filesystem.cjs.map +0 -1
- package/node/node-filesystem.d.cts +0 -35
- package/node/node-filesystem.d.ts +0 -35
- package/node/node-filesystem.js +0 -44
- package/node/node-filesystem.js.map +0 -1
- package/utils-ZVVGAXFE.js +0 -13
- package/utils-ZVVGAXFE.js.map +0 -1
- package/web/gateway-impl.cjs.map +0 -1
- package/web/gateway-impl.d.cts +0 -31
- package/web/gateway-impl.d.ts +0 -31
- package/web/gateway-impl.js.map +0 -1
- /package/node/{mem-filesystem.js.map → mem-filesystem-LPPT7QV5.js.map} +0 -0
@@ -1,51 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
getPath
|
3
|
-
} from "./chunk-F4FC6B2T.js";
|
4
|
-
import "./chunk-RXC4JGJT.js";
|
5
|
-
import "./chunk-PZ5AY32C.js";
|
6
|
-
|
7
|
-
// src/runtime/key-bag-indexdb.ts
|
8
|
-
import { openDB } from "idb";
|
9
|
-
import { ResolveOnce } from "@adviser/cement";
|
10
|
-
var KeyBagProviderIndexDB = class {
|
11
|
-
constructor(url, sthis) {
|
12
|
-
this._db = new ResolveOnce();
|
13
|
-
this.sthis = sthis;
|
14
|
-
this.logger = sthis.logger;
|
15
|
-
this.url = url;
|
16
|
-
this.dbName = getPath(this.url, this.sthis);
|
17
|
-
}
|
18
|
-
async _prepare() {
|
19
|
-
return this._db.once(async () => {
|
20
|
-
return await openDB(this.dbName, 1, {
|
21
|
-
upgrade(db) {
|
22
|
-
["bag"].map((store) => {
|
23
|
-
db.createObjectStore(store, {
|
24
|
-
autoIncrement: false
|
25
|
-
});
|
26
|
-
});
|
27
|
-
}
|
28
|
-
});
|
29
|
-
});
|
30
|
-
}
|
31
|
-
async get(id) {
|
32
|
-
const db = await this._prepare();
|
33
|
-
const tx = db.transaction(["bag"], "readonly");
|
34
|
-
const keyItem = await tx.objectStore("bag").get(id);
|
35
|
-
await tx.done;
|
36
|
-
if (!keyItem) {
|
37
|
-
return void 0;
|
38
|
-
}
|
39
|
-
return keyItem;
|
40
|
-
}
|
41
|
-
async set(id, item) {
|
42
|
-
const db = await this._prepare();
|
43
|
-
const tx = db.transaction(["bag"], "readwrite");
|
44
|
-
await tx.objectStore("bag").put(item, id);
|
45
|
-
await tx.done;
|
46
|
-
}
|
47
|
-
};
|
48
|
-
export {
|
49
|
-
KeyBagProviderIndexDB
|
50
|
-
};
|
51
|
-
//# sourceMappingURL=key-bag-indexdb-SYG3YD4D.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/key-bag-indexdb.ts"],"sourcesContent":["import { IDBPDatabase, openDB } from \"idb\";\nimport { KeyBagProvider, KeyItem } from \"./key-bag.js\";\nimport { getPath } from \"./gateways/file/utils.js\";\nimport { Logger, ResolveOnce, URI } from \"@adviser/cement\";\nimport type { SuperThis } from \"../types.js\";\n\nexport class KeyBagProviderIndexDB implements KeyBagProvider {\n readonly _db: ResolveOnce<IDBPDatabase<unknown>> = new ResolveOnce<IDBPDatabase<unknown>>();\n\n readonly dbName: string;\n readonly url: URI;\n readonly logger: Logger;\n readonly sthis: SuperThis;\n constructor(url: URI, sthis: SuperThis) {\n this.sthis = sthis;\n this.logger = sthis.logger;\n this.url = url;\n this.dbName = getPath(this.url, this.sthis);\n }\n\n async _prepare(): Promise<IDBPDatabase<unknown>> {\n return this._db.once(async () => {\n return await openDB(this.dbName, 1, {\n upgrade(db) {\n // console.log('upgrade:', dbName);\n [\"bag\"].map((store) => {\n db.createObjectStore(store, {\n autoIncrement: false,\n });\n });\n },\n });\n });\n }\n\n async get(id: string): Promise<KeyItem | undefined> {\n const db = await this._prepare();\n const tx = db.transaction([\"bag\"], \"readonly\");\n const keyItem = await tx.objectStore(\"bag\").get(id);\n await tx.done;\n if (!keyItem) {\n return undefined;\n }\n return keyItem;\n }\n\n async set(id: string, item: KeyItem): Promise<void> {\n const db = await this._prepare();\n const tx = db.transaction([\"bag\"], \"readwrite\");\n await tx.objectStore(\"bag\").put(item, id);\n await tx.done;\n }\n}\n"],"mappings":";;;;;;;AAAA,SAAuB,cAAc;AAGrC,SAAiB,mBAAwB;AAGlC,IAAM,wBAAN,MAAsD;AAAA,EAO3D,YAAY,KAAU,OAAkB;AANxC,SAAS,MAA0C,IAAI,YAAmC;AAOxF,SAAK,QAAQ;AACb,SAAK,SAAS,MAAM;AACpB,SAAK,MAAM;AACX,SAAK,SAAS,QAAQ,KAAK,KAAK,KAAK,KAAK;AAAA,EAC5C;AAAA,EAEA,MAAM,WAA2C;AAC/C,WAAO,KAAK,IAAI,KAAK,YAAY;AAC/B,aAAO,MAAM,OAAO,KAAK,QAAQ,GAAG;AAAA,QAClC,QAAQ,IAAI;AAEV,WAAC,KAAK,EAAE,IAAI,CAAC,UAAU;AACrB,eAAG,kBAAkB,OAAO;AAAA,cAC1B,eAAe;AAAA,YACjB,CAAC;AAAA,UACH,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,IAAI,IAA0C;AAClD,UAAM,KAAK,MAAM,KAAK,SAAS;AAC/B,UAAM,KAAK,GAAG,YAAY,CAAC,KAAK,GAAG,UAAU;AAC7C,UAAM,UAAU,MAAM,GAAG,YAAY,KAAK,EAAE,IAAI,EAAE;AAClD,UAAM,GAAG;AACT,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,IAAI,IAAY,MAA8B;AAClD,UAAM,KAAK,MAAM,KAAK,SAAS;AAC/B,UAAM,KAAK,GAAG,YAAY,CAAC,KAAK,GAAG,WAAW;AAC9C,UAAM,GAAG,YAAY,KAAK,EAAE,IAAI,MAAM,EAAE;AACxC,UAAM,GAAG;AAAA,EACX;AACF;","names":[]}
|
package/node/mem-filesystem.cjs
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/runtime/gateways/file/node/mem-filesystem.ts
|
21
|
-
var mem_filesystem_exports = {};
|
22
|
-
__export(mem_filesystem_exports, {
|
23
|
-
MemFileSystem: () => MemFileSystem
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(mem_filesystem_exports);
|
26
|
-
var import_memfs = require("memfs");
|
27
|
-
|
28
|
-
// src/runtime/gateways/file/node/to-array-buffer.ts
|
29
|
-
function toArrayBuffer(buffer) {
|
30
|
-
if (typeof buffer === "string") {
|
31
|
-
buffer = Buffer.from(buffer);
|
32
|
-
}
|
33
|
-
const ab = new ArrayBuffer(buffer.length);
|
34
|
-
const view = new Uint8Array(ab);
|
35
|
-
for (let i = 0; i < buffer.length; ++i) {
|
36
|
-
view[i] = buffer[i];
|
37
|
-
}
|
38
|
-
return view;
|
39
|
-
}
|
40
|
-
|
41
|
-
// src/runtime/gateways/file/node/mem-filesystem.ts
|
42
|
-
var MemFileSystem = class {
|
43
|
-
async start() {
|
44
|
-
return this;
|
45
|
-
}
|
46
|
-
mkdir(path, options) {
|
47
|
-
return import_memfs.fs.promises.mkdir(path, options);
|
48
|
-
}
|
49
|
-
readdir(path, options) {
|
50
|
-
return import_memfs.fs.promises.readdir(path, options);
|
51
|
-
}
|
52
|
-
rm(path, options) {
|
53
|
-
return import_memfs.fs.promises.rm(path, options);
|
54
|
-
}
|
55
|
-
copyFile(source, destination) {
|
56
|
-
return import_memfs.fs.promises.copyFile(source, destination);
|
57
|
-
}
|
58
|
-
async readfile(path, options) {
|
59
|
-
const ret = await import_memfs.fs.promises.readFile(path, options);
|
60
|
-
return toArrayBuffer(ret);
|
61
|
-
}
|
62
|
-
stat(path) {
|
63
|
-
return import_memfs.fs.promises.stat(path);
|
64
|
-
}
|
65
|
-
unlink(path) {
|
66
|
-
return import_memfs.fs.promises.unlink(path);
|
67
|
-
}
|
68
|
-
writefile(path, data) {
|
69
|
-
return import_memfs.fs.promises.writeFile(path, Buffer.from(data));
|
70
|
-
}
|
71
|
-
};
|
72
|
-
//# sourceMappingURL=mem-filesystem.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/gateways/file/node/mem-filesystem.ts","../../../src/runtime/gateways/file/node/to-array-buffer.ts"],"sourcesContent":["import type { PathLike, MakeDirectoryOptions, Stats } from \"fs\";\nimport { fs } from \"memfs\";\nimport { IReaddirOptions } from \"memfs/lib/node/types/options.js\";\nimport { toArrayBuffer } from \"./to-array-buffer.js\";\nimport type { SysFileSystem } from \"@fireproof/core\";\n\nexport class MemFileSystem implements SysFileSystem {\n async start(): Promise<SysFileSystem> {\n return this;\n }\n mkdir(path: PathLike, options?: { recursive: boolean }): Promise<string | undefined> {\n return fs.promises.mkdir(path, options);\n }\n readdir(path: PathLike, options?: IReaddirOptions): Promise<string[]> {\n return fs.promises.readdir(path, options) as Promise<string[]>;\n }\n rm(path: PathLike, options?: MakeDirectoryOptions & { recursive: boolean }): Promise<void> {\n return fs.promises.rm(path, options);\n }\n copyFile(source: PathLike, destination: PathLike): Promise<void> {\n return fs.promises.copyFile(source, destination);\n }\n async readfile(path: PathLike, options?: { encoding: BufferEncoding; flag?: string }): Promise<Uint8Array> {\n const ret = await fs.promises.readFile(path, options);\n return toArrayBuffer(ret);\n }\n stat(path: PathLike): Promise<Stats> {\n return fs.promises.stat(path) as Promise<Stats>;\n }\n unlink(path: PathLike): Promise<void> {\n return fs.promises.unlink(path);\n }\n writefile(path: PathLike, data: Uint8Array | string): Promise<void> {\n return fs.promises.writeFile(path, Buffer.from(data));\n }\n}\n","export 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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmB;;;ACDZ,SAAS,cAAc,QAAqC;AACjE,MAAI,OAAO,WAAW,UAAU;AAC9B,aAAS,OAAO,KAAK,MAAM;AAAA,EAC7B;AACA,QAAM,KAAK,IAAI,YAAY,OAAO,MAAM;AACxC,QAAM,OAAO,IAAI,WAAW,EAAE;AAC9B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,EAAE,GAAG;AACtC,SAAK,CAAC,IAAI,OAAO,CAAC;AAAA,EACpB;AACA,SAAO;AACT;;;ADJO,IAAM,gBAAN,MAA6C;AAAA,EAClD,MAAM,QAAgC;AACpC,WAAO;AAAA,EACT;AAAA,EACA,MAAM,MAAgB,SAA+D;AACnF,WAAO,gBAAG,SAAS,MAAM,MAAM,OAAO;AAAA,EACxC;AAAA,EACA,QAAQ,MAAgB,SAA8C;AACpE,WAAO,gBAAG,SAAS,QAAQ,MAAM,OAAO;AAAA,EAC1C;AAAA,EACA,GAAG,MAAgB,SAAwE;AACzF,WAAO,gBAAG,SAAS,GAAG,MAAM,OAAO;AAAA,EACrC;AAAA,EACA,SAAS,QAAkB,aAAsC;AAC/D,WAAO,gBAAG,SAAS,SAAS,QAAQ,WAAW;AAAA,EACjD;AAAA,EACA,MAAM,SAAS,MAAgB,SAA4E;AACzG,UAAM,MAAM,MAAM,gBAAG,SAAS,SAAS,MAAM,OAAO;AACpD,WAAO,cAAc,GAAG;AAAA,EAC1B;AAAA,EACA,KAAK,MAAgC;AACnC,WAAO,gBAAG,SAAS,KAAK,IAAI;AAAA,EAC9B;AAAA,EACA,OAAO,MAA+B;AACpC,WAAO,gBAAG,SAAS,OAAO,IAAI;AAAA,EAChC;AAAA,EACA,UAAU,MAAgB,MAA0C;AAClE,WAAO,gBAAG,SAAS,UAAU,MAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACtD;AACF;","names":[]}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import { PathLike, MakeDirectoryOptions, Stats } from 'fs';
|
2
|
-
import { IReaddirOptions } from 'memfs/lib/node/types/options.js';
|
3
|
-
import { SysFileSystem } from '@fireproof/core';
|
4
|
-
|
5
|
-
declare class MemFileSystem implements SysFileSystem {
|
6
|
-
start(): Promise<SysFileSystem>;
|
7
|
-
mkdir(path: PathLike, options?: {
|
8
|
-
recursive: boolean;
|
9
|
-
}): Promise<string | undefined>;
|
10
|
-
readdir(path: PathLike, options?: IReaddirOptions): Promise<string[]>;
|
11
|
-
rm(path: PathLike, options?: MakeDirectoryOptions & {
|
12
|
-
recursive: boolean;
|
13
|
-
}): Promise<void>;
|
14
|
-
copyFile(source: PathLike, destination: PathLike): Promise<void>;
|
15
|
-
readfile(path: PathLike, options?: {
|
16
|
-
encoding: BufferEncoding;
|
17
|
-
flag?: string;
|
18
|
-
}): Promise<Uint8Array>;
|
19
|
-
stat(path: PathLike): Promise<Stats>;
|
20
|
-
unlink(path: PathLike): Promise<void>;
|
21
|
-
writefile(path: PathLike, data: Uint8Array | string): Promise<void>;
|
22
|
-
}
|
23
|
-
|
24
|
-
export { MemFileSystem };
|
25
|
-
declare module '@fireproof/core/node'
|
package/node/mem-filesystem.d.ts
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
import { PathLike, MakeDirectoryOptions, Stats } from 'fs';
|
2
|
-
import { IReaddirOptions } from 'memfs/lib/node/types/options.js';
|
3
|
-
import { SysFileSystem } from '@fireproof/core';
|
4
|
-
|
5
|
-
declare class MemFileSystem implements SysFileSystem {
|
6
|
-
start(): Promise<SysFileSystem>;
|
7
|
-
mkdir(path: PathLike, options?: {
|
8
|
-
recursive: boolean;
|
9
|
-
}): Promise<string | undefined>;
|
10
|
-
readdir(path: PathLike, options?: IReaddirOptions): Promise<string[]>;
|
11
|
-
rm(path: PathLike, options?: MakeDirectoryOptions & {
|
12
|
-
recursive: boolean;
|
13
|
-
}): Promise<void>;
|
14
|
-
copyFile(source: PathLike, destination: PathLike): Promise<void>;
|
15
|
-
readfile(path: PathLike, options?: {
|
16
|
-
encoding: BufferEncoding;
|
17
|
-
flag?: string;
|
18
|
-
}): Promise<Uint8Array>;
|
19
|
-
stat(path: PathLike): Promise<Stats>;
|
20
|
-
unlink(path: PathLike): Promise<void>;
|
21
|
-
writefile(path: PathLike, data: Uint8Array | string): Promise<void>;
|
22
|
-
}
|
23
|
-
|
24
|
-
export { MemFileSystem };
|
25
|
-
declare module '@fireproof/core/node'
|
package/node/node-filesystem.cjs
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
|
30
|
-
// src/runtime/gateways/file/node/node-filesystem.ts
|
31
|
-
var node_filesystem_exports = {};
|
32
|
-
__export(node_filesystem_exports, {
|
33
|
-
NodeFileSystem: () => NodeFileSystem
|
34
|
-
});
|
35
|
-
module.exports = __toCommonJS(node_filesystem_exports);
|
36
|
-
|
37
|
-
// src/runtime/gateways/file/node/to-array-buffer.ts
|
38
|
-
function toArrayBuffer(buffer) {
|
39
|
-
if (typeof buffer === "string") {
|
40
|
-
buffer = Buffer.from(buffer);
|
41
|
-
}
|
42
|
-
const ab = new ArrayBuffer(buffer.length);
|
43
|
-
const view = new Uint8Array(ab);
|
44
|
-
for (let i = 0; i < buffer.length; ++i) {
|
45
|
-
view[i] = buffer[i];
|
46
|
-
}
|
47
|
-
return view;
|
48
|
-
}
|
49
|
-
|
50
|
-
// src/runtime/gateways/file/node/node-filesystem.ts
|
51
|
-
var import_cement = require("@adviser/cement");
|
52
|
-
var NodeFileSystem = class {
|
53
|
-
async start() {
|
54
|
-
this.fs = await import("fs/promises");
|
55
|
-
return this;
|
56
|
-
}
|
57
|
-
async mkdir(path, options) {
|
58
|
-
return this.fs?.mkdir(path, options);
|
59
|
-
}
|
60
|
-
async readdir(path, options) {
|
61
|
-
return this.fs?.readdir(path, options);
|
62
|
-
}
|
63
|
-
async rm(path, options) {
|
64
|
-
return this.fs?.rm(path, options);
|
65
|
-
}
|
66
|
-
async copyFile(source, destination) {
|
67
|
-
return this.fs?.copyFile(source, destination);
|
68
|
-
}
|
69
|
-
async readfile(path, options) {
|
70
|
-
const ret = await this.fs?.readFile(path, options);
|
71
|
-
return toArrayBuffer(ret);
|
72
|
-
}
|
73
|
-
stat(path) {
|
74
|
-
return this.fs?.stat(path);
|
75
|
-
}
|
76
|
-
async unlink(path) {
|
77
|
-
return this.fs?.unlink(path);
|
78
|
-
}
|
79
|
-
async writefile(path, data) {
|
80
|
-
if ((0, import_cement.runtimeFn)().isDeno) {
|
81
|
-
return this.fs?.writeFile(path, data);
|
82
|
-
}
|
83
|
-
return this.fs?.writeFile(path, Buffer.from(data));
|
84
|
-
}
|
85
|
-
};
|
86
|
-
//# sourceMappingURL=node-filesystem.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/gateways/file/node/node-filesystem.ts","../../../src/runtime/gateways/file/node/to-array-buffer.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 \"./to-array-buffer.js\";\nimport type { SysFileSystem } from \"@fireproof/core\";\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","export 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,cAAc,QAAqC;AACjE,MAAI,OAAO,WAAW,UAAU;AAC9B,aAAS,OAAO,KAAK,MAAM;AAAA,EAC7B;AACA,QAAM,KAAK,IAAI,YAAY,OAAO,MAAM;AACxC,QAAM,OAAO,IAAI,WAAW,EAAE;AAC9B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,EAAE,GAAG;AACtC,SAAK,CAAC,IAAI,OAAO,CAAC;AAAA,EACpB;AACA,SAAO;AACT;;;ADNA,oBAA0B;AAEnB,IAAM,iBAAN,MAA8C;AAAA,EAYnD,MAAM,QAAgC;AACpC,SAAK,KAAK,MAAM,OAAO,aAAkB;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,YAAI,yBAAU,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":[]}
|
@@ -1,35 +0,0 @@
|
|
1
|
-
import { PathLike, ObjectEncodingOptions, MakeDirectoryOptions, Stats } from 'node:fs';
|
2
|
-
import { mkdir, readdir, rm, copyFile, readFile, stat, unlink, writeFile } from 'node:fs/promises';
|
3
|
-
import { SysFileSystem } from '@fireproof/core';
|
4
|
-
|
5
|
-
declare class NodeFileSystem implements SysFileSystem {
|
6
|
-
fs?: {
|
7
|
-
mkdir: typeof mkdir;
|
8
|
-
readdir: typeof readdir;
|
9
|
-
rm: typeof rm;
|
10
|
-
copyFile: typeof copyFile;
|
11
|
-
readFile: typeof readFile;
|
12
|
-
stat: typeof stat;
|
13
|
-
unlink: typeof unlink;
|
14
|
-
writeFile: typeof writeFile;
|
15
|
-
};
|
16
|
-
start(): Promise<SysFileSystem>;
|
17
|
-
mkdir(path: PathLike, options?: {
|
18
|
-
recursive: boolean;
|
19
|
-
}): Promise<string | undefined>;
|
20
|
-
readdir(path: PathLike, options?: ObjectEncodingOptions): Promise<string[]>;
|
21
|
-
rm(path: PathLike, options?: MakeDirectoryOptions & {
|
22
|
-
recursive: boolean;
|
23
|
-
}): Promise<void>;
|
24
|
-
copyFile(source: PathLike, destination: PathLike): Promise<void>;
|
25
|
-
readfile(path: PathLike, options?: {
|
26
|
-
encoding: BufferEncoding;
|
27
|
-
flag?: string;
|
28
|
-
}): Promise<Uint8Array>;
|
29
|
-
stat(path: PathLike): Promise<Stats>;
|
30
|
-
unlink(path: PathLike): Promise<void>;
|
31
|
-
writefile(path: PathLike, data: Uint8Array | string): Promise<void>;
|
32
|
-
}
|
33
|
-
|
34
|
-
export { NodeFileSystem };
|
35
|
-
declare module '@fireproof/core/node'
|
@@ -1,35 +0,0 @@
|
|
1
|
-
import { PathLike, ObjectEncodingOptions, MakeDirectoryOptions, Stats } from 'node:fs';
|
2
|
-
import { mkdir, readdir, rm, copyFile, readFile, stat, unlink, writeFile } from 'node:fs/promises';
|
3
|
-
import { SysFileSystem } from '@fireproof/core';
|
4
|
-
|
5
|
-
declare class NodeFileSystem implements SysFileSystem {
|
6
|
-
fs?: {
|
7
|
-
mkdir: typeof mkdir;
|
8
|
-
readdir: typeof readdir;
|
9
|
-
rm: typeof rm;
|
10
|
-
copyFile: typeof copyFile;
|
11
|
-
readFile: typeof readFile;
|
12
|
-
stat: typeof stat;
|
13
|
-
unlink: typeof unlink;
|
14
|
-
writeFile: typeof writeFile;
|
15
|
-
};
|
16
|
-
start(): Promise<SysFileSystem>;
|
17
|
-
mkdir(path: PathLike, options?: {
|
18
|
-
recursive: boolean;
|
19
|
-
}): Promise<string | undefined>;
|
20
|
-
readdir(path: PathLike, options?: ObjectEncodingOptions): Promise<string[]>;
|
21
|
-
rm(path: PathLike, options?: MakeDirectoryOptions & {
|
22
|
-
recursive: boolean;
|
23
|
-
}): Promise<void>;
|
24
|
-
copyFile(source: PathLike, destination: PathLike): Promise<void>;
|
25
|
-
readfile(path: PathLike, options?: {
|
26
|
-
encoding: BufferEncoding;
|
27
|
-
flag?: string;
|
28
|
-
}): Promise<Uint8Array>;
|
29
|
-
stat(path: PathLike): Promise<Stats>;
|
30
|
-
unlink(path: PathLike): Promise<void>;
|
31
|
-
writefile(path: PathLike, data: Uint8Array | string): Promise<void>;
|
32
|
-
}
|
33
|
-
|
34
|
-
export { NodeFileSystem };
|
35
|
-
declare module '@fireproof/core/node'
|
package/node/node-filesystem.js
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
toArrayBuffer
|
3
|
-
} from "./chunk-4A4RAVNS.js";
|
4
|
-
|
5
|
-
// src/runtime/gateways/file/node/node-filesystem.ts
|
6
|
-
import { runtimeFn } from "@adviser/cement";
|
7
|
-
var NodeFileSystem = class {
|
8
|
-
async start() {
|
9
|
-
this.fs = await import("node:fs/promises");
|
10
|
-
return this;
|
11
|
-
}
|
12
|
-
async mkdir(path, options) {
|
13
|
-
return this.fs?.mkdir(path, options);
|
14
|
-
}
|
15
|
-
async readdir(path, options) {
|
16
|
-
return this.fs?.readdir(path, options);
|
17
|
-
}
|
18
|
-
async rm(path, options) {
|
19
|
-
return this.fs?.rm(path, options);
|
20
|
-
}
|
21
|
-
async copyFile(source, destination) {
|
22
|
-
return this.fs?.copyFile(source, destination);
|
23
|
-
}
|
24
|
-
async readfile(path, options) {
|
25
|
-
const ret = await this.fs?.readFile(path, options);
|
26
|
-
return toArrayBuffer(ret);
|
27
|
-
}
|
28
|
-
stat(path) {
|
29
|
-
return this.fs?.stat(path);
|
30
|
-
}
|
31
|
-
async unlink(path) {
|
32
|
-
return this.fs?.unlink(path);
|
33
|
-
}
|
34
|
-
async writefile(path, data) {
|
35
|
-
if (runtimeFn().isDeno) {
|
36
|
-
return this.fs?.writeFile(path, data);
|
37
|
-
}
|
38
|
-
return this.fs?.writeFile(path, Buffer.from(data));
|
39
|
-
}
|
40
|
-
};
|
41
|
-
export {
|
42
|
-
NodeFileSystem
|
43
|
-
};
|
44
|
-
//# sourceMappingURL=node-filesystem.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/gateways/file/node/node-filesystem.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 \"./to-array-buffer.js\";\nimport type { SysFileSystem } from \"@fireproof/core\";\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/utils-ZVVGAXFE.js
DELETED
package/utils-ZVVGAXFE.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/web/gateway-impl.cjs.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/gateways/indexdb/web/gateway-impl.ts","../../../src/runtime/gateways/indexdb/version.ts"],"sourcesContent":["import { openDB, IDBPDatabase } from \"idb\";\nimport { exception2Result, KeyedResolvOnce, Logger, Result, URI } from \"@adviser/cement\";\n\nimport { INDEXDB_VERSION } from \"../version.js\";\nimport { ensureLogger, exceptionWrapper, getKey, getStore, NotFoundError } from \"@fireproof/core\";\nimport type { bs } from \"@fireproof/core\";\nimport type { SuperThis } from \"@fireproof/core\";\n\nfunction ensureVersion(url: URI): URI {\n return url.build().defParam(\"version\", INDEXDB_VERSION).URI();\n}\n\ninterface IDBConn {\n readonly db: IDBPDatabase<unknown>;\n readonly dbName: DbName;\n readonly version: string;\n readonly url: URI;\n}\n\nfunction sanitzeKey(key: string | string[]): string | string[] {\n if (key.length === 1) {\n key = key[0];\n }\n return key;\n}\n\nconst onceConn = new KeyedResolvOnce<IDBConn>();\nasync function connectIdb(url: URI, sthis: SuperThis): Promise<IDBConn> {\n const dbName = getIndexDBName(url, sthis);\n const once = await onceConn.get(dbName.fullDb).once(async () => {\n const db = await openDB(dbName.fullDb, 1, {\n upgrade(db) {\n [\"version\", \"data\", \"wal\", \"meta\", \"idx.data\", \"idx.wal\", \"idx.meta\"].map((store) => {\n db.createObjectStore(store, {\n autoIncrement: false,\n });\n });\n },\n });\n const found = await db.get(\"version\", \"version\");\n const version = ensureVersion(url).getParam(\"version\") as string;\n if (!found) {\n await db.put(\"version\", { version }, \"version\");\n } else if (found.version !== version) {\n sthis.logger.Warn().Str(\"url\", url.toString()).Str(\"version\", version).Str(\"found\", found.version).Msg(\"version mismatch\");\n }\n return { db, dbName, version, url };\n });\n return {\n ...once,\n url: url.build().setParam(\"version\", once.version).URI(),\n };\n}\n\nexport interface DbName {\n readonly fullDb: string;\n readonly objStore: string;\n readonly connectionKey: string;\n readonly dbName: string;\n}\n\nfunction joinDBName(...names: string[]): string {\n return names\n .map((i) => i.replace(/^[^a-zA-Z0-9]+/g, \"\").replace(/[^a-zA-Z0-9-]+/g, \"_\"))\n .filter((i) => i.length)\n .join(\".\");\n}\n\n// const schemaVersion = new Map<string, number>();\nexport function getIndexDBName(iurl: URI, sthis: SuperThis): DbName {\n const url = ensureVersion(iurl);\n const fullDb = url.pathname.replace(/^\\/+/, \"\").replace(/\\?.*$/, \"\"); // cut leading slashes\n // const type = getStore(url);\n // const storageVersion = url.searchParams.get(\"version\");\n // not nice but we need to pass the version to the db name\n // url.searchParams.set(\"version\", storageVersion);\n // console.log(\"getIndexDBName:\", url.toString(), { fullDb, type, branch });\n // const dbName = fullDb.replace(new RegExp(`^fp.${storageVersion}.`), \"\"); // cut fp prefix\n const dbName = url.getParam(\"name\");\n if (!dbName) throw sthis.logger.Error().Str(\"url\", url.toString()).Msg(`name not found`).AsError();\n const result = joinDBName(fullDb, dbName);\n const objStore = getStore(url, sthis, joinDBName).name;\n const connectionKey = [result, objStore].join(\":\");\n return {\n fullDb: result,\n objStore,\n connectionKey,\n dbName,\n };\n}\n\nexport class IndexDBGatewayImpl implements bs.Gateway {\n readonly logger: Logger;\n readonly sthis: SuperThis;\n constructor(sthis: SuperThis) {\n this.logger = ensureLogger(sthis, \"IndexDBGateway\");\n this.sthis = sthis;\n }\n\n // _db: IDBPDatabase<unknown> = {} as IDBPDatabase<unknown>;\n\n async start(baseURL: URI): Promise<Result<URI>> {\n return exception2Result(async () => {\n this.logger.Debug().Url(baseURL).Msg(\"starting\");\n await this.sthis.start();\n const ic = await connectIdb(baseURL, this.sthis);\n this.logger.Debug().Url(ic.url).Msg(\"started\");\n return ic.url;\n });\n }\n async close(): Promise<Result<void>> {\n return Result.Ok(undefined);\n }\n async destroy(baseUrl: URI): Promise<Result<void>> {\n return exception2Result(async () => {\n // return deleteDB(getIndexDBName(this.url).fullDb);\n const type = getStore(baseUrl, this.sthis, joinDBName).name;\n // console.log(\"IndexDBDataStore:destroy\", type);\n const idb = await connectIdb(baseUrl, this.sthis);\n const trans = idb.db.transaction(type, \"readwrite\");\n const object_store = trans.objectStore(type);\n const toDelete = [];\n for (let cursor = await object_store.openCursor(); cursor; cursor = await cursor.continue()) {\n toDelete.push(cursor.primaryKey);\n }\n for (const key of toDelete) {\n await trans.db.delete(type, key);\n }\n await trans.done;\n });\n }\n\n buildUrl(baseUrl: URI, key: string): Promise<Result<URI>> {\n return Promise.resolve(Result.Ok(baseUrl.build().setParam(\"key\", key).URI()));\n }\n\n async get(url: URI): Promise<bs.GetResult> {\n return exceptionWrapper(async () => {\n const key = getKey(url, this.logger);\n const store = getStore(url, this.sthis, joinDBName).name;\n this.logger.Debug().Url(url).Str(\"key\", key).Str(\"store\", store).Msg(\"getting\");\n const { db } = await connectIdb(url, this.sthis);\n const tx = db.transaction([store], \"readonly\");\n const bytes = await tx.objectStore(store).get(sanitzeKey(key));\n await tx.done;\n if (!bytes) {\n return Result.Err(new NotFoundError(`missing ${key}`));\n }\n return Result.Ok(bytes as Uint8Array);\n });\n }\n async put(url: URI, value: Uint8Array) {\n return exception2Result(async () => {\n const key = getKey(url, this.logger);\n const store = getStore(url, this.sthis, joinDBName).name;\n this.logger.Debug().Url(url).Str(\"key\", key).Str(\"store\", store).Msg(\"putting\");\n const { db } = await connectIdb(url, this.sthis);\n const tx = db.transaction([store], \"readwrite\");\n await tx.objectStore(store).put(value, sanitzeKey(key));\n await tx.done;\n });\n }\n async delete(url: URI) {\n return exception2Result(async () => {\n const key = getKey(url, this.logger);\n const store = getStore(url, this.sthis, joinDBName).name;\n this.logger.Debug().Url(url).Str(\"key\", key).Str(\"store\", store).Msg(\"deleting\");\n const { db } = await connectIdb(url, this.sthis);\n const tx = db.transaction([store], \"readwrite\");\n await tx.objectStore(store).delete(sanitzeKey(key));\n await tx.done;\n return Result.Ok(undefined);\n });\n }\n}\n\n// export class IndexDBDataGateway extends IndexDBGateway {\n// readonly storeType = \"data\";\n// constructor(logger: Logger) {\n// super(ensureLogger(logger, \"IndexDBDataGateway\"));\n// }\n// }\n\n// export class IndexDBWalGateway extends IndexDBGateway {\n// readonly storeType = \"wal\";\n// constructor(logger: Logger) {\n// super(ensureLogger(logger, \"IndexDBWalGateway\"));\n// }\n// }\n// export class IndexDBMetaGateway extends IndexDBGateway {\n// readonly storeType = \"meta\";\n// constructor(logger: Logger) {\n// super(ensureLogger(logger, \"IndexDBMetaGateway\"));\n// }\n// }\n\nexport class IndexDBTestStore implements bs.TestGateway {\n readonly logger: Logger;\n readonly sthis: SuperThis;\n constructor(sthis: SuperThis) {\n this.sthis = sthis;\n this.logger = ensureLogger(sthis, \"IndexDBTestStore\", {});\n }\n async get(url: URI, key: string) {\n const ic = await connectIdb(url, this.sthis);\n const store = getStore(ic.url, this.sthis, joinDBName).name;\n this.logger.Debug().Str(\"key\", key).Str(\"store\", store).Msg(\"getting\");\n let bytes = await ic.db.get(store, sanitzeKey(key));\n this.logger.Debug().Str(\"key\", key).Str(\"store\", store).Int(\"len\", bytes.length).Msg(\"got\");\n if (typeof bytes === \"string\") {\n bytes = this.sthis.txt.encode(bytes);\n }\n return bytes as Uint8Array;\n }\n}\n","export const INDEXDB_VERSION = \"v0.19-indexdb\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,i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M,IAAI,KAAU,KAAa;AAC/B,UAAM,KAAK,MAAM,WAAW,KAAK,KAAK,KAAK;AAC3C,UAAM,YAAQ,sBAAS,GAAG,KAAK,KAAK,OAAO,UAAU,EAAE;AACvD,SAAK,OAAO,MAAM,EAAE,IAAI,OAAO,GAAG,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,SAAS;AACrE,QAAI,QAAQ,MAAM,GAAG,GAAG,IAAI,OAAO,WAAW,GAAG,CAAC;AAClD,SAAK,OAAO,MAAM,EAAE,IAAI,OAAO,GAAG,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,OAAO,MAAM,MAAM,EAAE,IAAI,KAAK;AAC1F,QAAI,OAAO,UAAU,UAAU;AAC7B,cAAQ,KAAK,MAAM,IAAI,OAAO,KAAK;AAAA,IACrC;AACA,WAAO;AAAA,EACT;AACF;","names":["db"]}
|
package/web/gateway-impl.d.cts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import { URI, Logger, Result } from '@adviser/cement';
|
2
|
-
import { SuperThis, bs } from '@fireproof/core';
|
3
|
-
|
4
|
-
interface DbName {
|
5
|
-
readonly fullDb: string;
|
6
|
-
readonly objStore: string;
|
7
|
-
readonly connectionKey: string;
|
8
|
-
readonly dbName: string;
|
9
|
-
}
|
10
|
-
declare function getIndexDBName(iurl: URI, sthis: SuperThis): DbName;
|
11
|
-
declare class IndexDBGatewayImpl implements bs.Gateway {
|
12
|
-
readonly logger: Logger;
|
13
|
-
readonly sthis: SuperThis;
|
14
|
-
constructor(sthis: SuperThis);
|
15
|
-
start(baseURL: URI): Promise<Result<URI>>;
|
16
|
-
close(): Promise<Result<void>>;
|
17
|
-
destroy(baseUrl: URI): Promise<Result<void>>;
|
18
|
-
buildUrl(baseUrl: URI, key: string): Promise<Result<URI>>;
|
19
|
-
get(url: URI): Promise<bs.GetResult>;
|
20
|
-
put(url: URI, value: Uint8Array): Promise<Result<void, Error>>;
|
21
|
-
delete(url: URI): Promise<Result<Result<undefined, Error>, Error>>;
|
22
|
-
}
|
23
|
-
declare class IndexDBTestStore implements bs.TestGateway {
|
24
|
-
readonly logger: Logger;
|
25
|
-
readonly sthis: SuperThis;
|
26
|
-
constructor(sthis: SuperThis);
|
27
|
-
get(url: URI, key: string): Promise<Uint8Array<ArrayBufferLike>>;
|
28
|
-
}
|
29
|
-
|
30
|
-
export { type DbName, IndexDBGatewayImpl, IndexDBTestStore, getIndexDBName };
|
31
|
-
declare module '@fireproof/core/web'
|
package/web/gateway-impl.d.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import { URI, Logger, Result } from '@adviser/cement';
|
2
|
-
import { SuperThis, bs } from '@fireproof/core';
|
3
|
-
|
4
|
-
interface DbName {
|
5
|
-
readonly fullDb: string;
|
6
|
-
readonly objStore: string;
|
7
|
-
readonly connectionKey: string;
|
8
|
-
readonly dbName: string;
|
9
|
-
}
|
10
|
-
declare function getIndexDBName(iurl: URI, sthis: SuperThis): DbName;
|
11
|
-
declare class IndexDBGatewayImpl implements bs.Gateway {
|
12
|
-
readonly logger: Logger;
|
13
|
-
readonly sthis: SuperThis;
|
14
|
-
constructor(sthis: SuperThis);
|
15
|
-
start(baseURL: URI): Promise<Result<URI>>;
|
16
|
-
close(): Promise<Result<void>>;
|
17
|
-
destroy(baseUrl: URI): Promise<Result<void>>;
|
18
|
-
buildUrl(baseUrl: URI, key: string): Promise<Result<URI>>;
|
19
|
-
get(url: URI): Promise<bs.GetResult>;
|
20
|
-
put(url: URI, value: Uint8Array): Promise<Result<void, Error>>;
|
21
|
-
delete(url: URI): Promise<Result<Result<undefined, Error>, Error>>;
|
22
|
-
}
|
23
|
-
declare class IndexDBTestStore implements bs.TestGateway {
|
24
|
-
readonly logger: Logger;
|
25
|
-
readonly sthis: SuperThis;
|
26
|
-
constructor(sthis: SuperThis);
|
27
|
-
get(url: URI, key: string): Promise<Uint8Array<ArrayBufferLike>>;
|
28
|
-
}
|
29
|
-
|
30
|
-
export { type DbName, IndexDBGatewayImpl, IndexDBTestStore, getIndexDBName };
|
31
|
-
declare module '@fireproof/core/web'
|
package/web/gateway-impl.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/gateways/indexdb/web/gateway-impl.ts","../../../src/runtime/gateways/indexdb/version.ts"],"sourcesContent":["import { openDB, IDBPDatabase } from \"idb\";\nimport { exception2Result, KeyedResolvOnce, Logger, Result, URI } from \"@adviser/cement\";\n\nimport { INDEXDB_VERSION } from \"../version.js\";\nimport { ensureLogger, exceptionWrapper, getKey, getStore, NotFoundError } from \"@fireproof/core\";\nimport type { bs } from \"@fireproof/core\";\nimport type { SuperThis } from \"@fireproof/core\";\n\nfunction ensureVersion(url: URI): URI {\n return url.build().defParam(\"version\", INDEXDB_VERSION).URI();\n}\n\ninterface IDBConn {\n readonly db: IDBPDatabase<unknown>;\n readonly dbName: DbName;\n readonly version: string;\n readonly url: URI;\n}\n\nfunction sanitzeKey(key: string | string[]): string | string[] {\n if (key.length === 1) {\n key = key[0];\n }\n return key;\n}\n\nconst onceConn = new KeyedResolvOnce<IDBConn>();\nasync function connectIdb(url: URI, sthis: SuperThis): Promise<IDBConn> {\n const dbName = getIndexDBName(url, sthis);\n const once = await onceConn.get(dbName.fullDb).once(async () => {\n const db = await openDB(dbName.fullDb, 1, {\n upgrade(db) {\n [\"version\", \"data\", \"wal\", \"meta\", \"idx.data\", \"idx.wal\", \"idx.meta\"].map((store) => {\n db.createObjectStore(store, {\n autoIncrement: false,\n });\n });\n },\n });\n const found = await db.get(\"version\", \"version\");\n const version = ensureVersion(url).getParam(\"version\") as string;\n if (!found) {\n await db.put(\"version\", { version }, \"version\");\n } else if (found.version !== version) {\n sthis.logger.Warn().Str(\"url\", url.toString()).Str(\"version\", version).Str(\"found\", found.version).Msg(\"version mismatch\");\n }\n return { db, dbName, version, url };\n });\n return {\n ...once,\n url: url.build().setParam(\"version\", once.version).URI(),\n };\n}\n\nexport interface DbName {\n readonly fullDb: string;\n readonly objStore: string;\n readonly connectionKey: string;\n readonly dbName: string;\n}\n\nfunction joinDBName(...names: string[]): string {\n return names\n .map((i) => i.replace(/^[^a-zA-Z0-9]+/g, \"\").replace(/[^a-zA-Z0-9-]+/g, \"_\"))\n .filter((i) => i.length)\n .join(\".\");\n}\n\n// const schemaVersion = new Map<string, number>();\nexport function getIndexDBName(iurl: URI, sthis: SuperThis): DbName {\n const url = ensureVersion(iurl);\n const fullDb = url.pathname.replace(/^\\/+/, \"\").replace(/\\?.*$/, \"\"); // cut leading slashes\n // const type = getStore(url);\n // const storageVersion = url.searchParams.get(\"version\");\n // not nice but we need to pass the version to the db name\n // url.searchParams.set(\"version\", storageVersion);\n // console.log(\"getIndexDBName:\", url.toString(), { fullDb, type, branch });\n // const dbName = fullDb.replace(new RegExp(`^fp.${storageVersion}.`), \"\"); // cut fp prefix\n const dbName = url.getParam(\"name\");\n if (!dbName) throw sthis.logger.Error().Str(\"url\", url.toString()).Msg(`name not found`).AsError();\n const result = joinDBName(fullDb, dbName);\n const objStore = getStore(url, sthis, joinDBName).name;\n const connectionKey = [result, objStore].join(\":\");\n return {\n fullDb: result,\n objStore,\n connectionKey,\n dbName,\n };\n}\n\nexport class IndexDBGatewayImpl implements bs.Gateway {\n readonly logger: Logger;\n readonly sthis: SuperThis;\n constructor(sthis: SuperThis) {\n this.logger = ensureLogger(sthis, \"IndexDBGateway\");\n this.sthis = sthis;\n }\n\n // _db: IDBPDatabase<unknown> = {} as IDBPDatabase<unknown>;\n\n async start(baseURL: URI): Promise<Result<URI>> {\n return exception2Result(async () => {\n this.logger.Debug().Url(baseURL).Msg(\"starting\");\n await this.sthis.start();\n const ic = await connectIdb(baseURL, this.sthis);\n this.logger.Debug().Url(ic.url).Msg(\"started\");\n return ic.url;\n });\n }\n async close(): Promise<Result<void>> {\n return Result.Ok(undefined);\n }\n async destroy(baseUrl: URI): Promise<Result<void>> {\n return exception2Result(async () => {\n // return deleteDB(getIndexDBName(this.url).fullDb);\n const type = getStore(baseUrl, this.sthis, joinDBName).name;\n // console.log(\"IndexDBDataStore:destroy\", type);\n const idb = await connectIdb(baseUrl, this.sthis);\n const trans = idb.db.transaction(type, \"readwrite\");\n const object_store = trans.objectStore(type);\n const toDelete = [];\n for (let cursor = await object_store.openCursor(); cursor; cursor = await cursor.continue()) {\n toDelete.push(cursor.primaryKey);\n }\n for (const key of toDelete) {\n await trans.db.delete(type, key);\n }\n await trans.done;\n });\n }\n\n buildUrl(baseUrl: URI, key: string): Promise<Result<URI>> {\n return Promise.resolve(Result.Ok(baseUrl.build().setParam(\"key\", key).URI()));\n }\n\n async get(url: URI): Promise<bs.GetResult> {\n return exceptionWrapper(async () => {\n const key = getKey(url, this.logger);\n const store = getStore(url, this.sthis, joinDBName).name;\n this.logger.Debug().Url(url).Str(\"key\", key).Str(\"store\", store).Msg(\"getting\");\n const { db } = await connectIdb(url, this.sthis);\n const tx = db.transaction([store], \"readonly\");\n const bytes = await tx.objectStore(store).get(sanitzeKey(key));\n await tx.done;\n if (!bytes) {\n return Result.Err(new NotFoundError(`missing ${key}`));\n }\n return Result.Ok(bytes as Uint8Array);\n });\n }\n async put(url: URI, value: Uint8Array) {\n return exception2Result(async () => {\n const key = getKey(url, this.logger);\n const store = getStore(url, this.sthis, joinDBName).name;\n this.logger.Debug().Url(url).Str(\"key\", key).Str(\"store\", store).Msg(\"putting\");\n const { db } = await connectIdb(url, this.sthis);\n const tx = db.transaction([store], \"readwrite\");\n await tx.objectStore(store).put(value, sanitzeKey(key));\n await tx.done;\n });\n }\n async delete(url: URI) {\n return exception2Result(async () => {\n const key = getKey(url, this.logger);\n const store = getStore(url, this.sthis, joinDBName).name;\n this.logger.Debug().Url(url).Str(\"key\", key).Str(\"store\", store).Msg(\"deleting\");\n const { db } = await connectIdb(url, this.sthis);\n const tx = db.transaction([store], \"readwrite\");\n await tx.objectStore(store).delete(sanitzeKey(key));\n await tx.done;\n return Result.Ok(undefined);\n });\n }\n}\n\n// export class IndexDBDataGateway extends IndexDBGateway {\n// readonly storeType = \"data\";\n// constructor(logger: Logger) {\n// super(ensureLogger(logger, \"IndexDBDataGateway\"));\n// }\n// }\n\n// export class IndexDBWalGateway extends IndexDBGateway {\n// readonly storeType = \"wal\";\n// constructor(logger: Logger) {\n// super(ensureLogger(logger, \"IndexDBWalGateway\"));\n// }\n// }\n// export class IndexDBMetaGateway extends IndexDBGateway {\n// readonly storeType = \"meta\";\n// constructor(logger: Logger) {\n// super(ensureLogger(logger, \"IndexDBMetaGateway\"));\n// }\n// }\n\nexport class IndexDBTestStore implements bs.TestGateway {\n readonly logger: Logger;\n readonly sthis: SuperThis;\n constructor(sthis: SuperThis) {\n this.sthis = sthis;\n this.logger = ensureLogger(sthis, \"IndexDBTestStore\", {});\n }\n async get(url: URI, key: string) {\n const ic = await connectIdb(url, this.sthis);\n const store = getStore(ic.url, this.sthis, joinDBName).name;\n this.logger.Debug().Str(\"key\", key).Str(\"store\", store).Msg(\"getting\");\n let bytes = await ic.db.get(store, sanitzeKey(key));\n this.logger.Debug().Str(\"key\", key).Str(\"store\", store).Int(\"len\", bytes.length).Msg(\"got\");\n if (typeof bytes === \"string\") {\n bytes = this.sthis.txt.encode(bytes);\n }\n return bytes as Uint8Array;\n }\n}\n","export const INDEXDB_VERSION = \"v0.19-indexdb\";\n"],"mappings":";AAAA,SAAS,cAA4B;AACrC,SAAS,kBAAkB,iBAAyB,cAAmB;;;ACDhE,IAAM,kBAAkB;;;ADI/B,SAAS,cAAc,kBAAkB,QAAQ,UAAU,qBAAqB;AAIhF,SAAS,cAAc,KAAe;AACpC,SAAO,IAAI,MAAM,EAAE,SAAS,WAAW,eAAe,EAAE,IAAI;AAC9D;AASA,SAAS,WAAW,KAA2C;AAC7D,MAAI,IAAI,WAAW,GAAG;AACpB,UAAM,IAAI,CAAC;AAAA,EACb;AACA,SAAO;AACT;AAEA,IAAM,WAAW,IAAI,gBAAyB;AAC9C,eAAe,WAAW,KAAU,OAAoC;AACtE,QAAM,SAAS,eAAe,KAAK,KAAK;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