@hey-api/json-schema-ref-parser 1.2.3 → 1.3.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 (92) hide show
  1. package/README.md +9 -84
  2. package/dist/index.d.mts +629 -0
  3. package/dist/index.d.mts.map +1 -0
  4. package/dist/index.mjs +1887 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +42 -78
  7. package/src/__tests__/bundle.test.ts +59 -0
  8. package/src/__tests__/index.test.ts +43 -0
  9. package/src/__tests__/pointer.test.ts +34 -0
  10. package/src/__tests__/utils.ts +3 -0
  11. package/{lib → src}/bundle.ts +143 -229
  12. package/{lib → src}/dereference.ts +20 -43
  13. package/{lib → src}/index.ts +103 -125
  14. package/{lib → src}/options.ts +13 -9
  15. package/{lib → src}/parse.ts +19 -15
  16. package/src/parsers/binary.ts +13 -0
  17. package/{lib → src}/parsers/json.ts +5 -6
  18. package/src/parsers/text.ts +21 -0
  19. package/{lib → src}/parsers/yaml.ts +9 -9
  20. package/{lib → src}/pointer.ts +42 -23
  21. package/{lib → src}/ref.ts +25 -21
  22. package/{lib → src}/refs.ts +23 -26
  23. package/{lib → src}/resolve-external.ts +91 -60
  24. package/{lib → src}/resolvers/file.ts +7 -10
  25. package/{lib → src}/resolvers/url.ts +12 -8
  26. package/{lib → src}/types/index.ts +9 -2
  27. package/src/util/convert-path-to-posix.ts +8 -0
  28. package/{lib → src}/util/errors.ts +38 -36
  29. package/{lib → src}/util/is-windows.ts +1 -1
  30. package/{lib → src}/util/plugins.ts +7 -8
  31. package/{lib → src}/util/url.ts +41 -42
  32. package/dist/lib/__tests__/bundle.test.d.ts +0 -1
  33. package/dist/lib/__tests__/bundle.test.js +0 -50
  34. package/dist/lib/__tests__/index.test.d.ts +0 -1
  35. package/dist/lib/__tests__/index.test.js +0 -43
  36. package/dist/lib/__tests__/pointer.test.d.ts +0 -1
  37. package/dist/lib/__tests__/pointer.test.js +0 -27
  38. package/dist/lib/bundle.d.ts +0 -26
  39. package/dist/lib/bundle.js +0 -600
  40. package/dist/lib/dereference.d.ts +0 -11
  41. package/dist/lib/dereference.js +0 -226
  42. package/dist/lib/index.d.ts +0 -92
  43. package/dist/lib/index.js +0 -525
  44. package/dist/lib/options.d.ts +0 -61
  45. package/dist/lib/options.js +0 -45
  46. package/dist/lib/parse.d.ts +0 -13
  47. package/dist/lib/parse.js +0 -87
  48. package/dist/lib/parsers/binary.d.ts +0 -2
  49. package/dist/lib/parsers/binary.js +0 -12
  50. package/dist/lib/parsers/json.d.ts +0 -2
  51. package/dist/lib/parsers/json.js +0 -38
  52. package/dist/lib/parsers/text.d.ts +0 -2
  53. package/dist/lib/parsers/text.js +0 -18
  54. package/dist/lib/parsers/yaml.d.ts +0 -2
  55. package/dist/lib/parsers/yaml.js +0 -28
  56. package/dist/lib/pointer.d.ts +0 -88
  57. package/dist/lib/pointer.js +0 -297
  58. package/dist/lib/ref.d.ts +0 -180
  59. package/dist/lib/ref.js +0 -226
  60. package/dist/lib/refs.d.ts +0 -127
  61. package/dist/lib/refs.js +0 -232
  62. package/dist/lib/resolve-external.d.ts +0 -13
  63. package/dist/lib/resolve-external.js +0 -151
  64. package/dist/lib/resolvers/file.d.ts +0 -6
  65. package/dist/lib/resolvers/file.js +0 -61
  66. package/dist/lib/resolvers/url.d.ts +0 -17
  67. package/dist/lib/resolvers/url.js +0 -62
  68. package/dist/lib/types/index.d.ts +0 -43
  69. package/dist/lib/types/index.js +0 -2
  70. package/dist/lib/util/convert-path-to-posix.d.ts +0 -1
  71. package/dist/lib/util/convert-path-to-posix.js +0 -14
  72. package/dist/lib/util/errors.d.ts +0 -56
  73. package/dist/lib/util/errors.js +0 -112
  74. package/dist/lib/util/is-windows.d.ts +0 -1
  75. package/dist/lib/util/is-windows.js +0 -6
  76. package/dist/lib/util/plugins.d.ts +0 -16
  77. package/dist/lib/util/plugins.js +0 -45
  78. package/dist/lib/util/url.d.ts +0 -79
  79. package/dist/lib/util/url.js +0 -285
  80. package/dist/vite.config.d.ts +0 -2
  81. package/dist/vite.config.js +0 -19
  82. package/lib/__tests__/bundle.test.ts +0 -52
  83. package/lib/__tests__/index.test.ts +0 -45
  84. package/lib/__tests__/pointer.test.ts +0 -26
  85. package/lib/__tests__/spec/circular-ref-with-description.json +0 -11
  86. package/lib/__tests__/spec/multiple-refs.json +0 -34
  87. package/lib/__tests__/spec/openapi-paths-ref.json +0 -46
  88. package/lib/__tests__/spec/path-parameter.json +0 -16
  89. package/lib/parsers/binary.ts +0 -13
  90. package/lib/parsers/text.ts +0 -21
  91. package/lib/util/convert-path-to-posix.ts +0 -11
  92. /package/{LICENSE → LICENSE.md} +0 -0
