@cofold/yaml 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Luiz Fernando Softov <lfs@softov.dev>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # @cofold/yaml
2
+
3
+ **A documented YAML subset as plain data.**
4
+
5
+ Parsing with source-aware errors, and document loading with local and remote references, JSON pointers and bounded reads. No dependencies, no I/O in the parser.
6
+
7
+ ```ts
8
+ import { parseYaml, loadYaml } from "@cofold/yaml";
9
+ ```
10
+
11
+ Part of the [cofold](https://github.com/softov/cofold) family.
12
+ The manual page is [`docs/commands/11-yaml.md`](../../docs/commands/11-yaml.md); the whole framework is described in [`@cofold/commands`](../commands).
13
+
14
+ ## License
15
+
16
+ MIT
@@ -0,0 +1,5 @@
1
+ export { parseYaml, YamlError } from "./yaml.js";
2
+ export { loadYaml } from "./load.js";
3
+ export type { LoadedYaml, YamlLoadOptions } from "./types/load.js";
4
+ export type { YamlParseOptions } from "./types/parse.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { parseYaml, YamlError } from "./yaml.js";
2
+ export { loadYaml } from "./load.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC"}
package/dist/load.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { LoadedYaml, YamlLoadOptions } from "./types/load.js";
2
+ /** Parse YAML or JSON and optionally resolve references relative to each containing document. */
3
+ export declare function loadYaml(source: string, options?: YamlLoadOptions): Promise<LoadedYaml>;
4
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAMnE,iGAAiG;AACjG,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAsEjG"}
package/dist/load.js ADDED
@@ -0,0 +1,117 @@
1
+ import { readFile as readLocal } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
+ import { parseYaml } from "./yaml.js";
5
+ /** Parse YAML or JSON and optionally resolve references relative to each containing document. */
6
+ export async function loadYaml(source, options = {}) {
7
+ const root = /^(?:https?:|file:)/u.test(source) ? new URL(source) : pathToFileURL(resolve(source));
8
+ const cache = new Map();
9
+ const diagnostics = [];
10
+ const maxBytes = options.maxBytes ?? 16 * 1024 * 1024;
11
+ const read = (url) => {
12
+ const address = new URL(url);
13
+ address.hash = "";
14
+ const key = address.href;
15
+ const prior = cache.get(key);
16
+ if (prior)
17
+ return prior;
18
+ if (cache.size >= (options.maxDocuments ?? 1024))
19
+ throw new Error("Reference loading exceeds maxDocuments");
20
+ const pending = (async () => {
21
+ let text;
22
+ if (address.protocol === "file:")
23
+ text = await (options.readFile ?? ((path) => readLocal(path, "utf8")))(fileURLToPath(address));
24
+ else if (address.protocol === "https:" || address.protocol === "http:") {
25
+ const response = await (options.fetch ?? globalThis.fetch)(address, { signal: AbortSignal.timeout(options.timeoutMs ?? 30_000), redirect: "error" });
26
+ if (!response.ok)
27
+ throw new Error(`${address.href} returned HTTP ${response.status}`);
28
+ const reader = response.body?.getReader();
29
+ const chunks = [];
30
+ let size = 0;
31
+ if (reader) {
32
+ for (;;) {
33
+ const part = await reader.read();
34
+ if (part.done)
35
+ break;
36
+ size += part.value.byteLength;
37
+ if (size > maxBytes) {
38
+ await reader.cancel();
39
+ throw new Error(`${address.href} exceeds maxBytes`);
40
+ }
41
+ chunks.push(part.value);
42
+ }
43
+ }
44
+ text = Buffer.concat(chunks).toString("utf8");
45
+ }
46
+ else
47
+ throw new Error(`Unsupported reference protocol ${address.protocol}`);
48
+ if (Buffer.byteLength(text) > maxBytes)
49
+ throw new Error(`${address.href} exceeds maxBytes`);
50
+ return address.pathname.endsWith(".json") ? JSON.parse(text) : parseYaml(text, { ...options, source: address.href });
51
+ })();
52
+ cache.set(key, pending);
53
+ return pending;
54
+ };
55
+ const pointer = (data, hash) => {
56
+ if (!hash || hash === "#")
57
+ return data;
58
+ const path = decodeURIComponent(hash.slice(1));
59
+ if (!path.startsWith("/"))
60
+ throw new Error(`Reference fragment ${hash} must be a JSON Pointer`);
61
+ let value = data;
62
+ for (const part of path.slice(1).split("/")) {
63
+ const key = part.replaceAll("~1", "/").replaceAll("~0", "~");
64
+ if (value === null || typeof value !== "object" || !Object.hasOwn(value, key))
65
+ throw new Error(`Reference ${hash} does not exist`);
66
+ value = value[key];
67
+ }
68
+ return value;
69
+ };
70
+ const visit = async (value, base, chain, depth) => {
71
+ if (depth > (options.maxDepth ?? 128))
72
+ throw new Error(`Reference nesting exceeds maxDepth: ${chain.join(" -> ")}`);
73
+ if (Array.isArray(value)) {
74
+ const out = [];
75
+ for (const entry of value)
76
+ out.push(await visit(entry, base, chain, depth + 1));
77
+ return out;
78
+ }
79
+ if (value === null || typeof value !== "object")
80
+ return value;
81
+ const object = value;
82
+ if (typeof object["$ref"] === "string" && options.refs !== undefined) {
83
+ const target = new URL(object["$ref"], base);
84
+ const external = target.href.split("#")[0] !== base.href.split("#")[0];
85
+ if (external && target.protocol === "file:" && (options.refs.local !== true || base.protocol !== "file:"))
86
+ throw new Error(`Local reference is not allowed: ${target.href}`);
87
+ if (external && /^https?:$/u.test(target.protocol) && options.refs.remote !== true)
88
+ throw new Error(`Remote reference is not allowed: ${target.href}`);
89
+ if (chain.includes(target.href)) {
90
+ if (options.refs.circular === "preserve")
91
+ return { $ref: target.href };
92
+ throw new Error(`Circular reference: ${[...chain, target.href].join(" -> ")}`);
93
+ }
94
+ let result;
95
+ try {
96
+ result = await visit(pointer(await read(target), target.hash), target, [...chain, target.href], depth + 1);
97
+ }
98
+ catch (error) {
99
+ if (options.refs.unresolved !== "preserve")
100
+ throw error;
101
+ diagnostics.push({ reference: target.href, message: error instanceof Error ? error.message : String(error) });
102
+ return { $ref: target.href };
103
+ }
104
+ const siblings = Object.entries(object).filter(([key]) => key !== "$ref");
105
+ if (siblings.some(([key]) => !["summary", "description"].includes(key)))
106
+ throw new Error(`Unsupported $ref siblings at ${base.href}; constraints must be in the referenced schema`);
107
+ return siblings.length && result !== null && typeof result === "object" ? { ...result, ...Object.fromEntries(siblings) } : result;
108
+ }
109
+ const out = {};
110
+ for (const [key, entry] of Object.entries(object))
111
+ Object.defineProperty(out, key, { value: await visit(entry, base, chain, depth + 1), enumerable: true });
112
+ return out;
113
+ };
114
+ const data = await visit(pointer(await read(root), root.hash), root, [], 0);
115
+ return { data, sources: [...cache.keys()], diagnostics };
116
+ }
117
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,iGAAiG;AACjG,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,MAAc,EAAE,UAA2B,EAAE;IAC1E,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACnG,MAAM,KAAK,GAAG,IAAI,GAAG,EAA4B,CAAC;IAClD,MAAM,WAAW,GAA8B,EAAE,CAAC;IAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IACtD,MAAM,IAAI,GAAG,CAAC,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gCAAgC,IAAI,CAAC,IAAI,gDAAgD,CAAC,CAAC;YACpL,OAAO,QAAQ,CAAC,MAAM,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;QACpI,CAAC;QACD,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5J,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC5E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { YamlParseOptions } from "./parse.js";
2
+ export interface YamlLoadOptions extends YamlParseOptions {
3
+ refs?: {
4
+ local?: boolean;
5
+ remote?: boolean;
6
+ circular?: "error" | "preserve";
7
+ unresolved?: "error" | "preserve";
8
+ };
9
+ readFile?(path: string): Promise<string> | string;
10
+ fetch?: typeof globalThis.fetch;
11
+ timeoutMs?: number;
12
+ maxDocuments?: number;
13
+ }
14
+ export interface LoadedYaml {
15
+ data: unknown;
16
+ sources: string[];
17
+ diagnostics: {
18
+ reference: string;
19
+ message: string;
20
+ }[];
21
+ }
22
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/types/load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;KAAE,CAAC;IACjH,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAClD,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/types/load.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export interface YamlParseOptions {
2
+ /** A filename or URL used in diagnostics; the parser does not read it. */
3
+ source?: string;
4
+ /** Bound input size before parsing. Default: 16 MiB. */
5
+ maxBytes?: number;
6
+ /** Bound nesting before recursive parsing. Default: 128. */
7
+ maxDepth?: number;
8
+ }
9
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/types/parse.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/types/parse.ts"],"names":[],"mappings":""}
package/dist/yaml.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { YamlParseOptions } from "./types/parse.js";
2
+ /**
3
+ * @cofold/yaml reads a documented YAML subset as plain data, without I/O or dependencies.
4
+ * Unsupported syntax is rejected rather than interpreted approximately.
5
+ * File loading, document composition, and reference resolution belong to callers.
6
+ */
7
+ export declare class YamlError extends Error {
8
+ readonly line: number;
9
+ readonly source: string | undefined;
10
+ readonly detail: string;
11
+ constructor(message: string, line: number, source?: string);
12
+ }
13
+ /** The document as data. Mappings become objects, sequences arrays, scalars themselves. */
14
+ export declare function parseYaml(text: string, options?: YamlParseOptions): unknown;
15
+ //# sourceMappingURL=yaml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;GAIG;AAEH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAOlE;AA4BD,2FAA2F;AAC3F,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAY/E"}