@rws-framework/db 2.3.2 → 2.4.1
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 -367
- package/dist/decorators/InverseRelation.d.ts +0 -0
- package/dist/decorators/InverseRelation.js +0 -0
- package/dist/decorators/InverseTimeSeries.d.ts +0 -0
- package/dist/decorators/InverseTimeSeries.js +0 -0
- package/dist/decorators/RWSCollection.d.ts +0 -0
- package/dist/decorators/RWSCollection.js +0 -0
- package/dist/decorators/Relation.d.ts +0 -0
- package/dist/decorators/Relation.js +0 -0
- package/dist/decorators/TrackType.d.ts +0 -0
- package/dist/decorators/TrackType.js +0 -0
- package/dist/decorators/index.d.ts +0 -0
- package/dist/decorators/index.js +0 -0
- package/dist/helper/DbHelper.d.ts +0 -0
- package/dist/helper/DbHelper.js +7 -7
- package/dist/helper/FieldsHelper.d.ts +0 -0
- package/dist/helper/FieldsHelper.js +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/models/TimeSeriesModel.d.ts +7 -7
- package/dist/models/TimeSeriesModel.js +33 -33
- package/dist/models/_model.d.ts +0 -0
- package/dist/models/_model.js +0 -0
- package/dist/models/core/RWSModel.d.ts +0 -0
- package/dist/models/core/RWSModel.js +0 -0
- package/dist/models/core/TimeSeriesModel.d.ts +0 -0
- package/dist/models/core/TimeSeriesModel.js +0 -0
- package/dist/models/index.d.ts +0 -0
- package/dist/models/index.js +0 -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/OpModelType.d.ts +0 -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 +0 -0
- package/dist/models/utils/RelationUtils.js +0 -0
- package/dist/models/utils/TimeSeriesUtils.d.ts +0 -0
- package/dist/models/utils/TimeSeriesUtils.js +0 -0
- package/dist/services/DBService.d.ts +1 -1
- package/dist/services/DBService.js +6 -6
- package/dist/types/DbConfigHandler.d.ts +3 -2
- 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 +0 -0
- 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 +75 -73
- package/exec/tsconfig.json +32 -32
- package/exec/webpackFilters.js +17 -17
- package/package.json +36 -36
- package/src/decorators/InverseRelation.ts +36 -36
- package/src/decorators/InverseTimeSeries.ts +21 -21
- package/src/decorators/RWSCollection.ts +27 -27
- package/src/decorators/Relation.ts +47 -47
- package/src/decorators/TrackType.ts +69 -69
- package/src/decorators/index.ts +7 -7
- package/src/empty.js +0 -0
- package/src/helper/DbHelper.ts +177 -177
- package/src/helper/FieldsHelper.ts +34 -34
- package/src/index.ts +36 -36
- package/src/models/_model.ts +29 -29
- package/src/models/core/RWSModel.ts +520 -520
- package/src/models/core/TimeSeriesModel.ts +19 -19
- package/src/models/index.ts +20 -20
- package/src/models/interfaces/IModel.ts +12 -12
- package/src/models/interfaces/IRWSModelServices.ts +7 -7
- package/src/models/interfaces/OpModelType.ts +49 -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 +12 -11
- 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
package/src/helper/DbHelper.ts
CHANGED
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
import { rwsShell, rwsPath } from '@rws-framework/console';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
|
|
6
|
-
import { IDbConfigHandler } from '../types/DbConfigHandler';
|
|
7
|
-
import { IMetaOpts, OpModelType, RWSModel } from '../models/_model';
|
|
8
|
-
// import TimeSeriesModel from '../models/core/TimeSeriesModel';
|
|
9
|
-
import { DBService } from '../services/DBService';
|
|
10
|
-
import { IRelationOpts } from '../decorators/Relation';
|
|
11
|
-
import { InverseRelationOpts } from '../decorators/InverseRelation';
|
|
12
|
-
|
|
13
|
-
const log = console.log;
|
|
14
|
-
const workspaceRoot = rwsPath.findRootWorkspacePath();
|
|
15
|
-
const moduleDir = path.resolve(workspaceRoot, 'node_modules', '@rws-framework', 'db');
|
|
16
|
-
|
|
17
|
-
export class DbHelper {
|
|
18
|
-
static async installPrisma(configService: IDbConfigHandler, dbService: DBService, leaveFile = false): Promise<void>
|
|
19
|
-
{
|
|
20
|
-
const dbUrl = configService.get('
|
|
21
|
-
const dbType = 'mongodb';
|
|
22
|
-
|
|
23
|
-
let template: string = `generator client {\n
|
|
24
|
-
provider = "prisma-client-js"\n
|
|
25
|
-
}\n\n`;
|
|
26
|
-
|
|
27
|
-
template += `\ndatasource db {\n
|
|
28
|
-
provider = "${dbType}"\n
|
|
29
|
-
url = env("
|
|
30
|
-
}\n\n`;
|
|
31
|
-
|
|
32
|
-
const dbModels: OpModelType<unknown>[] | null = configService.get('db_models');
|
|
33
|
-
|
|
34
|
-
if(dbModels){
|
|
35
|
-
|
|
36
|
-
for (const model of dbModels){
|
|
37
|
-
const modelSection = await DbHelper.generateModelSections(model);
|
|
38
|
-
|
|
39
|
-
template += '\n\n' + modelSection;
|
|
40
|
-
|
|
41
|
-
log(chalk.green('[RWS]'), chalk.blue('Building DB Model'), model.name);
|
|
42
|
-
|
|
43
|
-
// if(RWSModel.isSubclass(model as any, TimeSeriesModel)){
|
|
44
|
-
// dbService.collectionExists(model._collection).then((exists: boolean) => {
|
|
45
|
-
// if (exists){
|
|
46
|
-
// return;
|
|
47
|
-
// }
|
|
48
|
-
|
|
49
|
-
// log(chalk.green('[RWS Init]') + ` creating TimeSeries type collection from ${model} model`);
|
|
50
|
-
|
|
51
|
-
// dbService.createTimeSeriesCollection(model._collection);
|
|
52
|
-
// });
|
|
53
|
-
// }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const schemaDir = path.join(moduleDir, 'prisma');
|
|
57
|
-
const schemaPath = path.join(schemaDir, 'schema.prisma');
|
|
58
|
-
|
|
59
|
-
if(!fs.existsSync(schemaDir)){
|
|
60
|
-
fs.mkdirSync(schemaDir);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if(fs.existsSync(schemaPath)){
|
|
64
|
-
fs.unlinkSync(schemaPath);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
fs.writeFileSync(schemaPath, template);
|
|
68
|
-
process.env.DB_URL = dbUrl;
|
|
69
|
-
const endPrisma = 'npx prisma';
|
|
70
|
-
|
|
71
|
-
// console.log({cwd: process.cwd()})
|
|
72
|
-
// const clientPath = path.join(rwsPath.findRootWorkspacePath(), 'node_modules', '.prisma', 'client');
|
|
73
|
-
await rwsShell.runCommand(`${endPrisma} generate --schema=${schemaPath}`, process.cwd());
|
|
74
|
-
|
|
75
|
-
leaveFile = false;
|
|
76
|
-
log(chalk.green('[RWS Init]') + ' prisma schema generated from ', schemaPath);
|
|
77
|
-
|
|
78
|
-
if(!leaveFile){
|
|
79
|
-
fs.unlinkSync(schemaPath);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static async generateModelSections(model: OpModelType<any>): Promise<string> {
|
|
85
|
-
let section = '';
|
|
86
|
-
const modelMetadatas: Record<string, {annotationType: string, metadata: any}> = await RWSModel.getModelAnnotations(model);
|
|
87
|
-
|
|
88
|
-
const modelName: string = (model as any)._collection;
|
|
89
|
-
|
|
90
|
-
section += `model ${modelName} {\n`;
|
|
91
|
-
section += '\tid String @map("_id") @id @default(auto()) @db.ObjectId\n';
|
|
92
|
-
|
|
93
|
-
for (const key in modelMetadatas) {
|
|
94
|
-
const modelMetadata = modelMetadatas[key].metadata;
|
|
95
|
-
let requiredString = modelMetadata.required ? '' : '?';
|
|
96
|
-
const annotationType: string = modelMetadatas[key].annotationType;
|
|
97
|
-
|
|
98
|
-
if(key === 'id'){
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if(annotationType === 'Relation'){
|
|
104
|
-
const relationMeta = modelMetadata as IRelationOpts
|
|
105
|
-
|
|
106
|
-
const relatedModel = relationMeta.relatedTo as OpModelType<any>;
|
|
107
|
-
const isMany = relationMeta.many;
|
|
108
|
-
const cascadeOpts = [];
|
|
109
|
-
|
|
110
|
-
if (relationMeta.cascade?.onDelete) {
|
|
111
|
-
cascadeOpts.push(`onDelete: ${relationMeta.cascade.onDelete}`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (relationMeta.cascade?.onUpdate) {
|
|
115
|
-
cascadeOpts.push(`onUpdate: ${relationMeta.cascade.onUpdate}`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (isMany) {
|
|
119
|
-
// Handle many-to-many or one-to-many relation
|
|
120
|
-
section += `\t${key} ${relatedModel._collection}[] @relation("${modelName}_${relatedModel._collection}")\n`;
|
|
121
|
-
} else {
|
|
122
|
-
// Handle one-to-one or many-to-one relation
|
|
123
|
-
section += `\t${key} ${relatedModel._collection}${requiredString} @relation("${modelName}_${relatedModel._collection}", fields: [${modelMetadata.relationField}], references: [${modelMetadata.relatedToField || 'id'}], ${cascadeOpts.join(', ')})\n`;
|
|
124
|
-
section += `\t${modelMetadata.relationField} String${requiredString} @db.ObjectId\n`;
|
|
125
|
-
}
|
|
126
|
-
} else if (annotationType === 'InverseRelation'){
|
|
127
|
-
const relationMeta = modelMetadata as InverseRelationOpts;
|
|
128
|
-
|
|
129
|
-
// Handle inverse relation (one-to-many or one-to-one)
|
|
130
|
-
section += `\t${key} ${relationMeta.inversionModel._collection}[] @relation("${ relationMeta.relationName ? relationMeta.relationName : `${relationMeta.inversionModel._collection}_${modelName}`}")\n`;
|
|
131
|
-
} else if (annotationType === 'InverseTimeSeries'){
|
|
132
|
-
section += `\t${key} String[] @db.ObjectId\n`;
|
|
133
|
-
} else if (annotationType === 'TrackType'){
|
|
134
|
-
const tags: string[] = modelMetadata.tags.map((item: string) => '@' + item);
|
|
135
|
-
|
|
136
|
-
if(modelMetadata.isArray || modelMetadata.type.name === 'Array'){
|
|
137
|
-
requiredString = '';
|
|
138
|
-
}
|
|
139
|
-
section += `\t${key} ${DbHelper.toConfigCase(modelMetadata)}${requiredString} ${tags.join(' ')}\n`;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
section += '}\n';
|
|
144
|
-
return section;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
static toConfigCase(modelType: IMetaOpts): string {
|
|
148
|
-
const type = modelType.type;
|
|
149
|
-
let input = type.name;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if(input == 'Number'){
|
|
153
|
-
input = 'Int';
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if(input == 'Object'){
|
|
157
|
-
input = 'Json';
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if(input == 'Date'){
|
|
161
|
-
input = 'DateTime';
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if(input == 'Array'){
|
|
165
|
-
input = 'Json[]';
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const firstChar = input.charAt(0).toUpperCase();
|
|
169
|
-
const restOfString = input.slice(1);
|
|
170
|
-
let resultField = firstChar + restOfString;
|
|
171
|
-
|
|
172
|
-
if(modelType.isArray){
|
|
173
|
-
resultField += '[]';
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return resultField;
|
|
177
|
-
}
|
|
1
|
+
import { rwsShell, rwsPath } from '@rws-framework/console';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
|
|
6
|
+
import { IDbConfigHandler } from '../types/DbConfigHandler';
|
|
7
|
+
import { IMetaOpts, OpModelType, RWSModel } from '../models/_model';
|
|
8
|
+
// import TimeSeriesModel from '../models/core/TimeSeriesModel';
|
|
9
|
+
import { DBService } from '../services/DBService';
|
|
10
|
+
import { IRelationOpts } from '../decorators/Relation';
|
|
11
|
+
import { InverseRelationOpts } from '../decorators/InverseRelation';
|
|
12
|
+
|
|
13
|
+
const log = console.log;
|
|
14
|
+
const workspaceRoot = rwsPath.findRootWorkspacePath();
|
|
15
|
+
const moduleDir = path.resolve(workspaceRoot, 'node_modules', '@rws-framework', 'db');
|
|
16
|
+
|
|
17
|
+
export class DbHelper {
|
|
18
|
+
static async installPrisma(configService: IDbConfigHandler, dbService: DBService, leaveFile = false): Promise<void>
|
|
19
|
+
{
|
|
20
|
+
const dbUrl = configService.get('db_url');
|
|
21
|
+
const dbType = configService.get('db_type') || 'mongodb';
|
|
22
|
+
|
|
23
|
+
let template: string = `generator client {\n
|
|
24
|
+
provider = "prisma-client-js"\n
|
|
25
|
+
}\n\n`;
|
|
26
|
+
|
|
27
|
+
template += `\ndatasource db {\n
|
|
28
|
+
provider = "${dbType}"\n
|
|
29
|
+
url = env("PRISMA_DB_URL")\n
|
|
30
|
+
}\n\n`;
|
|
31
|
+
|
|
32
|
+
const dbModels: OpModelType<unknown>[] | null = configService.get('db_models');
|
|
33
|
+
|
|
34
|
+
if(dbModels){
|
|
35
|
+
|
|
36
|
+
for (const model of dbModels){
|
|
37
|
+
const modelSection = await DbHelper.generateModelSections(model);
|
|
38
|
+
|
|
39
|
+
template += '\n\n' + modelSection;
|
|
40
|
+
|
|
41
|
+
log(chalk.green('[RWS]'), chalk.blue('Building DB Model'), model.name);
|
|
42
|
+
|
|
43
|
+
// if(RWSModel.isSubclass(model as any, TimeSeriesModel)){
|
|
44
|
+
// dbService.collectionExists(model._collection).then((exists: boolean) => {
|
|
45
|
+
// if (exists){
|
|
46
|
+
// return;
|
|
47
|
+
// }
|
|
48
|
+
|
|
49
|
+
// log(chalk.green('[RWS Init]') + ` creating TimeSeries type collection from ${model} model`);
|
|
50
|
+
|
|
51
|
+
// dbService.createTimeSeriesCollection(model._collection);
|
|
52
|
+
// });
|
|
53
|
+
// }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const schemaDir = path.join(moduleDir, 'prisma');
|
|
57
|
+
const schemaPath = path.join(schemaDir, 'schema.prisma');
|
|
58
|
+
|
|
59
|
+
if(!fs.existsSync(schemaDir)){
|
|
60
|
+
fs.mkdirSync(schemaDir);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if(fs.existsSync(schemaPath)){
|
|
64
|
+
fs.unlinkSync(schemaPath);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fs.writeFileSync(schemaPath, template);
|
|
68
|
+
process.env.DB_URL = dbUrl;
|
|
69
|
+
const endPrisma = 'npx prisma';
|
|
70
|
+
|
|
71
|
+
// console.log({cwd: process.cwd()})
|
|
72
|
+
// const clientPath = path.join(rwsPath.findRootWorkspacePath(), 'node_modules', '.prisma', 'client');
|
|
73
|
+
await rwsShell.runCommand(`${endPrisma} generate --schema=${schemaPath}`, process.cwd());
|
|
74
|
+
|
|
75
|
+
leaveFile = false;
|
|
76
|
+
log(chalk.green('[RWS Init]') + ' prisma schema generated from ', schemaPath);
|
|
77
|
+
|
|
78
|
+
if(!leaveFile){
|
|
79
|
+
fs.unlinkSync(schemaPath);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static async generateModelSections(model: OpModelType<any>): Promise<string> {
|
|
85
|
+
let section = '';
|
|
86
|
+
const modelMetadatas: Record<string, {annotationType: string, metadata: any}> = await RWSModel.getModelAnnotations(model);
|
|
87
|
+
|
|
88
|
+
const modelName: string = (model as any)._collection;
|
|
89
|
+
|
|
90
|
+
section += `model ${modelName} {\n`;
|
|
91
|
+
section += '\tid String @map("_id") @id @default(auto()) @db.ObjectId\n';
|
|
92
|
+
|
|
93
|
+
for (const key in modelMetadatas) {
|
|
94
|
+
const modelMetadata = modelMetadatas[key].metadata;
|
|
95
|
+
let requiredString = modelMetadata.required ? '' : '?';
|
|
96
|
+
const annotationType: string = modelMetadatas[key].annotationType;
|
|
97
|
+
|
|
98
|
+
if(key === 'id'){
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
if(annotationType === 'Relation'){
|
|
104
|
+
const relationMeta = modelMetadata as IRelationOpts
|
|
105
|
+
|
|
106
|
+
const relatedModel = relationMeta.relatedTo as OpModelType<any>;
|
|
107
|
+
const isMany = relationMeta.many;
|
|
108
|
+
const cascadeOpts = [];
|
|
109
|
+
|
|
110
|
+
if (relationMeta.cascade?.onDelete) {
|
|
111
|
+
cascadeOpts.push(`onDelete: ${relationMeta.cascade.onDelete}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (relationMeta.cascade?.onUpdate) {
|
|
115
|
+
cascadeOpts.push(`onUpdate: ${relationMeta.cascade.onUpdate}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (isMany) {
|
|
119
|
+
// Handle many-to-many or one-to-many relation
|
|
120
|
+
section += `\t${key} ${relatedModel._collection}[] @relation("${modelName}_${relatedModel._collection}")\n`;
|
|
121
|
+
} else {
|
|
122
|
+
// Handle one-to-one or many-to-one relation
|
|
123
|
+
section += `\t${key} ${relatedModel._collection}${requiredString} @relation("${modelName}_${relatedModel._collection}", fields: [${modelMetadata.relationField}], references: [${modelMetadata.relatedToField || 'id'}], ${cascadeOpts.join(', ')})\n`;
|
|
124
|
+
section += `\t${modelMetadata.relationField} String${requiredString} @db.ObjectId\n`;
|
|
125
|
+
}
|
|
126
|
+
} else if (annotationType === 'InverseRelation'){
|
|
127
|
+
const relationMeta = modelMetadata as InverseRelationOpts;
|
|
128
|
+
|
|
129
|
+
// Handle inverse relation (one-to-many or one-to-one)
|
|
130
|
+
section += `\t${key} ${relationMeta.inversionModel._collection}[] @relation("${ relationMeta.relationName ? relationMeta.relationName : `${relationMeta.inversionModel._collection}_${modelName}`}")\n`;
|
|
131
|
+
} else if (annotationType === 'InverseTimeSeries'){
|
|
132
|
+
section += `\t${key} String[] @db.ObjectId\n`;
|
|
133
|
+
} else if (annotationType === 'TrackType'){
|
|
134
|
+
const tags: string[] = modelMetadata.tags.map((item: string) => '@' + item);
|
|
135
|
+
|
|
136
|
+
if(modelMetadata.isArray || modelMetadata.type.name === 'Array'){
|
|
137
|
+
requiredString = '';
|
|
138
|
+
}
|
|
139
|
+
section += `\t${key} ${DbHelper.toConfigCase(modelMetadata)}${requiredString} ${tags.join(' ')}\n`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
section += '}\n';
|
|
144
|
+
return section;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static toConfigCase(modelType: IMetaOpts): string {
|
|
148
|
+
const type = modelType.type;
|
|
149
|
+
let input = type.name;
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if(input == 'Number'){
|
|
153
|
+
input = 'Int';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if(input == 'Object'){
|
|
157
|
+
input = 'Json';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if(input == 'Date'){
|
|
161
|
+
input = 'DateTime';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if(input == 'Array'){
|
|
165
|
+
input = 'Json[]';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const firstChar = input.charAt(0).toUpperCase();
|
|
169
|
+
const restOfString = input.slice(1);
|
|
170
|
+
let resultField = firstChar + restOfString;
|
|
171
|
+
|
|
172
|
+
if(modelType.isArray){
|
|
173
|
+
resultField += '[]';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return resultField;
|
|
177
|
+
}
|
|
178
178
|
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
export class FieldsHelper {
|
|
2
|
-
private constructor(){
|
|
3
|
-
throw new Error(`Class ${this.constructor.name} cannot be instanced.`)
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
static getAllClassFields(target: any): string[] {
|
|
7
|
-
// Get instance properties
|
|
8
|
-
const instanceFields = Object.getOwnPropertyNames(target.prototype);
|
|
9
|
-
|
|
10
|
-
// Get static properties
|
|
11
|
-
const staticFields = Object.getOwnPropertyNames(target);
|
|
12
|
-
|
|
13
|
-
// Get decorated properties using Reflect metadata if available
|
|
14
|
-
const decoratedFields = Reflect.getMetadataKeys(target.prototype) || [];
|
|
15
|
-
|
|
16
|
-
// Combine all fields and remove duplicates and methods
|
|
17
|
-
const allFields = new Set([
|
|
18
|
-
...instanceFields,
|
|
19
|
-
...staticFields,
|
|
20
|
-
...decoratedFields
|
|
21
|
-
]);
|
|
22
|
-
|
|
23
|
-
// Filter out constructor and methods
|
|
24
|
-
return Array.from(allFields).filter(field => {
|
|
25
|
-
// Remove constructor
|
|
26
|
-
if (field === 'constructor') return false;
|
|
27
|
-
|
|
28
|
-
// Remove methods
|
|
29
|
-
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, field);
|
|
30
|
-
if (descriptor && typeof descriptor.value === 'function') return false;
|
|
31
|
-
|
|
32
|
-
return true;
|
|
33
|
-
});
|
|
34
|
-
};
|
|
1
|
+
export class FieldsHelper {
|
|
2
|
+
private constructor(){
|
|
3
|
+
throw new Error(`Class ${this.constructor.name} cannot be instanced.`)
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
static getAllClassFields(target: any): string[] {
|
|
7
|
+
// Get instance properties
|
|
8
|
+
const instanceFields = Object.getOwnPropertyNames(target.prototype);
|
|
9
|
+
|
|
10
|
+
// Get static properties
|
|
11
|
+
const staticFields = Object.getOwnPropertyNames(target);
|
|
12
|
+
|
|
13
|
+
// Get decorated properties using Reflect metadata if available
|
|
14
|
+
const decoratedFields = Reflect.getMetadataKeys(target.prototype) || [];
|
|
15
|
+
|
|
16
|
+
// Combine all fields and remove duplicates and methods
|
|
17
|
+
const allFields = new Set([
|
|
18
|
+
...instanceFields,
|
|
19
|
+
...staticFields,
|
|
20
|
+
...decoratedFields
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
// Filter out constructor and methods
|
|
24
|
+
return Array.from(allFields).filter(field => {
|
|
25
|
+
// Remove constructor
|
|
26
|
+
if (field === 'constructor') return false;
|
|
27
|
+
|
|
28
|
+
// Remove methods
|
|
29
|
+
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, field);
|
|
30
|
+
if (descriptor && typeof descriptor.value === 'function') return false;
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
35
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { DBService } from "./services/DBService";
|
|
2
|
-
import { RWSModel, OpModelType } from "./models/_model";
|
|
3
|
-
// import TimeSeriesModel from './models/core/TimeSeriesModel';
|
|
4
|
-
import { InverseRelation, Relation, TrackType, InverseTimeSeries, IMetaOpts } from './decorators';
|
|
5
|
-
|
|
6
|
-
import { DbHelper } from './helper/DbHelper';
|
|
7
|
-
import { FieldsHelper } from './helper/FieldsHelper';
|
|
8
|
-
|
|
9
|
-
import type { FindByType } from './types/FindParams';
|
|
10
|
-
import type { ITimeSeries } from './types/ITimeSeries';
|
|
11
|
-
import type { IDbConfigHandler } from './types/DbConfigHandler';
|
|
12
|
-
import type { IRWSModel } from './types/IRWSModel';
|
|
13
|
-
import { RWSCollection, IRWSCollectionMeta, IRWSCollectionOpts } from "./decorators/RWSCollection";
|
|
14
|
-
|
|
15
|
-
export type {
|
|
16
|
-
IRWSCollectionMeta, IRWSCollectionOpts,
|
|
17
|
-
IRWSModel,
|
|
18
|
-
IMetaOpts,
|
|
19
|
-
OpModelType,
|
|
20
|
-
IDbConfigHandler,
|
|
21
|
-
ITimeSeries,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
RWSModel,
|
|
26
|
-
RWSCollection,
|
|
27
|
-
|
|
28
|
-
DBService,
|
|
29
|
-
|
|
30
|
-
FindByType,
|
|
31
|
-
// TimeSeriesModel,
|
|
32
|
-
|
|
33
|
-
InverseRelation, Relation, TrackType, InverseTimeSeries,
|
|
34
|
-
|
|
35
|
-
DbHelper,
|
|
36
|
-
FieldsHelper
|
|
1
|
+
import { DBService } from "./services/DBService";
|
|
2
|
+
import { RWSModel, OpModelType } from "./models/_model";
|
|
3
|
+
// import TimeSeriesModel from './models/core/TimeSeriesModel';
|
|
4
|
+
import { InverseRelation, Relation, TrackType, InverseTimeSeries, IMetaOpts } from './decorators';
|
|
5
|
+
|
|
6
|
+
import { DbHelper } from './helper/DbHelper';
|
|
7
|
+
import { FieldsHelper } from './helper/FieldsHelper';
|
|
8
|
+
|
|
9
|
+
import type { FindByType } from './types/FindParams';
|
|
10
|
+
import type { ITimeSeries } from './types/ITimeSeries';
|
|
11
|
+
import type { IDbConfigHandler } from './types/DbConfigHandler';
|
|
12
|
+
import type { IRWSModel } from './types/IRWSModel';
|
|
13
|
+
import { RWSCollection, IRWSCollectionMeta, IRWSCollectionOpts } from "./decorators/RWSCollection";
|
|
14
|
+
|
|
15
|
+
export type {
|
|
16
|
+
IRWSCollectionMeta, IRWSCollectionOpts,
|
|
17
|
+
IRWSModel,
|
|
18
|
+
IMetaOpts,
|
|
19
|
+
OpModelType,
|
|
20
|
+
IDbConfigHandler,
|
|
21
|
+
ITimeSeries,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
RWSModel,
|
|
26
|
+
RWSCollection,
|
|
27
|
+
|
|
28
|
+
DBService,
|
|
29
|
+
|
|
30
|
+
FindByType,
|
|
31
|
+
// TimeSeriesModel,
|
|
32
|
+
|
|
33
|
+
InverseRelation, Relation, TrackType, InverseTimeSeries,
|
|
34
|
+
|
|
35
|
+
DbHelper,
|
|
36
|
+
FieldsHelper
|
|
37
37
|
};
|
package/src/models/_model.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated This file is deprecated. Import from 'models' directory instead.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
IModel,
|
|
7
|
-
IRWSModelServices,
|
|
8
|
-
OpModelType,
|
|
9
|
-
RelationBindType,
|
|
10
|
-
RelOneMetaType,
|
|
11
|
-
RelManyMetaType,
|
|
12
|
-
RWSModel,
|
|
13
|
-
TrackType,
|
|
14
|
-
IMetaOpts
|
|
15
|
-
} from './index';
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
RWSModel,
|
|
19
|
-
TrackType
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type {
|
|
23
|
-
IModel,
|
|
24
|
-
IRWSModelServices,
|
|
25
|
-
OpModelType,
|
|
26
|
-
RelationBindType,
|
|
27
|
-
RelOneMetaType,
|
|
28
|
-
RelManyMetaType,
|
|
29
|
-
IMetaOpts
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated This file is deprecated. Import from 'models' directory instead.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
IModel,
|
|
7
|
+
IRWSModelServices,
|
|
8
|
+
OpModelType,
|
|
9
|
+
RelationBindType,
|
|
10
|
+
RelOneMetaType,
|
|
11
|
+
RelManyMetaType,
|
|
12
|
+
RWSModel,
|
|
13
|
+
TrackType,
|
|
14
|
+
IMetaOpts
|
|
15
|
+
} from './index';
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
RWSModel,
|
|
19
|
+
TrackType
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type {
|
|
23
|
+
IModel,
|
|
24
|
+
IRWSModelServices,
|
|
25
|
+
OpModelType,
|
|
26
|
+
RelationBindType,
|
|
27
|
+
RelOneMetaType,
|
|
28
|
+
RelManyMetaType,
|
|
29
|
+
IMetaOpts
|
|
30
30
|
};
|