@tsofist/schema-forge 2.12.0 → 3.0.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 (114) hide show
  1. package/lib/artefacts-policy.d.ts +3 -0
  2. package/lib/artefacts-policy.d.ts.map +1 -0
  3. package/lib/artefacts-policy.js +7 -0
  4. package/lib/dbml-generator/converter.d.ts +5 -0
  5. package/lib/dbml-generator/converter.d.ts.map +1 -0
  6. package/lib/dbml-generator/converter.js +15 -0
  7. package/lib/dbml-generator/generator.d.ts +4 -0
  8. package/lib/dbml-generator/generator.d.ts.map +1 -0
  9. package/lib/dbml-generator/generator.js +423 -0
  10. package/lib/dbml-generator/generator.spec.d.ts +2 -0
  11. package/lib/dbml-generator/generator.spec.d.ts.map +1 -0
  12. package/lib/dbml-generator/generator.spec.js +94 -0
  13. package/lib/dbml-generator/types.d.ts +144 -0
  14. package/lib/dbml-generator/types.d.ts.map +1 -0
  15. package/lib/dbml-generator/types.js +53 -0
  16. package/lib/definition-info/api-signature.d.ts +18 -0
  17. package/lib/definition-info/api-signature.d.ts.map +1 -0
  18. package/lib/definition-info/api-signature.js +31 -0
  19. package/lib/definition-info/parser.d.ts +3 -0
  20. package/lib/definition-info/parser.d.ts.map +1 -0
  21. package/lib/definition-info/parser.js +44 -0
  22. package/lib/definition-info/ref.d.ts +3 -0
  23. package/lib/definition-info/ref.d.ts.map +1 -0
  24. package/lib/definition-info/ref.js +6 -0
  25. package/lib/definition-info/types.d.ts +48 -0
  26. package/lib/definition-info/types.d.ts.map +1 -0
  27. package/lib/definition-info/types.js +20 -0
  28. package/lib/efc.d.ts +27 -0
  29. package/lib/efc.d.ts.map +1 -0
  30. package/lib/efc.js +9 -0
  31. package/lib/fake-generator/generator-host.d.ts +4 -0
  32. package/lib/fake-generator/generator-host.d.ts.map +1 -0
  33. package/lib/fake-generator/generator-host.js +57 -0
  34. package/lib/fake-generator/generator.d.ts +6 -0
  35. package/lib/fake-generator/generator.d.ts.map +1 -0
  36. package/lib/fake-generator/generator.js +64 -0
  37. package/lib/fake-generator/generator.spec.d.ts +2 -0
  38. package/lib/fake-generator/generator.spec.d.ts.map +1 -0
  39. package/lib/{fake-generator.spec.js → fake-generator/generator.spec.js} +21 -19
  40. package/lib/fake-generator/modules.d.ts +3 -0
  41. package/lib/fake-generator/modules.d.ts.map +1 -0
  42. package/lib/fake-generator/modules.js +44 -0
  43. package/lib/fake-generator/types.d.ts +18 -0
  44. package/lib/fake-generator/types.d.ts.map +1 -0
  45. package/lib/fake-generator/types.js +2 -0
  46. package/lib/schema-generator/extended-annotations-reader.d.ts +2 -0
  47. package/lib/schema-generator/extended-annotations-reader.d.ts.map +1 -0
  48. package/lib/{util/patch.extended-annotations-reader.js → schema-generator/extended-annotations-reader.js} +2 -2
  49. package/lib/schema-generator/forge.d.ts +3 -0
  50. package/lib/schema-generator/forge.d.ts.map +1 -0
  51. package/lib/{generator.js → schema-generator/forge.js} +13 -33
  52. package/lib/schema-generator/forge.spec.d.ts +2 -0
  53. package/lib/schema-generator/forge.spec.d.ts.map +1 -0
  54. package/lib/{generator.spec.js → schema-generator/forge.spec.js} +113 -108
  55. package/lib/schema-generator/format-error.d.ts +2 -0
  56. package/lib/schema-generator/format-error.d.ts.map +1 -0
  57. package/lib/{util/format.error.js → schema-generator/format-error.js} +3 -3
  58. package/lib/schema-generator/generate-drafts.d.ts +17 -0
  59. package/lib/schema-generator/generate-drafts.d.ts.map +1 -0
  60. package/lib/{generator/types-generator.js → schema-generator/generate-drafts.js} +140 -120
  61. package/lib/schema-generator/generate-schema.d.ts +15 -0
  62. package/lib/schema-generator/generate-schema.d.ts.map +1 -0
  63. package/lib/{generator/schema-generator.js → schema-generator/generate-schema.js} +21 -20
  64. package/lib/{util/tsc.d.ts → schema-generator/helpers-tsc.d.ts} +2 -1
  65. package/lib/schema-generator/helpers-tsc.d.ts.map +1 -0
  66. package/lib/{shrink-names.d.ts → schema-generator/shrink-definition-name.d.ts} +2 -1
  67. package/lib/schema-generator/shrink-definition-name.d.ts.map +1 -0
  68. package/lib/{shrink-names.js → schema-generator/shrink-definition-name.js} +5 -5
  69. package/lib/schema-generator/sort-properties.d.ts +3 -0
  70. package/lib/schema-generator/sort-properties.d.ts.map +1 -0
  71. package/lib/{util → schema-generator}/sort-properties.js +2 -2
  72. package/lib/schema-generator/types.d.ts +18 -0
  73. package/lib/schema-generator/types.d.ts.map +1 -0
  74. package/lib/{generator → schema-generator}/types.js +20 -8
  75. package/lib/schema-registry/kw-api.d.ts +3 -0
  76. package/lib/schema-registry/kw-api.d.ts.map +1 -0
  77. package/lib/schema-registry/kw-api.js +25 -0
  78. package/lib/schema-registry/kw-common.d.ts +3 -0
  79. package/lib/schema-registry/kw-common.d.ts.map +1 -0
  80. package/lib/schema-registry/kw-common.js +47 -0
  81. package/lib/schema-registry/kw-dbml.d.ts +3 -0
  82. package/lib/schema-registry/kw-dbml.d.ts.map +1 -0
  83. package/lib/schema-registry/kw-dbml.js +79 -0
  84. package/lib/schema-registry/loader.d.ts +10 -0
  85. package/lib/schema-registry/loader.d.ts.map +1 -0
  86. package/lib/schema-registry/loader.js +24 -0
  87. package/lib/schema-registry/registry.d.ts +8 -0
  88. package/lib/schema-registry/registry.d.ts.map +1 -0
  89. package/lib/schema-registry/registry.js +230 -0
  90. package/lib/schema-registry/types.d.ts +94 -0
  91. package/lib/schema-registry/types.d.ts.map +1 -0
  92. package/lib/schema-registry/types.js +2 -0
  93. package/lib/types.d.ts +51 -78
  94. package/lib/types.d.ts.map +1 -0
  95. package/lib/types.js +0 -15
  96. package/package.json +6 -3
  97. package/lib/fake-generator.d.ts +0 -21
  98. package/lib/fake-generator.js +0 -158
  99. package/lib/fake-generator.spec.d.ts +0 -1
  100. package/lib/generator/schema-generator.d.ts +0 -20
  101. package/lib/generator/types-generator.d.ts +0 -13
  102. package/lib/generator/types.d.ts +0 -40
  103. package/lib/generator.d.ts +0 -5
  104. package/lib/generator.spec.d.ts +0 -1
  105. package/lib/index.d.ts +0 -7
  106. package/lib/index.js +0 -64
  107. package/lib/types/db.types.d.ts +0 -96
  108. package/lib/types/db.types.js +0 -17
  109. package/lib/util/format.error.d.ts +0 -1
  110. package/lib/util/patch.extended-annotations-reader.d.ts +0 -1
  111. package/lib/util/sort-properties.d.ts +0 -2
  112. package/lib/validator.d.ts +0 -47
  113. package/lib/validator.js +0 -396
  114. /package/lib/{util/tsc.js → schema-generator/helpers-tsc.js} +0 -0
