@fireproof/core-types-base 0.23.1 → 0.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../jsr/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
package/indexer.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"indexer.js","sourceRoot":"","sources":["indexer.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"indexer.js","sourceRoot":"","sources":["../jsr/indexer.ts"],"names":[],"mappings":""}
package/key-bag-if.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"key-bag-if.js","sourceRoot":"","sources":["key-bag-if.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"key-bag-if.js","sourceRoot":"","sources":["../jsr/key-bag-if.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireproof/core-types-base",
3
- "version": "0.23.1",
3
+ "version": "0.23.2",
4
4
  "description": "Live ledger for the web.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@adviser/cement": "^0.4.23",
35
- "@fireproof/core-types-blockstore": "0.23.1",
36
- "@fireproof/vendor": "0.23.1",
35
+ "@fireproof/core-types-blockstore": "0.23.2",
36
+ "@fireproof/vendor": "0.23.2",
37
37
  "@web3-storage/pail": "^0.6.2",
38
38
  "multiformats": "^13.4.0",
39
39
  "prolly-trees": "^1.0.4"
package/types.js.map CHANGED
@@ -1 +1 @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CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjC,CAAC;IAAA,CACF;CACF;AAwLD,MAAM,UAAU,yBAAyB,CAAC,CAAkB,EAAgC;IAC1F,OAAO,CAAC,CAAC,QAAQ,CAAC;AAAA,CACnB;AAsDD,MAAM,UAAU,qBAAqB,CAAC,IAAI,GAA8B,EAAE,EAAoB;IAC5F,OAAO;QACL,GAAG,IAAI;QACP,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;KACtE,CAAC;AAAA,CACH;AAMD,MAAM,UAAU,eAAe,CAAC,CAAoC,EAAsB;IACxF,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjB,IAAI,CAAC,CAAC,IAAI,EAAE;YAAE,OAAO,KAAK,CAAC;QAC3B,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACd,CAAC;IACD,IAAK,CAAmB,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACxD,OAAO,KAAK,CAAC;AAAA,CACd"}
package/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./indexer.js";
2
- export * from "./key-bag-if.js";
3
- export * from "./types.js";
package/indexer.ts DELETED
@@ -1,46 +0,0 @@
1
- /// <reference types="./prolly-trees.d.ts" />
2
-
3
- import { Logger } from "@adviser/cement";
4
- import {
5
- BaseBlockstore,
6
- ClockHead,
7
- CRDT,
8
- DocFragment,
9
- DocTypes,
10
- IdxMeta,
11
- IndexKeyType,
12
- IndexRows,
13
- MapFn,
14
- QueryOpts,
15
- } from "./types.js";
16
- import { AnyLink } from "@fireproof/core-types-blockstore";
17
-
18
- import { BaseNode } from "prolly-trees/base";
19
-
20
- export interface IndexTree<K extends IndexKeyType, R extends DocFragment> {
21
- cid?: AnyLink;
22
- root?: BaseNode<K, R>;
23
- // root?: ProllyNode<K, R>;
24
- }
25
-
26
- export interface IndexIf<T extends DocTypes, K extends IndexKeyType = string, R extends DocFragment = T> {
27
- readonly blockstore: BaseBlockstore;
28
- readonly crdt: CRDT;
29
- readonly name: string;
30
- mapFn?: MapFn<T>;
31
- readonly mapFnString: string;
32
- indexHead?: ClockHead;
33
-
34
- initError?: Error;
35
-
36
- byKey: IndexTree<K, R>;
37
- byId: IndexTree<K, R>;
38
-
39
- ready(): Promise<void>;
40
-
41
- readonly logger: Logger;
42
-
43
- applyMapFn(name: string, mapFn?: MapFn<T>, meta?: IdxMeta): void;
44
-
45
- query(opts: QueryOpts<K>): Promise<IndexRows<T, K, R>>;
46
- }
package/key-bag-if.ts DELETED
@@ -1,15 +0,0 @@
1
- import { Logger, URI, Result } from "@adviser/cement";
2
- import { KeysByFingerprint } from "@fireproof/core-types-blockstore";
3
- import { KeyBagRuntime } from "./types.js";
4
-
5
- export interface KeyBagIf {
6
- readonly logger: Logger;
7
- readonly rt: KeyBagRuntime;
8
-
9
- subtleKey(materialStrOrUint8: string | Uint8Array): Promise<CryptoKey>;
10
-
11
- ensureKeyFromUrl(url: URI, keyFactory: () => string): Promise<Result<URI>>;
12
- // flush(): Promise<void>;
13
-
14
- getNamedKey(name: string, failIfNotFound?: boolean, material?: string | Uint8Array): Promise<Result<KeysByFingerprint>>;
15
- }
package/prolly-trees.d.ts DELETED
@@ -1,91 +0,0 @@
1
- declare module "prolly-trees/base" {
2
- declare type AnyLink = Link<unknown, number, number, Version>;
3
- declare type KeyLiteral = string | number | boolean;
4
- declare type IndexKeyType = KeyLiteral | KeyLiteral[];
5
-
6
- declare type DocFragment = Uint8Array | string | number | boolean | null | AnyLink | DocFragment[] | object;
7
-
8
- declare interface IndexRow<K extends IndexKeyType, T extends DocFragment> {
9
- readonly id: string;
10
- readonly key: IndexKey<K>;
11
- readonly value: T;
12
- }
13
- // ProllyNode type based on the ProllyNode from 'prolly-trees/base'
14
- declare interface BaseNode<K extends IndexKeyType, T extends DocFragment> {
15
- getAllEntries(): PromiseLike<{ [x: string]: unknown; result: IndexRow<K, T>[] }>;
16
- getMany<KI extends IndexKeyType>(removeIds: KI[]): Promise<{ /* [x: K]: unknown; */ result: IndexKey<K>[] }>;
17
- range(a: string, b: string): Promise<{ result: ProllyIndexRow<K, T>[] }>;
18
- get(key: string): Promise<{ result: ProllyIndexRow<K, T>[] }>;
19
- bulk(bulk: (IndexUpdate<K> | IndexUpdateString)[]): PromiseLike<{
20
- readonly root?: ProllyNode<K, T>;
21
- readonly blocks: Block[];
22
- }>;
23
- readonly address: Promise<Link>;
24
- readonly distance: number;
25
- compare: (a: unknown, b: unknown) => number;
26
- readonly cache: unknown;
27
- readonly block: Promise<Block>;
28
- }
29
-
30
- declare interface StaticProllyOptions<T> {
31
- readonly cache: unknown;
32
- chunker: (entry: T, distance: number) => Promise<boolean>;
33
- readonly codec: unknown;
34
- readonly hasher: unknown;
35
- compare: (a: T, b: T) => number;
36
- }
37
- }
38
-
39
- declare module "prolly-trees/db-index" {
40
- declare function create<K extends IndexKeyType, T extends DocFragment>(opts: CreateOpts): Promise<BaseNode<K, T>[]>;
41
- declare function load(opts: LoadOpts): Promise<BaseNode>;
42
- }
43
-
44
- declare module "prolly-trees/utils" {
45
- declare interface Entry {
46
- identity(): number;
47
- }
48
- declare function bf<T>(factor: number): (entry: T, dist: number) => Promise<boolean>;
49
- // declare function bf(factor: number): (entry: Entry) => Promise<boolean>;
50
- declare function simpleCompare(a: number | string, b: number | string): number;
51
- }
52
-
53
- declare module "prolly-trees/cache" {
54
- declare interface Address {
55
- asCID: string;
56
- }
57
- declare interface Node {
58
- address: Address;
59
- }
60
- declare interface Cache {
61
- has(): boolean;
62
- get(key: Address): Node | undefined;
63
- set(node: Node): Promise<void>;
64
- }
65
- declare const nocache: Cache;
66
- declare const global: Cache;
67
- }
68
-
69
- declare module "prolly-trees/cid-set" {
70
- declare interface CreateOpts {
71
- get: unknown;
72
- cache: Cache;
73
- chunker: unknown;
74
- list: unknown;
75
- codec: unknown;
76
- hasher: unknown;
77
- sorted: unknown;
78
- }
79
- declare function create(opts: CreateOpts): void;
80
-
81
- declare interface LoadOpts {
82
- cid: Address;
83
- get: unknown;
84
- cache: Cache;
85
- chunker: unknown;
86
- codec: unknown;
87
- hasher: unknown;
88
- // ...opts: unkown
89
- }
90
- declare function load(opts: LoadOpts): Promise<Node>;
91
- }
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": [
3
- "/home/runner/work/fireproof/fireproof/tsconfig.dist.json"
4
- ],
5
- "compilerOptions": {
6
- "noEmit": false,
7
- "outDir": "./"
8
- },
9
- "include": [
10
- "**/*"
11
- ],
12
- "exclude": [
13
- "node_modules",
14
- "dist",
15
- ".git",
16
- ".vscode"
17
- ]
18
- }
package/types.ts DELETED
@@ -1,836 +0,0 @@
1
- import type { EventLink } from "@web3-storage/pail/clock/api";
2
- import type { Operation } from "@web3-storage/pail/crdt/api";
3
- import type { Block } from "multiformats";
4
- import { EnvFactoryOpts, Env, Logger, CryptoRuntime, Result, CoerceURI, AppContext, URI, CTCryptoKey } from "@adviser/cement";
5
-
6
- import type {
7
- DbMeta,
8
- AnyLink,
9
- StoreUrlsOpts,
10
- StoreEnDeFile,
11
- Loadable,
12
- TransactionWrapper,
13
- BlockstoreRuntime,
14
- StoreURIRuntime,
15
- DataAndMetaAndWalStore,
16
- UrlAndInterceptor,
17
- MetaStore,
18
- WALStore,
19
- BaseStore,
20
- FileStore,
21
- CarStore,
22
- FPBlock,
23
- BlockFetcher,
24
- } from "@fireproof/core-types-blockstore";
25
-
26
- import type { IndexIf } from "./indexer.js";
27
- import { SerdeGatewayInterceptor } from "@fireproof/core-types-blockstore";
28
-
29
- export class NotFoundError extends Error {
30
- readonly code = "ENOENT";
31
- }
32
-
33
- export type { DbMeta };
34
-
35
- export type Falsy = false | null | undefined;
36
-
37
- export function isFalsy(value: unknown): value is Falsy {
38
- return value === false || value === null || value === undefined;
39
- }
40
-
41
- export const PARAM = {
42
- SUFFIX: "suffix",
43
- URL_GEN: "urlGen", // "urlGen" | "default"
44
- STORE_KEY: "storekey",
45
- STORE: "store",
46
- KEY: "key",
47
- INDEX: "index",
48
- NAME: "name",
49
- VERSION: "version",
50
- RUNTIME: "runtime", // "node" | "deno" | "browser"
51
- FRAG_SIZE: "fragSize",
52
- IV_VERIFY: "ivVerify",
53
- IV_HASH: "ivHash",
54
- FRAG_FID: "fid",
55
- FRAG_OFS: "ofs",
56
- FRAG_LEN: "len",
57
- FRAG_HEAD: "headerSize",
58
- EXTRACTKEY: "extractKey",
59
- SELF_REFLECT: "selfReflect", // if no subscribe in Gateway see your own META updates
60
- CAR_PARALLEL: "parallel",
61
- CAR_CACHE_SIZE: "carCacheSize",
62
- CAR_COMPACT_CACHE_SIZE: "carCompactCacheSize",
63
- CAR_META_CACHE_SIZE: "carMetaCacheSize",
64
- GENESIS_CID: "baembeiarootfireproofgenesisblockaaaafireproofgenesisblocka",
65
- LOCAL_NAME: "localName",
66
- // FS = "fs",
67
- };
68
- export type PARAMS = (typeof PARAM)[keyof typeof PARAM];
69
-
70
- export function throwFalsy<T>(value: T | Falsy): T {
71
- if (isFalsy(value)) {
72
- throw new Error("value is Falsy");
73
- }
74
- return value;
75
- }
76
-
77
- export function falsyToUndef<T>(value: T | Falsy): T | undefined {
78
- if (isFalsy(value)) {
79
- return undefined;
80
- }
81
- return value;
82
- }
83
-
84
- export type StoreType = "car" | "file" | "wal" | "meta";
85
- export interface FPStats {
86
- isFile(): boolean;
87
- isDirectory(): boolean;
88
- isBlockDevice(): boolean;
89
- isCharacterDevice(): boolean;
90
- isSymbolicLink(): boolean;
91
- isFIFO(): boolean;
92
- isSocket(): boolean;
93
- uid: number | Falsy;
94
- gid: number | Falsy;
95
- size: number | Falsy;
96
- atime: Date | Falsy;
97
- mtime: Date | Falsy;
98
- ctime: Date | Falsy;
99
- birthtime: Date | Falsy;
100
- }
101
-
102
- export interface SysFileSystem {
103
- start(): Promise<SysFileSystem>;
104
- mkdir(path: string, options?: { recursive: boolean }): Promise<string | undefined>;
105
- readdir(path: string /*, options?: unknown*/): Promise<string[]>;
106
- rm(path: string, options?: { recursive: boolean }): Promise<void>;
107
- copyFile(source: string, destination: string): Promise<void>;
108
- readfile(path: string /*, options?: { encoding: BufferEncoding; flag?: string }*/): Promise<Uint8Array>;
109
- stat(path: string): Promise<FPStats>;
110
- unlink(path: string): Promise<void>;
111
- writefile(path: string, data: Uint8Array | string): Promise<void>;
112
- }
113
-
114
- export interface PathOps {
115
- join(...args: string[]): string;
116
- dirname(path: string): string;
117
- basename(path: string): string;
118
- }
119
-
120
- export type ToUInt8 = Uint8Array | Result<Uint8Array>;
121
- export type PromiseToUInt8 = ToUInt8 | Promise<Uint8Array> | Promise<Result<Uint8Array>>;
122
-
123
- export interface TextEndeCoder {
124
- encode(input: string): Uint8Array;
125
- decode(input: ToUInt8): string;
126
- }
127
- export interface SuperThisOpts {
128
- // readonly crypto?: CryptoRuntime;
129
- readonly logger: Logger;
130
- readonly pathOps: PathOps;
131
- readonly crypto: CryptoRuntime;
132
- readonly env: Partial<EnvFactoryOpts>;
133
- readonly txt: TextEndeCoder;
134
- readonly ctx: AppContext;
135
- }
136
-
137
- export interface SuperThis {
138
- readonly logger: Logger;
139
- readonly loggerCollector?: Logger;
140
- readonly env: Env;
141
- readonly pathOps: PathOps;
142
- readonly ctx: AppContext;
143
- readonly txt: TextEndeCoder;
144
- timeOrderedNextId(time?: number): { str: string; toString: () => string };
145
- nextId(bytes?: number): { str: string; bin: Uint8Array; toString: () => string };
146
- start(): Promise<void>;
147
- clone(override: Partial<SuperThisOpts>): SuperThis;
148
- }
149
-
150
- export interface IdleEventFromCommitQueue {
151
- readonly event: "idleFromCommitQueue";
152
- }
153
- export interface IdleEventFromBlockstore {
154
- readonly event: "idleFromBlockstore";
155
- readonly blockstore: "data" | "index";
156
- readonly ledger?: Ledger;
157
- }
158
-
159
- export interface BusyEventFromCommitQueue {
160
- readonly event: "busyFromCommitQueue";
161
- readonly queueLen: number;
162
- }
163
-
164
- export interface BusyEventFromBlockstore extends Omit<IdleEventFromBlockstore, "event"> {
165
- readonly event: "busyFromBlockstore";
166
- readonly queueLen: number;
167
- }
168
-
169
- export function EventIsIdleFromBlockstore(event: TraceEvent): event is IdleEventFromBlockstore {
170
- return event.event === "idleFromBlockstore";
171
- }
172
-
173
- export function EventIsBusyFromBlockstore(event: TraceEvent): event is BusyEventFromBlockstore {
174
- return event.event === "busyFromBlockstore";
175
- }
176
-
177
- export type TraceEvent = IdleEventFromCommitQueue | IdleEventFromBlockstore | BusyEventFromBlockstore | BusyEventFromCommitQueue;
178
-
179
- export interface ConfigOpts extends Partial<SuperThisOpts> {
180
- readonly public?: boolean;
181
- readonly meta?: DbMeta;
182
- // readonly persistIndexes?: boolean;
183
- readonly writeQueue?: Partial<WriteQueueParams>;
184
- readonly gatewayInterceptor?: SerdeGatewayInterceptor;
185
- readonly autoCompact?: number;
186
- // could be registered with registerCompactStrategy(name: string, compactStrategy: CompactStrategy)
187
- readonly compactStrategy?: string; // default "FULL" other "fireproof" , "no-op"
188
- readonly storeUrls?: StoreUrlsOpts;
189
- readonly storeEnDe?: StoreEnDeFile;
190
- readonly threshold?: number;
191
- readonly keyBag?: Partial<KeyBagOpts>;
192
- readonly tracer?: TraceFn;
193
- }
194
-
195
- // export interface ToCloudOpts {
196
- // readonly ledger: string;
197
- // }
198
-
199
- export type ClockLink = EventLink<Operation>;
200
-
201
- export type ClockHead = ClockLink[];
202
-
203
- export type DocFragment = Uint8Array | string | number | boolean | null | AnyLink | DocFragment[] | object;
204
- // | { [key: string]: DocFragment };
205
-
206
- export type DocLiteral = string | number | boolean | Uint8Array | unknown;
207
-
208
- export type DocObject = NonNullable<unknown>;
209
- export type DocTypes = DocObject;
210
-
211
- export type DocRecord<T extends DocObject> = T;
212
-
213
- export type UnknownDoc = DocRecord<never>;
214
-
215
- export type DocFiles = Record<string, DocFileMeta | File>;
216
-
217
- export interface DocBase {
218
- readonly _id: string;
219
- readonly _files?: DocFiles;
220
- readonly _publicFiles?: DocFiles;
221
- readonly _deleted?: boolean;
222
- }
223
-
224
- export type DocWithId<T extends DocTypes> = DocBase & T;
225
-
226
- export type DocSet<T extends DocTypes> = Partial<DocBase> & T;
227
-
228
- export interface DocFileMeta {
229
- readonly type: string;
230
- readonly size: number;
231
- readonly cid: AnyLink;
232
- readonly car?: AnyLink;
233
- readonly lastModified?: number;
234
- url?: string;
235
- file?: () => Promise<File>;
236
- }
237
-
238
- export interface DocUpdate<T extends DocTypes> {
239
- readonly id: string;
240
- readonly value?: DocSet<T>;
241
- readonly del?: boolean;
242
- readonly clock?: ClockLink; // would be useful to give ClockLinks a type
243
- }
244
-
245
- // todo merge into above
246
- export interface DocValue<T extends DocTypes> {
247
- readonly doc: DocWithId<T>;
248
- readonly del: boolean;
249
- readonly cid: AnyLink;
250
- }
251
-
252
- export type KeyLiteral = string | number | boolean;
253
- export type IndexKeyType = KeyLiteral | KeyLiteral[];
254
- export type IndexKey<K extends IndexKeyType> = [K, string];
255
-
256
- export interface IndexUpdate<K extends IndexKeyType> {
257
- readonly key: IndexKey<K>;
258
- readonly value?: DocFragment;
259
- readonly del?: boolean;
260
- }
261
-
262
- export interface IndexUpdateString {
263
- readonly key: string;
264
- readonly value?: DocFragment;
265
- readonly del?: boolean;
266
- }
267
-
268
- // export interface IndexRowObject<K extends IndexKeyType, T extends DocObject> {
269
- // readonly id: string;
270
- // readonly key: K;
271
- // readonly value: T
272
- // // readonly row: T // DocFragment;
273
- // // readonly doc?: DocWithId<T>;
274
- // // value?: T;
275
- // // readonly del?: boolean;
276
- // }
277
-
278
- // export interface IndexRowLiteral<K extends IndexKeyType, T extends DocLiteral> {
279
- // readonly id: string;
280
- // readonly key: IndexKey<K>;
281
- // readonly value: T
282
- // }
283
-
284
- // export type IndexRow<K extends IndexKeyType, T extends DocTypes> =
285
- // T extends DocLiteral ? IndexRowLiteral<K, T> : IndexRowObject<K, T>
286
-
287
- export interface FPIndexRow<K extends IndexKeyType, T extends DocObject, R extends DocFragment> {
288
- readonly id: string;
289
- readonly key: K; // IndexKey<K>;
290
- readonly value: R;
291
- readonly doc?: DocWithId<T>;
292
- }
293
-
294
- export interface IndexRows<T extends DocObject, K extends IndexKeyType = string, R extends DocFragment = T> {
295
- readonly rows: FPIndexRow<K, T, R>[];
296
- readonly docs: DocWithId<T>[];
297
- }
298
- export interface CRDTMeta {
299
- readonly head: ClockHead;
300
- }
301
-
302
- export interface IndexTransactionMeta {
303
- readonly indexes: Record<string, IdxMeta>;
304
- }
305
-
306
- export interface FileTransactionMeta {
307
- readonly files?: AnyLink[];
308
- }
309
-
310
- export type MetaType = CRDTMeta | IndexTransactionMeta | FileTransactionMeta;
311
-
312
- export interface IdxMeta {
313
- readonly byId: AnyLink;
314
- readonly byKey: AnyLink;
315
- readonly map: string;
316
- readonly name: string;
317
- readonly head: ClockHead;
318
- }
319
-
320
- export interface IdxMetaMap {
321
- readonly indexes?: Map<string, IdxMeta>;
322
- }
323
-
324
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
325
- export interface QueryOpts<K extends IndexKeyType> {
326
- readonly descending?: boolean;
327
- readonly limit?: number;
328
- includeDocs?: boolean;
329
- readonly range?: [IndexKeyType, IndexKeyType];
330
- readonly key?: DocFragment;
331
- readonly keys?: DocFragment[];
332
- prefix?: IndexKeyType;
333
- }
334
-
335
- export interface AllDocsQueryOpts extends QueryOpts<string> {
336
- readonly key: string;
337
- readonly keys: string[];
338
- readonly prefix: string;
339
- /**
340
- * Whether to include documents marked as deleted (_deleted: true).
341
- * Default is false - deleted documents are excluded.
342
- */
343
- readonly includeDeleted: boolean;
344
- }
345
-
346
- export interface AllDocsResponse<T extends DocTypes> {
347
- readonly rows: {
348
- readonly key: string;
349
- readonly value: DocWithId<T>;
350
- }[];
351
- readonly clock: ClockHead;
352
- readonly name?: string;
353
- }
354
-
355
- type EmitFn = (k: IndexKeyType, v?: DocFragment) => void;
356
- export type MapFn<T extends DocTypes> = (doc: DocWithId<T>, emit: EmitFn) => DocFragment | unknown;
357
-
358
- export interface ChangesOptions {
359
- readonly dirty?: boolean;
360
- readonly limit?: number;
361
- }
362
-
363
- export interface ChangesResponseRow<T extends DocTypes> {
364
- readonly key: string;
365
- readonly value: DocWithId<T>;
366
- readonly clock?: ClockLink;
367
- }
368
-
369
- export interface ChangesResponse<T extends DocTypes> {
370
- readonly clock: ClockHead;
371
- readonly rows: ChangesResponseRow<T>[];
372
- readonly name?: string;
373
- }
374
-
375
- export interface DocResponse {
376
- readonly id: string;
377
- readonly clock: ClockHead;
378
- readonly name?: string;
379
- }
380
-
381
- export interface BulkResponse {
382
- readonly ids: string[];
383
- readonly clock: ClockHead;
384
- readonly name?: string;
385
- }
386
-
387
- export type UpdateListenerFn<T extends DocTypes> = (docs: DocWithId<T>[]) => Promise<void> | void;
388
- export type NoUpdateListenerFn = () => Promise<void> | void;
389
- export type ListenerFn<T extends DocTypes> = UpdateListenerFn<T> | NoUpdateListenerFn;
390
-
391
- export interface CRDTEntry {
392
- readonly data: string;
393
- readonly parents: string[];
394
- readonly cid: string;
395
- }
396
-
397
- export type AsyncVoidFn = () => Promise<void>;
398
- export type VoidFn = () => void;
399
- export type UnReg = () => void;
400
- export interface CRDTClock {
401
- readonly head: ClockHead;
402
- onTock(fn: VoidFn): UnReg;
403
- onTick(fn: (updates: DocUpdate<DocTypes>[]) => void): UnReg;
404
- applyHead(newHead: ClockHead, prevHead: ClockHead, updates?: DocUpdate<DocTypes>[]): Promise<void>;
405
- onZoom(fn: VoidFn): UnReg;
406
- close(): Promise<void>;
407
- ready(): Promise<void>;
408
- }
409
-
410
- export interface CarTransaction {
411
- readonly parent: BaseBlockstore;
412
- get(cid: AnyLink): Promise<FPBlock | Falsy>;
413
-
414
- superGet(cid: AnyLink): Promise<FPBlock | Falsy>;
415
-
416
- // needed for genesis block
417
- unshift(fb: FPBlock): void;
418
- putSync(fb: FPBlock): void;
419
-
420
- put(fb: FPBlock): Promise<void>;
421
-
422
- entries(): AsyncIterableIterator<FPBlock>;
423
- }
424
-
425
- export interface CarTransactionOpts {
426
- readonly add: boolean;
427
- readonly noLoader: boolean;
428
- }
429
-
430
- export interface BaseBlockstore {
431
- readonly crdtParent?: CRDT;
432
- readonly transactions: Set<CarTransaction>;
433
- readonly sthis: SuperThis;
434
- readonly loader: Loadable;
435
- readonly ebOpts: BlockstoreRuntime;
436
- ready(): Promise<void>;
437
- close(): Promise<void>;
438
- destroy(): Promise<void>;
439
- compact(): Promise<void>;
440
- readonly logger: Logger;
441
-
442
- get(cid: AnyLink): Promise<FPBlock | Falsy>;
443
- put(fp: FPBlock): Promise<void>;
444
-
445
- transaction<M extends TransactionMeta>(
446
- fn: (t: CarTransaction) => Promise<M>,
447
- _opts?: CarTransactionOpts,
448
- ): Promise<TransactionWrapper<M>>;
449
-
450
- // get<T, C extends number, A extends number, V extends Version>(cid: AnyAnyLink): Promise<Block<T, C, A, V> | undefined>
451
- // transaction<M extends TransactionMeta>(
452
- // fn: (t: CarTransaction) => Promise<M>,
453
- // _opts?: CarTransactionOpts,
454
- // ): Promise<TransactionWrapper<M>>
455
-
456
- openTransaction(opts: CarTransactionOpts /* = { add: true, noLoader: false }*/): CarTransaction;
457
-
458
- commitTransaction<M extends TransactionMeta>(
459
- t: CarTransaction,
460
- done: M,
461
- opts: CarTransactionOpts,
462
- ): Promise<TransactionWrapper<M>>;
463
- entries(): AsyncIterableIterator<FPBlock>;
464
- }
465
-
466
- export interface CRDT extends ReadyCloseDestroy, HasLogger, HasSuperThis, HasCRDT {
467
- readonly ledgerParent?: Ledger;
468
- readonly logger: Logger;
469
- readonly sthis: SuperThis;
470
- // self reference to fullfill HasCRDT
471
- readonly crdt: CRDT;
472
- readonly clock: CRDTClock;
473
-
474
- readonly blockstore: BaseBlockstore;
475
- readonly indexBlockstore?: BaseBlockstore;
476
- readonly indexers: Map<string, IndexIf<DocTypes, IndexKeyType>>;
477
-
478
- bulk<T extends DocTypes>(updates: DocUpdate<T>[]): Promise<CRDTMeta>;
479
- ready(): Promise<void>;
480
- close(): Promise<void>;
481
- destroy(): Promise<void>;
482
- allDocs<T extends DocTypes>(): Promise<{ result: DocUpdate<T>[]; head: ClockHead }>;
483
- vis(): Promise<string>;
484
- getBlock(cidString: string): Promise<Block>;
485
- get(key: string): Promise<DocValue<DocTypes> | Falsy>;
486
- // defaults by impl
487
- changes<T extends DocTypes>(
488
- since?: ClockHead,
489
- opts?: ChangesOptions,
490
- ): Promise<{
491
- result: DocUpdate<T>[];
492
- head: ClockHead;
493
- }>;
494
- compact(): Promise<void>;
495
- }
496
-
497
- export interface HasCRDT {
498
- readonly crdt: CRDT;
499
- }
500
-
501
- export interface RefLedger {
502
- readonly ledger: Ledger;
503
- }
504
-
505
- export interface HasLogger {
506
- readonly logger: Logger;
507
- }
508
-
509
- export interface HasSuperThis {
510
- readonly sthis: SuperThis;
511
- }
512
-
513
- export interface ReadyCloseDestroy {
514
- close(): Promise<void>;
515
- destroy(): Promise<void>;
516
- ready(): Promise<void>;
517
- }
518
-
519
- export interface CoerceURIandInterceptor {
520
- readonly url: CoerceURI;
521
- readonly gatewayInterceptor?: SerdeGatewayInterceptor;
522
- }
523
-
524
- export interface AttachContext {
525
- detach(): Promise<void>;
526
- readonly ctx: AppContext;
527
- }
528
-
529
- /**
530
- * @description used by an attachable do define the urls of the attached gateways
531
- */
532
- export interface GatewayUrlsParam extends Partial<AttachContext> {
533
- readonly car: CoerceURIandInterceptor;
534
- readonly file: CoerceURIandInterceptor;
535
- readonly meta: CoerceURIandInterceptor;
536
- // if set this is a local Attachment
537
- readonly wal?: CoerceURIandInterceptor;
538
- }
539
-
540
- export interface GatewayUrls {
541
- readonly car: UrlAndInterceptor;
542
- readonly file: UrlAndInterceptor;
543
- readonly meta: UrlAndInterceptor;
544
- readonly wal?: UrlAndInterceptor;
545
- }
546
-
547
- export interface Attachable {
548
- readonly name: string;
549
- /**
550
- * @description prepare allows the Attable to register the gateways and
551
- * then return the urls of the gateways
552
- */
553
- prepare(db?: Ledger): Promise<GatewayUrlsParam>;
554
- /**
555
- * @description configHash is called on every attach to avoid multiple
556
- * calls to prepare with the same config.
557
- */
558
- configHash(): Promise<string>;
559
- }
560
-
561
- export class DataAndMetaAndWalAndBaseStore implements DataAndMetaAndWalStore {
562
- readonly wal?: WALStore | undefined;
563
- readonly file: FileStore;
564
- readonly car: CarStore;
565
- readonly meta: MetaStore;
566
- readonly baseStores: BaseStore[];
567
-
568
- constructor(dam: DataAndMetaAndWalStore) {
569
- this.wal = dam.wal;
570
- this.file = dam.file;
571
- this.car = dam.car;
572
- this.meta = dam.meta;
573
- this.baseStores = [this.file, this.car, this.meta];
574
- if (this.wal) {
575
- this.baseStores.push(this.wal);
576
- }
577
- }
578
- }
579
-
580
- export interface Attached {
581
- readonly keyed: string;
582
-
583
- readonly gatewayUrls: GatewayUrls;
584
-
585
- readonly stores: DataAndMetaAndWalAndBaseStore;
586
-
587
- detach(): Promise<void>;
588
- status(): "attached" | "loading" | "loaded" | "error" | "detached" | "syncing" | "idle";
589
-
590
- ctx(): AppContext;
591
- }
592
-
593
- export interface Database extends ReadyCloseDestroy, HasLogger, HasSuperThis {
594
- // readonly name: string;
595
- readonly ledger: Ledger;
596
- readonly logger: Logger;
597
- readonly sthis: SuperThis;
598
- // readonly id: string;
599
- readonly name: string;
600
-
601
- onClosed(fn: () => void): void;
602
-
603
- attach(a: Attachable): Promise<Attached>;
604
-
605
- get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
606
- put<T extends DocTypes>(doc: DocSet<T>): Promise<DocResponse>;
607
- bulk<T extends DocTypes>(docs: DocSet<T>[]): Promise<BulkResponse>;
608
- del(id: string): Promise<DocResponse>;
609
- remove(id: string): Promise<DocResponse>;
610
- changes<T extends DocTypes>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
611
- allDocs<T extends DocTypes>(opts?: Partial<AllDocsQueryOpts>): Promise<AllDocsResponse<T>>;
612
- allDocuments<T extends DocTypes>(): Promise<{
613
- rows: {
614
- key: string;
615
- value: DocWithId<T>;
616
- }[];
617
- clock: ClockHead;
618
- }>;
619
- subscribe<T extends DocTypes>(listener: ListenerFn<T>, updates?: boolean): () => void;
620
-
621
- query<T extends DocTypes, K extends IndexKeyType = string, R extends DocFragment = T>(
622
- field: string | MapFn<T>,
623
- opts?: QueryOpts<K>,
624
- ): Promise<IndexRows<T, K, R>>;
625
- compact(): Promise<void>;
626
- }
627
-
628
- export interface WriteQueue<T extends DocUpdate<S>, S extends DocTypes = DocTypes> {
629
- push(task: T): Promise<MetaType>;
630
- bulk(tasks: T[]): Promise<MetaType>;
631
- close(): Promise<void>;
632
- }
633
-
634
- export type TraceFn = (traceEvent: TraceEvent) => void;
635
-
636
- export interface Tracer {
637
- readonly tracer: TraceFn;
638
- }
639
-
640
- export type TransactionMeta = unknown;
641
- export interface CompactStrategyContext extends BlockFetcher {
642
- readonly transactions: Set<CarTransaction>;
643
- readonly clock?: CRDTClock;
644
- readonly lastTxMeta: TransactionMeta;
645
- readonly loader: Loadable;
646
- readonly logger: Logger;
647
- readonly blockstore: BlockFetcher;
648
- // loader: Loader | null = null
649
- readonly loggedBlocks: CarTransaction;
650
-
651
- get(cid: AnyLink): Promise<FPBlock | Falsy>;
652
- }
653
-
654
- export interface CompactStrategy {
655
- readonly name: string;
656
- compact(block: CompactStrategyContext): Promise<TransactionMeta>;
657
- }
658
-
659
- export interface LedgerOpts extends Tracer {
660
- readonly name: string;
661
- // readonly public?: boolean;
662
- readonly meta?: DbMeta;
663
- readonly gatewayInterceptor?: SerdeGatewayInterceptor;
664
-
665
- // could be registered with registerCompactStrategy(name: string, compactStrategy: CompactStrategy)
666
- readonly compactStrategy?: string; // default "FULL"
667
-
668
- readonly ctx: AppContext;
669
- readonly writeQueue: WriteQueueParams;
670
- readonly storeUrls: StoreURIRuntime;
671
- readonly storeEnDe: StoreEnDeFile;
672
- readonly keyBag: KeyBagRuntime;
673
- }
674
-
675
- export type LedgerOptsOptionalTracer = Omit<LedgerOpts, "tracer"> & Partial<Tracer>;
676
-
677
- export interface Ledger extends HasCRDT {
678
- readonly opts: LedgerOpts;
679
- // readonly name: string;
680
- readonly writeQueue: WriteQueue<DocUpdate<DocTypes>>;
681
-
682
- readonly logger: Logger;
683
- readonly sthis: SuperThis;
684
- // readonly id: string;
685
-
686
- readonly name: string;
687
-
688
- readonly ctx: AppContext;
689
-
690
- // a config and name hash to the same instance
691
- refId(): Promise<string>;
692
-
693
- onClosed(fn: () => void): () => void;
694
-
695
- attach(a: Attachable): Promise<Attached>;
696
-
697
- close(): Promise<void>;
698
- destroy(): Promise<void>;
699
- ready(): Promise<void>;
700
-
701
- subscribe<T extends DocTypes>(listener: ListenerFn<T>, updates?: boolean): () => void;
702
-
703
- // asDB(): Database;
704
-
705
- // get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
706
- // put<T extends DocTypes>(doc: DocSet<T>): Promise<DocResponse>;
707
- // bulk<T extends DocTypes>(docs: DocSet<T>[]): Promise<BulkResponse>;
708
- // del(id: string): Promise<DocResponse>;
709
- // changes<T extends DocTypes>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
710
- // allDocs<T extends DocTypes>(opts?: AllDocsQueryOpts): Promise<AllDocsResponse<T>>;
711
- // allDocuments<T extends DocTypes>(): Promise<{
712
- // rows: {
713
- // key: string;
714
- // value: DocWithId<T>;
715
- // }[];
716
- // clock: ClockHead;
717
- // }>;
718
- // subscribe<T extends DocTypes>(listener: ListenerFn<T>, updates?: boolean): () => void;
719
-
720
- // query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(
721
- // field: string | MapFn<T>,
722
- // opts?: QueryOpts<K>,
723
- // ): Promise<IndexRows<K, T, R>>;
724
- // compact(): Promise<void>;
725
- }
726
-
727
- export interface V1StorageKeyItem {
728
- readonly name: string;
729
- readonly key: string;
730
- }
731
-
732
- export interface V2StorageKeyItem {
733
- readonly key: string; // material
734
- readonly fingerPrint: string;
735
- readonly default: boolean;
736
- }
737
-
738
- // Serialized Version
739
- export interface V2KeysItem {
740
- readonly name: string;
741
- readonly keys: Record<string, V2StorageKeyItem>;
742
- }
743
-
744
- export interface KeyMaterial {
745
- readonly key: Uint8Array;
746
- readonly keyStr: string;
747
- }
748
-
749
- export interface KeyWithFingerPrint {
750
- readonly default: boolean;
751
- readonly fingerPrint: string;
752
- readonly key: CTCryptoKey;
753
- extract(): Promise<KeyMaterial>;
754
- asV2StorageKeyItem(): Promise<V2StorageKeyItem>;
755
- }
756
-
757
- export interface KeyUpsertResultModified {
758
- readonly modified: true;
759
- readonly kfp: KeyWithFingerPrint;
760
- }
761
-
762
- export function isKeyUpsertResultModified(r: KeyUpsertResult): r is KeyUpsertResultModified {
763
- return r.modified;
764
- }
765
-
766
- export interface KeyUpsertResultNotModified {
767
- readonly modified: false;
768
- }
769
-
770
- export type KeyUpsertResult = KeyUpsertResultModified | KeyUpsertResultNotModified;
771
-
772
- export interface KeysByFingerprint {
773
- readonly id: string;
774
- readonly name: string;
775
- get(fingerPrint?: string | Uint8Array): Promise<KeyWithFingerPrint | undefined>;
776
- upsert(key: string | Uint8Array, def?: boolean): Promise<Result<KeyUpsertResult>>;
777
- asV2KeysItem(): Promise<V2KeysItem>;
778
- }
779
-
780
- export interface KeysItem {
781
- readonly name: string;
782
- readonly keys: Record<string, KeyWithFingerPrint>;
783
- }
784
-
785
- export interface KeyBagProvider {
786
- get(id: string): Promise<V1StorageKeyItem | V2KeysItem | undefined>;
787
- set(item: V2KeysItem): Promise<void>;
788
- del(id: string): Promise<void>;
789
- }
790
-
791
- export interface KeyBagRuntime {
792
- readonly url: URI;
793
- readonly crypto: CryptoRuntime;
794
- readonly logger: Logger;
795
- readonly sthis: SuperThis;
796
- readonly keyLength: number;
797
- // readonly key?: FPCryptoKey;
798
- getBagProvider(): Promise<KeyBagProvider>;
799
- id(): string;
800
- }
801
-
802
- export interface KeyBagOpts {
803
- // in future you can encrypt the keybag with ?masterkey=xxxxx
804
- readonly url: CoerceURI;
805
- // readonly key: string; // key to encrypt the keybag
806
- readonly crypto: CryptoRuntime;
807
- readonly keyLength: number; // default: 16
808
- // readonly logger: Logger;
809
- readonly keyRuntime: KeyBagRuntime;
810
- }
811
-
812
- export interface WriteQueueParams {
813
- // default 32
814
- // if chunkSize is 1 the result will be ordered in time
815
- readonly chunkSize: number;
816
- }
817
-
818
- export function defaultWriteQueueOpts(opts: Partial<WriteQueueParams> = {}): WriteQueueParams {
819
- return {
820
- ...opts,
821
- chunkSize: opts.chunkSize && opts.chunkSize > 0 ? opts.chunkSize : 32,
822
- };
823
- }
824
-
825
- export type Readonly2Writeable<T> = {
826
- -readonly [P in keyof T]: T[P];
827
- };
828
-
829
- export function isNotFoundError(e: Error | Result<unknown> | unknown): e is NotFoundError {
830
- if (Result.Is(e)) {
831
- if (e.isOk()) return false;
832
- e = e.Err();
833
- }
834
- if ((e as NotFoundError).code === "ENOENT") return true;
835
- return false;
836
- }