@reldens/storage 0.67.0 → 0.69.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/README.md CHANGED
@@ -55,7 +55,23 @@ Options:
55
55
  - `--maxWaitTime=[ms]` - Max wait time in milliseconds (default: 30000)
56
56
  - `--prismaSchemaPath=[path]` - Path to Prisma schema directory
57
57
  - `--clientOutputPath=[path]` - Client output path (if not set, uses Prisma default)
58
- - `--generateBinaryTargets=[targets]` - Comma-separated binary targets (default: native)
58
+ - `--generateBinaryTargets=[targets]` - Comma-separated binary targets (default: native,debian-openssl-1.1.x)
59
+ - `--dbParams=[params]` - Database connection parameters (e.g., authPlugin=mysql_native_password)
60
+
61
+ ### Environment Variables
62
+
63
+ You can set database connection parameters using environment variables:
64
+
65
+ ```bash
66
+ # Basic authentication plugin for AWS MySQL 8.0+
67
+ RELDENS_DB_PARAMS="authPlugin=mysql_native_password"
68
+
69
+ # SSL configuration for AWS RDS
70
+ RELDENS_DB_PARAMS="authPlugin=mysql_native_password&sslmode=require&sslcert=ca-cert.pem"
71
+
72
+ # Full SSL with client certificates
73
+ RELDENS_DB_PARAMS="authPlugin=mysql_native_password&sslmode=require&sslcert=ca-cert.pem&sslidentity=client.p12&sslpassword=certpass"
74
+ ```
59
75
 
60
76
  ## Usage Examples
61
77
 
@@ -106,6 +122,20 @@ First, generate your Prisma schema:
106
122
  npx reldens-generate-prisma-schema --host=localhost --port=3306 --user=dbuser --password=dbpass --database=dbname
107
123
  ```
108
124
 
125
+ For AWS RDS with SSL:
126
+ ```bash
127
+ # Set environment variable first
128
+ export RELDENS_DB_PARAMS="authPlugin=mysql_native_password&sslmode=require"
129
+
130
+ # Then generate schema
131
+ npx reldens-generate-prisma-schema --host=your-rds-host.amazonaws.com --port=3306 --user=dbuser --password=dbpass --database=dbname
132
+ ```
133
+
134
+ Or pass parameters directly:
135
+ ```bash
136
+ npx reldens-generate-prisma-schema --host=your-rds-host.amazonaws.com --port=3306 --user=dbuser --password=dbpass --database=dbname --dbParams="authPlugin=mysql_native_password&sslmode=require"
137
+ ```
138
+
109
139
  Then, use the PrismaDataServer in your code:
110
140
  ```javascript
111
141
  const { PrismaDataServer } = require('@reldens/storage');
