@fireproof/core 0.19.123 → 0.19.125
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/README.md +120 -61
- package/index.cjs +42 -3
- package/index.cjs.map +1 -1
- package/index.js +42 -3
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +1 -1
- package/react/index.cjs +64 -0
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +290 -2
- package/react/index.d.ts +290 -2
- package/react/index.js +54 -0
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/fireproof/crdt.test.ts +1 -1
- package/tests/fireproof/database.test.ts +55 -1
- package/tests/react/img-file.test.tsx +199 -0
- package/tests/react/useFireproof.test.tsx +629 -9
package/index.js
CHANGED
@@ -2648,6 +2648,41 @@ function toString(key, logger) {
|
|
2648
2648
|
throw logger.Error().Msg("Invalid key type").AsError();
|
2649
2649
|
}
|
2650
2650
|
}
|
2651
|
+
function sanitizeDocumentFields(obj) {
|
2652
|
+
if (Array.isArray(obj)) {
|
2653
|
+
return obj.map((item) => {
|
2654
|
+
if (typeof item === "object" && item !== null) {
|
2655
|
+
return sanitizeDocumentFields(item);
|
2656
|
+
}
|
2657
|
+
return item;
|
2658
|
+
});
|
2659
|
+
} else if (typeof obj === "object" && obj !== null) {
|
2660
|
+
if (obj instanceof Date) {
|
2661
|
+
return obj.toISOString();
|
2662
|
+
}
|
2663
|
+
const typedObj = obj;
|
2664
|
+
const result = {};
|
2665
|
+
for (const key in typedObj) {
|
2666
|
+
if (Object.hasOwnProperty.call(typedObj, key)) {
|
2667
|
+
const value = typedObj[key];
|
2668
|
+
if (value === null || !Number.isNaN(value) && value !== void 0) {
|
2669
|
+
if (typeof value === "object" && !key.startsWith("_")) {
|
2670
|
+
if (value instanceof Date) {
|
2671
|
+
result[key] = value.toISOString();
|
2672
|
+
} else {
|
2673
|
+
const sanitized = sanitizeDocumentFields(value);
|
2674
|
+
result[key] = sanitized;
|
2675
|
+
}
|
2676
|
+
} else {
|
2677
|
+
result[key] = value;
|
2678
|
+
}
|
2679
|
+
}
|
2680
|
+
}
|
2681
|
+
}
|
2682
|
+
return result;
|
2683
|
+
}
|
2684
|
+
return obj;
|
2685
|
+
}
|
2651
2686
|
async function applyBulkUpdateToCrdt(store, tblocks, head, updates, logger) {
|
2652
2687
|
let result = null;
|
2653
2688
|
if (updates.length > 1) {
|
@@ -3084,7 +3119,7 @@ var Index = class {
|
|
3084
3119
|
if (this.mapFn) {
|
3085
3120
|
if (mapFn) {
|
3086
3121
|
if (this.mapFn.toString() !== mapFn.toString()) {
|
3087
|
-
|
3122
|
+
this.logger.Error().Msg("cannot apply different mapFn app2");
|
3088
3123
|
}
|
3089
3124
|
}
|
3090
3125
|
} else {
|
@@ -3093,7 +3128,7 @@ var Index = class {
|
|
3093
3128
|
}
|
3094
3129
|
if (this.mapFnString) {
|
3095
3130
|
if (this.mapFnString !== mapFn.toString()) {
|
3096
|
-
|
3131
|
+
this.logger.Error().Str("mapFnString", this.mapFnString).Str("mapFn", mapFn.toString()).Msg("cannot apply different mapFn app");
|
3097
3132
|
}
|
3098
3133
|
} else {
|
3099
3134
|
this.mapFnString = mapFn.toString();
|
@@ -3442,6 +3477,10 @@ var CRDT = class {
|
|
3442
3477
|
async bulk(updates) {
|
3443
3478
|
await this.ready();
|
3444
3479
|
const prevHead = [...this.clock.head];
|
3480
|
+
updates = updates.map((dupdate) => ({
|
3481
|
+
...dupdate,
|
3482
|
+
value: sanitizeDocumentFields(dupdate.value)
|
3483
|
+
}));
|
3445
3484
|
const done = await this.blockstore.transaction(async (blocks) => {
|
3446
3485
|
const { head } = await applyBulkUpdateToCrdt(
|
3447
3486
|
this.blockstore.ebOpts.storeRuntime,
|
@@ -3780,7 +3819,7 @@ var INDEXDB_VERSION = "v0.19-indexdb";
|
|
3780
3819
|
|
3781
3820
|
// src/version.ts
|
3782
3821
|
var PACKAGE_VERSION = Object.keys({
|
3783
|
-
"0.19.
|
3822
|
+
"0.19.125": "xxxx"
|
3784
3823
|
})[0];
|
3785
3824
|
export {
|
3786
3825
|
CRDT,
|