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