@rws-framework/db 2.4.5 → 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.
- package/.bin/add-v.sh +9 -9
- package/.bin/emerge.sh +10 -10
- package/.eslintrc.json +53 -53
- package/README.md +404 -404
- package/dist/decorators/IdType.d.ts +8 -0
- package/dist/decorators/IdType.js +10 -0
- package/dist/decorators/InverseRelation.d.ts +2 -2
- package/dist/decorators/InverseRelation.js +5 -1
- package/dist/decorators/InverseTimeSeries.d.ts +0 -0
- package/dist/decorators/InverseTimeSeries.js +0 -0
- package/dist/decorators/RWSCollection.d.ts +7 -0
- package/dist/decorators/RWSCollection.js +6 -0
- package/dist/decorators/Relation.d.ts +8 -6
- package/dist/decorators/Relation.js +8 -1
- package/dist/decorators/TrackType.d.ts +2 -14
- package/dist/decorators/TrackType.js +7 -0
- package/dist/decorators/TypeFunctions.d.ts +44 -0
- package/dist/decorators/TypeFunctions.js +174 -0
- package/dist/decorators/index.d.ts +4 -2
- package/dist/decorators/index.js +3 -1
- package/dist/helper/DbHelper.d.ts +76 -5
- package/dist/helper/DbHelper.js +93 -154
- package/dist/helper/FieldsHelper.d.ts +0 -0
- package/dist/helper/FieldsHelper.js +0 -0
- package/dist/helper/db/index.d.ts +9 -0
- package/dist/helper/db/index.js +18 -0
- package/dist/helper/db/relation-manager.d.ts +45 -0
- package/dist/helper/db/relation-manager.js +105 -0
- package/dist/helper/db/schema-generator.d.ts +37 -0
- package/dist/helper/db/schema-generator.js +243 -0
- package/dist/helper/db/type-converter.d.ts +22 -0
- package/dist/helper/db/type-converter.js +106 -0
- package/dist/helper/db/utils.d.ts +24 -0
- package/dist/helper/db/utils.js +99 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/models/TimeSeriesModel.d.ts +7 -7
- package/dist/models/TimeSeriesModel.js +33 -33
- package/dist/models/_model.d.ts +2 -2
- package/dist/models/_model.js +0 -0
- package/dist/models/core/RWSModel.d.ts +4 -1
- package/dist/models/core/RWSModel.js +6 -4
- package/dist/models/core/TimeSeriesModel.d.ts +0 -0
- package/dist/models/core/TimeSeriesModel.js +0 -0
- package/dist/models/index.d.ts +2 -2
- package/dist/models/index.js +0 -0
- package/dist/models/interfaces/IDbOpts.d.ts +17 -0
- package/dist/models/interfaces/IDbOpts.js +2 -0
- package/dist/models/interfaces/IIdOpts.d.ts +0 -0
- package/dist/models/interfaces/IIdOpts.js +1 -0
- package/dist/models/interfaces/IIdTypeOpts.d.ts +3 -0
- package/dist/models/interfaces/IIdTypeOpts.js +2 -0
- package/dist/models/interfaces/IModel.d.ts +0 -0
- package/dist/models/interfaces/IModel.js +0 -0
- package/dist/models/interfaces/IRWSModelServices.d.ts +0 -0
- package/dist/models/interfaces/IRWSModelServices.js +0 -0
- package/dist/models/interfaces/ITrackerOpts.d.ts +12 -0
- package/dist/models/interfaces/ITrackerOpts.js +2 -0
- package/dist/models/interfaces/OpModelType.d.ts +3 -0
- package/dist/models/interfaces/OpModelType.js +0 -0
- package/dist/models/types/RelationTypes.d.ts +0 -0
- package/dist/models/types/RelationTypes.js +0 -0
- package/dist/models/utils/ModelUtils.d.ts +0 -0
- package/dist/models/utils/ModelUtils.js +0 -0
- package/dist/models/utils/PaginationUtils.d.ts +0 -0
- package/dist/models/utils/PaginationUtils.js +0 -0
- package/dist/models/utils/RelationUtils.d.ts +1 -1
- package/dist/models/utils/RelationUtils.js +2 -2
- package/dist/models/utils/TimeSeriesUtils.d.ts +0 -0
- package/dist/models/utils/TimeSeriesUtils.js +0 -0
- package/dist/services/DBService.d.ts +0 -0
- package/dist/services/DBService.js +0 -0
- package/dist/types/DbConfigHandler.d.ts +1 -1
- package/dist/types/DbConfigHandler.js +0 -0
- package/dist/types/FindParams.d.ts +0 -0
- package/dist/types/FindParams.js +0 -0
- package/dist/types/IRWSModel.d.ts +1 -1
- package/dist/types/IRWSModel.js +0 -0
- package/dist/types/ITimeSeries.d.ts +0 -0
- package/dist/types/ITimeSeries.js +0 -0
- package/exec/console.js +110 -110
- package/exec/db.rws.webpack.config.js +168 -168
- package/exec/src/cli.ts +73 -75
- package/exec/tsconfig.json +32 -32
- package/exec/webpackFilters.js +17 -17
- package/package.json +36 -36
- package/src/decorators/IdType.ts +17 -0
- package/src/decorators/InverseRelation.ts +41 -37
- package/src/decorators/InverseTimeSeries.ts +21 -21
- package/src/decorators/RWSCollection.ts +45 -27
- package/src/decorators/Relation.ts +61 -48
- package/src/decorators/TrackType.ts +65 -69
- package/src/decorators/index.ts +16 -8
- package/src/empty.js +0 -0
- package/src/helper/DbHelper.ts +133 -223
- package/src/helper/FieldsHelper.ts +34 -34
- package/src/helper/db/index.ts +10 -0
- package/src/helper/db/relation-manager.ts +119 -0
- package/src/helper/db/schema-generator.ts +302 -0
- package/src/helper/db/type-converter.ts +119 -0
- package/src/helper/db/utils.ts +120 -0
- package/src/index.ts +47 -38
- package/src/models/_model.ts +29 -29
- package/src/models/core/RWSModel.ts +523 -520
- package/src/models/core/TimeSeriesModel.ts +19 -19
- package/src/models/index.ts +20 -20
- package/src/models/interfaces/IDbOpts.ts +17 -0
- package/src/models/interfaces/IIdTypeOpts.ts +4 -0
- package/src/models/interfaces/IModel.ts +12 -12
- package/src/models/interfaces/IRWSModelServices.ts +7 -7
- package/src/models/interfaces/ITrackerOpts.ts +13 -0
- package/src/models/interfaces/OpModelType.ts +52 -49
- package/src/models/types/RelationTypes.ts +25 -25
- package/src/models/utils/ModelUtils.ts +65 -65
- package/src/models/utils/PaginationUtils.ts +42 -42
- package/src/models/utils/RelationUtils.ts +76 -76
- package/src/models/utils/TimeSeriesUtils.ts +38 -38
- package/src/services/DBService.ts +277 -277
- package/src/types/DbConfigHandler.ts +17 -17
- package/src/types/FindParams.ts +13 -13
- package/src/types/IRWSModel.ts +2 -2
- package/src/types/ITimeSeries.ts +5 -5
- package/tsconfig.json +22 -22
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { IIdTypeOpts } from '../models/interfaces/IIdTypeOpts';
|
|
3
|
+
export interface IIdMetaOpts extends IIdTypeOpts {
|
|
4
|
+
type: any;
|
|
5
|
+
}
|
|
6
|
+
declare function IdType(type: any, opts?: IIdTypeOpts | null, tags?: string[]): (target: any, key: string) => void;
|
|
7
|
+
export default IdType;
|
|
8
|
+
export { IIdTypeOpts };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
function IdType(type, opts = null, tags = []) {
|
|
5
|
+
const metaOpts = { type, dbOptions: opts && opts.dbOptions ? opts.dbOptions : null };
|
|
6
|
+
return function (target, key) {
|
|
7
|
+
Reflect.defineMetadata(`IdType:${key}`, metaOpts, target);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
exports.default = IdType;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { RWSModel, OpModelType } from '../models/_model';
|
|
3
|
-
interface InverseRelationOpts {
|
|
3
|
+
export interface InverseRelationOpts {
|
|
4
4
|
key: string;
|
|
5
5
|
inversionModel: OpModelType<RWSModel<any>>;
|
|
6
6
|
foreignKey: string;
|
|
7
7
|
singular?: boolean;
|
|
8
8
|
relationName?: string;
|
|
9
|
+
mappingName?: string;
|
|
9
10
|
}
|
|
10
11
|
declare function InverseRelation(inversionModel: () => OpModelType<RWSModel<any>>, sourceModel: () => OpModelType<RWSModel<any>>, relationOptions?: Partial<InverseRelationOpts>): (target: any, key: string) => void;
|
|
11
12
|
export default InverseRelation;
|
|
12
|
-
export { InverseRelationOpts };
|
|
@@ -10,7 +10,11 @@ function InverseRelation(inversionModel, sourceModel, relationOptions = null) {
|
|
|
10
10
|
...relationOptions,
|
|
11
11
|
key,
|
|
12
12
|
inversionModel: model,
|
|
13
|
-
foreignKey: relationOptions && relationOptions.foreignKey ? relationOptions.foreignKey : `${source._collection}_id
|
|
13
|
+
foreignKey: relationOptions && relationOptions.foreignKey ? relationOptions.foreignKey : `${source._collection}_id`,
|
|
14
|
+
// Generate a unique relation name if one is not provided
|
|
15
|
+
relationName: relationOptions && relationOptions.relationName ?
|
|
16
|
+
relationOptions.relationName.toLowerCase() :
|
|
17
|
+
`${model._collection}_${key}_${source._collection}`.toLowerCase()
|
|
14
18
|
};
|
|
15
19
|
return metaOpts;
|
|
16
20
|
});
|
|
File without changes
|
|
File without changes
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { OpModelType } from "../models/_model";
|
|
2
|
+
export interface ISuperTagData {
|
|
3
|
+
tagType: string;
|
|
4
|
+
fields: string[];
|
|
5
|
+
map: string;
|
|
6
|
+
}
|
|
2
7
|
export interface IRWSCollectionOpts {
|
|
3
8
|
relations?: {
|
|
4
9
|
[key: string]: boolean;
|
|
5
10
|
};
|
|
6
11
|
ignored_keys?: string[];
|
|
12
|
+
noId?: boolean;
|
|
13
|
+
superTags?: ISuperTagData[];
|
|
7
14
|
}
|
|
8
15
|
export interface IRWSCollectionMeta {
|
|
9
16
|
collectionName: string;
|
|
@@ -11,6 +11,12 @@ function RWSCollection(collectionName, options) {
|
|
|
11
11
|
if (options && options.ignored_keys) {
|
|
12
12
|
target._CUT_KEYS = options.ignored_keys;
|
|
13
13
|
}
|
|
14
|
+
if (options && options.noId) {
|
|
15
|
+
target._NO_ID = options.noId;
|
|
16
|
+
}
|
|
17
|
+
if (options && options.superTags && options.superTags.length) {
|
|
18
|
+
target._SUPER_TAGS = options.superTags;
|
|
19
|
+
}
|
|
14
20
|
Reflect.defineMetadata(`RWSCollection`, metaOpts, target);
|
|
15
21
|
};
|
|
16
22
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { RWSModel, OpModelType } from '../models/_model';
|
|
3
|
-
type CascadingSetup = 'Cascade' | 'Restrict' | 'NoAction' | 'SetNull';
|
|
4
|
-
interface IRelationOpts {
|
|
3
|
+
export type CascadingSetup = 'Cascade' | 'Restrict' | 'NoAction' | 'SetNull';
|
|
4
|
+
export interface IRelationOpts {
|
|
5
5
|
required?: boolean;
|
|
6
6
|
key: string;
|
|
7
7
|
relationField: string;
|
|
8
8
|
relatedToField?: string;
|
|
9
|
+
mappingName?: string;
|
|
9
10
|
relatedTo: OpModelType<RWSModel<any>>;
|
|
10
11
|
many?: boolean;
|
|
11
12
|
embed?: boolean;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
useUuid?: boolean;
|
|
14
|
+
relationName?: string;
|
|
15
|
+
cascade?: {
|
|
16
|
+
onDelete?: CascadingSetup;
|
|
17
|
+
onUpdate?: CascadingSetup;
|
|
15
18
|
};
|
|
16
19
|
}
|
|
17
20
|
declare function Relation(theModel: () => OpModelType<RWSModel<any>>, relationOptions?: Partial<IRelationOpts>): (target: any, key: string) => void;
|
|
18
21
|
export default Relation;
|
|
19
|
-
export { IRelationOpts };
|
|
@@ -12,8 +12,15 @@ function Relation(theModel, relationOptions = _DEFAULTS) {
|
|
|
12
12
|
cascade: relationOptions.cascade || _DEFAULTS.cascade,
|
|
13
13
|
relatedTo,
|
|
14
14
|
relationField: relationOptions.relationField ? relationOptions.relationField : relatedTo._collection + '_id',
|
|
15
|
-
key
|
|
15
|
+
key,
|
|
16
|
+
// Generate a unique relation name if one is not provided
|
|
17
|
+
relationName: relationOptions.relationName ?
|
|
18
|
+
relationOptions.relationName.toLowerCase() :
|
|
19
|
+
`${target.constructor.name.toLowerCase()}_${key}_${relatedTo._collection.toLowerCase()}`
|
|
16
20
|
};
|
|
21
|
+
if (relationOptions.required) {
|
|
22
|
+
metaOpts.cascade.onDelete = 'Restrict';
|
|
23
|
+
}
|
|
17
24
|
return metaOpts;
|
|
18
25
|
});
|
|
19
26
|
// Store both the promise and the key information
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import {
|
|
3
|
-
interface ITrackerOpts {
|
|
4
|
-
required?: boolean;
|
|
5
|
-
isArray?: boolean;
|
|
6
|
-
relationField?: string;
|
|
7
|
-
relatedToField?: string;
|
|
8
|
-
relatedTo?: OpModelType<any>;
|
|
9
|
-
inversionModel?: OpModelType<any>;
|
|
10
|
-
relationName?: string;
|
|
11
|
-
}
|
|
12
|
-
interface IMetaOpts extends ITrackerOpts {
|
|
2
|
+
import { ITrackerOpts } from '../models/interfaces/ITrackerOpts';
|
|
3
|
+
export interface ITrackerMetaOpts extends ITrackerOpts {
|
|
13
4
|
type: any;
|
|
14
5
|
tags: string[];
|
|
15
|
-
required: boolean;
|
|
16
|
-
isArray: boolean;
|
|
17
6
|
}
|
|
18
7
|
declare function TrackType(type: any, opts?: ITrackerOpts | null, tags?: string[]): (target: any, key: string) => void;
|
|
19
8
|
export default TrackType;
|
|
20
|
-
export { IMetaOpts, ITrackerOpts };
|
|
@@ -30,6 +30,13 @@ function TrackType(type, opts = null, tags = []) {
|
|
|
30
30
|
if (opts.inversionModel) {
|
|
31
31
|
metaOpts.inversionModel = opts.inversionModel;
|
|
32
32
|
}
|
|
33
|
+
// Copy dbOptions if present
|
|
34
|
+
if (opts.dbOptions) {
|
|
35
|
+
metaOpts.dbOptions = opts.dbOptions;
|
|
36
|
+
}
|
|
37
|
+
if (opts.unique) {
|
|
38
|
+
metaOpts.unique = opts.unique;
|
|
39
|
+
}
|
|
33
40
|
//const resolvedType = typeof type === 'function' ? type() : type;
|
|
34
41
|
if (type._collection) {
|
|
35
42
|
metaOpts.type = type;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { ITrackerOpts } from './TrackType';
|
|
3
|
+
/**
|
|
4
|
+
* Type function options interface
|
|
5
|
+
*/
|
|
6
|
+
interface ITypeFunctionOpts extends ITrackerOpts {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* String type function
|
|
10
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
11
|
+
*/
|
|
12
|
+
declare function StringType(optsOrRequired?: ITypeFunctionOpts | boolean): PropertyDecorator;
|
|
13
|
+
/**
|
|
14
|
+
* Number type function
|
|
15
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
16
|
+
*/
|
|
17
|
+
declare function NumberType(optsOrRequired?: ITypeFunctionOpts | boolean): PropertyDecorator;
|
|
18
|
+
/**
|
|
19
|
+
* Boolean type function
|
|
20
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
21
|
+
*/
|
|
22
|
+
declare function BooleanType(optsOrRequired?: ITypeFunctionOpts | boolean): PropertyDecorator;
|
|
23
|
+
/**
|
|
24
|
+
* Date type function
|
|
25
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
26
|
+
*/
|
|
27
|
+
declare function DateType(optsOrRequired?: ITypeFunctionOpts | boolean): PropertyDecorator;
|
|
28
|
+
/**
|
|
29
|
+
* Object type function (maps to JSON in databases)
|
|
30
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
31
|
+
*/
|
|
32
|
+
declare function ObjectType(optsOrRequired?: ITypeFunctionOpts | boolean): PropertyDecorator;
|
|
33
|
+
/**
|
|
34
|
+
* Array type function
|
|
35
|
+
* @param itemType Type of array items
|
|
36
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
37
|
+
*/
|
|
38
|
+
declare function ArrayType(itemType: any, optsOrRequired?: ITypeFunctionOpts | boolean): PropertyDecorator;
|
|
39
|
+
/**
|
|
40
|
+
* ID type function
|
|
41
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
42
|
+
*/
|
|
43
|
+
declare function IdType(optsOrRequired?: ITypeFunctionOpts | boolean): PropertyDecorator;
|
|
44
|
+
export { StringType, NumberType, BooleanType, DateType, ObjectType, ArrayType, IdType, ITypeFunctionOpts };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StringType = StringType;
|
|
7
|
+
exports.NumberType = NumberType;
|
|
8
|
+
exports.BooleanType = BooleanType;
|
|
9
|
+
exports.DateType = DateType;
|
|
10
|
+
exports.ObjectType = ObjectType;
|
|
11
|
+
exports.ArrayType = ArrayType;
|
|
12
|
+
exports.IdType = IdType;
|
|
13
|
+
require("reflect-metadata");
|
|
14
|
+
const TrackType_1 = __importDefault(require("./TrackType"));
|
|
15
|
+
/**
|
|
16
|
+
* String type function
|
|
17
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
18
|
+
*/
|
|
19
|
+
function StringType(optsOrRequired) {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f;
|
|
21
|
+
let opts = {};
|
|
22
|
+
if (typeof optsOrRequired === 'boolean') {
|
|
23
|
+
opts.required = optsOrRequired;
|
|
24
|
+
}
|
|
25
|
+
else if (optsOrRequired) {
|
|
26
|
+
opts = optsOrRequired;
|
|
27
|
+
}
|
|
28
|
+
const tags = [];
|
|
29
|
+
// Add database-specific tags based on options
|
|
30
|
+
if ((_b = (_a = opts.dbOptions) === null || _a === void 0 ? void 0 : _a.mysql) === null || _b === void 0 ? void 0 : _b.useText) {
|
|
31
|
+
tags.push('db.Text');
|
|
32
|
+
}
|
|
33
|
+
else if ((_d = (_c = opts.dbOptions) === null || _c === void 0 ? void 0 : _c.mysql) === null || _d === void 0 ? void 0 : _d.maxLength) {
|
|
34
|
+
tags.push(`db.VarChar(${opts.dbOptions.mysql.maxLength})`);
|
|
35
|
+
}
|
|
36
|
+
if ((_f = (_e = opts.dbOptions) === null || _e === void 0 ? void 0 : _e.postgres) === null || _f === void 0 ? void 0 : _f.useText) {
|
|
37
|
+
tags.push('db.Text');
|
|
38
|
+
}
|
|
39
|
+
// Return a property decorator that calls TrackType
|
|
40
|
+
return function (target, propertyKey) {
|
|
41
|
+
if (typeof propertyKey === 'string') {
|
|
42
|
+
(0, TrackType_1.default)(String, opts, tags)(target, propertyKey);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Number type function
|
|
48
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
49
|
+
*/
|
|
50
|
+
function NumberType(optsOrRequired) {
|
|
51
|
+
let opts = {};
|
|
52
|
+
if (typeof optsOrRequired === 'boolean') {
|
|
53
|
+
opts.required = optsOrRequired;
|
|
54
|
+
}
|
|
55
|
+
else if (optsOrRequired) {
|
|
56
|
+
opts = optsOrRequired;
|
|
57
|
+
}
|
|
58
|
+
// Return a property decorator that calls TrackType
|
|
59
|
+
return function (target, propertyKey) {
|
|
60
|
+
if (typeof propertyKey === 'string') {
|
|
61
|
+
(0, TrackType_1.default)(Number, opts)(target, propertyKey);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Boolean type function
|
|
67
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
68
|
+
*/
|
|
69
|
+
function BooleanType(optsOrRequired) {
|
|
70
|
+
let opts = {};
|
|
71
|
+
if (typeof optsOrRequired === 'boolean') {
|
|
72
|
+
opts.required = optsOrRequired;
|
|
73
|
+
}
|
|
74
|
+
else if (optsOrRequired) {
|
|
75
|
+
opts = optsOrRequired;
|
|
76
|
+
}
|
|
77
|
+
// Return a property decorator that calls TrackType
|
|
78
|
+
return function (target, propertyKey) {
|
|
79
|
+
if (typeof propertyKey === 'string') {
|
|
80
|
+
(0, TrackType_1.default)(Boolean, opts)(target, propertyKey);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Date type function
|
|
86
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
87
|
+
*/
|
|
88
|
+
function DateType(optsOrRequired) {
|
|
89
|
+
let opts = {};
|
|
90
|
+
if (typeof optsOrRequired === 'boolean') {
|
|
91
|
+
opts.required = optsOrRequired;
|
|
92
|
+
}
|
|
93
|
+
else if (optsOrRequired) {
|
|
94
|
+
opts = optsOrRequired;
|
|
95
|
+
}
|
|
96
|
+
// Return a property decorator that calls TrackType
|
|
97
|
+
return function (target, propertyKey) {
|
|
98
|
+
if (typeof propertyKey === 'string') {
|
|
99
|
+
(0, TrackType_1.default)(Date, opts)(target, propertyKey);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Object type function (maps to JSON in databases)
|
|
105
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
106
|
+
*/
|
|
107
|
+
function ObjectType(optsOrRequired) {
|
|
108
|
+
let opts = {};
|
|
109
|
+
if (typeof optsOrRequired === 'boolean') {
|
|
110
|
+
opts.required = optsOrRequired;
|
|
111
|
+
}
|
|
112
|
+
else if (optsOrRequired) {
|
|
113
|
+
opts = optsOrRequired;
|
|
114
|
+
}
|
|
115
|
+
// Return a property decorator that calls TrackType
|
|
116
|
+
return function (target, propertyKey) {
|
|
117
|
+
if (typeof propertyKey === 'string') {
|
|
118
|
+
(0, TrackType_1.default)(Object, opts)(target, propertyKey);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Array type function
|
|
124
|
+
* @param itemType Type of array items
|
|
125
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
126
|
+
*/
|
|
127
|
+
function ArrayType(itemType, optsOrRequired) {
|
|
128
|
+
let opts = { isArray: true };
|
|
129
|
+
if (typeof optsOrRequired === 'boolean') {
|
|
130
|
+
opts.required = optsOrRequired;
|
|
131
|
+
}
|
|
132
|
+
else if (optsOrRequired) {
|
|
133
|
+
opts = { ...optsOrRequired, isArray: true };
|
|
134
|
+
}
|
|
135
|
+
// Return a property decorator that calls TrackType
|
|
136
|
+
return function (target, propertyKey) {
|
|
137
|
+
if (typeof propertyKey === 'string') {
|
|
138
|
+
(0, TrackType_1.default)(itemType, opts)(target, propertyKey);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* ID type function
|
|
144
|
+
* @param optsOrRequired Options object or boolean indicating if field is required
|
|
145
|
+
*/
|
|
146
|
+
function IdType(optsOrRequired) {
|
|
147
|
+
var _a, _b, _c, _d;
|
|
148
|
+
let opts = {};
|
|
149
|
+
if (typeof optsOrRequired === 'boolean') {
|
|
150
|
+
opts.required = optsOrRequired;
|
|
151
|
+
}
|
|
152
|
+
else if (optsOrRequired) {
|
|
153
|
+
opts = optsOrRequired;
|
|
154
|
+
}
|
|
155
|
+
const tags = ['id'];
|
|
156
|
+
// Add database-specific tags based on options
|
|
157
|
+
if ((_b = (_a = opts.dbOptions) === null || _a === void 0 ? void 0 : _a.postgres) === null || _b === void 0 ? void 0 : _b.useUuid) {
|
|
158
|
+
tags.push('default(uuid())');
|
|
159
|
+
}
|
|
160
|
+
else if ((_d = (_c = opts.dbOptions) === null || _c === void 0 ? void 0 : _c.mysql) === null || _d === void 0 ? void 0 : _d.useUuid) {
|
|
161
|
+
tags.push('default(uuid())');
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
tags.push('default(autoincrement())');
|
|
165
|
+
}
|
|
166
|
+
// Return a property decorator that calls TrackType
|
|
167
|
+
return function (target, propertyKey) {
|
|
168
|
+
var _a, _b, _c, _d;
|
|
169
|
+
if (typeof propertyKey === 'string') {
|
|
170
|
+
const type = ((_b = (_a = opts.dbOptions) === null || _a === void 0 ? void 0 : _a.postgres) === null || _b === void 0 ? void 0 : _b.useUuid) || ((_d = (_c = opts.dbOptions) === null || _c === void 0 ? void 0 : _c.mysql) === null || _d === void 0 ? void 0 : _d.useUuid) ? String : Number;
|
|
171
|
+
(0, TrackType_1.default)(type, opts, tags)(target, propertyKey);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import InverseRelation from './InverseRelation';
|
|
2
2
|
import Relation from './Relation';
|
|
3
|
-
import TrackType, {
|
|
3
|
+
import TrackType, { ITrackerMetaOpts } from './TrackType';
|
|
4
4
|
import InverseTimeSeries from './InverseTimeSeries';
|
|
5
|
-
|
|
5
|
+
import IdType from './IdType';
|
|
6
|
+
import { ITrackerOpts } from '../models/interfaces/ITrackerOpts';
|
|
7
|
+
export { InverseRelation, Relation, TrackType, IdType, InverseTimeSeries, ITrackerMetaOpts, ITrackerOpts };
|
package/dist/decorators/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.InverseTimeSeries = exports.TrackType = exports.Relation = exports.InverseRelation = void 0;
|
|
6
|
+
exports.InverseTimeSeries = exports.IdType = exports.TrackType = exports.Relation = exports.InverseRelation = void 0;
|
|
7
7
|
const InverseRelation_1 = __importDefault(require("./InverseRelation"));
|
|
8
8
|
exports.InverseRelation = InverseRelation_1.default;
|
|
9
9
|
const Relation_1 = __importDefault(require("./Relation"));
|
|
@@ -12,3 +12,5 @@ const TrackType_1 = __importDefault(require("./TrackType"));
|
|
|
12
12
|
exports.TrackType = TrackType_1.default;
|
|
13
13
|
const InverseTimeSeries_1 = __importDefault(require("./InverseTimeSeries"));
|
|
14
14
|
exports.InverseTimeSeries = InverseTimeSeries_1.default;
|
|
15
|
+
const IdType_1 = __importDefault(require("./IdType"));
|
|
16
|
+
exports.IdType = IdType_1.default;
|
|
@@ -1,12 +1,83 @@
|
|
|
1
|
-
import { IDbConfigHandler, IDbConfigParams
|
|
2
|
-
import {
|
|
1
|
+
import { IDbConfigHandler, IDbConfigParams } from '../types/DbConfigHandler';
|
|
2
|
+
import { OpModelType } from '../models/_model';
|
|
3
3
|
import { DBService } from '../services/DBService';
|
|
4
|
+
import { IIdMetaOpts } from '../decorators/IdType';
|
|
5
|
+
/**
|
|
6
|
+
* Database helper class
|
|
7
|
+
*
|
|
8
|
+
* This class provides a facade for the database helper modules.
|
|
9
|
+
* It delegates to the specialized modules for specific functionality.
|
|
10
|
+
*/
|
|
4
11
|
export declare class DbHelper {
|
|
12
|
+
/**
|
|
13
|
+
* The environment variable name for the Prisma database URL
|
|
14
|
+
*/
|
|
5
15
|
static dbUrlVarName: string;
|
|
16
|
+
/**
|
|
17
|
+
* Install Prisma with the generated schema
|
|
18
|
+
* @param configService The configuration service
|
|
19
|
+
* @param dbService The database service
|
|
20
|
+
* @param leaveFile Whether to leave the schema file after generation
|
|
21
|
+
*/
|
|
6
22
|
static installPrisma(configService: IDbConfigHandler, dbService: DBService, leaveFile?: boolean): Promise<void>;
|
|
7
|
-
|
|
8
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Push database models to the database
|
|
25
|
+
* @param configService The configuration service
|
|
26
|
+
* @param dbService The database service
|
|
27
|
+
* @param leaveFile Whether to leave the schema file after generation
|
|
28
|
+
*/
|
|
9
29
|
static pushDBModels(configService: IDbConfigHandler, dbService: DBService, leaveFile?: boolean): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Generate model sections for the schema
|
|
32
|
+
* @param model The model to generate a section for
|
|
33
|
+
* @param configService The configuration service
|
|
34
|
+
* @returns The model section
|
|
35
|
+
*/
|
|
10
36
|
static generateModelSections(model: OpModelType<any>, configService: IDbConfigHandler): Promise<string>;
|
|
11
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Generate the base schema for Prisma
|
|
39
|
+
* @param dbType The database type
|
|
40
|
+
* @param dbUrl The database URL
|
|
41
|
+
* @returns The base schema
|
|
42
|
+
*/
|
|
43
|
+
static generateBaseSchema(dbType: string, dbUrl: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Get the directory and path for the Prisma schema file
|
|
46
|
+
*/
|
|
47
|
+
static getSchemaDir(): [string, string];
|
|
48
|
+
/**
|
|
49
|
+
* Detect the package installer (yarn or npx)
|
|
50
|
+
*/
|
|
51
|
+
static detectInstaller(): string;
|
|
52
|
+
/**
|
|
53
|
+
* Generate an ID field based on the database type
|
|
54
|
+
*/
|
|
55
|
+
static generateId(dbType: IDbConfigParams['db_type'], modelMeta: Record<string, {
|
|
56
|
+
annotationType: string;
|
|
57
|
+
metadata: IIdMetaOpts;
|
|
58
|
+
}>): string;
|
|
59
|
+
/**
|
|
60
|
+
* Convert a JavaScript type to a Prisma schema type
|
|
61
|
+
*/
|
|
62
|
+
static toConfigCase(modelType: any, dbType?: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Process type functions metadata to extract database-specific options
|
|
65
|
+
*/
|
|
66
|
+
static processTypeOptions(metadata: any, dbType: string): string[];
|
|
67
|
+
/**
|
|
68
|
+
* Mark a relation between two models
|
|
69
|
+
*/
|
|
70
|
+
static markRelation(relationKey: string, inverse?: boolean): void;
|
|
71
|
+
/**
|
|
72
|
+
* Complete a relation between two models
|
|
73
|
+
*/
|
|
74
|
+
static completeRelation(relationKey: string, index: number, inverse?: boolean): void;
|
|
75
|
+
/**
|
|
76
|
+
* Get a unique counter for a relation between two models
|
|
77
|
+
*/
|
|
78
|
+
static getRelationCounter(relationKey: string, inverse?: boolean): number;
|
|
79
|
+
/**
|
|
80
|
+
* Generate a shortened relation name to stay within database limits
|
|
81
|
+
*/
|
|
82
|
+
static getShortenedRelationName(modelName: string, relatedModelName: string, index: number): string;
|
|
12
83
|
}
|