@fireproof/core 0.16.1 → 0.16.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. package/README.md +14 -7
  2. package/dist/browser/fireproof.cjs +251 -34623
  3. package/dist/browser/fireproof.cjs.map +1 -7
  4. package/dist/browser/fireproof.d.cts +286 -0
  5. package/dist/browser/fireproof.d.ts +286 -0
  6. package/dist/browser/fireproof.global.js +21282 -0
  7. package/dist/browser/fireproof.global.js.map +1 -0
  8. package/dist/browser/fireproof.js +1114 -0
  9. package/dist/browser/fireproof.js.map +1 -0
  10. package/dist/browser/metafile-cjs.json +1 -0
  11. package/dist/browser/metafile-esm.json +1 -0
  12. package/dist/browser/metafile-iife.json +1 -0
  13. package/dist/memory/fireproof.cjs +1143 -0
  14. package/dist/memory/fireproof.cjs.map +1 -0
  15. package/dist/memory/fireproof.d.cts +286 -0
  16. package/dist/memory/fireproof.d.ts +286 -0
  17. package/dist/memory/fireproof.global.js +21282 -0
  18. package/dist/memory/fireproof.global.js.map +1 -0
  19. package/dist/memory/fireproof.js +1114 -0
  20. package/dist/memory/fireproof.js.map +1 -0
  21. package/dist/memory/metafile-cjs.json +1 -0
  22. package/dist/memory/metafile-esm.json +1 -0
  23. package/dist/memory/metafile-iife.json +1 -0
  24. package/dist/node/fireproof.cjs +210 -43910
  25. package/dist/node/fireproof.cjs.map +1 -7
  26. package/dist/node/fireproof.d.cts +286 -0
  27. package/dist/node/fireproof.d.ts +286 -0
  28. package/dist/node/fireproof.global.js +21338 -0
  29. package/dist/node/fireproof.global.js.map +1 -0
  30. package/dist/node/fireproof.js +1114 -0
  31. package/dist/node/fireproof.js.map +1 -0
  32. package/dist/node/metafile-cjs.json +1 -0
  33. package/dist/node/metafile-esm.json +1 -0
  34. package/dist/node/metafile-iife.json +1 -0
  35. package/package.json +38 -33
  36. package/dist/browser/fireproof.esm.js +0 -35509
  37. package/dist/browser/fireproof.esm.js.map +0 -7
  38. package/dist/browser/fireproof.iife.js +0 -35517
  39. package/dist/browser/fireproof.iife.js.map +0 -7
  40. package/dist/node/fireproof.esm.js +0 -44848
  41. package/dist/node/fireproof.esm.js.map +0 -7
  42. package/dist/types/apply-head-queue.d.ts +0 -15
  43. package/dist/types/crdt-clock.d.ts +0 -20
  44. package/dist/types/crdt-helpers.d.ts +0 -14
  45. package/dist/types/crdt.d.ts +0 -27
  46. package/dist/types/database.d.ts +0 -48
  47. package/dist/types/eb-edge.d.ts +0 -0
  48. package/dist/types/eb-node.d.ts +0 -3
  49. package/dist/types/eb-web.d.ts +0 -3
  50. package/dist/types/files.d.ts +0 -12
  51. package/dist/types/fireproof.d.ts +0 -3
  52. package/dist/types/index.d.ts +0 -31
  53. package/dist/types/indexer-helpers.d.ts +0 -57
  54. package/dist/types/types.d.ts +0 -136
  55. package/dist/types/version.d.ts +0 -1
  56. package/dist/types/write-queue.d.ts +0 -7
