@tsofist/schema-forge 3.0.0-next.1 → 3.1.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/lib/dbml-generator/generator.spec.js +1 -1
- package/lib/definition-info/traversal.d.ts +1 -0
- package/lib/definition-info/traversal.d.ts.map +1 -0
- package/lib/definition-info/traversal.js +1 -0
- package/lib/schema-dereference/cache.d.ts +15 -0
- package/lib/schema-dereference/cache.d.ts.map +1 -0
- package/lib/schema-dereference/cache.js +22 -0
- package/lib/schema-dereference/dereference.d.ts +9 -0
- package/lib/schema-dereference/dereference.d.ts.map +1 -0
- package/lib/schema-dereference/dereference.js +88 -0
- package/lib/schema-dereference/dereference.spec.d.ts +2 -0
- package/lib/schema-dereference/dereference.spec.d.ts.map +1 -0
- package/lib/schema-dereference/dereference.spec.js +83 -0
- package/lib/schema-dereference/types.d.ts +34 -0
- package/lib/schema-dereference/types.d.ts.map +1 -0
- package/lib/schema-dereference/types.js +2 -0
- package/lib/schema-registry/loader.d.ts +3 -3
- package/lib/schema-registry/loader.d.ts.map +1 -1
- package/lib/schema-registry/registry.d.ts +2 -19
- package/lib/schema-registry/registry.d.ts.map +1 -1
- package/lib/schema-registry/types.d.ts +19 -3
- package/lib/schema-registry/types.d.ts.map +1 -1
- package/package.json +3 -1
|
@@ -28,7 +28,7 @@ describe('DBML Generator', () => {
|
|
|
28
28
|
registry = (0, registry_1.createSchemaForgeRegistry)();
|
|
29
29
|
const schema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
|
|
30
30
|
registry.addSchema(schema);
|
|
31
|
-
}
|
|
31
|
+
});
|
|
32
32
|
afterAll(async () => {
|
|
33
33
|
if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
|
|
34
34
|
await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=traversal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traversal.d.ts","sourceRoot":"","sources":["../../src/definition-info/traversal.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
export type SchemaDereferenceSharedCache = ReturnType<typeof createSchemaDereferenceSharedCache>;
|
|
3
|
+
export declare function createSchemaDereferenceSharedCache(): {
|
|
4
|
+
readonly main: Map<JSONSchema7, JSONSchema7 | undefined>;
|
|
5
|
+
readonly resolver: Map<JSONSchema7, Map<string, JSONSchema7 | undefined>>;
|
|
6
|
+
readonly size: number;
|
|
7
|
+
readonly clear: () => number;
|
|
8
|
+
};
|
|
9
|
+
export declare const DefaultSchemaDereferenceSharedCache: {
|
|
10
|
+
readonly main: Map<JSONSchema7, JSONSchema7 | undefined>;
|
|
11
|
+
readonly resolver: Map<JSONSchema7, Map<string, JSONSchema7 | undefined>>;
|
|
12
|
+
readonly size: number;
|
|
13
|
+
readonly clear: () => number;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,4BAA4B,GAAG,UAAU,CAAC,OAAO,kCAAkC,CAAC,CAAC;AAEjG,wBAAgB,kCAAkC;;;;;EAiBjD;AAED,eAAO,MAAM,mCAAmC;;;;;CAAuC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultSchemaDereferenceSharedCache = void 0;
|
|
4
|
+
exports.createSchemaDereferenceSharedCache = createSchemaDereferenceSharedCache;
|
|
5
|
+
function createSchemaDereferenceSharedCache() {
|
|
6
|
+
const main = new Map();
|
|
7
|
+
const resolver = new Map();
|
|
8
|
+
return {
|
|
9
|
+
main,
|
|
10
|
+
resolver,
|
|
11
|
+
get size() {
|
|
12
|
+
return main.size + resolver.size;
|
|
13
|
+
},
|
|
14
|
+
clear() {
|
|
15
|
+
const size = this.size;
|
|
16
|
+
main.clear();
|
|
17
|
+
resolver.clear();
|
|
18
|
+
return size;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.DefaultSchemaDereferenceSharedCache = createSchemaDereferenceSharedCache();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import type { SchemaForgeDereferenceOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Dereference a JSON Schema by resolving all (relative) `$ref` pointers.
|
|
5
|
+
*
|
|
6
|
+
* @returns new schema with no `$ref` pointers
|
|
7
|
+
*/
|
|
8
|
+
export declare function dereferenceSchema(schema: JSONSchema7, options?: SchemaForgeDereferenceOptions): JSONSchema7 | undefined;
|
|
9
|
+
//# sourceMappingURL=dereference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dereference.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/dereference.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,6BAA6B,GACxC,WAAW,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dereferenceSchema = dereferenceSchema;
|
|
4
|
+
const error_1 = require("@tsofist/stem/lib/error");
|
|
5
|
+
const structuredCloneModule = require("@ungap/structured-clone");
|
|
6
|
+
const cache_1 = require("./cache");
|
|
7
|
+
function dereferenceSchema(raw, options = {}) {
|
|
8
|
+
const cache = options.sharedCacheStorage || cache_1.DefaultSchemaDereferenceSharedCache;
|
|
9
|
+
if (cache.main.has(raw))
|
|
10
|
+
return cache.main.get(raw);
|
|
11
|
+
const schema = structuredClone(raw);
|
|
12
|
+
const seen = new WeakMap();
|
|
13
|
+
const { throwOnDereferenceFailure = true, onDereferenceFailure } = options;
|
|
14
|
+
function resolve(current, path) {
|
|
15
|
+
if (current === undefined || typeof current !== 'object')
|
|
16
|
+
return current;
|
|
17
|
+
// Circular
|
|
18
|
+
if (seen.has(current))
|
|
19
|
+
return seen.get(current);
|
|
20
|
+
// Arrays
|
|
21
|
+
if (Array.isArray(current)) {
|
|
22
|
+
const arr = current.map((item, i) => resolve(item, `${path}/${i}`));
|
|
23
|
+
seen.set(current, arr);
|
|
24
|
+
return arr;
|
|
25
|
+
}
|
|
26
|
+
// $ref
|
|
27
|
+
if ('$ref' in current && typeof current.$ref === 'string') {
|
|
28
|
+
const ref = resolveRef(cache, schema, current.$ref);
|
|
29
|
+
if (ref == null) {
|
|
30
|
+
const replacement = onDereferenceFailure && !throwOnDereferenceFailure
|
|
31
|
+
? onDereferenceFailure(current.$ref, current, schema)
|
|
32
|
+
: undefined;
|
|
33
|
+
if (throwOnDereferenceFailure) {
|
|
34
|
+
(0, error_1.raise)(`Failed to dereference schema: unresolved reference ${current.$ref} at ${path}`);
|
|
35
|
+
}
|
|
36
|
+
else if (!onDereferenceFailure && options.throwOnDereferenceFailure == null) {
|
|
37
|
+
console.warn(`WARNING: Reference ${current.$ref} at ${path} cannot be resolved`);
|
|
38
|
+
}
|
|
39
|
+
return replacement;
|
|
40
|
+
}
|
|
41
|
+
if (seen.has(ref))
|
|
42
|
+
return seen.get(ref);
|
|
43
|
+
if (Array.isArray(ref)) {
|
|
44
|
+
const resolvedArray = resolve(ref, current.$ref);
|
|
45
|
+
seen.set(ref, resolvedArray);
|
|
46
|
+
return resolvedArray;
|
|
47
|
+
}
|
|
48
|
+
const placeholder = {};
|
|
49
|
+
seen.set(current, placeholder);
|
|
50
|
+
const resolved = resolve(ref, current.$ref);
|
|
51
|
+
Object.assign(placeholder, resolved);
|
|
52
|
+
return resolved;
|
|
53
|
+
}
|
|
54
|
+
// Objects
|
|
55
|
+
const obj = Object.fromEntries(Object.entries(current).map(([key, value]) => [
|
|
56
|
+
key,
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
58
|
+
resolve(value, `${path}/${key}`),
|
|
59
|
+
]));
|
|
60
|
+
seen.set(current, obj);
|
|
61
|
+
return obj;
|
|
62
|
+
}
|
|
63
|
+
const result = resolve(schema, '#');
|
|
64
|
+
cache.main.set(raw, result);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function resolveRef(cache, schema, ref) {
|
|
68
|
+
if (!cache.resolver.has(schema))
|
|
69
|
+
cache.resolver.set(schema, new Map());
|
|
70
|
+
const schemaCache = cache.resolver.get(schema);
|
|
71
|
+
if (schemaCache.has(ref))
|
|
72
|
+
return schemaCache.get(ref);
|
|
73
|
+
const pathParts = ref.split('/').slice(1);
|
|
74
|
+
let current = schema;
|
|
75
|
+
for (const segment of pathParts) {
|
|
76
|
+
if (current === undefined || typeof current !== 'object') {
|
|
77
|
+
current = undefined;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
current = current[segment] ?? undefined;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
schemaCache.set(ref, current);
|
|
84
|
+
return current;
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
87
|
+
// @ts-expect-error CommonJS module fix
|
|
88
|
+
const structuredClone = structuredCloneModule.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dereference.spec.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/dereference.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cache_1 = require("./cache");
|
|
4
|
+
const dereference_1 = require("./dereference");
|
|
5
|
+
describe('schema-dereference', () => {
|
|
6
|
+
beforeAll(() => {
|
|
7
|
+
cache_1.DefaultSchemaDereferenceSharedCache.clear();
|
|
8
|
+
});
|
|
9
|
+
it('should resolve schema references correctly (using definitions)', () => {
|
|
10
|
+
const schema = {
|
|
11
|
+
$id: 'https://example.com/schema.json',
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: { user: { $ref: '#/definitions/User' } },
|
|
14
|
+
definitions: {
|
|
15
|
+
User: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: { id: { type: 'string' }, name: { type: 'string' } },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const dereferenced = (0, dereference_1.dereferenceSchema)(schema);
|
|
22
|
+
expect(dereferenced).toStrictEqual({
|
|
23
|
+
...schema,
|
|
24
|
+
properties: { user: schema.definitions.User },
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('should resolve schema references correctly (using $defs)', () => {
|
|
28
|
+
const schema = {
|
|
29
|
+
$id: 'https://example.com/schema.json',
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: { user: { $ref: '#/$defs/User' } },
|
|
32
|
+
$defs: {
|
|
33
|
+
User: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: { id: { type: 'string' }, name: { type: 'string' } },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
const dereferenced = (0, dereference_1.dereferenceSchema)(schema);
|
|
40
|
+
expect(dereferenced).toStrictEqual({
|
|
41
|
+
...schema,
|
|
42
|
+
properties: { user: schema.$defs.User },
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('should handle circular references', () => {
|
|
46
|
+
const schema = {
|
|
47
|
+
$id: 'https://example.com/circular-schema.json',
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: {
|
|
50
|
+
self: { $ref: '#' },
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const dereferenced = (0, dereference_1.dereferenceSchema)(schema);
|
|
54
|
+
expect(dereferenced).toStrictEqual({
|
|
55
|
+
...schema,
|
|
56
|
+
properties: {
|
|
57
|
+
self: dereferenced,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it('should return undefined for unresolved references', () => {
|
|
62
|
+
const schema = {
|
|
63
|
+
$id: 'https://example.com/unresolved-schema.json',
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
missing: { $ref: '#/definitions/Missing' },
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
const dereferenced = (0, dereference_1.dereferenceSchema)(schema, {
|
|
70
|
+
throwOnDereferenceFailure: false,
|
|
71
|
+
});
|
|
72
|
+
expect(dereferenced).toStrictEqual({
|
|
73
|
+
...schema,
|
|
74
|
+
properties: {
|
|
75
|
+
missing: undefined,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it('shared cache should be used', () => {
|
|
80
|
+
expect(cache_1.DefaultSchemaDereferenceSharedCache.clear()).toBeGreaterThan(0);
|
|
81
|
+
expect(cache_1.DefaultSchemaDereferenceSharedCache.size).toStrictEqual(0);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import type { SchemaDereferenceSharedCache } from './cache';
|
|
3
|
+
export interface SchemaForgeDereferenceOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Handler called when dereferencing fails.
|
|
6
|
+
*
|
|
7
|
+
* @see throwOnDereferenceFailure
|
|
8
|
+
* @returns the value of the node where dereferencing failed
|
|
9
|
+
* @default undefined
|
|
10
|
+
*/
|
|
11
|
+
onDereferenceFailure?: SchemaForgeDereferenceFailureHandler;
|
|
12
|
+
/**
|
|
13
|
+
* Defines the behavior when dereferencing fails.
|
|
14
|
+
* Possible options:
|
|
15
|
+
* * true - an exception will be thrown;
|
|
16
|
+
* * false - the value of the node where dereferencing failed will be set to undefined;
|
|
17
|
+
* * undefined - if onDereferenceFailure is not set (or it returns undefined), an exception will be thrown;
|
|
18
|
+
*
|
|
19
|
+
* @see onDereferenceFailure
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
throwOnDereferenceFailure?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Use a shared cache to store intermediate dereferencing results.
|
|
25
|
+
* This can significantly speed up the process if the schema contains many repeated references.
|
|
26
|
+
*
|
|
27
|
+
* @see DefaultSchemaDereferenceSharedCache
|
|
28
|
+
* @see createSchemaDereferenceSharedCache
|
|
29
|
+
* @default DefaultSchemaDereferenceSharedCache
|
|
30
|
+
*/
|
|
31
|
+
sharedCacheStorage?: SchemaDereferenceSharedCache;
|
|
32
|
+
}
|
|
33
|
+
export type SchemaForgeDereferenceFailureHandler = (unresolvedRef: string, currentNode: JSONSchema7, resultSchema: JSONSchema7) => JSONSchema7 | undefined;
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,WAAW,6BAA6B;IAC1C;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,oCAAoC,CAAC;IAC5D;;;;;;;;;OASG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,4BAA4B,CAAC;CACrD;AAED,MAAM,MAAM,oCAAoC,GAAG,CAC/C,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,WAAW,KACxB,WAAW,GAAG,SAAS,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
2
|
/**
|
|
3
3
|
* Load JSON schema files
|
|
4
4
|
*/
|
|
5
|
-
export declare function loadJSONSchema(files: string[]): Promise<
|
|
5
|
+
export declare function loadJSONSchema(files: string[]): Promise<JSONSchema7[]>;
|
|
6
6
|
/**
|
|
7
7
|
* Load JSON schema files synchronously
|
|
8
8
|
*/
|
|
9
|
-
export declare function loadJSONSchemaSync(files: string[]):
|
|
9
|
+
export declare function loadJSONSchemaSync(files: string[]): JSONSchema7[];
|
|
10
10
|
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/schema-registry/loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/schema-registry/loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAO5E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,CAKjE"}
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SchemaForgeRegistry } from './types';
|
|
3
|
-
interface SFROptions {
|
|
4
|
-
/**
|
|
5
|
-
* Extra ajv options
|
|
6
|
-
*
|
|
7
|
-
* @see https://ajv.js.org/options.html Options reference
|
|
8
|
-
* @see https://ajv.js.org/json-schema.html Schema reference
|
|
9
|
-
*/
|
|
10
|
-
engine?: AjvOptions;
|
|
11
|
-
/**
|
|
12
|
-
* Use additional formats via ajv-formats
|
|
13
|
-
*
|
|
14
|
-
* @see https://ajv.js.org/packages/ajv-formats.html ajv-formats
|
|
15
|
-
*/
|
|
16
|
-
extendedVocabulary?: boolean;
|
|
17
|
-
}
|
|
1
|
+
import { SchemaForgeRegistry, SchemaForgeRegistryOptions } from './types';
|
|
18
2
|
/**
|
|
19
3
|
* Create JSON schema data validation registry
|
|
20
4
|
*
|
|
21
5
|
* @see https://ajv.js.org/json-schema.html ajv
|
|
22
6
|
*/
|
|
23
|
-
export declare function createSchemaForgeRegistry(options?:
|
|
24
|
-
export {};
|
|
7
|
+
export declare function createSchemaForgeRegistry(options?: SchemaForgeRegistryOptions): SchemaForgeRegistry;
|
|
25
8
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/schema-registry/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/schema-registry/registry.ts"],"names":[],"mappings":"AA6BA,OAAO,EACH,mBAAmB,EAEnB,0BAA0B,EAC7B,MAAM,SAAS,CAAC;AAsBjB;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,OAAO,CAAC,EAAE,0BAA0B,GACrC,mBAAmB,CAkOrB"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ArrayMay, Nullable } from '@tsofist/stem';
|
|
2
2
|
import type { NonNegativeInt } from '@tsofist/stem/lib/number/integer/types';
|
|
3
3
|
import type { ErrorsTextOptions, Options } from 'ajv';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Options as AjvOptions } from 'ajv/dist/core';
|
|
5
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
5
6
|
import type { SchemaDefinitionInfo } from '../definition-info/types';
|
|
6
7
|
import type { SchemaForgeValidationContextBase } from '../efc';
|
|
7
8
|
import type { SchemaForgeDefinitionRef, SchemaForgeValidationFunction, SchemaForgeValidationReport, SchemaForgeValidationResult } from '../types';
|
|
@@ -19,7 +20,7 @@ export interface SchemaForgeRegistry {
|
|
|
19
20
|
/**
|
|
20
21
|
* Clone schemaRegistry with overridden options
|
|
21
22
|
*/
|
|
22
|
-
clone: (options?: Omit<Options, 'schemas'>, onSchema?: (schema:
|
|
23
|
+
clone: (options?: Omit<Options, 'schemas'>, onSchema?: (schema: JSONSchema7) => JSONSchema7) => SchemaForgeRegistry;
|
|
23
24
|
/**
|
|
24
25
|
* Remove all schemas from registry
|
|
25
26
|
*/
|
|
@@ -27,7 +28,7 @@ export interface SchemaForgeRegistry {
|
|
|
27
28
|
/**
|
|
28
29
|
* Add root schema's to registry
|
|
29
30
|
*/
|
|
30
|
-
addSchema: (schema:
|
|
31
|
+
addSchema: (schema: JSONSchema7[]) => void;
|
|
31
32
|
/**
|
|
32
33
|
* Check if schema (or definition) is already registered
|
|
33
34
|
*/
|
|
@@ -75,4 +76,19 @@ export interface SchemaForgeRegistry {
|
|
|
75
76
|
*/
|
|
76
77
|
warmupCacheSync: VoidFunction;
|
|
77
78
|
}
|
|
79
|
+
export interface SchemaForgeRegistryOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Extra ajv options
|
|
82
|
+
*
|
|
83
|
+
* @see https://ajv.js.org/options.html Options reference
|
|
84
|
+
* @see https://ajv.js.org/json-schema.html Schema reference
|
|
85
|
+
*/
|
|
86
|
+
engine?: AjvOptions;
|
|
87
|
+
/**
|
|
88
|
+
* Use additional formats via ajv-formats
|
|
89
|
+
*
|
|
90
|
+
* @see https://ajv.js.org/packages/ajv-formats.html ajv-formats
|
|
91
|
+
*/
|
|
92
|
+
extendedVocabulary?: boolean;
|
|
93
|
+
}
|
|
78
94
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-registry/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACtD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-registry/types.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsofist/schema-forge",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Generate JSON schema from TypeScript types",
|
|
5
5
|
"author": "Andrew Berdnikov <tsofistgudmen@gmail.com>",
|
|
6
6
|
"license": "LGPL-3.0",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"@dbml/core": "~3.13.5",
|
|
24
24
|
"@faker-js/faker": "^9.8.0",
|
|
25
25
|
"@tsofist/stem": "^5.1.0",
|
|
26
|
+
"@ungap/structured-clone": "^1.3.0",
|
|
26
27
|
"ajv": "^8.17.1",
|
|
27
28
|
"ajv-formats": "^3.0.1",
|
|
28
29
|
"json-schema": "^0.4.0",
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"@types/jest": "^29.5.14",
|
|
37
38
|
"@types/node": "^20.19.0",
|
|
38
39
|
"@types/supertest": "^6.0.3",
|
|
40
|
+
"@types/ungap__structured-clone": "^1.2.0",
|
|
39
41
|
"jest": "~29.7.0",
|
|
40
42
|
"rimraf": "^6.0.1",
|
|
41
43
|
"supertest": "^7.1.1",
|