ironflock 1.5.1 → 1.5.3

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,22 +1,22 @@
1
- import N from "autobahn";
2
- function B(h) {
1
+ import S from "autobahn";
2
+ function Y(h) {
3
3
  return h && h.__esModule && Object.prototype.hasOwnProperty.call(h, "default") ? h.default : h;
4
4
  }
5
- var S = { exports: {} }, C;
6
- function Y() {
5
+ var N = { exports: {} }, C;
6
+ function H() {
7
7
  return C || (C = 1, (function(h) {
8
- var s = Object.prototype.hasOwnProperty, t = "~";
8
+ var t = Object.prototype.hasOwnProperty, s = "~";
9
9
  function a() {
10
10
  }
11
- Object.create && (a.prototype = /* @__PURE__ */ Object.create(null), new a().__proto__ || (t = !1));
12
- function c(o, e, n) {
11
+ Object.create && (a.prototype = /* @__PURE__ */ Object.create(null), new a().__proto__ || (s = !1));
12
+ function l(o, e, n) {
13
13
  this.fn = o, this.context = e, this.once = n || !1;
14
14
  }
15
- function i(o, e, n, l, d) {
15
+ function i(o, e, n, c, d) {
16
16
  if (typeof n != "function")
17
17
  throw new TypeError("The listener must be a function");
18
- var v = new c(n, l || o, d), f = t ? t + e : e;
19
- return o._events[f] ? o._events[f].fn ? o._events[f] = [o._events[f], v] : o._events[f].push(v) : (o._events[f] = v, o._eventsCount++), o;
18
+ var y = new l(n, c || o, d), f = s ? s + e : e;
19
+ return o._events[f] ? o._events[f].fn ? o._events[f] = [o._events[f], y] : o._events[f].push(y) : (o._events[f] = y, o._eventsCount++), o;
20
20
  }
21
21
  function u(o, e) {
22
22
  --o._eventsCount === 0 ? o._events = new a() : delete o._events[e];
@@ -25,137 +25,137 @@ function Y() {
25
25
  this._events = new a(), this._eventsCount = 0;
26
26
  }
27
27
  r.prototype.eventNames = function() {
28
- var e = [], n, l;
28
+ var e = [], n, c;
29
29
  if (this._eventsCount === 0) return e;
30
- for (l in n = this._events)
31
- s.call(n, l) && e.push(t ? l.slice(1) : l);
30
+ for (c in n = this._events)
31
+ t.call(n, c) && e.push(s ? c.slice(1) : c);
32
32
  return Object.getOwnPropertySymbols ? e.concat(Object.getOwnPropertySymbols(n)) : e;
33
33
  }, r.prototype.listeners = function(e) {
34
- var n = t ? t + e : e, l = this._events[n];
35
- if (!l) return [];
36
- if (l.fn) return [l.fn];
37
- for (var d = 0, v = l.length, f = new Array(v); d < v; d++)
38
- f[d] = l[d].fn;
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 d = 0, y = c.length, f = new Array(y); d < y; d++)
38
+ f[d] = c[d].fn;
39
39
  return f;
40
40
  }, r.prototype.listenerCount = function(e) {
41
- var n = t ? t + e : e, l = this._events[n];
42
- return l ? l.fn ? 1 : l.length : 0;
43
- }, r.prototype.emit = function(e, n, l, d, v, f) {
44
- var g = t ? t + e : e;
41
+ var n = s ? s + e : e, c = this._events[n];
42
+ return c ? c.fn ? 1 : c.length : 0;
43
+ }, r.prototype.emit = function(e, n, c, d, y, f) {
44
+ var g = s ? s + e : e;
45
45
  if (!this._events[g]) return !1;
46
- var y = this._events[g], A = arguments.length, E, m;
47
- if (y.fn) {
48
- switch (y.once && this.removeListener(e, y.fn, void 0, !0), A) {
46
+ var v = this._events[g], b = arguments.length, E, m;
47
+ if (v.fn) {
48
+ switch (v.once && this.removeListener(e, v.fn, void 0, !0), b) {
49
49
  case 1:
50
- return y.fn.call(y.context), !0;
50
+ return v.fn.call(v.context), !0;
51
51
  case 2:
52
- return y.fn.call(y.context, n), !0;
52
+ return v.fn.call(v.context, n), !0;
53
53
  case 3:
54
- return y.fn.call(y.context, n, l), !0;
54
+ return v.fn.call(v.context, n, c), !0;
55
55
  case 4:
56
- return y.fn.call(y.context, n, l, d), !0;
56
+ return v.fn.call(v.context, n, c, d), !0;
57
57
  case 5:
58
- return y.fn.call(y.context, n, l, d, v), !0;
58
+ return v.fn.call(v.context, n, c, d, y), !0;
59
59
  case 6:
60
- return y.fn.call(y.context, n, l, d, v, f), !0;
60
+ return v.fn.call(v.context, n, c, d, y, f), !0;
61
61
  }
62
- for (m = 1, E = new Array(A - 1); m < A; m++)
62
+ for (m = 1, E = new Array(b - 1); m < b; m++)
63
63
  E[m - 1] = arguments[m];
64
- y.fn.apply(y.context, E);
64
+ v.fn.apply(v.context, E);
65
65
  } else {
66
- var W = y.length, $;
67
- for (m = 0; m < W; m++)
68
- switch (y[m].once && this.removeListener(e, y[m].fn, void 0, !0), A) {
66
+ var B = v.length, I;
67
+ for (m = 0; m < B; m++)
68
+ switch (v[m].once && this.removeListener(e, v[m].fn, void 0, !0), b) {
69
69
  case 1:
70
- y[m].fn.call(y[m].context);
70
+ v[m].fn.call(v[m].context);
71
71
  break;
72
72
  case 2:
73
- y[m].fn.call(y[m].context, n);
73
+ v[m].fn.call(v[m].context, n);
74
74
  break;
75
75
  case 3:
76
- y[m].fn.call(y[m].context, n, l);
76
+ v[m].fn.call(v[m].context, n, c);
77
77
  break;
78
78
  case 4:
79
- y[m].fn.call(y[m].context, n, l, d);
79
+ v[m].fn.call(v[m].context, n, c, d);
80
80
  break;
81
81
  default:
82
- if (!E) for ($ = 1, E = new Array(A - 1); $ < A; $++)
83
- E[$ - 1] = arguments[$];
84
- y[m].fn.apply(y[m].context, E);
82
+ if (!E) for (I = 1, E = new Array(b - 1); I < b; I++)
83
+ E[I - 1] = arguments[I];
84
+ v[m].fn.apply(v[m].context, E);
85
85
  }
86
86
  }
87
87
  return !0;
88
- }, r.prototype.on = function(e, n, l) {
89
- return i(this, e, n, l, !1);
90
- }, r.prototype.once = function(e, n, l) {
91
- return i(this, e, n, l, !0);
92
- }, r.prototype.removeListener = function(e, n, l, d) {
93
- var v = t ? t + e : e;
94
- if (!this._events[v]) return this;
88
+ }, r.prototype.on = function(e, n, c) {
89
+ return i(this, e, n, c, !1);
90
+ }, r.prototype.once = function(e, n, c) {
91
+ return i(this, e, n, c, !0);
92
+ }, r.prototype.removeListener = function(e, n, c, d) {
93
+ var y = s ? s + e : e;
94
+ if (!this._events[y]) return this;
95
95
  if (!n)
96
- return u(this, v), this;
97
- var f = this._events[v];
96
+ return u(this, y), this;
97
+ var f = this._events[y];
98
98
  if (f.fn)
99
- f.fn === n && (!d || f.once) && (!l || f.context === l) && u(this, v);
99
+ f.fn === n && (!d || f.once) && (!c || f.context === c) && u(this, y);
100
100
  else {
101
- for (var g = 0, y = [], A = f.length; g < A; g++)
102
- (f[g].fn !== n || d && !f[g].once || l && f[g].context !== l) && y.push(f[g]);
103
- y.length ? this._events[v] = y.length === 1 ? y[0] : y : u(this, v);
101
+ for (var g = 0, v = [], b = f.length; g < b; g++)
102
+ (f[g].fn !== n || d && !f[g].once || c && f[g].context !== c) && v.push(f[g]);
103
+ v.length ? this._events[y] = v.length === 1 ? v[0] : v : u(this, y);
104
104
  }
105
105
  return this;
106
106
  }, r.prototype.removeAllListeners = function(e) {
107
107
  var n;
108
- return e ? (n = t ? t + e : e, this._events[n] && u(this, n)) : (this._events = new a(), this._eventsCount = 0), this;
109
- }, r.prototype.off = r.prototype.removeListener, r.prototype.addListener = r.prototype.on, r.prefixed = t, r.EventEmitter = r, h.exports = r;
110
- })(S)), S.exports;
108
+ return e ? (n = s ? s + e : e, this._events[n] && u(this, n)) : (this._events = new a(), this._eventsCount = 0), this;
109
+ }, r.prototype.off = r.prototype.removeListener, r.prototype.addListener = r.prototype.on, r.prefixed = s, r.EventEmitter = r, h.exports = r;
110
+ })(N)), N.exports;
111
111
  }
112
- var H = Y();
113
- const Q = /* @__PURE__ */ B(H), G = "wss://cbw.datapods.io/ws-ua-usr", D = "wss://cbw.ironflock.com/ws-ua-usr", J = "wss://cbw.ironflock.dev/ws-ua-usr", Z = "wss://cbw.record-evolution.com/ws-ua-usr", O = "ws://localhost:8080/ws-ua-usr", L = {
114
- "https://studio.datapods.io": G,
115
- "https://studio.ironflock.dev": J,
116
- "https://studio.ironflock.com": D,
117
- "https://studio.record-evolution.com": Z,
118
- "http://localhost:8085": O,
119
- "http://localhost:8086": O,
120
- "http://host.docker.internal:8086": O
121
- }, z = 6e3, X = [
112
+ var Q = H();
113
+ const G = /* @__PURE__ */ Y(Q), J = "wss://cbw.datapods.io/ws-ua-usr", j = "wss://cbw.ironflock.com/ws-ua-usr", Z = "wss://cbw.ironflock.dev/ws-ua-usr", z = "wss://cbw.record-evolution.com/ws-ua-usr", K = "ws://localhost:8080/ws-ua-usr", X = "ws://host.docker.internal:8080/ws-ua-usr", L = {
114
+ "https://studio.datapods.io": J,
115
+ "https://studio.ironflock.dev": Z,
116
+ "https://studio.ironflock.com": j,
117
+ "https://studio.record-evolution.com": z,
118
+ "http://localhost:8085": K,
119
+ "http://localhost:8086": K,
120
+ "http://host.docker.internal:8086": X
121
+ }, q = 6e3, ee = [
122
122
  "wamp.error.not_authorized",
123
123
  "wamp.error.authorization_failed",
124
124
  "wamp.error.authentication_failed",
125
125
  "wamp.error.no_auth_method"
126
126
  ];
127
- class _ extends Q {
127
+ class $ extends G {
128
128
  constructor() {
129
129
  super(), this.failOnAuthError = !1, this.subscriptions = [], this.registrations = [], this.firstResolver = () => {
130
130
  }, this.firstRejecter = () => {
131
131
  }, this.shouldReconnect = !1, this.isReconnecting = !1, this.hasOpenedOnce = !1;
132
132
  }
133
- static getWebSocketURI(s) {
134
- var c;
135
- const t = typeof process < "u" ? (c = process.env) == null ? void 0 : c.DEVICE_ENDPOINT_URL : void 0;
136
- if (t)
133
+ static getWebSocketURI(t) {
134
+ var l;
135
+ const s = typeof process < "u" ? (l = process.env) == null ? void 0 : l.DEVICE_ENDPOINT_URL : void 0;
136
+ if (s)
137
137
  try {
138
- const i = new URL(t);
138
+ const i = new URL(s);
139
139
  return i.pathname = "/ws-ua-usr", i.toString().replace(/\/$/, "");
140
140
  } catch {
141
141
  }
142
- if (!s) return D;
143
- const a = L[s];
142
+ if (!t) return j;
143
+ const a = L[t];
144
144
  if (a === void 0)
145
145
  throw new Error(
146
- `Cannot resolve WebSocket URI for reswarmUrl=${JSON.stringify(s)}. Set DEVICE_ENDPOINT_URL to the deployment's WAMP router URL (e.g. ws://<host>:18080/ws-re-dev) or pass ironFlockUrl=… to IronFlock(). Known cloud URLs: ${JSON.stringify(Object.keys(L))}`
146
+ `Cannot resolve WebSocket URI for reswarmUrl=${JSON.stringify(t)}. Set DEVICE_ENDPOINT_URL to the deployment's WAMP router URL (e.g. ws://<host>:18080/ws-re-dev) or pass ironFlockUrl=… to IronFlock(). Known cloud URLs: ${JSON.stringify(Object.keys(L))}`
147
147
  );
148
148
  return a;
149
149
  }
150
- configure(s, t, a, c, i) {
151
- this.realm = `realm-${s}-${t}-${a}`, this.serial_number = c, this.socketURI = i ?? _.getWebSocketURI();
150
+ configure(t, s, a, l, i) {
151
+ this.realm = `realm-${t}-${s}-${a}`, this.serial_number = l, this.socketURI = i ?? $.getWebSocketURI();
152
152
  }
153
153
  async start() {
154
154
  if (!this.realm || !this.serial_number || !this.socketURI)
155
155
  throw new Error("CrossbarConnection must be configured before starting. Call configure() first.");
156
- return this.shouldReconnect = !0, this.firstConnection = new Promise((s, t) => {
157
- this.firstResolver = s, this.firstRejecter = t;
158
- }), this.connection = new N.Connection({
156
+ return this.shouldReconnect = !0, this.firstConnection = new Promise((t, s) => {
157
+ this.firstResolver = t, this.firstRejecter = s;
158
+ }), this.connection = new S.Connection({
159
159
  realm: this.realm,
160
160
  url: this.socketURI,
161
161
  authmethods: ["wampcra"],
@@ -166,49 +166,49 @@ class _ extends Q {
166
166
  // @ts-ignore
167
167
  autoping_interval: 2,
168
168
  autoping_timeout: 4,
169
- onchallenge: (s, t, a) => N.auth_cra.sign(this.serial_number, a.challenge)
169
+ onchallenge: (t, s, a) => S.auth_cra.sign(this.serial_number, a.challenge)
170
170
  }), this.connection.onopen = this.onOpen.bind(this), this.connection.onclose = this.onClose.bind(this), this.connection.open(), this.firstConnection;
171
171
  }
172
- onOpen(s) {
173
- this.session = s, this.session.caller_disclose_me = !0, this.hasOpenedOnce = !0, this.resubscribeAll(), this.reregisterAll(), this.emit("connected", this.serial_number), this.firstResolver(), this.firstResolver = () => {
172
+ onOpen(t) {
173
+ this.session = t, this.session.caller_disclose_me = !0, this.hasOpenedOnce = !0, this.resubscribeAll(), this.reregisterAll(), this.emit("connected", this.serial_number), this.firstResolver(), this.firstResolver = () => {
174
174
  };
175
175
  }
176
- onClose(s, t) {
176
+ onClose(t, s) {
177
177
  this.session = void 0, this.emit("disconnected"), this.firstRejecter(
178
178
  new Error(
179
- `Connection failed: ${s} - ${JSON.stringify(t, null, 2)}`
179
+ `Connection failed: ${t} - ${JSON.stringify(s, null, 2)}`
180
180
  )
181
181
  ), this.firstRejecter = () => {
182
182
  }, console.warn("Connection closed:", {
183
- reason: s,
184
- details: t,
183
+ reason: t,
184
+ details: s,
185
185
  realm: this.realm,
186
186
  url: this.socketURI,
187
187
  authid: this.serial_number
188
188
  });
189
- const a = (t == null ? void 0 : t.reason) ?? s;
190
- return this.failOnAuthError && typeof a == "string" && X.includes(a) ? (this.shouldReconnect = !1, this.emit("auth_failure", a, t), !0) : (this.shouldReconnect && this.hasOpenedOnce && (t == null ? void 0 : t.will_retry) === !1 && this.handleManualReconnect((t == null ? void 0 : t.reason) ?? s), !1);
189
+ const a = (s == null ? void 0 : s.reason) ?? t;
190
+ return this.failOnAuthError && typeof a == "string" && ee.includes(a) ? (this.shouldReconnect = !1, this.emit("auth_failure", a, s), !0) : (this.shouldReconnect && this.hasOpenedOnce && (s == null ? void 0 : s.will_retry) === !1 && this.handleManualReconnect((s == null ? void 0 : s.reason) ?? t), !1);
191
191
  }
192
- async handleManualReconnect(s) {
192
+ async handleManualReconnect(t) {
193
193
  if (!(this.isReconnecting || !this.shouldReconnect)) {
194
194
  for (this.isReconnecting = !0; this.shouldReconnect && !this.session; )
195
- if (await new Promise((t) => setTimeout(t, 1e3)), this.shouldReconnect && this.connection && !this.session) {
196
- console.log(`Manually retrying connection after ${s}...`);
195
+ if (await new Promise((s) => setTimeout(s, 1e3)), this.shouldReconnect && this.connection && !this.session) {
196
+ console.log(`Manually retrying connection after ${t}...`);
197
197
  try {
198
- this.connection.open(), await new Promise((t) => setTimeout(t, 500));
199
- } catch (t) {
200
- console.error("Error during manual reconnection attempt:", t);
198
+ this.connection.open(), await new Promise((s) => setTimeout(s, 500));
199
+ } catch (s) {
200
+ console.error("Error during manual reconnection attempt:", s);
201
201
  }
202
202
  }
203
203
  this.isReconnecting = !1;
204
204
  }
205
205
  }
206
206
  async sessionWait() {
207
- const s = Date.now();
207
+ const t = Date.now();
208
208
  for (; !this.session; ) {
209
- if (Date.now() - s > z)
209
+ if (Date.now() - t > q)
210
210
  throw new Error("Timeout waiting for session");
211
- await new Promise((t) => setTimeout(t, 200));
211
+ await new Promise((s) => setTimeout(s, 200));
212
212
  }
213
213
  }
214
214
  async waitForConnection() {
@@ -218,91 +218,91 @@ class _ extends Q {
218
218
  return this.session;
219
219
  }
220
220
  get is_open() {
221
- var s;
222
- return !!((s = this.session) != null && s.isOpen);
221
+ var t;
222
+ return !!((t = this.session) != null && t.isOpen);
223
223
  }
224
224
  isConnected() {
225
225
  return this.is_open;
226
226
  }
227
227
  stop() {
228
- var s;
229
- this.shouldReconnect = !1, (s = this.connection) == null || s.close("wamp.close.normal", "Connection closed by client");
228
+ var t;
229
+ this.shouldReconnect = !1, (t = this.connection) == null || t.close("wamp.close.normal", "Connection closed by client");
230
230
  }
231
- async subscribe(s, t) {
232
- var c;
231
+ async subscribe(t, s) {
232
+ var l;
233
233
  await this.sessionWait();
234
- const a = await ((c = this.session) == null ? void 0 : c.subscribe(s, t));
234
+ const a = await ((l = this.session) == null ? void 0 : l.subscribe(t, s));
235
235
  return a && this.subscriptions.push(a), a;
236
236
  }
237
- async unsubscribe(s) {
237
+ async unsubscribe(t) {
238
238
  var a;
239
239
  await this.sessionWait();
240
- const t = this.subscriptions.indexOf(s);
241
- t !== -1 && (this.subscriptions.splice(t, 1), await ((a = this.session) == null ? void 0 : a.unsubscribe(s)));
240
+ const s = this.subscriptions.indexOf(t);
241
+ s !== -1 && (this.subscriptions.splice(s, 1), await ((a = this.session) == null ? void 0 : a.unsubscribe(t)));
242
242
  }
243
- async unsubscribeTopic(s) {
244
- const t = this.subscriptions.filter((a) => a.topic === s);
245
- for (const a of t)
243
+ async unsubscribeTopic(t) {
244
+ const s = this.subscriptions.filter((a) => a.topic === t);
245
+ for (const a of s)
246
246
  await this.unsubscribe(a);
247
247
  }
248
248
  async resubscribeAll() {
249
- const s = [...this.subscriptions];
249
+ const t = [...this.subscriptions];
250
250
  this.subscriptions = [], await Promise.all(
251
- s.map((t) => this.subscribe(t.topic, t.handler))
251
+ t.map((s) => this.subscribe(s.topic, s.handler))
252
252
  );
253
253
  }
254
254
  async reregisterAll() {
255
- const s = [...this.registrations];
255
+ const t = [...this.registrations];
256
256
  this.registrations = [], await Promise.all(
257
- s.map((t) => this.register(t.procedure, t.endpoint, t.options))
257
+ t.map((s) => this.register(s.procedure, s.endpoint, s.options))
258
258
  );
259
259
  }
260
- async register(s, t, a) {
260
+ async register(t, s, a) {
261
261
  var u;
262
262
  await this.sessionWait();
263
- const c = { force_reregister: !0, ...a ?? {} }, i = await ((u = this.session) == null ? void 0 : u.register(s, t, c));
263
+ const l = { force_reregister: !0, ...a ?? {} }, i = await ((u = this.session) == null ? void 0 : u.register(t, s, l));
264
264
  return i && this.registrations.push(i), i;
265
265
  }
266
- async unregister(s) {
266
+ async unregister(t) {
267
267
  var a;
268
- await this.sessionWait(), await ((a = this.session) == null ? void 0 : a.unregister(s));
269
- const t = this.registrations.indexOf(s);
270
- t !== -1 && this.registrations.splice(t, 1);
268
+ await this.sessionWait(), await ((a = this.session) == null ? void 0 : a.unregister(t));
269
+ const s = this.registrations.indexOf(t);
270
+ s !== -1 && this.registrations.splice(s, 1);
271
271
  }
272
- async call(s, t, a, c) {
272
+ async call(t, s, a, l) {
273
273
  var i;
274
- return await this.sessionWait(), (i = this.session) == null ? void 0 : i.call(s, t, a, c);
274
+ return await this.sessionWait(), (i = this.session) == null ? void 0 : i.call(t, s, a, l);
275
275
  }
276
- async publish(s, t, a, c) {
276
+ async publish(t, s, a, l) {
277
277
  var i;
278
- return await this.sessionWait(), (i = this.session) == null ? void 0 : i.publish(s, t, a, c);
278
+ return await this.sessionWait(), (i = this.session) == null ? void 0 : i.publish(t, s, a, l);
279
279
  }
280
280
  }
281
- const T = (h) => Math.floor(h) === h && q <= h && h <= ee, q = 0, ee = 2 ** 32 - 1, I = (h) => re.test(h), re = /^[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 = (h) => {
282
- const s = (t) => {
281
+ const T = (h) => Math.floor(h) === h && re <= h && h <= te, re = 0, te = 2 ** 32 - 1, O = (h) => se.test(h), se = /^[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, R = (h) => {
282
+ const t = (s) => {
283
283
  if (h.length === 0)
284
284
  return !0;
285
285
  const a = h[h.length - 1].path;
286
- return t.length > a.length || a.substring(0, t.length) !== t;
286
+ return s.length > a.length || a.substring(0, s.length) !== s;
287
287
  };
288
- return (t, a) => (t && s(a.path) && (a.value === void 0 && (a.description ?? (a.description = [
288
+ return (s, a) => (s && t(a.path) && (a.value === void 0 && (a.description ?? (a.description = [
289
289
  "The value at this path is `undefined`.",
290
290
  "",
291
291
  `Please fill the \`${a.expected}\` typed value next time.`
292
292
  ].join(`
293
293
  `))), h.push(a)), !1);
294
- }, R = (h) => Object.assign(h, {
294
+ }, _ = (h) => Object.assign(h, {
295
295
  "~standard": {
296
296
  version: 1,
297
297
  vendor: "typia",
298
- validate: (s) => {
299
- const t = h(s);
300
- return t.success ? {
301
- value: t.data
298
+ validate: (t) => {
299
+ const s = h(t);
300
+ return s.success ? {
301
+ value: s.data
302
302
  } : {
303
- issues: t.errors.map((a) => ({
303
+ issues: s.errors.map((a) => ({
304
304
  message: `expected ${a.expected}, got ${a.value}`,
305
- path: te(a.path)
305
+ path: ne(a.path)
306
306
  }))
307
307
  };
308
308
  }
@@ -312,26 +312,26 @@ var w;
312
312
  (function(h) {
313
313
  h[h.Start = 0] = "Start", h[h.Property = 1] = "Property", h[h.StringKey = 2] = "StringKey", h[h.NumberKey = 3] = "NumberKey";
314
314
  })(w || (w = {}));
315
- const te = (h) => {
315
+ const ne = (h) => {
316
316
  if (!h.startsWith("$input"))
317
317
  throw new Error(`Invalid path: ${JSON.stringify(h)}`);
318
- const s = [];
319
- let t = "", a = w.Start, c = 5;
320
- for (; c < h.length - 1; ) {
321
- c++;
322
- const i = h[c];
323
- if (a === w.Property ? i === "." || i === "[" ? (s.push({
324
- key: t
325
- }), a = w.Start) : c === h.length - 1 ? (t += i, s.push({
326
- key: t
327
- }), c++, a = w.Start) : t += i : a === w.StringKey ? i === '"' ? (s.push({
328
- key: JSON.parse(t + i)
329
- }), c += 2, a = w.Start) : i === "\\" ? (t += h[c], c++, t += h[c]) : t += i : a === w.NumberKey && (i === "]" ? (s.push({
330
- key: Number.parseInt(t)
331
- }), c++, a = w.Start) : t += i), a === w.Start && c < h.length - 1) {
332
- const u = h[c];
333
- if (t = "", u === "[")
334
- h[c + 1] === '"' ? (a = w.StringKey, c++, t = '"') : a = w.NumberKey;
318
+ const t = [];
319
+ let s = "", a = w.Start, l = 5;
320
+ for (; l < h.length - 1; ) {
321
+ l++;
322
+ const i = h[l];
323
+ if (a === w.Property ? i === "." || i === "[" ? (t.push({
324
+ key: s
325
+ }), a = w.Start) : l === h.length - 1 ? (s += i, t.push({
326
+ key: s
327
+ }), l++, a = w.Start) : s += i : a === w.StringKey ? i === '"' ? (t.push({
328
+ key: JSON.parse(s + i)
329
+ }), l += 2, a = w.Start) : i === "\\" ? (s += h[l], l++, s += h[l]) : s += i : a === w.NumberKey && (i === "]" ? (t.push({
330
+ key: Number.parseInt(s)
331
+ }), l++, a = w.Start) : s += i), a === w.Start && l < h.length - 1) {
332
+ const u = h[l];
333
+ if (s = "", u === "[")
334
+ h[l + 1] === '"' ? (a = w.StringKey, l++, s = '"') : a = w.NumberKey;
335
335
  else if (u === ".")
336
336
  a = w.Property;
337
337
  else
@@ -340,126 +340,126 @@ const te = (h) => {
340
340
  }
341
341
  if (a !== w.Start)
342
342
  throw new Error(`Failed to parse path: ${JSON.stringify(h)}`);
343
- return s;
343
+ return t;
344
344
  };
345
345
  var k = /* @__PURE__ */ ((h) => (h.DEVELOPMENT = "dev", h.PRODUCTION = "prod", h))(k || {});
346
- const U = (() => {
347
- const h = (e) => typeof e.limit == "number" && T(e.limit) && 1 <= e.limit && e.limit <= 1e4 && (e.offset === void 0 || typeof e.offset == "number" && T(e.offset) && 0 <= e.offset) && (e.timeRange === void 0 || typeof e.timeRange == "object" && e.timeRange !== null && s(e.timeRange)) && (e.filterAnd === void 0 || Array.isArray(e.filterAnd) && e.filterAnd.every((n) => typeof n == "object" && n !== null && t(n))), s = (e) => typeof e.start == "string" && I(e.start) && typeof e.end == "string" && I(e.end), t = (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")), a = (e, n, l = !0) => [typeof e.limit == "number" && (T(e.limit) || o(l, {
346
+ const F = (() => {
347
+ const h = (e) => typeof e.limit == "number" && T(e.limit) && 1 <= e.limit && e.limit <= 1e4 && (e.offset === void 0 || typeof e.offset == "number" && T(e.offset) && 0 <= e.offset) && (e.timeRange === void 0 || typeof e.timeRange == "object" && e.timeRange !== null && t(e.timeRange)) && (e.filterAnd === void 0 || Array.isArray(e.filterAnd) && e.filterAnd.every((n) => typeof n == "object" && n !== null && s(n))), t = (e) => typeof e.start == "string" && O(e.start) && typeof e.end == "string" && O(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")), a = (e, n, c = !0) => [typeof e.limit == "number" && (T(e.limit) || o(c, {
348
348
  path: n + ".limit",
349
349
  expected: 'number & Type<"uint32">',
350
350
  value: e.limit
351
- })) && (1 <= e.limit || o(l, {
351
+ })) && (1 <= e.limit || o(c, {
352
352
  path: n + ".limit",
353
353
  expected: "number & Minimum<1>",
354
354
  value: e.limit
355
- })) && (e.limit <= 1e4 || o(l, {
355
+ })) && (e.limit <= 1e4 || o(c, {
356
356
  path: n + ".limit",
357
357
  expected: "number & Maximum<10000>",
358
358
  value: e.limit
359
- })) || o(l, {
359
+ })) || o(c, {
360
360
  path: n + ".limit",
361
361
  expected: '(number & Type<"uint32"> & Minimum<1> & Maximum<10000>)',
362
362
  value: e.limit
363
- }), e.offset === void 0 || typeof e.offset == "number" && (T(e.offset) || o(l, {
363
+ }), e.offset === void 0 || typeof e.offset == "number" && (T(e.offset) || o(c, {
364
364
  path: n + ".offset",
365
365
  expected: 'number & Type<"uint32">',
366
366
  value: e.offset
367
- })) && (0 <= e.offset || o(l, {
367
+ })) && (0 <= e.offset || o(c, {
368
368
  path: n + ".offset",
369
369
  expected: "number & Minimum<0>",
370
370
  value: e.offset
371
- })) || o(l, {
371
+ })) || o(c, {
372
372
  path: n + ".offset",
373
373
  expected: '((number & Type<"uint32"> & Minimum<0>) | undefined)',
374
374
  value: e.offset
375
- }), e.timeRange === void 0 || (typeof e.timeRange == "object" && e.timeRange !== null || o(l, {
375
+ }), e.timeRange === void 0 || (typeof e.timeRange == "object" && e.timeRange !== null || o(c, {
376
376
  path: n + ".timeRange",
377
377
  expected: "(ISOTimeRange | undefined)",
378
378
  value: e.timeRange
379
- })) && c(e.timeRange, n + ".timeRange", l) || o(l, {
379
+ })) && l(e.timeRange, n + ".timeRange", c) || o(c, {
380
380
  path: n + ".timeRange",
381
381
  expected: "(ISOTimeRange | undefined)",
382
382
  value: e.timeRange
383
- }), e.filterAnd === void 0 || (Array.isArray(e.filterAnd) || o(l, {
383
+ }), e.filterAnd === void 0 || (Array.isArray(e.filterAnd) || o(c, {
384
384
  path: n + ".filterAnd",
385
385
  expected: "(Array<SQLFilterAnd> | undefined)",
386
386
  value: e.filterAnd
387
- })) && e.filterAnd.map((d, v) => (typeof d == "object" && d !== null || o(l, {
388
- path: n + ".filterAnd[" + v + "]",
387
+ })) && e.filterAnd.map((d, y) => (typeof d == "object" && d !== null || o(c, {
388
+ path: n + ".filterAnd[" + y + "]",
389
389
  expected: "SQLFilterAnd",
390
390
  value: d
391
- })) && i(d, n + ".filterAnd[" + v + "]", l) || o(l, {
392
- path: n + ".filterAnd[" + v + "]",
391
+ })) && i(d, n + ".filterAnd[" + y + "]", c) || o(c, {
392
+ path: n + ".filterAnd[" + y + "]",
393
393
  expected: "SQLFilterAnd",
394
394
  value: d
395
- })).every((d) => d) || o(l, {
395
+ })).every((d) => d) || o(c, {
396
396
  path: n + ".filterAnd",
397
397
  expected: "(Array<SQLFilterAnd> | undefined)",
398
398
  value: e.filterAnd
399
- })].every((d) => d), c = (e, n, l = !0) => [typeof e.start == "string" && (I(e.start) || o(l, {
399
+ })].every((d) => d), l = (e, n, c = !0) => [typeof e.start == "string" && (O(e.start) || o(c, {
400
400
  path: n + ".start",
401
401
  expected: 'string & Format<"date-time">',
402
402
  value: e.start
403
- })) || o(l, {
403
+ })) || o(c, {
404
404
  path: n + ".start",
405
405
  expected: '(string & Format<"date-time">)',
406
406
  value: e.start
407
- }), typeof e.end == "string" && (I(e.end) || o(l, {
407
+ }), typeof e.end == "string" && (O(e.end) || o(c, {
408
408
  path: n + ".end",
409
409
  expected: 'string & Format<"date-time">',
410
410
  value: e.end
411
- })) || o(l, {
411
+ })) || o(c, {
412
412
  path: n + ".end",
413
413
  expected: '(string & Format<"date-time">)',
414
414
  value: e.end
415
- })].every((d) => d), i = (e, n, l = !0) => [typeof e.column == "string" && (1 <= e.column.length || o(l, {
415
+ })].every((d) => d), i = (e, n, c = !0) => [typeof e.column == "string" && (1 <= e.column.length || o(c, {
416
416
  path: n + ".column",
417
417
  expected: "string & MinLength<1>",
418
418
  value: e.column
419
- })) || o(l, {
419
+ })) || o(c, {
420
420
  path: n + ".column",
421
421
  expected: "(string & MinLength<1>)",
422
422
  value: e.column
423
- }), typeof e.operator == "string" && (1 <= e.operator.length || o(l, {
423
+ }), typeof e.operator == "string" && (1 <= e.operator.length || o(c, {
424
424
  path: n + ".operator",
425
425
  expected: "string & MinLength<1>",
426
426
  value: e.operator
427
- })) || o(l, {
427
+ })) || o(c, {
428
428
  path: n + ".operator",
429
429
  expected: "(string & MinLength<1>)",
430
430
  value: e.operator
431
- }), (e.value !== null || o(l, {
431
+ }), (e.value !== null || o(c, {
432
432
  path: n + ".value",
433
433
  expected: "(Array<string | number> | boolean | number | string)",
434
434
  value: e.value
435
- })) && (e.value !== void 0 || o(l, {
435
+ })) && (e.value !== void 0 || o(c, {
436
436
  path: n + ".value",
437
437
  expected: "(Array<string | number> | boolean | number | string)",
438
438
  value: e.value
439
- })) && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || (Array.isArray(e.value) || o(l, {
439
+ })) && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || (Array.isArray(e.value) || o(c, {
440
440
  path: n + ".value",
441
441
  expected: "(Array<string | number> | boolean | number | string)",
442
442
  value: e.value
443
- })) && e.value.map((d, v) => typeof d == "string" || typeof d == "number" || o(l, {
444
- path: n + ".value[" + v + "]",
443
+ })) && e.value.map((d, y) => typeof d == "string" || typeof d == "number" || o(c, {
444
+ path: n + ".value[" + y + "]",
445
445
  expected: "(number | string)",
446
446
  value: d
447
- })).every((d) => d) || o(l, {
447
+ })).every((d) => d) || o(c, {
448
448
  path: n + ".value",
449
449
  expected: "(Array<string | number> | boolean | number | string)",
450
450
  value: e.value
451
451
  }))].every((d) => d), u = (e) => typeof e == "object" && e !== null && h(e);
452
452
  let r, o;
453
- return R((e) => {
453
+ return _((e) => {
454
454
  if (u(e) === !1) {
455
- r = [], o = p(r), ((l, d, v = !0) => (typeof l == "object" && l !== null || o(!0, {
455
+ r = [], o = R(r), ((c, d, y = !0) => (typeof c == "object" && c !== null || o(!0, {
456
456
  path: d + "",
457
457
  expected: "TableQueryParams",
458
- value: l
459
- })) && a(l, d + "", !0) || o(!0, {
458
+ value: c
459
+ })) && a(c, d + "", !0) || o(!0, {
460
460
  path: d + "",
461
461
  expected: "TableQueryParams",
462
- value: l
462
+ value: c
463
463
  }))(e, "$input", !0);
464
464
  const n = r.length === 0;
465
465
  return n ? {
@@ -476,9 +476,9 @@ const U = (() => {
476
476
  data: e
477
477
  };
478
478
  });
479
- })(), F = (() => {
479
+ })(), V = (() => {
480
480
  const h = (e) => {
481
- const n = e, l = [
481
+ const n = e, c = [
482
482
  [
483
483
  (d) => d.length === 2 && (d[0] === null || typeof d[0] == "number") && (d[1] === null || typeof d[1] == "number"),
484
484
  (d) => d.length === 2 && (d[0] === null || typeof d[0] == "number") && (d[1] === null || typeof d[1] == "number")
@@ -488,28 +488,28 @@ const U = (() => {
488
488
  (d) => d.length === 2 && (d[0] === null || typeof d[0] == "string") && (d[1] === null || typeof d[1] == "string")
489
489
  ]
490
490
  ];
491
- for (const d of l)
491
+ for (const d of c)
492
492
  if (d[0](n))
493
493
  return d[1](n);
494
494
  return !1;
495
- }, s = (e, n, l = !0) => {
496
- const d = e, v = [
495
+ }, t = (e, n, c = !0) => {
496
+ const d = e, y = [
497
497
  [
498
498
  (f) => f.length === 2 && [
499
499
  f[0] === null || typeof f[0] == "number",
500
500
  f[1] === null || typeof f[1] == "number"
501
501
  ].every((g) => g),
502
- (f) => (f.length === 2 || o(l, {
502
+ (f) => (f.length === 2 || o(c, {
503
503
  path: n,
504
504
  expected: "[(null | number), (null | number)]",
505
505
  value: f
506
506
  })) && [
507
- f[0] === null || typeof f[0] == "number" || o(l, {
507
+ f[0] === null || typeof f[0] == "number" || o(c, {
508
508
  path: n + "[0]",
509
509
  expected: "(null | number)",
510
510
  value: f[0]
511
511
  }),
512
- f[1] === null || typeof f[1] == "number" || o(l, {
512
+ f[1] === null || typeof f[1] == "number" || o(c, {
513
513
  path: n + "[1]",
514
514
  expected: "(null | number)",
515
515
  value: f[1]
@@ -521,17 +521,17 @@ const U = (() => {
521
521
  f[0] === null || typeof f[0] == "string",
522
522
  f[1] === null || typeof f[1] == "string"
523
523
  ].every((g) => g),
524
- (f) => (f.length === 2 || o(l, {
524
+ (f) => (f.length === 2 || o(c, {
525
525
  path: n,
526
526
  expected: "[(null | string), (null | string)]",
527
527
  value: f
528
528
  })) && [
529
- f[0] === null || typeof f[0] == "string" || o(l, {
529
+ f[0] === null || typeof f[0] == "string" || o(c, {
530
530
  path: n + "[0]",
531
531
  expected: "(null | string)",
532
532
  value: f[0]
533
533
  }),
534
- f[1] === null || typeof f[1] == "string" || o(l, {
534
+ f[1] === null || typeof f[1] == "string" || o(c, {
535
535
  path: n + "[1]",
536
536
  expected: "(null | string)",
537
537
  value: f[1]
@@ -539,134 +539,134 @@ const U = (() => {
539
539
  ].every((g) => g)
540
540
  ]
541
541
  ];
542
- for (const f of v)
542
+ for (const f of y)
543
543
  if (f[0](d))
544
544
  return f[1](d);
545
- return o(l, {
545
+ return o(c, {
546
546
  path: n,
547
547
  expected: "([number | null, number | null] | [string | null, string | null])",
548
548
  value: e
549
549
  });
550
- }, t = (e) => Array.isArray(e.metrics) && e.metrics.every((n) => typeof n == "string") && (e.method === "AVG" || e.method === "SUM" || e.method === "COUNT" || e.method === "MIN" || e.method === "MAX" || e.method === "FIRST" || e.method === "LAST") && typeof e.limit == "number" && T(e.limit) && 1 <= e.limit && e.limit <= 1e4 && Array.isArray(e.timeRange) && (h(e.timeRange) || !1) && (e.groupBy === null || e.groupBy === void 0 || Array.isArray(e.groupBy) && e.groupBy.every((n) => typeof n == "string")) && (e.filterAnd === null || e.filterAnd === void 0 || Array.isArray(e.filterAnd) && e.filterAnd.every((n) => typeof n == "object" && n !== null && a(n))), a = (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")), c = (e, n, l = !0) => [(Array.isArray(e.metrics) || o(l, {
550
+ }, s = (e) => Array.isArray(e.metrics) && e.metrics.every((n) => typeof n == "string") && (e.method === "AVG" || e.method === "SUM" || e.method === "COUNT" || e.method === "MIN" || e.method === "MAX" || e.method === "FIRST" || e.method === "LAST") && typeof e.limit == "number" && T(e.limit) && 1 <= e.limit && e.limit <= 1e4 && Array.isArray(e.timeRange) && (h(e.timeRange) || !1) && (e.groupBy === null || e.groupBy === void 0 || Array.isArray(e.groupBy) && e.groupBy.every((n) => typeof n == "string")) && (e.filterAnd === null || e.filterAnd === void 0 || Array.isArray(e.filterAnd) && e.filterAnd.every((n) => typeof n == "object" && n !== null && a(n))), a = (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")), l = (e, n, c = !0) => [(Array.isArray(e.metrics) || o(c, {
551
551
  path: n + ".metrics",
552
552
  expected: "Array<string>",
553
553
  value: e.metrics
554
- })) && e.metrics.map((d, v) => typeof d == "string" || o(l, {
555
- path: n + ".metrics[" + v + "]",
554
+ })) && e.metrics.map((d, y) => typeof d == "string" || o(c, {
555
+ path: n + ".metrics[" + y + "]",
556
556
  expected: "string",
557
557
  value: d
558
- })).every((d) => d) || o(l, {
558
+ })).every((d) => d) || o(c, {
559
559
  path: n + ".metrics",
560
560
  expected: "Array<string>",
561
561
  value: e.metrics
562
- }), e.method === "AVG" || e.method === "SUM" || e.method === "COUNT" || e.method === "MIN" || e.method === "MAX" || e.method === "FIRST" || e.method === "LAST" || o(l, {
562
+ }), e.method === "AVG" || e.method === "SUM" || e.method === "COUNT" || e.method === "MIN" || e.method === "MAX" || e.method === "FIRST" || e.method === "LAST" || o(c, {
563
563
  path: n + ".method",
564
564
  expected: '("AVG" | "COUNT" | "FIRST" | "LAST" | "MAX" | "MIN" | "SUM")',
565
565
  value: e.method
566
- }), typeof e.limit == "number" && (T(e.limit) || o(l, {
566
+ }), typeof e.limit == "number" && (T(e.limit) || o(c, {
567
567
  path: n + ".limit",
568
568
  expected: 'number & Type<"uint32">',
569
569
  value: e.limit
570
- })) && (1 <= e.limit || o(l, {
570
+ })) && (1 <= e.limit || o(c, {
571
571
  path: n + ".limit",
572
572
  expected: "number & Minimum<1>",
573
573
  value: e.limit
574
- })) && (e.limit <= 1e4 || o(l, {
574
+ })) && (e.limit <= 1e4 || o(c, {
575
575
  path: n + ".limit",
576
576
  expected: "number & Maximum<10000>",
577
577
  value: e.limit
578
- })) || o(l, {
578
+ })) || o(c, {
579
579
  path: n + ".limit",
580
580
  expected: '(number & Type<"uint32"> & Minimum<1> & Maximum<10000>)',
581
581
  value: e.limit
582
- }), (Array.isArray(e.timeRange) || o(l, {
582
+ }), (Array.isArray(e.timeRange) || o(c, {
583
583
  path: n + ".timeRange",
584
584
  expected: "([number | null, number | null] | [string | null, string | null])",
585
585
  value: e.timeRange
586
- })) && (s(e.timeRange, n + ".timeRange", l) || o(l, {
586
+ })) && (t(e.timeRange, n + ".timeRange", c) || o(c, {
587
587
  path: n + ".timeRange",
588
588
  expected: "[number | null, number | null] | [string | null, string | null]",
589
589
  value: e.timeRange
590
- })) || o(l, {
590
+ })) || o(c, {
591
591
  path: n + ".timeRange",
592
592
  expected: "([number | null, number | null] | [string | null, string | null])",
593
593
  value: e.timeRange
594
- }), e.groupBy === null || e.groupBy === void 0 || (Array.isArray(e.groupBy) || o(l, {
594
+ }), e.groupBy === null || e.groupBy === void 0 || (Array.isArray(e.groupBy) || o(c, {
595
595
  path: n + ".groupBy",
596
596
  expected: "(Array<string> | null | undefined)",
597
597
  value: e.groupBy
598
- })) && e.groupBy.map((d, v) => typeof d == "string" || o(l, {
599
- path: n + ".groupBy[" + v + "]",
598
+ })) && e.groupBy.map((d, y) => typeof d == "string" || o(c, {
599
+ path: n + ".groupBy[" + y + "]",
600
600
  expected: "string",
601
601
  value: d
602
- })).every((d) => d) || o(l, {
602
+ })).every((d) => d) || o(c, {
603
603
  path: n + ".groupBy",
604
604
  expected: "(Array<string> | null | undefined)",
605
605
  value: e.groupBy
606
- }), e.filterAnd === null || e.filterAnd === void 0 || (Array.isArray(e.filterAnd) || o(l, {
606
+ }), e.filterAnd === null || e.filterAnd === void 0 || (Array.isArray(e.filterAnd) || o(c, {
607
607
  path: n + ".filterAnd",
608
608
  expected: "(Array<SQLFilterAnd> | null | undefined)",
609
609
  value: e.filterAnd
610
- })) && e.filterAnd.map((d, v) => (typeof d == "object" && d !== null || o(l, {
611
- path: n + ".filterAnd[" + v + "]",
610
+ })) && e.filterAnd.map((d, y) => (typeof d == "object" && d !== null || o(c, {
611
+ path: n + ".filterAnd[" + y + "]",
612
612
  expected: "SQLFilterAnd",
613
613
  value: d
614
- })) && i(d, n + ".filterAnd[" + v + "]", l) || o(l, {
615
- path: n + ".filterAnd[" + v + "]",
614
+ })) && i(d, n + ".filterAnd[" + y + "]", c) || o(c, {
615
+ path: n + ".filterAnd[" + y + "]",
616
616
  expected: "SQLFilterAnd",
617
617
  value: d
618
- })).every((d) => d) || o(l, {
618
+ })).every((d) => d) || o(c, {
619
619
  path: n + ".filterAnd",
620
620
  expected: "(Array<SQLFilterAnd> | null | undefined)",
621
621
  value: e.filterAnd
622
- })].every((d) => d), i = (e, n, l = !0) => [typeof e.column == "string" && (1 <= e.column.length || o(l, {
622
+ })].every((d) => d), i = (e, n, c = !0) => [typeof e.column == "string" && (1 <= e.column.length || o(c, {
623
623
  path: n + ".column",
624
624
  expected: "string & MinLength<1>",
625
625
  value: e.column
626
- })) || o(l, {
626
+ })) || o(c, {
627
627
  path: n + ".column",
628
628
  expected: "(string & MinLength<1>)",
629
629
  value: e.column
630
- }), typeof e.operator == "string" && (1 <= e.operator.length || o(l, {
630
+ }), typeof e.operator == "string" && (1 <= e.operator.length || o(c, {
631
631
  path: n + ".operator",
632
632
  expected: "string & MinLength<1>",
633
633
  value: e.operator
634
- })) || o(l, {
634
+ })) || o(c, {
635
635
  path: n + ".operator",
636
636
  expected: "(string & MinLength<1>)",
637
637
  value: e.operator
638
- }), (e.value !== null || o(l, {
638
+ }), (e.value !== null || o(c, {
639
639
  path: n + ".value",
640
640
  expected: "(Array<string | number> | boolean | number | string)",
641
641
  value: e.value
642
- })) && (e.value !== void 0 || o(l, {
642
+ })) && (e.value !== void 0 || o(c, {
643
643
  path: n + ".value",
644
644
  expected: "(Array<string | number> | boolean | number | string)",
645
645
  value: e.value
646
- })) && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || (Array.isArray(e.value) || o(l, {
646
+ })) && (typeof e.value == "string" || typeof e.value == "number" || typeof e.value == "boolean" || (Array.isArray(e.value) || o(c, {
647
647
  path: n + ".value",
648
648
  expected: "(Array<string | number> | boolean | number | string)",
649
649
  value: e.value
650
- })) && e.value.map((d, v) => typeof d == "string" || typeof d == "number" || o(l, {
651
- path: n + ".value[" + v + "]",
650
+ })) && e.value.map((d, y) => typeof d == "string" || typeof d == "number" || o(c, {
651
+ path: n + ".value[" + y + "]",
652
652
  expected: "(number | string)",
653
653
  value: d
654
- })).every((d) => d) || o(l, {
654
+ })).every((d) => d) || o(c, {
655
655
  path: n + ".value",
656
656
  expected: "(Array<string | number> | boolean | number | string)",
657
657
  value: e.value
658
- }))].every((d) => d), u = (e) => typeof e == "object" && e !== null && t(e);
658
+ }))].every((d) => d), u = (e) => typeof e == "object" && e !== null && s(e);
659
659
  let r, o;
660
- return R((e) => {
660
+ return _((e) => {
661
661
  if (u(e) === !1) {
662
- r = [], o = p(r), ((l, d, v = !0) => (typeof l == "object" && l !== null || o(!0, {
662
+ r = [], o = R(r), ((c, d, y = !0) => (typeof c == "object" && c !== null || o(!0, {
663
663
  path: d + "",
664
664
  expected: "SeriesQueryParams",
665
- value: l
666
- })) && c(l, d + "", !0) || o(!0, {
665
+ value: c
666
+ })) && l(c, d + "", !0) || o(!0, {
667
667
  path: d + "",
668
668
  expected: "SeriesQueryParams",
669
- value: l
669
+ value: c
670
670
  }))(e, "$input", !0);
671
671
  const n = r.length === 0;
672
672
  return n ? {
@@ -683,40 +683,40 @@ const U = (() => {
683
683
  data: e
684
684
  };
685
685
  });
686
- })(), se = (() => {
687
- const h = (i) => typeof i.longitude == "number" && -180 <= i.longitude && i.longitude <= 180 && typeof i.latitude == "number" && -90 <= i.latitude && i.latitude <= 90, s = (i, u, r = !0) => [typeof i.longitude == "number" && (-180 <= i.longitude || c(r, {
686
+ })(), oe = (() => {
687
+ const h = (i) => typeof i.longitude == "number" && -180 <= i.longitude && i.longitude <= 180 && typeof i.latitude == "number" && -90 <= i.latitude && i.latitude <= 90, t = (i, u, r = !0) => [typeof i.longitude == "number" && (-180 <= i.longitude || l(r, {
688
688
  path: u + ".longitude",
689
689
  expected: "number & Minimum<-180>",
690
690
  value: i.longitude
691
- })) && (i.longitude <= 180 || c(r, {
691
+ })) && (i.longitude <= 180 || l(r, {
692
692
  path: u + ".longitude",
693
693
  expected: "number & Maximum<180>",
694
694
  value: i.longitude
695
- })) || c(r, {
695
+ })) || l(r, {
696
696
  path: u + ".longitude",
697
697
  expected: "(number & Minimum<-180> & Maximum<180>)",
698
698
  value: i.longitude
699
- }), typeof i.latitude == "number" && (-90 <= i.latitude || c(r, {
699
+ }), typeof i.latitude == "number" && (-90 <= i.latitude || l(r, {
700
700
  path: u + ".latitude",
701
701
  expected: "number & Minimum<-90>",
702
702
  value: i.latitude
703
- })) && (i.latitude <= 90 || c(r, {
703
+ })) && (i.latitude <= 90 || l(r, {
704
704
  path: u + ".latitude",
705
705
  expected: "number & Maximum<90>",
706
706
  value: i.latitude
707
- })) || c(r, {
707
+ })) || l(r, {
708
708
  path: u + ".latitude",
709
709
  expected: "(number & Minimum<-90> & Maximum<90>)",
710
710
  value: i.latitude
711
- })].every((o) => o), t = (i) => typeof i == "object" && i !== null && h(i);
712
- let a, c;
713
- return R((i) => {
714
- if (t(i) === !1) {
715
- a = [], c = p(a), ((r, o, e = !0) => (typeof r == "object" && r !== null || c(!0, {
711
+ })].every((o) => o), s = (i) => typeof i == "object" && i !== null && h(i);
712
+ let a, l;
713
+ return _((i) => {
714
+ if (s(i) === !1) {
715
+ a = [], l = R(a), ((r, o, e = !0) => (typeof r == "object" && r !== null || l(!0, {
716
716
  path: o + "",
717
717
  expected: "LocationParams",
718
718
  value: r
719
- })) && s(r, o + "", !0) || c(!0, {
719
+ })) && t(r, o + "", !0) || l(!0, {
720
720
  path: o + "",
721
721
  expected: "LocationParams",
722
722
  value: r
@@ -736,8 +736,8 @@ const U = (() => {
736
736
  data: i
737
737
  };
738
738
  });
739
- })(), ne = (() => {
740
- const h = (r) => typeof r.topic == "string" && 1 <= r.topic.length && (r.args === void 0 || Array.isArray(r.args)) && (r.kwargs === void 0 || typeof r.kwargs == "object" && r.kwargs !== null && Array.isArray(r.kwargs) === !1 && s(r.kwargs)), s = (r) => Object.keys(r).every((o) => (r[o] === void 0, !0)), t = (r, o, e = !0) => [typeof r.topic == "string" && (1 <= r.topic.length || u(e, {
739
+ })(), ae = (() => {
740
+ const h = (r) => typeof r.topic == "string" && 1 <= r.topic.length && (r.args === void 0 || Array.isArray(r.args)) && (r.kwargs === void 0 || typeof r.kwargs == "object" && r.kwargs !== null && Array.isArray(r.kwargs) === !1 && t(r.kwargs)), t = (r) => Object.keys(r).every((o) => (r[o] === void 0, !0)), s = (r, o, e = !0) => [typeof r.topic == "string" && (1 <= r.topic.length || u(e, {
741
741
  path: o + ".topic",
742
742
  expected: "string & MinLength<1>",
743
743
  value: r.topic
@@ -757,15 +757,15 @@ const U = (() => {
757
757
  path: o + ".kwargs",
758
758
  expected: "(Record<string, unknown> | undefined)",
759
759
  value: r.kwargs
760
- })].every((n) => n), a = (r, o, e = !0) => [e === !1 || Object.keys(r).map((n) => (r[n] === void 0, !0)).every((n) => n)].every((n) => n), c = (r) => typeof r == "object" && r !== null && h(r);
760
+ })].every((n) => n), a = (r, o, e = !0) => [e === !1 || Object.keys(r).map((n) => (r[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (r) => typeof r == "object" && r !== null && h(r);
761
761
  let i, u;
762
- return R((r) => {
763
- if (c(r) === !1) {
764
- i = [], u = p(i), ((e, n, l = !0) => (typeof e == "object" && e !== null || u(!0, {
762
+ return _((r) => {
763
+ if (l(r) === !1) {
764
+ i = [], u = R(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
765
765
  path: n + "",
766
766
  expected: "PublishParams",
767
767
  value: e
768
- })) && t(e, n + "", !0) || u(!0, {
768
+ })) && s(e, n + "", !0) || u(!0, {
769
769
  path: n + "",
770
770
  expected: "PublishParams",
771
771
  value: e
@@ -785,8 +785,8 @@ const U = (() => {
785
785
  data: r
786
786
  };
787
787
  });
788
- })(), ce = (() => {
789
- const h = (r) => typeof r.deviceKey == "string" && 1 <= r.deviceKey.length && typeof r.topic == "string" && 1 <= r.topic.length && (r.args === void 0 || Array.isArray(r.args)) && (r.kwargs === void 0 || typeof r.kwargs == "object" && r.kwargs !== null && Array.isArray(r.kwargs) === !1 && s(r.kwargs)), s = (r) => Object.keys(r).every((o) => (r[o] === void 0, !0)), t = (r, o, e = !0) => [typeof r.deviceKey == "string" && (1 <= r.deviceKey.length || u(e, {
788
+ })(), de = (() => {
789
+ const h = (r) => typeof r.deviceKey == "string" && 1 <= r.deviceKey.length && typeof r.topic == "string" && 1 <= r.topic.length && (r.args === void 0 || Array.isArray(r.args)) && (r.kwargs === void 0 || typeof r.kwargs == "object" && r.kwargs !== null && Array.isArray(r.kwargs) === !1 && t(r.kwargs)), t = (r) => Object.keys(r).every((o) => (r[o] === void 0, !0)), s = (r, o, e = !0) => [typeof r.deviceKey == "string" && (1 <= r.deviceKey.length || u(e, {
790
790
  path: o + ".deviceKey",
791
791
  expected: "string & MinLength<1>",
792
792
  value: r.deviceKey
@@ -814,15 +814,15 @@ const U = (() => {
814
814
  path: o + ".kwargs",
815
815
  expected: "(Record<string, unknown> | undefined)",
816
816
  value: r.kwargs
817
- })].every((n) => n), a = (r, o, e = !0) => [e === !1 || Object.keys(r).map((n) => (r[n] === void 0, !0)).every((n) => n)].every((n) => n), c = (r) => typeof r == "object" && r !== null && h(r);
817
+ })].every((n) => n), a = (r, o, e = !0) => [e === !1 || Object.keys(r).map((n) => (r[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (r) => typeof r == "object" && r !== null && h(r);
818
818
  let i, u;
819
- return R((r) => {
820
- if (c(r) === !1) {
821
- i = [], u = p(i), ((e, n, l = !0) => (typeof e == "object" && e !== null || u(!0, {
819
+ return _((r) => {
820
+ if (l(r) === !1) {
821
+ i = [], u = R(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
822
822
  path: n + "",
823
823
  expected: "CallParams",
824
824
  value: e
825
- })) && t(e, n + "", !0) || u(!0, {
825
+ })) && s(e, n + "", !0) || u(!0, {
826
826
  path: n + "",
827
827
  expected: "CallParams",
828
828
  value: e
@@ -842,8 +842,8 @@ const U = (() => {
842
842
  data: r
843
843
  };
844
844
  });
845
- })(), P = (() => {
846
- const h = (r) => typeof r.tablename == "string" && 1 <= r.tablename.length && (r.args === void 0 || Array.isArray(r.args)) && (r.kwargs === void 0 || typeof r.kwargs == "object" && r.kwargs !== null && Array.isArray(r.kwargs) === !1 && s(r.kwargs)), s = (r) => Object.keys(r).every((o) => (r[o] === void 0, !0)), t = (r, o, e = !0) => [typeof r.tablename == "string" && (1 <= r.tablename.length || u(e, {
845
+ })(), D = (() => {
846
+ const h = (r) => typeof r.tablename == "string" && 1 <= r.tablename.length && (r.args === void 0 || Array.isArray(r.args)) && (r.kwargs === void 0 || typeof r.kwargs == "object" && r.kwargs !== null && Array.isArray(r.kwargs) === !1 && t(r.kwargs)), t = (r) => Object.keys(r).every((o) => (r[o] === void 0, !0)), s = (r, o, e = !0) => [typeof r.tablename == "string" && (1 <= r.tablename.length || u(e, {
847
847
  path: o + ".tablename",
848
848
  expected: "string & MinLength<1>",
849
849
  value: r.tablename
@@ -863,15 +863,15 @@ const U = (() => {
863
863
  path: o + ".kwargs",
864
864
  expected: "(Record<string, unknown> | undefined)",
865
865
  value: r.kwargs
866
- })].every((n) => n), a = (r, o, e = !0) => [e === !1 || Object.keys(r).map((n) => (r[n] === void 0, !0)).every((n) => n)].every((n) => n), c = (r) => typeof r == "object" && r !== null && h(r);
866
+ })].every((n) => n), a = (r, o, e = !0) => [e === !1 || Object.keys(r).map((n) => (r[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (r) => typeof r == "object" && r !== null && h(r);
867
867
  let i, u;
868
- return R((r) => {
869
- if (c(r) === !1) {
870
- i = [], u = p(i), ((e, n, l = !0) => (typeof e == "object" && e !== null || u(!0, {
868
+ return _((r) => {
869
+ if (l(r) === !1) {
870
+ i = [], u = R(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
871
871
  path: n + "",
872
872
  expected: "TableParams",
873
873
  value: e
874
- })) && t(e, n + "", !0) || u(!0, {
874
+ })) && s(e, n + "", !0) || u(!0, {
875
875
  path: n + "",
876
876
  expected: "TableParams",
877
877
  value: e
@@ -891,8 +891,8 @@ const U = (() => {
891
891
  data: r
892
892
  };
893
893
  });
894
- })(), x = (() => {
895
- const h = (r) => typeof r.tablename == "string" && 1 <= r.tablename.length && Array.isArray(r.rows) && 1 <= r.rows.length && r.rows.every((o) => typeof o == "object" && o !== null && Array.isArray(o) === !1 && s(o)) && (r.kwargs === void 0 || typeof r.kwargs == "object" && r.kwargs !== null && Array.isArray(r.kwargs) === !1 && s(r.kwargs)), s = (r) => Object.keys(r).every((o) => (r[o] === void 0, !0)), t = (r, o, e = !0) => [typeof r.tablename == "string" && (1 <= r.tablename.length || u(e, {
894
+ })(), P = (() => {
895
+ const h = (r) => typeof r.tablename == "string" && 1 <= r.tablename.length && Array.isArray(r.rows) && 1 <= r.rows.length && r.rows.every((o) => typeof o == "object" && o !== null && Array.isArray(o) === !1 && t(o)) && (r.kwargs === void 0 || typeof r.kwargs == "object" && r.kwargs !== null && Array.isArray(r.kwargs) === !1 && t(r.kwargs)), t = (r) => Object.keys(r).every((o) => (r[o] === void 0, !0)), s = (r, o, e = !0) => [typeof r.tablename == "string" && (1 <= r.tablename.length || u(e, {
896
896
  path: o + ".tablename",
897
897
  expected: "string & MinLength<1>",
898
898
  value: r.tablename
@@ -908,12 +908,12 @@ const U = (() => {
908
908
  path: o + ".rows",
909
909
  expected: "Array<> & MinItems<1>",
910
910
  value: r.rows
911
- })) && r.rows.map((n, l) => (typeof n == "object" && n !== null && Array.isArray(n) === !1 || u(e, {
912
- path: o + ".rows[" + l + "]",
911
+ })) && r.rows.map((n, c) => (typeof n == "object" && n !== null && Array.isArray(n) === !1 || u(e, {
912
+ path: o + ".rows[" + c + "]",
913
913
  expected: "Record<string, unknown>",
914
914
  value: n
915
- })) && a(n, o + ".rows[" + l + "]", e) || u(e, {
916
- path: o + ".rows[" + l + "]",
915
+ })) && a(n, o + ".rows[" + c + "]", e) || u(e, {
916
+ path: o + ".rows[" + c + "]",
917
917
  expected: "Record<string, unknown>",
918
918
  value: n
919
919
  })).every((n) => n) || u(e, {
@@ -928,15 +928,15 @@ const U = (() => {
928
928
  path: o + ".kwargs",
929
929
  expected: "(Record<string, unknown> | undefined)",
930
930
  value: r.kwargs
931
- })].every((n) => n), a = (r, o, e = !0) => [e === !1 || Object.keys(r).map((n) => (r[n] === void 0, !0)).every((n) => n)].every((n) => n), c = (r) => typeof r == "object" && r !== null && h(r);
931
+ })].every((n) => n), a = (r, o, e = !0) => [e === !1 || Object.keys(r).map((n) => (r[n] === void 0, !0)).every((n) => n)].every((n) => n), l = (r) => typeof r == "object" && r !== null && h(r);
932
932
  let i, u;
933
- return R((r) => {
934
- if (c(r) === !1) {
935
- i = [], u = p(i), ((e, n, l = !0) => (typeof e == "object" && e !== null || u(!0, {
933
+ return _((r) => {
934
+ if (l(r) === !1) {
935
+ i = [], u = R(i), ((e, n, c = !0) => (typeof e == "object" && e !== null || u(!0, {
936
936
  path: n + "",
937
937
  expected: "BulkTableParams",
938
938
  value: e
939
- })) && t(e, n + "", !0) || u(!0, {
939
+ })) && s(e, n + "", !0) || u(!0, {
940
940
  path: n + "",
941
941
  expected: "BulkTableParams",
942
942
  value: e
@@ -956,7 +956,7 @@ const U = (() => {
956
956
  data: r
957
957
  };
958
958
  });
959
- })(), oe = {
959
+ })(), ie = {
960
960
  "sys.appaccess.error.no_grant": "NO_GRANT",
961
961
  "sys.appaccess.error.provider_not_installed": "PROVIDER_NOT_INSTALLED",
962
962
  "sys.appaccess.error.unknown_app": "UNKNOWN_APP",
@@ -964,22 +964,22 @@ const U = (() => {
964
964
  "wamp.error.authorization_failed": "NOT_AUTHORIZED",
965
965
  "wamp.error.authentication_failed": "NOT_AUTHORIZED"
966
966
  };
967
- class M extends Error {
968
- constructor(s, t) {
969
- super(t ?? s), this.name = "CrossAppAccessError", this.code = s;
967
+ class p extends Error {
968
+ constructor(t, s) {
969
+ super(s ?? t), this.name = "CrossAppAccessError", this.code = t;
970
970
  }
971
971
  }
972
- function K(h) {
973
- const s = h == null ? void 0 : h.error;
974
- if (typeof s != "string") return null;
975
- const t = oe[s];
976
- if (!t) return null;
977
- const a = h.args, c = Array.isArray(a) && a.length > 0 ? `: ${JSON.stringify(a[0])}` : "";
978
- return new M(t, `${s}${c}`);
972
+ function M(h) {
973
+ const t = h == null ? void 0 : h.error;
974
+ if (typeof t != "string") return null;
975
+ const s = ie[t];
976
+ if (!s) return null;
977
+ const a = h.args, l = Array.isArray(a) && a.length > 0 ? `: ${JSON.stringify(a[0])}` : "";
978
+ return new p(s, `${t}${l}`);
979
979
  }
980
- class ae {
981
- constructor(s, t, a, c, i) {
982
- this.app = s, this.stage = t, this.tables = a.tables ?? [], this.transforms = a.transforms ?? [], this._connection = c, this._onClosed = i;
980
+ class ce {
981
+ constructor(t, s, a, l, i) {
982
+ this.app = t, this.stage = s, this.tables = a.tables ?? [], this.transforms = a.transforms ?? [], this._connection = l, this._onClosed = i;
983
983
  }
984
984
  get connection() {
985
985
  return this._connection;
@@ -990,13 +990,13 @@ class ae {
990
990
  // DX guard: names outside the shared catalog are either private or don't
991
991
  // exist — fail fast client-side instead of silently receiving nothing
992
992
  // (private publishes are filtered via exclude_authrole, not errors).
993
- assertInCatalog(s) {
994
- if (!s) throw new Error("Tablename must not be empty!");
995
- const t = [...this.tables, ...this.transforms].map((a) => a.tablename);
996
- if (!t.includes(s))
997
- throw new M(
993
+ assertInCatalog(t) {
994
+ if (!t) throw new Error("Tablename must not be empty!");
995
+ const s = [...this.tables, ...this.transforms].map((a) => a.tablename);
996
+ if (!s.includes(t))
997
+ throw new p(
998
998
  "PRIVATE_TABLE",
999
- `'${s}' is not shared by app '${this.app}' (${this.stage}). Available tables/transforms: ${t.length > 0 ? t.join(", ") : "none"}`
999
+ `'${t}' is not shared by app '${this.app}' (${this.stage}). Available tables/transforms: ${s.length > 0 ? s.join(", ") : "none"}`
1000
1000
  );
1001
1001
  }
1002
1002
  /**
@@ -1004,71 +1004,84 @@ class ae {
1004
1004
  * (`transformed.bulk.{t}`) are unrolled row-by-row through the same handler,
1005
1005
  * so caller code always sees the single-row shape.
1006
1006
  */
1007
- async subscribeToTable(s, t, a) {
1008
- this.assertInCatalog(s);
1009
- const c = await this._connection.subscribe(`transformed.${s}`, t), i = (u, r, o) => {
1007
+ async subscribeToTable(t, s, a) {
1008
+ this.assertInCatalog(t);
1009
+ const l = await this._connection.subscribe(`transformed.${t}`, s), i = (u, r, o) => {
1010
1010
  const e = Array.isArray(u) ? u[0] : u, n = Array.isArray(e) ? e : e == null ? [] : [e];
1011
- for (const l of n)
1012
- t([l], r, o);
1011
+ for (const c of n)
1012
+ s([c], r, o);
1013
1013
  };
1014
- return await this._connection.subscribe(`transformed.bulk.${s}`, i), c;
1014
+ return await this._connection.subscribe(`transformed.bulk.${t}`, i), l;
1015
1015
  }
1016
1016
  /** Queries history rows of a shared table or transform. */
1017
- async getHistory(s, t = { limit: 10 }) {
1018
- this.assertInCatalog(s), t.offset == null && (t.offset = 0);
1019
- const a = U(t);
1017
+ async getHistory(t, s = { limit: 10 }) {
1018
+ this.assertInCatalog(t), s.offset == null && (s.offset = 0);
1019
+ const a = F(s);
1020
1020
  if (!a.success)
1021
- throw new Error(`Invalid query parameters: ${a.errors.map((c) => c.path + ": " + c.expected).join(", ")}`);
1021
+ throw new Error(`Invalid query parameters: ${a.errors.map((l) => l.path + ": " + l.expected).join(", ")}`);
1022
1022
  try {
1023
- return await this._connection.call(`history.transformed.${s}`, [t]);
1024
- } catch (c) {
1025
- throw K(c) ?? c;
1023
+ return await this._connection.call(`history.transformed.${t}`, [s]);
1024
+ } catch (l) {
1025
+ throw M(l) ?? l;
1026
1026
  }
1027
1027
  }
1028
1028
  /** Queries down-sampled series history of a shared table (tables only — no series RPC exists for transforms). */
1029
- async getSeriesHistory(s, t) {
1030
- if (!s) throw new Error("Tablename must not be empty!");
1029
+ async getSeriesHistory(t, s) {
1030
+ if (!t) throw new Error("Tablename must not be empty!");
1031
1031
  const a = this.tables.map((i) => i.tablename);
1032
- if (!a.includes(s))
1033
- throw this.transforms.some((i) => i.tablename === s) ? new M(
1032
+ if (!a.includes(t))
1033
+ throw this.transforms.some((i) => i.tablename === t) ? new p(
1034
1034
  "PRIVATE_TABLE",
1035
- `'${s}' is a transform of app '${this.app}' (${this.stage}); series history is available for tables only — use getHistory() instead.`
1036
- ) : new M(
1035
+ `'${t}' is a transform of app '${this.app}' (${this.stage}); series history is available for tables only — use getHistory() instead.`
1036
+ ) : new p(
1037
1037
  "PRIVATE_TABLE",
1038
- `'${s}' is not a shared table of app '${this.app}' (${this.stage}). Available tables: ${a.length > 0 ? a.join(", ") : "none"}`
1038
+ `'${t}' is not a shared table of app '${this.app}' (${this.stage}). Available tables: ${a.length > 0 ? a.join(", ") : "none"}`
1039
1039
  );
1040
- const c = F(t);
1041
- if (!c.success)
1042
- throw new Error(`Invalid series query parameters: ${c.errors.map((i) => i.path + ": " + i.expected).join(", ")}`);
1040
+ const l = V(s);
1041
+ if (!l.success)
1042
+ throw new Error(`Invalid series query parameters: ${l.errors.map((i) => i.path + ": " + i.expected).join(", ")}`);
1043
1043
  try {
1044
- return await this._connection.call(`history.transformed.series.${s}`, [t]);
1044
+ return await this._connection.call(`history.transformed.series.${t}`, [s]);
1045
1045
  } catch (i) {
1046
- throw K(i) ?? i;
1046
+ throw M(i) ?? i;
1047
1047
  }
1048
1048
  }
1049
1049
  /** Closes the underlying connection to the provider's realm. */
1050
1050
  async close() {
1051
- var s;
1052
- this._connection.stop(), (s = this._onClosed) == null || s.call(this), this._onClosed = void 0;
1051
+ var t;
1052
+ this._connection.stop(), (t = this._onClosed) == null || t.call(this), this._onClosed = void 0;
1053
1053
  }
1054
1054
  }
1055
- const j = "error-logs";
1056
- function b(h) {
1057
- var s;
1058
- return typeof process < "u" ? (s = process.env) == null ? void 0 : s[h] : void 0;
1055
+ const U = "error-logs";
1056
+ function A(h) {
1057
+ var t;
1058
+ return typeof process < "u" ? (t = process.env) == null ? void 0 : t[h] : void 0;
1059
1059
  }
1060
- function ie(h) {
1061
- const s = h ?? b("DEVICE_SERIAL_NUMBER");
1062
- if (!s)
1060
+ function x(h) {
1061
+ var t;
1062
+ if (typeof process < "u")
1063
+ try {
1064
+ const s = (t = process.getBuiltinModule) == null ? void 0 : t.call(process, "node:fs");
1065
+ if (s) {
1066
+ const a = A("IRONFLOCK_ENV_DIR") ?? "/data/env", l = s.readFileSync(`${a}/${h}.txt`, "utf8").trim();
1067
+ if (l) return l;
1068
+ }
1069
+ } catch {
1070
+ }
1071
+ return A(h);
1072
+ }
1073
+ function le(h) {
1074
+ const t = h ?? A("DEVICE_SERIAL_NUMBER");
1075
+ if (!t)
1063
1076
  throw new Error("serialNumber option is required (or set DEVICE_SERIAL_NUMBER env var in Node.js)");
1064
- return s;
1077
+ return t;
1065
1078
  }
1066
- class V {
1067
- constructor(s) {
1068
- this._isConfigured = !1, this._consumedApps = /* @__PURE__ */ new Map(), this._serialNumber = ie(s == null ? void 0 : s.serialNumber), this._deviceName = (s == null ? void 0 : s.deviceName) ?? b("DEVICE_NAME"), this._deviceKey = (s == null ? void 0 : s.deviceKey) ?? b("DEVICE_KEY"), this._appName = (s == null ? void 0 : s.appName) ?? b("APP_NAME"), this._swarmKey = (s == null ? void 0 : s.swarmKey) ?? parseInt(b("SWARM_KEY") ?? "0", 10), this._appKey = (s == null ? void 0 : s.appKey) ?? parseInt(b("APP_KEY") ?? "0", 10), this._env = (s == null ? void 0 : s.env) ?? b("ENV"), this._reswarmUrl = (s == null ? void 0 : s.reswarmUrl) ?? b("RESWARM_URL"), this._cburl = (s == null ? void 0 : s.ironFlockUrl) ?? (s == null ? void 0 : s.cburl), this._connection = new _();
1069
- const t = [];
1070
- this._deviceKey || t.push("DEVICE_KEY"), this._appName || t.push("APP_NAME"), this._swarmKey || t.push("SWARM_KEY"), this._appKey || t.push("APP_KEY"), t.length > 0 && console.warn(
1071
- `Warning: The following environment variables must be present: ${t.join(", ")}`
1079
+ class W {
1080
+ constructor(t) {
1081
+ this._isConfigured = !1, this._consumedApps = /* @__PURE__ */ new Map(), this._serialNumber = le(t == null ? void 0 : t.serialNumber), this._deviceName = (t == null ? void 0 : t.deviceName) ?? A("DEVICE_NAME"), this._deviceKey = (t == null ? void 0 : t.deviceKey) ?? A("DEVICE_KEY"), this._appName = (t == null ? void 0 : t.appName) ?? A("APP_NAME"), this._swarmKey = (t == null ? void 0 : t.swarmKey) ?? parseInt(A("SWARM_KEY") ?? "0", 10), this._appKey = (t == null ? void 0 : t.appKey) ?? parseInt(A("APP_KEY") ?? "0", 10), this._env = (t == null ? void 0 : t.env) ?? A("ENV"), this._reswarmUrl = (t == null ? void 0 : t.reswarmUrl) ?? A("RESWARM_URL"), this._cburl = (t == null ? void 0 : t.ironFlockUrl) ?? (t == null ? void 0 : t.cburl), this._connection = new $();
1082
+ const s = [];
1083
+ 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(
1084
+ `Warning: The following environment variables must be present: ${s.join(", ")}`
1072
1085
  );
1073
1086
  }
1074
1087
  get connection() {
@@ -1077,27 +1090,27 @@ class V {
1077
1090
  get isConnected() {
1078
1091
  return this._connection.is_open;
1079
1092
  }
1080
- configureConnection(s) {
1093
+ configureConnection(t) {
1081
1094
  if (this._isConfigured) return;
1082
- const t = (this._env ?? "DEV").toUpperCase(), c = {
1095
+ const s = (this._env ?? "DEV").toUpperCase(), l = {
1083
1096
  DEV: k.DEVELOPMENT,
1084
1097
  PROD: k.PRODUCTION
1085
- }[t] ?? k.DEVELOPMENT, i = s ?? this._cburl ?? _.getWebSocketURI(this._reswarmUrl);
1098
+ }[s] ?? k.DEVELOPMENT, i = t ?? this._cburl ?? $.getWebSocketURI(this._reswarmUrl);
1086
1099
  this._connection.configure(
1087
1100
  this._swarmKey,
1088
1101
  this._appKey,
1089
- c,
1102
+ l,
1090
1103
  this._serialNumber,
1091
1104
  i
1092
1105
  ), this._isConfigured = !0;
1093
1106
  }
1094
- async start(s) {
1095
- this.configureConnection(s), await this._connection.start();
1107
+ async start(t) {
1108
+ this.configureConnection(t), await this._connection.start();
1096
1109
  }
1097
1110
  async stop() {
1098
- const s = [...this._consumedApps.values()];
1111
+ const t = [...this._consumedApps.values()];
1099
1112
  this._consumedApps.clear(), await Promise.all(
1100
- s.map((t) => t.then((a) => a.close()).catch(() => {
1113
+ t.map((s) => s.then((a) => a.close()).catch(() => {
1101
1114
  }))
1102
1115
  ), this._connection.stop();
1103
1116
  }
@@ -1114,76 +1127,146 @@ class V {
1114
1127
  * @throws {CrossAppAccessError} NO_GRANT | PROVIDER_NOT_INSTALLED |
1115
1128
  * UNKNOWN_APP | NOT_AUTHORIZED
1116
1129
  */
1117
- async connectToApp(s, t) {
1118
- if (!s) throw new Error("appName must not be empty!");
1119
- const a = (this._env ?? "DEV").toUpperCase() === "PROD" ? "prod" : "dev", c = (t == null ? void 0 : t.stage) ?? a, i = `${s}:${c}`, u = this._consumedApps.get(i);
1130
+ async connectToApp(t, s) {
1131
+ if (!t) throw new Error("appName must not be empty!");
1132
+ const a = (this._env ?? "DEV").toUpperCase() === "PROD" ? "prod" : "dev", l = (s == null ? void 0 : s.stage) ?? a, i = `${t.toLowerCase()}:${l}`, u = this._consumedApps.get(i);
1120
1133
  if (u) return u;
1121
1134
  let r;
1122
1135
  const o = () => {
1123
1136
  this._consumedApps.get(i) === r && this._consumedApps.delete(i);
1124
1137
  };
1125
- return r = this.openConsumedApp(s, c, o, t == null ? void 0 : t.onError), this._consumedApps.set(i, r), r.catch(o), r;
1138
+ return r = this.openConsumedApp(t, l, o, s == null ? void 0 : s.onError), this._consumedApps.set(i, r), r.catch(o), r;
1126
1139
  }
1127
- async openConsumedApp(s, t, a, c) {
1128
- var n;
1140
+ /**
1141
+ * Lists every non-private provider catalog in this project for an app holding
1142
+ * the wildcard consume grant (`consumes: [{app: "*"}]`). One
1143
+ * `sys.appaccess.list` call; opens no consumed-app connections. A picker (e.g.
1144
+ * a Node-RED node) renders the returned catalogs, then calls
1145
+ * {@link connectToApp} per chosen provider; {@link connectToAllApps} opens
1146
+ * them all eagerly.
1147
+ *
1148
+ * @throws {CrossAppAccessError} NO_GRANT when this app holds no wildcard grant.
1149
+ */
1150
+ async listConsumableApps() {
1151
+ try {
1152
+ return await this._connection.call(
1153
+ "sys.appaccess.list",
1154
+ []
1155
+ ) ?? [];
1156
+ } catch (t) {
1157
+ throw M(t) ?? t;
1158
+ }
1159
+ }
1160
+ /**
1161
+ * Opens read-only connections to every non-private provider in this project
1162
+ * (wildcard consumers only). Enumerates providers via {@link listConsumableApps}
1163
+ * and opens each directly from its resolved info — no per-app resolve
1164
+ * round-trip. Each handle is cached under the same `${app}:${stage}` key
1165
+ * {@link connectToApp} uses, so a later `connectToApp(name)` returns the warmed
1166
+ * handle. Providers lacking a data backend for the requested stage are skipped.
1167
+ *
1168
+ * @throws {CrossAppAccessError} NO_GRANT when this app holds no wildcard grant.
1169
+ */
1170
+ async connectToAllApps(t) {
1171
+ var e, n;
1172
+ const s = (this._env ?? "DEV").toUpperCase() === "PROD" ? "prod" : "dev", a = (t == null ? void 0 : t.stage) ?? s, l = (t == null ? void 0 : t.continueOnError) ?? !0, i = await this.listConsumableApps(), u = [];
1173
+ for (const c of i)
1174
+ (e = c.stages) != null && e[a] && u.push(this.openCachedFromInfo(c, a, t == null ? void 0 : t.onError));
1175
+ const r = await Promise.allSettled(u), o = [];
1176
+ for (const c of r)
1177
+ if (c.status === "fulfilled")
1178
+ o.push(c.value);
1179
+ else if (l)
1180
+ (n = t == null ? void 0 : t.onError) == null || n.call(t, c.reason);
1181
+ else
1182
+ throw c.reason;
1183
+ return o;
1184
+ }
1185
+ async openConsumedApp(t, s, a, l) {
1129
1186
  let i;
1130
1187
  try {
1131
1188
  i = await this._connection.call("sys.appaccess.resolve", [
1132
- { app: s }
1189
+ { app: t }
1133
1190
  ]);
1134
- } catch (l) {
1135
- throw K(l) ?? l;
1191
+ } catch (u) {
1192
+ throw M(u) ?? u;
1136
1193
  }
1137
- const u = (n = i == null ? void 0 : i.stages) == null ? void 0 : n[t];
1138
- if (!i || !u)
1139
- throw new M(
1194
+ if (!i)
1195
+ throw new p(
1140
1196
  "PROVIDER_NOT_INSTALLED",
1141
- `App '${s}' has no ${t} data backend in this project`
1197
+ `App '${t}' has no ${s} data backend in this project`
1142
1198
  );
1143
- const r = new _();
1199
+ return this.openFromInfo(i, s, a, l);
1200
+ }
1201
+ /** Caches (or reuses) a connection opened directly from a resolved provider
1202
+ * info, using the same `${app}:${stage}` key as {@link connectToApp}. */
1203
+ openCachedFromInfo(t, s, a) {
1204
+ const l = `${t.app}:${s}`, i = this._consumedApps.get(l);
1205
+ if (i) return i;
1206
+ let u;
1207
+ const r = () => {
1208
+ this._consumedApps.get(l) === u && this._consumedApps.delete(l);
1209
+ };
1210
+ return u = this.openFromInfo(t, s, r, a), this._consumedApps.set(l, u), u.catch(r), u;
1211
+ }
1212
+ /**
1213
+ * Opens the second CrossbarConnection to a provider realm from an already
1214
+ * resolved {@link ConsumedAppInfo} — everything after the sys.appaccess.resolve
1215
+ * round-trip. Shared by {@link connectToApp} (which resolves one provider) and
1216
+ * {@link connectToAllApps} (which lists every provider in one call).
1217
+ */
1218
+ async openFromInfo(t, s, a, l) {
1219
+ var n;
1220
+ const i = t.app, u = (n = t.stages) == null ? void 0 : n[s];
1221
+ if (!u)
1222
+ throw new p(
1223
+ "PROVIDER_NOT_INSTALLED",
1224
+ `App '${i}' has no ${s} data backend in this project`
1225
+ );
1226
+ const r = new $();
1144
1227
  r.failOnAuthError = !0, r.configure(
1145
1228
  this._swarmKey,
1146
- i.provider_app_key,
1147
- t === "prod" ? k.PRODUCTION : k.DEVELOPMENT,
1229
+ t.provider_app_key,
1230
+ s === "prod" ? k.PRODUCTION : k.DEVELOPMENT,
1148
1231
  this._serialNumber,
1149
1232
  // Reuse the own connection's resolved socket URI (set once start() ran).
1150
- this._connection.socketURI ?? this._cburl ?? _.getWebSocketURI(this._reswarmUrl)
1233
+ this._connection.socketURI ?? this._cburl ?? $.getWebSocketURI(this._reswarmUrl)
1151
1234
  );
1152
1235
  let o = !1, e;
1153
- r.on("auth_failure", (l) => {
1154
- e = new M(
1236
+ r.on("auth_failure", (c) => {
1237
+ e = new p(
1155
1238
  "NOT_AUTHORIZED",
1156
- `Access to app '${s}' (${t}) denied: ${l}. The grant may have been revoked.`
1157
- ), a(), o && (c == null || c(e));
1239
+ `Access to app '${i}' (${s}) denied: ${c}. The grant may have been revoked.`
1240
+ ), a(), o && (l == null || l(e));
1158
1241
  });
1159
1242
  try {
1160
1243
  await r.start();
1161
- } catch (l) {
1162
- throw e ?? l;
1244
+ } catch (c) {
1245
+ throw e ?? c;
1163
1246
  }
1164
- return o = !0, new ae(s, t, u, r, a);
1247
+ return o = !0, new ce(i, s, u, r, a);
1165
1248
  }
1166
- async publish(s, t, a) {
1167
- const c = ne({ topic: s, args: t, kwargs: a });
1168
- if (!c.success)
1169
- throw new Error(`Invalid publish parameters: ${c.errors.map((r) => r.path + ": " + r.expected).join(", ")}`);
1249
+ async publish(t, s, a) {
1250
+ const l = ae({ topic: t, args: s, kwargs: a });
1251
+ if (!l.success)
1252
+ throw new Error(`Invalid publish parameters: ${l.errors.map((r) => r.path + ": " + r.expected).join(", ")}`);
1170
1253
  const u = { ...{
1171
1254
  DEVICE_SERIAL_NUMBER: this._serialNumber,
1172
1255
  DEVICE_KEY: this._deviceKey,
1173
1256
  DEVICE_NAME: this._deviceName
1174
1257
  }, ...a ?? {} };
1175
- return this._connection.publish(s, t, u, {
1258
+ return this._connection.publish(t, s, u, {
1176
1259
  acknowledge: !0
1177
1260
  });
1178
1261
  }
1179
- async publishToTable(s, t, a) {
1180
- const c = P({ tablename: s, args: t, kwargs: a });
1181
- if (!c.success)
1182
- throw new Error(`Invalid table parameters: ${c.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
1262
+ async publishToTable(t, s, a) {
1263
+ const l = D({ tablename: t, args: s, kwargs: a });
1264
+ if (!l.success)
1265
+ throw new Error(`Invalid table parameters: ${l.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
1183
1266
  if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
1184
1267
  if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
1185
- const i = `${this._swarmKey}.${this._appKey}.${s}`;
1186
- return this.publish(i, t, a);
1268
+ const i = `${this._swarmKey}.${this._appKey}.${t}`;
1269
+ return this.publish(i, s, a);
1187
1270
  }
1188
1271
  /**
1189
1272
  * Reports an application error into the databackend's `error-logs` table.
@@ -1199,27 +1282,27 @@ class V {
1199
1282
  * @param error An error message, or an Error whose stack/message is recorded.
1200
1283
  * @param opts Optional level (default "error"), append flag, and tsp override.
1201
1284
  */
1202
- async reportError(s, t) {
1203
- const a = s instanceof Error ? s.stack ?? s.message : s, c = {
1204
- tsp: (t == null ? void 0 : t.tsp) ?? (/* @__PURE__ */ new Date()).toISOString(),
1285
+ async reportError(t, s) {
1286
+ const a = t instanceof Error ? t.stack ?? t.message : t, l = {
1287
+ tsp: (s == null ? void 0 : s.tsp) ?? (/* @__PURE__ */ new Date()).toISOString(),
1205
1288
  msg: a,
1206
1289
  source: "app",
1207
- level: (t == null ? void 0 : t.level) ?? "error"
1290
+ level: (s == null ? void 0 : s.level) ?? "error"
1208
1291
  };
1209
- return t != null && t.append ? this.appendToTable(j, [c]) : this.publishToTable(j, [c]);
1292
+ return s != null && s.append ? this.appendToTable(U, [l]) : this.publishToTable(U, [l]);
1210
1293
  }
1211
- async appendToTable(s, t, a) {
1212
- const c = P({ tablename: s, args: t, kwargs: a });
1213
- if (!c.success)
1214
- throw new Error(`Invalid table parameters: ${c.errors.map((o) => o.path + ": " + o.expected).join(", ")}`);
1294
+ async appendToTable(t, s, a) {
1295
+ const l = D({ tablename: t, args: s, kwargs: a });
1296
+ if (!l.success)
1297
+ throw new Error(`Invalid table parameters: ${l.errors.map((o) => o.path + ": " + o.expected).join(", ")}`);
1215
1298
  if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
1216
1299
  if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
1217
- const i = `append.${this._swarmKey}.${this._appKey}.${s}`, r = { ...{
1300
+ const i = `append.${this._swarmKey}.${this._appKey}.${t}`, r = { ...{
1218
1301
  DEVICE_SERIAL_NUMBER: this._serialNumber,
1219
1302
  DEVICE_KEY: this._deviceKey,
1220
1303
  DEVICE_NAME: this._deviceName
1221
1304
  }, ...a ?? {} };
1222
- return this._connection.call(i, t, r);
1305
+ return this._connection.call(i, s, r);
1223
1306
  }
1224
1307
  /**
1225
1308
  * Publishes many rows in a single message (bulk insert) to the dedicated topic
@@ -1229,14 +1312,14 @@ class V {
1229
1312
  * confirms delivery to the router, not the DB insert. Use appendRowsToTable when
1230
1313
  * you need the insert outcome.
1231
1314
  */
1232
- async publishRowsToTable(s, t, a) {
1233
- const c = x({ tablename: s, rows: t, kwargs: a });
1234
- if (!c.success)
1235
- throw new Error(`Invalid bulk table parameters: ${c.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
1315
+ async publishRowsToTable(t, s, a) {
1316
+ const l = P({ tablename: t, rows: s, kwargs: a });
1317
+ if (!l.success)
1318
+ throw new Error(`Invalid bulk table parameters: ${l.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
1236
1319
  if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
1237
1320
  if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
1238
- const i = `bulk.${this._swarmKey}.${this._appKey}.${s}`;
1239
- return this.publish(i, [t], a);
1321
+ const i = `bulk.${this._swarmKey}.${this._appKey}.${t}`;
1322
+ return this.publish(i, [s], a);
1240
1323
  }
1241
1324
  /**
1242
1325
  * Appends many rows in a single RPC (bulk insert) by calling the dedicated
@@ -1246,66 +1329,66 @@ class V {
1246
1329
  * (e.g. { success: true, count: N }). Prefer over publishRowsToTable when you
1247
1330
  * need the insert outcome.
1248
1331
  */
1249
- async appendRowsToTable(s, t, a) {
1250
- const c = x({ tablename: s, rows: t, kwargs: a });
1251
- if (!c.success)
1252
- throw new Error(`Invalid bulk table parameters: ${c.errors.map((o) => o.path + ": " + o.expected).join(", ")}`);
1332
+ async appendRowsToTable(t, s, a) {
1333
+ const l = P({ tablename: t, rows: s, kwargs: a });
1334
+ if (!l.success)
1335
+ throw new Error(`Invalid bulk table parameters: ${l.errors.map((o) => o.path + ": " + o.expected).join(", ")}`);
1253
1336
  if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
1254
1337
  if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
1255
- const i = `appendBulk.${this._swarmKey}.${this._appKey}.${s}`, r = { ...{
1338
+ const i = `appendBulk.${this._swarmKey}.${this._appKey}.${t}`, r = { ...{
1256
1339
  DEVICE_SERIAL_NUMBER: this._serialNumber,
1257
1340
  DEVICE_KEY: this._deviceKey,
1258
1341
  DEVICE_NAME: this._deviceName
1259
1342
  }, ...a ?? {} };
1260
- return this._connection.call(i, [t], r);
1343
+ return this._connection.call(i, [s], r);
1261
1344
  }
1262
- async subscribe(s, t, a) {
1263
- return this._connection.subscribe(s, t);
1345
+ async subscribe(t, s, a) {
1346
+ return this._connection.subscribe(t, s);
1264
1347
  }
1265
- async subscribeToTable(s, t, a) {
1348
+ async subscribeToTable(t, s, a) {
1266
1349
  if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
1267
1350
  if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
1268
- const c = `transformed.${s}`, i = await this.subscribe(c, t, a), u = (r, o, e) => {
1269
- const n = Array.isArray(r) ? r[0] : r, l = Array.isArray(n) ? n : n == null ? [] : [n];
1270
- for (const d of l)
1271
- t([d], o, e);
1351
+ const l = `transformed.${t}`, i = await this.subscribe(l, s, a), u = (r, o, e) => {
1352
+ const n = Array.isArray(r) ? r[0] : r, c = Array.isArray(n) ? n : n == null ? [] : [n];
1353
+ for (const d of c)
1354
+ s([d], o, e);
1272
1355
  };
1273
- return await this.subscribe(`transformed.bulk.${s}`, u, a), i;
1356
+ return await this.subscribe(`transformed.bulk.${t}`, u, a), i;
1274
1357
  }
1275
- async call(s, t, a, c) {
1276
- return this._connection.call(s, t, a, c);
1358
+ async call(t, s, a, l) {
1359
+ return this._connection.call(t, s, a, l);
1277
1360
  }
1278
- async callDeviceFunction(s, t, a, c, i) {
1279
- const u = `${this._swarmKey}.${s}.${this._appKey}.${this._env}.${t}`;
1280
- return this._connection.call(u, a, c, i);
1361
+ async callDeviceFunction(t, s, a, l, i) {
1362
+ const u = `${this._swarmKey}.${t}.${this._appKey}.${this._env}.${s}`;
1363
+ return this._connection.call(u, a, l, i);
1281
1364
  }
1282
1365
  /** @deprecated Use callDeviceFunction() instead. */
1283
- async callFunction(s, t, a, c, i) {
1284
- return console.warn("callFunction() is deprecated and will be removed in a future version. Use callDeviceFunction() instead."), this.callDeviceFunction(s, t, a, c, i);
1366
+ async callFunction(t, s, a, l, i) {
1367
+ return console.warn("callFunction() is deprecated and will be removed in a future version. Use callDeviceFunction() instead."), this.callDeviceFunction(t, s, a, l, i);
1285
1368
  }
1286
- async registerDeviceFunction(s, t, a) {
1287
- const c = `${this._swarmKey}.${this._deviceKey}.${this._appKey}.${this._env}.${s}`, i = await this._connection.register(c, t, a);
1288
- return console.log(`Function registered for IronFlock topic '${s}'. (Full WAMP topic: '${c}')`), i;
1369
+ async registerDeviceFunction(t, s, a) {
1370
+ const l = `${this._swarmKey}.${this._deviceKey}.${this._appKey}.${this._env}.${t}`, i = await this._connection.register(l, s, a);
1371
+ return console.log(`Function registered for IronFlock topic '${t}'. (Full WAMP topic: '${l}')`), i;
1289
1372
  }
1290
1373
  /** @deprecated Use registerDeviceFunction() instead. */
1291
- async registerFunction(s, t, a) {
1292
- return console.warn("registerFunction() is deprecated and will be removed in a future version. Use registerDeviceFunction() instead."), this.registerDeviceFunction(s, t, a);
1374
+ async registerFunction(t, s, a) {
1375
+ return console.warn("registerFunction() is deprecated and will be removed in a future version. Use registerDeviceFunction() instead."), this.registerDeviceFunction(t, s, a);
1293
1376
  }
1294
- async register(s, t, a) {
1295
- return this.registerDeviceFunction(s, t, a);
1377
+ async register(t, s, a) {
1378
+ return this.registerDeviceFunction(t, s, a);
1296
1379
  }
1297
- async getHistory(s, t = { limit: 10 }) {
1298
- if (!s) throw new Error("Tablename must not be empty!");
1299
- t.offset == null && (t.offset = 0);
1300
- const a = U(t);
1380
+ async getHistory(t, s = { limit: 10 }) {
1381
+ if (!t) throw new Error("Tablename must not be empty!");
1382
+ s.offset == null && (s.offset = 0);
1383
+ const a = F(s);
1301
1384
  if (!a.success)
1302
1385
  throw new Error(`Invalid query parameters: ${a.errors.map((i) => i.path + ": " + i.expected).join(", ")}`);
1303
- const c = `history.transformed.${s}`;
1386
+ const l = `history.transformed.${t}`;
1304
1387
  try {
1305
- return await this._connection.call(c, [t]);
1388
+ return await this._connection.call(l, [s]);
1306
1389
  } catch (i) {
1307
1390
  const u = String(i);
1308
- 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);
1391
+ 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);
1309
1392
  }
1310
1393
  }
1311
1394
  /**
@@ -1313,24 +1396,24 @@ class V {
1313
1396
  * `history.transformed.series.{tablename}` (tables only — no series RPC
1314
1397
  * exists for transforms).
1315
1398
  */
1316
- async getSeriesHistory(s, t) {
1317
- if (!s) throw new Error("Tablename must not be empty!");
1318
- const a = F(t);
1399
+ async getSeriesHistory(t, s) {
1400
+ if (!t) throw new Error("Tablename must not be empty!");
1401
+ const a = V(s);
1319
1402
  if (!a.success)
1320
1403
  throw new Error(`Invalid series query parameters: ${a.errors.map((i) => i.path + ": " + i.expected).join(", ")}`);
1321
- const c = `history.transformed.series.${s}`;
1404
+ const l = `history.transformed.series.${t}`;
1322
1405
  try {
1323
- return await this._connection.call(c, [t]);
1406
+ return await this._connection.call(l, [s]);
1324
1407
  } catch (i) {
1325
1408
  const u = String(i);
1326
- return u.includes("no_such_procedure") || u.includes("no callee registered") ? (console.error(`Get series history failed: History service procedure '${c}' not registered`), null) : (console.error(`Get series history failed: ${i}`), null);
1409
+ return u.includes("no_such_procedure") || u.includes("no callee registered") ? (console.error(`Get series history failed: History service procedure '${l}' not registered`), null) : (console.error(`Get series history failed: ${i}`), null);
1327
1410
  }
1328
1411
  }
1329
- async setDeviceLocation(s, t) {
1330
- const a = se({ longitude: s, latitude: t });
1412
+ async setDeviceLocation(t, s) {
1413
+ const a = oe({ longitude: t, latitude: s });
1331
1414
  if (!a.success)
1332
1415
  throw new Error(`Invalid location parameters: ${a.errors.map((u) => u.path + ": " + u.expected).join(", ")}`);
1333
- const c = { long: s, lat: t }, i = {
1416
+ const l = { long: t, lat: s }, i = {
1334
1417
  DEVICE_SERIAL_NUMBER: this._serialNumber,
1335
1418
  DEVICE_KEY: this._deviceKey,
1336
1419
  DEVICE_NAME: this._deviceName
@@ -1338,15 +1421,67 @@ class V {
1338
1421
  try {
1339
1422
  return await this._connection.call(
1340
1423
  "ironflock.location_service.update",
1341
- [c],
1424
+ [l],
1342
1425
  i
1343
1426
  );
1344
1427
  } catch (u) {
1345
1428
  return console.error(`Set location failed: ${u}`), null;
1346
1429
  }
1347
1430
  }
1348
- getRemoteAccessUrlForPort(s) {
1349
- return this._deviceKey && this._appName ? `https://${this._deviceKey}-${this._appName.toLowerCase()}-${s}.app.ironflock.com` : null;
1431
+ /**
1432
+ * Public URL under which a declared port (port-template.yml) is reachable
1433
+ * from the internet once its tunnel is active.
1434
+ *
1435
+ * For `http`/`https` ports, composes the platform's tunnel label
1436
+ * `{device_key}-{app_name}-{port}` (`https` ports carry the platform's
1437
+ * `secure-` prefix) on the tunnel domain the device agent injects
1438
+ * (`TUNNEL_DOMAIN`; the cloud edge, or the operator's appliance domain).
1439
+ * On devices that belong to an instance (appliance), the agent injects
1440
+ * `INSTANCE_KEY` and the cloud-forwarded route
1441
+ * `https://i{instance_key}-{label}.{cloud edge}` is returned instead —
1442
+ * reachable while the instance forwards its tunnels to the cloud.
1443
+ *
1444
+ * For `tcp`/`udp` ports, the URL uses the tunnel-assigned public port,
1445
+ * which the platform injects under the port-template's
1446
+ * `remote_port_environment` name — pass that name here. On instance
1447
+ * devices the internet-facing port arrives as `{name}_CLOUD`; when it is
1448
+ * not (yet) present, the instance-local URL built from `{name}` is
1449
+ * returned as a fallback.
1450
+ *
1451
+ * Port values are read live from the agent-maintained files under
1452
+ * `/data/env` (falling back to the process environment), so this method
1453
+ * returns the CURRENT url: the instance cloud port is allocated shortly
1454
+ * after the tunnel first connects and appears here within seconds — call
1455
+ * the method again rather than caching its result.
1456
+ *
1457
+ * Returns null when the identity or required env vars are unavailable,
1458
+ * the protocol is unknown, or the label is not a valid DNS label (longer
1459
+ * than 63 characters, or a dot in the app name).
1460
+ */
1461
+ getRemoteAccessUrlForPort(t, s = "http", a) {
1462
+ const l = A("INSTANCE_KEY");
1463
+ if (s === "tcp" || s === "udp") {
1464
+ if (!a)
1465
+ return null;
1466
+ if (l) {
1467
+ const e = x(`${a}_CLOUD`);
1468
+ if (e) {
1469
+ const n = A("CLOUD_TUNNEL_DOMAIN") ?? "app.ironflock.com";
1470
+ return `${s}://${n}:${e}`;
1471
+ }
1472
+ }
1473
+ const r = x(a);
1474
+ if (!r)
1475
+ return null;
1476
+ const o = A("TUNNEL_DOMAIN") ?? "app.ironflock.com";
1477
+ return `${s}://${o}:${r}`;
1478
+ }
1479
+ if (s !== "http" && s !== "https" || !this._deviceKey || !this._appName)
1480
+ return null;
1481
+ let i = `${this._deviceKey}-${this._appName.toLowerCase()}-${t}`;
1482
+ s === "https" && (i = `secure-${i}`);
1483
+ let u;
1484
+ return l ? (i = `i${l}-${i}`, u = A("CLOUD_TUNNEL_DOMAIN") ?? "app.ironflock.com") : u = A("TUNNEL_DOMAIN") ?? "app.ironflock.com", i.length > 63 || i.includes(".") ? null : `https://${i}.${u}`;
1350
1485
  }
1351
1486
  /**
1352
1487
  * Create an IronFlock instance by fetching configuration from a server endpoint.
@@ -1358,27 +1493,27 @@ class V {
1358
1493
  * await flock.start();
1359
1494
  * ```
1360
1495
  */
1361
- static async fromServer(s) {
1362
- const t = await fetch(s);
1363
- if (!t.ok)
1364
- throw new Error(`Failed to fetch IronFlock config from ${s}: ${t.status} ${t.statusText}`);
1365
- const a = await t.json();
1366
- return new V(a);
1496
+ static async fromServer(t) {
1497
+ const s = await fetch(t);
1498
+ if (!s.ok)
1499
+ throw new Error(`Failed to fetch IronFlock config from ${t}: ${s.status} ${s.statusText}`);
1500
+ const a = await s.json();
1501
+ return new W(a);
1367
1502
  }
1368
1503
  }
1369
1504
  export {
1370
- ae as ConsumedApp,
1371
- M as CrossAppAccessError,
1372
- _ as CrossbarConnection,
1373
- j as ERROR_LOGS_TABLE,
1374
- V as IronFlock,
1505
+ ce as ConsumedApp,
1506
+ p as CrossAppAccessError,
1507
+ $ as CrossbarConnection,
1508
+ U as ERROR_LOGS_TABLE,
1509
+ W as IronFlock,
1375
1510
  k as Stage,
1376
- x as validateBulkTableParams,
1377
- ce as validateCallParams,
1378
- se as validateLocationParams,
1379
- ne as validatePublishParams,
1380
- F as validateSeriesQueryParams,
1381
- P as validateTableParams,
1382
- U as validateTableQueryParams
1511
+ P as validateBulkTableParams,
1512
+ de as validateCallParams,
1513
+ oe as validateLocationParams,
1514
+ ae as validatePublishParams,
1515
+ V as validateSeriesQueryParams,
1516
+ D as validateTableParams,
1517
+ F as validateTableQueryParams
1383
1518
  };
1384
1519
  //# sourceMappingURL=index.mjs.map