@@ -1,96 +0,0 @@
1
- import { ArrayMay, HexString } from '@tsofist/stem';
2
- /**
3
- * Database index types.
4
- *
5
- * @see https://www.postgresql.org/docs/current/indexes-types.html PostgreSQL
6
- */
7
- export declare const DBIndexTypeList: readonly ["btree", "hash", "gin", "gist", "spgist", "brin"];
8
- /**
9
- * Database index type.
10
- *
11
- * @see https://www.postgresql.org/docs/current/indexes-types.html PostgreSQL
12
- * @default 'btree'
13
- */
14
- export type DBIndexType = (typeof DBIndexTypeList)[number];
15
- /**
16
- * Database index options.
17
- *
18
- * @see https://dbml.dbdiagram.io/docs/#index-definition dbml spec
19
- */
20
- export type DBIndexOptions = {
21
- /**
22
- * Type of index.
23
- * @default 'btree'
24
- */
25
- type?: DBIndexType;
26
- /**
27
- * Name of index.
28
- * @default 'ix_[schema]_[table]_[column]'
29
- */
30
- name?: string;
31
- /**
32
- * If true, the index will be unique.
33
- * @default false
34
- */
35
- unique?: boolean;
36
- /**
37
- * Is it a primary key
38
- * @default false
39
- */
40
- pk?: boolean;
41
- /**
42
- * Any important notes.
43
- * Can be used in DDL.
44
- */
45
- note?: string;
46
- /**
47
- * Any important developer comments.
48
- * Can't be used in DDL.
49
- */
50
- comment?: string;
51
- };
52
- export type DBIndexOptionsDef<B extends boolean = boolean> = ArrayMay<DBIndexOptions | string | B>;
53
- /**
54
- * Database entity options.
55
- *
56
- * @see https://dbml.dbdiagram.io/docs/#table-definition dbml spec
57
- */
58
- export type DBEntityOptions = {
59
- /**
60
- * Table name.
61
- *
62
- * @default '[schema].[table]'
63
- */
64
- name?: string;
65
- /**
66
- * Indexes of the table.
67
- * They can be overridden/added at the column level.
68
- *
69
- * Use `true` to apply default index options.
70
- * Use string literal to set index name.
71
- */
72
- indexes?: {
73
- [field: string]: DBIndexOptionsDef<true>;
74
- };
75
- /**
76
- * Any important notes.
77
- * Can be used in DDL.
78
- */
79
- note?: string;
80
- /**
81
- * Any important developer comments.
82
- * Can't be used in DDL.
83
- */
84
- comment?: string;
85
- /**
86
- * Table name alias.
87
- */
88
- alias?: string;
89
- /**
90
- * Settings.
91
- */
92
- settings?: {
93
- headercolor: HexString;
94
- };
95
- };
96
- export type DBEntityOptionsDef = DBEntityOptions | string;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DBIndexTypeList = void 0;
4
- /**
5
- * Database index types.
6
- *
7
- * @see https://www.postgresql.org/docs/current/indexes-types.html PostgreSQL
8
- */
9
- exports.DBIndexTypeList = [
10
- //
11
- 'btree',
12
- 'hash',
13
- 'gin',
14
- 'gist',
15
- 'spgist',
16
- 'brin',
17
- ];
@@ -1 +0,0 @@
1
- export declare function formatSchemaForgeError(error: Error, dir?: string): string;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { SchemaObject } from 'ajv';
2
- export declare function sortProperties<T extends SchemaObject>(schema: T): T;
@@ -1,47 +0,0 @@
1
- import { ArrayMay, Nullable } from '@tsofist/stem';
2
- import { ErrorsTextOptions, Options, SchemaObject } from 'ajv';
3
- import { SchemaDefinitionInfo, SchemaForgeDefinitionRef, SchemaForgeValidationContextBase, SchemaForgeValidationFunction, SchemaForgeValidationReport, SchemaForgeValidationResult } from './types';
4
- export type SchemaForgeValidator = ReturnType<typeof createSchemaForgeValidator>;
5
- export type SchemaForgeValidatorOptions = Parameters<typeof createSchemaForgeValidator>;
6
- /**
7
- * Create SchemaForge Registry: a json-schema validator with additional features
8
- */
9
- export declare function createSchemaForgeValidator(engineOptions?: Options, useAdditionalFormats?: boolean): {
10
- readonly compilationArtifactCount: number;
11
- readonly rev: number;
12
- clear: () => void;
13
- clone: (options?: Omit<Options, "schemas">, onSchema?: (value: SchemaObject) => SchemaObject) => {
14
- readonly compilationArtifactCount: number;
15
- readonly rev: number;
16
- clear: () => void;
17
- clone: /*elided*/ any;
18
- removeSchema: (ref: ArrayMay<SchemaForgeDefinitionRef>) => void;
19
- hasValidator: (ref: SchemaForgeDefinitionRef) => boolean;
20
- getValidator: <TData = unknown>(ref: SchemaForgeDefinitionRef | SchemaObject) => SchemaForgeValidationFunction<TData> | undefined;
21
- getSchema: (ref: SchemaForgeDefinitionRef) => import("ajv").AnySchema | undefined;
22
- getRootSchema: (schemaId: string) => (SchemaObject & {
23
- definitions?: SchemaObject;
24
- }) | undefined;
25
- addSchema: (schema: SchemaObject[]) => void;
26
- validateBySchema: (ref: SchemaForgeDefinitionRef, data: unknown, instancePath?: string) => SchemaForgeValidationResult;
27
- checkBySchema: <T = unknown, Ctx extends SchemaForgeValidationContextBase = SchemaForgeValidationContextBase>(ref: SchemaForgeDefinitionRef, data: unknown, context?: Ctx) => data is T;
28
- validationErrorsText: (errors: Nullable<SchemaForgeValidationReport>, options?: ErrorsTextOptions) => string;
29
- listDefinitions: (predicate?: (info: SchemaDefinitionInfo) => boolean) => SchemaDefinitionInfo[];
30
- warmupCache: (schemasPerIteration?: number, delayMs?: number) => Promise<void>;
31
- warmupCacheSync: () => void;
32
- };
33
- removeSchema: (ref: ArrayMay<SchemaForgeDefinitionRef>) => void;
34
- hasValidator: (ref: SchemaForgeDefinitionRef) => boolean;
35
- getValidator: <TData = unknown>(ref: SchemaForgeDefinitionRef | SchemaObject) => SchemaForgeValidationFunction<TData> | undefined;
36
- getSchema: (ref: SchemaForgeDefinitionRef) => import("ajv").AnySchema | undefined;
37
- getRootSchema: (schemaId: string) => (SchemaObject & {
38
- definitions?: SchemaObject;
39
- }) | undefined;
40
- addSchema: (schema: SchemaObject[]) => void;
41
- validateBySchema: (ref: SchemaForgeDefinitionRef, data: unknown, instancePath?: string) => SchemaForgeValidationResult;
42
- checkBySchema: <T = unknown, Ctx extends SchemaForgeValidationContextBase = SchemaForgeValidationContextBase>(ref: SchemaForgeDefinitionRef, data: unknown, context?: Ctx) => data is T;
43
- validationErrorsText: (errors: Nullable<SchemaForgeValidationReport>, options?: ErrorsTextOptions) => string;
44
- listDefinitions: (predicate?: (info: SchemaDefinitionInfo) => boolean) => SchemaDefinitionInfo[];
45
- warmupCache: (schemasPerIteration?: number, delayMs?: number) => Promise<void>;
46
- warmupCacheSync: () => void;
47
- };
package/lib/validator.js DELETED
@@ -1,396 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSchemaForgeValidator = createSchemaForgeValidator;
4
- const as_array_1 = require("@tsofist/stem/lib/as-array");
5
- const chunk_1 = require("@tsofist/stem/lib/chunk");
6
- const error_1 = require("@tsofist/stem/lib/error");
7
- const entries_1 = require("@tsofist/stem/lib/object/entries");
8
- const values_1 = require("@tsofist/stem/lib/object/values");
9
- const delay_1 = require("@tsofist/stem/lib/timers/delay");
10
- const ajv_1 = require("ajv");
11
- const ajv_formats_1 = require("ajv-formats");
12
- const types_1 = require("./types");
13
- const db_types_1 = require("./types/db.types");
14
- const index_1 = require("./index");
15
- const DEF_OPTIONS = {
16
- meta: true,
17
- defaultMeta: 'http://json-schema.org/draft-07/schema',
18
- allErrors: true,
19
- strict: true,
20
- strictSchema: true,
21
- strictTypes: false,
22
- strictTuples: false,
23
- allowUnionTypes: true,
24
- coerceTypes: false,
25
- removeAdditional: false,
26
- unicodeRegExp: true,
27
- useDefaults: false,
28
- addUsedSchema: false,
29
- inlineRefs: true,
30
- ownProperties: true,
31
- discriminator: false,
32
- code: {
33
- es5: false,
34
- esm: false,
35
- optimize: 2,
36
- },
37
- };
38
- /**
39
- * Create SchemaForge Registry: a json-schema validator with additional features
40
- */
41
- function createSchemaForgeValidator(engineOptions, useAdditionalFormats = false) {
42
- engineOptions = {
43
- ...DEF_OPTIONS,
44
- ...engineOptions,
45
- };
46
- const initialSchemas = engineOptions.schemas;
47
- if (initialSchemas)
48
- delete engineOptions.schemas;
49
- let rev = 0;
50
- let engine = new ajv_1.default(engineOptions);
51
- engine.removeSchema();
52
- if (initialSchemas)
53
- engine.addSchema(initialSchemas);
54
- addJSDocKeywords(engine);
55
- if (useAdditionalFormats)
56
- engine = (0, ajv_formats_1.default)(engine);
57
- /**
58
- * Clone validator with overridden options
59
- */
60
- function clone(options, onSchema) {
61
- const schemas = [];
62
- for (const env of (0, values_1.nonNullableValues)(engine.schemas)) {
63
- if (env.meta)
64
- continue;
65
- const schema = onSchema
66
- ? onSchema(env.schema)
67
- : env.schema;
68
- schemas.push(schema);
69
- }
70
- const opts = {
71
- ...engineOptions,
72
- schemas,
73
- ...options,
74
- };
75
- return createSchemaForgeValidator(opts, useAdditionalFormats);
76
- }
77
- /**
78
- * Get schema (or definition) validation function
79
- */
80
- function getValidator(ref) {
81
- if (typeof ref === 'string')
82
- return engine.getSchema(ref);
83
- const result = engine.compile(ref);
84
- checkIsSyncValidator(result);
85
- return result;
86
- }
87
- /**
88
- * Check if schema exists
89
- * WARN: this method may compile schema if it's not compiled yet
90
- */
91
- function hasValidator(ref) {
92
- return ref in engine.schemas || ref in engine.refs || engine.getSchema(ref) != null;
93
- }
94
- /**
95
- * Add root schema(s) to registry
96
- */
97
- function addSchema(schema) {
98
- engine.addSchema(schema);
99
- rev++;
100
- }
101
- /**
102
- * Remove root schema(s) from registry
103
- */
104
- function removeSchema(ref) {
105
- for (const item of (0, as_array_1.asArray)(ref))
106
- engine.removeSchema(item);
107
- rev++;
108
- }
109
- /**
110
- * Remove all schemas from registry
111
- */
112
- function clear() {
113
- engine.removeSchema();
114
- rev++;
115
- }
116
- /**
117
- * Get validation errors text
118
- */
119
- function validationErrorsText(errors, options) {
120
- return engine.errorsText(errors, options);
121
- }
122
- /**
123
- * Validate data by schema definition reference
124
- */
125
- function validateBySchema(ref, data, instancePath = '') {
126
- const validator = getValidator(ref);
127
- if (!validator) {
128
- (0, error_1.raiseEx)(types_1.SchemaNotFoundErrorCode, { schema: ref });
129
- }
130
- const valid = validator(data, {
131
- instancePath,
132
- parentData: {},
133
- parentDataProperty: '',
134
- rootData: {},
135
- dynamicAnchors: {},
136
- });
137
- const errors = validator.errors;
138
- return {
139
- valid,
140
- errors,
141
- errorsText(options) {
142
- return validationErrorsText(errors, options);
143
- },
144
- };
145
- }
146
- /**
147
- * Check (throw error if invalid) data by schema definition reference
148
- */
149
- function checkBySchema(ref, data, context) {
150
- const result = validateBySchema(ref, data, context?.instancePath);
151
- if (!result.valid) {
152
- const ctx = {
153
- ...context,
154
- schema: ref,
155
- errors: result.errors,
156
- };
157
- (0, error_1.raiseEx)(types_1.SchemaForgeValidationErrorCode, ctx, context?.errorMessage);
158
- }
159
- return result.valid;
160
- }
161
- function mapDefinitions(callback) {
162
- const result = [];
163
- for (const [schemaId, env] of (0, entries_1.entries)(engine.schemas)) {
164
- if (env &&
165
- typeof env.schema === 'object' &&
166
- !schemaId.startsWith('http') &&
167
- env.schema.definitions &&
168
- typeof env.schema.definitions === 'object') {
169
- for (const name of Object.keys(env.schema.definitions)) {
170
- result.push(callback(name, schemaId));
171
- }
172
- }
173
- }
174
- return result;
175
- }
176
- /**
177
- * List schema definitions
178
- */
179
- function listDefinitions(predicate) {
180
- const result = [];
181
- mapDefinitions((name, schemaId) => {
182
- const info = (0, index_1.parseSchemaDefinitionInfo)(name, schemaId);
183
- if (predicate === undefined || predicate(info))
184
- result.push(info);
185
- });
186
- return result;
187
- }
188
- /**
189
- * Get schema object of definition by reference
190
- */
191
- function getSchema(ref) {
192
- return getValidator(ref)?.schema;
193
- }
194
- /**
195
- * Get root schema object
196
- */
197
- function getRootSchema(schemaId) {
198
- return engine.schemas[schemaId]?.schema;
199
- }
200
- /**
201
- * Synchronously warm up validator cache
202
- * This action is useful to pre-compile all schemas and their definitions
203
- */
204
- function warmupCacheSync() {
205
- mapDefinitions((name, schemaId) => {
206
- const ref = (0, index_1.buildSchemaDefinitionRef)(name, schemaId);
207
- checkIsSyncValidator(engine.getSchema(ref));
208
- });
209
- }
210
- /**
211
- * Asynchronously warm up validator cache
212
- * This action is useful to pre-compile all schemas and their definitions
213
- */
214
- async function warmupCache(schemasPerIteration = 5, delayMs = 1) {
215
- await (0, chunk_1.chunk)(mapDefinitions((name, schemaId) => (0, index_1.buildSchemaDefinitionRef)(name, schemaId)), schemasPerIteration, async (items) => {
216
- for (const ref of items)
217
- engine.getSchema(ref);
218
- return (0, delay_1.delay)(delayMs);
219
- });
220
- }
221
- return {
222
- get compilationArtifactCount() {
223
- const names = new Set([
224
- //
225
- ...Object.keys(engine.refs),
226
- ...Object.keys(engine.schemas),
227
- ]);
228
- return names.size;
229
- },
230
- get rev() {
231
- return rev;
232
- },
233
- clear,
234
- clone,
235
- removeSchema,
236
- hasValidator,
237
- getValidator,
238
- getSchema,
239
- getRootSchema,
240
- addSchema,
241
- validateBySchema,
242
- checkBySchema,
243
- validationErrorsText,
244
- listDefinitions,
245
- warmupCache,
246
- warmupCacheSync,
247
- };
248
- }
249
- function addJSDocKeywords(engine) {
250
- const InterfaceNamePattern = '^[A-Z][a-zA-Z0-9]+$';
251
- const PropertyNamePattern = '^[a-z][a-zA-Z0-9]+$';
252
- const NestedPropertyNamePattern = '^[a-z][a-zA-Z0-9.-]+$';
253
- const MethodNamePattern = PropertyNamePattern;
254
- const MemberNamePattern = `${InterfaceNamePattern.substring(0, InterfaceNamePattern.length - 1)}#${PropertyNamePattern.substring(1)}`;
255
- const IXNamePattern = '^ix_[a-z][a-zA-Z0-9_]+$';
256
- const EntityNamePattern = '^([a-zA-Z_][a-z0-9_]*\\.)?[a-z_][a-z0-9_]*$';
257
- const FakerModulePattern = '^[a-zA-Z.]+$';
258
- engine.addKeyword({
259
- keyword: 'version',
260
- metaSchema: {
261
- type: 'string',
262
- },
263
- dependencies: ['$id', '$schema'],
264
- });
265
- engine.addKeyword({
266
- keyword: 'hash',
267
- metaSchema: {
268
- type: 'string',
269
- },
270
- dependencies: ['$id', '$schema'],
271
- });
272
- engine.addKeyword({
273
- keyword: 'interface',
274
- metaSchema: {
275
- type: 'string',
276
- pattern: InterfaceNamePattern,
277
- },
278
- });
279
- engine.addKeyword({
280
- keyword: 'property',
281
- metaSchema: {
282
- type: 'string',
283
- pattern: PropertyNamePattern,
284
- },
285
- });
286
- engine.addKeyword({
287
- keyword: 'method',
288
- metaSchema: {
289
- type: 'string',
290
- pattern: MethodNamePattern,
291
- },
292
- });
293
- engine.addKeyword({
294
- keyword: 'member',
295
- metaSchema: {
296
- type: 'string',
297
- pattern: MemberNamePattern,
298
- },
299
- });
300
- /**
301
- * @see https://fakerjs.dev/api/person.html
302
- */
303
- engine.addKeyword({
304
- keyword: 'faker',
305
- metaSchema: {
306
- oneOf: [
307
- {
308
- // https://fakerjs.dev/api/person.html
309
- // https://fakerjs.dev/api/company.html#name
310
- // https://github.com/json-schema-faker/json-schema-faker/blob/master/docs/USAGE.md
311
- // example (schema):
312
- // faker: 'person.fullName'
313
- // faker: 'person.firstName'
314
- // faker: 'company.name'
315
- // example (jsdoc):
316
- // @faker company.name
317
- type: 'string',
318
- pattern: FakerModulePattern,
319
- },
320
- {
321
- // https://fakerjs.dev/api/lorem.html#words
322
- // example (schema):
323
- // faker: { 'lorem.words': [{ min: 30, max: 50 }] },
324
- // example (jsdoc):
325
- // @faker { 'lorem.words': [{ min: 5, max: 10 }] }
326
- type: 'object',
327
- propertyNames: {
328
- pattern: FakerModulePattern,
329
- },
330
- },
331
- ],
332
- },
333
- });
334
- const DBIndexOptionsProperties = {
335
- name: { type: 'string', pattern: IXNamePattern },
336
- unique: { type: 'boolean' },
337
- pk: { type: 'boolean' },
338
- type: {
339
- type: 'string',
340
- enum: db_types_1.DBIndexTypeList,
341
- },
342
- note: { type: 'string' },
343
- comment: { type: 'string' },
344
- };
345
- const DBIndexSchema = {
346
- type: ['string', 'boolean', 'object', 'array'],
347
- pattern: IXNamePattern,
348
- additionalProperties: false,
349
- properties: DBIndexOptionsProperties,
350
- items: {},
351
- minItems: 1,
352
- };
353
- DBIndexSchema.items = {
354
- ...DBIndexSchema,
355
- type: ['string', 'boolean', 'object'],
356
- };
357
- engine.addKeyword({
358
- keyword: 'dbIndex',
359
- metaSchema: DBIndexSchema,
360
- });
361
- engine.addKeyword({
362
- keyword: 'dbEntity',
363
- metaSchema: {
364
- type: ['string', 'object'],
365
- pattern: EntityNamePattern,
366
- additionalProperties: false,
367
- properties: {
368
- name: {
369
- type: 'string',
370
- pattern: EntityNamePattern,
371
- },
372
- indexes: {
373
- type: 'object',
374
- additionalProperties: DBIndexSchema,
375
- propertyNames: {
376
- pattern: NestedPropertyNamePattern,
377
- },
378
- },
379
- note: { type: 'string' },
380
- comment: { type: 'string' },
381
- alias: { type: 'string' },
382
- settings: {
383
- type: 'object',
384
- properties: {
385
- headercolor: { type: 'string' },
386
- },
387
- },
388
- },
389
- },
390
- });
391
- }
392
- function checkIsSyncValidator(fn) {
393
- if (typeof fn === 'function' && '$async' in fn) {
394
- (0, error_1.raise)('[SchemaForge] Asynchronous validation schemas are not supported');
395
- }
396
- }