@amritk/resolve-refs 0.2.0 → 0.2.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/src/types.ts DELETED
@@ -1,88 +0,0 @@
1
- /**
2
- * A path into a JSON document: object keys and array indices, in order. Errors
3
- * report the location of the offending `$ref` with one of these.
4
- */
5
- export type JsonPath = (string | number)[]
6
-
7
- /** A single `$ref` resolution failure (a missing file, a bad URL, a refusal). */
8
- export type ResolveError = {
9
- message: string
10
- path: JsonPath
11
- }
12
-
13
- /**
14
- * Where an inlined node came from: the absolute location (file path or URL, or
15
- * `''` for the single in-memory document) of the document it was defined in, and
16
- * the path to it within that document.
17
- */
18
- export type Origin = {
19
- location: string
20
- pointer: JsonPath
21
- }
22
-
23
- /**
24
- * Per-node origin map produced when `trackOrigins` is set: maps each object/array
25
- * that was inlined in place of a `$ref` to where it was defined. A consumer can
26
- * then attribute a node in the resolved tree back to its source document and path
27
- * with a single lookup instead of re-deriving the `$ref` traversal. Keyed by node
28
- * identity, so it relies on the resolver sharing one object per repeated `$ref`
29
- * target (which it does).
30
- */
31
- export type OriginMap = Map<object, Origin>
32
-
33
- /** The outcome of a resolve pass: the dereferenced document plus any errors. */
34
- export type ResolveResult = {
35
- /** The dereferenced document (all resolvable `$ref`s inlined). */
36
- resolved: unknown
37
- errors: ResolveError[]
38
- /**
39
- * Per-node origin map. Present only when `trackOrigins` was requested; each
40
- * entry maps an inlined object/array to the document and path it came from.
41
- */
42
- origins?: OriginMap
43
- }
44
-
45
- /** Controls how external `$ref`s to other documents are loaded. */
46
- export type ResolveOptions = {
47
- /**
48
- * Whether http(s) `$ref`s may be fetched. Defaults to `true`.
49
- */
50
- remote?: boolean
51
- /**
52
- * If non-empty, only these hosts (e.g. `api.example.com`) may be fetched for
53
- * remote `$ref`s. An empty/undefined list allows any host (subject to
54
- * `remote`). An explicit entry here always bypasses the private-host guard.
55
- */
56
- allowedHosts?: string[]
57
- /**
58
- * Allow remote `$ref`s to loopback, private, link-local, and other
59
- * non-public addresses. Defaults to `false`: such hosts are refused as a
60
- * best-effort SSRF guard (notably the `169.254.169.254` cloud-metadata
61
- * endpoint). An explicit `allowedHosts` entry always bypasses this guard.
62
- */
63
- allowPrivateHosts?: boolean
64
- /**
65
- * Custom content parser. Receives the raw text of every loaded document and
66
- * its absolute location (file path or URL). Defaults to `JSON.parse`.
67
- *
68
- * Pass a YAML-aware function to support `.yaml`/`.yml` documents without
69
- * adding a dependency to this package:
70
- *
71
- * ```ts
72
- * import { parse as parseYaml } from 'yaml'
73
- *
74
- * resolveRefsFromFile(path, {
75
- * parse: (content, location) =>
76
- * /\.ya?ml$/i.test(location) ? parseYaml(content) : JSON.parse(content),
77
- * })
78
- * ```
79
- */
80
- parse?: (content: string, location: string) => unknown
81
- /**
82
- * Record a per-node origin map on the result (`origins`). For every object or
83
- * array inlined in place of a `$ref`, the map records the document and in-file
84
- * path it was defined at, so a consumer can attribute resolved-tree nodes back
85
- * to their source without re-walking the `$ref` chain. Defaults to `false`.
86
- */
87
- trackOrigins?: boolean
88
- }