@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/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
- throw this.logger.Error().Msg("cannot apply different mapFn app2").AsError();
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
- throw this.logger.Error().Str("mapFnString", this.mapFnString).Str("mapFn", mapFn.toString()).Msg("cannot apply different mapFn app").AsError();
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.123": "xxxx"
3822
+ "0.19.125": "xxxx"
3784
3823
  })[0];
3785
3824
  export {
3786
3825
  CRDT,