@synnaxlabs/freighter 0.30.0 → 0.32.0
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/freighter.cjs +13 -3
- package/dist/freighter.js +1068 -557
- package/dist/http.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/http.ts +0 -17
package/dist/freighter.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { z as
|
|
5
|
-
const
|
|
1
|
+
var it = Object.defineProperty;
|
|
2
|
+
var at = (r, e, t) => e in r ? it(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var p = (r, e, t) => at(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { z as i } from "zod";
|
|
5
|
+
const ot = (r) => {
|
|
6
6
|
const e = r.replace(/_[a-z]/g, (t) => t[1].toUpperCase());
|
|
7
7
|
return e.length > 1 && e[0] === e[0].toUpperCase() && e[1] === e[1].toUpperCase() ? e : e[0].toLowerCase() + e.slice(1);
|
|
8
|
-
},
|
|
9
|
-
const e = (t, n =
|
|
8
|
+
}, Le = (r) => {
|
|
9
|
+
const e = (t, n = de) => {
|
|
10
10
|
if (typeof t == "string") return r(t);
|
|
11
11
|
if (Array.isArray(t)) return t.map((c) => e(c, n));
|
|
12
|
-
if (!
|
|
13
|
-
n =
|
|
14
|
-
const
|
|
12
|
+
if (!ue(t)) return t;
|
|
13
|
+
n = lt(n);
|
|
14
|
+
const s = {}, a = t;
|
|
15
15
|
return Object.keys(a).forEach((c) => {
|
|
16
|
-
let
|
|
17
|
-
const
|
|
18
|
-
n.recursive && (
|
|
19
|
-
let
|
|
20
|
-
return
|
|
21
|
-
}))),
|
|
22
|
-
}),
|
|
16
|
+
let d = a[c];
|
|
17
|
+
const f = r(c);
|
|
18
|
+
n.recursive && (ue(d) ? Oe(d, n.keepTypesOnRecursion) || (d = e(d, n)) : n.recursiveInArray && Te(d) && (d = [...d].map((y) => {
|
|
19
|
+
let T = y;
|
|
20
|
+
return ue(y) ? Oe(T, n.keepTypesOnRecursion) || (T = e(y, n)) : Te(y) && (T = e({ key: y }, n).key), T;
|
|
21
|
+
}))), s[f] = d;
|
|
22
|
+
}), s;
|
|
23
23
|
};
|
|
24
24
|
return e;
|
|
25
|
-
},
|
|
25
|
+
}, Ye = Le(ot), ut = (r) => r.replace(/([a-z0-9])([A-Z])/g, (e, t, n) => `${t}_${n.toLowerCase()}`), ct = Le(ut), de = {
|
|
26
26
|
recursive: !0,
|
|
27
27
|
recursiveInArray: !0,
|
|
28
28
|
keepTypesOnRecursion: [Number, String, Uint8Array]
|
|
29
|
-
},
|
|
30
|
-
var
|
|
31
|
-
let
|
|
29
|
+
}, lt = (r = de) => (r.recursive == null ? r = de : r.recursiveInArray == null && (r.recursiveInArray = !1), r), Te = (r) => r != null && Array.isArray(r), ue = (r) => r != null && typeof r == "object" && !Array.isArray(r), Oe = (r, e) => (e || []).some((t) => r instanceof t), ke = (r) => r != null && typeof r == "object" && !Array.isArray(r);
|
|
30
|
+
var ht = Object.defineProperty, dt = (r, e, t) => e in r ? ht(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, H = (r, e, t) => dt(r, typeof e != "symbol" ? e + "" : e, t);
|
|
31
|
+
let ft = class {
|
|
32
32
|
constructor() {
|
|
33
|
-
|
|
33
|
+
H(this, "contentType", "application/json"), H(this, "decoder"), H(this, "encoder"), this.decoder = new TextDecoder(), this.encoder = new TextEncoder();
|
|
34
34
|
}
|
|
35
35
|
encode(e) {
|
|
36
36
|
return this.encoder.encode(this.encodeString(e)).buffer;
|
|
@@ -39,18 +39,18 @@ let et = class {
|
|
|
39
39
|
return this.decodeString(this.decoder.decode(e), t);
|
|
40
40
|
}
|
|
41
41
|
decodeString(e, t) {
|
|
42
|
-
const n = JSON.parse(e),
|
|
43
|
-
return t != null ? t.parse(
|
|
42
|
+
const n = JSON.parse(e), s = Ye(n);
|
|
43
|
+
return t != null ? t.parse(s) : s;
|
|
44
44
|
}
|
|
45
45
|
encodeString(e) {
|
|
46
|
-
const t =
|
|
47
|
-
return JSON.stringify(t, (n,
|
|
46
|
+
const t = ct(e);
|
|
47
|
+
return JSON.stringify(t, (n, s) => ArrayBuffer.isView(s) ? Array.from(s) : ke(s) && "encode_value" in s ? typeof s.value == "bigint" ? s.value.toString() : s.value : typeof s == "bigint" ? s.toString() : s);
|
|
48
48
|
}
|
|
49
49
|
static registerCustomType() {
|
|
50
50
|
}
|
|
51
|
-
},
|
|
51
|
+
}, gt = class {
|
|
52
52
|
constructor() {
|
|
53
|
-
|
|
53
|
+
H(this, "contentType", "text/csv");
|
|
54
54
|
}
|
|
55
55
|
encode(e) {
|
|
56
56
|
const t = this.encodeString(e);
|
|
@@ -61,28 +61,28 @@ let et = class {
|
|
|
61
61
|
return this.decodeString(n, t);
|
|
62
62
|
}
|
|
63
63
|
encodeString(e) {
|
|
64
|
-
if (!Array.isArray(e) || e.length === 0 || !
|
|
64
|
+
if (!Array.isArray(e) || e.length === 0 || !ke(e[0]))
|
|
65
65
|
throw new Error("Payload must be an array of objects");
|
|
66
66
|
const t = Object.keys(e[0]), n = [t.join(",")];
|
|
67
|
-
return e.forEach((
|
|
68
|
-
const a = t.map((c) => JSON.stringify(
|
|
67
|
+
return e.forEach((s) => {
|
|
68
|
+
const a = t.map((c) => JSON.stringify(s[c] ?? ""));
|
|
69
69
|
n.push(a.join(","));
|
|
70
70
|
}), n.join(`
|
|
71
71
|
`);
|
|
72
72
|
}
|
|
73
73
|
decodeString(e, t) {
|
|
74
|
-
const [n, ...
|
|
75
|
-
`).map((
|
|
74
|
+
const [n, ...s] = e.trim().split(`
|
|
75
|
+
`).map((d) => d.trim());
|
|
76
76
|
if (n.length === 0)
|
|
77
77
|
return t != null ? t.parse({}) : {};
|
|
78
|
-
const a = n.split(",").map((
|
|
79
|
-
return a.forEach((
|
|
80
|
-
c[
|
|
81
|
-
}),
|
|
82
|
-
const
|
|
83
|
-
a.forEach((
|
|
84
|
-
const
|
|
85
|
-
|
|
78
|
+
const a = n.split(",").map((d) => d.trim()), c = {};
|
|
79
|
+
return a.forEach((d) => {
|
|
80
|
+
c[d] = [];
|
|
81
|
+
}), s.forEach((d) => {
|
|
82
|
+
const f = d.split(",").map((y) => y.trim());
|
|
83
|
+
a.forEach((y, T) => {
|
|
84
|
+
const l = this.parseValue(f[T]);
|
|
85
|
+
l != null && c[y].push(l);
|
|
86
86
|
});
|
|
87
87
|
}), t != null ? t.parse(c) : c;
|
|
88
88
|
}
|
|
@@ -93,9 +93,9 @@ let et = class {
|
|
|
93
93
|
}
|
|
94
94
|
static registerCustomType() {
|
|
95
95
|
}
|
|
96
|
-
},
|
|
96
|
+
}, pt = class {
|
|
97
97
|
constructor() {
|
|
98
|
-
|
|
98
|
+
H(this, "contentType", "text/plain");
|
|
99
99
|
}
|
|
100
100
|
encode(e) {
|
|
101
101
|
return new TextEncoder().encode(e).buffer;
|
|
@@ -105,125 +105,125 @@ let et = class {
|
|
|
105
105
|
return t != null ? t.parse(n) : n;
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
|
-
new
|
|
109
|
-
new
|
|
110
|
-
new
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
signedWidth:
|
|
115
|
-
signedHeight:
|
|
116
|
-
}),
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
108
|
+
const _ = new ft();
|
|
109
|
+
new gt();
|
|
110
|
+
new pt();
|
|
111
|
+
const ie = i.tuple([i.number(), i.number()]);
|
|
112
|
+
i.tuple([i.bigint(), i.bigint()]);
|
|
113
|
+
const je = i.object({ width: i.number(), height: i.number() }), yt = i.object({
|
|
114
|
+
signedWidth: i.number(),
|
|
115
|
+
signedHeight: i.number()
|
|
116
|
+
}), mt = ["width", "height"];
|
|
117
|
+
i.enum(mt);
|
|
118
|
+
const wt = ["start", "center", "end"], bt = ["signedWidth", "signedHeight"];
|
|
119
|
+
i.enum(bt);
|
|
120
|
+
const ne = i.object({ x: i.number(), y: i.number() }), Tt = i.object({ clientX: i.number(), clientY: i.number() }), Ot = ["x", "y"], Fe = i.enum(Ot), Ge = ["top", "right", "bottom", "left"];
|
|
121
|
+
i.enum(Ge);
|
|
122
|
+
const vt = ["left", "right"], qe = i.enum(vt), St = ["top", "bottom"], We = i.enum(St), ze = ["center"], ve = i.enum(ze), It = [...Ge, ...ze], Ze = i.enum(It);
|
|
123
|
+
i.enum(wt);
|
|
124
|
+
const Nt = ["first", "last"];
|
|
125
|
+
i.enum(Nt);
|
|
126
|
+
const Et = i.object({ lower: i.number(), upper: i.number() }), At = i.object({ lower: i.bigint(), upper: i.bigint() });
|
|
127
|
+
i.union([Et, ie]);
|
|
128
|
+
i.union([At, ie]);
|
|
129
|
+
i.union([Fe, Ze]);
|
|
130
|
+
i.union([Fe, Ze, i.instanceof(String)]);
|
|
131
|
+
const K = (r, e) => {
|
|
132
132
|
const t = {};
|
|
133
133
|
if (typeof r == "number" || typeof r == "bigint")
|
|
134
134
|
e != null ? (t.lower = r, t.upper = e) : (t.lower = typeof r == "bigint" ? 0n : 0, t.upper = r);
|
|
135
135
|
else if (Array.isArray(r)) {
|
|
136
136
|
if (r.length !== 2) throw new Error("bounds: expected array of length 2");
|
|
137
137
|
[t.lower, t.upper] = r;
|
|
138
|
-
} else return
|
|
139
|
-
return
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
x:
|
|
143
|
-
y:
|
|
138
|
+
} else return Se(r);
|
|
139
|
+
return Se(t);
|
|
140
|
+
}, Se = (r) => r.lower > r.upper ? { lower: r.upper, upper: r.lower } : r;
|
|
141
|
+
i.object({
|
|
142
|
+
x: qe.or(ve),
|
|
143
|
+
y: We.or(ve)
|
|
144
144
|
});
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
]),
|
|
145
|
+
const xt = i.object({ x: qe, y: We }), Mt = Object.freeze({ x: "left", y: "top" }), $t = (r, e) => r.x === e.x && r.y === e.y, Ie = i.union([
|
|
146
|
+
i.number(),
|
|
147
|
+
ne,
|
|
148
|
+
ie,
|
|
149
|
+
je,
|
|
150
|
+
yt,
|
|
151
|
+
Tt
|
|
152
|
+
]), Rt = (r, e) => {
|
|
153
153
|
if (typeof r == "string") {
|
|
154
154
|
if (e === void 0) throw new Error("The y coordinate must be given.");
|
|
155
155
|
return r === "x" ? { x: e, y: 0 } : { x: 0, y: e };
|
|
156
156
|
}
|
|
157
157
|
return typeof r == "number" ? { x: r, y: e ?? r } : Array.isArray(r) ? { x: r[0], y: r[1] } : "signedWidth" in r ? { x: r.signedWidth, y: r.signedHeight } : "clientX" in r ? { x: r.clientX, y: r.clientY } : "width" in r ? { x: r.width, y: r.height } : { x: r.x, y: r.y };
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
top:
|
|
161
|
-
left:
|
|
162
|
-
width:
|
|
163
|
-
height:
|
|
158
|
+
}, Ne = Object.freeze({ x: 0, y: 0 }), X = i.union([i.number(), i.string()]);
|
|
159
|
+
i.object({
|
|
160
|
+
top: X,
|
|
161
|
+
left: X,
|
|
162
|
+
width: X,
|
|
163
|
+
height: X
|
|
164
164
|
});
|
|
165
|
-
|
|
166
|
-
left:
|
|
167
|
-
top:
|
|
168
|
-
right:
|
|
169
|
-
bottom:
|
|
165
|
+
i.object({
|
|
166
|
+
left: i.number(),
|
|
167
|
+
top: i.number(),
|
|
168
|
+
right: i.number(),
|
|
169
|
+
bottom: i.number()
|
|
170
170
|
});
|
|
171
|
-
|
|
172
|
-
one:
|
|
173
|
-
two:
|
|
174
|
-
root:
|
|
171
|
+
i.object({
|
|
172
|
+
one: ne,
|
|
173
|
+
two: ne,
|
|
174
|
+
root: xt
|
|
175
175
|
});
|
|
176
|
-
const
|
|
176
|
+
const ye = (r, e, t = 0, n = 0, s) => {
|
|
177
177
|
const a = {
|
|
178
|
-
one: { ...
|
|
179
|
-
two: { ...
|
|
180
|
-
root:
|
|
178
|
+
one: { ...Ne },
|
|
179
|
+
two: { ...Ne },
|
|
180
|
+
root: s ?? Mt
|
|
181
181
|
};
|
|
182
182
|
if (typeof r == "number") {
|
|
183
183
|
if (typeof e != "number")
|
|
184
184
|
throw new Error("Box constructor called with invalid arguments");
|
|
185
185
|
return a.one = { x: r, y: e }, a.two = { x: a.one.x + t, y: a.one.y + n }, a;
|
|
186
186
|
}
|
|
187
|
-
return "one" in r && "two" in r && "root" in r ? { ...r, root:
|
|
187
|
+
return "one" in r && "two" in r && "root" in r ? { ...r, root: s ?? r.root } : ("getBoundingClientRect" in r && (r = r.getBoundingClientRect()), "left" in r ? (a.one = { x: r.left, y: r.top }, a.two = { x: r.right, y: r.bottom }, a) : (a.one = r, e == null ? a.two = { x: a.one.x + t, y: a.one.y + n } : typeof e == "number" ? a.two = { x: a.one.x + e, y: a.one.y + t } : "width" in e ? a.two = {
|
|
188
188
|
x: a.one.x + e.width,
|
|
189
189
|
y: a.one.y + e.height
|
|
190
190
|
} : "signedWidth" in e ? a.two = {
|
|
191
191
|
x: a.one.x + e.signedWidth,
|
|
192
192
|
y: a.one.y + e.signedHeight
|
|
193
193
|
} : a.two = e, a));
|
|
194
|
-
},
|
|
195
|
-
const e =
|
|
194
|
+
}, ce = (r) => {
|
|
195
|
+
const e = ye(r);
|
|
196
196
|
return { lower: e.one.x, upper: e.two.x };
|
|
197
|
-
},
|
|
198
|
-
const e =
|
|
197
|
+
}, le = (r) => {
|
|
198
|
+
const e = ye(r);
|
|
199
199
|
return { lower: e.one.y, upper: e.two.y };
|
|
200
|
-
},
|
|
201
|
-
var
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
const
|
|
200
|
+
}, Bt = (r) => typeof r != "object" || r == null ? !1 : "one" in r && "two" in r && "root" in r;
|
|
201
|
+
var Ut = Object.defineProperty, Ct = (r, e, t) => e in r ? Ut(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, D = (r, e, t) => Ct(r, typeof e != "symbol" ? e + "" : e, t);
|
|
202
|
+
const Dt = (r, e, t) => e !== void 0 && r < e ? e : t !== void 0 && r > t ? t : r;
|
|
203
|
+
i.object({ offset: Ie, scale: Ie });
|
|
204
|
+
const Pt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
|
|
205
205
|
e,
|
|
206
|
-
|
|
207
|
-
],
|
|
206
|
+
s ? n - r : n + r
|
|
207
|
+
], Lt = (r) => (e, t, n, s) => [
|
|
208
208
|
e,
|
|
209
|
-
|
|
210
|
-
],
|
|
209
|
+
s ? n / r : n * r
|
|
210
|
+
], Yt = (r) => (e, t, n) => {
|
|
211
211
|
if (e === null) return [r, n];
|
|
212
|
-
const { lower:
|
|
213
|
-
if (t === "dimension") return [r, n * (
|
|
214
|
-
const
|
|
215
|
-
return [r,
|
|
216
|
-
},
|
|
212
|
+
const { lower: s, upper: a } = e, { lower: c, upper: d } = r, f = a - s, y = d - c;
|
|
213
|
+
if (t === "dimension") return [r, n * (y / f)];
|
|
214
|
+
const T = (n - s) * (y / f) + c;
|
|
215
|
+
return [r, T];
|
|
216
|
+
}, kt = (r) => (e, t, n) => [r, n], jt = () => (r, e, t) => {
|
|
217
217
|
if (r === null) throw new Error("cannot invert without bounds");
|
|
218
218
|
if (e === "dimension") return [r, t];
|
|
219
|
-
const { lower: n, upper:
|
|
220
|
-
return [r,
|
|
221
|
-
},
|
|
222
|
-
const { lower:
|
|
223
|
-
return n =
|
|
224
|
-
},
|
|
219
|
+
const { lower: n, upper: s } = r;
|
|
220
|
+
return [r, s - (t - n)];
|
|
221
|
+
}, Ft = (r) => (e, t, n) => {
|
|
222
|
+
const { lower: s, upper: a } = r;
|
|
223
|
+
return n = Dt(n, s, a), [e, n];
|
|
224
|
+
}, fe = class W {
|
|
225
225
|
constructor() {
|
|
226
|
-
|
|
226
|
+
D(this, "ops", []), D(this, "currBounds", null), D(this, "currType", null), D(this, "reversed", !1), this.ops = [];
|
|
227
227
|
}
|
|
228
228
|
static translate(e) {
|
|
229
229
|
return new W().translate(e);
|
|
@@ -235,27 +235,27 @@ const St = (r) => (e, t, n, i) => t === "dimension" ? [e, n] : [
|
|
|
235
235
|
return new W().scale(e, t);
|
|
236
236
|
}
|
|
237
237
|
translate(e) {
|
|
238
|
-
const t = this.new(), n =
|
|
238
|
+
const t = this.new(), n = Pt(e);
|
|
239
239
|
return n.type = "translate", t.ops.push(n), t;
|
|
240
240
|
}
|
|
241
241
|
magnify(e) {
|
|
242
|
-
const t = this.new(), n =
|
|
242
|
+
const t = this.new(), n = Lt(e);
|
|
243
243
|
return n.type = "magnify", t.ops.push(n), t;
|
|
244
244
|
}
|
|
245
245
|
scale(e, t) {
|
|
246
|
-
const n =
|
|
247
|
-
return a.type = "scale",
|
|
246
|
+
const n = K(e, t), s = this.new(), a = Yt(n);
|
|
247
|
+
return a.type = "scale", s.ops.push(a), s;
|
|
248
248
|
}
|
|
249
249
|
clamp(e, t) {
|
|
250
|
-
const n =
|
|
251
|
-
return a.type = "clamp",
|
|
250
|
+
const n = K(e, t), s = this.new(), a = Ft(n);
|
|
251
|
+
return a.type = "clamp", s.ops.push(a), s;
|
|
252
252
|
}
|
|
253
253
|
reBound(e, t) {
|
|
254
|
-
const n =
|
|
255
|
-
return a.type = "re-bound",
|
|
254
|
+
const n = K(e, t), s = this.new(), a = kt(n);
|
|
255
|
+
return a.type = "re-bound", s.ops.push(a), s;
|
|
256
256
|
}
|
|
257
257
|
invert() {
|
|
258
|
-
const e =
|
|
258
|
+
const e = jt();
|
|
259
259
|
e.type = "invert";
|
|
260
260
|
const t = this.new();
|
|
261
261
|
return t.ops.push(e), t;
|
|
@@ -272,7 +272,7 @@ const St = (r) => (e, t, n, i) => t === "dimension" ? [e, n] : [
|
|
|
272
272
|
}
|
|
273
273
|
exec(e, t) {
|
|
274
274
|
return this.currBounds = null, this.ops.reduce(
|
|
275
|
-
([n,
|
|
275
|
+
([n, s], a) => a(n, e, s, this.reversed),
|
|
276
276
|
[null, t]
|
|
277
277
|
)[1];
|
|
278
278
|
}
|
|
@@ -280,47 +280,47 @@ const St = (r) => (e, t, n, i) => t === "dimension" ? [e, n] : [
|
|
|
280
280
|
const e = this.new();
|
|
281
281
|
e.ops.reverse();
|
|
282
282
|
const t = [];
|
|
283
|
-
return e.ops.forEach((n,
|
|
284
|
-
if (n.type === "scale" || t.some(([c,
|
|
283
|
+
return e.ops.forEach((n, s) => {
|
|
284
|
+
if (n.type === "scale" || t.some(([c, d]) => s >= c && s <= d))
|
|
285
285
|
return;
|
|
286
|
-
const a = e.ops.findIndex((c,
|
|
287
|
-
a !== -1 && t.push([
|
|
288
|
-
}), t.forEach(([n,
|
|
289
|
-
const a = e.ops.slice(n,
|
|
290
|
-
a.unshift(e.ops[
|
|
286
|
+
const a = e.ops.findIndex((c, d) => c.type === "scale" && d > s);
|
|
287
|
+
a !== -1 && t.push([s, a]);
|
|
288
|
+
}), t.forEach(([n, s]) => {
|
|
289
|
+
const a = e.ops.slice(n, s);
|
|
290
|
+
a.unshift(e.ops[s]), e.ops.splice(n, s - n + 1, ...a);
|
|
291
291
|
}), e.reversed = !e.reversed, e;
|
|
292
292
|
}
|
|
293
293
|
};
|
|
294
|
-
|
|
295
|
-
let
|
|
296
|
-
const
|
|
297
|
-
constructor(e = new
|
|
298
|
-
|
|
294
|
+
D(fe, "IDENTITY", new fe());
|
|
295
|
+
let Ee = fe;
|
|
296
|
+
const Ae = class U {
|
|
297
|
+
constructor(e = new Ee(), t = new Ee(), n = null) {
|
|
298
|
+
D(this, "x"), D(this, "y"), D(this, "currRoot"), this.x = e, this.y = t, this.currRoot = n;
|
|
299
299
|
}
|
|
300
300
|
static translate(e, t) {
|
|
301
|
-
return new
|
|
301
|
+
return new U().translate(e, t);
|
|
302
302
|
}
|
|
303
303
|
static translateX(e) {
|
|
304
|
-
return new
|
|
304
|
+
return new U().translateX(e);
|
|
305
305
|
}
|
|
306
306
|
static translateY(e) {
|
|
307
|
-
return new
|
|
307
|
+
return new U().translateY(e);
|
|
308
308
|
}
|
|
309
309
|
static clamp(e) {
|
|
310
|
-
return new
|
|
310
|
+
return new U().clamp(e);
|
|
311
311
|
}
|
|
312
312
|
static magnify(e) {
|
|
313
|
-
return new
|
|
313
|
+
return new U().magnify(e);
|
|
314
314
|
}
|
|
315
315
|
static scale(e) {
|
|
316
|
-
return new
|
|
316
|
+
return new U().scale(e);
|
|
317
317
|
}
|
|
318
318
|
static reBound(e) {
|
|
319
|
-
return new
|
|
319
|
+
return new U().reBound(e);
|
|
320
320
|
}
|
|
321
321
|
translate(e, t) {
|
|
322
|
-
const n =
|
|
323
|
-
return
|
|
322
|
+
const n = Rt(e, t), s = this.copy();
|
|
323
|
+
return s.x = this.x.translate(n.x), s.y = this.y.translate(n.y), s;
|
|
324
324
|
}
|
|
325
325
|
translateX(e) {
|
|
326
326
|
const t = this.copy();
|
|
@@ -336,22 +336,22 @@ const ve = class M {
|
|
|
336
336
|
}
|
|
337
337
|
scale(e) {
|
|
338
338
|
const t = this.copy();
|
|
339
|
-
if (
|
|
339
|
+
if (Bt(e)) {
|
|
340
340
|
const n = this.currRoot;
|
|
341
|
-
return t.currRoot = e.root, n != null &&
|
|
341
|
+
return t.currRoot = e.root, n != null && !$t(n, e.root) && (n.x !== e.root.x && (t.x = t.x.invert()), n.y !== e.root.y && (t.y = t.y.invert())), t.x = t.x.scale(ce(e)), t.y = t.y.scale(le(e)), t;
|
|
342
342
|
}
|
|
343
343
|
return t.x = t.x.scale(e.width), t.y = t.y.scale(e.height), t;
|
|
344
344
|
}
|
|
345
345
|
reBound(e) {
|
|
346
346
|
const t = this.copy();
|
|
347
|
-
return t.x = this.x.reBound(
|
|
347
|
+
return t.x = this.x.reBound(ce(e)), t.y = this.y.reBound(le(e)), t;
|
|
348
348
|
}
|
|
349
349
|
clamp(e) {
|
|
350
350
|
const t = this.copy();
|
|
351
|
-
return t.x = this.x.clamp(
|
|
351
|
+
return t.x = this.x.clamp(ce(e)), t.y = this.y.clamp(le(e)), t;
|
|
352
352
|
}
|
|
353
353
|
copy() {
|
|
354
|
-
const e = new
|
|
354
|
+
const e = new U();
|
|
355
355
|
return e.currRoot = this.currRoot, e.x = this.x, e.y = this.y, e;
|
|
356
356
|
}
|
|
357
357
|
reverse() {
|
|
@@ -362,7 +362,7 @@ const ve = class M {
|
|
|
362
362
|
return { x: this.x.pos(e.x), y: this.y.pos(e.y) };
|
|
363
363
|
}
|
|
364
364
|
box(e) {
|
|
365
|
-
return
|
|
365
|
+
return ye(
|
|
366
366
|
this.pos(e.one),
|
|
367
367
|
this.pos(e.two),
|
|
368
368
|
0,
|
|
@@ -371,12 +371,45 @@ const ve = class M {
|
|
|
371
371
|
);
|
|
372
372
|
}
|
|
373
373
|
};
|
|
374
|
-
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
374
|
+
D(Ae, "IDENTITY", new Ae());
|
|
375
|
+
const Gt = (r) => r != null && typeof r == "object" && "toString" in r, qt = (r, e = !1) => {
|
|
376
|
+
const t = Gt(r) ? "stringer" : typeof r;
|
|
377
|
+
let n;
|
|
378
|
+
switch (t) {
|
|
379
|
+
case "string":
|
|
380
|
+
n = (s, a) => s.localeCompare(a);
|
|
381
|
+
break;
|
|
382
|
+
case "stringer":
|
|
383
|
+
n = (s, a) => s.toString().localeCompare(a.toString());
|
|
384
|
+
break;
|
|
385
|
+
case "number":
|
|
386
|
+
n = (s, a) => Number(s) - Number(a);
|
|
387
|
+
break;
|
|
388
|
+
case "bigint":
|
|
389
|
+
n = (s, a) => BigInt(s) - BigInt(a) > 0n ? 1 : -1;
|
|
390
|
+
break;
|
|
391
|
+
case "boolean":
|
|
392
|
+
n = (s, a) => Number(s) - Number(a);
|
|
393
|
+
break;
|
|
394
|
+
case "undefined":
|
|
395
|
+
n = () => 0;
|
|
396
|
+
break;
|
|
397
|
+
default:
|
|
398
|
+
return console.warn(`sortFunc: unknown type ${t}`), () => -1;
|
|
399
|
+
}
|
|
400
|
+
return e ? Wt(n) : n;
|
|
401
|
+
}, Wt = (r) => (e, t) => r(t, e), zt = i.object({ signedWidth: i.number(), signedHeight: i.number() });
|
|
402
|
+
i.union([je, zt, ne, ie]);
|
|
403
|
+
const Zt = i.bigint().or(i.string().transform(BigInt));
|
|
404
|
+
var Vt = Object.defineProperty, Jt = (r, e, t) => e in r ? Vt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, u = (r, e, t) => Jt(r, typeof e != "symbol" ? e + "" : e, t);
|
|
405
|
+
let Ht = (r, e = 21) => (t = e) => {
|
|
406
|
+
let n = "", s = t;
|
|
407
|
+
for (; s--; )
|
|
408
|
+
n += r[Math.random() * r.length | 0];
|
|
409
|
+
return n;
|
|
410
|
+
};
|
|
411
|
+
const Kt = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Xt = Ht(Kt, 11), Qt = i.enum(["static", "dynamic"]), Ve = (r, e) => {
|
|
412
|
+
const t = new O(e);
|
|
380
413
|
if (![
|
|
381
414
|
S.DAY,
|
|
382
415
|
S.HOUR,
|
|
@@ -385,28 +418,28 @@ const De = (r, e) => {
|
|
|
385
418
|
S.MILLISECOND,
|
|
386
419
|
S.MICROSECOND,
|
|
387
420
|
S.NANOSECOND
|
|
388
|
-
].some((
|
|
421
|
+
].some((s) => s.equals(t)))
|
|
389
422
|
throw new Error(
|
|
390
423
|
"Invalid argument for remainder. Must be an even TimeSpan or Timestamp"
|
|
391
424
|
);
|
|
392
425
|
const n = r.valueOf() % t.valueOf();
|
|
393
|
-
return r instanceof
|
|
394
|
-
},
|
|
426
|
+
return r instanceof O ? new O(n) : new S(n);
|
|
427
|
+
}, m = class h {
|
|
395
428
|
constructor(e, t = "UTC") {
|
|
396
|
-
if (u(this, "value"), u(this, "encodeValue", !0), e == null) this.value =
|
|
429
|
+
if (u(this, "value"), u(this, "encodeValue", !0), e == null) this.value = h.now().valueOf();
|
|
397
430
|
else if (e instanceof Date)
|
|
398
|
-
this.value = BigInt(e.getTime()) *
|
|
431
|
+
this.value = BigInt(e.getTime()) * h.MILLISECOND.valueOf();
|
|
399
432
|
else if (typeof e == "string")
|
|
400
|
-
this.value =
|
|
401
|
-
else if (Array.isArray(e)) this.value =
|
|
433
|
+
this.value = h.parseDateTimeString(e, t).valueOf();
|
|
434
|
+
else if (Array.isArray(e)) this.value = h.parseDate(e);
|
|
402
435
|
else {
|
|
403
436
|
let n = BigInt(0);
|
|
404
|
-
e instanceof Number && (e = e.valueOf()), t === "local" && (n =
|
|
437
|
+
e instanceof Number && (e = e.valueOf()), t === "local" && (n = h.utcOffset.valueOf()), typeof e == "number" && (isFinite(e) ? e = Math.trunc(e) : (isNaN(e) && (e = 0), e === 1 / 0 ? e = h.MAX : e = h.MIN)), this.value = BigInt(e.valueOf()) + n;
|
|
405
438
|
}
|
|
406
439
|
}
|
|
407
440
|
static parseDate([e = 1970, t = 1, n = 1]) {
|
|
408
|
-
const
|
|
409
|
-
return new
|
|
441
|
+
const s = new Date(e, t - 1, n, 0, 0, 0, 0);
|
|
442
|
+
return new h(BigInt(s.getTime()) * h.MILLISECOND.valueOf()).truncate(h.DAY).valueOf();
|
|
410
443
|
}
|
|
411
444
|
encode() {
|
|
412
445
|
return this.value.toString();
|
|
@@ -415,18 +448,18 @@ const De = (r, e) => {
|
|
|
415
448
|
return this.value;
|
|
416
449
|
}
|
|
417
450
|
static parseTimeString(e, t = "UTC") {
|
|
418
|
-
const [n,
|
|
419
|
-
let c = "00",
|
|
420
|
-
a != null && ([c,
|
|
421
|
-
let
|
|
422
|
-
return t === "local" && (
|
|
451
|
+
const [n, s, a] = e.split(":");
|
|
452
|
+
let c = "00", d = "00";
|
|
453
|
+
a != null && ([c, d] = a.split("."));
|
|
454
|
+
let f = h.hours(parseInt(n ?? "00", 10)).add(h.minutes(parseInt(s ?? "00", 10))).add(h.seconds(parseInt(c ?? "00", 10))).add(h.milliseconds(parseInt(d ?? "00", 10)));
|
|
455
|
+
return t === "local" && (f = f.add(h.utcOffset)), f.valueOf();
|
|
423
456
|
}
|
|
424
457
|
static parseDateTimeString(e, t = "UTC") {
|
|
425
458
|
if (!e.includes("/") && !e.includes("-"))
|
|
426
|
-
return
|
|
459
|
+
return h.parseTimeString(e, t);
|
|
427
460
|
const n = new Date(e);
|
|
428
|
-
return e.includes(":") || n.setUTCHours(0, 0, 0, 0), new
|
|
429
|
-
BigInt(n.getTime()) *
|
|
461
|
+
return e.includes(":") || n.setUTCHours(0, 0, 0, 0), new h(
|
|
462
|
+
BigInt(n.getTime()) * h.MILLISECOND.valueOf(),
|
|
430
463
|
t
|
|
431
464
|
).valueOf();
|
|
432
465
|
}
|
|
@@ -451,7 +484,7 @@ const De = (r, e) => {
|
|
|
451
484
|
}
|
|
452
485
|
}
|
|
453
486
|
toISOString(e = "UTC") {
|
|
454
|
-
return e === "UTC" ? this.date().toISOString() : this.sub(
|
|
487
|
+
return e === "UTC" ? this.date().toISOString() : this.sub(h.utcOffset).date().toISOString();
|
|
455
488
|
}
|
|
456
489
|
timeString(e = !1, t = "UTC") {
|
|
457
490
|
const n = this.toISOString(t);
|
|
@@ -463,7 +496,7 @@ const De = (r, e) => {
|
|
|
463
496
|
}
|
|
464
497
|
static get utcOffset() {
|
|
465
498
|
return new S(
|
|
466
|
-
BigInt((/* @__PURE__ */ new Date()).getTimezoneOffset()) *
|
|
499
|
+
BigInt((/* @__PURE__ */ new Date()).getTimezoneOffset()) * h.MINUTE.valueOf()
|
|
467
500
|
);
|
|
468
501
|
}
|
|
469
502
|
/**
|
|
@@ -472,7 +505,7 @@ const De = (r, e) => {
|
|
|
472
505
|
* @param other - The other timestamp.
|
|
473
506
|
*/
|
|
474
507
|
static since(e) {
|
|
475
|
-
return new
|
|
508
|
+
return new h().span(e);
|
|
476
509
|
}
|
|
477
510
|
/** @returns A JavaScript Date object representing the TimeStamp. */
|
|
478
511
|
date() {
|
|
@@ -485,7 +518,7 @@ const De = (r, e) => {
|
|
|
485
518
|
* @returns True if the TimeStamps are equal, false otherwise.
|
|
486
519
|
*/
|
|
487
520
|
equals(e) {
|
|
488
|
-
return this.valueOf() === new
|
|
521
|
+
return this.valueOf() === new h(e).valueOf();
|
|
489
522
|
}
|
|
490
523
|
/**
|
|
491
524
|
* Creates a TimeSpan representing the duration between the two timestamps.
|
|
@@ -505,7 +538,7 @@ const De = (r, e) => {
|
|
|
505
538
|
* valid, regardless of the TimeStamp order.
|
|
506
539
|
*/
|
|
507
540
|
range(e) {
|
|
508
|
-
return new
|
|
541
|
+
return new me(this, e).makeValid();
|
|
509
542
|
}
|
|
510
543
|
/**
|
|
511
544
|
* Creates a TimeRange starting at the TimeStamp and spanning the given
|
|
@@ -534,7 +567,7 @@ const De = (r, e) => {
|
|
|
534
567
|
* otherwise.
|
|
535
568
|
*/
|
|
536
569
|
after(e) {
|
|
537
|
-
return this.valueOf() > new
|
|
570
|
+
return this.valueOf() > new h(e).valueOf();
|
|
538
571
|
}
|
|
539
572
|
/**
|
|
540
573
|
* Checks if the TimeStamp is after or equal to the given TimeStamp.
|
|
@@ -544,7 +577,7 @@ const De = (r, e) => {
|
|
|
544
577
|
* false otherwise.
|
|
545
578
|
*/
|
|
546
579
|
afterEq(e) {
|
|
547
|
-
return this.valueOf() >= new
|
|
580
|
+
return this.valueOf() >= new h(e).valueOf();
|
|
548
581
|
}
|
|
549
582
|
/**
|
|
550
583
|
* Checks if the TimeStamp is before the given TimeStamp.
|
|
@@ -554,7 +587,7 @@ const De = (r, e) => {
|
|
|
554
587
|
* otherwise.
|
|
555
588
|
*/
|
|
556
589
|
before(e) {
|
|
557
|
-
return this.valueOf() < new
|
|
590
|
+
return this.valueOf() < new h(e).valueOf();
|
|
558
591
|
}
|
|
559
592
|
/**
|
|
560
593
|
* Checks if TimeStamp is before or equal to the current timestamp.
|
|
@@ -564,7 +597,7 @@ const De = (r, e) => {
|
|
|
564
597
|
* false otherwise.
|
|
565
598
|
*/
|
|
566
599
|
beforeEq(e) {
|
|
567
|
-
return this.valueOf() <= new
|
|
600
|
+
return this.valueOf() <= new h(e).valueOf();
|
|
568
601
|
}
|
|
569
602
|
/**
|
|
570
603
|
* Adds a TimeSpan to the TimeStamp.
|
|
@@ -574,7 +607,7 @@ const De = (r, e) => {
|
|
|
574
607
|
* TimeSpan.
|
|
575
608
|
*/
|
|
576
609
|
add(e) {
|
|
577
|
-
return new
|
|
610
|
+
return new h(this.valueOf() + BigInt(e.valueOf()));
|
|
578
611
|
}
|
|
579
612
|
/**
|
|
580
613
|
* Subtracts a TimeSpan from the TimeStamp.
|
|
@@ -584,13 +617,13 @@ const De = (r, e) => {
|
|
|
584
617
|
* TimeSpan.
|
|
585
618
|
*/
|
|
586
619
|
sub(e) {
|
|
587
|
-
return new
|
|
620
|
+
return new h(this.valueOf() - BigInt(e.valueOf()));
|
|
588
621
|
}
|
|
589
622
|
/**
|
|
590
623
|
* @returns The number of milliseconds since the unix epoch.
|
|
591
624
|
*/
|
|
592
625
|
milliseconds() {
|
|
593
|
-
return Number(this.valueOf()) / Number(
|
|
626
|
+
return Number(this.valueOf()) / Number(h.MILLISECOND.valueOf());
|
|
594
627
|
}
|
|
595
628
|
toString() {
|
|
596
629
|
return this.date().toISOString();
|
|
@@ -607,11 +640,11 @@ const De = (r, e) => {
|
|
|
607
640
|
* @example TimeStamp.now().remainder(TimeStamp.DAY) // => TimeStamp representing the current day
|
|
608
641
|
*/
|
|
609
642
|
remainder(e) {
|
|
610
|
-
return
|
|
643
|
+
return Ve(this, e);
|
|
611
644
|
}
|
|
612
645
|
/** @returns true if the day portion TimeStamp is today, false otherwise. */
|
|
613
646
|
get isToday() {
|
|
614
|
-
return this.truncate(S.DAY).equals(
|
|
647
|
+
return this.truncate(S.DAY).equals(h.now().truncate(S.DAY));
|
|
615
648
|
}
|
|
616
649
|
truncate(e) {
|
|
617
650
|
return this.sub(this.remainder(e));
|
|
@@ -622,72 +655,72 @@ const De = (r, e) => {
|
|
|
622
655
|
* JavaScript can do).
|
|
623
656
|
*/
|
|
624
657
|
static now() {
|
|
625
|
-
return new
|
|
658
|
+
return new h(/* @__PURE__ */ new Date());
|
|
626
659
|
}
|
|
627
660
|
static max(...e) {
|
|
628
|
-
let t =
|
|
661
|
+
let t = h.MIN;
|
|
629
662
|
for (const n of e) {
|
|
630
|
-
const
|
|
631
|
-
|
|
663
|
+
const s = new h(n);
|
|
664
|
+
s.after(t) && (t = s);
|
|
632
665
|
}
|
|
633
666
|
return t;
|
|
634
667
|
}
|
|
635
668
|
static min(...e) {
|
|
636
|
-
let t =
|
|
669
|
+
let t = h.MAX;
|
|
637
670
|
for (const n of e) {
|
|
638
|
-
const
|
|
639
|
-
|
|
671
|
+
const s = new h(n);
|
|
672
|
+
s.before(t) && (t = s);
|
|
640
673
|
}
|
|
641
674
|
return t;
|
|
642
675
|
}
|
|
643
676
|
/** @returns a new TimeStamp n nanoseconds after the unix epoch */
|
|
644
677
|
static nanoseconds(e) {
|
|
645
|
-
return new
|
|
678
|
+
return new h(e);
|
|
646
679
|
}
|
|
647
680
|
/** @returns a new TimeStamp n microseconds after the unix epoch */
|
|
648
681
|
static microseconds(e) {
|
|
649
|
-
return
|
|
682
|
+
return h.nanoseconds(e * 1e3);
|
|
650
683
|
}
|
|
651
684
|
/** @returns a new TimeStamp n milliseconds after the unix epoch */
|
|
652
685
|
static milliseconds(e) {
|
|
653
|
-
return
|
|
686
|
+
return h.microseconds(e * 1e3);
|
|
654
687
|
}
|
|
655
688
|
/** @returns a new TimeStamp n seconds after the unix epoch */
|
|
656
689
|
static seconds(e) {
|
|
657
|
-
return
|
|
690
|
+
return h.milliseconds(e * 1e3);
|
|
658
691
|
}
|
|
659
692
|
/** @returns a new TimeStamp n minutes after the unix epoch */
|
|
660
693
|
static minutes(e) {
|
|
661
|
-
return
|
|
694
|
+
return h.seconds(e * 60);
|
|
662
695
|
}
|
|
663
696
|
/** @returns a new TimeStamp n hours after the unix epoch */
|
|
664
697
|
static hours(e) {
|
|
665
|
-
return
|
|
698
|
+
return h.minutes(e * 60);
|
|
666
699
|
}
|
|
667
700
|
/** @returns a new TimeStamp n days after the unix epoch */
|
|
668
701
|
static days(e) {
|
|
669
|
-
return
|
|
702
|
+
return h.hours(e * 24);
|
|
670
703
|
}
|
|
671
704
|
};
|
|
672
|
-
u(
|
|
673
|
-
u(
|
|
674
|
-
u(
|
|
675
|
-
u(
|
|
676
|
-
u(
|
|
677
|
-
u(
|
|
678
|
-
u(
|
|
679
|
-
u(
|
|
680
|
-
u(
|
|
681
|
-
u(
|
|
682
|
-
u(
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
705
|
+
u(m, "NANOSECOND", m.nanoseconds(1)), /** One microsecond after the unix epoch */
|
|
706
|
+
u(m, "MICROSECOND", m.microseconds(1)), /** One millisecond after the unix epoch */
|
|
707
|
+
u(m, "MILLISECOND", m.milliseconds(1)), /** One second after the unix epoch */
|
|
708
|
+
u(m, "SECOND", m.seconds(1)), /** One minute after the unix epoch */
|
|
709
|
+
u(m, "MINUTE", m.minutes(1)), /** One hour after the unix epoch */
|
|
710
|
+
u(m, "HOUR", m.hours(1)), /** One day after the unix epoch */
|
|
711
|
+
u(m, "DAY", m.days(1)), /** The maximum possible value for a timestamp */
|
|
712
|
+
u(m, "MAX", new m((1n << 63n) - 1n)), /** The minimum possible value for a timestamp */
|
|
713
|
+
u(m, "MIN", new m(0)), /** The unix epoch */
|
|
714
|
+
u(m, "ZERO", new m(0)), /** A zod schema for validating timestamps */
|
|
715
|
+
u(m, "z", i.union([
|
|
716
|
+
i.object({ value: i.bigint() }).transform((r) => new m(r.value)),
|
|
717
|
+
i.string().transform((r) => new m(BigInt(r))),
|
|
718
|
+
i.instanceof(Number).transform((r) => new m(r)),
|
|
719
|
+
i.number().transform((r) => new m(r)),
|
|
720
|
+
i.instanceof(m)
|
|
688
721
|
]));
|
|
689
|
-
let
|
|
690
|
-
const
|
|
722
|
+
let O = m;
|
|
723
|
+
const w = class g {
|
|
691
724
|
constructor(e) {
|
|
692
725
|
u(this, "value"), u(this, "encodeValue", !0), typeof e == "number" && (e = Math.trunc(e.valueOf())), this.value = BigInt(e.valueOf());
|
|
693
726
|
}
|
|
@@ -698,52 +731,52 @@ const y = class d {
|
|
|
698
731
|
return this.value;
|
|
699
732
|
}
|
|
700
733
|
lessThan(e) {
|
|
701
|
-
return this.valueOf() < new
|
|
734
|
+
return this.valueOf() < new g(e).valueOf();
|
|
702
735
|
}
|
|
703
736
|
greaterThan(e) {
|
|
704
|
-
return this.valueOf() > new
|
|
737
|
+
return this.valueOf() > new g(e).valueOf();
|
|
705
738
|
}
|
|
706
739
|
lessThanOrEqual(e) {
|
|
707
|
-
return this.valueOf() <= new
|
|
740
|
+
return this.valueOf() <= new g(e).valueOf();
|
|
708
741
|
}
|
|
709
742
|
greaterThanOrEqual(e) {
|
|
710
|
-
return this.valueOf() >= new
|
|
743
|
+
return this.valueOf() >= new g(e).valueOf();
|
|
711
744
|
}
|
|
712
745
|
remainder(e) {
|
|
713
|
-
return
|
|
746
|
+
return Ve(this, e);
|
|
714
747
|
}
|
|
715
748
|
truncate(e) {
|
|
716
|
-
return new
|
|
749
|
+
return new g(
|
|
717
750
|
BigInt(Math.trunc(Number(this.valueOf() / e.valueOf()))) * e.valueOf()
|
|
718
751
|
);
|
|
719
752
|
}
|
|
720
753
|
toString() {
|
|
721
|
-
const e = this.truncate(
|
|
722
|
-
let
|
|
723
|
-
return
|
|
754
|
+
const e = this.truncate(g.DAY), t = this.truncate(g.HOUR), n = this.truncate(g.MINUTE), s = this.truncate(g.SECOND), a = this.truncate(g.MILLISECOND), c = this.truncate(g.MICROSECOND), d = this.truncate(g.NANOSECOND), f = e, y = t.sub(e), T = n.sub(t), l = s.sub(n), E = a.sub(s), R = c.sub(a), B = d.sub(c);
|
|
755
|
+
let x = "";
|
|
756
|
+
return f.isZero || (x += `${f.days}d `), y.isZero || (x += `${y.hours}h `), T.isZero || (x += `${T.minutes}m `), l.isZero || (x += `${l.seconds}s `), E.isZero || (x += `${E.milliseconds}ms `), R.isZero || (x += `${R.microseconds}µs `), B.isZero || (x += `${B.nanoseconds}ns`), x.trim();
|
|
724
757
|
}
|
|
725
758
|
/** @returns the decimal number of days in the timespan */
|
|
726
759
|
get days() {
|
|
727
|
-
return Number(this.valueOf()) / Number(
|
|
760
|
+
return Number(this.valueOf()) / Number(g.DAY.valueOf());
|
|
728
761
|
}
|
|
729
762
|
/** @returns the decimal number of hours in the timespan */
|
|
730
763
|
get hours() {
|
|
731
|
-
return Number(this.valueOf()) / Number(
|
|
764
|
+
return Number(this.valueOf()) / Number(g.HOUR.valueOf());
|
|
732
765
|
}
|
|
733
766
|
/** @returns the decimal number of minutes in the timespan */
|
|
734
767
|
get minutes() {
|
|
735
|
-
return Number(this.valueOf()) / Number(
|
|
768
|
+
return Number(this.valueOf()) / Number(g.MINUTE.valueOf());
|
|
736
769
|
}
|
|
737
770
|
/** @returns The number of seconds in the TimeSpan. */
|
|
738
771
|
get seconds() {
|
|
739
|
-
return Number(this.valueOf()) / Number(
|
|
772
|
+
return Number(this.valueOf()) / Number(g.SECOND.valueOf());
|
|
740
773
|
}
|
|
741
774
|
/** @returns The number of milliseconds in the TimeSpan. */
|
|
742
775
|
get milliseconds() {
|
|
743
|
-
return Number(this.valueOf()) / Number(
|
|
776
|
+
return Number(this.valueOf()) / Number(g.MILLISECOND.valueOf());
|
|
744
777
|
}
|
|
745
778
|
get microseconds() {
|
|
746
|
-
return Number(this.valueOf()) / Number(
|
|
779
|
+
return Number(this.valueOf()) / Number(g.MICROSECOND.valueOf());
|
|
747
780
|
}
|
|
748
781
|
get nanoseconds() {
|
|
749
782
|
return Number(this.valueOf());
|
|
@@ -762,7 +795,7 @@ const y = class d {
|
|
|
762
795
|
* @returns True if the TimeSpans are equal, false otherwise.
|
|
763
796
|
*/
|
|
764
797
|
equals(e) {
|
|
765
|
-
return this.valueOf() === new
|
|
798
|
+
return this.valueOf() === new g(e).valueOf();
|
|
766
799
|
}
|
|
767
800
|
/**
|
|
768
801
|
* Adds a TimeSpan to the TimeSpan.
|
|
@@ -770,7 +803,7 @@ const y = class d {
|
|
|
770
803
|
* @returns A new TimeSpan representing the sum of the two TimeSpans.
|
|
771
804
|
*/
|
|
772
805
|
add(e) {
|
|
773
|
-
return new
|
|
806
|
+
return new g(this.valueOf() + new g(e).valueOf());
|
|
774
807
|
}
|
|
775
808
|
/**
|
|
776
809
|
* Creates a TimeSpan representing the duration between the two timestamps.
|
|
@@ -778,7 +811,7 @@ const y = class d {
|
|
|
778
811
|
* @param other
|
|
779
812
|
*/
|
|
780
813
|
sub(e) {
|
|
781
|
-
return new
|
|
814
|
+
return new g(this.valueOf() - new g(e).valueOf());
|
|
782
815
|
}
|
|
783
816
|
/**
|
|
784
817
|
* Creates a TimeSpan representing the given number of nanoseconds.
|
|
@@ -787,7 +820,7 @@ const y = class d {
|
|
|
787
820
|
* @returns A TimeSpan representing the given number of nanoseconds.
|
|
788
821
|
*/
|
|
789
822
|
static nanoseconds(e = 1) {
|
|
790
|
-
return new
|
|
823
|
+
return new g(e);
|
|
791
824
|
}
|
|
792
825
|
/**
|
|
793
826
|
* Creates a TimeSpan representing the given number of microseconds.
|
|
@@ -796,7 +829,7 @@ const y = class d {
|
|
|
796
829
|
* @returns A TimeSpan representing the given number of microseconds.
|
|
797
830
|
*/
|
|
798
831
|
static microseconds(e = 1) {
|
|
799
|
-
return
|
|
832
|
+
return g.nanoseconds(e * 1e3);
|
|
800
833
|
}
|
|
801
834
|
/**
|
|
802
835
|
* Creates a TimeSpan representing the given number of milliseconds.
|
|
@@ -805,7 +838,7 @@ const y = class d {
|
|
|
805
838
|
* @returns A TimeSpan representing the given number of milliseconds.
|
|
806
839
|
*/
|
|
807
840
|
static milliseconds(e = 1) {
|
|
808
|
-
return
|
|
841
|
+
return g.microseconds(e * 1e3);
|
|
809
842
|
}
|
|
810
843
|
/**
|
|
811
844
|
* Creates a TimeSpan representing the given number of seconds.
|
|
@@ -814,7 +847,7 @@ const y = class d {
|
|
|
814
847
|
* @returns A TimeSpan representing the given number of seconds.
|
|
815
848
|
*/
|
|
816
849
|
static seconds(e = 1) {
|
|
817
|
-
return
|
|
850
|
+
return g.milliseconds(e * 1e3);
|
|
818
851
|
}
|
|
819
852
|
/**
|
|
820
853
|
* Creates a TimeSpan representing the given number of minutes.
|
|
@@ -823,7 +856,7 @@ const y = class d {
|
|
|
823
856
|
* @returns A TimeSpan representing the given number of minutes.
|
|
824
857
|
*/
|
|
825
858
|
static minutes(e) {
|
|
826
|
-
return
|
|
859
|
+
return g.seconds(e.valueOf() * 60);
|
|
827
860
|
}
|
|
828
861
|
/**
|
|
829
862
|
* Creates a TimeSpan representing the given number of hours.
|
|
@@ -832,7 +865,7 @@ const y = class d {
|
|
|
832
865
|
* @returns A TimeSpan representing the given number of hours.
|
|
833
866
|
*/
|
|
834
867
|
static hours(e) {
|
|
835
|
-
return
|
|
868
|
+
return g.minutes(e * 60);
|
|
836
869
|
}
|
|
837
870
|
/**
|
|
838
871
|
* Creates a TimeSpan representing the given number of days.
|
|
@@ -841,28 +874,28 @@ const y = class d {
|
|
|
841
874
|
* @returns A TimeSpan representing the given number of days.
|
|
842
875
|
*/
|
|
843
876
|
static days(e) {
|
|
844
|
-
return
|
|
877
|
+
return g.hours(e * 24);
|
|
845
878
|
}
|
|
846
879
|
};
|
|
847
|
-
u(
|
|
848
|
-
u(
|
|
849
|
-
u(
|
|
850
|
-
u(
|
|
851
|
-
u(
|
|
852
|
-
u(
|
|
853
|
-
u(
|
|
854
|
-
u(
|
|
855
|
-
u(
|
|
856
|
-
u(
|
|
857
|
-
u(
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
880
|
+
u(w, "NANOSECOND", w.nanoseconds(1)), /** A microsecond. */
|
|
881
|
+
u(w, "MICROSECOND", w.microseconds(1)), /** A millisecond. */
|
|
882
|
+
u(w, "MILLISECOND", w.milliseconds(1)), /** A second. */
|
|
883
|
+
u(w, "SECOND", w.seconds(1)), /** A minute. */
|
|
884
|
+
u(w, "MINUTE", w.minutes(1)), /** Represents an hour. */
|
|
885
|
+
u(w, "HOUR", w.hours(1)), /** Represents a day. */
|
|
886
|
+
u(w, "DAY", w.days(1)), /** The maximum possible value for a TimeSpan. */
|
|
887
|
+
u(w, "MAX", new w((1n << 63n) - 1n)), /** The minimum possible value for a TimeSpan. */
|
|
888
|
+
u(w, "MIN", new w(0)), /** The zero value for a TimeSpan. */
|
|
889
|
+
u(w, "ZERO", new w(0)), /** A zod schema for validating and transforming timespans */
|
|
890
|
+
u(w, "z", i.union([
|
|
891
|
+
i.object({ value: i.bigint() }).transform((r) => new w(r.value)),
|
|
892
|
+
i.string().transform((r) => new w(BigInt(r))),
|
|
893
|
+
i.instanceof(Number).transform((r) => new w(r)),
|
|
894
|
+
i.number().transform((r) => new w(r)),
|
|
895
|
+
i.instanceof(w)
|
|
863
896
|
]));
|
|
864
|
-
let S =
|
|
865
|
-
const
|
|
897
|
+
let S = w;
|
|
898
|
+
const Q = class ee extends Number {
|
|
866
899
|
constructor(e) {
|
|
867
900
|
e instanceof Number ? super(e.valueOf()) : super(e);
|
|
868
901
|
}
|
|
@@ -872,7 +905,7 @@ const z = class V extends Number {
|
|
|
872
905
|
}
|
|
873
906
|
/** @returns The number of seconds in the Rate. */
|
|
874
907
|
equals(e) {
|
|
875
|
-
return this.valueOf() === new
|
|
908
|
+
return this.valueOf() === new ee(e).valueOf();
|
|
876
909
|
}
|
|
877
910
|
/**
|
|
878
911
|
* Calculates the period of the Rate as a TimeSpan.
|
|
@@ -899,7 +932,7 @@ const z = class V extends Number {
|
|
|
899
932
|
* @returns The number of bytes in the given TimeSpan at this rate.
|
|
900
933
|
*/
|
|
901
934
|
byteCount(e, t) {
|
|
902
|
-
return this.sampleCount(e) * new
|
|
935
|
+
return this.sampleCount(e) * new A(t).valueOf();
|
|
903
936
|
}
|
|
904
937
|
/**
|
|
905
938
|
* Calculates a TimeSpan given the number of samples at this rate.
|
|
@@ -927,7 +960,7 @@ const z = class V extends Number {
|
|
|
927
960
|
* @returns A Rate representing the given number of Hz.
|
|
928
961
|
*/
|
|
929
962
|
static hz(e) {
|
|
930
|
-
return new
|
|
963
|
+
return new ee(e);
|
|
931
964
|
}
|
|
932
965
|
/**
|
|
933
966
|
* Creates a Rate representing the given number of kHz.
|
|
@@ -936,15 +969,15 @@ const z = class V extends Number {
|
|
|
936
969
|
* @returns A Rate representing the given number of kHz.
|
|
937
970
|
*/
|
|
938
971
|
static khz(e) {
|
|
939
|
-
return
|
|
972
|
+
return ee.hz(e * 1e3);
|
|
940
973
|
}
|
|
941
974
|
};
|
|
942
|
-
u(
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
975
|
+
u(Q, "z", i.union([
|
|
976
|
+
i.number().transform((r) => new Q(r)),
|
|
977
|
+
i.instanceof(Number).transform((r) => new Q(r)),
|
|
978
|
+
i.instanceof(Q)
|
|
946
979
|
]));
|
|
947
|
-
const
|
|
980
|
+
const I = class extends Number {
|
|
948
981
|
/**
|
|
949
982
|
* Creates a Density representing the given number of bytes per value.
|
|
950
983
|
*
|
|
@@ -959,22 +992,22 @@ const b = class extends Number {
|
|
|
959
992
|
return e.valueOf() / this.valueOf();
|
|
960
993
|
}
|
|
961
994
|
size(e) {
|
|
962
|
-
return new
|
|
995
|
+
return new Je(e * this.valueOf());
|
|
963
996
|
}
|
|
964
997
|
};
|
|
965
|
-
u(
|
|
966
|
-
u(
|
|
967
|
-
u(
|
|
968
|
-
u(
|
|
969
|
-
u(
|
|
970
|
-
u(
|
|
971
|
-
u(
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
998
|
+
u(I, "UNKNOWN", new I(0)), /** 128 bits per value. */
|
|
999
|
+
u(I, "BIT128", new I(16)), /** 64 bits per value. */
|
|
1000
|
+
u(I, "BIT64", new I(8)), /** 32 bits per value. */
|
|
1001
|
+
u(I, "BIT32", new I(4)), /** 16 bits per value. */
|
|
1002
|
+
u(I, "BIT16", new I(2)), /** 8 bits per value. */
|
|
1003
|
+
u(I, "BIT8", new I(1)), /** A zod schema for validating and transforming densities */
|
|
1004
|
+
u(I, "z", i.union([
|
|
1005
|
+
i.number().transform((r) => new I(r)),
|
|
1006
|
+
i.instanceof(Number).transform((r) => new I(r)),
|
|
1007
|
+
i.instanceof(I)
|
|
975
1008
|
]));
|
|
976
|
-
let
|
|
977
|
-
const
|
|
1009
|
+
let A = I;
|
|
1010
|
+
const M = class te {
|
|
978
1011
|
/**
|
|
979
1012
|
* Creates a TimeRange from the given start and end TimeStamps.
|
|
980
1013
|
*
|
|
@@ -982,7 +1015,7 @@ const $ = class H {
|
|
|
982
1015
|
* @param end - A TimeStamp representing the end of the range.
|
|
983
1016
|
*/
|
|
984
1017
|
constructor(e, t) {
|
|
985
|
-
u(this, "start"), u(this, "end"), typeof e == "object" && "start" in e ? (this.start = new
|
|
1018
|
+
u(this, "start"), u(this, "end"), typeof e == "object" && "start" in e ? (this.start = new O(e.start), this.end = new O(e.end)) : (this.start = new O(e), this.end = new O(t));
|
|
986
1019
|
}
|
|
987
1020
|
/** @returns The TimeSpan occupied by the TimeRange. */
|
|
988
1021
|
get span() {
|
|
@@ -1024,7 +1057,7 @@ const $ = class H {
|
|
|
1024
1057
|
* @returns A TimeRange with the start and end swapped.
|
|
1025
1058
|
*/
|
|
1026
1059
|
swap() {
|
|
1027
|
-
return new
|
|
1060
|
+
return new te(this.end, this.start);
|
|
1028
1061
|
}
|
|
1029
1062
|
/**
|
|
1030
1063
|
* Checks if the TimeRange is equal to the given TimeRange.
|
|
@@ -1054,48 +1087,48 @@ const $ = class H {
|
|
|
1054
1087
|
const n = this.makeValid();
|
|
1055
1088
|
if (this.equals(e)) return !0;
|
|
1056
1089
|
if (e.end.equals(n.start) || n.end.equals(e.start)) return !1;
|
|
1057
|
-
const
|
|
1058
|
-
return a.before(
|
|
1090
|
+
const s = O.max(n.start, e.start), a = O.min(n.end, e.end);
|
|
1091
|
+
return a.before(s) ? !1 : new S(a.sub(s)).greaterThanOrEqual(t);
|
|
1059
1092
|
}
|
|
1060
1093
|
roughlyEquals(e, t) {
|
|
1061
|
-
let n = this.start.sub(e.start).valueOf(),
|
|
1062
|
-
return n < 0 && (n = -n),
|
|
1094
|
+
let n = this.start.sub(e.start).valueOf(), s = this.end.sub(e.end).valueOf();
|
|
1095
|
+
return n < 0 && (n = -n), s < 0 && (s = -s), n <= t.valueOf() && s <= t.valueOf();
|
|
1063
1096
|
}
|
|
1064
1097
|
contains(e) {
|
|
1065
|
-
return e instanceof
|
|
1098
|
+
return e instanceof te ? this.contains(e.start) && this.contains(e.end) : this.start.beforeEq(e) && this.end.after(e);
|
|
1066
1099
|
}
|
|
1067
1100
|
boundBy(e) {
|
|
1068
|
-
const t = new
|
|
1101
|
+
const t = new te(this.start, this.end);
|
|
1069
1102
|
return e.start.after(this.start) && (t.start = e.start), e.start.after(this.end) && (t.end = e.start), e.end.before(this.end) && (t.end = e.end), e.end.before(this.start) && (t.start = e.end), t;
|
|
1070
1103
|
}
|
|
1071
1104
|
};
|
|
1072
|
-
u(
|
|
1073
|
-
u(
|
|
1074
|
-
u(
|
|
1075
|
-
u(
|
|
1076
|
-
|
|
1077
|
-
|
|
1105
|
+
u(M, "MAX", new M(O.MIN, O.MAX)), /** The minimum possible time range. */
|
|
1106
|
+
u(M, "MIN", new M(O.MAX, O.MIN)), /** A zero time range. */
|
|
1107
|
+
u(M, "ZERO", new M(O.ZERO, O.ZERO)), /** A zod schema for validating and transforming time ranges */
|
|
1108
|
+
u(M, "z", i.union([
|
|
1109
|
+
i.object({ start: O.z, end: O.z }).transform((r) => new M(r.start, r.end)),
|
|
1110
|
+
i.instanceof(M)
|
|
1078
1111
|
]));
|
|
1079
|
-
let
|
|
1080
|
-
const o = class
|
|
1112
|
+
let me = M;
|
|
1113
|
+
const o = class $ extends String {
|
|
1081
1114
|
constructor(e) {
|
|
1082
|
-
if (e instanceof
|
|
1115
|
+
if (e instanceof $ || typeof e == "string" || typeof e.valueOf() == "string") {
|
|
1083
1116
|
super(e.valueOf());
|
|
1084
1117
|
return;
|
|
1085
1118
|
} else {
|
|
1086
|
-
const t =
|
|
1119
|
+
const t = $.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);
|
|
1087
1120
|
if (t != null) {
|
|
1088
1121
|
super(t.valueOf());
|
|
1089
1122
|
return;
|
|
1090
1123
|
}
|
|
1091
1124
|
}
|
|
1092
|
-
throw super(
|
|
1125
|
+
throw super($.UNKNOWN.valueOf()), new Error(`unable to find data type for ${e.toString()}`);
|
|
1093
1126
|
}
|
|
1094
1127
|
/**
|
|
1095
1128
|
* @returns the TypedArray constructor for the DataType.
|
|
1096
1129
|
*/
|
|
1097
1130
|
get Array() {
|
|
1098
|
-
const e =
|
|
1131
|
+
const e = $.ARRAY_CONSTRUCTORS.get(this.toString());
|
|
1099
1132
|
if (e == null)
|
|
1100
1133
|
throw new Error(`unable to find array constructor for ${this.valueOf()}`);
|
|
1101
1134
|
return e;
|
|
@@ -1117,10 +1150,10 @@ const o = class x extends String {
|
|
|
1117
1150
|
return this.valueOf();
|
|
1118
1151
|
}
|
|
1119
1152
|
get isVariable() {
|
|
1120
|
-
return this.equals(
|
|
1153
|
+
return this.equals($.JSON) || this.equals($.STRING);
|
|
1121
1154
|
}
|
|
1122
1155
|
get isNumeric() {
|
|
1123
|
-
return !this.isVariable && !this.equals(
|
|
1156
|
+
return !this.isVariable && !this.equals($.UUID);
|
|
1124
1157
|
}
|
|
1125
1158
|
get isInteger() {
|
|
1126
1159
|
return this.toString().startsWith("int");
|
|
@@ -1129,7 +1162,7 @@ const o = class x extends String {
|
|
|
1129
1162
|
return this.toString().startsWith("float");
|
|
1130
1163
|
}
|
|
1131
1164
|
get density() {
|
|
1132
|
-
const e =
|
|
1165
|
+
const e = $.DENSITIES.get(this.toString());
|
|
1133
1166
|
if (e == null) throw new Error(`unable to find density for ${this.valueOf()}`);
|
|
1134
1167
|
return e;
|
|
1135
1168
|
}
|
|
@@ -1154,7 +1187,7 @@ const o = class x extends String {
|
|
|
1154
1187
|
return this.toString();
|
|
1155
1188
|
}
|
|
1156
1189
|
get usesBigInt() {
|
|
1157
|
-
return
|
|
1190
|
+
return $.BIG_INT_TYPES.some((e) => e.equals(this));
|
|
1158
1191
|
}
|
|
1159
1192
|
};
|
|
1160
1193
|
u(o, "UNKNOWN", new o("unknown")), /** Represents a 64-bit floating point value. */
|
|
@@ -1201,20 +1234,20 @@ u(o, "JSON", new o("json")), u(o, "ARRAY_CONSTRUCTORS", /* @__PURE__ */ new Map(
|
|
|
1201
1234
|
[Int32Array.name, o.INT32],
|
|
1202
1235
|
[BigInt64Array.name, o.INT64]
|
|
1203
1236
|
])), u(o, "DENSITIES", /* @__PURE__ */ new Map([
|
|
1204
|
-
[o.UINT8.toString(),
|
|
1205
|
-
[o.UINT16.toString(),
|
|
1206
|
-
[o.UINT32.toString(),
|
|
1207
|
-
[o.UINT64.toString(),
|
|
1208
|
-
[o.FLOAT32.toString(),
|
|
1209
|
-
[o.FLOAT64.toString(),
|
|
1210
|
-
[o.INT8.toString(),
|
|
1211
|
-
[o.INT16.toString(),
|
|
1212
|
-
[o.INT32.toString(),
|
|
1213
|
-
[o.INT64.toString(),
|
|
1214
|
-
[o.TIMESTAMP.toString(),
|
|
1215
|
-
[o.STRING.toString(),
|
|
1216
|
-
[o.JSON.toString(),
|
|
1217
|
-
[o.UUID.toString(),
|
|
1237
|
+
[o.UINT8.toString(), A.BIT8],
|
|
1238
|
+
[o.UINT16.toString(), A.BIT16],
|
|
1239
|
+
[o.UINT32.toString(), A.BIT32],
|
|
1240
|
+
[o.UINT64.toString(), A.BIT64],
|
|
1241
|
+
[o.FLOAT32.toString(), A.BIT32],
|
|
1242
|
+
[o.FLOAT64.toString(), A.BIT64],
|
|
1243
|
+
[o.INT8.toString(), A.BIT8],
|
|
1244
|
+
[o.INT16.toString(), A.BIT16],
|
|
1245
|
+
[o.INT32.toString(), A.BIT32],
|
|
1246
|
+
[o.INT64.toString(), A.BIT64],
|
|
1247
|
+
[o.TIMESTAMP.toString(), A.BIT64],
|
|
1248
|
+
[o.STRING.toString(), A.UNKNOWN],
|
|
1249
|
+
[o.JSON.toString(), A.UNKNOWN],
|
|
1250
|
+
[o.UUID.toString(), A.BIT128]
|
|
1218
1251
|
])), /** All the data types. */
|
|
1219
1252
|
u(o, "ALL", [
|
|
1220
1253
|
o.UNKNOWN,
|
|
@@ -1233,11 +1266,12 @@ u(o, "ALL", [
|
|
|
1233
1266
|
o.STRING,
|
|
1234
1267
|
o.JSON
|
|
1235
1268
|
]), u(o, "BIG_INT_TYPES", [o.INT64, o.UINT64, o.TIMESTAMP]), /** A zod schema for a DataType. */
|
|
1236
|
-
u(o, "z",
|
|
1237
|
-
|
|
1238
|
-
|
|
1269
|
+
u(o, "z", i.union([
|
|
1270
|
+
i.string().transform((r) => new o(r)),
|
|
1271
|
+
i.instanceof(o)
|
|
1239
1272
|
]));
|
|
1240
|
-
|
|
1273
|
+
let b = o;
|
|
1274
|
+
const N = class v extends Number {
|
|
1241
1275
|
constructor(e) {
|
|
1242
1276
|
super(e.valueOf());
|
|
1243
1277
|
}
|
|
@@ -1274,9 +1308,9 @@ const I = class v extends Number {
|
|
|
1274
1308
|
return this.valueOf() / v.TERABYTE.valueOf();
|
|
1275
1309
|
}
|
|
1276
1310
|
toString() {
|
|
1277
|
-
const e = this.truncate(v.TERABYTE), t = this.truncate(v.GIGABYTE), n = this.truncate(v.MEGABYTE),
|
|
1278
|
-
let
|
|
1279
|
-
return c.isZero || (
|
|
1311
|
+
const e = this.truncate(v.TERABYTE), t = this.truncate(v.GIGABYTE), n = this.truncate(v.MEGABYTE), s = this.truncate(v.KILOBYTE), a = this.truncate(v.BYTE), c = e, d = t.sub(e), f = n.sub(t), y = s.sub(n), T = a.sub(s);
|
|
1312
|
+
let l = "";
|
|
1313
|
+
return c.isZero || (l += `${c.terabytes}TB `), d.isZero || (l += `${d.gigabytes}GB `), f.isZero || (l += `${f.megabytes}MB `), y.isZero || (l += `${y.kilobytes}KB `), (!T.isZero || l === "") && (l += `${T.valueOf()}B`), l.trim();
|
|
1280
1314
|
}
|
|
1281
1315
|
/**
|
|
1282
1316
|
* Creates a Size from the given number of bytes.
|
|
@@ -1327,66 +1361,543 @@ const I = class v extends Number {
|
|
|
1327
1361
|
return this.valueOf() === 0;
|
|
1328
1362
|
}
|
|
1329
1363
|
};
|
|
1330
|
-
u(
|
|
1331
|
-
u(
|
|
1332
|
-
u(
|
|
1333
|
-
u(
|
|
1334
|
-
u(
|
|
1335
|
-
u(
|
|
1336
|
-
u(
|
|
1337
|
-
|
|
1338
|
-
|
|
1364
|
+
u(N, "BYTE", new N(1)), /** A kilobyte */
|
|
1365
|
+
u(N, "KILOBYTE", N.kilobytes(1)), /** A megabyte */
|
|
1366
|
+
u(N, "MEGABYTE", N.megabytes(1)), /** A gigabyte */
|
|
1367
|
+
u(N, "GIGABYTE", N.gigabytes(1)), /** A terabyte. */
|
|
1368
|
+
u(N, "TERABYTE", N.terabytes(1)), /** The zero value for Size */
|
|
1369
|
+
u(N, "ZERO", new N(0)), /** A zod schema for a Size. */
|
|
1370
|
+
u(N, "z", i.union([
|
|
1371
|
+
i.number().transform((r) => new N(r)),
|
|
1372
|
+
i.instanceof(N)
|
|
1339
1373
|
]));
|
|
1340
|
-
let
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1374
|
+
let Je = N;
|
|
1375
|
+
i.union([
|
|
1376
|
+
i.instanceof(Uint8Array),
|
|
1377
|
+
i.instanceof(Uint16Array),
|
|
1378
|
+
i.instanceof(Uint32Array),
|
|
1379
|
+
i.instanceof(BigUint64Array),
|
|
1380
|
+
i.instanceof(Float32Array),
|
|
1381
|
+
i.instanceof(Float64Array),
|
|
1382
|
+
i.instanceof(Int8Array),
|
|
1383
|
+
i.instanceof(Int16Array),
|
|
1384
|
+
i.instanceof(Int32Array),
|
|
1385
|
+
i.instanceof(BigInt64Array)
|
|
1352
1386
|
]);
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1387
|
+
const He = (r) => {
|
|
1388
|
+
const e = typeof r;
|
|
1389
|
+
return e === "string" || e === "number" || e === "boolean" || e === "bigint" || r instanceof O || r instanceof S || r instanceof Date;
|
|
1390
|
+
}, _t = (r, e, t, n = 0) => r.usesBigInt && !e.usesBigInt ? Number(t) - Number(n) : !r.usesBigInt && e.usesBigInt ? BigInt(t) - BigInt(n) : Z(t, -n), er = (r) => r == null ? !1 : Array.isArray(r) || r instanceof ArrayBuffer || ArrayBuffer.isView(r) && !(r instanceof DataView) || r instanceof nr ? !0 : He(r), Y = -1, tr = i.string().transform(
|
|
1391
|
+
(r) => new Uint8Array(
|
|
1392
|
+
atob(r).split("").map((e) => e.charCodeAt(0))
|
|
1393
|
+
).buffer
|
|
1394
|
+
), rr = i.union([i.null(), i.undefined()]).transform(() => new Uint8Array().buffer), z = class C {
|
|
1395
|
+
constructor(e) {
|
|
1396
|
+
u(this, "key", ""), u(this, "isSynnaxSeries", !0), u(this, "dataType"), u(this, "sampleOffset"), u(this, "gl"), u(this, "_data"), u(this, "_timeRange"), u(this, "alignment", 0n), u(this, "_cachedMin"), u(this, "_cachedMax"), u(this, "writePos", Y), u(this, "_refCount", 0), u(this, "_cachedLength"), er(e) && (e = { data: e });
|
|
1397
|
+
const {
|
|
1398
|
+
dataType: t,
|
|
1399
|
+
timeRange: n,
|
|
1400
|
+
sampleOffset: s = 0,
|
|
1401
|
+
glBufferUsage: a = "static",
|
|
1402
|
+
alignment: c = 0n,
|
|
1403
|
+
key: d = Xt()
|
|
1404
|
+
} = e, f = e.data ?? [];
|
|
1405
|
+
if (f instanceof C || typeof f == "object" && "isSynnaxSeries" in f && f.isSynnaxSeries === !0) {
|
|
1406
|
+
const l = f;
|
|
1407
|
+
this.key = l.key, this.dataType = l.dataType, this.sampleOffset = l.sampleOffset, this.gl = l.gl, this._data = l._data, this._timeRange = l._timeRange, this.alignment = l.alignment, this._cachedMin = l._cachedMin, this._cachedMax = l._cachedMax, this.writePos = l.writePos, this._refCount = l._refCount, this._cachedLength = l._cachedLength;
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
const y = He(f), T = Array.isArray(f);
|
|
1411
|
+
if (t != null) this.dataType = new b(t);
|
|
1412
|
+
else {
|
|
1413
|
+
if (f instanceof ArrayBuffer)
|
|
1414
|
+
throw new Error(
|
|
1415
|
+
"cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type."
|
|
1416
|
+
);
|
|
1417
|
+
if (T || y) {
|
|
1418
|
+
let l = f;
|
|
1419
|
+
if (!y) {
|
|
1420
|
+
if (f.length === 0)
|
|
1421
|
+
throw new Error(
|
|
1422
|
+
"cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type."
|
|
1423
|
+
);
|
|
1424
|
+
l = f[0];
|
|
1425
|
+
}
|
|
1426
|
+
if (typeof l == "string") this.dataType = b.STRING;
|
|
1427
|
+
else if (typeof l == "number") this.dataType = b.FLOAT64;
|
|
1428
|
+
else if (typeof l == "bigint") this.dataType = b.INT64;
|
|
1429
|
+
else if (typeof l == "boolean") this.dataType = b.BOOLEAN;
|
|
1430
|
+
else if (l instanceof O || l instanceof Date || l instanceof O)
|
|
1431
|
+
this.dataType = b.TIMESTAMP;
|
|
1432
|
+
else if (typeof l == "object") this.dataType = b.JSON;
|
|
1433
|
+
else
|
|
1434
|
+
throw new Error(
|
|
1435
|
+
`cannot infer data type of ${typeof l} when constructing a Series from a JS array`
|
|
1436
|
+
);
|
|
1437
|
+
} else this.dataType = new b(f);
|
|
1438
|
+
}
|
|
1439
|
+
if (!T && !y) this._data = f;
|
|
1440
|
+
else {
|
|
1441
|
+
let l = y ? [f] : f;
|
|
1442
|
+
const E = l[0];
|
|
1443
|
+
(E instanceof O || E instanceof Date || E instanceof S) && (l = l.map((R) => new O(R).valueOf())), this.dataType.equals(b.STRING) ? (this._cachedLength = l.length, this._data = new TextEncoder().encode(l.join(`
|
|
1444
|
+
`) + `
|
|
1445
|
+
`)) : this.dataType.equals(b.JSON) ? (this._cachedLength = l.length, this._data = new TextEncoder().encode(
|
|
1446
|
+
l.map((R) => _.encodeString(R)).join(`
|
|
1447
|
+
`) + `
|
|
1448
|
+
`
|
|
1449
|
+
)) : this._data = new this.dataType.Array(l).buffer;
|
|
1450
|
+
}
|
|
1451
|
+
this.key = d, this.alignment = c, this.sampleOffset = s ?? 0, this._timeRange = n, this.gl = {
|
|
1452
|
+
control: null,
|
|
1453
|
+
buffer: null,
|
|
1454
|
+
prevBuffer: 0,
|
|
1455
|
+
bufferUsage: a
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
static alloc({ capacity: e, dataType: t, ...n }) {
|
|
1459
|
+
if (e === 0)
|
|
1460
|
+
throw new Error("[Series] - cannot allocate an array of length 0");
|
|
1461
|
+
const s = new new b(t).Array(e), a = new C({
|
|
1462
|
+
data: s.buffer,
|
|
1463
|
+
dataType: t,
|
|
1464
|
+
...n
|
|
1465
|
+
});
|
|
1466
|
+
return a.writePos = 0, a;
|
|
1467
|
+
}
|
|
1468
|
+
static generateTimestamps(e, t, n) {
|
|
1469
|
+
const s = n.spanRange(t.span(e)), a = new BigInt64Array(e);
|
|
1470
|
+
for (let c = 0; c < e; c++)
|
|
1471
|
+
a[c] = BigInt(n.add(t.span(c)).valueOf());
|
|
1472
|
+
return new C({ data: a, dataType: b.TIMESTAMP, timeRange: s });
|
|
1473
|
+
}
|
|
1474
|
+
get refCount() {
|
|
1475
|
+
return this._refCount;
|
|
1476
|
+
}
|
|
1477
|
+
static fromStrings(e, t) {
|
|
1478
|
+
const n = new TextEncoder().encode(e.join(`
|
|
1479
|
+
`) + `
|
|
1480
|
+
`);
|
|
1481
|
+
return new C({ data: n, dataType: b.STRING, timeRange: t });
|
|
1482
|
+
}
|
|
1483
|
+
static fromJSON(e, t) {
|
|
1484
|
+
const n = new TextEncoder().encode(
|
|
1485
|
+
e.map((s) => _.encodeString(s)).join(`
|
|
1486
|
+
`) + `
|
|
1487
|
+
`
|
|
1488
|
+
);
|
|
1489
|
+
return new C({ data: n, dataType: b.JSON, timeRange: t });
|
|
1490
|
+
}
|
|
1491
|
+
acquire(e) {
|
|
1492
|
+
this._refCount++, e != null && this.updateGLBuffer(e);
|
|
1493
|
+
}
|
|
1494
|
+
release() {
|
|
1495
|
+
if (this._refCount--, this._refCount === 0 && this.gl.control != null)
|
|
1496
|
+
this.maybeGarbageCollectGLBuffer(this.gl.control);
|
|
1497
|
+
else if (this._refCount < 0)
|
|
1498
|
+
throw new Error("cannot release an array with a negative reference count");
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Writes the given series to this series. If the series being written exceeds the
|
|
1502
|
+
* remaining of series being written to, only the portion that fits will be written.
|
|
1503
|
+
* @param other the series to write to this series. The data type of the series written
|
|
1504
|
+
* must be the same as the data type of the series being written to.
|
|
1505
|
+
* @returns the number of samples written. If the entire series fits, this value is
|
|
1506
|
+
* equal to the length of the series being written.
|
|
1507
|
+
*/
|
|
1508
|
+
write(e) {
|
|
1509
|
+
if (!e.dataType.equals(this.dataType))
|
|
1510
|
+
throw new Error("buffer must be of the same type as this array");
|
|
1511
|
+
if (this.writePos === Y) return 0;
|
|
1512
|
+
const t = this.capacity - this.writePos, n = t < e.length ? e.slice(0, t) : e;
|
|
1513
|
+
return this.underlyingData.set(
|
|
1514
|
+
n.data,
|
|
1515
|
+
this.writePos
|
|
1516
|
+
), this.maybeRecomputeMinMax(n), this._cachedLength = void 0, this.writePos += n.length, n.length;
|
|
1517
|
+
}
|
|
1518
|
+
/** @returns the underlying buffer backing this array. */
|
|
1519
|
+
get buffer() {
|
|
1520
|
+
return this._data;
|
|
1521
|
+
}
|
|
1522
|
+
get underlyingData() {
|
|
1523
|
+
return new this.dataType.Array(this._data);
|
|
1524
|
+
}
|
|
1525
|
+
/** @returns a native typed array with the proper data type. */
|
|
1526
|
+
get data() {
|
|
1527
|
+
return this.writePos === Y ? this.underlyingData : new this.dataType.Array(this._data, 0, this.writePos);
|
|
1528
|
+
}
|
|
1529
|
+
toStrings() {
|
|
1530
|
+
if (!this.dataType.matches(b.STRING, b.UUID))
|
|
1531
|
+
throw new Error("cannot convert non-string series to strings");
|
|
1532
|
+
return new TextDecoder().decode(this.buffer).split(`
|
|
1533
|
+
`).slice(0, -1);
|
|
1534
|
+
}
|
|
1535
|
+
toUUIDs() {
|
|
1536
|
+
if (!this.dataType.equals(b.UUID))
|
|
1537
|
+
throw new Error("cannot convert non-uuid series to uuids");
|
|
1538
|
+
const e = b.UUID.density.valueOf(), t = Array(this.length);
|
|
1539
|
+
for (let n = 0; n < this.length; n++) {
|
|
1540
|
+
const s = this.buffer.slice(n * e, (n + 1) * e), a = Array.from(new Uint8Array(s), (c) => c.toString(16).padStart(2, "0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
|
|
1541
|
+
t[n] = a;
|
|
1542
|
+
}
|
|
1543
|
+
return t;
|
|
1544
|
+
}
|
|
1545
|
+
parseJSON(e) {
|
|
1546
|
+
if (!this.dataType.equals(b.JSON))
|
|
1547
|
+
throw new Error("cannot convert non-string series to strings");
|
|
1548
|
+
return new TextDecoder().decode(this.buffer).split(`
|
|
1549
|
+
`).slice(0, -1).map((t) => e.parse(_.decodeString(t)));
|
|
1550
|
+
}
|
|
1551
|
+
/** @returns the time range of this array. */
|
|
1552
|
+
get timeRange() {
|
|
1553
|
+
if (this._timeRange == null) throw new Error("time range not set on series");
|
|
1554
|
+
return this._timeRange;
|
|
1555
|
+
}
|
|
1556
|
+
/** @returns the capacity of the series in bytes. */
|
|
1557
|
+
get byteCapacity() {
|
|
1558
|
+
return new Je(this.buffer.byteLength);
|
|
1559
|
+
}
|
|
1560
|
+
/** @returns the capacity of the series in samples. */
|
|
1561
|
+
get capacity() {
|
|
1562
|
+
return this.dataType.density.length(this.byteCapacity);
|
|
1563
|
+
}
|
|
1564
|
+
/** @returns the length of the series in bytes. */
|
|
1565
|
+
get byteLength() {
|
|
1566
|
+
return this.writePos === Y ? this.byteCapacity : this.dataType.density.size(this.writePos);
|
|
1567
|
+
}
|
|
1568
|
+
/** @returns the number of samples in this array. */
|
|
1569
|
+
get length() {
|
|
1570
|
+
return this._cachedLength != null ? this._cachedLength : this.dataType.isVariable ? this.calculateCachedLength() : this.writePos === Y ? this.data.length : this.writePos;
|
|
1571
|
+
}
|
|
1572
|
+
calculateCachedLength() {
|
|
1573
|
+
if (!this.dataType.isVariable)
|
|
1574
|
+
throw new Error("cannot calculate length of a non-variable length data type");
|
|
1575
|
+
let e = 0;
|
|
1576
|
+
return this.data.forEach((t) => {
|
|
1577
|
+
t === 10 && e++;
|
|
1578
|
+
}), this._cachedLength = e, e;
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Creates a new array with a different data type.
|
|
1582
|
+
* @param target the data type to convert to.
|
|
1583
|
+
* @param sampleOffset an offset to apply to each sample. This can help with precision
|
|
1584
|
+
* issues when converting between data types.
|
|
1585
|
+
*
|
|
1586
|
+
* WARNING: This method is expensive and copies the entire underlying array. There
|
|
1587
|
+
* also may be untimely precision issues when converting between data types.
|
|
1588
|
+
*/
|
|
1589
|
+
convert(e, t = 0) {
|
|
1590
|
+
if (this.dataType.equals(e)) return this;
|
|
1591
|
+
const n = new e.Array(this.length);
|
|
1592
|
+
for (let s = 0; s < this.length; s++)
|
|
1593
|
+
n[s] = _t(this.dataType, e, this.data[s], t);
|
|
1594
|
+
return new C({
|
|
1595
|
+
data: n.buffer,
|
|
1596
|
+
dataType: e,
|
|
1597
|
+
timeRange: this._timeRange,
|
|
1598
|
+
sampleOffset: t,
|
|
1599
|
+
glBufferUsage: this.gl.bufferUsage,
|
|
1600
|
+
alignment: this.alignment
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
calcRawMax() {
|
|
1604
|
+
if (this.length === 0) return -1 / 0;
|
|
1605
|
+
if (this.dataType.equals(b.TIMESTAMP))
|
|
1606
|
+
this._cachedMax = this.data[this.data.length - 1];
|
|
1607
|
+
else if (this.dataType.usesBigInt) {
|
|
1608
|
+
const e = this.data;
|
|
1609
|
+
this._cachedMax = e.reduce((t, n) => t > n ? t : n);
|
|
1610
|
+
} else {
|
|
1611
|
+
const e = this.data;
|
|
1612
|
+
this._cachedMax = e.reduce((t, n) => t > n ? t : n);
|
|
1613
|
+
}
|
|
1614
|
+
return this._cachedMax;
|
|
1615
|
+
}
|
|
1616
|
+
/** @returns the maximum value in the array */
|
|
1617
|
+
get max() {
|
|
1618
|
+
if (this.dataType.isVariable)
|
|
1619
|
+
throw new Error("cannot calculate maximum on a variable length data type");
|
|
1620
|
+
return this.writePos === 0 ? -1 / 0 : (this._cachedMax == null && (this._cachedMax = this.calcRawMax()), Z(this._cachedMax, this.sampleOffset));
|
|
1621
|
+
}
|
|
1622
|
+
calcRawMin() {
|
|
1623
|
+
if (this.length === 0) return 1 / 0;
|
|
1624
|
+
if (this.dataType.equals(b.TIMESTAMP))
|
|
1625
|
+
this._cachedMin = this.data[0];
|
|
1626
|
+
else if (this.dataType.usesBigInt) {
|
|
1627
|
+
const e = this.data;
|
|
1628
|
+
this._cachedMin = e.reduce((t, n) => t < n ? t : n);
|
|
1629
|
+
} else {
|
|
1630
|
+
const e = this.data;
|
|
1631
|
+
this._cachedMin = e.reduce((t, n) => t < n ? t : n);
|
|
1632
|
+
}
|
|
1633
|
+
return this._cachedMin;
|
|
1634
|
+
}
|
|
1635
|
+
/** @returns the minimum value in the array */
|
|
1636
|
+
get min() {
|
|
1637
|
+
if (this.dataType.isVariable)
|
|
1638
|
+
throw new Error("cannot calculate minimum on a variable length data type");
|
|
1639
|
+
return this.writePos === 0 ? 1 / 0 : (this._cachedMin == null && (this._cachedMin = this.calcRawMin()), Z(this._cachedMin, this.sampleOffset));
|
|
1640
|
+
}
|
|
1641
|
+
/** @returns the bounds of this array. */
|
|
1642
|
+
get bounds() {
|
|
1643
|
+
return K(Number(this.min), Number(this.max));
|
|
1644
|
+
}
|
|
1645
|
+
maybeRecomputeMinMax(e) {
|
|
1646
|
+
if (this._cachedMin != null) {
|
|
1647
|
+
const t = e._cachedMin ?? e.calcRawMin();
|
|
1648
|
+
t < this._cachedMin && (this._cachedMin = t);
|
|
1649
|
+
}
|
|
1650
|
+
if (this._cachedMax != null) {
|
|
1651
|
+
const t = e._cachedMax ?? e.calcRawMax();
|
|
1652
|
+
t > this._cachedMax && (this._cachedMax = t);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
enrich() {
|
|
1656
|
+
this.max, this.min;
|
|
1657
|
+
}
|
|
1658
|
+
get range() {
|
|
1659
|
+
return Z(this.max, -this.min);
|
|
1660
|
+
}
|
|
1661
|
+
at(e, t) {
|
|
1662
|
+
if (this.dataType.isVariable) return this.atVariable(e, t ?? !1);
|
|
1663
|
+
e < 0 && (e = this.length + e);
|
|
1664
|
+
const n = this.data[e];
|
|
1665
|
+
if (n == null) {
|
|
1666
|
+
if (t === !0) throw new Error(`[series] - no value at index ${e}`);
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
return Z(n, this.sampleOffset);
|
|
1670
|
+
}
|
|
1671
|
+
atVariable(e, t) {
|
|
1672
|
+
e < 0 && (e = this.length + e);
|
|
1673
|
+
let n = 0, s = 0;
|
|
1674
|
+
for (let c = 0; c < this.data.length; c++)
|
|
1675
|
+
if (this.data[c] === 10) {
|
|
1676
|
+
if (e === 0) {
|
|
1677
|
+
s = c;
|
|
1678
|
+
break;
|
|
1679
|
+
}
|
|
1680
|
+
n = c + 1, e--;
|
|
1681
|
+
}
|
|
1682
|
+
if (s === 0 && (s = this.data.length), n >= s || e > 0) {
|
|
1683
|
+
if (t) throw new Error(`[series] - no value at index ${e}`);
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
const a = this.data.slice(n, s);
|
|
1687
|
+
return this.dataType.equals(b.STRING) ? new TextDecoder().decode(a) : Ye(
|
|
1688
|
+
JSON.parse(new TextDecoder().decode(a))
|
|
1689
|
+
);
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* @returns the index of the first sample that is greater than or equal to the given value.
|
|
1693
|
+
* The underlying array must be sorted. If it is not, the behavior of this method is undefined.
|
|
1694
|
+
* @param value the value to search for.
|
|
1695
|
+
*/
|
|
1696
|
+
binarySearch(e) {
|
|
1697
|
+
let t = 0, n = this.length - 1;
|
|
1698
|
+
const s = qt(e);
|
|
1699
|
+
for (; t <= n; ) {
|
|
1700
|
+
const a = Math.floor((t + n) / 2), c = s(this.at(a, !0), e);
|
|
1701
|
+
if (c === 0) return a;
|
|
1702
|
+
c < 0 ? t = a + 1 : n = a - 1;
|
|
1703
|
+
}
|
|
1704
|
+
return t;
|
|
1705
|
+
}
|
|
1706
|
+
updateGLBuffer(e) {
|
|
1707
|
+
if (this.gl.control = e, !this.dataType.equals(b.FLOAT32))
|
|
1708
|
+
throw new Error("Only FLOAT32 arrays can be used in WebGL");
|
|
1709
|
+
const { buffer: t, bufferUsage: n, prevBuffer: s } = this.gl;
|
|
1710
|
+
if (t == null && (this.gl.buffer = e.createBuffer()), this.writePos !== s)
|
|
1711
|
+
if (e.bindBuffer(e.ARRAY_BUFFER, this.gl.buffer), this.writePos !== Y) {
|
|
1712
|
+
s === 0 && e.bufferData(e.ARRAY_BUFFER, this.byteCapacity.valueOf(), e.STATIC_DRAW);
|
|
1713
|
+
const a = this.dataType.density.size(s).valueOf(), c = this.underlyingData.slice(this.gl.prevBuffer, this.writePos);
|
|
1714
|
+
e.bufferSubData(e.ARRAY_BUFFER, a, c.buffer), this.gl.prevBuffer = this.writePos;
|
|
1715
|
+
} else
|
|
1716
|
+
e.bufferData(
|
|
1717
|
+
e.ARRAY_BUFFER,
|
|
1718
|
+
this.buffer,
|
|
1719
|
+
n === "static" ? e.STATIC_DRAW : e.DYNAMIC_DRAW
|
|
1720
|
+
), this.gl.prevBuffer = Y;
|
|
1721
|
+
}
|
|
1722
|
+
as(e) {
|
|
1723
|
+
if (e === "string") {
|
|
1724
|
+
if (!this.dataType.equals(b.STRING))
|
|
1725
|
+
throw new Error(
|
|
1726
|
+
`cannot convert series of type ${this.dataType.toString()} to string`
|
|
1727
|
+
);
|
|
1728
|
+
return this;
|
|
1729
|
+
}
|
|
1730
|
+
if (e === "number") {
|
|
1731
|
+
if (!this.dataType.isNumeric)
|
|
1732
|
+
throw new Error(
|
|
1733
|
+
`cannot convert series of type ${this.dataType.toString()} to number`
|
|
1734
|
+
);
|
|
1735
|
+
return this;
|
|
1736
|
+
}
|
|
1737
|
+
if (e === "bigint") {
|
|
1738
|
+
if (!this.dataType.equals(b.INT64))
|
|
1739
|
+
throw new Error(
|
|
1740
|
+
`cannot convert series of type ${this.dataType.toString()} to bigint`
|
|
1741
|
+
);
|
|
1742
|
+
return this;
|
|
1743
|
+
}
|
|
1744
|
+
throw new Error(`cannot convert series to ${e}`);
|
|
1745
|
+
}
|
|
1746
|
+
get digest() {
|
|
1747
|
+
var e;
|
|
1748
|
+
return {
|
|
1749
|
+
key: this.key,
|
|
1750
|
+
dataType: this.dataType.toString(),
|
|
1751
|
+
sampleOffset: this.sampleOffset,
|
|
1752
|
+
alignment: this.alignmentBounds,
|
|
1753
|
+
timeRange: (e = this._timeRange) == null ? void 0 : e.toString(),
|
|
1754
|
+
length: this.length,
|
|
1755
|
+
capacity: this.capacity
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
get memInfo() {
|
|
1759
|
+
return {
|
|
1760
|
+
key: this.key,
|
|
1761
|
+
length: this.length,
|
|
1762
|
+
byteLength: this.byteLength,
|
|
1763
|
+
glBuffer: this.gl.buffer != null
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1766
|
+
get alignmentBounds() {
|
|
1767
|
+
return K(this.alignment, this.alignment + BigInt(this.length));
|
|
1768
|
+
}
|
|
1769
|
+
maybeGarbageCollectGLBuffer(e) {
|
|
1770
|
+
this.gl.buffer != null && (e.deleteBuffer(this.gl.buffer), this.gl.buffer = null, this.gl.prevBuffer = 0, this.gl.control = null);
|
|
1771
|
+
}
|
|
1772
|
+
get glBuffer() {
|
|
1773
|
+
if (this.gl.buffer == null) throw new Error("gl buffer not initialized");
|
|
1774
|
+
return this.gl.prevBuffer !== this.writePos && console.warn("buffer not updated"), this.gl.buffer;
|
|
1775
|
+
}
|
|
1776
|
+
[Symbol.iterator]() {
|
|
1777
|
+
if (this.dataType.isVariable) {
|
|
1778
|
+
const e = new sr(this);
|
|
1779
|
+
return this.dataType.equals(b.JSON) ? new ir(e) : e;
|
|
1780
|
+
}
|
|
1781
|
+
return new ar(this);
|
|
1782
|
+
}
|
|
1783
|
+
slice(e, t) {
|
|
1784
|
+
if (e <= 0 && (t == null || t >= this.length)) return this;
|
|
1785
|
+
const n = this.data.slice(e, t);
|
|
1786
|
+
return new C({
|
|
1787
|
+
data: n,
|
|
1788
|
+
dataType: this.dataType,
|
|
1789
|
+
timeRange: this._timeRange,
|
|
1790
|
+
sampleOffset: this.sampleOffset,
|
|
1791
|
+
glBufferUsage: this.gl.bufferUsage,
|
|
1792
|
+
alignment: this.alignment + BigInt(e)
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
reAlign(e) {
|
|
1796
|
+
return new C({
|
|
1797
|
+
data: this.buffer,
|
|
1798
|
+
dataType: this.dataType,
|
|
1799
|
+
timeRange: me.ZERO,
|
|
1800
|
+
sampleOffset: this.sampleOffset,
|
|
1801
|
+
glBufferUsage: "static",
|
|
1802
|
+
alignment: e
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
u(z, "crudeZ", i.object({
|
|
1807
|
+
timeRange: me.z.optional(),
|
|
1808
|
+
dataType: b.z,
|
|
1809
|
+
alignment: Zt.optional(),
|
|
1810
|
+
data: i.union([tr, rr, i.instanceof(ArrayBuffer)]),
|
|
1811
|
+
glBufferUsage: Qt.optional().default("static").optional()
|
|
1812
|
+
})), u(z, "z", z.crudeZ.transform((r) => new z(r)));
|
|
1813
|
+
let nr = z;
|
|
1814
|
+
class sr {
|
|
1815
|
+
constructor(e) {
|
|
1816
|
+
if (u(this, "series"), u(this, "index"), u(this, "decoder"), !e.dataType.isVariable)
|
|
1817
|
+
throw new Error(
|
|
1818
|
+
"cannot create a variable series iterator for a non-variable series"
|
|
1819
|
+
);
|
|
1820
|
+
this.series = e, this.index = 0, this.decoder = new TextDecoder();
|
|
1821
|
+
}
|
|
1822
|
+
next() {
|
|
1823
|
+
const e = this.index, t = this.series.data;
|
|
1824
|
+
for (; this.index < t.length && t[this.index] !== 10; ) this.index++;
|
|
1825
|
+
const n = this.index;
|
|
1826
|
+
return e === n ? { done: !0, value: void 0 } : (this.index++, { done: !1, value: this.decoder.decode(this.series.buffer.slice(e, n)) });
|
|
1827
|
+
}
|
|
1828
|
+
[Symbol.iterator]() {
|
|
1829
|
+
return this;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
var xe, Me;
|
|
1833
|
+
class ir {
|
|
1834
|
+
constructor(e) {
|
|
1835
|
+
u(this, "wrapped"), u(this, xe, "JSONSeriesIterator"), this.wrapped = e;
|
|
1836
|
+
}
|
|
1837
|
+
next() {
|
|
1838
|
+
const e = this.wrapped.next();
|
|
1839
|
+
return e.done === !0 ? { done: !0, value: void 0 } : {
|
|
1840
|
+
done: !1,
|
|
1841
|
+
value: _.decodeString(e.value)
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
[(Me = Symbol.iterator, xe = Symbol.toStringTag, Me)]() {
|
|
1845
|
+
return this;
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
var $e, Re;
|
|
1849
|
+
class ar {
|
|
1850
|
+
constructor(e) {
|
|
1851
|
+
u(this, "series"), u(this, "index"), u(this, $e, "SeriesIterator"), this.series = e, this.index = 0;
|
|
1852
|
+
}
|
|
1853
|
+
next() {
|
|
1854
|
+
return this.index >= this.series.length ? { done: !0, value: void 0 } : {
|
|
1855
|
+
done: !1,
|
|
1856
|
+
value: this.series.at(this.index++, !0)
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
[(Re = Symbol.iterator, $e = Symbol.toStringTag, Re)]() {
|
|
1860
|
+
return this;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
const Z = (r, e) => typeof r == "bigint" && typeof e == "bigint" || typeof r == "number" && typeof e == "number" ? r + e : e === 0 ? r : r === 0 ? e : Number(r) + Number(e);
|
|
1864
|
+
i.object({
|
|
1865
|
+
key: i.string(),
|
|
1866
|
+
value: i.string()
|
|
1356
1867
|
});
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1868
|
+
i.record(
|
|
1869
|
+
i.union([i.number(), i.string(), i.symbol()]),
|
|
1870
|
+
i.unknown()
|
|
1360
1871
|
);
|
|
1361
|
-
const
|
|
1362
|
-
let
|
|
1363
|
-
const
|
|
1872
|
+
const Ke = () => typeof process < "u" && process.versions != null && process.versions.node != null ? "node" : typeof window > "u" || window.document === void 0 ? "webworker" : "browser", or = Ke(), Xe = ["MacOS", "Windows", "Linux", "Docker"], ur = i.enum(Xe);
|
|
1873
|
+
let he;
|
|
1874
|
+
const cr = () => {
|
|
1364
1875
|
if (typeof window > "u") return;
|
|
1365
1876
|
const r = window.navigator.userAgent.toLowerCase();
|
|
1366
1877
|
if (r.includes("mac")) return "MacOS";
|
|
1367
1878
|
if (r.includes("win")) return "Windows";
|
|
1368
1879
|
if (r.includes("linux")) return "Linux";
|
|
1369
|
-
},
|
|
1880
|
+
}, lr = (r = {}) => {
|
|
1370
1881
|
const { force: e, default: t } = r;
|
|
1371
|
-
return e ??
|
|
1372
|
-
},
|
|
1882
|
+
return e ?? he ?? (he = cr(), he ?? t);
|
|
1883
|
+
}, Qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1373
1884
|
__proto__: null,
|
|
1374
|
-
OPERATING_SYSTEMS:
|
|
1375
|
-
RUNTIME:
|
|
1376
|
-
detect:
|
|
1377
|
-
getOS:
|
|
1378
|
-
osZ:
|
|
1885
|
+
OPERATING_SYSTEMS: Xe,
|
|
1886
|
+
RUNTIME: or,
|
|
1887
|
+
detect: Ke,
|
|
1888
|
+
getOS: lr,
|
|
1889
|
+
osZ: ur
|
|
1379
1890
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1380
|
-
var
|
|
1381
|
-
const
|
|
1891
|
+
var hr = Object.defineProperty, dr = (r, e, t) => e in r ? hr(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, V = (r, e, t) => dr(r, typeof e != "symbol" ? e + "" : e, t);
|
|
1892
|
+
const fr = (...r) => r.map(_e).join(""), _e = (r) => (r.endsWith("/") || (r += "/"), r.startsWith("/") && (r = r.slice(1)), r), gr = (r) => r.endsWith("/") ? r.slice(0, -1) : r, pr = (r, e = "") => r === null ? "" : "?" + Object.entries(r).filter(([, t]) => t == null ? !1 : Array.isArray(t) ? t.length > 0 : !0).map(([t, n]) => `${e}${t}=${n}`).join("&"), ge = class pe {
|
|
1382
1893
|
/**
|
|
1383
1894
|
* @param host - The hostname or IP address of the server.
|
|
1384
1895
|
* @param port - The port number of the server.
|
|
1385
1896
|
* @param protocol - The protocol to use for all requests. Defaults to "".
|
|
1386
1897
|
* @param pathPrefix - A path prefix to use for all requests. Defaults to "".
|
|
1387
1898
|
*/
|
|
1388
|
-
constructor({ host: e, port: t, protocol: n = "", pathPrefix:
|
|
1389
|
-
|
|
1899
|
+
constructor({ host: e, port: t, protocol: n = "", pathPrefix: s = "" }) {
|
|
1900
|
+
V(this, "protocol"), V(this, "host"), V(this, "port"), V(this, "path"), this.protocol = n, this.host = e, this.port = t, this.path = _e(s);
|
|
1390
1901
|
}
|
|
1391
1902
|
/**
|
|
1392
1903
|
* Replaces creates a new URL with the specified properties replaced.
|
|
@@ -1394,7 +1905,7 @@ const kt = (...r) => r.map(je).join(""), je = (r) => (r.endsWith("/") || (r += "
|
|
|
1394
1905
|
* @returns a new URL.
|
|
1395
1906
|
*/
|
|
1396
1907
|
replace(e) {
|
|
1397
|
-
return new
|
|
1908
|
+
return new pe({
|
|
1398
1909
|
host: e.host ?? this.host,
|
|
1399
1910
|
port: e.port ?? this.port,
|
|
1400
1911
|
protocol: e.protocol ?? this.protocol,
|
|
@@ -1407,54 +1918,54 @@ const kt = (...r) => r.map(je).join(""), je = (r) => (r.endsWith("/") || (r += "
|
|
|
1407
1918
|
* @returns a new URL.
|
|
1408
1919
|
*/
|
|
1409
1920
|
child(e) {
|
|
1410
|
-
return new
|
|
1921
|
+
return new pe({
|
|
1411
1922
|
...this,
|
|
1412
|
-
pathPrefix:
|
|
1923
|
+
pathPrefix: fr(this.path, e)
|
|
1413
1924
|
});
|
|
1414
1925
|
}
|
|
1415
1926
|
/** @returns a string representation of the url */
|
|
1416
1927
|
toString() {
|
|
1417
|
-
return
|
|
1928
|
+
return gr(
|
|
1418
1929
|
`${this.protocol}://${this.host}:${this.port}/${this.path}`
|
|
1419
1930
|
);
|
|
1420
1931
|
}
|
|
1421
1932
|
};
|
|
1422
|
-
|
|
1423
|
-
let
|
|
1424
|
-
var
|
|
1425
|
-
const
|
|
1933
|
+
V(ge, "UNKNOWN", new ge({ host: "unknown", port: 0 }));
|
|
1934
|
+
let yr = ge;
|
|
1935
|
+
var mr = Object.defineProperty, wr = (r, e, t) => e in r ? mr(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, re = (r, e, t) => wr(r, typeof e != "symbol" ? e + "" : e, t);
|
|
1936
|
+
const j = class extends Number {
|
|
1426
1937
|
};
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1938
|
+
re(j, "Absolute", 255), re(j, "Default", 1), re(j, "z", i.union([
|
|
1939
|
+
i.instanceof(j),
|
|
1940
|
+
i.number().int().min(0).max(255).transform((r) => new j(r)),
|
|
1941
|
+
i.instanceof(Number).transform((r) => new j(r))
|
|
1431
1942
|
]));
|
|
1432
|
-
|
|
1433
|
-
name:
|
|
1434
|
-
key:
|
|
1943
|
+
i.object({
|
|
1944
|
+
name: i.string(),
|
|
1945
|
+
key: i.string()
|
|
1435
1946
|
});
|
|
1436
|
-
const
|
|
1947
|
+
const et = class J extends Error {
|
|
1437
1948
|
constructor() {
|
|
1438
|
-
super(
|
|
1949
|
+
super(J.MESSAGE);
|
|
1439
1950
|
}
|
|
1440
1951
|
/** Returns true if the error or message is a cancellation error" */
|
|
1441
1952
|
matches(e) {
|
|
1442
|
-
return typeof e == "string" ? e.includes(
|
|
1953
|
+
return typeof e == "string" ? e.includes(J.MESSAGE) : e instanceof J || e.message.includes(J.MESSAGE);
|
|
1443
1954
|
}
|
|
1444
1955
|
};
|
|
1445
|
-
|
|
1446
|
-
let
|
|
1447
|
-
new
|
|
1448
|
-
|
|
1449
|
-
const
|
|
1450
|
-
class
|
|
1956
|
+
re(et, "MESSAGE", "canceled");
|
|
1957
|
+
let br = et;
|
|
1958
|
+
new br();
|
|
1959
|
+
i.string().regex(/^\d+\.\d+\.\d+$/);
|
|
1960
|
+
const we = (r) => (e) => e != null && typeof e == "object" && "type" in e && typeof e.type == "string" ? e.type.includes(r) : e instanceof Error ? e.message.includes(r) : typeof e != "string" ? !1 : e.includes(r);
|
|
1961
|
+
class ae extends Error {
|
|
1451
1962
|
constructor(t) {
|
|
1452
1963
|
super(t);
|
|
1453
|
-
|
|
1454
|
-
|
|
1964
|
+
p(this, "discriminator", "FreighterError");
|
|
1965
|
+
p(this, "type", "");
|
|
1455
1966
|
}
|
|
1456
1967
|
}
|
|
1457
|
-
const
|
|
1968
|
+
const Tr = (r) => {
|
|
1458
1969
|
if (r == null || typeof r != "object") return !1;
|
|
1459
1970
|
const e = r;
|
|
1460
1971
|
if (e.discriminator !== "FreighterError") return !1;
|
|
@@ -1463,98 +1974,98 @@ const Vt = (r) => {
|
|
|
1463
1974
|
`Freighter error is missing its type property: ${JSON.stringify(e)}`
|
|
1464
1975
|
);
|
|
1465
1976
|
return !0;
|
|
1466
|
-
},
|
|
1467
|
-
class
|
|
1977
|
+
}, Be = "unknown", Ue = "nil", Or = "freighter", tt = i.object({ type: i.string(), data: i.string() });
|
|
1978
|
+
class vr {
|
|
1468
1979
|
constructor() {
|
|
1469
|
-
|
|
1980
|
+
p(this, "providers", []);
|
|
1470
1981
|
}
|
|
1471
1982
|
register(e) {
|
|
1472
1983
|
this.providers.push(e);
|
|
1473
1984
|
}
|
|
1474
1985
|
encode(e) {
|
|
1475
|
-
if (e == null) return { type:
|
|
1476
|
-
if (
|
|
1986
|
+
if (e == null) return { type: Ue, data: "" };
|
|
1987
|
+
if (Tr(e))
|
|
1477
1988
|
for (const t of this.providers) {
|
|
1478
1989
|
const n = t.encode(e);
|
|
1479
1990
|
if (n != null) return n;
|
|
1480
1991
|
}
|
|
1481
|
-
return { type:
|
|
1992
|
+
return { type: Be, data: JSON.stringify(e) };
|
|
1482
1993
|
}
|
|
1483
1994
|
decode(e) {
|
|
1484
|
-
if (e == null || e.type ===
|
|
1485
|
-
if (e.type ===
|
|
1995
|
+
if (e == null || e.type === Ue) return null;
|
|
1996
|
+
if (e.type === Be) return new Ce(e.data);
|
|
1486
1997
|
for (const t of this.providers) {
|
|
1487
1998
|
const n = t.decode(e);
|
|
1488
1999
|
if (n != null) return n;
|
|
1489
2000
|
}
|
|
1490
|
-
return new
|
|
2001
|
+
return new Ce(e.data);
|
|
1491
2002
|
}
|
|
1492
2003
|
}
|
|
1493
|
-
const
|
|
2004
|
+
const be = new vr(), Sr = ({
|
|
1494
2005
|
encode: r,
|
|
1495
2006
|
decode: e
|
|
1496
|
-
}) =>
|
|
1497
|
-
class
|
|
2007
|
+
}) => be.register({ encode: r, decode: e }), Fr = (r) => be.encode(r), rt = (r) => be.decode(r);
|
|
2008
|
+
class Ce extends ae {
|
|
1498
2009
|
constructor(t) {
|
|
1499
2010
|
super(t);
|
|
1500
|
-
|
|
2011
|
+
p(this, "type", "unknown");
|
|
1501
2012
|
}
|
|
1502
2013
|
}
|
|
1503
|
-
const
|
|
2014
|
+
const oe = "freighter.", F = class F extends ae {
|
|
1504
2015
|
constructor() {
|
|
1505
2016
|
super("EOF");
|
|
1506
|
-
|
|
2017
|
+
p(this, "type", F.TYPE);
|
|
1507
2018
|
}
|
|
1508
2019
|
};
|
|
1509
|
-
|
|
1510
|
-
let
|
|
1511
|
-
const
|
|
2020
|
+
p(F, "TYPE", oe + "eof"), p(F, "matches", we(F.TYPE));
|
|
2021
|
+
let P = F;
|
|
2022
|
+
const G = class G extends ae {
|
|
1512
2023
|
constructor() {
|
|
1513
2024
|
super("StreamClosed");
|
|
1514
|
-
|
|
2025
|
+
p(this, "type", G.TYPE);
|
|
1515
2026
|
}
|
|
1516
2027
|
};
|
|
1517
|
-
|
|
1518
|
-
let
|
|
1519
|
-
const
|
|
2028
|
+
p(G, "TYPE", oe + "stream_closed"), p(G, "matches", we(G.TYPE));
|
|
2029
|
+
let L = G;
|
|
2030
|
+
const q = class q extends ae {
|
|
1520
2031
|
constructor(t = {}) {
|
|
1521
|
-
const { message: n = "Unreachable", url:
|
|
2032
|
+
const { message: n = "Unreachable", url: s = yr.UNKNOWN } = t;
|
|
1522
2033
|
super(n);
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
this.url =
|
|
2034
|
+
p(this, "type", q.TYPE);
|
|
2035
|
+
p(this, "url");
|
|
2036
|
+
this.url = s;
|
|
1526
2037
|
}
|
|
1527
2038
|
};
|
|
1528
|
-
|
|
1529
|
-
let
|
|
1530
|
-
const
|
|
1531
|
-
if (!r.type.startsWith(
|
|
1532
|
-
if (
|
|
1533
|
-
if (
|
|
1534
|
-
return { type:
|
|
1535
|
-
if (
|
|
1536
|
-
return { type:
|
|
2039
|
+
p(q, "TYPE", oe + "unreachable"), p(q, "matches", we(q.TYPE));
|
|
2040
|
+
let k = q;
|
|
2041
|
+
const Ir = (r) => {
|
|
2042
|
+
if (!r.type.startsWith(Or)) return null;
|
|
2043
|
+
if (P.matches(r)) return { type: P.TYPE, data: "EOF" };
|
|
2044
|
+
if (L.matches(r))
|
|
2045
|
+
return { type: L.TYPE, data: "StreamClosed" };
|
|
2046
|
+
if (k.matches(r))
|
|
2047
|
+
return { type: k.TYPE, data: "Unreachable" };
|
|
1537
2048
|
throw new Error(`Unknown error type: ${r.type}: ${r.message}`);
|
|
1538
|
-
},
|
|
1539
|
-
if (!r.type.startsWith(
|
|
2049
|
+
}, Nr = (r) => {
|
|
2050
|
+
if (!r.type.startsWith(oe)) return null;
|
|
1540
2051
|
switch (r.type) {
|
|
1541
|
-
case
|
|
1542
|
-
return new
|
|
1543
|
-
case
|
|
1544
|
-
return new
|
|
1545
|
-
case
|
|
1546
|
-
return new
|
|
2052
|
+
case P.TYPE:
|
|
2053
|
+
return new P();
|
|
2054
|
+
case L.TYPE:
|
|
2055
|
+
return new L();
|
|
2056
|
+
case k.TYPE:
|
|
2057
|
+
return new k();
|
|
1547
2058
|
default:
|
|
1548
2059
|
throw new Error(`Unknown error type: ${r.data}`);
|
|
1549
2060
|
}
|
|
1550
2061
|
};
|
|
1551
|
-
|
|
1552
|
-
encode:
|
|
1553
|
-
decode:
|
|
2062
|
+
Sr({
|
|
2063
|
+
encode: Ir,
|
|
2064
|
+
decode: Nr
|
|
1554
2065
|
});
|
|
1555
|
-
class
|
|
2066
|
+
class nt {
|
|
1556
2067
|
constructor() {
|
|
1557
|
-
|
|
2068
|
+
p(this, "middleware", []);
|
|
1558
2069
|
}
|
|
1559
2070
|
/** Implements the Transport interface */
|
|
1560
2071
|
use(...e) {
|
|
@@ -1571,106 +2082,106 @@ class Ge {
|
|
|
1571
2082
|
*/
|
|
1572
2083
|
async executeMiddleware(e, t) {
|
|
1573
2084
|
let n = 0;
|
|
1574
|
-
const
|
|
2085
|
+
const s = async (a) => {
|
|
1575
2086
|
if (n === this.middleware.length) return await t(a);
|
|
1576
2087
|
const c = this.middleware[n];
|
|
1577
|
-
return n++, await c(a,
|
|
2088
|
+
return n++, await c(a, s);
|
|
1578
2089
|
};
|
|
1579
|
-
return await
|
|
2090
|
+
return await s(e);
|
|
1580
2091
|
}
|
|
1581
2092
|
}
|
|
1582
|
-
const
|
|
1583
|
-
if (
|
|
2093
|
+
const st = "Content-Type", De = (r) => {
|
|
2094
|
+
if (Qe.RUNTIME !== "node") return fetch;
|
|
1584
2095
|
const e = require("node-fetch");
|
|
1585
2096
|
if (r === "http") return e;
|
|
1586
2097
|
const t = require("https"), n = new t.Agent({ rejectUnauthorized: !1 });
|
|
1587
|
-
return async (
|
|
2098
|
+
return async (s, a) => await e(s, { ...a, agent: n });
|
|
1588
2099
|
};
|
|
1589
|
-
class
|
|
1590
|
-
constructor(t, n,
|
|
2100
|
+
class Gr extends nt {
|
|
2101
|
+
constructor(t, n, s = !1) {
|
|
1591
2102
|
super();
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
return this.endpoint = t.replace({ protocol:
|
|
1596
|
-
get: (a, c,
|
|
2103
|
+
p(this, "endpoint");
|
|
2104
|
+
p(this, "encoder");
|
|
2105
|
+
p(this, "fetch");
|
|
2106
|
+
return this.endpoint = t.replace({ protocol: s ? "https" : "http" }), this.encoder = n, this.fetch = De(this.endpoint.protocol), new Proxy(this, {
|
|
2107
|
+
get: (a, c, d) => c === "endpoint" ? this.endpoint : Reflect.get(a, c, d)
|
|
1597
2108
|
});
|
|
1598
2109
|
}
|
|
1599
2110
|
get headers() {
|
|
1600
2111
|
return {
|
|
1601
|
-
[
|
|
2112
|
+
[st]: this.encoder.contentType
|
|
1602
2113
|
};
|
|
1603
2114
|
}
|
|
1604
|
-
async send(t, n,
|
|
1605
|
-
n =
|
|
2115
|
+
async send(t, n, s, a) {
|
|
2116
|
+
n = s == null ? void 0 : s.parse(n);
|
|
1606
2117
|
let c = null;
|
|
1607
|
-
const
|
|
1608
|
-
|
|
1609
|
-
const [,
|
|
2118
|
+
const d = this.endpoint.child(t), f = {};
|
|
2119
|
+
f.method = "POST", f.body = this.encoder.encode(n ?? {});
|
|
2120
|
+
const [, y] = await this.executeMiddleware(
|
|
1610
2121
|
{
|
|
1611
|
-
target:
|
|
2122
|
+
target: d.toString(),
|
|
1612
2123
|
protocol: this.endpoint.protocol,
|
|
1613
2124
|
params: {},
|
|
1614
2125
|
role: "client"
|
|
1615
2126
|
},
|
|
1616
|
-
async (
|
|
1617
|
-
const
|
|
1618
|
-
|
|
2127
|
+
async (T) => {
|
|
2128
|
+
const l = { ...T, params: {} };
|
|
2129
|
+
f.headers = {
|
|
1619
2130
|
...this.headers,
|
|
1620
|
-
...
|
|
2131
|
+
...T.params
|
|
1621
2132
|
};
|
|
1622
|
-
let
|
|
2133
|
+
let E;
|
|
1623
2134
|
try {
|
|
1624
|
-
|
|
1625
|
-
} catch (
|
|
1626
|
-
let
|
|
1627
|
-
return
|
|
2135
|
+
E = await De(T.protocol)(T.target, f);
|
|
2136
|
+
} catch (B) {
|
|
2137
|
+
let x = B;
|
|
2138
|
+
return x.message === "Load failed" && (x = new k({ url: d })), [l, x];
|
|
1628
2139
|
}
|
|
1629
|
-
const
|
|
1630
|
-
if (
|
|
1631
|
-
return a != null && (c = this.encoder.decode(
|
|
2140
|
+
const R = await E.arrayBuffer();
|
|
2141
|
+
if (E != null && E.ok)
|
|
2142
|
+
return a != null && (c = this.encoder.decode(R, a)), [l, null];
|
|
1632
2143
|
try {
|
|
1633
|
-
if (
|
|
1634
|
-
const
|
|
1635
|
-
return [
|
|
1636
|
-
} catch (
|
|
2144
|
+
if (E.status !== 400) return [l, new Error(E.statusText)];
|
|
2145
|
+
const B = this.encoder.decode(R, tt), x = rt(B);
|
|
2146
|
+
return [l, x];
|
|
2147
|
+
} catch (B) {
|
|
1637
2148
|
return [
|
|
1638
|
-
|
|
2149
|
+
l,
|
|
1639
2150
|
new Error(
|
|
1640
|
-
`[freighter] - failed to decode error: ${
|
|
2151
|
+
`[freighter] - failed to decode error: ${E.statusText}: ${B.message}`
|
|
1641
2152
|
)
|
|
1642
2153
|
];
|
|
1643
2154
|
}
|
|
1644
2155
|
}
|
|
1645
2156
|
);
|
|
1646
|
-
return [c,
|
|
2157
|
+
return [c, y];
|
|
1647
2158
|
}
|
|
1648
2159
|
}
|
|
1649
|
-
const
|
|
1650
|
-
const [a, c] = await r.send(e, t, n,
|
|
2160
|
+
const qr = async (r, e, t, n, s) => {
|
|
2161
|
+
const [a, c] = await r.send(e, t, n, s);
|
|
1651
2162
|
if (c != null) throw c;
|
|
1652
2163
|
return a;
|
|
1653
|
-
},
|
|
1654
|
-
type:
|
|
1655
|
-
payload:
|
|
1656
|
-
error:
|
|
2164
|
+
}, Er = () => Qe.RUNTIME !== "node" ? (r) => new WebSocket(r) : (r) => new (require("ws")).WebSocket(r, { rejectUnauthorized: !1 }), Ar = i.object({
|
|
2165
|
+
type: i.union([i.literal("data"), i.literal("close")]),
|
|
2166
|
+
payload: i.unknown().optional(),
|
|
2167
|
+
error: i.optional(tt)
|
|
1657
2168
|
});
|
|
1658
|
-
class
|
|
1659
|
-
constructor(e, t, n,
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
this.encoder = t, this.reqSchema = n, this.resSchema =
|
|
2169
|
+
class xr {
|
|
2170
|
+
constructor(e, t, n, s) {
|
|
2171
|
+
p(this, "encoder");
|
|
2172
|
+
p(this, "reqSchema");
|
|
2173
|
+
p(this, "resSchema");
|
|
2174
|
+
p(this, "ws");
|
|
2175
|
+
p(this, "serverClosed");
|
|
2176
|
+
p(this, "sendClosed");
|
|
2177
|
+
p(this, "receiveDataQueue", []);
|
|
2178
|
+
p(this, "receiveCallbacksQueue", []);
|
|
2179
|
+
this.encoder = t, this.reqSchema = n, this.resSchema = s, this.ws = e, this.sendClosed = !1, this.serverClosed = null, this.listenForMessages();
|
|
1669
2180
|
}
|
|
1670
2181
|
/** Implements the Stream protocol */
|
|
1671
2182
|
send(e) {
|
|
1672
|
-
if (this.serverClosed != null) return new
|
|
1673
|
-
if (this.sendClosed) throw new
|
|
2183
|
+
if (this.serverClosed != null) return new P();
|
|
2184
|
+
if (this.sendClosed) throw new L();
|
|
1674
2185
|
return this.ws.send(this.encoder.encode({ type: "data", payload: e })), null;
|
|
1675
2186
|
}
|
|
1676
2187
|
/** Implements the Stream protocol */
|
|
@@ -1679,7 +2190,7 @@ class tr {
|
|
|
1679
2190
|
const e = await this.receiveMsg();
|
|
1680
2191
|
if (e.type === "close") {
|
|
1681
2192
|
if (e.error == null) throw new Error("Message error must be defined");
|
|
1682
|
-
return this.serverClosed =
|
|
2193
|
+
return this.serverClosed = rt(e.error), [null, this.serverClosed];
|
|
1683
2194
|
}
|
|
1684
2195
|
return [this.resSchema.parse(e.payload), null];
|
|
1685
2196
|
}
|
|
@@ -1708,74 +2219,74 @@ class tr {
|
|
|
1708
2219
|
t != null ? t.resolve(e) : this.receiveDataQueue.push(e);
|
|
1709
2220
|
}
|
|
1710
2221
|
listenForMessages() {
|
|
1711
|
-
this.ws.onmessage = (e) => this.addMessage(this.encoder.decode(e.data,
|
|
2222
|
+
this.ws.onmessage = (e) => this.addMessage(this.encoder.decode(e.data, Ar)), this.ws.onclose = (e) => this.addMessage({
|
|
1712
2223
|
type: "close",
|
|
1713
|
-
error: { type:
|
|
2224
|
+
error: { type: Ur(e) ? P.TYPE : L.TYPE, data: "" }
|
|
1714
2225
|
});
|
|
1715
2226
|
}
|
|
1716
2227
|
}
|
|
1717
|
-
const
|
|
2228
|
+
const Mr = "freighterctx", $r = 1e3, Rr = 1001, Br = [$r, Rr], Ur = (r) => Br.includes(r.code), se = class se extends nt {
|
|
1718
2229
|
/**
|
|
1719
2230
|
* @param encoder - The encoder to use for encoding messages and decoding
|
|
1720
2231
|
* responses.
|
|
1721
2232
|
* @param baseEndpoint - A base url to use as a prefix for all requests.
|
|
1722
2233
|
*/
|
|
1723
|
-
constructor(t, n,
|
|
2234
|
+
constructor(t, n, s = !1) {
|
|
1724
2235
|
super();
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
this.baseUrl = t.replace({ protocol:
|
|
2236
|
+
p(this, "baseUrl");
|
|
2237
|
+
p(this, "encoder");
|
|
2238
|
+
this.baseUrl = t.replace({ protocol: s ? "wss" : "ws" }), this.encoder = n;
|
|
1728
2239
|
}
|
|
1729
2240
|
/** Implements the StreamClient interface. */
|
|
1730
|
-
async stream(t, n,
|
|
1731
|
-
const a =
|
|
2241
|
+
async stream(t, n, s) {
|
|
2242
|
+
const a = Er();
|
|
1732
2243
|
let c;
|
|
1733
|
-
const [,
|
|
2244
|
+
const [, d] = await this.executeMiddleware(
|
|
1734
2245
|
{ target: t, protocol: "websocket", params: {}, role: "client" },
|
|
1735
|
-
async (
|
|
1736
|
-
const
|
|
1737
|
-
|
|
1738
|
-
const
|
|
1739
|
-
return
|
|
2246
|
+
async (f) => {
|
|
2247
|
+
const y = a(this.buildURL(t, f)), T = { ...f, params: {} };
|
|
2248
|
+
y.binaryType = se.MESSAGE_TYPE;
|
|
2249
|
+
const l = await this.wrapSocket(y, n, s);
|
|
2250
|
+
return l instanceof Error ? [T, l] : (c = l, [T, null]);
|
|
1740
2251
|
}
|
|
1741
2252
|
);
|
|
1742
|
-
if (
|
|
2253
|
+
if (d != null) throw d;
|
|
1743
2254
|
return c;
|
|
1744
2255
|
}
|
|
1745
2256
|
buildURL(t, n) {
|
|
1746
|
-
const
|
|
2257
|
+
const s = pr(
|
|
1747
2258
|
{
|
|
1748
|
-
[
|
|
2259
|
+
[st]: this.encoder.contentType,
|
|
1749
2260
|
...n.params
|
|
1750
2261
|
},
|
|
1751
|
-
|
|
2262
|
+
Mr
|
|
1752
2263
|
);
|
|
1753
|
-
return this.baseUrl.child(t).toString() +
|
|
2264
|
+
return this.baseUrl.child(t).toString() + s;
|
|
1754
2265
|
}
|
|
1755
|
-
async wrapSocket(t, n,
|
|
2266
|
+
async wrapSocket(t, n, s) {
|
|
1756
2267
|
return await new Promise((a) => {
|
|
1757
2268
|
t.onopen = () => {
|
|
1758
|
-
a(new
|
|
2269
|
+
a(new xr(t, this.encoder, n, s));
|
|
1759
2270
|
}, t.onerror = (c) => {
|
|
1760
|
-
const
|
|
1761
|
-
a(new Error(
|
|
2271
|
+
const d = c;
|
|
2272
|
+
a(new Error(d.message));
|
|
1762
2273
|
};
|
|
1763
2274
|
});
|
|
1764
2275
|
}
|
|
1765
2276
|
};
|
|
1766
|
-
|
|
1767
|
-
let
|
|
2277
|
+
p(se, "MESSAGE_TYPE", "arraybuffer");
|
|
2278
|
+
let Pe = se;
|
|
1768
2279
|
export {
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
2280
|
+
ae as BaseTypedError,
|
|
2281
|
+
P as EOF,
|
|
2282
|
+
Gr as HTTPClient,
|
|
2283
|
+
L as StreamClosed,
|
|
2284
|
+
k as Unreachable,
|
|
2285
|
+
Pe as WebSocketClient,
|
|
2286
|
+
rt as decodeError,
|
|
2287
|
+
Fr as encodeError,
|
|
2288
|
+
we as errorMatcher,
|
|
2289
|
+
tt as errorZ,
|
|
2290
|
+
Sr as registerError,
|
|
2291
|
+
qr as sendRequired
|
|
1781
2292
|
};
|