ironflock 1.2.4 → 1.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
@@ -1,21 +1,21 @@
1
- import C from "autobahn";
2
- function P(d) {
1
+ import O from "autobahn";
2
+ function L(d) {
3
3
  return d && d.__esModule && Object.prototype.hasOwnProperty.call(d, "default") ? d.default : d;
4
4
  }
5
- var I = { exports: {} }, N;
6
- function L() {
7
- return N || (N = 1, (function(d) {
5
+ var $ = { exports: {} }, C;
6
+ function j() {
7
+ return C || (C = 1, (function(d) {
8
8
  var r = Object.prototype.hasOwnProperty, s = "~";
9
9
  function o() {
10
10
  }
11
11
  Object.create && (o.prototype = /* @__PURE__ */ Object.create(null), new o().__proto__ || (s = !1));
12
- function l(a, e, n) {
12
+ function c(a, e, n) {
13
13
  this.fn = a, this.context = e, this.once = n || !1;
14
14
  }
15
- function i(a, e, n, c, f) {
15
+ function i(a, e, n, l, h) {
16
16
  if (typeof n != "function")
17
17
  throw new TypeError("The listener must be a function");
18
- var v = new l(n, c || a, f), g = s ? s + e : e;
18
+ var v = new c(n, l || a, h), g = s ? s + e : e;
19
19
  return a._events[g] ? a._events[g].fn ? a._events[g] = [a._events[g], v] : a._events[g].push(v) : (a._events[g] = v, a._eventsCount++), a;
20
20
  }
21
21
  function u(a, e) {
@@ -25,118 +25,126 @@ function L() {
25
25
  this._events = new o(), this._eventsCount = 0;
26
26
  }
27
27
  t.prototype.eventNames = function() {
28
- var e = [], n, c;
28
+ var e = [], n, l;
29
29
  if (this._eventsCount === 0) return e;
30
- for (c in n = this._events)
31
- r.call(n, c) && e.push(s ? c.slice(1) : c);
30
+ for (l in n = this._events)
31
+ r.call(n, l) && e.push(s ? l.slice(1) : l);
32
32
  return Object.getOwnPropertySymbols ? e.concat(Object.getOwnPropertySymbols(n)) : e;
33
33
  }, t.prototype.listeners = function(e) {
34
- var n = s ? s + e : e, c = this._events[n];
35
- if (!c) return [];
36
- if (c.fn) return [c.fn];
37
- for (var f = 0, v = c.length, g = new Array(v); f < v; f++)
38
- g[f] = c[f].fn;
34
+ var n = s ? s + e : e, l = this._events[n];
35
+ if (!l) return [];
36
+ if (l.fn) return [l.fn];
37
+ for (var h = 0, v = l.length, g = new Array(v); h < v; h++)
38
+ g[h] = l[h].fn;
39
39
  return g;
40
40
  }, t.prototype.listenerCount = function(e) {
41
- var n = s ? s + e : e, c = this._events[n];
42
- return c ? c.fn ? 1 : c.length : 0;
43
- }, t.prototype.emit = function(e, n, c, f, v, g) {
41
+ var n = s ? s + e : e, l = this._events[n];
42
+ return l ? l.fn ? 1 : l.length : 0;
43
+ }, t.prototype.emit = function(e, n, l, h, v, g) {
44
44
  var w = s ? s + e : e;
45
45
  if (!this._events[w]) return !1;
46
- var h = this._events[w], b = arguments.length, _, y;
47
- if (h.fn) {
48
- switch (h.once && this.removeListener(e, h.fn, void 0, !0), b) {
46
+ var f = this._events[w], b = arguments.length, _, y;
47
+ if (f.fn) {
48
+ switch (f.once && this.removeListener(e, f.fn, void 0, !0), b) {
49
49
  case 1:
50
- return h.fn.call(h.context), !0;
50
+ return f.fn.call(f.context), !0;
51
51
  case 2:
52
- return h.fn.call(h.context, n), !0;
52
+ return f.fn.call(f.context, n), !0;
53
53
  case 3:
54
- return h.fn.call(h.context, n, c), !0;
54
+ return f.fn.call(f.context, n, l), !0;
55
55
  case 4:
56
- return h.fn.call(h.context, n, c, f), !0;
56
+ return f.fn.call(f.context, n, l, h), !0;
57
57
  case 5:
58
- return h.fn.call(h.context, n, c, f, v), !0;
58
+ return f.fn.call(f.context, n, l, h, v), !0;
59
59
  case 6:
60
- return h.fn.call(h.context, n, c, f, v, g), !0;
60
+ return f.fn.call(f.context, n, l, h, v, g), !0;
61
61
  }
62
62
  for (y = 1, _ = new Array(b - 1); y < b; y++)
63
63
  _[y - 1] = arguments[y];
64
- h.fn.apply(h.context, _);
64
+ f.fn.apply(f.context, _);
65
65
  } else {
66
- var j = h.length, A;
67
- for (y = 0; y < j; y++)
68
- switch (h[y].once && this.removeListener(e, h[y].fn, void 0, !0), b) {
66
+ var P = f.length, A;
67
+ for (y = 0; y < P; y++)
68
+ switch (f[y].once && this.removeListener(e, f[y].fn, void 0, !0), b) {
69
69
  case 1:
70
- h[y].fn.call(h[y].context);
70
+ f[y].fn.call(f[y].context);
71
71
  break;
72
72
  case 2:
73
- h[y].fn.call(h[y].context, n);
73
+ f[y].fn.call(f[y].context, n);
74
74
  break;
75
75
  case 3:
76
- h[y].fn.call(h[y].context, n, c);
76
+ f[y].fn.call(f[y].context, n, l);
77
77
  break;
78
78
  case 4:
79
- h[y].fn.call(h[y].context, n, c, f);
79
+ f[y].fn.call(f[y].context, n, l, h);
80
80
  break;
81
81
  default:
82
82
  if (!_) for (A = 1, _ = new Array(b - 1); A < b; A++)
83
83
  _[A - 1] = arguments[A];
84
- h[y].fn.apply(h[y].context, _);
84
+ f[y].fn.apply(f[y].context, _);
85
85
  }
86
86
  }
87
87
  return !0;
88
- }, t.prototype.on = function(e, n, c) {
89
- return i(this, e, n, c, !1);
90
- }, t.prototype.once = function(e, n, c) {
91
- return i(this, e, n, c, !0);
92
- }, t.prototype.removeListener = function(e, n, c, f) {
88
+ }, t.prototype.on = function(e, n, l) {
89
+ return i(this, e, n, l, !1);
90
+ }, t.prototype.once = function(e, n, l) {
91
+ return i(this, e, n, l, !0);
92
+ }, t.prototype.removeListener = function(e, n, l, h) {
93
93
  var v = s ? s + e : e;
94
94
  if (!this._events[v]) return this;
95
95
  if (!n)
96
96
  return u(this, v), this;
97
97
  var g = this._events[v];
98
98
  if (g.fn)
99
- g.fn === n && (!f || g.once) && (!c || g.context === c) && u(this, v);
99
+ g.fn === n && (!h || g.once) && (!l || g.context === l) && u(this, v);
100
100
  else {
101
- for (var w = 0, h = [], b = g.length; w < b; w++)
102
- (g[w].fn !== n || f && !g[w].once || c && g[w].context !== c) && h.push(g[w]);
103
- h.length ? this._events[v] = h.length === 1 ? h[0] : h : u(this, v);
101
+ for (var w = 0, f = [], b = g.length; w < b; w++)
102
+ (g[w].fn !== n || h && !g[w].once || l && g[w].context !== l) && f.push(g[w]);
103
+ f.length ? this._events[v] = f.length === 1 ? f[0] : f : u(this, v);
104
104
  }
105
105
  return this;
106
106
  }, t.prototype.removeAllListeners = function(e) {
107
107
  var n;
108
108
  return e ? (n = s ? s + e : e, this._events[n] && u(this, n)) : (this._events = new o(), this._eventsCount = 0), this;
109
109
  }, t.prototype.off = t.prototype.removeListener, t.prototype.addListener = t.prototype.on, t.prefixed = s, t.EventEmitter = t, d.exports = t;
110
- })(I)), I.exports;
110
+ })($)), $.exports;
111
111
  }
112
- var D = L();
113
- const U = /* @__PURE__ */ P(D), F = "wss://cbw.datapods.io/ws-ua-usr", $ = "wss://cbw.ironflock.com/ws-ua-usr", W = "wss://cbw.ironflock.dev/ws-ua-usr", V = "wss://cbw.record-evolution.com/ws-ua-usr", S = "ws://localhost:8080/ws-ua-usr", Y = {
112
+ var D = j();
113
+ const U = /* @__PURE__ */ L(D), F = "wss://cbw.datapods.io/ws-ua-usr", S = "wss://cbw.ironflock.com/ws-ua-usr", W = "wss://cbw.ironflock.dev/ws-ua-usr", V = "wss://cbw.record-evolution.com/ws-ua-usr", x = "ws://localhost:8080/ws-ua-usr", Y = {
114
114
  "https://studio.datapods.io": F,
115
115
  "https://studio.ironflock.dev": W,
116
- "https://studio.ironflock.com": $,
116
+ "https://studio.ironflock.com": S,
117
117
  "https://studio.record-evolution.com": V,
118
- "http://localhost:8085": S,
119
- "http://localhost:8086": S,
120
- "http://host.docker.internal:8086": S
118
+ "http://localhost:8085": x,
119
+ "http://localhost:8086": x,
120
+ "http://host.docker.internal:8086": x
121
121
  }, Q = 6e3;
122
- class x extends U {
122
+ class I extends U {
123
123
  constructor() {
124
124
  super(), this.subscriptions = [], this.registrations = [], this.firstResolver = () => {
125
125
  }, this.firstRejecter = () => {
126
- };
126
+ }, this.shouldReconnect = !1, this.isReconnecting = !1, this.hasOpenedOnce = !1;
127
127
  }
128
128
  static getWebSocketURI(r) {
129
- return r ? Y[r] ?? $ : $;
129
+ var o;
130
+ const s = typeof process < "u" ? (o = process.env) == null ? void 0 : o.DEVICE_ENDPOINT_URL : void 0;
131
+ if (s)
132
+ try {
133
+ const c = new URL(s);
134
+ return c.pathname = "/ws-ua-usr", c.toString().replace(/\/$/, "");
135
+ } catch {
136
+ }
137
+ return r ? Y[r] ?? S : S;
130
138
  }
131
- configure(r, s, o, l, i) {
132
- this.realm = `realm-${r}-${s}-${o}`, this.serial_number = l, this.socketURI = i ?? x.getWebSocketURI();
139
+ configure(r, s, o, c, i) {
140
+ this.realm = `realm-${r}-${s}-${o}`, this.serial_number = c, this.socketURI = i ?? I.getWebSocketURI();
133
141
  }
134
142
  async start() {
135
143
  if (!this.realm || !this.serial_number || !this.socketURI)
136
144
  throw new Error("CrossbarConnection must be configured before starting. Call configure() first.");
137
- return this.firstConnection = new Promise((r, s) => {
145
+ return this.shouldReconnect = !0, this.firstConnection = new Promise((r, s) => {
138
146
  this.firstResolver = r, this.firstRejecter = s;
139
- }), this.connection = new C.Connection({
147
+ }), this.connection = new O.Connection({
140
148
  realm: this.realm,
141
149
  url: this.socketURI,
142
150
  authmethods: ["wampcra"],
@@ -147,11 +155,11 @@ class x extends U {
147
155
  // @ts-ignore
148
156
  autoping_interval: 2,
149
157
  autoping_timeout: 4,
150
- onchallenge: (r, s, o) => C.auth_cra.sign(this.serial_number, o.challenge)
158
+ onchallenge: (r, s, o) => O.auth_cra.sign(this.serial_number, o.challenge)
151
159
  }), this.connection.onopen = this.onOpen.bind(this), this.connection.onclose = this.onClose.bind(this), this.connection.open(), this.firstConnection;
152
160
  }
153
161
  onOpen(r) {
154
- this.session = r, this.session.caller_disclose_me = !0, this.resubscribeAll(), this.emit("connected", this.serial_number), this.firstResolver(), this.firstResolver = () => {
162
+ this.session = r, this.session.caller_disclose_me = !0, this.hasOpenedOnce = !0, this.resubscribeAll(), this.reregisterAll(), this.emit("connected", this.serial_number), this.firstResolver(), this.firstResolver = () => {
155
163
  };
156
164
  }
157
165
  onClose(r, s) {
@@ -166,7 +174,21 @@ class x extends U {
166
174
  realm: this.realm,
167
175
  url: this.socketURI,
168
176
  authid: this.serial_number
169
- }), !1;
177
+ }), this.shouldReconnect && this.hasOpenedOnce && (s == null ? void 0 : s.will_retry) === !1 && this.handleManualReconnect((s == null ? void 0 : s.reason) ?? r), !1;
178
+ }
179
+ async handleManualReconnect(r) {
180
+ if (!(this.isReconnecting || !this.shouldReconnect)) {
181
+ for (this.isReconnecting = !0; this.shouldReconnect && !this.session; )
182
+ if (await new Promise((s) => setTimeout(s, 1e3)), this.shouldReconnect && this.connection && !this.session) {
183
+ console.log(`Manually retrying connection after ${r}...`);
184
+ try {
185
+ this.connection.open(), await new Promise((s) => setTimeout(s, 500));
186
+ } catch (s) {
187
+ console.error("Error during manual reconnection attempt:", s);
188
+ }
189
+ }
190
+ this.isReconnecting = !1;
191
+ }
170
192
  }
171
193
  async sessionWait() {
172
194
  const r = Date.now();
@@ -191,12 +213,12 @@ class x extends U {
191
213
  }
192
214
  stop() {
193
215
  var r;
194
- (r = this.connection) == null || r.close("wamp.close.normal", "Connection closed by client");
216
+ this.shouldReconnect = !1, (r = this.connection) == null || r.close("wamp.close.normal", "Connection closed by client");
195
217
  }
196
218
  async subscribe(r, s) {
197
- var l;
219
+ var c;
198
220
  await this.sessionWait();
199
- const o = await ((l = this.session) == null ? void 0 : l.subscribe(r, s));
221
+ const o = await ((c = this.session) == null ? void 0 : c.subscribe(r, s));
200
222
  return o && this.subscriptions.push(o), o;
201
223
  }
202
224
  async unsubscribe(r) {
@@ -216,10 +238,16 @@ class x extends U {
216
238
  r.map((s) => this.subscribe(s.topic, s.handler))
217
239
  );
218
240
  }
241
+ async reregisterAll() {
242
+ const r = [...this.registrations];
243
+ this.registrations = [], await Promise.all(
244
+ r.map((s) => this.register(s.procedure, s.endpoint, s.options))
245
+ );
246
+ }
219
247
  async register(r, s, o) {
220
248
  var u;
221
249
  await this.sessionWait();
222
- const l = { force_reregister: !0, ...o ?? {} }, i = await ((u = this.session) == null ? void 0 : u.register(r, s, l));
250
+ const c = { force_reregister: !0, ...o ?? {} }, i = await ((u = this.session) == null ? void 0 : u.register(r, s, c));
223
251
  return i && this.registrations.push(i), i;
224
252
  }
225
253
  async unregister(r) {
@@ -228,16 +256,16 @@ class x extends U {
228
256
  const s = this.registrations.indexOf(r);
229
257
  s !== -1 && this.registrations.splice(s, 1);
230
258
  }
231
- async call(r, s, o, l) {
259
+ async call(r, s, o, c) {
232
260
  var i;
233
- return await this.sessionWait(), (i = this.session) == null ? void 0 : i.call(r, s, o, l);
261
+ return await this.sessionWait(), (i = this.session) == null ? void 0 : i.call(r, s, o, c);
234
262
  }
235
- async publish(r, s, o, l) {
263
+ async publish(r, s, o, c) {
236
264
  var i;
237
- return await this.sessionWait(), (i = this.session) == null ? void 0 : i.publish(r, s, o, l);
265
+ return await this.sessionWait(), (i = this.session) == null ? void 0 : i.publish(r, s, o, c);
238
266
  }
239
267
  }
240
- const K = (d) => Math.floor(d) === d && B <= d && d <= J, B = 0, J = 2 ** 32 - 1, R = (d) => q.test(d), q = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i, k = (d) => {
268
+ const R = (d) => Math.floor(d) === d && B <= d && d <= J, B = 0, J = 2 ** 32 - 1, K = (d) => H.test(d), H = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i, p = (d) => {
241
269
  const r = (s) => {
242
270
  if (d.length === 0)
243
271
  return !0;
@@ -250,7 +278,7 @@ const K = (d) => Math.floor(d) === d && B <= d && d <= J, B = 0, J = 2 ** 32 - 1
250
278
  `Please fill the \`${o.expected}\` typed value next time.`
251
279
  ].join(`
252
280
  `))), d.push(o)), !1);
253
- }, p = (d) => Object.assign(d, {
281
+ }, k = (d) => Object.assign(d, {
254
282
  "~standard": {
255
283
  version: 1,
256
284
  vendor: "typia",
@@ -261,7 +289,7 @@ const K = (d) => Math.floor(d) === d && B <= d && d <= J, B = 0, J = 2 ** 32 - 1
261
289
  } : {
262
290
  issues: s.errors.map((o) => ({
263
291
  message: `expected ${o.expected}, got ${o.value}`,
264
- path: H(o.path)
292
+ path: G(o.path)
265
293
  }))
266
294
  };
267
295
  }
@@ -271,26 +299,26 @@ var m;
271
299
  (function(d) {
272
300
  d[d.Start = 0] = "Start", d[d.Property = 1] = "Property", d[d.StringKey = 2] = "StringKey", d[d.NumberKey = 3] = "NumberKey";
273
301
  })(m || (m = {}));
274
- const H = (d) => {
302
+ const G = (d) => {
275
303
  if (!d.startsWith("$input"))
276
304
  throw new Error(`Invalid path: ${JSON.stringify(d)}`);
277
305
  const r = [];
278
- let s = "", o = m.Start, l = 5;
279
- for (; l < d.length - 1; ) {
280
- l++;
281
- const i = d[l];
306
+ let s = "", o = m.Start, c = 5;
307
+ for (; c < d.length - 1; ) {
308
+ c++;
309
+ const i = d[c];
282
310
  if (o === m.Property ? i === "." || i === "[" ? (r.push({
283
311
  key: s
284
- }), o = m.Start) : l === d.length - 1 ? (s += i, r.push({
312
+ }), o = m.Start) : c === d.length - 1 ? (s += i, r.push({
285
313
  key: s
286
- }), l++, o = m.Start) : s += i : o === m.StringKey ? i === '"' ? (r.push({
314
+ }), c++, o = m.Start) : s += i : o === m.StringKey ? i === '"' ? (r.push({
287
315
  key: JSON.parse(s + i)
288
- }), l += 2, o = m.Start) : i === "\\" ? (s += d[l], l++, s += d[l]) : s += i : o === m.NumberKey && (i === "]" ? (r.push({
316
+ }), c += 2, o = m.Start) : i === "\\" ? (s += d[c], c++, s += d[c]) : s += i : o === m.NumberKey && (i === "]" ? (r.push({
289
317
  key: Number.parseInt(s)
290
- }), l++, o = m.Start) : s += i), o === m.Start && l < d.length - 1) {
291
- const u = d[l];
318
+ }), c++, o = m.Start) : s += i), o === m.Start && c < d.length - 1) {
319
+ const u = d[c];
292
320
  if (s = "", u === "[")
293
- d[l + 1] === '"' ? (o = m.StringKey, l++, s = '"') : o = m.NumberKey;
321
+ d[c + 1] === '"' ? (o = m.StringKey, c++, s = '"') : o = m.NumberKey;
294
322
  else if (u === ".")
295
323
  o = m.Property;
296
324
  else
@@ -302,123 +330,123 @@ const H = (d) => {
302
330
  return r;
303
331
  };
304
332
  var M = /* @__PURE__ */ ((d) => (d.DEVELOPMENT = "dev", d.PRODUCTION = "prod", d))(M || {});
305
- const G = (() => {
306
- const d = (e) => typeof e.limit == "number" && K(e.limit) && 1 <= e.limit && e.limit <= 1e4 && (e.offset === void 0 || typeof e.offset == "number" && K(e.offset) && 0 <= e.offset) && (e.timeRange === void 0 || typeof e.timeRange == "object" && e.timeRange !== null && r(e.timeRange)) && (e.filterAnd === void 0 || Array.isArray(e.filterAnd) && e.filterAnd.every((n) => typeof n == "object" && n !== null && s(n))), r = (e) => typeof e.start == "string" && R(e.start) && typeof e.end == "string" && R(e.end), s = (e) => typeof e.column == "string" && 1 <= e.column.length && typeof e.operator == "string" && 1 <= e.operator.length && e.value !== null && e.value !== void 0 && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || Array.isArray(e.value) && e.value.every((n) => typeof n == "string" || typeof n == "number")), o = (e, n, c = !0) => [typeof e.limit == "number" && (K(e.limit) || a(c, {
333
+ const q = (() => {
334
+ const d = (e) => typeof e.limit == "number" && R(e.limit) && 1 <= e.limit && e.limit <= 1e4 && (e.offset === void 0 || typeof e.offset == "number" && R(e.offset) && 0 <= e.offset) && (e.timeRange === void 0 || typeof e.timeRange == "object" && e.timeRange !== null && r(e.timeRange)) && (e.filterAnd === void 0 || Array.isArray(e.filterAnd) && e.filterAnd.every((n) => typeof n == "object" && n !== null && s(n))), r = (e) => typeof e.start == "string" && K(e.start) && typeof e.end == "string" && K(e.end), s = (e) => typeof e.column == "string" && 1 <= e.column.length && typeof e.operator == "string" && 1 <= e.operator.length && e.value !== null && e.value !== void 0 && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || Array.isArray(e.value) && e.value.every((n) => typeof n == "string" || typeof n == "number")), o = (e, n, l = !0) => [typeof e.limit == "number" && (R(e.limit) || a(l, {
307
335
  path: n + ".limit",
308
336
  expected: 'number & Type<"uint32">',
309
337
  value: e.limit
310
- })) && (1 <= e.limit || a(c, {
338
+ })) && (1 <= e.limit || a(l, {
311
339
  path: n + ".limit",
312
340
  expected: "number & Minimum<1>",
313
341
  value: e.limit
314
- })) && (e.limit <= 1e4 || a(c, {
342
+ })) && (e.limit <= 1e4 || a(l, {
315
343
  path: n + ".limit",
316
344
  expected: "number & Maximum<10000>",
317
345
  value: e.limit
318
- })) || a(c, {
346
+ })) || a(l, {
319
347
  path: n + ".limit",
320
348
  expected: '(number & Type<"uint32"> & Minimum<1> & Maximum<10000>)',
321
349
  value: e.limit
322
- }), e.offset === void 0 || typeof e.offset == "number" && (K(e.offset) || a(c, {
350
+ }), e.offset === void 0 || typeof e.offset == "number" && (R(e.offset) || a(l, {
323
351
  path: n + ".offset",
324
352
  expected: 'number & Type<"uint32">',
325
353
  value: e.offset
326
- })) && (0 <= e.offset || a(c, {
354
+ })) && (0 <= e.offset || a(l, {
327
355
  path: n + ".offset",
328
356
  expected: "number & Minimum<0>",
329
357
  value: e.offset
330
- })) || a(c, {
358
+ })) || a(l, {
331
359
  path: n + ".offset",
332
360
  expected: '((number & Type<"uint32"> & Minimum<0>) | undefined)',
333
361
  value: e.offset
334
- }), e.timeRange === void 0 || (typeof e.timeRange == "object" && e.timeRange !== null || a(c, {
362
+ }), e.timeRange === void 0 || (typeof e.timeRange == "object" && e.timeRange !== null || a(l, {
335
363
  path: n + ".timeRange",
336
364
  expected: "(ISOTimeRange | undefined)",
337
365
  value: e.timeRange
338
- })) && l(e.timeRange, n + ".timeRange", c) || a(c, {
366
+ })) && c(e.timeRange, n + ".timeRange", l) || a(l, {
339
367
  path: n + ".timeRange",
340
368
  expected: "(ISOTimeRange | undefined)",
341
369
  value: e.timeRange
342
- }), e.filterAnd === void 0 || (Array.isArray(e.filterAnd) || a(c, {
370
+ }), e.filterAnd === void 0 || (Array.isArray(e.filterAnd) || a(l, {
343
371
  path: n + ".filterAnd",
344
372
  expected: "(Array<SQLFilterAnd> | undefined)",
345
373
  value: e.filterAnd
346
- })) && e.filterAnd.map((f, v) => (typeof f == "object" && f !== null || a(c, {
374
+ })) && e.filterAnd.map((h, v) => (typeof h == "object" && h !== null || a(l, {
347
375
  path: n + ".filterAnd[" + v + "]",
348
376
  expected: "SQLFilterAnd",
349
- value: f
350
- })) && i(f, n + ".filterAnd[" + v + "]", c) || a(c, {
377
+ value: h
378
+ })) && i(h, n + ".filterAnd[" + v + "]", l) || a(l, {
351
379
  path: n + ".filterAnd[" + v + "]",
352
380
  expected: "SQLFilterAnd",
353
- value: f
354
- })).every((f) => f) || a(c, {
381
+ value: h
382
+ })).every((h) => h) || a(l, {
355
383
  path: n + ".filterAnd",
356
384
  expected: "(Array<SQLFilterAnd> | undefined)",
357
385
  value: e.filterAnd
358
- })].every((f) => f), l = (e, n, c = !0) => [typeof e.start == "string" && (R(e.start) || a(c, {
386
+ })].every((h) => h), c = (e, n, l = !0) => [typeof e.start == "string" && (K(e.start) || a(l, {
359
387
  path: n + ".start",
360
388
  expected: 'string & Format<"date-time">',
361
389
  value: e.start
362
- })) || a(c, {
390
+ })) || a(l, {
363
391
  path: n + ".start",
364
392
  expected: '(string & Format<"date-time">)',
365
393
  value: e.start
366
- }), typeof e.end == "string" && (R(e.end) || a(c, {
394
+ }), typeof e.end == "string" && (K(e.end) || a(l, {
367
395
  path: n + ".end",
368
396
  expected: 'string & Format<"date-time">',
369
397
  value: e.end
370
- })) || a(c, {
398
+ })) || a(l, {
371
399
  path: n + ".end",
372
400
  expected: '(string & Format<"date-time">)',
373
401
  value: e.end
374
- })].every((f) => f), i = (e, n, c = !0) => [typeof e.column == "string" && (1 <= e.column.length || a(c, {
402
+ })].every((h) => h), i = (e, n, l = !0) => [typeof e.column == "string" && (1 <= e.column.length || a(l, {
375
403
  path: n + ".column",
376
404
  expected: "string & MinLength<1>",
377
405
  value: e.column
378
- })) || a(c, {
406
+ })) || a(l, {
379
407
  path: n + ".column",
380
408
  expected: "(string & MinLength<1>)",
381
409
  value: e.column
382
- }), typeof e.operator == "string" && (1 <= e.operator.length || a(c, {
410
+ }), typeof e.operator == "string" && (1 <= e.operator.length || a(l, {
383
411
  path: n + ".operator",
384
412
  expected: "string & MinLength<1>",
385
413
  value: e.operator
386
- })) || a(c, {
414
+ })) || a(l, {
387
415
  path: n + ".operator",
388
416
  expected: "(string & MinLength<1>)",
389
417
  value: e.operator
390
- }), (e.value !== null || a(c, {
418
+ }), (e.value !== null || a(l, {
391
419
  path: n + ".value",
392
420
  expected: "(Array<string | number> | boolean | number | string)",
393
421
  value: e.value
394
- })) && (e.value !== void 0 || a(c, {
422
+ })) && (e.value !== void 0 || a(l, {
395
423
  path: n + ".value",
396
424
  expected: "(Array<string | number> | boolean | number | string)",
397
425
  value: e.value
398
- })) && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || (Array.isArray(e.value) || a(c, {
426
+ })) && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || (Array.isArray(e.value) || a(l, {
399
427
  path: n + ".value",
400
428
  expected: "(Array<string | number> | boolean | number | string)",
401
429
  value: e.value
402
- })) && e.value.map((f, v) => typeof f == "string" || typeof f == "number" || a(c, {
430
+ })) && e.value.map((h, v) => typeof h == "string" || typeof h == "number" || a(l, {
403
431
  path: n + ".value[" + v + "]",
404
432
  expected: "(number | string)",
405
- value: f
406
- })).every((f) => f) || a(c, {
433
+ value: h
434
+ })).every((h) => h) || a(l, {
407
435
  path: n + ".value",
408
436
  expected: "(Array<string | number> | boolean | number | string)",
409
437
  value: e.value
410
- }))].every((f) => f), u = (e) => typeof e == "object" && e !== null && d(e);
438
+ }))].every((h) => h), u = (e) => typeof e == "object" && e !== null && d(e);
411
439
  let t, a;
412
- return p((e) => {
440
+ return k((e) => {
413
441
  if (u(e) === !1) {
414
- t = [], a = k(t), ((c, f, v = !0) => (typeof c == "object" && c !== null || a(!0, {
415
- path: f + "",
442
+ t = [], a = p(t), ((l, h, v = !0) => (typeof l == "object" && l !== null || a(!0, {
443
+ path: h + "",
416
444
  expected: "TableQueryParams",
417
- value: c
418
- })) && o(c, f + "", !0) || a(!0, {
419
- path: f + "",
445
+ value: l
446
+ })) && o(l, h + "", !0) || a(!0, {
447
+ path: h + "",
420
448
  expected: "TableQueryParams",
421
- value: c
449
+ value: l
422
450
  }))(e, "$input", !0);
423
451
  const n = t.length === 0;
424
452
  return n ? {
@@ -436,39 +464,39 @@ const G = (() => {
436
464
  };
437
465
  });
438
466
  })(), X = (() => {
439
- const d = (i) => typeof i.longitude == "number" && -180 <= i.longitude && i.longitude <= 180 && typeof i.latitude == "number" && -90 <= i.latitude && i.latitude <= 90, r = (i, u, t = !0) => [typeof i.longitude == "number" && (-180 <= i.longitude || l(t, {
467
+ const d = (i) => typeof i.longitude == "number" && -180 <= i.longitude && i.longitude <= 180 && typeof i.latitude == "number" && -90 <= i.latitude && i.latitude <= 90, r = (i, u, t = !0) => [typeof i.longitude == "number" && (-180 <= i.longitude || c(t, {
440
468
  path: u + ".longitude",
441
469
  expected: "number & Minimum<-180>",
442
470
  value: i.longitude
443
- })) && (i.longitude <= 180 || l(t, {
471
+ })) && (i.longitude <= 180 || c(t, {
444
472
  path: u + ".longitude",
445
473
  expected: "number & Maximum<180>",
446
474
  value: i.longitude
447
- })) || l(t, {
475
+ })) || c(t, {
448
476
  path: u + ".longitude",
449
477
  expected: "(number & Minimum<-180> & Maximum<180>)",
450
478
  value: i.longitude
451
- }), typeof i.latitude == "number" && (-90 <= i.latitude || l(t, {
479
+ }), typeof i.latitude == "number" && (-90 <= i.latitude || c(t, {
452
480
  path: u + ".latitude",
453
481
  expected: "number & Minimum<-90>",
454
482
  value: i.latitude
455
- })) && (i.latitude <= 90 || l(t, {
483
+ })) && (i.latitude <= 90 || c(t, {
456
484
  path: u + ".latitude",
457
485
  expected: "number & Maximum<90>",
458
486
  value: i.latitude
459
- })) || l(t, {
487
+ })) || c(t, {
460
488
  path: u + ".latitude",
461
489
  expected: "(number & Minimum<-90> & Maximum<90>)",
462
490
  value: i.latitude
463
491
  })].every((a) => a), s = (i) => typeof i == "object" && i !== null && d(i);
464
- let o, l;
465
- return p((i) => {
492
+ let o, c;
493
+ return k((i) => {
466
494
  if (s(i) === !1) {
467
- o = [], l = k(o), ((t, a, e = !0) => (typeof t == "object" && t !== null || l(!0, {
495
+ o = [], c = p(o), ((t, a, e = !0) => (typeof t == "object" && t !== null || c(!0, {
468
496
  path: a + "",
469
497
  expected: "LocationParams",
470
498
  value: t
471
- })) && r(t, a + "", !0) || l(!0, {
499
+ })) && r(t, a + "", !0) || c(!0, {
472
500
  path: a + "",
473
501
  expected: "LocationParams",
474
502
  value: t
@@ -509,11 +537,11 @@ const G = (() => {
509
537
  path: a + ".kwargs",
510
538
  expected: "(Record<string, unknown> | undefined)",
511
539
  value: t.kwargs
512
- })].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (t) => typeof t == "object" && t !== null && d(t);
540
+ })].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), c = (t) => typeof t == "object" && t !== null && d(t);
513
541
  let i, u;
514
- return p((t) => {
515
- if (l(t) === !1) {
516
- i = [], u = k(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
542
+ return k((t) => {
543
+ if (c(t) === !1) {
544
+ i = [], u = p(i), ((e, n, l = !0) => (typeof e == "object" && e !== null || u(!0, {
517
545
  path: n + "",
518
546
  expected: "PublishParams",
519
547
  value: e
@@ -566,11 +594,11 @@ const G = (() => {
566
594
  path: a + ".kwargs",
567
595
  expected: "(Record<string, unknown> | undefined)",
568
596
  value: t.kwargs
569
- })].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (t) => typeof t == "object" && t !== null && d(t);
597
+ })].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), c = (t) => typeof t == "object" && t !== null && d(t);
570
598
  let i, u;
571
- return p((t) => {
572
- if (l(t) === !1) {
573
- i = [], u = k(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
599
+ return k((t) => {
600
+ if (c(t) === !1) {
601
+ i = [], u = p(i), ((e, n, l = !0) => (typeof e == "object" && e !== null || u(!0, {
574
602
  path: n + "",
575
603
  expected: "CallParams",
576
604
  value: e
@@ -594,7 +622,7 @@ const G = (() => {
594
622
  data: t
595
623
  };
596
624
  });
597
- })(), T = (() => {
625
+ })(), N = (() => {
598
626
  const d = (t) => typeof t.tablename == "string" && 1 <= t.tablename.length && (t.args === void 0 || Array.isArray(t.args)) && (t.kwargs === void 0 || typeof t.kwargs == "object" && t.kwargs !== null && Array.isArray(t.kwargs) === !1 && r(t.kwargs)), r = (t) => Object.keys(t).every((a) => (t[a] === void 0, !0)), s = (t, a, e = !0) => [typeof t.tablename == "string" && (1 <= t.tablename.length || u(e, {
599
627
  path: a + ".tablename",
600
628
  expected: "string & MinLength<1>",
@@ -615,11 +643,11 @@ const G = (() => {
615
643
  path: a + ".kwargs",
616
644
  expected: "(Record<string, unknown> | undefined)",
617
645
  value: t.kwargs
618
- })].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (t) => typeof t == "object" && t !== null && d(t);
646
+ })].every((n) => n), o = (t, a, e = !0) => [e === !1 || Object.keys(t).map((n) => (t[n] === void 0, !0)).every((n) => n)].every((n) => n), c = (t) => typeof t == "object" && t !== null && d(t);
619
647
  let i, u;
620
- return p((t) => {
621
- if (l(t) === !1) {
622
- i = [], u = k(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
648
+ return k((t) => {
649
+ if (c(t) === !1) {
650
+ i = [], u = p(i), ((e, n, l = !0) => (typeof e == "object" && e !== null || u(!0, {
623
651
  path: n + "",
624
652
  expected: "TableParams",
625
653
  value: e
@@ -654,9 +682,9 @@ function z(d) {
654
682
  throw new Error("serialNumber option is required (or set DEVICE_SERIAL_NUMBER env var in Node.js)");
655
683
  return r;
656
684
  }
657
- class O {
685
+ class T {
658
686
  constructor(r) {
659
- this._isConfigured = !1, this._serialNumber = z(r == null ? void 0 : r.serialNumber), this._deviceName = (r == null ? void 0 : r.deviceName) ?? E("DEVICE_NAME"), this._deviceKey = (r == null ? void 0 : r.deviceKey) ?? E("DEVICE_KEY"), this._appName = (r == null ? void 0 : r.appName) ?? E("APP_NAME"), this._swarmKey = (r == null ? void 0 : r.swarmKey) ?? parseInt(E("SWARM_KEY") ?? "0", 10), this._appKey = (r == null ? void 0 : r.appKey) ?? parseInt(E("APP_KEY") ?? "0", 10), this._env = (r == null ? void 0 : r.env) ?? E("ENV"), this._reswarmUrl = (r == null ? void 0 : r.reswarmUrl) ?? E("RESWARM_URL"), this._cburl = r == null ? void 0 : r.cburl, this._connection = new x();
687
+ this._isConfigured = !1, this._serialNumber = z(r == null ? void 0 : r.serialNumber), this._deviceName = (r == null ? void 0 : r.deviceName) ?? E("DEVICE_NAME"), this._deviceKey = (r == null ? void 0 : r.deviceKey) ?? E("DEVICE_KEY"), this._appName = (r == null ? void 0 : r.appName) ?? E("APP_NAME"), this._swarmKey = (r == null ? void 0 : r.swarmKey) ?? parseInt(E("SWARM_KEY") ?? "0", 10), this._appKey = (r == null ? void 0 : r.appKey) ?? parseInt(E("APP_KEY") ?? "0", 10), this._env = (r == null ? void 0 : r.env) ?? E("ENV"), this._reswarmUrl = (r == null ? void 0 : r.reswarmUrl) ?? E("RESWARM_URL"), this._cburl = (r == null ? void 0 : r.ironFlockUrl) ?? (r == null ? void 0 : r.cburl), this._connection = new I();
660
688
  const s = [];
661
689
  this._deviceKey || s.push("DEVICE_KEY"), this._appName || s.push("APP_NAME"), this._swarmKey || s.push("SWARM_KEY"), this._appKey || s.push("APP_KEY"), s.length > 0 && console.warn(
662
690
  `Warning: The following environment variables must be present: ${s.join(", ")}`
@@ -670,14 +698,14 @@ class O {
670
698
  }
671
699
  configureConnection(r) {
672
700
  if (this._isConfigured) return;
673
- const s = (this._env ?? "DEV").toUpperCase(), l = {
701
+ const s = (this._env ?? "DEV").toUpperCase(), c = {
674
702
  DEV: M.DEVELOPMENT,
675
703
  PROD: M.PRODUCTION
676
- }[s] ?? M.DEVELOPMENT, i = r ?? this._cburl ?? x.getWebSocketURI(this._reswarmUrl);
704
+ }[s] ?? M.DEVELOPMENT, i = r ?? this._cburl ?? I.getWebSocketURI(this._reswarmUrl);
677
705
  this._connection.configure(
678
706
  this._swarmKey,
679
707
  this._appKey,
680
- l,
708
+ c,
681
709
  this._serialNumber,
682
710
  i
683
711
  ), this._isConfigured = !0;
@@ -689,9 +717,9 @@ class O {
689
717
  this._connection.stop();
690
718
  }
691
719
  async publish(r, s, o) {
692
- const l = Z({ topic: r, args: s, kwargs: o });
693
- if (!l.success)
694
- throw new Error(`Invalid publish parameters: ${l.errors.map((t) => t.path + ": " + t.expected).join(", ")}`);
720
+ const c = Z({ topic: r, args: s, kwargs: o });
721
+ if (!c.success)
722
+ throw new Error(`Invalid publish parameters: ${c.errors.map((t) => t.path + ": " + t.expected).join(", ")}`);
695
723
  const u = { ...{
696
724
  DEVICE_SERIAL_NUMBER: this._serialNumber,
697
725
  DEVICE_KEY: this._deviceKey,
@@ -702,18 +730,18 @@ class O {
702
730
  });
703
731
  }
704
732
  async publishToTable(r, s, o) {
705
- const l = T({ tablename: r, args: s, kwargs: o });
706
- if (!l.success)
707
- throw new Error(`Invalid table parameters: ${l.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
733
+ const c = N({ tablename: r, args: s, kwargs: o });
734
+ if (!c.success)
735
+ throw new Error(`Invalid table parameters: ${c.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
708
736
  if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
709
737
  if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
710
738
  const i = `${this._swarmKey}.${this._appKey}.${r}`;
711
739
  return this.publish(i, s, o);
712
740
  }
713
741
  async appendToTable(r, s, o) {
714
- const l = T({ tablename: r, args: s, kwargs: o });
715
- if (!l.success)
716
- throw new Error(`Invalid table parameters: ${l.errors.map((a) => a.path + ": " + a.expected).join(", ")}`);
742
+ const c = N({ tablename: r, args: s, kwargs: o });
743
+ if (!c.success)
744
+ throw new Error(`Invalid table parameters: ${c.errors.map((a) => a.path + ": " + a.expected).join(", ")}`);
717
745
  if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
718
746
  if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
719
747
  const i = `append.${this._swarmKey}.${this._appKey}.${r}`, t = { ...{
@@ -729,23 +757,23 @@ class O {
729
757
  async subscribeToTable(r, s, o) {
730
758
  if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
731
759
  if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
732
- const l = `${this._swarmKey}.${this._appKey}.${r}`;
733
- return this.subscribe(l, s, o);
760
+ const c = `${this._swarmKey}.${this._appKey}.${r}`;
761
+ return this.subscribe(c, s, o);
734
762
  }
735
- async call(r, s, o, l) {
736
- return this._connection.call(r, s, o, l);
763
+ async call(r, s, o, c) {
764
+ return this._connection.call(r, s, o, c);
737
765
  }
738
- async callDeviceFunction(r, s, o, l, i) {
766
+ async callDeviceFunction(r, s, o, c, i) {
739
767
  const u = `${this._swarmKey}.${r}.${this._appKey}.${this._env}.${s}`;
740
- return this._connection.call(u, o, l, i);
768
+ return this._connection.call(u, o, c, i);
741
769
  }
742
770
  /** @deprecated Use callDeviceFunction() instead. */
743
- async callFunction(r, s, o, l, i) {
744
- return console.warn("callFunction() is deprecated and will be removed in a future version. Use callDeviceFunction() instead."), this.callDeviceFunction(r, s, o, l, i);
771
+ async callFunction(r, s, o, c, i) {
772
+ return console.warn("callFunction() is deprecated and will be removed in a future version. Use callDeviceFunction() instead."), this.callDeviceFunction(r, s, o, c, i);
745
773
  }
746
774
  async registerDeviceFunction(r, s, o) {
747
- const l = `${this._swarmKey}.${this._deviceKey}.${this._appKey}.${this._env}.${r}`, i = await this._connection.register(l, s, o);
748
- return console.log(`Function registered for IronFlock topic '${r}'. (Full WAMP topic: '${l}')`), i;
775
+ const c = `${this._swarmKey}.${this._deviceKey}.${this._appKey}.${this._env}.${r}`, i = await this._connection.register(c, s, o);
776
+ return console.log(`Function registered for IronFlock topic '${r}'. (Full WAMP topic: '${c}')`), i;
749
777
  }
750
778
  /** @deprecated Use registerDeviceFunction() instead. */
751
779
  async registerFunction(r, s, o) {
@@ -756,22 +784,23 @@ class O {
756
784
  }
757
785
  async getHistory(r, s = { limit: 10 }) {
758
786
  if (!r) throw new Error("Tablename must not be empty!");
759
- const o = G(s);
787
+ s.offset == null && (s.offset = 0);
788
+ const o = q(s);
760
789
  if (!o.success)
761
790
  throw new Error(`Invalid query parameters: ${o.errors.map((i) => i.path + ": " + i.expected).join(", ")}`);
762
- const l = `history.transformed.app.${this._appKey}.${r}`;
791
+ const c = `history.transformed.app.${this._appKey}.${r}`;
763
792
  try {
764
- return await this._connection.call(l, [s]);
793
+ return await this._connection.call(c, [s]);
765
794
  } catch (i) {
766
795
  const u = String(i);
767
- return u.includes("no_such_procedure") || u.includes("no callee registered") ? (console.error(`Get history failed: History service procedure '${l}' not registered`), null) : (console.error(`Get history failed: ${i}`), null);
796
+ return u.includes("no_such_procedure") || u.includes("no callee registered") ? (console.error(`Get history failed: History service procedure '${c}' not registered`), null) : (console.error(`Get history failed: ${i}`), null);
768
797
  }
769
798
  }
770
799
  async setDeviceLocation(r, s) {
771
800
  const o = X({ longitude: r, latitude: s });
772
801
  if (!o.success)
773
802
  throw new Error(`Invalid location parameters: ${o.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
774
- const l = { long: r, lat: s }, i = {
803
+ const c = { long: r, lat: s }, i = {
775
804
  DEVICE_SERIAL_NUMBER: this._serialNumber,
776
805
  DEVICE_KEY: this._deviceKey,
777
806
  DEVICE_NAME: this._deviceName
@@ -779,7 +808,7 @@ class O {
779
808
  try {
780
809
  return await this._connection.call(
781
810
  "ironflock.location_service.update",
782
- [l],
811
+ [c],
783
812
  i
784
813
  );
785
814
  } catch (u) {
@@ -804,17 +833,17 @@ class O {
804
833
  if (!s.ok)
805
834
  throw new Error(`Failed to fetch IronFlock config from ${r}: ${s.status} ${s.statusText}`);
806
835
  const o = await s.json();
807
- return new O(o);
836
+ return new T(o);
808
837
  }
809
838
  }
810
839
  export {
811
- x as CrossbarConnection,
812
- O as IronFlock,
840
+ I as CrossbarConnection,
841
+ T as IronFlock,
813
842
  M as Stage,
814
843
  te as validateCallParams,
815
844
  X as validateLocationParams,
816
845
  Z as validatePublishParams,
817
- T as validateTableParams,
818
- G as validateTableQueryParams
846
+ N as validateTableParams,
847
+ q as validateTableQueryParams
819
848
  };
820
849
  //# sourceMappingURL=index.mjs.map