@amazon/vinyl-hls-parser 1.1.1 → 2.0.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.
Files changed (84) hide show
  1. package/dist/hlsTestAssets/types/current/tsconfig.tsbuildinfo +1 -1
  2. package/dist/index.cjs +140 -58
  3. package/dist/index.cjs.map +4 -4
  4. package/dist/index.js +139 -57
  5. package/dist/index.js.map +4 -4
  6. package/dist/test/benchmark.es5.js +79 -255
  7. package/dist/test/benchmark.js +584 -1224
  8. package/dist/test/benchmark.js.map +4 -4
  9. package/dist/types/current/index.d.ts +11 -10
  10. package/dist/types/current/index.d.ts.map +1 -1
  11. package/dist/types/current/index.js +11 -10
  12. package/dist/types/current/parse/parseMainPlaylist.d.ts +8 -3
  13. package/dist/types/current/parse/parseMainPlaylist.d.ts.map +1 -1
  14. package/dist/types/current/parse/parseMainPlaylist.js +43 -5
  15. package/dist/types/current/parse/parseMediaPlaylist.d.ts +11 -4
  16. package/dist/types/current/parse/parseMediaPlaylist.d.ts.map +1 -1
  17. package/dist/types/current/parse/parseMediaPlaylist.js +111 -7
  18. package/dist/types/current/tsconfig.tsbuildinfo +1 -1
  19. package/dist/types/current/types/AlternativeRendition.d.ts +13 -0
  20. package/dist/types/current/types/AlternativeRendition.d.ts.map +1 -1
  21. package/dist/types/current/types/HlsDateRange.d.ts +51 -0
  22. package/dist/types/current/types/HlsDateRange.d.ts.map +1 -0
  23. package/dist/types/current/types/HlsDateRange.js +11 -0
  24. package/dist/types/{ts4.7/types/MainPlaylist.d.ts → current/types/HlsMainPlaylist.d.ts} +4 -4
  25. package/dist/types/current/types/HlsMainPlaylist.d.ts.map +1 -0
  26. package/dist/types/{ts4.1/types/MediaPlaylist.d.ts → current/types/HlsMediaPlaylist.d.ts} +11 -4
  27. package/dist/types/current/types/HlsMediaPlaylist.d.ts.map +1 -0
  28. package/dist/types/ts3.7/index.d.ts +11 -10
  29. package/dist/types/ts3.7/parse/parseMainPlaylist.d.ts +8 -3
  30. package/dist/types/ts3.7/parse/parseMediaPlaylist.d.ts +11 -4
  31. package/dist/types/ts3.7/types/AlternativeRendition.d.ts +13 -0
  32. package/dist/types/ts3.7/types/HlsDateRange.d.ts +51 -0
  33. package/dist/types/ts3.7/types/{MainPlaylist.d.ts → HlsMainPlaylist.d.ts} +4 -4
  34. package/dist/types/ts3.7/types/{MediaPlaylist.d.ts → HlsMediaPlaylist.d.ts} +11 -4
  35. package/dist/types/ts4.1/index.d.ts +11 -10
  36. package/dist/types/ts4.1/parse/parseMainPlaylist.d.ts +8 -3
  37. package/dist/types/ts4.1/parse/parseMediaPlaylist.d.ts +11 -4
  38. package/dist/types/ts4.1/types/AlternativeRendition.d.ts +13 -0
  39. package/dist/types/ts4.1/types/HlsDateRange.d.ts +51 -0
  40. package/dist/types/{current/types/MainPlaylist.d.ts → ts4.1/types/HlsMainPlaylist.d.ts} +4 -4
  41. package/dist/types/{current/types/MediaPlaylist.d.ts → ts4.1/types/HlsMediaPlaylist.d.ts} +11 -4
  42. package/dist/types/ts4.7/index.d.ts +11 -10
  43. package/dist/types/ts4.7/parse/parseMainPlaylist.d.ts +8 -3
  44. package/dist/types/ts4.7/parse/parseMediaPlaylist.d.ts +11 -4
  45. package/dist/types/ts4.7/types/AlternativeRendition.d.ts +13 -0
  46. package/dist/types/ts4.7/types/HlsDateRange.d.ts +51 -0
  47. package/dist/types/{ts4.1/types/MainPlaylist.d.ts → ts4.7/types/HlsMainPlaylist.d.ts} +4 -4
  48. package/dist/types/ts4.7/types/{MediaPlaylist.d.ts → HlsMediaPlaylist.d.ts} +11 -4
  49. package/package.json +30 -19
  50. package/dist/test/benchmark.css +0 -71
  51. package/dist/test/benchmark.html +0 -67
  52. package/dist/test/favicon.png +0 -0
  53. package/dist/test/index.html +0 -61
  54. package/dist/test/integ.es5.js +0 -410
  55. package/dist/test/integ.js +0 -2127
  56. package/dist/test/integ.js.map +0 -7
  57. package/dist/test/jasmine.css +0 -304
  58. package/dist/test/jasmineHtml.es5.js +0 -670
  59. package/dist/test/jasmineHtml.js +0 -10851
  60. package/dist/test/jasmineHtml.js.map +0 -7
  61. package/dist/test/styles.css +0 -42
  62. package/dist/types/current/types/MainPlaylist.d.ts.map +0 -1
  63. package/dist/types/current/types/MediaPlaylist.d.ts.map +0 -1
  64. package/dist/unit/types/current/index.d.ts +0 -7
  65. package/dist/unit/types/current/index.d.ts.map +0 -1
  66. package/dist/unit/types/current/index.js +0 -6
  67. package/dist/unit/types/current/parse/parseAttributes.test.d.ts +0 -2
  68. package/dist/unit/types/current/parse/parseAttributes.test.d.ts.map +0 -1
  69. package/dist/unit/types/current/parse/parseAttributes.test.js +0 -70
  70. package/dist/unit/types/current/parse/parseMainPlaylist.test.d.ts +0 -2
  71. package/dist/unit/types/current/parse/parseMainPlaylist.test.d.ts.map +0 -1
  72. package/dist/unit/types/current/parse/parseMainPlaylist.test.js +0 -194
  73. package/dist/unit/types/current/parse/parseMediaPlaylist.test.d.ts +0 -2
  74. package/dist/unit/types/current/parse/parseMediaPlaylist.test.d.ts.map +0 -1
  75. package/dist/unit/types/current/parse/parseMediaPlaylist.test.js +0 -401
  76. package/dist/unit/types/current/parse/parseUtil.test.d.ts +0 -2
  77. package/dist/unit/types/current/parse/parseUtil.test.d.ts.map +0 -1
  78. package/dist/unit/types/current/parse/parseUtil.test.js +0 -67
  79. package/dist/unit/types/current/setup.d.ts +0 -2
  80. package/dist/unit/types/current/setup.d.ts.map +0 -1
  81. package/dist/unit/types/current/setup.js +0 -19
  82. package/dist/unit/types/current/tsconfig.tsbuildinfo +0 -1
  83. /package/dist/types/current/types/{MainPlaylist.js → HlsMainPlaylist.js} +0 -0
  84. /package/dist/types/current/types/{MediaPlaylist.js → HlsMediaPlaylist.js} +0 -0
@@ -19,31 +19,21 @@
19
19
  return a;
20
20
  };