@@ -1,158 +1,160 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- *
5
- * Reldens - Generate Prisma Schema CLI
6
- *
7
- */
8
-
9
- const { PrismaSchemaGenerator } = require('../lib/prisma/prisma-schema-generator');
10
- const { Logger, sc } = require('@reldens/utils');
11
-
12
- class PrismaSchemaGeneratorCLI
13
- {
14
-
15
- constructor()
16
- {
17
- this.args = process.argv.slice(2);
18
- this.config = {};
19
- this.parseArguments();
20
- }
21
-
22
- parseArguments()
23
- {
24
- for(let i = 0; i < this.args.length; i++){
25
- let arg = this.args[i];
26
- if(!arg.startsWith('--')){
27
- continue;
28
- }
29
- let equalIndex = arg.indexOf('=');
30
- if(-1 === equalIndex){
31
- let flag = arg.substring(2);
32
- if('debug' === flag || 'dataProxy' === flag || 'help' === flag || 'h' === flag){
33
- this.config[flag] = true;
34
- }
35
- continue;
36
- }
37
- let key = arg.substring(2, equalIndex);
38
- let value = arg.substring(equalIndex + 1);
39
- if('port' === key || 'checkInterval' === key || 'maxWaitTime' === key){
40
- this.config[key] = parseInt(value);
41
- continue;
42
- }
43
- if('generateBinaryTargets' === key){
44
- this.config[key] = value.split(',').map(target => target.trim());
45
- continue;
46
- }
47
- this.config[key] = value;
48
- }
49
- }
50
-
51
- shouldShowHelp()
52
- {
53
- return 0 === this.args.length || sc.get(this.config, 'help', false) || sc.get(this.config, 'h', false);
54
- }
55
-
56
- showHelp()
57
- {
58
- Logger.info('');
59
- Logger.info('Reldens Prisma Schema Generator');
60
- Logger.info('================================');
61
- Logger.info('');
62
- Logger.info('Usage: npx reldens-generate-prisma-schema [options]');
63
- Logger.info('');
64
- Logger.info('Required Options:');
65
- Logger.info(' --host=[host] Database host');
66
- Logger.info(' --port=[port] Database port');
67
- Logger.info(' --user=[user] Database user');
68
- Logger.info(' --password=[password] Database password');
69
- Logger.info(' --database=[database] Database name');
70
- Logger.info('');
71
- Logger.info('Optional Options:');
72
- Logger.info(' --client=[client] Database client (default: mysql)');
73
- Logger.info(' --debug Enable debug mode (default: false)');
74
- Logger.info(' --dataProxy Enable data proxy (default: false)');
75
- Logger.info(' --checkInterval=[ms] Check interval in milliseconds (default: 1000)');
76
- Logger.info(' --maxWaitTime=[ms] Max wait time in milliseconds (default: 30000)');
77
- Logger.info(' --prismaSchemaPath=[path] Path to Prisma schema directory');
78
- Logger.info(' --clientOutputPath=[path] Client output path (if not set, uses Prisma default)');
79
- Logger.info(' --generateBinaryTargets=[targets] Comma-separated binary targets (default: native)');
80
- Logger.info('');
81
- Logger.info('Example:');
82
- Logger.info(' npx reldens-generate-prisma-schema --host=localhost --port=3306 --user=root --password=secret --database=mydb');
83
- Logger.info('');
84
- Logger.info('Advanced Example:');
85
- Logger.info(' npx reldens-generate-prisma-schema --host=localhost --port=3306 --user=root --password=secret --database=mydb --client=postgresql --debug --dataProxy --checkInterval=2000 --maxWaitTime=60000 --prismaSchemaPath=./custom/prisma --clientOutputPath=./custom/client --generateBinaryTargets=native,debian-openssl-1.1.x');
86
- Logger.info('');
87
- }
88
-
89
- validateRequiredArgs()
90
- {
91
- let requiredArgs = ['host', 'port', 'user', 'password', 'database'];
92
- let missing = [];
93
- for(let arg of requiredArgs){
94
- if(!this.config[arg]){
95
- missing.push(arg);
96
- }
97
- }
98
- if(0 < missing.length){
99
- Logger.error('Missing required arguments: ' + missing.join(', '));
100
- this.showHelp();
101
- return false;
102
- }
103
- return true;
104
- }
105
-
106
- getSchemaConfig()
107
- {
108
- return {
109
- config: {
110
- host: this.config.host,
111
- port: this.config.port,
112
- user: this.config.user,
113
- password: this.config.password,
114
- database: this.config.database
115
- },
116
- client: sc.get(this.config, 'client', 'mysql'),
117
- debug: sc.get(this.config, 'debug', false),
118
- dataProxy: sc.get(this.config, 'dataProxy', false),
119
- checkInterval: sc.get(this.config, 'checkInterval', 1000),
120
- maxWaitTime: sc.get(this.config, 'maxWaitTime', 30000),
121
- prismaSchemaPath: sc.get(this.config, 'prismaSchemaPath'),
122
- clientOutputPath: sc.get(this.config, 'clientOutputPath'),
123
- generateBinaryTargets: sc.get(this.config, 'generateBinaryTargets')
124
- };
125
- }
126
-
127
- async run()
128
- {
129
- if(this.shouldShowHelp()){
130
- this.showHelp();
131
- return true;
132
- }
133
- if(!this.validateRequiredArgs()){
134
- return false;
135
- }
136
- let schemaConfig = this.getSchemaConfig();
137
- let generator = new PrismaSchemaGenerator(schemaConfig);
138
- let success = await generator.generate();
139
- if(!success){
140
- Logger.critical('Failed to generate Prisma schema');
141
- return false;
142
- }
143
- Logger.info('Prisma schema generation completed successfully');
144
- return true;
145
- }
146
-
147
- }
148
-
149
- let generator = new PrismaSchemaGeneratorCLI();
150
- generator.run().then((success) => {
151
- if(!success){
152
- process.exit(1);
153
- }
154
- process.exit(0);
155
- }).catch((error) => {
156
- Logger.critical('Unexpected error: ' + error.message);
157
- process.exit(1);
158
- });
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * Reldens - Generate Prisma Schema CLI
6
+ *
7
+ */
8
+
9
+ const { PrismaSchemaGenerator } = require('../lib/prisma/prisma-schema-generator');
10
+ const { Logger, sc } = require('@reldens/utils');
11
+
12
+ class PrismaSchemaGeneratorCLI
13
+ {
14
+
15
+ constructor()
16
+ {
17
+ this.args = process.argv.slice(2);
18
+ this.config = {};
19
+ this.parseArguments();
20
+ }
21
+
22
+ parseArguments()
23
+ {
24
+ for(let i = 0; i < this.args.length; i++){
25
+ let arg = this.args[i];
26
+ if(!arg.startsWith('--')){
27
+ continue;
28
+ }
29
+ let equalIndex = arg.indexOf('=');
30
+ if(-1 === equalIndex){
31
+ let flag = arg.substring(2);
32
+ if('debug' === flag || 'dataProxy' === flag || 'help' === flag || 'h' === flag){
33
+ this.config[flag] = true;
34
+ }
35
+ continue;
36
+ }
37
+ let key = arg.substring(2, equalIndex);
38
+ let value = arg.substring(equalIndex + 1);
39
+ if('port' === key || 'checkInterval' === key || 'maxWaitTime' === key){
40
+ this.config[key] = parseInt(value);
41
+ continue;
42
+ }
43
+ if('generateBinaryTargets' === key){
44
+ this.config[key] = value.split(',').map(target => target.trim());
45
+ continue;
46
+ }
47
+ this.config[key] = value;
48
+ }
49
+ }
50
+
51
+ shouldShowHelp()
52
+ {
53
+ return 0 === this.args.length || sc.get(this.config, 'help', false) || sc.get(this.config, 'h', false);
54
+ }
55
+
56
+ showHelp()
57
+ {
58
+ Logger.info('');
59
+ Logger.info('Reldens Prisma Schema Generator');
60
+ Logger.info('================================');
61
+ Logger.info('');
62
+ Logger.info('Usage: npx reldens-generate-prisma-schema [options]');
63
+ Logger.info('');
64
+ Logger.info('Required Options:');
65
+ Logger.info(' --host=[host] Database host');
66
+ Logger.info(' --port=[port] Database port');
67
+ Logger.info(' --user=[user] Database user');
68
+ Logger.info(' --password=[password] Database password');
69
+ Logger.info(' --database=[database] Database name');
70
+ Logger.info('');
71
+ Logger.info('Optional Options:');
72
+ Logger.info(' --client=[client] Database client (default: mysql)');
73
+ Logger.info(' --debug Enable debug mode (default: false)');
74
+ Logger.info(' --dataProxy Enable data proxy (default: false)');
75
+ Logger.info(' --checkInterval=[ms] Check interval in milliseconds (default: 1000)');
76
+ Logger.info(' --maxWaitTime=[ms] Max wait time in milliseconds (default: 30000)');
77
+ Logger.info(' --prismaSchemaPath=[path] Path to Prisma schema directory');
78
+ Logger.info(' --clientOutputPath=[path] Client output path (if not set, uses Prisma default)');
79
+ Logger.info(' --generateBinaryTargets=[targets] Comma-separated binary targets (default: native,debian-openssl-1.1.x)');
80
+ Logger.info(' --dbParams=[params] Database connection parameters (e.g., authPlugin=mysql_native_password)');
81
+ Logger.info('');
82
+ Logger.info('Example:');
83
+ Logger.info(' npx reldens-generate-prisma-schema --host=localhost --port=3306 --user=root --password=secret --database=mydb');
84
+ Logger.info('');
85
+ Logger.info('Advanced Example:');
86
+ Logger.info(' npx reldens-generate-prisma-schema --host=localhost --port=3306 --user=root --password=secret --database=mydb --client=postgresql --debug --dataProxy --checkInterval=2000 --maxWaitTime=60000 --prismaSchemaPath=./custom/prisma --clientOutputPath=./custom/client --generateBinaryTargets=native,debian-openssl-1.1.x');
87
+ Logger.info('');
88
+ }
89
+
90
+ validateRequiredArgs()
91
+ {
92
+ let requiredArgs = ['host', 'port', 'user', 'password', 'database'];
93
+ let missing = [];
94
+ for(let arg of requiredArgs){
95
+ if(!this.config[arg]){
96
+ missing.push(arg);
97
+ }
98
+ }
99
+ if(0 < missing.length){
100
+ Logger.error('Missing required arguments: ' + missing.join(', '));
101
+ this.showHelp();
102
+ return false;
103
+ }
104
+ return true;
105
+ }
106
+
107
+ getSchemaConfig()
108
+ {
109
+ return {
110
+ config: {
111
+ host: this.config.host,
112
+ port: this.config.port,
113
+ user: this.config.user,
114
+ password: this.config.password,
115
+ database: this.config.database
116
+ },
117
+ client: sc.get(this.config, 'client', 'mysql'),
118
+ debug: sc.get(this.config, 'debug', false),
119
+ dataProxy: sc.get(this.config, 'dataProxy', false),
120
+ checkInterval: sc.get(this.config, 'checkInterval', 1000),
121
+ maxWaitTime: sc.get(this.config, 'maxWaitTime', 30000),
122
+ prismaSchemaPath: sc.get(this.config, 'prismaSchemaPath'),
123
+ clientOutputPath: sc.get(this.config, 'clientOutputPath'),
124
+ generateBinaryTargets: sc.get(this.config, 'generateBinaryTargets'),
125
+ dbParams: sc.get(this.config, 'dbParams')
126
+ };
127
+ }
128
+
129
+ async run()
130
+ {
131
+ if(this.shouldShowHelp()){
132
+ this.showHelp();
133
+ return true;
134
+ }
135
+ if(!this.validateRequiredArgs()){
136
+ return false;
137
+ }
138
+ let schemaConfig = this.getSchemaConfig();
139
+ let generator = new PrismaSchemaGenerator(schemaConfig);
140
+ let success = await generator.generate();
141
+ if(!success){
142
+ Logger.critical('Failed to generate Prisma schema');
143
+ return false;
144
+ }
145
+ Logger.info('Prisma schema generation completed successfully');
146
+ return true;
147
+ }
148
+
149
+ }
150
+
151
+ let generator = new PrismaSchemaGeneratorCLI();
152
+ generator.run().then((success) => {
153
+ if(!success){
154
+ process.exit(1);
155
+ }
156
+ process.exit(0);
157
+ }).catch((error) => {
158
+ Logger.critical('Unexpected error: ' + error.message);
159
+ process.exit(1);
160
+ });
@@ -1,180 +1,182 @@
1
- /**
2
- *
3
- * Reldens - PrismaSchemaGenerator
4
- *
5
- */
6
-
7
- const { execSync } = require('child_process');
8
- const { FileHandler } = require('@reldens/server-utils');
9
- const { Logger, sc } = require('@reldens/utils');
10
-
11
- class PrismaSchemaGenerator
12
- {
13
-
14
- constructor(props)
15
- {
16
- this.config = sc.get(props, 'config', {});
17
- this.client = sc.get(props, 'client', 'mysql');
18
- this.debug = sc.get(props, 'debug', false);
19
- this.dataProxy = sc.get(props, 'dataProxy', false);
20
- this.checkInterval = sc.get(props, 'checkInterval', 1000);
21
- this.maxWaitTime = sc.get(props, 'maxWaitTime', 30000);
22
- this.prismaSchemaPath = sc.get(props, 'prismaSchemaPath', FileHandler.joinPaths(process.cwd(), 'prisma'));
23
- this.schemaFilePath = FileHandler.joinPaths(this.prismaSchemaPath, 'schema.prisma');
24
- this.clientOutputPath = sc.get(props, 'clientOutputPath', '');
25
- this.generateBinaryTargets = sc.get(props, 'generateBinaryTargets', ['native']);
26
- }
27
-
28
- async generate()
29
- {
30
- FileHandler.createFolder(this.prismaSchemaPath);
31
- this.generateSchemaFile();
32
- Logger.info('Running prisma introspect "npx prisma db pull"...');
33
- try {
34
- execSync('npx prisma db pull', { stdio: 'inherit' });
35
- } catch(error) {
36
- Logger.critical('Failed to pull database schema: ' + error.message);
37
- return false;
38
- }
39
- let generateCommand = 'npx prisma generate';
40
- if(this.dataProxy){
41
- generateCommand += ' --data-proxy';
42
- }
43
- Logger.info('Running prisma generate "'+generateCommand+'"...');
44
- try {
45
- execSync(generateCommand, { stdio: 'inherit' });
46
- } catch(error) {
47
- let errorString = error.toString();
48
- if(errorString.includes('EPERM') && errorString.includes('query_engine-windows.dll.node')){
49
- Logger.warning('Windows permission error detected with query engine file.');
50
- Logger.warning('This is a known Prisma issue on Windows.');
51
- Logger.warning('Please manually run: ' + generateCommand);
52
- Logger.warning('You may need to close any processes using the Prisma client first.');
53
- return false;
54
- }
55
- Logger.critical('Generate command failed: ' + error.message);
56
- return false;
57
- }
58
- await this.waitForSchemaGeneration();
59
- return true;
60
- }
61
-
62
- async waitForSchemaGeneration()
63
- {
64
- let clientPath = this.clientOutputPath || 'node_modules/.prisma/client';
65
- let generatedClientPath = this.resolveClientPath(clientPath);
66
- let clientIndexPath = FileHandler.joinPaths(generatedClientPath, 'index.js');
67
- let startTime = Date.now();
68
- return new Promise((resolve) => {
69
- let interval = setInterval(() => {
70
- let awaitTime = Date.now() - startTime;
71
- Logger.info('Awaiting on schema generation: ' + clientIndexPath, (awaitTime/1000).toFixed(0));
72
- if(FileHandler.exists(clientIndexPath)){
73
- clearInterval(interval);
74
- resolve();
75
- return;
76
- }
77
- if(awaitTime > this.maxWaitTime){
78
- clearInterval(interval);
79
- Logger.warning('Schema generation wait timeout reached.');
80
- resolve();
81
- }
82
- }, this.checkInterval);
83
- });
84
- }
85
-
86
- resolveClientPath(clientPath)
87
- {
88
- if(clientPath.match(/^[a-zA-Z]:/) || clientPath.startsWith('/')){
89
- return clientPath;
90
- }
91
- if(clientPath.startsWith('node_modules')){
92
- return FileHandler.joinPaths(process.cwd(), clientPath);
93
- }
94
- return FileHandler.joinPaths(this.prismaSchemaPath, clientPath);
95
- }
96
-
97
- generateSchemaFile()
98
- {
99
- let datasourceProvider = this.getDatasourceProvider();
100
- let schemaContent = this.buildSchemaContent(
101
- datasourceProvider,
102
- this.buildConnectionString(datasourceProvider),
103
- this.buildDirectConnectionString(datasourceProvider)
104
- );
105
- FileHandler.writeFile(this.schemaFilePath, schemaContent);
106
- Logger.info('Generated Prisma schema file at: '+this.schemaFilePath);
107
- }
108
-
109
- getDatasourceProvider()
110
- {
111
- if('postgresql' === this.client || 'postgres' === this.client){
112
- return 'postgresql';
113
- }
114
- if('mongodb' === this.client){
115
- return 'mongodb';
116
- }
117
- return 'mysql';
118
- }
119
-
120
- buildConnectionString(datasourceProvider)
121
- {
122
- if(this.dataProxy){
123
- datasourceProvider = 'prisma';
124
- }
125
- return datasourceProvider + this.buildConnectionDataString();
126
- }
127
-
128
- buildDirectConnectionString(datasourceProvider)
129
- {
130
- if(!this.dataProxy){
131
- return '';
132
- }
133
- return datasourceProvider + this.buildConnectionDataString();
134
- }
135
-
136
- buildConnectionDataString()
137
- {
138
- return '://' + this.config.user + ':' + this.config.password
139
- + '@' + this.config.host+':' + this.config.port
140
- + '/' + this.config.database;
141
- }
142
-
143
- buildSchemaContent(datasourceProvider, connectionString, directConnectionString)
144
- {
145
- return this.buildGeneratorBlock() + '\n\n'
146
- + this.buildDatasourceBlock(datasourceProvider, connectionString, directConnectionString) + '\n';
147
- }
148
-
149
- buildGeneratorBlock()
150
- {
151
- let generatorContent = 'generator client {\n';
152
- generatorContent += ' provider = "prisma-client-js"\n';
153
- if(this.clientOutputPath){
154
- let normalizedPath = this.clientOutputPath.replace(/\\/g, '/');
155
- generatorContent += ' output = "' + normalizedPath + '"\n';
156
- }
157
- if(0 < this.generateBinaryTargets.length){
158
- generatorContent += ' binaryTargets = [' +
159
- this.generateBinaryTargets.map(target => '"' + target + '"').join(', ')
160
- + ']\n';
161
- }
162
- generatorContent += '}';
163
- return generatorContent;
164
- }
165
-
166
- buildDatasourceBlock(datasourceProvider, connectionString, directConnectionString)
167
- {
168
- let datasourceContent = 'datasource db {\n';
169
- datasourceContent += ' provider = "' + datasourceProvider + '"\n';
170
- datasourceContent += ' url = "' + connectionString + '"\n';
171
- if('' !== directConnectionString){
172
- datasourceContent += ' directUrl = "' + directConnectionString + '"\n';
173
- }
174
- datasourceContent += '}';
175
- return datasourceContent;
176
- }
177
-
178
- }
179
-
180
- module.exports.PrismaSchemaGenerator = PrismaSchemaGenerator;
1
+ /**
2
+ *
3
+ * Reldens - PrismaSchemaGenerator
4
+ *
5
+ */
6
+
7
+ const { execSync } = require('child_process');
8
+ const { FileHandler } = require('@reldens/server-utils');
9
+ const { Logger, sc } = require('@reldens/utils');
10
+
11
+ class PrismaSchemaGenerator
12
+ {
13
+
14
+ constructor(props)
15
+ {
16
+ this.config = sc.get(props, 'config', {});
17
+ this.client = sc.get(props, 'client', 'mysql');
18
+ this.debug = sc.get(props, 'debug', false);
19
+ this.dataProxy = sc.get(props, 'dataProxy', false);
20
+ this.checkInterval = sc.get(props, 'checkInterval', 1000);
21
+ this.maxWaitTime = sc.get(props, 'maxWaitTime', 30000);
22
+ this.prismaSchemaPath = sc.get(props, 'prismaSchemaPath', FileHandler.joinPaths(process.cwd(), 'prisma'));
23
+ this.schemaFilePath = FileHandler.joinPaths(this.prismaSchemaPath, 'schema.prisma');
24
+ this.clientOutputPath = sc.get(props, 'clientOutputPath', '');
25
+ this.generateBinaryTargets = sc.get(props, 'generateBinaryTargets', ['native', 'debian-openssl-1.1.x']);
26
+ this.dbParams = sc.get(props, 'dbParams', process.env.RELDENS_DB_PARAMS || '');
27
+ }
28
+
29
+ async generate()
30
+ {
31
+ FileHandler.createFolder(this.prismaSchemaPath);
32
+ this.generateSchemaFile();
33
+ Logger.info('Running prisma introspect "npx prisma db pull"...');
34
+ try {
35
+ execSync('npx prisma db pull', { stdio: 'inherit' });
36
+ } catch(error) {
37
+ Logger.critical('Failed to pull database schema: ' + error.message);
38
+ return false;
39
+ }
40
+ let generateCommand = 'npx prisma generate';
41
+ if(this.dataProxy){
42
+ generateCommand += ' --data-proxy';
43
+ }
44
+ Logger.info('Running prisma generate "'+generateCommand+'"...');
45
+ try {
46
+ execSync(generateCommand, { stdio: 'inherit' });
47
+ } catch(error) {
48
+ let errorString = error.toString();
49
+ if(errorString.includes('EPERM') && errorString.includes('query_engine-windows.dll.node')){
50
+ Logger.warning('Windows permission error detected with query engine file.');
51
+ Logger.warning('This is a known Prisma issue on Windows.');
52
+ Logger.warning('Please manually run: ' + generateCommand);
53
+ Logger.warning('You may need to close any processes using the Prisma client first.');
54
+ return false;
55
+ }
56
+ Logger.critical('Generate command failed: ' + error.message);
57
+ return false;
58
+ }
59
+ await this.waitForSchemaGeneration();
60
+ return true;
61
+ }
62
+
63
+ async waitForSchemaGeneration()
64
+ {
65
+ let clientPath = this.clientOutputPath || 'node_modules/.prisma/client';
66
+ let generatedClientPath = this.resolveClientPath(clientPath);
67
+ let clientIndexPath = FileHandler.joinPaths(generatedClientPath, 'index.js');
68
+ let startTime = Date.now();
69
+ return new Promise((resolve) => {
70
+ let interval = setInterval(() => {
71
+ let awaitTime = Date.now() - startTime;
72
+ Logger.info('Awaiting on schema generation: ' + clientIndexPath, (awaitTime/1000).toFixed(0));
73
+ if(FileHandler.exists(clientIndexPath)){
74
+ clearInterval(interval);
75
+ resolve();
76
+ return;
77
+ }
78
+ if(awaitTime > this.maxWaitTime){
79
+ clearInterval(interval);
80
+ Logger.warning('Schema generation wait timeout reached.');
81
+ resolve();
82
+ }
83
+ }, this.checkInterval);
84
+ });
85
+ }
86
+
87
+ resolveClientPath(clientPath)
88
+ {
89
+ if(clientPath.match(/^[a-zA-Z]:/) || clientPath.startsWith('/')){
90
+ return clientPath;
91
+ }
92
+ if(clientPath.startsWith('node_modules')){
93
+ return FileHandler.joinPaths(process.cwd(), clientPath);
94
+ }
95
+ return FileHandler.joinPaths(this.prismaSchemaPath, clientPath);
96
+ }
97
+
98
+ generateSchemaFile()
99
+ {
100
+ let datasourceProvider = this.getDatasourceProvider();
101
+ let schemaContent = this.buildSchemaContent(
102
+ datasourceProvider,
103
+ this.buildConnectionString(datasourceProvider),
104
+ this.buildDirectConnectionString(datasourceProvider)
105
+ );
106
+ FileHandler.writeFile(this.schemaFilePath, schemaContent);
107
+ Logger.info('Generated Prisma schema file at: '+this.schemaFilePath);
108
+ }
109
+
110
+ getDatasourceProvider()
111
+ {
112
+ if('postgresql' === this.client || 'postgres' === this.client){
113
+ return 'postgresql';
114
+ }
115
+ if('mongodb' === this.client){
116
+ return 'mongodb';
117
+ }
118
+ return 'mysql';
119
+ }
120
+
121
+ buildConnectionString(datasourceProvider)
122
+ {
123
+ if(this.dataProxy){
124
+ datasourceProvider = 'prisma';
125
+ }
126
+ return datasourceProvider + this.buildConnectionDataString();
127
+ }
128
+
129
+ buildDirectConnectionString(datasourceProvider)
130
+ {
131
+ if(!this.dataProxy){
132
+ return '';
133
+ }
134
+ return datasourceProvider + this.buildConnectionDataString();
135
+ }
136
+
137
+ buildConnectionDataString()
138
+ {
139
+ return '://' + this.config.user + ':' + this.config.password
140
+ + '@' + this.config.host+':' + this.config.port
141
+ + '/' + this.config.database
142
+ + (this.dbParams ? '?' + this.dbParams : '');
143
+ }
144
+
145
+ buildSchemaContent(datasourceProvider, connectionString, directConnectionString)
146
+ {
147
+ return this.buildGeneratorBlock() + '\n\n'
148
+ + this.buildDatasourceBlock(datasourceProvider, connectionString, directConnectionString) + '\n';
149
+ }
150
+
151
+ buildGeneratorBlock()
152
+ {
153
+ let generatorContent = 'generator client {\n';
154
+ generatorContent += ' provider = "prisma-client-js"\n';
155
+ if(this.clientOutputPath){
156
+ let normalizedPath = this.clientOutputPath.replace(/\\/g, '/');
157
+ generatorContent += ' output = "' + normalizedPath + '"\n';
158
+ }
159
+ if(0 < this.generateBinaryTargets.length){
160
+ generatorContent += ' binaryTargets = [' +
161
+ this.generateBinaryTargets.map(target => '"' + target + '"').join(', ')
162
+ + ']\n';
163
+ }
164
+ generatorContent += '}';
165
+ return generatorContent;
166
+ }
167
+
168
+ buildDatasourceBlock(datasourceProvider, connectionString, directConnectionString)
169
+ {
170
+ let datasourceContent = 'datasource db {\n';
171
+ datasourceContent += ' provider = "' + datasourceProvider + '"\n';
172
+ datasourceContent += ' url = "' + connectionString + '"\n';
173
+ if('' !== directConnectionString){
174
+ datasourceContent += ' directUrl = "' + directConnectionString + '"\n';
175
+ }
176
+ datasourceContent += '}';
177
+ return datasourceContent;
178
+ }
179
+
180
+ }
181
+
182
+ module.exports.PrismaSchemaGenerator = PrismaSchemaGenerator;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/storage",
3
3
  "scope": "@reldens",
