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