@sylwellsoftware/glue 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -7
- package/dist/emitters/liveQuery.d.ts +21 -1
- package/dist/emitters/liveQuery.d.ts.map +1 -1
- package/dist/emitters/liveResult.d.ts +14 -0
- package/dist/emitters/liveResult.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +465 -236
- package/dist/index.js.map +1 -1
- package/dist/queryhandling/endpoints.d.ts +77 -0
- package/dist/queryhandling/endpoints.d.ts.map +1 -0
- package/dist/queryhandling/restQueryHandler.d.ts +3 -0
- package/dist/queryhandling/restQueryHandler.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var n = (
|
|
4
|
-
let
|
|
1
|
+
var H = Object.defineProperty;
|
|
2
|
+
var F = (t, r, e) => r in t ? H(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
|
|
3
|
+
var n = (t, r, e) => F(t, typeof r != "symbol" ? r + "" : r, e);
|
|
4
|
+
let x = 1;
|
|
5
5
|
class b {
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(r = {}) {
|
|
7
7
|
n(this, "id");
|
|
8
8
|
n(this, "timestamp");
|
|
9
9
|
n(this, "purpose");
|
|
@@ -16,53 +16,53 @@ class b {
|
|
|
16
16
|
n(this, "ownerRef");
|
|
17
17
|
n(this, "strongOwner");
|
|
18
18
|
var s;
|
|
19
|
-
if (
|
|
19
|
+
if (r == null || typeof r != "object" || Array.isArray(r))
|
|
20
20
|
throw new TypeError("EventBubble options must be an object");
|
|
21
|
-
this.id = `event-${
|
|
22
|
-
const e =
|
|
23
|
-
this.ownerType = e == null ? null :
|
|
21
|
+
this.id = `event-${x++}`, this.timestamp = r.timestamp ?? Date.now(), this.purpose = r.purpose ?? "unspecified", this.cause = r.cause ?? null, this.value = r.value, this.parent = r.parent ?? null, this.parentBubble = this.parent;
|
|
22
|
+
const e = r.owner;
|
|
23
|
+
this.ownerType = e == null ? null : $(e) ?? typeof e, B(e) && typeof WeakRef == "function" ? (this.ownerRef = new WeakRef(e), this.strongOwner = void 0) : (this.ownerRef = null, this.strongOwner = e), (s = this.parent) == null || s.registerChild(this);
|
|
24
24
|
}
|
|
25
25
|
get owner() {
|
|
26
|
-
var
|
|
27
|
-
return ((
|
|
26
|
+
var r;
|
|
27
|
+
return ((r = this.ownerRef) == null ? void 0 : r.deref()) ?? this.strongOwner;
|
|
28
28
|
}
|
|
29
|
-
registerChild(
|
|
30
|
-
if (!(
|
|
29
|
+
registerChild(r) {
|
|
30
|
+
if (!(r instanceof b))
|
|
31
31
|
throw new TypeError("EventBubble children must be EventBubble instances");
|
|
32
|
-
this.children.includes(
|
|
32
|
+
this.children.includes(r) || this.children.push(r);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
return typeof
|
|
35
|
+
function B(t) {
|
|
36
|
+
return typeof t == "object" && t !== null || typeof t == "function";
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
38
|
+
function $(t) {
|
|
39
|
+
const r = Reflect.get(t, "constructor");
|
|
40
|
+
if (r == null || typeof r != "object" && typeof r != "function")
|
|
41
41
|
return;
|
|
42
|
-
const e = Reflect.get(
|
|
42
|
+
const e = Reflect.get(r, "name");
|
|
43
43
|
return typeof e == "string" ? e : void 0;
|
|
44
44
|
}
|
|
45
45
|
const m = /* @__PURE__ */ new Set();
|
|
46
|
-
function
|
|
47
|
-
if (typeof
|
|
46
|
+
function C(t) {
|
|
47
|
+
if (typeof t != "function")
|
|
48
48
|
throw new TypeError("EventBus.subscribe requires a function");
|
|
49
|
-
m.add(
|
|
50
|
-
let
|
|
49
|
+
m.add(t);
|
|
50
|
+
let r = !0;
|
|
51
51
|
return () => {
|
|
52
|
-
|
|
52
|
+
r && (r = !1, m.delete(t));
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
for (const
|
|
55
|
+
function V(t) {
|
|
56
|
+
for (const r of [...m]) r(t);
|
|
57
57
|
}
|
|
58
|
-
const
|
|
59
|
-
subscribe:
|
|
60
|
-
emit:
|
|
61
|
-
emitBubble:
|
|
62
|
-
registerBubbleGraph(
|
|
63
|
-
if (
|
|
58
|
+
const w = Object.freeze({
|
|
59
|
+
subscribe: C,
|
|
60
|
+
emit: V,
|
|
61
|
+
emitBubble: V,
|
|
62
|
+
registerBubbleGraph(t) {
|
|
63
|
+
if (t == null || typeof t.addBubble != "function")
|
|
64
64
|
throw new TypeError("registerBubbleGraph requires an addBubble() method");
|
|
65
|
-
return
|
|
65
|
+
return C((r) => t.addBubble(r));
|
|
66
66
|
},
|
|
67
67
|
get hasSubscribers() {
|
|
68
68
|
return m.size > 0;
|
|
@@ -70,28 +70,28 @@ const y = Object.freeze({
|
|
|
70
70
|
get subscriberCount() {
|
|
71
71
|
return m.size;
|
|
72
72
|
}
|
|
73
|
-
}),
|
|
73
|
+
}), h = Object.freeze({
|
|
74
74
|
Error: "error",
|
|
75
75
|
Loading: "loading",
|
|
76
76
|
Initial: "initial",
|
|
77
77
|
Ready: "ready"
|
|
78
|
-
}),
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[
|
|
82
|
-
[
|
|
78
|
+
}), S = /* @__PURE__ */ new Map([
|
|
79
|
+
[h.Ready, 1],
|
|
80
|
+
[h.Initial, 2],
|
|
81
|
+
[h.Loading, 3],
|
|
82
|
+
[h.Error, 4]
|
|
83
83
|
]);
|
|
84
|
-
function
|
|
85
|
-
let
|
|
86
|
-
for (const e of
|
|
87
|
-
if (!
|
|
84
|
+
function j(t) {
|
|
85
|
+
let r = h.Ready;
|
|
86
|
+
for (const e of t) {
|
|
87
|
+
if (!S.has(e))
|
|
88
88
|
throw new TypeError(`Unknown fetch state: ${String(e)}`);
|
|
89
|
-
if ((
|
|
89
|
+
if ((S.get(e) ?? 0) > (S.get(r) ?? 0) && (r = e), r === h.Error) break;
|
|
90
90
|
}
|
|
91
|
-
return
|
|
91
|
+
return r;
|
|
92
92
|
}
|
|
93
|
-
class
|
|
94
|
-
constructor(
|
|
93
|
+
class g {
|
|
94
|
+
constructor(r, e = {}) {
|
|
95
95
|
n(this, "subscribers", /* @__PURE__ */ new Set());
|
|
96
96
|
n(this, "value");
|
|
97
97
|
n(this, "fetchState");
|
|
@@ -103,28 +103,28 @@ class w {
|
|
|
103
103
|
n(this, "trace");
|
|
104
104
|
if (e == null || typeof e != "object" || Array.isArray(e))
|
|
105
105
|
throw new TypeError("Emitter options must be an object");
|
|
106
|
-
if (this.value =
|
|
106
|
+
if (this.value = r, this.fetchState = e.fetchState ?? h.Ready, this.error = e.error ?? null, this.equals = e.equals ?? Object.is, this.owner = e.owner, this.purpose = e.purpose ?? this.constructor.name, this.trace = e.trace ?? !1, typeof this.equals != "function")
|
|
107
107
|
throw new TypeError("Emitter equals option must be a function");
|
|
108
|
-
|
|
108
|
+
R(this.fetchState);
|
|
109
109
|
}
|
|
110
|
-
subscribe(
|
|
110
|
+
subscribe(r, e = {}) {
|
|
111
111
|
if (this.isDisposed) throw new Error("Cannot subscribe to a disposed emitter");
|
|
112
|
-
if (typeof
|
|
112
|
+
if (typeof r != "function")
|
|
113
113
|
throw new TypeError("subscribe requires a function");
|
|
114
114
|
if (e == null || typeof e != "object" || Array.isArray(e))
|
|
115
115
|
throw new TypeError("subscribe options must be an object");
|
|
116
116
|
const { emitCurrent: s = !0, parentEvent: i = null } = e;
|
|
117
|
-
if (this.subscribers.add(
|
|
117
|
+
if (this.subscribers.add(r), s) {
|
|
118
118
|
const u = this.createEvent("subscribed", i, this.value);
|
|
119
|
-
|
|
119
|
+
r(this.notification(u));
|
|
120
120
|
}
|
|
121
121
|
let o = !0;
|
|
122
122
|
return () => {
|
|
123
|
-
o && (o = !1, this.subscribers.delete(
|
|
123
|
+
o && (o = !1, this.subscribers.delete(r));
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
-
subscribeFutureValues(
|
|
127
|
-
return this.subscribe(
|
|
126
|
+
subscribeFutureValues(r) {
|
|
127
|
+
return this.subscribe(r, { emitCurrent: !1 });
|
|
128
128
|
}
|
|
129
129
|
get() {
|
|
130
130
|
return this.value;
|
|
@@ -141,11 +141,11 @@ class w {
|
|
|
141
141
|
get subscriberCount() {
|
|
142
142
|
return this.subscribers.size;
|
|
143
143
|
}
|
|
144
|
-
map(
|
|
145
|
-
if (typeof
|
|
146
|
-
return new
|
|
144
|
+
map(r, e = {}) {
|
|
145
|
+
if (typeof r != "function") throw new TypeError("map requires a function");
|
|
146
|
+
return new D(
|
|
147
147
|
[this],
|
|
148
|
-
([s]) =>
|
|
148
|
+
([s]) => r(s),
|
|
149
149
|
{
|
|
150
150
|
...e,
|
|
151
151
|
owner: e.owner ?? this.owner,
|
|
@@ -154,13 +154,13 @@ class w {
|
|
|
154
154
|
}
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
|
-
mapEach(
|
|
158
|
-
if (typeof
|
|
159
|
-
return new
|
|
157
|
+
mapEach(r, e = {}) {
|
|
158
|
+
if (typeof r != "function") throw new TypeError("mapEach requires a function");
|
|
159
|
+
return new D([this], ([s]) => {
|
|
160
160
|
if (s == null) return s;
|
|
161
161
|
if (!Array.isArray(s))
|
|
162
162
|
throw new TypeError("mapEach source value must be an array");
|
|
163
|
-
return s.map((o, u) => o == null ? o :
|
|
163
|
+
return s.map((o, u) => o == null ? o : r(o, u));
|
|
164
164
|
}, {
|
|
165
165
|
...e,
|
|
166
166
|
purpose: e.purpose ?? `${this.purpose}:mapEach`
|
|
@@ -169,45 +169,45 @@ class w {
|
|
|
169
169
|
dispose() {
|
|
170
170
|
this.isDisposed || (this.isDisposed = !0, this.subscribers.clear());
|
|
171
171
|
}
|
|
172
|
-
notification(
|
|
172
|
+
notification(r = null) {
|
|
173
173
|
return Object.freeze({
|
|
174
174
|
value: this.value,
|
|
175
175
|
fetchState: this.fetchState,
|
|
176
176
|
error: this.error,
|
|
177
|
-
event:
|
|
177
|
+
event: r
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
|
-
notify(
|
|
180
|
+
notify(r = null) {
|
|
181
181
|
if (this.isDisposed) return;
|
|
182
|
-
const e = this.notification(
|
|
182
|
+
const e = this.notification(r);
|
|
183
183
|
for (const s of [...this.subscribers]) s(e);
|
|
184
184
|
}
|
|
185
|
-
setSnapshot(
|
|
185
|
+
setSnapshot(r = {}) {
|
|
186
186
|
if (this.isDisposed) return !1;
|
|
187
|
-
const e = Object.hasOwn(
|
|
188
|
-
if (
|
|
187
|
+
const e = Object.hasOwn(r, "value") ? r.value : this.value, s = r.fetchState ?? this.fetchState, i = Object.hasOwn(r, "error") ? r.error : this.error, o = r.cause ?? "state changed", u = r.parentEvent ?? null;
|
|
188
|
+
if (R(s), !(!this.equals(this.value, e) || this.fetchState !== s || !Object.is(this.error, i))) return !1;
|
|
189
189
|
this.value = e, this.fetchState = s, this.error = i;
|
|
190
190
|
const c = this.createEvent(o, u, e);
|
|
191
191
|
return this.notify(c), !0;
|
|
192
192
|
}
|
|
193
|
-
createEvent(
|
|
194
|
-
if (!this.trace && !e && !
|
|
193
|
+
createEvent(r, e = null, s = this.value) {
|
|
194
|
+
if (!this.trace && !e && !w.hasSubscribers) return null;
|
|
195
195
|
const i = new b({
|
|
196
196
|
owner: this.owner ?? this,
|
|
197
197
|
purpose: this.purpose,
|
|
198
198
|
value: s,
|
|
199
|
-
cause:
|
|
199
|
+
cause: r,
|
|
200
200
|
parent: e
|
|
201
201
|
});
|
|
202
|
-
return e ||
|
|
202
|
+
return e || w.emit(i), i;
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
class
|
|
205
|
+
class D extends g {
|
|
206
206
|
constructor(e, s, i = {}) {
|
|
207
|
-
const { computeFetchState: o =
|
|
207
|
+
const { computeFetchState: o = j, ...u } = i;
|
|
208
208
|
super(void 0, {
|
|
209
209
|
...u,
|
|
210
|
-
fetchState:
|
|
210
|
+
fetchState: h.Initial,
|
|
211
211
|
error: null
|
|
212
212
|
});
|
|
213
213
|
n(this, "sources");
|
|
@@ -218,7 +218,7 @@ class R extends w {
|
|
|
218
218
|
}
|
|
219
219
|
setSourcesAndCompute(e, s = this.compute, i = {}) {
|
|
220
220
|
if (this.isDisposed) throw new Error("Cannot update a disposed derived emitter");
|
|
221
|
-
if (!Array.isArray(e) || e.some((o) => !
|
|
221
|
+
if (!Array.isArray(e) || e.some((o) => !k(o)))
|
|
222
222
|
throw new TypeError("DerivedEmitter sources must be an array of emitters");
|
|
223
223
|
if (typeof s != "function")
|
|
224
224
|
throw new TypeError("DerivedEmitter compute must be a function");
|
|
@@ -234,75 +234,75 @@ class R extends w {
|
|
|
234
234
|
this.sourceUnsubscribers = [];
|
|
235
235
|
}
|
|
236
236
|
recompute(e = null, s = !0) {
|
|
237
|
-
const i = this.sources.map((d) => d.get()), o = this.sources.map((d) => d.getFetchState()), u = this.sources.map((d,
|
|
238
|
-
let
|
|
237
|
+
const i = this.sources.map((d) => d.get()), o = this.sources.map((d) => d.getFetchState()), u = this.sources.map((d, v) => ({ sourceIndex: v, error: d.getError() })).filter((d) => d.error != null);
|
|
238
|
+
let a, c = null;
|
|
239
239
|
try {
|
|
240
|
-
|
|
240
|
+
a = this.compute(i);
|
|
241
241
|
} catch (d) {
|
|
242
|
-
c = d,
|
|
242
|
+
c = d, a = void 0;
|
|
243
243
|
}
|
|
244
|
-
const
|
|
245
|
-
let
|
|
246
|
-
if (
|
|
247
|
-
this.value =
|
|
244
|
+
const f = c == null ? u : [...u, { sourceIndex: null, error: c }], p = _(this.error, f);
|
|
245
|
+
let l = this.computeFetchState(o);
|
|
246
|
+
if (R(l), (c != null || u.length > 0) && (l = h.Error), !s) {
|
|
247
|
+
this.value = a, this.fetchState = l, this.error = p;
|
|
248
248
|
return;
|
|
249
249
|
}
|
|
250
250
|
this.setSnapshot({
|
|
251
|
-
value:
|
|
252
|
-
fetchState:
|
|
251
|
+
value: a,
|
|
252
|
+
fetchState: l,
|
|
253
253
|
error: p,
|
|
254
254
|
cause: "derived source changed",
|
|
255
255
|
parentEvent: e
|
|
256
256
|
});
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
-
function
|
|
260
|
-
return
|
|
259
|
+
function _(t, r) {
|
|
260
|
+
return r.length === 0 ? null : t != null && t.length === r.length && t.every((e, s) => {
|
|
261
261
|
var i, o;
|
|
262
|
-
return e.sourceIndex === ((i =
|
|
263
|
-
}) ?
|
|
262
|
+
return e.sourceIndex === ((i = r[s]) == null ? void 0 : i.sourceIndex) && Object.is(e.error, (o = r[s]) == null ? void 0 : o.error);
|
|
263
|
+
}) ? t : Object.freeze(r.map((e) => Object.freeze(e)));
|
|
264
264
|
}
|
|
265
|
-
function
|
|
266
|
-
return (typeof
|
|
265
|
+
function k(t) {
|
|
266
|
+
return (typeof t != "object" || t === null) && typeof t != "function" ? !1 : typeof Reflect.get(t, "get") == "function" && typeof Reflect.get(t, "getFetchState") == "function" && typeof Reflect.get(t, "getError") == "function" && typeof Reflect.get(t, "subscribe") == "function";
|
|
267
267
|
}
|
|
268
|
-
function
|
|
269
|
-
|
|
268
|
+
function R(t) {
|
|
269
|
+
j([t]);
|
|
270
270
|
}
|
|
271
|
-
class
|
|
272
|
-
constructor(
|
|
273
|
-
super(
|
|
271
|
+
class U extends g {
|
|
272
|
+
constructor(r, e = {}) {
|
|
273
|
+
super(r, e);
|
|
274
274
|
}
|
|
275
|
-
setWithState(
|
|
275
|
+
setWithState(r, e = h.Ready, s = null, i = null) {
|
|
276
276
|
const o = i instanceof b ? i : null, u = o ? "set called" : i ?? "set called";
|
|
277
|
-
return this.setSnapshot({ value:
|
|
277
|
+
return this.setSnapshot({ value: r, fetchState: e, error: s, cause: u, parentEvent: o });
|
|
278
278
|
}
|
|
279
|
-
set(
|
|
280
|
-
return this.setWithState(
|
|
279
|
+
set(r, e = null) {
|
|
280
|
+
return this.setWithState(r, h.Ready, null, e);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
class
|
|
283
|
+
class M extends Error {
|
|
284
284
|
constructor() {
|
|
285
285
|
super("AsyncCommand is already running"), this.name = "AsyncCommandConcurrencyError";
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
class
|
|
288
|
+
class fe extends g {
|
|
289
289
|
constructor(e) {
|
|
290
|
-
|
|
290
|
+
N(e);
|
|
291
291
|
const {
|
|
292
292
|
execute: s,
|
|
293
293
|
concurrency: i = "ignore",
|
|
294
|
-
mapError: o = (
|
|
294
|
+
mapError: o = (f) => f,
|
|
295
295
|
owner: u,
|
|
296
|
-
purpose:
|
|
296
|
+
purpose: a = "async command",
|
|
297
297
|
trace: c
|
|
298
298
|
} = e;
|
|
299
|
-
if (
|
|
299
|
+
if (W(i), typeof o != "function")
|
|
300
300
|
throw new TypeError("AsyncCommand mapError must be a function");
|
|
301
301
|
super(void 0, {
|
|
302
|
-
fetchState:
|
|
302
|
+
fetchState: h.Initial,
|
|
303
303
|
error: null,
|
|
304
304
|
owner: u,
|
|
305
|
-
purpose:
|
|
305
|
+
purpose: a,
|
|
306
306
|
...c === void 0 ? {} : { trace: c }
|
|
307
307
|
});
|
|
308
308
|
n(this, "execute");
|
|
@@ -316,9 +316,9 @@ class K extends w {
|
|
|
316
316
|
n(this, "hasSuccessfulValue", !1);
|
|
317
317
|
/** Exposed for deterministic tests; consumers should use run()/abort(). */
|
|
318
318
|
n(this, "_activeRequest", null);
|
|
319
|
-
this.execute = s, this.concurrency = i, this.mapError = o, this.runningEmitter = new
|
|
319
|
+
this.execute = s, this.concurrency = i, this.mapError = o, this.runningEmitter = new U(!1, {
|
|
320
320
|
owner: u ?? this,
|
|
321
|
-
purpose: `${
|
|
321
|
+
purpose: `${a}:running`,
|
|
322
322
|
...c === void 0 ? {} : { trace: c }
|
|
323
323
|
}), this.isRunning = this.runningEmitter;
|
|
324
324
|
}
|
|
@@ -328,52 +328,52 @@ class K extends w {
|
|
|
328
328
|
if (this._activeRequest != null) {
|
|
329
329
|
if (this.concurrency === "ignore") return this._activeRequest;
|
|
330
330
|
if (this.concurrency === "reject")
|
|
331
|
-
return Promise.reject(new
|
|
331
|
+
return Promise.reject(new M());
|
|
332
332
|
(p = this.abortController) == null || p.abort();
|
|
333
333
|
}
|
|
334
|
-
const i = ++this.requestId, o =
|
|
334
|
+
const i = ++this.requestId, o = G();
|
|
335
335
|
this.abortController = o;
|
|
336
|
-
const u = s instanceof b ? s : null,
|
|
336
|
+
const u = s instanceof b ? s : null, a = u ? "parent command requested" : s;
|
|
337
337
|
this.setSnapshot({
|
|
338
338
|
value: this.lastSuccessfulValue,
|
|
339
|
-
fetchState:
|
|
339
|
+
fetchState: h.Loading,
|
|
340
340
|
error: null,
|
|
341
|
-
cause:
|
|
341
|
+
cause: a,
|
|
342
342
|
parentEvent: u
|
|
343
343
|
});
|
|
344
344
|
const c = this.createEvent("command execute", u, e);
|
|
345
|
-
this.runningEmitter.set(!0, c ??
|
|
346
|
-
const
|
|
345
|
+
this.runningEmitter.set(!0, c ?? a);
|
|
346
|
+
const f = Promise.resolve().then(() => this.execute(e, {
|
|
347
347
|
signal: o.signal,
|
|
348
348
|
event: c
|
|
349
|
-
})).then((
|
|
349
|
+
})).then((l) => {
|
|
350
350
|
if (this.isCurrentRequest(i, o))
|
|
351
|
-
return this.lastSuccessfulValue =
|
|
352
|
-
value:
|
|
353
|
-
fetchState:
|
|
351
|
+
return this.lastSuccessfulValue = l, this.hasSuccessfulValue = !0, this.setSnapshot({
|
|
352
|
+
value: l,
|
|
353
|
+
fetchState: h.Ready,
|
|
354
354
|
error: null,
|
|
355
355
|
cause: "command succeeded",
|
|
356
356
|
parentEvent: c
|
|
357
|
-
}),
|
|
358
|
-
}).catch((
|
|
357
|
+
}), l;
|
|
358
|
+
}).catch((l) => {
|
|
359
359
|
this.isCurrentRequest(i, o) && this.setSnapshot({
|
|
360
360
|
value: this.lastSuccessfulValue,
|
|
361
|
-
fetchState:
|
|
362
|
-
error: this.mapCommandError(
|
|
361
|
+
fetchState: h.Error,
|
|
362
|
+
error: this.mapCommandError(l),
|
|
363
363
|
cause: "command failed",
|
|
364
364
|
parentEvent: c
|
|
365
365
|
});
|
|
366
366
|
}).finally(() => {
|
|
367
367
|
this.isCurrentRequest(i, o) && (this.abortController = null, this._activeRequest = null, this.runningEmitter.set(!1, c ?? "command settled"));
|
|
368
368
|
});
|
|
369
|
-
return this._activeRequest =
|
|
369
|
+
return this._activeRequest = f, f;
|
|
370
370
|
}
|
|
371
371
|
abort(e = "command aborted") {
|
|
372
372
|
if (this.isDisposed || this.abortController == null) return !1;
|
|
373
373
|
const s = e instanceof b ? e : null, i = s ? "parent command aborted" : e;
|
|
374
374
|
return this.requestId += 1, this.abortController.abort(), this.abortController = null, this._activeRequest = null, this.runningEmitter.set(!1, s ?? i), this.setSnapshot({
|
|
375
375
|
value: this.lastSuccessfulValue,
|
|
376
|
-
fetchState: this.hasSuccessfulValue ?
|
|
376
|
+
fetchState: this.hasSuccessfulValue ? h.Ready : h.Initial,
|
|
377
377
|
error: null,
|
|
378
378
|
cause: i,
|
|
379
379
|
parentEvent: s
|
|
@@ -385,7 +385,7 @@ class K extends w {
|
|
|
385
385
|
const s = e instanceof b ? e : null;
|
|
386
386
|
this.setSnapshot({
|
|
387
387
|
value: void 0,
|
|
388
|
-
fetchState:
|
|
388
|
+
fetchState: h.Initial,
|
|
389
389
|
error: null,
|
|
390
390
|
cause: s ? "parent command reset" : e,
|
|
391
391
|
parentEvent: s
|
|
@@ -406,23 +406,23 @@ class K extends w {
|
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
|
-
function
|
|
410
|
-
if (
|
|
409
|
+
function N(t) {
|
|
410
|
+
if (t == null || typeof t != "object" || Array.isArray(t))
|
|
411
411
|
throw new TypeError("AsyncCommand options must be an object");
|
|
412
|
-
if (typeof
|
|
412
|
+
if (typeof t.execute != "function")
|
|
413
413
|
throw new TypeError("AsyncCommand execute must be a function");
|
|
414
414
|
}
|
|
415
|
-
function
|
|
416
|
-
if (
|
|
417
|
-
throw new TypeError(`Unknown AsyncCommand concurrency policy: ${
|
|
415
|
+
function W(t) {
|
|
416
|
+
if (t !== "ignore" && t !== "replace" && t !== "reject")
|
|
417
|
+
throw new TypeError(`Unknown AsyncCommand concurrency policy: ${t}`);
|
|
418
418
|
}
|
|
419
|
-
function
|
|
420
|
-
const
|
|
421
|
-
if (typeof
|
|
419
|
+
function G() {
|
|
420
|
+
const t = Reflect.get(globalThis, "AbortController");
|
|
421
|
+
if (typeof t != "function")
|
|
422
422
|
throw new Error("AsyncCommand requires AbortController in this runtime");
|
|
423
|
-
return new
|
|
423
|
+
return new t();
|
|
424
424
|
}
|
|
425
|
-
class
|
|
425
|
+
class I extends g {
|
|
426
426
|
constructor(e) {
|
|
427
427
|
if (e == null || typeof e != "object" || Array.isArray(e))
|
|
428
428
|
throw new TypeError("LiveQuery options must be an object");
|
|
@@ -431,34 +431,40 @@ class X extends w {
|
|
|
431
431
|
args: i = {},
|
|
432
432
|
autoFetch: o = !0,
|
|
433
433
|
keepPreviousValue: u = !0,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
434
|
+
polling: a,
|
|
435
|
+
owner: c,
|
|
436
|
+
purpose: f = "live query",
|
|
437
|
+
trace: p
|
|
437
438
|
} = e;
|
|
438
439
|
if (s == null || typeof s.fetch != "function")
|
|
439
440
|
throw new TypeError("LiveQuery handler must implement fetch()");
|
|
440
|
-
|
|
441
|
+
X(i), a != null && K(a);
|
|
441
442
|
super(void 0, {
|
|
442
|
-
fetchState:
|
|
443
|
+
fetchState: h.Initial,
|
|
443
444
|
error: null,
|
|
444
|
-
owner:
|
|
445
|
-
purpose:
|
|
446
|
-
...
|
|
445
|
+
owner: c,
|
|
446
|
+
purpose: f,
|
|
447
|
+
...p === void 0 ? {} : { trace: p }
|
|
447
448
|
});
|
|
448
449
|
n(this, "handler");
|
|
449
450
|
n(this, "args");
|
|
450
451
|
n(this, "keepPreviousValue");
|
|
451
452
|
n(this, "lastSuccessfulValue");
|
|
453
|
+
n(this, "hasSuccessfulValue", !1);
|
|
452
454
|
n(this, "argumentUnsubscribers");
|
|
455
|
+
n(this, "pollingUnsubscribers", []);
|
|
456
|
+
n(this, "polling");
|
|
457
|
+
n(this, "pollingScheduler");
|
|
458
|
+
n(this, "pollingHandle", null);
|
|
453
459
|
n(this, "requestId", 0);
|
|
454
460
|
n(this, "abortController", null);
|
|
455
461
|
/** Exposed for deterministic tests; consumers should use refresh()/retry(). */
|
|
456
462
|
n(this, "_activeRequest", null);
|
|
457
|
-
this.handler = s, this.args = { ...i }, this.keepPreviousValue = u, this.lastSuccessfulValue = void 0, this.argumentUnsubscribers = Object.values(this.args).map(
|
|
458
|
-
(
|
|
459
|
-
this.refresh(
|
|
463
|
+
this.handler = s, this.args = { ...i }, this.keepPreviousValue = u, this.polling = a, this.pollingScheduler = (a == null ? void 0 : a.scheduler) ?? J, this.lastSuccessfulValue = void 0, this.argumentUnsubscribers = Object.values(this.args).map(
|
|
464
|
+
(l) => l.subscribe(({ event: d }) => {
|
|
465
|
+
this.refresh(d);
|
|
460
466
|
}, { emitCurrent: !1 })
|
|
461
|
-
), o && (this._activeRequest = this.refresh("initial fetch"));
|
|
467
|
+
), a != null && this.initializePolling(a), o && (this._activeRequest = this.refresh("initial fetch")), this.scheduleNextPoll();
|
|
462
468
|
}
|
|
463
469
|
get argumentValues() {
|
|
464
470
|
return Object.fromEntries(
|
|
@@ -470,73 +476,139 @@ class X extends w {
|
|
|
470
476
|
if (this.isDisposed) return Promise.resolve(void 0);
|
|
471
477
|
const s = ++this.requestId;
|
|
472
478
|
(p = this.abortController) == null || p.abort();
|
|
473
|
-
const i =
|
|
479
|
+
const i = Y();
|
|
474
480
|
this.abortController = i;
|
|
475
|
-
const o = e instanceof b ? e : null, u = o ? "query arguments changed" : e,
|
|
481
|
+
const o = e instanceof b ? e : null, u = o ? "query arguments changed" : e, a = this.keepPreviousValue ? this.lastSuccessfulValue : void 0;
|
|
476
482
|
this.setSnapshot({
|
|
477
|
-
value:
|
|
478
|
-
fetchState:
|
|
483
|
+
value: a,
|
|
484
|
+
fetchState: h.Loading,
|
|
479
485
|
error: null,
|
|
480
486
|
cause: u,
|
|
481
487
|
parentEvent: o
|
|
482
488
|
});
|
|
483
|
-
const c = this.createEvent("query fetch", o, this.argumentValues),
|
|
489
|
+
const c = this.createEvent("query fetch", o, this.argumentValues), f = Promise.resolve().then(() => this.handler.fetch(this.argumentValues, {
|
|
484
490
|
signal: i.signal,
|
|
485
491
|
event: c
|
|
486
|
-
})).then((
|
|
492
|
+
})).then((l) => {
|
|
487
493
|
if (this.isCurrentRequest(s, i))
|
|
488
|
-
return this.lastSuccessfulValue =
|
|
489
|
-
value:
|
|
490
|
-
fetchState:
|
|
494
|
+
return this.lastSuccessfulValue = l, this.hasSuccessfulValue = !0, this.setSnapshot({
|
|
495
|
+
value: l,
|
|
496
|
+
fetchState: h.Ready,
|
|
491
497
|
error: null,
|
|
492
498
|
cause: "query succeeded",
|
|
493
499
|
parentEvent: c
|
|
494
|
-
}),
|
|
495
|
-
}).catch((
|
|
496
|
-
!this.isCurrentRequest(s, i) ||
|
|
500
|
+
}), l;
|
|
501
|
+
}).catch((l) => {
|
|
502
|
+
!this.isCurrentRequest(s, i) || Z(l) || this.setSnapshot({
|
|
497
503
|
value: this.keepPreviousValue ? this.lastSuccessfulValue : void 0,
|
|
498
|
-
fetchState:
|
|
499
|
-
error:
|
|
504
|
+
fetchState: h.Error,
|
|
505
|
+
error: l,
|
|
500
506
|
cause: "query failed",
|
|
501
507
|
parentEvent: c
|
|
502
508
|
});
|
|
503
509
|
}).finally(() => {
|
|
504
510
|
this.isCurrentRequest(s, i) && (this.abortController = null, this._activeRequest = null);
|
|
505
511
|
});
|
|
506
|
-
return this._activeRequest =
|
|
512
|
+
return this._activeRequest = f, f;
|
|
507
513
|
}
|
|
508
514
|
retry(e = "retry") {
|
|
509
515
|
return this.refresh(e);
|
|
510
516
|
}
|
|
517
|
+
abort(e = "query aborted") {
|
|
518
|
+
if (this.isDisposed || this.abortController == null) return;
|
|
519
|
+
this.requestId += 1, this.abortController.abort(), this.abortController = null, this._activeRequest = null;
|
|
520
|
+
const s = e instanceof b ? e : null;
|
|
521
|
+
this.setSnapshot({
|
|
522
|
+
value: this.hasSuccessfulValue ? this.lastSuccessfulValue : void 0,
|
|
523
|
+
fetchState: this.hasSuccessfulValue ? h.Ready : h.Initial,
|
|
524
|
+
error: null,
|
|
525
|
+
cause: s == null ? e : "query aborted",
|
|
526
|
+
parentEvent: s
|
|
527
|
+
});
|
|
528
|
+
}
|
|
511
529
|
dispose() {
|
|
512
530
|
var e;
|
|
513
531
|
if (!this.isDisposed) {
|
|
514
|
-
this.requestId += 1, (e = this.abortController) == null || e.abort(), this.abortController = null, this._activeRequest = null;
|
|
532
|
+
this.requestId += 1, (e = this.abortController) == null || e.abort(), this.abortController = null, this._activeRequest = null, this.cancelScheduledPoll();
|
|
515
533
|
for (const s of this.argumentUnsubscribers) s();
|
|
516
|
-
this.argumentUnsubscribers = []
|
|
534
|
+
this.argumentUnsubscribers = [];
|
|
535
|
+
for (const s of this.pollingUnsubscribers) s();
|
|
536
|
+
this.pollingUnsubscribers = [], super.dispose();
|
|
517
537
|
}
|
|
518
538
|
}
|
|
539
|
+
initializePolling(e) {
|
|
540
|
+
for (const s of [e.intervalMs, e.enabled])
|
|
541
|
+
T(s) && this.pollingUnsubscribers.push(s.subscribe(() => {
|
|
542
|
+
q(y(e.intervalMs)), Q(y(e.enabled, !0)), this.cancelScheduledPoll(), this.scheduleNextPoll();
|
|
543
|
+
}, { emitCurrent: !1 }));
|
|
544
|
+
}
|
|
545
|
+
scheduleNextPoll() {
|
|
546
|
+
if (this.isDisposed || this.polling == null || this.pollingHandle != null || !y(this.polling.enabled, !0)) return;
|
|
547
|
+
const e = y(this.polling.intervalMs);
|
|
548
|
+
q(e), this.pollingHandle = this.pollingScheduler.schedule(() => {
|
|
549
|
+
this.pollingHandle = null, this.scheduleNextPoll(), this._activeRequest == null && this.refresh("poll");
|
|
550
|
+
}, e);
|
|
551
|
+
}
|
|
552
|
+
cancelScheduledPoll() {
|
|
553
|
+
this.pollingHandle != null && (this.pollingScheduler.cancel(this.pollingHandle), this.pollingHandle = null);
|
|
554
|
+
}
|
|
519
555
|
isCurrentRequest(e, s) {
|
|
520
556
|
return !this.isDisposed && e === this.requestId && s === this.abortController && !s.signal.aborted;
|
|
521
557
|
}
|
|
522
558
|
}
|
|
523
|
-
|
|
524
|
-
|
|
559
|
+
const J = {
|
|
560
|
+
schedule(t, r) {
|
|
561
|
+
const e = Reflect.get(globalThis, "setTimeout");
|
|
562
|
+
if (typeof e != "function")
|
|
563
|
+
throw new Error("LiveQuery polling requires an injected scheduler in this runtime");
|
|
564
|
+
return Reflect.apply(e, globalThis, [t, r]);
|
|
565
|
+
},
|
|
566
|
+
cancel(t) {
|
|
567
|
+
const r = Reflect.get(globalThis, "clearTimeout");
|
|
568
|
+
typeof r == "function" && Reflect.apply(r, globalThis, [t]);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
function T(t) {
|
|
572
|
+
return t != null && (typeof t == "object" || typeof t == "function") && typeof Reflect.get(t, "get") == "function" && typeof Reflect.get(t, "subscribe") == "function";
|
|
573
|
+
}
|
|
574
|
+
function O(t, r) {
|
|
575
|
+
if (typeof t != "number" && typeof t != "boolean" && !T(t))
|
|
576
|
+
throw new TypeError(`LiveQuery polling ${r} must be a value or emitter`);
|
|
577
|
+
}
|
|
578
|
+
function K(t) {
|
|
579
|
+
if (t == null || typeof t != "object" || Array.isArray(t))
|
|
580
|
+
throw new TypeError("LiveQuery polling options must be an object");
|
|
581
|
+
if (O(t.intervalMs, "intervalMs"), t.enabled !== void 0 && O(t.enabled, "enabled"), q(y(t.intervalMs)), Q(y(t.enabled, !0)), t.scheduler != null && (typeof t.scheduler.schedule != "function" || typeof t.scheduler.cancel != "function"))
|
|
582
|
+
throw new TypeError("LiveQuery polling scheduler must implement schedule() and cancel()");
|
|
583
|
+
}
|
|
584
|
+
function y(t, r) {
|
|
585
|
+
return t === void 0 ? r : T(t) ? t.get() : t;
|
|
586
|
+
}
|
|
587
|
+
function q(t) {
|
|
588
|
+
if (!Number.isFinite(t) || t <= 0)
|
|
589
|
+
throw new RangeError("LiveQuery polling intervalMs must be a finite positive number");
|
|
590
|
+
}
|
|
591
|
+
function Q(t) {
|
|
592
|
+
if (typeof t != "boolean")
|
|
593
|
+
throw new TypeError("LiveQuery polling enabled must be a boolean");
|
|
594
|
+
}
|
|
595
|
+
function X(t) {
|
|
596
|
+
if (t == null || typeof t != "object" || Array.isArray(t))
|
|
525
597
|
throw new TypeError("LiveQuery args must be a named record of emitters");
|
|
526
|
-
for (const [
|
|
598
|
+
for (const [r, e] of Object.entries(t))
|
|
527
599
|
if (e == null || typeof Reflect.get(e, "get") != "function" || typeof Reflect.get(e, "subscribe") != "function")
|
|
528
|
-
throw new TypeError(`LiveQuery argument ${
|
|
600
|
+
throw new TypeError(`LiveQuery argument ${r} must be an emitter`);
|
|
529
601
|
}
|
|
530
|
-
function
|
|
531
|
-
const
|
|
532
|
-
if (typeof
|
|
602
|
+
function Y() {
|
|
603
|
+
const t = Reflect.get(globalThis, "AbortController");
|
|
604
|
+
if (typeof t != "function")
|
|
533
605
|
throw new Error("LiveQuery requires AbortController in this runtime");
|
|
534
|
-
return new
|
|
606
|
+
return new t();
|
|
535
607
|
}
|
|
536
|
-
function
|
|
537
|
-
return
|
|
608
|
+
function Z(t) {
|
|
609
|
+
return t instanceof Error && t.name === "AbortError";
|
|
538
610
|
}
|
|
539
|
-
class
|
|
611
|
+
class pe extends U {
|
|
540
612
|
constructor(e, s, i = {}) {
|
|
541
613
|
if (typeof e != "string" || e.length === 0)
|
|
542
614
|
throw new TypeError("QueryArg name must be a non-empty string");
|
|
@@ -564,120 +636,277 @@ class Y extends C {
|
|
|
564
636
|
this.isDisposed || ((e = this.sourceUnsubscribe) == null || e.call(this), this.sourceUnsubscribe = null, super.dispose());
|
|
565
637
|
}
|
|
566
638
|
}
|
|
567
|
-
class
|
|
568
|
-
fetch(
|
|
639
|
+
class ee {
|
|
640
|
+
fetch(r, e = {}) {
|
|
569
641
|
throw new Error("fetch() must be implemented");
|
|
570
642
|
}
|
|
571
643
|
}
|
|
572
|
-
class
|
|
644
|
+
class te extends Error {
|
|
573
645
|
constructor(e) {
|
|
574
646
|
super(`HTTP ${e ?? "unknown"}`);
|
|
575
647
|
n(this, "status");
|
|
576
648
|
this.name = "HttpError", this.status = e;
|
|
577
649
|
}
|
|
578
650
|
}
|
|
579
|
-
class
|
|
651
|
+
class re extends ee {
|
|
580
652
|
constructor(e) {
|
|
581
653
|
super();
|
|
582
654
|
n(this, "url");
|
|
583
655
|
n(this, "baseUrl");
|
|
584
656
|
n(this, "fetchImplementation");
|
|
585
657
|
n(this, "serialize");
|
|
658
|
+
n(this, "parseResult");
|
|
586
659
|
n(this, "trace");
|
|
587
660
|
const s = typeof e == "string" ? { url: e } : e;
|
|
588
661
|
if (s == null || typeof s != "object")
|
|
589
662
|
throw new TypeError("RestQueryHandler requires a URL or options object");
|
|
590
663
|
if (typeof s.url != "string" || s.url.length === 0)
|
|
591
664
|
throw new TypeError("RestQueryHandler url must be a non-empty string");
|
|
592
|
-
if (this.url = s.url, this.baseUrl = s.baseUrl ??
|
|
665
|
+
if (this.url = s.url, this.baseUrl = s.baseUrl ?? ie(), this.fetchImplementation = s.fetch ?? oe(), this.serialize = s.serialize ?? se, this.parseResult = s.parseResult, this.trace = s.trace ?? !1, typeof this.fetchImplementation != "function")
|
|
593
666
|
throw new TypeError("RestQueryHandler requires an injected fetch implementation");
|
|
594
667
|
if (typeof this.serialize != "function")
|
|
595
668
|
throw new TypeError("RestQueryHandler serialize must be a function");
|
|
669
|
+
if (this.parseResult !== void 0 && typeof this.parseResult != "function")
|
|
670
|
+
throw new TypeError("RestQueryHandler parseResult must be a function");
|
|
596
671
|
}
|
|
597
672
|
async fetch(e, s = {}) {
|
|
598
673
|
if (e == null || typeof e != "object" || Array.isArray(e))
|
|
599
674
|
throw new TypeError("REST query args must be a named record");
|
|
600
|
-
const i =
|
|
675
|
+
const i = ne(this.url, this.baseUrl), o = this.serialize(i, e) ?? i, u = P();
|
|
601
676
|
if (!(o instanceof u))
|
|
602
677
|
throw new TypeError("REST serializer must mutate or return a URL");
|
|
603
|
-
const
|
|
604
|
-
if (this.trace ||
|
|
605
|
-
const
|
|
678
|
+
const a = s.event ?? null;
|
|
679
|
+
if (this.trace || a || w.hasSubscribers) {
|
|
680
|
+
const l = new b({
|
|
606
681
|
owner: this,
|
|
607
682
|
purpose: "REST fetch",
|
|
608
683
|
value: o.toString(),
|
|
609
684
|
cause: "fetch called",
|
|
610
|
-
parent:
|
|
685
|
+
parent: a
|
|
611
686
|
});
|
|
612
|
-
|
|
687
|
+
a || w.emit(l);
|
|
613
688
|
}
|
|
614
|
-
const c = s.signal === void 0 ? {} : { signal: s.signal },
|
|
615
|
-
if (!(
|
|
616
|
-
|
|
689
|
+
const c = s.signal === void 0 ? {} : { signal: s.signal }, f = await this.fetchImplementation(o.toString(), c);
|
|
690
|
+
if (!(f != null && f.ok)) throw new te(f == null ? void 0 : f.status);
|
|
691
|
+
const p = await f.json();
|
|
692
|
+
return this.parseResult == null ? p : this.parseResult(p);
|
|
617
693
|
}
|
|
618
694
|
}
|
|
619
|
-
function
|
|
620
|
-
for (const [e, s] of Object.entries(
|
|
621
|
-
|
|
622
|
-
return
|
|
695
|
+
function se(t, r) {
|
|
696
|
+
for (const [e, s] of Object.entries(r))
|
|
697
|
+
L(t.searchParams, e, s);
|
|
698
|
+
return t;
|
|
623
699
|
}
|
|
624
|
-
function
|
|
700
|
+
function L(t, r, e) {
|
|
625
701
|
if (e !== void 0) {
|
|
626
702
|
if (e === null) {
|
|
627
|
-
|
|
703
|
+
t.append(r, "");
|
|
628
704
|
return;
|
|
629
705
|
}
|
|
630
706
|
if (Array.isArray(e)) {
|
|
631
|
-
for (const s of e)
|
|
707
|
+
for (const s of e) L(t, r, s);
|
|
632
708
|
return;
|
|
633
709
|
}
|
|
634
710
|
if (typeof e == "object") {
|
|
635
|
-
|
|
711
|
+
t.append(r, JSON.stringify(e));
|
|
636
712
|
return;
|
|
637
713
|
}
|
|
638
|
-
|
|
714
|
+
t.append(r, String(e));
|
|
639
715
|
}
|
|
640
716
|
}
|
|
641
|
-
function
|
|
642
|
-
const e =
|
|
717
|
+
function ne(t, r) {
|
|
718
|
+
const e = P();
|
|
643
719
|
try {
|
|
644
|
-
return new e(
|
|
720
|
+
return new e(t);
|
|
645
721
|
} catch (s) {
|
|
646
|
-
if (
|
|
647
|
-
throw new TypeError(`Relative REST URL requires baseUrl: ${
|
|
648
|
-
return new e(
|
|
722
|
+
if (r == null)
|
|
723
|
+
throw new TypeError(`Relative REST URL requires baseUrl: ${t}`, { cause: s });
|
|
724
|
+
return new e(t, r);
|
|
649
725
|
}
|
|
650
726
|
}
|
|
651
|
-
function
|
|
652
|
-
const
|
|
653
|
-
if (typeof
|
|
727
|
+
function P() {
|
|
728
|
+
const t = Reflect.get(globalThis, "URL");
|
|
729
|
+
if (typeof t != "function")
|
|
654
730
|
throw new Error("RestQueryHandler requires URL in this runtime");
|
|
655
|
-
return
|
|
731
|
+
return t;
|
|
656
732
|
}
|
|
657
|
-
function
|
|
658
|
-
const
|
|
659
|
-
if (
|
|
733
|
+
function ie() {
|
|
734
|
+
const t = Reflect.get(globalThis, "location");
|
|
735
|
+
if (t == null || typeof t != "object" && typeof t != "function")
|
|
660
736
|
return;
|
|
661
|
-
const
|
|
662
|
-
return typeof
|
|
737
|
+
const r = Reflect.get(t, "href");
|
|
738
|
+
return typeof r == "string" ? r : void 0;
|
|
663
739
|
}
|
|
664
|
-
function
|
|
740
|
+
function oe() {
|
|
665
741
|
return Reflect.get(globalThis, "fetch");
|
|
666
742
|
}
|
|
743
|
+
class ue {
|
|
744
|
+
constructor(r) {
|
|
745
|
+
n(this, "handler");
|
|
746
|
+
n(this, "queryOptions");
|
|
747
|
+
if (r == null || typeof r != "object" || Array.isArray(r))
|
|
748
|
+
throw new TypeError("QueryEndpoint options must be an object");
|
|
749
|
+
if (r.handler == null || typeof r.handler.fetch != "function")
|
|
750
|
+
throw new TypeError("QueryEndpoint handler must implement fetch()");
|
|
751
|
+
const e = r.query ?? {};
|
|
752
|
+
E(e), this.handler = r.handler, this.queryOptions = Object.freeze({ ...e }), Object.freeze(this);
|
|
753
|
+
}
|
|
754
|
+
open(r, e = {}) {
|
|
755
|
+
return A(r), E(e), new I({
|
|
756
|
+
handler: this.handler,
|
|
757
|
+
args: r,
|
|
758
|
+
...this.queryOptions,
|
|
759
|
+
...e
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
function de(t) {
|
|
764
|
+
return new ue(t);
|
|
765
|
+
}
|
|
766
|
+
class ce {
|
|
767
|
+
constructor(r) {
|
|
768
|
+
n(this, "handler");
|
|
769
|
+
n(this, "queryOptions");
|
|
770
|
+
if (r == null || typeof r != "object" || Array.isArray(r))
|
|
771
|
+
throw new TypeError("RestEndpoint options must be an object");
|
|
772
|
+
const { query: e = {}, ...s } = r;
|
|
773
|
+
E(e, "RestEndpoint query options"), this.handler = new re(s), this.queryOptions = Object.freeze({ ...e }), Object.freeze(this);
|
|
774
|
+
}
|
|
775
|
+
open(r, e = {}) {
|
|
776
|
+
return A(r), E(e), new I({
|
|
777
|
+
handler: this.handler,
|
|
778
|
+
args: r,
|
|
779
|
+
...this.queryOptions,
|
|
780
|
+
...e
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
function be(t) {
|
|
785
|
+
return new ce(t);
|
|
786
|
+
}
|
|
787
|
+
class le {
|
|
788
|
+
constructor(r) {
|
|
789
|
+
n(this, "apply");
|
|
790
|
+
n(this, "purpose");
|
|
791
|
+
if (r == null || typeof r != "object" || Array.isArray(r))
|
|
792
|
+
throw new TypeError("DerivedEndpoint options must be an object");
|
|
793
|
+
if (typeof r.apply != "function")
|
|
794
|
+
throw new TypeError("DerivedEndpoint apply must be a function");
|
|
795
|
+
this.apply = r.apply, this.purpose = r.purpose ?? "derived endpoint", Object.freeze(this);
|
|
796
|
+
}
|
|
797
|
+
open(r) {
|
|
798
|
+
return new ae({
|
|
799
|
+
...r,
|
|
800
|
+
apply: this.apply,
|
|
801
|
+
purpose: r.purpose ?? this.purpose
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
function ye(t) {
|
|
806
|
+
return new le(t);
|
|
807
|
+
}
|
|
808
|
+
class ae extends g {
|
|
809
|
+
constructor(e) {
|
|
810
|
+
if (e == null || typeof e != "object" || Array.isArray(e))
|
|
811
|
+
throw new TypeError("DerivedLiveResult options must be an object");
|
|
812
|
+
if (A(e.args), !z(e.source))
|
|
813
|
+
throw new TypeError("DerivedLiveResult source must be an emitter");
|
|
814
|
+
if (typeof e.apply != "function")
|
|
815
|
+
throw new TypeError("DerivedLiveResult apply must be a function");
|
|
816
|
+
super(void 0, {
|
|
817
|
+
fetchState: h.Initial,
|
|
818
|
+
error: null,
|
|
819
|
+
owner: e.owner,
|
|
820
|
+
...e.purpose === void 0 ? {} : { purpose: e.purpose },
|
|
821
|
+
...e.trace === void 0 ? {} : { trace: e.trace }
|
|
822
|
+
});
|
|
823
|
+
n(this, "source");
|
|
824
|
+
n(this, "args");
|
|
825
|
+
n(this, "apply");
|
|
826
|
+
n(this, "unsubscribers", []);
|
|
827
|
+
n(this, "lastSuccessfulValue");
|
|
828
|
+
this.source = e.source, this.args = { ...e.args }, this.apply = e.apply, this.lastSuccessfulValue = void 0;
|
|
829
|
+
const s = [
|
|
830
|
+
this.source,
|
|
831
|
+
...Object.values(this.args)
|
|
832
|
+
];
|
|
833
|
+
this.unsubscribers = s.map((i) => i.subscribe(({ event: o }) => {
|
|
834
|
+
this.recompute(o);
|
|
835
|
+
}, { emitCurrent: !1 })), this.recompute(null, !1);
|
|
836
|
+
}
|
|
837
|
+
dispose() {
|
|
838
|
+
if (!this.isDisposed) {
|
|
839
|
+
for (const e of this.unsubscribers) e();
|
|
840
|
+
this.unsubscribers = [], super.dispose();
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
recompute(e, s = !0) {
|
|
844
|
+
var p;
|
|
845
|
+
const i = [
|
|
846
|
+
this.source,
|
|
847
|
+
...Object.values(this.args)
|
|
848
|
+
], o = ((p = i.find((l) => l.getError() != null)) == null ? void 0 : p.getError()) ?? null;
|
|
849
|
+
let u = j(
|
|
850
|
+
i.map((l) => l.getFetchState())
|
|
851
|
+
);
|
|
852
|
+
const a = this.source.get();
|
|
853
|
+
let c = this.lastSuccessfulValue, f = o;
|
|
854
|
+
try {
|
|
855
|
+
const l = Object.fromEntries(
|
|
856
|
+
Object.entries(this.args).map(([d, v]) => [d, v.get()])
|
|
857
|
+
);
|
|
858
|
+
c = this.apply(a, l), this.lastSuccessfulValue = c;
|
|
859
|
+
} catch (l) {
|
|
860
|
+
f = l, u = h.Error;
|
|
861
|
+
}
|
|
862
|
+
if (o != null && (f = o, u = h.Error), !s) {
|
|
863
|
+
this.value = c, this.fetchState = u, this.error = f;
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
this.setSnapshot({
|
|
867
|
+
value: c,
|
|
868
|
+
fetchState: u,
|
|
869
|
+
error: f,
|
|
870
|
+
cause: "derived endpoint source changed",
|
|
871
|
+
parentEvent: e
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
function E(t, r = "Endpoint query options") {
|
|
876
|
+
if (t == null || typeof t != "object" || Array.isArray(t))
|
|
877
|
+
throw new TypeError(`${r} must be an object`);
|
|
878
|
+
}
|
|
879
|
+
function A(t) {
|
|
880
|
+
if (t == null || typeof t != "object" || Array.isArray(t))
|
|
881
|
+
throw new TypeError("Endpoint args must be a named record of emitters");
|
|
882
|
+
for (const [r, e] of Object.entries(t))
|
|
883
|
+
if (!z(e))
|
|
884
|
+
throw new TypeError(`Endpoint argument ${r} must be an emitter`);
|
|
885
|
+
}
|
|
886
|
+
function z(t) {
|
|
887
|
+
return t != null && (typeof t == "object" || typeof t == "function") && typeof Reflect.get(t, "get") == "function" && typeof Reflect.get(t, "getFetchState") == "function" && typeof Reflect.get(t, "getError") == "function" && typeof Reflect.get(t, "subscribe") == "function";
|
|
888
|
+
}
|
|
667
889
|
export {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
890
|
+
fe as AsyncCommand,
|
|
891
|
+
M as AsyncCommandConcurrencyError,
|
|
892
|
+
g as BaseEmitter,
|
|
893
|
+
D as DerivedEmitter,
|
|
894
|
+
le as DerivedEndpoint,
|
|
895
|
+
ae as DerivedLiveResult,
|
|
896
|
+
U as Emitter,
|
|
673
897
|
b as EventBubble,
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
898
|
+
w as EventBus,
|
|
899
|
+
h as FetchState,
|
|
900
|
+
S as FetchStateValues,
|
|
901
|
+
I as LiveQuery,
|
|
902
|
+
pe as QueryArg,
|
|
903
|
+
ue as QueryEndpoint,
|
|
904
|
+
ee as QueryHandler,
|
|
905
|
+
ce as RestEndpoint,
|
|
906
|
+
re as RestQueryHandler,
|
|
907
|
+
j as combineFetchStates,
|
|
908
|
+
ye as derivedEndpoint,
|
|
909
|
+
de as queryEndpoint,
|
|
910
|
+
be as restEndpoint
|
|
682
911
|
};
|
|
683
912
|
//# sourceMappingURL=index.js.map
|