@fireproof/core 0.5.18 → 0.5.19
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/dist/src/clock.js +3 -3
- package/dist/src/database.js +13 -3
- package/dist/src/fireproof.d.ts +4 -28
- package/dist/src/fireproof.js +17 -6
- package/dist/src/fireproof.js.map +1 -1
- package/dist/src/fireproof.mjs +17 -6
- package/dist/src/fireproof.mjs.map +1 -1
- package/package.json +2 -2
- package/src/clock.js +3 -3
- package/src/database.js +14 -3
package/dist/src/clock.js
CHANGED
@@ -78,7 +78,7 @@ export class EventBlock extends Block {
|
|
78
78
|
* @param {Uint8Array} config.bytes
|
79
79
|
*/
|
80
80
|
constructor({ cid, value, bytes }) {
|
81
|
-
// @ts-
|
81
|
+
// @ts-ignore
|
82
82
|
super({ cid, value, bytes });
|
83
83
|
}
|
84
84
|
/**
|
@@ -129,7 +129,7 @@ export class EventFetcher {
|
|
129
129
|
export async function encodeEventBlock(value) {
|
130
130
|
// TODO: sort parents
|
131
131
|
const { cid, bytes } = await encode({ value, codec: cbor, hasher: sha256 });
|
132
|
-
// @ts-
|
132
|
+
// @ts-ignore
|
133
133
|
return new Block({ cid, value, bytes });
|
134
134
|
}
|
135
135
|
/**
|
@@ -139,7 +139,7 @@ export async function encodeEventBlock(value) {
|
|
139
139
|
*/
|
140
140
|
export async function decodeEventBlock(bytes) {
|
141
141
|
const { cid, value } = await decode({ bytes, codec: cbor, hasher: sha256 });
|
142
|
-
// @ts-
|
142
|
+
// @ts-ignore
|
143
143
|
return new Block({ cid, value, bytes });
|
144
144
|
}
|
145
145
|
/**
|
package/dist/src/database.js
CHANGED
@@ -75,6 +75,17 @@ export class Database {
|
|
75
75
|
localSet('fp.' + this.name, JSON.stringify(this));
|
76
76
|
}
|
77
77
|
}
|
78
|
+
index(name) {
|
79
|
+
// iterate over the indexes and gather any with the same name
|
80
|
+
// if there are more than one, throw an error
|
81
|
+
// if there is one, return it
|
82
|
+
// if there are none, return null
|
83
|
+
const indexes = [...this.indexes.values()].filter(index => index.name === name);
|
84
|
+
if (indexes.length > 1) {
|
85
|
+
throw new Error(`Multiple indexes found with name ${name}`);
|
86
|
+
}
|
87
|
+
return indexes[0] || null;
|
88
|
+
}
|
78
89
|
/**
|
79
90
|
* Triggers a notification to all listeners
|
80
91
|
* of the Fireproof instance so they can repaint UI, etc.
|
@@ -215,12 +226,11 @@ export class Database {
|
|
215
226
|
return doc;
|
216
227
|
}
|
217
228
|
/**
|
218
|
-
* @typedef {
|
229
|
+
* @typedef {any} Document
|
219
230
|
* @property {string} _id - The ID of the document (required)
|
220
231
|
* @property {string} [_proof] - The proof of the document (optional)
|
221
232
|
* @property {string} [_clock] - The clock of the document (optional)
|
222
|
-
* @property {any} [
|
223
|
-
* * @property {Object.<string, any>} [otherProperties] - Any other unknown properties (optional)
|
233
|
+
* @property {Object.<string, any>} [unknown: string] - Any other unknown properties (optional)
|
224
234
|
*/
|
225
235
|
/**
|
226
236
|
* Adds a new document to the database, or updates an existing document. Returns the ID of the document and the new clock head.
|
package/dist/src/fireproof.d.ts
CHANGED
@@ -236,6 +236,7 @@ declare class Database {
|
|
236
236
|
indexCar: any;
|
237
237
|
}): void;
|
238
238
|
maybeSaveClock(): void;
|
239
|
+
index(name: any): any;
|
239
240
|
/**
|
240
241
|
* Triggers a notification to all listeners
|
241
242
|
* of the Fireproof instance so they can repaint UI, etc.
|
@@ -290,12 +291,11 @@ declare class Database {
|
|
290
291
|
_id: string;
|
291
292
|
}>;
|
292
293
|
/**
|
293
|
-
* @typedef {
|
294
|
+
* @typedef {any} Document
|
294
295
|
* @property {string} _id - The ID of the document (required)
|
295
296
|
* @property {string} [_proof] - The proof of the document (optional)
|
296
297
|
* @property {string} [_clock] - The clock of the document (optional)
|
297
|
-
* @property {any} [
|
298
|
-
* * @property {Object.<string, any>} [otherProperties] - Any other unknown properties (optional)
|
298
|
+
* @property {Object.<string, any>} [unknown: string] - Any other unknown properties (optional)
|
299
299
|
*/
|
300
300
|
/**
|
301
301
|
* Adds a new document to the database, or updates an existing document. Returns the ID of the document and the new clock head.
|
@@ -305,31 +305,7 @@ declare class Database {
|
|
305
305
|
* @memberof Fireproof
|
306
306
|
* @instance
|
307
307
|
*/
|
308
|
-
put({ _id, _proof, ...doc }: {
|
309
|
-
/**
|
310
|
-
* - The ID of the document (required)
|
311
|
-
*/
|
312
|
-
_id: string;
|
313
|
-
/**
|
314
|
-
* - The proof of the document (optional)
|
315
|
-
*/
|
316
|
-
_proof?: string;
|
317
|
-
/**
|
318
|
-
* - The clock of the document (optional)
|
319
|
-
*/
|
320
|
-
_clock?: string;
|
321
|
-
/**
|
322
|
-
* : string] - Index signature notation to allow any other unknown fields
|
323
|
-
* *
|
324
|
-
*/
|
325
|
-
key?: any;
|
326
|
-
/**
|
327
|
-
* - Any other unknown properties (optional)
|
328
|
-
*/
|
329
|
-
otherProperties?: {
|
330
|
-
[x: string]: any;
|
331
|
-
};
|
332
|
-
}): Promise<{
|
308
|
+
put({ _id, _proof, ...doc }: any): Promise<{
|
333
309
|
id: string;
|
334
310
|
clock: CID[];
|
335
311
|
}>;
|
package/dist/src/fireproof.js
CHANGED
@@ -5566,7 +5566,7 @@ class EventBlock extends Block {
|
|
5566
5566
|
* @param {Uint8Array} config.bytes
|
5567
5567
|
*/
|
5568
5568
|
constructor ({ cid, value, bytes }) {
|
5569
|
-
// @ts-
|
5569
|
+
// @ts-ignore
|
5570
5570
|
super({ cid, value, bytes });
|
5571
5571
|
}
|
5572
5572
|
|
@@ -5620,7 +5620,7 @@ class EventFetcher {
|
|
5620
5620
|
async function encodeEventBlock (value) {
|
5621
5621
|
// TODO: sort parents
|
5622
5622
|
const { cid, bytes } = await encode$7({ value, codec: codec$1, hasher: sha256$2 });
|
5623
|
-
// @ts-
|
5623
|
+
// @ts-ignore
|
5624
5624
|
return new Block({ cid, value, bytes })
|
5625
5625
|
}
|
5626
5626
|
|
@@ -5631,7 +5631,7 @@ async function encodeEventBlock (value) {
|
|
5631
5631
|
*/
|
5632
5632
|
async function decodeEventBlock (bytes) {
|
5633
5633
|
const { cid, value } = await decode$9({ bytes, codec: codec$1, hasher: sha256$2 });
|
5634
|
-
// @ts-
|
5634
|
+
// @ts-ignore
|
5635
5635
|
return new Block({ cid, value, bytes })
|
5636
5636
|
}
|
5637
5637
|
|
@@ -41014,6 +41014,18 @@ class Database {
|
|
41014
41014
|
}
|
41015
41015
|
}
|
41016
41016
|
|
41017
|
+
index (name) {
|
41018
|
+
// iterate over the indexes and gather any with the same name
|
41019
|
+
// if there are more than one, throw an error
|
41020
|
+
// if there is one, return it
|
41021
|
+
// if there are none, return null
|
41022
|
+
const indexes = [...this.indexes.values()].filter(index => index.name === name);
|
41023
|
+
if (indexes.length > 1) {
|
41024
|
+
throw new Error(`Multiple indexes found with name ${name}`)
|
41025
|
+
}
|
41026
|
+
return indexes[0] || null
|
41027
|
+
}
|
41028
|
+
|
41017
41029
|
/**
|
41018
41030
|
* Triggers a notification to all listeners
|
41019
41031
|
* of the Fireproof instance so they can repaint UI, etc.
|
@@ -41161,12 +41173,11 @@ class Database {
|
|
41161
41173
|
return doc
|
41162
41174
|
}
|
41163
41175
|
/**
|
41164
|
-
* @typedef {
|
41176
|
+
* @typedef {any} Document
|
41165
41177
|
* @property {string} _id - The ID of the document (required)
|
41166
41178
|
* @property {string} [_proof] - The proof of the document (optional)
|
41167
41179
|
* @property {string} [_clock] - The clock of the document (optional)
|
41168
|
-
* @property {any} [
|
41169
|
-
* * @property {Object.<string, any>} [otherProperties] - Any other unknown properties (optional)
|
41180
|
+
* @property {Object.<string, any>} [unknown: string] - Any other unknown properties (optional)
|
41170
41181
|
*/
|
41171
41182
|
|
41172
41183
|
/**
|