ironflock 1.0.2 → 1.1.1
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/README.md +258 -24
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +146 -2
- package/dist/index.mjs +669 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -11
- package/dist/crossbar/index.d.ts +0 -38
- package/dist/crossbar/index.js +0 -153
- package/dist/crossbar/serializer.d.ts +0 -8
- package/dist/crossbar/serializer.js +0 -55
- package/dist/index.js +0 -3
- package/dist/ironflock.d.ts +0 -19
- package/dist/ironflock.js +0 -166
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.js +0 -69
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -26
- package/src/crossbar/index.ts +0 -125
- package/src/crossbar/serializer.ts +0 -31
- package/src/index.ts +0 -3
- package/src/ironflock.ts +0 -109
- package/src/test/index.ts +0 -28
- package/src/utils/index.ts +0 -25
- package/tsconfig.json +0 -21
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
import R from "autobahn";
|
|
2
|
+
import { EventEmitter as M } from "events";
|
|
3
|
+
const _ = "wss://cbw.datapods.io/ws-ua-usr", E = "wss://cbw.ironflock.com/ws-ua-usr", p = "wss://cbw.ironflock.dev/ws-ua-usr", K = "wss://cbw.record-evolution.com/ws-ua-usr", A = "ws://localhost:8080/ws-ua-usr", I = {
|
|
4
|
+
"https://studio.datapods.io": _,
|
|
5
|
+
"https://studio.ironflock.dev": p,
|
|
6
|
+
"https://studio.ironflock.com": E,
|
|
7
|
+
"https://studio.record-evolution.com": K,
|
|
8
|
+
"http://localhost:8085": A,
|
|
9
|
+
"http://localhost:8086": A,
|
|
10
|
+
"http://host.docker.internal:8086": A
|
|
11
|
+
}, S = 6e3;
|
|
12
|
+
class k extends M {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(), this.subscriptions = [], this.registrations = [], this.firstResolver = () => {
|
|
15
|
+
}, this.firstRejecter = () => {
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
static getWebSocketURI() {
|
|
19
|
+
const t = process.env.RESWARM_URL;
|
|
20
|
+
return t ? I[t] ?? E : E;
|
|
21
|
+
}
|
|
22
|
+
configure(t, s, o, c, n) {
|
|
23
|
+
this.realm = `realm-${t}-${s}-${o}`, this.serial_number = c, this.socketURI = n ?? k.getWebSocketURI();
|
|
24
|
+
}
|
|
25
|
+
async start() {
|
|
26
|
+
if (!this.realm || !this.serial_number || !this.socketURI)
|
|
27
|
+
throw new Error("CrossbarConnection must be configured before starting. Call configure() first.");
|
|
28
|
+
return this.firstConnection = new Promise((t, s) => {
|
|
29
|
+
this.firstResolver = t, this.firstRejecter = s;
|
|
30
|
+
}), this.connection = new R.Connection({
|
|
31
|
+
realm: this.realm,
|
|
32
|
+
url: this.socketURI,
|
|
33
|
+
authmethods: ["wampcra"],
|
|
34
|
+
authid: this.serial_number,
|
|
35
|
+
max_retries: -1,
|
|
36
|
+
max_retry_delay: 2,
|
|
37
|
+
initial_retry_delay: 1,
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
autoping_interval: 2,
|
|
40
|
+
autoping_timeout: 4,
|
|
41
|
+
onchallenge: (t, s, o) => R.auth_cra.sign(this.serial_number, o.challenge)
|
|
42
|
+
}), this.connection.onopen = this.onOpen.bind(this), this.connection.onclose = this.onClose.bind(this), this.connection.open(), this.firstConnection;
|
|
43
|
+
}
|
|
44
|
+
onOpen(t) {
|
|
45
|
+
this.session = t, this.session.caller_disclose_me = !0, this.resubscribeAll(), this.emit("connected", this.serial_number), this.firstResolver(), this.firstResolver = () => {
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
onClose(t, s) {
|
|
49
|
+
return this.session = void 0, this.emit("disconnected"), this.firstRejecter(
|
|
50
|
+
new Error(
|
|
51
|
+
`Connection failed: ${t} - ${JSON.stringify(s, null, 2)}`
|
|
52
|
+
)
|
|
53
|
+
), this.firstRejecter = () => {
|
|
54
|
+
}, console.warn("Connection closed:", {
|
|
55
|
+
reason: t,
|
|
56
|
+
details: s,
|
|
57
|
+
realm: this.realm,
|
|
58
|
+
url: this.socketURI,
|
|
59
|
+
authid: this.serial_number
|
|
60
|
+
}), !1;
|
|
61
|
+
}
|
|
62
|
+
async sessionWait() {
|
|
63
|
+
const t = Date.now();
|
|
64
|
+
for (; !this.session; ) {
|
|
65
|
+
if (Date.now() - t > S)
|
|
66
|
+
throw new Error("Timeout waiting for session");
|
|
67
|
+
await new Promise((s) => setTimeout(s, 200));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async waitForConnection() {
|
|
71
|
+
return this.firstConnection;
|
|
72
|
+
}
|
|
73
|
+
getSession() {
|
|
74
|
+
return this.session;
|
|
75
|
+
}
|
|
76
|
+
get is_open() {
|
|
77
|
+
var t;
|
|
78
|
+
return !!((t = this.session) != null && t.isOpen);
|
|
79
|
+
}
|
|
80
|
+
isConnected() {
|
|
81
|
+
return this.is_open;
|
|
82
|
+
}
|
|
83
|
+
stop() {
|
|
84
|
+
var t;
|
|
85
|
+
(t = this.connection) == null || t.close("wamp.close.normal", "Connection closed by client");
|
|
86
|
+
}
|
|
87
|
+
async subscribe(t, s) {
|
|
88
|
+
var c;
|
|
89
|
+
await this.sessionWait();
|
|
90
|
+
const o = await ((c = this.session) == null ? void 0 : c.subscribe(t, s));
|
|
91
|
+
return o && this.subscriptions.push(o), o;
|
|
92
|
+
}
|
|
93
|
+
async unsubscribe(t) {
|
|
94
|
+
var o;
|
|
95
|
+
await this.sessionWait();
|
|
96
|
+
const s = this.subscriptions.indexOf(t);
|
|
97
|
+
s !== -1 && (this.subscriptions.splice(s, 1), await ((o = this.session) == null ? void 0 : o.unsubscribe(t)));
|
|
98
|
+
}
|
|
99
|
+
async unsubscribeTopic(t) {
|
|
100
|
+
const s = this.subscriptions.filter((o) => o.topic === t);
|
|
101
|
+
for (const o of s)
|
|
102
|
+
await this.unsubscribe(o);
|
|
103
|
+
}
|
|
104
|
+
async resubscribeAll() {
|
|
105
|
+
const t = [...this.subscriptions];
|
|
106
|
+
this.subscriptions = [], await Promise.all(
|
|
107
|
+
t.map((s) => this.subscribe(s.topic, s.handler))
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
async register(t, s) {
|
|
111
|
+
var c;
|
|
112
|
+
await this.sessionWait();
|
|
113
|
+
const o = await ((c = this.session) == null ? void 0 : c.register(t, s));
|
|
114
|
+
return o && this.registrations.push(o), o;
|
|
115
|
+
}
|
|
116
|
+
async unregister(t) {
|
|
117
|
+
var o;
|
|
118
|
+
await this.sessionWait(), await ((o = this.session) == null ? void 0 : o.unregister(t));
|
|
119
|
+
const s = this.registrations.indexOf(t);
|
|
120
|
+
s !== -1 && this.registrations.splice(s, 1);
|
|
121
|
+
}
|
|
122
|
+
async call(t, s, o, c) {
|
|
123
|
+
var n;
|
|
124
|
+
return await this.sessionWait(), (n = this.session) == null ? void 0 : n.call(t, s, o, c);
|
|
125
|
+
}
|
|
126
|
+
async publish(t, s, o, c) {
|
|
127
|
+
var n;
|
|
128
|
+
return await this.sessionWait(), (n = this.session) == null ? void 0 : n.publish(t, s, o, c);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const y = (d) => Math.floor(d) === d && $ <= d && d <= T, $ = 0, T = 2 ** 32 - 1, w = (d) => N.test(d), N = /^[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, f = (d) => {
|
|
132
|
+
const t = (s) => {
|
|
133
|
+
if (d.length === 0)
|
|
134
|
+
return !0;
|
|
135
|
+
const o = d[d.length - 1].path;
|
|
136
|
+
return s.length > o.length || o.substring(0, s.length) !== s;
|
|
137
|
+
};
|
|
138
|
+
return (s, o) => (s && t(o.path) && (o.value === void 0 && (o.description ?? (o.description = [
|
|
139
|
+
"The value at this path is `undefined`.",
|
|
140
|
+
"",
|
|
141
|
+
`Please fill the \`${o.expected}\` typed value next time.`
|
|
142
|
+
].join(`
|
|
143
|
+
`))), d.push(o)), !1);
|
|
144
|
+
}, m = (d) => Object.assign(d, {
|
|
145
|
+
"~standard": {
|
|
146
|
+
version: 1,
|
|
147
|
+
vendor: "typia",
|
|
148
|
+
validate: (t) => {
|
|
149
|
+
const s = d(t);
|
|
150
|
+
return s.success ? {
|
|
151
|
+
value: s.data
|
|
152
|
+
} : {
|
|
153
|
+
issues: s.errors.map((o) => ({
|
|
154
|
+
message: `expected ${o.expected}, got ${o.value}`,
|
|
155
|
+
path: x(o.path)
|
|
156
|
+
}))
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
var v;
|
|
162
|
+
(function(d) {
|
|
163
|
+
d[d.Start = 0] = "Start", d[d.Property = 1] = "Property", d[d.StringKey = 2] = "StringKey", d[d.NumberKey = 3] = "NumberKey";
|
|
164
|
+
})(v || (v = {}));
|
|
165
|
+
const x = (d) => {
|
|
166
|
+
if (!d.startsWith("$input"))
|
|
167
|
+
throw new Error(`Invalid path: ${JSON.stringify(d)}`);
|
|
168
|
+
const t = [];
|
|
169
|
+
let s = "", o = v.Start, c = 5;
|
|
170
|
+
for (; c < d.length - 1; ) {
|
|
171
|
+
c++;
|
|
172
|
+
const n = d[c];
|
|
173
|
+
if (o === v.Property ? n === "." || n === "[" ? (t.push({
|
|
174
|
+
key: s
|
|
175
|
+
}), o = v.Start) : c === d.length - 1 ? (s += n, t.push({
|
|
176
|
+
key: s
|
|
177
|
+
}), c++, o = v.Start) : s += n : o === v.StringKey ? n === '"' ? (t.push({
|
|
178
|
+
key: JSON.parse(s + n)
|
|
179
|
+
}), c += 2, o = v.Start) : n === "\\" ? (s += d[c], c++, s += d[c]) : s += n : o === v.NumberKey && (n === "]" ? (t.push({
|
|
180
|
+
key: Number.parseInt(s)
|
|
181
|
+
}), c++, o = v.Start) : s += n), o === v.Start && c < d.length - 1) {
|
|
182
|
+
const l = d[c];
|
|
183
|
+
if (s = "", l === "[")
|
|
184
|
+
d[c + 1] === '"' ? (o = v.StringKey, c++, s = '"') : o = v.NumberKey;
|
|
185
|
+
else if (l === ".")
|
|
186
|
+
o = v.Property;
|
|
187
|
+
else
|
|
188
|
+
throw new Error("Unreachable: pointer points invalid character");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (o !== v.Start)
|
|
192
|
+
throw new Error(`Failed to parse path: ${JSON.stringify(d)}`);
|
|
193
|
+
return t;
|
|
194
|
+
};
|
|
195
|
+
var b = /* @__PURE__ */ ((d) => (d.DEVELOPMENT = "dev", d.PRODUCTION = "prod", d))(b || {});
|
|
196
|
+
const C = (() => {
|
|
197
|
+
const d = (r) => typeof r.limit == "number" && y(r.limit) && 1 <= r.limit && r.limit <= 1e4 && (r.offset === void 0 || typeof r.offset == "number" && y(r.offset) && 0 <= r.offset) && (r.timeRange === void 0 || typeof r.timeRange == "object" && r.timeRange !== null && t(r.timeRange)) && (r.filterAnd === void 0 || Array.isArray(r.filterAnd) && r.filterAnd.every((i) => typeof i == "object" && i !== null && s(i))), t = (r) => typeof r.start == "string" && w(r.start) && typeof r.end == "string" && w(r.end), s = (r) => typeof r.column == "string" && 1 <= r.column.length && typeof r.operator == "string" && 1 <= r.operator.length && r.value !== null && r.value !== void 0 && (typeof r.value == "string" || typeof r.value == "number" || typeof r.value == "boolean" || Array.isArray(r.value) && r.value.every((i) => typeof i == "string" || typeof i == "number")), o = (r, i, u = !0) => [typeof r.limit == "number" && (y(r.limit) || a(u, {
|
|
198
|
+
path: i + ".limit",
|
|
199
|
+
expected: 'number & Type<"uint32">',
|
|
200
|
+
value: r.limit
|
|
201
|
+
})) && (1 <= r.limit || a(u, {
|
|
202
|
+
path: i + ".limit",
|
|
203
|
+
expected: "number & Minimum<1>",
|
|
204
|
+
value: r.limit
|
|
205
|
+
})) && (r.limit <= 1e4 || a(u, {
|
|
206
|
+
path: i + ".limit",
|
|
207
|
+
expected: "number & Maximum<10000>",
|
|
208
|
+
value: r.limit
|
|
209
|
+
})) || a(u, {
|
|
210
|
+
path: i + ".limit",
|
|
211
|
+
expected: '(number & Type<"uint32"> & Minimum<1> & Maximum<10000>)',
|
|
212
|
+
value: r.limit
|
|
213
|
+
}), r.offset === void 0 || typeof r.offset == "number" && (y(r.offset) || a(u, {
|
|
214
|
+
path: i + ".offset",
|
|
215
|
+
expected: 'number & Type<"uint32">',
|
|
216
|
+
value: r.offset
|
|
217
|
+
})) && (0 <= r.offset || a(u, {
|
|
218
|
+
path: i + ".offset",
|
|
219
|
+
expected: "number & Minimum<0>",
|
|
220
|
+
value: r.offset
|
|
221
|
+
})) || a(u, {
|
|
222
|
+
path: i + ".offset",
|
|
223
|
+
expected: '((number & Type<"uint32"> & Minimum<0>) | undefined)',
|
|
224
|
+
value: r.offset
|
|
225
|
+
}), r.timeRange === void 0 || (typeof r.timeRange == "object" && r.timeRange !== null || a(u, {
|
|
226
|
+
path: i + ".timeRange",
|
|
227
|
+
expected: "(ISOTimeRange | undefined)",
|
|
228
|
+
value: r.timeRange
|
|
229
|
+
})) && c(r.timeRange, i + ".timeRange", u) || a(u, {
|
|
230
|
+
path: i + ".timeRange",
|
|
231
|
+
expected: "(ISOTimeRange | undefined)",
|
|
232
|
+
value: r.timeRange
|
|
233
|
+
}), r.filterAnd === void 0 || (Array.isArray(r.filterAnd) || a(u, {
|
|
234
|
+
path: i + ".filterAnd",
|
|
235
|
+
expected: "(Array<SQLFilterAnd> | undefined)",
|
|
236
|
+
value: r.filterAnd
|
|
237
|
+
})) && r.filterAnd.map((h, g) => (typeof h == "object" && h !== null || a(u, {
|
|
238
|
+
path: i + ".filterAnd[" + g + "]",
|
|
239
|
+
expected: "SQLFilterAnd",
|
|
240
|
+
value: h
|
|
241
|
+
})) && n(h, i + ".filterAnd[" + g + "]", u) || a(u, {
|
|
242
|
+
path: i + ".filterAnd[" + g + "]",
|
|
243
|
+
expected: "SQLFilterAnd",
|
|
244
|
+
value: h
|
|
245
|
+
})).every((h) => h) || a(u, {
|
|
246
|
+
path: i + ".filterAnd",
|
|
247
|
+
expected: "(Array<SQLFilterAnd> | undefined)",
|
|
248
|
+
value: r.filterAnd
|
|
249
|
+
})].every((h) => h), c = (r, i, u = !0) => [typeof r.start == "string" && (w(r.start) || a(u, {
|
|
250
|
+
path: i + ".start",
|
|
251
|
+
expected: 'string & Format<"date-time">',
|
|
252
|
+
value: r.start
|
|
253
|
+
})) || a(u, {
|
|
254
|
+
path: i + ".start",
|
|
255
|
+
expected: '(string & Format<"date-time">)',
|
|
256
|
+
value: r.start
|
|
257
|
+
}), typeof r.end == "string" && (w(r.end) || a(u, {
|
|
258
|
+
path: i + ".end",
|
|
259
|
+
expected: 'string & Format<"date-time">',
|
|
260
|
+
value: r.end
|
|
261
|
+
})) || a(u, {
|
|
262
|
+
path: i + ".end",
|
|
263
|
+
expected: '(string & Format<"date-time">)',
|
|
264
|
+
value: r.end
|
|
265
|
+
})].every((h) => h), n = (r, i, u = !0) => [typeof r.column == "string" && (1 <= r.column.length || a(u, {
|
|
266
|
+
path: i + ".column",
|
|
267
|
+
expected: "string & MinLength<1>",
|
|
268
|
+
value: r.column
|
|
269
|
+
})) || a(u, {
|
|
270
|
+
path: i + ".column",
|
|
271
|
+
expected: "(string & MinLength<1>)",
|
|
272
|
+
value: r.column
|
|
273
|
+
}), typeof r.operator == "string" && (1 <= r.operator.length || a(u, {
|
|
274
|
+
path: i + ".operator",
|
|
275
|
+
expected: "string & MinLength<1>",
|
|
276
|
+
value: r.operator
|
|
277
|
+
})) || a(u, {
|
|
278
|
+
path: i + ".operator",
|
|
279
|
+
expected: "(string & MinLength<1>)",
|
|
280
|
+
value: r.operator
|
|
281
|
+
}), (r.value !== null || a(u, {
|
|
282
|
+
path: i + ".value",
|
|
283
|
+
expected: "(Array<string | number> | boolean | number | string)",
|
|
284
|
+
value: r.value
|
|
285
|
+
})) && (r.value !== void 0 || a(u, {
|
|
286
|
+
path: i + ".value",
|
|
287
|
+
expected: "(Array<string | number> | boolean | number | string)",
|
|
288
|
+
value: r.value
|
|
289
|
+
})) && (typeof r.value == "string" || typeof r.value == "number" || typeof r.value == "boolean" || (Array.isArray(r.value) || a(u, {
|
|
290
|
+
path: i + ".value",
|
|
291
|
+
expected: "(Array<string | number> | boolean | number | string)",
|
|
292
|
+
value: r.value
|
|
293
|
+
})) && r.value.map((h, g) => typeof h == "string" || typeof h == "number" || a(u, {
|
|
294
|
+
path: i + ".value[" + g + "]",
|
|
295
|
+
expected: "(number | string)",
|
|
296
|
+
value: h
|
|
297
|
+
})).every((h) => h) || a(u, {
|
|
298
|
+
path: i + ".value",
|
|
299
|
+
expected: "(Array<string | number> | boolean | number | string)",
|
|
300
|
+
value: r.value
|
|
301
|
+
}))].every((h) => h), l = (r) => typeof r == "object" && r !== null && d(r);
|
|
302
|
+
let e, a;
|
|
303
|
+
return m((r) => {
|
|
304
|
+
if (l(r) === !1) {
|
|
305
|
+
e = [], a = f(e), ((u, h, g = !0) => (typeof u == "object" && u !== null || a(!0, {
|
|
306
|
+
path: h + "",
|
|
307
|
+
expected: "TableQueryParams",
|
|
308
|
+
value: u
|
|
309
|
+
})) && o(u, h + "", !0) || a(!0, {
|
|
310
|
+
path: h + "",
|
|
311
|
+
expected: "TableQueryParams",
|
|
312
|
+
value: u
|
|
313
|
+
}))(r, "$input", !0);
|
|
314
|
+
const i = e.length === 0;
|
|
315
|
+
return i ? {
|
|
316
|
+
success: i,
|
|
317
|
+
data: r
|
|
318
|
+
} : {
|
|
319
|
+
success: i,
|
|
320
|
+
errors: e,
|
|
321
|
+
data: r
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
success: !0,
|
|
326
|
+
data: r
|
|
327
|
+
};
|
|
328
|
+
});
|
|
329
|
+
})(), j = (() => {
|
|
330
|
+
const d = (n) => typeof n.longitude == "number" && -180 <= n.longitude && n.longitude <= 180 && typeof n.latitude == "number" && -90 <= n.latitude && n.latitude <= 90, t = (n, l, e = !0) => [typeof n.longitude == "number" && (-180 <= n.longitude || c(e, {
|
|
331
|
+
path: l + ".longitude",
|
|
332
|
+
expected: "number & Minimum<-180>",
|
|
333
|
+
value: n.longitude
|
|
334
|
+
})) && (n.longitude <= 180 || c(e, {
|
|
335
|
+
path: l + ".longitude",
|
|
336
|
+
expected: "number & Maximum<180>",
|
|
337
|
+
value: n.longitude
|
|
338
|
+
})) || c(e, {
|
|
339
|
+
path: l + ".longitude",
|
|
340
|
+
expected: "(number & Minimum<-180> & Maximum<180>)",
|
|
341
|
+
value: n.longitude
|
|
342
|
+
}), typeof n.latitude == "number" && (-90 <= n.latitude || c(e, {
|
|
343
|
+
path: l + ".latitude",
|
|
344
|
+
expected: "number & Minimum<-90>",
|
|
345
|
+
value: n.latitude
|
|
346
|
+
})) && (n.latitude <= 90 || c(e, {
|
|
347
|
+
path: l + ".latitude",
|
|
348
|
+
expected: "number & Maximum<90>",
|
|
349
|
+
value: n.latitude
|
|
350
|
+
})) || c(e, {
|
|
351
|
+
path: l + ".latitude",
|
|
352
|
+
expected: "(number & Minimum<-90> & Maximum<90>)",
|
|
353
|
+
value: n.latitude
|
|
354
|
+
})].every((a) => a), s = (n) => typeof n == "object" && n !== null && d(n);
|
|
355
|
+
let o, c;
|
|
356
|
+
return m((n) => {
|
|
357
|
+
if (s(n) === !1) {
|
|
358
|
+
o = [], c = f(o), ((e, a, r = !0) => (typeof e == "object" && e !== null || c(!0, {
|
|
359
|
+
path: a + "",
|
|
360
|
+
expected: "LocationParams",
|
|
361
|
+
value: e
|
|
362
|
+
})) && t(e, a + "", !0) || c(!0, {
|
|
363
|
+
path: a + "",
|
|
364
|
+
expected: "LocationParams",
|
|
365
|
+
value: e
|
|
366
|
+
}))(n, "$input", !0);
|
|
367
|
+
const l = o.length === 0;
|
|
368
|
+
return l ? {
|
|
369
|
+
success: l,
|
|
370
|
+
data: n
|
|
371
|
+
} : {
|
|
372
|
+
success: l,
|
|
373
|
+
errors: o,
|
|
374
|
+
data: n
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
success: !0,
|
|
379
|
+
data: n
|
|
380
|
+
};
|
|
381
|
+
});
|
|
382
|
+
})(), P = (() => {
|
|
383
|
+
const d = (e) => typeof e.topic == "string" && 1 <= e.topic.length && (e.args === void 0 || Array.isArray(e.args)) && (e.kwargs === void 0 || typeof e.kwargs == "object" && e.kwargs !== null && Array.isArray(e.kwargs) === !1 && t(e.kwargs)), t = (e) => Object.keys(e).every((a) => (e[a] === void 0, !0)), s = (e, a, r = !0) => [typeof e.topic == "string" && (1 <= e.topic.length || l(r, {
|
|
384
|
+
path: a + ".topic",
|
|
385
|
+
expected: "string & MinLength<1>",
|
|
386
|
+
value: e.topic
|
|
387
|
+
})) || l(r, {
|
|
388
|
+
path: a + ".topic",
|
|
389
|
+
expected: "(string & MinLength<1>)",
|
|
390
|
+
value: e.topic
|
|
391
|
+
}), e.args === void 0 || Array.isArray(e.args) || l(r, {
|
|
392
|
+
path: a + ".args",
|
|
393
|
+
expected: "(Array<unknown> | undefined)",
|
|
394
|
+
value: e.args
|
|
395
|
+
}), e.kwargs === void 0 || (typeof e.kwargs == "object" && e.kwargs !== null && Array.isArray(e.kwargs) === !1 || l(r, {
|
|
396
|
+
path: a + ".kwargs",
|
|
397
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
398
|
+
value: e.kwargs
|
|
399
|
+
})) && o(e.kwargs, a + ".kwargs", r) || l(r, {
|
|
400
|
+
path: a + ".kwargs",
|
|
401
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
402
|
+
value: e.kwargs
|
|
403
|
+
})].every((i) => i), o = (e, a, r = !0) => [r === !1 || Object.keys(e).map((i) => (e[i] === void 0, !0)).every((i) => i)].every((i) => i), c = (e) => typeof e == "object" && e !== null && d(e);
|
|
404
|
+
let n, l;
|
|
405
|
+
return m((e) => {
|
|
406
|
+
if (c(e) === !1) {
|
|
407
|
+
n = [], l = f(n), ((r, i, u = !0) => (typeof r == "object" && r !== null || l(!0, {
|
|
408
|
+
path: i + "",
|
|
409
|
+
expected: "PublishParams",
|
|
410
|
+
value: r
|
|
411
|
+
})) && s(r, i + "", !0) || l(!0, {
|
|
412
|
+
path: i + "",
|
|
413
|
+
expected: "PublishParams",
|
|
414
|
+
value: r
|
|
415
|
+
}))(e, "$input", !0);
|
|
416
|
+
const a = n.length === 0;
|
|
417
|
+
return a ? {
|
|
418
|
+
success: a,
|
|
419
|
+
data: e
|
|
420
|
+
} : {
|
|
421
|
+
success: a,
|
|
422
|
+
errors: n,
|
|
423
|
+
data: e
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
return {
|
|
427
|
+
success: !0,
|
|
428
|
+
data: e
|
|
429
|
+
};
|
|
430
|
+
});
|
|
431
|
+
})(), O = (() => {
|
|
432
|
+
const d = (e) => typeof e.deviceKey == "string" && 1 <= e.deviceKey.length && typeof e.topic == "string" && 1 <= e.topic.length && (e.args === void 0 || Array.isArray(e.args)) && (e.kwargs === void 0 || typeof e.kwargs == "object" && e.kwargs !== null && Array.isArray(e.kwargs) === !1 && t(e.kwargs)), t = (e) => Object.keys(e).every((a) => (e[a] === void 0, !0)), s = (e, a, r = !0) => [typeof e.deviceKey == "string" && (1 <= e.deviceKey.length || l(r, {
|
|
433
|
+
path: a + ".deviceKey",
|
|
434
|
+
expected: "string & MinLength<1>",
|
|
435
|
+
value: e.deviceKey
|
|
436
|
+
})) || l(r, {
|
|
437
|
+
path: a + ".deviceKey",
|
|
438
|
+
expected: "(string & MinLength<1>)",
|
|
439
|
+
value: e.deviceKey
|
|
440
|
+
}), typeof e.topic == "string" && (1 <= e.topic.length || l(r, {
|
|
441
|
+
path: a + ".topic",
|
|
442
|
+
expected: "string & MinLength<1>",
|
|
443
|
+
value: e.topic
|
|
444
|
+
})) || l(r, {
|
|
445
|
+
path: a + ".topic",
|
|
446
|
+
expected: "(string & MinLength<1>)",
|
|
447
|
+
value: e.topic
|
|
448
|
+
}), e.args === void 0 || Array.isArray(e.args) || l(r, {
|
|
449
|
+
path: a + ".args",
|
|
450
|
+
expected: "(Array<unknown> | undefined)",
|
|
451
|
+
value: e.args
|
|
452
|
+
}), e.kwargs === void 0 || (typeof e.kwargs == "object" && e.kwargs !== null && Array.isArray(e.kwargs) === !1 || l(r, {
|
|
453
|
+
path: a + ".kwargs",
|
|
454
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
455
|
+
value: e.kwargs
|
|
456
|
+
})) && o(e.kwargs, a + ".kwargs", r) || l(r, {
|
|
457
|
+
path: a + ".kwargs",
|
|
458
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
459
|
+
value: e.kwargs
|
|
460
|
+
})].every((i) => i), o = (e, a, r = !0) => [r === !1 || Object.keys(e).map((i) => (e[i] === void 0, !0)).every((i) => i)].every((i) => i), c = (e) => typeof e == "object" && e !== null && d(e);
|
|
461
|
+
let n, l;
|
|
462
|
+
return m((e) => {
|
|
463
|
+
if (c(e) === !1) {
|
|
464
|
+
n = [], l = f(n), ((r, i, u = !0) => (typeof r == "object" && r !== null || l(!0, {
|
|
465
|
+
path: i + "",
|
|
466
|
+
expected: "CallParams",
|
|
467
|
+
value: r
|
|
468
|
+
})) && s(r, i + "", !0) || l(!0, {
|
|
469
|
+
path: i + "",
|
|
470
|
+
expected: "CallParams",
|
|
471
|
+
value: r
|
|
472
|
+
}))(e, "$input", !0);
|
|
473
|
+
const a = n.length === 0;
|
|
474
|
+
return a ? {
|
|
475
|
+
success: a,
|
|
476
|
+
data: e
|
|
477
|
+
} : {
|
|
478
|
+
success: a,
|
|
479
|
+
errors: n,
|
|
480
|
+
data: e
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
return {
|
|
484
|
+
success: !0,
|
|
485
|
+
data: e
|
|
486
|
+
};
|
|
487
|
+
});
|
|
488
|
+
})(), L = (() => {
|
|
489
|
+
const d = (e) => typeof e.tablename == "string" && 1 <= e.tablename.length && (e.args === void 0 || Array.isArray(e.args)) && (e.kwargs === void 0 || typeof e.kwargs == "object" && e.kwargs !== null && Array.isArray(e.kwargs) === !1 && t(e.kwargs)), t = (e) => Object.keys(e).every((a) => (e[a] === void 0, !0)), s = (e, a, r = !0) => [typeof e.tablename == "string" && (1 <= e.tablename.length || l(r, {
|
|
490
|
+
path: a + ".tablename",
|
|
491
|
+
expected: "string & MinLength<1>",
|
|
492
|
+
value: e.tablename
|
|
493
|
+
})) || l(r, {
|
|
494
|
+
path: a + ".tablename",
|
|
495
|
+
expected: "(string & MinLength<1>)",
|
|
496
|
+
value: e.tablename
|
|
497
|
+
}), e.args === void 0 || Array.isArray(e.args) || l(r, {
|
|
498
|
+
path: a + ".args",
|
|
499
|
+
expected: "(Array<unknown> | undefined)",
|
|
500
|
+
value: e.args
|
|
501
|
+
}), e.kwargs === void 0 || (typeof e.kwargs == "object" && e.kwargs !== null && Array.isArray(e.kwargs) === !1 || l(r, {
|
|
502
|
+
path: a + ".kwargs",
|
|
503
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
504
|
+
value: e.kwargs
|
|
505
|
+
})) && o(e.kwargs, a + ".kwargs", r) || l(r, {
|
|
506
|
+
path: a + ".kwargs",
|
|
507
|
+
expected: "(Record<string, unknown> | undefined)",
|
|
508
|
+
value: e.kwargs
|
|
509
|
+
})].every((i) => i), o = (e, a, r = !0) => [r === !1 || Object.keys(e).map((i) => (e[i] === void 0, !0)).every((i) => i)].every((i) => i), c = (e) => typeof e == "object" && e !== null && d(e);
|
|
510
|
+
let n, l;
|
|
511
|
+
return m((e) => {
|
|
512
|
+
if (c(e) === !1) {
|
|
513
|
+
n = [], l = f(n), ((r, i, u = !0) => (typeof r == "object" && r !== null || l(!0, {
|
|
514
|
+
path: i + "",
|
|
515
|
+
expected: "TableParams",
|
|
516
|
+
value: r
|
|
517
|
+
})) && s(r, i + "", !0) || l(!0, {
|
|
518
|
+
path: i + "",
|
|
519
|
+
expected: "TableParams",
|
|
520
|
+
value: r
|
|
521
|
+
}))(e, "$input", !0);
|
|
522
|
+
const a = n.length === 0;
|
|
523
|
+
return a ? {
|
|
524
|
+
success: a,
|
|
525
|
+
data: e
|
|
526
|
+
} : {
|
|
527
|
+
success: a,
|
|
528
|
+
errors: n,
|
|
529
|
+
data: e
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
return {
|
|
533
|
+
success: !0,
|
|
534
|
+
data: e
|
|
535
|
+
};
|
|
536
|
+
});
|
|
537
|
+
})();
|
|
538
|
+
function D(d) {
|
|
539
|
+
const t = d ?? process.env.DEVICE_SERIAL_NUMBER;
|
|
540
|
+
if (!t)
|
|
541
|
+
throw new Error("DEVICE_SERIAL_NUMBER environment variable is not set and no serialNumber was provided");
|
|
542
|
+
return t;
|
|
543
|
+
}
|
|
544
|
+
class V {
|
|
545
|
+
constructor(t) {
|
|
546
|
+
this._isConfigured = !1, this._serialNumber = D(t == null ? void 0 : t.serialNumber), this._deviceName = process.env.DEVICE_NAME, this._deviceKey = process.env.DEVICE_KEY, this._appName = process.env.APP_NAME, this._swarmKey = parseInt(process.env.SWARM_KEY ?? "0", 10), this._appKey = parseInt(process.env.APP_KEY ?? "0", 10), this._env = process.env.ENV, this._connection = new k();
|
|
547
|
+
const s = [];
|
|
548
|
+
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(
|
|
549
|
+
`Warning: The following environment variables must be present: ${s.join(", ")}`
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
get connection() {
|
|
553
|
+
return this._connection;
|
|
554
|
+
}
|
|
555
|
+
get isConnected() {
|
|
556
|
+
return this._connection.is_open;
|
|
557
|
+
}
|
|
558
|
+
configureConnection(t) {
|
|
559
|
+
if (this._isConfigured) return;
|
|
560
|
+
const s = (this._env ?? "DEV").toUpperCase(), c = {
|
|
561
|
+
DEV: b.DEVELOPMENT,
|
|
562
|
+
PROD: b.PRODUCTION
|
|
563
|
+
}[s] ?? b.DEVELOPMENT;
|
|
564
|
+
this._connection.configure(
|
|
565
|
+
this._swarmKey,
|
|
566
|
+
this._appKey,
|
|
567
|
+
c,
|
|
568
|
+
this._serialNumber,
|
|
569
|
+
t
|
|
570
|
+
), this._isConfigured = !0;
|
|
571
|
+
}
|
|
572
|
+
async start(t) {
|
|
573
|
+
this.configureConnection(t), await this._connection.start();
|
|
574
|
+
}
|
|
575
|
+
async stop() {
|
|
576
|
+
this._connection.stop();
|
|
577
|
+
}
|
|
578
|
+
async publish(t, s, o) {
|
|
579
|
+
const c = P({ topic: t, args: s, kwargs: o });
|
|
580
|
+
if (!c.success)
|
|
581
|
+
throw new Error(`Invalid publish parameters: ${c.errors.map((e) => e.path + ": " + e.expected).join(", ")}`);
|
|
582
|
+
const l = { ...{
|
|
583
|
+
DEVICE_SERIAL_NUMBER: this._serialNumber,
|
|
584
|
+
DEVICE_KEY: this._deviceKey,
|
|
585
|
+
DEVICE_NAME: this._deviceName
|
|
586
|
+
}, ...o ?? {} };
|
|
587
|
+
return this._connection.publish(t, s, l, {
|
|
588
|
+
acknowledge: !0
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
async publishToTable(t, s, o) {
|
|
592
|
+
const c = L({ tablename: t, args: s, kwargs: o });
|
|
593
|
+
if (!c.success)
|
|
594
|
+
throw new Error(`Invalid table parameters: ${c.errors.map((l) => l.path + ": " + l.expected).join(", ")}`);
|
|
595
|
+
if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
|
|
596
|
+
if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
|
|
597
|
+
const n = `${this._swarmKey}.${this._appKey}.${t}`;
|
|
598
|
+
return this.publish(n, s, o);
|
|
599
|
+
}
|
|
600
|
+
async subscribe(t, s, o) {
|
|
601
|
+
return this._connection.subscribe(t, s);
|
|
602
|
+
}
|
|
603
|
+
async subscribeToTable(t, s, o) {
|
|
604
|
+
if (!this._swarmKey) throw new Error("SWARM_KEY not set in environment variables!");
|
|
605
|
+
if (!this._appKey) throw new Error("APP_KEY not set in environment variables!");
|
|
606
|
+
const c = `${this._swarmKey}.${this._appKey}.${t}`;
|
|
607
|
+
return this.subscribe(c, s, o);
|
|
608
|
+
}
|
|
609
|
+
async call(t, s, o, c, n) {
|
|
610
|
+
const l = O({ deviceKey: t, topic: s, args: o, kwargs: c });
|
|
611
|
+
if (!l.success)
|
|
612
|
+
throw new Error(`Invalid call parameters: ${l.errors.map((a) => a.path + ": " + a.expected).join(", ")}`);
|
|
613
|
+
const e = `${t}.${s}`;
|
|
614
|
+
return this._connection.call(e, o, c, n);
|
|
615
|
+
}
|
|
616
|
+
async registerFunction(t, s, o) {
|
|
617
|
+
const c = `${this._swarmKey}.${this._deviceKey}.${this._appKey}.${this._env}.${t}`, n = await this._connection.register(c, s);
|
|
618
|
+
return console.log(`Function registered for IronFlock topic '${t}'. (Full WAMP topic: '${c}')`), n;
|
|
619
|
+
}
|
|
620
|
+
async register(t, s, o) {
|
|
621
|
+
return this.registerFunction(t, s, o);
|
|
622
|
+
}
|
|
623
|
+
async getHistory(t, s = { limit: 10 }) {
|
|
624
|
+
if (!t) throw new Error("Tablename must not be empty!");
|
|
625
|
+
const o = C(s);
|
|
626
|
+
if (!o.success)
|
|
627
|
+
throw new Error(`Invalid query parameters: ${o.errors.map((n) => n.path + ": " + n.expected).join(", ")}`);
|
|
628
|
+
const c = `history.transformed.app.${this._appKey}.${t}`;
|
|
629
|
+
try {
|
|
630
|
+
return await this._connection.call(c, [s]);
|
|
631
|
+
} catch (n) {
|
|
632
|
+
const l = String(n);
|
|
633
|
+
return l.includes("no_such_procedure") || l.includes("no callee registered") ? (console.error(`Get history failed: History service procedure '${c}' not registered`), null) : (console.error(`Get history failed: ${n}`), null);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
async setDeviceLocation(t, s) {
|
|
637
|
+
const o = j({ longitude: t, latitude: s });
|
|
638
|
+
if (!o.success)
|
|
639
|
+
throw new Error(`Invalid location parameters: ${o.errors.map((l) => l.path + ": " + l.expected).join(", ")}`);
|
|
640
|
+
const c = { long: t, lat: s }, n = {
|
|
641
|
+
DEVICE_SERIAL_NUMBER: this._serialNumber,
|
|
642
|
+
DEVICE_KEY: this._deviceKey,
|
|
643
|
+
DEVICE_NAME: this._deviceName
|
|
644
|
+
};
|
|
645
|
+
try {
|
|
646
|
+
return await this._connection.call(
|
|
647
|
+
"ironflock.location_service.update",
|
|
648
|
+
[c],
|
|
649
|
+
n
|
|
650
|
+
);
|
|
651
|
+
} catch (l) {
|
|
652
|
+
return console.error(`Set location failed: ${l}`), null;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
getRemoteAccessUrlForPort(t) {
|
|
656
|
+
return this._deviceKey && this._appName ? `https://${this._deviceKey}-${this._appName.toLowerCase()}-${t}.app.ironflock.com` : null;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
export {
|
|
660
|
+
k as CrossbarConnection,
|
|
661
|
+
V as IronFlock,
|
|
662
|
+
b as Stage,
|
|
663
|
+
O as validateCallParams,
|
|
664
|
+
j as validateLocationParams,
|
|
665
|
+
P as validatePublishParams,
|
|
666
|
+
L as validateTableParams,
|
|
667
|
+
C as validateTableQueryParams
|
|
668
|
+
};
|
|
669
|
+
//# sourceMappingURL=index.mjs.map
|