@tsofist/schema-forge 2.3.0 → 2.4.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/generator.spec.js +2 -0
- package/lib/types/db.types.d.ts +56 -0
- package/lib/types/db.types.js +17 -0
- package/lib/validator.js +32 -19
- package/package.json +1 -1
package/lib/generator.spec.js
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ArrayMay } 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
|
+
export type DBIndexOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Type of index.
|
|
21
|
+
* @default 'btree'
|
|
22
|
+
*/
|
|
23
|
+
type?: DBIndexType;
|
|
24
|
+
/**
|
|
25
|
+
* Name of index.
|
|
26
|
+
* @default 'ix_[schema]_[table]_[column]'
|
|
27
|
+
*/
|
|
28
|
+
name?: string;
|
|
29
|
+
/**
|
|
30
|
+
* If true, the index will be unique.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
unique?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export type DBIndexOptionsDef<B extends boolean = boolean> = ArrayMay<DBIndexOptions | string | B>;
|
|
36
|
+
/**
|
|
37
|
+
* Database entity options.
|
|
38
|
+
*/
|
|
39
|
+
export type DBEntityOptions = {
|
|
40
|
+
/**
|
|
41
|
+
* Table name.
|
|
42
|
+
*
|
|
43
|
+
* @default '[schema].[table]'
|
|
44
|
+
*/
|
|
45
|
+
name?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Indexes of the table.
|
|
48
|
+
* They can be overridden/added at the column level.
|
|
49
|
+
*
|
|
50
|
+
* Use `true` to apply default index options.
|
|
51
|
+
* Use string literal to set index name.
|
|
52
|
+
*/
|
|
53
|
+
indexes?: {
|
|
54
|
+
[column: string]: DBIndexOptionsDef<true>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
];
|
package/lib/validator.js
CHANGED
|
@@ -10,6 +10,7 @@ const delay_1 = require("@tsofist/stem/lib/timers/delay");
|
|
|
10
10
|
const ajv_1 = require("ajv");
|
|
11
11
|
const ajv_formats_1 = require("ajv-formats");
|
|
12
12
|
const types_1 = require("./types");
|
|
13
|
+
const db_types_1 = require("./types/db.types");
|
|
13
14
|
const index_1 = require("./index");
|
|
14
15
|
const DEF_OPTIONS = {
|
|
15
16
|
meta: true,
|
|
@@ -329,34 +330,46 @@ function addJSDocKeywords(engine) {
|
|
|
329
330
|
],
|
|
330
331
|
},
|
|
331
332
|
});
|
|
332
|
-
const
|
|
333
|
-
type: '
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
type: {
|
|
339
|
-
type: 'string',
|
|
340
|
-
enum: ['btree', 'gin', 'gist'],
|
|
341
|
-
},
|
|
333
|
+
const DBIndexOptionsProperties = {
|
|
334
|
+
name: { type: 'string', pattern: IXNamePattern },
|
|
335
|
+
unique: { type: 'boolean' },
|
|
336
|
+
type: {
|
|
337
|
+
type: 'string',
|
|
338
|
+
enum: db_types_1.DBIndexTypeList,
|
|
342
339
|
},
|
|
343
340
|
};
|
|
341
|
+
const DBIndexSchema = {
|
|
342
|
+
type: ['string', 'boolean', 'object', 'array'],
|
|
343
|
+
pattern: IXNamePattern,
|
|
344
|
+
additionalProperties: false,
|
|
345
|
+
properties: DBIndexOptionsProperties,
|
|
346
|
+
items: {},
|
|
347
|
+
minItems: 1,
|
|
348
|
+
};
|
|
349
|
+
DBIndexSchema.items = {
|
|
350
|
+
...DBIndexSchema,
|
|
351
|
+
type: ['string', 'boolean', 'object'],
|
|
352
|
+
};
|
|
344
353
|
engine.addKeyword({
|
|
345
354
|
keyword: 'dbIndex',
|
|
346
|
-
metaSchema:
|
|
347
|
-
type: ['string', 'boolean', 'object', 'array'],
|
|
348
|
-
pattern: IXNamePattern,
|
|
349
|
-
additionalProperties: false,
|
|
350
|
-
properties: DBIndexSettingsSchema.properties,
|
|
351
|
-
items: DBIndexSettingsSchema,
|
|
352
|
-
minItems: 1,
|
|
353
|
-
},
|
|
355
|
+
metaSchema: DBIndexSchema,
|
|
354
356
|
});
|
|
355
357
|
engine.addKeyword({
|
|
356
358
|
keyword: 'dbEntity',
|
|
357
359
|
metaSchema: {
|
|
358
|
-
type: 'string',
|
|
360
|
+
type: ['string', 'object'],
|
|
359
361
|
pattern: EntityNamePattern,
|
|
362
|
+
additionalProperties: false,
|
|
363
|
+
properties: {
|
|
364
|
+
name: {
|
|
365
|
+
type: 'string',
|
|
366
|
+
pattern: EntityNamePattern,
|
|
367
|
+
},
|
|
368
|
+
indexes: {
|
|
369
|
+
type: 'array',
|
|
370
|
+
items: DBIndexSchema,
|
|
371
|
+
},
|
|
372
|
+
},
|
|
360
373
|
},
|
|
361
374
|
});
|
|
362
375
|
}
|