21
21
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
-
23
- // ../vinyl-util/dist/index.js
24
- var __defProp2 = Object.defineProperty;
25
- var __defProps2 = Object.defineProperties;
26
- var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
27
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
28
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
29
- var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
30
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
31
- var __spreadValues2 = (a, b) => {
32
- for (var prop in b || (b = {}))
33
- if (__hasOwnProp2.call(b, prop))
34
- __defNormalProp2(a, prop, b[prop]);
35
- if (__getOwnPropSymbols2)
36
- for (var prop of __getOwnPropSymbols2(b)) {
37
- if (__propIsEnum2.call(b, prop))
38
- __defNormalProp2(a, prop, b[prop]);
22
+ var __objRest = (source, exclude) => {
23
+ var target = {};
24
+ for (var prop in source)
25
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
26
+ target[prop] = source[prop];
27
+ if (source != null && __getOwnPropSymbols)
28
+ for (var prop of __getOwnPropSymbols(source)) {
29
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
30
+ target[prop] = source[prop];
39
31
  }
40
- return a;
32
+ return target;
41
33
  };
42
- var __spreadProps2 = (a, b) => __defProps2(a, __getOwnPropDescs2(b));
43
- var __publicField = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
44
- function invariant() {
45
- return void 0;
46
- }
34
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
35
+
36
+ // ../vinyl-util/src/error/ErrorOrigin.ts
47
37
  var ErrorOrigin = {
48
38
  /**
49
39
  * The error originated from Vinyl and was reported from the uncaught exception or promise
@@ -88,11 +78,13 @@
88
78
  */
89
79
  DRM: "drm"
90
80
  };
81
+
82
+ // ../vinyl-util/src/error/ReportableError.ts
91
83
  var ReportableError = class _ReportableError extends Error {
92
- constructor(message, origin = ErrorOrigin.INTERNAL, level = "fatal") {
84
+ constructor(message, origin = ErrorOrigin.INTERNAL, level = "fatal" /* FATAL */) {
93
85
  super(message);
94
- this.origin = origin;
95
- this.level = level;
86
+ __publicField(this, "origin", origin);
87
+ __publicField(this, "level", level);
96
88
  Object.setPrototypeOf(this, _ReportableError.prototype);
97
89
  }
98
90
  get [Symbol.toStringTag]() {
@@ -114,16 +106,34 @@
114
106
  };
115
107
  }
116
108
  };
109
+
110
+ // ../vinyl-util/src/error/IllegalArgumentError.ts
117
111
  var IllegalArgumentError = class _IllegalArgumentError extends ReportableError {
118
112
  constructor(message, isInternal = true) {
119
113
  super(message, isInternal ? ErrorOrigin.INTERNAL : ErrorOrigin.API);
120
- this.isInternal = isInternal;
114
+ __publicField(this, "isInternal", isInternal);
121
115
  Object.setPrototypeOf(this, _IllegalArgumentError.prototype);
122
116
  }
123
117
  get [Symbol.toStringTag]() {
124
118
  return "IllegalArgumentError";
125
119
  }
126
120
  };
121
+
122
+ // ../vinyl-util/src/util/map/map.ts
123
+ function flipMap(map) {
124
+ const result = /* @__PURE__ */ new Map();
125
+ for (const [key, value] of map) {
126
+ result.set(value, key);
127
+ }
128
+ return result;
129
+ }
130
+
131
+ // ../vinyl-util/src/util/type.ts
132
+ function invariant() {
133
+ return void 0;
134
+ }
135
+
136
+ // ../vinyl-util/src/util/string/string.ts
127
137
  var locale = {
128
138
  variableNotDefined: "Variable '{name}' is not defined"
129
139
  };
@@ -144,6 +154,14 @@
144
154
  charCode === 13 || // '\r' (carriage return)
145
155
  charCode === 10;
146
156
  }
157
+ var predefinedDecodeEntities = /* @__PURE__ */ new Map([
158
+ ["apos", "'"],
159
+ ["amp", "&"],
160
+ ["lt", "<"],
161
+ ["gt", ">"],
162
+ ["quot", '"']
163
+ ]);
164
+ var standardEntityValueToNames = flipMap(predefinedDecodeEntities);
147
165
  function eqStr(a, b, ignoreCase = false) {
148
166
  if (a == null && b == null) return true;
149
167
  if (a == null || b == null) return false;
@@ -161,9 +179,103 @@
161
179
  return str.substring(0, maxLength - indicator.length) + indicator;
162
180
  return str;
163
181
  }
164
- function clamp(value, min2, max2) {
165
- return Math.min(Math.max(value, min2), max2);
182
+
183
+ // ../vinyl-util/src/util/object/object.ts
184
+ function ownKeys(obj) {
185
+ if (!obj) return /* @__PURE__ */ new Set();
186
+ if (typeof Reflect !== "undefined")
187
+ return new Set(Reflect.ownKeys(obj));
188
+ const properties = /* @__PURE__ */ new Set();
189
+ Object.getOwnPropertyNames(obj).forEach((item) => properties.add(item));
190
+ Object.getOwnPropertySymbols(obj).forEach((item) => properties.add(item));
191
+ return properties;
192
+ }
193
+ function isPlainObject(value) {
194
+ if (!value || typeof value !== "object" || Array.isArray(value))
195
+ return false;
196
+ const proto = Object.getPrototypeOf(value);
197
+ return !proto || !Object.getPrototypeOf(proto);
198
+ }
199
+
200
+ // ../vinyl-util/src/util/serialization/json.ts
201
+ function toJson(value) {
202
+ return toJsonInternal(value, /* @__PURE__ */ new Set());
203
+ }
204
+ function toJsonInternal(value, visited) {
205
+ switch (typeof value) {
206
+ case "object":
207
+ return objectToJsonInternal(value, visited);
208
+ case "undefined":
209
+ case "boolean":
210
+ case "number":
211
+ case "string":
212
+ return value;
213
+ case "function":
214
+ return `[function ${value.name}]`;
215
+ case "symbol":
216
+ return `[symbol ${value.toString().slice(7, -1)}]`;
217
+ case "bigint":
218
+ return value.toString();
219
+ }
220
+ }
221
+ function objectToJsonInternal(value, visited) {
222
+ if (value == null) return value;
223
+ if (visited.has(value)) return `<circular reference: ${String(value)}>`;
224
+ visited.add(value);
225
+ if ("toJSON" in value && typeof value.toJSON === "function")
226
+ return value.toJSON();
227
+ if (value instanceof Set) {
228
+ return Array.from(value).map((e) => toJsonInternal(e, visited));
229
+ } else if (Array.isArray(value)) {
230
+ return value.map((e) => toJsonInternal(e, visited));
231
+ } else {
232
+ if (isPlainObject(value)) {
233
+ const o = {};
234
+ for (const key in value) {
235
+ o[key] = toJsonInternal(value[key], visited);
236
+ }
237
+ return o;
238
+ } else if (value instanceof Error) {
239
+ return {
240
+ name: value.name,
241
+ message: value.message,
242
+ stack: value.stack
243
+ };
244
+ } else {
245
+ return value.toString();
246
+ }
247
+ }
248
+ }
249
+
250
+ // ../vinyl-util/src/error/ValidationError.ts
251
+ var ValidationError = class _ValidationError extends ReportableError {
252
+ /**
253
+ * @param message The validation error message.
254
+ * @param origin The error origin, typically API (default) or SERVICE_EXTERNAL
255
+ * @param path The property path to the invalid field.
256
+ */
257
+ constructor(message, origin = ErrorOrigin.API, path = []) {
258
+ super(message, origin);
259
+ __publicField(this, "path", path);
260
+ Object.setPrototypeOf(this, _ValidationError.prototype);
261
+ }
262
+ get [Symbol.toStringTag]() {
263
+ return "ValidationError";
264
+ }
265
+ toJSON() {
266
+ return __spreadProps(__spreadValues({}, super.toJSON()), {
267
+ origin: this.origin,
268
+ path: this.path
269
+ });
270
+ }
271
+ };
272
+
273
+ // ../vinyl-util/src/util/math/math.ts
274
+ function clamp(value, min, max) {
275
+ return Math.min(Math.max(value, min), max);
166
276
  }
277
+
278
+ // ../vinyl-util/src/util/serialization/ParseError.ts
167
279
  function printStringPosition(str, index, options) {
168
280
  var _a;
169
281
  const caret = (options == null ? void 0 : options.caret) || "^";
@@ -190,12 +302,42 @@
190
302
  out += " ".repeat(leadingChars) + caret;
191
303
  return out;
192
304
  }
305
+
306
+ // ../vinyl-util/src/util/serialization/stringifyForPrint.ts
307
+ function stringifyForPrint(value, maxLength, indicator = "\u2026") {
308
+ let str = JSON.stringify(
309
+ toJson(value),
310
+ (_, value2) => {
311
+ const type = typeof value2;
312
+ if (["undefined"].includes(type)) {
313
+ return `{{${String(value2)}}}`;
314
+ }
315
+ if (type === "number") {
316
+ if (Number.isNaN(value2) || !Number.isFinite(value2))
317
+ return `{{${value2.toString()}}}`;
318
+ }
319
+ return value2;
320
+ },
321
+ " "
322
+ );
323
+ str = str.replace(/("\{\{.*}}")/g, (_, s) => {
324
+ return s.substring(3, s.length - 3);
325
+ });
326
+ if (maxLength) str = truncate(str, maxLength, indicator);
327
+ return str;
328
+ }
329
+
330
+ // ../vinyl-util/src/util/string/StringReader.ts
193
331
  var StringReader = class {
194
332
  /**
195
333
  * @param data The string to read.
196
334
  */
197
335
  constructor(data) {
198
- this.data = data;
336
+ __publicField(this, "data", data);
337
+ /**
338
+ * The current cursor.
339
+ * This should always be between the range 0 and `data.length`
340
+ */
199
341
  __publicField(this, "position", 0);
200
342
  }
201
343
  /**
@@ -394,168 +536,65 @@
394
536
  };
395
537
  var StringParseError = class _StringParseError extends ReportableError {
396
538
  constructor(str, position, reason) {
397
- const location2 = printStringPosition(str, position);
539
+ const location = printStringPosition(str, position);
398
540
  super(
399
- `${reason}${locale2.messageSeparator}${location2}`,
541
+ `${reason}${locale2.messageSeparator}${location}`,
400
542
  ErrorOrigin.PARSING
401
543
  );
402
- this.position = position;
403
- this.reason = reason;
544
+ __publicField(this, "position", position);
545
+ __publicField(this, "reason", reason);
404
546
  __publicField(this, "location");
405
- this.location = location2;
547
+ this.location = location;
406
548
  Object.setPrototypeOf(this, _StringParseError.prototype);
407
549
  }
408
550
  get [Symbol.toStringTag]() {
409
551
  return "StringParseError";
410
552
  }
411
553
  toJSON() {
412
- return __spreadProps2(__spreadValues2({}, super.toJSON()), {
554
+ return __spreadProps(__spreadValues({}, super.toJSON()), {
413
555
  position: this.position,
414
556
  location: this.location,
415
557
  reason: this.reason
416
558
  });
417
559
  }
418
560
  };
419
- function ownKeys(obj) {
420
- if (!obj) return /* @__PURE__ */ new Set();
421
- if (typeof Reflect !== "undefined")
422
- return new Set(Reflect.ownKeys(obj));
423
- const properties = /* @__PURE__ */ new Set();
424
- Object.getOwnPropertyNames(obj).forEach((item) => properties.add(item));
425
- Object.getOwnPropertySymbols(obj).forEach((item) => properties.add(item));
426
- return properties;
427
- }
428
- function isPlainObject(value) {
429
- if (!value || typeof value !== "object" || Array.isArray(value))
430
- return false;
431
- const proto = Object.getPrototypeOf(value);
432
- return !proto || !Object.getPrototypeOf(proto);
433
- }
434
- function toJson(value) {
435
- return toJsonInternal(value, /* @__PURE__ */ new Set());
436
- }
437
- function toJsonInternal(value, visited) {
438
- switch (typeof value) {
439
- case "object":
440
- return objectToJsonInternal(value, visited);
441
- case "undefined":
442
- case "boolean":
443
- case "number":
444
- case "string":
445
- return value;
446
- case "function":
447
- return `[function ${value.name}]`;
448
- case "symbol":
449
- return `[symbol ${value.toString().slice(7, -1)}]`;
450
- case "bigint":
451
- return value.toString();
452
- }
453
- }
454
- function objectToJsonInternal(value, visited) {
455
- if (value == null) return value;
456
- if (visited.has(value)) return `<circular reference: ${String(value)}>`;
457
- visited.add(value);
458
- if ("toJSON" in value && typeof value.toJSON === "function")
459
- return value.toJSON();
460
- if (value instanceof Set) {
461
- return Array.from(value).map((e) => toJsonInternal(e, visited));
462
- } else if (Array.isArray(value)) {
463
- return value.map((e) => toJsonInternal(e, visited));
464
- } else {
465
- if (isPlainObject(value)) {
466
- const o = {};
467
- for (const key in value) {
468
- o[key] = toJsonInternal(value[key], visited);
469
- }
470
- return o;
471
- } else if (value instanceof Error) {
472
- return {
473
- name: value.name,
474
- message: value.message,
475
- stack: value.stack
476
- };
561
+
562
+ // src/parse/parseAttributes.ts
563
+ var EQUALS = char("=");
564
+ var COMMA = char(",");
565
+ var QUOTE = char('"');
566
+ function parseAttributes(reader) {
567
+ const attrs = {};
568
+ while (reader.hasNext() && reader.peek !== char("\n") && reader.peek !== char("\r")) {
569
+ const key = reader.substringUntilChar(EQUALS);
570
+ if (!key || !reader.hasNext()) break;
571
+ reader.next();
572
+ let value;
573
+ if (reader.peek === QUOTE) {
574
+ reader.next();
575
+ value = reader.substringUntilChar(QUOTE);
576
+ if (reader.hasNext()) reader.next();
477
577
  } else {
478
- return value.toString();
578
+ value = reader.substringUntil(
579
+ (cc) => cc === COMMA || cc === char("\n") || cc === char("\r")
580
+ );
581
+ }
582
+ attrs[key] = value;
583
+ if (reader.hasNext() && reader.peek === COMMA) {
584
+ reader.next();
479
585
  }
480
586
  }
587
+ return attrs;
481
588
  }
482
- function stringifyForPrint(value, maxLength, indicator = "\u2026") {
483
- let str = JSON.stringify(
484
- toJson(value),
485
- (_, value2) => {
486
- const type = typeof value2;
487
- if (["undefined"].includes(type)) {
488
- return `{{${String(value2)}}}`;
489
- }
490
- if (type === "number") {
491
- if (Number.isNaN(value2) || !Number.isFinite(value2))
492
- return `{{${value2.toString()}}}`;
493
- }
494
- return value2;
495
- },
496
- " "
497
- );
498
- str = str.replace(/("\{\{.*}}")/g, (_, s) => {
499
- return s.substring(3, s.length - 3);
500
- });
501
- if (maxLength) str = truncate(str, maxLength, indicator);
502
- return str;
503
- }
504
- function merge(...sources) {
505
- if (!sources.length) return void 0;
506
- if (Array.isArray(sources[0])) return Array.prototype.concat(...sources);
507
- return Object.assign({}, ...sources);
508
- }
509
- var ValidationError = class _ValidationError extends ReportableError {
589
+
590
+ // ../vinyl-validation/src/validation/Validator.ts
591
+ var validatorLocale = {
510
592
  /**
511
- * @param message The validation error message.
512
- * @param origin The error origin, typically API (default) or SERVICE_EXTERNAL
513
- * @param path The property path to the invalid field.
514
- */
515
- constructor(message, origin = ErrorOrigin.API, path = []) {
516
- super(message, origin);
517
- this.path = path;
518
- Object.setPrototypeOf(this, _ValidationError.prototype);
519
- }
520
- get [Symbol.toStringTag]() {
521
- return "ValidationError";
522
- }
523
- toJSON() {
524
- return __spreadProps2(__spreadValues2({}, super.toJSON()), {
525
- origin: this.origin,
526
- path: this.path
527
- });
528
- }
529
- };
530
-
531
- // ../vinyl-validation/dist/index.js
532
- var __defProp3 = Object.defineProperty;
533
- var __defProps3 = Object.defineProperties;
534
- var __getOwnPropDescs3 = Object.getOwnPropertyDescriptors;
535
- var __getOwnPropSymbols3 = Object.getOwnPropertySymbols;
536
- var __hasOwnProp3 = Object.prototype.hasOwnProperty;
537
- var __propIsEnum3 = Object.prototype.propertyIsEnumerable;
538
- var __defNormalProp3 = (obj, key, value) => key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
539
- var __spreadValues3 = (a, b) => {
540
- for (var prop in b || (b = {}))
541
- if (__hasOwnProp3.call(b, prop))
542
- __defNormalProp3(a, prop, b[prop]);
543
- if (__getOwnPropSymbols3)
544
- for (var prop of __getOwnPropSymbols3(b)) {
545
- if (__propIsEnum3.call(b, prop))
546
- __defNormalProp3(a, prop, b[prop]);
547
- }
548
- return a;
549
- };
550
- var __spreadProps3 = (a, b) => __defProps3(a, __getOwnPropDescs3(b));
551
- var __publicField2 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
552
- var validatorLocale = {
553
- /**
554
- * The expectation template string with the following replacement tokens:
555
- *
556
- * `{expected}` - The expected description.
557
- * `{actual}` - The actual value.
558
- * `{path}` - The path, dot separated.
593
+ * The expectation template string with the following replacement tokens:
594
+ *
595
+ * `{expected}` - The expected description.
596
+ * `{actual}` - The actual value.
597
+ * `{path}` - The path, dot separated.
559
598
  */
560
599
  template: "Expected: {expected}, but was: {actual}. At: {path}"
561
600
  };
@@ -566,9 +605,10 @@
566
605
  path: path.join(".")
567
606
  });
568
607
  }
569
- function createValidator(expectationMessage, isValid, inputStringify = (input) => stringifyForPrint(input, 500)) {
608
+ function createValidator(expectationMessage, isValid, inputStringify = (input) => stringifyForPrint(input, 500), jsonSchema) {
570
609
  return {
571
610
  description: expectationMessage,
611
+ jsonSchema,
572
612
  isValid(input) {
573
613
  return isValid(input);
574
614
  },
@@ -604,9 +644,10 @@
604
644
  }
605
645
  };
606
646
  }
607
- function createDeepValidator(description, validate) {
647
+ function createDeepValidator(description, validate, jsonSchema) {
608
648
  return {
609
649
  description,
650
+ jsonSchema,
610
651
  isValid(input) {
611
652
  return validate(input, { all: false }, []).length === 0;
612
653
  },
@@ -622,6 +663,33 @@
622
663
  }
623
664
  };
624
665
  }
666
+
667
+ // ../vinyl-validation/src/validation/JsonSchema.ts
668
+ function mergeJsonSchema(...fragments) {
669
+ var _a;
670
+ const merged = {};
671
+ for (const fragment of fragments) {
672
+ if (fragment == null) continue;
673
+ for (const key of ownKeys(fragment)) {
674
+ if (fragment[key] === void 0) continue;
675
+ if (key === "properties") {
676
+ merged.properties = __spreadValues(__spreadValues({}, merged.properties), fragment.properties);
677
+ } else if (key === "required") {
678
+ merged.required = [
679
+ .../* @__PURE__ */ new Set([
680
+ ...(_a = merged.required) != null ? _a : [],
681
+ ...fragment.required
682
+ ])
683
+ ];
684
+ } else {
685
+ merged[key] = fragment[key];
686
+ }
687
+ }
688
+ }
689
+ return merged;
690
+ }
691
+
692
+ // ../vinyl-validation/src/validation/andValidators.ts
625
693
  var locale3 = {
626
694
  /**
627
695
  * {value} The child validators' descriptions, joined with `separator`.
@@ -647,10 +715,13 @@
647
715
  if (errors.length) return errors;
648
716
  }
649
717
  return [];
650
- }
718
+ },
719
+ mergeJsonSchema(...validators.map((v) => v.jsonSchema))
651
720
  );
652
721
  }
653
- var locale22 = {
722
+
723
+ // ../vinyl-validation/src/validation/orValidators.ts
724
+ var locale4 = {
654
725
  /**
655
726
  * {value} - The child validators' descriptions, joined with `separator`.
656
727
  */
@@ -660,53 +731,66 @@
660
731
  */
661
732
  separator: " | "
662
733
  };
734
+ function unionJsonSchema(validators) {
735
+ const branches = validators.map((v) => v.jsonSchema).filter((fragment) => fragment != null);
736
+ if (branches.length === 0) return void 0;
737
+ if (branches.length === 1) return branches[0];
738
+ return { anyOf: branches };
739
+ }
663
740
  function orValidators(...validators) {
664
- const description = substitute(locale22.template, {
665
- value: validators.map((v) => v.description).join(locale22.separator)
741
+ const description = substitute(locale4.template, {
742
+ value: validators.map((v) => v.description).join(locale4.separator)
666
743
  });
667
- return createDeepValidator(description, (input, options, path) => {
668
- let longestErrors = [];
669
- let longestPath = 0;
670
- for (const validator of validators) {
671
- const errors = validator.validate(input, options, path);
672
- if (!errors.length) return errors;
673
- const pathLength = errors.reduce(
674
- (max, m) => Math.max(m.path.length, max),
675
- 0
676
- );
677
- if (pathLength >= longestPath) {
678
- longestErrors = errors;
679
- longestPath = pathLength;
744
+ return createDeepValidator(
745
+ description,
746
+ (input, options, path) => {
747
+ let longestErrors = [];
748
+ let longestPath = 0;
749
+ for (const validator of validators) {
750
+ const errors = validator.validate(input, options, path);
751
+ if (!errors.length) return errors;
752
+ const pathLength = errors.reduce(
753
+ (max, m) => Math.max(m.path.length, max),
754
+ 0
755
+ );
756
+ if (pathLength >= longestPath) {
757
+ longestErrors = errors;
758
+ longestPath = pathLength;
759
+ }
680
760
  }
681
- }
682
- return longestPath > path.length ? longestErrors : [
683
- {
684
- message: createValidationExpectationMessage(
685
- description,
686
- input,
761
+ return longestPath > path.length ? longestErrors : [
762
+ {
763
+ message: createValidationExpectationMessage(
764
+ description,
765
+ input,
766
+ path
767
+ ),
687
768
  path
688
- ),
689
- path
690
- }
691
- ];
692
- });
769
+ }
770
+ ];
771
+ },
772
+ unionJsonSchema(validators)
773
+ );
693
774
  }
775
+
776
+ // ../vinyl-validation/src/validation/SchemaBase.ts
694
777
  var requiredValidationOptions = {
695
778
  optional: false
696
779
  };
697
780
  var SchemaBase = class {
698
781
  constructor(currentValidator, previousSchema, operation) {
699
- this.currentValidator = currentValidator;
700
- this.previousSchema = previousSchema;
701
- this.operation = operation;
702
- __publicField2(this, "__type", /* @__PURE__ */ invariant());
703
- __publicField2(this, "validator");
704
- __publicField2(this, "_options", requiredValidationOptions);
705
- __publicField2(this, "assert", (input, origin, path) => {
782
+ __publicField(this, "currentValidator", currentValidator);
783
+ __publicField(this, "previousSchema", previousSchema);
784
+ __publicField(this, "operation", operation);
785
+ __publicField(this, "__type", invariant());
786
+ __publicField(this, "validator");
787
+ __publicField(this, "_options", requiredValidationOptions);
788
+ __publicField(this, "_jsonSchemaDescription");
789
+ __publicField(this, "assert", (input, origin, path) => {
706
790
  this.validator.assert(input, origin, path);
707
791
  });
708
- __publicField2(this, "isValid", (input) => this.validator.isValid(input));
709
- __publicField2(this, "validate", (input, options, path) => this.validator.validate(input, options, path));
792
+ __publicField(this, "isValid", (input) => this.validator.isValid(input));
793
+ __publicField(this, "validate", (input, options, path) => this.validator.validate(input, options, path));
710
794
  this.validator = operation == null ? currentValidator : operation(previousSchema, currentValidator);
711
795
  }
712
796
  get options() {
@@ -715,6 +799,39 @@
715
799
  get description() {
716
800
  return this.validator.description;
717
801
  }
802
+ /**
803
+ * The composed JSON Schema fragment for this schema, including any {@link describe} description.
804
+ * Composes through chaining the same way {@link description} does; serialize a complete
805
+ * definition with {@link toJsonSchema}.
806
+ */
807
+ get jsonSchema() {
808
+ const base = this.validator.jsonSchema;
809
+ if (this._jsonSchemaDescription == null) return base;
810
+ return mergeJsonSchema(base, {
811
+ description: this._jsonSchemaDescription
812
+ });
813
+ }
814
+ /**
815
+ * Attaches a human-readable description to this schema, akin to zod's `describe`.
816
+ * The description is metadata only; it does not affect validation, and surfaces in the output
817
+ * of {@link toJsonSchema}.
818
+ *
819
+ * @param description The description to attach.
820
+ * @return A clone of this schema carrying the description.
821
+ */
822
+ describe(description) {
823
+ const cloned = this.clone();
824
+ cloned._jsonSchemaDescription = description;
825
+ return cloned;
826
+ }
827
+ /**
828
+ * Serializes this schema to a JSON Schema definition, suitable for describing the shape to an
829
+ * LLM or other consumer. Works similarly to zod-to-json-schema.
830
+ */
831
+ toJsonSchema() {
832
+ var _a;
833
+ return (_a = this.jsonSchema) != null ? _a : {};
834
+ }
718
835
  /**
719
836
  * Clones this schema, transforming all validators with the given mutator.
720
837
  *
@@ -729,6 +846,7 @@
729
846
  this.operation
730
847
  ) : this.self(transform(this.currentValidator));
731
848
  cloned._options = this._options;
849
+ cloned._jsonSchemaDescription = this._jsonSchemaDescription;
732
850
  return cloned;
733
851
  }
734
852
  self(current, previous, operation) {
@@ -752,902 +870,111 @@
752
870
  }
753
871
  optional() {
754
872
  const cloned = this.clone();
755
- cloned._options = __spreadProps3(__spreadValues3({}, cloned.options), {
873
+ cloned._options = __spreadProps(__spreadValues({}, cloned.options), {
756
874
  optional: true
757
875
  });
758
876
  return cloned;
759
877
  }
760
878
  required() {
761
879
  const cloned = this.clone();
762
- cloned._options = __spreadProps3(__spreadValues3({}, cloned.options), {
880
+ cloned._options = __spreadProps(__spreadValues({}, cloned.options), {
763
881
  optional: false
764
- });
765
- return cloned;
766
- }
767
- };
768
- var locale32 = {
769
- null: "null",
770
- nullish: "nullish",
771
- undefined: "undefined"
772
- };
773
- var valueValidators = {
774
- any() {
775
- return createValidator("", () => true);
776
- },
777
- /**
778
- * Creates a validator that asserts that the input is nullish.
779
- */
780
- nullish() {
781
- return createValidator(locale32.nullish, (input) => input == null);
782
- },
783
- /**
784
- * Creates a validator that asserts that the input is strictly null.
785
- */
786
- null() {
787
- return createValidator(locale32.null, (input) => input === null);
788
- },
789
- /**
790
- * Creates a validator that asserts that the input is strictly undefined.
791
- */
792
- undefined() {
793
- return createValidator(locale32.undefined, (input) => input === void 0);
794
- }
795
- };
796
- var ValueSchema = class _ValueSchema extends SchemaBase {
797
- /**
798
- * Prepends this validator allowing for null or undefined.
799
- */
800
- maybe() {
801
- return this.or(valueValidators.nullish());
802
- }
803
- /**
804
- * Prepends this validator allowing for null.
805
- */
806
- orNull() {
807
- return this.or(valueValidators.null());
808
- }
809
- /**
810
- * Prepends this validator allowing for undefined.
811
- */
812
- orUndefined() {
813
- return this.or(valueValidators.undefined());
814
- }
815
- /**
816
- * Returns a validator that asserts if this validator and the next passes.
817
- *
818
- * @see andValidators
819
- *
820
- * @param nextValidator The validator to run after the current.
821
- * @return Returns a new ValueSchema intersecting this validator and the next.
822
- */
823
- and(nextValidator) {
824
- return new _ValueSchema(nextValidator, this, andValidators);
825
- }
826
- /**
827
- * Returns a validator that asserts if this validator or the next passes.
828
- *
829
- * Implementation note:
830
- * subclasses should not change the schema instance returned unless all chainable validators
831
- * accept input type 'unknown'.
832
- *
833
- * @param nextValidator The validator to run after the current.
834
- * @return Returns a new ValueSchema providing the union of this validator and the next.
835
- */
836
- or(nextValidator) {
837
- return new _ValueSchema(nextValidator, this, orValidators);
838
- }
839
- };
840
- var locale4 = {
841
- array: "array",
842
- minLength: "at least {value} elements",
843
- maxLength: "at most {value} elements",
844
- exactlyLength: "exactly {value} elements",
845
- actualLength: "length {value}",
846
- withElements: "({value})[]",
847
- tuple: "[{value}]"
848
- };
849
- var arrayValidators = {
850
- /**
851
- * Creates a validator that asserts that the input is an array.
852
- *
853
- * Note: arrays can only be readonly by type system, there is no native readonly
854
- * js array. This validator assumes mutability, use the ArraySchema readonly() method
855
- * to cast to a readonly array.
856
- */
857
- isArray() {
858
- return createValidator(
859
- locale4.array,
860
- (input) => Array.isArray(input)
861
- );
862
- },
863
- /**
864
- * Creates a validator that asserts that every element passes the given validator.
865
- *
866
- * @param elementValidator
867
- */
868
- withElements(elementValidator) {
869
- return createDeepValidator(
870
- substitute(locale4.withElements, {
871
- value: elementValidator.description
872
- }),
873
- (input, options, path) => {
874
- const errors = [];
875
- for (let i = 0; i < input.length; i++) {
876
- const element = input[i];
877
- errors.push(
878
- ...elementValidator.validate(
879
- element,
880
- options,
881
- path.concat(i.toString())
882
- )
883
- );
884
- if (!options.all && errors.length) return errors;
885
- }
886
- return errors;
887
- }
888
- );
889
- },
890
- /**
891
- * Creates a validator that asserts that the input array is a tuple whose elements match
892
- * the given validators.
893
- *
894
- * @param validators
895
- */
896
- tuple(...validators) {
897
- const lengthValidator = createValidator(
898
- substitute(locale4.exactlyLength, {
899
- value: validators.length
900
- }),
901
- (length) => length === validators.length
902
- );
903
- return createDeepValidator(
904
- substitute(locale4.tuple, { value: validators.join(", ") }),
905
- (input, options, path) => {
906
- const errors = [];
907
- errors.push(
908
- ...lengthValidator.validate(input.length, options, path)
909
- );
910
- if (!options.all && errors.length) return errors;
911
- const n = Math.min(validators.length, input.length);
912
- for (let i = 0; i < n; i++) {
913
- const element = input[i];
914
- const validator = validators[i];
915
- errors.push(
916
- ...validator.validate(
917
- element,
918
- options,
919
- path.concat(i.toString())
920
- )
921
- );
922
- if (!options.all && errors.length) return errors;
923
- }
924
- return errors;
925
- }
926
- );
927
- },
928
- /**
929
- * Creates a validator that validates the input array has the given minimum length.
930
- * @param min The minimum number of elements (inclusive)
931
- */
932
- minLength(min) {
933
- return createValidator(
934
- substitute(locale4.minLength, { value: min }),
935
- (input) => input.length >= min,
936
- (input) => substitute(locale4.actualLength, { value: input.length })
937
- );
938
- },
939
- /**
940
- *
941
- * Creates a validator that validates the input array has the given maximum length.
942
- * @param max The maximum number of elements (inclusive)
943
- */
944
- maxLength(max) {
945
- return createValidator(
946
- substitute(locale4.maxLength, { value: max }),
947
- (input) => input.length <= max,
948
- (input) => substitute(locale4.actualLength, { value: input.length })
949
- );
950
- }
951
- };
952
- var _ArraySchema = class _ArraySchema2 extends ValueSchema {
953
- /**
954
- * The base ArraySchema instance validating that the input is an Array.
955
- */
956
- static get base() {
957
- if (this._base == null)
958
- this._base = new _ArraySchema2(arrayValidators.isArray());
959
- return this._base;
960
- }
961
- /**
962
- * Creates a validator that asserts that every element passes the given validator.
963
- *
964
- * @param elementValidator
965
- */
966
- withElements(elementValidator) {
967
- return this.chain(arrayValidators.withElements(elementValidator));
968
- }
969
- /**
970
- * Creates a validator that asserts that the input array is a tuple whose elements match
971
- * the given validators.
972
- *
973
- * @param validators
974
- */
975
- tuple(...validators) {
976
- return this.chain(arrayValidators.tuple(...validators));
977
- }
978
- /**
979
- * Creates a validator that validates the input array has the given minimum length.
980
- * @param min The minimum number of elements (inclusive)
981
- */
982
- minLength(min) {
983
- return this.chain(arrayValidators.minLength(min));
984
- }
985
- /**
986
- *
987
- * Creates a validator that validates the input array has the given maximum length.
988
- * @param max The maximum number of elements (inclusive)
989
- */
990
- maxLength(max) {
991
- return this.chain(arrayValidators.maxLength(max));
992
- }
993
- /**
994
- * Casts to a readonly array.
995
- * This is a shallow cast, elements of the array will not be changed.
996
- */
997
- readonly() {
998
- return this;
999
- }
1000
- /**
1001
- * Casts the type parameter.
1002
- */
1003
- cast() {
1004
- return this;
1005
- }
1006
- };
1007
- __publicField2(_ArraySchema, "_base", null);
1008
- var locale5 = {
1009
- template: "type {value}"
1010
- };
1011
- function typeOfValidator(expected) {
1012
- return createValidator(
1013
- substitute(locale5.template, { value: expected }),
1014
- (input) => {
1015
- return input != null && typeof input === expected;
1016
- }
1017
- );
1018
- }
1019
- var typeOfValidatorCache = {};
1020
- function cachedTypeOfValidator(type) {
1021
- if (!(type in typeOfValidatorCache)) {
1022
- typeOfValidatorCache[type] = typeOfValidator(type);
1023
- }
1024
- return typeOfValidatorCache[type];
1025
- }
1026
- var typeOfValidators = {
1027
- get boolean() {
1028
- return cachedTypeOfValidator("boolean");
1029
- },
1030
- get func() {
1031
- return cachedTypeOfValidator("function");
1032
- },
1033
- get number() {
1034
- return cachedTypeOfValidator("number");
1035
- },
1036
- get object() {
1037
- return cachedTypeOfValidator("object");
1038
- },
1039
- get string() {
1040
- return cachedTypeOfValidator("string");
1041
- },
1042
- get symbol() {
1043
- return cachedTypeOfValidator("symbol");
1044
- }
1045
- };
1046
- var locale6 = {
1047
- length: "at most {value} arguments",
1048
- actualLength: "{value} arguments"
1049
- };
1050
- var functionValidators = {
1051
- length(max) {
1052
- return createValidator(
1053
- substitute(locale6.length, { value: max }),
1054
- (input) => input.length <= max,
1055
- (input) => substitute(locale6.actualLength, { value: input.length })
1056
- );
1057
- }
1058
- };
1059
- var _FunctionSchema = class _FunctionSchema2 extends ValueSchema {
1060
- /**
1061
- * The base Function validator validating that the input is a function.
1062
- */
1063
- static get base() {
1064
- if (this._base == null)
1065
- this._base = new _FunctionSchema2(typeOfValidators.func);
1066
- return this._base;
1067
- }
1068
- length(max) {
1069
- return this.chain(functionValidators.length(max));
1070
- }
1071
- /**
1072
- * Casts the function signature.
1073
- * Function signatures, except for their required number of parameters, cannot be
1074
- * meaningfully validated.
1075
- */
1076
- cast() {
1077
- return this;
1078
- }
1079
- };
1080
- __publicField2(_FunctionSchema, "_base", null);
1081
- var locale7 = {
1082
- set: "Set",
1083
- withElements: "Set<{value}>"
1084
- };
1085
- var setValidators = {
1086
- /**
1087
- * Creates a validator that asserts that the input is a set.
1088
- */
1089
- isSet() {
1090
- return createValidator(
1091
- locale7.set,
1092
- (input) => input instanceof Set
1093
- );
1094
- },
1095
- /**
1096
- * Creates a validator that asserts that every element passes the given validator.
1097
- *
1098
- * @param elementValidator
1099
- */
1100
- withElements(elementValidator) {
1101
- return createDeepValidator(
1102
- substitute(locale7.withElements, {
1103
- value: elementValidator.description
1104
- }),
1105
- (input, options, path) => {
1106
- const errors = [];
1107
- let i = 0;
1108
- for (const element of input) {
1109
- errors.push(
1110
- ...elementValidator.validate(
1111
- element,
1112
- options,
1113
- path.concat(i.toString())
1114
- )
1115
- );
1116
- if (!options.all && errors.length) return errors;
1117
- i++;
1118
- }
1119
- return errors;
1120
- }
1121
- );
1122
- }
1123
- };
1124
- var _SetSchema = class _SetSchema2 extends ValueSchema {
1125
- /**
1126
- * The base SetSchema instance validating that the input is a Set.
1127
- */
1128
- static get base() {
1129
- if (this._base == null)
1130
- this._base = new _SetSchema2(setValidators.isSet());
1131
- return this._base;
1132
- }
1133
- /**
1134
- * Creates a validator that asserts that every element passes the given validator.
1135
- *
1136
- * @param elementValidator
1137
- */
1138
- withElements(elementValidator) {
1139
- return this.chain(setValidators.withElements(elementValidator));
1140
- }
1141
- /**
1142
- * Casts to a readonly set.
1143
- * This is a shallow cast, elements of the array will not be changed.
1144
- */
1145
- readonly() {
1146
- return this;
1147
- }
1148
- /**
1149
- * Casts the parameter type.
1150
- */
1151
- cast() {
1152
- return this;
1153
- }
1154
- };
1155
- __publicField2(_SetSchema, "_base", null);
1156
- var locale8 = {
1157
- gte: "at least {value}",
1158
- gt: "greater than {value}",
1159
- lte: "at most {value}",
1160
- lt: "less than {value}",
1161
- within: "within {min} and {max}",
1162
- safeInteger: "safe integer",
1163
- finite: "finite"
1164
- };
1165
- var numberValidators = {
1166
- /**
1167
- * Creates a validator that asserts that the input number is at least the provided minimum
1168
- * value.
1169
- *
1170
- * @param min The minimum (inclusive) the value may be.
1171
- */
1172
- gte(min) {
1173
- return createValidator(
1174
- substitute(locale8.gte, { value: min }),
1175
- (input) => input >= min
1176
- );
1177
- },
1178
- /**
1179
- * Creates a validator that asserts that the input number is greater than the provided minimum
1180
- * value.
1181
- *
1182
- * @param min The minimum (exclusive) the value may be.
1183
- */
1184
- gt(min) {
1185
- return createValidator(
1186
- substitute(locale8.gt, { value: min }),
1187
- (input) => input > min
1188
- );
1189
- },
1190
- /**
1191
- * Creates a validator that asserts that the input number is at most the provided maximum
1192
- * value.
1193
- *
1194
- * @param max The maximum (inclusive) the value may be.
1195
- */
1196
- lte(max) {
1197
- return createValidator(
1198
- substitute(locale8.lte, { value: max }),
1199
- (input) => input <= max
1200
- );
1201
- },
1202
- /**
1203
- * Creates a validator that asserts that the input number is less than the provided maximum
1204
- * value.
1205
- *
1206
- * @param max The maximum (exclusive) the value may be.
1207
- */
1208
- lt(max) {
1209
- return createValidator(
1210
- substitute(locale8.lt, { value: max }),
1211
- (input) => input < max
1212
- );
1213
- },
1214
- /**
1215
- * Creates a validator that asserts that the input number is at least the provided minimum
1216
- * and at most the provided maximum values.
1217
- *
1218
- * @param min The minimum (inclusive) value the input may be.
1219
- * @param max The maximum (inclusive) value the input may be.
1220
- */
1221
- within(min, max) {
1222
- return createValidator(
1223
- substitute(locale8.within, { min, max }),
1224
- (input) => input >= min && input <= max
1225
- );
1226
- },
1227
- /**
1228
- * Creates a validator that asserts that the input number is finite.
1229
- */
1230
- finite() {
1231
- return createValidator(locale8.finite, (input) => Number.isFinite(input));
1232
- },
1233
- /**
1234
- * Creates a validator that asserts that the input number is a safe integer.
1235
- */
1236
- safeInteger() {
1237
- return createValidator(
1238
- locale8.safeInteger,
1239
- (input) => Number.isSafeInteger(input)
1240
- );
1241
- }
1242
- };
1243
- var _NumberSchema = class _NumberSchema2 extends ValueSchema {
1244
- /**
1245
- * The base Object validator validating that the input is an object.
1246
- */
1247
- static get base() {
1248
- if (this._base == null)
1249
- this._base = new _NumberSchema2(typeOfValidators.number);
1250
- return this._base;
1251
- }
1252
- /**
1253
- * Creates a validator that asserts that the input number is at least the provided minimum
1254
- * value.
1255
- *
1256
- * @param min The minimum (inclusive) the value may be.
1257
- */
1258
- gte(min) {
1259
- return this.chain(numberValidators.gte(min));
1260
- }
1261
- /**
1262
- * Creates a validator that asserts that the input number is greater than the provided minimum
1263
- * value.
1264
- *
1265
- * @param min The minimum (exclusive) the value may be.
1266
- */
1267
- gt(min) {
1268
- return this.chain(numberValidators.gt(min));
1269
- }
1270
- /**
1271
- * Creates a validator that asserts that the input number is at most the provided maximum
1272
- * value.
1273
- *
1274
- * @param max The maximum (inclusive) the value may be.
1275
- */
1276
- lte(max) {
1277
- return this.chain(numberValidators.lte(max));
1278
- }
1279
- /**
1280
- * Creates a validator that asserts that the input number is less than the provided maximum
1281
- * value.
1282
- *
1283
- * @param max The maximum (exclusive) the value may be.
1284
- */
1285
- lt(max) {
1286
- return this.chain(numberValidators.lt(max));
1287
- }
1288
- /**
1289
- * Creates a validator that asserts that the input number is at least the provided minimum
1290
- * and at most the provided maximum values.
1291
- *
1292
- * @param min The minimum (inclusive) value the input may be.
1293
- * @param max The maximum (inclusive) value the input may be.
1294
- */
1295
- within(min, max) {
1296
- return this.chain(numberValidators.within(min, max));
1297
- }
1298
- /**
1299
- * Creates a validator that asserts that the input number is finite.
1300
- */
1301
- finite() {
1302
- return this.chain(numberValidators.finite());
1303
- }
1304
- /**
1305
- * Creates a validator that asserts that the input number is a safe integer.
1306
- */
1307
- safeInteger() {
1308
- return this.chain(numberValidators.safeInteger());
1309
- }
1310
- };
1311
- __publicField2(_NumberSchema, "_base", null);
1312
- function isValidatorWithPartial(validator) {
1313
- return "partial" in validator && "partialDeep" in validator;
1314
- }
1315
- function maybeToDeepPartial(validator) {
1316
- return isValidatorWithPartial(validator) ? validator.partialDeep() : validator;
1317
- }
1318
- function maybeToPartial(validator) {
1319
- return isValidatorWithPartial(validator) ? validator.partial() : validator;
1320
- }
1321
- var locale9 = {
1322
- extend: "{\n{body}\n}",
1323
- prop: "{key}: {value}",
1324
- propSeparator: ",\n",
1325
- indent: " ",
1326
- required: `property '{key}' is required`
1327
- };
1328
- var objectValidators = {
1329
- /**
1330
- * Creates a validator that validates the input has properties that pass their respective
1331
- * validators.
1332
- *
1333
- * @param propertyValidators
1334
- */
1335
- properties(propertyValidators) {
1336
- const propertiesDescriptions = [];
1337
- const keys = ownKeys(propertyValidators);
1338
- for (const key of keys) {
1339
- const validator2 = propertyValidators[key];
1340
- propertiesDescriptions.push(
1341
- substitute(locale9.prop, {
1342
- key: String(key) + (validator2.options.optional ? "?" : ""),
1343
- value: validator2.description
1344
- })
1345
- );
1346
- }
1347
- const description = substitute(locale9.extend, {
1348
- body: propertiesDescriptions.join(locale9.propSeparator).split("\n").map((line) => locale9.indent + line).join("\n")
1349
- });
1350
- const validator = createDeepValidator(
1351
- description,
1352
- (input, options, path) => {
1353
- const errors = [];
1354
- for (const key of keys) {
1355
- const validator2 = propertyValidators[key];
1356
- if (key in input) {
1357
- const value = input[key];
1358
- errors.push(
1359
- ...validator2.validate(
1360
- value,
1361
- options,
1362
- path.concat(String(key))
1363
- )
1364
- );
1365
- } else {
1366
- if (!validator2.options.optional) {
1367
- errors.push({
1368
- message: substitute(locale9.required, { key }),
1369
- path: path.concat(String(key))
1370
- });
1371
- }
1372
- }
1373
- if (!options.all && errors.length) return errors;
1374
- }
1375
- return errors;
1376
- }
1377
- );
1378
- return merge(validator, {
1379
- partial() {
1380
- const optionalPropertyValidators = {};
1381
- for (const key of keys) {
1382
- optionalPropertyValidators[key] = propertyValidators[key].optional();
1383
- }
1384
- return objectValidators.properties(
1385
- optionalPropertyValidators
1386
- );
1387
- },
1388
- partialDeep() {
1389
- const optionalPropertyValidators = {};
1390
- for (const key of keys) {
1391
- optionalPropertyValidators[key] = maybeToDeepPartial(
1392
- propertyValidators[key].optional()
1393
- );
1394
- }
1395
- return objectValidators.properties(
1396
- optionalPropertyValidators
1397
- );
1398
- }
1399
- });
1400
- }
1401
- };
1402
- var _ObjectSchema = class _ObjectSchema2 extends ValueSchema {
1403
- /**
1404
- * The base Object validator validating that the input is an object.
1405
- */
1406
- static get base() {
1407
- if (this._base == null)
1408
- this._base = new _ObjectSchema2(typeOfValidators.object);
1409
- return this._base;
1410
- }
1411
- /**
1412
- * Creates a validator that validates the input has properties that pass their respective
1413
- * validators.
1414
- *
1415
- * @param propertyValidators
1416
- */
1417
- extend(propertyValidators) {
1418
- return this.chain(objectValidators.properties(propertyValidators));
1419
- }
1420
- /**
1421
- * Allows all properties to be undefined.
1422
- */
1423
- partial() {
1424
- return this.clone(maybeToPartial);
1425
- }
1426
- /**
1427
- * Allows all recursive properties to be undefined.
1428
- */
1429
- partialDeep() {
1430
- return this.clone(maybeToDeepPartial);
1431
- }
1432
- /**
1433
- * Casts the type parameter.
1434
- */
1435
- cast() {
1436
- return this;
882
+ });
883
+ return cloned;
1437
884
  }
1438
885
  };
1439
- __publicField2(_ObjectSchema, "_base", null);
1440
- var locale10 = {
1441
- notEmpty: "not empty",
1442
- minLength: "at least {value} characters",
1443
- maxLength: "at most {value} characters",
1444
- noWhitespace: "no whitespace characters",
1445
- matches: "matches {value}"
886
+
887
+ // ../vinyl-validation/src/validation/ValueSchema.ts
888
+ var locale5 = {
889
+ null: "null",
890
+ nullish: "nullish",
891
+ undefined: "undefined"
1446
892
  };
1447
- var stringValidators = {
1448
- /**
1449
- * Creates a validator that asserts that the input is not empty.
1450
- */
1451
- notEmpty() {
1452
- return createValidator(locale10.notEmpty, (input) => input !== "");
1453
- },
1454
- /**
1455
- * Creates a validator that asserts that the input string has at least the given minimum
1456
- * length.
1457
- *
1458
- * @param min The string must be at least this length.
1459
- */
1460
- minLength(min) {
1461
- return createValidator(
1462
- substitute(locale10.minLength, { value: min }),
1463
- (input) => input.length >= min
1464
- );
893
+ var valueValidators = {
894
+ any() {
895
+ return createValidator("", () => true);
1465
896
  },
1466
897
  /**
1467
- * Creates a validator that asserts that the input string has at most the given maximum
1468
- * length.
1469
- *
1470
- * @param max The string must be at most this length.
898
+ * Creates a validator that asserts that the input is nullish.
899
+ * JSON Schema has no representation for `undefined`, so only `null` is expressed.
1471
900
  */
1472
- maxLength(max) {
901
+ nullish() {
1473
902
  return createValidator(
1474
- substitute(locale10.maxLength, { value: max }),
1475
- (input) => input.length <= max
903
+ locale5.nullish,
904
+ (input) => input == null,
905
+ void 0,
906
+ {
907
+ type: "null"
908
+ }
1476
909
  );
1477
910
  },
1478
911
  /**
1479
- * Creates a validator that asserts that the input string has no whitespace characters.
1480
- * Whitespace characters include space, new line, carriage return, and tab.
912
+ * Creates a validator that asserts that the input is strictly null.
1481
913
  */
1482
- noWhitespace() {
914
+ null() {
1483
915
  return createValidator(
1484
- locale10.noWhitespace,
1485
- (input) => input.search(/\s/g) === -1
916
+ locale5.null,
917
+ (input) => input === null,
918
+ void 0,
919
+ {
920
+ type: "null"
921
+ }
1486
922
  );
1487
923
  },
1488
924
  /**
1489
- * Creates a validator that asserts that the input string matches the given regex.
1490
- * @param regex
925
+ * Creates a validator that asserts that the input is strictly undefined.
1491
926
  */
1492
- matches(regex) {
1493
- return createValidator(
1494
- substitute(locale10.matches, { value: regex.toString() }),
1495
- (input) => {
1496
- return regex.test(input);
1497
- }
1498
- );
927
+ undefined() {
928
+ return createValidator(locale5.undefined, (input) => input === void 0);
1499
929
  }
1500
930
  };
1501
- var _StringSchema = class _StringSchema2 extends ValueSchema {
1502
- /**
1503
- * The base SetSchema instance validating that the input is a Set.
1504
- */
1505
- static get base() {
1506
- if (this._base == null)
1507
- this._base = new _StringSchema2(typeOfValidators.string);
1508
- return this._base;
1509
- }
1510
- /**
1511
- * Creates a validator that asserts that the input is not empty.
1512
- */
1513
- notEmpty() {
1514
- return this.chain(stringValidators.notEmpty());
1515
- }
1516
- /**
1517
- * Creates a validator that asserts that the input string has at least the given minimum
1518
- * length.
1519
- *
1520
- * @param min The string must be at least this length.
1521
- */
1522
- minLength(min) {
1523
- return this.chain(stringValidators.minLength(min));
1524
- }
1525
- /**
1526
- * Creates a validator that asserts that the input string has at most the given maximum
1527
- * length.
1528
- *
1529
- * @param max The string must be at most this length.
1530
- */
1531
- maxLength(max) {
1532
- return this.chain(stringValidators.maxLength(max));
1533
- }
1534
- /**
1535
- * Creates a validator that asserts that the input string has no whitespace characters.
1536
- * Whitespace characters include space, new line, carriage return, and tab.
1537
- */
1538
- noWhitespace() {
1539
- return this.chain(stringValidators.noWhitespace());
1540
- }
931
+ var ValueSchema = class _ValueSchema extends SchemaBase {
1541
932
  /**
1542
- * Creates a validator that asserts that the input string matches the given regex.
1543
- * @param regex
933
+ * Prepends this validator allowing for null or undefined.
1544
934
  */
1545
- matches(regex) {
1546
- return this.chain(stringValidators.matches(regex));
935
+ maybe() {
936
+ return this.or(valueValidators.nullish());
1547
937
  }
1548
- };
1549
- __publicField2(_StringSchema, "_base", null);
1550
- var StringSchema = _StringSchema;
1551
- var locale11 = {
1552
- record: "{ [key: {key}]: {value} }"
1553
- };
1554
- var recordValidators = {
1555
938
  /**
1556
- * Returns a validator that asserts that the object's own enumerable properties has keys and
1557
- * values that match their respective validators.
1558
- *
1559
- * Prototype members are not included.
1560
- * Numeric keys are validated as strings. For example the object `{ [0]: 1 }` will be passed
1561
- * to the key validator as '0'.
1562
- *
1563
- * @param keyValidator Validates each key.
1564
- * @param valueValidator Validates each value.
939
+ * Prepends this validator allowing for null.
1565
940
  */
1566
- record(keyValidator, valueValidator) {
1567
- return createDeepValidator(
1568
- substitute(locale11.record, {
1569
- key: keyValidator.description,
1570
- value: valueValidator.description
1571
- }),
1572
- (input, options, path) => {
1573
- const errors = [];
1574
- for (const key of ownKeys(input)) {
1575
- const keyStr = String(key);
1576
- errors.push(
1577
- ...keyValidator.validate(
1578
- key,
1579
- options,
1580
- path.concat(`[${keyStr}]`)
1581
- )
1582
- );
1583
- if (!options.all && errors.length) return errors;
1584
- const value = input[key];
1585
- errors.push(
1586
- ...valueValidator.validate(
1587
- value,
1588
- options,
1589
- path.concat(keyStr)
1590
- )
1591
- );
1592
- if (!options.all && errors.length) return errors;
1593
- }
1594
- return errors;
1595
- }
1596
- );
941
+ orNull() {
942
+ return this.or(valueValidators.null());
1597
943
  }
1598
- };
1599
- var _RecordSchema = class _RecordSchema2 extends ValueSchema {
1600
944
  /**
1601
- * The base Object validator validating that the input is an object.
945
+ * Prepends this validator allowing for undefined.
1602
946
  */
1603
- static get base() {
1604
- if (this._base == null)
1605
- this._base = new _RecordSchema2(typeOfValidators.object);
1606
- return this._base;
1607
- }
1608
- static get defaultKeyValidator() {
1609
- return StringSchema.base;
947
+ orUndefined() {
948
+ return this.or(valueValidators.undefined());
1610
949
  }
1611
950
  /**
1612
- * Returns a validator that asserts that the object's own enumerable properties has keys and
1613
- * values that match their respective validators.
951
+ * Returns a validator that asserts if this validator and the next passes.
1614
952
  *
1615
- * Prototype members are not included.
1616
- * Numeric keys are validated as strings. For example the object `{ [0]: 1 }` will be passed
1617
- * to the key validator as '0'.
953
+ * @see andValidators
1618
954
  *
1619
- * @param keyValidator Validates each key.
1620
- * @param valueValidator Validates each value.
955
+ * @param nextValidator The validator to run after the current.
956
+ * @return Returns a new ValueSchema intersecting this validator and the next.
1621
957
  */
1622
- record(keyValidator, valueValidator) {
1623
- return this.chain(recordValidators.record(keyValidator, valueValidator));
958
+ and(nextValidator) {
959
+ return new _ValueSchema(nextValidator, this, andValidators);
1624
960
  }
1625
961
  /**
1626
- * Returns a validator that asserts that the object's own enumerable properties has
1627
- * string keys and values that match the given validator.
962
+ * Returns a validator that asserts if this validator or the next passes.
1628
963
  *
1629
- * Prototype members are not included.
964
+ * Implementation note:
965
+ * subclasses should not change the schema instance returned unless all chainable validators
966
+ * accept input type 'unknown'.
1630
967
  *
1631
- * @param valueValidator Validates each value.
1632
- */
1633
- recordValues(valueValidator) {
1634
- return this.record(_RecordSchema2.defaultKeyValidator, valueValidator);
1635
- }
1636
- /**
1637
- * Casts to a ReadonlyRecord
1638
- */
1639
- readonly() {
1640
- return this;
1641
- }
1642
- /**
1643
- * Casts the type parameter.
968
+ * @param nextValidator The validator to run after the current.
969
+ * @return Returns a new ValueSchema providing the union of this validator and the next.
1644
970
  */
1645
- cast() {
1646
- return this;
971
+ or(nextValidator) {
972
+ return new _ValueSchema(nextValidator, this, orValidators);
1647
973
  }
1648
974
  };
1649
- __publicField2(_RecordSchema, "_base", null);
1650
- var locale12 = {
975
+
976
+ // ../vinyl-validation/src/validation/validators.ts
977
+ var locale6 = {
1651
978
  isOneOf: "one of: {value}",
1652
979
  instanceOf: "instance of {value}",
1653
980
  oneOfSeparator: " | "
@@ -1655,22 +982,16 @@
1655
982
  function isOneOf(...possibleValues) {
1656
983
  return new ValueSchema(
1657
984
  createValidator(
1658
- substitute(locale12.isOneOf, {
1659
- value: possibleValues.join(locale12.oneOfSeparator)
985
+ substitute(locale6.isOneOf, {
986
+ value: possibleValues.join(locale6.oneOfSeparator)
1660
987
  }),
1661
- (input) => possibleValues.includes(input)
988
+ (input) => possibleValues.includes(input),
989
+ void 0,
990
+ { enum: [...possibleValues] }
1662
991
  )
1663
992
  );
1664
993
  }
1665
994
 
1666
- // src/types/EncryptionKey.ts
1667
- var encryptionMethodValidator = isOneOf(
1668
- "NONE",
1669
- "AES-128",
1670
- "SAMPLE-AES",
1671
- "SAMPLE-AES-CTR"
1672
- );
1673
-
1674
995
  // src/types/AlternativeRendition.ts
1675
996
  var renditionTypeValidator = isOneOf(
1676
997
  "AUDIO",
@@ -1679,6 +1000,14 @@
1679
1000
  "CLOSED-CAPTIONS"
1680
1001
  );
1681
1002
 
1003
+ // src/types/EncryptionKey.ts
1004
+ var encryptionMethodValidator = isOneOf(
1005
+ "NONE",
1006
+ "AES-128",
1007
+ "SAMPLE-AES",
1008
+ "SAMPLE-AES-CTR"
1009
+ );
1010
+
1682
1011
  // src/parse/parseUtil.ts
1683
1012
  var LF = char("\n");
1684
1013
  var CR = char("\r");
@@ -1711,36 +1040,8 @@
1711
1040
  return obj;
1712
1041
  }
1713
1042
 
1714
- // src/parse/parseAttributes.ts
1715
- var EQUALS = char("=");
1716
- var COMMA = char(",");
1717
- var QUOTE = char('"');
1718
- function parseAttributes(reader) {
1719
- const attrs = {};
1720
- while (reader.hasNext() && reader.peek !== char("\n") && reader.peek !== char("\r")) {
1721
- const key = reader.substringUntilChar(EQUALS);
1722
- if (!key || !reader.hasNext()) break;
1723
- reader.next();
1724
- let value;
1725
- if (reader.peek === QUOTE) {
1726
- reader.next();
1727
- value = reader.substringUntilChar(QUOTE);
1728
- if (reader.hasNext()) reader.next();
1729
- } else {
1730
- value = reader.substringUntil(
1731
- (cc) => cc === COMMA || cc === char("\n") || cc === char("\r")
1732
- );
1733
- }
1734
- attrs[key] = value;
1735
- if (reader.hasNext() && reader.peek === COMMA) {
1736
- reader.next();
1737
- }
1738
- }
1739
- return attrs;
1740
- }
1741
-
1742
1043
  // src/parse/parseMediaPlaylist.ts
1743
- var HLS_VARIABLE_PATTERN = /\{\$([^}]+)}/g;
1044
+ var HLS_VARIABLE_PATTERN = /\{\$([^{}]+)}/g;
1744
1045
  var EXTM3U = "#EXTM3U";
1745
1046
  var EXTINF = "#EXTINF:";
1746
1047
  var EXT_X_TARGETDURATION = "#EXT-X-TARGETDURATION:";
@@ -1753,7 +1054,11 @@
1753
1054
  var EXT_X_DISCONTINUITY = "#EXT-X-DISCONTINUITY";
1754
1055
  var EXT_X_PROGRAM_DATE_TIME = "#EXT-X-PROGRAM-DATE-TIME:";
1755
1056
  var EXT_X_MAP = "#EXT-X-MAP:";
1756
- function parseMediaPlaylist(text, variables) {
1057
+ var EXT_X_DEFINE = "#EXT-X-DEFINE:";
1058
+ var EXT_X_DATERANGE = "#EXT-X-DATERANGE:";
1059
+ function parseMediaPlaylist(text, variables, queryParams) {
1060
+ const defines = __spreadValues({}, variables != null ? variables : {});
1061
+ const substituteVars = (v) => Object.keys(defines).length === 0 ? v : substitute(v, defines, HLS_VARIABLE_PATTERN);
1757
1062
  const reader = new StringReader(text);
1758
1063
  reader.white();
1759
1064
  if (!reader.stringIf(EXTM3U)) {
@@ -1771,6 +1076,7 @@
1771
1076
  let pendingDiscontinuity = false;
1772
1077
  let pendingDateTime;
1773
1078
  const segments = [];
1079
+ const dateRanges = [];
1774
1080
  let sequenceCounter = 0;
1775
1081
  while (reader.hasNext()) {
1776
1082
  if (skipWhitespaceLine(reader)) continue;
@@ -1785,7 +1091,7 @@
1785
1091
  if (skipWhitespaceLine(reader)) continue;
1786
1092
  const nextLine = readLine(reader).trim();
1787
1093
  if (!nextLine.startsWith("#")) {
1788
- uri = variables ? substitute(nextLine, variables, HLS_VARIABLE_PATTERN) : nextLine;
1094
+ uri = substituteVars(nextLine);
1789
1095
  break;
1790
1096
  }
1791
1097
  if (nextLine.startsWith(EXT_X_BYTERANGE)) {
@@ -1878,6 +1184,29 @@
1878
1184
  pendingDiscontinuity = true;
1879
1185
  } else if (trimmed.startsWith(EXT_X_PROGRAM_DATE_TIME)) {
1880
1186
  pendingDateTime = trimmed.substring(EXT_X_PROGRAM_DATE_TIME.length);
1187
+ } else if (trimmed.startsWith(EXT_X_DEFINE)) {
1188
+ const attrStr = trimmed.substring(EXT_X_DEFINE.length);
1189
+ const attrReader = new StringReader(attrStr);
1190
+ const attrs = parseAttributes(attrReader);
1191
+ const importName = attrs["IMPORT"];
1192
+ const queryParamName = attrs["QUERYPARAM"];
1193
+ if (importName) {
1194
+ const imported = variables == null ? void 0 : variables[importName];
1195
+ if (imported !== void 0) defines[importName] = imported;
1196
+ } else if (queryParamName) {
1197
+ const queryValue = queryParams == null ? void 0 : queryParams[queryParamName];
1198
+ if (queryValue !== void 0) {
1199
+ defines[queryParamName] = queryValue;
1200
+ }
1201
+ } else if (attrs["NAME"] && attrs["VALUE"]) {
1202
+ defines[attrs["NAME"]] = attrs["VALUE"];
1203
+ }
1204
+ } else if (trimmed.startsWith(EXT_X_DATERANGE)) {
1205
+ const dateRange = parseHlsDateRange(
1206
+ trimmed.substring(EXT_X_DATERANGE.length),
1207
+ substituteVars
1208
+ );
1209
+ if (dateRange) dateRanges.push(dateRange);
1881
1210
  }
1882
1211
  }
1883
1212
  return {
@@ -1886,9 +1215,40 @@
1886
1215
  mediaSequence,
1887
1216
  playlistType,
1888
1217
  ended,
1889
- segments
1218
+ segments,
1219
+ dateRanges
1890
1220
  };
1891
1221
  }
1222
+ var DATERANGE_RESERVED_ATTRS = /* @__PURE__ */ new Set([
1223
+ "ID",
1224
+ "CLASS",
1225
+ "START-DATE",
1226
+ "END-DATE",
1227
+ "DURATION",
1228
+ "PLANNED-DURATION",
1229
+ "END-ON-NEXT"
1230
+ ]);
1231
+ function parseHlsDateRange(attrStr, substituteVars) {
1232
+ const attrs = parseAttributes(new StringReader(attrStr));
1233
+ const id = attrs["ID"];
1234
+ const startDate = "START-DATE" in attrs ? attrs["START-DATE"] : "";
1235
+ const endOnNext = attrs["END-ON-NEXT"] === "YES";
1236
+ if (!id) return void 0;
1237
+ if (!startDate && !endOnNext) return void 0;
1238
+ const clientAttributes = {};
1239
+ for (const [key, value] of Object.entries(attrs)) {
1240
+ if (DATERANGE_RESERVED_ATTRS.has(key)) continue;
1241
+ clientAttributes[key] = substituteVars(value);
1242
+ }
1243
+ return __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
1244
+ id,
1245
+ startDate
1246
+ }, attrs["CLASS"] && { classId: attrs["CLASS"] }), attrs["END-DATE"] && { endDate: attrs["END-DATE"] }), attrs["DURATION"] && { duration: Number(attrs["DURATION"]) }), attrs["PLANNED-DURATION"] && {
1247
+ plannedDuration: Number(attrs["PLANNED-DURATION"])
1248
+ }), endOnNext && { endOnNext: true }), {
1249
+ clientAttributes
1250
+ });
1251
+ }
1892
1252
  function parseByteRangeString(str) {
1893
1253
  const parts = str.split("@");
1894
1254
  return {
@@ -1902,8 +1262,8 @@
1902
1262
  var EXT_X_STREAM_INF = "#EXT-X-STREAM-INF:";
1903
1263
  var EXT_X_MEDIA = "#EXT-X-MEDIA:";
1904
1264
  var EXT_X_SESSION_DATA = "#EXT-X-SESSION-DATA:";
1905
- var EXT_X_DEFINE = "#EXT-X-DEFINE:";
1906
- function parseMainPlaylist(text) {
1265
+ var EXT_X_DEFINE2 = "#EXT-X-DEFINE:";
1266
+ function parseMainPlaylist(text, queryParams) {
1907
1267
  const reader = new StringReader(text);
1908
1268
  reader.white();
1909
1269
  if (!reader.stringIf(EXTM3U2)) {
@@ -1933,7 +1293,7 @@
1933
1293
  addIfPresent(
1934
1294
  __spreadValues(__spreadValues({
1935
1295
  bandwidth: Number(attrs["BANDWIDTH"]),
1936
- uri
1296
+ uri: substituteHlsVariables(uri, defines)
1937
1297
  }, attrs["FRAME-RATE"] && {
1938
1298
  frameRate: Number(attrs["FRAME-RATE"])
1939
1299
  }), attrs.RESOLUTION && parseResolution(attrs.RESOLUTION)),
@@ -1953,9 +1313,12 @@
1953
1313
  const attrs = parseAttributes(attrReader);
1954
1314
  const type = attrs["TYPE"];
1955
1315
  renditionTypeValidator.assert(type);
1316
+ if (attrs["URI"]) {
1317
+ attrs["URI"] = substituteHlsVariables(attrs["URI"], defines);
1318
+ }
1956
1319
  alternativeRenditions.push(
1957
1320
  addIfPresent(
1958
- __spreadValues(__spreadValues({
1321
+ __spreadValues(__spreadValues(__spreadValues(__spreadValues({
1959
1322
  type,
1960
1323
  groupId: attrs["GROUP-ID"],
1961
1324
  name: attrs["NAME"]
@@ -1963,6 +1326,10 @@
1963
1326
  default: attrs["DEFAULT"] === "YES"
1964
1327
  }), attrs["AUTOSELECT"] && {
1965
1328
  autoSelect: attrs["AUTOSELECT"] === "YES"
1329
+ }), attrs["FORCED"] && {
1330
+ forced: attrs["FORCED"] === "YES"
1331
+ }), attrs["CHARACTERISTICS"] && {
1332
+ characteristics: attrs["CHARACTERISTICS"].split(",").map((c) => c.trim()).filter((c) => c.length > 0)
1966
1333
  }),
1967
1334
  attrs,
1968
1335
  {
@@ -1988,17 +1355,27 @@
1988
1355
  }
1989
1356
  )
1990
1357
  );
1991
- } else if (trimmed.startsWith(EXT_X_DEFINE)) {
1992
- const attrStr = trimmed.substring(EXT_X_DEFINE.length);
1358
+ } else if (trimmed.startsWith(EXT_X_DEFINE2)) {
1359
+ const attrStr = trimmed.substring(EXT_X_DEFINE2.length);
1993
1360
  const attrReader = new StringReader(attrStr);
1994
1361
  const attrs = parseAttributes(attrReader);
1995
- if (attrs["NAME"] && attrs["VALUE"]) {
1362
+ const queryParamName = attrs["QUERYPARAM"];
1363
+ if (queryParamName) {
1364
+ const queryValue = queryParams == null ? void 0 : queryParams[queryParamName];
1365
+ if (queryValue !== void 0) {
1366
+ defines[queryParamName] = queryValue;
1367
+ }
1368
+ } else if (attrs["NAME"] && attrs["VALUE"]) {
1996
1369
  defines[attrs["NAME"]] = attrs["VALUE"];
1997
1370
  }
1998
1371
  }
1999
1372
  }
2000
1373
  return { variants, alternativeRenditions, sessionData, defines };
2001
1374
  }
1375
+ function substituteHlsVariables(value, variables) {
1376
+ if (!value || Object.keys(variables).length === 0) return value;
1377
+ return substitute(value, variables, HLS_VARIABLE_PATTERN);
1378
+ }
2002
1379
  function parseResolution(resolution) {
2003
1380
  const parts = resolution.split("x");
2004
1381
  if (parts.length !== 2) {
@@ -2016,105 +1393,7 @@
2016
1393
  return { width, height };
2017
1394
  }
2018
1395
 
2019
- // ../vinyl-util/dist/browserTestUtil/index.js
2020
- var __defProp4 = Object.defineProperty;
2021
- var __getOwnPropSymbols4 = Object.getOwnPropertySymbols;
2022
- var __hasOwnProp4 = Object.prototype.hasOwnProperty;
2023
- var __propIsEnum4 = Object.prototype.propertyIsEnumerable;
2024
- var __defNormalProp4 = (obj, key, value) => key in obj ? __defProp4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2025
- var __spreadValues4 = (a, b) => {
2026
- for (var prop in b || (b = {}))
2027
- if (__hasOwnProp4.call(b, prop))
2028
- __defNormalProp4(a, prop, b[prop]);
2029
- if (__getOwnPropSymbols4)
2030
- for (var prop of __getOwnPropSymbols4(b)) {
2031
- if (__propIsEnum4.call(b, prop))
2032
- __defNormalProp4(a, prop, b[prop]);
2033
- }
2034
- return a;
2035
- };
2036
- var __objRest = (source, exclude) => {
2037
- var target = {};
2038
- for (var prop in source)
2039
- if (__hasOwnProp4.call(source, prop) && exclude.indexOf(prop) < 0)
2040
- target[prop] = source[prop];
2041
- if (source != null && __getOwnPropSymbols4)
2042
- for (var prop of __getOwnPropSymbols4(source)) {
2043
- if (exclude.indexOf(prop) < 0 && __propIsEnum4.call(source, prop))
2044
- target[prop] = source[prop];
2045
- }
2046
- return target;
2047
- };
2048
- var __publicField3 = (obj, key, value) => __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
2049
- var createSpy = jasmine.createSpy;
2050
- function createSpy2(key) {
2051
- return createSpy(String(key));
2052
- }
2053
- var MockAbortSignal = class {
2054
- constructor() {
2055
- __publicField3(this, "aborted", false);
2056
- __publicField3(this, "onabort", null);
2057
- __publicField3(this, "reason");
2058
- __publicField3(this, "throwIfAborted", createSpy2("throwIfAborted"));
2059
- __publicField3(this, "addEventListener", createSpy2("addEventListener"));
2060
- __publicField3(this, "removeEventListener", createSpy2(
2061
- "removeEventListener"
2062
- ));
2063
- __publicField3(this, "dispatchEvent", createSpy2("dispatchEvent"));
2064
- }
2065
- };
2066
- var MockMediaSource = class {
2067
- constructor() {
2068
- __publicField3(this, "activeSourceBuffers");
2069
- __publicField3(this, "duration", 0);
2070
- __publicField3(this, "onsourceclose", null);
2071
- __publicField3(this, "onsourceended", null);
2072
- __publicField3(this, "onsourceopen", null);
2073
- __publicField3(this, "readyState", "closed");
2074
- __publicField3(this, "sourceBuffers");
2075
- __publicField3(this, "addSourceBuffer", createSpy2("addSourceBuffer"));
2076
- __publicField3(this, "clearLiveSeekableRange", createSpy2(
2077
- "clearLiveSeekableRange"
2078
- ));
2079
- __publicField3(this, "endOfStream", createSpy2("endOfStream"));
2080
- __publicField3(this, "removeSourceBuffer", createSpy2("removeSourceBuffer"));
2081
- __publicField3(this, "setLiveSeekableRange", createSpy2(
2082
- "setLiveSeekableRange"
2083
- ));
2084
- __publicField3(this, "addEventListener", createSpy2("addEventListener"));
2085
- __publicField3(this, "removeEventListener", createSpy2(
2086
- "removeEventListener"
2087
- ));
2088
- __publicField3(this, "dispatchEvent", createSpy2("dispatchEvent"));
2089
- }
2090
- };
2091
- var MockMediaSourceGlobal = class extends MockMediaSource {
2092
- };
2093
- __publicField3(MockMediaSourceGlobal, "canConstructInDedicatedWorker", false);
2094
- __publicField3(MockMediaSourceGlobal, "isTypeSupported", createSpy2(
2095
- "isTypeSupported"
2096
- ));
2097
- var MockAbortSignalGlobal = class extends MockAbortSignal {
2098
- };
2099
- __publicField3(MockAbortSignalGlobal, "abort", createSpy2("abort"));
2100
- __publicField3(MockAbortSignalGlobal, "any", createSpy2("any"));
2101
- __publicField3(MockAbortSignalGlobal, "timeout", createSpy2("timeout"));
2102
- function expectNothing() {
2103
- expect(true).toBeTruthy();
2104
- }
2105
- var nextTestTimeoutOverridden = false;
2106
- function setTestTimeout(timeout) {
2107
- let originalTimeout = null;
2108
- beforeEach(() => {
2109
- originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
2110
- if (!nextTestTimeoutOverridden)
2111
- jasmine.DEFAULT_TIMEOUT_INTERVAL = timeout * 1e3;
2112
- });
2113
- afterEach(() => {
2114
- if (originalTimeout) jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
2115
- if (nextTestTimeoutOverridden) nextTestTimeoutOverridden = false;
2116
- });
2117
- }
1396
+ // ../vinyl-util/test/browserTestUtil/benchmark/Benchmark.ts
2118
1397
  var now;
2119
1398
  if (typeof window !== "undefined" && typeof window.performance !== "undefined" && typeof window.performance.now !== "undefined") {
2120
1399
  now = () => window.performance.now();
@@ -2125,9 +1404,9 @@
2125
1404
  }
2126
1405
  var BenchmarkRunResults = class {
2127
1406
  constructor(name) {
2128
- this.name = name;
2129
- __publicField3(this, "cycleResults", []);
2130
- __publicField3(this, "_totalSamples", 0);
1407
+ __publicField(this, "name", name);
1408
+ __publicField(this, "cycleResults", []);
1409
+ __publicField(this, "_totalSamples", 0);
2131
1410
  }
2132
1411
  get totalSamples() {
2133
1412
  return this._totalSamples;
@@ -2178,8 +1457,11 @@
2178
1457
  };
2179
1458
  var RunResultsComparison = class {
2180
1459
  constructor(name, results) {
2181
- this.name = name;
2182
- __publicField3(this, "results");
1460
+ __publicField(this, "name", name);
1461
+ /**
1462
+ * Sorted by median ops/s from slowest to fastest.
1463
+ */
1464
+ __publicField(this, "results");
2183
1465
  this.results = results.sort((a, b) => {
2184
1466
  return a.meanOpsPerSec - b.meanOpsPerSec;
2185
1467
  });
@@ -2224,7 +1506,7 @@
2224
1506
  maxCycleDuration: 0.5,
2225
1507
  cycles: 9
2226
1508
  };
2227
- var _Benchmark = class _Benchmark2 {
1509
+ var _Benchmark = class _Benchmark {
2228
1510
  /**
2229
1511
  * Constructs a new Benchmark.
2230
1512
  *
@@ -2234,14 +1516,14 @@
2234
1516
  * @param options Optional configuration for the benchmark.
2235
1517
  */
2236
1518
  constructor(name, executor, options) {
2237
- this.name = name;
2238
- this.executor = executor;
2239
- __publicField3(this, "options");
2240
- this.options = __spreadValues4(__spreadValues4({}, defaultBenchmarkOptions), options);
1519
+ __publicField(this, "name", name);
1520
+ __publicField(this, "executor", executor);
1521
+ __publicField(this, "options");
1522
+ this.options = __spreadValues(__spreadValues({}, defaultBenchmarkOptions), options);
2241
1523
  }
2242
1524
  async run() {
2243
1525
  const opts = this.options;
2244
- await _Benchmark2.semaphore;
1526
+ await _Benchmark.semaphore;
2245
1527
  const warmupTimeMs = opts.warmupTime * 1e3;
2246
1528
  const cycleStart = now();
2247
1529
  let isAsync = false;
@@ -2259,7 +1541,7 @@
2259
1541
  }
2260
1542
  return results;
2261
1543
  })();
2262
- _Benchmark2.semaphore = resultsPromise;
1544
+ _Benchmark.semaphore = resultsPromise;
2263
1545
  return await resultsPromise;
2264
1546
  }
2265
1547
  /**
@@ -2285,7 +1567,7 @@
2285
1567
  };
2286
1568
  }
2287
1569
  };
2288
- __publicField3(_Benchmark, "semaphore", nextFrame());
1570
+ __publicField(_Benchmark, "semaphore", nextFrame());
2289
1571
  var Benchmark = _Benchmark;
2290
1572
  function benchmark(name, executor, options) {
2291
1573
  const benchmark2 = new Benchmark(name, executor, options);
@@ -2312,7 +1594,85 @@
2312
1594
  const sum = values.reduce((acc, value) => acc + value, 0);
2313
1595
  return sum / values.length;
2314
1596
  }
2315
- var createSpy3 = jasmine.createSpy;
1597
+
1598
+ // ../vinyl-util/test/browserTestUtil/env/jasmineEnv.ts
1599
+ var nextTestTimeoutOverridden = false;
1600
+ function setTestTimeout(timeout) {
1601
+ let originalTimeout = null;
1602
+ beforeEach(() => {
1603
+ originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
1604
+ if (!nextTestTimeoutOverridden)
1605
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = timeout * 1e3;
1606
+ });
1607
+ afterEach(() => {
1608
+ if (originalTimeout) jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
1609
+ if (nextTestTimeoutOverridden) nextTestTimeoutOverridden = false;
1610
+ });
1611
+ }
1612
+
1613
+ // ../vinyl-util/test/browserTestUtil/expect/expectNothing.ts
1614
+ function expectNothing() {
1615
+ expect(true).toBeTruthy();
1616
+ }
1617
+
1618
+ // ../vinyl-util/test/browserTestUtil/mock/createSpyFactory.ts
1619
+ var createSpy = jasmine.createSpy;
1620
+ function createSpy2(key) {
1621
+ return createSpy(String(key));
1622
+ }
1623
+
1624
+ // ../vinyl-util/test/browserTestUtil/mock/dom/lib.dom.ts
1625
+ var MockAbortSignal = class {
1626
+ constructor() {
1627
+ __publicField(this, "aborted", false);
1628
+ __publicField(this, "onabort", null);
1629
+ __publicField(this, "reason");
1630
+ __publicField(this, "throwIfAborted", createSpy2("throwIfAborted"));
1631
+ __publicField(this, "addEventListener", createSpy2("addEventListener"));
1632
+ __publicField(this, "removeEventListener", createSpy2(
1633
+ "removeEventListener"
1634
+ ));
1635
+ __publicField(this, "dispatchEvent", createSpy2("dispatchEvent"));
1636
+ }
1637
+ };
1638
+ var MockMediaSource = class {
1639
+ constructor() {
1640
+ __publicField(this, "activeSourceBuffers");
1641
+ __publicField(this, "duration", 0);
1642
+ __publicField(this, "onsourceclose", null);
1643
+ __publicField(this, "onsourceended", null);
1644
+ __publicField(this, "onsourceopen", null);
1645
+ __publicField(this, "readyState", "closed");
1646
+ __publicField(this, "sourceBuffers");
1647
+ __publicField(this, "addSourceBuffer", createSpy2("addSourceBuffer"));
1648
+ __publicField(this, "clearLiveSeekableRange", createSpy2(
1649
+ "clearLiveSeekableRange"
1650
+ ));
1651
+ __publicField(this, "endOfStream", createSpy2("endOfStream"));
1652
+ __publicField(this, "removeSourceBuffer", createSpy2("removeSourceBuffer"));
1653
+ __publicField(this, "setLiveSeekableRange", createSpy2(
1654
+ "setLiveSeekableRange"
1655
+ ));
1656
+ __publicField(this, "addEventListener", createSpy2("addEventListener"));
1657
+ __publicField(this, "removeEventListener", createSpy2(
1658
+ "removeEventListener"
1659
+ ));
1660
+ __publicField(this, "dispatchEvent", createSpy2("dispatchEvent"));
1661
+ }
1662
+ };
1663
+
1664
+ // ../vinyl-util/test/browserTestUtil/mock/dom/globals.ts
1665
+ var MockMediaSourceGlobal = class extends MockMediaSource {
1666
+ };
1667
+ __publicField(MockMediaSourceGlobal, "canConstructInDedicatedWorker", false);
1668
+ __publicField(MockMediaSourceGlobal, "isTypeSupported", createSpy2(
1669
+ "isTypeSupported"
1670
+ ));
1671
+ var MockAbortSignalGlobal = class extends MockAbortSignal {
1672
+ };
1673
+ __publicField(MockAbortSignalGlobal, "abort", createSpy2("abort"));
1674
+ __publicField(MockAbortSignalGlobal, "any", createSpy2("any"));
1675
+ __publicField(MockAbortSignalGlobal, "timeout", createSpy2("timeout"));
2316
1676
 
2317
1677
  // test/benchmark/setup.ts
2318
1678
  function setupBenchmark() {