ironflock 1.2.3 → 1.2.6

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,9 +1,9 @@
1
1
  import C from "autobahn";
2
- function P(d) {
2
+ function L(d) {
3
3
  return d && d.__esModule && Object.prototype.hasOwnProperty.call(d, "default") ? d.default : d;
4
4
  }
5
5
  var I = { exports: {} }, N;
6
- function L() {
6
+ function D() {
7
7
  return N || (N = 1, (function(d) {
8
8
  var r = Object.prototype.hasOwnProperty, s = "~";
9
9
  function o() {
@@ -15,8 +15,8 @@ function L() {
15
15
  function i(a, e, n, c, f) {
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), m = s ? s + e : e;
19
- return a._events[m] ? a._events[m].fn ? a._events[m] = [a._events[m], v] : a._events[m].push(v) : (a._events[m] = v, a._eventsCount++), a;
18
+ var v = new l(n, c || a, f), g = s ? s + e : e;
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) {
22
22
  --a._eventsCount === 0 ? a._events = new o() : delete a._events[e];
@@ -34,16 +34,16 @@ function L() {
34
34
  var n = s ? s + e : e, c = this._events[n];
35
35
  if (!c) return [];
36
36
  if (c.fn) return [c.fn];
37
- for (var f = 0, v = c.length, m = new Array(v); f < v; f++)
38
- m[f] = c[f].fn;
39
- return m;
37
+ for (var f = 0, v = c.length, g = new Array(v); f < v; f++)
38
+ g[f] = c[f].fn;
39
+ return g;
40
40
  }, t.prototype.listenerCount = function(e) {
41
41
  var n = s ? s + e : e, c = this._events[n];
42
42
  return c ? c.fn ? 1 : c.length : 0;
43
- }, t.prototype.emit = function(e, n, c, f, v, m) {
43
+ }, t.prototype.emit = function(e, n, c, f, 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, _, g;
46
+ var h = this._events[w], b = arguments.length, _, y;
47
47
  if (h.fn) {
48
48
  switch (h.once && this.removeListener(e, h.fn, void 0, !0), b) {
49
49
  case 1:
@@ -57,31 +57,31 @@ function L() {
57
57
  case 5:
58
58
  return h.fn.call(h.context, n, c, f, v), !0;
59
59
  case 6:
60
- return h.fn.call(h.context, n, c, f, v, m), !0;
60
+ return h.fn.call(h.context, n, c, f, v, g), !0;
61
61
  }
62
- for (g = 1, _ = new Array(b - 1); g < b; g++)
63
- _[g - 1] = arguments[g];
62
+ for (y = 1, _ = new Array(b - 1); y < b; y++)
63
+ _[y - 1] = arguments[y];
64
64
  h.fn.apply(h.context, _);
65
65
  } else {
66
66
  var j = h.length, A;
67
- for (g = 0; g < j; g++)
68
- switch (h[g].once && this.removeListener(e, h[g].fn, void 0, !0), b) {
67
+ for (y = 0; y < j; y++)
68
+ switch (h[y].once && this.removeListener(e, h[y].fn, void 0, !0), b) {
69
69
  case 1:
70
- h[g].fn.call(h[g].context);
70
+ h[y].fn.call(h[y].context);
71
71
  break;
72
72
  case 2:
73
- h[g].fn.call(h[g].context, n);
73
+ h[y].fn.call(h[y].context, n);
74
74
  break;
75
75
  case 3:
76
- h[g].fn.call(h[g].context, n, c);
76
+ h[y].fn.call(h[y].context, n, c);
77
77
  break;
78
78
  case 4:
79
- h[g].fn.call(h[g].context, n, c, f);
79
+ h[y].fn.call(h[y].context, n, c, f);
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[g].fn.apply(h[g].context, _);
84
+ h[y].fn.apply(h[y].context, _);
85
85
  }
86
86
  }
87
87
  return !0;
@@ -94,12 +94,12 @@ function L() {
94
94
  if (!this._events[v]) return this;
95
95
  if (!n)
96
96
  return u(this, v), this;
97
- var m = this._events[v];
98
- if (m.fn)
99
- m.fn === n && (!f || m.once) && (!c || m.context === c) && u(this, v);
97
+ var g = this._events[v];
98
+ if (g.fn)
99
+ g.fn === n && (!f || g.once) && (!c || g.context === c) && u(this, v);
100
100
  else {
101
- for (var w = 0, h = [], b = m.length; w < b; w++)
102
- (m[w].fn !== n || f && !m[w].once || c && m[w].context !== c) && h.push(m[w]);
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
103
  h.length ? this._events[v] = h.length === 1 ? h[0] : h : u(this, v);
104
104
  }
105
105
  return this;
@@ -109,12 +109,12 @@ function L() {
109
109
  }, t.prototype.off = t.prototype.removeListener, t.prototype.addListener = t.prototype.on, t.prefixed = s, t.EventEmitter = t, d.exports = t;
110
110
  })(I)), I.exports;
111
111
  }
112
- var D = L();
113
- const U = /* @__PURE__ */ P(D), W = "wss://cbw.datapods.io/ws-ua-usr", $ = "wss://cbw.ironflock.com/ws-ua-usr", V = "wss://cbw.ironflock.dev/ws-ua-usr", F = "wss://cbw.record-evolution.com/ws-ua-usr", S = "ws://localhost:8080/ws-ua-usr", Y = {
114
- "https://studio.datapods.io": W,
115
- "https://studio.ironflock.dev": V,
112
+ var P = D();
113
+ const U = /* @__PURE__ */ L(P), 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 = {
114
+ "https://studio.datapods.io": F,
115
+ "https://studio.ironflock.dev": W,
116
116
  "https://studio.ironflock.com": $,
117
- "https://studio.record-evolution.com": F,
117
+ "https://studio.record-evolution.com": V,
118
118
  "http://localhost:8085": S,
119
119
  "http://localhost:8086": S,
120
120
  "http://host.docker.internal:8086": S
@@ -216,11 +216,11 @@ class x extends U {
216
216
  r.map((s) => this.subscribe(s.topic, s.handler))
217
217
  );
218
218
  }
219
- async register(r, s) {
220
- var l;
219
+ async register(r, s, o) {
220
+ var u;
221
221
  await this.sessionWait();
222
- const o = await ((l = this.session) == null ? void 0 : l.register(r, s));
223
- return o && this.registrations.push(o), o;
222
+ const l = { force_reregister: !0, ...o ?? {} }, i = await ((u = this.session) == null ? void 0 : u.register(r, s, l));
223
+ return i && this.registrations.push(i), i;
224
224
  }
225
225
  async unregister(r) {
226
226
  var o;
@@ -237,7 +237,7 @@ class x extends U {
237
237
  return await this.sessionWait(), (i = this.session) == null ? void 0 : i.publish(r, s, o, l);
238
238
  }
239
239
  }
240
- const R = (d) => Math.floor(d) === d && B <= d && d <= J, B = 0, J = 2 ** 32 - 1, K = (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) => {
240
+ const K = (d) => Math.floor(d) === d && B <= d && d <= J, B = 0, J = 2 ** 32 - 1, R = (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, k = (d) => {
241
241
  const r = (s) => {
242
242
  if (d.length === 0)
243
243
  return !0;
@@ -261,49 +261,49 @@ const R = (d) => Math.floor(d) === d && B <= d && d <= J, B = 0, J = 2 ** 32 - 1
261
261
  } : {
262
262
  issues: s.errors.map((o) => ({
263
263
  message: `expected ${o.expected}, got ${o.value}`,
264
- path: H(o.path)
264
+ path: G(o.path)
265
265
  }))
266
266
  };
267
267
  }
268
268
  }
269
269
  });
270
- var y;
270
+ var m;
271
271
  (function(d) {
272
272
  d[d.Start = 0] = "Start", d[d.Property = 1] = "Property", d[d.StringKey = 2] = "StringKey", d[d.NumberKey = 3] = "NumberKey";
273
- })(y || (y = {}));
274
- const H = (d) => {
273
+ })(m || (m = {}));
274
+ const G = (d) => {
275
275
  if (!d.startsWith("$input"))
276
276
  throw new Error(`Invalid path: ${JSON.stringify(d)}`);
277
277
  const r = [];
278
- let s = "", o = y.Start, l = 5;
278
+ let s = "", o = m.Start, l = 5;
279
279
  for (; l < d.length - 1; ) {
280
280
  l++;
281
281
  const i = d[l];
282
- if (o === y.Property ? i === "." || i === "[" ? (r.push({
282
+ if (o === m.Property ? i === "." || i === "[" ? (r.push({
283
283
  key: s
284
- }), o = y.Start) : l === d.length - 1 ? (s += i, r.push({
284
+ }), o = m.Start) : l === d.length - 1 ? (s += i, r.push({
285
285
  key: s
286
- }), l++, o = y.Start) : s += i : o === y.StringKey ? i === '"' ? (r.push({
286
+ }), l++, o = m.Start) : s += i : o === m.StringKey ? i === '"' ? (r.push({
287
287
  key: JSON.parse(s + i)
288
- }), l += 2, o = y.Start) : i === "\\" ? (s += d[l], l++, s += d[l]) : s += i : o === y.NumberKey && (i === "]" ? (r.push({
288
+ }), l += 2, o = m.Start) : i === "\\" ? (s += d[l], l++, s += d[l]) : s += i : o === m.NumberKey && (i === "]" ? (r.push({
289
289
  key: Number.parseInt(s)
290
- }), l++, o = y.Start) : s += i), o === y.Start && l < d.length - 1) {
290
+ }), l++, o = m.Start) : s += i), o === m.Start && l < d.length - 1) {
291
291
  const u = d[l];
292
292
  if (s = "", u === "[")
293
- d[l + 1] === '"' ? (o = y.StringKey, l++, s = '"') : o = y.NumberKey;
293
+ d[l + 1] === '"' ? (o = m.StringKey, l++, s = '"') : o = m.NumberKey;
294
294
  else if (u === ".")
295
- o = y.Property;
295
+ o = m.Property;
296
296
  else
297
297
  throw new Error("Unreachable: pointer points invalid character");
298
298
  }
299
299
  }
300
- if (o !== y.Start)
300
+ if (o !== m.Start)
301
301
  throw new Error(`Failed to parse path: ${JSON.stringify(d)}`);
302
302
  return r;
303
303
  };
304
304
  var M = /* @__PURE__ */ ((d) => (d.DEVELOPMENT = "dev", d.PRODUCTION = "prod", d))(M || {});
305
- const G = (() => {
306
- 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, c = !0) => [typeof e.limit == "number" && (R(e.limit) || a(c, {
305
+ const q = (() => {
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, {
307
307
  path: n + ".limit",
308
308
  expected: 'number & Type<"uint32">',
309
309
  value: e.limit
@@ -319,7 +319,7 @@ const G = (() => {
319
319
  path: n + ".limit",
320
320
  expected: '(number & Type<"uint32"> & Minimum<1> & Maximum<10000>)',
321
321
  value: e.limit
322
- }), e.offset === void 0 || typeof e.offset == "number" && (R(e.offset) || a(c, {
322
+ }), e.offset === void 0 || typeof e.offset == "number" && (K(e.offset) || a(c, {
323
323
  path: n + ".offset",
324
324
  expected: 'number & Type<"uint32">',
325
325
  value: e.offset
@@ -355,7 +355,7 @@ const G = (() => {
355
355
  path: n + ".filterAnd",
356
356
  expected: "(Array<SQLFilterAnd> | undefined)",
357
357
  value: e.filterAnd
358
- })].every((f) => f), l = (e, n, c = !0) => [typeof e.start == "string" && (K(e.start) || a(c, {
358
+ })].every((f) => f), l = (e, n, c = !0) => [typeof e.start == "string" && (R(e.start) || a(c, {
359
359
  path: n + ".start",
360
360
  expected: 'string & Format<"date-time">',
361
361
  value: e.start
@@ -363,7 +363,7 @@ const G = (() => {
363
363
  path: n + ".start",
364
364
  expected: '(string & Format<"date-time">)',
365
365
  value: e.start
366
- }), typeof e.end == "string" && (K(e.end) || a(c, {
366
+ }), typeof e.end == "string" && (R(e.end) || a(c, {
367
367
  path: n + ".end",
368
368
  expected: 'string & Format<"date-time">',
369
369
  value: e.end
@@ -537,7 +537,7 @@ const G = (() => {
537
537
  data: t
538
538
  };
539
539
  });
540
- })(), z = (() => {
540
+ })(), te = (() => {
541
541
  const d = (t) => typeof t.deviceKey == "string" && 1 <= t.deviceKey.length && typeof t.topic == "string" && 1 <= t.topic.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.deviceKey == "string" && (1 <= t.deviceKey.length || u(e, {
542
542
  path: a + ".deviceKey",
543
543
  expected: "string & MinLength<1>",
@@ -648,7 +648,7 @@ function E(d) {
648
648
  var r;
649
649
  return typeof process < "u" ? (r = process.env) == null ? void 0 : r[d] : void 0;
650
650
  }
651
- function ee(d) {
651
+ function z(d) {
652
652
  const r = d ?? E("DEVICE_SERIAL_NUMBER");
653
653
  if (!r)
654
654
  throw new Error("serialNumber option is required (or set DEVICE_SERIAL_NUMBER env var in Node.js)");
@@ -656,7 +656,7 @@ function ee(d) {
656
656
  }
657
657
  class O {
658
658
  constructor(r) {
659
- this._isConfigured = !1, this._serialNumber = ee(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();
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();
660
660
  const s = [];
661
661
  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
662
  `Warning: The following environment variables must be present: ${s.join(", ")}`
@@ -732,23 +732,32 @@ class O {
732
732
  const l = `${this._swarmKey}.${this._appKey}.${r}`;
733
733
  return this.subscribe(l, s, o);
734
734
  }
735
- async call(r, s, o, l, i) {
736
- const u = z({ deviceKey: r, topic: s, args: o, kwargs: l });
737
- if (!u.success)
738
- throw new Error(`Invalid call parameters: ${u.errors.map((a) => a.path + ": " + a.expected).join(", ")}`);
739
- const t = `${r}.${s}`;
740
- return this._connection.call(t, o, l, i);
735
+ async call(r, s, o, l) {
736
+ return this._connection.call(r, s, o, l);
741
737
  }
742
- async registerFunction(r, s, o) {
743
- const l = `${this._swarmKey}.${this._deviceKey}.${this._appKey}.${this._env}.${r}`, i = await this._connection.register(l, s);
738
+ async callDeviceFunction(r, s, o, l, i) {
739
+ const u = `${this._swarmKey}.${r}.${this._appKey}.${this._env}.${s}`;
740
+ return this._connection.call(u, o, l, i);
741
+ }
742
+ /** @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);
745
+ }
746
+ 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);
744
748
  return console.log(`Function registered for IronFlock topic '${r}'. (Full WAMP topic: '${l}')`), i;
745
749
  }
750
+ /** @deprecated Use registerDeviceFunction() instead. */
751
+ async registerFunction(r, s, o) {
752
+ return console.warn("registerFunction() is deprecated and will be removed in a future version. Use registerDeviceFunction() instead."), this.registerDeviceFunction(r, s, o);
753
+ }
746
754
  async register(r, s, o) {
747
- return this.registerFunction(r, s, o);
755
+ return this.registerDeviceFunction(r, s, o);
748
756
  }
749
757
  async getHistory(r, s = { limit: 10 }) {
750
758
  if (!r) throw new Error("Tablename must not be empty!");
751
- const o = G(s);
759
+ s.offset == null && (s.offset = 0);
760
+ const o = q(s);
752
761
  if (!o.success)
753
762
  throw new Error(`Invalid query parameters: ${o.errors.map((i) => i.path + ": " + i.expected).join(", ")}`);
754
763
  const l = `history.transformed.app.${this._appKey}.${r}`;
@@ -803,10 +812,10 @@ export {
803
812
  x as CrossbarConnection,
804
813
  O as IronFlock,
805
814
  M as Stage,
806
- z as validateCallParams,
815
+ te as validateCallParams,
807
816
  X as validateLocationParams,
808
817
  Z as validatePublishParams,
809
818
  T as validateTableParams,
810
- G as validateTableQueryParams
819
+ q as validateTableQueryParams
811
820
  };
812
821
  //# sourceMappingURL=index.mjs.map