@carbonorm/carbonnode 1.2.0 → 1.2.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.
- package/package.json +1 -1
- package/scripts/assets/handlebars/C6.tsx.handlebars +9 -0
- package/scripts/assets/handlebars/Table.tsx.handlebars +94 -63
- package/scripts/generateRestBindings.cjs +2 -2
- package/scripts/generateRestBindings.ts +2 -2
- package/src/api/interfaces/ormInterfaces.ts +2 -1
- package/src/api/rest/C6.tsx +1606 -0
package/package.json
CHANGED
|
@@ -2,6 +2,10 @@ import {
|
|
|
2
2
|
C6RestfulModel,
|
|
3
3
|
C6Constants
|
|
4
4
|
} from "@carbonorm/carbonnode";
|
|
5
|
+
{{#TABLES}}
|
|
6
|
+
import {{TABLE_NAME_SHORT_PASCAL_CASE}} from "./{{TABLE_NAME_SHORT_PASCAL_CASE}}";
|
|
7
|
+
{{/TABLES}}
|
|
8
|
+
|
|
5
9
|
|
|
6
10
|
export type RestTableNames = {{{RestTableNames}}};
|
|
7
11
|
|
|
@@ -70,6 +74,11 @@ export const {{TABLE_NAME_SHORT}}: C6RestfulModel & iDefine{{TABLE_NAME_SHORT_PA
|
|
|
70
74
|
CONSTRAINT: '{{CONSTRAINT}}',
|
|
71
75
|
},{{/this}}],{{/each}}
|
|
72
76
|
},
|
|
77
|
+
REST_STATE_OPERATIONS: {
|
|
78
|
+
PUT: {{TABLE_NAME_SHORT_PASCAL_CASE}}.putState{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
79
|
+
POST: {{TABLE_NAME_SHORT_PASCAL_CASE}}.postState{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
80
|
+
DELETE: {{TABLE_NAME_SHORT_PASCAL_CASE}}.deleteState{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
81
|
+
},
|
|
73
82
|
}
|
|
74
83
|
{{/TABLES}}
|
|
75
84
|
|
|
@@ -10,97 +10,128 @@ import {
|
|
|
10
10
|
iPutC6RestResponse,
|
|
11
11
|
removeInvalidKeys
|
|
12
12
|
} from "@carbonorm/carbonnode";
|
|
13
|
+
import {AxiosResponse} from "axios";
|
|
14
|
+
import {iAPI, Modify} from "restRequest";
|
|
13
15
|
import {deleteRestfulObjectArrays, updateRestfulObjectArrays} from "@carbonorm/carbonreact";
|
|
14
|
-
import {C6, i{{
|
|
16
|
+
import {C6, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, {{TABLE_NAME_SHORT}}, RestShortTableNames} from "./C6";
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
{{{TABLE_DEFINITION}}}
|
|
20
|
+
**/
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
type GetCustomAndRequiredFields = {}
|
|
23
|
+
|
|
24
|
+
type GetRequestTableOverrides = {}
|
|
25
|
+
|
|
26
|
+
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
27
|
+
export const Get = restRequest<GetCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, GetRequestTableOverrides, iGetC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestShortTableNames>({
|
|
19
28
|
C6: C6,
|
|
20
|
-
tableName: {{
|
|
29
|
+
tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
|
|
21
30
|
requestMethod: GET,
|
|
22
31
|
queryCallback: (request) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
request.success ??= 'Successfully received {{TABLE_NAME_SHORT}}!'
|
|
33
|
+
request.error ??= 'An unknown issue occurred creating the {{TABLE_NAME_SHORT}}!'
|
|
34
|
+
return request
|
|
26
35
|
},
|
|
27
36
|
responseCallback: (response, _request) => {
|
|
28
|
-
updateRestfulObjectArrays<i{{
|
|
37
|
+
updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>(response?.data?.rest, "{{TABLE_NAME_SHORT}}", C6.{{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[])
|
|
29
38
|
}
|
|
30
|
-
})
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
type PutCustomAndRequiredFields = {}
|
|
42
|
+
|
|
43
|
+
type PutRequestTableOverrides = {}
|
|
44
|
+
|
|
45
|
+
export function putState{{TABLE_NAME_SHORT_PASCAL_CASE}}(response : AxiosResponse<iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>, request : iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
46
|
+
updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>([
|
|
47
|
+
removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
48
|
+
...request,
|
|
49
|
+
...response?.data?.rest,
|
|
50
|
+
}, C6.TABLES)
|
|
51
|
+
], "{{TABLE_NAME_SHORT}}", {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[])
|
|
52
|
+
}
|
|
31
53
|
|
|
32
|
-
export const Put = restRequest<
|
|
54
|
+
export const Put = restRequest<PutCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides, iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestShortTableNames>({
|
|
33
55
|
C6: C6,
|
|
34
|
-
tableName: {{
|
|
56
|
+
tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
|
|
35
57
|
requestMethod: PUT,
|
|
36
58
|
queryCallback: (request) => {
|
|
37
|
-
request.success ??= 'Successfully updated {{
|
|
38
|
-
request.error ??= 'An unknown issue occurred updating the {{
|
|
59
|
+
request.success ??= 'Successfully updated {{TABLE_NAME_SHORT}} data!'
|
|
60
|
+
request.error ??= 'An unknown issue occurred updating the {{TABLE_NAME_SHORT}} data!'
|
|
39
61
|
return request
|
|
40
62
|
},
|
|
41
|
-
responseCallback:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
...response?.data?.rest,
|
|
46
|
-
}, C6.TABLES)
|
|
47
|
-
], "{{noPrefix}}", {{noPrefix}}.PRIMARY_SHORT as (keyof i{{ucEachTableName}})[])
|
|
48
|
-
}
|
|
49
|
-
})
|
|
63
|
+
responseCallback: putState{{TABLE_NAME_SHORT_PASCAL_CASE}}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
type PostCustomAndRequiredFields = {}
|
|
50
67
|
|
|
68
|
+
type PostRequestTableOverrides = {}
|
|
51
69
|
|
|
52
|
-
export
|
|
70
|
+
export function postState{{TABLE_NAME_SHORT_PASCAL_CASE}}(response : AxiosResponse<iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>, request : iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
71
|
+
if ('number' === typeof id || 'string' === typeof id) {
|
|
72
|
+
if (1 !== {{TABLE_NAME_SHORT}}.PRIMARY_SHORT.length) {
|
|
73
|
+
console.error("C6 received unexpected result's given the primary key length");
|
|
74
|
+
} else {
|
|
75
|
+
request[{{TABLE_NAME_SHORT}}.PRIMARY_SHORT[0]] = id
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>(
|
|
79
|
+
undefined !== request.dataInsertMultipleRows
|
|
80
|
+
? request.dataInsertMultipleRows.map((request, index) => {
|
|
81
|
+
return removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
82
|
+
...request,
|
|
83
|
+
...(index === 0 ? response?.data?.rest : {}),
|
|
84
|
+
}, C6.TABLES)
|
|
85
|
+
})
|
|
86
|
+
: [
|
|
87
|
+
removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
88
|
+
...request,
|
|
89
|
+
...response?.data?.rest,
|
|
90
|
+
}, C6.TABLES)
|
|
91
|
+
],
|
|
92
|
+
"{{TABLE_NAME_SHORT}}",
|
|
93
|
+
{{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const Post = restRequest<PostCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PostRequestTableOverrides, iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestShortTableNames>({
|
|
53
98
|
C6: C6,
|
|
54
|
-
tableName: {{
|
|
99
|
+
tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
|
|
55
100
|
requestMethod: POST,
|
|
56
101
|
queryCallback: (request) => {
|
|
57
|
-
request.success ??= 'Successfully created the {{
|
|
58
|
-
request.error ??= 'An unknown issue occurred creating the {{
|
|
102
|
+
request.success ??= 'Successfully created the {{TABLE_NAME_SHORT}} data!'
|
|
103
|
+
request.error ??= 'An unknown issue occurred creating the {{TABLE_NAME_SHORT}} data!'
|
|
59
104
|
return request
|
|
60
105
|
},
|
|
61
|
-
responseCallback:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} else {
|
|
66
|
-
request[{{noPrefix}}.PRIMARY_SHORT[0]] = id
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
updateRestfulObjectArrays<i{{ucEachTableName}}>(
|
|
70
|
-
undefined !== request.dataInsertMultipleRows
|
|
71
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
72
|
-
return removeInvalidKeys<i{{ucEachTableName}}>({
|
|
73
|
-
...request,
|
|
74
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
75
|
-
}, C6.TABLES)
|
|
76
|
-
})
|
|
77
|
-
: [
|
|
78
|
-
removeInvalidKeys<i{{ucEachTableName}}>({
|
|
79
|
-
...request,
|
|
80
|
-
...response?.data?.rest,
|
|
81
|
-
}, C6.TABLES)
|
|
82
|
-
], "{{noPrefix}}", {{noPrefix}}.PRIMARY_SHORT as (keyof i{{ucEachTableName}})[])
|
|
83
|
-
}
|
|
84
|
-
})
|
|
106
|
+
responseCallback: postState{{TABLE_NAME_SHORT_PASCAL_CASE}}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
type DeleteCustomAndRequiredFields = {}
|
|
85
110
|
|
|
86
|
-
|
|
111
|
+
type DeleteRequestTableOverrides = {}
|
|
112
|
+
|
|
113
|
+
export function deleteState{{TABLE_NAME_SHORT_PASCAL_CASE}}(_response : AxiosResponse<iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>, request : iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
114
|
+
deleteRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>([
|
|
115
|
+
request
|
|
116
|
+
], "{{TABLE_NAME_SHORT}}", {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[])
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const Delete = restRequest<DeleteCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, DeleteRequestTableOverrides, iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestShortTableNames>({
|
|
87
120
|
C6: C6,
|
|
88
|
-
tableName: {{
|
|
121
|
+
tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
|
|
89
122
|
requestMethod: DELETE,
|
|
90
123
|
queryCallback: (request) => {
|
|
91
|
-
request.success ??= 'Successfully removed the {{
|
|
92
|
-
request.error ??= 'An unknown issue occurred removing the {{
|
|
124
|
+
request.success ??= 'Successfully removed the {{TABLE_NAME_SHORT}} data!'
|
|
125
|
+
request.error ??= 'An unknown issue occurred removing the {{TABLE_NAME_SHORT}} data!'
|
|
93
126
|
return request
|
|
94
127
|
},
|
|
95
|
-
responseCallback:
|
|
96
|
-
// todo - request . where
|
|
97
|
-
deleteRestfulObjectArrays<i{{ucEachTableName}}>([
|
|
98
|
-
request
|
|
99
|
-
], "{{noPrefix}}", {{noPrefix}}.PRIMARY_SHORT as (keyof i{{ucEachTableName}})[])
|
|
100
|
-
}
|
|
128
|
+
responseCallback: deleteState{{TABLE_NAME_SHORT_PASCAL_CASE}}
|
|
101
129
|
});
|
|
102
130
|
|
|
103
|
-
|
|
104
131
|
export default {
|
|
105
|
-
|
|
106
|
-
|
|
132
|
+
// Export all GET, POST, PUT, DELETE functions for each table
|
|
133
|
+
Get,
|
|
134
|
+
Post,
|
|
135
|
+
Put,
|
|
136
|
+
Delete,
|
|
137
|
+
}
|
|
@@ -287,8 +287,8 @@ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(c
|
|
|
287
287
|
var template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.tsx.handlebars'), 'utf-8');
|
|
288
288
|
var testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.tsx.handlebars'), 'utf-8');
|
|
289
289
|
Object.values(tableData.TABLES).map(function (tableData, key) {
|
|
290
|
-
var tableName = tableData.
|
|
290
|
+
var tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE;
|
|
291
291
|
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.tsx'), Handlebars.compile(template)(tableData));
|
|
292
|
-
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.
|
|
292
|
+
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.tsx'), Handlebars.compile(testTemplate)(tableData));
|
|
293
293
|
});
|
|
294
294
|
console.log('Successfully created CarbonORM bindings!');
|
|
@@ -375,11 +375,11 @@ const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/
|
|
|
375
375
|
|
|
376
376
|
Object.values(tableData.TABLES).map((tableData, key) => {
|
|
377
377
|
|
|
378
|
-
const tableName = tableData.
|
|
378
|
+
const tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE
|
|
379
379
|
|
|
380
380
|
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.tsx'), Handlebars.compile(template)(tableData));
|
|
381
381
|
|
|
382
|
-
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.
|
|
382
|
+
fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.tsx'), Handlebars.compile(testTemplate)(tableData));
|
|
383
383
|
|
|
384
384
|
})
|
|
385
385
|
|
|
@@ -36,5 +36,6 @@ export interface C6RestfulModel<RestShortTableNames extends string = string> {
|
|
|
36
36
|
REGEX_VALIDATION: RegExpMap,
|
|
37
37
|
TYPE_VALIDATION: {[key: string]: iTypeValidation},
|
|
38
38
|
TABLE_REFERENCES: {[columnName: string]: iConstraint[]},
|
|
39
|
-
TABLE_REFERENCED_BY: {[columnName: string]: iConstraint[]}
|
|
39
|
+
TABLE_REFERENCED_BY: {[columnName: string]: iConstraint[]},
|
|
40
|
+
REST_STATE_OPERATIONS: { PUT: Function, POST: Function, DELETE: Function },
|
|
40
41
|
}
|