@synnaxlabs/freighter 0.45.0 → 0.46.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/.turbo/turbo-build.log +17 -0
- package/dist/freighter.cjs +4 -4
- package/dist/freighter.js +780 -694
- package/package.json +10 -10
- package/src/http.ts +1 -1
package/dist/freighter.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
1
|
+
import b, { z as s } from "zod";
|
|
2
|
+
const nt = (n) => {
|
|
3
3
|
const e = n.replace(/_[a-z]/g, (t) => t[1].toUpperCase());
|
|
4
4
|
return e.length > 1 && e[0] === e[0].toUpperCase() && e[1] === e[1].toUpperCase() || e.length === 0 ? e : e[0].toLowerCase() + e.slice(1);
|
|
5
|
-
},
|
|
6
|
-
const e = (t, r =
|
|
5
|
+
}, Ce = (n) => {
|
|
6
|
+
const e = (t, r = le) => {
|
|
7
7
|
if (typeof t == "string") return n(t);
|
|
8
8
|
if (Array.isArray(t)) return t.map((c) => e(c, r));
|
|
9
|
-
if (!
|
|
10
|
-
r =
|
|
9
|
+
if (!ae(t)) return t;
|
|
10
|
+
r = at(r);
|
|
11
11
|
const i = {}, a = t;
|
|
12
12
|
return "toJSON" in a && typeof a.toJSON == "function" ? e(a.toJSON(), r) : (Object.keys(a).forEach((c) => {
|
|
13
|
-
let
|
|
13
|
+
let d = a[c];
|
|
14
14
|
const y = n(c);
|
|
15
|
-
r.recursive && (
|
|
16
|
-
let
|
|
17
|
-
return
|
|
18
|
-
}))), i[y] =
|
|
15
|
+
r.recursive && (ae(d) ? Se(d) || (d = e(d, r)) : r.recursiveInArray && ve(d) && (d = [...d].map((f) => {
|
|
16
|
+
let g = f;
|
|
17
|
+
return ae(f) ? Se(g) || (g = e(f, r)) : ve(f) && (g = e({ key: f }, r).key), g;
|
|
18
|
+
}))), i[y] = d;
|
|
19
19
|
}), i);
|
|
20
20
|
};
|
|
21
21
|
return e;
|
|
22
|
-
},
|
|
22
|
+
}, Be = Ce(nt), rt = (n) => (
|
|
23
23
|
// Don't convert the first character and don't convert a character that is after a
|
|
24
24
|
// non-alphanumeric character
|
|
25
25
|
n.replace(
|
|
26
26
|
/([a-z0-9])([A-Z])/g,
|
|
27
27
|
(e, t, r) => `${t}_${r.toLowerCase()}`
|
|
28
28
|
)
|
|
29
|
-
),
|
|
29
|
+
), st = Ce(rt), it = [Number, String, Uint8Array], le = {
|
|
30
30
|
recursive: !0,
|
|
31
31
|
recursiveInArray: !0
|
|
32
|
-
},
|
|
33
|
-
let
|
|
32
|
+
}, at = (n = le) => (n.recursive == null ? n = le : n.recursiveInArray ??= !1, n), ve = (n) => n != null && Array.isArray(n), ae = (n) => n != null && typeof n == "object" && !Array.isArray(n), Se = (n) => it.some((e) => n instanceof e);
|
|
33
|
+
let ot = class {
|
|
34
34
|
contentType = "application/json";
|
|
35
35
|
decoder;
|
|
36
36
|
encoder;
|
|
@@ -44,16 +44,16 @@ let rt = class {
|
|
|
44
44
|
return this.decodeString(this.decoder.decode(e), t);
|
|
45
45
|
}
|
|
46
46
|
decodeString(e, t) {
|
|
47
|
-
const r = JSON.parse(e), i =
|
|
47
|
+
const r = JSON.parse(e), i = Be(r);
|
|
48
48
|
return t != null ? t.parse(i) : i;
|
|
49
49
|
}
|
|
50
50
|
encodeString(e) {
|
|
51
|
-
const t =
|
|
51
|
+
const t = st(e);
|
|
52
52
|
return JSON.stringify(t, (r, i) => ArrayBuffer.isView(i) ? Array.from(i) : typeof i == "bigint" ? i.toString() : i);
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
-
const
|
|
56
|
-
let
|
|
55
|
+
const ce = new ot(), A = (n) => n != null && typeof n == "object" && "value" in n;
|
|
56
|
+
let Z = class {
|
|
57
57
|
/** The underlying primitive value */
|
|
58
58
|
value;
|
|
59
59
|
constructor(e) {
|
|
@@ -73,8 +73,8 @@ let F = class {
|
|
|
73
73
|
return this.value.toString();
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
const
|
|
77
|
-
const t =
|
|
76
|
+
const ut = (n) => n != null && typeof n == "object" && "toString" in n, lt = (n, e = !1) => {
|
|
77
|
+
const t = ut(n) ? "stringer" : typeof n;
|
|
78
78
|
let r;
|
|
79
79
|
switch (t) {
|
|
80
80
|
case "string":
|
|
@@ -98,38 +98,38 @@ const st = (n) => n != null && typeof n == "object" && "toString" in n, it = (n,
|
|
|
98
98
|
default:
|
|
99
99
|
return console.warn(`sortFunc: unknown type ${t}`), () => -1;
|
|
100
100
|
}
|
|
101
|
-
return e ?
|
|
102
|
-
},
|
|
101
|
+
return e ? ct(r) : r;
|
|
102
|
+
}, ct = (n) => (e, t) => n(t, e), te = s.tuple([s.number(), s.number()]);
|
|
103
103
|
s.tuple([s.bigint(), s.bigint()]);
|
|
104
|
-
const
|
|
104
|
+
const Re = s.object({ width: s.number(), height: s.number() }), ht = s.object({
|
|
105
105
|
signedWidth: s.number(),
|
|
106
106
|
signedHeight: s.number()
|
|
107
|
-
}),
|
|
108
|
-
s.enum(
|
|
109
|
-
const
|
|
110
|
-
s.enum(
|
|
111
|
-
const
|
|
112
|
-
s.enum(
|
|
113
|
-
const
|
|
114
|
-
s.enum(
|
|
115
|
-
const
|
|
116
|
-
s.enum(
|
|
117
|
-
const
|
|
118
|
-
s.union([
|
|
119
|
-
s.union([
|
|
120
|
-
s.enum([...
|
|
107
|
+
}), ft = ["width", "height"];
|
|
108
|
+
s.enum(ft);
|
|
109
|
+
const dt = ["start", "center", "end"], gt = ["signedWidth", "signedHeight"];
|
|
110
|
+
s.enum(gt);
|
|
111
|
+
const ee = s.object({ x: s.number(), y: s.number() }), pt = s.object({ clientX: s.number(), clientY: s.number() }), mt = ["x", "y"], De = s.enum(mt), Le = ["top", "right", "bottom", "left"];
|
|
112
|
+
s.enum(Le);
|
|
113
|
+
const yt = ["left", "right"], Pe = s.enum(yt), wt = ["top", "bottom"], ke = s.enum(wt), je = ["center"], Ie = s.enum(je), bt = [...Le, ...je], Ye = s.enum(bt);
|
|
114
|
+
s.enum(dt);
|
|
115
|
+
const Ot = ["first", "last"];
|
|
116
|
+
s.enum(Ot);
|
|
117
|
+
const Tt = s.object({ lower: s.number(), upper: s.number() }), vt = s.object({ lower: s.bigint(), upper: s.bigint() });
|
|
118
|
+
s.union([Tt, te]);
|
|
119
|
+
s.union([vt, te]);
|
|
120
|
+
s.enum([...De.options, ...Ye.options]);
|
|
121
121
|
s.enum(["x", "left", "right"]);
|
|
122
122
|
s.enum(["y", "top", "bottom"]);
|
|
123
|
-
s.union([
|
|
124
|
-
const
|
|
123
|
+
s.union([De, Ye, s.instanceof(String)]);
|
|
124
|
+
const ne = (n) => (e, t) => {
|
|
125
125
|
if (typeof e == "bigint") {
|
|
126
|
-
if (
|
|
126
|
+
if (St(t))
|
|
127
127
|
return n(e, BigInt(t));
|
|
128
128
|
const r = n(Number(e), Number(t));
|
|
129
129
|
return typeof r == "number" ? BigInt(Math.round(r)) : r;
|
|
130
130
|
}
|
|
131
131
|
return n(Number(e), Number(t));
|
|
132
|
-
},
|
|
132
|
+
}, re = ne((n, e) => n - e), se = ne((n, e) => n + e), St = (n) => typeof n == "bigint" ? !0 : Number.isInteger(n), C = ne((n, e) => n * e), ie = ne((n, e) => n / e), P = (n, e, t) => {
|
|
133
133
|
const r = {};
|
|
134
134
|
if (typeof e == "object" && (t = e, e = void 0), t = { makeValid: !0, ...t }, typeof n == "number" || typeof n == "bigint")
|
|
135
135
|
e != null ? (r.lower = n, r.upper = e) : (r.lower = typeof n == "bigint" ? 0n : 0, r.upper = n);
|
|
@@ -138,34 +138,34 @@ const _ = (n) => (e, t) => {
|
|
|
138
138
|
[r.lower, r.upper] = n;
|
|
139
139
|
} else
|
|
140
140
|
r.lower = n.lower, r.upper = n.upper;
|
|
141
|
-
return t?.makeValid ?
|
|
142
|
-
},
|
|
143
|
-
const t =
|
|
141
|
+
return t?.makeValid ? It(r) : r;
|
|
142
|
+
}, It = (n) => n.lower > n.upper ? { lower: n.upper, upper: n.lower } : n, Ne = (n, e) => {
|
|
143
|
+
const t = P(n);
|
|
144
144
|
return e < t.lower ? t.lower : e >= t.upper ? t.upper - (typeof t.upper == "number" ? 1 : 1n) : e;
|
|
145
145
|
};
|
|
146
146
|
s.object({
|
|
147
|
-
x:
|
|
148
|
-
y:
|
|
147
|
+
x: Pe.or(Ie),
|
|
148
|
+
y: ke.or(Ie)
|
|
149
149
|
});
|
|
150
|
-
const
|
|
150
|
+
const Nt = s.object({ x: Pe, y: ke }), Et = Object.freeze({ x: "left", y: "top" }), xt = (n, e) => n.x === e.x && n.y === e.y, Ee = s.union([
|
|
151
151
|
s.number(),
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
]),
|
|
152
|
+
ee,
|
|
153
|
+
te,
|
|
154
|
+
Re,
|
|
155
|
+
ht,
|
|
156
|
+
pt
|
|
157
|
+
]), At = (n, e) => {
|
|
158
158
|
if (typeof n == "string") {
|
|
159
159
|
if (e === void 0) throw new Error("The y coordinate must be given.");
|
|
160
160
|
return n === "x" ? { x: e, y: 0 } : { x: 0, y: e };
|
|
161
161
|
}
|
|
162
162
|
return typeof n == "number" ? { x: n, y: e ?? n } : Array.isArray(n) ? { x: n[0], y: n[1] } : "signedWidth" in n ? { x: n.signedWidth, y: n.signedHeight } : "clientX" in n ? { x: n.clientX, y: n.clientY } : "width" in n ? { x: n.width, y: n.height } : { x: n.x, y: n.y };
|
|
163
|
-
},
|
|
163
|
+
}, xe = Object.freeze({ x: 0, y: 0 }), K = s.union([s.number(), s.string()]);
|
|
164
164
|
s.object({
|
|
165
|
-
top:
|
|
166
|
-
left:
|
|
167
|
-
width:
|
|
168
|
-
height:
|
|
165
|
+
top: K,
|
|
166
|
+
left: K,
|
|
167
|
+
width: K,
|
|
168
|
+
height: K
|
|
169
169
|
});
|
|
170
170
|
s.object({
|
|
171
171
|
left: s.number(),
|
|
@@ -174,15 +174,15 @@ s.object({
|
|
|
174
174
|
bottom: s.number()
|
|
175
175
|
});
|
|
176
176
|
s.object({
|
|
177
|
-
one:
|
|
178
|
-
two:
|
|
179
|
-
root:
|
|
177
|
+
one: ee,
|
|
178
|
+
two: ee,
|
|
179
|
+
root: Nt
|
|
180
180
|
});
|
|
181
|
-
const
|
|
181
|
+
const ye = (n, e, t = 0, r = 0, i) => {
|
|
182
182
|
const a = {
|
|
183
|
-
one: { ...
|
|
184
|
-
two: { ...
|
|
185
|
-
root: i ??
|
|
183
|
+
one: { ...xe },
|
|
184
|
+
two: { ...xe },
|
|
185
|
+
root: i ?? Et
|
|
186
186
|
};
|
|
187
187
|
if (typeof n == "number") {
|
|
188
188
|
if (typeof e != "number")
|
|
@@ -196,39 +196,39 @@ const de = (n, e, t = 0, r = 0, i) => {
|
|
|
196
196
|
x: a.one.x + e.signedWidth,
|
|
197
197
|
y: a.one.y + e.signedHeight
|
|
198
198
|
} : a.two = e, a));
|
|
199
|
-
},
|
|
200
|
-
const e =
|
|
199
|
+
}, oe = (n) => {
|
|
200
|
+
const e = ye(n);
|
|
201
201
|
return { lower: e.one.x, upper: e.two.x };
|
|
202
|
-
},
|
|
203
|
-
const e =
|
|
202
|
+
}, ue = (n) => {
|
|
203
|
+
const e = ye(n);
|
|
204
204
|
return { lower: e.one.y, upper: e.two.y };
|
|
205
|
-
},
|
|
206
|
-
s.union([
|
|
207
|
-
const
|
|
208
|
-
s.object({ offset:
|
|
205
|
+
}, Ut = (n) => typeof n != "object" || n == null ? !1 : "one" in n && "two" in n && "root" in n, Mt = s.object({ signedWidth: s.number(), signedHeight: s.number() });
|
|
206
|
+
s.union([Re, Mt, ee, te]);
|
|
207
|
+
const $t = (n, e, t) => e !== void 0 && n < e ? e : t !== void 0 && n > t ? t : n;
|
|
208
|
+
s.object({ offset: Ee, scale: Ee });
|
|
209
209
|
s.object({ offset: s.number(), scale: s.number() });
|
|
210
|
-
const
|
|
210
|
+
const Ct = (n) => (e, t, r, i) => t === "dimension" ? [e, r] : [
|
|
211
211
|
e,
|
|
212
212
|
i ? r - n : r + n
|
|
213
|
-
],
|
|
213
|
+
], Bt = (n) => (e, t, r, i) => [
|
|
214
214
|
e,
|
|
215
215
|
i ? r / n : r * n
|
|
216
|
-
],
|
|
216
|
+
], Rt = (n) => (e, t, r) => {
|
|
217
217
|
if (e === null) return [n, r];
|
|
218
|
-
const { lower: i, upper: a } = e, { lower: c, upper:
|
|
218
|
+
const { lower: i, upper: a } = e, { lower: c, upper: d } = n, y = a - i, f = d - c;
|
|
219
219
|
if (t === "dimension") return [n, r * (f / y)];
|
|
220
|
-
const
|
|
221
|
-
return [n,
|
|
222
|
-
},
|
|
220
|
+
const g = (r - i) * (f / y) + c;
|
|
221
|
+
return [n, g];
|
|
222
|
+
}, Dt = (n) => (e, t, r) => [n, r], Lt = () => (n, e, t) => {
|
|
223
223
|
if (n === null) throw new Error("cannot invert without bounds");
|
|
224
224
|
if (e === "dimension") return [n, t];
|
|
225
225
|
const { lower: r, upper: i } = n;
|
|
226
226
|
return [n, i - (t - r)];
|
|
227
|
-
},
|
|
227
|
+
}, Pt = (n) => (e, t, r) => {
|
|
228
228
|
const { lower: i, upper: a } = n;
|
|
229
|
-
return r =
|
|
229
|
+
return r = $t(r, i, a), [e, r];
|
|
230
230
|
};
|
|
231
|
-
let
|
|
231
|
+
let Ae = class k {
|
|
232
232
|
ops = [];
|
|
233
233
|
currBounds = null;
|
|
234
234
|
currType = null;
|
|
@@ -242,7 +242,7 @@ let Ie = class L {
|
|
|
242
242
|
* @param value - The amount to translate by.
|
|
243
243
|
*/
|
|
244
244
|
static translate(e) {
|
|
245
|
-
return new
|
|
245
|
+
return new k().translate(e);
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
248
248
|
* @returns a new scale with a magnification as its first operation. Any number provided
|
|
@@ -250,10 +250,10 @@ let Ie = class L {
|
|
|
250
250
|
* @param value - The amount to translate by.
|
|
251
251
|
*/
|
|
252
252
|
static magnify(e) {
|
|
253
|
-
return new
|
|
253
|
+
return new k().magnify(e);
|
|
254
254
|
}
|
|
255
255
|
static scale(e, t) {
|
|
256
|
-
return new
|
|
256
|
+
return new k().scale(e, t);
|
|
257
257
|
}
|
|
258
258
|
/**
|
|
259
259
|
* @returns a copy of the scale with a translation as its next operation. Any
|
|
@@ -262,7 +262,7 @@ let Ie = class L {
|
|
|
262
262
|
* @param value - The amount to translate by.
|
|
263
263
|
*/
|
|
264
264
|
translate(e) {
|
|
265
|
-
const t = this.new(), r =
|
|
265
|
+
const t = this.new(), r = Ct(e);
|
|
266
266
|
return r.type = "translate", t.ops.push(r), t;
|
|
267
267
|
}
|
|
268
268
|
/**
|
|
@@ -272,23 +272,23 @@ let Ie = class L {
|
|
|
272
272
|
* @param value - The amount to magnify by.
|
|
273
273
|
*/
|
|
274
274
|
magnify(e) {
|
|
275
|
-
const t = this.new(), r =
|
|
275
|
+
const t = this.new(), r = Bt(e);
|
|
276
276
|
return r.type = "magnify", t.ops.push(r), t;
|
|
277
277
|
}
|
|
278
278
|
scale(e, t) {
|
|
279
|
-
const r =
|
|
279
|
+
const r = P(e, t), i = this.new(), a = Rt(r);
|
|
280
280
|
return a.type = "scale", i.ops.push(a), i;
|
|
281
281
|
}
|
|
282
282
|
clamp(e, t) {
|
|
283
|
-
const r =
|
|
283
|
+
const r = P(e, t), i = this.new(), a = Pt(r);
|
|
284
284
|
return a.type = "clamp", i.ops.push(a), i;
|
|
285
285
|
}
|
|
286
286
|
reBound(e, t) {
|
|
287
|
-
const r =
|
|
287
|
+
const r = P(e, t), i = this.new(), a = Dt(r);
|
|
288
288
|
return a.type = "re-bound", i.ops.push(a), i;
|
|
289
289
|
}
|
|
290
290
|
invert() {
|
|
291
|
-
const e =
|
|
291
|
+
const e = Lt();
|
|
292
292
|
e.type = "invert";
|
|
293
293
|
const t = this.new();
|
|
294
294
|
return t.ops.push(e), t;
|
|
@@ -300,7 +300,7 @@ let Ie = class L {
|
|
|
300
300
|
return this.exec("dimension", e);
|
|
301
301
|
}
|
|
302
302
|
new() {
|
|
303
|
-
const e = new
|
|
303
|
+
const e = new k();
|
|
304
304
|
return e.ops = this.ops.slice(), e.reversed = this.reversed, e;
|
|
305
305
|
}
|
|
306
306
|
exec(e, t) {
|
|
@@ -314,9 +314,9 @@ let Ie = class L {
|
|
|
314
314
|
e.ops.reverse();
|
|
315
315
|
const t = [];
|
|
316
316
|
return e.ops.forEach((r, i) => {
|
|
317
|
-
if (r.type === "scale" || t.some(([c,
|
|
317
|
+
if (r.type === "scale" || t.some(([c, d]) => i >= c && i <= d))
|
|
318
318
|
return;
|
|
319
|
-
const a = e.ops.findIndex((c,
|
|
319
|
+
const a = e.ops.findIndex((c, d) => c.type === "scale" && d > i);
|
|
320
320
|
a !== -1 && t.push([i, a]);
|
|
321
321
|
}), t.forEach(([r, i]) => {
|
|
322
322
|
const a = e.ops.slice(r, i);
|
|
@@ -326,37 +326,37 @@ let Ie = class L {
|
|
|
326
326
|
get transform() {
|
|
327
327
|
return { scale: this.dim(1), offset: this.pos(0) };
|
|
328
328
|
}
|
|
329
|
-
static IDENTITY = new
|
|
330
|
-
},
|
|
329
|
+
static IDENTITY = new k();
|
|
330
|
+
}, sr = class M {
|
|
331
331
|
x;
|
|
332
332
|
y;
|
|
333
333
|
currRoot;
|
|
334
|
-
constructor(e = new
|
|
334
|
+
constructor(e = new Ae(), t = new Ae(), r = null) {
|
|
335
335
|
this.x = e, this.y = t, this.currRoot = r;
|
|
336
336
|
}
|
|
337
337
|
static translate(e, t) {
|
|
338
|
-
return new
|
|
338
|
+
return new M().translate(e, t);
|
|
339
339
|
}
|
|
340
340
|
static translateX(e) {
|
|
341
|
-
return new
|
|
341
|
+
return new M().translateX(e);
|
|
342
342
|
}
|
|
343
343
|
static translateY(e) {
|
|
344
|
-
return new
|
|
344
|
+
return new M().translateY(e);
|
|
345
345
|
}
|
|
346
346
|
static clamp(e) {
|
|
347
|
-
return new
|
|
347
|
+
return new M().clamp(e);
|
|
348
348
|
}
|
|
349
349
|
static magnify(e) {
|
|
350
|
-
return new
|
|
350
|
+
return new M().magnify(e);
|
|
351
351
|
}
|
|
352
352
|
static scale(e) {
|
|
353
|
-
return new
|
|
353
|
+
return new M().scale(e);
|
|
354
354
|
}
|
|
355
355
|
static reBound(e) {
|
|
356
|
-
return new
|
|
356
|
+
return new M().reBound(e);
|
|
357
357
|
}
|
|
358
358
|
translate(e, t) {
|
|
359
|
-
const r =
|
|
359
|
+
const r = At(e, t), i = this.copy();
|
|
360
360
|
return i.x = this.x.translate(r.x), i.y = this.y.translate(r.y), i;
|
|
361
361
|
}
|
|
362
362
|
translateX(e) {
|
|
@@ -373,22 +373,22 @@ let Ie = class L {
|
|
|
373
373
|
}
|
|
374
374
|
scale(e) {
|
|
375
375
|
const t = this.copy();
|
|
376
|
-
if (
|
|
376
|
+
if (Ut(e)) {
|
|
377
377
|
const r = this.currRoot;
|
|
378
|
-
return t.currRoot = e.root, r != null && !
|
|
378
|
+
return t.currRoot = e.root, r != null && !xt(r, e.root) && (r.x !== e.root.x && (t.x = t.x.invert()), r.y !== e.root.y && (t.y = t.y.invert())), t.x = t.x.scale(oe(e)), t.y = t.y.scale(ue(e)), t;
|
|
379
379
|
}
|
|
380
380
|
return t.x = t.x.scale(e.width), t.y = t.y.scale(e.height), t;
|
|
381
381
|
}
|
|
382
382
|
reBound(e) {
|
|
383
383
|
const t = this.copy();
|
|
384
|
-
return t.x = this.x.reBound(
|
|
384
|
+
return t.x = this.x.reBound(oe(e)), t.y = this.y.reBound(ue(e)), t;
|
|
385
385
|
}
|
|
386
386
|
clamp(e) {
|
|
387
387
|
const t = this.copy();
|
|
388
|
-
return t.x = this.x.clamp(
|
|
388
|
+
return t.x = this.x.clamp(oe(e)), t.y = this.y.clamp(ue(e)), t;
|
|
389
389
|
}
|
|
390
390
|
copy() {
|
|
391
|
-
const e = new
|
|
391
|
+
const e = new M();
|
|
392
392
|
return e.currRoot = this.currRoot, e.x = this.x, e.y = this.y, e;
|
|
393
393
|
}
|
|
394
394
|
reverse() {
|
|
@@ -402,7 +402,7 @@ let Ie = class L {
|
|
|
402
402
|
return { x: this.x.dim(e.x), y: this.y.dim(e.y) };
|
|
403
403
|
}
|
|
404
404
|
box(e) {
|
|
405
|
-
return
|
|
405
|
+
return ye(
|
|
406
406
|
this.pos(e.one),
|
|
407
407
|
this.pos(e.two),
|
|
408
408
|
0,
|
|
@@ -416,50 +416,50 @@ let Ie = class L {
|
|
|
416
416
|
offset: this.pos({ x: 0, y: 0 })
|
|
417
417
|
};
|
|
418
418
|
}
|
|
419
|
-
static IDENTITY = new
|
|
420
|
-
},
|
|
419
|
+
static IDENTITY = new M();
|
|
420
|
+
}, qe = (n, e = 21) => (t = e) => {
|
|
421
421
|
let r = "", i = t | 0;
|
|
422
422
|
for (; i--; )
|
|
423
423
|
r += n[Math.random() * n.length | 0];
|
|
424
424
|
return r;
|
|
425
425
|
};
|
|
426
|
-
const
|
|
426
|
+
const Fe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", kt = `0123456789${Fe}`, jt = 11, Yt = qe(Fe, 1), qt = qe(kt, jt - 1), Ft = () => `${Yt()}${qt()}`, Wt = (n, e) => (t) => t instanceof e || typeof t == "object" && t !== null && "discriminator" in t && t.discriminator === n, he = 2n ** 63n - 1n, Zt = 2 ** 63 - 1, Gt = s.enum(["static", "dynamic"]), Ue = 365, X = 30, zt = s.union([
|
|
427
427
|
s.tuple([s.int()]),
|
|
428
428
|
s.tuple([s.int(), s.int().min(1).max(12)]),
|
|
429
429
|
s.tuple([s.int(), s.int().min(1).max(12), s.int().min(1).max(31)])
|
|
430
|
-
]),
|
|
431
|
-
const t = new
|
|
430
|
+
]), We = (n, e) => {
|
|
431
|
+
const t = new u(e);
|
|
432
432
|
if (![
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
433
|
+
l.DAY,
|
|
434
|
+
l.HOUR,
|
|
435
|
+
l.MINUTE,
|
|
436
|
+
l.SECOND,
|
|
437
|
+
l.MILLISECOND,
|
|
438
|
+
l.MICROSECOND,
|
|
439
|
+
l.NANOSECOND
|
|
440
440
|
].some((i) => i.equals(t)))
|
|
441
441
|
throw new Error(
|
|
442
442
|
"Invalid argument for remainder. Must be an even TimeSpan or Timestamp"
|
|
443
443
|
);
|
|
444
444
|
const r = n.valueOf() % t.valueOf();
|
|
445
|
-
return n instanceof
|
|
445
|
+
return n instanceof u ? new u(r) : new l(r);
|
|
446
446
|
};
|
|
447
|
-
class
|
|
447
|
+
class u extends Z {
|
|
448
448
|
constructor(e, t = "UTC") {
|
|
449
|
-
if (e == null) super(
|
|
449
|
+
if (e == null) super(u.now().valueOf());
|
|
450
450
|
else if (e instanceof Date)
|
|
451
|
-
super(BigInt(e.getTime()) *
|
|
451
|
+
super(BigInt(e.getTime()) * u.MILLISECOND.valueOf());
|
|
452
452
|
else if (typeof e == "string")
|
|
453
|
-
super(
|
|
454
|
-
else if (Array.isArray(e)) super(
|
|
453
|
+
super(u.parseDateTimeString(e, t).valueOf());
|
|
454
|
+
else if (Array.isArray(e)) super(u.parseDate(e));
|
|
455
455
|
else {
|
|
456
456
|
let r = 0n;
|
|
457
|
-
e instanceof Number && (e = e.valueOf()), t === "local" && (r =
|
|
457
|
+
e instanceof Number && (e = e.valueOf()), t === "local" && (r = u.utcOffset.valueOf()), typeof e == "number" && (isFinite(e) ? e === Zt ? e = he : e = Math.trunc(e) : (isNaN(e) && (e = 0), e === 1 / 0 ? e = u.MAX : e = u.MIN)), A(e) && (e = e.value), super(BigInt(e.valueOf()) + r);
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
460
|
static parseDate([e = 1970, t = 1, r = 1]) {
|
|
461
461
|
const i = new Date(e, t - 1, r, 0, 0, 0, 0);
|
|
462
|
-
return new
|
|
462
|
+
return new u(BigInt(i.getTime()) * u.MILLISECOND.valueOf()).truncate(u.DAY).valueOf();
|
|
463
463
|
}
|
|
464
464
|
/**
|
|
465
465
|
* @returns the primitive value of the TimeStamp. Overrides standard JS valueOf()
|
|
@@ -470,49 +470,22 @@ class o extends F {
|
|
|
470
470
|
}
|
|
471
471
|
static parseTimeString(e, t = "UTC") {
|
|
472
472
|
const [r, i, a] = e.split(":");
|
|
473
|
-
let c = "00",
|
|
474
|
-
a != null && ([c,
|
|
475
|
-
let y =
|
|
476
|
-
return t === "local" && (y = y.add(
|
|
473
|
+
let c = "00", d = "00";
|
|
474
|
+
a != null && ([c, d] = a.split("."));
|
|
475
|
+
let y = u.hours(parseInt(r ?? "00")).add(u.minutes(parseInt(i ?? "00"))).add(u.seconds(parseInt(c ?? "00"))).add(u.milliseconds(parseInt(d ?? "00")));
|
|
476
|
+
return t === "local" && (y = y.add(u.utcOffset)), y.valueOf();
|
|
477
477
|
}
|
|
478
478
|
static parseDateTimeString(e, t = "UTC") {
|
|
479
479
|
if (!e.includes("/") && !e.includes("-"))
|
|
480
|
-
return
|
|
480
|
+
return u.parseTimeString(e, t);
|
|
481
481
|
const r = new Date(e);
|
|
482
|
-
return e.includes(":") || r.setUTCHours(0, 0, 0, 0), new
|
|
483
|
-
BigInt(r.getTime()) *
|
|
482
|
+
return e.includes(":") || r.setUTCHours(0, 0, 0, 0), new u(
|
|
483
|
+
BigInt(r.getTime()) * u.MILLISECOND.valueOf(),
|
|
484
484
|
t
|
|
485
485
|
).valueOf();
|
|
486
486
|
}
|
|
487
|
-
/**
|
|
488
|
-
* Formats the TimeStamp as a string in the specified format.
|
|
489
|
-
*
|
|
490
|
-
* @param format - The format to use for the string representation.
|
|
491
|
-
* @param tzInfo - The timezone to use when creating the string representation.
|
|
492
|
-
* @returns A string representation of the TimeStamp in the specified format.
|
|
493
|
-
*/
|
|
494
|
-
fString(e = "ISO", t = "UTC") {
|
|
495
|
-
switch (e) {
|
|
496
|
-
case "ISODate":
|
|
497
|
-
return this.toISOString(t).slice(0, 10);
|
|
498
|
-
case "ISOTime":
|
|
499
|
-
return this.toISOString(t).slice(11, 23);
|
|
500
|
-
case "time":
|
|
501
|
-
return this.timeString(!1, t);
|
|
502
|
-
case "preciseTime":
|
|
503
|
-
return this.timeString(!0, t);
|
|
504
|
-
case "date":
|
|
505
|
-
return this.dateString();
|
|
506
|
-
case "preciseDate":
|
|
507
|
-
return `${this.dateString()} ${this.timeString(!0, t)}`;
|
|
508
|
-
case "dateTime":
|
|
509
|
-
return `${this.dateString()} ${this.timeString(!1, t)}`;
|
|
510
|
-
default:
|
|
511
|
-
return this.toISOString(t);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
487
|
toISOString(e = "UTC") {
|
|
515
|
-
return e === "UTC" ? this.date().toISOString() : this.sub(
|
|
488
|
+
return e === "UTC" ? this.date().toISOString() : this.sub(u.utcOffset).date().toISOString();
|
|
516
489
|
}
|
|
517
490
|
timeString(e = !1, t = "UTC") {
|
|
518
491
|
const r = this.toISOString(t);
|
|
@@ -524,8 +497,8 @@ class o extends F {
|
|
|
524
497
|
}
|
|
525
498
|
/** @returns The UTC offset for the time zone of the machine. */
|
|
526
499
|
static get utcOffset() {
|
|
527
|
-
return new
|
|
528
|
-
BigInt((/* @__PURE__ */ new Date()).getTimezoneOffset()) *
|
|
500
|
+
return new l(
|
|
501
|
+
BigInt((/* @__PURE__ */ new Date()).getTimezoneOffset()) * u.MINUTE.valueOf()
|
|
529
502
|
);
|
|
530
503
|
}
|
|
531
504
|
/**
|
|
@@ -534,7 +507,7 @@ class o extends F {
|
|
|
534
507
|
* @param other - The other timestamp.
|
|
535
508
|
*/
|
|
536
509
|
static since(e) {
|
|
537
|
-
return new
|
|
510
|
+
return new u().span(e);
|
|
538
511
|
}
|
|
539
512
|
/** @returns A JavaScript Date object representing the TimeStamp. */
|
|
540
513
|
date() {
|
|
@@ -547,7 +520,7 @@ class o extends F {
|
|
|
547
520
|
* @returns True if the TimeStamps are equal, false otherwise.
|
|
548
521
|
*/
|
|
549
522
|
equals(e) {
|
|
550
|
-
return this.valueOf() === new
|
|
523
|
+
return this.valueOf() === new u(e).valueOf();
|
|
551
524
|
}
|
|
552
525
|
/**
|
|
553
526
|
* Creates a TimeSpan representing the duration between the two timestamps.
|
|
@@ -567,7 +540,7 @@ class o extends F {
|
|
|
567
540
|
* valid, regardless of the TimeStamp order.
|
|
568
541
|
*/
|
|
569
542
|
range(e) {
|
|
570
|
-
return new
|
|
543
|
+
return new G(this, e).makeValid();
|
|
571
544
|
}
|
|
572
545
|
/**
|
|
573
546
|
* Creates a TimeRange starting at the TimeStamp and spanning the given
|
|
@@ -596,7 +569,7 @@ class o extends F {
|
|
|
596
569
|
* otherwise.
|
|
597
570
|
*/
|
|
598
571
|
after(e) {
|
|
599
|
-
return this.valueOf() > new
|
|
572
|
+
return this.valueOf() > new u(e).valueOf();
|
|
600
573
|
}
|
|
601
574
|
/**
|
|
602
575
|
* Checks if the TimeStamp is after or equal to the given TimeStamp.
|
|
@@ -606,7 +579,7 @@ class o extends F {
|
|
|
606
579
|
* false otherwise.
|
|
607
580
|
*/
|
|
608
581
|
afterEq(e) {
|
|
609
|
-
return this.valueOf() >= new
|
|
582
|
+
return this.valueOf() >= new u(e).valueOf();
|
|
610
583
|
}
|
|
611
584
|
/**
|
|
612
585
|
* Checks if the TimeStamp is before the given TimeStamp.
|
|
@@ -616,7 +589,7 @@ class o extends F {
|
|
|
616
589
|
* otherwise.
|
|
617
590
|
*/
|
|
618
591
|
before(e) {
|
|
619
|
-
return this.valueOf() < new
|
|
592
|
+
return this.valueOf() < new u(e).valueOf();
|
|
620
593
|
}
|
|
621
594
|
/**
|
|
622
595
|
* Checks if TimeStamp is before or equal to the current timestamp.
|
|
@@ -626,7 +599,7 @@ class o extends F {
|
|
|
626
599
|
* false otherwise.
|
|
627
600
|
*/
|
|
628
601
|
beforeEq(e) {
|
|
629
|
-
return this.valueOf() <= new
|
|
602
|
+
return this.valueOf() <= new u(e).valueOf();
|
|
630
603
|
}
|
|
631
604
|
/**
|
|
632
605
|
* Adds a TimeSpan to the TimeStamp.
|
|
@@ -636,7 +609,7 @@ class o extends F {
|
|
|
636
609
|
* TimeSpan.
|
|
637
610
|
*/
|
|
638
611
|
add(e) {
|
|
639
|
-
return new
|
|
612
|
+
return new u(se(this.valueOf(), new l(e).valueOf()));
|
|
640
613
|
}
|
|
641
614
|
/**
|
|
642
615
|
* Subtracts a TimeSpan from the TimeStamp.
|
|
@@ -646,43 +619,43 @@ class o extends F {
|
|
|
646
619
|
* TimeSpan.
|
|
647
620
|
*/
|
|
648
621
|
sub(e) {
|
|
649
|
-
return new
|
|
622
|
+
return new u(re(this.valueOf(), new l(e).valueOf()));
|
|
650
623
|
}
|
|
651
624
|
/**
|
|
652
625
|
* @returns the floating point number of hours since the unix epoch to the timestamp
|
|
653
626
|
* value.
|
|
654
627
|
*/
|
|
655
628
|
get hours() {
|
|
656
|
-
return Number(this.valueOf()) / Number(
|
|
629
|
+
return Number(this.valueOf()) / Number(l.HOUR.valueOf());
|
|
657
630
|
}
|
|
658
631
|
/**
|
|
659
632
|
* @returns the floating point number of minutes since the unix epoch to the timestamp
|
|
660
633
|
* value.
|
|
661
634
|
*/
|
|
662
635
|
get minutes() {
|
|
663
|
-
return Number(this.valueOf()) / Number(
|
|
636
|
+
return Number(this.valueOf()) / Number(l.MINUTE.valueOf());
|
|
664
637
|
}
|
|
665
638
|
/**
|
|
666
639
|
* @returns the floating point number of days since the unix epoch to the timestamp
|
|
667
640
|
* value.
|
|
668
641
|
*/
|
|
669
642
|
get days() {
|
|
670
|
-
return Number(this.valueOf()) / Number(
|
|
643
|
+
return Number(this.valueOf()) / Number(l.DAY.valueOf());
|
|
671
644
|
}
|
|
672
645
|
/**
|
|
673
646
|
* @returns the floating point number of seconds since the unix epoch to the timestamp
|
|
674
647
|
* value.
|
|
675
648
|
*/
|
|
676
649
|
get seconds() {
|
|
677
|
-
return Number(this.valueOf()) / Number(
|
|
650
|
+
return Number(this.valueOf()) / Number(l.SECOND.valueOf());
|
|
678
651
|
}
|
|
679
652
|
/** @returns the floating point number of milliseconds since the unix epoch. */
|
|
680
653
|
get milliseconds() {
|
|
681
|
-
return Number(this.valueOf()) / Number(
|
|
654
|
+
return Number(this.valueOf()) / Number(u.MILLISECOND.valueOf());
|
|
682
655
|
}
|
|
683
656
|
/** @returns the floating point number of microseconds since the unix epoch. */
|
|
684
657
|
get microseconds() {
|
|
685
|
-
return Number(this.valueOf()) / Number(
|
|
658
|
+
return Number(this.valueOf()) / Number(u.MICROSECOND.valueOf());
|
|
686
659
|
}
|
|
687
660
|
/**
|
|
688
661
|
* @returns the floating point number of nanoseconds since the unix epoch.
|
|
@@ -702,7 +675,7 @@ class o extends F {
|
|
|
702
675
|
*/
|
|
703
676
|
setYear(e) {
|
|
704
677
|
const t = this.date();
|
|
705
|
-
return t.setUTCFullYear(e), new
|
|
678
|
+
return t.setUTCFullYear(e), new u(t);
|
|
706
679
|
}
|
|
707
680
|
/** @returns the integer month that the timestamp corresponds to with its year. */
|
|
708
681
|
get month() {
|
|
@@ -714,7 +687,7 @@ class o extends F {
|
|
|
714
687
|
*/
|
|
715
688
|
setMonth(e) {
|
|
716
689
|
const t = this.date();
|
|
717
|
-
return t.setUTCMonth(e), new
|
|
690
|
+
return t.setUTCMonth(e), new u(t);
|
|
718
691
|
}
|
|
719
692
|
/** @returns the integer day that the timestamp corresponds to within its month. */
|
|
720
693
|
get day() {
|
|
@@ -726,7 +699,7 @@ class o extends F {
|
|
|
726
699
|
*/
|
|
727
700
|
setDay(e) {
|
|
728
701
|
const t = this.date();
|
|
729
|
-
return t.setUTCDate(e), new
|
|
702
|
+
return t.setUTCDate(e), new u(t);
|
|
730
703
|
}
|
|
731
704
|
/**
|
|
732
705
|
* @returns the integer hour that the timestamp corresponds to within its day.
|
|
@@ -746,7 +719,7 @@ class o extends F {
|
|
|
746
719
|
*/
|
|
747
720
|
setLocalHour(e) {
|
|
748
721
|
const t = this.date();
|
|
749
|
-
return t.setHours(e), new
|
|
722
|
+
return t.setHours(e), new u(t);
|
|
750
723
|
}
|
|
751
724
|
/**
|
|
752
725
|
* @returns a copy of the timestamp with the hour changed.
|
|
@@ -754,7 +727,7 @@ class o extends F {
|
|
|
754
727
|
*/
|
|
755
728
|
setHour(e) {
|
|
756
729
|
const t = this.date();
|
|
757
|
-
return t.setUTCHours(e), new
|
|
730
|
+
return t.setUTCHours(e), new u(t);
|
|
758
731
|
}
|
|
759
732
|
/** @returns the integer minute that the timestamp corresponds to within its hour. */
|
|
760
733
|
get minute() {
|
|
@@ -766,7 +739,7 @@ class o extends F {
|
|
|
766
739
|
*/
|
|
767
740
|
setMinute(e) {
|
|
768
741
|
const t = this.date();
|
|
769
|
-
return t.setUTCMinutes(e), new
|
|
742
|
+
return t.setUTCMinutes(e), new u(t);
|
|
770
743
|
}
|
|
771
744
|
/**
|
|
772
745
|
* @returns the integer second that the timestamp corresponds to within its
|
|
@@ -781,11 +754,11 @@ class o extends F {
|
|
|
781
754
|
*/
|
|
782
755
|
setSecond(e) {
|
|
783
756
|
const t = this.date();
|
|
784
|
-
return t.setUTCSeconds(e), new
|
|
757
|
+
return t.setUTCSeconds(e), new u(t);
|
|
785
758
|
}
|
|
786
759
|
/**
|
|
787
|
-
* @
|
|
788
|
-
*
|
|
760
|
+
* @returns the integer millisecond that the timestamp corresponds to within its
|
|
761
|
+
* second.
|
|
789
762
|
*/
|
|
790
763
|
get millisecond() {
|
|
791
764
|
return this.date().getUTCMilliseconds();
|
|
@@ -796,11 +769,34 @@ class o extends F {
|
|
|
796
769
|
*/
|
|
797
770
|
setMillisecond(e) {
|
|
798
771
|
const t = this.date();
|
|
799
|
-
return t.setUTCMilliseconds(e), new
|
|
772
|
+
return t.setUTCMilliseconds(e), new u(t);
|
|
800
773
|
}
|
|
801
|
-
/**
|
|
802
|
-
|
|
803
|
-
|
|
774
|
+
/**
|
|
775
|
+
* Returns a string representation of the TimeStamp.
|
|
776
|
+
*
|
|
777
|
+
* @param format - Optional format for the string representation. Defaults to "ISO".
|
|
778
|
+
* @param tzInfo - Optional timezone info. Defaults to "UTC".
|
|
779
|
+
* @returns A string representation of the TimeStamp.
|
|
780
|
+
*/
|
|
781
|
+
toString(e = "ISO", t = "UTC") {
|
|
782
|
+
switch (e) {
|
|
783
|
+
case "ISODate":
|
|
784
|
+
return this.toISOString(t).slice(0, 10);
|
|
785
|
+
case "ISOTime":
|
|
786
|
+
return this.toISOString(t).slice(11, 23);
|
|
787
|
+
case "time":
|
|
788
|
+
return this.timeString(!1, t);
|
|
789
|
+
case "preciseTime":
|
|
790
|
+
return this.timeString(!0, t);
|
|
791
|
+
case "date":
|
|
792
|
+
return this.dateString();
|
|
793
|
+
case "preciseDate":
|
|
794
|
+
return `${this.dateString()} ${this.timeString(!0, t)}`;
|
|
795
|
+
case "dateTime":
|
|
796
|
+
return `${this.dateString()} ${this.timeString(!1, t)}`;
|
|
797
|
+
default:
|
|
798
|
+
return this.toISOString(t);
|
|
799
|
+
}
|
|
804
800
|
}
|
|
805
801
|
/**
|
|
806
802
|
* @returns A new TimeStamp that is the remainder of the TimeStamp divided by the
|
|
@@ -814,11 +810,11 @@ class o extends F {
|
|
|
814
810
|
* @example TimeStamp.now().remainder(TimeStamp.DAY) // => TimeStamp representing the current day
|
|
815
811
|
*/
|
|
816
812
|
remainder(e) {
|
|
817
|
-
return
|
|
813
|
+
return We(this, e);
|
|
818
814
|
}
|
|
819
815
|
/** @returns true if the day portion TimeStamp is today, false otherwise. */
|
|
820
816
|
get isToday() {
|
|
821
|
-
return this.truncate(
|
|
817
|
+
return this.truncate(l.DAY).equals(u.now().truncate(l.DAY));
|
|
822
818
|
}
|
|
823
819
|
/**
|
|
824
820
|
* Truncates the TimeStamp to the nearest multiple of the given span.
|
|
@@ -835,7 +831,7 @@ class o extends F {
|
|
|
835
831
|
* JavaScript can do).
|
|
836
832
|
*/
|
|
837
833
|
static now() {
|
|
838
|
-
return new
|
|
834
|
+
return new u(/* @__PURE__ */ new Date());
|
|
839
835
|
}
|
|
840
836
|
/**
|
|
841
837
|
* Finds the maximum timestamp among the provided timestamps.
|
|
@@ -844,9 +840,9 @@ class o extends F {
|
|
|
844
840
|
* @returns The maximum (latest) timestamp from the input.
|
|
845
841
|
*/
|
|
846
842
|
static max(...e) {
|
|
847
|
-
let t =
|
|
843
|
+
let t = u.MIN;
|
|
848
844
|
for (const r of e) {
|
|
849
|
-
const i = new
|
|
845
|
+
const i = new u(r);
|
|
850
846
|
i.after(t) && (t = i);
|
|
851
847
|
}
|
|
852
848
|
return t;
|
|
@@ -858,9 +854,9 @@ class o extends F {
|
|
|
858
854
|
* @returns The minimum (earliest) timestamp from the input.
|
|
859
855
|
*/
|
|
860
856
|
static min(...e) {
|
|
861
|
-
let t =
|
|
857
|
+
let t = u.MAX;
|
|
862
858
|
for (const r of e) {
|
|
863
|
-
const i = new
|
|
859
|
+
const i = new u(r);
|
|
864
860
|
i.before(t) && (t = i);
|
|
865
861
|
}
|
|
866
862
|
return t;
|
|
@@ -872,62 +868,62 @@ class o extends F {
|
|
|
872
868
|
* @returns A TimeStamp representing the given number of nanoseconds.
|
|
873
869
|
*/
|
|
874
870
|
static nanoseconds(e, t = "UTC") {
|
|
875
|
-
return new
|
|
871
|
+
return new u(e, t);
|
|
876
872
|
}
|
|
877
873
|
/** One nanosecond after the unix epoch */
|
|
878
|
-
static NANOSECOND =
|
|
874
|
+
static NANOSECOND = u.nanoseconds(1);
|
|
879
875
|
/** @returns a new TimeStamp n microseconds after the unix epoch */
|
|
880
876
|
static microseconds(e, t = "UTC") {
|
|
881
|
-
return
|
|
877
|
+
return u.nanoseconds(e * 1e3, t);
|
|
882
878
|
}
|
|
883
879
|
/** One microsecond after the unix epoch */
|
|
884
|
-
static MICROSECOND =
|
|
880
|
+
static MICROSECOND = u.microseconds(1);
|
|
885
881
|
/** @returns a new TimeStamp n milliseconds after the unix epoch */
|
|
886
882
|
static milliseconds(e, t = "UTC") {
|
|
887
|
-
return
|
|
883
|
+
return u.microseconds(e * 1e3, t);
|
|
888
884
|
}
|
|
889
885
|
/** One millisecond after the unix epoch */
|
|
890
|
-
static MILLISECOND =
|
|
886
|
+
static MILLISECOND = u.milliseconds(1);
|
|
891
887
|
/** @returns a new TimeStamp n seconds after the unix epoch */
|
|
892
888
|
static seconds(e, t = "UTC") {
|
|
893
|
-
return
|
|
889
|
+
return u.milliseconds(e * 1e3, t);
|
|
894
890
|
}
|
|
895
891
|
/** One second after the unix epoch */
|
|
896
|
-
static SECOND =
|
|
892
|
+
static SECOND = u.seconds(1);
|
|
897
893
|
/** @returns a new TimeStamp n minutes after the unix epoch */
|
|
898
894
|
static minutes(e, t = "UTC") {
|
|
899
|
-
return
|
|
895
|
+
return u.seconds(e * 60, t);
|
|
900
896
|
}
|
|
901
897
|
/** One minute after the unix epoch */
|
|
902
|
-
static MINUTE =
|
|
898
|
+
static MINUTE = u.minutes(1);
|
|
903
899
|
/** @returns a new TimeStamp n hours after the unix epoch */
|
|
904
900
|
static hours(e, t = "UTC") {
|
|
905
|
-
return
|
|
901
|
+
return u.minutes(e * 60, t);
|
|
906
902
|
}
|
|
907
903
|
/** One hour after the unix epoch */
|
|
908
|
-
static HOUR =
|
|
904
|
+
static HOUR = u.hours(1);
|
|
909
905
|
/** @returns a new TimeStamp n days after the unix epoch */
|
|
910
906
|
static days(e, t = "UTC") {
|
|
911
|
-
return
|
|
907
|
+
return u.hours(e * 24, t);
|
|
912
908
|
}
|
|
913
909
|
/** One day after the unix epoch */
|
|
914
|
-
static DAY =
|
|
910
|
+
static DAY = u.days(1);
|
|
915
911
|
/** The maximum possible value for a timestamp */
|
|
916
|
-
static MAX = new
|
|
912
|
+
static MAX = new u(he);
|
|
917
913
|
/** The minimum possible value for a timestamp */
|
|
918
|
-
static MIN = new
|
|
914
|
+
static MIN = new u(0);
|
|
919
915
|
/** The unix epoch */
|
|
920
|
-
static ZERO = new
|
|
916
|
+
static ZERO = new u(0);
|
|
921
917
|
/** A zod schema for validating timestamps */
|
|
922
918
|
static z = s.union([
|
|
923
|
-
s.instanceof(
|
|
924
|
-
s.object({ value: s.bigint() }).transform((e) => new
|
|
925
|
-
s.string().transform((e) => new
|
|
926
|
-
s.number().transform((e) => new
|
|
927
|
-
s.bigint().transform((e) => new
|
|
928
|
-
s.date().transform((e) => new
|
|
929
|
-
s.custom((e) => e instanceof
|
|
930
|
-
|
|
919
|
+
s.instanceof(u),
|
|
920
|
+
s.object({ value: s.bigint() }).transform((e) => new u(e.value)),
|
|
921
|
+
s.string().transform((e) => new u(BigInt(e))),
|
|
922
|
+
s.number().transform((e) => new u(e)),
|
|
923
|
+
s.bigint().transform((e) => new u(e)),
|
|
924
|
+
s.date().transform((e) => new u(e)),
|
|
925
|
+
s.custom((e) => e instanceof l).transform((e) => new u(e)),
|
|
926
|
+
zt.transform((e) => new u(e))
|
|
931
927
|
]);
|
|
932
928
|
/**
|
|
933
929
|
* Sorts two timestamps.
|
|
@@ -941,9 +937,9 @@ class o extends F {
|
|
|
941
937
|
return Number(e.valueOf() - t.valueOf());
|
|
942
938
|
}
|
|
943
939
|
}
|
|
944
|
-
|
|
940
|
+
class l extends Z {
|
|
945
941
|
constructor(e) {
|
|
946
|
-
typeof e == "number" && (e = Math.trunc(e.valueOf())),
|
|
942
|
+
typeof e == "number" && (e = Math.trunc(e.valueOf())), A(e) && (e = e.value), super(BigInt(e.valueOf()));
|
|
947
943
|
}
|
|
948
944
|
/**
|
|
949
945
|
* Creates a TimeSpan representing the given number of seconds.
|
|
@@ -952,7 +948,7 @@ let p = class l extends F {
|
|
|
952
948
|
* @returns A TimeSpan representing the given number of seconds.
|
|
953
949
|
*/
|
|
954
950
|
static fromSeconds(e) {
|
|
955
|
-
return e instanceof l ? e : e instanceof
|
|
951
|
+
return e instanceof l ? e : e instanceof E ? e.period : e instanceof u ? new l(e) : (A(e) && (e = e.value), ["number", "bigint"].includes(typeof e) ? l.seconds(e) : new l(e));
|
|
956
952
|
}
|
|
957
953
|
/**
|
|
958
954
|
* Creates a TimeSpan representing the given number of milliseconds.
|
|
@@ -961,7 +957,7 @@ let p = class l extends F {
|
|
|
961
957
|
* @returns A TimeSpan representing the given number of milliseconds.
|
|
962
958
|
*/
|
|
963
959
|
static fromMilliseconds(e) {
|
|
964
|
-
return e instanceof l ? e : e instanceof
|
|
960
|
+
return e instanceof l ? e : e instanceof E ? e.period : e instanceof u ? new l(e) : (A(e) && (e = e.value), ["number", "bigint"].includes(typeof e) ? l.milliseconds(e) : new l(e));
|
|
965
961
|
}
|
|
966
962
|
/**
|
|
967
963
|
* @returns the primitive value of the TimeSpan. Overrides standard JS valueOf()
|
|
@@ -1013,7 +1009,7 @@ let p = class l extends F {
|
|
|
1013
1009
|
* @returns A new TimeSpan representing the remainder.
|
|
1014
1010
|
*/
|
|
1015
1011
|
remainder(e) {
|
|
1016
|
-
return
|
|
1012
|
+
return We(this, e);
|
|
1017
1013
|
}
|
|
1018
1014
|
/**
|
|
1019
1015
|
* Truncates the TimeSpan to the nearest multiple of the given span.
|
|
@@ -1029,12 +1025,72 @@ let p = class l extends F {
|
|
|
1029
1025
|
/**
|
|
1030
1026
|
* Returns a string representation of the TimeSpan.
|
|
1031
1027
|
*
|
|
1028
|
+
* @param format - Optional format for the string representation. Defaults to "full".
|
|
1029
|
+
* - "full": Shows all non-zero units with full precision (e.g., "2d 3h 45m 12s 500ms")
|
|
1030
|
+
* - "semantic": Shows 1-2 most significant units (e.g., "2d 3h")
|
|
1032
1031
|
* @returns A string representation of the TimeSpan.
|
|
1033
1032
|
*/
|
|
1034
|
-
toString() {
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1033
|
+
toString(e = "full") {
|
|
1034
|
+
if (e === "semantic") return this.toSemanticString();
|
|
1035
|
+
const t = this.truncate(l.DAY), r = this.truncate(l.HOUR), i = this.truncate(l.MINUTE), a = this.truncate(l.SECOND), c = this.truncate(l.MILLISECOND), d = this.truncate(l.MICROSECOND), y = this.truncate(l.NANOSECOND), f = t, g = r.sub(t), w = i.sub(r), h = a.sub(i), T = c.sub(a), x = d.sub(c), U = y.sub(d);
|
|
1036
|
+
let m = "";
|
|
1037
|
+
return f.isZero || (m += `${f.days}d `), g.isZero || (m += `${g.hours}h `), w.isZero || (m += `${w.minutes}m `), h.isZero || (m += `${h.seconds}s `), T.isZero || (m += `${T.milliseconds}ms `), x.isZero || (m += `${x.microseconds}µs `), U.isZero || (m += `${U.nanoseconds}ns`), m.trim();
|
|
1038
|
+
}
|
|
1039
|
+
toSemanticString() {
|
|
1040
|
+
const e = this.valueOf() < 0n ? -this.valueOf() : this.valueOf(), t = new l(e), r = this.valueOf() < 0n;
|
|
1041
|
+
if (t.valueOf() === 0n) return "0s";
|
|
1042
|
+
if (t.lessThan(l.SECOND)) return "< 1s";
|
|
1043
|
+
const i = t.days, a = t.hours, c = t.minutes, d = t.seconds, y = Math.floor(i / Ue), f = Math.floor(i / X), g = Math.floor(i / 7), w = Math.floor(i), h = Math.floor(a), T = Math.floor(c), x = Math.floor(d), U = r ? "-" : "";
|
|
1044
|
+
if (y >= 1) {
|
|
1045
|
+
let m = `${y}y`;
|
|
1046
|
+
if (y < 2) {
|
|
1047
|
+
const v = Math.floor(
|
|
1048
|
+
i % Ue / X
|
|
1049
|
+
);
|
|
1050
|
+
v > 0 && (m += ` ${v}mo`);
|
|
1051
|
+
}
|
|
1052
|
+
return U + m;
|
|
1053
|
+
}
|
|
1054
|
+
if (g >= 1 && i < X && i % 7 === 0) {
|
|
1055
|
+
let m = `${g}w`;
|
|
1056
|
+
const v = Math.floor(i % 7), L = Math.floor(a - g * 7 * 24);
|
|
1057
|
+
return g < 2 && (v > 0 ? m += ` ${v}d` : L > 0 && L < 24 && (m += ` ${L}h`)), U + m;
|
|
1058
|
+
}
|
|
1059
|
+
if (f >= 1) {
|
|
1060
|
+
let m = `${f}mo`;
|
|
1061
|
+
if (f < 3) {
|
|
1062
|
+
const v = Math.floor(i % X);
|
|
1063
|
+
v > 0 && (m += ` ${v}d`);
|
|
1064
|
+
}
|
|
1065
|
+
return U + m;
|
|
1066
|
+
}
|
|
1067
|
+
if (g >= 1) {
|
|
1068
|
+
let m = `${g}w`;
|
|
1069
|
+
const v = Math.floor(i % 7), L = Math.floor(a - g * 7 * 24);
|
|
1070
|
+
return g < 2 && (v > 0 ? m += ` ${v}d` : L > 0 && L < 24 && (m += ` ${L}h`)), U + m;
|
|
1071
|
+
}
|
|
1072
|
+
if (w >= 1) {
|
|
1073
|
+
let m = `${w}d`;
|
|
1074
|
+
const v = Math.floor(a - w * 24);
|
|
1075
|
+
return w < 2 && v > 0 && (m += ` ${v}h`), U + m;
|
|
1076
|
+
}
|
|
1077
|
+
if (h >= 1) {
|
|
1078
|
+
let m = `${h}h`;
|
|
1079
|
+
if (h < 3) {
|
|
1080
|
+
const v = Math.floor(c - h * 60);
|
|
1081
|
+
v > 0 && (m += ` ${v}m`);
|
|
1082
|
+
}
|
|
1083
|
+
return U + m;
|
|
1084
|
+
}
|
|
1085
|
+
if (T >= 1) {
|
|
1086
|
+
let m = `${T}m`;
|
|
1087
|
+
if (T < 5) {
|
|
1088
|
+
const v = Math.floor(d - T * 60);
|
|
1089
|
+
v > 0 && (m += ` ${v}s`);
|
|
1090
|
+
}
|
|
1091
|
+
return U + m;
|
|
1092
|
+
}
|
|
1093
|
+
return `${U}${x}s`;
|
|
1038
1094
|
}
|
|
1039
1095
|
/**
|
|
1040
1096
|
* Multiplies the TimeSpan by a scalar value.
|
|
@@ -1043,7 +1099,7 @@ let p = class l extends F {
|
|
|
1043
1099
|
* @returns A new TimeSpan that is this TimeSpan multiplied by the provided value.
|
|
1044
1100
|
*/
|
|
1045
1101
|
mult(e) {
|
|
1046
|
-
return new l(
|
|
1102
|
+
return new l(C(this.valueOf(), e));
|
|
1047
1103
|
}
|
|
1048
1104
|
/**
|
|
1049
1105
|
* Divides the TimeSpan by a scalar value.
|
|
@@ -1052,7 +1108,7 @@ let p = class l extends F {
|
|
|
1052
1108
|
* @returns A new TimeSpan that is this TimeSpan divided by the provided value.
|
|
1053
1109
|
*/
|
|
1054
1110
|
div(e) {
|
|
1055
|
-
return new l(
|
|
1111
|
+
return new l(ie(this.valueOf(), e));
|
|
1056
1112
|
}
|
|
1057
1113
|
/** @returns the decimal number of days in the TimeSpan. */
|
|
1058
1114
|
get days() {
|
|
@@ -1132,7 +1188,7 @@ let p = class l extends F {
|
|
|
1132
1188
|
* @returns A TimeSpan representing the given number of microseconds.
|
|
1133
1189
|
*/
|
|
1134
1190
|
static microseconds(e = 1) {
|
|
1135
|
-
return l.nanoseconds(
|
|
1191
|
+
return l.nanoseconds(C(e, 1e3));
|
|
1136
1192
|
}
|
|
1137
1193
|
/** A microsecond. */
|
|
1138
1194
|
static MICROSECOND = l.microseconds(1);
|
|
@@ -1143,7 +1199,7 @@ let p = class l extends F {
|
|
|
1143
1199
|
* @returns A TimeSpan representing the given number of milliseconds.
|
|
1144
1200
|
*/
|
|
1145
1201
|
static milliseconds(e = 1) {
|
|
1146
|
-
return l.microseconds(
|
|
1202
|
+
return l.microseconds(C(e, 1e3));
|
|
1147
1203
|
}
|
|
1148
1204
|
/** A millisecond. */
|
|
1149
1205
|
static MILLISECOND = l.milliseconds(1);
|
|
@@ -1154,7 +1210,7 @@ let p = class l extends F {
|
|
|
1154
1210
|
* @returns A TimeSpan representing the given number of seconds.
|
|
1155
1211
|
*/
|
|
1156
1212
|
static seconds(e = 1) {
|
|
1157
|
-
return l.milliseconds(
|
|
1213
|
+
return l.milliseconds(C(e, 1e3));
|
|
1158
1214
|
}
|
|
1159
1215
|
/** A second. */
|
|
1160
1216
|
static SECOND = l.seconds(1);
|
|
@@ -1165,7 +1221,7 @@ let p = class l extends F {
|
|
|
1165
1221
|
* @returns A TimeSpan representing the given number of minutes.
|
|
1166
1222
|
*/
|
|
1167
1223
|
static minutes(e = 1) {
|
|
1168
|
-
return l.seconds(
|
|
1224
|
+
return l.seconds(C(e, 60));
|
|
1169
1225
|
}
|
|
1170
1226
|
/** A minute. */
|
|
1171
1227
|
static MINUTE = l.minutes(1);
|
|
@@ -1176,7 +1232,7 @@ let p = class l extends F {
|
|
|
1176
1232
|
* @returns A TimeSpan representing the given number of hours.
|
|
1177
1233
|
*/
|
|
1178
1234
|
static hours(e) {
|
|
1179
|
-
return l.minutes(
|
|
1235
|
+
return l.minutes(C(e, 60));
|
|
1180
1236
|
}
|
|
1181
1237
|
/** Represents an hour. */
|
|
1182
1238
|
static HOUR = l.hours(1);
|
|
@@ -1187,30 +1243,30 @@ let p = class l extends F {
|
|
|
1187
1243
|
* @returns A TimeSpan representing the given number of days.
|
|
1188
1244
|
*/
|
|
1189
1245
|
static days(e) {
|
|
1190
|
-
return l.hours(
|
|
1246
|
+
return l.hours(C(e, 24));
|
|
1191
1247
|
}
|
|
1192
1248
|
/** Represents a day. */
|
|
1193
1249
|
static DAY = l.days(1);
|
|
1194
1250
|
/** The maximum possible value for a TimeSpan. */
|
|
1195
|
-
static MAX = new l(
|
|
1251
|
+
static MAX = new l(he);
|
|
1196
1252
|
/** The minimum possible value for a TimeSpan. */
|
|
1197
1253
|
static MIN = new l(0);
|
|
1198
1254
|
/** The zero value for a TimeSpan. */
|
|
1199
1255
|
static ZERO = new l(0);
|
|
1200
|
-
/** A zod schema for validating and transforming
|
|
1256
|
+
/** A zod schema for validating and transforming time spans */
|
|
1201
1257
|
static z = s.union([
|
|
1202
1258
|
s.object({ value: s.bigint() }).transform((e) => new l(e.value)),
|
|
1203
1259
|
s.string().transform((e) => new l(BigInt(e))),
|
|
1204
1260
|
s.number().transform((e) => new l(e)),
|
|
1205
1261
|
s.bigint().transform((e) => new l(e)),
|
|
1206
1262
|
s.instanceof(l),
|
|
1207
|
-
s.instanceof(
|
|
1208
|
-
s.custom((e) => e instanceof
|
|
1263
|
+
s.instanceof(u).transform((e) => new l(e)),
|
|
1264
|
+
s.custom((e) => e instanceof E).transform((e) => new l(e))
|
|
1209
1265
|
]);
|
|
1210
|
-
}
|
|
1211
|
-
class
|
|
1266
|
+
}
|
|
1267
|
+
class E extends Z {
|
|
1212
1268
|
constructor(e) {
|
|
1213
|
-
|
|
1269
|
+
A(e) && (e = e.value), super(e.valueOf());
|
|
1214
1270
|
}
|
|
1215
1271
|
/** @returns a pretty string representation of the rate in the format "X Hz". */
|
|
1216
1272
|
toString() {
|
|
@@ -1218,7 +1274,7 @@ class S extends F {
|
|
|
1218
1274
|
}
|
|
1219
1275
|
/** @returns The number of seconds in the Rate. */
|
|
1220
1276
|
equals(e) {
|
|
1221
|
-
return this.valueOf() === new
|
|
1277
|
+
return this.valueOf() === new E(e).valueOf();
|
|
1222
1278
|
}
|
|
1223
1279
|
/**
|
|
1224
1280
|
* Calculates the period of the Rate as a TimeSpan.
|
|
@@ -1226,7 +1282,7 @@ class S extends F {
|
|
|
1226
1282
|
* @returns A TimeSpan representing the period of the Rate.
|
|
1227
1283
|
*/
|
|
1228
1284
|
get period() {
|
|
1229
|
-
return
|
|
1285
|
+
return l.seconds(1 / this.valueOf());
|
|
1230
1286
|
}
|
|
1231
1287
|
/**
|
|
1232
1288
|
* Calculates the number of samples in the given TimeSpan at this rate.
|
|
@@ -1235,7 +1291,7 @@ class S extends F {
|
|
|
1235
1291
|
* @returns The number of samples in the given TimeSpan at this rate.
|
|
1236
1292
|
*/
|
|
1237
1293
|
sampleCount(e) {
|
|
1238
|
-
return new
|
|
1294
|
+
return new l(e).seconds * this.valueOf();
|
|
1239
1295
|
}
|
|
1240
1296
|
/**
|
|
1241
1297
|
* Calculates the number of bytes in the given TimeSpan at this rate.
|
|
@@ -1254,7 +1310,7 @@ class S extends F {
|
|
|
1254
1310
|
* @returns A TimeSpan that corresponds to the given number of samples.
|
|
1255
1311
|
*/
|
|
1256
1312
|
span(e) {
|
|
1257
|
-
return
|
|
1313
|
+
return l.seconds(e / this.valueOf());
|
|
1258
1314
|
}
|
|
1259
1315
|
/**
|
|
1260
1316
|
* Calculates a TimeSpan given the number of bytes at this rate.
|
|
@@ -1273,7 +1329,7 @@ class S extends F {
|
|
|
1273
1329
|
* @returns A new Rate representing the sum of the two rates.
|
|
1274
1330
|
*/
|
|
1275
1331
|
add(e) {
|
|
1276
|
-
return new
|
|
1332
|
+
return new E(se(this.valueOf(), new E(e).valueOf()));
|
|
1277
1333
|
}
|
|
1278
1334
|
/**
|
|
1279
1335
|
* Subtracts another Rate from this Rate.
|
|
@@ -1282,7 +1338,7 @@ class S extends F {
|
|
|
1282
1338
|
* @returns A new Rate representing the difference of the two rates.
|
|
1283
1339
|
*/
|
|
1284
1340
|
sub(e) {
|
|
1285
|
-
return new
|
|
1341
|
+
return new E(re(this.valueOf(), new E(e).valueOf()));
|
|
1286
1342
|
}
|
|
1287
1343
|
/**
|
|
1288
1344
|
* Multiplies this Rate by a scalar value.
|
|
@@ -1291,7 +1347,7 @@ class S extends F {
|
|
|
1291
1347
|
* @returns A new Rate representing this Rate multiplied by the value.
|
|
1292
1348
|
*/
|
|
1293
1349
|
mult(e) {
|
|
1294
|
-
return new
|
|
1350
|
+
return new E(C(this.valueOf(), e));
|
|
1295
1351
|
}
|
|
1296
1352
|
/**
|
|
1297
1353
|
* Divides this Rate by a scalar value.
|
|
@@ -1300,7 +1356,7 @@ class S extends F {
|
|
|
1300
1356
|
* @returns A new Rate representing this Rate divided by the value.
|
|
1301
1357
|
*/
|
|
1302
1358
|
div(e) {
|
|
1303
|
-
return new
|
|
1359
|
+
return new E(ie(this.valueOf(), e));
|
|
1304
1360
|
}
|
|
1305
1361
|
/**
|
|
1306
1362
|
* Creates a Rate representing the given number of Hz.
|
|
@@ -1309,7 +1365,7 @@ class S extends F {
|
|
|
1309
1365
|
* @returns A Rate representing the given number of Hz.
|
|
1310
1366
|
*/
|
|
1311
1367
|
static hz(e) {
|
|
1312
|
-
return new
|
|
1368
|
+
return new E(e);
|
|
1313
1369
|
}
|
|
1314
1370
|
/**
|
|
1315
1371
|
* Creates a Rate representing the given number of kHz.
|
|
@@ -1318,15 +1374,15 @@ class S extends F {
|
|
|
1318
1374
|
* @returns A Rate representing the given number of kHz.
|
|
1319
1375
|
*/
|
|
1320
1376
|
static khz(e) {
|
|
1321
|
-
return
|
|
1377
|
+
return E.hz(e * 1e3);
|
|
1322
1378
|
}
|
|
1323
1379
|
/** A zod schema for validating and transforming rates */
|
|
1324
1380
|
static z = s.union([
|
|
1325
|
-
s.number().transform((e) => new
|
|
1326
|
-
s.instanceof(
|
|
1381
|
+
s.number().transform((e) => new E(e)),
|
|
1382
|
+
s.instanceof(E)
|
|
1327
1383
|
]);
|
|
1328
1384
|
}
|
|
1329
|
-
let I = class N extends
|
|
1385
|
+
let I = class N extends Z {
|
|
1330
1386
|
/**
|
|
1331
1387
|
* Creates a Density representing the given number of bytes per value.
|
|
1332
1388
|
*
|
|
@@ -1335,7 +1391,7 @@ let I = class N extends F {
|
|
|
1335
1391
|
* @returns A Density representing the given number of bytes per value.
|
|
1336
1392
|
*/
|
|
1337
1393
|
constructor(e) {
|
|
1338
|
-
|
|
1394
|
+
A(e) && (e = e.value), super(e.valueOf());
|
|
1339
1395
|
}
|
|
1340
1396
|
/**
|
|
1341
1397
|
* Calculates the number of values in the given Size.
|
|
@@ -1353,7 +1409,7 @@ let I = class N extends F {
|
|
|
1353
1409
|
* @returns A Size representing the given number of values.
|
|
1354
1410
|
*/
|
|
1355
1411
|
size(e) {
|
|
1356
|
-
return new
|
|
1412
|
+
return new fe(e * this.valueOf());
|
|
1357
1413
|
}
|
|
1358
1414
|
/**
|
|
1359
1415
|
* Adds another Density to this Density.
|
|
@@ -1362,7 +1418,7 @@ let I = class N extends F {
|
|
|
1362
1418
|
* @returns A new Density representing the sum of the two densities.
|
|
1363
1419
|
*/
|
|
1364
1420
|
add(e) {
|
|
1365
|
-
return new N(
|
|
1421
|
+
return new N(se(this.valueOf(), new N(e).valueOf()));
|
|
1366
1422
|
}
|
|
1367
1423
|
/**
|
|
1368
1424
|
* Subtracts another Density from this Density.
|
|
@@ -1371,7 +1427,7 @@ let I = class N extends F {
|
|
|
1371
1427
|
* @returns A new Density representing the difference of the two densities.
|
|
1372
1428
|
*/
|
|
1373
1429
|
sub(e) {
|
|
1374
|
-
return new N(
|
|
1430
|
+
return new N(re(this.valueOf(), new N(e).valueOf()));
|
|
1375
1431
|
}
|
|
1376
1432
|
/**
|
|
1377
1433
|
* Multiplies this Density by a scalar value.
|
|
@@ -1380,7 +1436,7 @@ let I = class N extends F {
|
|
|
1380
1436
|
* @returns A new Density representing this Density multiplied by the value.
|
|
1381
1437
|
*/
|
|
1382
1438
|
mult(e) {
|
|
1383
|
-
return new N(
|
|
1439
|
+
return new N(C(this.valueOf(), e));
|
|
1384
1440
|
}
|
|
1385
1441
|
/**
|
|
1386
1442
|
* Divides this Density by a scalar value.
|
|
@@ -1389,7 +1445,7 @@ let I = class N extends F {
|
|
|
1389
1445
|
* @returns A new Density representing this Density divided by the value.
|
|
1390
1446
|
*/
|
|
1391
1447
|
div(e) {
|
|
1392
|
-
return new N(
|
|
1448
|
+
return new N(ie(this.valueOf(), e));
|
|
1393
1449
|
}
|
|
1394
1450
|
/** Unknown/Invalid Density. */
|
|
1395
1451
|
static UNKNOWN = new N(0);
|
|
@@ -1408,7 +1464,7 @@ let I = class N extends F {
|
|
|
1408
1464
|
s.number().transform((e) => new N(e)),
|
|
1409
1465
|
s.instanceof(N)
|
|
1410
1466
|
]);
|
|
1411
|
-
},
|
|
1467
|
+
}, G = class $ {
|
|
1412
1468
|
/**
|
|
1413
1469
|
* The starting TimeStamp of the TimeRange.
|
|
1414
1470
|
*
|
|
@@ -1434,11 +1490,11 @@ let I = class N extends F {
|
|
|
1434
1490
|
* @param end - A TimeStamp representing the end of the range.
|
|
1435
1491
|
*/
|
|
1436
1492
|
constructor(e, t) {
|
|
1437
|
-
typeof e == "object" && "start" in e ? (this.start = new
|
|
1493
|
+
typeof e == "object" && "start" in e ? (this.start = new u(e.start), this.end = new u(e.end)) : (this.start = new u(e), this.end = new u(t));
|
|
1438
1494
|
}
|
|
1439
1495
|
/** @returns The TimeSpan occupied by the TimeRange. */
|
|
1440
1496
|
get span() {
|
|
1441
|
-
return new
|
|
1497
|
+
return new l(this.end.valueOf() - this.start.valueOf());
|
|
1442
1498
|
}
|
|
1443
1499
|
/**
|
|
1444
1500
|
* Checks if the timestamp is valid i.e. the start is before the end.
|
|
@@ -1457,12 +1513,12 @@ let I = class N extends F {
|
|
|
1457
1513
|
return this.isValid ? this : this.swap();
|
|
1458
1514
|
}
|
|
1459
1515
|
/**
|
|
1460
|
-
* Checks if the TimeRange
|
|
1516
|
+
* Checks if the TimeRange is zero (both start and end are TimeStamp.ZERO).
|
|
1461
1517
|
*
|
|
1462
|
-
* @returns True if
|
|
1518
|
+
* @returns True if both start and end are TimeStamp.ZERO, false otherwise.
|
|
1463
1519
|
*/
|
|
1464
1520
|
get isZero() {
|
|
1465
|
-
return this.
|
|
1521
|
+
return this.start.isZero && this.end.isZero;
|
|
1466
1522
|
}
|
|
1467
1523
|
/**
|
|
1468
1524
|
* @returns the TimeRange as a numeric object with start and end properties.
|
|
@@ -1476,7 +1532,7 @@ let I = class N extends F {
|
|
|
1476
1532
|
* @returns A TimeRange with the start and end swapped.
|
|
1477
1533
|
*/
|
|
1478
1534
|
swap() {
|
|
1479
|
-
return new
|
|
1535
|
+
return new $(this.end, this.start);
|
|
1480
1536
|
}
|
|
1481
1537
|
get numericBounds() {
|
|
1482
1538
|
return {
|
|
@@ -1490,7 +1546,7 @@ let I = class N extends F {
|
|
|
1490
1546
|
* @param other - The TimeRange to compare to.
|
|
1491
1547
|
* @returns True if the TimeRange is equal to the given TimeRange.
|
|
1492
1548
|
*/
|
|
1493
|
-
equals(e, t =
|
|
1549
|
+
equals(e, t = l.ZERO) {
|
|
1494
1550
|
if (t.isZero)
|
|
1495
1551
|
return this.start.equals(e.start) && this.end.equals(e.end);
|
|
1496
1552
|
let r = this.start.sub(e.start).valueOf(), i = this.end.sub(e.end).valueOf();
|
|
@@ -1510,7 +1566,7 @@ let I = class N extends F {
|
|
|
1510
1566
|
* @returns A pretty string representation of the TimeRange.
|
|
1511
1567
|
*/
|
|
1512
1568
|
toPrettyString() {
|
|
1513
|
-
return `${this.start.
|
|
1569
|
+
return `${this.start.toString("preciseDate")} - ${this.span.toString()}`;
|
|
1514
1570
|
}
|
|
1515
1571
|
/**
|
|
1516
1572
|
* Checks if the two time ranges overlap. If the two time ranges are equal, returns
|
|
@@ -1523,16 +1579,16 @@ let I = class N extends F {
|
|
|
1523
1579
|
* checking for overlap.
|
|
1524
1580
|
* @returns True if the two TimeRanges overlap, false otherwise.
|
|
1525
1581
|
*/
|
|
1526
|
-
overlapsWith(e, t =
|
|
1582
|
+
overlapsWith(e, t = l.ZERO) {
|
|
1527
1583
|
e = e.makeValid();
|
|
1528
1584
|
const r = this.makeValid();
|
|
1529
1585
|
if (this.equals(e)) return !0;
|
|
1530
1586
|
if (e.end.equals(r.start) || r.end.equals(e.start)) return !1;
|
|
1531
|
-
const i =
|
|
1532
|
-
return a.before(i) ? !1 : new
|
|
1587
|
+
const i = u.max(r.start, e.start), a = u.min(r.end, e.end);
|
|
1588
|
+
return a.before(i) ? !1 : new l(a.sub(i)).greaterThanOrEqual(t);
|
|
1533
1589
|
}
|
|
1534
1590
|
contains(e) {
|
|
1535
|
-
return e instanceof
|
|
1591
|
+
return e instanceof $ ? this.contains(e.start) && this.contains(e.end) : this.start.beforeEq(e) && this.end.after(e);
|
|
1536
1592
|
}
|
|
1537
1593
|
/**
|
|
1538
1594
|
* Returns a new TimeRange that is bound by the given TimeRange.
|
|
@@ -1546,25 +1602,23 @@ let I = class N extends F {
|
|
|
1546
1602
|
* console.log(bounded); // TimeRange(1500, 2000)
|
|
1547
1603
|
*/
|
|
1548
1604
|
boundBy(e) {
|
|
1549
|
-
const t = new
|
|
1605
|
+
const t = new $(this.start, this.end);
|
|
1550
1606
|
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;
|
|
1551
1607
|
}
|
|
1552
1608
|
static max(...e) {
|
|
1553
|
-
return new
|
|
1554
|
-
|
|
1555
|
-
|
|
1609
|
+
return new $(
|
|
1610
|
+
u.min(...e.map((t) => t.start)),
|
|
1611
|
+
u.max(...e.map((t) => t.end))
|
|
1556
1612
|
);
|
|
1557
1613
|
}
|
|
1558
1614
|
/** The maximum possible time range. */
|
|
1559
|
-
static MAX = new
|
|
1560
|
-
/** The minimum possible time range. */
|
|
1561
|
-
static MIN = new x(o.MAX, o.MIN);
|
|
1615
|
+
static MAX = new $(u.MIN, u.MAX);
|
|
1562
1616
|
/** A time range whose start and end are both zero. */
|
|
1563
|
-
static ZERO = new
|
|
1617
|
+
static ZERO = new $(u.ZERO, u.ZERO);
|
|
1564
1618
|
/** A zod schema for validating and transforming time ranges */
|
|
1565
1619
|
static z = s.union([
|
|
1566
|
-
s.object({ start:
|
|
1567
|
-
s.instanceof(
|
|
1620
|
+
s.object({ start: u.z, end: u.z }).transform((e) => new $(e.start, e.end)),
|
|
1621
|
+
s.instanceof($)
|
|
1568
1622
|
]);
|
|
1569
1623
|
/**
|
|
1570
1624
|
* Sorts two time ranges. The range with the earlier start time is considered less than
|
|
@@ -1578,7 +1632,7 @@ let I = class N extends F {
|
|
|
1578
1632
|
* equal.
|
|
1579
1633
|
*/
|
|
1580
1634
|
static sort(e, t) {
|
|
1581
|
-
return
|
|
1635
|
+
return u.sort(e.start, t.start) || u.sort(e.end, t.end);
|
|
1582
1636
|
}
|
|
1583
1637
|
/**
|
|
1584
1638
|
* Simplify takes the list of `TimeRange`s, makes all of them valid, sorts them, and
|
|
@@ -1588,20 +1642,20 @@ let I = class N extends F {
|
|
|
1588
1642
|
* @returns A list of simplified `TimeRange`s.
|
|
1589
1643
|
*/
|
|
1590
1644
|
static simplify(e) {
|
|
1591
|
-
return e.map((t) => t.makeValid()).sort((t, r) =>
|
|
1592
|
-
if (r.isZero) return t;
|
|
1645
|
+
return e.map((t) => t.makeValid()).sort((t, r) => $.sort(t, r)).reduce((t, r) => {
|
|
1646
|
+
if (r.span.isZero) return t;
|
|
1593
1647
|
if (t.length === 0)
|
|
1594
1648
|
return t.push(r), t;
|
|
1595
1649
|
const i = t[t.length - 1];
|
|
1596
|
-
return i.overlapsWith(r) || i.end.equals(r.start) ? i.end =
|
|
1650
|
+
return i.overlapsWith(r) || i.end.equals(r.start) ? i.end = u.max(i.end, r.end) : t.push(r), t;
|
|
1597
1651
|
}, []);
|
|
1598
1652
|
}
|
|
1599
|
-
},
|
|
1653
|
+
}, O = class o extends Z {
|
|
1600
1654
|
constructor(e) {
|
|
1601
|
-
if (
|
|
1655
|
+
if (A(e) && (e = e.value), e instanceof o || typeof e == "string" || typeof e.valueOf() == "string")
|
|
1602
1656
|
super(e.valueOf());
|
|
1603
1657
|
else {
|
|
1604
|
-
const t =
|
|
1658
|
+
const t = o.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);
|
|
1605
1659
|
if (t == null)
|
|
1606
1660
|
throw new Error(`unable to find data type for ${e.toString()}`);
|
|
1607
1661
|
super(t.valueOf());
|
|
@@ -1611,7 +1665,7 @@ let I = class N extends F {
|
|
|
1611
1665
|
* @returns the TypedArray constructor for the DataType.
|
|
1612
1666
|
*/
|
|
1613
1667
|
get Array() {
|
|
1614
|
-
const e =
|
|
1668
|
+
const e = o.ARRAY_CONSTRUCTORS.get(this.toString());
|
|
1615
1669
|
if (e == null)
|
|
1616
1670
|
throw new Error(`unable to find array constructor for ${this.valueOf()}`);
|
|
1617
1671
|
return e;
|
|
@@ -1628,9 +1682,10 @@ let I = class N extends F {
|
|
|
1628
1682
|
matches(...e) {
|
|
1629
1683
|
return e.some((t) => this.equals(t));
|
|
1630
1684
|
}
|
|
1631
|
-
/** @returns a string representation of the DataType.
|
|
1632
|
-
|
|
1633
|
-
|
|
1685
|
+
/** @returns a string representation of the DataType. If short is true, a 1-4
|
|
1686
|
+
* character representation (i64, str, etc.) is returned instead. */
|
|
1687
|
+
toString(e = !1) {
|
|
1688
|
+
return e ? o.SHORT_STRINGS.get(this.valueOf()) ?? this.valueOf() : this.valueOf();
|
|
1634
1689
|
}
|
|
1635
1690
|
/**
|
|
1636
1691
|
* @returns true if the DataType has a variable density.
|
|
@@ -1638,7 +1693,7 @@ let I = class N extends F {
|
|
|
1638
1693
|
* @example DataType.INT32.isVariable // false
|
|
1639
1694
|
*/
|
|
1640
1695
|
get isVariable() {
|
|
1641
|
-
return this.equals(
|
|
1696
|
+
return this.equals(o.JSON) || this.equals(o.STRING);
|
|
1642
1697
|
}
|
|
1643
1698
|
/**
|
|
1644
1699
|
* @returns true if the DataType is numeric.
|
|
@@ -1646,7 +1701,7 @@ let I = class N extends F {
|
|
|
1646
1701
|
* @example DataType.STRING.isNumeric // false
|
|
1647
1702
|
*/
|
|
1648
1703
|
get isNumeric() {
|
|
1649
|
-
return !this.isVariable && !this.equals(
|
|
1704
|
+
return !this.isVariable && !this.equals(o.UUID);
|
|
1650
1705
|
}
|
|
1651
1706
|
/**
|
|
1652
1707
|
* @returns true if the DataType is an integer.
|
|
@@ -1671,7 +1726,7 @@ let I = class N extends F {
|
|
|
1671
1726
|
* @example DataType.FLOAT32.density // Density.BIT32
|
|
1672
1727
|
*/
|
|
1673
1728
|
get density() {
|
|
1674
|
-
const e =
|
|
1729
|
+
const e = o.DENSITIES.get(this.toString());
|
|
1675
1730
|
if (e == null) throw new Error(`unable to find density for ${this.valueOf()}`);
|
|
1676
1731
|
return e;
|
|
1677
1732
|
}
|
|
@@ -1681,7 +1736,7 @@ let I = class N extends F {
|
|
|
1681
1736
|
* @example DataType.INT32.isUnsigned // false
|
|
1682
1737
|
*/
|
|
1683
1738
|
get isUnsignedInteger() {
|
|
1684
|
-
return this.equals(
|
|
1739
|
+
return this.equals(o.UINT8) || this.equals(o.UINT16) || this.equals(o.UINT32) || this.equals(o.UINT64);
|
|
1685
1740
|
}
|
|
1686
1741
|
/**
|
|
1687
1742
|
* @returns true if the DataType is a signed integer.
|
|
@@ -1689,11 +1744,11 @@ let I = class N extends F {
|
|
|
1689
1744
|
* @example DataType.UINT32.isSigned // false
|
|
1690
1745
|
*/
|
|
1691
1746
|
get isSignedInteger() {
|
|
1692
|
-
return this.equals(
|
|
1747
|
+
return this.equals(o.INT8) || this.equals(o.INT16) || this.equals(o.INT32) || this.equals(o.INT64);
|
|
1693
1748
|
}
|
|
1694
1749
|
/** @returns true if the data type can be cast to the other data type without loss of precision. */
|
|
1695
1750
|
canSafelyCastTo(e) {
|
|
1696
|
-
return this.equals(e) ? !0 : !this.isNumeric || !e.isNumeric || this.isVariable || e.isVariable || this.isUnsignedInteger && e.isSignedInteger ? !1 : this.isFloat ? e.isFloat && this.density.valueOf() <= e.density.valueOf() : this.equals(
|
|
1751
|
+
return this.equals(e) ? !0 : !this.isNumeric || !e.isNumeric || this.isVariable || e.isVariable || this.isUnsignedInteger && e.isSignedInteger ? !1 : this.isFloat ? e.isFloat && this.density.valueOf() <= e.density.valueOf() : this.equals(o.INT32) && e.equals(o.FLOAT64) || this.equals(o.INT8) && e.equals(o.FLOAT32) ? !0 : this.isInteger && e.isInteger ? this.density.valueOf() <= e.density.valueOf() && this.isUnsignedInteger === e.isUnsignedInteger : !1;
|
|
1697
1752
|
}
|
|
1698
1753
|
/** @returns true if the data type can be cast to the other data type, even if there is a loss of precision. */
|
|
1699
1754
|
canCastTo(e) {
|
|
@@ -1710,129 +1765,146 @@ let I = class N extends F {
|
|
|
1710
1765
|
}
|
|
1711
1766
|
/** @returns true if the data type uses bigints to store values. */
|
|
1712
1767
|
get usesBigInt() {
|
|
1713
|
-
return
|
|
1768
|
+
return o.BIG_INT_TYPES.some((e) => e.equals(this));
|
|
1714
1769
|
}
|
|
1715
1770
|
/** Represents an Unknown/Invalid DataType. */
|
|
1716
|
-
static UNKNOWN = new
|
|
1771
|
+
static UNKNOWN = new o("unknown");
|
|
1717
1772
|
/** Represents a 64-bit floating point value. */
|
|
1718
|
-
static FLOAT64 = new
|
|
1773
|
+
static FLOAT64 = new o("float64");
|
|
1719
1774
|
/** Represents a 32-bit floating point value. */
|
|
1720
|
-
static FLOAT32 = new
|
|
1775
|
+
static FLOAT32 = new o("float32");
|
|
1721
1776
|
/** Represents a 64-bit signed integer value. */
|
|
1722
|
-
static INT64 = new
|
|
1777
|
+
static INT64 = new o("int64");
|
|
1723
1778
|
/** Represents a 32-bit signed integer value. */
|
|
1724
|
-
static INT32 = new
|
|
1779
|
+
static INT32 = new o("int32");
|
|
1725
1780
|
/** Represents a 16-bit signed integer value. */
|
|
1726
|
-
static INT16 = new
|
|
1781
|
+
static INT16 = new o("int16");
|
|
1727
1782
|
/** Represents a 8-bit signed integer value. */
|
|
1728
|
-
static INT8 = new
|
|
1783
|
+
static INT8 = new o("int8");
|
|
1729
1784
|
/** Represents a 64-bit unsigned integer value. */
|
|
1730
|
-
static UINT64 = new
|
|
1785
|
+
static UINT64 = new o("uint64");
|
|
1731
1786
|
/** Represents a 32-bit unsigned integer value. */
|
|
1732
|
-
static UINT32 = new
|
|
1787
|
+
static UINT32 = new o("uint32");
|
|
1733
1788
|
/** Represents a 16-bit unsigned integer value. */
|
|
1734
|
-
static UINT16 = new
|
|
1789
|
+
static UINT16 = new o("uint16");
|
|
1735
1790
|
/** Represents a 8-bit unsigned integer value. */
|
|
1736
|
-
static UINT8 = new
|
|
1737
|
-
/** Represents a boolean value.
|
|
1738
|
-
static BOOLEAN =
|
|
1791
|
+
static UINT8 = new o("uint8");
|
|
1792
|
+
/** Represents a boolean value. Stored as a 8-bit unsigned integer. */
|
|
1793
|
+
static BOOLEAN = new o("boolean");
|
|
1739
1794
|
/** Represents a 64-bit unix epoch. */
|
|
1740
|
-
static TIMESTAMP = new
|
|
1741
|
-
/** Represents a UUID data type */
|
|
1742
|
-
static UUID = new
|
|
1795
|
+
static TIMESTAMP = new o("timestamp");
|
|
1796
|
+
/** Represents a UUID data type. */
|
|
1797
|
+
static UUID = new o("uuid");
|
|
1743
1798
|
/** Represents a string data type. Strings have an unknown density, and are separate
|
|
1744
1799
|
* by a newline character. */
|
|
1745
|
-
static STRING = new
|
|
1800
|
+
static STRING = new o("string");
|
|
1746
1801
|
/** Represents a JSON data type. JSON has an unknown density, and is separated by a
|
|
1747
1802
|
* newline character. */
|
|
1748
|
-
static JSON = new
|
|
1803
|
+
static JSON = new o("json");
|
|
1749
1804
|
static ARRAY_CONSTRUCTORS = /* @__PURE__ */ new Map([
|
|
1750
|
-
[
|
|
1751
|
-
[
|
|
1752
|
-
[
|
|
1753
|
-
[
|
|
1754
|
-
[
|
|
1755
|
-
[
|
|
1756
|
-
[
|
|
1757
|
-
[
|
|
1758
|
-
[
|
|
1759
|
-
[
|
|
1760
|
-
[
|
|
1761
|
-
[
|
|
1762
|
-
[
|
|
1763
|
-
[
|
|
1805
|
+
[o.UINT8.toString(), Uint8Array],
|
|
1806
|
+
[o.UINT16.toString(), Uint16Array],
|
|
1807
|
+
[o.UINT32.toString(), Uint32Array],
|
|
1808
|
+
[o.UINT64.toString(), BigUint64Array],
|
|
1809
|
+
[o.FLOAT32.toString(), Float32Array],
|
|
1810
|
+
[o.FLOAT64.toString(), Float64Array],
|
|
1811
|
+
[o.INT8.toString(), Int8Array],
|
|
1812
|
+
[o.INT16.toString(), Int16Array],
|
|
1813
|
+
[o.INT32.toString(), Int32Array],
|
|
1814
|
+
[o.INT64.toString(), BigInt64Array],
|
|
1815
|
+
[o.TIMESTAMP.toString(), BigInt64Array],
|
|
1816
|
+
[o.STRING.toString(), Uint8Array],
|
|
1817
|
+
[o.JSON.toString(), Uint8Array],
|
|
1818
|
+
[o.UUID.toString(), Uint8Array]
|
|
1764
1819
|
]);
|
|
1765
1820
|
static ARRAY_CONSTRUCTOR_DATA_TYPES = /* @__PURE__ */ new Map([
|
|
1766
|
-
[Uint8Array.name,
|
|
1767
|
-
[Uint16Array.name,
|
|
1768
|
-
[Uint32Array.name,
|
|
1769
|
-
[BigUint64Array.name,
|
|
1770
|
-
[Float32Array.name,
|
|
1771
|
-
[Float64Array.name,
|
|
1772
|
-
[Int8Array.name,
|
|
1773
|
-
[Int16Array.name,
|
|
1774
|
-
[Int32Array.name,
|
|
1775
|
-
[BigInt64Array.name,
|
|
1821
|
+
[Uint8Array.name, o.UINT8],
|
|
1822
|
+
[Uint16Array.name, o.UINT16],
|
|
1823
|
+
[Uint32Array.name, o.UINT32],
|
|
1824
|
+
[BigUint64Array.name, o.UINT64],
|
|
1825
|
+
[Float32Array.name, o.FLOAT32],
|
|
1826
|
+
[Float64Array.name, o.FLOAT64],
|
|
1827
|
+
[Int8Array.name, o.INT8],
|
|
1828
|
+
[Int16Array.name, o.INT16],
|
|
1829
|
+
[Int32Array.name, o.INT32],
|
|
1830
|
+
[BigInt64Array.name, o.INT64]
|
|
1776
1831
|
]);
|
|
1777
1832
|
static DENSITIES = /* @__PURE__ */ new Map([
|
|
1778
|
-
[
|
|
1779
|
-
[
|
|
1780
|
-
[
|
|
1781
|
-
[
|
|
1782
|
-
[
|
|
1783
|
-
[
|
|
1784
|
-
[
|
|
1785
|
-
[
|
|
1786
|
-
[
|
|
1787
|
-
[
|
|
1788
|
-
[
|
|
1789
|
-
[
|
|
1790
|
-
[
|
|
1791
|
-
[
|
|
1833
|
+
[o.UINT8.toString(), I.BIT8],
|
|
1834
|
+
[o.UINT16.toString(), I.BIT16],
|
|
1835
|
+
[o.UINT32.toString(), I.BIT32],
|
|
1836
|
+
[o.UINT64.toString(), I.BIT64],
|
|
1837
|
+
[o.FLOAT32.toString(), I.BIT32],
|
|
1838
|
+
[o.FLOAT64.toString(), I.BIT64],
|
|
1839
|
+
[o.INT8.toString(), I.BIT8],
|
|
1840
|
+
[o.INT16.toString(), I.BIT16],
|
|
1841
|
+
[o.INT32.toString(), I.BIT32],
|
|
1842
|
+
[o.INT64.toString(), I.BIT64],
|
|
1843
|
+
[o.TIMESTAMP.toString(), I.BIT64],
|
|
1844
|
+
[o.STRING.toString(), I.UNKNOWN],
|
|
1845
|
+
[o.JSON.toString(), I.UNKNOWN],
|
|
1846
|
+
[o.UUID.toString(), I.BIT128]
|
|
1792
1847
|
]);
|
|
1793
1848
|
/** All the data types. */
|
|
1794
1849
|
static ALL = [
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1850
|
+
o.UNKNOWN,
|
|
1851
|
+
o.FLOAT64,
|
|
1852
|
+
o.FLOAT32,
|
|
1853
|
+
o.INT64,
|
|
1854
|
+
o.INT32,
|
|
1855
|
+
o.INT16,
|
|
1856
|
+
o.INT8,
|
|
1857
|
+
o.UINT64,
|
|
1858
|
+
o.UINT32,
|
|
1859
|
+
o.UINT16,
|
|
1860
|
+
o.UINT8,
|
|
1861
|
+
o.TIMESTAMP,
|
|
1862
|
+
o.UUID,
|
|
1863
|
+
o.STRING,
|
|
1864
|
+
o.JSON
|
|
1810
1865
|
];
|
|
1811
|
-
static
|
|
1866
|
+
static SHORT_STRINGS = /* @__PURE__ */ new Map([
|
|
1867
|
+
[o.UINT8.toString(), "u8"],
|
|
1868
|
+
[o.UINT16.toString(), "u16"],
|
|
1869
|
+
[o.UINT32.toString(), "u32"],
|
|
1870
|
+
[o.UINT64.toString(), "u64"],
|
|
1871
|
+
[o.INT8.toString(), "i8"],
|
|
1872
|
+
[o.INT16.toString(), "i16"],
|
|
1873
|
+
[o.INT32.toString(), "i32"],
|
|
1874
|
+
[o.INT64.toString(), "i64"],
|
|
1875
|
+
[o.FLOAT32.toString(), "f32"],
|
|
1876
|
+
[o.FLOAT64.toString(), "f64"],
|
|
1877
|
+
[o.BOOLEAN.toString(), "bool"],
|
|
1878
|
+
[o.TIMESTAMP.toString(), "ts"],
|
|
1879
|
+
[o.UUID.toString(), "uuid"],
|
|
1880
|
+
[o.STRING.toString(), "str"],
|
|
1881
|
+
[o.JSON.toString(), "json"]
|
|
1882
|
+
]);
|
|
1883
|
+
static BIG_INT_TYPES = [o.INT64, o.UINT64, o.TIMESTAMP];
|
|
1812
1884
|
/** A zod schema for a DataType. */
|
|
1813
1885
|
static z = s.union([
|
|
1814
|
-
s.string().transform((e) => new
|
|
1815
|
-
s.instanceof(
|
|
1886
|
+
s.string().transform((e) => new o(e)),
|
|
1887
|
+
s.instanceof(o)
|
|
1816
1888
|
]);
|
|
1817
|
-
},
|
|
1889
|
+
}, fe = class p extends Z {
|
|
1818
1890
|
constructor(e) {
|
|
1819
|
-
|
|
1891
|
+
A(e) && (e = e.value), super(e.valueOf());
|
|
1820
1892
|
}
|
|
1821
1893
|
/** @returns true if the Size is larger than the other size. */
|
|
1822
1894
|
largerThan(e) {
|
|
1823
|
-
return
|
|
1895
|
+
return A(e) && (e = e.value), this.valueOf() > e.valueOf();
|
|
1824
1896
|
}
|
|
1825
1897
|
/** @returns true if the Size is smaller than the other size. */
|
|
1826
1898
|
smallerThan(e) {
|
|
1827
|
-
return
|
|
1899
|
+
return A(e) && (e = e.value), this.valueOf() < e.valueOf();
|
|
1828
1900
|
}
|
|
1829
1901
|
/** @returns a new Size representing the sum of the two Sizes. */
|
|
1830
1902
|
add(e) {
|
|
1831
|
-
return
|
|
1903
|
+
return A(e) && (e = e.value), new p(se(this.valueOf(), e.valueOf()));
|
|
1832
1904
|
}
|
|
1833
1905
|
/** @returns a new Size representing the difference of the two Sizes. */
|
|
1834
1906
|
sub(e) {
|
|
1835
|
-
return
|
|
1907
|
+
return A(e) && (e = e.value), new p(re(this.valueOf(), e.valueOf()));
|
|
1836
1908
|
}
|
|
1837
1909
|
/**
|
|
1838
1910
|
* Multiplies this Size by a scalar value.
|
|
@@ -1841,7 +1913,7 @@ let I = class N extends F {
|
|
|
1841
1913
|
* @returns A new Size representing this Size multiplied by the value.
|
|
1842
1914
|
*/
|
|
1843
1915
|
mult(e) {
|
|
1844
|
-
return new
|
|
1916
|
+
return new p(C(this.valueOf(), e));
|
|
1845
1917
|
}
|
|
1846
1918
|
/**
|
|
1847
1919
|
* Divides this Size by a scalar value.
|
|
@@ -1850,39 +1922,39 @@ let I = class N extends F {
|
|
|
1850
1922
|
* @returns A new Size representing this Size divided by the value.
|
|
1851
1923
|
*/
|
|
1852
1924
|
div(e) {
|
|
1853
|
-
return new
|
|
1925
|
+
return new p(ie(this.valueOf(), e));
|
|
1854
1926
|
}
|
|
1855
1927
|
/** @returns a new Size representing the truncated value of the Size. */
|
|
1856
1928
|
truncate(e) {
|
|
1857
|
-
return new
|
|
1858
|
-
Math.trunc(this.valueOf() / new
|
|
1929
|
+
return new p(
|
|
1930
|
+
Math.trunc(this.valueOf() / new p(e).valueOf()) * new p(e).valueOf()
|
|
1859
1931
|
);
|
|
1860
1932
|
}
|
|
1861
1933
|
/** @returns a new Size representing the remainder of the Size. */
|
|
1862
1934
|
remainder(e) {
|
|
1863
|
-
return
|
|
1935
|
+
return p.bytes(this.valueOf() % new p(e).valueOf());
|
|
1864
1936
|
}
|
|
1865
1937
|
/** @returns the number of gigabytes in the Size. */
|
|
1866
1938
|
get gigabytes() {
|
|
1867
|
-
return this.valueOf() /
|
|
1939
|
+
return this.valueOf() / p.GIGABYTE.valueOf();
|
|
1868
1940
|
}
|
|
1869
1941
|
/** @returns the number of megabytes in the Size. */
|
|
1870
1942
|
get megabytes() {
|
|
1871
|
-
return this.valueOf() /
|
|
1943
|
+
return this.valueOf() / p.MEGABYTE.valueOf();
|
|
1872
1944
|
}
|
|
1873
1945
|
/** @returns the number of kilobytes in the Size. */
|
|
1874
1946
|
get kilobytes() {
|
|
1875
|
-
return this.valueOf() /
|
|
1947
|
+
return this.valueOf() / p.KILOBYTE.valueOf();
|
|
1876
1948
|
}
|
|
1877
1949
|
/** @returns the number of terabytes in the Size. */
|
|
1878
1950
|
get terabytes() {
|
|
1879
|
-
return this.valueOf() /
|
|
1951
|
+
return this.valueOf() / p.TERABYTE.valueOf();
|
|
1880
1952
|
}
|
|
1881
1953
|
/** @returns a nicely formatted string representation of the Size. */
|
|
1882
1954
|
toString() {
|
|
1883
|
-
const e = this.truncate(
|
|
1884
|
-
let
|
|
1885
|
-
return c.isZero || (
|
|
1955
|
+
const e = this.truncate(p.TERABYTE), t = this.truncate(p.GIGABYTE), r = this.truncate(p.MEGABYTE), i = this.truncate(p.KILOBYTE), a = this.truncate(p.BYTE), c = e, d = t.sub(e), y = r.sub(t), f = i.sub(r), g = a.sub(i);
|
|
1956
|
+
let w = "";
|
|
1957
|
+
return c.isZero || (w += `${c.terabytes}TB `), d.isZero || (w += `${d.gigabytes}GB `), y.isZero || (w += `${y.megabytes}MB `), f.isZero || (w += `${f.kilobytes}KB `), (!g.isZero || w === "") && (w += `${g.valueOf()}B`), w.trim();
|
|
1886
1958
|
}
|
|
1887
1959
|
/**
|
|
1888
1960
|
* Creates a Size from the given number of bytes.
|
|
@@ -1891,10 +1963,10 @@ let I = class N extends F {
|
|
|
1891
1963
|
* @returns A Size representing the given number of bytes.
|
|
1892
1964
|
*/
|
|
1893
1965
|
static bytes(e = 1) {
|
|
1894
|
-
return new
|
|
1966
|
+
return new p(e);
|
|
1895
1967
|
}
|
|
1896
1968
|
/** A single byte */
|
|
1897
|
-
static BYTE = new
|
|
1969
|
+
static BYTE = new p(1);
|
|
1898
1970
|
/**
|
|
1899
1971
|
* Creates a Size from the given number if kilobytes.
|
|
1900
1972
|
*
|
|
@@ -1902,10 +1974,10 @@ let I = class N extends F {
|
|
|
1902
1974
|
* @returns A Size representing the given number of kilobytes.
|
|
1903
1975
|
*/
|
|
1904
1976
|
static kilobytes(e = 1) {
|
|
1905
|
-
return
|
|
1977
|
+
return p.bytes(new p(e).valueOf() * 1e3);
|
|
1906
1978
|
}
|
|
1907
1979
|
/** A kilobyte */
|
|
1908
|
-
static KILOBYTE =
|
|
1980
|
+
static KILOBYTE = p.kilobytes(1);
|
|
1909
1981
|
/**
|
|
1910
1982
|
* Creates a Size from the given number of megabytes.
|
|
1911
1983
|
*
|
|
@@ -1913,10 +1985,10 @@ let I = class N extends F {
|
|
|
1913
1985
|
* @returns A Size representing the given number of megabytes.
|
|
1914
1986
|
*/
|
|
1915
1987
|
static megabytes(e = 1) {
|
|
1916
|
-
return
|
|
1988
|
+
return p.kilobytes(new p(e).valueOf() * 1e3);
|
|
1917
1989
|
}
|
|
1918
1990
|
/** A megabyte */
|
|
1919
|
-
static MEGABYTE =
|
|
1991
|
+
static MEGABYTE = p.megabytes(1);
|
|
1920
1992
|
/**
|
|
1921
1993
|
* Creates a Size from the given number of gigabytes.
|
|
1922
1994
|
*
|
|
@@ -1924,10 +1996,10 @@ let I = class N extends F {
|
|
|
1924
1996
|
* @returns A Size representing the given number of gigabytes.
|
|
1925
1997
|
*/
|
|
1926
1998
|
static gigabytes(e = 1) {
|
|
1927
|
-
return
|
|
1999
|
+
return p.megabytes(new p(e).valueOf() * 1e3);
|
|
1928
2000
|
}
|
|
1929
2001
|
/** A gigabyte */
|
|
1930
|
-
static GIGABYTE =
|
|
2002
|
+
static GIGABYTE = p.gigabytes(1);
|
|
1931
2003
|
/**
|
|
1932
2004
|
* Creates a Size from the given number of terabytes.
|
|
1933
2005
|
*
|
|
@@ -1935,22 +2007,26 @@ let I = class N extends F {
|
|
|
1935
2007
|
* @returns A Size representing the given number of terabytes.
|
|
1936
2008
|
*/
|
|
1937
2009
|
static terabytes(e) {
|
|
1938
|
-
return
|
|
2010
|
+
return p.gigabytes(new p(e).valueOf() * 1e3);
|
|
1939
2011
|
}
|
|
1940
2012
|
/** A terabyte. */
|
|
1941
|
-
static TERABYTE =
|
|
2013
|
+
static TERABYTE = p.terabytes(1);
|
|
1942
2014
|
/** The zero value for Size */
|
|
1943
|
-
static ZERO = new
|
|
2015
|
+
static ZERO = new p(0);
|
|
1944
2016
|
/** A zod schema for a Size. */
|
|
1945
2017
|
static z = s.union([
|
|
1946
|
-
s.number().transform((e) => new
|
|
1947
|
-
s.instanceof(
|
|
2018
|
+
s.number().transform((e) => new p(e)),
|
|
2019
|
+
s.instanceof(p)
|
|
1948
2020
|
]);
|
|
1949
2021
|
/** @returns true if the Size is zero. */
|
|
1950
2022
|
get isZero() {
|
|
1951
2023
|
return this.valueOf() === 0;
|
|
1952
2024
|
}
|
|
1953
2025
|
};
|
|
2026
|
+
s.object({
|
|
2027
|
+
start: s.number(),
|
|
2028
|
+
end: s.number()
|
|
2029
|
+
});
|
|
1954
2030
|
s.union([
|
|
1955
2031
|
s.instanceof(Uint8Array),
|
|
1956
2032
|
s.instanceof(Uint16Array),
|
|
@@ -1963,37 +2039,37 @@ s.union([
|
|
|
1963
2039
|
s.instanceof(Int32Array),
|
|
1964
2040
|
s.instanceof(BigInt64Array)
|
|
1965
2041
|
]);
|
|
1966
|
-
const
|
|
2042
|
+
const Ze = (n) => {
|
|
1967
2043
|
const e = typeof n;
|
|
1968
|
-
return e === "string" || e === "number" || e === "boolean" || e === "bigint" || n instanceof
|
|
1969
|
-
},
|
|
1970
|
-
function
|
|
1971
|
-
return typeof n == "string" &&
|
|
2044
|
+
return e === "string" || e === "number" || e === "boolean" || e === "bigint" || n instanceof u || n instanceof l || n instanceof Date;
|
|
2045
|
+
}, Vt = (n, e, t, r = 0) => n.usesBigInt && !e.usesBigInt ? Number(t) - Number(r) : !n.usesBigInt && e.usesBigInt ? BigInt(t.valueOf()) - BigInt(r.valueOf()) : _(t, -r), _ = (n, e) => e == 0 ? n : n == 0 ? e : typeof n == "bigint" && typeof e == "bigint" || typeof n == "number" && typeof e == "number" ? n + e : Number(n) + Number(e), Ht = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
|
|
2046
|
+
function Jt(n) {
|
|
2047
|
+
return typeof n == "string" && Ht.test(n);
|
|
1972
2048
|
}
|
|
1973
|
-
const
|
|
2049
|
+
const S = [];
|
|
1974
2050
|
for (let n = 0; n < 256; ++n)
|
|
1975
|
-
|
|
1976
|
-
function
|
|
1977
|
-
return (
|
|
2051
|
+
S.push((n + 256).toString(16).slice(1));
|
|
2052
|
+
function Kt(n, e = 0) {
|
|
2053
|
+
return (S[n[e + 0]] + S[n[e + 1]] + S[n[e + 2]] + S[n[e + 3]] + "-" + S[n[e + 4]] + S[n[e + 5]] + "-" + S[n[e + 6]] + S[n[e + 7]] + "-" + S[n[e + 8]] + S[n[e + 9]] + "-" + S[n[e + 10]] + S[n[e + 11]] + S[n[e + 12]] + S[n[e + 13]] + S[n[e + 14]] + S[n[e + 15]]).toLowerCase();
|
|
1978
2054
|
}
|
|
1979
|
-
function
|
|
1980
|
-
const t =
|
|
1981
|
-
if (!
|
|
2055
|
+
function Xt(n, e = 0) {
|
|
2056
|
+
const t = Kt(n, e);
|
|
2057
|
+
if (!Jt(t))
|
|
1982
2058
|
throw TypeError("Stringified UUID is invalid");
|
|
1983
2059
|
return t;
|
|
1984
2060
|
}
|
|
1985
2061
|
typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
1986
|
-
const
|
|
2062
|
+
const Ge = (n, e) => Xt(n, e), R = -1, Qt = s.string().transform(
|
|
1987
2063
|
(n) => new Uint8Array(
|
|
1988
2064
|
atob(n).split("").map((e) => e.charCodeAt(0))
|
|
1989
2065
|
).buffer
|
|
1990
|
-
),
|
|
2066
|
+
), _t = s.union([s.null(), s.undefined()]).transform(() => new Uint8Array().buffer), de = 10, en = (n, e) => {
|
|
1991
2067
|
if (n === "number" && !e.isNumeric)
|
|
1992
2068
|
throw new Error(`cannot convert series of type ${e.toString()} to number`);
|
|
1993
2069
|
if (n === "bigint" && !e.usesBigInt)
|
|
1994
2070
|
throw new Error(`cannot convert series of type ${e.toString()} to bigint`);
|
|
1995
|
-
},
|
|
1996
|
-
|
|
2071
|
+
}, ze = "sy_x_telem_series";
|
|
2072
|
+
class B {
|
|
1997
2073
|
/**
|
|
1998
2074
|
* A unique identifier for the series. If specified by the user, it is their
|
|
1999
2075
|
* responsibility to ensure that it is unique. If not specified, a new ID will be
|
|
@@ -2004,7 +2080,7 @@ let qe = class B {
|
|
|
2004
2080
|
* A discriminator used for identifying instances of the series class even
|
|
2005
2081
|
* when bundlers mangle the class name.
|
|
2006
2082
|
*/
|
|
2007
|
-
discriminator =
|
|
2083
|
+
discriminator = ze;
|
|
2008
2084
|
/** The data type of the series. */
|
|
2009
2085
|
dataType;
|
|
2010
2086
|
/**
|
|
@@ -2020,7 +2096,7 @@ let qe = class B {
|
|
|
2020
2096
|
/** The underlying data. */
|
|
2021
2097
|
_data;
|
|
2022
2098
|
/** The time range occupied by the series' data. */
|
|
2023
|
-
timeRange =
|
|
2099
|
+
timeRange = G.ZERO;
|
|
2024
2100
|
/**
|
|
2025
2101
|
* Alignment defines the location of the series relative to other series in a logical
|
|
2026
2102
|
* group. Useful for defining the position of the series within a channel's data.
|
|
@@ -2037,7 +2113,7 @@ let qe = class B {
|
|
|
2037
2113
|
/** A cached maximum value. */
|
|
2038
2114
|
cachedMax;
|
|
2039
2115
|
/** The write position of the buffer. */
|
|
2040
|
-
writePos =
|
|
2116
|
+
writePos = R;
|
|
2041
2117
|
/** Tracks the number of entities currently using this array. */
|
|
2042
2118
|
_refCount = 0;
|
|
2043
2119
|
/** Caches the length of the array for variable length data types. */
|
|
@@ -2049,16 +2125,16 @@ let qe = class B {
|
|
|
2049
2125
|
* can be constructed into a series.
|
|
2050
2126
|
*/
|
|
2051
2127
|
static crudeZ = s.object({
|
|
2052
|
-
timeRange:
|
|
2053
|
-
dataType:
|
|
2128
|
+
timeRange: G.z.optional(),
|
|
2129
|
+
dataType: O.z,
|
|
2054
2130
|
alignment: s.coerce.bigint().optional(),
|
|
2055
2131
|
data: s.union([
|
|
2056
|
-
|
|
2057
|
-
|
|
2132
|
+
Qt,
|
|
2133
|
+
_t,
|
|
2058
2134
|
s.instanceof(ArrayBuffer),
|
|
2059
2135
|
s.instanceof(Uint8Array)
|
|
2060
2136
|
]),
|
|
2061
|
-
glBufferUsage:
|
|
2137
|
+
glBufferUsage: Gt.optional().default("static").optional()
|
|
2062
2138
|
});
|
|
2063
2139
|
/**
|
|
2064
2140
|
* A zod schema that validates and constructs a series from it's crude
|
|
@@ -2139,70 +2215,70 @@ let qe = class B {
|
|
|
2139
2215
|
* @throws Error if data type cannot be inferred from input
|
|
2140
2216
|
*/
|
|
2141
2217
|
constructor(e) {
|
|
2142
|
-
|
|
2218
|
+
tn(e) && (e = { data: e }), e.data ??= [];
|
|
2143
2219
|
const {
|
|
2144
2220
|
dataType: t,
|
|
2145
2221
|
timeRange: r,
|
|
2146
2222
|
sampleOffset: i = 0,
|
|
2147
2223
|
glBufferUsage: a = "static",
|
|
2148
2224
|
alignment: c = 0n,
|
|
2149
|
-
alignmentMultiple:
|
|
2150
|
-
key: y =
|
|
2225
|
+
alignmentMultiple: d = 1n,
|
|
2226
|
+
key: y = Ft(),
|
|
2151
2227
|
data: f
|
|
2152
2228
|
} = e;
|
|
2153
|
-
if (
|
|
2229
|
+
if (nn(f)) {
|
|
2154
2230
|
const h = f;
|
|
2155
2231
|
this.key = h.key, this.dataType = h.dataType, this.sampleOffset = h.sampleOffset, this.gl = h.gl, this._data = h._data, this.timeRange = h.timeRange, this.alignment = h.alignment, this.alignmentMultiple = h.alignmentMultiple, this.cachedMin = h.cachedMin, this.cachedMax = h.cachedMax, this.writePos = h.writePos, this._refCount = h._refCount, this.cachedLength = h.cachedLength;
|
|
2156
2232
|
return;
|
|
2157
2233
|
}
|
|
2158
|
-
const
|
|
2159
|
-
if (t != null) this.dataType = new
|
|
2234
|
+
const g = Ze(f), w = Array.isArray(f);
|
|
2235
|
+
if (t != null) this.dataType = new O(t);
|
|
2160
2236
|
else {
|
|
2161
2237
|
if (f instanceof ArrayBuffer)
|
|
2162
2238
|
throw new Error(
|
|
2163
2239
|
"cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type."
|
|
2164
2240
|
);
|
|
2165
|
-
if (
|
|
2241
|
+
if (w || g) {
|
|
2166
2242
|
let h = f;
|
|
2167
|
-
if (!
|
|
2243
|
+
if (!g) {
|
|
2168
2244
|
if (f.length === 0)
|
|
2169
2245
|
throw new Error(
|
|
2170
2246
|
"cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type."
|
|
2171
2247
|
);
|
|
2172
2248
|
h = f[0];
|
|
2173
2249
|
}
|
|
2174
|
-
if (typeof h == "string") this.dataType =
|
|
2175
|
-
else if (typeof h == "number") this.dataType =
|
|
2176
|
-
else if (typeof h == "bigint") this.dataType =
|
|
2177
|
-
else if (typeof h == "boolean") this.dataType =
|
|
2178
|
-
else if (h instanceof
|
|
2179
|
-
this.dataType =
|
|
2180
|
-
else if (typeof h == "object") this.dataType =
|
|
2250
|
+
if (typeof h == "string") this.dataType = O.STRING;
|
|
2251
|
+
else if (typeof h == "number") this.dataType = O.FLOAT64;
|
|
2252
|
+
else if (typeof h == "bigint") this.dataType = O.INT64;
|
|
2253
|
+
else if (typeof h == "boolean") this.dataType = O.BOOLEAN;
|
|
2254
|
+
else if (h instanceof u || h instanceof Date || h instanceof u)
|
|
2255
|
+
this.dataType = O.TIMESTAMP;
|
|
2256
|
+
else if (typeof h == "object") this.dataType = O.JSON;
|
|
2181
2257
|
else
|
|
2182
2258
|
throw new Error(
|
|
2183
2259
|
`cannot infer data type of ${typeof h} when constructing a Series from a JS array`
|
|
2184
2260
|
);
|
|
2185
|
-
} else this.dataType = new
|
|
2261
|
+
} else this.dataType = new O(f);
|
|
2186
2262
|
}
|
|
2187
|
-
if (!
|
|
2188
|
-
else if (
|
|
2263
|
+
if (!w && !g) this._data = f;
|
|
2264
|
+
else if (w && f.length === 0)
|
|
2189
2265
|
this._data = new this.dataType.Array([]).buffer;
|
|
2190
2266
|
else {
|
|
2191
|
-
let h =
|
|
2267
|
+
let h = g ? [f] : f;
|
|
2192
2268
|
const T = h[0];
|
|
2193
|
-
(T instanceof
|
|
2269
|
+
(T instanceof u || T instanceof Date || T instanceof l) && (h = h.map((x) => new u(x).valueOf())), this.dataType.equals(O.STRING) ? (this.cachedLength = h.length, this._data = new TextEncoder().encode(`${h.join(`
|
|
2194
2270
|
`)}
|
|
2195
|
-
`).buffer) : this.dataType.equals(
|
|
2196
|
-
`${h.map((
|
|
2271
|
+
`).buffer) : this.dataType.equals(O.JSON) ? (this.cachedLength = h.length, this._data = new TextEncoder().encode(
|
|
2272
|
+
`${h.map((x) => ce.encodeString(x)).join(`
|
|
2197
2273
|
`)}
|
|
2198
2274
|
`
|
|
2199
2275
|
).buffer) : this.dataType.usesBigInt && typeof T == "number" ? this._data = new this.dataType.Array(
|
|
2200
|
-
h.map((
|
|
2276
|
+
h.map((x) => BigInt(Math.round(x)))
|
|
2201
2277
|
).buffer : !this.dataType.usesBigInt && typeof T == "bigint" ? this._data = new this.dataType.Array(
|
|
2202
2278
|
h.map(Number)
|
|
2203
2279
|
).buffer : this._data = new this.dataType.Array(h).buffer;
|
|
2204
2280
|
}
|
|
2205
|
-
this.key = y, this.alignment = c, this.alignmentMultiple =
|
|
2281
|
+
this.key = y, this.alignment = c, this.alignmentMultiple = d, this.sampleOffset = i ?? 0, this.timeRange = r ?? G.ZERO, this.gl = {
|
|
2206
2282
|
control: null,
|
|
2207
2283
|
buffer: null,
|
|
2208
2284
|
prevBuffer: 0,
|
|
@@ -2219,7 +2295,7 @@ let qe = class B {
|
|
|
2219
2295
|
static alloc({ capacity: e, dataType: t, ...r }) {
|
|
2220
2296
|
if (e === 0)
|
|
2221
2297
|
throw new Error("[Series] - cannot allocate an array of length 0");
|
|
2222
|
-
const i = new new
|
|
2298
|
+
const i = new new O(t).Array(e), a = new B({ data: i.buffer, dataType: t, ...r });
|
|
2223
2299
|
return a.writePos = 0, a;
|
|
2224
2300
|
}
|
|
2225
2301
|
/**
|
|
@@ -2262,12 +2338,12 @@ let qe = class B {
|
|
|
2262
2338
|
return this.dataType.isVariable ? this.writeVariable(e) : this.writeFixed(e);
|
|
2263
2339
|
}
|
|
2264
2340
|
writeVariable(e) {
|
|
2265
|
-
if (this.writePos ===
|
|
2341
|
+
if (this.writePos === R) return 0;
|
|
2266
2342
|
const t = this.byteCapacity.valueOf() - this.writePos, r = e.subBytes(0, t);
|
|
2267
2343
|
return this.writeToUnderlyingData(r), this.writePos += r.byteLength.valueOf(), this.cachedLength != null && (this.cachedLength += r.length, this.calculateCachedLength()), r.length;
|
|
2268
2344
|
}
|
|
2269
2345
|
writeFixed(e) {
|
|
2270
|
-
if (this.writePos ===
|
|
2346
|
+
if (this.writePos === R) return 0;
|
|
2271
2347
|
const t = this.capacity - this.writePos, r = e.sub(0, t);
|
|
2272
2348
|
return this.writeToUnderlyingData(r), this.cachedLength = void 0, this.maybeRecomputeMinMax(r), this.writePos += r.length, r.length;
|
|
2273
2349
|
}
|
|
@@ -2290,7 +2366,7 @@ let qe = class B {
|
|
|
2290
2366
|
* @returns A typed array containing the series data.
|
|
2291
2367
|
*/
|
|
2292
2368
|
get data() {
|
|
2293
|
-
return this.writePos ===
|
|
2369
|
+
return this.writePos === R ? this.underlyingData : new this.dataType.Array(this._data, 0, this.writePos);
|
|
2294
2370
|
}
|
|
2295
2371
|
/**
|
|
2296
2372
|
* Returns an array of the values in the series as strings.
|
|
@@ -2309,16 +2385,16 @@ let qe = class B {
|
|
|
2309
2385
|
* @returns An array of values parsed from the JSON series.
|
|
2310
2386
|
*/
|
|
2311
2387
|
parseJSON(e) {
|
|
2312
|
-
if (!this.dataType.equals(
|
|
2388
|
+
if (!this.dataType.equals(O.JSON))
|
|
2313
2389
|
throw new Error("cannot parse non-JSON series as JSON");
|
|
2314
|
-
return this.toStrings().map((t) => e.parse(
|
|
2390
|
+
return this.toStrings().map((t) => e.parse(ce.decodeString(t)));
|
|
2315
2391
|
}
|
|
2316
2392
|
/**
|
|
2317
2393
|
* Returns the capacity of the series in bytes.
|
|
2318
2394
|
* @returns The size of the underlying buffer in bytes.
|
|
2319
2395
|
*/
|
|
2320
2396
|
get byteCapacity() {
|
|
2321
|
-
return new
|
|
2397
|
+
return new fe(this.underlyingData.byteLength);
|
|
2322
2398
|
}
|
|
2323
2399
|
/**
|
|
2324
2400
|
* Returns the capacity of the series in samples.
|
|
@@ -2334,7 +2410,7 @@ let qe = class B {
|
|
|
2334
2410
|
* @returns The size of the data in bytes.
|
|
2335
2411
|
*/
|
|
2336
2412
|
get byteLength() {
|
|
2337
|
-
return this.writePos ===
|
|
2413
|
+
return this.writePos === R ? this.byteCapacity : this.dataType.isVariable ? new fe(this.writePos) : this.dataType.density.size(this.writePos);
|
|
2338
2414
|
}
|
|
2339
2415
|
/**
|
|
2340
2416
|
* Returns the number of samples in this array.
|
|
@@ -2342,7 +2418,7 @@ let qe = class B {
|
|
|
2342
2418
|
* @returns The number of samples in the series.
|
|
2343
2419
|
*/
|
|
2344
2420
|
get length() {
|
|
2345
|
-
return this.cachedLength != null ? this.cachedLength : this.dataType.isVariable ? this.calculateCachedLength() : this.writePos ===
|
|
2421
|
+
return this.cachedLength != null ? this.cachedLength : this.dataType.isVariable ? this.calculateCachedLength() : this.writePos === R ? this.byteCapacity.valueOf() / this.dataType.density.valueOf() : this.writePos;
|
|
2346
2422
|
}
|
|
2347
2423
|
calculateCachedLength() {
|
|
2348
2424
|
if (!this.dataType.isVariable)
|
|
@@ -2350,7 +2426,7 @@ let qe = class B {
|
|
|
2350
2426
|
let e = 0;
|
|
2351
2427
|
const t = [0];
|
|
2352
2428
|
return this.data.forEach((r, i) => {
|
|
2353
|
-
r ===
|
|
2429
|
+
r === de && (e++, t.push(i + 1));
|
|
2354
2430
|
}), this._cachedIndexes = t, this.cachedLength = e, e;
|
|
2355
2431
|
}
|
|
2356
2432
|
/**
|
|
@@ -2366,7 +2442,7 @@ let qe = class B {
|
|
|
2366
2442
|
if (this.dataType.equals(e)) return this;
|
|
2367
2443
|
const r = new e.Array(this.length);
|
|
2368
2444
|
for (let i = 0; i < this.length; i++)
|
|
2369
|
-
r[i] =
|
|
2445
|
+
r[i] = Vt(this.dataType, e, this.data[i], t);
|
|
2370
2446
|
return new B({
|
|
2371
2447
|
data: r.buffer,
|
|
2372
2448
|
dataType: e,
|
|
@@ -2378,7 +2454,7 @@ let qe = class B {
|
|
|
2378
2454
|
}
|
|
2379
2455
|
calcRawMax() {
|
|
2380
2456
|
if (this.length === 0) return -1 / 0;
|
|
2381
|
-
if (this.dataType.equals(
|
|
2457
|
+
if (this.dataType.equals(O.TIMESTAMP))
|
|
2382
2458
|
this.cachedMax = this.data[this.data.length - 1];
|
|
2383
2459
|
else if (this.dataType.usesBigInt) {
|
|
2384
2460
|
const e = this.data;
|
|
@@ -2396,11 +2472,11 @@ let qe = class B {
|
|
|
2396
2472
|
calcMax() {
|
|
2397
2473
|
if (this.dataType.isVariable)
|
|
2398
2474
|
throw new Error("cannot calculate maximum on a variable length data type");
|
|
2399
|
-
return this.writePos === 0 ? -1 / 0 : (this.cachedMax ??= this.calcRawMax(),
|
|
2475
|
+
return this.writePos === 0 ? -1 / 0 : (this.cachedMax ??= this.calcRawMax(), _(this.cachedMax, this.sampleOffset));
|
|
2400
2476
|
}
|
|
2401
2477
|
calcRawMin() {
|
|
2402
2478
|
if (this.length === 0) return 1 / 0;
|
|
2403
|
-
if (this.dataType.equals(
|
|
2479
|
+
if (this.dataType.equals(O.TIMESTAMP)) this.cachedMin = this.data[0];
|
|
2404
2480
|
else if (this.dataType.usesBigInt) {
|
|
2405
2481
|
const e = this.data;
|
|
2406
2482
|
this.cachedMin = e.reduce((t, r) => t < r ? t : r);
|
|
@@ -2417,11 +2493,11 @@ let qe = class B {
|
|
|
2417
2493
|
calcMin() {
|
|
2418
2494
|
if (this.dataType.isVariable)
|
|
2419
2495
|
throw new Error("cannot calculate minimum on a variable length data type");
|
|
2420
|
-
return this.writePos === 0 ? 1 / 0 : (this.cachedMin ??= this.calcRawMin(),
|
|
2496
|
+
return this.writePos === 0 ? 1 / 0 : (this.cachedMin ??= this.calcRawMin(), _(this.cachedMin, this.sampleOffset));
|
|
2421
2497
|
}
|
|
2422
2498
|
/** @returns the bounds of the series. */
|
|
2423
2499
|
get bounds() {
|
|
2424
|
-
return
|
|
2500
|
+
return P(Number(this.min), Number(this.max), { makeValid: !1 });
|
|
2425
2501
|
}
|
|
2426
2502
|
maybeRecomputeMinMax(e) {
|
|
2427
2503
|
if (this.cachedMin != null) {
|
|
@@ -2443,18 +2519,18 @@ let qe = class B {
|
|
|
2443
2519
|
}
|
|
2444
2520
|
at(e, t = !1) {
|
|
2445
2521
|
if (this.dataType.isVariable) return this.atVariable(e, t ?? !1);
|
|
2446
|
-
if (this.dataType.equals(
|
|
2522
|
+
if (this.dataType.equals(O.UUID)) return this.atUUID(e, t);
|
|
2447
2523
|
e < 0 && (e = this.length + e);
|
|
2448
2524
|
const r = this.data[e];
|
|
2449
2525
|
if (r == null) {
|
|
2450
2526
|
if (t === !0) throw new Error(`[series] - no value at index ${e}`);
|
|
2451
2527
|
return;
|
|
2452
2528
|
}
|
|
2453
|
-
return
|
|
2529
|
+
return _(r, this.sampleOffset);
|
|
2454
2530
|
}
|
|
2455
2531
|
atUUID(e, t) {
|
|
2456
2532
|
e < 0 && (e = this.length + e);
|
|
2457
|
-
const r =
|
|
2533
|
+
const r = Ge(
|
|
2458
2534
|
new Uint8Array(this.buffer, e * this.dataType.density.valueOf())
|
|
2459
2535
|
);
|
|
2460
2536
|
if (r == null) {
|
|
@@ -2470,7 +2546,7 @@ let qe = class B {
|
|
|
2470
2546
|
else {
|
|
2471
2547
|
e < 0 && (e = this.length + e);
|
|
2472
2548
|
for (let c = 0; c < this.data.length; c++)
|
|
2473
|
-
if (this.data[c] ===
|
|
2549
|
+
if (this.data[c] === de) {
|
|
2474
2550
|
if (e === 0) {
|
|
2475
2551
|
i = c;
|
|
2476
2552
|
break;
|
|
@@ -2483,7 +2559,7 @@ let qe = class B {
|
|
|
2483
2559
|
}
|
|
2484
2560
|
}
|
|
2485
2561
|
const a = this.data.slice(r, i);
|
|
2486
|
-
return this.dataType.equals(
|
|
2562
|
+
return this.dataType.equals(O.STRING) ? new TextDecoder().decode(a) : Be(JSON.parse(new TextDecoder().decode(a)));
|
|
2487
2563
|
}
|
|
2488
2564
|
/**
|
|
2489
2565
|
* @returns the index of the first sample that is greater than or equal to the given value.
|
|
@@ -2492,7 +2568,7 @@ let qe = class B {
|
|
|
2492
2568
|
*/
|
|
2493
2569
|
binarySearch(e) {
|
|
2494
2570
|
let t = 0, r = this.length - 1;
|
|
2495
|
-
const i =
|
|
2571
|
+
const i = lt(e);
|
|
2496
2572
|
for (; t <= r; ) {
|
|
2497
2573
|
const a = Math.floor((t + r) / 2), c = i(this.at(a, !0), e);
|
|
2498
2574
|
if (c === 0) return a;
|
|
@@ -2508,11 +2584,11 @@ let qe = class B {
|
|
|
2508
2584
|
* be the same buffer previously passed to {@method acquire} or {@method updateGLBuffer}.
|
|
2509
2585
|
*/
|
|
2510
2586
|
updateGLBuffer(e) {
|
|
2511
|
-
if (this.gl.control = e, !this.dataType.equals(
|
|
2587
|
+
if (this.gl.control = e, !this.dataType.equals(O.FLOAT32) && !this.dataType.equals(O.UINT8))
|
|
2512
2588
|
throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");
|
|
2513
2589
|
const { buffer: t, bufferUsage: r, prevBuffer: i } = this.gl;
|
|
2514
2590
|
if (t == null && (this.gl.buffer = e.createBuffer()), this.writePos !== i)
|
|
2515
|
-
if (e.bindBuffer(e.ARRAY_BUFFER, this.gl.buffer), this.writePos !==
|
|
2591
|
+
if (e.bindBuffer(e.ARRAY_BUFFER, this.gl.buffer), this.writePos !== R) {
|
|
2516
2592
|
i === 0 && e.bufferData(e.ARRAY_BUFFER, this.byteCapacity.valueOf(), e.STATIC_DRAW);
|
|
2517
2593
|
const a = this.dataType.density.size(i).valueOf(), c = this.underlyingData.slice(this.gl.prevBuffer, this.writePos);
|
|
2518
2594
|
e.bufferSubData(e.ARRAY_BUFFER, a, c.buffer), this.gl.prevBuffer = this.writePos;
|
|
@@ -2521,10 +2597,10 @@ let qe = class B {
|
|
|
2521
2597
|
e.ARRAY_BUFFER,
|
|
2522
2598
|
this.buffer,
|
|
2523
2599
|
r === "static" ? e.STATIC_DRAW : e.DYNAMIC_DRAW
|
|
2524
|
-
), this.gl.prevBuffer =
|
|
2600
|
+
), this.gl.prevBuffer = R;
|
|
2525
2601
|
}
|
|
2526
2602
|
as(e) {
|
|
2527
|
-
return
|
|
2603
|
+
return en(e, this.dataType), this;
|
|
2528
2604
|
}
|
|
2529
2605
|
/** @returns a digest containing information about the series. */
|
|
2530
2606
|
get digest() {
|
|
@@ -2533,8 +2609,8 @@ let qe = class B {
|
|
|
2533
2609
|
dataType: this.dataType.toString(),
|
|
2534
2610
|
sampleOffset: this.sampleOffset,
|
|
2535
2611
|
alignment: {
|
|
2536
|
-
lower:
|
|
2537
|
-
upper:
|
|
2612
|
+
lower: $e(this.alignmentBounds.lower),
|
|
2613
|
+
upper: $e(this.alignmentBounds.upper),
|
|
2538
2614
|
multiple: this.alignmentMultiple
|
|
2539
2615
|
},
|
|
2540
2616
|
timeRange: this.timeRange.toString(),
|
|
@@ -2552,7 +2628,7 @@ let qe = class B {
|
|
|
2552
2628
|
* is exclusive.
|
|
2553
2629
|
*/
|
|
2554
2630
|
get alignmentBounds() {
|
|
2555
|
-
return
|
|
2631
|
+
return P(
|
|
2556
2632
|
this.alignment,
|
|
2557
2633
|
this.alignment + BigInt(this.length) * this.alignmentMultiple
|
|
2558
2634
|
);
|
|
@@ -2572,10 +2648,10 @@ let qe = class B {
|
|
|
2572
2648
|
}
|
|
2573
2649
|
[Symbol.iterator]() {
|
|
2574
2650
|
if (this.dataType.isVariable) {
|
|
2575
|
-
const e = new
|
|
2576
|
-
return this.dataType.equals(
|
|
2651
|
+
const e = new rn(this);
|
|
2652
|
+
return this.dataType.equals(O.JSON) ? new we(e) : e;
|
|
2577
2653
|
}
|
|
2578
|
-
return this.dataType.equals(
|
|
2654
|
+
return this.dataType.equals(O.UUID) ? new sn(this) : new an(this);
|
|
2579
2655
|
}
|
|
2580
2656
|
/**
|
|
2581
2657
|
* Returns a slice of the series from start to end.
|
|
@@ -2602,7 +2678,7 @@ let qe = class B {
|
|
|
2602
2678
|
* @returns An iterator over the specified range.
|
|
2603
2679
|
*/
|
|
2604
2680
|
subIterator(e, t) {
|
|
2605
|
-
return new
|
|
2681
|
+
return new Me(this, e, t ?? this.length);
|
|
2606
2682
|
}
|
|
2607
2683
|
/**
|
|
2608
2684
|
* Returns an iterator over a portion of the series based on alignment.
|
|
@@ -2616,7 +2692,7 @@ let qe = class B {
|
|
|
2616
2692
|
), i = Math.ceil(
|
|
2617
2693
|
Number(t - this.alignment) / Number(this.alignmentMultiple)
|
|
2618
2694
|
);
|
|
2619
|
-
return new
|
|
2695
|
+
return new Me(this, r, i);
|
|
2620
2696
|
}
|
|
2621
2697
|
subBytes(e, t) {
|
|
2622
2698
|
if (e >= 0 && (t == null || t >= this.byteLength.valueOf())) return this;
|
|
@@ -2651,7 +2727,7 @@ let qe = class B {
|
|
|
2651
2727
|
return new B({
|
|
2652
2728
|
data: this.buffer,
|
|
2653
2729
|
dataType: this.dataType,
|
|
2654
|
-
timeRange:
|
|
2730
|
+
timeRange: G.ZERO,
|
|
2655
2731
|
sampleOffset: this.sampleOffset,
|
|
2656
2732
|
glBufferUsage: "static",
|
|
2657
2733
|
alignment: e
|
|
@@ -2674,22 +2750,22 @@ let qe = class B {
|
|
|
2674
2750
|
}
|
|
2675
2751
|
return e += "])", e;
|
|
2676
2752
|
}
|
|
2677
|
-
}
|
|
2678
|
-
const
|
|
2679
|
-
|
|
2753
|
+
}
|
|
2754
|
+
const tn = (n) => n == null ? !1 : Array.isArray(n) || n instanceof ArrayBuffer || ArrayBuffer.isView(n) && !(n instanceof DataView) || n instanceof B ? !0 : Ze(n), nn = Wt(ze, B);
|
|
2755
|
+
class Me {
|
|
2680
2756
|
series;
|
|
2681
2757
|
end;
|
|
2682
2758
|
index;
|
|
2683
2759
|
constructor(e, t, r) {
|
|
2684
2760
|
this.series = e;
|
|
2685
|
-
const i =
|
|
2686
|
-
this.end =
|
|
2761
|
+
const i = P(0, e.length + 1);
|
|
2762
|
+
this.end = Ne(i, r), this.index = Ne(i, t);
|
|
2687
2763
|
}
|
|
2688
2764
|
next() {
|
|
2689
2765
|
return this.index >= this.end ? { done: !0, value: void 0 } : { done: !1, value: this.series.at(this.index++, !0) };
|
|
2690
2766
|
}
|
|
2691
|
-
}
|
|
2692
|
-
class
|
|
2767
|
+
}
|
|
2768
|
+
let rn = class {
|
|
2693
2769
|
series;
|
|
2694
2770
|
index;
|
|
2695
2771
|
decoder;
|
|
@@ -2702,12 +2778,12 @@ class Qt {
|
|
|
2702
2778
|
}
|
|
2703
2779
|
next() {
|
|
2704
2780
|
const e = this.index, t = this.series.data;
|
|
2705
|
-
for (; this.index < t.length && t[this.index] !==
|
|
2781
|
+
for (; this.index < t.length && t[this.index] !== de; ) this.index++;
|
|
2706
2782
|
const r = this.index;
|
|
2707
2783
|
return e === r ? { done: !0, value: void 0 } : (this.index++, { done: !1, value: this.decoder.decode(this.series.buffer.slice(e, r)) });
|
|
2708
2784
|
}
|
|
2709
|
-
}
|
|
2710
|
-
|
|
2785
|
+
};
|
|
2786
|
+
class we {
|
|
2711
2787
|
wrapped;
|
|
2712
2788
|
static schema = s.record(s.string(), s.unknown());
|
|
2713
2789
|
constructor(e) {
|
|
@@ -2717,26 +2793,27 @@ let _t = class Fe {
|
|
|
2717
2793
|
const e = this.wrapped.next();
|
|
2718
2794
|
return e.done === !0 ? { done: !0, value: void 0 } : {
|
|
2719
2795
|
done: !1,
|
|
2720
|
-
value:
|
|
2796
|
+
value: ce.decodeString(e.value, we.schema)
|
|
2721
2797
|
};
|
|
2722
2798
|
}
|
|
2723
|
-
}
|
|
2799
|
+
}
|
|
2800
|
+
class sn {
|
|
2724
2801
|
series;
|
|
2725
2802
|
index;
|
|
2726
2803
|
data;
|
|
2727
2804
|
density;
|
|
2728
2805
|
constructor(e) {
|
|
2729
|
-
if (!e.dataType.equals(
|
|
2806
|
+
if (!e.dataType.equals(O.UUID))
|
|
2730
2807
|
throw new Error("cannot create a UUID series iterator for a non-UUID series");
|
|
2731
|
-
this.series = e, this.index = 0, this.data = new Uint8Array(e.buffer), this.density =
|
|
2808
|
+
this.series = e, this.index = 0, this.data = new Uint8Array(e.buffer), this.density = O.UUID.density.valueOf();
|
|
2732
2809
|
}
|
|
2733
2810
|
next() {
|
|
2734
2811
|
if (this.index >= this.series.length) return { done: !0, value: void 0 };
|
|
2735
|
-
const e =
|
|
2812
|
+
const e = Ge(this.data, this.index * this.density);
|
|
2736
2813
|
return this.index++, { done: !1, value: e };
|
|
2737
2814
|
}
|
|
2738
|
-
}
|
|
2739
|
-
class
|
|
2815
|
+
}
|
|
2816
|
+
let an = class {
|
|
2740
2817
|
series;
|
|
2741
2818
|
index;
|
|
2742
2819
|
constructor(e) {
|
|
@@ -2748,8 +2825,8 @@ class tn {
|
|
|
2748
2825
|
value: this.series.at(this.index++, !0)
|
|
2749
2826
|
};
|
|
2750
2827
|
}
|
|
2751
|
-
}
|
|
2752
|
-
const
|
|
2828
|
+
};
|
|
2829
|
+
const $e = (n) => {
|
|
2753
2830
|
const e = n >> 32n, t = n & 0xffffffffn;
|
|
2754
2831
|
return { domain: e, sample: t };
|
|
2755
2832
|
};
|
|
@@ -2758,17 +2835,17 @@ s.record(
|
|
|
2758
2835
|
s.union([s.number(), s.string(), s.symbol()]),
|
|
2759
2836
|
s.unknown()
|
|
2760
2837
|
);
|
|
2761
|
-
const
|
|
2762
|
-
|
|
2763
|
-
const
|
|
2838
|
+
const on = () => typeof process < "u" && process.versions != null && process.versions.node != null ? "node" : typeof window > "u" || window.document === void 0 ? "webworker" : "browser";
|
|
2839
|
+
on();
|
|
2840
|
+
const un = ["macOS", "Windows", "Linux"], ln = ["macos", "windows", "linux"], cn = {
|
|
2764
2841
|
macos: "macOS",
|
|
2765
2842
|
windows: "Windows",
|
|
2766
2843
|
linux: "Linux"
|
|
2767
2844
|
};
|
|
2768
|
-
s.enum(
|
|
2769
|
-
s.enum(
|
|
2845
|
+
s.enum(un).or(
|
|
2846
|
+
s.enum(ln).transform((n) => cn[n])
|
|
2770
2847
|
);
|
|
2771
|
-
const
|
|
2848
|
+
const hn = (...n) => n.map(Ve).join(""), Ve = (n) => (n.endsWith("/") || (n += "/"), n.startsWith("/") && (n = n.slice(1)), n), fn = (n) => n.endsWith("/") ? n.slice(0, -1) : n, dn = (n, e = "") => n === null ? "" : `?${Object.entries(n).filter(([, t]) => t == null ? !1 : Array.isArray(t) ? t.length > 0 : !0).map(([t, r]) => `${e}${t}=${r}`).join("&")}`;
|
|
2772
2849
|
class V {
|
|
2773
2850
|
protocol;
|
|
2774
2851
|
host;
|
|
@@ -2781,7 +2858,7 @@ class V {
|
|
|
2781
2858
|
* @param pathPrefix - A path prefix to use for all requests. Defaults to "".
|
|
2782
2859
|
*/
|
|
2783
2860
|
constructor({ host: e, port: t, protocol: r = "", pathPrefix: i = "" }) {
|
|
2784
|
-
this.protocol = r, this.host = e, this.port = t, this.path =
|
|
2861
|
+
this.protocol = r, this.host = e, this.port = t, this.path = Ve(i);
|
|
2785
2862
|
}
|
|
2786
2863
|
/**
|
|
2787
2864
|
* Replaces creates a new URL with the specified properties replaced.
|
|
@@ -2804,31 +2881,31 @@ class V {
|
|
|
2804
2881
|
child(e) {
|
|
2805
2882
|
return new V({
|
|
2806
2883
|
...this,
|
|
2807
|
-
pathPrefix:
|
|
2884
|
+
pathPrefix: hn(this.path, e)
|
|
2808
2885
|
});
|
|
2809
2886
|
}
|
|
2810
2887
|
/** @returns a string representation of the url */
|
|
2811
2888
|
toString() {
|
|
2812
|
-
return
|
|
2889
|
+
return fn(
|
|
2813
2890
|
`${this.protocol}://${this.host}:${this.port}/${this.path}`
|
|
2814
2891
|
);
|
|
2815
2892
|
}
|
|
2816
2893
|
static UNKNOWN = new V({ host: "unknown", port: 0 });
|
|
2817
2894
|
}
|
|
2818
|
-
const
|
|
2819
|
-
(e) => setTimeout(e,
|
|
2895
|
+
const gn = async (n) => await new Promise(
|
|
2896
|
+
(e) => setTimeout(e, l.fromMilliseconds(n).milliseconds)
|
|
2820
2897
|
);
|
|
2821
|
-
class
|
|
2898
|
+
class pn {
|
|
2822
2899
|
config;
|
|
2823
2900
|
retries;
|
|
2824
2901
|
interval;
|
|
2825
2902
|
constructor(e) {
|
|
2826
2903
|
this.config = {
|
|
2827
|
-
baseInterval: new
|
|
2904
|
+
baseInterval: new l(e?.baseInterval ?? l.seconds(1)),
|
|
2828
2905
|
maxRetries: e?.maxRetries ?? 5,
|
|
2829
2906
|
scale: e?.scale ?? 1,
|
|
2830
|
-
sleepFn: e?.sleepFn ??
|
|
2831
|
-
}, this.retries = 0, this.interval = new
|
|
2907
|
+
sleepFn: e?.sleepFn ?? gn
|
|
2908
|
+
}, this.retries = 0, this.interval = new l(this.config.baseInterval);
|
|
2832
2909
|
}
|
|
2833
2910
|
async wait() {
|
|
2834
2911
|
const { maxRetries: e, scale: t, sleepFn: r } = this.config;
|
|
@@ -2841,159 +2918,165 @@ class hn {
|
|
|
2841
2918
|
this.retries = 0, this.interval = this.config.baseInterval;
|
|
2842
2919
|
}
|
|
2843
2920
|
}
|
|
2844
|
-
const
|
|
2845
|
-
baseInterval:
|
|
2921
|
+
const mn = s.object({
|
|
2922
|
+
baseInterval: l.z.optional(),
|
|
2846
2923
|
maxRetries: s.number().optional(),
|
|
2847
2924
|
scale: s.number().optional()
|
|
2848
|
-
}),
|
|
2925
|
+
}), yn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2849
2926
|
__proto__: null,
|
|
2850
|
-
Breaker:
|
|
2851
|
-
breakerConfigZ:
|
|
2852
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
2853
|
-
if (n =
|
|
2927
|
+
Breaker: pn,
|
|
2928
|
+
breakerConfigZ: mn
|
|
2929
|
+
}, Symbol.toStringTag, { value: "Module" })), wn = /^#?([0-9a-f]{6}|[0-9a-f]{8})$/i, He = s.string().regex(wn), Y = s.number().min(0).max(255), Je = s.number().min(0).max(1), Ke = s.tuple([Y, Y, Y, Je]), bn = s.tuple([Y, Y, Y]), On = s.object({ rgba255: Ke }), Tn = s.number().min(0).max(360), vn = s.number().min(0).max(100), Sn = s.number().min(0).max(100), In = s.tuple([Tn, vn, Sn, Je]), be = s.union([He, bn, Ke, In, On]), Nn = be.transform((n) => Oe(n)), Oe = (n, e = 1) => {
|
|
2930
|
+
if (n = be.parse(n), typeof n == "string") return En(n, e);
|
|
2854
2931
|
if (Array.isArray(n)) {
|
|
2855
2932
|
if (n.length < 3 || n.length > 4)
|
|
2856
2933
|
throw new Error(`Invalid color: [${n.join(", ")}]`);
|
|
2857
2934
|
return n.length === 3 ? [...n, e] : n;
|
|
2858
2935
|
}
|
|
2859
2936
|
return n.rgba255;
|
|
2860
|
-
},
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
n.length === 8 ?
|
|
2865
|
-
]),
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
const
|
|
2937
|
+
}, En = (n, e = 1) => (n = He.parse(n), n = xn(n), [
|
|
2938
|
+
Q(n, 0),
|
|
2939
|
+
Q(n, 2),
|
|
2940
|
+
Q(n, 4),
|
|
2941
|
+
n.length === 8 ? Q(n, 6) / 255 : e
|
|
2942
|
+
]), Q = (n, e) => parseInt(n.slice(e, e + 2), 16), xn = (n) => n.startsWith("#") ? n.slice(1) : n;
|
|
2943
|
+
Oe("#000000");
|
|
2944
|
+
Oe("#ffffff");
|
|
2945
|
+
const An = s.object({
|
|
2869
2946
|
key: s.string(),
|
|
2870
|
-
color:
|
|
2947
|
+
color: be,
|
|
2871
2948
|
position: s.number(),
|
|
2872
2949
|
switched: s.boolean().optional()
|
|
2873
2950
|
});
|
|
2874
|
-
s.array(
|
|
2875
|
-
const
|
|
2951
|
+
s.array(An);
|
|
2952
|
+
const Un = s.object({
|
|
2876
2953
|
key: s.string(),
|
|
2877
2954
|
name: s.string(),
|
|
2878
|
-
color:
|
|
2955
|
+
color: Nn
|
|
2879
2956
|
});
|
|
2880
2957
|
s.object({
|
|
2881
2958
|
key: s.string(),
|
|
2882
2959
|
name: s.string(),
|
|
2883
|
-
swatches: s.array(
|
|
2960
|
+
swatches: s.array(Un)
|
|
2884
2961
|
});
|
|
2885
2962
|
s.int().min(0).max(255);
|
|
2886
2963
|
s.object({
|
|
2887
2964
|
name: s.string(),
|
|
2888
2965
|
key: s.string()
|
|
2889
2966
|
});
|
|
2890
|
-
const
|
|
2967
|
+
const Mn = (n) => Object.getOwnPropertySymbols(globalThis).includes(n), $n = (n, e) => {
|
|
2891
2968
|
const t = Symbol.for(n);
|
|
2892
|
-
if (!
|
|
2969
|
+
if (!Mn(t)) {
|
|
2893
2970
|
const r = e();
|
|
2894
2971
|
Object.defineProperty(globalThis, t, { value: r });
|
|
2895
2972
|
}
|
|
2896
2973
|
return () => globalThis[t];
|
|
2897
|
-
},
|
|
2898
|
-
static discriminator =
|
|
2899
|
-
discriminator =
|
|
2974
|
+
}, Xe = "sy_x_error", Cn = (n) => (e) => e != null && typeof e == "object" && "type" in e && typeof e.type == "string" ? e.type.startsWith(n) : e instanceof Error ? e.message.startsWith(n) : typeof e != "string" ? !1 : e.startsWith(n), H = (n) => class z extends Error {
|
|
2975
|
+
static discriminator = Xe;
|
|
2976
|
+
discriminator = z.discriminator;
|
|
2900
2977
|
static TYPE = n;
|
|
2901
|
-
type =
|
|
2902
|
-
static matches =
|
|
2903
|
-
matches =
|
|
2978
|
+
type = z.TYPE;
|
|
2979
|
+
static matches = Cn(n);
|
|
2980
|
+
matches = z.matches;
|
|
2904
2981
|
constructor(t, r) {
|
|
2905
|
-
super(t, r), this.name =
|
|
2982
|
+
super(t, r), this.name = z.TYPE;
|
|
2906
2983
|
}
|
|
2907
2984
|
static sub(t) {
|
|
2908
|
-
return
|
|
2985
|
+
return H(`${n}.${t}`);
|
|
2909
2986
|
}
|
|
2910
|
-
},
|
|
2987
|
+
}, Qe = (n) => {
|
|
2911
2988
|
if (n == null || typeof n != "object") return !1;
|
|
2912
2989
|
const e = n;
|
|
2913
|
-
if (e.discriminator !==
|
|
2990
|
+
if (e.discriminator !== Xe) return !1;
|
|
2914
2991
|
if (!("type" in e))
|
|
2915
2992
|
throw new Error(
|
|
2916
2993
|
`X Error is missing its type property: ${JSON.stringify(e)}`
|
|
2917
2994
|
);
|
|
2918
2995
|
return !0;
|
|
2919
|
-
},
|
|
2920
|
-
class
|
|
2996
|
+
}, j = "unknown", ge = "nil";
|
|
2997
|
+
class Bn {
|
|
2921
2998
|
providers = [];
|
|
2922
2999
|
register(e) {
|
|
2923
3000
|
this.providers.push(e);
|
|
2924
3001
|
}
|
|
2925
3002
|
encode(e) {
|
|
2926
|
-
if (e == null) return { type:
|
|
2927
|
-
if (
|
|
3003
|
+
if (e == null) return { type: ge, data: "" };
|
|
3004
|
+
if (Qe(e))
|
|
2928
3005
|
for (const t of this.providers) {
|
|
2929
3006
|
const r = t.encode(e);
|
|
2930
3007
|
if (r != null) return r;
|
|
2931
3008
|
}
|
|
2932
|
-
if (e instanceof Error) return { type:
|
|
2933
|
-
if (typeof e == "string") return { type:
|
|
3009
|
+
if (e instanceof Error) return { type: j, data: e.message };
|
|
3010
|
+
if (typeof e == "string") return { type: j, data: e };
|
|
2934
3011
|
try {
|
|
2935
|
-
return { type:
|
|
3012
|
+
return { type: j, data: JSON.stringify(e) };
|
|
2936
3013
|
} catch {
|
|
2937
|
-
return { type:
|
|
3014
|
+
return { type: j, data: "unable to encode error information" };
|
|
2938
3015
|
}
|
|
2939
3016
|
}
|
|
2940
3017
|
decode(e) {
|
|
2941
|
-
if (e == null || e.type ===
|
|
2942
|
-
if (e.type ===
|
|
3018
|
+
if (e == null || e.type === ge) return null;
|
|
3019
|
+
if (e.type === j) return new pe(e.data);
|
|
2943
3020
|
for (const t of this.providers) {
|
|
2944
3021
|
const r = t.decode(e);
|
|
2945
3022
|
if (r != null) return r;
|
|
2946
3023
|
}
|
|
2947
|
-
return new
|
|
3024
|
+
return new pe(e.data);
|
|
2948
3025
|
}
|
|
2949
3026
|
}
|
|
2950
|
-
const
|
|
2951
|
-
class
|
|
3027
|
+
const Te = $n("synnax-error-registry", () => new Bn()), Rn = ({ encode: n, decode: e }) => Te().register({ encode: n, decode: e }), Dn = (n) => Te().encode(n), Ln = (n) => n == null ? null : Te().decode(n);
|
|
3028
|
+
class pe extends H("unknown") {
|
|
2952
3029
|
}
|
|
2953
|
-
const
|
|
2954
|
-
class
|
|
3030
|
+
const Pn = s.object({ type: s.string(), data: s.string() });
|
|
3031
|
+
class kn extends H("canceled") {
|
|
2955
3032
|
}
|
|
2956
|
-
class
|
|
3033
|
+
class jn extends H("not_implemented") {
|
|
2957
3034
|
}
|
|
2958
|
-
const
|
|
3035
|
+
const D = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2959
3036
|
__proto__: null,
|
|
2960
|
-
Canceled:
|
|
2961
|
-
NONE:
|
|
2962
|
-
NotImplemented:
|
|
2963
|
-
UNKNOWN:
|
|
2964
|
-
Unknown:
|
|
2965
|
-
createTyped:
|
|
2966
|
-
decode:
|
|
2967
|
-
encode:
|
|
2968
|
-
isTyped:
|
|
2969
|
-
payloadZ:
|
|
2970
|
-
register:
|
|
2971
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
2972
|
-
jsonrpc:
|
|
2973
|
-
method:
|
|
3037
|
+
Canceled: kn,
|
|
3038
|
+
NONE: ge,
|
|
3039
|
+
NotImplemented: jn,
|
|
3040
|
+
UNKNOWN: j,
|
|
3041
|
+
Unknown: pe,
|
|
3042
|
+
createTyped: H,
|
|
3043
|
+
decode: Ln,
|
|
3044
|
+
encode: Dn,
|
|
3045
|
+
isTyped: Qe,
|
|
3046
|
+
payloadZ: Pn,
|
|
3047
|
+
register: Rn
|
|
3048
|
+
}, Symbol.toStringTag, { value: "Module" })), Yn = b.object({
|
|
3049
|
+
jsonrpc: b.literal("2.0"),
|
|
3050
|
+
method: b.string(),
|
|
2974
3051
|
// params should be z.union([z.record(z.string(), z.json()),
|
|
2975
3052
|
// z.array(z.json())]).optional() but the VSCode JSON RPC implementation uses a looser
|
|
2976
3053
|
// definition of params then in the JSON-RPC spec.
|
|
2977
|
-
params:
|
|
2978
|
-
id:
|
|
2979
|
-
}),
|
|
2980
|
-
jsonrpc:
|
|
2981
|
-
id:
|
|
2982
|
-
}),
|
|
2983
|
-
result:
|
|
2984
|
-
}),
|
|
2985
|
-
error:
|
|
2986
|
-
code:
|
|
3054
|
+
params: b.any().optional(),
|
|
3055
|
+
id: b.union([b.string(), b.number(), b.null()]).optional()
|
|
3056
|
+
}), _e = b.object({
|
|
3057
|
+
jsonrpc: b.literal("2.0"),
|
|
3058
|
+
id: b.union([b.string(), b.number(), b.null()])
|
|
3059
|
+
}), qn = _e.extend({
|
|
3060
|
+
result: b.json()
|
|
3061
|
+
}), Fn = _e.extend({
|
|
3062
|
+
error: b.object({
|
|
3063
|
+
code: b.number().int(),
|
|
2987
3064
|
// This should be z.string(), but the VSCode JSON RPC implementation uses a looser
|
|
2988
3065
|
// definition of error than the JSON-RPC spec.
|
|
2989
|
-
message:
|
|
2990
|
-
data:
|
|
3066
|
+
message: b.string().optional(),
|
|
3067
|
+
data: b.json().optional()
|
|
2991
3068
|
})
|
|
2992
|
-
}),
|
|
2993
|
-
|
|
3069
|
+
}), Wn = b.union([qn, Fn]);
|
|
3070
|
+
b.union([Yn, Wn]);
|
|
3071
|
+
const Zn = b.uuid();
|
|
3072
|
+
b.object({
|
|
3073
|
+
key: Zn,
|
|
3074
|
+
name: b.string().min(1),
|
|
3075
|
+
color: b.string()
|
|
3076
|
+
});
|
|
2994
3077
|
s.string().regex(/^\d+\.\d+\.\d+$/);
|
|
2995
|
-
const
|
|
2996
|
-
s.enum(
|
|
3078
|
+
const Gn = ["standard", "scientific", "engineering"];
|
|
3079
|
+
s.enum(Gn);
|
|
2997
3080
|
s.enum([
|
|
2998
3081
|
"success",
|
|
2999
3082
|
"info",
|
|
@@ -3002,51 +3085,54 @@ s.enum([
|
|
|
3002
3085
|
"loading",
|
|
3003
3086
|
"disabled"
|
|
3004
3087
|
]);
|
|
3005
|
-
|
|
3088
|
+
s.object({
|
|
3089
|
+
stack: s.string()
|
|
3090
|
+
});
|
|
3091
|
+
class J extends D.createTyped("freighter") {
|
|
3006
3092
|
}
|
|
3007
|
-
class
|
|
3093
|
+
class q extends J.sub("eof") {
|
|
3008
3094
|
constructor() {
|
|
3009
3095
|
super("EOF");
|
|
3010
3096
|
}
|
|
3011
3097
|
}
|
|
3012
|
-
class
|
|
3098
|
+
class F extends J.sub("stream_closed") {
|
|
3013
3099
|
constructor() {
|
|
3014
3100
|
super("StreamClosed");
|
|
3015
3101
|
}
|
|
3016
3102
|
}
|
|
3017
|
-
class
|
|
3103
|
+
class W extends J.sub("unreachable") {
|
|
3018
3104
|
url;
|
|
3019
3105
|
constructor(e = {}) {
|
|
3020
3106
|
const { message: t = "Unreachable", url: r = V.UNKNOWN } = e;
|
|
3021
3107
|
super(t), this.url = r;
|
|
3022
3108
|
}
|
|
3023
3109
|
}
|
|
3024
|
-
const
|
|
3025
|
-
if (!n.type.startsWith(
|
|
3026
|
-
if (
|
|
3027
|
-
if (
|
|
3028
|
-
return { type:
|
|
3029
|
-
if (
|
|
3030
|
-
return { type:
|
|
3110
|
+
const zn = (n) => {
|
|
3111
|
+
if (!n.type.startsWith(J.TYPE)) return null;
|
|
3112
|
+
if (q.matches(n)) return { type: q.TYPE, data: "EOF" };
|
|
3113
|
+
if (F.matches(n))
|
|
3114
|
+
return { type: F.TYPE, data: "StreamClosed" };
|
|
3115
|
+
if (W.matches(n))
|
|
3116
|
+
return { type: W.TYPE, data: "Unreachable" };
|
|
3031
3117
|
throw new Error(`Unknown error type: ${n.type}: ${n.message}`);
|
|
3032
|
-
},
|
|
3033
|
-
if (!n.type.startsWith(
|
|
3118
|
+
}, Vn = (n) => {
|
|
3119
|
+
if (!n.type.startsWith(J.TYPE)) return null;
|
|
3034
3120
|
switch (n.type) {
|
|
3035
|
-
case j.TYPE:
|
|
3036
|
-
return new j();
|
|
3037
|
-
case Y.TYPE:
|
|
3038
|
-
return new Y();
|
|
3039
3121
|
case q.TYPE:
|
|
3040
3122
|
return new q();
|
|
3123
|
+
case F.TYPE:
|
|
3124
|
+
return new F();
|
|
3125
|
+
case W.TYPE:
|
|
3126
|
+
return new W();
|
|
3041
3127
|
default:
|
|
3042
|
-
throw new
|
|
3128
|
+
throw new D.Unknown(`Unknown error type: ${n.data}`);
|
|
3043
3129
|
}
|
|
3044
3130
|
};
|
|
3045
|
-
|
|
3046
|
-
encode:
|
|
3047
|
-
decode:
|
|
3131
|
+
D.register({
|
|
3132
|
+
encode: zn,
|
|
3133
|
+
decode: Vn
|
|
3048
3134
|
});
|
|
3049
|
-
class
|
|
3135
|
+
class et {
|
|
3050
3136
|
middleware = [];
|
|
3051
3137
|
/** Implements the Transport interface */
|
|
3052
3138
|
use(...e) {
|
|
@@ -3071,24 +3157,24 @@ class Xe {
|
|
|
3071
3157
|
return await i(e);
|
|
3072
3158
|
}
|
|
3073
3159
|
}
|
|
3074
|
-
const
|
|
3160
|
+
const tt = "Content-Type", Hn = /* @__PURE__ */ new Set([
|
|
3075
3161
|
"ECONNREFUSED",
|
|
3076
3162
|
"ECONNRESET",
|
|
3077
3163
|
"ETIMEDOUT",
|
|
3078
3164
|
"EPIPE",
|
|
3079
3165
|
"UND_ERR_CONNECT_TIMEOUT",
|
|
3080
3166
|
"UND_ERR_SOCKET"
|
|
3081
|
-
]),
|
|
3167
|
+
]), Jn = (n) => {
|
|
3082
3168
|
const e = n?.cause?.code ?? n?.code ?? n?.errno;
|
|
3083
|
-
if (typeof e == "string" &&
|
|
3169
|
+
if (typeof e == "string" && Hn.has(e)) return !0;
|
|
3084
3170
|
if (n.name === "TypeError") {
|
|
3085
3171
|
const t = String(n.message || "").toLowerCase();
|
|
3086
3172
|
if (/load failed|failed to fetch|networkerror|network error/.test(t))
|
|
3087
3173
|
return typeof navigator < "u" && navigator.onLine === !1, !0;
|
|
3088
3174
|
}
|
|
3089
3175
|
return n?.name === "AbortError" || n?.code === "ABORT_ERR", !1;
|
|
3090
|
-
},
|
|
3091
|
-
class
|
|
3176
|
+
}, Kn = 400;
|
|
3177
|
+
class or extends et {
|
|
3092
3178
|
endpoint;
|
|
3093
3179
|
encoder;
|
|
3094
3180
|
constructor(e, t, r = !1) {
|
|
@@ -3098,14 +3184,14 @@ class nr extends Xe {
|
|
|
3098
3184
|
}
|
|
3099
3185
|
get headers() {
|
|
3100
3186
|
return {
|
|
3101
|
-
[
|
|
3187
|
+
[tt]: this.encoder.contentType
|
|
3102
3188
|
};
|
|
3103
3189
|
}
|
|
3104
3190
|
async send(e, t, r, i) {
|
|
3105
3191
|
t = r?.parse(t);
|
|
3106
3192
|
let a = null;
|
|
3107
|
-
const c = this.endpoint.child(e),
|
|
3108
|
-
|
|
3193
|
+
const c = this.endpoint.child(e), d = {};
|
|
3194
|
+
d.method = "POST", d.body = this.encoder.encode(t ?? {});
|
|
3109
3195
|
const [, y] = await this.executeMiddleware(
|
|
3110
3196
|
{
|
|
3111
3197
|
target: c.toString(),
|
|
@@ -3114,31 +3200,31 @@ class nr extends Xe {
|
|
|
3114
3200
|
role: "client"
|
|
3115
3201
|
},
|
|
3116
3202
|
async (f) => {
|
|
3117
|
-
const
|
|
3118
|
-
|
|
3203
|
+
const g = { ...f, params: {} };
|
|
3204
|
+
d.headers = {
|
|
3119
3205
|
...this.headers,
|
|
3120
3206
|
...f.params
|
|
3121
3207
|
};
|
|
3122
|
-
let
|
|
3208
|
+
let w;
|
|
3123
3209
|
try {
|
|
3124
|
-
|
|
3210
|
+
w = await fetch(f.target, d);
|
|
3125
3211
|
} catch (T) {
|
|
3126
3212
|
if (!(T instanceof Error)) throw T;
|
|
3127
|
-
return [
|
|
3213
|
+
return [g, Jn(T) ? new W({ url: c }) : T];
|
|
3128
3214
|
}
|
|
3129
|
-
const h = await
|
|
3130
|
-
if (
|
|
3131
|
-
return i != null && (a = this.encoder.decode(h, i)), [
|
|
3215
|
+
const h = await w.arrayBuffer();
|
|
3216
|
+
if (w?.ok)
|
|
3217
|
+
return i != null && (a = this.encoder.decode(h, i)), [g, null];
|
|
3132
3218
|
try {
|
|
3133
|
-
if (
|
|
3134
|
-
return [
|
|
3135
|
-
const T = this.encoder.decode(h,
|
|
3136
|
-
return [
|
|
3219
|
+
if (w.status !== Kn)
|
|
3220
|
+
return [g, new Error(w.statusText)];
|
|
3221
|
+
const T = this.encoder.decode(h, D.payloadZ), x = D.decode(T);
|
|
3222
|
+
return [g, x];
|
|
3137
3223
|
} catch (T) {
|
|
3138
3224
|
return [
|
|
3139
|
-
|
|
3225
|
+
g,
|
|
3140
3226
|
new Error(
|
|
3141
|
-
`[freighter] - failed to decode error: ${
|
|
3227
|
+
`[freighter] - failed to decode error: ${w.statusText}: ${T.message}`
|
|
3142
3228
|
)
|
|
3143
3229
|
];
|
|
3144
3230
|
}
|
|
@@ -3149,7 +3235,7 @@ class nr extends Xe {
|
|
|
3149
3235
|
return [a, null];
|
|
3150
3236
|
}
|
|
3151
3237
|
}
|
|
3152
|
-
const
|
|
3238
|
+
const ur = (n, e) => {
|
|
3153
3239
|
class t {
|
|
3154
3240
|
wrapped;
|
|
3155
3241
|
constructor(i) {
|
|
@@ -3158,27 +3244,27 @@ const rr = (n, e) => {
|
|
|
3158
3244
|
use(...i) {
|
|
3159
3245
|
this.wrapped.use(...i);
|
|
3160
3246
|
}
|
|
3161
|
-
async send(i, a, c,
|
|
3162
|
-
const y = new
|
|
3247
|
+
async send(i, a, c, d) {
|
|
3248
|
+
const y = new yn.Breaker(e);
|
|
3163
3249
|
do {
|
|
3164
|
-
const [f,
|
|
3165
|
-
if (
|
|
3166
|
-
if (!
|
|
3167
|
-
if (console.warn(`[freighter] ${y.retryMessage}`,
|
|
3250
|
+
const [f, g] = await this.wrapped.send(i, a, c, d);
|
|
3251
|
+
if (g == null) return [f, null];
|
|
3252
|
+
if (!W.matches(g)) return [null, g];
|
|
3253
|
+
if (console.warn(`[freighter] ${y.retryMessage}`, g), !await y.wait()) return [f, g];
|
|
3168
3254
|
} while (!0);
|
|
3169
3255
|
}
|
|
3170
3256
|
}
|
|
3171
3257
|
return new t(n);
|
|
3172
|
-
},
|
|
3258
|
+
}, lr = async (n, e, t, r, i) => {
|
|
3173
3259
|
const [a, c] = await n.send(e, t, r, i);
|
|
3174
3260
|
if (c != null) throw c;
|
|
3175
3261
|
return a;
|
|
3176
|
-
},
|
|
3262
|
+
}, Xn = s.object({
|
|
3177
3263
|
type: s.enum(["data", "close", "open"]),
|
|
3178
3264
|
payload: s.unknown(),
|
|
3179
|
-
error: s.optional(
|
|
3265
|
+
error: s.optional(D.payloadZ)
|
|
3180
3266
|
});
|
|
3181
|
-
class
|
|
3267
|
+
class Qn {
|
|
3182
3268
|
codec;
|
|
3183
3269
|
reqSchema;
|
|
3184
3270
|
resSchema;
|
|
@@ -3194,14 +3280,14 @@ class Gn {
|
|
|
3194
3280
|
const e = await this.receiveMsg();
|
|
3195
3281
|
if (e.type !== "open") {
|
|
3196
3282
|
if (e.error == null) throw new Error("Message error must be defined");
|
|
3197
|
-
return
|
|
3283
|
+
return D.decode(e.error);
|
|
3198
3284
|
}
|
|
3199
3285
|
return null;
|
|
3200
3286
|
}
|
|
3201
3287
|
/** Implements the Stream protocol */
|
|
3202
3288
|
send(e) {
|
|
3203
|
-
if (this.serverClosed != null) return new
|
|
3204
|
-
if (this.sendClosed) throw new
|
|
3289
|
+
if (this.serverClosed != null) return new q();
|
|
3290
|
+
if (this.sendClosed) throw new F();
|
|
3205
3291
|
return this.ws.send(this.codec.encode({ type: "data", payload: e })), null;
|
|
3206
3292
|
}
|
|
3207
3293
|
/** Implements the Stream protocol */
|
|
@@ -3210,7 +3296,7 @@ class Gn {
|
|
|
3210
3296
|
const e = await this.receiveMsg();
|
|
3211
3297
|
if (e.type === "close") {
|
|
3212
3298
|
if (e.error == null) throw new Error("Message error must be defined");
|
|
3213
|
-
if (this.serverClosed =
|
|
3299
|
+
if (this.serverClosed = D.decode(e.error), this.serverClosed == null) throw new Error("Message error must be defined");
|
|
3214
3300
|
return [null, this.serverClosed];
|
|
3215
3301
|
}
|
|
3216
3302
|
return [this.resSchema.parse(e.payload), null];
|
|
@@ -3243,20 +3329,20 @@ class Gn {
|
|
|
3243
3329
|
this.ws.onmessage = this.onMessage.bind(this), this.ws.onclose = this.onClose.bind(this);
|
|
3244
3330
|
}
|
|
3245
3331
|
onMessage(e) {
|
|
3246
|
-
this.addMessage(this.codec.decode(e.data,
|
|
3332
|
+
this.addMessage(this.codec.decode(e.data, Xn));
|
|
3247
3333
|
}
|
|
3248
3334
|
onClose(e) {
|
|
3249
3335
|
this.addMessage({
|
|
3250
3336
|
type: "close",
|
|
3251
3337
|
error: {
|
|
3252
|
-
type: e.code ===
|
|
3338
|
+
type: e.code === er ? q.TYPE : F.TYPE,
|
|
3253
3339
|
data: ""
|
|
3254
3340
|
}
|
|
3255
3341
|
});
|
|
3256
3342
|
}
|
|
3257
3343
|
}
|
|
3258
|
-
const
|
|
3259
|
-
class
|
|
3344
|
+
const _n = "freighterctx", er = 1e3;
|
|
3345
|
+
class me extends et {
|
|
3260
3346
|
baseUrl;
|
|
3261
3347
|
encoder;
|
|
3262
3348
|
secure;
|
|
@@ -3270,7 +3356,7 @@ class fe extends Xe {
|
|
|
3270
3356
|
super(), this.secure = r, this.baseUrl = e.replace({ protocol: r ? "wss" : "ws" }), this.encoder = t;
|
|
3271
3357
|
}
|
|
3272
3358
|
withCodec(e) {
|
|
3273
|
-
const t = new
|
|
3359
|
+
const t = new me(this.baseUrl, e, this.secure);
|
|
3274
3360
|
return t.use(...this.middleware), t;
|
|
3275
3361
|
}
|
|
3276
3362
|
/** Implements the StreamClient interface. */
|
|
@@ -3279,9 +3365,9 @@ class fe extends Xe {
|
|
|
3279
3365
|
const [, a] = await this.executeMiddleware(
|
|
3280
3366
|
{ target: e, protocol: "websocket", params: {}, role: "client" },
|
|
3281
3367
|
async (c) => {
|
|
3282
|
-
const
|
|
3283
|
-
|
|
3284
|
-
const f = await this.wrapSocket(
|
|
3368
|
+
const d = new WebSocket(this.buildURL(e, c)), y = { ...c, params: {} };
|
|
3369
|
+
d.binaryType = me.MESSAGE_TYPE;
|
|
3370
|
+
const f = await this.wrapSocket(d, t, r);
|
|
3285
3371
|
return f instanceof Error ? [y, f] : (i = f, [y, null]);
|
|
3286
3372
|
}
|
|
3287
3373
|
);
|
|
@@ -3289,19 +3375,19 @@ class fe extends Xe {
|
|
|
3289
3375
|
return i;
|
|
3290
3376
|
}
|
|
3291
3377
|
buildURL(e, t) {
|
|
3292
|
-
const r =
|
|
3378
|
+
const r = dn(
|
|
3293
3379
|
{
|
|
3294
|
-
[
|
|
3380
|
+
[tt]: this.encoder.contentType,
|
|
3295
3381
|
...t.params
|
|
3296
3382
|
},
|
|
3297
|
-
|
|
3383
|
+
_n
|
|
3298
3384
|
);
|
|
3299
3385
|
return this.baseUrl.child(e).toString() + r;
|
|
3300
3386
|
}
|
|
3301
3387
|
async wrapSocket(e, t, r) {
|
|
3302
3388
|
return await new Promise((i) => {
|
|
3303
3389
|
e.onopen = () => {
|
|
3304
|
-
const a = new
|
|
3390
|
+
const a = new Qn(e, this.encoder, t, r);
|
|
3305
3391
|
a.receiveOpenAck().then((c) => {
|
|
3306
3392
|
c != null ? i(c) : i(a);
|
|
3307
3393
|
}).catch((c) => i(c));
|
|
@@ -3313,11 +3399,11 @@ class fe extends Xe {
|
|
|
3313
3399
|
}
|
|
3314
3400
|
}
|
|
3315
3401
|
export {
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3402
|
+
q as EOF,
|
|
3403
|
+
or as HTTPClient,
|
|
3404
|
+
F as StreamClosed,
|
|
3405
|
+
W as Unreachable,
|
|
3406
|
+
me as WebSocketClient,
|
|
3407
|
+
lr as sendRequired,
|
|
3408
|
+
ur as unaryWithBreaker
|
|
3323
3409
|
};
|