@asgard-js/core 0.2.7 → 0.2.8

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.mjs CHANGED
@@ -148,21 +148,21 @@ function Ge(r, e, t) {
148
148
  };
149
149
  }
150
150
  function a(l, y) {
151
- n[l] && (o[l] = function(v) {
151
+ n[l] && (o[l] = function(p) {
152
152
  return new Promise(function(S, w) {
153
- i.push([l, v, S, w]) > 1 || c(l, v);
153
+ i.push([l, p, S, w]) > 1 || c(l, p);
154
154
  });
155
155
  }, y && (o[l] = y(o[l])));
156
156
  }
157
157
  function c(l, y) {
158
158
  try {
159
159
  u(n[l](y));
160
- } catch (v) {
161
- p(i[0][3], v);
160
+ } catch (p) {
161
+ v(i[0][3], p);
162
162
  }
163
163
  }
164
164
  function u(l) {
165
- l.value instanceof P ? Promise.resolve(l.value.v).then(f, h) : p(i[0][2], l);
165
+ l.value instanceof P ? Promise.resolve(l.value.v).then(f, h) : v(i[0][2], l);
166
166
  }
167
167
  function f(l) {
168
168
  c("next", l);
@@ -170,7 +170,7 @@ function Ge(r, e, t) {
170
170
  function h(l) {
171
171
  c("throw", l);
172
172
  }
173
- function p(l, y) {
173
+ function v(l, y) {
174
174
  l(y), i.shift(), i.length && c(i[0][0], i[0][1]);
175
175
  }
176
176
  }
@@ -233,8 +233,8 @@ var U = (function() {
233
233
  var u = c.value;
234
234
  u.remove(this);
235
235
  }
236
- } catch (v) {
237
- e = { error: v };
236
+ } catch (p) {
237
+ e = { error: p };
238
238
  } finally {
239
239
  try {
240
240
  c && !c.done && (t = a.return) && t.call(a);
@@ -248,26 +248,26 @@ var U = (function() {
248
248
  if (m(f))
249
249
  try {
250
250
  f();
251
- } catch (v) {
252
- i = v instanceof q ? v.errors : [v];
251
+ } catch (p) {
252
+ i = p instanceof q ? p.errors : [p];
253
253
  }
254
254
  var h = this._finalizers;
255
255
  if (h) {
256
256
  this._finalizers = null;
257
257
  try {
258
- for (var p = M(h), l = p.next(); !l.done; l = p.next()) {
258
+ for (var v = M(h), l = v.next(); !l.done; l = v.next()) {
259
259
  var y = l.value;
260
260
  try {
261
261
  te(y);
262
- } catch (v) {
263
- i = i ?? [], v instanceof q ? i = R(R([], L(i)), L(v.errors)) : i.push(v);
262
+ } catch (p) {
263
+ i = i ?? [], p instanceof q ? i = R(R([], L(i)), L(p.errors)) : i.push(p);
264
264
  }
265
265
  }
266
- } catch (v) {
267
- n = { error: v };
266
+ } catch (p) {
267
+ n = { error: p };
268
268
  } finally {
269
269
  try {
270
- l && !l.done && (o = p.return) && o.call(p);
270
+ l && !l.done && (o = v.return) && o.call(v);
271
271
  } finally {
272
272
  if (n) throw n.error;
273
273
  }
@@ -306,7 +306,7 @@ var U = (function() {
306
306
  return e.closed = !0, e;
307
307
  })(), r;
308
308
  })(), he = U.EMPTY;
309
- function pe(r) {
309
+ function ve(r) {
310
310
  return r instanceof U || r && "closed" in r && m(r.remove) && m(r.add) && m(r.unsubscribe);
311
311
  }
312
312
  function te(r) {
@@ -325,7 +325,7 @@ var Fe = {
325
325
  },
326
326
  delegate: void 0
327
327
  };
328
- function ve(r) {
328
+ function pe(r) {
329
329
  Ve.setTimeout(function() {
330
330
  throw r;
331
331
  });
@@ -339,7 +339,7 @@ var z = (function(r) {
339
339
  O(e, r);
340
340
  function e(t) {
341
341
  var n = r.call(this) || this;
342
- return n.isStopped = !1, t ? (n.destination = t, pe(t) && t.add(n)) : n.destination = Be, n;
342
+ return n.isStopped = !1, t ? (n.destination = t, ve(t) && t.add(n)) : n.destination = Be, n;
343
343
  }
344
344
  return e.create = function(t, n, o) {
345
345
  return new X(t, n, o);
@@ -410,7 +410,7 @@ var z = (function(r) {
410
410
  return e;
411
411
  })(z);
412
412
  function $(r) {
413
- ve(r);
413
+ pe(r);
414
414
  }
415
415
  function Ke(r) {
416
416
  throw r;
@@ -501,7 +501,7 @@ function We(r) {
501
501
  return r && m(r.next) && m(r.error) && m(r.complete);
502
502
  }
503
503
  function Xe(r) {
504
- return r && r instanceof z || We(r) && pe(r);
504
+ return r && r instanceof z || We(r) && ve(r);
505
505
  }
506
506
  function Je(r) {
507
507
  return m(r?.lift);
@@ -889,7 +889,7 @@ function ut(r) {
889
889
  e.closed || (e.next(t), e.complete());
890
890
  }, function(t) {
891
891
  return e.error(t);
892
- }).then(null, ve);
892
+ }).then(null, pe);
893
893
  });
894
894
  }
895
895
  function lt(r) {
@@ -996,10 +996,10 @@ function Me(r, e) {
996
996
  function ht(r, e) {
997
997
  return x(r).pipe(Me(e), Pe(e));
998
998
  }
999
- function pt(r, e) {
999
+ function vt(r, e) {
1000
1000
  return x(r).pipe(Me(e), Pe(e));
1001
1001
  }
1002
- function vt(r, e) {
1002
+ function pt(r, e) {
1003
1003
  return new g(function(t) {
1004
1004
  var n = 0;
1005
1005
  return e.schedule(function() {
@@ -1048,9 +1048,9 @@ function bt(r, e) {
1048
1048
  if (Ee(r))
1049
1049
  return ht(r, e);
1050
1050
  if (Se(r))
1051
- return vt(r, e);
1052
- if (we(r))
1053
1051
  return pt(r, e);
1052
+ if (we(r))
1053
+ return vt(r, e);
1054
1054
  if (Ie(r))
1055
1055
  return Le(r, e);
1056
1056
  if (Ce(r))
@@ -1131,9 +1131,9 @@ function Lt(r, e, t) {
1131
1131
  ae(e, function() {
1132
1132
  for (var o = r.length, i = new Array(o), s = o, a = o, c = function(f) {
1133
1133
  ae(e, function() {
1134
- var h = ee(r[f], e), p = !1;
1134
+ var h = ee(r[f], e), v = !1;
1135
1135
  h.subscribe(I(n, function(l) {
1136
- i[f] = l, p || (p = !0, a--), a || n.next(t(i.slice()));
1136
+ i[f] = l, v || (v = !0, a--), a || n.next(t(i.slice()));
1137
1137
  }, function() {
1138
1138
  --s || n.complete();
1139
1139
  }));
@@ -1147,14 +1147,14 @@ function ae(r, e, t) {
1147
1147
  r ? C(t, r, e) : e();
1148
1148
  }
1149
1149
  function Rt(r, e, t, n, o, i, s, a) {
1150
- var c = [], u = 0, f = 0, h = !1, p = function() {
1150
+ var c = [], u = 0, f = 0, h = !1, v = function() {
1151
1151
  h && !c.length && !u && e.complete();
1152
- }, l = function(v) {
1153
- return u < n ? y(v) : c.push(v);
1154
- }, y = function(v) {
1152
+ }, l = function(p) {
1153
+ return u < n ? y(p) : c.push(p);
1154
+ }, y = function(p) {
1155
1155
  u++;
1156
1156
  var S = !1;
1157
- x(t(v, f++)).subscribe(I(e, function(w) {
1157
+ x(t(p, f++)).subscribe(I(e, function(w) {
1158
1158
  e.next(w);
1159
1159
  }, function() {
1160
1160
  S = !0;
@@ -1167,14 +1167,14 @@ function Rt(r, e, t, n, o, i, s, a) {
1167
1167
  s || y(_);
1168
1168
  }; c.length && u < n; )
1169
1169
  w();
1170
- p();
1170
+ v();
1171
1171
  } catch (_) {
1172
1172
  e.error(_);
1173
1173
  }
1174
1174
  }));
1175
1175
  };
1176
1176
  return r.subscribe(I(e, l, function() {
1177
- h = !0, p();
1177
+ h = !0, v();
1178
1178
  })), function() {
1179
1179
  };
1180
1180
  }
@@ -1237,26 +1237,26 @@ function Nt(r) {
1237
1237
  var t = e.count, n = t === void 0 ? 1 / 0 : t, o = e.delay, i = e.resetOnSuccess, s = i === void 0 ? !1 : i;
1238
1238
  return n <= 0 ? G : T(function(a, c) {
1239
1239
  var u = 0, f, h = function() {
1240
- var p = !1;
1240
+ var v = !1;
1241
1241
  f = a.subscribe(I(c, function(l) {
1242
1242
  s && (u = 0), c.next(l);
1243
1243
  }, void 0, function(l) {
1244
1244
  if (u++ < n) {
1245
1245
  var y = function() {
1246
- f ? (f.unsubscribe(), f = null, h()) : p = !0;
1246
+ f ? (f.unsubscribe(), f = null, h()) : v = !0;
1247
1247
  };
1248
1248
  if (o != null) {
1249
- var v = typeof o == "number" ? Re(o) : x(o(l, u)), S = I(c, function() {
1249
+ var p = typeof o == "number" ? Re(o) : x(o(l, u)), S = I(c, function() {
1250
1250
  S.unsubscribe(), y();
1251
1251
  }, function() {
1252
1252
  c.complete();
1253
1253
  });
1254
- v.subscribe(S);
1254
+ p.subscribe(S);
1255
1255
  } else
1256
1256
  y();
1257
1257
  } else
1258
1258
  c.error(l);
1259
- })), p && (f.unsubscribe(), f = null, h());
1259
+ })), v && (f.unsubscribe(), f = null, h());
1260
1260
  };
1261
1261
  h();
1262
1262
  });
@@ -1351,17 +1351,17 @@ var Kt = function(r, e) {
1351
1351
  const J = "text/event-stream", Bt = 1e3, ue = "last-event-id";
1352
1352
  function Yt(r, e) {
1353
1353
  var { signal: t, headers: n, onopen: o, onmessage: i, onclose: s, onerror: a, openWhenHidden: c, fetch: u } = e, f = Kt(e, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
1354
- return new Promise((h, p) => {
1354
+ return new Promise((h, v) => {
1355
1355
  const l = Object.assign({}, n);
1356
1356
  l.accept || (l.accept = J);
1357
1357
  let y;
1358
- function v() {
1358
+ function p() {
1359
1359
  y.abort(), document.hidden || F();
1360
1360
  }
1361
- c || document.addEventListener("visibilitychange", v);
1361
+ c || document.addEventListener("visibilitychange", p);
1362
1362
  let S = Bt, w = 0;
1363
1363
  function _() {
1364
- document.removeEventListener("visibilitychange", v), window.clearTimeout(w), y.abort();
1364
+ document.removeEventListener("visibilitychange", p), window.clearTimeout(w), y.abort();
1365
1365
  }
1366
1366
  t?.addEventListener("abort", () => {
1367
1367
  _(), h();
@@ -1383,7 +1383,7 @@ function Yt(r, e) {
1383
1383
  const A = (V = a?.(k)) !== null && V !== void 0 ? V : S;
1384
1384
  window.clearTimeout(w), w = window.setTimeout(F, A);
1385
1385
  } catch (A) {
1386
- _(), p(A);
1386
+ _(), v(A);
1387
1387
  }
1388
1388
  }
1389
1389
  }
@@ -1418,18 +1418,18 @@ function Xt(r) {
1418
1418
  * https://github.com/Azure/fetch-event-source/issues/17#issuecomment-1525904929
1419
1419
  */
1420
1420
  openWhenHidden: !0,
1421
- onopen: async (p) => {
1422
- p.ok ? c = p.headers.get("X-Trace-Id") ?? void 0 : (s.error(p), a.abort());
1421
+ onopen: async (v) => {
1422
+ v.ok ? c = v.headers.get("X-Trace-Id") ?? void 0 : (s.error(v), a.abort());
1423
1423
  },
1424
- onmessage: (p) => {
1425
- const l = JSON.parse(p.data);
1424
+ onmessage: (v) => {
1425
+ const l = JSON.parse(v.data);
1426
1426
  c ? l.traceId = c : l.requestId && (l.traceId = l.requestId, c || (c = l.requestId)), s.next(l);
1427
1427
  },
1428
1428
  onclose: () => {
1429
1429
  s.complete();
1430
1430
  },
1431
- onerror: (p) => {
1432
- throw s.error(p), a.abort(), p;
1431
+ onerror: (v) => {
1432
+ throw s.error(v), a.abort(), v;
1433
1433
  }
1434
1434
  }), () => {
1435
1435
  a.abort();
@@ -1748,6 +1748,20 @@ class ke {
1748
1748
  }))
1749
1749
  ).subscribe(this.statesObserver);
1750
1750
  }
1751
+ /**
1752
+ * Resolves payload by executing it if it's a function, otherwise returns as-is.
1753
+ */
1754
+ resolvePayload(e) {
1755
+ if (typeof e == "function")
1756
+ try {
1757
+ return e();
1758
+ } catch (t) {
1759
+ throw new Error(
1760
+ `Failed to resolve payload function: ${t instanceof Error ? t.message : String(t)}`
1761
+ );
1762
+ }
1763
+ return e;
1764
+ }
1751
1765
  fetchSse(e, t) {
1752
1766
  return new Promise((n, o) => {
1753
1767
  this.isConnecting$.next(!0), this.client.fetchSse(e, {
@@ -1778,7 +1792,7 @@ class ke {
1778
1792
  customChannelId: this.customChannelId,
1779
1793
  customMessageId: this.customMessageId,
1780
1794
  text: e?.text || "",
1781
- payload: e?.payload
1795
+ payload: this.resolvePayload(e?.payload)
1782
1796
  },
1783
1797
  t
1784
1798
  );
@@ -1800,7 +1814,7 @@ class ke {
1800
1814
  action: B.NONE,
1801
1815
  customChannelId: this.customChannelId,
1802
1816
  customMessageId: o,
1803
- payload: e?.payload,
1817
+ payload: this.resolvePayload(e?.payload),
1804
1818
  text: n,
1805
1819
  blobIds: e?.blobIds
1806
1820
  },