@rws-framework/db 2.4.6 → 3.0.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.
Files changed (123) hide show
  1. package/.bin/add-v.sh +9 -9
  2. package/.bin/emerge.sh +10 -10
  3. package/.eslintrc.json +53 -53
  4. package/README.md +343 -405
  5. package/dist/decorators/IdType.d.ts +8 -0
  6. package/dist/decorators/IdType.js +10 -0
  7. package/dist/decorators/InverseRelation.d.ts +2 -2
  8. package/dist/decorators/InverseRelation.js +5 -1
  9. package/dist/decorators/InverseTimeSeries.d.ts +0 -0
  10. package/dist/decorators/InverseTimeSeries.js +0 -0
  11. package/dist/decorators/RWSCollection.d.ts +7 -0
  12. package/dist/decorators/RWSCollection.js +6 -0
  13. package/dist/decorators/Relation.d.ts +8 -6
  14. package/dist/decorators/Relation.js +8 -1
  15. package/dist/decorators/TrackType.d.ts +2 -14
  16. package/dist/decorators/TrackType.js +7 -0
  17. package/dist/decorators/TypeFunctions.d.ts +44 -0
  18. package/dist/decorators/TypeFunctions.js +174 -0
  19. package/dist/decorators/index.d.ts +4 -2
  20. package/dist/decorators/index.js +3 -1
  21. package/dist/helper/DbHelper.d.ts +76 -5
  22. package/dist/helper/DbHelper.js +93 -154
  23. package/dist/helper/FieldsHelper.d.ts +0 -0
  24. package/dist/helper/FieldsHelper.js +0 -0
  25. package/dist/helper/db/index.d.ts +9 -0
  26. package/dist/helper/db/index.js +18 -0
  27. package/dist/helper/db/relation-manager.d.ts +45 -0
  28. package/dist/helper/db/relation-manager.js +105 -0
  29. package/dist/helper/db/schema-generator.d.ts +37 -0
  30. package/dist/helper/db/schema-generator.js +255 -0
  31. package/dist/helper/db/type-converter.d.ts +22 -0
  32. package/dist/helper/db/type-converter.js +106 -0
  33. package/dist/helper/db/utils.d.ts +24 -0
  34. package/dist/helper/db/utils.js +99 -0
  35. package/dist/index.d.ts +3 -3
  36. package/dist/index.js +2 -1
  37. package/dist/models/TimeSeriesModel.d.ts +7 -7
  38. package/dist/models/TimeSeriesModel.js +33 -33
  39. package/dist/models/_model.d.ts +2 -2
  40. package/dist/models/_model.js +0 -0
  41. package/dist/models/core/RWSModel.d.ts +5 -2
  42. package/dist/models/core/RWSModel.js +8 -5
  43. package/dist/models/core/TimeSeriesModel.d.ts +0 -0
  44. package/dist/models/core/TimeSeriesModel.js +0 -0
  45. package/dist/models/index.d.ts +2 -2
  46. package/dist/models/index.js +0 -0
  47. package/dist/models/interfaces/IDbOpts.d.ts +17 -0
  48. package/dist/models/interfaces/IDbOpts.js +2 -0
  49. package/dist/models/interfaces/IIdOpts.d.ts +0 -0
  50. package/dist/models/interfaces/IIdOpts.js +1 -0
  51. package/dist/models/interfaces/IIdTypeOpts.d.ts +3 -0
  52. package/dist/models/interfaces/IIdTypeOpts.js +2 -0
  53. package/dist/models/interfaces/IModel.d.ts +0 -0
  54. package/dist/models/interfaces/IModel.js +0 -0
  55. package/dist/models/interfaces/IRWSModelServices.d.ts +0 -0
  56. package/dist/models/interfaces/IRWSModelServices.js +0 -0
  57. package/dist/models/interfaces/ITrackerOpts.d.ts +12 -0
  58. package/dist/models/interfaces/ITrackerOpts.js +2 -0
  59. package/dist/models/interfaces/OpModelType.d.ts +4 -1
  60. package/dist/models/interfaces/OpModelType.js +0 -0
  61. package/dist/models/types/RelationTypes.d.ts +0 -0
  62. package/dist/models/types/RelationTypes.js +0 -0
  63. package/dist/models/utils/ModelUtils.d.ts +0 -0
  64. package/dist/models/utils/ModelUtils.js +0 -0
  65. package/dist/models/utils/PaginationUtils.d.ts +0 -0
  66. package/dist/models/utils/PaginationUtils.js +0 -0
  67. package/dist/models/utils/RelationUtils.d.ts +1 -1
  68. package/dist/models/utils/RelationUtils.js +2 -2
  69. package/dist/models/utils/TimeSeriesUtils.d.ts +0 -0
  70. package/dist/models/utils/TimeSeriesUtils.js +0 -0
  71. package/dist/services/DBService.d.ts +0 -0
  72. package/dist/services/DBService.js +0 -0
  73. package/dist/types/DbConfigHandler.d.ts +1 -1
  74. package/dist/types/DbConfigHandler.js +0 -0
  75. package/dist/types/FindParams.d.ts +0 -0
  76. package/dist/types/FindParams.js +0 -0
  77. package/dist/types/IRWSModel.d.ts +1 -1
  78. package/dist/types/IRWSModel.js +0 -0
  79. package/dist/types/ITimeSeries.d.ts +0 -0
  80. package/dist/types/ITimeSeries.js +0 -0
  81. package/exec/console.js +110 -110
  82. package/exec/db.rws.webpack.config.js +168 -168
  83. package/exec/src/cli.ts +73 -75
  84. package/exec/tsconfig.json +32 -32
  85. package/exec/webpackFilters.js +17 -17
  86. package/package.json +36 -36
  87. package/src/decorators/IdType.ts +17 -0
  88. package/src/decorators/InverseRelation.ts +41 -37
  89. package/src/decorators/InverseTimeSeries.ts +21 -21
  90. package/src/decorators/RWSCollection.ts +45 -27
  91. package/src/decorators/Relation.ts +61 -48
  92. package/src/decorators/TrackType.ts +65 -69
  93. package/src/decorators/index.ts +16 -8
  94. package/src/empty.js +0 -0
  95. package/src/helper/DbHelper.ts +133 -223
  96. package/src/helper/FieldsHelper.ts +34 -34
  97. package/src/helper/db/index.ts +10 -0
  98. package/src/helper/db/relation-manager.ts +119 -0
  99. package/src/helper/db/schema-generator.ts +318 -0
  100. package/src/helper/db/type-converter.ts +119 -0
  101. package/src/helper/db/utils.ts +120 -0
  102. package/src/index.ts +47 -38
  103. package/src/models/_model.ts +29 -29
  104. package/src/models/core/RWSModel.ts +529 -520
  105. package/src/models/core/TimeSeriesModel.ts +19 -19
  106. package/src/models/index.ts +20 -20
  107. package/src/models/interfaces/IDbOpts.ts +17 -0
  108. package/src/models/interfaces/IIdTypeOpts.ts +4 -0
  109. package/src/models/interfaces/IModel.ts +12 -12
  110. package/src/models/interfaces/IRWSModelServices.ts +7 -7
  111. package/src/models/interfaces/ITrackerOpts.ts +13 -0
  112. package/src/models/interfaces/OpModelType.ts +52 -49
  113. package/src/models/types/RelationTypes.ts +25 -25
  114. package/src/models/utils/ModelUtils.ts +65 -65
  115. package/src/models/utils/PaginationUtils.ts +42 -42
  116. package/src/models/utils/RelationUtils.ts +76 -76
  117. package/src/models/utils/TimeSeriesUtils.ts +38 -38
  118. package/src/services/DBService.ts +277 -277
  119. package/src/types/DbConfigHandler.ts +17 -17
  120. package/src/types/FindParams.ts +13 -13
  121. package/src/types/IRWSModel.ts +2 -2
  122. package/src/types/ITimeSeries.ts +5 -5
  123. package/tsconfig.json +22 -22
