@fireproof/core 0.19.101 → 0.19.102
Sign up to get free protection for your applications and to get access to all the features.
- package/{chunk-3EB3ENHT.js → chunk-OFGPKRCM.js} +25 -54
- package/chunk-OFGPKRCM.js.map +1 -0
- package/chunk-WS3YRPIA.js +75 -0
- package/chunk-WS3YRPIA.js.map +1 -0
- package/{gateway-GK5QZ6KP.js → gateway-5FCWPX5W.js} +12 -13
- package/gateway-5FCWPX5W.js.map +1 -0
- package/{gateway-TQTGDRCN.js → gateway-H7UD6TNB.js} +8 -9
- package/gateway-H7UD6TNB.js.map +1 -0
- package/index.cjs +1571 -1992
- package/index.cjs.map +1 -1
- package/index.d.cts +117 -257
- package/index.d.ts +117 -257
- package/index.global.js +12280 -12741
- package/index.global.js.map +1 -1
- package/index.js +1463 -1790
- package/index.js.map +1 -1
- package/{key-bag-file-VOSSK46F.js → key-bag-file-WADZBHYG.js} +3 -4
- package/{key-bag-file-VOSSK46F.js.map → key-bag-file-WADZBHYG.js.map} +1 -1
- package/{key-bag-indexdb-AXTQOSMC.js → key-bag-indexdb-PGVAI3FJ.js} +3 -4
- package/{key-bag-indexdb-AXTQOSMC.js.map → key-bag-indexdb-PGVAI3FJ.js.map} +1 -1
- package/mem-filesystem-YPPJV7Q2.js +41 -0
- package/mem-filesystem-YPPJV7Q2.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-CFRXFSO7.js → node-filesystem-INX4ZTHE.js} +9 -6
- package/node-filesystem-INX4ZTHE.js.map +1 -0
- package/package.json +1 -1
- package/tests/blockstore/keyed-crypto.test.ts +227 -63
- package/tests/blockstore/loader.test.ts +11 -19
- package/tests/blockstore/store.test.ts +19 -23
- package/tests/blockstore/transaction.test.ts +12 -12
- package/tests/fireproof/all-gateway.test.ts +193 -201
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +316 -324
- package/tests/fireproof/config.test.ts +172 -0
- package/tests/fireproof/crdt.test.ts +16 -67
- package/tests/fireproof/database.test.ts +21 -183
- package/tests/fireproof/fireproof.test.ts +74 -83
- package/tests/fireproof/hello.test.ts +14 -18
- package/tests/fireproof/indexer.test.ts +43 -53
- package/tests/fireproof/utils.test.ts +6 -18
- package/tests/helpers.ts +9 -27
- package/tests/react/useFireproof.test.tsx +1 -1
- package/{utils-STA2C35G.js → utils-QO2HIWGI.js} +3 -4
- package/chunk-3EB3ENHT.js.map +0 -1
- package/chunk-HQ7D3PEU.js +0 -61
- package/chunk-HQ7D3PEU.js.map +0 -1
- package/chunk-PZ5AY32C.js +0 -10
- package/deno-filesystem-Q2IJ7YDR.js +0 -57
- package/deno-filesystem-Q2IJ7YDR.js.map +0 -1
- package/gateway-GK5QZ6KP.js.map +0 -1
- package/gateway-TQTGDRCN.js.map +0 -1
- package/key-bag-memory-LWE6ARPX.js +0 -29
- package/key-bag-memory-LWE6ARPX.js.map +0 -1
- package/node-filesystem-CFRXFSO7.js.map +0 -1
- package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +0 -129
- package/tests/gateway/file/loader-config.test.ts +0 -303
- package/tests/gateway/indexdb/loader-config.test.ts +0 -75
- package/utils-STA2C35G.js.map +0 -1
- /package/tests/fireproof/{fireproof.fixture.ts → fireproof.test.fixture.ts} +0 -0
- /package/{chunk-PZ5AY32C.js.map → utils-QO2HIWGI.js.map} +0 -0
package/gateway-TQTGDRCN.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/gateways/indexdb/gateway.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 \"../../../utils.js\";\nimport { Gateway, GetResult, TestGateway } from \"../../../blockstore/gateway.js\";\nimport { PARAM, SuperThis } from \"../../../types.js\";\n\nfunction ensureVersion(url: URI): URI {\n return url.build().defParam(PARAM.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}\nconst onceIndexDB = new KeyedResolvOnce<IDBConn>();\n\nfunction sanitzeKey(key: string | string[]): string | string[] {\n if (key.length === 1) {\n key = key[0];\n }\n return key;\n}\n\nasync function connectIdb(url: URI, sthis: SuperThis): Promise<IDBConn> {\n const dbName = getIndexDBName(url, sthis);\n const once = await onceIndexDB.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(PARAM.VERSION) as string;\n if (!found) {\n await db.put(\"version\", { version }, \"version\");\n } else if (found.version !== version) {\n sthis.logger.Warn().Url(url).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(PARAM.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(PARAM.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 IndexDBGateway implements 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 _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._db = ic.db;\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 = this._db;\n const trans = idb.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(PARAM.KEY, key).URI()));\n }\n\n async get(url: URI): Promise<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 tx = this._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 tx = this._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 tx = this._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 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"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,cAA4B;AACrC,SAAS,kBAAkB,iBAAyB,cAAmB;AAOvE,SAAS,cAAc,KAAe;AACpC,SAAO,IAAI,MAAM,EAAE,kCAAwB,eAAe,EAAE,IAAI;AAClE;AAQA,IAAM,cAAc,IAAI,gBAAyB;AAEjD,SAAS,WAAW,KAA2C;AAC7D,MAAI,IAAI,WAAW,GAAG;AACpB,UAAM,IAAI,CAAC;AAAA,EACb;AACA,SAAO;AACT;AAEA,eAAe,WAAW,KAAU,OAAoC;AACtE,QAAM,SAAS,eAAe,KAAK,KAAK;AACxC,QAAM,OAAO,MAAM,YAAY,IAAI,OAAO,MAAM,EAAE,KAAK,YAAY;AACjE,UAAM,KAAK,MAAM,OAAO,OAAO,QAAQ,GAAG;AAAA,MACxC,QAAQA,KAAI;AACV,SAAC,WAAW,QAAQ,OAAO,QAAQ,YAAY,WAAW,UAAU,EAAE,IAAI,CAAC,UAAU;AACnF,UAAAA,IAAG,kBAAkB,OAAO;AAAA,YAC1B,eAAe;AAAA,UACjB,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AACD,UAAM,QAAQ,MAAM,GAAG,IAAI,WAAW,SAAS;AAC/C,UAAM,UAAU,cAAc,GAAG,EAAE,gCAAsB;AACzD,QAAI,CAAC,OAAO;AACV,YAAM,GAAG,IAAI,WAAW,EAAE,QAAQ,GAAG,SAAS;AAAA,IAChD,WAAW,MAAM,YAAY,SAAS;AACpC,YAAM,OAAO,KAAK,EAAE,IAAI,G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AAK,SAAS,aAAa,OAAO,oBAAoB,CAAC,CAAC;AAAA,EAC1D;AAAA,EACA,MAAM,IAAI,KAAU,KAAa;AAC/B,UAAM,KAAK,MAAM,WAAW,KAAK,KAAK,KAAK;AAC3C,UAAM,QAAQ,SAAS,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"]}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import "./chunk-PZ5AY32C.js";
|
2
|
-
|
3
|
-
// src/runtime/key-bag-memory.ts
|
4
|
-
var memoryKeyBag = /* @__PURE__ */ new Map();
|
5
|
-
var KeyBagProviderMemory = class {
|
6
|
-
constructor(url, sthis) {
|
7
|
-
this.url = url;
|
8
|
-
this.sthis = sthis;
|
9
|
-
}
|
10
|
-
key(id) {
|
11
|
-
return `${this.url.pathname}/${id}`;
|
12
|
-
}
|
13
|
-
async get(id) {
|
14
|
-
const binKeyItem = memoryKeyBag.get(this.key(id));
|
15
|
-
if (binKeyItem) {
|
16
|
-
const ki = JSON.parse(this.sthis.txt.decode(binKeyItem));
|
17
|
-
return ki;
|
18
|
-
}
|
19
|
-
return void 0;
|
20
|
-
}
|
21
|
-
async set(id, item) {
|
22
|
-
const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));
|
23
|
-
memoryKeyBag.set(this.key(id), p);
|
24
|
-
}
|
25
|
-
};
|
26
|
-
export {
|
27
|
-
KeyBagProviderMemory
|
28
|
-
};
|
29
|
-
//# sourceMappingURL=key-bag-memory-LWE6ARPX.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/key-bag-memory.ts"],"sourcesContent":["import { URI } from \"@adviser/cement\";\nimport { KeyBagProvider, KeyItem } from \"./key-bag.js\";\nimport { SuperThis } from \"../types.js\";\n\nconst memoryKeyBag = new Map<string, Uint8Array>();\n\nexport class KeyBagProviderMemory implements KeyBagProvider {\n private readonly url: URI;\n readonly sthis: SuperThis;\n constructor(url: URI, sthis: SuperThis) {\n this.url = url;\n this.sthis = sthis;\n }\n key(id: string): string {\n return `${this.url.pathname}/${id}`;\n }\n\n async get(id: string): Promise<KeyItem | undefined> {\n const binKeyItem = memoryKeyBag.get(this.key(id));\n if (binKeyItem) {\n const ki = JSON.parse(this.sthis.txt.decode(binKeyItem)) as KeyItem;\n return ki;\n }\n return undefined;\n }\n\n async set(id: string, item: KeyItem): Promise<void> {\n const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));\n memoryKeyBag.set(this.key(id), p);\n }\n}\n"],"mappings":";;;AAIA,IAAM,eAAe,oBAAI,IAAwB;AAE1C,IAAM,uBAAN,MAAqD;AAAA,EAG1D,YAAY,KAAU,OAAkB;AACtC,SAAK,MAAM;AACX,SAAK,QAAQ;AAAA,EACf;AAAA,EACA,IAAI,IAAoB;AACtB,WAAO,GAAG,KAAK,IAAI,QAAQ,IAAI,EAAE;AAAA,EACnC;AAAA,EAEA,MAAM,IAAI,IAA0C;AAClD,UAAM,aAAa,aAAa,IAAI,KAAK,IAAI,EAAE,CAAC;AAChD,QAAI,YAAY;AACd,YAAM,KAAK,KAAK,MAAM,KAAK,MAAM,IAAI,OAAO,UAAU,CAAC;AACvD,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,IAAI,IAAY,MAA8B;AAClD,UAAM,IAAI,KAAK,MAAM,IAAI,OAAO,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;AAC7D,iBAAa,IAAI,KAAK,IAAI,EAAE,GAAG,CAAC;AAAA,EAClC;AACF;","names":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/gateways/file/node-filesystem.ts"],"sourcesContent":["import type { PathLike, MakeDirectoryOptions, ObjectEncodingOptions } from \"fs\";\nimport type { mkdir, readdir, rm, copyFile, readFile, stat, unlink, writeFile } from \"fs/promises\";\nimport { toArrayBuffer } from \"./utils.js\";\nimport { FPStats, SysFileSystem } from \"../../../types.js\";\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(\"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<FPStats> {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.fs!.stat(path);\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 return this.fs?.writeFile(path, Buffer.from(data));\n }\n}\n"],"mappings":";;;;;;;AAKO,IAAM,iBAAN,MAA8C;AAAA,EAYnD,MAAM,QAAgC;AACpC,SAAK,KAAK,MAAM,OAAO,aAAa;AACpC,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,MAAkC;AAErC,WAAO,KAAK,GAAI,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,WAAO,KAAK,IAAI,UAAU,MAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACnD;AACF;","names":[]}
|
@@ -1,129 +0,0 @@
|
|
1
|
-
import { bs, PARAM, rt } from "@fireproof/core";
|
2
|
-
import { runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
|
3
|
-
import { base58btc } from "multiformats/bases/base58";
|
4
|
-
import { mockSuperThis } from "../helpers";
|
5
|
-
|
6
|
-
describe("KeyBag indexdb and file", () => {
|
7
|
-
let url: URI;
|
8
|
-
const sthis = mockSuperThis();
|
9
|
-
beforeAll(async () => {
|
10
|
-
await sthis.start();
|
11
|
-
if (runtimeFn().isBrowser) {
|
12
|
-
url = URI.from("indexdb://fp-keybag");
|
13
|
-
} else {
|
14
|
-
url = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
15
|
-
}
|
16
|
-
});
|
17
|
-
it("default-path", async () => {
|
18
|
-
const old = sthis.env.get("FP_KEYBAG_URL");
|
19
|
-
sthis.env.delete("FP_KEYBAG_URL");
|
20
|
-
const kb = await rt.kb.getKeyBag(sthis);
|
21
|
-
if (runtimeFn().isBrowser) {
|
22
|
-
expect(kb.rt.url.toString()).toBe(`indexdb://fp-keybag`);
|
23
|
-
} else {
|
24
|
-
expect(kb.rt.url.toString()).toBe(`file://${sthis.env.get("HOME")}/.fireproof/keybag`);
|
25
|
-
}
|
26
|
-
sthis.env.set("FP_KEYBAG_URL", old);
|
27
|
-
});
|
28
|
-
it("from env", async () => {
|
29
|
-
const old = sthis.env.get("FP_KEYBAG_URL");
|
30
|
-
sthis.env.set("FP_KEYBAG_URL", url.toString());
|
31
|
-
const kb = await rt.kb.getKeyBag(sthis);
|
32
|
-
expect(kb.rt.url.toString()).toBe(url.toString());
|
33
|
-
sthis.env.set("FP_KEYBAG_URL", old);
|
34
|
-
});
|
35
|
-
it("simple add", async () => {
|
36
|
-
const kb = await rt.kb.getKeyBag(sthis, {
|
37
|
-
url: url.toString(),
|
38
|
-
crypto: toCryptoRuntime({
|
39
|
-
randomBytes: (size) => new Uint8Array(size).map((_, i) => i),
|
40
|
-
}),
|
41
|
-
});
|
42
|
-
const name = "setkey" + Math.random();
|
43
|
-
expect((await kb.getNamedKey(name, true)).isErr()).toBeTruthy();
|
44
|
-
|
45
|
-
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
46
|
-
const res = await kb.setNamedKey(name, key);
|
47
|
-
expect(res.isOk()).toBeTruthy();
|
48
|
-
expect((await kb.getNamedKey(name, true)).Ok()).toEqual(res.Ok());
|
49
|
-
|
50
|
-
const name2 = "implicit";
|
51
|
-
const created = await kb.getNamedKey(name2);
|
52
|
-
expect(created.isOk()).toBeTruthy();
|
53
|
-
|
54
|
-
expect((await kb.getNamedKey(name2)).Ok()).toEqual(created.Ok());
|
55
|
-
|
56
|
-
let diskBag: rt.kb.KeyItem;
|
57
|
-
let diskBag2: rt.kb.KeyItem;
|
58
|
-
const provider = await kb.rt.getBag();
|
59
|
-
if (runtimeFn().isBrowser) {
|
60
|
-
const p = provider as rt.kb.KeyBagProviderIndexDB;
|
61
|
-
diskBag = await p._prepare().then((db) => db.get("bag", name));
|
62
|
-
diskBag2 = await p._prepare().then((db) => db.get("bag", name2));
|
63
|
-
} else {
|
64
|
-
const p = provider as rt.kb.KeyBagProviderFile;
|
65
|
-
const { sysFS } = await p._prepare(name);
|
66
|
-
|
67
|
-
diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
|
68
|
-
return JSON.parse(new TextDecoder().decode(data)) as rt.kb.KeyItem;
|
69
|
-
});
|
70
|
-
diskBag2 = await sysFS.readfile((await p._prepare(name2)).fName).then((data) => {
|
71
|
-
return JSON.parse(new TextDecoder().decode(data)) as rt.kb.KeyItem;
|
72
|
-
});
|
73
|
-
}
|
74
|
-
expect(await kb.toKeyWithFingerPrint(diskBag.key)).toEqual(res);
|
75
|
-
expect(await kb.toKeyWithFingerPrint(diskBag2.key)).toEqual(created);
|
76
|
-
const algo = {
|
77
|
-
name: "AES-GCM",
|
78
|
-
iv: kb.rt.crypto.randomBytes(12),
|
79
|
-
tagLength: 128,
|
80
|
-
};
|
81
|
-
const data = kb.rt.crypto.randomBytes(122);
|
82
|
-
expect(await kb.rt.crypto.encrypt(algo, res.Ok().key, data)).toEqual(await kb.rt.crypto.encrypt(algo, created.Ok().key, data));
|
83
|
-
expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(diskBag.key), data)).toEqual(
|
84
|
-
await kb.rt.crypto.encrypt(algo, created.Ok().key, data),
|
85
|
-
);
|
86
|
-
expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(diskBag2.key), data)).toEqual(
|
87
|
-
await kb.rt.crypto.encrypt(algo, created.Ok().key, data),
|
88
|
-
);
|
89
|
-
});
|
90
|
-
});
|
91
|
-
|
92
|
-
describe("KeyedCryptoStore", () => {
|
93
|
-
let kb: rt.kb.KeyBag;
|
94
|
-
// let logger: Logger;
|
95
|
-
let baseUrl: URI;
|
96
|
-
const sthis = mockSuperThis();
|
97
|
-
beforeEach(async () => {
|
98
|
-
await sthis.start();
|
99
|
-
// logger = MockLogger().logger;
|
100
|
-
let kbUrl: URI;
|
101
|
-
if (runtimeFn().isBrowser) {
|
102
|
-
kbUrl = URI.from("indexdb://fp-keybag");
|
103
|
-
baseUrl = URI.from("indexdb://fp-keyed-crypto-store");
|
104
|
-
} else {
|
105
|
-
kbUrl = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
106
|
-
baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
|
107
|
-
}
|
108
|
-
baseUrl = baseUrl.build().defParam(PARAM.NAME, "test").URI();
|
109
|
-
kb = await rt.kb.getKeyBag(sthis, {
|
110
|
-
url: kbUrl,
|
111
|
-
});
|
112
|
-
});
|
113
|
-
it("no crypto", async () => {
|
114
|
-
const strt = bs.toStoreRuntime(sthis);
|
115
|
-
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
|
116
|
-
|
117
|
-
for (const pstore of [
|
118
|
-
strt.makeDataStore({ sthis, url, keybag: kb }),
|
119
|
-
strt.makeMetaStore({ sthis, url, keybag: kb }),
|
120
|
-
strt.makeWALStore({ sthis, url, keybag: kb }),
|
121
|
-
]) {
|
122
|
-
const store = await pstore;
|
123
|
-
// await store.start();
|
124
|
-
const kc = await store.keyedCrypto();
|
125
|
-
expect(kc.constructor.name).toBe("noCrypto");
|
126
|
-
// expect(kc.isEncrypting).toBe(false);
|
127
|
-
}
|
128
|
-
});
|
129
|
-
});
|
@@ -1,303 +0,0 @@
|
|
1
|
-
import { BuildURI, CoerceURI, URI } from "@adviser/cement";
|
2
|
-
import { fireproof, PARAM, rt, SuperThis } from "@fireproof/core";
|
3
|
-
import { mockSuperThis } from "../../helpers";
|
4
|
-
|
5
|
-
function dataDir(sthis: SuperThis, name?: string, base?: CoerceURI): URI {
|
6
|
-
if (!base) {
|
7
|
-
const home = sthis.env.get("HOME") || "./";
|
8
|
-
base =
|
9
|
-
sthis.env.get("FP_STORAGE_URL") ||
|
10
|
-
`file://${sthis.pathOps.join(home, ".fireproof", rt.FILESTORE_VERSION.replace(/-.*$/, ""))}?${PARAM.URL_GEN}=default`;
|
11
|
-
}
|
12
|
-
return URI.from(base.toString())
|
13
|
-
.build()
|
14
|
-
.setParam(PARAM.NAME, name || "")
|
15
|
-
.URI();
|
16
|
-
}
|
17
|
-
|
18
|
-
const _my_app = "my-app";
|
19
|
-
function my_app() {
|
20
|
-
return _my_app;
|
21
|
-
}
|
22
|
-
|
23
|
-
describe("config file gateway", () => {
|
24
|
-
const sthis = mockSuperThis();
|
25
|
-
const isMemFS: { fs?: string } = {};
|
26
|
-
|
27
|
-
beforeAll(async () => {
|
28
|
-
await sthis.start();
|
29
|
-
const url = URI.from(sthis.env.get("FP_STORAGE_URL"));
|
30
|
-
if (url.getParam("fs") === "mem") {
|
31
|
-
isMemFS.fs = "mem";
|
32
|
-
}
|
33
|
-
});
|
34
|
-
|
35
|
-
it("loader", async () => {
|
36
|
-
const db = fireproof(my_app());
|
37
|
-
await db.put({ name: "my-app" });
|
38
|
-
expect(db.name()).toBe(my_app());
|
39
|
-
|
40
|
-
const fileStore = await db.crdt.blockstore.loader?.fileStore();
|
41
|
-
expect(fileStore?.url().asObj()).toEqual({
|
42
|
-
pathname: "./dist/fp-dir-file",
|
43
|
-
protocol: "file:",
|
44
|
-
searchParams: {
|
45
|
-
...isMemFS,
|
46
|
-
name: "my-app",
|
47
|
-
store: "data",
|
48
|
-
storekey: "@my-app-data@",
|
49
|
-
urlGen: "fromEnv",
|
50
|
-
version: "v0.19-file",
|
51
|
-
},
|
52
|
-
style: "path",
|
53
|
-
});
|
54
|
-
|
55
|
-
const dataStore = await db.crdt.blockstore.loader?.carStore();
|
56
|
-
expect(dataStore?.url().asObj()).toEqual({
|
57
|
-
pathname: "./dist/fp-dir-file",
|
58
|
-
protocol: "file:",
|
59
|
-
searchParams: {
|
60
|
-
...isMemFS,
|
61
|
-
name: "my-app",
|
62
|
-
store: "data",
|
63
|
-
suffix: ".car",
|
64
|
-
storekey: "@my-app-data@",
|
65
|
-
urlGen: "fromEnv",
|
66
|
-
version: "v0.19-file",
|
67
|
-
},
|
68
|
-
style: "path",
|
69
|
-
});
|
70
|
-
const metaStore = await db.crdt.blockstore.loader?.metaStore();
|
71
|
-
expect(metaStore?.url().asObj()).toEqual({
|
72
|
-
pathname: "./dist/fp-dir-file",
|
73
|
-
protocol: "file:",
|
74
|
-
searchParams: {
|
75
|
-
...isMemFS,
|
76
|
-
name: "my-app",
|
77
|
-
store: "meta",
|
78
|
-
storekey: "@my-app-meta@",
|
79
|
-
urlGen: "fromEnv",
|
80
|
-
version: "v0.19-file",
|
81
|
-
},
|
82
|
-
style: "path",
|
83
|
-
});
|
84
|
-
const WALStore = await db.crdt.blockstore.loader?.WALStore();
|
85
|
-
expect(WALStore?.url().asObj()).toEqual({
|
86
|
-
pathname: "./dist/fp-dir-file",
|
87
|
-
protocol: "file:",
|
88
|
-
searchParams: {
|
89
|
-
...isMemFS,
|
90
|
-
name: "my-app",
|
91
|
-
store: "wal",
|
92
|
-
storekey: "@my-app-wal@",
|
93
|
-
urlGen: "fromEnv",
|
94
|
-
version: "v0.19-file",
|
95
|
-
},
|
96
|
-
style: "path",
|
97
|
-
});
|
98
|
-
await db.close();
|
99
|
-
});
|
100
|
-
|
101
|
-
it("file path", async () => {
|
102
|
-
let baseDir = "./dist/data".replace(/\?.*$/, "").replace(/^file:\/\//, "");
|
103
|
-
baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
|
104
|
-
const base = BuildURI.from("./dist/data");
|
105
|
-
if (isMemFS.fs) {
|
106
|
-
base.setParam("fs", isMemFS.fs);
|
107
|
-
}
|
108
|
-
const sysfs = await rt.getFileSystem(base.URI());
|
109
|
-
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
110
|
-
/* */
|
111
|
-
});
|
112
|
-
|
113
|
-
const db = fireproof(my_app(), { storeUrls: { base } });
|
114
|
-
// console.log(`>>>>>>>>>>>>>>>file-path`)
|
115
|
-
await db.put({ name: "my-app" });
|
116
|
-
expect(db.name()).toBe(my_app());
|
117
|
-
const carStore = await db.crdt.blockstore.loader?.carStore();
|
118
|
-
expect(carStore?.url().asObj()).toEqual({
|
119
|
-
pathname: "./dist/data",
|
120
|
-
protocol: "file:",
|
121
|
-
searchParams: {
|
122
|
-
...isMemFS,
|
123
|
-
name: "my-app",
|
124
|
-
store: "data",
|
125
|
-
storekey: "@my-app-data@",
|
126
|
-
suffix: ".car",
|
127
|
-
version: "v0.19-file",
|
128
|
-
},
|
129
|
-
style: "path",
|
130
|
-
});
|
131
|
-
const fileStore = await db.crdt.blockstore.loader?.fileStore();
|
132
|
-
expect(fileStore?.url().asObj()).toEqual({
|
133
|
-
pathname: "./dist/data",
|
134
|
-
protocol: "file:",
|
135
|
-
searchParams: {
|
136
|
-
...isMemFS,
|
137
|
-
name: "my-app",
|
138
|
-
store: "data",
|
139
|
-
storekey: "@my-app-data@",
|
140
|
-
version: "v0.19-file",
|
141
|
-
},
|
142
|
-
style: "path",
|
143
|
-
});
|
144
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
145
|
-
const metaStore = await db.crdt.blockstore.loader?.metaStore();
|
146
|
-
expect(metaStore?.url().asObj()).toEqual({
|
147
|
-
pathname: "./dist/data",
|
148
|
-
protocol: "file:",
|
149
|
-
searchParams: {
|
150
|
-
...isMemFS,
|
151
|
-
name: "my-app",
|
152
|
-
store: "meta",
|
153
|
-
storekey: "@my-app-meta@",
|
154
|
-
version: "v0.19-file",
|
155
|
-
},
|
156
|
-
style: "path",
|
157
|
-
});
|
158
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
159
|
-
await db.close();
|
160
|
-
});
|
161
|
-
|
162
|
-
it("homedir default", async () => {
|
163
|
-
const old = sthis.env.get("FP_STORAGE_URL");
|
164
|
-
sthis.env.delete("FP_STORAGE_URL");
|
165
|
-
// this switches file: protocol not memory:
|
166
|
-
let baseDir = dataDir(sthis, my_app()).pathname;
|
167
|
-
baseDir = sthis.pathOps.join(baseDir, my_app());
|
168
|
-
|
169
|
-
const base = BuildURI.from(baseDir);
|
170
|
-
if (isMemFS.fs) {
|
171
|
-
base.setParam("fs", isMemFS.fs);
|
172
|
-
}
|
173
|
-
const sysfs = await rt.getFileSystem(base.URI());
|
174
|
-
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
175
|
-
/* */
|
176
|
-
});
|
177
|
-
|
178
|
-
expect(baseDir).toMatch(new RegExp(`/\\.fireproof/${rt.FILESTORE_VERSION.replace(/-file/, "")}/${my_app()}`));
|
179
|
-
|
180
|
-
const db = fireproof(my_app());
|
181
|
-
await db.put({ name: "my-app" });
|
182
|
-
expect(db.name()).toBe(my_app());
|
183
|
-
const carStore = await db.crdt.blockstore.loader?.carStore();
|
184
|
-
|
185
|
-
expect(carStore?.url().asObj()).toEqual({
|
186
|
-
pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
|
187
|
-
protocol: "file:",
|
188
|
-
style: "path",
|
189
|
-
searchParams: {
|
190
|
-
...isMemFS,
|
191
|
-
suffix: ".car",
|
192
|
-
urlGen: "default",
|
193
|
-
store: "data",
|
194
|
-
name: my_app(),
|
195
|
-
storekey: `@${my_app()}-data@`,
|
196
|
-
version: rt.FILESTORE_VERSION,
|
197
|
-
},
|
198
|
-
});
|
199
|
-
|
200
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
201
|
-
|
202
|
-
const fileStore = await db.crdt.blockstore.loader?.fileStore();
|
203
|
-
expect(fileStore?.url().asObj()).toEqual({
|
204
|
-
pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
|
205
|
-
protocol: "file:",
|
206
|
-
style: "path",
|
207
|
-
searchParams: {
|
208
|
-
...isMemFS,
|
209
|
-
urlGen: "default",
|
210
|
-
store: "data",
|
211
|
-
name: my_app(),
|
212
|
-
storekey: `@${my_app()}-data@`,
|
213
|
-
version: rt.FILESTORE_VERSION,
|
214
|
-
},
|
215
|
-
});
|
216
|
-
const metaStore = await db.crdt.blockstore.loader?.metaStore();
|
217
|
-
expect(metaStore?.url().asObj()).toEqual({
|
218
|
-
pathname: `${sthis.env.get("HOME")}/.fireproof/v0.19`,
|
219
|
-
protocol: "file:",
|
220
|
-
style: "path",
|
221
|
-
searchParams: {
|
222
|
-
...isMemFS,
|
223
|
-
urlGen: "default",
|
224
|
-
store: "meta",
|
225
|
-
name: my_app(),
|
226
|
-
storekey: `@${my_app()}-meta@`,
|
227
|
-
version: rt.FILESTORE_VERSION,
|
228
|
-
},
|
229
|
-
});
|
230
|
-
|
231
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
232
|
-
sthis.env.set("FP_STORAGE_URL", old);
|
233
|
-
await db.close();
|
234
|
-
});
|
235
|
-
|
236
|
-
it("set by env", async () => {
|
237
|
-
const old = sthis.env.get("FP_STORAGE_URL");
|
238
|
-
// assert(!old, "FP_STORAGE_URL must set")
|
239
|
-
const testUrl = BuildURI.from(old);
|
240
|
-
// sthis.env.set("FP_STORAGE_URL", testUrl.toString());
|
241
|
-
|
242
|
-
let baseDir = dataDir(sthis, my_app()).pathname;
|
243
|
-
baseDir = sthis.pathOps.join(baseDir, /* testCfg(sthis, "data").version, */ my_app());
|
244
|
-
|
245
|
-
const sysfs = await rt.getFileSystem(testUrl.URI());
|
246
|
-
await sysfs.rm(baseDir, { recursive: true }).catch(() => {
|
247
|
-
/* */
|
248
|
-
});
|
249
|
-
|
250
|
-
const db = fireproof(my_app());
|
251
|
-
await db.put({ name: "my-app" });
|
252
|
-
expect(db.name()).toBe(my_app());
|
253
|
-
const carStore = await db.crdt.blockstore.loader?.carStore();
|
254
|
-
expect(carStore?.url().asObj()).toEqual({
|
255
|
-
pathname: "./dist/fp-dir-file",
|
256
|
-
protocol: "file:",
|
257
|
-
style: "path",
|
258
|
-
searchParams: {
|
259
|
-
...isMemFS,
|
260
|
-
urlGen: "fromEnv",
|
261
|
-
store: "data",
|
262
|
-
suffix: ".car",
|
263
|
-
name: my_app(),
|
264
|
-
storekey: `@${my_app()}-data@`,
|
265
|
-
version: rt.FILESTORE_VERSION,
|
266
|
-
},
|
267
|
-
});
|
268
|
-
|
269
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "data"))).isDirectory()).toBeTruthy();
|
270
|
-
const fileStore = await db.crdt.blockstore.loader?.fileStore();
|
271
|
-
expect(fileStore?.url().asObj()).toEqual({
|
272
|
-
pathname: `./dist/fp-dir-file`,
|
273
|
-
protocol: "file:",
|
274
|
-
style: "path",
|
275
|
-
searchParams: {
|
276
|
-
...isMemFS,
|
277
|
-
urlGen: "fromEnv",
|
278
|
-
store: "data",
|
279
|
-
name: my_app(),
|
280
|
-
storekey: `@${my_app()}-data@`,
|
281
|
-
version: rt.FILESTORE_VERSION,
|
282
|
-
},
|
283
|
-
});
|
284
|
-
|
285
|
-
const metaStore = await db.crdt.blockstore.loader?.metaStore();
|
286
|
-
expect(metaStore?.url().asObj()).toEqual({
|
287
|
-
pathname: `./dist/fp-dir-file`,
|
288
|
-
protocol: "file:",
|
289
|
-
style: "path",
|
290
|
-
searchParams: {
|
291
|
-
...isMemFS,
|
292
|
-
urlGen: "fromEnv",
|
293
|
-
store: "meta",
|
294
|
-
name: my_app(),
|
295
|
-
storekey: `@${my_app()}-meta@`,
|
296
|
-
version: rt.FILESTORE_VERSION,
|
297
|
-
},
|
298
|
-
});
|
299
|
-
expect((await sysfs.stat(sthis.pathOps.join(baseDir, "meta"))).isDirectory()).toBeTruthy();
|
300
|
-
await db.close();
|
301
|
-
sthis.env.set("FP_STORAGE_URL", old);
|
302
|
-
});
|
303
|
-
});
|
@@ -1,75 +0,0 @@
|
|
1
|
-
import { fireproof } from "@fireproof/core";
|
2
|
-
import { mockSuperThis } from "../../helpers";
|
3
|
-
|
4
|
-
describe("fireproof config indexdb", () => {
|
5
|
-
const _my_app = "my-app";
|
6
|
-
function my_app() {
|
7
|
-
return _my_app;
|
8
|
-
}
|
9
|
-
const sthis = mockSuperThis();
|
10
|
-
beforeAll(async () => {
|
11
|
-
await sthis.start();
|
12
|
-
});
|
13
|
-
|
14
|
-
it("indexdb-loader", async () => {
|
15
|
-
const db = fireproof(my_app());
|
16
|
-
await db.put({ name: "my-app" });
|
17
|
-
expect(db.name()).toBe(my_app());
|
18
|
-
|
19
|
-
const fileStore = await db.crdt.blockstore.loader?.fileStore();
|
20
|
-
expect(fileStore?.url().asObj()).toEqual({
|
21
|
-
pathname: "fp",
|
22
|
-
protocol: "indexdb:",
|
23
|
-
searchParams: {
|
24
|
-
name: "my-app",
|
25
|
-
store: "data",
|
26
|
-
storekey: "@my-app-data@",
|
27
|
-
urlGen: "default",
|
28
|
-
version: "v0.19-indexdb",
|
29
|
-
},
|
30
|
-
style: "path",
|
31
|
-
});
|
32
|
-
|
33
|
-
const dataStore = await db.crdt.blockstore.loader?.carStore();
|
34
|
-
expect(dataStore?.url().asObj()).toEqual({
|
35
|
-
pathname: "fp",
|
36
|
-
protocol: "indexdb:",
|
37
|
-
searchParams: {
|
38
|
-
name: "my-app",
|
39
|
-
store: "data",
|
40
|
-
storekey: "@my-app-data@",
|
41
|
-
suffix: ".car",
|
42
|
-
urlGen: "default",
|
43
|
-
version: "v0.19-indexdb",
|
44
|
-
},
|
45
|
-
style: "path",
|
46
|
-
});
|
47
|
-
const metaStore = await db.crdt.blockstore.loader?.metaStore();
|
48
|
-
expect(metaStore?.url().asObj()).toEqual({
|
49
|
-
pathname: "fp",
|
50
|
-
protocol: "indexdb:",
|
51
|
-
searchParams: {
|
52
|
-
name: "my-app",
|
53
|
-
store: "meta",
|
54
|
-
storekey: "@my-app-meta@",
|
55
|
-
urlGen: "default",
|
56
|
-
version: "v0.19-indexdb",
|
57
|
-
},
|
58
|
-
style: "path",
|
59
|
-
});
|
60
|
-
const WALStore = await db.crdt.blockstore.loader?.WALStore();
|
61
|
-
expect(WALStore?.url().asObj()).toEqual({
|
62
|
-
pathname: "fp",
|
63
|
-
protocol: "indexdb:",
|
64
|
-
searchParams: {
|
65
|
-
name: "my-app",
|
66
|
-
store: "wal",
|
67
|
-
storekey: "@my-app-wal@",
|
68
|
-
urlGen: "default",
|
69
|
-
version: "v0.19-indexdb",
|
70
|
-
},
|
71
|
-
style: "path",
|
72
|
-
});
|
73
|
-
await db.close();
|
74
|
-
});
|
75
|
-
});
|
package/utils-STA2C35G.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
File without changes
|
File without changes
|