rest-client-vue 1.0.0-a3 → 1.0.0-a4

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.
@@ -28,26 +28,26 @@ class ke extends Error {
28
28
  this.context = $, this.innerError = e;
29
29
  }
30
30
  }
31
- var O;
31
+ var _;
32
32
  class Ie {
33
33
  constructor() {
34
- Se(this, O, {});
34
+ Se(this, _, {});
35
35
  }
36
36
  clearAllStores() {
37
- for (const s in Q(this, O))
38
- Q(this, O)[s].clear();
37
+ for (const s in Q(this, _))
38
+ Q(this, _)[s].clear();
39
39
  }
40
40
  destroyStore(s) {
41
- Q(this, O)[s] && (Q(this, O)[s].$dispose(), delete Q(this, O)[s]);
41
+ Q(this, _)[s] && (Q(this, _)[s].$dispose(), delete Q(this, _)[s]);
42
42
  }
43
43
  getStore(s) {
44
- return Q(this, O)[s];
44
+ return Q(this, _)[s];
45
45
  }
46
46
  registerStore(s, R) {
47
- Q(this, O)[s] = R;
47
+ Q(this, _)[s] = R;
48
48
  }
49
49
  }
50
- O = new WeakMap();
50
+ _ = new WeakMap();
51
51
  function v(f, s) {
52
52
  return a.get(f, (s == null ? void 0 : s.idProperty) || "_id");
53
53
  }
@@ -681,7 +681,7 @@ const De = {
681
681
  return e.$id = R.$id, e;
682
682
  })();
