@fireproof/core 0.17.1 → 0.17.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/README.md +2 -2
  2. package/dist/browser/fireproof.cjs +3 -4
  3. package/dist/browser/fireproof.cjs.map +1 -1
  4. package/dist/browser/fireproof.d.cts +21 -24
  5. package/dist/browser/fireproof.d.ts +21 -24
  6. package/dist/browser/fireproof.global.js +15 -17
  7. package/dist/browser/fireproof.global.js.map +1 -1
  8. package/dist/browser/fireproof.js +3 -4
  9. package/dist/browser/fireproof.js.map +1 -1
  10. package/dist/browser/metafile-cjs.json +1 -1
  11. package/dist/browser/metafile-esm.json +1 -1
  12. package/dist/browser/metafile-iife.json +1 -1
  13. package/dist/memory/fireproof.cjs +3 -4
  14. package/dist/memory/fireproof.cjs.map +1 -1
  15. package/dist/memory/fireproof.d.cts +21 -24
  16. package/dist/memory/fireproof.d.ts +21 -24
  17. package/dist/memory/fireproof.global.js +15 -17
  18. package/dist/memory/fireproof.global.js.map +1 -1
  19. package/dist/memory/fireproof.js +3 -4
  20. package/dist/memory/fireproof.js.map +1 -1
  21. package/dist/memory/metafile-cjs.json +1 -1
  22. package/dist/memory/metafile-esm.json +1 -1
  23. package/dist/memory/metafile-iife.json +1 -1
  24. package/dist/node/fireproof.cjs +3 -4
  25. package/dist/node/fireproof.cjs.map +1 -1
  26. package/dist/node/fireproof.d.cts +21 -24
  27. package/dist/node/fireproof.d.ts +21 -24
  28. package/dist/node/fireproof.global.js +15 -17
  29. package/dist/node/fireproof.global.js.map +1 -1
  30. package/dist/node/fireproof.js +3 -4
  31. package/dist/node/fireproof.js.map +1 -1
  32. package/dist/node/metafile-cjs.json +1 -1
  33. package/dist/node/metafile-esm.json +1 -1
  34. package/dist/node/metafile-iife.json +1 -1
  35. package/package.json +3 -3
@@ -17,13 +17,16 @@ type ClockHead = ClockLink[];
17
17
  type DocFragment = Uint8Array | string | number | boolean | null | AnyLink | DocFragment[] | {
18
18
  [key: string]: DocFragment;
19
19
  };
20
- type DocRecord = Record<string, DocFragment>;
21
- type Doc<T extends DocRecord = {}> = DocBase & DocBody<T>;
20
+ type DocRecord<T> = {
21
+ [K in keyof T]: DocFragment;
22
+ };
23
+ type DocFiles = Record<string, DocFileMeta | File>;
22
24
  type DocBase = {
23
25
  _id?: string;
24
26
  _files?: DocFiles;
25
27
  _publicFiles?: DocFiles;
26
28
  };