4
- "version": "0.67.0",
4
+ "version": "0.69.0",
5
5
  "description": "Reldens - Storage",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",
@@ -42,16 +42,16 @@
42
42
  "url": "https://github.com/damian-pastorini/reldens-storage/issues"
43
43
  },
44
44
  "dependencies": {
45
- "@mikro-orm/core": "^6.4.16",
46
- "@mikro-orm/mongodb": "^6.4.16",
47
- "@mikro-orm/mysql": "^6.4.16",
48
- "@prisma/client": "^6.14.0",
49
- "@reldens/server-utils": "^0.25.0",
45
+ "@mikro-orm/core": "^6.5.2",
46
+ "@mikro-orm/mongodb": "^6.5.2",
47
+ "@mikro-orm/mysql": "^6.5.2",
48
+ "@prisma/client": "^6.15.0",
49
+ "@reldens/server-utils": "^0.26.0",
50
50
  "@reldens/utils": "^0.53.0",
51
51
  "knex": "^3.1.0",
52
52
  "mysql": "^2.18.1",
53
- "mysql2": "^3.14.3",
53
+ "mysql2": "^3.14.4",
54
54
  "objection": "^3.1.5",
55
- "prisma": "^6.14.0"
55
+ "prisma": "^6.15.0"
56
56
  }
57
57
  }