683
683
  }, ie = new Ie(), Be = (f = {}) => {
684
- var oe, ce, ue, de;
684
+ var ne, ce, ue, de;
685
685
  console.log("hereaaaaaaa"), console.log(f);
686
686
  const {
687
687
  collectionId: s,
@@ -689,7 +689,7 @@ const De = {
689
689
  enabled: $,
690
690
  resourceType: e,
691
691
  options: r
692
- } = f, t = I(void 0), l = I(s), u = I(R), c = I($ ?? !0), d = I([te(e)]), y = I(r), E = S(() => u.value), T = I(c.value), b = I(H()), q = I((ce = (oe = y.value) == null ? void 0 : oe.filter) == null ? void 0 : ce.resourceIds), A = I((de = (ue = y.value) == null ? void 0 : ue.filter) == null ? void 0 : de.query), z = S(
692
+ } = f, t = I(void 0), l = I(s), u = I(R), c = I($ ?? !0), d = I([te(e)]), y = I(r), E = S(() => u.value), T = I(c.value), b = I(H()), q = I((ce = (ne = y.value) == null ? void 0 : ne.filter) == null ? void 0 : ce.resourceIds), A = I((de = (ue = y.value) == null ? void 0 : ue.filter) == null ? void 0 : de.query), z = S(
693
693
  () => u.value == null && l.value != null && ie.getStore(l.value) != null
694
694
  ), B = I(z.value), g = S(() => L("status", "Uninitialized"));
695
695
  function m(i) {
@@ -700,31 +700,31 @@ const De = {
700
700
  if (t.value)
701
701
  return await i(t.value);
702
702
  }
703
- function L(i, o) {
703
+ function L(i, n) {
704
704
  if (t.value)
705
705
  return t.value[i];
706
- if (o !== void 0)
707
- return o;
706
+ if (n !== void 0)
707
+ return n;
708
708
  throw "Attempted to use a REST collection store that has not been created, with no default value.";
709
709
  }
710
710
  const D = (i = {}) => {
711
711
  var fe, ve, ge, Re;
712
712
  const {
713
- collectionId: o,
713
+ collectionId: n,
714
714
  draftBatchId: w,
715
- enabled: _,
715
+ enabled: O,
716
716
  resourceType: se,
717
717
  options: he
718
718
  } = i;
719
- l.value = o, u.value = w, c.value = _ ?? !0, d.value = [te(se)], he != null && (y.value = he, q.value = (ve = (fe = y.value) == null ? void 0 : fe.filter) == null ? void 0 : ve.resourceIds, A.value = (Re = (ge = y.value) == null ? void 0 : ge.filter) == null ? void 0 : Re.query), b.value = H(), W(c.value);
719
+ l.value = n, u.value = w, c.value = O ?? !0, d.value = [te(se)], he != null && (y.value = he, q.value = (ve = (fe = y.value) == null ? void 0 : fe.filter) == null ? void 0 : ve.resourceIds, A.value = (Re = (ge = y.value) == null ? void 0 : ge.filter) == null ? void 0 : Re.query), b.value = H(), W(c.value);
720
720
  }, W = async (i) => {
721
721
  i != T.value && (T.value = i, i && (K(), N()));
722
722
  }, X = async (i) => {
723
- q.value = i, await U(async (o) => await o.setFilterResourceIds(q.value || null));
723
+ q.value = i, await U(async (n) => await n.setFilterResourceIds(q.value || null));
724
724
  }, J = async (i) => {
725
725
  if (A.value = i, g.value != "Uninitialized") {
726
- const o = i, w = S(() => a.isFunction(o) ? p.value ? o(p.value) : null : o);
727
- await U((_) => _.setQuery(w.value || null));
726
+ const n = i, w = S(() => a.isFunction(n) ? p.value ? n(p.value) : null : n);
727
+ await U((O) => O.setQuery(w.value || null));
728
728
  }
729
729
  }, K = () => {
730
730
  y.value = a.merge({}, y.value || {}, {
@@ -733,12 +733,12 @@ const De = {
733
733
  }, p = S(
734
734
  () => d.value[0].value || void 0
735
735
  ), k = function(i) {
736
- const o = a.get(i, "filter.query"), w = a.get(i, "referencePathsToExpand"), _ = a.isFunction(o) ? o(p.value) : o, se = p.value ? a.isFunction(w) ? w(p.value) : w || [] : [];
736
+ const n = a.get(i, "filter.query"), w = a.get(i, "referencePathsToExpand"), O = a.isFunction(n) ? n(p.value) : n, se = p.value ? a.isFunction(w) ? w(p.value) : w || [] : [];
737
737
  return {
738
738
  ...a.cloneDeep(i || {}),
739
739
  filter: {
740
740
  ...a.cloneDeep((i == null ? void 0 : i.filter) || {}),
741
- query: _
741
+ query: O
742
742
  },
743
743
  referencePathsToExpand: se
744
744
  };
@@ -749,7 +749,7 @@ const De = {
749
749
  return x.value.restCollectionUrl;
750
750
  if (!B.value)
751
751
  return !p.value || !p.value.collectionName ? null : E.value ? `${ee.config.apiBaseUrl}/draft-batches/${E.value}/${p.value.collectionName}` : `${ee.config.apiBaseUrl}/${p.value.collectionName}`;
752
- }), n = S(() => {
752
+ }), o = S(() => {
753
753
  var i;
754
754
  if (p.value)
755
755
  return a.mergeWith(
@@ -759,8 +759,8 @@ const De = {
759
759
  idProperty: (i = p.value) == null ? void 0 : i.idProperty,
760
760
  restCollectionUrl: M.value || ""
761
761
  },
762
- (o, w) => {
763
- if (a.isArray(w) && w.length == 0 && (o == null || a.isArray(o)))
762
+ (n, w) => {
763
+ if (a.isArray(w) && w.length == 0 && (n == null || a.isArray(n)))
764
764
  return w;
765
765
  }
766
766
  );
@@ -772,34 +772,34 @@ const De = {
772
772
  ), N = () => {
773
773
  if (T.value) {
774
774
  let i = !1;
775
- return p.value && F.value && (t.value = ie.getStore(F.value), t.value ? i = !1 : n.value && (B.value = !1, t.value = Pe(F.value, n.value)(), i = !0)), i;
775
+ return p.value && F.value && (t.value = ie.getStore(F.value), t.value ? i = !1 : o.value && (B.value = !1, t.value = Pe(F.value, o.value)(), i = !0)), i;
776
776
  } else
777
777
  return !1;
778
778
  }, G = () => {
779
779
  F.value && l.value == F.value ? (t.value = void 0, N()) : (t.value = void 0, h.value = h.value + 1, N());
780
780
  };
781
- C(E, (i, o) => {
782
- a.isEqual(i, o) || G();
783
- }), C(T, (i, o) => {
784
- i != o && (i ? N() : t.value = void 0);
785
- }), C(p, (i, o) => {
786
- i && !o ? N() : !i && o || a.isEqual(i, o) || G();
787
- }), C(n, (i, o) => {
788
- a.isEqual(i, o) || G();
781
+ C(E, (i, n) => {
782
+ a.isEqual(i, n) || G();
783
+ }), C(T, (i, n) => {
784
+ i != n && (i ? N() : t.value = void 0);
785
+ }), C(p, (i, n) => {
786
+ i && !n ? N() : !i && n || a.isEqual(i, n) || G();
787
+ }), C(o, (i, n) => {
788
+ a.isEqual(i, n) || G();
789
789
  }), C(z, () => {
790
790
  z.value || (B.value = !1);
791
- }), C(F, () => N()), C(M, (i, o) => {
792
- a.isEqual(i, o) || G();
791
+ }), C(F, () => N()), C(M, (i, n) => {
792
+ a.isEqual(i, n) || G();
793
793
  });
794
794
  const j = [], Ue = function(i) {
795
795
  g.value != "Uninitialized" ? Le(i) : j.push(i);
796
796
  };
797
- return C(g, (i, o) => {
798
- if (i != "Uninitialized" && o == "Uninitialized") {
797
+ return C(g, (i, n) => {
798
+ if (i != "Uninitialized" && n == "Uninitialized") {
799
799
  const w = a.clone(j);
800
800
  j.splice(0, j.length);
801
- for (const _ of w)
802
- _();
801
+ for (const O of w)
802
+ O();
803
803
  }
804
804
  }), N(), {
805
805
  // Configuration
@@ -823,7 +823,7 @@ const De = {
823
823
  // Methods: Configuration
824
824
  reconfigureCollection: D,
825
825
  setEditingDetailSelection: (i) => m(
826
- (o) => o.setEditingDetailSelection(i)
826
+ (n) => n.setEditingDetailSelection(i)
827
827
  ),
828
828
  setEnabled: W,
829
829
  setFilterResourceIds: X,
@@ -831,46 +831,46 @@ const De = {
831
831
  // Methods: Status
832
832
  ensureStore: N,
833
833
  // TODO Rename
834
- setBatchSaveAttempted: (i) => m((o) => o.setBatchSaveAttempted(i)),
834
+ setBatchSaveAttempted: (i) => m((n) => n.setBatchSaveAttempted(i)),
835
835
  // Local collection management
836
836
  clear: () => m((i) => i.clear()),
837
837
  ensureCollectionLoaded: async () => await U(async (i) => i.ensureCollectionLoaded()),
838
838
  loadResources: async () => await U(async (i) => await i.loadResources()),
839
839
  // Methods: Recording changes to the collection
840
- addResource: (i) => m((o) => o.addResource(i)),
841
- checkForDeletedResource: async (i) => await U(async (o) => await o.checkForDeletedResource(i)) == !0,
842
- recordDeletion: (i) => m((o) => o.recordDeletion(i)),
843
- recordInsertion: (i, { insertAtBeginning: o = !1, transientData: w = void 0 } = {}) => m((_) => _.recordInsertion(i, { insertAtBeginning: o, transientData: w })),
844
- recordUpdate: (i) => m((o) => o.recordUpdate(i)),
840
+ addResource: (i) => m((n) => n.addResource(i)),
841
+ checkForDeletedResource: async (i) => await U(async (n) => await n.checkForDeletedResource(i)) == !0,
842
+ recordDeletion: (i) => m((n) => n.recordDeletion(i)),
843
+ recordInsertion: (i, { insertAtBeginning: n = !1, transientData: w = void 0 } = {}) => m((O) => O.recordInsertion(i, { insertAtBeginning: n, transientData: w })),
844
+ recordUpdate: (i) => m((n) => n.recordUpdate(i)),
845
845
  refreshResource: async (i) => await U(
846
- async (o) => await o.refreshResource(i)
846
+ async (n) => await n.refreshResource(i)
847
847
  ),
848
848
  // Methods: Modifying the collection
849
849
  deleteResource: async (i) => await U(
850
- async (o) => await o.deleteResource(i)
850
+ async (n) => await n.deleteResource(i)
851
851
  ),
852
- saveResource: async (i) => await U(async (o) => await o.saveResource(i)),
853
- saveResources: async (i) => await U(async (o) => await o.saveResources(i)),
852
+ saveResource: async (i) => await U(async (n) => await n.saveResource(i)),
853
+ saveResources: async (i) => await U(async (n) => await n.saveResources(i)),
854
854
  // Methods: Transient data
855
855
  clearTransientData: () => m((i) => i.clearTransientData()),
856
- setInvalidResourceIds: (i) => m((o) => o.setInvalidResourceIds(i)),
856
+ setInvalidResourceIds: (i) => m((n) => n.setInvalidResourceIds(i)),
857
857
  setTransientDataForResources: (i) => m(
858
- (o) => o.setTransientDataForResources(i)
858
+ (n) => n.setTransientDataForResources(i)
859
859
  ),
860
860
  // Methods: Selection and detail selection
861
861
  clearSelection: () => m((i) => i.clearSelection()),
862
- deselectResources: (i) => m((o) => o.deselectResources(i)),
863
- selectResources: (i, o) => m(
864
- (w) => w.selectResources(i, o)
862
+ deselectResources: (i) => m((n) => n.deselectResources(i)),
863
+ selectResources: (i, n) => m(
864
+ (w) => w.selectResources(i, n)
865
865
  ),
866
866
  // Methods: Managing the detail view
867
867
  hideDetail: () => m((i) => i.hideDetail()),
868
868
  // Methods: Editors
869
- deregisterEditor: (i) => m((o) => o.deregisterEditor(i)),
870
- registerEditor: (i) => m((o) => o.registerEditor(i)),
869
+ deregisterEditor: (i) => m((n) => n.deregisterEditor(i)),
870
+ registerEditor: (i) => m((n) => n.registerEditor(i)),
871
871
  // Methods: List navigators
872
- deregisterListNavigator: (i) => m((o) => o.deregisterListNavigator(i)),
873
- registerListNavigator: (i) => m((o) => o.registerListNavigator(i)),
872
+ deregisterListNavigator: (i) => m((n) => n.deregisterListNavigator(i)),
873
+ registerListNavigator: (i) => m((n) => n.registerListNavigator(i)),
874
874
  // Callbacks
875
875
  onItemsStoreReady: Ue
876
876
  };
@@ -1110,11 +1110,11 @@ const Ee = {
1110
1110
  return (() => {
1111
1111
  const e = (r, t) => {
1112
1112
  const l = R(r, t);
1113
- return ne.registerStore(l.$id, l), l;
1113
+ return oe.registerStore(l.$id, l), l;
1114
1114
  };
1115
1115
  return e.$id = R.$id, e;
1116
1116
  })();
1117
- }, ne = new Ie(), Me = (f = {}) => {
1117
+ }, oe = new Ie(), Me = (f = {}) => {
1118
1118
  console.log("HERE!!!!"), console.log(f);
1119
1119
  const {
1120
1120
  resourceClientId: s,
@@ -1123,40 +1123,40 @@ const Ee = {
1123
1123
  resourceType: e,
1124
1124
  options: r
1125
1125
  } = f, t = I(void 0), l = I(s), u = I(R), c = I($ ?? !0), d = I([te(e)]), y = I(r), E = S(() => u.value), T = I(c.value), b = I(H()), q = S(
1126
- () => u.value == null && l.value != null && ne.getStore(l.value) != null
1126
+ () => u.value == null && l.value != null && oe.getStore(l.value) != null
1127
1127
  ), A = I(q.value), z = S(() => m("status", "Uninitialized"));
1128
- function B(n) {
1128
+ function B(o) {
1129
1129
  if (t.value)
1130
- return n(t.value);
1130
+ return o(t.value);
1131
1131
  }
1132
- async function g(n) {
1133
- if (t.value)
1134
- return await n(t.value);
1132
+ async function g(o) {
1133
+ if (console.log("dispatchAsync"), console.log("STORE:"), console.log(t.value), t.value)
1134
+ return await o(t.value);
1135
1135
  }
1136
- function m(n, h) {
1136
+ function m(o, h) {
1137
1137
  if (t.value)
1138
- return t.value[n];
1138
+ return t.value[o];
1139
1139
  if (h !== void 0)
1140
1140
  return h;
1141
1141
  throw "Attempted to use a REST resource store that has not been created, with no default value.";
1142
1142
  }
1143
- const U = (n = {}) => {
1143
+ const U = (o = {}) => {
1144
1144
  const {
1145
1145
  resourceClientId: h,
1146
1146
  draftBatchId: F,
1147
1147
  enabled: N,
1148
1148
  resourceType: G,
1149
1149
  options: j
1150
- } = n;
1150
+ } = o;
1151
1151
  l.value = h, u.value = F, c.value = N ?? !0, d.value = [te(G)], j != null && (y.value = j), b.value = H(), L(c.value);
1152
- }, L = async (n) => {
1153
- n != T.value && (T.value = n, n && x());
1152
+ }, L = async (o) => {
1153
+ o != T.value && (T.value = o, o && x());
1154
1154
  }, D = S(
1155
1155
  () => d.value[0].value || void 0
1156
- ), W = function(n) {
1157
- const h = a.get(n, "referencePathsToExpand"), F = D.value ? a.isFunction(h) ? h(D.value) : h || [] : [];
1156
+ ), W = function(o) {
1157
+ const h = a.get(o, "referencePathsToExpand"), F = D.value ? a.isFunction(h) ? h(D.value) : h || [] : [];
1158
1158
  return {
1159
- ...a.cloneDeep(n || {}),
1159
+ ...a.cloneDeep(o || {}),
1160
1160
  referencePathsToExpand: F
1161
1161
  };
1162
1162
  }, X = S(() => W(y.value)), J = S(() => {
@@ -1173,37 +1173,37 @@ const Ee = {
1173
1173
  idProperty: D.value.idProperty,
1174
1174
  restCollectionUrl: J.value
1175
1175
  },
1176
- (n, h) => {
1177
- if (a.isArray(h) && h.length == 0 && (n == null || a.isArray(n)))
1176
+ (o, h) => {
1177
+ if (a.isArray(h) && h.length == 0 && (o == null || a.isArray(o)))
1178
1178
  return h;
1179
1179
  }
1180
1180
  );
1181
1181
  }), p = I(0), k = S(
1182
1182
  () => {
1183
- var n;
1184
- return p.value, l.value || D.value && ((n = D.value) == null ? void 0 : n.collectionName) && (E.value ? `draftBatches/${E.value}/${D.value.collectionName}/${b.value}` : `${D.value.collectionName}/${b.value}`) || null;
1183
+ var o;
1184
+ return p.value, l.value || D.value && ((o = D.value) == null ? void 0 : o.collectionName) && (E.value ? `draftBatches/${E.value}/${D.value.collectionName}/${b.value}` : `${D.value.collectionName}/${b.value}`) || null;
1185
1185
  }
1186
1186
  ), x = () => {
1187
1187
  if (T.value) {
1188
- let n = !1;
1189
- return D.value && k.value && (t.value = ne.getStore(k.value), t.value ? n = !1 : K.value && (A.value = !1, t.value = xe(k.value, K.value)(), n = !0)), n;
1188
+ let o = !1;
1189
+ return D.value && k.value && (t.value = oe.getStore(k.value), t.value ? o = !1 : K.value && (A.value = !1, t.value = xe(k.value, K.value)(), o = !0)), o;
1190
1190
  } else
1191
1191
  return !1;
1192
1192
  }, M = () => {
1193
1193
  k.value && l.value == k.value ? (t.value = void 0, x()) : (t.value = void 0, p.value = p.value + 1, x());
1194
1194
  };
1195
- return C(E, (n, h) => {
1196
- a.isEqual(n, h) || M();
1197
- }), C(T, (n, h) => {
1198
- n != h && (n ? x() : t.value = void 0);
1199
- }), C(D, (n, h) => {
1200
- n && !h ? x() : !n && h || a.isEqual(n, h) || M();
1201
- }), C(K, (n, h) => {
1202
- a.isEqual(n, h) || M();
1195
+ return C(E, (o, h) => {
1196
+ a.isEqual(o, h) || M();
1197
+ }), C(T, (o, h) => {
1198
+ o != h && (o ? x() : t.value = void 0);
1199
+ }), C(D, (o, h) => {
1200
+ o && !h ? x() : !o && h || a.isEqual(o, h) || M();
1201
+ }), C(K, (o, h) => {
1202
+ a.isEqual(o, h) || M();
1203
1203
  }), C(q, () => {
1204
1204
  q.value || (A.value = !1);
1205
- }), C(k, () => x()), C(J, (n, h) => {
1206
- a.isEqual(n, h) || M();
1205
+ }), C(k, () => x()), C(J, (o, h) => {
1206
+ a.isEqual(o, h) || M();
1207
1207
  }), x(), {
1208
1208
  // Configuration
1209
1209
  resourceClientId: k,
@@ -1213,32 +1213,34 @@ const Ee = {
1213
1213
  // Status
1214
1214
  status: z,
1215
1215
  // Resources loaded from the REST API
1216
- resource: S(() => z.value != "Uninitialized" ? (g((n) => n.ensureResourceLoaded()), m("resource", [])) : []),
1216
+ resource: S(() => z.value != "Uninitialized" ? (g((o) => o.ensureResourceLoaded()), m("resource", [])) : []),
1217
1217
  resourceId: S(() => m("resourceId", null)),
1218
1218
  resourceUrl: S(() => m("resourceUrl", null)),
1219
1219
  // Methods: Configuration
1220
1220
  reconfigureClient: U,
1221
1221
  setEnabled: L,
1222
- setResourceId: async (n) => await g(async (h) => await h.setResourceId(n)),
1223
- setResourceUrl: async (n) => await g(async (h) => await h.setResourceUrl(n)),
1222
+ setResourceId: async (o) => await g(async (h) => {
1223
+ console.log(h), console.log(h.setResourceId), console.log(o), await h.setResourceId(o);
1224
+ }),
1225
+ setResourceUrl: async (o) => await g(async (h) => await h.setResourceUrl(o)),
1224
1226
  // Methods: Status
1225
1227
  ensureStore: x,
1226
1228
  // Methods: Resource management
1227
- clear: () => B((n) => n.clear()),
1228
- ensureResourceLoaded: async () => await g(async (n) => n.ensureResourceLoaded()),
1229
- loadResource: async () => await g(async (n) => await n.loadResource()),
1229
+ clear: () => B((o) => o.clear()),
1230
+ ensureResourceLoaded: async () => await g(async (o) => o.ensureResourceLoaded()),
1231
+ loadResource: async () => await g(async (o) => await o.loadResource()),
1230
1232
  // Methods: Recording changes to the resource
1231
- checkForDeletedResource: async () => await g(async (n) => await n.checkForDeletedResource()) == !0,
1232
- recordDeletion: () => g((n) => n.recordDeletion()),
1233
- recordInsertion: (n) => g((h) => h.recordInsertion(n)),
1234
- recordUpdate: (n) => g((h) => h.recordUpdate(n)),
1235
- refreshResource: async () => await g(async (n) => await n.refreshResource()),
1233
+ checkForDeletedResource: async () => await g(async (o) => await o.checkForDeletedResource()) == !0,
1234
+ recordDeletion: () => g((o) => o.recordDeletion()),
1235
+ recordInsertion: (o) => g((h) => h.recordInsertion(o)),
1236
+ recordUpdate: (o) => g((h) => h.recordUpdate(o)),
1237
+ refreshResource: async () => await g(async (o) => await o.refreshResource()),
1236
1238
  // Methods: Modifying the resource
1237
- deleteResource: async () => await g(async (n) => await n.deleteResource()),
1238
- saveResource: async (n) => await g(async (h) => await h.saveResource(n)),
1239
+ deleteResource: async () => await g(async (o) => await o.deleteResource()),
1240
+ saveResource: async (o) => await g(async (h) => await h.saveResource(o)),
1239
1241
  // Methods: Custom API endpoints
1240
- makeCustomApiRequest: async (n) => await g(
1241
- async (h) => await h.makeCustomApiRequest(n)
1242
+ makeCustomApiRequest: async (o) => await g(
1243
+ async (h) => await h.makeCustomApiRequest(o)
1242
1244
  )
1243
1245
  };
1244
1246
  }, ee = {
@@ -1 +1 @@
1
- (function(v,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("lodash"),require("uuid"),require("vue"),require("axios"),require("jsog"),require("json-stringify-deterministic"),require("pinia")):typeof define=="function"&&define.amd?define(["exports","lodash","uuid","vue","axios","jsog","json-stringify-deterministic","pinia"],r):(v=typeof globalThis<"u"?globalThis:v||self,r(v["rest-client-vue"]={},v._,v.uuid,v.Vue,v.axios,v.jsog,v.stringify,v.pinia))})(this,function(v,r,w,a,$,ne,J,ae){"use strict";var Pe=Object.defineProperty;var Fe=(v,r,w)=>r in v?Pe(v,r,{enumerable:!0,configurable:!0,writable:!0,value:w}):v[r]=w;var le=(v,r,w)=>(Fe(v,typeof r!="symbol"?r+"":r,w),w),Ne=(v,r,w)=>{if(!r.has(v))throw TypeError("Cannot "+w)};var j=(v,r,w)=>(Ne(v,r,"read from private field"),w?w.call(v):r.get(v)),Ie=(v,r,w)=>{if(r.has(v))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(v):r.set(v,w)};var A;const oe={apiBaseUrl:"",useVueLogger:!1};class we extends Error{constructor(C,q=void 0,e=void 0){super(C);le(this,"context");le(this,"innerError");this.context=q,this.innerError=e}}class ce{constructor(){Ie(this,A,{})}clearAllStores(){for(const n in j(this,A))j(this,A)[n].clear()}destroyStore(n){j(this,A)[n]&&(j(this,A)[n].$dispose(),delete j(this,A)[n])}getStore(n){return j(this,A)[n]}registerStore(n,C){j(this,A)[n]=C}}A=new WeakMap;function g(y,n){return r.get(y,(n==null?void 0:n.idProperty)||"_id")}function De(y,n){var C;return y&&((C=n.filter)!=null&&C.resourceIds)&&!n.order?n.filter.resourceIds.map(q=>y.find(e=>g(e,n)==q)).filter(q=>q!=null):y}const ue={detail:{allowMultiple:!0,autoEdit:!1,autoFromMultipleSelection:!0,autoFromSingleInsertion:!0,autoFromSingleSelection:!0,constrainToSelection:!0},filter:{namedFilter:null,query:null,resourceIds:null},idProperty:"_id",limit:5e3,limitTransientDataToLocalCollection:!0,loading:{firstPageSize:500,pageSize:5e3},order:[[{path:"history.creation.timestamp"},"desc"],[{path:"history.creation.orderInBatch"},"desc"]]},K={resources:[],status:"NotLoaded",selection:[],detailSelection:[],invalidResources:[],transientData:{}},te={editingDetailSelection:!1,batchSaveAttempted:!1,editors:[],listNavigators:{}},Ee=(y,n)=>{n=r.merge({},ue,n);const C=ae.defineStore(y,{state:()=>({idProperty:n.idProperty,filter:n.filter,order:n.order||null,referencePathsToExpand:n.referencePathsToExpand||null,...K,...te}),getters:{fixedQueryParams:e=>{var l,d,u,h;const s={};(l=e.filter)!=null&&l.namedFilter&&(s.namedFilter=e.filter.namedFilter);const t=[];if((d=e.filter)!=null&&d.resourceIds&&t.push({l:{path:e.idProperty},r:{constant:e.filter.resourceIds},operator:"in"}),(u=e.filter)!=null&&u.query&&t.push((h=e.filter)==null?void 0:h.query),t.length>0){const p=t.length==1?t[0]:{and:t};s.q=J(p)}return e.order&&(s.o=J(e.order)),e.referencePathsToExpand&&(s.r=J(e.referencePathsToExpand)),s}},actions:{reset(){for(const e in K)this[e]=K[e];for(const e in te)this[e]=te[e]},resetRetainingTransientData(){if(n.limitTransientDataToLocalCollection)this.reset();else{const e=this.transientData;this.reset(),this.transientData=e}},setEditingDetailSelection(e){this.editingDetailSelection=e},setFilter(e){r.isEqual(e,this.filter)||(this.filter=e,this.status="NotLoaded",this.resources=[],this.selection=[],this.detailSelection=[],this.invalidResources=[],this.editingDetailSelection=!1)},async setQuery(e){var s,t;if(!r.isEqual(e,(s=this.filter)==null?void 0:s.query)&&(e!=null||((t=this.filter)==null?void 0:t.query)!=null)){const l=r.cloneDeep(this.filter)||{};e!==null?l.query=e:r.unset(l,"query");const d=this.status;this.setFilter(l),d!="NotLoaded"&&await this.loadResources()}},async setFilterResourceIds(e){if(!r.isEqual(e,r.get(this.filter,"resourceIds"))){const s=r.cloneDeep(this.filter)||{};e!=null?s.resourceIds=e:r.unset(s,"resourceIds");const t=this.status;this.setFilter(s),t!="NotLoaded"&&await this.loadResources()}},setBatchSaveAttempted(e){e!=this.batchSaveAttempted&&(this.batchSaveAttempted=e)},clear(){for(const e in K)this[e]=K[e]},clearRetainingTransientData(){if(n.limitTransientDataToLocalCollection)this.reset();else{const e=this.transientData;this.reset(),this.transientData=e}},async ensureCollectionLoaded(){["Loaded","Loading","LoadingMore","Failed"].includes(this.status)||await this.loadResources()},async loadResources(e={}){this.resetRetainingTransientData();const s=w.v4();this._loadId=s,await this._loadResources(0,s,e)},async _loadResources(e,s,t){var b,F,O,k,Q;const l=e==0;if(this.status=l?"Loading":"LoadingMore",this._loadOffset=e,((b=this.filter)==null?void 0:b.query)===!1){this.resources=[];return}const d=this.fixedQueryParams,u=r.cloneDeep(d),h=l?(F=this.filter)!=null&&F.resourceIds&&!this.order?null:t.firstPageSize||((O=n.loading)==null?void 0:O.firstPageSize)||t.pageSize||((k=n.loading)==null?void 0:k.pageSize)||null:t.pageSize||((Q=n.loading)==null?void 0:Q.pageSize)||null,p=h!=null||n.limit!=null?r.min(r.filter([h,n.limit],R=>R!=null)):void 0;p!=null?(u.offset=e,u.limit=p):e!=0&&(u.offset=e);const D=r.map(u,(R,m)=>R!=null?`${encodeURIComponent(m)}=${encodeURIComponent(R)}`:null).filter(R=>R!=null).join("&"),T=r.isEmpty(D)?n.restCollectionUrl:`${n.restCollectionUrl}?${D}`;try{const R=await $.get(T),m=this.fixedQueryParams;if(s!=this._loadId||e!=this._loadOffset||!r.isEqual(d,m))console.log(`Discarding resources fetched by obsolete query from ${n.restCollectionUrl}.`);else{const E=ne.decode(r.get(R,"data.data",[])),L=(l?0:this.resources.length)+E.length,I=p==null||E.length<p||n.limit&&L>=n.limit;console.log(`Loaded ${E.length}${l?"":" more"} resources from ${n.restCollectionUrl}`),l&&(this.resources=[]);const H=[...this.resources,...E.map(Z=>Object.freeze(Z))];this.resources=De(H,this),this.status=I?"Loaded":"LoadingMore",I||this._loadResources(this.resources.length,s,t)}}catch(R){console.log(`Error while loading resources (URL="${T}"):`,R),this.clearRetainingTransientData(),this.status="Failed"}},async checkForDeletedResource(e){let s;try{s=await $.get(`${n.restCollectionUrl}/${e}`)}catch(t){$.isAxiosError(t)&&(s=t.response)}return s&&s.status==404?(this.recordDeletion(e),!0):!1},recordDeletion(e){var s;if(["Loaded","LoadingMore"].includes(this.status)){let t=this.resources.findIndex(l=>g(l,this)==e);t>=0&&this.resources.splice(t,1),t=this.selection.findIndex(l=>g(l,this)==e),t>=0&&this.selection.splice(t,1),t=this.detailSelection.findIndex(l=>g(l,this)==e),t>=0&&(this.detailSelection.splice(t,1),this.detailSelection.length==0&&(this.editingDetailSelection=((s=n.detail)==null?void 0:s.autoEdit)||!1)),n.limitTransientDataToLocalCollection&&delete this.transientData[e]}},recordInsertion(e,{insertAtBeginning:s,transientData:t}={}){var l;if(["Loaded","LoadingMore"].includes(this.status)){const d=Object.freeze(e);s?this.resources.unshift(d):this.resources.push(d),(l=n.detail)!=null&&l.autoFromSingleInsertion&&(this.detailSelection.length==0||this.detailSelection.length==1&&g(this.detailSelection[0],this)==null)&&(this.detailSelection=[d],this.editingDetailSelection=n.detail.autoEdit);const u=g(e,this);u&&(t===void 0?delete this.transientData[u]:this.transientData[u]=t)}},recordUpdate(e){const s=g(e,this);if(s&&["Loaded","LoadingMore"].includes(this.status)){const t=Object.freeze(e);let l=this.resources.findIndex(d=>g(d,this)==s);l>=0&&(this.resources[l]=t),l=this.selection.findIndex(d=>g(d,this)==s),l>=0&&(this.selection[l]=t),l=this.detailSelection.findIndex(d=>g(d,this)==s),l>=0&&(this.detailSelection[l]=t)}},async refreshResource(e){if(e){const s={};this.referencePathsToExpand&&(s.r=J(this.referencePathsToExpand));const t=r.map(s,(u,h)=>u!=null?`${encodeURIComponent(h)}=${encodeURIComponent(u)}`:null).filter(u=>u!=null).join("&"),l=r.isEmpty(t)?`${n.restCollectionUrl}/${e}`:`${n.restCollectionUrl}/${e}?${t}`,d=await $.get(l);if(d.status==200){const u=d.data;return this.recordUpdate(u),u}}return null},addResource(e={}){this.detailSelection=[r.omit(r.merge({},e),this.idProperty)],this.editingDetailSelection=!0},async deleteResource(e){if((await $.delete(`${n.restCollectionUrl}/${e}`)).status==200&&["Loaded","LoadingMore"].includes(this.status)){let t=this.resources.findIndex(l=>g(l,this)==e);t>=0&&this.resources.splice(t,1),t=this.selection.findIndex(l=>g(l,this)==e),t>=0&&this.selection.splice(t,1),t=this.detailSelection.findIndex(l=>g(l,this)==e),t>=0&&(this.detailSelection.splice(t,1),this.detailSelection.length==0&&(this.editingDetailSelection=n.detail.autoEdit)),n.limitTransientDataToLocalCollection&&delete this.transientData[e]}},async saveResource(e){const s=g(e,this),t=s==null,l=await $({method:t?"post":"put",url:t?n.restCollectionUrl:`${n.restCollectionUrl}/${s}`,data:e});if(l.status==200){const d=l.data,u=g(d,this),h=u?await this.refreshResource(u):null;return t&&this.recordInsertion(h||Object.freeze(d)),h||d}return null},async saveResources(e){const s=await $({method:"put",url:n.restCollectionUrl,data:e});if(s.status==200){const t=s.data||[],l=[];for(const[d,u]of t.entries()){const h=g(e[d],this)==null,p=g(u,this),D=p?await this.refreshResource(p):null;h&&this.recordInsertion(D||u),l.push(D||Object.freeze(u))}return l}return[]},clearTransientData(){this.transientData={}},setInvalidResourceIds(e){r.isEqual(e,this.invalidResources.map(s=>g(s,this)))||(this.invalidResources=e.map(s=>this.resources.find(t=>g(t,this)==s)).filter(s=>s!=null))},setTransientDataForResources(e){const{transientData:s,merge:t=!0}=e;t?r.merge(this.transientData,s):r.assign(this.transientData,s)},clearSelection(){this.setSelection([])},deselectResources(e){const s=this.selection.map(t=>g(t,this)).filter(t=>t!=null&&!e.includes(t));this.setSelection(s)},selectResources(e,s){const{addToSelection:t,edit:l}=s||{},d=this.selection.map(h=>g(h,this));let u=e;if(t){const h=r.difference(e,d);h.length>0&&(u=d.concat(h).filter(p=>p!=null))}r.isEqual(d,u)||this.setSelection(u,l)},setSelection(e,s){if(!r.isEqual(e,this.selection.map(t=>g(t,this)))){let t=!0;if(this.editors.length>0){if(n.detail.autoFromSingleSelection&&this.selection.length==1)t=!1;else if(n.detail.autoFromMultipleSelection&&n.detail.allowMultiple&&this.selection.length>1)t=!1;else if(n.detail.constrainToSelection){const l=this.selection.map(h=>g(h,this)),u=this.detailSelection.map(h=>g(h,this)).filter(h=>l.includes(h));this.detailSelection.filter(h=>!u.includes(g(h,this))).length>0&&(t=!1)}}if(!t)return;if(this.selection=e.map(l=>this.resources.find(d=>g(d,this)==l)).filter(l=>l!=null),n.detail.autoFromSingleSelection&&this.selection.length==1){const l=this.selection[0];(this.detailSelection.length!=1||g(this.detailSelection[0],this)!=g(l,this))&&(this.detailSelection=[l])}else if(n.detail.autoFromMultipleSelection&&n.detail.allowMultiple&&this.selection.length>1)r.isEqual(this.selection.map(l=>g(l,this)),this.detailSelection.map(l=>g(l,this)))||(this.detailSelection=r.clone(this.selection));else if(n.detail.constrainToSelection){const l=this.selection.map(h=>g(h,this)),d=this.detailSelection.map(h=>g(h,this)),u=d.filter(h=>l.includes(h));r.isEqual(u,d)||(this.detailSelection=this.detailSelection.filter(h=>u.includes(g(h,this))))}this.detailSelection.length==0?this.editingDetailSelection=!1:this.editingDetailSelection=s!==void 0?s:this.editingDetailSelection||n.detail.autoEdit}},hideDetail(){this.detailSelection.length>0&&(this.detailSelection=[],this.editingDetailSelection=!1)},showSelectionAsDetail(e){if(this.selection.length<=1||n.detail.allowMultiple){const s=this.selection.map(l=>g(l,this)),t=this.detailSelection.map(l=>g(l,this));r.isEqual(s,t)||(this.detailSelection=r.clone(this.selection)),this.detailSelection.length==0?this.editingDetailSelection=!1:this.editingDetailSelection=e!==void 0?e:this.editingDetailSelection||n.detail.autoEdit}},deregisterEditor(e){r.remove(this.editors,s=>s==e)},registerEditor(e){this.editors.includes(e)||this.editors.push(e)},deregisterListNavigator({name:e,listNavigator:s}){(s==null||this.listNavigators[e]==s)&&delete this.listNavigators[e]},registerListNavigator({name:e,listNavigator:s}){this.listNavigators[e]!=s&&(this.listNavigators[e]=s)}}});return(()=>{const e=(s,t)=>{const l=C(s,t);return ee.registerStore(l.$id,l),l};return e.$id=C.$id,e})()},ee=new ce,Ue=(y={})=>{var he,fe,ge,ve;console.log("hereaaaaaaa"),console.log(y);const{collectionId:n,draftBatchId:C,enabled:q,resourceType:e,options:s}=y,t=a.ref(void 0),l=a.ref(n),d=a.ref(C),u=a.ref(q??!0),h=a.ref([a.toRef(e)]),p=a.ref(s),D=a.computed(()=>d.value),T=a.ref(u.value),b=a.ref(w.v4()),F=a.ref((fe=(he=p.value)==null?void 0:he.filter)==null?void 0:fe.resourceIds),O=a.ref((ve=(ge=p.value)==null?void 0:ge.filter)==null?void 0:ve.query),k=a.computed(()=>d.value==null&&l.value!=null&&ee.getStore(l.value)!=null),Q=a.ref(k.value),R=a.computed(()=>L("status","Uninitialized"));function m(i){if(t.value)return i(t.value)}async function E(i){if(t.value)return await i(t.value)}function L(i,c){if(t.value)return t.value[i];if(c!==void 0)return c;throw"Attempted to use a REST collection store that has not been created, with no default value."}const I=(i={})=>{var me,pe,Se,ye;const{collectionId:c,draftBatchId:U,enabled:z,resourceType:re,options:Re}=i;l.value=c,d.value=U,u.value=z??!0,h.value=[a.toRef(re)],Re!=null&&(p.value=Re,F.value=(pe=(me=p.value)==null?void 0:me.filter)==null?void 0:pe.resourceIds,O.value=(ye=(Se=p.value)==null?void 0:Se.filter)==null?void 0:ye.query),b.value=w.v4(),H(u.value)},H=async i=>{i!=T.value&&(T.value=i,i&&(_(),x()))},Z=async i=>{F.value=i,await E(async c=>await c.setFilterResourceIds(F.value||null))},V=async i=>{if(O.value=i,R.value!="Uninitialized"){const c=i,U=a.computed(()=>r.isFunction(c)?S.value?c(S.value):null:c);await E(z=>z.setQuery(U.value||null))}},_=()=>{p.value=r.merge({},p.value||{},{filter:{resourceIds:F.value,query:O.value}})},S=a.computed(()=>h.value[0].value||void 0),B=function(i){const c=r.get(i,"filter.query"),U=r.get(i,"referencePathsToExpand"),z=r.isFunction(c)?c(S.value):c,re=S.value?r.isFunction(U)?U(S.value):U||[]:[];return{...r.cloneDeep(i||{}),filter:{...r.cloneDeep((i==null?void 0:i.filter)||{}),query:z},referencePathsToExpand:re}},P=a.computed(()=>B(p.value)),M=a.computed(()=>{if(!S.value)return null;if(P.value.restCollectionUrl!==void 0)return P.value.restCollectionUrl;if(!Q.value)return!S.value||!S.value.collectionName?null:D.value?`${G.config.apiBaseUrl}/draft-batches/${D.value}/${S.value.collectionName}`:`${G.config.apiBaseUrl}/${S.value.collectionName}`}),o=a.computed(()=>{var i;if(S.value)return r.mergeWith(r.cloneDeep(ue),P.value,{idProperty:(i=S.value)==null?void 0:i.idProperty,restCollectionUrl:M.value||""},(c,U)=>{if(r.isArray(U)&&U.length==0&&(c==null||r.isArray(c)))return U})}),f=a.ref(0),N=a.computed(()=>{var i;return f.value,l.value||S.value&&((i=S.value)==null?void 0:i.collectionName)&&(D.value?`draftBatches/${D.value}/${S.value.collectionName}/${b.value}`:`${S.value.collectionName}/${b.value}`)||null}),x=()=>{if(T.value){let i=!1;return S.value&&N.value&&(t.value=ee.getStore(N.value),t.value?i=!1:o.value&&(Q.value=!1,t.value=Ee(N.value,o.value)(),i=!0)),i}else return!1},X=()=>{N.value&&l.value==N.value?(t.value=void 0,x()):(t.value=void 0,f.value=f.value+1,x())};a.watch(D,(i,c)=>{r.isEqual(i,c)||X()}),a.watch(T,(i,c)=>{i!=c&&(i?x():t.value=void 0)}),a.watch(S,(i,c)=>{i&&!c?x():!i&&c||r.isEqual(i,c)||X()}),a.watch(o,(i,c)=>{r.isEqual(i,c)||X()}),a.watch(k,()=>{k.value||(Q.value=!1)}),a.watch(N,()=>x()),a.watch(M,(i,c)=>{r.isEqual(i,c)||X()});const W=[],qe=function(i){R.value!="Uninitialized"?a.nextTick(i):W.push(i)};return a.watch(R,(i,c)=>{if(i!="Uninitialized"&&c=="Uninitialized"){const U=r.clone(W);W.splice(0,W.length);for(const z of U)z()}}),x(),{collectionId:N,draftBatchId:D,resourceType:S,enabled:T,status:R,batchSaveAttempted:a.computed(()=>L("batchSaveAttempted",!1)),listNavigators:a.computed(()=>L("listNavigators",!1)),invalidResources:a.computed(()=>L("invalidResources",[])),resources:a.computed(()=>R.value!="Uninitialized"?(E(i=>i.ensureCollectionLoaded()),L("resources",[])):[]),transientData:a.computed(()=>L("transientData",[])),detailSelection:a.computed(()=>L("detailSelection",[])),editingDetailSelection:a.computed(()=>L("editingDetailSelection",!1)),selection:a.computed(()=>L("selection",[])),reconfigureCollection:I,setEditingDetailSelection:i=>m(c=>c.setEditingDetailSelection(i)),setEnabled:H,setFilterResourceIds:Z,setQuery:V,ensureStore:x,setBatchSaveAttempted:i=>m(c=>c.setBatchSaveAttempted(i)),clear:()=>m(i=>i.clear()),ensureCollectionLoaded:async()=>await E(async i=>i.ensureCollectionLoaded()),loadResources:async()=>await E(async i=>await i.loadResources()),addResource:i=>m(c=>c.addResource(i)),checkForDeletedResource:async i=>await E(async c=>await c.checkForDeletedResource(i))==!0,recordDeletion:i=>m(c=>c.recordDeletion(i)),recordInsertion:(i,{insertAtBeginning:c=!1,transientData:U=void 0}={})=>m(z=>z.recordInsertion(i,{insertAtBeginning:c,transientData:U})),recordUpdate:i=>m(c=>c.recordUpdate(i)),refreshResource:async i=>await E(async c=>await c.refreshResource(i)),deleteResource:async i=>await E(async c=>await c.deleteResource(i)),saveResource:async i=>await E(async c=>await c.saveResource(i)),saveResources:async i=>await E(async c=>await c.saveResources(i)),clearTransientData:()=>m(i=>i.clearTransientData()),setInvalidResourceIds:i=>m(c=>c.setInvalidResourceIds(i)),setTransientDataForResources:i=>m(c=>c.setTransientDataForResources(i)),clearSelection:()=>m(i=>i.clearSelection()),deselectResources:i=>m(c=>c.deselectResources(i)),selectResources:(i,c)=>m(U=>U.selectResources(i,c)),hideDetail:()=>m(i=>i.hideDetail()),deregisterEditor:i=>m(c=>c.deregisterEditor(i)),registerEditor:i=>m(c=>c.registerEditor(i)),deregisterListNavigator:i=>m(c=>c.deregisterListNavigator(i)),registerListNavigator:i=>m(c=>c.registerListNavigator(i)),onItemsStoreReady:qe}},Ce=()=>{ee.clearAllStores()};function ie(y,n){return r.get(y,(n==null?void 0:n.idProperty)||"_id")}const de={idProperty:"_id"},Y={resource:null,status:"NotLoaded"},Te=(y,n)=>{n=r.merge({},de,n),console.log(y),console.log(n);const C=ae.defineStore(y,{state:()=>({idProperty:n.idProperty,resourceId:n.resourceId||null,resourceUrl:n.resourceUrl||null,referencePathsToExpand:n.referencePathsToExpand||null,...Y}),getters:{currentResourceUrl:e=>(console.log(e),console.log(n),e.resourceUrl||(n.restCollectionUrl&&e.resourceId?`${n.restCollectionUrl}/${e.resourceId}`:null)||n.restCollectionUrl||null),fixedQueryParams:e=>{const s={};return e.referencePathsToExpand&&(s.r=J(e.referencePathsToExpand)),s}},actions:{reset(){for(const e in Y)this[e]=Y[e]},async setResourceId(e){const s=this.currentResourceUrl;this.resourceId=e,console.log(e),!r.isEqual(this.currentResourceUrl,s)&&this.status!="NotLoaded"&&(console.log("here"),await this.loadResource())},async setResourceUrl(e){const s=this.currentResourceUrl;this.resourceUrl=e,!r.isEqual(this.currentResourceUrl,s)&&this.status!="NotLoaded"&&await this.loadResource()},clear(){for(const e in Y)this[e]=Y[e]},async ensureResourceLoaded(){["Loaded","Loading","Failed"].includes(this.status)||await this.loadResource()},async loadResource(){this.reset();const e=w.v4();if(this._loadId=e,this.currentResourceUrl){this.status="Loading";const s=this.fixedQueryParams,t=r.cloneDeep(s),l=r.map(t,(u,h)=>u!=null?`${encodeURIComponent(h)}=${encodeURIComponent(u)}`:null).filter(u=>u!=null).join("&"),d=r.isEmpty(l)?this.currentResourceUrl:`${this.currentResourceUrl}?${l}`;try{const u=await $.get(d),h=this.fixedQueryParams;e!=this._loadId||!r.isEqual(s,h)?console.log(`Discarding resource fetched by obsolete query from ${d}.`):(this.resource=ne.decode(r.get(u,"data",{})),this.status="Loaded")}catch(u){console.log(`Error while loading resource (URL="${d}")`,u),this.reset(),this.status="Failed"}}else throw"Cannot load a resource because its URL, or its ID and collection URL, are unknown."},async checkForDeletedResource(){if(this.currentResourceUrl){let e;try{e=await $.get(this.currentResourceUrl)}catch(s){$.isAxiosError(s)&&(e=s.response)}return e&&e.status==404?(this.recordDeletion(),!0):!1}else throw"Cannot check for a deleted resource because its URL, or its ID and collection URL, are unknown."},recordDeletion(){this.resource=null,this.status="Loaded"},recordInsertion(e){this.resourceId=ie(e,this)||null,this.status=="Loaded"&&(this.resource=Object.freeze(e))},recordUpdate(e){this.resourceId=ie(e,this)||null,this.status=="Loaded"&&(this.resource=Object.freeze(e))},async refreshResource(){return await this.loadResource(),this.resource},async deleteResource(){if(this.currentResourceUrl)(await $.delete(this.currentResourceUrl)).status==200&&this.recordDeletion();else throw"Cannot delete a resource because its URL, or its ID and collection URL, are unknown."},async saveResource(e){const s=ie(e,this),t=s==null;if(!s)throw"The REST resource store cannot create new resources on the server.";if(!this.currentResourceUrl)throw"Cannot save a resource because its URL, or its ID and collection URL, are unknown.";const l=await $({method:t?"post":"put",url:this.currentResourceUrl,data:e});if(l.status==200){const d=l.data,u=await this.refreshResource();return t&&this.recordInsertion(u||d),u||Object.freeze(d)}return null},async makeCustomApiRequest(e){const{method:s,subpath:t,url:l,data:d}=e;let u=l;if(!u)if(this.currentResourceUrl)u=`${this.currentResourceUrl}/${t}`;else throw"Cannot make a custom API request for a resource because its URL, or its ID and collection URL, are unknown.";const h=await $({method:s||"get",url:u,data:d});return h.status>=200&&h.status<300?h.data:null}}});return(()=>{const e=(s,t)=>{const l=C(s,t);return se.registerStore(l.$id,l),l};return e.$id=C.$id,e})()},se=new ce,Le=(y={})=>{console.log("HERE!!!!"),console.log(y);const{resourceClientId:n,draftBatchId:C,enabled:q,resourceType:e,options:s}=y,t=a.ref(void 0),l=a.ref(n),d=a.ref(C),u=a.ref(q??!0),h=a.ref([a.toRef(e)]),p=a.ref(s),D=a.computed(()=>d.value),T=a.ref(u.value),b=a.ref(w.v4()),F=a.computed(()=>d.value==null&&l.value!=null&&se.getStore(l.value)!=null),O=a.ref(F.value),k=a.computed(()=>m("status","Uninitialized"));function Q(o){if(t.value)return o(t.value)}async function R(o){if(t.value)return await o(t.value)}function m(o,f){if(t.value)return t.value[o];if(f!==void 0)return f;throw"Attempted to use a REST resource store that has not been created, with no default value."}const E=(o={})=>{const{resourceClientId:f,draftBatchId:N,enabled:x,resourceType:X,options:W}=o;l.value=f,d.value=N,u.value=x??!0,h.value=[a.toRef(X)],W!=null&&(p.value=W),b.value=w.v4(),L(u.value)},L=async o=>{o!=T.value&&(T.value=o,o&&P())},I=a.computed(()=>h.value[0].value||void 0),H=function(o){const f=r.get(o,"referencePathsToExpand"),N=I.value?r.isFunction(f)?f(I.value):f||[]:[];return{...r.cloneDeep(o||{}),referencePathsToExpand:N}},Z=a.computed(()=>H(p.value)),V=a.computed(()=>{if(!I.value)return null;if(!O.value)return!I.value||!I.value.collectionName?null:D.value?`${G.config.apiBaseUrl}/draft-batches/${D.value}/${I.value.collectionName}`:`${G.config.apiBaseUrl}/${I.value.collectionName}`}),_=a.computed(()=>{if(I.value&&V.value)return r.mergeWith(r.cloneDeep(de),Z.value,{idProperty:I.value.idProperty,restCollectionUrl:V.value},(o,f)=>{if(r.isArray(f)&&f.length==0&&(o==null||r.isArray(o)))return f})}),S=a.ref(0),B=a.computed(()=>{var o;return S.value,l.value||I.value&&((o=I.value)==null?void 0:o.collectionName)&&(D.value?`draftBatches/${D.value}/${I.value.collectionName}/${b.value}`:`${I.value.collectionName}/${b.value}`)||null}),P=()=>{if(T.value){let o=!1;return I.value&&B.value&&(t.value=se.getStore(B.value),t.value?o=!1:_.value&&(O.value=!1,t.value=Te(B.value,_.value)(),o=!0)),o}else return!1},M=()=>{B.value&&l.value==B.value?(t.value=void 0,P()):(t.value=void 0,S.value=S.value+1,P())};return a.watch(D,(o,f)=>{r.isEqual(o,f)||M()}),a.watch(T,(o,f)=>{o!=f&&(o?P():t.value=void 0)}),a.watch(I,(o,f)=>{o&&!f?P():!o&&f||r.isEqual(o,f)||M()}),a.watch(_,(o,f)=>{r.isEqual(o,f)||M()}),a.watch(F,()=>{F.value||(O.value=!1)}),a.watch(B,()=>P()),a.watch(V,(o,f)=>{r.isEqual(o,f)||M()}),P(),{resourceClientId:B,draftBatchId:D,enabled:T,resourceType:I,status:k,resource:a.computed(()=>k.value!="Uninitialized"?(R(o=>o.ensureResourceLoaded()),m("resource",[])):[]),resourceId:a.computed(()=>m("resourceId",null)),resourceUrl:a.computed(()=>m("resourceUrl",null)),reconfigureClient:E,setEnabled:L,setResourceId:async o=>await R(async f=>await f.setResourceId(o)),setResourceUrl:async o=>await R(async f=>await f.setResourceUrl(o)),ensureStore:P,clear:()=>Q(o=>o.clear()),ensureResourceLoaded:async()=>await R(async o=>o.ensureResourceLoaded()),loadResource:async()=>await R(async o=>await o.loadResource()),checkForDeletedResource:async()=>await R(async o=>await o.checkForDeletedResource())==!0,recordDeletion:()=>R(o=>o.recordDeletion()),recordInsertion:o=>R(f=>f.recordInsertion(o)),recordUpdate:o=>R(f=>f.recordUpdate(o)),refreshResource:async()=>await R(async o=>await o.refreshResource()),deleteResource:async()=>await R(async o=>await o.deleteResource()),saveResource:async o=>await R(async f=>await f.saveResource(o)),makeCustomApiRequest:async o=>await R(async f=>await f.makeCustomApiRequest(o))}},G={config:{...oe}};function $e(y){G.config=r.merge({},oe,y)}v.ApiClientError=we,v.clearAllRestCollections=Ce,v.initRestClient=$e,v.restClient=G,v.useRestCollection=Ue,v.useRestResource=Le,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
1
+ (function(v,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("lodash"),require("uuid"),require("vue"),require("axios"),require("jsog"),require("json-stringify-deterministic"),require("pinia")):typeof define=="function"&&define.amd?define(["exports","lodash","uuid","vue","axios","jsog","json-stringify-deterministic","pinia"],r):(v=typeof globalThis<"u"?globalThis:v||self,r(v["rest-client-vue"]={},v._,v.uuid,v.Vue,v.axios,v.jsog,v.stringify,v.pinia))})(this,function(v,r,w,o,$,ne,J,oe){"use strict";var Pe=Object.defineProperty;var Fe=(v,r,w)=>r in v?Pe(v,r,{enumerable:!0,configurable:!0,writable:!0,value:w}):v[r]=w;var le=(v,r,w)=>(Fe(v,typeof r!="symbol"?r+"":r,w),w),Ne=(v,r,w)=>{if(!r.has(v))throw TypeError("Cannot "+w)};var j=(v,r,w)=>(Ne(v,r,"read from private field"),w?w.call(v):r.get(v)),Ie=(v,r,w)=>{if(r.has(v))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(v):r.set(v,w)};var A;const ae={apiBaseUrl:"",useVueLogger:!1};class we extends Error{constructor(C,q=void 0,e=void 0){super(C);le(this,"context");le(this,"innerError");this.context=q,this.innerError=e}}class ce{constructor(){Ie(this,A,{})}clearAllStores(){for(const n in j(this,A))j(this,A)[n].clear()}destroyStore(n){j(this,A)[n]&&(j(this,A)[n].$dispose(),delete j(this,A)[n])}getStore(n){return j(this,A)[n]}registerStore(n,C){j(this,A)[n]=C}}A=new WeakMap;function g(y,n){return r.get(y,(n==null?void 0:n.idProperty)||"_id")}function De(y,n){var C;return y&&((C=n.filter)!=null&&C.resourceIds)&&!n.order?n.filter.resourceIds.map(q=>y.find(e=>g(e,n)==q)).filter(q=>q!=null):y}const ue={detail:{allowMultiple:!0,autoEdit:!1,autoFromMultipleSelection:!0,autoFromSingleInsertion:!0,autoFromSingleSelection:!0,constrainToSelection:!0},filter:{namedFilter:null,query:null,resourceIds:null},idProperty:"_id",limit:5e3,limitTransientDataToLocalCollection:!0,loading:{firstPageSize:500,pageSize:5e3},order:[[{path:"history.creation.timestamp"},"desc"],[{path:"history.creation.orderInBatch"},"desc"]]},K={resources:[],status:"NotLoaded",selection:[],detailSelection:[],invalidResources:[],transientData:{}},te={editingDetailSelection:!1,batchSaveAttempted:!1,editors:[],listNavigators:{}},Ee=(y,n)=>{n=r.merge({},ue,n);const C=oe.defineStore(y,{state:()=>({idProperty:n.idProperty,filter:n.filter,order:n.order||null,referencePathsToExpand:n.referencePathsToExpand||null,...K,...te}),getters:{fixedQueryParams:e=>{var l,d,u,h;const s={};(l=e.filter)!=null&&l.namedFilter&&(s.namedFilter=e.filter.namedFilter);const t=[];if((d=e.filter)!=null&&d.resourceIds&&t.push({l:{path:e.idProperty},r:{constant:e.filter.resourceIds},operator:"in"}),(u=e.filter)!=null&&u.query&&t.push((h=e.filter)==null?void 0:h.query),t.length>0){const p=t.length==1?t[0]:{and:t};s.q=J(p)}return e.order&&(s.o=J(e.order)),e.referencePathsToExpand&&(s.r=J(e.referencePathsToExpand)),s}},actions:{reset(){for(const e in K)this[e]=K[e];for(const e in te)this[e]=te[e]},resetRetainingTransientData(){if(n.limitTransientDataToLocalCollection)this.reset();else{const e=this.transientData;this.reset(),this.transientData=e}},setEditingDetailSelection(e){this.editingDetailSelection=e},setFilter(e){r.isEqual(e,this.filter)||(this.filter=e,this.status="NotLoaded",this.resources=[],this.selection=[],this.detailSelection=[],this.invalidResources=[],this.editingDetailSelection=!1)},async setQuery(e){var s,t;if(!r.isEqual(e,(s=this.filter)==null?void 0:s.query)&&(e!=null||((t=this.filter)==null?void 0:t.query)!=null)){const l=r.cloneDeep(this.filter)||{};e!==null?l.query=e:r.unset(l,"query");const d=this.status;this.setFilter(l),d!="NotLoaded"&&await this.loadResources()}},async setFilterResourceIds(e){if(!r.isEqual(e,r.get(this.filter,"resourceIds"))){const s=r.cloneDeep(this.filter)||{};e!=null?s.resourceIds=e:r.unset(s,"resourceIds");const t=this.status;this.setFilter(s),t!="NotLoaded"&&await this.loadResources()}},setBatchSaveAttempted(e){e!=this.batchSaveAttempted&&(this.batchSaveAttempted=e)},clear(){for(const e in K)this[e]=K[e]},clearRetainingTransientData(){if(n.limitTransientDataToLocalCollection)this.reset();else{const e=this.transientData;this.reset(),this.transientData=e}},async ensureCollectionLoaded(){["Loaded","Loading","LoadingMore","Failed"].includes(this.status)||await this.loadResources()},async loadResources(e={}){this.resetRetainingTransientData();const s=w.v4();this._loadId=s,await this._loadResources(0,s,e)},async _loadResources(e,s,t){var b,F,O,k,Q;const l=e==0;if(this.status=l?"Loading":"LoadingMore",this._loadOffset=e,((b=this.filter)==null?void 0:b.query)===!1){this.resources=[];return}const d=this.fixedQueryParams,u=r.cloneDeep(d),h=l?(F=this.filter)!=null&&F.resourceIds&&!this.order?null:t.firstPageSize||((O=n.loading)==null?void 0:O.firstPageSize)||t.pageSize||((k=n.loading)==null?void 0:k.pageSize)||null:t.pageSize||((Q=n.loading)==null?void 0:Q.pageSize)||null,p=h!=null||n.limit!=null?r.min(r.filter([h,n.limit],R=>R!=null)):void 0;p!=null?(u.offset=e,u.limit=p):e!=0&&(u.offset=e);const D=r.map(u,(R,m)=>R!=null?`${encodeURIComponent(m)}=${encodeURIComponent(R)}`:null).filter(R=>R!=null).join("&"),T=r.isEmpty(D)?n.restCollectionUrl:`${n.restCollectionUrl}?${D}`;try{const R=await $.get(T),m=this.fixedQueryParams;if(s!=this._loadId||e!=this._loadOffset||!r.isEqual(d,m))console.log(`Discarding resources fetched by obsolete query from ${n.restCollectionUrl}.`);else{const E=ne.decode(r.get(R,"data.data",[])),L=(l?0:this.resources.length)+E.length,I=p==null||E.length<p||n.limit&&L>=n.limit;console.log(`Loaded ${E.length}${l?"":" more"} resources from ${n.restCollectionUrl}`),l&&(this.resources=[]);const H=[...this.resources,...E.map(Z=>Object.freeze(Z))];this.resources=De(H,this),this.status=I?"Loaded":"LoadingMore",I||this._loadResources(this.resources.length,s,t)}}catch(R){console.log(`Error while loading resources (URL="${T}"):`,R),this.clearRetainingTransientData(),this.status="Failed"}},async checkForDeletedResource(e){let s;try{s=await $.get(`${n.restCollectionUrl}/${e}`)}catch(t){$.isAxiosError(t)&&(s=t.response)}return s&&s.status==404?(this.recordDeletion(e),!0):!1},recordDeletion(e){var s;if(["Loaded","LoadingMore"].includes(this.status)){let t=this.resources.findIndex(l=>g(l,this)==e);t>=0&&this.resources.splice(t,1),t=this.selection.findIndex(l=>g(l,this)==e),t>=0&&this.selection.splice(t,1),t=this.detailSelection.findIndex(l=>g(l,this)==e),t>=0&&(this.detailSelection.splice(t,1),this.detailSelection.length==0&&(this.editingDetailSelection=((s=n.detail)==null?void 0:s.autoEdit)||!1)),n.limitTransientDataToLocalCollection&&delete this.transientData[e]}},recordInsertion(e,{insertAtBeginning:s,transientData:t}={}){var l;if(["Loaded","LoadingMore"].includes(this.status)){const d=Object.freeze(e);s?this.resources.unshift(d):this.resources.push(d),(l=n.detail)!=null&&l.autoFromSingleInsertion&&(this.detailSelection.length==0||this.detailSelection.length==1&&g(this.detailSelection[0],this)==null)&&(this.detailSelection=[d],this.editingDetailSelection=n.detail.autoEdit);const u=g(e,this);u&&(t===void 0?delete this.transientData[u]:this.transientData[u]=t)}},recordUpdate(e){const s=g(e,this);if(s&&["Loaded","LoadingMore"].includes(this.status)){const t=Object.freeze(e);let l=this.resources.findIndex(d=>g(d,this)==s);l>=0&&(this.resources[l]=t),l=this.selection.findIndex(d=>g(d,this)==s),l>=0&&(this.selection[l]=t),l=this.detailSelection.findIndex(d=>g(d,this)==s),l>=0&&(this.detailSelection[l]=t)}},async refreshResource(e){if(e){const s={};this.referencePathsToExpand&&(s.r=J(this.referencePathsToExpand));const t=r.map(s,(u,h)=>u!=null?`${encodeURIComponent(h)}=${encodeURIComponent(u)}`:null).filter(u=>u!=null).join("&"),l=r.isEmpty(t)?`${n.restCollectionUrl}/${e}`:`${n.restCollectionUrl}/${e}?${t}`,d=await $.get(l);if(d.status==200){const u=d.data;return this.recordUpdate(u),u}}return null},addResource(e={}){this.detailSelection=[r.omit(r.merge({},e),this.idProperty)],this.editingDetailSelection=!0},async deleteResource(e){if((await $.delete(`${n.restCollectionUrl}/${e}`)).status==200&&["Loaded","LoadingMore"].includes(this.status)){let t=this.resources.findIndex(l=>g(l,this)==e);t>=0&&this.resources.splice(t,1),t=this.selection.findIndex(l=>g(l,this)==e),t>=0&&this.selection.splice(t,1),t=this.detailSelection.findIndex(l=>g(l,this)==e),t>=0&&(this.detailSelection.splice(t,1),this.detailSelection.length==0&&(this.editingDetailSelection=n.detail.autoEdit)),n.limitTransientDataToLocalCollection&&delete this.transientData[e]}},async saveResource(e){const s=g(e,this),t=s==null,l=await $({method:t?"post":"put",url:t?n.restCollectionUrl:`${n.restCollectionUrl}/${s}`,data:e});if(l.status==200){const d=l.data,u=g(d,this),h=u?await this.refreshResource(u):null;return t&&this.recordInsertion(h||Object.freeze(d)),h||d}return null},async saveResources(e){const s=await $({method:"put",url:n.restCollectionUrl,data:e});if(s.status==200){const t=s.data||[],l=[];for(const[d,u]of t.entries()){const h=g(e[d],this)==null,p=g(u,this),D=p?await this.refreshResource(p):null;h&&this.recordInsertion(D||u),l.push(D||Object.freeze(u))}return l}return[]},clearTransientData(){this.transientData={}},setInvalidResourceIds(e){r.isEqual(e,this.invalidResources.map(s=>g(s,this)))||(this.invalidResources=e.map(s=>this.resources.find(t=>g(t,this)==s)).filter(s=>s!=null))},setTransientDataForResources(e){const{transientData:s,merge:t=!0}=e;t?r.merge(this.transientData,s):r.assign(this.transientData,s)},clearSelection(){this.setSelection([])},deselectResources(e){const s=this.selection.map(t=>g(t,this)).filter(t=>t!=null&&!e.includes(t));this.setSelection(s)},selectResources(e,s){const{addToSelection:t,edit:l}=s||{},d=this.selection.map(h=>g(h,this));let u=e;if(t){const h=r.difference(e,d);h.length>0&&(u=d.concat(h).filter(p=>p!=null))}r.isEqual(d,u)||this.setSelection(u,l)},setSelection(e,s){if(!r.isEqual(e,this.selection.map(t=>g(t,this)))){let t=!0;if(this.editors.length>0){if(n.detail.autoFromSingleSelection&&this.selection.length==1)t=!1;else if(n.detail.autoFromMultipleSelection&&n.detail.allowMultiple&&this.selection.length>1)t=!1;else if(n.detail.constrainToSelection){const l=this.selection.map(h=>g(h,this)),u=this.detailSelection.map(h=>g(h,this)).filter(h=>l.includes(h));this.detailSelection.filter(h=>!u.includes(g(h,this))).length>0&&(t=!1)}}if(!t)return;if(this.selection=e.map(l=>this.resources.find(d=>g(d,this)==l)).filter(l=>l!=null),n.detail.autoFromSingleSelection&&this.selection.length==1){const l=this.selection[0];(this.detailSelection.length!=1||g(this.detailSelection[0],this)!=g(l,this))&&(this.detailSelection=[l])}else if(n.detail.autoFromMultipleSelection&&n.detail.allowMultiple&&this.selection.length>1)r.isEqual(this.selection.map(l=>g(l,this)),this.detailSelection.map(l=>g(l,this)))||(this.detailSelection=r.clone(this.selection));else if(n.detail.constrainToSelection){const l=this.selection.map(h=>g(h,this)),d=this.detailSelection.map(h=>g(h,this)),u=d.filter(h=>l.includes(h));r.isEqual(u,d)||(this.detailSelection=this.detailSelection.filter(h=>u.includes(g(h,this))))}this.detailSelection.length==0?this.editingDetailSelection=!1:this.editingDetailSelection=s!==void 0?s:this.editingDetailSelection||n.detail.autoEdit}},hideDetail(){this.detailSelection.length>0&&(this.detailSelection=[],this.editingDetailSelection=!1)},showSelectionAsDetail(e){if(this.selection.length<=1||n.detail.allowMultiple){const s=this.selection.map(l=>g(l,this)),t=this.detailSelection.map(l=>g(l,this));r.isEqual(s,t)||(this.detailSelection=r.clone(this.selection)),this.detailSelection.length==0?this.editingDetailSelection=!1:this.editingDetailSelection=e!==void 0?e:this.editingDetailSelection||n.detail.autoEdit}},deregisterEditor(e){r.remove(this.editors,s=>s==e)},registerEditor(e){this.editors.includes(e)||this.editors.push(e)},deregisterListNavigator({name:e,listNavigator:s}){(s==null||this.listNavigators[e]==s)&&delete this.listNavigators[e]},registerListNavigator({name:e,listNavigator:s}){this.listNavigators[e]!=s&&(this.listNavigators[e]=s)}}});return(()=>{const e=(s,t)=>{const l=C(s,t);return ee.registerStore(l.$id,l),l};return e.$id=C.$id,e})()},ee=new ce,Ue=(y={})=>{var he,fe,ge,ve;console.log("hereaaaaaaa"),console.log(y);const{collectionId:n,draftBatchId:C,enabled:q,resourceType:e,options:s}=y,t=o.ref(void 0),l=o.ref(n),d=o.ref(C),u=o.ref(q??!0),h=o.ref([o.toRef(e)]),p=o.ref(s),D=o.computed(()=>d.value),T=o.ref(u.value),b=o.ref(w.v4()),F=o.ref((fe=(he=p.value)==null?void 0:he.filter)==null?void 0:fe.resourceIds),O=o.ref((ve=(ge=p.value)==null?void 0:ge.filter)==null?void 0:ve.query),k=o.computed(()=>d.value==null&&l.value!=null&&ee.getStore(l.value)!=null),Q=o.ref(k.value),R=o.computed(()=>L("status","Uninitialized"));function m(i){if(t.value)return i(t.value)}async function E(i){if(t.value)return await i(t.value)}function L(i,c){if(t.value)return t.value[i];if(c!==void 0)return c;throw"Attempted to use a REST collection store that has not been created, with no default value."}const I=(i={})=>{var me,pe,Se,ye;const{collectionId:c,draftBatchId:U,enabled:z,resourceType:re,options:Re}=i;l.value=c,d.value=U,u.value=z??!0,h.value=[o.toRef(re)],Re!=null&&(p.value=Re,F.value=(pe=(me=p.value)==null?void 0:me.filter)==null?void 0:pe.resourceIds,O.value=(ye=(Se=p.value)==null?void 0:Se.filter)==null?void 0:ye.query),b.value=w.v4(),H(u.value)},H=async i=>{i!=T.value&&(T.value=i,i&&(_(),x()))},Z=async i=>{F.value=i,await E(async c=>await c.setFilterResourceIds(F.value||null))},V=async i=>{if(O.value=i,R.value!="Uninitialized"){const c=i,U=o.computed(()=>r.isFunction(c)?S.value?c(S.value):null:c);await E(z=>z.setQuery(U.value||null))}},_=()=>{p.value=r.merge({},p.value||{},{filter:{resourceIds:F.value,query:O.value}})},S=o.computed(()=>h.value[0].value||void 0),B=function(i){const c=r.get(i,"filter.query"),U=r.get(i,"referencePathsToExpand"),z=r.isFunction(c)?c(S.value):c,re=S.value?r.isFunction(U)?U(S.value):U||[]:[];return{...r.cloneDeep(i||{}),filter:{...r.cloneDeep((i==null?void 0:i.filter)||{}),query:z},referencePathsToExpand:re}},P=o.computed(()=>B(p.value)),M=o.computed(()=>{if(!S.value)return null;if(P.value.restCollectionUrl!==void 0)return P.value.restCollectionUrl;if(!Q.value)return!S.value||!S.value.collectionName?null:D.value?`${G.config.apiBaseUrl}/draft-batches/${D.value}/${S.value.collectionName}`:`${G.config.apiBaseUrl}/${S.value.collectionName}`}),a=o.computed(()=>{var i;if(S.value)return r.mergeWith(r.cloneDeep(ue),P.value,{idProperty:(i=S.value)==null?void 0:i.idProperty,restCollectionUrl:M.value||""},(c,U)=>{if(r.isArray(U)&&U.length==0&&(c==null||r.isArray(c)))return U})}),f=o.ref(0),N=o.computed(()=>{var i;return f.value,l.value||S.value&&((i=S.value)==null?void 0:i.collectionName)&&(D.value?`draftBatches/${D.value}/${S.value.collectionName}/${b.value}`:`${S.value.collectionName}/${b.value}`)||null}),x=()=>{if(T.value){let i=!1;return S.value&&N.value&&(t.value=ee.getStore(N.value),t.value?i=!1:a.value&&(Q.value=!1,t.value=Ee(N.value,a.value)(),i=!0)),i}else return!1},X=()=>{N.value&&l.value==N.value?(t.value=void 0,x()):(t.value=void 0,f.value=f.value+1,x())};o.watch(D,(i,c)=>{r.isEqual(i,c)||X()}),o.watch(T,(i,c)=>{i!=c&&(i?x():t.value=void 0)}),o.watch(S,(i,c)=>{i&&!c?x():!i&&c||r.isEqual(i,c)||X()}),o.watch(a,(i,c)=>{r.isEqual(i,c)||X()}),o.watch(k,()=>{k.value||(Q.value=!1)}),o.watch(N,()=>x()),o.watch(M,(i,c)=>{r.isEqual(i,c)||X()});const W=[],qe=function(i){R.value!="Uninitialized"?o.nextTick(i):W.push(i)};return o.watch(R,(i,c)=>{if(i!="Uninitialized"&&c=="Uninitialized"){const U=r.clone(W);W.splice(0,W.length);for(const z of U)z()}}),x(),{collectionId:N,draftBatchId:D,resourceType:S,enabled:T,status:R,batchSaveAttempted:o.computed(()=>L("batchSaveAttempted",!1)),listNavigators:o.computed(()=>L("listNavigators",!1)),invalidResources:o.computed(()=>L("invalidResources",[])),resources:o.computed(()=>R.value!="Uninitialized"?(E(i=>i.ensureCollectionLoaded()),L("resources",[])):[]),transientData:o.computed(()=>L("transientData",[])),detailSelection:o.computed(()=>L("detailSelection",[])),editingDetailSelection:o.computed(()=>L("editingDetailSelection",!1)),selection:o.computed(()=>L("selection",[])),reconfigureCollection:I,setEditingDetailSelection:i=>m(c=>c.setEditingDetailSelection(i)),setEnabled:H,setFilterResourceIds:Z,setQuery:V,ensureStore:x,setBatchSaveAttempted:i=>m(c=>c.setBatchSaveAttempted(i)),clear:()=>m(i=>i.clear()),ensureCollectionLoaded:async()=>await E(async i=>i.ensureCollectionLoaded()),loadResources:async()=>await E(async i=>await i.loadResources()),addResource:i=>m(c=>c.addResource(i)),checkForDeletedResource:async i=>await E(async c=>await c.checkForDeletedResource(i))==!0,recordDeletion:i=>m(c=>c.recordDeletion(i)),recordInsertion:(i,{insertAtBeginning:c=!1,transientData:U=void 0}={})=>m(z=>z.recordInsertion(i,{insertAtBeginning:c,transientData:U})),recordUpdate:i=>m(c=>c.recordUpdate(i)),refreshResource:async i=>await E(async c=>await c.refreshResource(i)),deleteResource:async i=>await E(async c=>await c.deleteResource(i)),saveResource:async i=>await E(async c=>await c.saveResource(i)),saveResources:async i=>await E(async c=>await c.saveResources(i)),clearTransientData:()=>m(i=>i.clearTransientData()),setInvalidResourceIds:i=>m(c=>c.setInvalidResourceIds(i)),setTransientDataForResources:i=>m(c=>c.setTransientDataForResources(i)),clearSelection:()=>m(i=>i.clearSelection()),deselectResources:i=>m(c=>c.deselectResources(i)),selectResources:(i,c)=>m(U=>U.selectResources(i,c)),hideDetail:()=>m(i=>i.hideDetail()),deregisterEditor:i=>m(c=>c.deregisterEditor(i)),registerEditor:i=>m(c=>c.registerEditor(i)),deregisterListNavigator:i=>m(c=>c.deregisterListNavigator(i)),registerListNavigator:i=>m(c=>c.registerListNavigator(i)),onItemsStoreReady:qe}},Ce=()=>{ee.clearAllStores()};function ie(y,n){return r.get(y,(n==null?void 0:n.idProperty)||"_id")}const de={idProperty:"_id"},Y={resource:null,status:"NotLoaded"},Te=(y,n)=>{n=r.merge({},de,n),console.log(y),console.log(n);const C=oe.defineStore(y,{state:()=>({idProperty:n.idProperty,resourceId:n.resourceId||null,resourceUrl:n.resourceUrl||null,referencePathsToExpand:n.referencePathsToExpand||null,...Y}),getters:{currentResourceUrl:e=>(console.log(e),console.log(n),e.resourceUrl||(n.restCollectionUrl&&e.resourceId?`${n.restCollectionUrl}/${e.resourceId}`:null)||n.restCollectionUrl||null),fixedQueryParams:e=>{const s={};return e.referencePathsToExpand&&(s.r=J(e.referencePathsToExpand)),s}},actions:{reset(){for(const e in Y)this[e]=Y[e]},async setResourceId(e){const s=this.currentResourceUrl;this.resourceId=e,console.log(e),!r.isEqual(this.currentResourceUrl,s)&&this.status!="NotLoaded"&&(console.log("here"),await this.loadResource())},async setResourceUrl(e){const s=this.currentResourceUrl;this.resourceUrl=e,!r.isEqual(this.currentResourceUrl,s)&&this.status!="NotLoaded"&&await this.loadResource()},clear(){for(const e in Y)this[e]=Y[e]},async ensureResourceLoaded(){["Loaded","Loading","Failed"].includes(this.status)||await this.loadResource()},async loadResource(){this.reset();const e=w.v4();if(this._loadId=e,this.currentResourceUrl){this.status="Loading";const s=this.fixedQueryParams,t=r.cloneDeep(s),l=r.map(t,(u,h)=>u!=null?`${encodeURIComponent(h)}=${encodeURIComponent(u)}`:null).filter(u=>u!=null).join("&"),d=r.isEmpty(l)?this.currentResourceUrl:`${this.currentResourceUrl}?${l}`;try{const u=await $.get(d),h=this.fixedQueryParams;e!=this._loadId||!r.isEqual(s,h)?console.log(`Discarding resource fetched by obsolete query from ${d}.`):(this.resource=ne.decode(r.get(u,"data",{})),this.status="Loaded")}catch(u){console.log(`Error while loading resource (URL="${d}")`,u),this.reset(),this.status="Failed"}}else throw"Cannot load a resource because its URL, or its ID and collection URL, are unknown."},async checkForDeletedResource(){if(this.currentResourceUrl){let e;try{e=await $.get(this.currentResourceUrl)}catch(s){$.isAxiosError(s)&&(e=s.response)}return e&&e.status==404?(this.recordDeletion(),!0):!1}else throw"Cannot check for a deleted resource because its URL, or its ID and collection URL, are unknown."},recordDeletion(){this.resource=null,this.status="Loaded"},recordInsertion(e){this.resourceId=ie(e,this)||null,this.status=="Loaded"&&(this.resource=Object.freeze(e))},recordUpdate(e){this.resourceId=ie(e,this)||null,this.status=="Loaded"&&(this.resource=Object.freeze(e))},async refreshResource(){return await this.loadResource(),this.resource},async deleteResource(){if(this.currentResourceUrl)(await $.delete(this.currentResourceUrl)).status==200&&this.recordDeletion();else throw"Cannot delete a resource because its URL, or its ID and collection URL, are unknown."},async saveResource(e){const s=ie(e,this),t=s==null;if(!s)throw"The REST resource store cannot create new resources on the server.";if(!this.currentResourceUrl)throw"Cannot save a resource because its URL, or its ID and collection URL, are unknown.";const l=await $({method:t?"post":"put",url:this.currentResourceUrl,data:e});if(l.status==200){const d=l.data,u=await this.refreshResource();return t&&this.recordInsertion(u||d),u||Object.freeze(d)}return null},async makeCustomApiRequest(e){const{method:s,subpath:t,url:l,data:d}=e;let u=l;if(!u)if(this.currentResourceUrl)u=`${this.currentResourceUrl}/${t}`;else throw"Cannot make a custom API request for a resource because its URL, or its ID and collection URL, are unknown.";const h=await $({method:s||"get",url:u,data:d});return h.status>=200&&h.status<300?h.data:null}}});return(()=>{const e=(s,t)=>{const l=C(s,t);return se.registerStore(l.$id,l),l};return e.$id=C.$id,e})()},se=new ce,Le=(y={})=>{console.log("HERE!!!!"),console.log(y);const{resourceClientId:n,draftBatchId:C,enabled:q,resourceType:e,options:s}=y,t=o.ref(void 0),l=o.ref(n),d=o.ref(C),u=o.ref(q??!0),h=o.ref([o.toRef(e)]),p=o.ref(s),D=o.computed(()=>d.value),T=o.ref(u.value),b=o.ref(w.v4()),F=o.computed(()=>d.value==null&&l.value!=null&&se.getStore(l.value)!=null),O=o.ref(F.value),k=o.computed(()=>m("status","Uninitialized"));function Q(a){if(t.value)return a(t.value)}async function R(a){if(console.log("dispatchAsync"),console.log("STORE:"),console.log(t.value),t.value)return await a(t.value)}function m(a,f){if(t.value)return t.value[a];if(f!==void 0)return f;throw"Attempted to use a REST resource store that has not been created, with no default value."}const E=(a={})=>{const{resourceClientId:f,draftBatchId:N,enabled:x,resourceType:X,options:W}=a;l.value=f,d.value=N,u.value=x??!0,h.value=[o.toRef(X)],W!=null&&(p.value=W),b.value=w.v4(),L(u.value)},L=async a=>{a!=T.value&&(T.value=a,a&&P())},I=o.computed(()=>h.value[0].value||void 0),H=function(a){const f=r.get(a,"referencePathsToExpand"),N=I.value?r.isFunction(f)?f(I.value):f||[]:[];return{...r.cloneDeep(a||{}),referencePathsToExpand:N}},Z=o.computed(()=>H(p.value)),V=o.computed(()=>{if(!I.value)return null;if(!O.value)return!I.value||!I.value.collectionName?null:D.value?`${G.config.apiBaseUrl}/draft-batches/${D.value}/${I.value.collectionName}`:`${G.config.apiBaseUrl}/${I.value.collectionName}`}),_=o.computed(()=>{if(I.value&&V.value)return r.mergeWith(r.cloneDeep(de),Z.value,{idProperty:I.value.idProperty,restCollectionUrl:V.value},(a,f)=>{if(r.isArray(f)&&f.length==0&&(a==null||r.isArray(a)))return f})}),S=o.ref(0),B=o.computed(()=>{var a;return S.value,l.value||I.value&&((a=I.value)==null?void 0:a.collectionName)&&(D.value?`draftBatches/${D.value}/${I.value.collectionName}/${b.value}`:`${I.value.collectionName}/${b.value}`)||null}),P=()=>{if(T.value){let a=!1;return I.value&&B.value&&(t.value=se.getStore(B.value),t.value?a=!1:_.value&&(O.value=!1,t.value=Te(B.value,_.value)(),a=!0)),a}else return!1},M=()=>{B.value&&l.value==B.value?(t.value=void 0,P()):(t.value=void 0,S.value=S.value+1,P())};return o.watch(D,(a,f)=>{r.isEqual(a,f)||M()}),o.watch(T,(a,f)=>{a!=f&&(a?P():t.value=void 0)}),o.watch(I,(a,f)=>{a&&!f?P():!a&&f||r.isEqual(a,f)||M()}),o.watch(_,(a,f)=>{r.isEqual(a,f)||M()}),o.watch(F,()=>{F.value||(O.value=!1)}),o.watch(B,()=>P()),o.watch(V,(a,f)=>{r.isEqual(a,f)||M()}),P(),{resourceClientId:B,draftBatchId:D,enabled:T,resourceType:I,status:k,resource:o.computed(()=>k.value!="Uninitialized"?(R(a=>a.ensureResourceLoaded()),m("resource",[])):[]),resourceId:o.computed(()=>m("resourceId",null)),resourceUrl:o.computed(()=>m("resourceUrl",null)),reconfigureClient:E,setEnabled:L,setResourceId:async a=>await R(async f=>{console.log(f),console.log(f.setResourceId),console.log(a),await f.setResourceId(a)}),setResourceUrl:async a=>await R(async f=>await f.setResourceUrl(a)),ensureStore:P,clear:()=>Q(a=>a.clear()),ensureResourceLoaded:async()=>await R(async a=>a.ensureResourceLoaded()),loadResource:async()=>await R(async a=>await a.loadResource()),checkForDeletedResource:async()=>await R(async a=>await a.checkForDeletedResource())==!0,recordDeletion:()=>R(a=>a.recordDeletion()),recordInsertion:a=>R(f=>f.recordInsertion(a)),recordUpdate:a=>R(f=>f.recordUpdate(a)),refreshResource:async()=>await R(async a=>await a.refreshResource()),deleteResource:async()=>await R(async a=>await a.deleteResource()),saveResource:async a=>await R(async f=>await f.saveResource(a)),makeCustomApiRequest:async a=>await R(async f=>await f.makeCustomApiRequest(a))}},G={config:{...ae}};function $e(y){G.config=r.merge({},ae,y)}v.ApiClientError=we,v.clearAllRestCollections=Ce,v.initRestClient=$e,v.restClient=G,v.useRestCollection=Ue,v.useRestResource=Le,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rest-client-vue",
3
- "version": "1.0.0-a3",
3
+ "version": "1.0.0-a4",
4
4
  "author": {
5
5
  "name": "Jeremy Stone",
6
6
  "email": "stoneje@msn.com"