@@ -0,0 +1,286 @@
1
+ import { Link, Block } from 'multiformats';
2
+ import { EventLink } from '@alanshaw/pail/clock';
3
+ import { EventData } from '@alanshaw/pail/crdt';
4
+ import * as _fireproof_encrypted_blockstore from '@fireproof/encrypted-blockstore';
5
+ import { DbMeta, EncryptedBlockstore } from '@fireproof/encrypted-blockstore';
6
+ import * as multiformats_dist_types_src_block from 'multiformats/dist/types/src/block';
7
+ import { ProllyNode as ProllyNode$1 } from 'prolly-trees/base';
8
+
9
+ type ConfigOpts = {
10
+ public?: boolean;
11
+ meta?: DbMeta;
12
+ persistIndexes?: boolean;
13
+ autoCompact?: number;
14
+ };
15
+ type ClockLink = EventLink<EventData>;
16
+ type ClockHead = ClockLink[];
17
+ type DocFragment = Uint8Array | string | number | boolean | null | AnyLink | DocFragment[] | {
18
+ [key: string]: DocFragment;
19
+ };
20
+ type DocRecord = Record<string, DocFragment>;
21
+ type Doc<T extends DocRecord = {}> = DocBase & DocBody<T>;
22
+ type DocBase = {
23
+ _id?: string;
24
+ _files?: DocFiles;
25
+ _publicFiles?: DocFiles;
26
+ };
27
+ type DocFileMeta = {
28
+ type: string;
29
+ size: number;
30
+ cid: AnyLink;
31
+ car?: AnyLink;
32
+ url?: string;
33
+ file?: () => Promise<File>;
34
+ };
35
+ type DocFiles = Record<string, DocFileMeta | File>;
36
+ type DocBody<T extends DocRecord = {}> = {
37
+ _id?: string;
38
+ } & {
39
+ [K in Exclude<keyof T, keyof DocBase>]: DocFragment;
40
+ } & T;
41
+ type DocUpdate = {
42
+ key: string;
43
+ value?: Record<string, any>;
44
+ del?: boolean;
45
+ clock?: AnyLink;
46
+ };
47
+ type DocValue = {
48
+ doc?: DocBase;
49
+ del?: boolean;
50
+ };
51
+ type IndexKey = [string, string] | string;
52
+ type IndexUpdate = {
53
+ key: IndexKey;
54
+ value?: DocFragment;
55
+ del?: boolean;
56
+ };
57
+ type IndexRow<T extends DocRecord = {}> = {
58
+ id: string;
59
+ key: IndexKey;
60
+ row?: DocFragment;
61
+ doc?: Doc<T> | null;
62
+ value?: DocFragment;
63
+ del?: boolean;
64
+ };
65
+ type CRDTMeta = {
66
+ head: ClockHead;
67
+ };
68
+ type IdxMeta = {
69
+ byId: AnyLink;
70
+ byKey: AnyLink;
71
+ map: string;
72
+ name: string;
73
+ head: ClockHead;
74
+ };
75
+ type QueryOpts = {
76
+ descending?: boolean;
77
+ limit?: number;
78
+ includeDocs?: boolean;
79
+ range?: [IndexKey, IndexKey];
80
+ key?: DocFragment;
81
+ keys?: DocFragment[];
82
+ prefix?: DocFragment | [DocFragment];
83
+ };
84
+ type AnyLink = Link<unknown, number, number, 1 | 0>;
85
+ type EmitFn = (k: DocFragment, v?: DocFragment) => void;
86
+ type MapFn = <T extends DocRecord = {}>(doc: Doc<T>, emit: EmitFn) => DocFragment | void;
87
+ type ChangesOptions = {
88
+ dirty?: boolean;
89
+ limit?: number;
90
+ };
91
+ type ChangesResponse<T extends DocRecord = {}> = {
92
+ clock: ClockHead;
93
+ rows: {
94
+ key: string;
95
+ value: Doc<T>;
96
+ }[];
97
+ };
98
+ type DbResponse = {
99
+ id: string;
100
+ clock: ClockHead;
101
+ };
102
+
103
+ type WriteQueue = {
104
+ push(task: DocUpdate): Promise<CRDTMeta>;
105
+ };
106
+
107
+ declare class IndexTree {
108
+ cid: AnyLink | null;
109
+ root: ProllyNode | null;
110
+ }
111
+ interface ProllyNode extends ProllyNode$1 {
112
+ getAllEntries<T extends DocRecord = {}>(): PromiseLike<{
113
+ [x: string]: any;
114
+ result: IndexRow<T>[];
115
+ }>;
116
+ getMany(removeIds: string[]): Promise<{
117
+ [x: string]: any;
118
+ result: IndexKey[];
119
+ }>;
120
+ range<T extends DocRecord = {}>(a: IndexKey, b: IndexKey): Promise<{
121
+ result: IndexRow<T>[];
122
+ }>;
123
+ get<T extends DocRecord = {}>(key: string): Promise<{
124
+ result: IndexRow<T>[];
125
+ }>;
126
+ bulk(bulk: IndexUpdate[]): PromiseLike<{
127
+ root: ProllyNode | null;
128
+ blocks: Block[];
129
+ }>;
130
+ address: Promise<Link>;
131
+ distance: number;
132
+ compare: (a: any, b: any) => number;
133
+ cache: any;
134
+ block: Promise<Block>;
135
+ }
136
+
137
+ declare class Index {
138
+ blockstore: EncryptedBlockstore;
139
+ crdt: CRDT;
140
+ name: string | null;
141
+ mapFn: MapFn | null;
142
+ mapFnString: string;
143
+ byKey: IndexTree;
144
+ byId: IndexTree;
145
+ indexHead: ClockHead | undefined;
146
+ includeDocsDefault: boolean;
147
+ initError: Error | null;
148
+ ready: Promise<void>;
149
+ constructor(crdt: CRDT, name: string, mapFn?: MapFn, meta?: IdxMeta);
150
+ applyMapFn<T extends Record<string, any> = {}>(name: string, mapFn?: MapFn, meta?: IdxMeta): void;
151
+ query<T extends DocRecord = {}>(opts?: QueryOpts): Promise<{
152
+ rows: IndexRow<T>[];
153
+ }>;
154
+ _resetIndex(): void;
155
+ _hydrateIndex(): Promise<void>;
156
+ _updateIndex(): Promise<{
157
+ [x: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | {
158
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
159
+ } | null)[] | {
160
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
161
+ } | null)[] | {
162
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
163
+ } | null)[] | {
164
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
165
+ } | null)[] | {
166
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
167
+ } | null)[] | {
168
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
169
+ } | null)[] | {
170
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
171
+ } | null)[] | {
172
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
173
+ } | null)[] | {
174
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
175
+ } | null)[] | {
176
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
177
+ } | null)[] | {
178
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
179
+ } | null)[] | {
180
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
181
+ } | null;
182
+ } | {
183
+ byId: IndexTree;
184
+ byKey: IndexTree;
185
+ }>;
186
+ }
187
+
188
+ type ApplyHeadTask = {
189
+ newHead: ClockHead;
190
+ prevHead: ClockHead;
191
+ updates: DocUpdate[] | null;
192
+ };
193
+ type ApplyHeadQueue = {
194
+ push(task: ApplyHeadTask): AsyncGenerator<{
195
+ updates: DocUpdate[];
196
+ all: boolean;
197
+ }, void, unknown>;
198
+ };
199
+
200
+ declare class CRDTClock {
201
+ head: ClockHead;
202
+ zoomers: Set<() => void>;
203
+ watchers: Set<(updates: DocUpdate[]) => void>;
204
+ emptyWatchers: Set<() => void>;
205
+ blockstore: EncryptedBlockstore | null;
206
+ applyHeadQueue: ApplyHeadQueue;
207
+ constructor();
208
+ setHead(head: ClockHead): void;
209
+ applyHead(newHead: ClockHead, prevHead: ClockHead, updates?: DocUpdate[] | null): Promise<void>;
210
+ processUpdates(updatesAcc: DocUpdate[], all: boolean, prevHead: ClockHead): Promise<void>;
211
+ notifyWatchers(updates: DocUpdate[]): void;
212
+ onTick(fn: (updates: DocUpdate[]) => void): void;
213
+ onTock(fn: () => void): void;
214
+ onZoom(fn: () => void): void;
215
+ int_applyHead(newHead: ClockHead, prevHead: ClockHead): Promise<void>;
216
+ }
217
+
218
+ declare class CRDT {
219
+ name: string | null;
220
+ opts: ConfigOpts;
221
+ ready: Promise<void>;
222
+ blockstore: EncryptedBlockstore;
223
+ indexBlockstore: EncryptedBlockstore;
224
+ indexers: Map<string, Index>;
225
+ clock: CRDTClock;
226
+ constructor(name?: string, opts?: ConfigOpts);
227
+ bulk(updates: DocUpdate[], options?: object): Promise<CRDTMeta>;
228
+ allDocs(): Promise<{
229
+ result: DocUpdate[];
230
+ head: ClockHead;
231
+ }>;
232
+ vis(): Promise<string>;
233
+ getBlock(cidString: string): Promise<multiformats_dist_types_src_block.Block<unknown, 113, 18, 1>>;
234
+ get(key: string): Promise<DocValue | null>;
235
+ changes(since?: ClockHead, opts?: ChangesOptions): Promise<{
236
+ result: DocUpdate[];
237
+ head: ClockHead;
238
+ }>;
239
+ compact(): Promise<void>;
240
+ }
241
+
242
+ type DbName = string | null;
243
+ declare class Database {
244
+ static databases: Map<string, Database>;
245
+ name: DbName;
246
+ opts: ConfigOpts;
247
+ _listening: boolean;
248
+ _listeners: Set<ListenerFn>;
249
+ _noupdate_listeners: Set<ListenerFn>;
250
+ _crdt: CRDT;
251
+ _writeQueue: WriteQueue;
252
+ blockstore: EncryptedBlockstore;
253
+ constructor(name?: string, opts?: ConfigOpts);
254
+ get<T extends DocRecord = {}>(id: string): Promise<Doc<T>>;
255
+ put<T extends DocRecord = {}>(doc: Doc<T>): Promise<DbResponse>;
256
+ del(id: string): Promise<DbResponse>;
257
+ changes<T extends DocRecord = {}>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
258
+ allDocs<T extends DocRecord = {}>(): Promise<{
259
+ rows: {
260
+ key: string;
261
+ value: Doc<T>;
262
+ }[];
263
+ clock: ClockHead;
264
+ }>;
265
+ allDocuments<T extends DocRecord = {}>(): Promise<{
266
+ rows: {
267
+ key: string;
268
+ value: Doc<T>;
269
+ }[];
270
+ clock: ClockHead;
271
+ }>;
272
+ subscribe(listener: ListenerFn | NoUpdateListenerFn, updates?: boolean): () => void;
273
+ query<T extends DocRecord = {}>(field: string | MapFn, opts?: QueryOpts): Promise<{
274
+ rows: IndexRow<T>[];
275
+ }>;
276
+ compact(): Promise<void>;
277
+ _notify(updates: DocUpdate[]): Promise<void>;
278
+ _no_update_notify(): Promise<void>;
279
+ }
280
+ type UpdateListenerFn = <T extends DocRecord = {}>(docs: Doc<T>[]) => Promise<void> | void;
281
+ type NoUpdateListenerFn = () => Promise<void> | void;
282
+ type ListenerFn = UpdateListenerFn | NoUpdateListenerFn;
283
+ declare function fireproof(name: string, opts?: ConfigOpts): Database;
284
+
285
+ export { Database, fireproof };
286
+ declare module '@fireproof/core'
@@ -0,0 +1,286 @@
1
+ import { Link, Block } from 'multiformats';
2
+ import { EventLink } from '@alanshaw/pail/clock';
3
+ import { EventData } from '@alanshaw/pail/crdt';
4
+ import * as _fireproof_encrypted_blockstore from '@fireproof/encrypted-blockstore';
5
+ import { DbMeta, EncryptedBlockstore } from '@fireproof/encrypted-blockstore';
6
+ import * as multiformats_dist_types_src_block from 'multiformats/dist/types/src/block';
7
+ import { ProllyNode as ProllyNode$1 } from 'prolly-trees/base';
8
+
9
+ type ConfigOpts = {
10
+ public?: boolean;
11
+ meta?: DbMeta;
12
+ persistIndexes?: boolean;
13
+ autoCompact?: number;
14
+ };
15
+ type ClockLink = EventLink<EventData>;
16
+ type ClockHead = ClockLink[];
17
+ type DocFragment = Uint8Array | string | number | boolean | null | AnyLink | DocFragment[] | {
18
+ [key: string]: DocFragment;
19
+ };
20
+ type DocRecord = Record<string, DocFragment>;
21
+ type Doc<T extends DocRecord = {}> = DocBase & DocBody<T>;
22
+ type DocBase = {
23
+ _id?: string;
24
+ _files?: DocFiles;
25
+ _publicFiles?: DocFiles;
26
+ };
27
+ type DocFileMeta = {
28
+ type: string;
29
+ size: number;
30
+ cid: AnyLink;
31
+ car?: AnyLink;
32
+ url?: string;
33
+ file?: () => Promise<File>;
34
+ };
35
+ type DocFiles = Record<string, DocFileMeta | File>;
36
+ type DocBody<T extends DocRecord = {}> = {
37
+ _id?: string;
38
+ } & {
39
+ [K in Exclude<keyof T, keyof DocBase>]: DocFragment;
40
+ } & T;
41
+ type DocUpdate = {
42
+ key: string;
43
+ value?: Record<string, any>;
44
+ del?: boolean;
45
+ clock?: AnyLink;
46
+ };
47
+ type DocValue = {
48
+ doc?: DocBase;
49
+ del?: boolean;
50
+ };
51
+ type IndexKey = [string, string] | string;
52
+ type IndexUpdate = {
53
+ key: IndexKey;
54
+ value?: DocFragment;
55
+ del?: boolean;
56
+ };
57
+ type IndexRow<T extends DocRecord = {}> = {
58
+ id: string;
59
+ key: IndexKey;
60
+ row?: DocFragment;
61
+ doc?: Doc<T> | null;
62
+ value?: DocFragment;
63
+ del?: boolean;
64
+ };
65
+ type CRDTMeta = {
66
+ head: ClockHead;
67
+ };
68
+ type IdxMeta = {
69
+ byId: AnyLink;
70
+ byKey: AnyLink;
71
+ map: string;
72
+ name: string;
73
+ head: ClockHead;
74
+ };
75
+ type QueryOpts = {
76
+ descending?: boolean;
77
+ limit?: number;
78
+ includeDocs?: boolean;
79
+ range?: [IndexKey, IndexKey];
80
+ key?: DocFragment;
81
+ keys?: DocFragment[];
82
+ prefix?: DocFragment | [DocFragment];
83
+ };
84
+ type AnyLink = Link<unknown, number, number, 1 | 0>;
85
+ type EmitFn = (k: DocFragment, v?: DocFragment) => void;
86
+ type MapFn = <T extends DocRecord = {}>(doc: Doc<T>, emit: EmitFn) => DocFragment | void;
87
+ type ChangesOptions = {
88
+ dirty?: boolean;
89
+ limit?: number;
90
+ };
91
+ type ChangesResponse<T extends DocRecord = {}> = {
92
+ clock: ClockHead;
93
+ rows: {
94
+ key: string;
95
+ value: Doc<T>;
96
+ }[];
97
+ };
98
+ type DbResponse = {
99
+ id: string;
100
+ clock: ClockHead;
101
+ };
102
+
103
+ type WriteQueue = {
104
+ push(task: DocUpdate): Promise<CRDTMeta>;
105
+ };
106
+
107
+ declare class IndexTree {
108
+ cid: AnyLink | null;
109
+ root: ProllyNode | null;
110
+ }
111
+ interface ProllyNode extends ProllyNode$1 {
112
+ getAllEntries<T extends DocRecord = {}>(): PromiseLike<{
113
+ [x: string]: any;
114
+ result: IndexRow<T>[];
115
+ }>;
116
+ getMany(removeIds: string[]): Promise<{
117
+ [x: string]: any;
118
+ result: IndexKey[];
119
+ }>;
120
+ range<T extends DocRecord = {}>(a: IndexKey, b: IndexKey): Promise<{
121
+ result: IndexRow<T>[];
122
+ }>;
123
+ get<T extends DocRecord = {}>(key: string): Promise<{
124
+ result: IndexRow<T>[];
125
+ }>;
126
+ bulk(bulk: IndexUpdate[]): PromiseLike<{
127
+ root: ProllyNode | null;
128
+ blocks: Block[];
129
+ }>;
130
+ address: Promise<Link>;
131
+ distance: number;
132
+ compare: (a: any, b: any) => number;
133
+ cache: any;
134
+ block: Promise<Block>;
135
+ }
136
+
137
+ declare class Index {
138
+ blockstore: EncryptedBlockstore;
139
+ crdt: CRDT;
140
+ name: string | null;
141
+ mapFn: MapFn | null;
142
+ mapFnString: string;
143
+ byKey: IndexTree;
144
+ byId: IndexTree;
145
+ indexHead: ClockHead | undefined;
146
+ includeDocsDefault: boolean;
147
+ initError: Error | null;
148
+ ready: Promise<void>;
149
+ constructor(crdt: CRDT, name: string, mapFn?: MapFn, meta?: IdxMeta);
150
+ applyMapFn<T extends Record<string, any> = {}>(name: string, mapFn?: MapFn, meta?: IdxMeta): void;
151
+ query<T extends DocRecord = {}>(opts?: QueryOpts): Promise<{
152
+ rows: IndexRow<T>[];
153
+ }>;
154
+ _resetIndex(): void;
155
+ _hydrateIndex(): Promise<void>;
156
+ _updateIndex(): Promise<{
157
+ [x: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | (string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | {
158
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
159
+ } | null)[] | {
160
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
161
+ } | null)[] | {
162
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
163
+ } | null)[] | {
164
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
165
+ } | null)[] | {
166
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
167
+ } | null)[] | {
168
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
169
+ } | null)[] | {
170
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
171
+ } | null)[] | {
172
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
173
+ } | null)[] | {
174
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
175
+ } | null)[] | {
176
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
177
+ } | null)[] | {
178
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
179
+ } | null)[] | {
180
+ [key: string]: string | number | boolean | Uint8Array | _fireproof_encrypted_blockstore.AnyLink | any | any | null;
181
+ } | null;
182
+ } | {
183
+ byId: IndexTree;
184
+ byKey: IndexTree;
185
+ }>;
186
+ }
187
+
188
+ type ApplyHeadTask = {
189
+ newHead: ClockHead;
190
+ prevHead: ClockHead;
191
+ updates: DocUpdate[] | null;
192
+ };
193
+ type ApplyHeadQueue = {
194
+ push(task: ApplyHeadTask): AsyncGenerator<{
195
+ updates: DocUpdate[];
196
+ all: boolean;
197
+ }, void, unknown>;
198
+ };
199
+
200
+ declare class CRDTClock {
201
+ head: ClockHead;
202
+ zoomers: Set<() => void>;
203
+ watchers: Set<(updates: DocUpdate[]) => void>;
204
+ emptyWatchers: Set<() => void>;
205
+ blockstore: EncryptedBlockstore | null;
206
+ applyHeadQueue: ApplyHeadQueue;
207
+ constructor();
208
+ setHead(head: ClockHead): void;
209
+ applyHead(newHead: ClockHead, prevHead: ClockHead, updates?: DocUpdate[] | null): Promise<void>;
210
+ processUpdates(updatesAcc: DocUpdate[], all: boolean, prevHead: ClockHead): Promise<void>;
211
+ notifyWatchers(updates: DocUpdate[]): void;
212
+ onTick(fn: (updates: DocUpdate[]) => void): void;
213
+ onTock(fn: () => void): void;
214
+ onZoom(fn: () => void): void;
215
+ int_applyHead(newHead: ClockHead, prevHead: ClockHead): Promise<void>;
216
+ }
217
+
218
+ declare class CRDT {
219
+ name: string | null;
220
+ opts: ConfigOpts;
221
+ ready: Promise<void>;
222
+ blockstore: EncryptedBlockstore;
223
+ indexBlockstore: EncryptedBlockstore;
224
+ indexers: Map<string, Index>;
225
+ clock: CRDTClock;
226
+ constructor(name?: string, opts?: ConfigOpts);
227
+ bulk(updates: DocUpdate[], options?: object): Promise<CRDTMeta>;
228
+ allDocs(): Promise<{
229
+ result: DocUpdate[];
230
+ head: ClockHead;
231
+ }>;
232
+ vis(): Promise<string>;
233
+ getBlock(cidString: string): Promise<multiformats_dist_types_src_block.Block<unknown, 113, 18, 1>>;
234
+ get(key: string): Promise<DocValue | null>;
235
+ changes(since?: ClockHead, opts?: ChangesOptions): Promise<{
236
+ result: DocUpdate[];
237
+ head: ClockHead;
238
+ }>;
239
+ compact(): Promise<void>;
240
+ }
241
+
242
+ type DbName = string | null;
243
+ declare class Database {
244
+ static databases: Map<string, Database>;
245
+ name: DbName;
246
+ opts: ConfigOpts;
247
+ _listening: boolean;
248
+ _listeners: Set<ListenerFn>;
249
+ _noupdate_listeners: Set<ListenerFn>;
250
+ _crdt: CRDT;
251
+ _writeQueue: WriteQueue;
252
+ blockstore: EncryptedBlockstore;
253
+ constructor(name?: string, opts?: ConfigOpts);
254
+ get<T extends DocRecord = {}>(id: string): Promise<Doc<T>>;
255
+ put<T extends DocRecord = {}>(doc: Doc<T>): Promise<DbResponse>;
256
+ del(id: string): Promise<DbResponse>;
257
+ changes<T extends DocRecord = {}>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
258
+ allDocs<T extends DocRecord = {}>(): Promise<{
259
+ rows: {
260
+ key: string;
261
+ value: Doc<T>;
262
+ }[];
263
+ clock: ClockHead;
264
+ }>;
265
+ allDocuments<T extends DocRecord = {}>(): Promise<{
266
+ rows: {
267
+ key: string;
268
+ value: Doc<T>;
269
+ }[];
270
+ clock: ClockHead;
271
+ }>;
272
+ subscribe(listener: ListenerFn | NoUpdateListenerFn, updates?: boolean): () => void;
273
+ query<T extends DocRecord = {}>(field: string | MapFn, opts?: QueryOpts): Promise<{
274
+ rows: IndexRow<T>[];
275
+ }>;
276
+ compact(): Promise<void>;
277
+ _notify(updates: DocUpdate[]): Promise<void>;
278
+ _no_update_notify(): Promise<void>;
279
+ }
280
+ type UpdateListenerFn = <T extends DocRecord = {}>(docs: Doc<T>[]) => Promise<void> | void;
281
+ type NoUpdateListenerFn = () => Promise<void> | void;
282
+ type ListenerFn = UpdateListenerFn | NoUpdateListenerFn;
283
+ declare function fireproof(name: string, opts?: ConfigOpts): Database;
284
+
285
+ export { Database, fireproof };
286
+ declare module '@fireproof/core'