@@ -0,0 +1,629 @@
1
+ import { JSONSchema4, JSONSchema4Object, JSONSchema4Type, JSONSchema6, JSONSchema6Object, JSONSchema6Type, JSONSchema7, JSONSchema7Object, JSONSchema7Type } from "json-schema";
2
+
3
+ //#region src/types/index.d.ts
4
+ type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
5
+ type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
6
+ interface Plugin {
7
+ /**
8
+ * Can this parser be used to process this file?
9
+ */
10
+ canHandle: (file: FileInfo) => boolean;
11
+ /**
12
+ * This is where the real work of a parser happens. The `parse` method accepts the same file info object as the `canHandle` function, but rather than returning a boolean value, the `parse` method should return a JavaScript representation of the file contents. For our CSV parser, that is a two-dimensional array of lines and values. For your parser, it might be an object, a string, a custom class, or anything else.
13
+ *
14
+ * Unlike the `canHandle` function, the `parse` method can also be asynchronous. This might be important if your parser needs to retrieve data from a database or if it relies on an external HTTP service to return the parsed value. You can return your asynchronous value via a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or a Node.js-style error-first callback. Here are examples of both approaches:
15
+ */
16
+ handler: (file: FileInfo) => string | Buffer | JSONSchema | Promise<{
17
+ data: Buffer;
18
+ }> | Promise<string | Buffer | JSONSchema>;
19
+ name: 'binary' | 'file' | 'http' | 'json' | 'text' | 'yaml';
20
+ }
21
+ /**
22
+ * JSON Schema `$Ref` Parser supports plug-ins, such as resolvers and parsers. These plug-ins can have methods such as `canHandle()`, `read()`, `canHandle()`, and `parse()`. All of these methods accept the same object as their parameter: an object containing information about the file being read or parsed.
23
+ *
24
+ * The file info object currently only consists of a few properties, but it may grow in the future if plug-ins end up needing more information.
25
+ *
26
+ * See https://apitools.dev/json-schema-ref-parser/docs/plugins/file-info-object.html
27
+ */
28
+ interface FileInfo {
29
+ /**
30
+ * The raw file contents, in whatever form they were returned by the resolver that read the file.
31
+ */
32
+ data: string | Buffer;
33
+ /**
34
+ * The lowercase file extension, such as ".json", ".yaml", ".txt", etc.
35
+ */
36
+ extension: string;
37
+ /**
38
+ * The hash (URL fragment) of the file URL, including the # symbol. If the URL doesn't have a hash, then this will be an empty string.
39
+ */
40
+ hash: string;
41
+ /**
42
+ * The full URL of the file. This could be any type of URL, including "http://", "https://", "file://", "ftp://", "mongodb://", or even a local filesystem path (when running in Node.js).
43
+ */
44
+ url: string;
45
+ }
46
+ //#endregion
47
+ //#region src/options.d.ts
48
+ interface DereferenceOptions {
49
+ /**
50
+ * Determines whether circular `$ref` pointers are handled.
51
+ *
52
+ * If set to `false`, then a `ReferenceError` will be thrown if the schema contains any circular references.
53
+ *
54
+ * If set to `"ignore"`, then circular references will simply be ignored. No error will be thrown, but the `$Refs.circular` property will still be set to `true`.
55
+ */
56
+ circular?: boolean | 'ignore';
57
+ /**
58
+ * A function, called for each path, which can return true to stop this path and all
59
+ * subpaths from being dereferenced further. This is useful in schemas where some
60
+ * subpaths contain literal $ref keys that should not be dereferenced.
61
+ */
62
+ excludedPathMatcher?(path: string): boolean;
63
+ /**
64
+ * Callback invoked during dereferencing.
65
+ *
66
+ * @argument {string} path - The path being dereferenced (ie. the `$ref` string)
67
+ * @argument {JSONSchemaObject} value - The JSON-Schema that the `$ref` resolved to
68
+ * @argument {JSONSchemaObject} parent - The parent of the dereferenced object
69
+ * @argument {string} parentPropName - The prop name of the parent object whose value was dereferenced
70
+ */
71
+ onDereference?(path: string, value: JSONSchemaObject, parent?: JSONSchemaObject, parentPropName?: string): void;
72
+ }
73
+ /**
74
+ * Options that determine how JSON schemas are parsed, resolved, and dereferenced.
75
+ *
76
+ * @param [options] - Overridden options
77
+ * @class
78
+ */
79
+ interface $RefParserOptions {
80
+ /**
81
+ * The `dereference` options control how JSON Schema `$Ref` Parser will dereference `$ref` pointers within the JSON schema.
82
+ */
83
+ dereference: DereferenceOptions;
84
+ /**
85
+ * The `parse` options determine how different types of files will be parsed.
86
+ *
87
+ * JSON Schema `$Ref` Parser comes with built-in JSON, YAML, plain-text, and binary parsers, any of which you can configure or disable. You can also add your own custom parsers if you want.
88
+ */
89
+ parse: {
90
+ binary: Plugin;
91
+ json: Plugin;
92
+ text: Plugin;
93
+ yaml: Plugin;
94
+ };
95
+ /**
96
+ * The maximum amount of time (in milliseconds) that JSON Schema $Ref Parser will spend dereferencing a single schema.
97
+ * It will throw a timeout error if the operation takes longer than this.
98
+ */
99
+ timeoutMs?: number;
100
+ }
101
+ type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
102
+ type ParserOptions = DeepPartial<$RefParserOptions>;
103
+ //#endregion
104
+ //#region src/util/errors.d.ts
105
+ type JSONParserErrorType = 'EUNKNOWN' | 'EPARSER' | 'EUNMATCHEDPARSER' | 'ETIMEOUT' | 'ERESOLVER' | 'EUNMATCHEDRESOLVER' | 'EMISSINGPOINTER' | 'EINVALIDPOINTER';
106
+ declare class JSONParserError extends Error {
107
+ readonly name: string;
108
+ readonly message: string;
109
+ source: string | undefined;
110
+ path: Array<string | number> | null;
111
+ readonly code: JSONParserErrorType;
112
+ constructor(message: string, source?: string);
113
+ get footprint(): string;
114
+ }
115
+ declare class ParserError extends JSONParserError {
116
+ code: JSONParserErrorType;
117
+ name: string;
118
+ constructor(message: any, source: any);
119
+ }
120
+ declare class ResolverError extends JSONParserError {
121
+ code: JSONParserErrorType;
122
+ name: string;
123
+ ioErrorCode?: string;
124
+ constructor(ex: Error | any, source?: string);
125
+ }
126
+ declare class MissingPointerError extends JSONParserError {
127
+ code: JSONParserErrorType;
128
+ name: string;
129
+ constructor(token: string, path: string);
130
+ }
131
+ //#endregion
132
+ //#region src/ref.d.ts
133
+ type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
134
+ /**
135
+ * This class represents a single JSON reference and its resolved value.
136
+ *
137
+ * @class
138
+ */
139
+ declare class $Ref<S extends object = JSONSchema> {
140
+ /**
141
+ * The file path or URL of the referenced file.
142
+ * This path is relative to the path of the main JSON schema file.
143
+ *
144
+ * This path does NOT contain document fragments (JSON pointers). It always references an ENTIRE file.
145
+ * Use methods such as {@link $Ref#get}, {@link $Ref#resolve}, and {@link $Ref#exists} to get
146
+ * specific JSON pointers within the file.
147
+ *
148
+ * @type {string}
149
+ */
150
+ path: undefined | string;
151
+ /**
152
+ * The resolved value of the JSON reference.
153
+ * Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
154
+ *
155
+ * @type {?*}
156
+ */
157
+ value: any;
158
+ /**
159
+ * The {@link $Refs} object that contains this {@link $Ref} object.
160
+ *
161
+ * @type {$Refs}
162
+ */
163
+ $refs: $Refs<S>;
164
+ /**
165
+ * Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
166
+ */
167
+ pathType: string | unknown;
168
+ /**
169
+ * List of all errors. Undefined if no errors.
170
+ */
171
+ errors: Array<$RefError>;
172
+ constructor($refs: $Refs<S>);
173
+ /**
174
+ * Pushes an error to errors array.
175
+ *
176
+ * @param err - The error to be pushed
177
+ * @returns
178
+ */
179
+ addError(err: $RefError): void;
180
+ /**
181
+ * Determines whether the given JSON reference exists within this {@link $Ref#value}.
182
+ *
183
+ * @param path - The full path being resolved, optionally with a JSON pointer in the hash
184
+ * @param options
185
+ * @returns
186
+ */
187
+ exists(path: string, options?: ParserOptions): boolean;
188
+ /**
189
+ * Resolves the given JSON reference within this {@link $Ref#value} and returns the resolved value.
190
+ *
191
+ * @param path - The full path being resolved, optionally with a JSON pointer in the hash
192
+ * @param options
193
+ * @returns - Returns the resolved value
194
+ */
195
+ get(path: string, options?: ParserOptions): any;
196
+ /**
197
+ * Resolves the given JSON reference within this {@link $Ref#value}.
198
+ *
199
+ * @param path - The full path being resolved, optionally with a JSON pointer in the hash
200
+ * @param options
201
+ * @param friendlyPath - The original user-specified path (used for error messages)
202
+ * @param pathFromRoot - The path of `obj` from the schema root
203
+ * @returns
204
+ */
205
+ resolve(path: string, options?: ParserOptions, friendlyPath?: string, pathFromRoot?: string): Pointer<S>;
206
+ /**
207
+ * Sets the value of a nested property within this {@link $Ref#value}.
208
+ * If the property, or any of its parents don't exist, they will be created.
209
+ *
210
+ * @param path - The full path of the property to set, optionally with a JSON pointer in the hash
211
+ * @param value - The value to assign
212
+ */
213
+ set(path: string, value: any): void;
214
+ /**
215
+ * Determines whether the given value is a JSON reference.
216
+ *
217
+ * @param value - The value to inspect
218
+ * @returns
219
+ */
220
+ static is$Ref(value: unknown): value is {
221
+ $ref: string;
222
+ length?: number;
223
+ };
224
+ /**
225
+ * Determines whether the given value is an external JSON reference.
226
+ *
227
+ * @param value - The value to inspect
228
+ * @returns
229
+ */
230
+ static isExternal$Ref(value: unknown): boolean;
231
+ /**
232
+ * Determines whether the given value is a JSON reference, and whether it is allowed by the options.
233
+ *
234
+ * @param value - The value to inspect
235
+ * @param options
236
+ * @returns
237
+ */
238
+ static isAllowed$Ref(value: unknown): true | undefined;
239
+ /**
240
+ * Determines whether the given value is a JSON reference that "extends" its resolved value.
241
+ * That is, it has extra properties (in addition to "$ref"), so rather than simply pointing to
242
+ * an existing value, this $ref actually creates a NEW value that is a shallow copy of the resolved
243
+ * value, plus the extra properties.
244
+ *
245
+ * @example: {
246
+ person: {
247
+ properties: {
248
+ firstName: { type: string }
249
+ lastName: { type: string }
250
+ }
251
+ }
252
+ employee: {
253
+ properties: {
254
+ $ref: #/person/properties
255
+ salary: { type: number }
256
+ }
257
+ }
258
+ }
259
+ * In this example, "employee" is an extended $ref, since it extends "person" with an additional
260
+ * property (salary). The result is a NEW value that looks like this:
261
+ *
262
+ * {
263
+ * properties: {
264
+ * firstName: { type: string }
265
+ * lastName: { type: string }
266
+ * salary: { type: number }
267
+ * }
268
+ * }
269
+ *
270
+ * @param value - The value to inspect
271
+ * @returns
272
+ */
273
+ static isExtended$Ref(value: unknown): boolean;
274
+ /**
275
+ * Returns the resolved value of a JSON Reference.
276
+ * If necessary, the resolved value is merged with the JSON Reference to create a new object
277
+ *
278
+ * @example: {
279
+ person: {
280
+ properties: {
281
+ firstName: { type: string }
282
+ lastName: { type: string }
283
+ }
284
+ }
285
+ employee: {
286
+ properties: {
287
+ $ref: #/person/properties
288
+ salary: { type: number }
289
+ }
290
+ }
291
+ } When "person" and "employee" are merged, you end up with the following object:
292
+ *
293
+ * {
294
+ * properties: {
295
+ * firstName: { type: string }
296
+ * lastName: { type: string }
297
+ * salary: { type: number }
298
+ * }
299
+ * }
300
+ *
301
+ * @param $ref - The JSON reference object (the one with the "$ref" property)
302
+ * @param resolvedValue - The resolved value, which can be any type
303
+ * @returns - Returns the dereferenced value
304
+ */
305
+ static dereference<S extends object = JSONSchema>($ref: $Ref<S>, resolvedValue: S): S;
306
+ }
307
+ //#endregion
308
+ //#region src/pointer.d.ts
309
+ /**
310
+ * This class represents a single JSON pointer and its resolved value.
311
+ *
312
+ * @param $ref
313
+ * @param path
314
+ * @param [friendlyPath] - The original user-specified path (used for error messages)
315
+ * @class
316
+ */
317
+ declare class Pointer<S extends object = JSONSchema> {
318
+ /**
319
+ * The {@link $Ref} object that contains this {@link Pointer} object.
320
+ */
321
+ $ref: $Ref<S>;
322
+ /**
323
+ * The file path or URL, containing the JSON pointer in the hash.
324
+ * This path is relative to the path of the main JSON schema file.
325
+ */
326
+ path: string;
327
+ /**
328
+ * The original path or URL, used for error messages.
329
+ */
330
+ originalPath: string;
331
+ /**
332
+ * The value of the JSON pointer.
333
+ * Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
334
+ */
335
+ value: any;
336
+ /**
337
+ * Indicates whether the pointer references itself.
338
+ */
339
+ circular: boolean;
340
+ /**
341
+ * The number of indirect references that were traversed to resolve the value.
342
+ * Resolving a single pointer may require resolving multiple $Refs.
343
+ */
344
+ indirections: number;
345
+ constructor($ref: $Ref<S>, path: string, friendlyPath?: string);
346
+ /**
347
+ * Resolves the value of a nested property within the given object.
348
+ *
349
+ * @param obj - The object that will be crawled
350
+ * @param options
351
+ * @param pathFromRoot - the path of place that initiated resolving
352
+ *
353
+ * @returns
354
+ * Returns a JSON pointer whose {@link Pointer#value} is the resolved value.
355
+ * If resolving this value required resolving other JSON references, then
356
+ * the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
357
+ * of the resolved value.
358
+ */
359
+ resolve(obj: S, options?: ParserOptions, pathFromRoot?: string): this;
360
+ /**
361
+ * Sets the value of a nested property within the given object.
362
+ *
363
+ * @param obj - The object that will be crawled
364
+ * @param value - the value to assign
365
+ * @param options
366
+ *
367
+ * @returns
368
+ * Returns the modified object, or an entirely new object if the entire object is overwritten.
369
+ */
370
+ set(obj: S, value: any, options?: ParserOptions): any;
371
+ /**
372
+ * Parses a JSON pointer (or a path containing a JSON pointer in the hash)
373
+ * and returns an array of the pointer's tokens.
374
+ * (e.g. "schema.json#/definitions/person/name" => ["definitions", "person", "name"])
375
+ *
376
+ * The pointer is parsed according to RFC 6901
377
+ * {@link https://tools.ietf.org/html/rfc6901#section-3}
378
+ *
379
+ * @param path
380
+ * @param [originalPath]
381
+ * @returns
382
+ */
383
+ static parse(path: string, originalPath?: string): string[];
384
+ /**
385
+ * Creates a JSON pointer path, by joining one or more tokens to a base path.
386
+ *
387
+ * @param base - The base path (e.g. "schema.json#/definitions/person")
388
+ * @param tokens - The token(s) to append (e.g. ["name", "first"])
389
+ * @returns
390
+ */
391
+ static join(base: string, tokens: string | string[]): string;
392
+ }
393
+ //#endregion
394
+ //#region src/refs.d.ts
395
+ interface $RefsMap<S extends object = JSONSchema> {
396
+ [url: string]: $Ref<S>;
397
+ }
398
+ /**
399
+ * When you call the resolve method, the value that gets passed to the callback function (or Promise) is a $Refs object. This same object is accessible via the parser.$refs property of $RefParser objects.
400
+ *
401
+ * This object is a map of JSON References and their resolved values. It also has several convenient helper methods that make it easy for you to navigate and manipulate the JSON References.
402
+ *
403
+ * See https://apitools.dev/json-schema-ref-parser/docs/refs.html
404
+ */
405
+ declare class $Refs<S extends object = JSONSchema> {
406
+ /**
407
+ * This property is true if the schema contains any circular references. You may want to check this property before serializing the dereferenced schema as JSON, since JSON.stringify() does not support circular references by default.
408
+ *
409
+ * See https://apitools.dev/json-schema-ref-parser/docs/refs.html#circular
410
+ */
411
+ circular: boolean;
412
+ /**
413
+ * Returns the paths/URLs of all the files in your schema (including the main schema file).
414
+ *
415
+ * See https://apitools.dev/json-schema-ref-parser/docs/refs.html#pathstypes
416
+ *
417
+ * @param types (optional) Optionally only return certain types of paths ("file", "http", etc.)
418
+ */
419
+ paths(...types: (string | string[])[]): string[];
420
+ /**
421
+ * Returns a map of paths/URLs and their correspond values.
422
+ *
423
+ * See https://apitools.dev/json-schema-ref-parser/docs/refs.html#valuestypes
424
+ *
425
+ * @param types (optional) Optionally only return values from certain locations ("file", "http", etc.)
426
+ */
427
+ values(...types: (string | string[])[]): S;
428
+ /**
429
+ * Returns `true` if the given path exists in the schema; otherwise, returns `false`
430
+ *
431
+ * See https://apitools.dev/json-schema-ref-parser/docs/refs.html#existsref
432
+ *
433
+ * @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
434
+ */
435
+ /**
436
+ * Determines whether the given JSON reference exists.
437
+ *
438
+ * @param path - The path being resolved, optionally with a JSON pointer in the hash
439
+ * @param [options]
440
+ * @returns
441
+ */
442
+ exists(path: string, options: any): boolean;
443
+ /**
444
+ * Resolves the given JSON reference and returns the resolved value.
445
+ *
446
+ * @param path - The path being resolved, with a JSON pointer in the hash
447
+ * @param [options]
448
+ * @returns - Returns the resolved value
449
+ */
450
+ get(path: string, options?: ParserOptions): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type;
451
+ /**
452
+ * Sets the value at the given path in the schema. If the property, or any of its parents, don't exist, they will be created.
453
+ *
454
+ * @param path The JSON Reference path, optionally with a JSON Pointer in the hash
455
+ * @param value The value to assign. Can be anything (object, string, number, etc.)
456
+ */
457
+ set(path: string, value: JSONSchema4Type | JSONSchema6Type | JSONSchema7Type): void;
458
+ /**
459
+ * Returns the specified {@link $Ref} object, or undefined.
460
+ *
461
+ * @param path - The path being resolved, optionally with a JSON pointer in the hash
462
+ * @returns
463
+ * @protected
464
+ */
465
+ _get$Ref(path: string): $Ref<S> | undefined;
466
+ /**
467
+ * Creates a new {@link $Ref} object and adds it to this {@link $Refs} object.
468
+ *
469
+ * @param path - The file path or URL of the referenced file
470
+ */
471
+ _add(path: string): $Ref<S>;
472
+ /**
473
+ * Resolves the given JSON reference.
474
+ *
475
+ * @param path - The path being resolved, optionally with a JSON pointer in the hash
476
+ * @param pathFromRoot - The path of `obj` from the schema root
477
+ * @param [options]
478
+ * @returns
479
+ * @protected
480
+ */
481
+ _resolve(path: string, pathFromRoot: string, options?: ParserOptions): Pointer<S> | null;
482
+ /**
483
+ * A map of paths/urls to {@link $Ref} objects
484
+ *
485
+ * @type {object}
486
+ * @protected
487
+ */
488
+ _$refs: $RefsMap<S>;
489
+ /**
490
+ * The {@link $Ref} object that is the root of the JSON schema.
491
+ *
492
+ * @type {$Ref}
493
+ * @protected
494
+ */
495
+ _root$Ref: $Ref<S>;
496
+ constructor();
497
+ /**
498
+ * Returns the paths of all the files/URLs that are referenced by the JSON schema,
499
+ * including the schema itself.
500
+ *
501
+ * @param [types] - Only return paths of the given types ("file", "http", etc.)
502
+ * @returns
503
+ */
504
+ /**
505
+ * Returns the map of JSON references and their resolved values.
506
+ *
507
+ * @param [types] - Only return references of the given types ("file", "http", etc.)
508
+ * @returns
509
+ */
510
+ /**
511
+ * Returns a POJO (plain old JavaScript object) for serialization as JSON.
512
+ *
513
+ * @returns {object}
514
+ */
515
+ toJSON: (...types: (string | string[])[]) => S;
516
+ }
517
+ //#endregion
518
+ //#region src/resolvers/url.d.ts
519
+ declare const sendRequest: ({
520
+ fetchOptions,
521
+ redirects,
522
+ timeout,
523
+ url
524
+ }: {
525
+ fetchOptions?: RequestInit;
526
+ redirects?: string[];
527
+ timeout?: number;
528
+ url: URL | string;
529
+ }) => Promise<{
530
+ fetchOptions?: RequestInit;
531
+ response: Response;
532
+ }>;
533
+ //#endregion
534
+ //#region src/index.d.ts
535
+ interface ResolvedInput {
536
+ path: string;
537
+ schema: string | JSONSchema | Buffer | Awaited<JSONSchema> | undefined;
538
+ type: 'file' | 'json' | 'url';
539
+ }
540
+ declare function getResolvedInput({
541
+ pathOrUrlOrSchema
542
+ }: {
543
+ pathOrUrlOrSchema: JSONSchema | string | unknown;
544
+ }): ResolvedInput;
545
+ /**
546
+ * This class parses a JSON schema, builds a map of its JSON references and their resolved values,
547
+ * and provides methods for traversing, manipulating, and dereferencing those references.
548
+ */
549
+ declare class $RefParser {
550
+ /**
551
+ * The resolved JSON references
552
+ *
553
+ * @type {$Refs}
554
+ * @readonly
555
+ */
556
+ $refs: $Refs<JSONSchema>;
557
+ options: $RefParserOptions;
558
+ /**
559
+ * The parsed (and possibly dereferenced) JSON schema object
560
+ *
561
+ * @type {object}
562
+ * @readonly
563
+ */
564
+ schema: JSONSchema | null;
565
+ schemaMany: JSONSchema[];
566
+ schemaManySources: string[];
567
+ sourcePathToPrefix: Map<string, string>;
568
+ /**
569
+ * Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
570
+ *
571
+ * This also eliminates the risk of circular references, so the schema can be safely serialized using `JSON.stringify()`.
572
+ *
573
+ * See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#bundleschema-options-callback
574
+ *
575
+ * @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
576
+ */
577
+ bundle({
578
+ arrayBuffer,
579
+ fetch,
580
+ pathOrUrlOrSchema,
581
+ resolvedInput
582
+ }: {
583
+ arrayBuffer?: ArrayBuffer;
584
+ fetch?: RequestInit;
585
+ pathOrUrlOrSchema: JSONSchema | string | unknown;
586
+ resolvedInput?: ResolvedInput;
587
+ }): Promise<JSONSchema>;
588
+ /**
589
+ * Bundles multiple roots (files/URLs/objects) into a single schema by creating a synthetic root
590
+ * that references each input, resolving all externals, and then hoisting via the existing bundler.
591
+ */
592
+ bundleMany({
593
+ arrayBuffer,
594
+ fetch,
595
+ pathOrUrlOrSchemas,
596
+ resolvedInputs
597
+ }: {
598
+ arrayBuffer?: ArrayBuffer[];
599
+ fetch?: RequestInit;
600
+ pathOrUrlOrSchemas: Array<JSONSchema | string | unknown>;
601
+ resolvedInputs?: ResolvedInput[];
602
+ }): Promise<JSONSchema>;
603
+ /**
604
+ * Parses the given JSON schema.
605
+ * This method does not resolve any JSON references.
606
+ * It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
607
+ *
608
+ * @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
609
+ * @returns - The returned promise resolves with the parsed JSON schema object.
610
+ */
611
+ parse({
612
+ arrayBuffer,
613
+ fetch,
614
+ pathOrUrlOrSchema,
615
+ resolvedInput: _resolvedInput
616
+ }: {
617
+ arrayBuffer?: ArrayBuffer;
618
+ fetch?: RequestInit;
619
+ pathOrUrlOrSchema: JSONSchema | string | unknown;
620
+ resolvedInput?: ResolvedInput;
621
+ }): Promise<{
622
+ schema: JSONSchema;
623
+ }>;
624
+ private parseMany;
625
+ mergeMany(): JSONSchema;
626
+ }
627
+ //#endregion
628
+ export { $RefParser, type JSONSchema, getResolvedInput, sendRequest };
629
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/index.ts","../src/options.ts","../src/util/errors.ts","../src/ref.ts","../src/pointer.ts","../src/refs.ts","../src/resolvers/url.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;KASY,UAAA,GAAa,cAAc,cAAc;KACzC,gBAAA,GAAmB,oBAAoB,oBAAoB;AAD3D,UAGK,MAAA,CAHK;EAAG;;;EAAuC,SAAA,EAAA,CAAA,IAAA,EAO5C,QAP4C,EAAA,GAAA,OAAA;EACpD;;;;;EAEK,OAAA,EAAM,CAAA,IAAA,EAWb,QAXa,EAAA,GAAA,MAAA,GAcjB,MAdiB,GAejB,UAfiB,GAgBjB,OAhBiB,CAAA;IAIH,IAAA,EAYE,MAZF;EAOV,CAAA,CAAA,GAMJ,OANI,CAAA,MAAA,GAMa,MANb,GAMsB,UANtB,CAAA;EAGJ,IAAA,EAAA,QAAA,GAAA,MAAA,GAAA,MAAA,GAAA,MAAA,GAAA,MAAA,GAAA,MAAA;;;;;;;;AAcN;UAAiB,QAAA;;;AClCjB;EAqCiB,IAAA,EAAA,MAAA,GDCA,MCDiB;EAInB;;;EASL,SAAA,EAAA,MAAA;EACA;;AA+C8B;EAElB,IAAA,EAAA,MAAA;EAEJ;;;EAAK,GAAA,EAAA,MAAA;;;;UAtGN,kBAAA;;ADGjB;;;;;AACA;EAA+B,QAAA,CAAA,EAAA,OAAA,GAAA,QAAA;EAAoB;;;AAEnD;;EAWU,mBAAA,EAAA,IAAA,EAAA,MAAA,CAAA,EAAA,OAAA;EAGJ;;;;;;;;EAcW,aAAQ,EAAA,IAAA,EAAA,MAIR,EAAA,KAAM,ECbZ,gBDaY,EAAA,MAAA,CAAA,ECZV,gBDYU,EAAA,cAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;;;ACtCvB;AAqCA;;;AAYU,UAZO,iBAAA,CAYP;EACA;;;EAkDL,WAAA,EA3DU,kBA2DC;EAAM;;;;;EAIlB,KAAA,EAAA;IAA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