@carbonorm/carbonnode 1.1.11 → 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.
@@ -0,0 +1,137 @@
1
+ import {
2
+ iPostC6RestResponse,
3
+ restRequest,
4
+ GET,
5
+ POST,
6
+ PUT,
7
+ DELETE,
8
+ iDeleteC6RestResponse,
9
+ iGetC6RestResponse,
10
+ iPutC6RestResponse,
11
+ removeInvalidKeys
12
+ } from "@carbonorm/carbonnode";
13
+ import {AxiosResponse} from "axios";
14
+ import {iAPI, Modify} from "restRequest";
15
+ import {deleteRestfulObjectArrays, updateRestfulObjectArrays} from "@carbonorm/carbonreact";
16
+ import {C6, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, {{TABLE_NAME_SHORT}}, RestShortTableNames} from "./C6";
17
+
18
+ /**
19
+ {{{TABLE_DEFINITION}}}
20
+ **/
21
+
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>({
28
+ C6: C6,
29
+ tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
30
+ requestMethod: GET,
31
+ queryCallback: (request) => {
32
+ request.success ??= 'Successfully received {{TABLE_NAME_SHORT}}!'
33
+ request.error ??= 'An unknown issue occurred creating the {{TABLE_NAME_SHORT}}!'
34
+ return request
35
+ },
36
+ responseCallback: (response, _request) => {
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}})[])
38
+ }
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
+ }
53
+
54
+ export const Put = restRequest<PutCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides, iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestShortTableNames>({
55
+ C6: C6,
56
+ tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
57
+ requestMethod: PUT,
58
+ queryCallback: (request) => {
59
+ request.success ??= 'Successfully updated {{TABLE_NAME_SHORT}} data!'
60
+ request.error ??= 'An unknown issue occurred updating the {{TABLE_NAME_SHORT}} data!'
61
+ return request
62
+ },
63
+ responseCallback: putState{{TABLE_NAME_SHORT_PASCAL_CASE}}
64
+ });
65
+
66
+ type PostCustomAndRequiredFields = {}
67
+
68
+ type PostRequestTableOverrides = {}
69
+
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>({
98
+ C6: C6,
99
+ tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
100
+ requestMethod: POST,
101
+ queryCallback: (request) => {
102
+ request.success ??= 'Successfully created the {{TABLE_NAME_SHORT}} data!'
103
+ request.error ??= 'An unknown issue occurred creating the {{TABLE_NAME_SHORT}} data!'
104
+ return request
105
+ },
106
+ responseCallback: postState{{TABLE_NAME_SHORT_PASCAL_CASE}}
107
+ });
108
+
109
+ type DeleteCustomAndRequiredFields = {}
110
+
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>({
120
+ C6: C6,
121
+ tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
122
+ requestMethod: DELETE,
123
+ queryCallback: (request) => {
124
+ request.success ??= 'Successfully removed the {{TABLE_NAME_SHORT}} data!'
125
+ request.error ??= 'An unknown issue occurred removing the {{TABLE_NAME_SHORT}} data!'
126
+ return request
127
+ },
128
+ responseCallback: deleteState{{TABLE_NAME_SHORT_PASCAL_CASE}}
129
+ });
130
+
131
+ export default {
132
+ // Export all GET, POST, PUT, DELETE functions for each table
133
+ Get,
134
+ Post,
135
+ Put,
136
+ Delete,
137
+ }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  var __values = (this && this.__values) || function(o) {
2
3
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
4
  if (m) return m.call(o);
@@ -19,7 +20,7 @@ for (var i = 0; i < args.length; i += 2) {
19
20
  argMap[args[i]] = args[i + 1];
20
21
  }
21
22
  var createDirIfNotExists = function (dir) {
22
- return !fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined;
23
+ return !fs.existsSync(dir) ? fs.mkdirSync(dir, { recursive: true }) : undefined;
23
24
  };
24
25
  var MySQLDump = /** @class */ (function () {
25
26
  function MySQLDump() {
@@ -281,11 +282,13 @@ var tableData = parseSQLToTypeScript(sql);
281
282
  // write to file
282
283
  fs.writeFileSync(path.join(process.cwd(), 'C6MySqlDump.json'), JSON.stringify(tableData));
283
284
  // import this file src/assets/handlebars/C6.tsx.handlebars for a mustache template
284
- var template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.tsx.handlebars'), 'utf-8');
285
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(template)(tableData));
286
- var testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Tests.tsx.handlebars'), 'utf-8');
285
+ var c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.tsx.handlebars'), 'utf-8');
286
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(c6Template)(tableData));
287
+ var template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.tsx.handlebars'), 'utf-8');
288
+ var testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.tsx.handlebars'), 'utf-8');
287
289
  Object.values(tableData.TABLES).map(function (tableData, key) {
288
- var tableName = tableData.TABLE_NAME_SHORT;
289
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.tsx'), Handlebars.compile(testTemplate)(tableData));
290
+ var tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE;
291
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.tsx'), Handlebars.compile(template)(tableData));
292
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.tsx'), Handlebars.compile(testTemplate)(tableData));
290
293
  });
291
294
  console.log('Successfully created CarbonORM bindings!');
@@ -365,17 +365,21 @@ fs.writeFileSync(path.join(process.cwd(), 'C6MySqlDump.json'), JSON.stringify(ta
365
365
 
366
366
  // import this file src/assets/handlebars/C6.tsx.handlebars for a mustache template
367
367
 
368
- const template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.tsx.handlebars'), 'utf-8');
368
+ const c6Template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/C6.tsx.handlebars'), 'utf-8');
369
369
 
370
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(template)(tableData));
370
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, 'C6.tsx'), Handlebars.compile(c6Template)(tableData));
371
371
 
372
- const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Tests.tsx.handlebars'), 'utf-8');
372
+ const template = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.tsx.handlebars'), 'utf-8');
373
+
374
+ const testTemplate = fs.readFileSync(path.resolve(__dirname, 'assets/handlebars/Table.test.tsx.handlebars'), 'utf-8');
373
375
 
374
376
  Object.values(tableData.TABLES).map((tableData, key) => {
375
377
 
376
- const tableName = tableData.TABLE_NAME_SHORT
378
+ const tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE
379
+
380
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.tsx'), Handlebars.compile(template)(tableData));
377
381
 
378
- fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.tsx'), Handlebars.compile(testTemplate)(tableData));
382
+ fs.writeFileSync(path.join(MySQLDump.OUTPUT_DIR, tableName + '.test.tsx'), Handlebars.compile(testTemplate)(tableData));
379
383
 
380
384
  })
381
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
  }