Skip to content

Commit 56241ad

Browse files
committed
fix(exports): export more types for usage in other libraries, fix some types
1 parent fb49854 commit 56241ad

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

lib/index.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ import maybe from "./util/maybe.js";
2121
import type { ParserOptions } from "./options.js";
2222
import type { $RefsCallback, JSONSchema, SchemaCallback } from "./types/index.js";
2323

24-
export { JSONParserError };
25-
export { InvalidPointerError };
26-
export { MissingPointerError };
27-
export { ResolverError };
28-
export { ParserError };
29-
export { UnmatchedParserError };
30-
export { UnmatchedResolverError };
31-
32-
type RefParserSchema = string | JSONSchema;
24+
export type RefParserSchema = string | JSONSchema;
3325

3426
/**
3527
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
@@ -76,7 +68,6 @@ export class $RefParser {
7668
options: ParserOptions,
7769
callback: SchemaCallback,
7870
): Promise<void>;
79-
8071
async parse() {
8172
const args = normalizeArgs(arguments as any);
8273
let promise;
@@ -418,3 +409,19 @@ export const parse = $RefParser.parse;
418409
export const resolve = $RefParser.resolve;
419410
export const bundle = $RefParser.bundle;
420411
export const dereference = $RefParser.dereference;
412+
413+
export {
414+
UnmatchedResolverError,
415+
JSONParserError,
416+
JSONSchema,
417+
InvalidPointerError,
418+
MissingPointerError,
419+
ResolverError,
420+
ParserError,
421+
UnmatchedParserError,
422+
ParserOptions,
423+
$RefsCallback,
424+
isHandledError,
425+
JSONParserErrorGroup,
426+
SchemaCallback,
427+
};

lib/normalize-args.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { getNewOptions } from "./options.js";
2+
import type { JSONSchema, SchemaCallback } from "./types";
3+
import type $RefParserOptions from "./options";
24

35
export default normalizeArgs;
46

7+
// I really dislike this function and the way it's written. It's not clear what it's doing, and it's way too flexible
8+
// In the future, I'd like to deprecate the api and accept only named parameters in index.ts
9+
export interface NormalizedArguments {
10+
path: string;
11+
schema: JSONSchema;
12+
options: $RefParserOptions;
13+
callback: SchemaCallback;
14+
}
515
/**
616
* Normalizes the given arguments, accounting for optional args.
717
*/
8-
function normalizeArgs(_args: Partial<IArguments>) {
18+
function normalizeArgs(_args: Partial<IArguments>): NormalizedArguments {
919
let path, schema, options, callback;
1020
const args = Array.prototype.slice.call(_args) as any[];
1121

lib/options.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import httpResolver from "./resolvers/http.js";
77

88
import type { HTTPResolverOptions, JSONSchemaObject, Plugin, ResolverOptions } from "./types/index.js";
99

10-
type DeepPartial<T> = T extends object
10+
export type DeepPartial<T> = T extends object
1111
? {
1212
[P in keyof T]?: DeepPartial<T[P]>;
1313
}
@@ -18,7 +18,7 @@ type DeepPartial<T> = T extends object
1818
* @param [options] - Overridden options
1919
* @class
2020
*/
21-
interface $RefParserOptions {
21+
export interface $RefParserOptions {
2222
/**
2323
* The `parse` options determine how different types of files will be parsed.
2424
*
@@ -101,7 +101,7 @@ interface $RefParserOptions {
101101
};
102102
}
103103

104-
const getDefaults = () => {
104+
export const getJsonSchemaRefParserDefaultOptions = () => {
105105
const defaults = {
106106
/**
107107
* Determines how different types of files will be parsed.
@@ -172,8 +172,8 @@ const getDefaults = () => {
172172
return defaults;
173173
};
174174

175-
export const getNewOptions = (options: DeepPartial<$RefParserOptions>): $RefParserOptions => {
176-
const newOptions = getDefaults();
175+
export const getNewOptions = (options: DeepPartial<$RefParserOptions> | undefined): $RefParserOptions => {
176+
const newOptions = getJsonSchemaRefParserDefaultOptions();
177177
if (options) {
178178
merge(newOptions, options);
179179
}

lib/types/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type $Refs from "../refs.js";
1010

1111
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
1212
export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
13-
export type SchemaCallback = (err: Error | null, schema?: JSONSchema | object) => any;
13+
export type SchemaCallback = (err: Error | null, schema?: JSONSchema | object | null) => any;
1414
export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
1515

1616
/**

0 commit comments

Comments
 (0)