@@ -3,12 +3,15 @@ import { IRWSModelServices } from '../interfaces/IRWSModelServices';
3
3
  import { OpModelType } from '../interfaces/OpModelType';
4
4
  import { FindByType, IPaginationParams } from '../../types/FindParams';
5
5
  import { DBService } from '../../services/DBService';
6
+ import { ISuperTagData } from '../../decorators/RWSCollection';
6
7
  declare class RWSModel<T> implements IModel {
7
8
  static services: IRWSModelServices;
8
9
  [key: string]: any;
9
10
  id: string | number;
10
11
  static _collection: string;
11
12
  static _RELATIONS: {};
13
+ static _NO_ID: boolean;
14
+ static _SUPER_TAGS: ISuperTagData[];
12
15
  static _BANNED_KEYS: string[];
13
16
  static allModels: OpModelType<any>[];
14
17
  static _CUT_KEYS: string[];
@@ -51,14 +54,14 @@ declare class RWSModel<T> implements IModel {
51
54
  sanitizeDBData(data: any): any;
52
55
  static watchCollection<T extends RWSModel<T>>(this: OpModelType<T>, preRun: () => void): Promise<any>;
53
56
  static findOneBy<T extends RWSModel<T>>(this: OpModelType<T>, findParams?: FindByType): Promise<T | null>;
54
- static find<T extends RWSModel<T>>(this: OpModelType<T>, id: string, findParams?: Omit<FindByType, 'conditions'>): Promise<T | null>;
57
+ static find<T extends RWSModel<T>>(this: OpModelType<T>, id: string | number, findParams?: Omit<FindByType, 'conditions'>): Promise<T | null>;
55
58
  static findBy<T extends RWSModel<T>>(this: OpModelType<T>, findParams?: FindByType): Promise<T[]>;
56
59
  static delete<T extends RWSModel<T>>(this: OpModelType<T>, conditions: any): Promise<void>;
57
60
  delete<T extends RWSModel<T>>(): Promise<void>;
58
61
  static create<T extends RWSModel<T>>(this: new () => T, data: any): Promise<T>;
59
62
  static loadModels(): OpModelType<any>[];
60
63
  loadModels(): OpModelType<any>[];
61
- private checkRelEnabled;
64
+ private checkRelDisabled;
62
65
  static setServices(services: IRWSModelServices): void;
63
66
  getDb(): DBService;
64
67
  static getDb(): DBService;
@@ -94,7 +94,7 @@ class RWSModel {
94
94
  continue;
95
95
  }
96
96
  const relMeta = relManyData[key];
97
- const relationEnabled = RelationUtils_1.RelationUtils.checkRelEnabled(this, relMeta.key);
97
+ const relationEnabled = !RelationUtils_1.RelationUtils.checkRelDisabled(this, relMeta.key);
98
98
  if (relationEnabled) {
99
99
  this[relMeta.key] = await relMeta.inversionModel.findBy({
100
100
  conditions: {
@@ -110,7 +110,7 @@ class RWSModel {
110
110
  continue;
111
111
  }
112
112
  const relMeta = relOneData[key];
113
- const relationEnabled = RelationUtils_1.RelationUtils.checkRelEnabled(this, relMeta.key);
113
+ const relationEnabled = !RelationUtils_1.RelationUtils.checkRelDisabled(this, relMeta.key);
114
114
  if (!data[relMeta.hydrationField] && relMeta.required) {
115
115
  throw new Error(`Relation field "${relMeta.hydrationField}" is required in model ${this.constructor.name}.`);
116
116
  }
@@ -122,7 +122,8 @@ class RWSModel {
122
122
  this[relMeta.key] = await newRelModel.save();
123
123
  }
124
124
  const cutKeys = this.constructor._CUT_KEYS;
125
- if (!cutKeys.includes(relMeta.hydrationField)) {
125
+ const trackedField = Object.keys((await ModelUtils_1.ModelUtils.getModelAnnotations(this.constructor))).includes(relMeta.hydrationField);
126
+ if (!cutKeys.includes(relMeta.hydrationField) && !trackedField) {
126
127
  cutKeys.push(relMeta.hydrationField);
127
128
  }
128
129
  }
@@ -373,8 +374,8 @@ class RWSModel {
373
374
  loadModels() {
374
375
  return RWSModel.loadModels();
375
376
  }
376
- checkRelEnabled(key) {
377
- return RelationUtils_1.RelationUtils.checkRelEnabled(this, key);
377
+ checkRelDisabled(key) {
378
+ return RelationUtils_1.RelationUtils.checkRelDisabled(this, key);
378
379
  }
379
380
  static setServices(services) {
380
381
  this.allModels = services.configService.get('db_models');
@@ -391,6 +392,8 @@ exports.RWSModel = RWSModel;
391
392
  RWSModel.services = {};
392
393
  RWSModel._collection = null;
393
394
  RWSModel._RELATIONS = {};
395
+ RWSModel._NO_ID = false;
396
+ RWSModel._SUPER_TAGS = [];
394
397
  RWSModel._BANNED_KEYS = ['_collection'];
395
398
  RWSModel.allModels = [];
396
399
  RWSModel._CUT_KEYS = [];
File without changes
File without changes
@@ -3,5 +3,5 @@ import { IRWSModelServices } from './interfaces/IRWSModelServices';
3
3
  import { OpModelType } from './interfaces/OpModelType';
4
4
  import { RelationBindType, RelOneMetaType, RelManyMetaType } from './types/RelationTypes';
5
5
  import { RWSModel } from './core/RWSModel';
6
- import { TrackType, IMetaOpts } from '../decorators';
7
- export { IModel, IRWSModelServices, OpModelType, RelationBindType, RelOneMetaType, RelManyMetaType, RWSModel, TrackType, IMetaOpts };
6
+ import { TrackType, ITrackerMetaOpts } from '../decorators';
7
+ export { IModel, IRWSModelServices, OpModelType, RelationBindType, RelOneMetaType, RelManyMetaType, RWSModel, TrackType, ITrackerMetaOpts };
File without changes
@@ -0,0 +1,17 @@
1
+ export interface IDbOpts {
2
+ dbOptions?: {
3
+ mysql?: {
4
+ useType?: string;
5
+ useText?: boolean;
6
+ maxLength?: number;
7
+ useUuid?: boolean;
8
+ };
9
+ postgres?: {
10
+ useText?: boolean;
11
+ useUuid?: boolean;
12
+ };
13
+ mongodb?: {
14
+ customType?: string;
15
+ };
16
+ };
17
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,3 @@
1
+ import { IDbOpts } from "./IDbOpts";
2
+ export interface IIdTypeOpts extends IDbOpts {
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ import { IDbOpts } from "./IDbOpts";
2
+ import { OpModelType } from "./OpModelType";
3
+ export interface ITrackerOpts extends IDbOpts {
4
+ required?: boolean;
5
+ unique?: boolean | string;
6
+ isArray?: boolean;
7
+ relationField?: string;
8
+ relatedToField?: string;
9
+ relatedTo?: OpModelType<any>;
10
+ inversionModel?: OpModelType<any>;
11
+ relationName?: string;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,11 +4,14 @@ import { IRWSModelServices } from './IRWSModelServices';
4
4
  import { RelOneMetaType, RelManyMetaType } from '../types/RelationTypes';
5
5
  import { DBService } from '../../services/DBService';
6
6
  import type { RWSModel } from '../core/RWSModel';
7
+ import { ISuperTagData } from '../../decorators/RWSCollection';
7
8
  export interface OpModelType<T> {
8
9
  new (data?: any | null): T;
9
10
  services: IRWSModelServices;
10
11
  name: string;
11
12
  _collection: string;
13
+ _NO_ID: boolean;
14
+ _SUPER_TAGS: ISuperTagData[];
12
15
  _RELATIONS: {
13
16
  [key: string]: boolean;
14
17
  };
@@ -18,7 +21,7 @@ export interface OpModelType<T> {
18
21
  checkForInclusionWithThrow: (className: string) => void;
19
22
  checkForInclusion: (className: string) => boolean;
20
23
  findOneBy<T extends RWSModel<T>>(this: OpModelType<T>, findParams?: FindByType): Promise<T | null>;
21
- find<T extends RWSModel<T>>(this: OpModelType<T>, id: string, findParams?: Omit<FindByType, 'conditions'>): Promise<T | null>;
24
+ find<T extends RWSModel<T>>(this: OpModelType<T>, id: string | number, findParams?: Omit<FindByType, 'conditions'>): Promise<T | null>;
22
25
  findBy<T extends RWSModel<T>>(this: OpModelType<T>, findParams?: FindByType): Promise<T[]>;
23
26
  paginate<T extends RWSModel<T>>(this: OpModelType<T>, paginateParams?: IPaginationParams, findParams?: FindByType): Promise<T[]>;
24
27
  delete<T extends RWSModel<T>>(this: OpModelType<T>, conditions: any): Promise<void>;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -10,5 +10,5 @@ export declare class RelationUtils {
10
10
  };
11
11
  };
12
12
  static hasRelation(model: RWSModel<any>, key: string): boolean;
13
- static checkRelEnabled(model: RWSModel<any>, key: string): boolean;
13
+ static checkRelDisabled(model: RWSModel<any>, key: string): boolean;
14
14
  }
@@ -57,9 +57,9 @@ class RelationUtils {
57
57
  // Check if the property exists and is an object with an id property
58
58
  return !!model[key] && typeof model[key] === 'object' && model[key] !== null && 'id' in model[key];
59
59
  }
60
- static checkRelEnabled(model, key) {
60
+ static checkRelDisabled(model, key) {
61
61
  return Object.keys(model.constructor._RELATIONS).includes(key) &&
62
- model.constructor._RELATIONS[key] === true;
62
+ model.constructor._RELATIONS[key] === false;
63
63
  }
64
64
  }
65
65
  exports.RelationUtils = RelationUtils;
File without changes
File without changes
File without changes
File without changes
@@ -2,7 +2,7 @@ import { OpModelType } from "../models/interfaces/OpModelType";
2
2
  export interface IDbConfigParams {
3
3
  db_url?: string;
4
4
  db_name?: string;
5
- db_type?: 'mongodb' | 'mysql' | 'sqlite';
5
+ db_type?: 'mongodb' | 'mysql' | 'sqlite' | 'postgresql' | 'postgres';
6
6
  db_models?: OpModelType<any>[];
7
7
  }
8
8
  export interface IdGeneratorOptions {
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  export interface IRWSModel {
2
- id?: string;
2
+ id?: string | number;
3
3
  }
File without changes
File without changes
File without changes
package/exec/console.js CHANGED
@@ -1,111 +1,111 @@
1
- #!/usr/bin/env node
2
-
3
- const { rwsShell, rwsPath } = require('@rws-framework/console');
4
- const chalk = require('chalk');
5
- const crypto = require('crypto');
6
- const path = require('path');
7
- const fs = require('fs');
8
-
9
- const params = process.argv.splice(2);
10
- let paramsString = params.length ? (' ' + params.join(' ')) : '';
11
-
12
- const appRoot = process.cwd();
13
- const rwsCliConfigDir = path.resolve(appRoot, 'node_modules', '.rws', 'cli');
14
- const getCachedPath = (key) => path.resolve(rwsCliConfigDir, key);
15
-
16
- const currentCwd = path.resolve(__dirname);
17
-
18
- console.log({params})
19
-
20
-
21
- const commandString = `npx webpack --config db.rws.webpack.config.js --output-path ./build ${process.cwd()} ${params[2]}`;
22
- function needsCacheWarming(){
23
-
24
- if(!fs.existsSync(getCachedPath('paths')) || !fs.existsSync(getCachedPath('checksum'))){
25
- return true;
26
- }
27
-
28
- const fileList = fs.readFileSync(getCachedPath('paths'), 'utf-8').split('\n');
29
-
30
- if(fileList.length){
31
- const fileContents = [];
32
- for(const filePath of fileList){
33
- if(fs.existsSync(filePath)){
34
- fileContents.push(fs.readFileSync(filePath, 'utf-8'));
35
- }
36
- }
37
- const finalMD5 = crypto.createHash('md5').update(fileContents.join('\n')).digest('hex');
38
- const cachedMD5 = fs.readFileSync(getCachedPath('checksum'), 'utf-8');
39
-
40
- if(finalMD5 === cachedMD5){
41
- return false;
42
- }
43
- }
44
-
45
- return true;
46
- }
47
-
48
- async function main()
49
- {
50
- const hasRebuild = paramsString.split(' ').pop().indexOf('--rebuild') > -1;
51
- const doWarmCache = needsCacheWarming() || hasRebuild;
52
-
53
- if(!((params[0] || false) && (params[1] || false) && (params[2] || false))){
54
- throw new Error(`CLI command MUST have 3 parameters: {DB_URL, DB_NAME, MODELS_DIR}`);
55
- }
56
-
57
- if(doWarmCache){
58
- console.log(chalk.yellow('[RWS DB CLI] Building CLI client...'));
59
-
60
- const cacheTypes = ['paths', 'checksum'];
61
-
62
- for(const type of cacheTypes){
63
- if(fs.existsSync(getCachedPath(type))){
64
- fs.unlinkSync(getCachedPath(type));
65
- }
66
- }
67
-
68
- await tsc();
69
-
70
- await rwsShell.runCommand(commandString, currentCwd);
71
-
72
-
73
- }else{
74
- console.log(chalk.blue('[RWS CLI CACHE] Starting command from built CLI client.'));
75
- }
76
-
77
- let startSlice = hasRebuild ? -1 : paramsString.split(' ').length;
78
- let endSlice = hasRebuild ? -1 : null ;
79
-
80
- paramsString = [
81
- ...paramsString.split(' ').slice(0, startSlice),
82
- currentCwd,
83
- endSlice ?
84
- paramsString.split(' ').at(endSlice)
85
- : null
86
- ].filter((item) => item !== null).join(' ');
87
-
88
- await rwsShell.runCommand(`node ${path.join(currentCwd, 'build', 'main.cli.rws.js')}${paramsString}`, process.cwd());
89
- }
90
-
91
- async function tsc (){
92
- const tempConfigContent = {
93
- "extends": "./tsconfig.json",
94
- "include": [
95
- path.join(process.cwd(), params[2], 'index.ts')
96
- ],
97
- };
98
-
99
- const tempConfigPath = path.join(currentCwd, '.tmp.gitignore.json');
100
- fs.writeFileSync(tempConfigPath, JSON.stringify(tempConfigContent, null, 2));
101
-
102
-
103
- await rwsShell.runCommand(`tsc -p ${tempConfigPath}`, currentCwd);
104
- fs.unlinkSync(tempConfigPath);
105
- }
106
-
107
- main().then((data) => {
108
- console.log(chalk.green('[RWS DB CLI] Command complete.'));
109
- }).catch((e) => {
110
- console.error(e.message);
1
+ #!/usr/bin/env node
2
+
3
+ const { rwsShell, rwsPath } = require('@rws-framework/console');
4
+ const chalk = require('chalk');
5
+ const crypto = require('crypto');
6
+ const path = require('path');
7
+ const fs = require('fs');
8
+
9
+ const params = process.argv.splice(2);
10
+ let paramsString = params.length ? (' ' + params.join(' ')) : '';
11
+
12
+ const appRoot = process.cwd();
13
+ const rwsCliConfigDir = path.resolve(appRoot, 'node_modules', '.rws', 'cli');
14
+ const getCachedPath = (key) => path.resolve(rwsCliConfigDir, key);
15
+
16
+ const currentCwd = path.resolve(__dirname);
17
+
18
+ console.log({params})
19
+
20
+
21
+ const commandString = `npx webpack --config db.rws.webpack.config.js --output-path ./build ${process.cwd()} ${params[2]}`;
22
+ function needsCacheWarming(){
23
+
24
+ if(!fs.existsSync(getCachedPath('paths')) || !fs.existsSync(getCachedPath('checksum'))){
25
+ return true;
26
+ }
27
+
28
+ const fileList = fs.readFileSync(getCachedPath('paths'), 'utf-8').split('\n');
29
+
30
+ if(fileList.length){
31
+ const fileContents = [];
32
+ for(const filePath of fileList){
33
+ if(fs.existsSync(filePath)){
34
+ fileContents.push(fs.readFileSync(filePath, 'utf-8'));
35
+ }
36
+ }
37
+ const finalMD5 = crypto.createHash('md5').update(fileContents.join('\n')).digest('hex');
38
+ const cachedMD5 = fs.readFileSync(getCachedPath('checksum'), 'utf-8');
39
+
40
+ if(finalMD5 === cachedMD5){
41
+ return false;
42
+ }
43
+ }
44
+
45
+ return true;
46
+ }
47
+
48
+ async function main()
49
+ {
50
+ const hasRebuild = paramsString.split(' ').pop().indexOf('--rebuild') > -1;
51
+ const doWarmCache = needsCacheWarming() || hasRebuild;
52
+
53
+ if(!((params[0] || false) && (params[1] || false) && (params[2] || false))){
54
+ throw new Error(`CLI command MUST have 3 parameters: {DB_URL, DB_NAME, MODELS_DIR}`);
55
+ }
56
+
57
+ if(doWarmCache){
58
+ console.log(chalk.yellow('[RWS DB CLI] Building CLI client...'));
59
+
60
+ const cacheTypes = ['paths', 'checksum'];
61
+
62
+ for(const type of cacheTypes){
63
+ if(fs.existsSync(getCachedPath(type))){
64
+ fs.unlinkSync(getCachedPath(type));
65
+ }
66
+ }
67
+
68
+ await tsc();
69
+
70
+ await rwsShell.runCommand(commandString, currentCwd);
71
+
72
+
73
+ }else{
74
+ console.log(chalk.blue('[RWS CLI CACHE] Starting command from built CLI client.'));
75
+ }
76
+
77
+ let startSlice = hasRebuild ? -1 : paramsString.split(' ').length;
78
+ let endSlice = hasRebuild ? -1 : null ;
79
+
80
+ paramsString = [
81
+ ...paramsString.split(' ').slice(0, startSlice),
82
+ currentCwd,
83
+ endSlice ?
84
+ paramsString.split(' ').at(endSlice)
85
+ : null
86
+ ].filter((item) => item !== null).join(' ');
87
+
88
+ await rwsShell.runCommand(`node ${path.join(currentCwd, 'build', 'main.cli.rws.js')}${paramsString}`, process.cwd());
89
+ }
90
+
91
+ async function tsc (){
92
+ const tempConfigContent = {
93
+ "extends": "./tsconfig.json",
94
+ "include": [
95
+ path.join(process.cwd(), params[2], 'index.ts')
96
+ ],
97
+ };
98
+
99
+ const tempConfigPath = path.join(currentCwd, '.tmp.gitignore.json');
100
+ fs.writeFileSync(tempConfigPath, JSON.stringify(tempConfigContent, null, 2));
101
+
102
+
103
+ await rwsShell.runCommand(`tsc -p ${tempConfigPath}`, currentCwd);
104
+ fs.unlinkSync(tempConfigPath);
105
+ }
106
+
107
+ main().then((data) => {
108
+ console.log(chalk.green('[RWS DB CLI] Command complete.'));
109
+ }).catch((e) => {
110
+ console.error(e.message);
111
111
  });