@carbonorm/carbonnode 1.4.4 → 1.5.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 +498 -2
- package/dist/api/restRequest.d.ts +2 -1
- package/dist/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +3 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -2
- package/scripts/assets/handlebars/Table.ts.handlebars +4 -0
- package/scripts/generateRestBindings.cjs +23 -16
- package/scripts/generateRestBindings.ts +27 -20
- package/src/api/restRequest.ts +30 -22
|
@@ -26,7 +26,7 @@ var MySQLDump = /** @class */ (function () {
|
|
|
26
26
|
function MySQLDump() {
|
|
27
27
|
}
|
|
28
28
|
MySQLDump.buildCNF = function (cnfFile) {
|
|
29
|
-
if (cnfFile === void 0) { cnfFile =
|
|
29
|
+
if (cnfFile === void 0) { cnfFile = ''; }
|
|
30
30
|
if (this.mysqlcnf !== '') {
|
|
31
31
|
return this.mysqlcnf;
|
|
32
32
|
}
|
|
@@ -39,7 +39,9 @@ var MySQLDump = /** @class */ (function () {
|
|
|
39
39
|
'',
|
|
40
40
|
];
|
|
41
41
|
cnf.push("");
|
|
42
|
-
|
|
42
|
+
if ('' === cnfFile) {
|
|
43
|
+
cnfFile = path.join(process.cwd(), '/mysql.cnf');
|
|
44
|
+
}
|
|
43
45
|
try {
|
|
44
46
|
fs.writeFileSync(cnfFile, cnf.join('\n'));
|
|
45
47
|
fs.chmodSync(cnfFile, 488);
|
|
@@ -52,14 +54,13 @@ var MySQLDump = /** @class */ (function () {
|
|
|
52
54
|
return (this.mysqlcnf = cnfFile);
|
|
53
55
|
};
|
|
54
56
|
MySQLDump.MySQLDump = function (mysqldump, data, schemas, outputFile, otherOption, specificTable) {
|
|
55
|
-
if (mysqldump === void 0) { mysqldump =
|
|
57
|
+
if (mysqldump === void 0) { mysqldump = 'mysqldump'; }
|
|
56
58
|
if (data === void 0) { data = false; }
|
|
57
59
|
if (schemas === void 0) { schemas = true; }
|
|
58
|
-
if (outputFile === void 0) { outputFile =
|
|
60
|
+
if (outputFile === void 0) { outputFile = ''; }
|
|
59
61
|
if (otherOption === void 0) { otherOption = ''; }
|
|
60
|
-
if (specificTable === void 0) { specificTable =
|
|
61
|
-
|
|
62
|
-
if (outputFile === null) {
|
|
62
|
+
if (specificTable === void 0) { specificTable = ''; }
|
|
63
|
+
if (outputFile === '') {
|
|
63
64
|
outputFile = path.join(process.cwd(), 'mysqldump.sql');
|
|
64
65
|
}
|
|
65
66
|
if (!data && !schemas) {
|
|
@@ -68,7 +69,7 @@ var MySQLDump = /** @class */ (function () {
|
|
|
68
69
|
var defaultsExtraFile = this.buildCNF();
|
|
69
70
|
var hexBlobOption = data ? '--hex-blob ' : '--no-data ';
|
|
70
71
|
var createInfoOption = schemas ? '' : ' --no-create-info ';
|
|
71
|
-
var cmd = "".concat(mysqldump
|
|
72
|
+
var cmd = "".concat(mysqldump, " --defaults-extra-file=\"").concat(defaultsExtraFile, "\" ").concat(otherOption, " --skip-add-locks --single-transaction --quick ").concat(createInfoOption).concat(hexBlobOption).concat(this.DB_NAME, " ").concat(specificTable, " > '").concat(outputFile, "'");
|
|
72
73
|
this.executeAndCheckStatus(cmd);
|
|
73
74
|
return (this.mysqldump = outputFile);
|
|
74
75
|
};
|
|
@@ -79,11 +80,10 @@ var MySQLDump = /** @class */ (function () {
|
|
|
79
80
|
var stdout = execSync(command, { encoding: 'utf-8' });
|
|
80
81
|
output.push(stdout);
|
|
81
82
|
}
|
|
82
|
-
catch (
|
|
83
|
-
console.log("
|
|
84
|
-
console.log("Command output::\t ".concat(error.stdout));
|
|
83
|
+
catch (e) {
|
|
84
|
+
console.log("Command output::", e);
|
|
85
85
|
if (exitOnFailure) {
|
|
86
|
-
process.exit(
|
|
86
|
+
process.exit(1);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
};
|
|
@@ -170,8 +170,8 @@ var parseSQLToTypeScript = function (sql) {
|
|
|
170
170
|
var localColumn = foreignKeyMatch[2];
|
|
171
171
|
var foreignTable = foreignKeyMatch[3];
|
|
172
172
|
var foreignColumn = foreignKeyMatch[4];
|
|
173
|
-
var onDeleteAction = foreignKeyMatch[6] ||
|
|
174
|
-
var onUpdateAction = foreignKeyMatch[8] ||
|
|
173
|
+
var onDeleteAction = foreignKeyMatch[6] || '';
|
|
174
|
+
var onUpdateAction = foreignKeyMatch[8] || '';
|
|
175
175
|
references.push({
|
|
176
176
|
TABLE: tableName,
|
|
177
177
|
CONSTRAINT: constraintName,
|
|
@@ -186,6 +186,7 @@ var parseSQLToTypeScript = function (sql) {
|
|
|
186
186
|
TABLE_NAME: tableName,
|
|
187
187
|
TABLE_DEFINITION: tableMatch[0],
|
|
188
188
|
TABLE_CONSTRAINT: references,
|
|
189
|
+
REST_URL_EXPRESSION: argMap['--restUrlExpression'] || '"/rest/"',
|
|
189
190
|
TABLE_NAME_SHORT: tableName.replace(MySQLDump.DB_PREFIX, ''),
|
|
190
191
|
TABLE_NAME_LOWER: tableName.toLowerCase(),
|
|
191
192
|
TABLE_NAME_UPPER: tableName.toUpperCase(),
|
|
@@ -244,12 +245,15 @@ var parseSQLToTypeScript = function (sql) {
|
|
|
244
245
|
console.log("Foreign table ".concat(foreignTable, " not found for ").concat(ref.TABLE, ".").concat(ref.CONSTRAINT));
|
|
245
246
|
continue;
|
|
246
247
|
}
|
|
247
|
-
if (!tableData[foreignTable]
|
|
248
|
+
if (!('TABLE_REFERENCED_BY' in tableData[foreignTable])) {
|
|
248
249
|
tableData[foreignTable].TABLE_REFERENCED_BY = {};
|
|
249
250
|
}
|
|
251
|
+
// @ts-ignore
|
|
250
252
|
if (!tableData[foreignTable].TABLE_REFERENCED_BY[foreignColumn]) {
|
|
253
|
+
// @ts-ignore
|
|
251
254
|
tableData[foreignTable].TABLE_REFERENCED_BY[foreignColumn] = [];
|
|
252
255
|
}
|
|
256
|
+
// @ts-ignore
|
|
253
257
|
tableData[foreignTable].TABLE_REFERENCED_BY[foreignColumn].push({
|
|
254
258
|
TABLE: tableName,
|
|
255
259
|
COLUMN: columnName,
|
|
@@ -258,9 +262,12 @@ var parseSQLToTypeScript = function (sql) {
|
|
|
258
262
|
if (!tableData[tableName].TABLE_REFERENCES) {
|
|
259
263
|
tableData[tableName].TABLE_REFERENCES = {};
|
|
260
264
|
}
|
|
265
|
+
// @ts-ignore
|
|
261
266
|
if (!tableData[tableName].TABLE_REFERENCES[columnName]) {
|
|
267
|
+
// @ts-ignore
|
|
262
268
|
tableData[tableName].TABLE_REFERENCES[columnName] = [];
|
|
263
269
|
}
|
|
270
|
+
// @ts-ignore
|
|
264
271
|
tableData[tableName].TABLE_REFERENCES[columnName].push({
|
|
265
272
|
TABLE: foreignTable,
|
|
266
273
|
COLUMN: foreignColumn,
|
|
@@ -296,7 +303,7 @@ var wsLiveUpdatesTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/hand
|
|
|
296
303
|
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'WsLiveUpdates.ts'), Handlebars.compile(wsLiveUpdatesTemplate)(tableData));
|
|
297
304
|
var template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.ts.handlebars'), 'utf-8');
|
|
298
305
|
var testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.ts.handlebars'), 'utf-8');
|
|
299
|
-
Object.values(tableData.TABLES).
|
|
306
|
+
Object.values(tableData.TABLES).forEach(function (tableData) {
|
|
300
307
|
var tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE;
|
|
301
308
|
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.ts'), Handlebars.compile(template)(tableData));
|
|
302
309
|
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.ts'), Handlebars.compile(testTemplate)(tableData));
|
|
@@ -14,7 +14,7 @@ for (let i = 0; i < args.length; i += 2) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const createDirIfNotExists = dir =>
|
|
17
|
-
!fs.existsSync(dir) ? fs.mkdirSync(dir, {
|
|
17
|
+
!fs.existsSync(dir) ? fs.mkdirSync(dir, {recursive: true}) : undefined;
|
|
18
18
|
|
|
19
19
|
class MySQLDump {
|
|
20
20
|
|
|
@@ -29,7 +29,7 @@ class MySQLDump {
|
|
|
29
29
|
static RELATIVE_OUTPUT_DIR = argMap['--output'] || '/src/api/rest';
|
|
30
30
|
static OUTPUT_DIR = path.join(process.cwd(), MySQLDump.RELATIVE_OUTPUT_DIR);
|
|
31
31
|
|
|
32
|
-
static buildCNF(cnfFile =
|
|
32
|
+
static buildCNF(cnfFile: string = '') {
|
|
33
33
|
|
|
34
34
|
if (this.mysqlcnf !== '') {
|
|
35
35
|
|
|
@@ -46,10 +46,13 @@ class MySQLDump {
|
|
|
46
46
|
'',
|
|
47
47
|
];
|
|
48
48
|
|
|
49
|
-
|
|
50
49
|
cnf.push(``);
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
if ('' === cnfFile) {
|
|
52
|
+
|
|
53
|
+
cnfFile = path.join(process.cwd(), '/mysql.cnf');
|
|
54
|
+
|
|
55
|
+
}
|
|
53
56
|
|
|
54
57
|
try {
|
|
55
58
|
|
|
@@ -71,10 +74,9 @@ class MySQLDump {
|
|
|
71
74
|
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
static MySQLDump(mysqldump =
|
|
75
|
-
specificTable = specificTable || '';
|
|
77
|
+
static MySQLDump(mysqldump: string = 'mysqldump', data = false, schemas = true, outputFile = '', otherOption = '', specificTable: string = '') {
|
|
76
78
|
|
|
77
|
-
if (outputFile ===
|
|
79
|
+
if (outputFile === '') {
|
|
78
80
|
outputFile = path.join(process.cwd(), 'mysqldump.sql');
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -88,7 +90,7 @@ class MySQLDump {
|
|
|
88
90
|
|
|
89
91
|
const createInfoOption = schemas ? '' : ' --no-create-info ';
|
|
90
92
|
|
|
91
|
-
const cmd = `${mysqldump
|
|
93
|
+
const cmd = `${mysqldump} --defaults-extra-file="${defaultsExtraFile}" ${otherOption} --skip-add-locks --single-transaction --quick ${createInfoOption}${hexBlobOption}${this.DB_NAME} ${specificTable} > '${outputFile}'`;
|
|
92
94
|
|
|
93
95
|
this.executeAndCheckStatus(cmd);
|
|
94
96
|
|
|
@@ -96,7 +98,7 @@ class MySQLDump {
|
|
|
96
98
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
static executeAndCheckStatus(command, exitOnFailure = true, output = []) {
|
|
101
|
+
static executeAndCheckStatus(command: string, exitOnFailure = true, output: any[] = []) {
|
|
100
102
|
|
|
101
103
|
try {
|
|
102
104
|
|
|
@@ -104,18 +106,17 @@ class MySQLDump {
|
|
|
104
106
|
|
|
105
107
|
output.push(stdout);
|
|
106
108
|
|
|
107
|
-
} catch (
|
|
108
|
-
|
|
109
|
-
console.log(`The command >> ${command} \n\t returned with a status code (${error.status}). Expecting 0 for success.`);
|
|
109
|
+
} catch (e) {
|
|
110
110
|
|
|
111
|
-
console.log(`Command output
|
|
111
|
+
console.log(`Command output::`, e);
|
|
112
112
|
|
|
113
113
|
if (exitOnFailure) {
|
|
114
114
|
|
|
115
|
-
process.exit(
|
|
115
|
+
process.exit(1);
|
|
116
116
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
}
|
|
@@ -220,7 +221,6 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
220
221
|
let columnMatch;
|
|
221
222
|
|
|
222
223
|
|
|
223
|
-
|
|
224
224
|
const columnDefinitionsLines = columnDefinitions.split('\n');
|
|
225
225
|
|
|
226
226
|
columnDefinitionsLines.forEach(line => {
|
|
@@ -253,8 +253,8 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
253
253
|
const localColumn = foreignKeyMatch[2];
|
|
254
254
|
const foreignTable = foreignKeyMatch[3];
|
|
255
255
|
const foreignColumn = foreignKeyMatch[4];
|
|
256
|
-
const onDeleteAction = foreignKeyMatch[6] ||
|
|
257
|
-
const onUpdateAction = foreignKeyMatch[8] ||
|
|
256
|
+
const onDeleteAction = foreignKeyMatch[6] || '';
|
|
257
|
+
const onUpdateAction = foreignKeyMatch[8] || '';
|
|
258
258
|
|
|
259
259
|
references.push({
|
|
260
260
|
TABLE: tableName,
|
|
@@ -272,6 +272,7 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
272
272
|
TABLE_NAME: tableName,
|
|
273
273
|
TABLE_DEFINITION: tableMatch[0],
|
|
274
274
|
TABLE_CONSTRAINT: references,
|
|
275
|
+
REST_URL_EXPRESSION: argMap['--restUrlExpression'] || '"/rest/"',
|
|
275
276
|
TABLE_NAME_SHORT: tableName.replace(MySQLDump.DB_PREFIX, ''),
|
|
276
277
|
TABLE_NAME_LOWER: tableName.toLowerCase(),
|
|
277
278
|
TABLE_NAME_UPPER: tableName.toUpperCase(),
|
|
@@ -284,7 +285,7 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
284
285
|
TYPE_VALIDATION: {},
|
|
285
286
|
REGEX_VALIDATION: {},
|
|
286
287
|
TABLE_REFERENCES: {},
|
|
287
|
-
TABLE_REFERENCED_BY:{},
|
|
288
|
+
TABLE_REFERENCED_BY: {},
|
|
288
289
|
};
|
|
289
290
|
|
|
290
291
|
for (const colName in columns) {
|
|
@@ -326,14 +327,17 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
326
327
|
continue;
|
|
327
328
|
}
|
|
328
329
|
|
|
329
|
-
if (!tableData[foreignTable]
|
|
330
|
+
if (!('TABLE_REFERENCED_BY' in tableData[foreignTable])) {
|
|
330
331
|
tableData[foreignTable].TABLE_REFERENCED_BY = {};
|
|
331
332
|
}
|
|
332
333
|
|
|
334
|
+
// @ts-ignore
|
|
333
335
|
if (!tableData[foreignTable].TABLE_REFERENCED_BY[foreignColumn]) {
|
|
336
|
+
// @ts-ignore
|
|
334
337
|
tableData[foreignTable].TABLE_REFERENCED_BY[foreignColumn] = [];
|
|
335
338
|
}
|
|
336
339
|
|
|
340
|
+
// @ts-ignore
|
|
337
341
|
tableData[foreignTable].TABLE_REFERENCED_BY[foreignColumn].push({
|
|
338
342
|
TABLE: tableName,
|
|
339
343
|
COLUMN: columnName,
|
|
@@ -344,10 +348,13 @@ const parseSQLToTypeScript = (sql: string) => {
|
|
|
344
348
|
tableData[tableName].TABLE_REFERENCES = {};
|
|
345
349
|
}
|
|
346
350
|
|
|
351
|
+
// @ts-ignore
|
|
347
352
|
if (!tableData[tableName].TABLE_REFERENCES[columnName]) {
|
|
353
|
+
// @ts-ignore
|
|
348
354
|
tableData[tableName].TABLE_REFERENCES[columnName] = [];
|
|
349
355
|
}
|
|
350
356
|
|
|
357
|
+
// @ts-ignore
|
|
351
358
|
tableData[tableName].TABLE_REFERENCES[columnName].push({
|
|
352
359
|
TABLE: foreignTable,
|
|
353
360
|
COLUMN: foreignColumn,
|
|
@@ -390,7 +397,7 @@ const template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Tabl
|
|
|
390
397
|
|
|
391
398
|
const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.ts.handlebars'), 'utf-8');
|
|
392
399
|
|
|
393
|
-
Object.values(tableData.TABLES).
|
|
400
|
+
Object.values(tableData.TABLES).forEach((tableData) => {
|
|
394
401
|
|
|
395
402
|
const tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE
|
|
396
403
|
|
package/src/api/restRequest.ts
CHANGED
|
@@ -44,7 +44,9 @@ export function TestRestfulResponse(response: AxiosResponse | any, success: ((r:
|
|
|
44
44
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export function removeInvalidKeys<iRestObject>(request: any, c6Tables: {
|
|
47
|
+
export function removeInvalidKeys<iRestObject>(request: any, c6Tables: {
|
|
48
|
+
[key: string]: (iC6RestfulModel & { [key: string]: any })
|
|
49
|
+
}): iRestObject {
|
|
48
50
|
|
|
49
51
|
let intersection: iRestObject = {} as iRestObject
|
|
50
52
|
|
|
@@ -300,6 +302,7 @@ export interface iC6Object {
|
|
|
300
302
|
{ [key: string]: string | number }
|
|
301
303
|
},
|
|
302
304
|
PREFIX: string,
|
|
305
|
+
|
|
303
306
|
[key: string]: any
|
|
304
307
|
}
|
|
305
308
|
|
|
@@ -324,6 +327,7 @@ interface iRest<CustomAndRequiredFields extends { [key: string]: any }, RestTabl
|
|
|
324
327
|
C6: iC6Object,
|
|
325
328
|
axios?: AxiosInstance,
|
|
326
329
|
restURL?: string,
|
|
330
|
+
withCredentials?: boolean,
|
|
327
331
|
tableName: RestShortTableNames | RestShortTableNames[],
|
|
328
332
|
requestMethod: iRestMethods,
|
|
329
333
|
clearCache?: () => void,
|
|
@@ -362,6 +366,7 @@ export default function restApi<
|
|
|
362
366
|
C6,
|
|
363
367
|
axios = axiosInstance,
|
|
364
368
|
restURL = '/rest/',
|
|
369
|
+
withCredentials = true,
|
|
365
370
|
tableName,
|
|
366
371
|
requestMethod = GET,
|
|
367
372
|
queryCallback = {},
|
|
@@ -676,42 +681,45 @@ export default function restApi<
|
|
|
676
681
|
|
|
677
682
|
const axiosActiveRequest: AxiosPromise<ResponseDataType> = axios[requestMethod.toLowerCase()]<ResponseDataType>(
|
|
678
683
|
restRequestUri,
|
|
679
|
-
|
|
684
|
+
{
|
|
685
|
+
withCredentials: withCredentials,
|
|
686
|
+
...((() => {
|
|
680
687
|
|
|
681
|
-
|
|
688
|
+
if (requestMethod === GET) {
|
|
682
689
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
690
|
+
return {
|
|
691
|
+
params: query
|
|
692
|
+
}
|
|
686
693
|
|
|
687
|
-
|
|
694
|
+
} else if (requestMethod === POST) {
|
|
688
695
|
|
|
689
|
-
|
|
696
|
+
if (undefined !== request?.dataInsertMultipleRows) {
|
|
690
697
|
|
|
691
|
-
|
|
692
|
-
|
|
698
|
+
return request.dataInsertMultipleRows.map(data =>
|
|
699
|
+
convertForRequestBody<typeof data>(data, fullTableList, C6, (message) => toast.error(message, toastOptions)));
|
|
693
700
|
|
|
694
|
-
|
|
701
|
+
}
|
|
695
702
|
|
|
696
|
-
|
|
703
|
+
return convertForRequestBody<RestTableInterfaces>(query as RestTableInterfaces, fullTableList, C6, (message) => toast.error(message, toastOptions))
|
|
697
704
|
|
|
698
|
-
|
|
705
|
+
} else if (requestMethod === PUT) {
|
|
699
706
|
|
|
700
|
-
|
|
707
|
+
return convertForRequestBody<RestTableInterfaces>(query as RestTableInterfaces, fullTableList, C6, (message) => toast.error(message, toastOptions))
|
|
701
708
|
|
|
702
|
-
|
|
709
|
+
} else if (requestMethod === DELETE) {
|
|
703
710
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
711
|
+
return {
|
|
712
|
+
data: convertForRequestBody<RestTableInterfaces>(query as RestTableInterfaces, fullTableList, C6, (message) => toast.error(message, toastOptions))
|
|
713
|
+
}
|
|
707
714
|
|
|
708
|
-
|
|
715
|
+
} else {
|
|
709
716
|
|
|
710
|
-
|
|
717
|
+
throw new Error('The request method (' + requestMethod + ') was not recognized.')
|
|
711
718
|
|
|
712
|
-
|
|
719
|
+
}
|
|
713
720
|
|
|
714
|
-
|
|
721
|
+
})())
|
|
722
|
+
}
|
|
715
723
|
);
|
|
716
724
|
|
|
717
725
|
if (cachingConfirmed) {
|