29
+ type Doc<T extends DocRecord<T> = {}> = DocBase & T;
27
30
  type DocFileMeta = {
28
31
  type: string;
29
32
  size: number;
@@ -32,12 +35,6 @@ type DocFileMeta = {
32
35
  url?: string;
33
36
  file?: () => Promise<File>;
34
37
  };
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
38
  type DocUpdate = {
42
39
  key: string;
43
40
  value?: Record<string, any>;
@@ -54,7 +51,7 @@ type IndexUpdate = {
54
51
  value?: DocFragment;
55
52
  del?: boolean;
56
53
  };
57
- type IndexRow<T extends DocRecord = {}> = {
54
+ type IndexRow<T extends DocRecord<T> = {}> = {
58
55
  id: string;
59
56
  key: IndexKey;
60
57
  row?: DocFragment;
@@ -95,12 +92,12 @@ type AnyDecodedBlock = {
95
92
  value: any;
96
93
  };
97
94
  type EmitFn = (k: DocFragment, v?: DocFragment) => void;
98
- type MapFn = <T extends DocRecord = {}>(doc: Doc<T>, emit: EmitFn) => DocFragment | void;
95
+ type MapFn = <T extends DocRecord<T> = {}>(doc: Doc<T>, emit: EmitFn) => DocFragment | void;
99
96
  type ChangesOptions = {
100
97
  dirty?: boolean;
101
98
  limit?: number;
102
99
  };
103
- type ChangesResponse<T extends DocRecord = {}> = {
100
+ type ChangesResponse<T extends DocRecord<T> = {}> = {
104
101
  clock: ClockHead;
105
102
  rows: {
106
103
  key: string;
@@ -121,7 +118,7 @@ declare class IndexTree {
121
118
  root: ProllyNode | null;
122
119
  }
123
120
  interface ProllyNode extends ProllyNode$1 {
124
- getAllEntries<T extends DocRecord = {}>(): PromiseLike<{
121
+ getAllEntries<T extends DocRecord<T> = {}>(): PromiseLike<{
125
122
  [x: string]: any;
126
123
  result: IndexRow<T>[];
127
124
  }>;
@@ -129,10 +126,10 @@ interface ProllyNode extends ProllyNode$1 {
129
126
  [x: string]: any;
130
127
  result: IndexKey[];
131
128
  }>;
132
- range<T extends DocRecord = {}>(a: IndexKey, b: IndexKey): Promise<{
129
+ range<T extends DocRecord<T> = {}>(a: IndexKey, b: IndexKey): Promise<{
133
130
  result: IndexRow<T>[];
134
131
  }>;
135
- get<T extends DocRecord = {}>(key: string): Promise<{
132
+ get<T extends DocRecord<T> = {}>(key: string): Promise<{
136
133
  result: IndexRow<T>[];
137
134
  }>;
138
135
  bulk(bulk: IndexUpdate[]): PromiseLike<{
@@ -159,8 +156,8 @@ declare class Index {
159
156
  initError: Error | null;
160
157
  ready: Promise<void>;
161
158
  constructor(crdt: CRDT, name: string, mapFn?: MapFn, meta?: IdxMeta);
162
- applyMapFn<T extends Record<string, any> = {}>(name: string, mapFn?: MapFn, meta?: IdxMeta): void;
163
- query<T extends DocRecord = {}>(opts?: QueryOpts): Promise<{
159
+ applyMapFn<T extends DocRecord<T> = {}>(name: string, mapFn?: MapFn, meta?: IdxMeta): void;
160
+ query<T extends DocRecord<T> = {}>(opts?: QueryOpts): Promise<{
164
161
  rows: IndexRow<T>[];
165
162
  }>;
166
163
  _resetIndex(): void;
@@ -263,18 +260,18 @@ declare class Database {
263
260
  _writeQueue: WriteQueue;
264
261
  blockstore: EncryptedBlockstore;
265
262
  constructor(name?: string, opts?: ConfigOpts);
266
- get<T extends DocRecord = {}>(id: string): Promise<Doc<T>>;
267
- put<T extends DocRecord = {}>(doc: Doc<T>): Promise<DbResponse>;
263
+ get<T extends DocRecord<T> = {}>(id: string): Promise<Doc<T>>;
264
+ put<T extends DocRecord<T> = {}>(doc: Doc<T>): Promise<DbResponse>;
268
265
  del(id: string): Promise<DbResponse>;
269
- changes<T extends DocRecord = {}>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
270
- allDocs<T extends DocRecord = {}>(): Promise<{
266
+ changes<T extends DocRecord<T> = {}>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
267
+ allDocs<T extends DocRecord<T> = {}>(): Promise<{
271
268
  rows: {
272
269
  key: string;
273
270
  value: Doc<T>;
274
271
  }[];
275
272
  clock: ClockHead;
276
273
  }>;
277
- allDocuments<T extends DocRecord = {}>(): Promise<{
274
+ allDocuments<T extends DocRecord<T> = {}>(): Promise<{
278
275
  rows: {
279
276
  key: string;
280
277
  value: Doc<T>;
@@ -282,17 +279,17 @@ declare class Database {
282
279
  clock: ClockHead;
283
280
  }>;
284
281
  subscribe(listener: ListenerFn | NoUpdateListenerFn, updates?: boolean): () => void;
285
- query<T extends DocRecord = {}>(field: string | MapFn, opts?: QueryOpts): Promise<{
282
+ query<T extends DocRecord<T> = {}>(field: string | MapFn, opts?: QueryOpts): Promise<{
286
283
  rows: IndexRow<T>[];
287
284
  }>;
288
285
  compact(): Promise<void>;
289
286
  _notify(updates: DocUpdate[]): Promise<void>;
290
287
  _no_update_notify(): Promise<void>;
291
288
  }
292
- type UpdateListenerFn = <T extends DocRecord = {}>(docs: Doc<T>[]) => Promise<void> | void;
289
+ type UpdateListenerFn = <T extends DocRecord<T>>(docs: Doc<T>[]) => Promise<void> | void;
293
290
  type NoUpdateListenerFn = () => Promise<void> | void;
294
291
  type ListenerFn = UpdateListenerFn | NoUpdateListenerFn;
295
292
  declare function fireproof(name: string, opts?: ConfigOpts): Database;
296
293
 
297
- export { type AnyBlock, type AnyDecodedBlock, type AnyLink, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ClockHead, type ClockLink, type ConfigOpts, Database, type DbResponse, type Doc, type DocBase, type DocBody, type DocFileMeta, type DocFiles, type DocFragment, type DocRecord, type DocUpdate, type DocValue, type IdxMeta, type IdxMetaMap, type IndexKey, type IndexRow, type IndexUpdate, type MapFn, type QueryOpts, fireproof };
294
+ export { type AnyBlock, type AnyDecodedBlock, type AnyLink, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ClockHead, type ClockLink, type ConfigOpts, Database, type DbResponse, type Doc, type DocBase, type DocFileMeta, type DocFiles, type DocFragment, type DocRecord, type DocUpdate, type DocValue, type IdxMeta, type IdxMetaMap, type IndexKey, type IndexRow, type IndexUpdate, type MapFn, type QueryOpts, fireproof };
298
295
  declare module '@fireproof/core'
@@ -10157,8 +10157,7 @@ You can use close({ resize: true }) to resize header`);
10157
10157
  }
10158
10158
  async _commitInternal(t, done, opts = { noLoader: false, compact: false }) {
10159
10159
  await this.ready;
10160
- const header = done;
10161
- const fp = this.makeCarHeader(header, this.carLog, !!opts.compact);
10160
+ const fp = this.makeCarHeader(done, this.carLog, !!opts.compact);
10162
10161
  let roots = await this.prepareRoots(fp, t);
10163
10162
  const { cid, bytes } = await this.prepareCarFile(roots[0], t, !!opts.public);
10164
10163
  await this.carStore.save({ cid, bytes });
@@ -10189,10 +10188,9 @@ You can use close({ resize: true }) to resize header`);
10189
10188
  }
10190
10189
  async updateCarLog(cid, fp, compact) {
10191
10190
  if (compact) {
10192
- const fpCar = fp;
10193
- const previousCompactCid = this.carLog[this.carLog.length - 1];
10194
- fpCar.compact.map((c) => c.toString()).forEach(this.seenCompacted.add, this.seenCompacted);
10195
- this.carLog = [...uniqueCids([cid, ...this.carLog], this.seenCompacted)];
10191
+ const previousCompactCid = fp.compact[fp.compact.length - 1];
10192
+ fp.compact.map((c) => c.toString()).forEach(this.seenCompacted.add, this.seenCompacted);
10193
+ this.carLog = [...uniqueCids([...this.carLog, ...fp.cars, cid], this.seenCompacted)];
10196
10194
  void this.removeCidsForCompact(previousCompactCid);
10197
10195
  } else {
10198
10196
  this.carLog.unshift(cid);
@@ -10206,13 +10204,14 @@ You can use close({ resize: true }) to resize header`);
10206
10204
  await this.carStore.remove(cid2);
10207
10205
  }
10208
10206
  }
10209
- async flushCars() {
10210
- await this.ready;
10211
- for (const cid of this.carLog) {
10212
- const dbMeta = { car: cid, key: this.key || null };
10213
- await this.remoteWAL.enqueue(dbMeta, { public: false });
10214
- }
10215
- }
10207
+ // async flushCars() {
10208
+ // await this.ready
10209
+ // // for each cid in car log, make a dbMeta
10210
+ // for (const cid of this.carLog) {
10211
+ // const dbMeta = { car: cid, key: this.key || null } as DbMeta
10212
+ // await this.remoteWAL!.enqueue(dbMeta, { public: false })
10213
+ // }
10214
+ // }
10216
10215
  async *entries() {
10217
10216
  await this.ready;
10218
10217
  for (const [, block] of this.getBlockCache) {
@@ -20432,8 +20431,10 @@ You can use close({ resize: true }) to resize header`);
20432
20431
 
20433
20432
  // src/crdt-helpers.ts
20434
20433
  function time(tag2) {
20434
+ console.time(tag2);
20435
20435
  }
20436
20436
  function timeEnd(tag2) {
20437
+ console.timeEnd(tag2);
20437
20438
  }
20438
20439
  async function applyBulkUpdateToCrdt(tblocks, head, updates) {
20439
20440
  let result = null;
@@ -21200,7 +21201,7 @@ You can use close({ resize: true }) to resize header`);
21200
21201
  }
21201
21202
  } else {
21202
21203
  if (!mapFn) {
21203
- mapFn = makeMapFnFromName(name7);
21204
+ mapFn = (doc) => doc[name7] ?? void 0;
21204
21205
  }
21205
21206
  if (this.mapFnString) {
21206
21207
  if (this.mapFnString !== mapFn.toString())
@@ -21341,9 +21342,6 @@ You can use close({ resize: true }) to resize header`);
21341
21342
  });
21342
21343
  }
21343
21344
  };
21344
- function makeMapFnFromName(name7) {
21345
- return (doc) => doc[name7] ?? void 0;
21346
- }
21347
21345
 
21348
21346
  // src/apply-head-queue.ts
21349
21347
  function applyHeadQueue(worker) {