@fireproof/core 0.19.123 → 0.19.124

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.cjs CHANGED
@@ -2683,6 +2683,41 @@ function toString(key, logger) {
2683
2683
  throw logger.Error().Msg("Invalid key type").AsError();
2684
2684
  }
2685
2685
  }
2686
+ function sanitizeDocumentFields(obj) {
2687
+ if (Array.isArray(obj)) {
2688
+ return obj.map((item) => {
2689
+ if (typeof item === "object" && item !== null) {
2690
+ return sanitizeDocumentFields(item);
2691
+ }
2692
+ return item;
2693
+ });
2694
+ } else if (typeof obj === "object" && obj !== null) {
2695
+ if (obj instanceof Date) {
2696
+ return obj.toISOString();
2697
+ }
2698
+ const typedObj = obj;
2699
+ const result = {};
2700
+ for (const key in typedObj) {
2701
+ if (Object.hasOwnProperty.call(typedObj, key)) {
2702
+ const value = typedObj[key];
2703
+ if (value === null || !Number.isNaN(value) && value !== void 0) {
2704
+ if (typeof value === "object" && !key.startsWith("_")) {
2705
+ if (value instanceof Date) {
2706
+ result[key] = value.toISOString();
2707
+ } else {
2708
+ const sanitized = sanitizeDocumentFields(value);
2709
+ result[key] = sanitized;
2710
+ }
2711
+ } else {
2712
+ result[key] = value;
2713
+ }
2714
+ }
2715
+ }
2716
+ }
2717
+ return result;
2718
+ }
2719
+ return obj;
2720
+ }
2686
2721
  async function applyBulkUpdateToCrdt(store, tblocks, head, updates, logger) {
2687
2722
  let result = null;
2688
2723
  if (updates.length > 1) {
@@ -3119,7 +3154,7 @@ var Index = class {
3119
3154
  if (this.mapFn) {
3120
3155
  if (mapFn) {
3121
3156
  if (this.mapFn.toString() !== mapFn.toString()) {
3122
- throw this.logger.Error().Msg("cannot apply different mapFn app2").AsError();
3157
+ this.logger.Error().Msg("cannot apply different mapFn app2");
3123
3158
  }
3124
3159
  }
3125
3160
  } else {
@@ -3128,7 +3163,7 @@ var Index = class {
3128
3163
  }
3129
3164
  if (this.mapFnString) {
3130
3165
  if (this.mapFnString !== mapFn.toString()) {
3131
- throw this.logger.Error().Str("mapFnString", this.mapFnString).Str("mapFn", mapFn.toString()).Msg("cannot apply different mapFn app").AsError();
3166
+ this.logger.Error().Str("mapFnString", this.mapFnString).Str("mapFn", mapFn.toString()).Msg("cannot apply different mapFn app");
3132
3167
  }
3133
3168
  } else {
3134
3169
  this.mapFnString = mapFn.toString();
@@ -3477,6 +3512,10 @@ var CRDT = class {
3477
3512
  async bulk(updates) {
3478
3513
  await this.ready();
3479
3514
  const prevHead = [...this.clock.head];
3515
+ updates = updates.map((dupdate) => ({
3516
+ ...dupdate,
3517
+ value: sanitizeDocumentFields(dupdate.value)
3518
+ }));
3480
3519
  const done = await this.blockstore.transaction(async (blocks) => {
3481
3520
  const { head } = await applyBulkUpdateToCrdt(
3482
3521
  this.blockstore.ebOpts.storeRuntime,
@@ -3815,6 +3854,6 @@ var INDEXDB_VERSION = "v0.19-indexdb";
3815
3854
 
3816
3855
  // src/version.ts
3817
3856
  var PACKAGE_VERSION = Object.keys({
3818
- "0.19.123": "xxxx"
3857
+ "0.19.124": "xxxx"
3819
3858
  })[0];
3820
3859
  //# sourceMappingURL=index.cjs.map