js-bao 0.3.0 → 0.4.0

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/client.cjs CHANGED
@@ -337,7 +337,8 @@ var DOClientEngine = class extends DatabaseEngine {
337
337
  data,
338
338
  stringSets,
339
339
  ifNotExists: options?.ifNotExists,
340
- condition: options?.condition
340
+ condition: options?.condition,
341
+ upsertOn: options?.upsertOn
341
342
  };
342
343
  const response = await this.doFetch("/save", request);
343
344
  return response.id;
@@ -670,22 +671,24 @@ function createModelAccessor(engine, modelName) {
670
671
  return result.data.length > 0 ? result.data[0] : null;
671
672
  },
672
673
  save: (data, options) => {
673
- if (!data.id) {
674
- throw new Error("Record must have an 'id' field");
675
- }
676
674
  let stringSets;
677
675
  let ifNotExists;
678
676
  let condition;
677
+ let upsertOn;
679
678
  if (options && typeof options === "object") {
680
- if (options.ifNotExists !== void 0 || options.stringSets !== void 0 || options.condition !== void 0) {
679
+ if (options.ifNotExists !== void 0 || options.stringSets !== void 0 || options.condition !== void 0 || options.upsertOn !== void 0) {
681
680
  stringSets = options.stringSets;
682
681
  ifNotExists = options.ifNotExists;
683
682
  condition = options.condition;
683
+ upsertOn = options.upsertOn;
684
684
  } else {
685
685
  stringSets = options;
686
686
  }
687
687
  }
688
- return engine.saveModel(modelName, data.id, data, stringSets, { ifNotExists, condition });
688
+ if (!data.id && !upsertOn) {
689
+ throw new Error("Record must have an 'id' field (or use upsertOn)");
690
+ }
691
+ return engine.saveModel(modelName, data.id, data, stringSets, { ifNotExists, condition, upsertOn });
689
692
  },
690
693
  patch: (id, data, options) => {
691
694
  let stringSets;
@@ -772,22 +775,24 @@ function connectDoDb(options) {
772
775
  return result.data.length > 0 ? result.data[0] : null;
773
776
  },
774
777
  save: (model, data, options2) => {
775
- if (!data.id) {
776
- throw new Error("Record must have an 'id' field");
777
- }
778
778
  let stringSets;
779
779
  let ifNotExists;
780
780
  let condition;
781
+ let upsertOn;
781
782
  if (options2 && typeof options2 === "object") {
782
- if (options2.ifNotExists !== void 0 || options2.stringSets !== void 0 || options2.condition !== void 0) {
783
+ if (options2.ifNotExists !== void 0 || options2.stringSets !== void 0 || options2.condition !== void 0 || options2.upsertOn !== void 0) {
783
784
  stringSets = options2.stringSets;
784
785
  ifNotExists = options2.ifNotExists;
785
786
  condition = options2.condition;
787
+ upsertOn = options2.upsertOn;
786
788
  } else {
787
789
  stringSets = options2;
788
790
  }
789
791
  }
790
- return engine.saveModel(resolveModelName(model), data.id, data, stringSets, { ifNotExists, condition });
792
+ if (!data.id && !upsertOn) {
793
+ throw new Error("Record must have an 'id' field (or use upsertOn)");
794
+ }
795
+ return engine.saveModel(resolveModelName(model), data.id, data, stringSets, { ifNotExists, condition, upsertOn });
791
796
  },
792
797
  patch: (model, id2, data, options2) => {
793
798
  let stringSets;
package/dist/client.d.cts CHANGED
@@ -825,9 +825,10 @@ declare class DOClientEngine extends DatabaseEngine {
825
825
  /**
826
826
  * Save a record to the DO.
827
827
  */
828
- saveModel(modelName: string, id: string, data: Record<string, any>, stringSets?: Record<string, string[]>, options?: {
828
+ saveModel(modelName: string, id: string | undefined, data: Record<string, any>, stringSets?: Record<string, string[]>, options?: {
829
829
  ifNotExists?: boolean;
830
830
  condition?: DocumentFilter;
831
+ upsertOn?: string;
831
832
  }): Promise<string>;
832
833
  /**
833
834
  * Patch (partial update) a record in the DO.
@@ -1017,6 +1018,7 @@ interface SaveOptions {
1017
1018
  stringSets?: Record<string, string[]>;
1018
1019
  ifNotExists?: boolean;
1019
1020
  condition?: DocumentFilter;
1021
+ upsertOn?: string;
1020
1022
  }
1021
1023
  interface PatchOptions {
1022
1024
  stringSets?: Record<string, string[]>;
package/dist/client.d.ts CHANGED
@@ -825,9 +825,10 @@ declare class DOClientEngine extends DatabaseEngine {
825
825
  /**
826
826
  * Save a record to the DO.
827
827
  */
828
- saveModel(modelName: string, id: string, data: Record<string, any>, stringSets?: Record<string, string[]>, options?: {
828
+ saveModel(modelName: string, id: string | undefined, data: Record<string, any>, stringSets?: Record<string, string[]>, options?: {
829
829
  ifNotExists?: boolean;
830
830
  condition?: DocumentFilter;
831
+ upsertOn?: string;
831
832
  }): Promise<string>;
832
833
  /**
833
834
  * Patch (partial update) a record in the DO.
@@ -1017,6 +1018,7 @@ interface SaveOptions {
1017
1018
  stringSets?: Record<string, string[]>;
1018
1019
  ifNotExists?: boolean;
1019
1020
  condition?: DocumentFilter;
1021
+ upsertOn?: string;
1020
1022
  }
1021
1023
  interface PatchOptions {
1022
1024
  stringSets?: Record<string, string[]>;
package/dist/client.js CHANGED
@@ -302,7 +302,8 @@ var DOClientEngine = class extends DatabaseEngine {
302
302
  data,
303
303
  stringSets,
304
304
  ifNotExists: options?.ifNotExists,
305
- condition: options?.condition
305
+ condition: options?.condition,
306
+ upsertOn: options?.upsertOn
306
307
  };
307
308
  const response = await this.doFetch("/save", request);
308
309
  return response.id;
@@ -635,22 +636,24 @@ function createModelAccessor(engine, modelName) {
635
636
  return result.data.length > 0 ? result.data[0] : null;
636
637
  },
637
638
  save: (data, options) => {
638
- if (!data.id) {
639
- throw new Error("Record must have an 'id' field");
640
- }
641
639
  let stringSets;
642
640
  let ifNotExists;
643
641
  let condition;
642
+ let upsertOn;
644
643
  if (options && typeof options === "object") {
645
- if (options.ifNotExists !== void 0 || options.stringSets !== void 0 || options.condition !== void 0) {
644
+ if (options.ifNotExists !== void 0 || options.stringSets !== void 0 || options.condition !== void 0 || options.upsertOn !== void 0) {
646
645
  stringSets = options.stringSets;
647
646
  ifNotExists = options.ifNotExists;
648
647
  condition = options.condition;
648
+ upsertOn = options.upsertOn;
649
649
  } else {
650
650
  stringSets = options;
651
651
  }
652
652
  }
653
- return engine.saveModel(modelName, data.id, data, stringSets, { ifNotExists, condition });
653
+ if (!data.id && !upsertOn) {
654
+ throw new Error("Record must have an 'id' field (or use upsertOn)");
655
+ }
656
+ return engine.saveModel(modelName, data.id, data, stringSets, { ifNotExists, condition, upsertOn });
654
657
  },
655
658
  patch: (id, data, options) => {
656
659
  let stringSets;
@@ -737,22 +740,24 @@ function connectDoDb(options) {
737
740
  return result.data.length > 0 ? result.data[0] : null;
738
741
  },
739
742
  save: (model, data, options2) => {
740
- if (!data.id) {
741
- throw new Error("Record must have an 'id' field");
742
- }
743
743
  let stringSets;
744
744
  let ifNotExists;
745
745
  let condition;
746
+ let upsertOn;
746
747
  if (options2 && typeof options2 === "object") {
747
- if (options2.ifNotExists !== void 0 || options2.stringSets !== void 0 || options2.condition !== void 0) {
748
+ if (options2.ifNotExists !== void 0 || options2.stringSets !== void 0 || options2.condition !== void 0 || options2.upsertOn !== void 0) {
748
749
  stringSets = options2.stringSets;
749
750
  ifNotExists = options2.ifNotExists;
750
751
  condition = options2.condition;
752
+ upsertOn = options2.upsertOn;
751
753
  } else {
752
754
  stringSets = options2;
753
755
  }
754
756
  }
755
- return engine.saveModel(resolveModelName(model), data.id, data, stringSets, { ifNotExists, condition });
757
+ if (!data.id && !upsertOn) {
758
+ throw new Error("Record must have an 'id' field (or use upsertOn)");
759
+ }
760
+ return engine.saveModel(resolveModelName(model), data.id, data, stringSets, { ifNotExists, condition, upsertOn });
756
761
  },
757
762
  patch: (model, id2, data, options2) => {
758
763
  let stringSets;