rest-client-vue 1.1.1-b7 → 1.2.0-b1
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 +26 -2
- package/dist/rest-client-vue.js +416 -356
- package/dist/rest-client-vue.umd.cjs +1 -1
- package/dist/src/rest-collection-resources.d.ts +1 -0
- package/dist/src/rest-collection-resources.d.ts.map +1 -1
- package/dist/src/rest-collection.d.ts +23 -2
- package/dist/src/rest-collection.d.ts.map +1 -1
- package/dist/src/rest-resource.d.ts +1 -0
- package/dist/src/rest-resource.d.ts.map +1 -1
- package/dist/src/stores/rest-collection-store.d.ts +30 -5
- package/dist/src/stores/rest-collection-store.d.ts.map +1 -1
- package/dist/src/stores/rest-resource-store.d.ts +23 -1
- package/dist/src/stores/rest-resource-store.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/rest-client-vue.js
CHANGED
@@ -1,61 +1,72 @@
|
|
1
|
-
var
|
2
|
-
var Ce = (
|
3
|
-
var ae = (
|
4
|
-
if (!
|
5
|
-
throw TypeError("Cannot " +
|
1
|
+
var Ee = Object.defineProperty;
|
2
|
+
var Ce = (h, i, g) => i in h ? Ee(h, i, { enumerable: !0, configurable: !0, writable: !0, value: g }) : h[i] = g;
|
3
|
+
var ae = (h, i, g) => (Ce(h, typeof i != "symbol" ? i + "" : i, g), g), Te = (h, i, g) => {
|
4
|
+
if (!i.has(h))
|
5
|
+
throw TypeError("Cannot " + g);
|
6
6
|
};
|
7
|
-
var Q = (
|
8
|
-
if (
|
7
|
+
var Q = (h, i, g) => (Te(h, i, "read from private field"), g ? g.call(h) : i.get(h)), Se = (h, i, g) => {
|
8
|
+
if (i.has(h))
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
10
|
-
|
10
|
+
i instanceof WeakSet ? i.add(h) : i.set(h, g);
|
11
11
|
};
|
12
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
|
16
|
-
import
|
14
|
+
import { ref as I, toRef as se, computed as R, watch as L, nextTick as Le } from "vue";
|
15
|
+
import $ from "axios";
|
16
|
+
import pe from "jsog";
|
17
17
|
import X from "json-stringify-deterministic";
|
18
|
-
import { defineStore as
|
18
|
+
import { defineStore as me } from "pinia";
|
19
19
|
const ye = {
|
20
20
|
apiBaseUrl: "",
|
21
21
|
useVueLogger: !1
|
22
22
|
};
|
23
|
-
class
|
24
|
-
constructor(
|
25
|
-
super(
|
23
|
+
class Be extends Error {
|
24
|
+
constructor(g, U = void 0, e = void 0) {
|
25
|
+
super(g);
|
26
26
|
ae(this, "context");
|
27
27
|
ae(this, "innerError");
|
28
|
-
this.context =
|
28
|
+
this.context = U, 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 i in Q(this, _))
|
38
|
+
Q(this, _)[i].clear();
|
39
39
|
}
|
40
|
-
destroyStore(
|
41
|
-
Q(this,
|
40
|
+
destroyStore(i) {
|
41
|
+
Q(this, _)[i] && (Q(this, _)[i].$dispose(), delete Q(this, _)[i]);
|
42
42
|
}
|
43
|
-
getStore(
|
44
|
-
return Q(this,
|
43
|
+
getStore(i) {
|
44
|
+
return Q(this, _)[i];
|
45
45
|
}
|
46
|
-
registerStore(
|
47
|
-
Q(this,
|
46
|
+
registerStore(i, g) {
|
47
|
+
Q(this, _)[i] = g;
|
48
48
|
}
|
49
49
|
}
|
50
|
-
|
51
|
-
function v(
|
52
|
-
return a.get(
|
50
|
+
_ = new WeakMap();
|
51
|
+
function v(h, i) {
|
52
|
+
return a.get(h, (i == null ? void 0 : i.idProperty) || "_id");
|
53
53
|
}
|
54
|
-
function $e(
|
55
|
-
|
56
|
-
|
54
|
+
function $e(h, i) {
|
55
|
+
const g = a.map(
|
56
|
+
i,
|
57
|
+
(U, e) => U != null ? `${encodeURIComponent(e)}=${encodeURIComponent(U)}` : null
|
58
|
+
).filter((U) => U != null).join("&");
|
59
|
+
if (g.length > 0) {
|
60
|
+
const U = h.indexOf("?");
|
61
|
+
return U == h.length - 1 ? `${h}${g}` : U >= 0 ? `${h}&${g}` : `${h}?${g}`;
|
62
|
+
} else
|
63
|
+
return h;
|
57
64
|
}
|
58
|
-
|
65
|
+
function xe(h, i) {
|
66
|
+
var g;
|
67
|
+
return h && ((g = i.filter) != null && g.resourceIds) && !i.order ? i.filter.resourceIds.map((U) => h.find((e) => v(e, i) == U)).filter((U) => U != null) : h;
|
68
|
+
}
|
69
|
+
const Ue = {
|
59
70
|
detail: {
|
60
71
|
allowMultiple: !0,
|
61
72
|
autoEdit: !1,
|
@@ -81,7 +92,7 @@ const De = {
|
|
81
92
|
[{ path: "history.creation.timestamp" }, "desc"],
|
82
93
|
[{ path: "history.creation.indexInBatch" }, "desc"]
|
83
94
|
]
|
84
|
-
},
|
95
|
+
}, Y = {
|
85
96
|
resources: [],
|
86
97
|
remoteCollectionSize: null,
|
87
98
|
status: "NotLoaded",
|
@@ -89,22 +100,23 @@ const De = {
|
|
89
100
|
detailSelection: [],
|
90
101
|
invalidResources: [],
|
91
102
|
transientData: {}
|
92
|
-
},
|
103
|
+
}, oe = {
|
93
104
|
editingDetailSelection: !1,
|
94
105
|
batchSaveAttempted: !1,
|
95
106
|
editors: [],
|
96
107
|
listNavigators: {}
|
97
|
-
}, Pe = (
|
98
|
-
|
99
|
-
const
|
108
|
+
}, Pe = (h, i) => {
|
109
|
+
i = a.merge({}, Ue, i);
|
110
|
+
const g = me(h, {
|
100
111
|
state: () => ({
|
101
|
-
idProperty:
|
102
|
-
filter:
|
103
|
-
order:
|
104
|
-
|
105
|
-
referencePathsToExpand:
|
106
|
-
|
107
|
-
...
|
112
|
+
idProperty: i.idProperty,
|
113
|
+
filter: i.filter,
|
114
|
+
order: i.order || null,
|
115
|
+
propertiesToExclude: i.propertiesToExclude || null,
|
116
|
+
referencePathsToExpand: i.referencePathsToExpand || null,
|
117
|
+
restCollectionUrl: i.restCollectionUrl,
|
118
|
+
...Y,
|
119
|
+
...oe
|
108
120
|
}),
|
109
121
|
getters: {
|
110
122
|
/**
|
@@ -118,10 +130,10 @@ const De = {
|
|
118
130
|
(l = e.filter) != null && l.namedFilter && (r.namedFilter = e.filter.namedFilter);
|
119
131
|
const t = [];
|
120
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) {
|
121
|
-
const
|
122
|
-
r.q = X(
|
133
|
+
const m = t.length == 1 ? t[0] : { and: t };
|
134
|
+
r.q = X(m);
|
123
135
|
}
|
124
|
-
return e.order && (r.o = X(e.order)), e.
|
136
|
+
return e.order && (r.o = X(e.order)), e.propertiesToExclude && (r.ex = X(e.propertiesToExclude)), e.referencePathsToExpand && (r.r = X(e.referencePathsToExpand)), r;
|
125
137
|
}
|
126
138
|
},
|
127
139
|
actions: {
|
@@ -134,10 +146,10 @@ const De = {
|
|
134
146
|
* Configuration is retained, but REST collection contents and contextual state are reset.
|
135
147
|
*/
|
136
148
|
reset() {
|
137
|
-
for (const e in
|
138
|
-
this[e] =
|
139
|
-
for (const e in
|
140
|
-
this[e] =
|
149
|
+
for (const e in Y)
|
150
|
+
this[e] = Y[e];
|
151
|
+
for (const e in oe)
|
152
|
+
this[e] = oe[e];
|
141
153
|
},
|
142
154
|
/**
|
143
155
|
* Reset the store to its initial state, but retain transient data if appropriate.
|
@@ -146,7 +158,7 @@ const De = {
|
|
146
158
|
* Transient data are retained if options.limitTransientDataToLocalCollection is false.
|
147
159
|
*/
|
148
160
|
resetRetainingTransientData() {
|
149
|
-
if (
|
161
|
+
if (i.limitTransientDataToLocalCollection)
|
150
162
|
this.reset();
|
151
163
|
else {
|
152
164
|
const e = this.transientData;
|
@@ -237,8 +249,8 @@ const De = {
|
|
237
249
|
* Configuration and contextual state are retained, but REST collection contents are reset.
|
238
250
|
*/
|
239
251
|
clear() {
|
240
|
-
for (const e in
|
241
|
-
this[e] =
|
252
|
+
for (const e in Y)
|
253
|
+
this[e] = Y[e];
|
242
254
|
},
|
243
255
|
/**
|
244
256
|
* Clear the collection's contents, but retain transient data if appropriate.
|
@@ -247,7 +259,7 @@ const De = {
|
|
247
259
|
* Transient data are retained if options.limitTransientDataToLocalCollection is false.
|
248
260
|
*/
|
249
261
|
clearRetainingTransientData() {
|
250
|
-
if (
|
262
|
+
if (i.limitTransientDataToLocalCollection)
|
251
263
|
this.reset();
|
252
264
|
else {
|
253
265
|
const e = this.transientData;
|
@@ -289,32 +301,29 @@ const De = {
|
|
289
301
|
* @param loadOptions Pagination options that may override the defaults.
|
290
302
|
*/
|
291
303
|
async _loadResources(e, r, t) {
|
292
|
-
var
|
304
|
+
var x, A, N, O, k;
|
293
305
|
const l = e == 0;
|
294
|
-
if (this.status = l ? "Loading" : "LoadingMore", this._loadOffset = e, ((
|
306
|
+
if (this.status = l ? "Loading" : "LoadingMore", this._loadOffset = e, ((x = this.filter) == null ? void 0 : x.query) === !1) {
|
295
307
|
this.resources = [], this.remoteCollectionSize = 0;
|
296
308
|
return;
|
297
309
|
}
|
298
|
-
const u = this.fixedQueryParams, c = a.cloneDeep(u), d = l ? (
|
299
|
-
|
300
|
-
const
|
301
|
-
c,
|
302
|
-
(g, m) => g != null ? `${encodeURIComponent(m)}=${encodeURIComponent(g)}` : null
|
303
|
-
).filter((g) => g != null).join("&"), L = a.isEmpty(U) ? s.restCollectionUrl : `${s.restCollectionUrl}?${U}`;
|
310
|
+
const u = this.fixedQueryParams, c = a.cloneDeep(u), d = l ? (A = this.filter) != null && A.resourceIds && !this.order ? null : t.firstPageSize || ((N = i.loading) == null ? void 0 : N.firstPageSize) || t.pageSize || ((O = i.loading) == null ? void 0 : O.pageSize) || null : t.pageSize || ((k = i.loading) == null ? void 0 : k.pageSize) || null, m = d != null || i.limit != null ? a.min(a.filter([d, i.limit], (P) => P != null)) : void 0;
|
311
|
+
m != null ? (c.offset = e, c.limit = m) : e != 0 && (c.offset = e);
|
312
|
+
const w = $e(i.restCollectionUrl, c);
|
304
313
|
try {
|
305
|
-
const
|
306
|
-
if (r != this._loadId || e != this._loadOffset || !a.isEqual(u,
|
307
|
-
console.log(`Discarding resources fetched by obsolete query from ${
|
314
|
+
const P = await $.get(w), y = this.fixedQueryParams;
|
315
|
+
if (r != this._loadId || e != this._loadOffset || !a.isEqual(u, y))
|
316
|
+
console.log(`Discarding resources fetched by obsolete query from ${i.restCollectionUrl}.`);
|
308
317
|
else {
|
309
|
-
const
|
318
|
+
const S = pe.decode(a.get(P, "data.data", [])), T = (l ? 0 : this.resources.length) + S.length, E = m == null || S.length < m || i.limit && T >= i.limit;
|
310
319
|
console.log(
|
311
|
-
`Loaded ${
|
320
|
+
`Loaded ${S.length}${l ? "" : " more"} resources from ${i.restCollectionUrl}`
|
312
321
|
), l && (this.resources = []);
|
313
|
-
const
|
314
|
-
this.resources =
|
322
|
+
const D = [...this.resources, ...S.map((W) => Object.freeze(W))];
|
323
|
+
this.resources = xe(D, 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, r, t);
|
315
324
|
}
|
316
|
-
} catch (
|
317
|
-
console.log(`Error while loading resources (URL="${
|
325
|
+
} catch (P) {
|
326
|
+
console.log(`Error while loading resources (URL="${w}"):`, P), this.clearRetainingTransientData(), this.status = "Failed";
|
318
327
|
}
|
319
328
|
},
|
320
329
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -332,9 +341,9 @@ const De = {
|
|
332
341
|
async checkForDeletedResource(e) {
|
333
342
|
let r;
|
334
343
|
try {
|
335
|
-
r = await
|
344
|
+
r = await $.get(`${i.restCollectionUrl}/${e}`);
|
336
345
|
} catch (t) {
|
337
|
-
|
346
|
+
$.isAxiosError(t) && (r = t.response);
|
338
347
|
}
|
339
348
|
return r && r.status == 404 ? (this.recordDeletion(e), !0) : !1;
|
340
349
|
},
|
@@ -351,7 +360,7 @@ const De = {
|
|
351
360
|
var r;
|
352
361
|
if (["Loaded", "LoadingMore"].includes(this.status)) {
|
353
362
|
let t = this.resources.findIndex((l) => v(l, this) == e);
|
354
|
-
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 =
|
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 = ((r = i.detail) == null ? void 0 : r.autoEdit) || !1)), i.limitTransientDataToLocalCollection && delete this.transientData[e];
|
355
364
|
}
|
356
365
|
},
|
357
366
|
/**
|
@@ -373,7 +382,7 @@ const De = {
|
|
373
382
|
var l;
|
374
383
|
if (["Loaded", "LoadingMore"].includes(this.status)) {
|
375
384
|
const u = Object.freeze(e);
|
376
|
-
r ? this.resources.unshift(u) : this.resources.push(u), (l =
|
385
|
+
r ? this.resources.unshift(u) : this.resources.push(u), (l = i.detail) != null && l.autoFromSingleInsertion && (this.detailSelection.length == 0 || this.detailSelection.length == 1 && v(this.detailSelection[0], this) == null) && (this.detailSelection = [u], this.editingDetailSelection = i.detail.autoEdit);
|
377
386
|
const c = v(e, this);
|
378
387
|
c && (t === void 0 ? delete this.transientData[c] : this.transientData[c] = t);
|
379
388
|
}
|
@@ -419,7 +428,7 @@ const De = {
|
|
419
428
|
const t = a.map(
|
420
429
|
r,
|
421
430
|
(c, d) => c != null ? `${encodeURIComponent(d)}=${encodeURIComponent(c)}` : null
|
422
|
-
).filter((c) => c != null).join("&"), l = a.isEmpty(t) ? `${
|
431
|
+
).filter((c) => c != null).join("&"), l = a.isEmpty(t) ? `${i.restCollectionUrl}/${e}` : `${i.restCollectionUrl}/${e}?${t}`, u = await $.get(l);
|
423
432
|
if (u.status == 200) {
|
424
433
|
const c = u.data;
|
425
434
|
return this.recordUpdate(c), c;
|
@@ -446,9 +455,9 @@ const De = {
|
|
446
455
|
* @param resourceId The ID of the resource to delete.
|
447
456
|
*/
|
448
457
|
async deleteResource(e) {
|
449
|
-
if ((await
|
458
|
+
if ((await $.delete(`${i.restCollectionUrl}/${e}`)).status == 200 && ["Loaded", "LoadingMore"].includes(this.status)) {
|
450
459
|
let t = this.resources.findIndex((l) => v(l, this) == e);
|
451
|
-
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 = i.detail.autoEdit)), i.limitTransientDataToLocalCollection && delete this.transientData[e];
|
452
461
|
}
|
453
462
|
},
|
454
463
|
/**
|
@@ -463,9 +472,9 @@ const De = {
|
|
463
472
|
* the operation failed.
|
464
473
|
*/
|
465
474
|
async saveResource(e) {
|
466
|
-
const r = v(e, this), t = r == null, l = await
|
475
|
+
const r = v(e, this), t = r == null, l = await $({
|
467
476
|
method: t ? "post" : "put",
|
468
|
-
url: t ?
|
477
|
+
url: t ? i.restCollectionUrl : `${i.restCollectionUrl}/${r}`,
|
469
478
|
data: e
|
470
479
|
});
|
471
480
|
if (l.status == 200) {
|
@@ -485,16 +494,42 @@ const De = {
|
|
485
494
|
* @returns An array of refreshed local resources, one for each remote resource whose save operation succeeded.
|
486
495
|
*/
|
487
496
|
async saveResources(e) {
|
488
|
-
const r = await
|
497
|
+
const r = await $({
|
489
498
|
method: "put",
|
490
|
-
url:
|
499
|
+
url: i.restCollectionUrl,
|
491
500
|
data: e
|
492
501
|
});
|
493
502
|
if (r.status == 200) {
|
494
503
|
const t = r.data || [], l = [];
|
495
504
|
for (const [u, c] of t.entries()) {
|
496
|
-
const d = v(e[u], this) == null,
|
497
|
-
d && this.recordInsertion(
|
505
|
+
const d = v(e[u], this) == null, m = v(c, this), w = m ? await this.refreshResource(m) : null;
|
506
|
+
d && this.recordInsertion(w || c), l.push(w || Object.freeze(c));
|
507
|
+
}
|
508
|
+
return l;
|
509
|
+
}
|
510
|
+
return [];
|
511
|
+
},
|
512
|
+
/**
|
513
|
+
* Perform an update on one or more resources 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 resourcePropertyUpdates The list of update operations to perform, each having ID, property path, value, and update method.
|
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 updateResources(e) {
|
523
|
+
const r = await $({
|
524
|
+
method: "patch",
|
525
|
+
url: `${i.restCollectionUrl}`,
|
526
|
+
data: e
|
527
|
+
});
|
528
|
+
if (r.status == 200) {
|
529
|
+
const t = r.data || [], l = [];
|
530
|
+
for (const u of t) {
|
531
|
+
const c = v(u, this), d = c ? await this.refreshResource(c) : null;
|
532
|
+
l.push(d || Object.freeze(u));
|
498
533
|
}
|
499
534
|
return l;
|
500
535
|
}
|
@@ -559,7 +594,7 @@ const De = {
|
|
559
594
|
let c = e;
|
560
595
|
if (t) {
|
561
596
|
const d = a.difference(e, u);
|
562
|
-
d.length > 0 && (c = u.concat(d).filter((
|
597
|
+
d.length > 0 && (c = u.concat(d).filter((m) => m != null));
|
563
598
|
}
|
564
599
|
a.isEqual(u, c) || this.setSelection(c, l);
|
565
600
|
},
|
@@ -574,30 +609,30 @@ const De = {
|
|
574
609
|
if (!a.isEqual(e, this.selection.map((t) => v(t, this)))) {
|
575
610
|
let t = !0;
|
576
611
|
if (this.editors.length > 0) {
|
577
|
-
if (
|
612
|
+
if (i.detail.autoFromSingleSelection && this.selection.length == 1)
|
578
613
|
t = !1;
|
579
|
-
else if (
|
614
|
+
else if (i.detail.autoFromMultipleSelection && i.detail.allowMultiple && this.selection.length > 1)
|
580
615
|
t = !1;
|
581
|
-
else if (
|
616
|
+
else if (i.detail.constrainToSelection) {
|
582
617
|
const l = this.selection.map((d) => v(d, this)), c = this.detailSelection.map((d) => v(d, this)).filter((d) => l.includes(d));
|
583
618
|
this.detailSelection.filter((d) => !c.includes(v(d, this))).length > 0 && (t = !1);
|
584
619
|
}
|
585
620
|
}
|
586
621
|
if (!t)
|
587
622
|
return;
|
588
|
-
if (this.selection = e.map((l) => this.resources.find((u) => v(u, this) == l)).filter((l) => l != null),
|
623
|
+
if (this.selection = e.map((l) => this.resources.find((u) => v(u, this) == l)).filter((l) => l != null), i.detail.autoFromSingleSelection && this.selection.length == 1) {
|
589
624
|
const l = this.selection[0];
|
590
625
|
(this.detailSelection.length != 1 || v(this.detailSelection[0], this) != v(l, this)) && (this.detailSelection = [l]);
|
591
|
-
} else if (
|
626
|
+
} else if (i.detail.autoFromMultipleSelection && i.detail.allowMultiple && this.selection.length > 1)
|
592
627
|
a.isEqual(
|
593
628
|
this.selection.map((l) => v(l, this)),
|
594
629
|
this.detailSelection.map((l) => v(l, this))
|
595
630
|
) || (this.detailSelection = a.clone(this.selection));
|
596
|
-
else if (
|
631
|
+
else if (i.detail.constrainToSelection) {
|
597
632
|
const l = this.selection.map((d) => v(d, this)), u = this.detailSelection.map((d) => v(d, this)), c = u.filter((d) => l.includes(d));
|
598
633
|
a.isEqual(c, u) || (this.detailSelection = this.detailSelection.filter((d) => c.includes(v(d, this))));
|
599
634
|
}
|
600
|
-
this.detailSelection.length == 0 ? this.editingDetailSelection = !1 : this.editingDetailSelection = r !== void 0 ? r : this.editingDetailSelection ||
|
635
|
+
this.detailSelection.length == 0 ? this.editingDetailSelection = !1 : this.editingDetailSelection = r !== void 0 ? r : this.editingDetailSelection || i.detail.autoEdit;
|
601
636
|
}
|
602
637
|
},
|
603
638
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -621,9 +656,9 @@ const De = {
|
|
621
656
|
* or set to true if options.detail.autoEdit is true.
|
622
657
|
*/
|
623
658
|
showSelectionAsDetail(e) {
|
624
|
-
if (this.selection.length <= 1 ||
|
659
|
+
if (this.selection.length <= 1 || i.detail.allowMultiple) {
|
625
660
|
const r = this.selection.map((l) => v(l, this)), t = this.detailSelection.map((l) => v(l, this));
|
626
|
-
a.isEqual(r, t) || (this.detailSelection = a.clone(this.selection)), this.detailSelection.length == 0 ? this.editingDetailSelection = !1 : this.editingDetailSelection = e !== void 0 ? e : this.editingDetailSelection ||
|
661
|
+
a.isEqual(r, t) || (this.detailSelection = a.clone(this.selection)), this.detailSelection.length == 0 ? this.editingDetailSelection = !1 : this.editingDetailSelection = e !== void 0 ? e : this.editingDetailSelection || i.detail.autoEdit;
|
627
662
|
}
|
628
663
|
},
|
629
664
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -677,229 +712,229 @@ const De = {
|
|
677
712
|
});
|
678
713
|
return (() => {
|
679
714
|
const e = (r, t) => {
|
680
|
-
const l =
|
681
|
-
return
|
715
|
+
const l = g(r, t);
|
716
|
+
return ie.registerStore(l.$id, l), l;
|
682
717
|
};
|
683
|
-
return e.$id =
|
718
|
+
return e.$id = g.$id, e;
|
684
719
|
})();
|
685
|
-
},
|
720
|
+
}, ie = new Ie(), Qe = (h = {}) => {
|
686
721
|
var ue, de, he, fe;
|
687
722
|
const {
|
688
|
-
collectionId:
|
689
|
-
draftBatchId:
|
690
|
-
enabled:
|
723
|
+
collectionId: i,
|
724
|
+
draftBatchId: g,
|
725
|
+
enabled: U,
|
691
726
|
resourceType: e,
|
692
727
|
options: r
|
693
|
-
} =
|
694
|
-
() => u.value == null && l.value != null &&
|
695
|
-
),
|
696
|
-
function
|
728
|
+
} = h, t = I(void 0), l = I(i), u = I(g), c = I(U ?? !0), d = I([se(e)]), m = I(r), w = R(() => 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 = R(
|
729
|
+
() => u.value == null && l.value != null && ie.getStore(l.value) != null
|
730
|
+
), P = I(k.value), y = R(() => E("status", "Uninitialized"));
|
731
|
+
function S(s) {
|
697
732
|
if (t.value)
|
698
|
-
return
|
733
|
+
return s(t.value);
|
699
734
|
}
|
700
|
-
async function
|
735
|
+
async function T(s) {
|
701
736
|
if (t.value)
|
702
|
-
return await
|
737
|
+
return await s(t.value);
|
703
738
|
}
|
704
|
-
function
|
739
|
+
function E(s, n) {
|
705
740
|
if (t.value)
|
706
|
-
return t.value[
|
707
|
-
if (
|
708
|
-
return
|
741
|
+
return t.value[s];
|
742
|
+
if (n !== void 0)
|
743
|
+
return n;
|
709
744
|
throw "Attempted to use a REST collection store that has not been created, with no default value.";
|
710
745
|
}
|
711
|
-
const D = (
|
712
|
-
var
|
746
|
+
const D = (s = {}) => {
|
747
|
+
var te, ve, ge, Re;
|
713
748
|
const {
|
714
|
-
collectionId:
|
715
|
-
draftBatchId:
|
716
|
-
enabled:
|
749
|
+
collectionId: n,
|
750
|
+
draftBatchId: C,
|
751
|
+
enabled: F,
|
717
752
|
resourceType: le,
|
718
|
-
options:
|
719
|
-
} =
|
720
|
-
l.value =
|
721
|
-
}, W = async (
|
722
|
-
|
723
|
-
},
|
724
|
-
|
725
|
-
},
|
726
|
-
if (
|
727
|
-
const
|
728
|
-
await
|
753
|
+
options: ee
|
754
|
+
} = s;
|
755
|
+
l.value = n, 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 = (Re = (ge = m.value) == null ? void 0 : ge.filter) == null ? void 0 : Re.query), A.value = H(), W(c.value);
|
756
|
+
}, W = async (s) => {
|
757
|
+
s != x.value && (x.value = s, s && (K(), z()));
|
758
|
+
}, re = async (s) => {
|
759
|
+
N.value = s, await T(async (n) => await n.setFilterResourceIds(N.value || null));
|
760
|
+
}, J = async (s) => {
|
761
|
+
if (O.value = s, y.value != "Uninitialized") {
|
762
|
+
const n = s, C = R(() => a.isFunction(n) ? p.value ? n(p.value) : null : n);
|
763
|
+
await T((F) => F.setQuery(C.value || null));
|
729
764
|
}
|
730
|
-
},
|
731
|
-
|
732
|
-
filter: { resourceIds:
|
765
|
+
}, K = () => {
|
766
|
+
m.value = a.merge({}, m.value || {}, {
|
767
|
+
filter: { resourceIds: N.value, query: O.value }
|
733
768
|
});
|
734
|
-
}, p =
|
769
|
+
}, p = R(
|
735
770
|
() => d.value[0].value || void 0
|
736
|
-
),
|
737
|
-
const
|
771
|
+
), B = function(s) {
|
772
|
+
const n = a.get(s, "filter.query"), C = a.get(s, "propertiesToExclude"), F = a.get(s, "referencePathsToExpand"), le = a.isFunction(n) ? n(p.value) : n, ee = p.value ? a.isFunction(C) ? C(p.value) : C || [] : [], te = p.value ? a.isFunction(F) ? F(p.value) : F || [] : [];
|
738
773
|
return {
|
739
|
-
...a.cloneDeep(
|
774
|
+
...a.cloneDeep(s || {}),
|
740
775
|
filter: {
|
741
|
-
...a.cloneDeep((
|
776
|
+
...a.cloneDeep((s == null ? void 0 : s.filter) || {}),
|
742
777
|
query: le
|
743
778
|
},
|
744
|
-
|
745
|
-
referencePathsToExpand:
|
779
|
+
propertiesToExclude: ee,
|
780
|
+
referencePathsToExpand: te
|
746
781
|
};
|
747
|
-
},
|
748
|
-
if (
|
749
|
-
return
|
750
|
-
if (
|
751
|
-
return
|
752
|
-
|
753
|
-
|
754
|
-
}), n = S(() => {
|
755
|
-
var i;
|
782
|
+
}, q = R(() => B(m.value)), j = R(() => {
|
783
|
+
if (q.value.restCollectionUrl !== void 0)
|
784
|
+
return q.value.restCollectionUrl;
|
785
|
+
if (!P.value)
|
786
|
+
return !p.value || !p.value.collectionName ? null : w.value ? `${V.config.apiBaseUrl}/draft-batches/${w.value}/${p.value.collectionName}` : `${V.config.apiBaseUrl}/${p.value.collectionName}`;
|
787
|
+
}), o = R(() => {
|
788
|
+
var s;
|
756
789
|
if (p.value)
|
757
790
|
return a.mergeWith(
|
758
|
-
a.cloneDeep(
|
759
|
-
|
791
|
+
a.cloneDeep(Ue),
|
792
|
+
q.value,
|
760
793
|
{
|
761
|
-
idProperty: (
|
762
|
-
restCollectionUrl:
|
794
|
+
idProperty: (s = p.value) == null ? void 0 : s.idProperty,
|
795
|
+
restCollectionUrl: j.value || ""
|
763
796
|
},
|
764
|
-
(
|
765
|
-
if (a.isArray(
|
766
|
-
return
|
797
|
+
(n, C) => {
|
798
|
+
if (a.isArray(C) && C.length == 0 && (n == null || a.isArray(n)))
|
799
|
+
return C;
|
767
800
|
}
|
768
801
|
);
|
769
|
-
}),
|
802
|
+
}), f = I(0), b = R(
|
770
803
|
() => {
|
771
|
-
var
|
772
|
-
return
|
804
|
+
var s;
|
805
|
+
return f.value, l.value || p.value && ((s = p.value) == null ? void 0 : s.collectionName) && (w.value ? `draftBatches/${w.value}/${p.value.collectionName}/${A.value}` : `${p.value.collectionName}/${A.value}`) || null;
|
773
806
|
}
|
774
|
-
),
|
775
|
-
if (
|
776
|
-
let
|
777
|
-
return p.value &&
|
807
|
+
), z = () => {
|
808
|
+
if (x.value) {
|
809
|
+
let s = !1;
|
810
|
+
return p.value && b.value && (t.value = ie.getStore(b.value), t.value ? s = !1 : o.value && (P.value = !1, t.value = Pe(b.value, o.value)(), s = !0)), s;
|
778
811
|
} else
|
779
812
|
return !1;
|
780
813
|
}, G = () => {
|
781
|
-
|
814
|
+
b.value && l.value == b.value ? (t.value = void 0, z()) : (t.value = void 0, f.value = f.value + 1, z());
|
782
815
|
};
|
783
|
-
|
784
|
-
a.isEqual(
|
785
|
-
}),
|
786
|
-
|
787
|
-
}),
|
788
|
-
|
789
|
-
}),
|
790
|
-
a.isEqual(
|
791
|
-
}),
|
792
|
-
|
793
|
-
}),
|
794
|
-
a.isEqual(
|
816
|
+
L(w, (s, n) => {
|
817
|
+
a.isEqual(s, n) || G();
|
818
|
+
}), L(x, (s, n) => {
|
819
|
+
s != n && (s ? z() : t.value = void 0);
|
820
|
+
}), L(p, (s, n) => {
|
821
|
+
s && !n ? z() : !s && n || a.isEqual(s, n) || G();
|
822
|
+
}), L(o, (s, n) => {
|
823
|
+
a.isEqual(s, n) || G();
|
824
|
+
}), L(k, () => {
|
825
|
+
k.value || (P.value = !1);
|
826
|
+
}), L(b, () => z()), L(j, (s, n) => {
|
827
|
+
a.isEqual(s, n) || G();
|
795
828
|
});
|
796
|
-
const
|
797
|
-
|
829
|
+
const M = [], we = function(s) {
|
830
|
+
y.value != "Uninitialized" ? Le(s) : M.push(s);
|
798
831
|
};
|
799
|
-
return
|
800
|
-
if (
|
801
|
-
const
|
802
|
-
|
803
|
-
for (const
|
804
|
-
|
832
|
+
return L(y, (s, n) => {
|
833
|
+
if (s != "Uninitialized" && n == "Uninitialized") {
|
834
|
+
const C = a.clone(M);
|
835
|
+
M.splice(0, M.length);
|
836
|
+
for (const F of C)
|
837
|
+
F();
|
805
838
|
}
|
806
|
-
}),
|
839
|
+
}), z(), {
|
807
840
|
// Configuration
|
808
|
-
collectionId:
|
809
|
-
draftBatchId:
|
841
|
+
collectionId: b,
|
842
|
+
draftBatchId: w,
|
810
843
|
resourceType: p,
|
844
|
+
restCollectionUrl: R(() => E("restCollectionUrl", null)),
|
811
845
|
// Status
|
812
|
-
enabled:
|
813
|
-
status:
|
814
|
-
batchSaveAttempted:
|
815
|
-
listNavigators:
|
846
|
+
enabled: x,
|
847
|
+
status: y,
|
848
|
+
batchSaveAttempted: R(() => E("batchSaveAttempted", !1)),
|
849
|
+
listNavigators: R(() => E("listNavigators", !1)),
|
816
850
|
// Resources loaded from the REST API
|
817
|
-
invalidResources:
|
818
|
-
resources:
|
819
|
-
remoteCollectionSize:
|
851
|
+
invalidResources: R(() => E("invalidResources", [])),
|
852
|
+
resources: R(() => y.value != "Uninitialized" ? (T((s) => s.ensureCollectionLoaded()), E("resources", [])) : []),
|
853
|
+
remoteCollectionSize: R(() => E("remoteCollectionSize", null)),
|
820
854
|
// Transient data
|
821
|
-
transientData:
|
855
|
+
transientData: R(() => E("transientData", [])),
|
822
856
|
// Selection and detail selection
|
823
|
-
detailSelection:
|
824
|
-
editingDetailSelection:
|
825
|
-
selection:
|
857
|
+
detailSelection: R(() => E("detailSelection", [])),
|
858
|
+
editingDetailSelection: R(() => E("editingDetailSelection", !1)),
|
859
|
+
selection: R(() => E("selection", [])),
|
826
860
|
// Methods: Configuration
|
827
861
|
reconfigureCollection: D,
|
828
|
-
setEditingDetailSelection: (
|
829
|
-
(
|
862
|
+
setEditingDetailSelection: (s) => S(
|
863
|
+
(n) => n.setEditingDetailSelection(s)
|
830
864
|
),
|
831
865
|
setEnabled: W,
|
832
|
-
setFilterResourceIds:
|
833
|
-
setQuery:
|
866
|
+
setFilterResourceIds: re,
|
867
|
+
setQuery: J,
|
834
868
|
// Methods: Status
|
835
|
-
ensureStore:
|
869
|
+
ensureStore: z,
|
836
870
|
// TODO Rename
|
837
|
-
setBatchSaveAttempted: (
|
871
|
+
setBatchSaveAttempted: (s) => S((n) => n.setBatchSaveAttempted(s)),
|
838
872
|
// Local collection management
|
839
|
-
clear: () =>
|
840
|
-
ensureCollectionLoaded: async () => await
|
841
|
-
loadResources: async () => await
|
873
|
+
clear: () => S((s) => s.clear()),
|
874
|
+
ensureCollectionLoaded: async () => await T(async (s) => s.ensureCollectionLoaded()),
|
875
|
+
loadResources: async () => await T(async (s) => await s.loadResources()),
|
842
876
|
// Methods: Recording changes to the collection
|
843
|
-
addResource: (
|
844
|
-
checkForDeletedResource: async (
|
845
|
-
recordDeletion: (
|
846
|
-
recordInsertion: (
|
847
|
-
recordUpdate: (
|
848
|
-
refreshResource: async (
|
849
|
-
async (
|
877
|
+
addResource: (s) => S((n) => n.addResource(s)),
|
878
|
+
checkForDeletedResource: async (s) => await T(async (n) => await n.checkForDeletedResource(s)) == !0,
|
879
|
+
recordDeletion: (s) => S((n) => n.recordDeletion(s)),
|
880
|
+
recordInsertion: (s, { insertAtBeginning: n = !1, transientData: C = void 0 } = {}) => S((F) => F.recordInsertion(s, { insertAtBeginning: n, transientData: C })),
|
881
|
+
recordUpdate: (s) => S((n) => n.recordUpdate(s)),
|
882
|
+
refreshResource: async (s) => await T(
|
883
|
+
async (n) => await n.refreshResource(s)
|
850
884
|
),
|
851
885
|
// Methods: Modifying the collection
|
852
|
-
deleteResource: async (
|
853
|
-
async (
|
886
|
+
deleteResource: async (s) => await T(
|
887
|
+
async (n) => await n.deleteResource(s)
|
854
888
|
),
|
855
|
-
saveResource: async (
|
856
|
-
saveResources: async (
|
889
|
+
saveResource: async (s) => await T(async (n) => await n.saveResource(s)),
|
890
|
+
saveResources: async (s) => await T(async (n) => await n.saveResources(s)),
|
891
|
+
updateResources: async (s) => await T(async (n) => await n.updateResources(s)),
|
857
892
|
// Methods: Transient data
|
858
|
-
clearTransientData: () =>
|
859
|
-
setInvalidResourceIds: (
|
860
|
-
setTransientDataForResources: (
|
861
|
-
(
|
893
|
+
clearTransientData: () => S((s) => s.clearTransientData()),
|
894
|
+
setInvalidResourceIds: (s) => S((n) => n.setInvalidResourceIds(s)),
|
895
|
+
setTransientDataForResources: (s) => S(
|
896
|
+
(n) => n.setTransientDataForResources(s)
|
862
897
|
),
|
863
898
|
// Methods: Selection and detail selection
|
864
|
-
clearSelection: () =>
|
865
|
-
deselectResources: (
|
866
|
-
selectResources: (
|
867
|
-
(
|
899
|
+
clearSelection: () => S((s) => s.clearSelection()),
|
900
|
+
deselectResources: (s) => S((n) => n.deselectResources(s)),
|
901
|
+
selectResources: (s, n) => S(
|
902
|
+
(C) => C.selectResources(s, n)
|
868
903
|
),
|
869
904
|
// Methods: Managing the detail view
|
870
|
-
hideDetail: () =>
|
905
|
+
hideDetail: () => S((s) => s.hideDetail()),
|
871
906
|
// Methods: Editors
|
872
|
-
deregisterEditor: (
|
873
|
-
registerEditor: (
|
907
|
+
deregisterEditor: (s) => S((n) => n.deregisterEditor(s)),
|
908
|
+
registerEditor: (s) => S((n) => n.registerEditor(s)),
|
874
909
|
// Methods: List navigators
|
875
|
-
deregisterListNavigator: (
|
876
|
-
registerListNavigator: (
|
910
|
+
deregisterListNavigator: (s) => S((n) => n.deregisterListNavigator(s)),
|
911
|
+
registerListNavigator: (s) => S((n) => n.registerListNavigator(s)),
|
877
912
|
// Callbacks
|
878
|
-
onItemsStoreReady:
|
913
|
+
onItemsStoreReady: we
|
879
914
|
};
|
880
|
-
},
|
881
|
-
|
915
|
+
}, je = () => {
|
916
|
+
ie.clearAllStores();
|
882
917
|
};
|
883
|
-
function
|
884
|
-
return a.get(
|
918
|
+
function ne(h, i) {
|
919
|
+
return a.get(h, (i == null ? void 0 : i.idProperty) || "_id");
|
885
920
|
}
|
886
|
-
const
|
921
|
+
const De = {
|
887
922
|
idProperty: "_id"
|
888
|
-
},
|
923
|
+
}, Z = {
|
889
924
|
resource: null,
|
890
925
|
status: "NotLoaded"
|
891
|
-
},
|
892
|
-
|
893
|
-
const
|
926
|
+
}, qe = (h, i) => {
|
927
|
+
i = a.merge({}, De, i);
|
928
|
+
const g = me(h, {
|
894
929
|
state: () => ({
|
895
|
-
idProperty:
|
896
|
-
resourceId:
|
897
|
-
resourceUrl:
|
898
|
-
referencePathsToExpand:
|
899
|
-
...
|
930
|
+
idProperty: i.idProperty,
|
931
|
+
resourceId: i.resourceId || null,
|
932
|
+
resourceUrl: i.resourceUrl || null,
|
933
|
+
referencePathsToExpand: i.referencePathsToExpand || null,
|
934
|
+
...Z
|
900
935
|
}),
|
901
936
|
getters: {
|
902
|
-
currentResourceUrl: (e) => e.resourceUrl || (
|
937
|
+
currentResourceUrl: (e) => e.resourceUrl || (i.restCollectionUrl && e.resourceId ? `${i.restCollectionUrl}/${e.resourceId}` : null) || i.restCollectionUrl || null,
|
903
938
|
/** Get the REST query parameters that can be determined from the options. */
|
904
939
|
fixedQueryParams: (e) => {
|
905
940
|
const r = {};
|
@@ -916,8 +951,8 @@ const Ue = {
|
|
916
951
|
* Configuration is retained, but REST resource content and contextual state are reset.
|
917
952
|
*/
|
918
953
|
reset() {
|
919
|
-
for (const e in
|
920
|
-
this[e] =
|
954
|
+
for (const e in Z)
|
955
|
+
this[e] = Z[e];
|
921
956
|
},
|
922
957
|
async setResourceId(e) {
|
923
958
|
const r = this.currentResourceUrl;
|
@@ -936,8 +971,8 @@ const Ue = {
|
|
936
971
|
* Configuration and contextual state are retained, but REST collection contents are reset.
|
937
972
|
*/
|
938
973
|
clear() {
|
939
|
-
for (const e in
|
940
|
-
this[e] =
|
974
|
+
for (const e in Z)
|
975
|
+
this[e] = Z[e];
|
941
976
|
},
|
942
977
|
/**
|
943
978
|
* Load the resource, if it has not been loaded.
|
@@ -962,8 +997,8 @@ const Ue = {
|
|
962
997
|
(c, d) => c != null ? `${encodeURIComponent(d)}=${encodeURIComponent(c)}` : null
|
963
998
|
).filter((c) => c != null).join("&"), u = a.isEmpty(l) ? this.currentResourceUrl : `${this.currentResourceUrl}?${l}`;
|
964
999
|
try {
|
965
|
-
const c = await
|
966
|
-
e != this._loadId || !a.isEqual(r, d) ? console.log(`Discarding resource fetched by obsolete query from ${u}.`) : (this.resource =
|
1000
|
+
const c = await $.get(u), d = this.fixedQueryParams;
|
1001
|
+
e != this._loadId || !a.isEqual(r, d) ? console.log(`Discarding resource fetched by obsolete query from ${u}.`) : (this.resource = pe.decode(a.get(c, "data", {})), this.status = "Loaded");
|
967
1002
|
} catch (c) {
|
968
1003
|
console.log(`Error while loading resource (URL="${u}")`, c), this.reset(), this.status = "Failed";
|
969
1004
|
}
|
@@ -985,9 +1020,9 @@ const Ue = {
|
|
985
1020
|
if (this.currentResourceUrl) {
|
986
1021
|
let e;
|
987
1022
|
try {
|
988
|
-
e = await
|
1023
|
+
e = await $.get(this.currentResourceUrl);
|
989
1024
|
} catch (r) {
|
990
|
-
|
1025
|
+
$.isAxiosError(r) && (e = r.response);
|
991
1026
|
}
|
992
1027
|
return e && e.status == 404 ? (this.recordDeletion(), !0) : !1;
|
993
1028
|
} else
|
@@ -1022,7 +1057,7 @@ const Ue = {
|
|
1022
1057
|
* @param resource The resource that has been inserted.
|
1023
1058
|
*/
|
1024
1059
|
recordInsertion(e) {
|
1025
|
-
this.resourceId =
|
1060
|
+
this.resourceId = ne(e, this) || null, this.status == "Loaded" && (this.resource = Object.freeze(e));
|
1026
1061
|
},
|
1027
1062
|
/**
|
1028
1063
|
* Record an update, making the same changes in the local resource.
|
@@ -1043,7 +1078,7 @@ const Ue = {
|
|
1043
1078
|
* @param resource The resource that has been updated.
|
1044
1079
|
*/
|
1045
1080
|
recordUpdate(e) {
|
1046
|
-
this.resourceId =
|
1081
|
+
this.resourceId = ne(e, this) || null, this.status == "Loaded" && (this.resource = Object.freeze(e));
|
1047
1082
|
},
|
1048
1083
|
async refreshResource() {
|
1049
1084
|
return await this.loadResource(), this.resource;
|
@@ -1058,7 +1093,7 @@ const Ue = {
|
|
1058
1093
|
*/
|
1059
1094
|
async deleteResource() {
|
1060
1095
|
if (this.currentResourceUrl)
|
1061
|
-
(await
|
1096
|
+
(await $.delete(this.currentResourceUrl)).status == 200 && this.recordDeletion();
|
1062
1097
|
else
|
1063
1098
|
throw "Cannot delete a resource because its URL, or its ID and collection URL, are unknown.";
|
1064
1099
|
},
|
@@ -1074,12 +1109,12 @@ const Ue = {
|
|
1074
1109
|
* the operation failed.
|
1075
1110
|
*/
|
1076
1111
|
async saveResource(e) {
|
1077
|
-
const r =
|
1112
|
+
const r = ne(e, this), t = r == null;
|
1078
1113
|
if (!r)
|
1079
1114
|
throw "The REST resource store cannot create new resources on the server.";
|
1080
1115
|
if (!this.currentResourceUrl)
|
1081
1116
|
throw "Cannot save a resource because its URL, or its ID and collection URL, are unknown.";
|
1082
|
-
const l = await
|
1117
|
+
const l = await $({
|
1083
1118
|
method: t ? "post" : "put",
|
1084
1119
|
url: this.currentResourceUrl,
|
1085
1120
|
data: e
|
@@ -1090,6 +1125,30 @@ const Ue = {
|
|
1090
1125
|
}
|
1091
1126
|
return null;
|
1092
1127
|
},
|
1128
|
+
/**
|
1129
|
+
* Partial update of the remote resource, then mirror the change locally.
|
1130
|
+
*
|
1131
|
+
* After writing changes, {@link refreshResource} is called to ensure that the local resource (which is also the
|
1132
|
+
* return value) has the same object-graph characteristics as the rest of the local collection.
|
1133
|
+
*
|
1134
|
+
* @param resourcePropertyUpdates A list of property paths, values, and update methods to apply .
|
1135
|
+
* @returns The refreshed local resource after the change has been persisted to the remote collection, or null if
|
1136
|
+
* the operation failed.
|
1137
|
+
*/
|
1138
|
+
async updateResource(e) {
|
1139
|
+
if (!this.currentResourceUrl)
|
1140
|
+
throw "Cannot save a resource because its URL, or its ID and collection URL, are unknown.";
|
1141
|
+
const r = await $({
|
1142
|
+
method: "patch",
|
1143
|
+
url: this.currentResourceUrl,
|
1144
|
+
data: e
|
1145
|
+
});
|
1146
|
+
if (r.status == 200) {
|
1147
|
+
const t = r.data;
|
1148
|
+
return await this.refreshResource() || Object.freeze(t);
|
1149
|
+
}
|
1150
|
+
return null;
|
1151
|
+
},
|
1093
1152
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
1094
1153
|
// Actions: Custom API endpoints
|
1095
1154
|
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@@ -1101,7 +1160,7 @@ const Ue = {
|
|
1101
1160
|
c = `${this.currentResourceUrl}/${t}`;
|
1102
1161
|
else
|
1103
1162
|
throw "Cannot make a custom API request for a resource because its URL, or its ID and collection URL, are unknown.";
|
1104
|
-
const d = await
|
1163
|
+
const d = await $({
|
1105
1164
|
method: r || "get",
|
1106
1165
|
url: c,
|
1107
1166
|
data: u
|
@@ -1112,148 +1171,149 @@ const Ue = {
|
|
1112
1171
|
});
|
1113
1172
|
return (() => {
|
1114
1173
|
const e = (r, t) => {
|
1115
|
-
const l =
|
1174
|
+
const l = g(r, t);
|
1116
1175
|
return ce.registerStore(l.$id, l), l;
|
1117
1176
|
};
|
1118
|
-
return e.$id =
|
1177
|
+
return e.$id = g.$id, e;
|
1119
1178
|
})();
|
1120
|
-
}, ce = new Ie(), Me = (
|
1179
|
+
}, ce = new Ie(), Me = (h = {}) => {
|
1121
1180
|
const {
|
1122
|
-
resourceClientId:
|
1123
|
-
draftBatchId:
|
1124
|
-
enabled:
|
1181
|
+
resourceClientId: i,
|
1182
|
+
draftBatchId: g,
|
1183
|
+
enabled: U,
|
1125
1184
|
resourceType: e,
|
1126
1185
|
options: r
|
1127
|
-
} =
|
1186
|
+
} = h, t = I(void 0), l = I(i), u = I(g), c = I(U ?? !0), d = I([se(e)]), m = I(r), w = R(() => u.value), x = I(c.value), A = I(H()), N = R(
|
1128
1187
|
() => u.value == null && l.value != null && ce.getStore(l.value) != null
|
1129
|
-
),
|
1130
|
-
function
|
1188
|
+
), O = I(N.value), k = R(() => S("status", "Uninitialized"));
|
1189
|
+
function P(o) {
|
1131
1190
|
if (t.value)
|
1132
|
-
return
|
1191
|
+
return o(t.value);
|
1133
1192
|
}
|
1134
|
-
async function
|
1193
|
+
async function y(o) {
|
1135
1194
|
if (t.value)
|
1136
|
-
return await
|
1195
|
+
return await o(t.value);
|
1137
1196
|
}
|
1138
|
-
function
|
1197
|
+
function S(o, f) {
|
1139
1198
|
if (t.value)
|
1140
|
-
return t.value[
|
1141
|
-
if (
|
1142
|
-
return
|
1199
|
+
return t.value[o];
|
1200
|
+
if (f !== void 0)
|
1201
|
+
return f;
|
1143
1202
|
throw "Attempted to use a REST resource store that has not been created, with no default value.";
|
1144
1203
|
}
|
1145
|
-
const
|
1204
|
+
const T = (o = {}) => {
|
1146
1205
|
const {
|
1147
|
-
resourceClientId:
|
1148
|
-
draftBatchId:
|
1149
|
-
enabled:
|
1206
|
+
resourceClientId: f,
|
1207
|
+
draftBatchId: b,
|
1208
|
+
enabled: z,
|
1150
1209
|
resourceType: G,
|
1151
|
-
options:
|
1152
|
-
} =
|
1153
|
-
l.value =
|
1154
|
-
},
|
1155
|
-
|
1156
|
-
}, D =
|
1210
|
+
options: M
|
1211
|
+
} = o;
|
1212
|
+
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);
|
1213
|
+
}, E = async (o) => {
|
1214
|
+
o != x.value && (x.value = o, o && q());
|
1215
|
+
}, D = R(
|
1157
1216
|
() => d.value[0].value || void 0
|
1158
|
-
), W = function(
|
1159
|
-
const
|
1217
|
+
), W = function(o) {
|
1218
|
+
const f = a.get(o, "referencePathsToExpand"), b = D.value ? a.isFunction(f) ? f(D.value) : f || [] : [];
|
1160
1219
|
return {
|
1161
|
-
...a.cloneDeep(
|
1162
|
-
referencePathsToExpand:
|
1220
|
+
...a.cloneDeep(o || {}),
|
1221
|
+
referencePathsToExpand: b
|
1163
1222
|
};
|
1164
|
-
},
|
1223
|
+
}, re = R(() => W(m.value)), J = R(() => {
|
1165
1224
|
if (!D.value)
|
1166
1225
|
return null;
|
1167
|
-
if (!
|
1168
|
-
return !D.value || !D.value.collectionName ? null :
|
1169
|
-
}),
|
1170
|
-
if (D.value &&
|
1226
|
+
if (!O.value)
|
1227
|
+
return !D.value || !D.value.collectionName ? null : w.value ? `${V.config.apiBaseUrl}/draft-batches/${w.value}/${D.value.collectionName}` : `${V.config.apiBaseUrl}/${D.value.collectionName}`;
|
1228
|
+
}), K = R(() => {
|
1229
|
+
if (D.value && J.value)
|
1171
1230
|
return a.mergeWith(
|
1172
|
-
a.cloneDeep(
|
1173
|
-
|
1231
|
+
a.cloneDeep(De),
|
1232
|
+
re.value,
|
1174
1233
|
{
|
1175
1234
|
idProperty: D.value.idProperty,
|
1176
|
-
restCollectionUrl:
|
1235
|
+
restCollectionUrl: J.value
|
1177
1236
|
},
|
1178
|
-
(
|
1179
|
-
if (a.isArray(
|
1180
|
-
return
|
1237
|
+
(o, f) => {
|
1238
|
+
if (a.isArray(f) && f.length == 0 && (o == null || a.isArray(o)))
|
1239
|
+
return f;
|
1181
1240
|
}
|
1182
1241
|
);
|
1183
|
-
}), p = I(0),
|
1242
|
+
}), p = I(0), B = R(
|
1184
1243
|
() => {
|
1185
|
-
var
|
1186
|
-
return p.value, l.value || D.value && ((
|
1244
|
+
var o;
|
1245
|
+
return p.value, l.value || D.value && ((o = D.value) == null ? void 0 : o.collectionName) && (w.value ? `draftBatches/${w.value}/${D.value.collectionName}/${A.value}` : `${D.value.collectionName}/${A.value}`) || null;
|
1187
1246
|
}
|
1188
|
-
),
|
1189
|
-
if (
|
1190
|
-
let
|
1191
|
-
return D.value &&
|
1247
|
+
), q = () => {
|
1248
|
+
if (x.value) {
|
1249
|
+
let o = !1;
|
1250
|
+
return D.value && B.value && (t.value = ce.getStore(B.value), t.value ? o = !1 : K.value && (O.value = !1, t.value = qe(B.value, K.value)(), o = !0)), o;
|
1192
1251
|
} else
|
1193
1252
|
return !1;
|
1194
|
-
},
|
1195
|
-
|
1253
|
+
}, j = () => {
|
1254
|
+
B.value && l.value == B.value ? (t.value = void 0, q()) : (t.value = void 0, p.value = p.value + 1, q());
|
1196
1255
|
};
|
1197
|
-
return
|
1198
|
-
a.isEqual(
|
1199
|
-
}),
|
1200
|
-
|
1201
|
-
}),
|
1202
|
-
|
1203
|
-
}),
|
1204
|
-
a.isEqual(
|
1205
|
-
}),
|
1206
|
-
|
1207
|
-
}),
|
1208
|
-
a.isEqual(
|
1209
|
-
}),
|
1256
|
+
return L(w, (o, f) => {
|
1257
|
+
a.isEqual(o, f) || j();
|
1258
|
+
}), L(x, (o, f) => {
|
1259
|
+
o != f && (o ? q() : t.value = void 0);
|
1260
|
+
}), L(D, (o, f) => {
|
1261
|
+
o && !f ? q() : !o && f || a.isEqual(o, f) || j();
|
1262
|
+
}), L(K, (o, f) => {
|
1263
|
+
a.isEqual(o, f) || j();
|
1264
|
+
}), L(N, () => {
|
1265
|
+
N.value || (O.value = !1);
|
1266
|
+
}), L(B, () => q()), L(J, (o, f) => {
|
1267
|
+
a.isEqual(o, f) || j();
|
1268
|
+
}), q(), {
|
1210
1269
|
// Configuration
|
1211
|
-
resourceClientId:
|
1212
|
-
draftBatchId:
|
1213
|
-
enabled:
|
1270
|
+
resourceClientId: B,
|
1271
|
+
draftBatchId: w,
|
1272
|
+
enabled: x,
|
1214
1273
|
resourceType: D,
|
1215
1274
|
// Status
|
1216
|
-
status:
|
1275
|
+
status: k,
|
1217
1276
|
// Resources loaded from the REST API
|
1218
|
-
resource:
|
1219
|
-
resourceId:
|
1220
|
-
resourceUrl:
|
1277
|
+
resource: R(() => k.value != "Uninitialized" ? (y((o) => o.ensureResourceLoaded()), S("resource", [])) : []),
|
1278
|
+
resourceId: R(() => S("resourceId", null)),
|
1279
|
+
resourceUrl: R(() => S("resourceUrl", null)),
|
1221
1280
|
// Methods: Configuration
|
1222
|
-
reconfigureClient:
|
1223
|
-
setEnabled:
|
1224
|
-
setResourceId: async (
|
1225
|
-
setResourceUrl: async (
|
1281
|
+
reconfigureClient: T,
|
1282
|
+
setEnabled: E,
|
1283
|
+
setResourceId: async (o) => await y(async (f) => await f.setResourceId(o)),
|
1284
|
+
setResourceUrl: async (o) => await y(async (f) => await f.setResourceUrl(o)),
|
1226
1285
|
// Methods: Status
|
1227
|
-
ensureStore:
|
1286
|
+
ensureStore: q,
|
1228
1287
|
// Methods: Resource management
|
1229
|
-
clear: () =>
|
1230
|
-
ensureResourceLoaded: async () => await
|
1231
|
-
loadResource: async () => await
|
1288
|
+
clear: () => P((o) => o.clear()),
|
1289
|
+
ensureResourceLoaded: async () => await y(async (o) => o.ensureResourceLoaded()),
|
1290
|
+
loadResource: async () => await y(async (o) => await o.loadResource()),
|
1232
1291
|
// Methods: Recording changes to the resource
|
1233
|
-
checkForDeletedResource: async () => await
|
1234
|
-
recordDeletion: () =>
|
1235
|
-
recordInsertion: (
|
1236
|
-
recordUpdate: (
|
1237
|
-
refreshResource: async () => await
|
1292
|
+
checkForDeletedResource: async () => await y(async (o) => await o.checkForDeletedResource()) == !0,
|
1293
|
+
recordDeletion: () => y((o) => o.recordDeletion()),
|
1294
|
+
recordInsertion: (o) => y((f) => f.recordInsertion(o)),
|
1295
|
+
recordUpdate: (o) => y((f) => f.recordUpdate(o)),
|
1296
|
+
refreshResource: async () => await y(async (o) => await o.refreshResource()),
|
1238
1297
|
// Methods: Modifying the resource
|
1239
|
-
deleteResource: async () => await
|
1240
|
-
saveResource: async (
|
1298
|
+
deleteResource: async () => await y(async (o) => await o.deleteResource()),
|
1299
|
+
saveResource: async (o) => await y(async (f) => await f.saveResource(o)),
|
1300
|
+
updateResource: async (o) => await y(async (f) => await f.updateResource(o)),
|
1241
1301
|
// Methods: Custom API endpoints
|
1242
|
-
makeCustomApiRequest: async (
|
1243
|
-
async (
|
1302
|
+
makeCustomApiRequest: async (o) => await y(
|
1303
|
+
async (f) => await f.makeCustomApiRequest(o)
|
1244
1304
|
)
|
1245
1305
|
};
|
1246
|
-
},
|
1306
|
+
}, V = {
|
1247
1307
|
config: { ...ye }
|
1248
1308
|
};
|
1249
|
-
function
|
1250
|
-
|
1309
|
+
function We(h) {
|
1310
|
+
V.config = a.merge({}, ye, h);
|
1251
1311
|
}
|
1252
1312
|
export {
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1313
|
+
Be as ApiClientError,
|
1314
|
+
je as clearAllRestCollections,
|
1315
|
+
We as initRestClient,
|
1316
|
+
V as restClient,
|
1317
|
+
Qe as useRestCollection,
|
1258
1318
|
Me as useRestResource
|
1259
1319
|
};
|