@variantlab/core 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 variantlab contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @variantlab/core
2
+
3
+ The framework-agnostic variantlab engine. Zero dependencies, runs anywhere.
4
+
5
+ > **Status:** Phase 1 — Pre-alpha. Not ready for production use.
6
+
7
+ See the [root README](../../README.md) for project overview, motivation, and roadmap.
@@ -0,0 +1,634 @@
1
+ 'use strict';
2
+
3
+ // src/config/errors.ts
4
+ var ConfigValidationError = class extends Error {
5
+ constructor(issues) {
6
+ super(`Config validation failed with ${issues.length} issue(s)`);
7
+ this.name = "ConfigValidationError";
8
+ this.issues = Object.freeze(issues.slice());
9
+ }
10
+ };
11
+
12
+ // src/config/freeze.ts
13
+ function deepFreeze(value) {
14
+ if (value === null || typeof value !== "object") {
15
+ return value;
16
+ }
17
+ if (Object.isFrozen(value)) {
18
+ return value;
19
+ }
20
+ if (Array.isArray(value)) {
21
+ for (let i = 0; i < value.length; i++) {
22
+ deepFreeze(value[i]);
23
+ }
24
+ return Object.freeze(value);
25
+ }
26
+ const obj = value;
27
+ const keys = Object.keys(obj);
28
+ for (let i = 0; i < keys.length; i++) {
29
+ deepFreeze(obj[keys[i]]);
30
+ }
31
+ return Object.freeze(value);
32
+ }
33
+
34
+ // src/targeting/glob.ts
35
+ function compileGlob(pattern) {
36
+ if (pattern.length === 0) return null;
37
+ if (pattern === "*") return [{ kind: "param" }];
38
+ if (pattern === "**") return [{ kind: "rest" }];
39
+ if (pattern[0] !== "/") return null;
40
+ if (pattern.indexOf("***") >= 0) return null;
41
+ const normalized = pattern.length > 1 && pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
42
+ if (normalized === "/") return [];
43
+ const raw = normalized.slice(1).split("/");
44
+ const segs = [];
45
+ for (let i = 0; i < raw.length; i++) {
46
+ const part = raw[i];
47
+ if (part.length === 0) return null;
48
+ if (part === "**") {
49
+ if (i !== raw.length - 1) return null;
50
+ segs.push({ kind: "rest" });
51
+ continue;
52
+ }
53
+ if (part === "*") {
54
+ segs.push({ kind: "param" });
55
+ continue;
56
+ }
57
+ if (part[0] === ":") {
58
+ if (part.length < 2) return null;
59
+ segs.push({ kind: "param" });
60
+ continue;
61
+ }
62
+ if (/[*:?[\]{}!]/.test(part)) return null;
63
+ segs.push({ kind: "literal", value: part });
64
+ }
65
+ return segs;
66
+ }
67
+
68
+ // src/targeting/semver.ts
69
+ function parseVersion(s) {
70
+ if (s.length === 0) return null;
71
+ const parts = [0, 0, 0];
72
+ let idx = 0;
73
+ let part = 0;
74
+ let seen = false;
75
+ for (let i = 0; i < s.length; i++) {
76
+ const c = s.charCodeAt(i);
77
+ if (c === 46) {
78
+ if (!seen) return null;
79
+ parts[idx++] = part;
80
+ if (idx > 2) return null;
81
+ part = 0;
82
+ seen = false;
83
+ } else if (c >= 48 && c <= 57) {
84
+ part = part * 10 + (c - 48);
85
+ seen = true;
86
+ } else return null;
87
+ }
88
+ if (!seen || idx !== 2) return null;
89
+ parts[2] = part;
90
+ return [parts[0], parts[1], parts[2]];
91
+ }
92
+ function parseSemver(s) {
93
+ if (s.length === 0) return null;
94
+ const clauses = [];
95
+ for (const part of s.split("||")) {
96
+ const c = parseClause(part.trim());
97
+ if (c === null) return null;
98
+ clauses.push(c);
99
+ }
100
+ return clauses;
101
+ }
102
+ function parseClause(s) {
103
+ if (s.length === 0) return null;
104
+ const hy = s.indexOf(" - ");
105
+ if (hy >= 0) {
106
+ const lo = parseVersion(s.slice(0, hy).trim());
107
+ const hi = parseVersion(s.slice(hy + 3).trim());
108
+ if (lo === null || hi === null) return null;
109
+ return [
110
+ { op: ">=", v: lo },
111
+ { op: "<=", v: hi }
112
+ ];
113
+ }
114
+ const cmps = [];
115
+ for (const tok of s.split(/\s+/)) {
116
+ if (tok.length === 0) continue;
117
+ const parsed = parseComparator(tok);
118
+ if (parsed === null) return null;
119
+ for (const c of parsed) cmps.push(c);
120
+ }
121
+ return cmps.length > 0 ? cmps : null;
122
+ }
123
+ function parseComparator(s) {
124
+ const c0 = s[0];
125
+ if (c0 === "^" || c0 === "~") {
126
+ const v2 = parseVersion(s.slice(1));
127
+ if (v2 === null) return null;
128
+ const upper = c0 === "^" ? [v2[0] + 1, 0, 0] : [v2[0], v2[1] + 1, 0];
129
+ return [
130
+ { op: ">=", v: v2 },
131
+ { op: "<", v: upper }
132
+ ];
133
+ }
134
+ let op = "=";
135
+ let rest = s;
136
+ if (c0 === ">" || c0 === "<") {
137
+ if (s[1] === "=") {
138
+ op = `${c0}=`;
139
+ rest = s.slice(2);
140
+ } else {
141
+ op = c0;
142
+ rest = s.slice(1);
143
+ }
144
+ } else if (c0 === "=") {
145
+ rest = s.slice(1);
146
+ }
147
+ const v = parseVersion(rest);
148
+ return v === null ? null : [{ op, v }];
149
+ }
150
+
151
+ // src/config/validator.ts
152
+ var MAX_BYTES = 1048576;
153
+ var MAX_EXP = 1e3;
154
+ var MAX_VAR = 100;
155
+ var MIN_VAR = 2;
156
+ var MAX_ROUTES = 100;
157
+ var MAX_DEPTH = 10;
158
+ var MAX_NAME = 128;
159
+ var MAX_DESC = 512;
160
+ var ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
161
+ var RESERVED = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
162
+ var ASSIGNS = /* @__PURE__ */ new Set(["default", "random", "sticky-hash", "weighted"]);
163
+ var STATUSES = /* @__PURE__ */ new Set(["draft", "active", "archived"]);
164
+ var TYPES = /* @__PURE__ */ new Set(["render", "value"]);
165
+ var PLATFORMS = /* @__PURE__ */ new Set(["ios", "android", "web", "node"]);
166
+ var SIZES = /* @__PURE__ */ new Set(["small", "medium", "large"]);
167
+ function validateConfig(input) {
168
+ const issues = [];
169
+ if (measureBytes(input) > MAX_BYTES) {
170
+ push(issues, "", "config-too-large");
171
+ throw new ConfigValidationError(issues);
172
+ }
173
+ let parsed = input;
174
+ if (typeof input === "string") {
175
+ try {
176
+ parsed = JSON.parse(input);
177
+ } catch (err) {
178
+ push(issues, "", "invalid-json", err.message);
179
+ throw new ConfigValidationError(issues);
180
+ }
181
+ }
182
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
183
+ push(issues, "", "not-an-object");
184
+ throw new ConfigValidationError(issues);
185
+ }
186
+ const sanitized = sanitize(parsed, issues, "");
187
+ validateRoot(sanitized, issues);
188
+ if (issues.length > 0) {
189
+ throw new ConfigValidationError(issues);
190
+ }
191
+ return deepFreeze(sanitized);
192
+ }
193
+ var encoder = new TextEncoder();
194
+ function measureBytes(input) {
195
+ if (typeof input === "string") return encoder.encode(input).length;
196
+ try {
197
+ const s = JSON.stringify(input);
198
+ if (typeof s !== "string") return 0;
199
+ return encoder.encode(s).length;
200
+ } catch {
201
+ return 0;
202
+ }
203
+ }
204
+ function sanitize(value, issues, ptr) {
205
+ if (value === null || typeof value !== "object") return value;
206
+ if (Array.isArray(value)) {
207
+ const out = [];
208
+ for (let i = 0; i < value.length; i++) {
209
+ out.push(sanitize(value[i], issues, `${ptr}/${i}`));
210
+ }
211
+ return out;
212
+ }
213
+ const src = value;
214
+ const dst = /* @__PURE__ */ Object.create(null);
215
+ const keys = Object.keys(src);
216
+ for (let i = 0; i < keys.length; i++) {
217
+ const k = keys[i];
218
+ if (RESERVED.has(k)) {
219
+ push(issues, jp(ptr, k), "reserved-key", k);
220
+ continue;
221
+ }
222
+ dst[k] = sanitize(src[k], issues, jp(ptr, k));
223
+ }
224
+ return dst;
225
+ }
226
+ function validateRoot(root, issues) {
227
+ const version = root["version"];
228
+ if (version === void 0) {
229
+ push(issues, "/version", "version/missing");
230
+ } else if (version !== 1) {
231
+ push(issues, "/version", "version/invalid");
232
+ }
233
+ const enabled = root["enabled"];
234
+ if (enabled !== void 0 && typeof enabled !== "boolean") {
235
+ push(issues, "/enabled", "enabled/invalid");
236
+ }
237
+ const signature = root["signature"];
238
+ if (signature !== void 0 && (typeof signature !== "string" || signature.length === 0)) {
239
+ push(issues, "/signature", "signature/invalid");
240
+ }
241
+ const experiments = root["experiments"];
242
+ if (experiments === void 0) {
243
+ push(issues, "/experiments", "experiments/missing");
244
+ return;
245
+ }
246
+ if (!Array.isArray(experiments)) {
247
+ push(issues, "/experiments", "experiments/not-an-array");
248
+ return;
249
+ }
250
+ if (experiments.length > MAX_EXP) {
251
+ push(issues, "/experiments", "experiments/too-many");
252
+ }
253
+ const seen = /* @__PURE__ */ new Set();
254
+ for (let i = 0; i < experiments.length; i++) {
255
+ validateExperiment(experiments[i], `/experiments/${i}`, seen, issues);
256
+ }
257
+ }
258
+ function validateExperiment(exp, p, seen, issues) {
259
+ if (exp === null || typeof exp !== "object" || Array.isArray(exp)) {
260
+ push(issues, p, "experiment/not-an-object");
261
+ return;
262
+ }
263
+ const e = exp;
264
+ const id = e["id"];
265
+ if (id === void 0) {
266
+ push(issues, `${p}/id`, "experiment/missing-required", "id");
267
+ } else if (typeof id !== "string" || !ID_RE.test(id)) {
268
+ push(issues, `${p}/id`, "experiment/id/invalid");
269
+ } else if (seen.has(id)) {
270
+ push(issues, `${p}/id`, "experiment/id/duplicate", id);
271
+ } else {
272
+ seen.add(id);
273
+ }
274
+ const name = e["name"];
275
+ if (name === void 0) {
276
+ push(issues, `${p}/name`, "experiment/missing-required", "name");
277
+ } else if (typeof name !== "string" || name.length === 0 || name.length > MAX_NAME) {
278
+ push(issues, `${p}/name`, "experiment/name/invalid");
279
+ }
280
+ checkOptString(
281
+ e["description"],
282
+ `${p}/description`,
283
+ MAX_DESC,
284
+ "experiment/description/invalid",
285
+ issues
286
+ );
287
+ checkEnum(e["type"], `${p}/type`, TYPES, "experiment/type/invalid", issues);
288
+ checkEnum(e["status"], `${p}/status`, STATUSES, "experiment/status/invalid", issues);
289
+ checkOptString(e["mutex"], `${p}/mutex`, MAX_NAME, "experiment/mutex/invalid", issues);
290
+ checkOptString(e["owner"], `${p}/owner`, MAX_NAME, "experiment/owner/invalid", issues);
291
+ checkOptBool(e["overridable"], `${p}/overridable`, "experiment/overridable/invalid", issues);
292
+ const variantIds = validateVariants(e["variants"], p, issues);
293
+ validateDefault(e["default"], variantIds, p, issues);
294
+ validateAssignment(e["assignment"], e["split"], variantIds, p, issues);
295
+ validateRoutes(e["routes"], p, issues);
296
+ validateTargeting(e["targeting"], p, issues);
297
+ validateDates(e["startDate"], e["endDate"], p, issues);
298
+ validateRollback(e["rollback"], p, issues);
299
+ }
300
+ function validateVariants(field, p, issues) {
301
+ const ids = /* @__PURE__ */ new Set();
302
+ const vp = `${p}/variants`;
303
+ if (field === void 0) {
304
+ push(issues, vp, "experiment/variants/missing");
305
+ return ids;
306
+ }
307
+ if (!Array.isArray(field)) {
308
+ push(issues, vp, "experiment/variants/missing");
309
+ return ids;
310
+ }
311
+ if (field.length < MIN_VAR) {
312
+ push(issues, vp, "experiment/variants/too-few");
313
+ }
314
+ if (field.length > MAX_VAR) {
315
+ push(issues, vp, "experiment/variants/too-many");
316
+ }
317
+ for (let i = 0; i < field.length; i++) {
318
+ const v = field[i];
319
+ const vip = `${vp}/${i}`;
320
+ if (v === null || typeof v !== "object" || Array.isArray(v)) {
321
+ push(issues, vip, "variant/not-an-object");
322
+ continue;
323
+ }
324
+ const vo = v;
325
+ const vid = vo["id"];
326
+ if (vid === void 0) {
327
+ push(issues, `${vip}/id`, "experiment/missing-required", "variant.id");
328
+ } else if (typeof vid !== "string" || !ID_RE.test(vid)) {
329
+ push(issues, `${vip}/id`, "variant/id/invalid");
330
+ } else if (ids.has(vid)) {
331
+ push(issues, `${vip}/id`, "variant/id/duplicate", vid);
332
+ } else {
333
+ ids.add(vid);
334
+ }
335
+ checkOptString(vo["label"], `${vip}/label`, MAX_NAME, "variant/label/invalid", issues);
336
+ checkOptString(
337
+ vo["description"],
338
+ `${vip}/description`,
339
+ MAX_DESC,
340
+ "variant/description/invalid",
341
+ issues
342
+ );
343
+ }
344
+ return ids;
345
+ }
346
+ function validateDefault(field, ids, p, issues) {
347
+ const dp = `${p}/default`;
348
+ if (field === void 0) {
349
+ push(issues, dp, "experiment/default/missing");
350
+ return;
351
+ }
352
+ if (typeof field !== "string") {
353
+ push(issues, dp, "experiment/default/unknown-variant");
354
+ return;
355
+ }
356
+ if (ids.size > 0 && !ids.has(field)) {
357
+ push(issues, dp, "experiment/default/unknown-variant", field);
358
+ }
359
+ }
360
+ function validateAssignment(aField, sField, ids, p, issues) {
361
+ let strategy = "default";
362
+ if (aField !== void 0) {
363
+ if (typeof aField !== "string" || !ASSIGNS.has(aField)) {
364
+ push(issues, `${p}/assignment`, "experiment/assignment/invalid");
365
+ } else {
366
+ strategy = aField;
367
+ }
368
+ }
369
+ const sp = `${p}/split`;
370
+ if (strategy === "weighted" && sField === void 0) {
371
+ push(issues, sp, "split/missing");
372
+ return;
373
+ }
374
+ if (sField === void 0) return;
375
+ if (sField === null || typeof sField !== "object" || Array.isArray(sField)) {
376
+ push(issues, sp, "split/not-an-object");
377
+ return;
378
+ }
379
+ const split = sField;
380
+ const keys = Object.keys(split);
381
+ let sum = 0;
382
+ let bad = false;
383
+ for (let i = 0; i < keys.length; i++) {
384
+ const k = keys[i];
385
+ if (ids.size > 0 && !ids.has(k)) {
386
+ push(issues, `${sp}/${esc(k)}`, "split/unknown-variant", k);
387
+ bad = true;
388
+ continue;
389
+ }
390
+ const v = split[k];
391
+ if (typeof v !== "number" || !Number.isInteger(v) || v < 0 || v > 100) {
392
+ push(issues, `${sp}/${esc(k)}`, "split/value-invalid");
393
+ bad = true;
394
+ continue;
395
+ }
396
+ sum += v;
397
+ }
398
+ if (!bad && sum !== 100) {
399
+ push(issues, sp, "split/sum-invalid", String(sum));
400
+ }
401
+ }
402
+ function validateRoutes(field, p, issues) {
403
+ if (field === void 0) return;
404
+ const rp = `${p}/routes`;
405
+ if (!Array.isArray(field)) {
406
+ push(issues, rp, "experiment/routes/invalid");
407
+ return;
408
+ }
409
+ if (field.length > MAX_ROUTES) {
410
+ push(issues, rp, "experiment/routes/invalid");
411
+ }
412
+ for (let i = 0; i < field.length; i++) {
413
+ const r = field[i];
414
+ if (typeof r !== "string" || compileGlob(r) === null) {
415
+ push(issues, `${rp}/${i}`, "route/glob/invalid");
416
+ }
417
+ }
418
+ }
419
+ function validateTargeting(field, p, issues) {
420
+ if (field === void 0) return;
421
+ const tp = `${p}/targeting`;
422
+ if (field === null || typeof field !== "object" || Array.isArray(field)) {
423
+ push(issues, tp, "targeting/not-an-object");
424
+ return;
425
+ }
426
+ if (depthOf(field, 0) > MAX_DEPTH) {
427
+ push(issues, tp, "targeting/depth-exceeded");
428
+ }
429
+ const t = field;
430
+ if (t["platform"] !== void 0) {
431
+ checkEnumArray(
432
+ t["platform"],
433
+ `${tp}/platform`,
434
+ PLATFORMS,
435
+ "targeting/platform/invalid",
436
+ issues
437
+ );
438
+ }
439
+ if (t["appVersion"] !== void 0) {
440
+ const v = t["appVersion"];
441
+ if (typeof v !== "string" || parseSemver(v) === null) {
442
+ push(issues, `${tp}/appVersion`, "targeting/appversion/invalid");
443
+ }
444
+ }
445
+ if (t["locale"] !== void 0) {
446
+ checkStringArray(t["locale"], `${tp}/locale`, "targeting/locale/invalid", issues);
447
+ }
448
+ if (t["screenSize"] !== void 0) {
449
+ checkEnumArray(
450
+ t["screenSize"],
451
+ `${tp}/screenSize`,
452
+ SIZES,
453
+ "targeting/screensize/invalid",
454
+ issues
455
+ );
456
+ }
457
+ if (t["routes"] !== void 0) {
458
+ const r = t["routes"];
459
+ if (!Array.isArray(r) || r.length === 0) {
460
+ push(issues, `${tp}/routes`, "targeting/routes/invalid");
461
+ } else {
462
+ for (let i = 0; i < r.length; i++) {
463
+ const v = r[i];
464
+ if (typeof v !== "string" || compileGlob(v) === null) {
465
+ push(issues, `${tp}/routes/${i}`, "targeting/routes/invalid");
466
+ }
467
+ }
468
+ }
469
+ }
470
+ if (t["userId"] !== void 0) {
471
+ validateUserId(t["userId"], `${tp}/userId`, issues);
472
+ }
473
+ if (t["attributes"] !== void 0) {
474
+ const a = t["attributes"];
475
+ if (a === null || typeof a !== "object" || Array.isArray(a)) {
476
+ push(issues, `${tp}/attributes`, "targeting/attributes/invalid");
477
+ }
478
+ }
479
+ }
480
+ function validateUserId(u, p, issues) {
481
+ const code = "targeting/userid/invalid";
482
+ if (Array.isArray(u)) {
483
+ if (u.length === 0) {
484
+ push(issues, p, code);
485
+ return;
486
+ }
487
+ for (let i = 0; i < u.length; i++) {
488
+ const v = u[i];
489
+ if (typeof v !== "string" || v.length === 0) {
490
+ push(issues, `${p}/${i}`, code);
491
+ }
492
+ }
493
+ return;
494
+ }
495
+ if (u !== null && typeof u === "object") {
496
+ const o = u;
497
+ const h = o["hash"];
498
+ const m = o["mod"];
499
+ if (typeof h !== "string" || h.length === 0) {
500
+ push(issues, `${p}/hash`, code);
501
+ }
502
+ if (typeof m !== "number" || !Number.isInteger(m) || m < 0 || m > 100) {
503
+ push(issues, `${p}/mod`, code);
504
+ }
505
+ return;
506
+ }
507
+ push(issues, p, code);
508
+ }
509
+ function validateDates(sField, eField, p, issues) {
510
+ let s;
511
+ let e;
512
+ if (sField !== void 0) {
513
+ if (typeof sField !== "string" || !isValidIsoDate(sField)) {
514
+ push(issues, `${p}/startDate`, "experiment/startdate/invalid");
515
+ } else {
516
+ s = Date.parse(sField);
517
+ }
518
+ }
519
+ if (eField !== void 0) {
520
+ if (typeof eField !== "string" || !isValidIsoDate(eField)) {
521
+ push(issues, `${p}/endDate`, "experiment/enddate/invalid");
522
+ } else {
523
+ e = Date.parse(eField);
524
+ }
525
+ }
526
+ if (s !== void 0 && e !== void 0 && !(e > s)) {
527
+ push(issues, `${p}/endDate`, "experiment/date-range/invalid");
528
+ }
529
+ }
530
+ function validateRollback(field, p, issues) {
531
+ if (field === void 0) return;
532
+ const rp = `${p}/rollback`;
533
+ if (field === null || typeof field !== "object" || Array.isArray(field)) {
534
+ push(issues, rp, "rollback/not-an-object");
535
+ return;
536
+ }
537
+ const r = field;
538
+ const thr = r["threshold"];
539
+ if (thr === void 0) {
540
+ push(issues, `${rp}/threshold`, "rollback/threshold/invalid");
541
+ } else if (typeof thr !== "number" || !Number.isInteger(thr) || thr < 1 || thr > 100) {
542
+ push(issues, `${rp}/threshold`, "rollback/threshold/invalid");
543
+ }
544
+ const win = r["window"];
545
+ if (win === void 0) {
546
+ push(issues, `${rp}/window`, "rollback/window/invalid");
547
+ } else if (typeof win !== "number" || !Number.isInteger(win) || win < 1e3 || win > 36e5) {
548
+ push(issues, `${rp}/window`, "rollback/window/invalid");
549
+ }
550
+ const persistent = r["persistent"];
551
+ if (persistent !== void 0 && typeof persistent !== "boolean") {
552
+ push(issues, `${rp}/persistent`, "rollback/persistent/invalid");
553
+ }
554
+ }
555
+ function checkOptString(v, p, max, code, issues) {
556
+ if (v === void 0) return;
557
+ if (typeof v !== "string" || v.length === 0 || v.length > max) {
558
+ push(issues, p, code);
559
+ }
560
+ }
561
+ function checkOptBool(v, p, code, issues) {
562
+ if (v === void 0) return;
563
+ if (typeof v !== "boolean") {
564
+ push(issues, p, code);
565
+ }
566
+ }
567
+ function checkEnum(v, p, set, code, issues) {
568
+ if (v === void 0) return;
569
+ if (typeof v !== "string" || !set.has(v)) {
570
+ push(issues, p, code);
571
+ }
572
+ }
573
+ function checkEnumArray(v, p, set, code, issues) {
574
+ if (!Array.isArray(v) || v.length === 0) {
575
+ push(issues, p, code);
576
+ return;
577
+ }
578
+ for (let i = 0; i < v.length; i++) {
579
+ const x = v[i];
580
+ if (typeof x !== "string" || !set.has(x)) {
581
+ push(issues, `${p}/${i}`, code);
582
+ }
583
+ }
584
+ }
585
+ function checkStringArray(v, p, code, issues) {
586
+ if (!Array.isArray(v) || v.length === 0) {
587
+ push(issues, p, code);
588
+ return;
589
+ }
590
+ for (let i = 0; i < v.length; i++) {
591
+ const x = v[i];
592
+ if (typeof x !== "string" || x.length === 0) {
593
+ push(issues, `${p}/${i}`, code);
594
+ }
595
+ }
596
+ }
597
+ var ISO_TAIL_RE = /T.*(?:Z|[+-]\d{2}:?\d{2})$/;
598
+ function isValidIsoDate(s) {
599
+ if (s.length < 10) return false;
600
+ if (Number.isNaN(Date.parse(s))) return false;
601
+ return ISO_TAIL_RE.test(s);
602
+ }
603
+ function depthOf(value, current) {
604
+ if (value === null || typeof value !== "object") return current;
605
+ let m = current;
606
+ if (Array.isArray(value)) {
607
+ for (let i = 0; i < value.length; i++) {
608
+ const d = depthOf(value[i], current + 1);
609
+ if (d > m) m = d;
610
+ }
611
+ return m;
612
+ }
613
+ const obj = value;
614
+ const keys = Object.keys(obj);
615
+ for (let i = 0; i < keys.length; i++) {
616
+ const d = depthOf(obj[keys[i]], current + 1);
617
+ if (d > m) m = d;
618
+ }
619
+ return m;
620
+ }
621
+ function jp(parent, key) {
622
+ return `${parent}/${esc(key)}`;
623
+ }
624
+ function esc(s) {
625
+ return s.replace(/~/g, "~0").replace(/\//g, "~1");
626
+ }
627
+ function push(issues, path, code, message) {
628
+ issues.push({ path, code, message: message ?? code });
629
+ }
630
+
631
+ exports.ConfigValidationError = ConfigValidationError;
632
+ exports.validateConfig = validateConfig;
633
+ //# sourceMappingURL=config.cjs.map
634
+ //# sourceMappingURL=config.cjs.map