@sylwellsoftware/glue 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,30 +1,449 @@
1
- var g = Object.defineProperty;
2
- var v = (t, s, e) => s in t ? g(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
3
- var n = (t, s, e) => v(t, typeof s != "symbol" ? s + "" : s, e);
4
- import { B as w, F as p, a as y, E, b } from "./emitter-upM7NC28.js";
5
- import { D as _, c as x, d as D } from "./emitter-upM7NC28.js";
6
- class H extends w {
1
+ var U = Object.defineProperty;
2
+ var V = (r, t, e) => t in r ? U(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var n = (r, t, e) => V(r, typeof t != "symbol" ? t + "" : t, e);
4
+ let I = 1;
5
+ class b {
6
+ constructor(t = {}) {
7
+ n(this, "id");
8
+ n(this, "timestamp");
9
+ n(this, "purpose");
10
+ n(this, "cause");
11
+ n(this, "value");
12
+ n(this, "parent");
13
+ n(this, "parentBubble");
14
+ n(this, "children", []);
15
+ n(this, "ownerType");
16
+ n(this, "ownerRef");
17
+ n(this, "strongOwner");
18
+ var s;
19
+ if (t == null || typeof t != "object" || Array.isArray(t))
20
+ throw new TypeError("EventBubble options must be an object");
21
+ this.id = `event-${I++}`, this.timestamp = t.timestamp ?? Date.now(), this.purpose = t.purpose ?? "unspecified", this.cause = t.cause ?? null, this.value = t.value, this.parent = t.parent ?? null, this.parentBubble = this.parent;
22
+ const e = t.owner;
23
+ this.ownerType = e == null ? null : z(e) ?? typeof e, D(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
+ }
25
+ get owner() {
26
+ var t;
27
+ return ((t = this.ownerRef) == null ? void 0 : t.deref()) ?? this.strongOwner;
28
+ }
29
+ registerChild(t) {
30
+ if (!(t instanceof b))
31
+ throw new TypeError("EventBubble children must be EventBubble instances");
32
+ this.children.includes(t) || this.children.push(t);
33
+ }
34
+ }
35
+ function D(r) {
36
+ return typeof r == "object" && r !== null || typeof r == "function";
37
+ }
38
+ function z(r) {
39
+ const t = Reflect.get(r, "constructor");
40
+ if (t == null || typeof t != "object" && typeof t != "function")
41
+ return;
42
+ const e = Reflect.get(t, "name");
43
+ return typeof e == "string" ? e : void 0;
44
+ }
45
+ const m = /* @__PURE__ */ new Set();
46
+ function v(r) {
47
+ if (typeof r != "function")
48
+ throw new TypeError("EventBus.subscribe requires a function");
49
+ m.add(r);
50
+ let t = !0;
51
+ return () => {
52
+ t && (t = !1, m.delete(r));
53
+ };
54
+ }
55
+ function S(r) {
56
+ for (const t of [...m]) t(r);
57
+ }
58
+ const y = Object.freeze({
59
+ subscribe: v,
60
+ emit: S,
61
+ emitBubble: S,
62
+ registerBubbleGraph(r) {
63
+ if (r == null || typeof r.addBubble != "function")
64
+ throw new TypeError("registerBubbleGraph requires an addBubble() method");
65
+ return v((t) => r.addBubble(t));
66
+ },
67
+ get hasSubscribers() {
68
+ return m.size > 0;
69
+ },
70
+ get subscriberCount() {
71
+ return m.size;
72
+ }
73
+ }), a = Object.freeze({
74
+ Error: "error",
75
+ Loading: "loading",
76
+ Initial: "initial",
77
+ Ready: "ready"
78
+ }), g = /* @__PURE__ */ new Map([
79
+ [a.Ready, 1],
80
+ [a.Initial, 2],
81
+ [a.Loading, 3],
82
+ [a.Error, 4]
83
+ ]);
84
+ function q(r) {
85
+ let t = a.Ready;
86
+ for (const e of r) {
87
+ if (!g.has(e))
88
+ throw new TypeError(`Unknown fetch state: ${String(e)}`);
89
+ if ((g.get(e) ?? 0) > (g.get(t) ?? 0) && (t = e), t === a.Error) break;
90
+ }
91
+ return t;
92
+ }
93
+ class w {
94
+ constructor(t, e = {}) {
95
+ n(this, "subscribers", /* @__PURE__ */ new Set());
96
+ n(this, "value");
97
+ n(this, "fetchState");
98
+ n(this, "error");
99
+ n(this, "equals");
100
+ n(this, "isDisposed", !1);
101
+ n(this, "owner");
102
+ n(this, "purpose");
103
+ n(this, "trace");
104
+ if (e == null || typeof e != "object" || Array.isArray(e))
105
+ throw new TypeError("Emitter options must be an object");
106
+ if (this.value = t, this.fetchState = e.fetchState ?? a.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
+ throw new TypeError("Emitter equals option must be a function");
108
+ E(this.fetchState);
109
+ }
110
+ subscribe(t, e = {}) {
111
+ if (this.isDisposed) throw new Error("Cannot subscribe to a disposed emitter");
112
+ if (typeof t != "function")
113
+ throw new TypeError("subscribe requires a function");
114
+ if (e == null || typeof e != "object" || Array.isArray(e))
115
+ throw new TypeError("subscribe options must be an object");
116
+ const { emitCurrent: s = !0, parentEvent: i = null } = e;
117
+ if (this.subscribers.add(t), s) {
118
+ const u = this.createEvent("subscribed", i, this.value);
119
+ t(this.notification(u));
120
+ }
121
+ let o = !0;
122
+ return () => {
123
+ o && (o = !1, this.subscribers.delete(t));
124
+ };
125
+ }
126
+ subscribeFutureValues(t) {
127
+ return this.subscribe(t, { emitCurrent: !1 });
128
+ }
129
+ get() {
130
+ return this.value;
131
+ }
132
+ getError() {
133
+ return this.error;
134
+ }
135
+ getFetchState() {
136
+ return this.fetchState;
137
+ }
138
+ get disposed() {
139
+ return this.isDisposed;
140
+ }
141
+ get subscriberCount() {
142
+ return this.subscribers.size;
143
+ }
144
+ map(t, e = {}) {
145
+ if (typeof t != "function") throw new TypeError("map requires a function");
146
+ return new R(
147
+ [this],
148
+ ([s]) => t(s),
149
+ {
150
+ ...e,
151
+ owner: e.owner ?? this.owner,
152
+ purpose: e.purpose ?? `${this.purpose}:map`,
153
+ trace: e.trace ?? this.trace
154
+ }
155
+ );
156
+ }
157
+ mapEach(t, e = {}) {
158
+ if (typeof t != "function") throw new TypeError("mapEach requires a function");
159
+ return new R([this], ([s]) => {
160
+ if (s == null) return s;
161
+ if (!Array.isArray(s))
162
+ throw new TypeError("mapEach source value must be an array");
163
+ return s.map((o, u) => o == null ? o : t(o, u));
164
+ }, {
165
+ ...e,
166
+ purpose: e.purpose ?? `${this.purpose}:mapEach`
167
+ });
168
+ }
169
+ dispose() {
170
+ this.isDisposed || (this.isDisposed = !0, this.subscribers.clear());
171
+ }
172
+ notification(t = null) {
173
+ return Object.freeze({
174
+ value: this.value,
175
+ fetchState: this.fetchState,
176
+ error: this.error,
177
+ event: t
178
+ });
179
+ }
180
+ notify(t = null) {
181
+ if (this.isDisposed) return;
182
+ const e = this.notification(t);
183
+ for (const s of [...this.subscribers]) s(e);
184
+ }
185
+ setSnapshot(t = {}) {
186
+ if (this.isDisposed) return !1;
187
+ const e = Object.hasOwn(t, "value") ? t.value : this.value, s = t.fetchState ?? this.fetchState, i = Object.hasOwn(t, "error") ? t.error : this.error, o = t.cause ?? "state changed", u = t.parentEvent ?? null;
188
+ if (E(s), !(!this.equals(this.value, e) || this.fetchState !== s || !Object.is(this.error, i))) return !1;
189
+ this.value = e, this.fetchState = s, this.error = i;
190
+ const c = this.createEvent(o, u, e);
191
+ return this.notify(c), !0;
192
+ }
193
+ createEvent(t, e = null, s = this.value) {
194
+ if (!this.trace && !e && !y.hasSubscribers) return null;
195
+ const i = new b({
196
+ owner: this.owner ?? this,
197
+ purpose: this.purpose,
198
+ value: s,
199
+ cause: t,
200
+ parent: e
201
+ });
202
+ return e || y.emit(i), i;
203
+ }
204
+ }
205
+ class R extends w {
206
+ constructor(e, s, i = {}) {
207
+ const { computeFetchState: o = q, ...u } = i;
208
+ super(void 0, {
209
+ ...u,
210
+ fetchState: a.Initial,
211
+ error: null
212
+ });
213
+ n(this, "sources");
214
+ n(this, "sourceUnsubscribers", []);
215
+ n(this, "compute");
216
+ n(this, "computeFetchState");
217
+ this.sources = [], this.compute = s, this.computeFetchState = o, this.setSourcesAndCompute(e, s, { notify: !1 });
218
+ }
219
+ setSourcesAndCompute(e, s = this.compute, i = {}) {
220
+ if (this.isDisposed) throw new Error("Cannot update a disposed derived emitter");
221
+ if (!Array.isArray(e) || e.some((o) => !Q(o)))
222
+ throw new TypeError("DerivedEmitter sources must be an array of emitters");
223
+ if (typeof s != "function")
224
+ throw new TypeError("DerivedEmitter compute must be a function");
225
+ return this.releaseSources(), this.sources = [...e], this.compute = s, this.sourceUnsubscribers = this.sources.map(
226
+ (o) => o.subscribe(({ event: u }) => this.recompute(u), { emitCurrent: !1 })
227
+ ), this.recompute(i.parentEvent ?? null, i.notify ?? !0), this;
228
+ }
229
+ dispose() {
230
+ this.isDisposed || (this.releaseSources(), super.dispose());
231
+ }
232
+ releaseSources() {
233
+ for (const e of this.sourceUnsubscribers) e();
234
+ this.sourceUnsubscribers = [];
235
+ }
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, j) => ({ sourceIndex: j, error: d.getError() })).filter((d) => d.error != null);
238
+ let h, c = null;
239
+ try {
240
+ h = this.compute(i);
241
+ } catch (d) {
242
+ c = d, h = void 0;
243
+ }
244
+ const l = c == null ? u : [...u, { sourceIndex: null, error: c }], p = L(this.error, l);
245
+ let f = this.computeFetchState(o);
246
+ if (E(f), (c != null || u.length > 0) && (f = a.Error), !s) {
247
+ this.value = h, this.fetchState = f, this.error = p;
248
+ return;
249
+ }
250
+ this.setSnapshot({
251
+ value: h,
252
+ fetchState: f,
253
+ error: p,
254
+ cause: "derived source changed",
255
+ parentEvent: e
256
+ });
257
+ }
258
+ }
259
+ function L(r, t) {
260
+ return t.length === 0 ? null : r != null && r.length === t.length && r.every((e, s) => {
261
+ var i, o;
262
+ return e.sourceIndex === ((i = t[s]) == null ? void 0 : i.sourceIndex) && Object.is(e.error, (o = t[s]) == null ? void 0 : o.error);
263
+ }) ? r : Object.freeze(t.map((e) => Object.freeze(e)));
264
+ }
265
+ function Q(r) {
266
+ return (typeof r != "object" || r === null) && typeof r != "function" ? !1 : typeof Reflect.get(r, "get") == "function" && typeof Reflect.get(r, "getFetchState") == "function" && typeof Reflect.get(r, "getError") == "function" && typeof Reflect.get(r, "subscribe") == "function";
267
+ }
268
+ function E(r) {
269
+ q([r]);
270
+ }
271
+ class C extends w {
272
+ constructor(t, e = {}) {
273
+ super(t, e);
274
+ }
275
+ setWithState(t, e = a.Ready, s = null, i = null) {
276
+ const o = i instanceof b ? i : null, u = o ? "set called" : i ?? "set called";
277
+ return this.setSnapshot({ value: t, fetchState: e, error: s, cause: u, parentEvent: o });
278
+ }
279
+ set(t, e = null) {
280
+ return this.setWithState(t, a.Ready, null, e);
281
+ }
282
+ }
283
+ class B extends Error {
284
+ constructor() {
285
+ super("AsyncCommand is already running"), this.name = "AsyncCommandConcurrencyError";
286
+ }
287
+ }
288
+ class K extends w {
289
+ constructor(e) {
290
+ O(e);
291
+ const {
292
+ execute: s,
293
+ concurrency: i = "ignore",
294
+ mapError: o = (l) => l,
295
+ owner: u,
296
+ purpose: h = "async command",
297
+ trace: c
298
+ } = e;
299
+ if (F(i), typeof o != "function")
300
+ throw new TypeError("AsyncCommand mapError must be a function");
301
+ super(void 0, {
302
+ fetchState: a.Initial,
303
+ error: null,
304
+ owner: u,
305
+ purpose: h,
306
+ ...c === void 0 ? {} : { trace: c }
307
+ });
308
+ n(this, "execute");
309
+ n(this, "concurrency");
310
+ n(this, "isRunning");
311
+ n(this, "mapError");
312
+ n(this, "runningEmitter");
313
+ n(this, "requestId", 0);
314
+ n(this, "abortController", null);
315
+ n(this, "lastSuccessfulValue");
316
+ n(this, "hasSuccessfulValue", !1);
317
+ /** Exposed for deterministic tests; consumers should use run()/abort(). */
318
+ n(this, "_activeRequest", null);
319
+ this.execute = s, this.concurrency = i, this.mapError = o, this.runningEmitter = new C(!1, {
320
+ owner: u ?? this,
321
+ purpose: `${h}:running`,
322
+ ...c === void 0 ? {} : { trace: c }
323
+ }), this.isRunning = this.runningEmitter;
324
+ }
325
+ run(e, s = "command run") {
326
+ var p;
327
+ if (this.isDisposed) return Promise.resolve(void 0);
328
+ if (this._activeRequest != null) {
329
+ if (this.concurrency === "ignore") return this._activeRequest;
330
+ if (this.concurrency === "reject")
331
+ return Promise.reject(new B());
332
+ (p = this.abortController) == null || p.abort();
333
+ }
334
+ const i = ++this.requestId, o = k();
335
+ this.abortController = o;
336
+ const u = s instanceof b ? s : null, h = u ? "parent command requested" : s;
337
+ this.setSnapshot({
338
+ value: this.lastSuccessfulValue,
339
+ fetchState: a.Loading,
340
+ error: null,
341
+ cause: h,
342
+ parentEvent: u
343
+ });
344
+ const c = this.createEvent("command execute", u, e);
345
+ this.runningEmitter.set(!0, c ?? h);
346
+ const l = Promise.resolve().then(() => this.execute(e, {
347
+ signal: o.signal,
348
+ event: c
349
+ })).then((f) => {
350
+ if (this.isCurrentRequest(i, o))
351
+ return this.lastSuccessfulValue = f, this.hasSuccessfulValue = !0, this.setSnapshot({
352
+ value: f,
353
+ fetchState: a.Ready,
354
+ error: null,
355
+ cause: "command succeeded",
356
+ parentEvent: c
357
+ }), f;
358
+ }).catch((f) => {
359
+ this.isCurrentRequest(i, o) && this.setSnapshot({
360
+ value: this.lastSuccessfulValue,
361
+ fetchState: a.Error,
362
+ error: this.mapCommandError(f),
363
+ cause: "command failed",
364
+ parentEvent: c
365
+ });
366
+ }).finally(() => {
367
+ this.isCurrentRequest(i, o) && (this.abortController = null, this._activeRequest = null, this.runningEmitter.set(!1, c ?? "command settled"));
368
+ });
369
+ return this._activeRequest = l, l;
370
+ }
371
+ abort(e = "command aborted") {
372
+ if (this.isDisposed || this.abortController == null) return !1;
373
+ const s = e instanceof b ? e : null, i = s ? "parent command aborted" : e;
374
+ return this.requestId += 1, this.abortController.abort(), this.abortController = null, this._activeRequest = null, this.runningEmitter.set(!1, s ?? i), this.setSnapshot({
375
+ value: this.lastSuccessfulValue,
376
+ fetchState: this.hasSuccessfulValue ? a.Ready : a.Initial,
377
+ error: null,
378
+ cause: i,
379
+ parentEvent: s
380
+ }), !0;
381
+ }
382
+ reset(e = "command reset") {
383
+ if (this.isDisposed) return;
384
+ this.abort(e), this.lastSuccessfulValue = void 0, this.hasSuccessfulValue = !1;
385
+ const s = e instanceof b ? e : null;
386
+ this.setSnapshot({
387
+ value: void 0,
388
+ fetchState: a.Initial,
389
+ error: null,
390
+ cause: s ? "parent command reset" : e,
391
+ parentEvent: s
392
+ });
393
+ }
394
+ dispose() {
395
+ var e;
396
+ this.isDisposed || (this.requestId += 1, (e = this.abortController) == null || e.abort(), this.abortController = null, this._activeRequest = null, this.runningEmitter.set(!1, "command disposed"), this.runningEmitter.dispose(), super.dispose());
397
+ }
398
+ isCurrentRequest(e, s) {
399
+ return !this.isDisposed && e === this.requestId && s === this.abortController && !s.signal.aborted;
400
+ }
401
+ mapCommandError(e) {
402
+ try {
403
+ return this.mapError(e);
404
+ } catch (s) {
405
+ return s;
406
+ }
407
+ }
408
+ }
409
+ function O(r) {
410
+ if (r == null || typeof r != "object" || Array.isArray(r))
411
+ throw new TypeError("AsyncCommand options must be an object");
412
+ if (typeof r.execute != "function")
413
+ throw new TypeError("AsyncCommand execute must be a function");
414
+ }
415
+ function F(r) {
416
+ if (r !== "ignore" && r !== "replace" && r !== "reject")
417
+ throw new TypeError(`Unknown AsyncCommand concurrency policy: ${r}`);
418
+ }
419
+ function k() {
420
+ const r = Reflect.get(globalThis, "AbortController");
421
+ if (typeof r != "function")
422
+ throw new Error("AsyncCommand requires AbortController in this runtime");
423
+ return new r();
424
+ }
425
+ class X extends w {
7
426
  constructor(e) {
8
427
  if (e == null || typeof e != "object" || Array.isArray(e))
9
428
  throw new TypeError("LiveQuery options must be an object");
10
429
  const {
11
- handler: r,
430
+ handler: s,
12
431
  args: i = {},
13
432
  autoFetch: o = !0,
14
- keepPreviousValue: f = !0,
15
- owner: l,
433
+ keepPreviousValue: u = !0,
434
+ owner: h,
16
435
  purpose: c = "live query",
17
- trace: u
436
+ trace: l
18
437
  } = e;
19
- if (r == null || typeof r.fetch != "function")
438
+ if (s == null || typeof s.fetch != "function")
20
439
  throw new TypeError("LiveQuery handler must implement fetch()");
21
- R(i);
440
+ P(i);
22
441
  super(void 0, {
23
- fetchState: p.Initial,
442
+ fetchState: a.Initial,
24
443
  error: null,
25
- owner: l,
444
+ owner: h,
26
445
  purpose: c,
27
- ...u === void 0 ? {} : { trace: u }
446
+ ...l === void 0 ? {} : { trace: l }
28
447
  });
29
448
  n(this, "handler");
30
449
  n(this, "args");
@@ -35,56 +454,56 @@ class H extends w {
35
454
  n(this, "abortController", null);
36
455
  /** Exposed for deterministic tests; consumers should use refresh()/retry(). */
37
456
  n(this, "_activeRequest", null);
38
- this.handler = r, this.args = { ...i }, this.keepPreviousValue = f, this.lastSuccessfulValue = void 0, this.argumentUnsubscribers = Object.values(this.args).map(
39
- (h) => h.subscribe(({ event: a }) => {
40
- this.refresh(a);
457
+ this.handler = s, this.args = { ...i }, this.keepPreviousValue = u, this.lastSuccessfulValue = void 0, this.argumentUnsubscribers = Object.values(this.args).map(
458
+ (p) => p.subscribe(({ event: f }) => {
459
+ this.refresh(f);
41
460
  }, { emitCurrent: !1 })
42
461
  ), o && (this._activeRequest = this.refresh("initial fetch"));
43
462
  }
44
463
  get argumentValues() {
45
464
  return Object.fromEntries(
46
- Object.entries(this.args).map(([e, r]) => [e, r.get()])
465
+ Object.entries(this.args).map(([e, s]) => [e, s.get()])
47
466
  );
48
467
  }
49
468
  refresh(e = "refresh") {
50
- var h;
469
+ var p;
51
470
  if (this.isDisposed) return Promise.resolve(void 0);
52
- const r = ++this.requestId;
53
- (h = this.abortController) == null || h.abort();
54
- const i = q();
471
+ const s = ++this.requestId;
472
+ (p = this.abortController) == null || p.abort();
473
+ const i = _();
55
474
  this.abortController = i;
56
- const o = e instanceof y ? e : null, f = o ? "query arguments changed" : e, l = this.keepPreviousValue ? this.lastSuccessfulValue : void 0;
475
+ const o = e instanceof b ? e : null, u = o ? "query arguments changed" : e, h = this.keepPreviousValue ? this.lastSuccessfulValue : void 0;
57
476
  this.setSnapshot({
58
- value: l,
59
- fetchState: p.Loading,
477
+ value: h,
478
+ fetchState: a.Loading,
60
479
  error: null,
61
- cause: f,
480
+ cause: u,
62
481
  parentEvent: o
63
482
  });
64
- const c = this.createEvent("query fetch", o, this.argumentValues), u = Promise.resolve().then(() => this.handler.fetch(this.argumentValues, {
483
+ const c = this.createEvent("query fetch", o, this.argumentValues), l = Promise.resolve().then(() => this.handler.fetch(this.argumentValues, {
65
484
  signal: i.signal,
66
485
  event: c
67
- })).then((a) => {
68
- if (this.isCurrentRequest(r, i))
69
- return this.lastSuccessfulValue = a, this.setSnapshot({
70
- value: a,
71
- fetchState: p.Ready,
486
+ })).then((f) => {
487
+ if (this.isCurrentRequest(s, i))
488
+ return this.lastSuccessfulValue = f, this.setSnapshot({
489
+ value: f,
490
+ fetchState: a.Ready,
72
491
  error: null,
73
492
  cause: "query succeeded",
74
493
  parentEvent: c
75
- }), a;
76
- }).catch((a) => {
77
- !this.isCurrentRequest(r, i) || S(a) || this.setSnapshot({
494
+ }), f;
495
+ }).catch((f) => {
496
+ !this.isCurrentRequest(s, i) || H(f) || this.setSnapshot({
78
497
  value: this.keepPreviousValue ? this.lastSuccessfulValue : void 0,
79
- fetchState: p.Error,
80
- error: a,
498
+ fetchState: a.Error,
499
+ error: f,
81
500
  cause: "query failed",
82
501
  parentEvent: c
83
502
  });
84
503
  }).finally(() => {
85
- this.isCurrentRequest(r, i) && (this.abortController = null, this._activeRequest = null);
504
+ this.isCurrentRequest(s, i) && (this.abortController = null, this._activeRequest = null);
86
505
  });
87
- return this._activeRequest = u, u;
506
+ return this._activeRequest = l, l;
88
507
  }
89
508
  retry(e = "retry") {
90
509
  return this.refresh(e);
@@ -93,45 +512,45 @@ class H extends w {
93
512
  var e;
94
513
  if (!this.isDisposed) {
95
514
  this.requestId += 1, (e = this.abortController) == null || e.abort(), this.abortController = null, this._activeRequest = null;
96
- for (const r of this.argumentUnsubscribers) r();
515
+ for (const s of this.argumentUnsubscribers) s();
97
516
  this.argumentUnsubscribers = [], super.dispose();
98
517
  }
99
518
  }
100
- isCurrentRequest(e, r) {
101
- return !this.isDisposed && e === this.requestId && r === this.abortController && !r.signal.aborted;
519
+ isCurrentRequest(e, s) {
520
+ return !this.isDisposed && e === this.requestId && s === this.abortController && !s.signal.aborted;
102
521
  }
103
522
  }
104
- function R(t) {
105
- if (t == null || typeof t != "object" || Array.isArray(t))
523
+ function P(r) {
524
+ if (r == null || typeof r != "object" || Array.isArray(r))
106
525
  throw new TypeError("LiveQuery args must be a named record of emitters");
107
- for (const [s, e] of Object.entries(t))
526
+ for (const [t, e] of Object.entries(r))
108
527
  if (e == null || typeof Reflect.get(e, "get") != "function" || typeof Reflect.get(e, "subscribe") != "function")
109
- throw new TypeError(`LiveQuery argument ${s} must be an emitter`);
528
+ throw new TypeError(`LiveQuery argument ${t} must be an emitter`);
110
529
  }
111
- function q() {
112
- const t = Reflect.get(globalThis, "AbortController");
113
- if (typeof t != "function")
530
+ function _() {
531
+ const r = Reflect.get(globalThis, "AbortController");
532
+ if (typeof r != "function")
114
533
  throw new Error("LiveQuery requires AbortController in this runtime");
115
- return new t();
534
+ return new r();
116
535
  }
117
- function S(t) {
118
- return t instanceof Error && t.name === "AbortError";
536
+ function H(r) {
537
+ return r instanceof Error && r.name === "AbortError";
119
538
  }
120
- class z extends E {
121
- constructor(e, r, i = {}) {
539
+ class Y extends C {
540
+ constructor(e, s, i = {}) {
122
541
  if (typeof e != "string" || e.length === 0)
123
542
  throw new TypeError("QueryArg name must be a non-empty string");
124
- if (r == null || typeof r.get != "function" || typeof r.subscribe != "function")
543
+ if (s == null || typeof s.get != "function" || typeof s.subscribe != "function")
125
544
  throw new TypeError("QueryArg source must be an emitter");
126
- super(r.get(), {
545
+ super(s.get(), {
127
546
  ...i,
128
- fetchState: r.getFetchState(),
129
- error: r.getError(),
547
+ fetchState: s.getFetchState(),
548
+ error: s.getError(),
130
549
  purpose: i.purpose ?? `query argument: ${e}`
131
550
  });
132
551
  n(this, "name");
133
552
  n(this, "sourceUnsubscribe");
134
- this.name = e, this.sourceUnsubscribe = r.subscribe((o) => {
553
+ this.name = e, this.sourceUnsubscribe = s.subscribe((o) => {
135
554
  this.setWithState(
136
555
  o.value,
137
556
  o.fetchState,
@@ -145,19 +564,19 @@ class z extends E {
145
564
  this.isDisposed || ((e = this.sourceUnsubscribe) == null || e.call(this), this.sourceUnsubscribe = null, super.dispose());
146
565
  }
147
566
  }
148
- class T {
149
- fetch(s, e = {}) {
567
+ class $ {
568
+ fetch(t, e = {}) {
150
569
  throw new Error("fetch() must be implemented");
151
570
  }
152
571
  }
153
- class U extends Error {
572
+ class x extends Error {
154
573
  constructor(e) {
155
574
  super(`HTTP ${e ?? "unknown"}`);
156
575
  n(this, "status");
157
576
  this.name = "HttpError", this.status = e;
158
577
  }
159
578
  }
160
- class I extends T {
579
+ class Z extends $ {
161
580
  constructor(e) {
162
581
  super();
163
582
  n(this, "url");
@@ -165,98 +584,100 @@ class I extends T {
165
584
  n(this, "fetchImplementation");
166
585
  n(this, "serialize");
167
586
  n(this, "trace");
168
- const r = typeof e == "string" ? { url: e } : e;
169
- if (r == null || typeof r != "object")
587
+ const s = typeof e == "string" ? { url: e } : e;
588
+ if (s == null || typeof s != "object")
170
589
  throw new TypeError("RestQueryHandler requires a URL or options object");
171
- if (typeof r.url != "string" || r.url.length === 0)
590
+ if (typeof s.url != "string" || s.url.length === 0)
172
591
  throw new TypeError("RestQueryHandler url must be a non-empty string");
173
- if (this.url = r.url, this.baseUrl = r.baseUrl ?? V(), this.fetchImplementation = r.fetch ?? j(), this.serialize = r.serialize ?? A, this.trace = r.trace ?? !1, typeof this.fetchImplementation != "function")
592
+ if (this.url = s.url, this.baseUrl = s.baseUrl ?? N(), this.fetchImplementation = s.fetch ?? J(), this.serialize = s.serialize ?? W, this.trace = s.trace ?? !1, typeof this.fetchImplementation != "function")
174
593
  throw new TypeError("RestQueryHandler requires an injected fetch implementation");
175
594
  if (typeof this.serialize != "function")
176
595
  throw new TypeError("RestQueryHandler serialize must be a function");
177
596
  }
178
- async fetch(e, r = {}) {
597
+ async fetch(e, s = {}) {
179
598
  if (e == null || typeof e != "object" || Array.isArray(e))
180
599
  throw new TypeError("REST query args must be a named record");
181
- const i = Q(this.url, this.baseUrl), o = this.serialize(i, e) ?? i, f = d();
182
- if (!(o instanceof f))
600
+ const i = G(this.url, this.baseUrl), o = this.serialize(i, e) ?? i, u = A();
601
+ if (!(o instanceof u))
183
602
  throw new TypeError("REST serializer must mutate or return a URL");
184
- const l = r.event ?? null;
185
- if (this.trace || l || b.hasSubscribers) {
186
- const h = new y({
603
+ const h = s.event ?? null;
604
+ if (this.trace || h || y.hasSubscribers) {
605
+ const p = new b({
187
606
  owner: this,
188
607
  purpose: "REST fetch",
189
608
  value: o.toString(),
190
609
  cause: "fetch called",
191
- parent: l
610
+ parent: h
192
611
  });
193
- l || b.emit(h);
612
+ h || y.emit(p);
194
613
  }
195
- const c = r.signal === void 0 ? {} : { signal: r.signal }, u = await this.fetchImplementation(o.toString(), c);
196
- if (!(u != null && u.ok)) throw new U(u == null ? void 0 : u.status);
197
- return await u.json();
614
+ const c = s.signal === void 0 ? {} : { signal: s.signal }, l = await this.fetchImplementation(o.toString(), c);
615
+ if (!(l != null && l.ok)) throw new x(l == null ? void 0 : l.status);
616
+ return await l.json();
198
617
  }
199
618
  }
200
- function A(t, s) {
201
- for (const [e, r] of Object.entries(s))
202
- m(t.searchParams, e, r);
203
- return t;
619
+ function W(r, t) {
620
+ for (const [e, s] of Object.entries(t))
621
+ T(r.searchParams, e, s);
622
+ return r;
204
623
  }
205
- function m(t, s, e) {
624
+ function T(r, t, e) {
206
625
  if (e !== void 0) {
207
626
  if (e === null) {
208
- t.append(s, "");
627
+ r.append(t, "");
209
628
  return;
210
629
  }
211
630
  if (Array.isArray(e)) {
212
- for (const r of e) m(t, s, r);
631
+ for (const s of e) T(r, t, s);
213
632
  return;
214
633
  }
215
634
  if (typeof e == "object") {
216
- t.append(s, JSON.stringify(e));
635
+ r.append(t, JSON.stringify(e));
217
636
  return;
218
637
  }
219
- t.append(s, String(e));
638
+ r.append(t, String(e));
220
639
  }
221
640
  }
222
- function Q(t, s) {
223
- const e = d();
641
+ function G(r, t) {
642
+ const e = A();
224
643
  try {
225
- return new e(t);
226
- } catch (r) {
227
- if (s == null)
228
- throw new TypeError(`Relative REST URL requires baseUrl: ${t}`, { cause: r });
229
- return new e(t, s);
644
+ return new e(r);
645
+ } catch (s) {
646
+ if (t == null)
647
+ throw new TypeError(`Relative REST URL requires baseUrl: ${r}`, { cause: s });
648
+ return new e(r, t);
230
649
  }
231
650
  }
232
- function d() {
233
- const t = Reflect.get(globalThis, "URL");
234
- if (typeof t != "function")
651
+ function A() {
652
+ const r = Reflect.get(globalThis, "URL");
653
+ if (typeof r != "function")
235
654
  throw new Error("RestQueryHandler requires URL in this runtime");
236
- return t;
655
+ return r;
237
656
  }
238
- function V() {
239
- const t = Reflect.get(globalThis, "location");
240
- if (t == null || typeof t != "object" && typeof t != "function")
657
+ function N() {
658
+ const r = Reflect.get(globalThis, "location");
659
+ if (r == null || typeof r != "object" && typeof r != "function")
241
660
  return;
242
- const s = Reflect.get(t, "href");
243
- return typeof s == "string" ? s : void 0;
661
+ const t = Reflect.get(r, "href");
662
+ return typeof t == "string" ? t : void 0;
244
663
  }
245
- function j() {
664
+ function J() {
246
665
  return Reflect.get(globalThis, "fetch");
247
666
  }
248
667
  export {
668
+ K as AsyncCommand,
669
+ B as AsyncCommandConcurrencyError,
249
670
  w as BaseEmitter,
250
- _ as DerivedEmitter,
251
- E as Emitter,
252
- y as EventBubble,
253
- b as EventBus,
254
- p as FetchState,
255
- x as FetchStateValues,
256
- H as LiveQuery,
257
- z as QueryArg,
258
- T as QueryHandler,
259
- I as RestQueryHandler,
260
- D as combineFetchStates
671
+ R as DerivedEmitter,
672
+ C as Emitter,
673
+ b as EventBubble,
674
+ y as EventBus,
675
+ a as FetchState,
676
+ g as FetchStateValues,
677
+ X as LiveQuery,
678
+ Y as QueryArg,
679
+ $ as QueryHandler,
680
+ Z as RestQueryHandler,
681
+ q as combineFetchStates
261
682
  };
262
683
  //# sourceMappingURL=index.js.map