@carbonorm/carbonnode 1.2.4 → 1.2.6
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/dist/api/interfaces/ormInterfaces.d.ts +5 -5
- package/package.json +1 -1
- package/scripts/assets/handlebars/Table.test.tsx.handlebars +3 -3
- package/scripts/assets/handlebars/WsLiveUpdates.tsx.handlebars +22 -0
- package/scripts/generateRestBindings.cjs +19 -11
- package/scripts/generateRestBindings.ts +29 -13
- package/src/api/interfaces/ormInterfaces.ts +2 -1
|
@@ -26,6 +26,11 @@ export type tC6Tables = {
|
|
|
26
26
|
[key: string]: any;
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
+
export type tWsLiveUpdate = {
|
|
30
|
+
PUT: Function;
|
|
31
|
+
POST: Function;
|
|
32
|
+
DELETE: Function;
|
|
33
|
+
};
|
|
29
34
|
export interface C6RestfulModel<RestShortTableNames extends string = string> {
|
|
30
35
|
TABLE_NAME: RestShortTableNames;
|
|
31
36
|
PRIMARY: string[];
|
|
@@ -41,9 +46,4 @@ export interface C6RestfulModel<RestShortTableNames extends string = string> {
|
|
|
41
46
|
TABLE_REFERENCED_BY: {
|
|
42
47
|
[columnName: string]: iConstraint[];
|
|
43
48
|
};
|
|
44
|
-
REST_STATE_OPERATIONS: {
|
|
45
|
-
PUT: Function;
|
|
46
|
-
POST: Function;
|
|
47
|
-
DELETE: Function;
|
|
48
|
-
};
|
|
49
49
|
}
|
package/package.json
CHANGED
|
@@ -14,9 +14,9 @@ const fillString = 'string' + randomString + randomInt;
|
|
|
14
14
|
**/
|
|
15
15
|
|
|
16
16
|
const Test_Data: i{{TABLE_NAME_SHORT_PASCAL_CASE}} = {
|
|
17
|
-
{{#each TYPE_VALIDATION}}
|
|
18
|
-
{{
|
|
19
|
-
{{/each}}
|
|
17
|
+
{{#each TYPE_VALIDATION}}{{#SKIP_COLUMN_IN_POST}}
|
|
18
|
+
{{COLUMN_NAME}}: {{#TYPESCRIPT_TYPE_IS_STRING}}fillString{{#MAX_LENGTH}}.substring(0, {{MAX_LENGTH}}){{/MAX_LENGTH}}{{/TYPESCRIPT_TYPE_IS_STRING}}{{#TYPESCRIPT_TYPE_IS_NUMBER}}randomInt{{/TYPESCRIPT_TYPE_IS_NUMBER}},
|
|
19
|
+
{{/SKIP_COLUMN_IN_POST}}{{/each}}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export default Test_Data;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tWsLiveUpdate
|
|
3
|
+
} from "@carbonorm/carbonnode";
|
|
4
|
+
|
|
5
|
+
{{#TABLES}}
|
|
6
|
+
import { putState{{TABLE_NAME_SHORT_PASCAL_CASE}}, postState{{TABLE_NAME_SHORT_PASCAL_CASE}}, deleteState{{TABLE_NAME_SHORT_PASCAL_CASE}} } from "./{{TABLE_NAME_SHORT_PASCAL_CASE}}";
|
|
7
|
+
{{/TABLES}}
|
|
8
|
+
|
|
9
|
+
const wsLiveUpdates: tWsLiveUpdate = {
|
|
10
|
+
{{#TABLES}}
|
|
11
|
+
{{TABLE_NAME_SHORT}}: {
|
|
12
|
+
PUT: putState{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
13
|
+
POST: postState{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
14
|
+
DELETE: deleteState{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
15
|
+
},
|
|
16
|
+
{{/TABLES}}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export default wsLiveUpdates;
|
|
21
|
+
|
|
22
|
+
|
|
@@ -140,17 +140,23 @@ var parseSQLToTypeScript = function (sql) {
|
|
|
140
140
|
var tableName = tableMatch[1];
|
|
141
141
|
var columnDefinitions = tableMatch[2];
|
|
142
142
|
var columns = {};
|
|
143
|
-
|
|
144
|
-
var
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
143
|
+
// Improved regular expression to match column definitions
|
|
144
|
+
var columnRegex = /\s*`([^`]*)`\s+(\w+)(?:\(([^)]+)\))?\s*(NOT NULL)?\s*(AUTO_INCREMENT)?\s*(DEFAULT\s+'.*?'|DEFAULT\s+\S+)?/gm;
|
|
145
|
+
var columnMatch;
|
|
146
|
+
var columnDefinitionsLines = columnDefinitions.split('\n');
|
|
147
|
+
columnDefinitionsLines.forEach(function (line) {
|
|
148
|
+
if (!line.match(/(PRIMARY KEY|UNIQUE KEY|CONSTRAINT)/)) {
|
|
149
|
+
while ((columnMatch = columnRegex.exec(line))) {
|
|
150
|
+
columns[columnMatch[1]] = {
|
|
151
|
+
type: columnMatch[2],
|
|
152
|
+
length: columnMatch[3] || '',
|
|
153
|
+
notNull: !!columnMatch[4],
|
|
154
|
+
autoIncrement: !!columnMatch[5],
|
|
155
|
+
defaultValue: columnMatch[6] ? columnMatch[6].replace(/^DEFAULT\s+/i, '') : ''
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
154
160
|
// Extract primary keys
|
|
155
161
|
var primaryKeyMatch = columnDefinitions.match(/PRIMARY KEY \(([^)]+)\)/i);
|
|
156
162
|
var primaryKeys = primaryKeyMatch
|
|
@@ -284,6 +290,8 @@ fs.writeFileSync(path.join(process.cwd(), 'C6MySqlDump.json'), JSON.stringify(ta
|
|
|
284
290
|
// import this file src/assets/handlebars/C6.tsx.handlebars for a mustache template
|
|
285
291
|
var c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.tsx.handlebars'), 'utf-8');
|
|
286
292
|
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(c6Template)(tableData));
|
|
293
|
+
var wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/WsLiveUpdates.tsx.handlebars'), 'utf-8');
|
|
294
|
+
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.tsx'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
|
|
287
295
|
var template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.tsx.handlebars'), 'utf-8');
|
|
288
296
|
var testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.tsx.handlebars'), 'utf-8');
|
|
289
297
|
Object.values(tableData.TABLES).map(function (tableData, key) {
|
|
@@ -211,19 +211,30 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
211
211
|
const tableName = tableMatch[1];
|
|
212
212
|
const columnDefinitions = tableMatch[2];
|
|
213
213
|
|
|
214
|
-
let columns
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
214
|
+
let columns = {};
|
|
215
|
+
|
|
216
|
+
// Improved regular expression to match column definitions
|
|
217
|
+
const columnRegex = /\s*`([^`]*)`\s+(\w+)(?:\(([^)]+)\))?\s*(NOT NULL)?\s*(AUTO_INCREMENT)?\s*(DEFAULT\s+'.*?'|DEFAULT\s+\S+)?/gm;
|
|
218
|
+
|
|
219
|
+
let columnMatch;
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
const columnDefinitionsLines = columnDefinitions.split('\n');
|
|
224
|
+
|
|
225
|
+
columnDefinitionsLines.forEach(line => {
|
|
226
|
+
if (!line.match(/(PRIMARY KEY|UNIQUE KEY|CONSTRAINT)/)) {
|
|
227
|
+
while ((columnMatch = columnRegex.exec(line))) {
|
|
228
|
+
columns[columnMatch[1]] = {
|
|
229
|
+
type: columnMatch[2],
|
|
230
|
+
length: columnMatch[3] || '',
|
|
231
|
+
notNull: !!columnMatch[4],
|
|
232
|
+
autoIncrement: !!columnMatch[5],
|
|
233
|
+
defaultValue: columnMatch[6] ? columnMatch[6].replace(/^DEFAULT\s+/i, '') : ''
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
227
238
|
|
|
228
239
|
// Extract primary keys
|
|
229
240
|
const primaryKeyMatch = columnDefinitions.match(/PRIMARY KEY \(([^)]+)\)/i);
|
|
@@ -235,6 +246,7 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
235
246
|
const foreignKeyRegex: RegExp = /CONSTRAINT `([^`]+)` FOREIGN KEY \(`([^`]+)`\) REFERENCES `([^`]+)` \(`([^`]+)`\)( ON DELETE (\w+))?( ON UPDATE (\w+))?/g;
|
|
236
247
|
let foreignKeyMatch: RegExpExecArray | null;
|
|
237
248
|
|
|
249
|
+
|
|
238
250
|
while ((foreignKeyMatch = foreignKeyRegex.exec(columnDefinitions))) {
|
|
239
251
|
const constraintName = foreignKeyMatch[1];
|
|
240
252
|
const localColumn = foreignKeyMatch[2];
|
|
@@ -369,6 +381,10 @@ const c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6
|
|
|
369
381
|
|
|
370
382
|
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(c6Template)(tableData));
|
|
371
383
|
|
|
384
|
+
const wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/WsLiveUpdates.tsx.handlebars'), 'utf-8');
|
|
385
|
+
|
|
386
|
+
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.tsx'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
|
|
387
|
+
|
|
372
388
|
const template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.tsx.handlebars'), 'utf-8');
|
|
373
389
|
|
|
374
390
|
const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.tsx.handlebars'), 'utf-8');
|
|
@@ -30,6 +30,8 @@ export interface iConstraint {
|
|
|
30
30
|
|
|
31
31
|
export type tC6Tables = { [key: string]: (C6RestfulModel & { [key: string]: any }) }
|
|
32
32
|
|
|
33
|
+
export type tWsLiveUpdate = { PUT: Function, POST: Function, DELETE: Function };
|
|
34
|
+
|
|
33
35
|
export interface C6RestfulModel<RestShortTableNames extends string = string> {
|
|
34
36
|
TABLE_NAME: RestShortTableNames,
|
|
35
37
|
PRIMARY: string[],
|
|
@@ -39,5 +41,4 @@ export interface C6RestfulModel<RestShortTableNames extends string = string> {
|
|
|
39
41
|
TYPE_VALIDATION: {[key: string]: iTypeValidation},
|
|
40
42
|
TABLE_REFERENCES: {[columnName: string]: iConstraint[]},
|
|
41
43
|
TABLE_REFERENCED_BY: {[columnName: string]: iConstraint[]},
|
|
42
|
-
REST_STATE_OPERATIONS: { PUT: Function, POST: Function, DELETE: Function },
|
|
43
44
|
}
|