@origints/yaml 0.1.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,19 +1,23 @@
1
- import { isAlias as c, isMap as f, isSeq as d, isScalar as l, isPair as y, parseDocument as b, parseAllDocuments as E } from "yaml";
1
+ import { TYPE_LABEL as L, registerSpecExecutor as M, globalRegistry as P } from "@origints/core";
2
+ import { isAlias as h, isMap as c, isSeq as d, isScalar as l, isPair as A, parseDocument as E, parseAllDocuments as I } from "yaml";
2
3
  function i(t, e) {
3
4
  return { ok: !0, value: t, path: e };
4
5
  }
5
- function u(t, e, n, s) {
6
+ function u(t, e, n, r) {
6
7
  return {
7
8
  ok: !1,
8
- failure: { kind: t, message: e, path: n, position: s }
9
+ failure: { kind: t, message: e, path: n, position: r }
9
10
  };
10
11
  }
11
- function I(t) {
12
+ function B(t) {
12
13
  return t.length === 0 ? "root" : t.map((e) => typeof e == "number" ? `[${e}]` : `.${e}`).join("").replace(/^\./, "");
13
14
  }
14
15
  class p {
15
- constructor(e, n, s) {
16
- this.node = e, this._path = n, this.doc = s;
16
+ constructor(e, n, r) {
17
+ this.node = e, this._path = n, this.doc = r;
18
+ }
19
+ get [L]() {
20
+ return `YamlNode(${this.nodeType})`;
17
21
  }
18
22
  /**
19
23
  * Creates a YamlNode from a parsed YAML document.
@@ -25,8 +29,8 @@ class p {
25
29
  * Creates a YamlNode from a YAML AST node.
26
30
  * @internal
27
31
  */
28
- static fromNode(e, n, s) {
29
- return new p(e, n, s);
32
+ static fromNode(e, n, r) {
33
+ return new p(e, n, r);
30
34
  }
31
35
  /**
32
36
  * Returns the current path through the YAML structure.
@@ -49,7 +53,7 @@ class p {
49
53
  * Returns the type of this YAML node.
50
54
  */
51
55
  get nodeType() {
52
- return this.node ? c(this.node) ? "alias" : f(this.node) ? "mapping" : d(this.node) ? "sequence" : "scalar" : "scalar";
56
+ return this.node ? h(this.node) ? "alias" : c(this.node) ? "mapping" : d(this.node) ? "sequence" : "scalar" : "scalar";
53
57
  }
54
58
  /**
55
59
  * Returns the underlying raw value.
@@ -66,17 +70,17 @@ class p {
66
70
  * Navigate to a nested value in a JSON structure using the path.
67
71
  */
68
72
  navigatePath(e, n) {
69
- let s = e;
70
- for (const r of n) {
71
- if (s == null) return;
72
- if (typeof r == "number" && Array.isArray(s))
73
- s = s[r];
74
- else if (typeof r == "string" && typeof s == "object")
75
- s = s[r];
73
+ let r = e;
74
+ for (const s of n) {
75
+ if (r == null) return;
76
+ if (typeof s == "number" && Array.isArray(r))
77
+ r = r[s];
78
+ else if (typeof s == "string" && typeof r == "object")
79
+ r = r[s];
76
80
  else
77
81
  return;
78
82
  }
79
- return s;
83
+ return r;
80
84
  }
81
85
  // ---------------------------------------------------------------------------
82
86
  // YAML-SPECIFIC METADATA
@@ -85,31 +89,31 @@ class p {
85
89
  * Get the YAML tag (e.g., '!!str', '!!int', custom tags).
86
90
  */
87
91
  tag() {
88
- return this.node ? l(this.node) ? i(this.node.tag ?? null, this._path) : f(this.node) || d(this.node) ? i(this.node.tag ?? null, this._path) : i(null, this._path) : i(null, this._path);
92
+ return this.node ? l(this.node) ? i(this.node.tag ?? null, this._path) : c(this.node) || d(this.node) ? i(this.node.tag ?? null, this._path) : i(null, this._path) : i(null, this._path);
89
93
  }
90
94
  /**
91
95
  * Get anchor name if this node defines one.
92
96
  */
93
97
  anchor() {
94
- return this.node ? l(this.node) || f(this.node) || d(this.node) ? i(this.node.anchor ?? null, this._path) : i(null, this._path) : i(null, this._path);
98
+ return this.node ? l(this.node) || c(this.node) || d(this.node) ? i(this.node.anchor ?? null, this._path) : i(null, this._path) : i(null, this._path);
95
99
  }
96
100
  /**
97
101
  * Check if this node is an alias reference.
98
102
  */
99
103
  isAlias() {
100
- return this.node !== null && c(this.node);
104
+ return this.node !== null && h(this.node);
101
105
  }
102
106
  /**
103
107
  * If alias, get the anchor name it references.
104
108
  */
105
109
  aliasTarget() {
106
- return !this.node || !c(this.node) ? u("alias", "Node is not an alias", this._path, this.position) : i(this.node.source, this._path);
110
+ return !this.node || !h(this.node) ? u("alias", "Node is not an alias", this._path, this.position) : i(this.node.source, this._path);
107
111
  }
108
112
  /**
109
113
  * If alias, resolve to the actual node.
110
114
  */
111
115
  resolveAlias() {
112
- if (!this.node || !c(this.node))
116
+ if (!this.node || !h(this.node))
113
117
  return u("alias", "Node is not an alias", this._path, this.position);
114
118
  const e = this.node.resolve(this.doc);
115
119
  return e ? i(new p(e, [...this._path], this.doc), this._path) : u(
@@ -123,13 +127,13 @@ class p {
123
127
  * Get comment before this node.
124
128
  */
125
129
  commentBefore() {
126
- return this.node ? l(this.node) || f(this.node) || d(this.node) ? i(this.node.commentBefore ?? null, this._path) : i(null, this._path) : i(null, this._path);
130
+ return this.node ? l(this.node) || c(this.node) || d(this.node) ? i(this.node.commentBefore ?? null, this._path) : i(null, this._path) : i(null, this._path);
127
131
  }
128
132
  /**
129
133
  * Get comment on same line as this node.
130
134
  */
131
135
  comment() {
132
- return this.node ? l(this.node) || f(this.node) || d(this.node) ? i(this.node.comment ?? null, this._path) : i(null, this._path) : i(null, this._path);
136
+ return this.node ? l(this.node) || c(this.node) || d(this.node) ? i(this.node.comment ?? null, this._path) : i(null, this._path) : i(null, this._path);
133
137
  }
134
138
  // ---------------------------------------------------------------------------
135
139
  // NAVIGATION
@@ -141,20 +145,20 @@ class p {
141
145
  get(e) {
142
146
  const n = this.resolveIfAlias();
143
147
  if (!n.ok) return n;
144
- const s = n.value.node;
145
- if (!s || !f(s))
148
+ const r = n.value.node;
149
+ if (!r || !c(r))
146
150
  return u(
147
151
  "type",
148
152
  `Expected mapping, got ${this.nodeType}`,
149
153
  this._path,
150
154
  this.position
151
155
  );
152
- const r = s.items.find((a) => {
153
- if (!y(a)) return !1;
154
- const h = a.key;
155
- return l(h) ? h.value === e : !1;
156
+ const s = r.items.find((a) => {
157
+ if (!A(a)) return !1;
158
+ const f = a.key;
159
+ return l(f) ? f.value === e : !1;
156
160
  });
157
- if (!r)
161
+ if (!s)
158
162
  return u(
159
163
  "missing",
160
164
  `Key "${e}" not found`,
@@ -163,7 +167,7 @@ class p {
163
167
  );
164
168
  const o = [...this._path, e];
165
169
  return i(
166
- new p(r.value, o, this.doc),
170
+ new p(s.value, o, this.doc),
167
171
  o
168
172
  );
169
173
  }
@@ -174,25 +178,25 @@ class p {
174
178
  at(e) {
175
179
  const n = this.resolveIfAlias();
176
180
  if (!n.ok) return n;
177
- const s = n.value.node;
178
- if (!s || !d(s))
181
+ const r = n.value.node;
182
+ if (!r || !d(r))
179
183
  return u(
180
184
  "type",
181
185
  `Expected sequence, got ${this.nodeType}`,
182
186
  this._path,
183
187
  this.position
184
188
  );
185
- if (e < 0 || e >= s.items.length)
189
+ if (e < 0 || e >= r.items.length)
186
190
  return u(
187
191
  "missing",
188
- `Index ${e} out of bounds (length: ${s.items.length})`,
192
+ `Index ${e} out of bounds (length: ${r.items.length})`,
189
193
  this._path,
190
194
  this.position
191
195
  );
192
- const r = [...this._path, e];
196
+ const s = [...this._path, e];
193
197
  return i(
194
- new p(s.items[e], r, this.doc),
195
- r
198
+ new p(r.items[e], s, this.doc),
199
+ s
196
200
  );
197
201
  }
198
202
  /**
@@ -202,17 +206,17 @@ class p {
202
206
  const e = this.resolveIfAlias();
203
207
  if (!e.ok) return e;
204
208
  const n = e.value.node;
205
- if (!n || !f(n))
209
+ if (!n || !c(n))
206
210
  return u(
207
211
  "type",
208
212
  `Expected mapping, got ${this.nodeType}`,
209
213
  this._path,
210
214
  this.position
211
215
  );
212
- const s = [];
213
- for (const r of n.items)
214
- y(r) && l(r.key) && s.push(String(r.key.value));
215
- return i(s, this._path);
216
+ const r = [];
217
+ for (const s of n.items)
218
+ A(s) && l(s.key) && r.push(String(s.key.value));
219
+ return i(r, this._path);
216
220
  }
217
221
  /**
218
222
  * Get all values of a mapping as [key, node] pairs.
@@ -221,23 +225,23 @@ class p {
221
225
  const e = this.resolveIfAlias();
222
226
  if (!e.ok) return e;
223
227
  const n = e.value.node;
224
- if (!n || !f(n))
228
+ if (!n || !c(n))
225
229
  return u(
226
230
  "type",
227
231
  `Expected mapping, got ${this.nodeType}`,
228
232
  this._path,
229
233
  this.position
230
234
  );
231
- const s = [];
232
- for (const r of n.items)
233
- if (y(r) && l(r.key)) {
234
- const o = String(r.key.value), a = [...this._path, o];
235
- s.push([
235
+ const r = [];
236
+ for (const s of n.items)
237
+ if (A(s) && l(s.key)) {
238
+ const o = String(s.key.value), a = [...this._path, o];
239
+ r.push([
236
240
  o,
237
- new p(r.value, a, this.doc)
241
+ new p(s.value, a, this.doc)
238
242
  ]);
239
243
  }
240
- return i(s, this._path);
244
+ return i(r, this._path);
241
245
  }
242
246
  /**
243
247
  * Get all items of a sequence.
@@ -253,14 +257,14 @@ class p {
253
257
  this._path,
254
258
  this.position
255
259
  );
256
- const s = [];
257
- for (let r = 0; r < n.items.length; r++) {
258
- const o = [...this._path, r];
259
- s.push(
260
- new p(n.items[r], o, this.doc)
260
+ const r = [];
261
+ for (let s = 0; s < n.items.length; s++) {
262
+ const o = [...this._path, s];
263
+ r.push(
264
+ new p(n.items[s], o, this.doc)
261
265
  );
262
266
  }
263
- return i(s, this._path);
267
+ return i(r, this._path);
264
268
  }
265
269
  /**
266
270
  * Check if mapping has key.
@@ -268,10 +272,10 @@ class p {
268
272
  has(e) {
269
273
  const n = this.resolveIfAlias();
270
274
  if (!n.ok) return !1;
271
- const s = n.value.node;
272
- return !s || !f(s) ? !1 : s.items.some((r) => {
273
- if (!y(r)) return !1;
274
- const o = r.key;
275
+ const r = n.value.node;
276
+ return !r || !c(r) ? !1 : r.items.some((s) => {
277
+ if (!A(s)) return !1;
278
+ const o = s.key;
275
279
  return l(o) ? o.value === e : !1;
276
280
  });
277
281
  }
@@ -285,7 +289,7 @@ class p {
285
289
  const e = this.getScalarValue();
286
290
  return typeof e != "string" ? u(
287
291
  "type",
288
- `Expected string, got ${_(e)}`,
292
+ `Expected string, got ${S(e)}`,
289
293
  this._path,
290
294
  this.position
291
295
  ) : i(e, this._path);
@@ -297,7 +301,7 @@ class p {
297
301
  const e = this.getScalarValue();
298
302
  return typeof e != "number" ? u(
299
303
  "type",
300
- `Expected number, got ${_(e)}`,
304
+ `Expected number, got ${S(e)}`,
301
305
  this._path,
302
306
  this.position
303
307
  ) : i(e, this._path);
@@ -309,7 +313,7 @@ class p {
309
313
  const e = this.getScalarValue();
310
314
  return typeof e != "boolean" ? u(
311
315
  "type",
312
- `Expected boolean, got ${_(e)}`,
316
+ `Expected boolean, got ${S(e)}`,
313
317
  this._path,
314
318
  this.position
315
319
  ) : i(e, this._path);
@@ -321,7 +325,7 @@ class p {
321
325
  const e = this.getScalarValue();
322
326
  return e !== null ? u(
323
327
  "type",
324
- `Expected null, got ${_(e)}`,
328
+ `Expected null, got ${S(e)}`,
325
329
  this._path,
326
330
  this.position
327
331
  ) : i(null, this._path);
@@ -339,8 +343,8 @@ class p {
339
343
  const e = this.entries();
340
344
  if (!e.ok) return e;
341
345
  const n = {};
342
- for (const [s, r] of e.value)
343
- n[s] = r;
346
+ for (const [r, s] of e.value)
347
+ n[r] = s;
344
348
  return i(n, this._path);
345
349
  }
346
350
  // ---------------------------------------------------------------------------
@@ -348,7 +352,7 @@ class p {
348
352
  // ---------------------------------------------------------------------------
349
353
  isScalar() {
350
354
  if (!this.node) return !0;
351
- if (c(this.node)) {
355
+ if (h(this.node)) {
352
356
  const e = this.node.resolve(this.doc);
353
357
  return !e || l(e);
354
358
  }
@@ -356,7 +360,7 @@ class p {
356
360
  }
357
361
  isSequence() {
358
362
  if (!this.node) return !1;
359
- if (c(this.node)) {
363
+ if (h(this.node)) {
360
364
  const e = this.node.resolve(this.doc);
361
365
  return e !== null && d(e);
362
366
  }
@@ -364,11 +368,11 @@ class p {
364
368
  }
365
369
  isMapping() {
366
370
  if (!this.node) return !1;
367
- if (c(this.node)) {
371
+ if (h(this.node)) {
368
372
  const e = this.node.resolve(this.doc);
369
- return e !== null && f(e);
373
+ return e !== null && c(e);
370
374
  }
371
- return f(this.node);
375
+ return c(this.node);
372
376
  }
373
377
  isString() {
374
378
  return typeof this.getScalarValue() == "string";
@@ -389,45 +393,99 @@ class p {
389
393
  * Resolve alias if this is one, otherwise return self.
390
394
  */
391
395
  resolveIfAlias() {
392
- return this.node && c(this.node) ? this.resolveAlias() : i(this, this._path);
396
+ return this.node && h(this.node) ? this.resolveAlias() : i(this, this._path);
393
397
  }
394
398
  /**
395
399
  * Get the scalar value, resolving aliases.
396
400
  */
397
401
  getScalarValue() {
398
402
  if (!this.node) return null;
399
- if (c(this.node)) {
403
+ if (h(this.node)) {
400
404
  const e = this.node.resolve(this.doc);
401
405
  return e ? l(e) ? e.value : e.toJSON() : null;
402
406
  }
403
407
  return l(this.node) ? this.node.value : this.node.toJSON();
404
408
  }
405
409
  }
406
- function _(t) {
410
+ function S(t) {
407
411
  return t === null ? "null" : Array.isArray(t) ? "sequence" : typeof t == "object" ? "mapping" : typeof t;
408
412
  }
409
- async function $(t) {
410
- const e = t.getReader(), n = new TextDecoder(), s = [];
413
+ function k(t, e) {
414
+ return { kind: "extract", format: "yaml", steps: t, extract: e };
415
+ }
416
+ class y {
417
+ constructor(e) {
418
+ this.steps = e;
419
+ }
420
+ /** Create a root spec builder */
421
+ static root() {
422
+ return new y([]);
423
+ }
424
+ /** Navigate to a mapping property */
425
+ get(e) {
426
+ return new y([...this.steps, { kind: "get", key: e }]);
427
+ }
428
+ /** Navigate to a sequence element */
429
+ at(e) {
430
+ return new y([...this.steps, { kind: "at", index: e }]);
431
+ }
432
+ /** Extract as string */
433
+ string() {
434
+ return k(this.steps, "string");
435
+ }
436
+ /** Extract as number */
437
+ number() {
438
+ return k(this.steps, "number");
439
+ }
440
+ /** Extract as boolean */
441
+ boolean() {
442
+ return k(this.steps, "boolean");
443
+ }
444
+ /** Extract as null */
445
+ null() {
446
+ return k(this.steps, "null");
447
+ }
448
+ /** Iterate over sequence items, mapping each to a spec */
449
+ array(e) {
450
+ const n = e(y.root());
451
+ return {
452
+ kind: "array",
453
+ source: k(this.steps, "items"),
454
+ items: n
455
+ };
456
+ }
457
+ /** Extract all items as strings */
458
+ strings() {
459
+ return this.array((e) => e.string());
460
+ }
461
+ /** Extract all items as numbers */
462
+ numbers() {
463
+ return this.array((e) => e.number());
464
+ }
465
+ }
466
+ async function O(t) {
467
+ const e = t.getReader(), n = new TextDecoder(), r = [];
411
468
  try {
412
469
  for (; ; ) {
413
- const { done: r, value: o } = await e.read();
414
- if (r) break;
415
- s.push(n.decode(o, { stream: !0 }));
470
+ const { done: s, value: o } = await e.read();
471
+ if (s) break;
472
+ r.push(n.decode(o, { stream: !0 }));
416
473
  }
417
- return s.push(n.decode()), s.join("");
474
+ return r.push(n.decode()), r.join("");
418
475
  } finally {
419
476
  e.releaseLock();
420
477
  }
421
478
  }
422
- function J(t) {
479
+ function U(t) {
423
480
  return {
424
481
  kind: "transform",
425
482
  namespace: "@origints/yaml",
426
483
  name: "parseYaml",
427
- args: t
484
+ args: t,
485
+ specBuilderFactory: () => y.root()
428
486
  };
429
487
  }
430
- function P(t) {
488
+ function K(t) {
431
489
  return {
432
490
  kind: "transform",
433
491
  namespace: "@origints/yaml",
@@ -435,69 +493,73 @@ function P(t) {
435
493
  args: t
436
494
  };
437
495
  }
438
- const V = {
496
+ const N = {
439
497
  namespace: "@origints/yaml",
440
498
  name: "parseYaml",
441
499
  execute(t, e) {
442
- const s = A(e ?? {});
443
- let r;
500
+ const r = Y(e ?? {});
501
+ let s;
444
502
  if (typeof t == "string")
445
- r = t;
503
+ s = t;
446
504
  else throw t instanceof ReadableStream ? new Error(
447
505
  "parseYaml received a stream. Use streamToString first or ensure the input is a string."
448
506
  ) : new Error(`parseYaml expects string input, got ${typeof t}`);
449
- const o = b(r, s);
507
+ const o = E(s, r);
450
508
  if (o.errors.length > 0) {
451
509
  const a = o.errors[0];
452
510
  throw new Error(`YAML parse error: ${a.message}`);
453
511
  }
454
512
  return p.fromDocument(o);
455
513
  }
456
- }, Y = {
514
+ }, J = {
457
515
  namespace: "@origints/yaml",
458
516
  name: "parseYaml",
459
517
  async execute(t, e) {
460
- const s = A(e ?? {});
461
- let r;
518
+ const r = Y(e ?? {});
519
+ let s;
462
520
  if (typeof t == "string")
463
- r = t;
521
+ s = t;
464
522
  else if (t instanceof ReadableStream)
465
- r = await $(t);
523
+ s = await O(t);
524
+ else if (t instanceof Uint8Array)
525
+ s = new TextDecoder().decode(t);
526
+ else if (t instanceof ArrayBuffer)
527
+ s = new TextDecoder().decode(t);
466
528
  else
467
529
  throw new Error(
468
- `parseYaml expects string or stream input, got ${typeof t}`
530
+ `parseYaml expects a string, stream, Uint8Array, or ArrayBuffer input, got ${typeof t}`
469
531
  );
470
- const o = b(r, s);
532
+ const o = E(s, r);
471
533
  if (o.errors.length > 0) {
472
534
  const a = o.errors[0];
473
535
  throw new Error(`YAML parse error: ${a.message}`);
474
536
  }
475
537
  return p.fromDocument(o);
476
538
  }
477
- }, x = {
539
+ }, D = {
478
540
  namespace: "@origints/yaml",
479
541
  name: "parseYamlAll",
480
542
  async execute(t, e) {
481
- const s = A(e ?? {});
482
- let r;
543
+ const r = Y(e ?? {});
544
+ let s;
483
545
  if (typeof t == "string")
484
- r = t;
546
+ s = t;
485
547
  else if (t instanceof ReadableStream)
486
- r = await $(t);
548
+ s = await O(t);
487
549
  else
488
550
  throw new Error(
489
551
  `parseYamlAll expects string or stream input, got ${typeof t}`
490
552
  );
491
- const o = E(r, s);
553
+ const o = I(s, r);
492
554
  for (const a of o)
493
555
  if (a.errors.length > 0) {
494
- const h = a.errors[0];
495
- throw new Error(`YAML parse error: ${h.message}`);
556
+ const f = a.errors[0];
557
+ throw new Error(`YAML parse error: ${f.message}`);
496
558
  }
497
559
  return o.map((a) => p.fromDocument(a));
498
560
  }
499
561
  };
500
- function A(t) {
562
+ function Y(t) {
501
563
  return {
502
564
  uniqueKeys: t.duplicateKeys !== "last",
503
565
  keepSourceTokens: !0,
@@ -505,106 +567,162 @@ function A(t) {
505
567
  version: t.version ?? "1.2"
506
568
  };
507
569
  }
508
- function D(t) {
570
+ function w(t) {
571
+ return { ok: !0, value: t, path: [] };
572
+ }
573
+ function m(t) {
574
+ return { ok: !1, kind: "format", message: t, path: [] };
575
+ }
576
+ function V(t, e) {
577
+ if (t.kind !== "extract" || t.format !== "yaml")
578
+ return m(
579
+ `Expected spec kind "extract" with format "yaml", got kind "${t.kind}" format "${t.format}"`
580
+ );
581
+ let n = e;
582
+ for (const r of t.steps)
583
+ switch (r.kind) {
584
+ case "get": {
585
+ const s = n.get(r.key);
586
+ if (!s.ok)
587
+ return m(
588
+ `YAML navigation failed at get("${r.key}"): ${s.failure.message}`
589
+ );
590
+ n = s.value;
591
+ break;
592
+ }
593
+ case "at": {
594
+ const s = n.at(r.index);
595
+ if (!s.ok)
596
+ return m(
597
+ `YAML navigation failed at at(${r.index}): ${s.failure.message}`
598
+ );
599
+ n = s.value;
600
+ break;
601
+ }
602
+ }
603
+ switch (t.extract) {
604
+ case "string": {
605
+ const r = n.asString();
606
+ return r.ok ? w(r.value) : m(`YAML extraction failed: ${r.failure.message}`);
607
+ }
608
+ case "number": {
609
+ const r = n.asNumber();
610
+ return r.ok ? w(r.value) : m(`YAML extraction failed: ${r.failure.message}`);
611
+ }
612
+ case "boolean": {
613
+ const r = n.asBoolean();
614
+ return r.ok ? w(r.value) : m(`YAML extraction failed: ${r.failure.message}`);
615
+ }
616
+ case "null": {
617
+ const r = n.asNull();
618
+ return r.ok ? w(r.value) : m(`YAML extraction failed: ${r.failure.message}`);
619
+ }
620
+ case "items": {
621
+ const r = n.items();
622
+ return r.ok ? w(r.value) : m(`YAML extraction failed: ${r.failure.message}`);
623
+ }
624
+ }
625
+ }
626
+ function C(t) {
509
627
  const e = t.unwrap();
510
- return k(e) ? i(e, t.path) : u(
628
+ return x(e) ? i(e, t.path) : u(
511
629
  "type",
512
630
  `Cannot convert YAML value to JSON: ${typeof e}`,
513
631
  t.path,
514
632
  t.position
515
633
  );
516
634
  }
517
- function k(t) {
518
- return t === null || typeof t == "boolean" ? !0 : typeof t == "number" ? Number.isFinite(t) : typeof t == "string" ? !0 : Array.isArray(t) ? t.every(k) : typeof t == "object" ? Object.values(t).every(k) : !1;
635
+ function x(t) {
636
+ return t === null || typeof t == "boolean" ? !0 : typeof t == "number" ? Number.isFinite(t) : typeof t == "string" ? !0 : Array.isArray(t) ? t.every(x) : typeof t == "object" ? Object.values(t).every(x) : !1;
519
637
  }
520
- function q(t, e = {}) {
638
+ function F(t, e = {}) {
521
639
  const n = t;
522
- return v(n.node, n.doc, t.path, e);
640
+ return b(n.node, n.doc, t.path, e);
523
641
  }
524
- function v(t, e, n, s) {
642
+ function b(t, e, n, r) {
525
643
  if (t === null) return i(null, n);
526
- if (c(t)) {
527
- const r = t.resolve(e);
528
- return r ? v(r, e, n, s) : u(
644
+ if (h(t)) {
645
+ const s = t.resolve(e);
646
+ return s ? b(s, e, n, r) : u(
529
647
  "anchor",
530
648
  `Unresolved alias: ${t.source}`,
531
649
  n,
532
- w(t)
650
+ $(t)
533
651
  );
534
652
  }
535
653
  if (l(t)) {
536
- const r = t.value;
537
- if (r === null) return i(null, n);
538
- if (typeof r == "boolean" || typeof r == "string") return i(r, n);
539
- if (typeof r == "number") {
540
- if (!Number.isFinite(r))
541
- switch (s.nonJsonValues ?? "error") {
654
+ const s = t.value;
655
+ if (s === null) return i(null, n);
656
+ if (typeof s == "boolean" || typeof s == "string") return i(s, n);
657
+ if (typeof s == "number") {
658
+ if (!Number.isFinite(s))
659
+ switch (r.nonJsonValues ?? "error") {
542
660
  case "null":
543
661
  return i(null, n);
544
662
  case "string":
545
- return i(String(r), n);
663
+ return i(String(s), n);
546
664
  default:
547
665
  return u(
548
666
  "type",
549
- `Cannot convert ${r} to JSON`,
667
+ `Cannot convert ${s} to JSON`,
550
668
  n,
551
- w(t)
669
+ $(t)
552
670
  );
553
671
  }
554
- return i(r, n);
672
+ return i(s, n);
555
673
  }
556
- if (r instanceof Date)
557
- switch (s.dates ?? "iso") {
674
+ if (s instanceof Date)
675
+ switch (r.dates ?? "iso") {
558
676
  case "iso":
559
- return i(r.toISOString(), n);
677
+ return i(s.toISOString(), n);
560
678
  case "timestamp":
561
- return i(r.getTime(), n);
679
+ return i(s.getTime(), n);
562
680
  default:
563
681
  return u(
564
682
  "type",
565
683
  "Date objects are not JSON-compatible",
566
684
  n,
567
- w(t)
685
+ $(t)
568
686
  );
569
687
  }
570
- return i(String(r), n);
688
+ return i(String(s), n);
571
689
  }
572
690
  if (d(t)) {
573
- const r = [];
691
+ const s = [];
574
692
  for (let o = 0; o < t.items.length; o++) {
575
- const a = t.items[o], h = [...n, o], g = v(a, e, h, s);
576
- if (!g.ok) return g;
577
- r.push(g.value);
693
+ const a = t.items[o], f = [...n, o], v = b(a, e, f, r);
694
+ if (!v.ok) return v;
695
+ s.push(v.value);
578
696
  }
579
- return i(r, n);
697
+ return i(s, n);
580
698
  }
581
- if (f(t)) {
582
- const r = {};
699
+ if (c(t)) {
700
+ const s = {};
583
701
  for (const o of t.items) {
584
- if (!y(o)) continue;
702
+ if (!A(o)) continue;
585
703
  let a;
586
- const h = o.key;
587
- if (h === null)
704
+ const f = o.key;
705
+ if (f === null)
588
706
  a = "null";
589
- else if (c(h)) {
590
- const m = h.resolve(e);
591
- m && l(m) ? a = String(m.value) : a = String(h.source);
592
- } else if (l(h))
593
- a = String(h.value);
707
+ else if (h(f)) {
708
+ const g = f.resolve(e);
709
+ g && l(g) ? a = String(g.value) : a = String(f.source);
710
+ } else if (l(f))
711
+ a = String(f.value);
594
712
  else {
595
- const m = v(h, e, n, s);
596
- if (!m.ok) return m;
597
- a = JSON.stringify(m.value);
713
+ const g = b(f, e, n, r);
714
+ if (!g.ok) return g;
715
+ a = JSON.stringify(g.value);
598
716
  }
599
- const g = [...n, a], O = o.value, S = v(O, e, g, s);
600
- if (!S.ok) return S;
601
- r[a] = S.value;
717
+ const v = [...n, a], T = o.value, _ = b(T, e, v, r);
718
+ if (!_.ok) return _;
719
+ s[a] = _.value;
602
720
  }
603
- return i(r, n);
721
+ return i(s, n);
604
722
  }
605
723
  return u("type", "Unexpected YAML node type", n, void 0);
606
724
  }
607
- function w(t) {
725
+ function $(t) {
608
726
  if (!t.range) return;
609
727
  const [e, n] = t.range;
610
728
  return {
@@ -612,22 +730,29 @@ function w(t) {
612
730
  end: { line: 0, column: 0, offset: n }
613
731
  };
614
732
  }
615
- function M(t) {
616
- t.register(Y), t.register(x);
733
+ function R(t) {
734
+ t.register(J), t.register(D);
617
735
  }
736
+ R(P);
737
+ M(
738
+ "yaml",
739
+ (t, e) => V(t, e)
740
+ );
618
741
  export {
619
742
  p as YamlNode,
743
+ y as YamlSpecBuilder,
744
+ V as executeYamlSpec,
620
745
  u as fail,
621
- I as formatYamlPath,
746
+ B as formatYamlPath,
622
747
  i as ok,
623
- J as parseYaml,
624
- P as parseYamlAll,
625
- x as parseYamlAllImpl,
626
- Y as parseYamlAsyncImpl,
627
- V as parseYamlImpl,
628
- M as registerYamlTransforms,
629
- $ as streamToString,
630
- q as toJson,
631
- D as toJsonValue
748
+ U as parseYaml,
749
+ K as parseYamlAll,
750
+ D as parseYamlAllImpl,
751
+ J as parseYamlAsyncImpl,
752
+ N as parseYamlImpl,
753
+ R as registerYamlTransforms,
754
+ O as streamToString,
755
+ F as toJson,
756
+ C as toJsonValue
632
757
  };
633
758
  //# sourceMappingURL=index.es.js.map