@rws-framework/db 3.3.8 → 3.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.
@@ -1,168 +1,168 @@
1
- const path = require('path');
2
- const chalk = require('chalk');
3
- const webpackFilters = require('./webpackFilters');
4
- const webpack = require('webpack');
5
- const { rwsPath } = require('@rws-framework/console');
6
- // Get CLI arguments
7
- const args = process.argv.slice(2);
8
- const fs = require('fs');
9
- const appRootPath = args[4] || process.cwd();
10
- const modelsDir = args[5] || '';
11
-
12
- const internalCwd = process.cwd()
13
- const rootPackageNodeModules = path.resolve(rwsPath.findRootWorkspacePath(), 'node_modules');
14
- const thisPackage = path.resolve(__dirname, '..');
15
- const WEBPACK_PLUGINS = [new webpack.optimize.ModuleConcatenationPlugin()];
16
-
17
- const modules_setup = [rootPackageNodeModules, appRootPath];
18
- const isDev = true;
19
-
20
- function prettyLog(data){
21
- for(const key of Object.keys(data)){
22
- const valObject = data[key];
23
-
24
- console.log(`${chalk.yellow('[Log]')} ${chalk.blue(key)}:`, valObject)
25
- }
26
- }
27
-
28
-
29
-
30
- const mainEntry = './' + path.relative(appRootPath, path.join(internalCwd, '/src/cli.ts'));
31
- const vPath = path.relative(__dirname, path.join(__dirname, '../build/vendors'));
32
-
33
- prettyLog({ buildPaths:{
34
- thisPackage,
35
- rootPackageNodeModules,
36
- appRootPath,
37
- internalCwd,
38
- vPath
39
- }});
40
-
41
- if(!fs.existsSync(path.join(appRootPath, modelsDir, 'index.ts'))){
42
- console.log(`${chalk.red('[RWS Structure Error] ')} ${chalk.blue(`
43
- No index.ts in "${path.join(appRootPath, modelsDir)}"\n
44
- RWS DB requires "index.ts" that has default export with array of your models:\n
45
-
46
- ${chalk.blue('import')} RWSModel${chalk.blue(',')} OpModelType ${chalk.blue('from')} ${chalk.green('./src/models/user.model.ts')}${chalk.blue(';')}
47
-
48
- RWSModel<ModelDataInterface> is instance type and
49
- OpModelType<ModelDataInterface> is type for static methods that navigate through db to populate instanced models.`)}\n
50
-
51
- Example: \n
52
-
53
- ${chalk.blue('import')} User ${chalk.blue('from')} ${chalk.green('\'./src/models/user.model.ts\'')}${chalk.blue(';')}
54
- ${chalk.blue('import')} ApiKey ${chalk.blue('from')} ${chalk.green('\'./src/models/apiKey.model.ts\'')}${chalk.blue(';')}
55
-
56
- ${chalk.blue('export')} default ${chalk.magenta('[')}
57
- User${chalk.blue(',')}
58
- ApiKey
59
- ${chalk.magenta(']')}${chalk.blue(';')}
60
- `);
61
-
62
- throw new Error("Build stopped.")
63
- }
64
-
65
- const cfgExport = {
66
- context: appRootPath,
67
- entry: mainEntry,
68
- mode: isDev ? 'development' : 'production',
69
- target: 'node',
70
- devtool: isDev ? 'source-map' : false,
71
- output: {
72
- path: path.resolve(internalCwd, 'build'), // Resolve output path relative to config directory
73
- filename: '[name].cli.rws.js',
74
- sourceMapFilename: '[file].map',
75
- chunkFilename: "[name].chunk.js",
76
- libraryTarget: 'commonjs2',
77
- clean: false
78
- },
79
- resolve: {
80
- extensions: ['.ts', '.js'],
81
- modules: modules_setup,
82
- alias: {
83
- '@V': vPath,
84
- 'src': path.resolve(appRootPath, 'src'), // Add explicit resolution for src directory
85
- },
86
- fallback: {
87
- "kerberos": false,
88
- "mongodb-client-encryption": false
89
- }
90
- },
91
- module: {
92
- rules: [
93
- {
94
- test: /\.(ts)$/,
95
- use: [
96
- {
97
- loader: 'ts-loader',
98
- options: {
99
- transpileOnly: true,
100
- configFile: path.resolve(__dirname, 'tsconfig.json'),
101
- compilerOptions: {
102
- outDir: path.resolve(internalCwd, 'build'),
103
- }
104
- }
105
- }
106
- ],
107
- include: [
108
- path.resolve(appRootPath),
109
- path.resolve(thisPackage),
110
- path.resolve(rootPackageNodeModules, '@rws-framework')
111
- ],
112
- exclude: [
113
- /node_modules\/(?!(@rws-framework)\/).*/,
114
- /\.d\.ts$/
115
- ]
116
- },
117
- {
118
- test: /\.node$/,
119
- use: 'node-loader',
120
- }
121
- ],
122
- },
123
- plugins: [
124
- ...WEBPACK_PLUGINS,
125
- new webpack.DefinePlugin({
126
- 'process.env.APP_ROOT': JSON.stringify(appRootPath),
127
- 'process.env.DB_CLI': JSON.stringify(1)
128
- }),
129
- new webpack.IgnorePlugin({
130
- resourceRegExp: /^kerberos$/,
131
- }),
132
- new webpack.NormalModuleReplacementPlugin(
133
- /.*\/build\/Debug\/kerberos\.node$/,
134
- '@rws-framework/db/src/empty.js'
135
- )
136
- ],
137
- ignoreWarnings: webpackFilters,
138
- optimization: {
139
- minimize: false
140
- },
141
- experiments: {
142
- topLevelAwait: true, // Enable top-level await if needed
143
- }
144
- // stats: 'verbose'
145
-
146
- };
147
-
148
- cfgExport.externals = {
149
- '@nestjs/common': 'commonjs @nestjs/common',
150
- '@nestjs/core': 'commonjs @nestjs/core',
151
- '@nestjs/config': 'commonjs @nestjs/config',
152
- '@anthropic-ai/sdk': 'commonjs @anthropic-ai/sdk',
153
- '@zip.js/zip.js': 'commonjs @zip.js/zip.js',
154
- 'mongodb-client-encryption': 'commonjs mongodb-client-encryption',
155
- 'uuid': 'commonjs uuid',
156
- 'source-map-support': 'commonjs source-map-support'
157
- };
158
-
159
- cfgExport.plugins.push(
160
- new webpack.BannerPlugin({
161
- banner: 'require("source-map-support").install();',
162
- raw: true
163
- })
164
- );
165
-
166
- // console.log('Final config', cfgExport);
167
-
168
- module.exports = cfgExport;
1
+ const path = require('path');
2
+ const chalk = require('chalk');
3
+ const webpackFilters = require('./webpackFilters');
4
+ const webpack = require('webpack');
5
+ const { rwsPath } = require('@rws-framework/console');
6
+ // Get CLI arguments
7
+ const args = process.argv.slice(2);
8
+ const fs = require('fs');
9
+ const appRootPath = args[4] || process.cwd();
10
+ const modelsDir = args[5] || '';
11
+
12
+ const internalCwd = process.cwd()
13
+ const rootPackageNodeModules = path.resolve(rwsPath.findRootWorkspacePath(), 'node_modules');
14
+ const thisPackage = path.resolve(__dirname, '..');
15
+ const WEBPACK_PLUGINS = [new webpack.optimize.ModuleConcatenationPlugin()];
16
+
17
+ const modules_setup = [rootPackageNodeModules, appRootPath];
18
+ const isDev = true;
19
+
20
+ function prettyLog(data){
21
+ for(const key of Object.keys(data)){
22
+ const valObject = data[key];
23
+
24
+ console.log(`${chalk.yellow('[Log]')} ${chalk.blue(key)}:`, valObject)
25
+ }
26
+ }
27
+
28
+
29
+
30
+ const mainEntry = './' + path.relative(appRootPath, path.join(internalCwd, '/src/cli.ts'));
31
+ const vPath = path.relative(__dirname, path.join(__dirname, '../build/vendors'));
32
+
33
+ prettyLog({ buildPaths:{
34
+ thisPackage,
35
+ rootPackageNodeModules,
36
+ appRootPath,
37
+ internalCwd,
38
+ vPath
39
+ }});
40
+
41
+ if(!fs.existsSync(path.join(appRootPath, modelsDir, 'index.ts'))){
42
+ console.log(`${chalk.red('[RWS Structure Error] ')} ${chalk.blue(`
43
+ No index.ts in "${path.join(appRootPath, modelsDir)}"\n
44
+ RWS DB requires "index.ts" that has default export with array of your models:\n
45
+
46
+ ${chalk.blue('import')} RWSModel${chalk.blue(',')} OpModelType ${chalk.blue('from')} ${chalk.green('./src/models/user.model.ts')}${chalk.blue(';')}
47
+
48
+ RWSModel<ModelDataInterface> is instance type and
49
+ OpModelType<ModelDataInterface> is type for static methods that navigate through db to populate instanced models.`)}\n
50
+
51
+ Example: \n
52
+
53
+ ${chalk.blue('import')} User ${chalk.blue('from')} ${chalk.green('\'./src/models/user.model.ts\'')}${chalk.blue(';')}
54
+ ${chalk.blue('import')} ApiKey ${chalk.blue('from')} ${chalk.green('\'./src/models/apiKey.model.ts\'')}${chalk.blue(';')}
55
+
56
+ ${chalk.blue('export')} default ${chalk.magenta('[')}
57
+ User${chalk.blue(',')}
58
+ ApiKey
59
+ ${chalk.magenta(']')}${chalk.blue(';')}
60
+ `);
61
+
62
+ throw new Error("Build stopped.")
63
+ }
64
+
65
+ const cfgExport = {
66
+ context: appRootPath,
67
+ entry: mainEntry,
68
+ mode: isDev ? 'development' : 'production',
69
+ target: 'node',
70
+ devtool: isDev ? 'source-map' : false,
71
+ output: {
72
+ path: path.resolve(internalCwd, 'build'), // Resolve output path relative to config directory
73
+ filename: '[name].cli.rws.js',
74
+ sourceMapFilename: '[file].map',
75
+ chunkFilename: "[name].chunk.js",
76
+ libraryTarget: 'commonjs2',
77
+ clean: false
78
+ },
79
+ resolve: {
80
+ extensions: ['.ts', '.js'],
81
+ modules: modules_setup,
82
+ alias: {
83
+ '@V': vPath,
84
+ 'src': path.resolve(appRootPath, 'src'), // Add explicit resolution for src directory
85
+ },
86
+ fallback: {
87
+ "kerberos": false,
88
+ "mongodb-client-encryption": false
89
+ }
90
+ },
91
+ module: {
92
+ rules: [
93
+ {
94
+ test: /\.(ts)$/,
95
+ use: [
96
+ {
97
+ loader: 'ts-loader',
98
+ options: {
99
+ transpileOnly: true,
100
+ configFile: path.resolve(__dirname, 'tsconfig.json'),
101
+ compilerOptions: {
102
+ outDir: path.resolve(internalCwd, 'build'),
103
+ }
104
+ }
105
+ }
106
+ ],
107
+ include: [
108
+ path.resolve(appRootPath),
109
+ path.resolve(thisPackage),
110
+ path.resolve(rootPackageNodeModules, '@rws-framework')
111
+ ],
112
+ exclude: [
113
+ /node_modules\/(?!(@rws-framework)\/).*/,
114
+ /\.d\.ts$/
115
+ ]
116
+ },
117
+ {
118
+ test: /\.node$/,
119
+ use: 'node-loader',
120
+ }
121
+ ],
122
+ },
123
+ plugins: [
124
+ ...WEBPACK_PLUGINS,
125
+ new webpack.DefinePlugin({
126
+ 'process.env.APP_ROOT': JSON.stringify(appRootPath),
127
+ 'process.env.DB_CLI': JSON.stringify(1)
128
+ }),
129
+ new webpack.IgnorePlugin({
130
+ resourceRegExp: /^kerberos$/,
131
+ }),
132
+ new webpack.NormalModuleReplacementPlugin(
133
+ /.*\/build\/Debug\/kerberos\.node$/,
134
+ '@rws-framework/db/src/empty.js'
135
+ )
136
+ ],
137
+ ignoreWarnings: webpackFilters,
138
+ optimization: {
139
+ minimize: false
140
+ },
141
+ experiments: {
142
+ topLevelAwait: true, // Enable top-level await if needed
143
+ }
144
+ // stats: 'verbose'
145
+
146
+ };
147
+
148
+ cfgExport.externals = {
149
+ '@nestjs/common': 'commonjs @nestjs/common',
150
+ '@nestjs/core': 'commonjs @nestjs/core',
151
+ '@nestjs/config': 'commonjs @nestjs/config',
152
+ '@anthropic-ai/sdk': 'commonjs @anthropic-ai/sdk',
153
+ '@zip.js/zip.js': 'commonjs @zip.js/zip.js',
154
+ 'mongodb-client-encryption': 'commonjs mongodb-client-encryption',
155
+ 'uuid': 'commonjs uuid',
156
+ 'source-map-support': 'commonjs source-map-support'
157
+ };
158
+
159
+ cfgExport.plugins.push(
160
+ new webpack.BannerPlugin({
161
+ banner: 'require("source-map-support").install();',
162
+ raw: true
163
+ })
164
+ );
165
+
166
+ // console.log('Final config', cfgExport);
167
+
168
+ module.exports = cfgExport;
@@ -1,32 +1,32 @@
1
- {
2
- "compilerOptions": {
3
- "baseUrl": "./",
4
- "experimentalDecorators": true,
5
- "emitDecoratorMetadata": true,
6
- "emitDeclarationOnly": false,
7
- "target": "ES2018",
8
- "module": "commonjs",
9
- "moduleResolution": "node",
10
- "strict": true,
11
- "skipLibCheck": true,
12
- "esModuleInterop": true,
13
- "resolveJsonModule": true,
14
- "strictNullChecks": false,
15
- "allowSyntheticDefaultImports": true,
16
- "sourceMap": true,
17
- "declaration": true,
18
- "outDir": "build/vendors",
19
- "preserveWatchOutput": true,
20
- "allowJs": true,
21
- "paths": {
22
- "@V/*": ["./build/vendors/*"]
23
- }
24
- },
25
- "include": [
26
- "src/cli.ts",
27
- "../src/*"
28
- ],
29
- "exclude": [
30
- "node_modules"
31
- ]
32
- }
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "./",
4
+ "experimentalDecorators": true,
5
+ "emitDecoratorMetadata": true,
6
+ "emitDeclarationOnly": false,
7
+ "target": "ES2018",
8
+ "module": "commonjs",
9
+ "moduleResolution": "node",
10
+ "strict": true,
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true,
13
+ "resolveJsonModule": true,
14
+ "strictNullChecks": false,
15
+ "allowSyntheticDefaultImports": true,
16
+ "sourceMap": true,
17
+ "declaration": true,
18
+ "outDir": "build/vendors",
19
+ "preserveWatchOutput": true,
20
+ "allowJs": true,
21
+ "paths": {
22
+ "@V/*": ["./build/vendors/*"]
23
+ }
24
+ },
25
+ "include": [
26
+ "src/cli.ts",
27
+ "../src/*"
28
+ ],
29
+ "exclude": [
30
+ "node_modules"
31
+ ]
32
+ }
@@ -1,18 +1,18 @@
1
- module.exports = [
2
- /aws-crt/,
3
- /express\/lib\/view/,
4
- /mongodb-client-encryption\/lib\/providers\/gcp/,
5
- /mongodb/,
6
- /nest-commander/,
7
- /snappy/,
8
- /mongodb-js\/zstd/,
9
- /puppeteer/,
10
- /kerberos/,
11
- /@zip\.js\/zip.js/,
12
- /Module not found: Error: Can't resolve 'fsevents' in/,
13
- /Critical dependency: the request of a dependency is an expression/,
14
- /Module not found: Error: Can't resolve 'aws4'/,
15
- /Critical dependency: require function is used in a way in which dependencies cannot be statically extracted/,
16
- /Can't resolve .* in '.*kerberos.*'/,
17
- /Can't resolve .* in '.*mongodb-client-encryption.*'/
1
+ module.exports = [
2
+ /aws-crt/,
3
+ /express\/lib\/view/,
4
+ /mongodb-client-encryption\/lib\/providers\/gcp/,
5
+ /mongodb/,
6
+ /nest-commander/,
7
+ /snappy/,
8
+ /mongodb-js\/zstd/,
9
+ /puppeteer/,
10
+ /kerberos/,
11
+ /@zip\.js\/zip.js/,
12
+ /Module not found: Error: Can't resolve 'fsevents' in/,
13
+ /Critical dependency: the request of a dependency is an expression/,
14
+ /Module not found: Error: Can't resolve 'aws4'/,
15
+ /Critical dependency: require function is used in a way in which dependencies cannot be statically extracted/,
16
+ /Can't resolve .* in '.*kerberos.*'/,
17
+ /Can't resolve .* in '.*mongodb-client-encryption.*'/
18
18
  ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/db",
3
3
  "private": false,
4
- "version": "3.3.8",
4
+ "version": "3.4.1",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -21,12 +21,11 @@
21
21
  "crypto": "^1.0.1",
22
22
  "source-map-support": "^0.5.21",
23
23
  "tsconfig-paths": "^4.2.0",
24
- "tsconfig-paths-webpack-plugin": "^4.1.0"
24
+ "tsconfig-paths-webpack-plugin": "^4.1.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/xml2js": "^0.4.14",
28
28
  "typescript": "^5.7.2"
29
-
30
29
  },
31
30
  "repository": {
32
31
  "type": "git",
@@ -1,22 +1,22 @@
1
- import 'reflect-metadata';
2
-
3
- interface InverseTimeSeriesOpts{
4
- timeSeriesModel: string
5
- hydrationField: string
6
- }
7
-
8
- function InverseTimeSeries(timeSeriesModel: string, hydrationField: string) {
9
-
10
- const metaOpts: InverseTimeSeriesOpts = {
11
- timeSeriesModel: timeSeriesModel,
12
- hydrationField: hydrationField
13
- };
14
-
15
-
16
- return function(target: any, key: string) {
17
- Reflect.defineMetadata(`InverseTimeSeries:${key}`, metaOpts, target);
18
- };
19
- }
20
-
21
- export default InverseTimeSeries;
1
+ import 'reflect-metadata';
2
+
3
+ interface InverseTimeSeriesOpts{
4
+ timeSeriesModel: string
5
+ hydrationField: string
6
+ }
7
+
8
+ function InverseTimeSeries(timeSeriesModel: string, hydrationField: string) {
9
+
10
+ const metaOpts: InverseTimeSeriesOpts = {
11
+ timeSeriesModel: timeSeriesModel,
12
+ hydrationField: hydrationField
13
+ };
14
+
15
+
16
+ return function(target: any, key: string) {
17
+ Reflect.defineMetadata(`InverseTimeSeries:${key}`, metaOpts, target);
18
+ };
19
+ }
20
+
21
+ export default InverseTimeSeries;
22
22
  export {InverseTimeSeriesOpts};
@@ -70,8 +70,8 @@ export class DbHelper {
70
70
  * @param dbUrl The database URL
71
71
  * @returns The base schema
72
72
  */
73
- static generateBaseSchema(dbType: string, dbUrl: string): string {
74
- return SchemaGenerator.generateBaseSchema(dbType, dbUrl);
73
+ static generateBaseSchema(dbType: string, dbUrl: string, output?: string, binaryTargets?: string[]): string {
74
+ return SchemaGenerator.generateBaseSchema(dbType, dbUrl, output, binaryTargets);
75
75
  }
76
76
 
77
77
  /**
@@ -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
  }
@@ -30,19 +30,26 @@ export class SchemaGenerator {
30
30
  * @param dbUrl The database URL
31
31
  * @returns The base schema
32
32
  */
33
- static generateBaseSchema(dbType: string, dbUrl: string): string {
33
+ static generateBaseSchema(dbType: string, dbUrl: string, output?: string, binaryTargets?: string[]): string {
34
34
  process.env = { ...process.env, [this.dbUrlVarName]: dbUrl };
35
35
 
36
36
  return `generator client {
37
37
  provider = "prisma-client-js"
38
+ ${output ? `output = "${this.ospath(output)}"` : ''}
39
+ ${binaryTargets ? `binaryTargets = ${JSON.stringify(binaryTargets)}` : ''}
38
40
  }
39
41
 
40
42
  datasource db {
41
43
  provider = "${dbType}"
42
- url = env("${this.dbUrlVarName}")
44
+ url = env("${this.dbUrlVarName}")
43
45
  }`;
44
46
  }
45
47
 
48
+ private static ospath(outPath: string): string
49
+ {
50
+ return outPath.split('')[1] === ':' ? outPath.replace(/\\/g,'\\\\') : outPath
51
+ }
52
+
46
53
  /**
47
54
  * Generate model sections for the schema
48
55
  * @param model The model to generate a section for
@@ -356,8 +363,10 @@ datasource db {
356
363
  static async installPrisma(configService: IDbConfigHandler, dbService: DBService, leaveFile = false): Promise<void> {
357
364
  const dbUrl = configService.get('db_url');
358
365
  const dbType = configService.get('db_type') || 'mongodb';
366
+ const dbPrismaOutput = configService.get('db_prisma_output');
367
+ const dbPrismaBinaryTargets = configService.get('db_prisma_binary_targets');
359
368
 
360
- let template: string = this.generateBaseSchema(dbType, dbUrl);
369
+ let template: string = this.generateBaseSchema(dbType, dbUrl, dbPrismaOutput, dbPrismaBinaryTargets);
361
370
 
362
371
  const dbModels: OpModelType<unknown>[] | null = configService.get('db_models');
363
372