@amritk/resolve-refs 0.8.0 → 0.9.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/AI.md +3 -1
- package/README.md +1 -0
- package/dist/resolve-refs-from-file.js +3 -1
- package/dist/types.d.ts +17 -0
- package/package.json +1 -1
package/AI.md
CHANGED
|
@@ -45,7 +45,9 @@ const remote = await resolveRefsFromFile('https://api.example.com/schema.json',
|
|
|
45
45
|
`allowedRoots: ['./specs']` (or whatever contains both files) to allow it.
|
|
46
46
|
`localRefs: false` refuses cross-file reads entirely.
|
|
47
47
|
5. **JSON-only by default** (`JSON.parse`). For YAML pass a custom
|
|
48
|
-
`parse: (content, location) => …` (e.g. wrapping `@amritk/yaml`).
|
|
48
|
+
`parse: (content, location) => …` (e.g. wrapping `@amritk/yaml`). Already
|
|
49
|
+
parsed the root? Pass it as `rootDocument` and the file is not read or
|
|
50
|
+
parsed again (its path still anchors relative refs and `allowedRoots`).
|
|
49
51
|
6. **`origins` exists only with `trackOrigins: true`.** Cycles are preserved (the
|
|
50
52
|
cycle point stays a `$ref`), so output is not always fully flat. The remote
|
|
51
53
|
cache is process-wide but credential-scoped and bounded (10 min TTL, 256
|
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ const remote = await resolveRefsFromFile('https://api.example.com/schema.json',
|
|
|
70
70
|
| `maxDepth` | `512` | How deep to walk before leaving a subtree unresolved and recording an error. |
|
|
71
71
|
| `cache` | `true` | Pass `false` to bypass the process-wide session cache for this call — everything is re-fetched, nothing is stored. |
|
|
72
72
|
| `parse` | `JSON.parse` | Custom content parser (e.g. YAML-aware). |
|
|
73
|
+
| `rootDocument` | — | The root's already-parsed value. The named file is then neither read nor parsed; its location still anchors relative refs, `allowedRoots`, and `origins`. The value is only read, never written or aliased into the result. |
|
|
73
74
|
| `trackOrigins` | `false` | Record a per-node origin map on the result. |
|
|
74
75
|
|
|
75
76
|
Errors (a missing file, a refused host, a refused path, a bad URL, a document too
|
|
@@ -419,7 +419,9 @@ const resolveRefsFromFile = async (filename, options = {}) => {
|
|
|
419
419
|
return null;
|
|
420
420
|
return `it resolves outside the allowed roots [${localRoots.join(", ")}] (set allowedRoots to permit it)`;
|
|
421
421
|
};
|
|
422
|
-
if (
|
|
422
|
+
if (options.rootDocument !== void 0) {
|
|
423
|
+
docCache.set(rootLocation, options.rootDocument);
|
|
424
|
+
} else if (!await loadDoc(rootLocation, docCache, options, errors, deadline, [])) {
|
|
423
425
|
return { resolved: {}, errors };
|
|
424
426
|
}
|
|
425
427
|
const registries = /* @__PURE__ */ new Map();
|
package/dist/types.d.ts
CHANGED
|
@@ -128,6 +128,23 @@ export type ResolveOptions = {
|
|
|
128
128
|
* ```
|
|
129
129
|
*/
|
|
130
130
|
parse?: (content: string, location: string) => unknown;
|
|
131
|
+
/**
|
|
132
|
+
* The root document's already-parsed content. When set, the file you named
|
|
133
|
+
* is neither read nor handed to `parse` — this value stands in for it — but
|
|
134
|
+
* its location still anchors everything else: relative `$ref`s resolve
|
|
135
|
+
* against it, the default `allowedRoots` is its folder, and `origins` name it.
|
|
136
|
+
*
|
|
137
|
+
* For callers that have parsed the root already (a linter, a code generator)
|
|
138
|
+
* and would otherwise pay to read and parse a large document twice. It is
|
|
139
|
+
* only read, never written, so the caller keeps ownership of the tree; the
|
|
140
|
+
* resolved result never shares an object with it.
|
|
141
|
+
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* const document = parseYaml(await readFile(path, 'utf8'))
|
|
144
|
+
* resolveRefsFromFile(path, { rootDocument: document, parse: parseYamlOrJson })
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
rootDocument?: unknown;
|
|
131
148
|
/**
|
|
132
149
|
* Record a per-node origin map on the result (`origins`). For every object or
|
|
133
150
|
* array inlined in place of a `$ref`, the map records the document and in-file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/resolve-refs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Resolve and inline JSON Schema / OpenAPI $refs — internal, cross-file, and remote — with session caching and a default-deny SSRF guard.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|