rest-client-vue 1.2.0-b3 → 1.2.1-a
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/index.d.ts +14 -7
- package/dist/rest-client-vue.js +383 -371
- package/dist/rest-client-vue.umd.cjs +1 -1
- package/dist/src/rest-collection-resources.d.ts +0 -1
- package/dist/src/rest-collection-resources.d.ts.map +1 -1
- package/dist/src/rest-collection.d.ts +13 -4
- package/dist/src/rest-collection.d.ts.map +1 -1
- package/dist/src/rest-resource.d.ts +1 -1
- package/dist/src/rest-resource.d.ts.map +1 -1
- package/dist/src/stores/rest-collection-store.d.ts +29 -13
- package/dist/src/stores/rest-collection-store.d.ts.map +1 -1
- package/dist/src/stores/rest-resource-store.d.ts +7 -7
- package/dist/src/stores/rest-resource-store.d.ts.map +1 -1
- package/package.json +9 -3
package/dist/rest-client-vue.js
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
var Ee = Object.defineProperty;
|
2
|
-
var Ce = (h,
|
3
|
-
var
|
4
|
-
if (!
|
5
|
-
throw TypeError("Cannot " +
|
2
|
+
var Ce = (h, r, R) => r in h ? Ee(h, r, { enumerable: !0, configurable: !0, writable: !0, value: R }) : h[r] = R;
|
3
|
+
var ae = (h, r, R) => (Ce(h, typeof r != "symbol" ? r + "" : r, R), R), Te = (h, r, R) => {
|
4
|
+
if (!r.has(h))
|
5
|
+
throw TypeError("Cannot " + R);
|
6
6
|
};
|
7
|
-
var Q = (h,
|
8
|
-
if (
|
7
|
+
var Q = (h, r, R) => (Te(h, r, "read from private field"), R ? R.call(h) : r.get(h)), Se = (h, r, R) => {
|
8
|
+
if (r.has(h))
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
10
|
-
|
10
|
+
r instanceof WeakSet ? r.add(h) : r.set(h, R);
|
11
11
|
};
|
12
|
-
import
|
12
|
+
import a from "lodash";
|
13
13
|
import { v4 as H } from "uuid";
|
14
|
-
import { ref as I, toRef as se, computed as
|
15
|
-
import
|
14
|
+
import { ref as I, toRef as se, computed as g, watch as $, nextTick as Le } from "vue";
|
15
|
+
import L from "axios";
|
16
16
|
import pe from "jsog";
|
17
17
|
import X from "json-stringify-deterministic";
|
18
18
|
import { defineStore as me } from "pinia";
|
@@ -21,52 +21,52 @@ const ye = {
|
|
21
21
|
useVueLogger: !1
|
22
22
|
};
|
23
23
|
class Be extends Error {
|
24
|
-
constructor(
|
25
|
-
super(
|
26
|
-
|
27
|
-
|
28
|
-
this.context =
|
24
|
+
constructor(R, w = void 0, e = void 0) {
|
25
|
+
super(R);
|
26
|
+
ae(this, "context");
|
27
|
+
ae(this, "innerError");
|
28
|
+
this.context = w, this.innerError = e;
|
29
29
|
}
|
30
30
|
}
|
31
|
-
var
|
31
|
+
var _;
|
32
32
|
class Ie {
|
33
33
|
constructor() {
|
34
|
-
Se(this,
|
34
|
+
Se(this, _, {});
|
35
35
|
}
|
36
36
|
clearAllStores() {
|
37
|
-
for (const
|
38
|
-
Q(this,
|
37
|
+
for (const r in Q(this, _))
|
38
|
+
Q(this, _)[r].clear();
|
39
39
|
}
|
40
|
-
destroyStore(
|
41
|
-
Q(this,
|
40
|
+
destroyStore(r) {
|
41
|
+
Q(this, _)[r] && (Q(this, _)[r].$dispose(), delete Q(this, _)[r]);
|
42
42
|
}
|
43
|
-
getStore(
|
44
|
-
return Q(this,
|
43
|
+
getStore(r) {
|
44
|
+
return Q(this, _)[r];
|
45
45
|
}
|
46
|
-
registerStore(
|
47
|
-
Q(this,
|
46
|
+
registerStore(r, R) {
|
47
|
+
Q(this, _)[r] = R;
|
48
48
|
}
|
49
49
|
}
|
50
|
-
|
51
|
-
function v(h,
|
52
|
-
return
|
50
|
+
_ = new WeakMap();
|
51
|
+
function v(h, r) {
|
52
|
+
return a.get(h, (r == null ? void 0 : r.idProperty) || "_id");
|
53
53
|
}
|
54
|
-
function $e(h,
|
55
|
-
const
|
56
|
-
|
57
|
-
(
|
58
|
-
).filter((
|
59
|
-
if (
|
60
|
-
const
|
61
|
-
return
|
54
|
+
function $e(h, r) {
|
55
|
+
const R = a.map(
|
56
|
+
r,
|
57
|
+
(w, e) => w != null ? `${encodeURIComponent(e)}=${encodeURIComponent(w)}` : null
|
58
|
+
).filter((w) => w != null).join("&");
|
59
|
+
if (R.length > 0) {
|
60
|
+
const w = h.indexOf("?");
|
61
|
+
return w == h.length - 1 ? `${h}${R}` : w >= 0 ? `${h}&${R}` : `${h}?${R}`;
|
62
62
|
} else
|
63
63
|
return h;
|
64
64
|
}
|
65
|
-
function xe(h,
|
66
|
-
var
|
67
|
-
return h && ((
|
65
|
+
function xe(h, r) {
|
66
|
+
var R;
|
67
|
+
return h && ((R = r.filter) != null && R.resourceIds) && !r.order ? r.filter.resourceIds.map((w) => h.find((e) => v(e, r) == w)).filter((w) => w != null) : h;
|
68
68
|
}
|
69
|
-
const
|
69
|
+
const we = {
|
70
70
|
detail: {
|
71
71
|
allowMultiple: !0,
|
72
72
|
autoEdit: !1,
|
@@ -80,9 +80,6 @@ const Ue = {
|
|
80
80
|
query: null,
|
81
81
|
resourceIds: null
|
82
82
|
},
|
83
|
-
hooks: {
|
84
|
-
beforeLoadResources: null
|
85
|
-
},
|
86
83
|
idProperty: "_id",
|
87
84
|
limit: 5e3,
|
88
85
|
limitTransientDataToLocalCollection: !0,
|
@@ -102,25 +99,24 @@ const Ue = {
|
|
102
99
|
selection: [],
|
103
100
|
detailSelection: [],
|
104
101
|
invalidResources: [],
|
105
|
-
transientData: {}
|
106
|
-
|
107
|
-
}, ae = {
|
102
|
+
transientData: {}
|
103
|
+
}, oe = {
|
108
104
|
editingDetailSelection: !1,
|
109
105
|
batchSaveAttempted: !1,
|
110
106
|
editors: [],
|
111
107
|
listNavigators: {}
|
112
|
-
}, Pe = (h,
|
113
|
-
|
114
|
-
const
|
108
|
+
}, Pe = (h, r) => {
|
109
|
+
r = a.merge({}, we, r);
|
110
|
+
const R = me(h, {
|
115
111
|
state: () => ({
|
116
|
-
idProperty:
|
117
|
-
filter:
|
118
|
-
order:
|
119
|
-
propertiesToExclude:
|
120
|
-
referencePathsToExpand:
|
121
|
-
restCollectionUrl:
|
112
|
+
idProperty: r.idProperty,
|
113
|
+
filter: r.filter,
|
114
|
+
order: r.order || null,
|
115
|
+
propertiesToExclude: r.propertiesToExclude || null,
|
116
|
+
referencePathsToExpand: r.referencePathsToExpand || null,
|
117
|
+
restCollectionUrl: r.restCollectionUrl,
|
122
118
|
...Y,
|
123
|
-
...
|
119
|
+
...oe
|
124
120
|
}),
|
125
121
|
getters: {
|
126
122
|
/**
|
@@ -130,14 +126,14 @@ const Ue = {
|
|
130
126
|
*/
|
131
127
|
fixedQueryParams: (e) => {
|
132
128
|
var l, u, c, d;
|
133
|
-
const
|
134
|
-
(l = e.filter) != null && l.namedFilter && (
|
129
|
+
const i = {};
|
130
|
+
(l = e.filter) != null && l.namedFilter && (i.namedFilter = e.filter.namedFilter);
|
135
131
|
const t = [];
|
136
132
|
if ((u = e.filter) != null && u.resourceIds && t.push({ l: { path: e.idProperty }, r: { constant: e.filter.resourceIds }, operator: "in" }), (c = e.filter) != null && c.query && t.push((d = e.filter) == null ? void 0 : d.query), t.length > 0) {
|
137
133
|
const m = t.length == 1 ? t[0] : { and: t };
|
138
|
-
|
134
|
+
i.q = X(m);
|
139
135
|
}
|
140
|
-
return e.order && (
|
136
|
+
return e.order && (i.o = X(e.order)), e.propertiesToExclude && (i.ex = X(e.propertiesToExclude)), e.referencePathsToExpand && (i.r = X(e.referencePathsToExpand)), i;
|
141
137
|
}
|
142
138
|
},
|
143
139
|
actions: {
|
@@ -152,8 +148,8 @@ const Ue = {
|
|
152
148
|
reset() {
|
153
149
|
for (const e in Y)
|
154
150
|
this[e] = Y[e];
|
155
|
-
for (const e in
|
156
|
-
this[e] =
|
151
|
+
for (const e in oe)
|
152
|
+
this[e] = oe[e];
|
157
153
|
},
|
158
154
|
/**
|
159
155
|
* Reset the store to its initial state, but retain transient data if appropriate.
|
@@ -162,7 +158,7 @@ const Ue = {
|
|
162
158
|
* Transient data are retained if options.limitTransientDataToLocalCollection is false.
|
163
159
|
*/
|
164
160
|
resetRetainingTransientData() {
|
165
|
-
if (
|
161
|
+
if (r.limitTransientDataToLocalCollection)
|
166
162
|
this.reset();
|
167
163
|
else {
|
168
164
|
const e = this.transientData;
|
@@ -193,7 +189,7 @@ const Ue = {
|
|
193
189
|
* @param filter The new filter.
|
194
190
|
*/
|
195
191
|
setFilter(e) {
|
196
|
-
|
192
|
+
a.isEqual(e, this.filter) || (this.filter = e, this.status = "NotLoaded", this.resources = [], this.remoteCollectionSize = null, this.selection = [], this.detailSelection = [], this.invalidResources = [], this.editingDetailSelection = !1);
|
197
193
|
},
|
198
194
|
/**
|
199
195
|
* Set the filter query.
|
@@ -205,10 +201,10 @@ const Ue = {
|
|
205
201
|
* need to be reloaded.
|
206
202
|
*/
|
207
203
|
async setQuery(e) {
|
208
|
-
var
|
209
|
-
if (!
|
210
|
-
const l =
|
211
|
-
e !== null ? l.query = e :
|
204
|
+
var i, t;
|
205
|
+
if (!a.isEqual(e, (i = this.filter) == null ? void 0 : i.query) && (e != null || ((t = this.filter) == null ? void 0 : t.query) != null)) {
|
206
|
+
const l = a.cloneDeep(this.filter) || {};
|
207
|
+
e !== null ? l.query = e : a.unset(l, "query");
|
212
208
|
const u = this.status;
|
213
209
|
this.setFilter(l), u != "NotLoaded" && await this.loadResources();
|
214
210
|
}
|
@@ -223,11 +219,11 @@ const Ue = {
|
|
223
219
|
* need to be reloaded.
|
224
220
|
*/
|
225
221
|
async setFilterResourceIds(e) {
|
226
|
-
if (!
|
227
|
-
const
|
228
|
-
e != null ?
|
222
|
+
if (!a.isEqual(e, a.get(this.filter, "resourceIds"))) {
|
223
|
+
const i = a.cloneDeep(this.filter) || {};
|
224
|
+
e != null ? i.resourceIds = e : a.unset(i, "resourceIds");
|
229
225
|
const t = this.status;
|
230
|
-
this.setFilter(
|
226
|
+
this.setFilter(i), t != "NotLoaded" && await this.loadResources();
|
231
227
|
}
|
232
228
|
},
|
233
229
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -263,7 +259,7 @@ const Ue = {
|
|
263
259
|
* Transient data are retained if options.limitTransientDataToLocalCollection is false.
|
264
260
|
*/
|
265
261
|
clearRetainingTransientData() {
|
266
|
-
if (
|
262
|
+
if (r.limitTransientDataToLocalCollection)
|
267
263
|
this.reset();
|
268
264
|
else {
|
269
265
|
const e = this.transientData;
|
@@ -288,8 +284,8 @@ const Ue = {
|
|
288
284
|
*/
|
289
285
|
async loadResources(e = {}) {
|
290
286
|
this.resetRetainingTransientData();
|
291
|
-
const
|
292
|
-
this._loadId =
|
287
|
+
const i = H();
|
288
|
+
this._loadId = i, await this._loadResources(0, i, e);
|
293
289
|
},
|
294
290
|
/**
|
295
291
|
* Load the collection, optionally starting at some offset.
|
@@ -304,40 +300,30 @@ const Ue = {
|
|
304
300
|
* be written to the store's state property named loadId.
|
305
301
|
* @param loadOptions Pagination options that may override the defaults.
|
306
302
|
*/
|
307
|
-
async _loadResources(e,
|
308
|
-
var
|
303
|
+
async _loadResources(e, i, t) {
|
304
|
+
var x, A, N, O, k;
|
309
305
|
const l = e == 0;
|
310
|
-
if (this.status = l ? "Loading" : "LoadingMore", this.
|
311
|
-
const E = i.hooks.beforeLoadResources();
|
312
|
-
if (o.isArray(E)) {
|
313
|
-
this.resources = E, this.status = "Loaded";
|
314
|
-
return;
|
315
|
-
} else if (E === !1) {
|
316
|
-
this.status = "Failed";
|
317
|
-
return;
|
318
|
-
}
|
319
|
-
}
|
320
|
-
if (this._isBeforeLoad = !1, this._loadOffset = e, ((P = this.filter) == null ? void 0 : P.query) === !1) {
|
306
|
+
if (this.status = l ? "Loading" : "LoadingMore", this._loadOffset = e, ((x = this.filter) == null ? void 0 : x.query) === !1) {
|
321
307
|
this.resources = [], this.remoteCollectionSize = 0;
|
322
308
|
return;
|
323
309
|
}
|
324
|
-
const u = this.fixedQueryParams, c =
|
310
|
+
const u = this.fixedQueryParams, c = a.cloneDeep(u), d = l ? (A = this.filter) != null && A.resourceIds && !this.order ? null : t.firstPageSize || ((N = r.loading) == null ? void 0 : N.firstPageSize) || t.pageSize || ((O = r.loading) == null ? void 0 : O.pageSize) || null : t.pageSize || ((k = r.loading) == null ? void 0 : k.pageSize) || null, m = d != null || r.limit != null ? a.min(a.filter([d, r.limit], (P) => P != null)) : void 0;
|
325
311
|
m != null ? (c.offset = e, c.limit = m) : e != 0 && (c.offset = e);
|
326
|
-
const
|
312
|
+
const D = $e(r.restCollectionUrl, c);
|
327
313
|
try {
|
328
|
-
const
|
329
|
-
if (
|
330
|
-
console.log(`Discarding resources fetched by obsolete query from ${
|
314
|
+
const P = await L.get(D), y = this.fixedQueryParams;
|
315
|
+
if (i != this._loadId || e != this._loadOffset || !a.isEqual(u, y))
|
316
|
+
console.log(`Discarding resources fetched by obsolete query from ${r.restCollectionUrl}.`);
|
331
317
|
else {
|
332
|
-
const S = pe.decode(
|
318
|
+
const S = pe.decode(a.get(P, "data.data", [])), T = (l ? 0 : this.resources.length) + S.length, E = m == null || S.length < m || r.limit && T >= r.limit;
|
333
319
|
console.log(
|
334
|
-
`Loaded ${S.length}${l ? "" : " more"} resources from ${
|
320
|
+
`Loaded ${S.length}${l ? "" : " more"} resources from ${r.restCollectionUrl}`
|
335
321
|
), l && (this.resources = []);
|
336
|
-
const
|
337
|
-
this.resources = xe(
|
322
|
+
const U = [...this.resources, ...S.map((W) => Object.freeze(W))];
|
323
|
+
this.resources = xe(U, this), a.get(P, "data.totalCollectionSize") ? this.remoteCollectionSize = a.get(P, "data.totalCollectionSize") : this.remoteCollectionSize = null, this.status = E ? "Loaded" : "LoadingMore", E || this._loadResources(this.resources.length, i, t);
|
338
324
|
}
|
339
|
-
} catch (
|
340
|
-
console.log(`Error while loading resources (URL="${
|
325
|
+
} catch (P) {
|
326
|
+
console.log(`Error while loading resources (URL="${D}"):`, P), this.clearRetainingTransientData(), this.status = "Failed";
|
341
327
|
}
|
342
328
|
},
|
343
329
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -353,13 +339,13 @@ const Ue = {
|
|
353
339
|
* @return true if the record does not exist in the remote collection, false if it does or if an error occurred.
|
354
340
|
*/
|
355
341
|
async checkForDeletedResource(e) {
|
356
|
-
let
|
342
|
+
let i;
|
357
343
|
try {
|
358
|
-
|
344
|
+
i = await L.get(`${r.restCollectionUrl}/${e}`);
|
359
345
|
} catch (t) {
|
360
|
-
|
346
|
+
L.isAxiosError(t) && (i = t.response);
|
361
347
|
}
|
362
|
-
return
|
348
|
+
return i && i.status == 404 ? (this.recordDeletion(e), !0) : !1;
|
363
349
|
},
|
364
350
|
/**
|
365
351
|
* Record a deletion, removing the deleted resource from the local collection.
|
@@ -371,10 +357,10 @@ const Ue = {
|
|
371
357
|
* @param resourceId The ID of the resource that has been deleted.
|
372
358
|
*/
|
373
359
|
recordDeletion(e) {
|
374
|
-
var
|
360
|
+
var i;
|
375
361
|
if (["Loaded", "LoadingMore"].includes(this.status)) {
|
376
362
|
let t = this.resources.findIndex((l) => v(l, this) == e);
|
377
|
-
t >= 0 && this.resources.splice(t, 1), t = this.selection.findIndex((l) => v(l, this) == e), t >= 0 && this.selection.splice(t, 1), t = this.detailSelection.findIndex((l) => v(l, this) == e), t >= 0 && (this.detailSelection.splice(t, 1), this.detailSelection.length == 0 && (this.editingDetailSelection = ((
|
363
|
+
t >= 0 && this.resources.splice(t, 1), t = this.selection.findIndex((l) => v(l, this) == e), t >= 0 && this.selection.splice(t, 1), t = this.detailSelection.findIndex((l) => v(l, this) == e), t >= 0 && (this.detailSelection.splice(t, 1), this.detailSelection.length == 0 && (this.editingDetailSelection = ((i = r.detail) == null ? void 0 : i.autoEdit) || !1)), r.limitTransientDataToLocalCollection && delete this.transientData[e];
|
378
364
|
}
|
379
365
|
},
|
380
366
|
/**
|
@@ -392,11 +378,11 @@ const Ue = {
|
|
392
378
|
* @param resource The item that has been inserted.
|
393
379
|
* @param TODO
|
394
380
|
*/
|
395
|
-
recordInsertion(e, { insertAtBeginning:
|
381
|
+
recordInsertion(e, { insertAtBeginning: i, transientData: t } = {}) {
|
396
382
|
var l;
|
397
383
|
if (["Loaded", "LoadingMore"].includes(this.status)) {
|
398
384
|
const u = Object.freeze(e);
|
399
|
-
|
385
|
+
i ? this.resources.unshift(u) : this.resources.push(u), (l = r.detail) != null && l.autoFromSingleInsertion && (this.detailSelection.length == 0 || this.detailSelection.length == 1 && v(this.detailSelection[0], this) == null) && (this.detailSelection = [u], this.editingDetailSelection = r.detail.autoEdit);
|
400
386
|
const c = v(e, this);
|
401
387
|
c && (t === void 0 ? delete this.transientData[c] : this.transientData[c] = t);
|
402
388
|
}
|
@@ -416,11 +402,11 @@ const Ue = {
|
|
416
402
|
* @param resource The item that has been updated.
|
417
403
|
*/
|
418
404
|
recordUpdate(e) {
|
419
|
-
const
|
420
|
-
if (
|
405
|
+
const i = v(e, this);
|
406
|
+
if (i && ["Loaded", "LoadingMore"].includes(this.status)) {
|
421
407
|
const t = Object.freeze(e);
|
422
|
-
let l = this.resources.findIndex((u) => v(u, this) ==
|
423
|
-
l >= 0 && (this.resources[l] = t), l = this.selection.findIndex((u) => v(u, this) ==
|
408
|
+
let l = this.resources.findIndex((u) => v(u, this) == i);
|
409
|
+
l >= 0 && (this.resources[l] = t), l = this.selection.findIndex((u) => v(u, this) == i), l >= 0 && (this.selection[l] = t), l = this.detailSelection.findIndex((u) => v(u, this) == i), l >= 0 && (this.detailSelection[l] = t);
|
424
410
|
}
|
425
411
|
},
|
426
412
|
/**
|
@@ -437,12 +423,12 @@ const Ue = {
|
|
437
423
|
*/
|
438
424
|
async refreshResource(e) {
|
439
425
|
if (e) {
|
440
|
-
const
|
441
|
-
this.referencePathsToExpand && (
|
442
|
-
const t =
|
443
|
-
|
426
|
+
const i = {};
|
427
|
+
this.referencePathsToExpand && (i.r = X(this.referencePathsToExpand));
|
428
|
+
const t = a.map(
|
429
|
+
i,
|
444
430
|
(c, d) => c != null ? `${encodeURIComponent(d)}=${encodeURIComponent(c)}` : null
|
445
|
-
).filter((c) => c != null).join("&"), l =
|
431
|
+
).filter((c) => c != null).join("&"), l = a.isEmpty(t) ? `${r.restCollectionUrl}/${e}` : `${r.restCollectionUrl}/${e}?${t}`, u = await L.get(l);
|
446
432
|
if (u.status == 200) {
|
447
433
|
const c = u.data;
|
448
434
|
return this.recordUpdate(c), c;
|
@@ -459,7 +445,7 @@ const Ue = {
|
|
459
445
|
* @param resourceDefaults Initial properties of the new resource.
|
460
446
|
*/
|
461
447
|
addResource(e = {}) {
|
462
|
-
this.detailSelection = [
|
448
|
+
this.detailSelection = [a.omit(a.merge({}, e), this.idProperty)], this.editingDetailSelection = !0;
|
463
449
|
},
|
464
450
|
/**
|
465
451
|
* Delete one resource.
|
@@ -469,9 +455,9 @@ const Ue = {
|
|
469
455
|
* @param resourceId The ID of the resource to delete.
|
470
456
|
*/
|
471
457
|
async deleteResource(e) {
|
472
|
-
if ((await
|
458
|
+
if ((await L.delete(`${r.restCollectionUrl}/${e}`)).status == 200 && ["Loaded", "LoadingMore"].includes(this.status)) {
|
473
459
|
let t = this.resources.findIndex((l) => v(l, this) == e);
|
474
|
-
t >= 0 && this.resources.splice(t, 1), t = this.selection.findIndex((l) => v(l, this) == e), t >= 0 && this.selection.splice(t, 1), t = this.detailSelection.findIndex((l) => v(l, this) == e), t >= 0 && (this.detailSelection.splice(t, 1), this.detailSelection.length == 0 && (this.editingDetailSelection =
|
460
|
+
t >= 0 && this.resources.splice(t, 1), t = this.selection.findIndex((l) => v(l, this) == e), t >= 0 && this.selection.splice(t, 1), t = this.detailSelection.findIndex((l) => v(l, this) == e), t >= 0 && (this.detailSelection.splice(t, 1), this.detailSelection.length == 0 && (this.editingDetailSelection = r.detail.autoEdit)), r.limitTransientDataToLocalCollection && delete this.transientData[e];
|
475
461
|
}
|
476
462
|
},
|
477
463
|
/**
|
@@ -486,9 +472,9 @@ const Ue = {
|
|
486
472
|
* the operation failed.
|
487
473
|
*/
|
488
474
|
async saveResource(e) {
|
489
|
-
const
|
475
|
+
const i = v(e, this), t = i == null, l = await L({
|
490
476
|
method: t ? "post" : "put",
|
491
|
-
url: t ?
|
477
|
+
url: t ? r.restCollectionUrl : `${r.restCollectionUrl}/${i}`,
|
492
478
|
data: e
|
493
479
|
});
|
494
480
|
if (l.status == 200) {
|
@@ -508,39 +494,64 @@ const Ue = {
|
|
508
494
|
* @returns An array of refreshed local resources, one for each remote resource whose save operation succeeded.
|
509
495
|
*/
|
510
496
|
async saveResources(e) {
|
511
|
-
const
|
497
|
+
const i = await L({
|
512
498
|
method: "put",
|
513
|
-
url:
|
499
|
+
url: r.restCollectionUrl,
|
514
500
|
data: e
|
515
501
|
});
|
516
|
-
if (
|
517
|
-
const t =
|
502
|
+
if (i.status == 200) {
|
503
|
+
const t = i.data || [], l = [];
|
518
504
|
for (const [u, c] of t.entries()) {
|
519
|
-
const d = v(e[u], this) == null, m = v(c, this),
|
520
|
-
d && this.recordInsertion(
|
505
|
+
const d = v(e[u], this) == null, m = v(c, this), D = m ? await this.refreshResource(m) : null;
|
506
|
+
d && this.recordInsertion(D || c), l.push(D || Object.freeze(c));
|
521
507
|
}
|
522
508
|
return l;
|
523
509
|
}
|
524
510
|
return [];
|
525
511
|
},
|
526
512
|
/**
|
527
|
-
* Perform an update
|
513
|
+
* Perform an update of a resource of the remote collection, then mirror the changes in the local collection.
|
514
|
+
*
|
515
|
+
* After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the
|
516
|
+
* return value) has the same object-graph characteristics as the rest of the local collection.
|
517
|
+
*
|
518
|
+
* @param partialResource The partial resource to merge.
|
519
|
+
* @returns The refreshed local resource after the change has been persisted to the remote collection, or null if
|
520
|
+
* the operation failed.
|
521
|
+
*/
|
522
|
+
async updateResource(e) {
|
523
|
+
const i = v(e, this);
|
524
|
+
if (!i)
|
525
|
+
throw "To update a REST collection resource, the resource must have an ID.";
|
526
|
+
const t = await L({
|
527
|
+
method: "patch",
|
528
|
+
url: `${r.restCollectionUrl}/${i}`,
|
529
|
+
data: e
|
530
|
+
});
|
531
|
+
if (t.status == 200) {
|
532
|
+
const l = t.data, u = v(l, this);
|
533
|
+
return (u ? await this.refreshResource(u) : null) || l;
|
534
|
+
}
|
535
|
+
return null;
|
536
|
+
},
|
537
|
+
/**
|
538
|
+
* Perform an update of multiple resource of the remote collection, then mirror the changes in the local collection.
|
528
539
|
*
|
529
540
|
* After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the
|
530
541
|
* return value) has the same object-graph characteristics as the rest of the local collection.
|
531
542
|
*
|
532
|
-
* @param
|
543
|
+
* @param partialResources The partial resources to merge.
|
533
544
|
* @returns The refreshed local resource after the change has been persisted to the remote collection, or null if
|
534
545
|
* the operation failed.
|
535
546
|
*/
|
536
547
|
async updateResources(e) {
|
537
|
-
const
|
548
|
+
const i = await L({
|
538
549
|
method: "patch",
|
539
|
-
url:
|
550
|
+
url: `${r.restCollectionUrl}`,
|
540
551
|
data: e
|
541
552
|
});
|
542
|
-
if (
|
543
|
-
const t =
|
553
|
+
if (i.status == 200) {
|
554
|
+
const t = i.data || [], l = [];
|
544
555
|
for (const u of t) {
|
545
556
|
const c = v(u, this), d = c ? await this.refreshResource(c) : null;
|
546
557
|
l.push(d || Object.freeze(u));
|
@@ -564,7 +575,7 @@ const Ue = {
|
|
564
575
|
* @param resourceIds The IDs of all local resources that failed validation.
|
565
576
|
*/
|
566
577
|
setInvalidResourceIds(e) {
|
567
|
-
|
578
|
+
a.isEqual(e, this.invalidResources.map((i) => v(i, this))) || (this.invalidResources = e.map((i) => this.resources.find((t) => v(t, this) == i)).filter((i) => i != null));
|
568
579
|
},
|
569
580
|
/**
|
570
581
|
* Set transient data.
|
@@ -574,8 +585,8 @@ const Ue = {
|
|
574
585
|
* the transient data for each resource ID in the keys of transientData.
|
575
586
|
*/
|
576
587
|
setTransientDataForResources(e) {
|
577
|
-
const { transientData:
|
578
|
-
t ?
|
588
|
+
const { transientData: i, merge: t = !0 } = e;
|
589
|
+
t ? a.merge(this.transientData, i) : a.assign(this.transientData, i);
|
579
590
|
},
|
580
591
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
581
592
|
// Actions: Managing selections
|
@@ -592,8 +603,8 @@ const Ue = {
|
|
592
603
|
* @param resourceIds The IDs of resources to remove from the selection.
|
593
604
|
*/
|
594
605
|
deselectResources(e) {
|
595
|
-
const
|
596
|
-
this.setSelection(
|
606
|
+
const i = this.selection.map((t) => v(t, this)).filter((t) => t != null && !e.includes(t));
|
607
|
+
this.setSelection(i);
|
597
608
|
},
|
598
609
|
/**
|
599
610
|
* Add to or replace the selection.
|
@@ -603,14 +614,14 @@ const Ue = {
|
|
603
614
|
* @param edit If not undefined, sets the editing mode of the new selection. If undefined, the editing mode will
|
604
615
|
* be left as is, or set to true if options.detail.autoEdit is true.
|
605
616
|
*/
|
606
|
-
selectResources(e,
|
607
|
-
const { addToSelection: t, edit: l } =
|
617
|
+
selectResources(e, i) {
|
618
|
+
const { addToSelection: t, edit: l } = i || {}, u = this.selection.map((d) => v(d, this));
|
608
619
|
let c = e;
|
609
620
|
if (t) {
|
610
|
-
const d =
|
621
|
+
const d = a.difference(e, u);
|
611
622
|
d.length > 0 && (c = u.concat(d).filter((m) => m != null));
|
612
623
|
}
|
613
|
-
|
624
|
+
a.isEqual(u, c) || this.setSelection(c, l);
|
614
625
|
},
|
615
626
|
/**
|
616
627
|
* Set a new selection.
|
@@ -619,34 +630,34 @@ const Ue = {
|
|
619
630
|
* @param edit If not undefined, sets the editing mode of the new selection. If undefined, the editing mode will
|
620
631
|
* be left as is, or set to true if options.detail.autoEdit is true.
|
621
632
|
*/
|
622
|
-
setSelection(e,
|
623
|
-
if (!
|
633
|
+
setSelection(e, i) {
|
634
|
+
if (!a.isEqual(e, this.selection.map((t) => v(t, this)))) {
|
624
635
|
let t = !0;
|
625
636
|
if (this.editors.length > 0) {
|
626
|
-
if (
|
637
|
+
if (r.detail.autoFromSingleSelection && this.selection.length == 1)
|
627
638
|
t = !1;
|
628
|
-
else if (
|
639
|
+
else if (r.detail.autoFromMultipleSelection && r.detail.allowMultiple && this.selection.length > 1)
|
629
640
|
t = !1;
|
630
|
-
else if (
|
641
|
+
else if (r.detail.constrainToSelection) {
|
631
642
|
const l = this.selection.map((d) => v(d, this)), c = this.detailSelection.map((d) => v(d, this)).filter((d) => l.includes(d));
|
632
643
|
this.detailSelection.filter((d) => !c.includes(v(d, this))).length > 0 && (t = !1);
|
633
644
|
}
|
634
645
|
}
|
635
646
|
if (!t)
|
636
647
|
return;
|
637
|
-
if (this.selection = e.map((l) => this.resources.find((u) => v(u, this) == l)).filter((l) => l != null),
|
648
|
+
if (this.selection = e.map((l) => this.resources.find((u) => v(u, this) == l)).filter((l) => l != null), r.detail.autoFromSingleSelection && this.selection.length == 1) {
|
638
649
|
const l = this.selection[0];
|
639
650
|
(this.detailSelection.length != 1 || v(this.detailSelection[0], this) != v(l, this)) && (this.detailSelection = [l]);
|
640
|
-
} else if (
|
641
|
-
|
651
|
+
} else if (r.detail.autoFromMultipleSelection && r.detail.allowMultiple && this.selection.length > 1)
|
652
|
+
a.isEqual(
|
642
653
|
this.selection.map((l) => v(l, this)),
|
643
654
|
this.detailSelection.map((l) => v(l, this))
|
644
|
-
) || (this.detailSelection =
|
645
|
-
else if (
|
655
|
+
) || (this.detailSelection = a.clone(this.selection));
|
656
|
+
else if (r.detail.constrainToSelection) {
|
646
657
|
const l = this.selection.map((d) => v(d, this)), u = this.detailSelection.map((d) => v(d, this)), c = u.filter((d) => l.includes(d));
|
647
|
-
|
658
|
+
a.isEqual(c, u) || (this.detailSelection = this.detailSelection.filter((d) => c.includes(v(d, this))));
|
648
659
|
}
|
649
|
-
this.detailSelection.length == 0 ? this.editingDetailSelection = !1 : this.editingDetailSelection =
|
660
|
+
this.detailSelection.length == 0 ? this.editingDetailSelection = !1 : this.editingDetailSelection = i !== void 0 ? i : this.editingDetailSelection || r.detail.autoEdit;
|
650
661
|
}
|
651
662
|
},
|
652
663
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -670,9 +681,9 @@ const Ue = {
|
|
670
681
|
* or set to true if options.detail.autoEdit is true.
|
671
682
|
*/
|
672
683
|
showSelectionAsDetail(e) {
|
673
|
-
if (this.selection.length <= 1 ||
|
674
|
-
const
|
675
|
-
|
684
|
+
if (this.selection.length <= 1 || r.detail.allowMultiple) {
|
685
|
+
const i = this.selection.map((l) => v(l, this)), t = this.detailSelection.map((l) => v(l, this));
|
686
|
+
a.isEqual(i, t) || (this.detailSelection = a.clone(this.selection)), this.detailSelection.length == 0 ? this.editingDetailSelection = !1 : this.editingDetailSelection = e !== void 0 ? e : this.editingDetailSelection || r.detail.autoEdit;
|
676
687
|
}
|
677
688
|
},
|
678
689
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -684,7 +695,7 @@ const Ue = {
|
|
684
695
|
* @param editor The editor to deregister.
|
685
696
|
*/
|
686
697
|
deregisterEditor(e) {
|
687
|
-
|
698
|
+
a.remove(this.editors, (i) => i == e);
|
688
699
|
},
|
689
700
|
/**
|
690
701
|
* Register an editor.
|
@@ -704,8 +715,8 @@ const Ue = {
|
|
704
715
|
* @param listNavigator The list navigator. If defined, the named list navigator will only be deleted if it equals
|
705
716
|
* this parameter.
|
706
717
|
*/
|
707
|
-
deregisterListNavigator({ name: e, listNavigator:
|
708
|
-
(
|
718
|
+
deregisterListNavigator({ name: e, listNavigator: i }) {
|
719
|
+
(i == null || this.listNavigators[e] == i) && delete this.listNavigators[e];
|
709
720
|
},
|
710
721
|
/**
|
711
722
|
* Register a list navigator.
|
@@ -719,162 +730,162 @@ const Ue = {
|
|
719
730
|
* @param name The name under which to register the list navigator.
|
720
731
|
* @param listNavigator The list navigator.
|
721
732
|
*/
|
722
|
-
registerListNavigator({ name: e, listNavigator:
|
723
|
-
this.listNavigators[e] !=
|
733
|
+
registerListNavigator({ name: e, listNavigator: i }) {
|
734
|
+
this.listNavigators[e] != i && (this.listNavigators[e] = i);
|
724
735
|
}
|
725
736
|
}
|
726
737
|
});
|
727
738
|
return (() => {
|
728
|
-
const e = (
|
729
|
-
const l =
|
739
|
+
const e = (i, t) => {
|
740
|
+
const l = R(i, t);
|
730
741
|
return ie.registerStore(l.$id, l), l;
|
731
742
|
};
|
732
|
-
return e.$id =
|
743
|
+
return e.$id = R.$id, e;
|
733
744
|
})();
|
734
745
|
}, ie = new Ie(), Qe = (h = {}) => {
|
735
746
|
var ue, de, he, fe;
|
736
747
|
const {
|
737
|
-
collectionId:
|
738
|
-
draftBatchId:
|
739
|
-
enabled:
|
748
|
+
collectionId: r,
|
749
|
+
draftBatchId: R,
|
750
|
+
enabled: w,
|
740
751
|
resourceType: e,
|
741
|
-
options:
|
742
|
-
} = h, t = I(void 0), l = I(
|
752
|
+
options: i
|
753
|
+
} = h, t = I(void 0), l = I(r), u = I(R), c = I(w ?? !0), d = I([se(e)]), m = I(i), D = g(() => u.value), x = I(c.value), A = I(H()), N = I((de = (ue = m.value) == null ? void 0 : ue.filter) == null ? void 0 : de.resourceIds), O = I((fe = (he = m.value) == null ? void 0 : he.filter) == null ? void 0 : fe.query), k = g(
|
743
754
|
() => u.value == null && l.value != null && ie.getStore(l.value) != null
|
744
|
-
),
|
755
|
+
), P = I(k.value), y = g(() => E("status", "Uninitialized"));
|
745
756
|
function S(s) {
|
746
757
|
if (t.value)
|
747
758
|
return s(t.value);
|
748
759
|
}
|
749
|
-
async function
|
760
|
+
async function T(s) {
|
750
761
|
if (t.value)
|
751
762
|
return await s(t.value);
|
752
763
|
}
|
753
|
-
function
|
764
|
+
function E(s, o) {
|
754
765
|
if (t.value)
|
755
766
|
return t.value[s];
|
756
|
-
if (
|
757
|
-
return
|
767
|
+
if (o !== void 0)
|
768
|
+
return o;
|
758
769
|
throw "Attempted to use a REST collection store that has not been created, with no default value.";
|
759
770
|
}
|
760
|
-
const
|
761
|
-
var te, ve,
|
771
|
+
const U = (s = {}) => {
|
772
|
+
var te, ve, Re, ge;
|
762
773
|
const {
|
763
|
-
collectionId:
|
764
|
-
draftBatchId:
|
774
|
+
collectionId: o,
|
775
|
+
draftBatchId: C,
|
765
776
|
enabled: F,
|
766
777
|
resourceType: le,
|
767
778
|
options: ee
|
768
779
|
} = s;
|
769
|
-
l.value =
|
780
|
+
l.value = o, u.value = C, c.value = F ?? !0, d.value = [se(le)], ee != null && (m.value = ee, N.value = (ve = (te = m.value) == null ? void 0 : te.filter) == null ? void 0 : ve.resourceIds, O.value = (ge = (Re = m.value) == null ? void 0 : Re.filter) == null ? void 0 : ge.query), A.value = H(), W(c.value);
|
770
781
|
}, W = async (s) => {
|
771
|
-
s !=
|
782
|
+
s != x.value && (x.value = s, s && (K(), z()));
|
772
783
|
}, re = async (s) => {
|
773
|
-
N.value = s, await
|
784
|
+
N.value = s, await T(async (o) => await o.setFilterResourceIds(N.value || null));
|
774
785
|
}, J = async (s) => {
|
775
|
-
if (
|
776
|
-
const
|
777
|
-
await
|
786
|
+
if (O.value = s, y.value != "Uninitialized") {
|
787
|
+
const o = s, C = g(() => a.isFunction(o) ? p.value ? o(p.value) : null : o);
|
788
|
+
await T((F) => F.setQuery(C.value || null));
|
778
789
|
}
|
779
790
|
}, K = () => {
|
780
|
-
m.value =
|
781
|
-
filter: { resourceIds: N.value, query:
|
791
|
+
m.value = a.merge({}, m.value || {}, {
|
792
|
+
filter: { resourceIds: N.value, query: O.value }
|
782
793
|
});
|
783
|
-
}, p =
|
794
|
+
}, p = g(
|
784
795
|
() => d.value[0].value || void 0
|
785
796
|
), B = function(s) {
|
786
|
-
const
|
797
|
+
const o = a.get(s, "filter.query"), C = a.get(s, "propertiesToExclude"), F = a.get(s, "referencePathsToExpand"), le = a.isFunction(o) ? o(p.value) : o, ee = p.value ? a.isFunction(C) ? C(p.value) : C || [] : [], te = p.value ? a.isFunction(F) ? F(p.value) : F || [] : [];
|
787
798
|
return {
|
788
|
-
...
|
799
|
+
...a.cloneDeep(s || {}),
|
789
800
|
filter: {
|
790
|
-
...
|
801
|
+
...a.cloneDeep((s == null ? void 0 : s.filter) || {}),
|
791
802
|
query: le
|
792
803
|
},
|
793
804
|
propertiesToExclude: ee,
|
794
805
|
referencePathsToExpand: te
|
795
806
|
};
|
796
|
-
}, q =
|
807
|
+
}, q = g(() => B(m.value)), j = g(() => {
|
797
808
|
if (q.value.restCollectionUrl !== void 0)
|
798
809
|
return q.value.restCollectionUrl;
|
799
|
-
if (!
|
800
|
-
return !p.value || !p.value.collectionName ? null :
|
801
|
-
}),
|
810
|
+
if (!P.value)
|
811
|
+
return !p.value || !p.value.collectionName ? null : D.value ? `${V.config.apiBaseUrl}/draft-batches/${D.value}/${p.value.collectionName}` : `${V.config.apiBaseUrl}/${p.value.collectionName}`;
|
812
|
+
}), n = g(() => {
|
802
813
|
var s;
|
803
814
|
if (p.value)
|
804
|
-
return
|
805
|
-
|
815
|
+
return a.mergeWith(
|
816
|
+
a.cloneDeep(we),
|
806
817
|
q.value,
|
807
818
|
{
|
808
819
|
idProperty: (s = p.value) == null ? void 0 : s.idProperty,
|
809
820
|
restCollectionUrl: j.value || ""
|
810
821
|
},
|
811
|
-
(
|
812
|
-
if (
|
813
|
-
return
|
822
|
+
(o, C) => {
|
823
|
+
if (a.isArray(C) && C.length == 0 && (o == null || a.isArray(o)))
|
824
|
+
return C;
|
814
825
|
}
|
815
826
|
);
|
816
|
-
}), f = I(0), b =
|
827
|
+
}), f = I(0), b = g(
|
817
828
|
() => {
|
818
829
|
var s;
|
819
|
-
return f.value, l.value || p.value && ((s = p.value) == null ? void 0 : s.collectionName) && (
|
830
|
+
return f.value, l.value || p.value && ((s = p.value) == null ? void 0 : s.collectionName) && (D.value ? `draftBatches/${D.value}/${p.value.collectionName}/${A.value}` : `${p.value.collectionName}/${A.value}`) || null;
|
820
831
|
}
|
821
832
|
), z = () => {
|
822
|
-
if (
|
833
|
+
if (x.value) {
|
823
834
|
let s = !1;
|
824
|
-
return p.value && b.value && (t.value = ie.getStore(b.value), t.value ? s = !1 :
|
835
|
+
return p.value && b.value && (t.value = ie.getStore(b.value), t.value ? s = !1 : n.value && (P.value = !1, t.value = Pe(b.value, n.value)(), s = !0)), s;
|
825
836
|
} else
|
826
837
|
return !1;
|
827
838
|
}, G = () => {
|
828
839
|
b.value && l.value == b.value ? (t.value = void 0, z()) : (t.value = void 0, f.value = f.value + 1, z());
|
829
840
|
};
|
830
|
-
$(
|
831
|
-
|
832
|
-
}), $(
|
833
|
-
s !=
|
834
|
-
}), $(p, (s,
|
835
|
-
s && !
|
836
|
-
}), $(
|
837
|
-
|
841
|
+
$(D, (s, o) => {
|
842
|
+
a.isEqual(s, o) || G();
|
843
|
+
}), $(x, (s, o) => {
|
844
|
+
s != o && (s ? z() : t.value = void 0);
|
845
|
+
}), $(p, (s, o) => {
|
846
|
+
s && !o ? z() : !s && o || a.isEqual(s, o) || G();
|
847
|
+
}), $(n, (s, o) => {
|
848
|
+
a.isEqual(s, o) || G();
|
838
849
|
}), $(k, () => {
|
839
|
-
k.value || (
|
840
|
-
}), $(b, () => z()), $(j, (s,
|
841
|
-
|
850
|
+
k.value || (P.value = !1);
|
851
|
+
}), $(b, () => z()), $(j, (s, o) => {
|
852
|
+
a.isEqual(s, o) || G();
|
842
853
|
});
|
843
|
-
const M = [],
|
854
|
+
const M = [], De = function(s) {
|
844
855
|
y.value != "Uninitialized" ? Le(s) : M.push(s);
|
845
856
|
};
|
846
|
-
return $(y, (s,
|
847
|
-
if (s != "Uninitialized" &&
|
848
|
-
const
|
857
|
+
return $(y, (s, o) => {
|
858
|
+
if (s != "Uninitialized" && o == "Uninitialized") {
|
859
|
+
const C = a.clone(M);
|
849
860
|
M.splice(0, M.length);
|
850
|
-
for (const F of
|
861
|
+
for (const F of C)
|
851
862
|
F();
|
852
863
|
}
|
853
864
|
}), z(), {
|
854
865
|
// Configuration
|
855
866
|
collectionId: b,
|
856
|
-
draftBatchId:
|
867
|
+
draftBatchId: D,
|
857
868
|
resourceType: p,
|
858
|
-
restCollectionUrl:
|
869
|
+
restCollectionUrl: g(() => E("restCollectionUrl", null)),
|
859
870
|
// Status
|
860
|
-
enabled:
|
871
|
+
enabled: x,
|
861
872
|
status: y,
|
862
|
-
batchSaveAttempted:
|
863
|
-
listNavigators:
|
873
|
+
batchSaveAttempted: g(() => E("batchSaveAttempted", !1)),
|
874
|
+
listNavigators: g(() => E("listNavigators", !1)),
|
864
875
|
// Resources loaded from the REST API
|
865
|
-
invalidResources:
|
866
|
-
resources:
|
867
|
-
remoteCollectionSize:
|
876
|
+
invalidResources: g(() => E("invalidResources", [])),
|
877
|
+
resources: g(() => y.value != "Uninitialized" ? (T((s) => s.ensureCollectionLoaded()), E("resources", [])) : []),
|
878
|
+
remoteCollectionSize: g(() => E("remoteCollectionSize", null)),
|
868
879
|
// Transient data
|
869
|
-
transientData:
|
880
|
+
transientData: g(() => E("transientData", [])),
|
870
881
|
// Selection and detail selection
|
871
|
-
detailSelection:
|
872
|
-
editingDetailSelection:
|
873
|
-
selection:
|
882
|
+
detailSelection: g(() => E("detailSelection", [])),
|
883
|
+
editingDetailSelection: g(() => E("editingDetailSelection", !1)),
|
884
|
+
selection: g(() => E("selection", [])),
|
874
885
|
// Methods: Configuration
|
875
|
-
reconfigureCollection:
|
886
|
+
reconfigureCollection: U,
|
876
887
|
setEditingDetailSelection: (s) => S(
|
877
|
-
(
|
888
|
+
(o) => o.setEditingDetailSelection(s)
|
878
889
|
),
|
879
890
|
setEnabled: W,
|
880
891
|
setFilterResourceIds: re,
|
@@ -882,77 +893,78 @@ const Ue = {
|
|
882
893
|
// Methods: Status
|
883
894
|
ensureStore: z,
|
884
895
|
// TODO Rename
|
885
|
-
setBatchSaveAttempted: (s) => S((
|
896
|
+
setBatchSaveAttempted: (s) => S((o) => o.setBatchSaveAttempted(s)),
|
886
897
|
// Local collection management
|
887
898
|
clear: () => S((s) => s.clear()),
|
888
|
-
ensureCollectionLoaded: async () => await
|
889
|
-
loadResources: async () => await
|
899
|
+
ensureCollectionLoaded: async () => await T(async (s) => s.ensureCollectionLoaded()),
|
900
|
+
loadResources: async () => await T(async (s) => await s.loadResources()),
|
890
901
|
// Methods: Recording changes to the collection
|
891
|
-
addResource: (s) => S((
|
892
|
-
checkForDeletedResource: async (s) => await
|
893
|
-
recordDeletion: (s) => S((
|
894
|
-
recordInsertion: (s, { insertAtBeginning:
|
895
|
-
recordUpdate: (s) => S((
|
896
|
-
refreshResource: async (s) => await
|
897
|
-
async (
|
902
|
+
addResource: (s) => S((o) => o.addResource(s)),
|
903
|
+
checkForDeletedResource: async (s) => await T(async (o) => await o.checkForDeletedResource(s)) == !0,
|
904
|
+
recordDeletion: (s) => S((o) => o.recordDeletion(s)),
|
905
|
+
recordInsertion: (s, { insertAtBeginning: o = !1, transientData: C = void 0 } = {}) => S((F) => F.recordInsertion(s, { insertAtBeginning: o, transientData: C })),
|
906
|
+
recordUpdate: (s) => S((o) => o.recordUpdate(s)),
|
907
|
+
refreshResource: async (s) => await T(
|
908
|
+
async (o) => await o.refreshResource(s)
|
898
909
|
),
|
899
910
|
// Methods: Modifying the collection
|
900
|
-
deleteResource: async (s) => await
|
901
|
-
async (
|
911
|
+
deleteResource: async (s) => await T(
|
912
|
+
async (o) => await o.deleteResource(s)
|
902
913
|
),
|
903
|
-
saveResource: async (s) => await
|
904
|
-
saveResources: async (s) => await
|
905
|
-
|
914
|
+
saveResource: async (s) => await T(async (o) => await o.saveResource(s)),
|
915
|
+
saveResources: async (s) => await T(async (o) => await o.saveResources(s)),
|
916
|
+
updateResource: async (s) => await T(async (o) => await o.updateResource(s)),
|
917
|
+
updateResources: async (s) => await T(async (o) => await o.updateResources(s)),
|
906
918
|
// Methods: Transient data
|
907
919
|
clearTransientData: () => S((s) => s.clearTransientData()),
|
908
|
-
setInvalidResourceIds: (s) => S((
|
920
|
+
setInvalidResourceIds: (s) => S((o) => o.setInvalidResourceIds(s)),
|
909
921
|
setTransientDataForResources: (s) => S(
|
910
|
-
(
|
922
|
+
(o) => o.setTransientDataForResources(s)
|
911
923
|
),
|
912
924
|
// Methods: Selection and detail selection
|
913
925
|
clearSelection: () => S((s) => s.clearSelection()),
|
914
|
-
deselectResources: (s) => S((
|
915
|
-
selectResources: (s,
|
916
|
-
(
|
926
|
+
deselectResources: (s) => S((o) => o.deselectResources(s)),
|
927
|
+
selectResources: (s, o) => S(
|
928
|
+
(C) => C.selectResources(s, o)
|
917
929
|
),
|
918
930
|
// Methods: Managing the detail view
|
919
931
|
hideDetail: () => S((s) => s.hideDetail()),
|
920
932
|
// Methods: Editors
|
921
|
-
deregisterEditor: (s) => S((
|
922
|
-
registerEditor: (s) => S((
|
933
|
+
deregisterEditor: (s) => S((o) => o.deregisterEditor(s)),
|
934
|
+
registerEditor: (s) => S((o) => o.registerEditor(s)),
|
923
935
|
// Methods: List navigators
|
924
|
-
deregisterListNavigator: (s) => S((
|
925
|
-
registerListNavigator: (s) => S((
|
936
|
+
deregisterListNavigator: (s) => S((o) => o.deregisterListNavigator(s)),
|
937
|
+
registerListNavigator: (s) => S((o) => o.registerListNavigator(s)),
|
926
938
|
// Callbacks
|
927
|
-
onItemsStoreReady:
|
939
|
+
onItemsStoreReady: De
|
928
940
|
};
|
929
941
|
}, je = () => {
|
930
942
|
ie.clearAllStores();
|
931
943
|
};
|
932
|
-
function ne(h,
|
933
|
-
return
|
944
|
+
function ne(h, r) {
|
945
|
+
return a.get(h, (r == null ? void 0 : r.idProperty) || "_id");
|
934
946
|
}
|
935
|
-
const
|
947
|
+
const Ue = {
|
936
948
|
idProperty: "_id"
|
937
949
|
}, Z = {
|
938
950
|
resource: null,
|
939
951
|
status: "NotLoaded"
|
940
|
-
}, qe = (h,
|
941
|
-
|
942
|
-
const
|
952
|
+
}, qe = (h, r) => {
|
953
|
+
r = a.merge({}, Ue, r);
|
954
|
+
const R = me(h, {
|
943
955
|
state: () => ({
|
944
|
-
idProperty:
|
945
|
-
resourceId:
|
946
|
-
resourceUrl:
|
947
|
-
referencePathsToExpand:
|
956
|
+
idProperty: r.idProperty,
|
957
|
+
resourceId: r.resourceId || null,
|
958
|
+
resourceUrl: r.resourceUrl || null,
|
959
|
+
referencePathsToExpand: r.referencePathsToExpand || null,
|
948
960
|
...Z
|
949
961
|
}),
|
950
962
|
getters: {
|
951
|
-
currentResourceUrl: (e) => e.resourceUrl || (
|
963
|
+
currentResourceUrl: (e) => e.resourceUrl || (r.restCollectionUrl && e.resourceId ? `${r.restCollectionUrl}/${e.resourceId}` : null) || r.restCollectionUrl || null,
|
952
964
|
/** Get the REST query parameters that can be determined from the options. */
|
953
965
|
fixedQueryParams: (e) => {
|
954
|
-
const
|
955
|
-
return e.referencePathsToExpand && (
|
966
|
+
const i = {};
|
967
|
+
return e.referencePathsToExpand && (i.r = X(e.referencePathsToExpand)), i;
|
956
968
|
}
|
957
969
|
},
|
958
970
|
actions: {
|
@@ -969,12 +981,12 @@ const De = {
|
|
969
981
|
this[e] = Z[e];
|
970
982
|
},
|
971
983
|
async setResourceId(e) {
|
972
|
-
const
|
973
|
-
this.resourceId = e, !
|
984
|
+
const i = this.currentResourceUrl;
|
985
|
+
this.resourceId = e, !a.isEqual(this.currentResourceUrl, i) && this.status != "NotLoaded" && await this.loadResource();
|
974
986
|
},
|
975
987
|
async setResourceUrl(e) {
|
976
|
-
const
|
977
|
-
this.resourceUrl = e, !
|
988
|
+
const i = this.currentResourceUrl;
|
989
|
+
this.resourceUrl = e, !a.isEqual(this.currentResourceUrl, i) && this.status != "NotLoaded" && await this.loadResource();
|
978
990
|
},
|
979
991
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
980
992
|
// Actions: Loading and unloading the collection
|
@@ -1006,13 +1018,13 @@ const De = {
|
|
1006
1018
|
const e = H();
|
1007
1019
|
if (this._loadId = e, this.currentResourceUrl) {
|
1008
1020
|
this.status = "Loading";
|
1009
|
-
const
|
1021
|
+
const i = this.fixedQueryParams, t = a.cloneDeep(i), l = a.map(
|
1010
1022
|
t,
|
1011
1023
|
(c, d) => c != null ? `${encodeURIComponent(d)}=${encodeURIComponent(c)}` : null
|
1012
|
-
).filter((c) => c != null).join("&"), u =
|
1024
|
+
).filter((c) => c != null).join("&"), u = a.isEmpty(l) ? this.currentResourceUrl : `${this.currentResourceUrl}?${l}`;
|
1013
1025
|
try {
|
1014
|
-
const c = await
|
1015
|
-
e != this._loadId || !
|
1026
|
+
const c = await L.get(u), d = this.fixedQueryParams;
|
1027
|
+
e != this._loadId || !a.isEqual(i, d) ? console.log(`Discarding resource fetched by obsolete query from ${u}.`) : (this.resource = pe.decode(a.get(c, "data", {})), this.status = "Loaded");
|
1016
1028
|
} catch (c) {
|
1017
1029
|
console.log(`Error while loading resource (URL="${u}")`, c), this.reset(), this.status = "Failed";
|
1018
1030
|
}
|
@@ -1034,9 +1046,9 @@ const De = {
|
|
1034
1046
|
if (this.currentResourceUrl) {
|
1035
1047
|
let e;
|
1036
1048
|
try {
|
1037
|
-
e = await
|
1038
|
-
} catch (
|
1039
|
-
|
1049
|
+
e = await L.get(this.currentResourceUrl);
|
1050
|
+
} catch (i) {
|
1051
|
+
L.isAxiosError(i) && (e = i.response);
|
1040
1052
|
}
|
1041
1053
|
return e && e.status == 404 ? (this.recordDeletion(), !0) : !1;
|
1042
1054
|
} else
|
@@ -1107,7 +1119,7 @@ const De = {
|
|
1107
1119
|
*/
|
1108
1120
|
async deleteResource() {
|
1109
1121
|
if (this.currentResourceUrl)
|
1110
|
-
(await
|
1122
|
+
(await L.delete(this.currentResourceUrl)).status == 200 && this.recordDeletion();
|
1111
1123
|
else
|
1112
1124
|
throw "Cannot delete a resource because its URL, or its ID and collection URL, are unknown.";
|
1113
1125
|
},
|
@@ -1123,12 +1135,12 @@ const De = {
|
|
1123
1135
|
* the operation failed.
|
1124
1136
|
*/
|
1125
1137
|
async saveResource(e) {
|
1126
|
-
const
|
1127
|
-
if (!
|
1138
|
+
const i = ne(e, this), t = i == null;
|
1139
|
+
if (!i)
|
1128
1140
|
throw "The REST resource store cannot create new resources on the server.";
|
1129
1141
|
if (!this.currentResourceUrl)
|
1130
1142
|
throw "Cannot save a resource because its URL, or its ID and collection URL, are unknown.";
|
1131
|
-
const l = await
|
1143
|
+
const l = await L({
|
1132
1144
|
method: t ? "post" : "put",
|
1133
1145
|
url: this.currentResourceUrl,
|
1134
1146
|
data: e
|
@@ -1140,25 +1152,25 @@ const De = {
|
|
1140
1152
|
return null;
|
1141
1153
|
},
|
1142
1154
|
/**
|
1143
|
-
*
|
1155
|
+
* Update only the specified properties of the remote resource, then mirror the change locally.
|
1144
1156
|
*
|
1145
1157
|
* After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the
|
1146
1158
|
* return value) has the same object-graph characteristics as the rest of the local collection.
|
1147
1159
|
*
|
1148
|
-
* @param
|
1160
|
+
* @param partialResource The partial resource to merge.
|
1149
1161
|
* @returns The refreshed local resource after the change has been persisted to the remote collection, or null if
|
1150
1162
|
* the operation failed.
|
1151
1163
|
*/
|
1152
1164
|
async updateResource(e) {
|
1153
1165
|
if (!this.currentResourceUrl)
|
1154
1166
|
throw "Cannot save a resource because its URL, or its ID and collection URL, are unknown.";
|
1155
|
-
const
|
1167
|
+
const i = await L({
|
1156
1168
|
method: "patch",
|
1157
1169
|
url: this.currentResourceUrl,
|
1158
1170
|
data: e
|
1159
1171
|
});
|
1160
|
-
if (
|
1161
|
-
const t =
|
1172
|
+
if (i.status == 200) {
|
1173
|
+
const t = i.data;
|
1162
1174
|
return await this.refreshResource() || Object.freeze(t);
|
1163
1175
|
}
|
1164
1176
|
return null;
|
@@ -1167,15 +1179,15 @@ const De = {
|
|
1167
1179
|
// Actions: Custom API endpoints
|
1168
1180
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
1169
1181
|
async makeCustomApiRequest(e) {
|
1170
|
-
const { method:
|
1182
|
+
const { method: i, subpath: t, url: l, data: u } = e;
|
1171
1183
|
let c = l;
|
1172
1184
|
if (!c)
|
1173
1185
|
if (this.currentResourceUrl)
|
1174
1186
|
c = `${this.currentResourceUrl}/${t}`;
|
1175
1187
|
else
|
1176
1188
|
throw "Cannot make a custom API request for a resource because its URL, or its ID and collection URL, are unknown.";
|
1177
|
-
const d = await
|
1178
|
-
method:
|
1189
|
+
const d = await L({
|
1190
|
+
method: i || "get",
|
1179
1191
|
url: c,
|
1180
1192
|
data: u
|
1181
1193
|
});
|
@@ -1184,144 +1196,144 @@ const De = {
|
|
1184
1196
|
}
|
1185
1197
|
});
|
1186
1198
|
return (() => {
|
1187
|
-
const e = (
|
1188
|
-
const l =
|
1199
|
+
const e = (i, t) => {
|
1200
|
+
const l = R(i, t);
|
1189
1201
|
return ce.registerStore(l.$id, l), l;
|
1190
1202
|
};
|
1191
|
-
return e.$id =
|
1203
|
+
return e.$id = R.$id, e;
|
1192
1204
|
})();
|
1193
1205
|
}, ce = new Ie(), Me = (h = {}) => {
|
1194
1206
|
const {
|
1195
|
-
resourceClientId:
|
1196
|
-
draftBatchId:
|
1197
|
-
enabled:
|
1207
|
+
resourceClientId: r,
|
1208
|
+
draftBatchId: R,
|
1209
|
+
enabled: w,
|
1198
1210
|
resourceType: e,
|
1199
|
-
options:
|
1200
|
-
} = h, t = I(void 0), l = I(
|
1211
|
+
options: i
|
1212
|
+
} = h, t = I(void 0), l = I(r), u = I(R), c = I(w ?? !0), d = I([se(e)]), m = I(i), D = g(() => u.value), x = I(c.value), A = I(H()), N = g(
|
1201
1213
|
() => u.value == null && l.value != null && ce.getStore(l.value) != null
|
1202
|
-
),
|
1203
|
-
function
|
1214
|
+
), O = I(N.value), k = g(() => S("status", "Uninitialized"));
|
1215
|
+
function P(n) {
|
1204
1216
|
if (t.value)
|
1205
|
-
return
|
1217
|
+
return n(t.value);
|
1206
1218
|
}
|
1207
|
-
async function y(
|
1219
|
+
async function y(n) {
|
1208
1220
|
if (t.value)
|
1209
|
-
return await
|
1221
|
+
return await n(t.value);
|
1210
1222
|
}
|
1211
|
-
function S(
|
1223
|
+
function S(n, f) {
|
1212
1224
|
if (t.value)
|
1213
|
-
return t.value[
|
1225
|
+
return t.value[n];
|
1214
1226
|
if (f !== void 0)
|
1215
1227
|
return f;
|
1216
1228
|
throw "Attempted to use a REST resource store that has not been created, with no default value.";
|
1217
1229
|
}
|
1218
|
-
const
|
1230
|
+
const T = (n = {}) => {
|
1219
1231
|
const {
|
1220
1232
|
resourceClientId: f,
|
1221
1233
|
draftBatchId: b,
|
1222
1234
|
enabled: z,
|
1223
1235
|
resourceType: G,
|
1224
1236
|
options: M
|
1225
|
-
} =
|
1226
|
-
l.value = f, u.value = b, c.value = z ?? !0, d.value = [se(G)], M != null && (m.value = M), A.value = H(),
|
1227
|
-
},
|
1228
|
-
|
1229
|
-
},
|
1237
|
+
} = n;
|
1238
|
+
l.value = f, u.value = b, c.value = z ?? !0, d.value = [se(G)], M != null && (m.value = M), A.value = H(), E(c.value);
|
1239
|
+
}, E = async (n) => {
|
1240
|
+
n != x.value && (x.value = n, n && q());
|
1241
|
+
}, U = g(
|
1230
1242
|
() => d.value[0].value || void 0
|
1231
|
-
), W = function(
|
1232
|
-
const f =
|
1243
|
+
), W = function(n) {
|
1244
|
+
const f = a.get(n, "referencePathsToExpand"), b = U.value ? a.isFunction(f) ? f(U.value) : f || [] : [];
|
1233
1245
|
return {
|
1234
|
-
...
|
1246
|
+
...a.cloneDeep(n || {}),
|
1235
1247
|
referencePathsToExpand: b
|
1236
1248
|
};
|
1237
|
-
}, re =
|
1238
|
-
if (!
|
1249
|
+
}, re = g(() => W(m.value)), J = g(() => {
|
1250
|
+
if (!U.value)
|
1239
1251
|
return null;
|
1240
|
-
if (!
|
1241
|
-
return !
|
1242
|
-
}), K =
|
1243
|
-
if (
|
1244
|
-
return
|
1245
|
-
|
1252
|
+
if (!O.value)
|
1253
|
+
return !U.value || !U.value.collectionName ? null : D.value ? `${V.config.apiBaseUrl}/draft-batches/${D.value}/${U.value.collectionName}` : `${V.config.apiBaseUrl}/${U.value.collectionName}`;
|
1254
|
+
}), K = g(() => {
|
1255
|
+
if (U.value && J.value)
|
1256
|
+
return a.mergeWith(
|
1257
|
+
a.cloneDeep(Ue),
|
1246
1258
|
re.value,
|
1247
1259
|
{
|
1248
|
-
idProperty:
|
1260
|
+
idProperty: U.value.idProperty,
|
1249
1261
|
restCollectionUrl: J.value
|
1250
1262
|
},
|
1251
|
-
(
|
1252
|
-
if (
|
1263
|
+
(n, f) => {
|
1264
|
+
if (a.isArray(f) && f.length == 0 && (n == null || a.isArray(n)))
|
1253
1265
|
return f;
|
1254
1266
|
}
|
1255
1267
|
);
|
1256
|
-
}), p = I(0), B =
|
1268
|
+
}), p = I(0), B = g(
|
1257
1269
|
() => {
|
1258
|
-
var
|
1259
|
-
return p.value, l.value ||
|
1270
|
+
var n;
|
1271
|
+
return p.value, l.value || U.value && ((n = U.value) == null ? void 0 : n.collectionName) && (D.value ? `draftBatches/${D.value}/${U.value.collectionName}/${A.value}` : `${U.value.collectionName}/${A.value}`) || null;
|
1260
1272
|
}
|
1261
1273
|
), q = () => {
|
1262
|
-
if (
|
1263
|
-
let
|
1264
|
-
return
|
1274
|
+
if (x.value) {
|
1275
|
+
let n = !1;
|
1276
|
+
return U.value && B.value && (t.value = ce.getStore(B.value), t.value ? n = !1 : K.value && (O.value = !1, t.value = qe(B.value, K.value)(), n = !0)), n;
|
1265
1277
|
} else
|
1266
1278
|
return !1;
|
1267
1279
|
}, j = () => {
|
1268
1280
|
B.value && l.value == B.value ? (t.value = void 0, q()) : (t.value = void 0, p.value = p.value + 1, q());
|
1269
1281
|
};
|
1270
|
-
return $(
|
1271
|
-
|
1272
|
-
}), $(
|
1273
|
-
|
1274
|
-
}), $(
|
1275
|
-
|
1276
|
-
}), $(K, (
|
1277
|
-
|
1282
|
+
return $(D, (n, f) => {
|
1283
|
+
a.isEqual(n, f) || j();
|
1284
|
+
}), $(x, (n, f) => {
|
1285
|
+
n != f && (n ? q() : t.value = void 0);
|
1286
|
+
}), $(U, (n, f) => {
|
1287
|
+
n && !f ? q() : !n && f || a.isEqual(n, f) || j();
|
1288
|
+
}), $(K, (n, f) => {
|
1289
|
+
a.isEqual(n, f) || j();
|
1278
1290
|
}), $(N, () => {
|
1279
|
-
N.value || (
|
1280
|
-
}), $(B, () => q()), $(J, (
|
1281
|
-
|
1291
|
+
N.value || (O.value = !1);
|
1292
|
+
}), $(B, () => q()), $(J, (n, f) => {
|
1293
|
+
a.isEqual(n, f) || j();
|
1282
1294
|
}), q(), {
|
1283
1295
|
// Configuration
|
1284
1296
|
resourceClientId: B,
|
1285
|
-
draftBatchId:
|
1286
|
-
enabled:
|
1287
|
-
resourceType:
|
1297
|
+
draftBatchId: D,
|
1298
|
+
enabled: x,
|
1299
|
+
resourceType: U,
|
1288
1300
|
// Status
|
1289
1301
|
status: k,
|
1290
1302
|
// Resources loaded from the REST API
|
1291
|
-
resource:
|
1292
|
-
resourceId:
|
1293
|
-
resourceUrl:
|
1303
|
+
resource: g(() => k.value != "Uninitialized" ? (y((n) => n.ensureResourceLoaded()), S("resource", [])) : []),
|
1304
|
+
resourceId: g(() => S("resourceId", null)),
|
1305
|
+
resourceUrl: g(() => S("resourceUrl", null)),
|
1294
1306
|
// Methods: Configuration
|
1295
|
-
reconfigureClient:
|
1296
|
-
setEnabled:
|
1297
|
-
setResourceId: async (
|
1298
|
-
setResourceUrl: async (
|
1307
|
+
reconfigureClient: T,
|
1308
|
+
setEnabled: E,
|
1309
|
+
setResourceId: async (n) => await y(async (f) => await f.setResourceId(n)),
|
1310
|
+
setResourceUrl: async (n) => await y(async (f) => await f.setResourceUrl(n)),
|
1299
1311
|
// Methods: Status
|
1300
1312
|
ensureStore: q,
|
1301
1313
|
// Methods: Resource management
|
1302
|
-
clear: () =>
|
1303
|
-
ensureResourceLoaded: async () => await y(async (
|
1304
|
-
loadResource: async () => await y(async (
|
1314
|
+
clear: () => P((n) => n.clear()),
|
1315
|
+
ensureResourceLoaded: async () => await y(async (n) => n.ensureResourceLoaded()),
|
1316
|
+
loadResource: async () => await y(async (n) => await n.loadResource()),
|
1305
1317
|
// Methods: Recording changes to the resource
|
1306
|
-
checkForDeletedResource: async () => await y(async (
|
1307
|
-
recordDeletion: () => y((
|
1308
|
-
recordInsertion: (
|
1309
|
-
recordUpdate: (
|
1310
|
-
refreshResource: async () => await y(async (
|
1318
|
+
checkForDeletedResource: async () => await y(async (n) => await n.checkForDeletedResource()) == !0,
|
1319
|
+
recordDeletion: () => y((n) => n.recordDeletion()),
|
1320
|
+
recordInsertion: (n) => y((f) => f.recordInsertion(n)),
|
1321
|
+
recordUpdate: (n) => y((f) => f.recordUpdate(n)),
|
1322
|
+
refreshResource: async () => await y(async (n) => await n.refreshResource()),
|
1311
1323
|
// Methods: Modifying the resource
|
1312
|
-
deleteResource: async () => await y(async (
|
1313
|
-
saveResource: async (
|
1314
|
-
updateResource: async (
|
1324
|
+
deleteResource: async () => await y(async (n) => await n.deleteResource()),
|
1325
|
+
saveResource: async (n) => await y(async (f) => await f.saveResource(n)),
|
1326
|
+
updateResource: async (n) => await y(async (f) => await f.updateResource(n)),
|
1315
1327
|
// Methods: Custom API endpoints
|
1316
|
-
makeCustomApiRequest: async (
|
1317
|
-
async (f) => await f.makeCustomApiRequest(
|
1328
|
+
makeCustomApiRequest: async (n) => await y(
|
1329
|
+
async (f) => await f.makeCustomApiRequest(n)
|
1318
1330
|
)
|
1319
1331
|
};
|
1320
1332
|
}, V = {
|
1321
1333
|
config: { ...ye }
|
1322
1334
|
};
|
1323
1335
|
function We(h) {
|
1324
|
-
V.config =
|
1336
|
+
V.config = a.merge({}, ye, h);
|
1325
1337
|
}
|
1326
1338
|
export {
|
1327
1339
|
Be as ApiClientError,
|