@carbonorm/carbonnode 3.0.2 → 3.0.4
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/convertForRequestBody.d.ts +7 -3
- package/dist/api/executors/Executor.d.ts +9 -9
- package/dist/api/executors/HttpExecutor.d.ts +9 -5
- package/dist/api/executors/SqlExecutor.d.ts +5 -5
- package/dist/api/restOrm.d.ts +15 -0
- package/dist/api/restRequest.d.ts +4 -5
- package/dist/api/types/ormInterfaces.d.ts +165 -139
- package/dist/index.cjs.js +263 -160
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +264 -161
- package/dist/index.esm.js.map +1 -1
- package/package.json +5 -4
- package/scripts/assets/handlebars/C6.test.ts.handlebars +88 -0
- package/scripts/assets/handlebars/C6.ts.handlebars +45 -12
- package/scripts/generateRestBindings.cjs +3 -7
- package/scripts/generateRestBindings.ts +3 -14
- package/src/api/convertForRequestBody.ts +62 -90
- package/src/api/executors/Executor.ts +67 -13
- package/src/api/executors/HttpExecutor.ts +224 -90
- package/src/api/executors/SqlExecutor.ts +6 -6
- package/src/api/restOrm.ts +61 -0
- package/src/api/restRequest.ts +19 -14
- package/src/api/types/ormInterfaces.ts +208 -246
- package/src/api/utils/apiHelpers.ts +4 -0
- package/src/index.ts +1 -0
- package/scripts/assets/handlebars/Table.test.ts.handlebars +0 -126
- package/scripts/assets/handlebars/Table.ts.handlebars +0 -193
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
iPostC6RestResponse,
|
|
3
|
-
restRequest,
|
|
4
|
-
GET,
|
|
5
|
-
POST,
|
|
6
|
-
PUT,
|
|
7
|
-
DELETE,
|
|
8
|
-
iDeleteC6RestResponse,
|
|
9
|
-
iGetC6RestResponse,
|
|
10
|
-
iPutC6RestResponse,{{#REACT_IMPORT}}
|
|
11
|
-
removeInvalidKeys,
|
|
12
|
-
iAPI,
|
|
13
|
-
Modify{{/REACT_IMPORT}}
|
|
14
|
-
} from "@carbonorm/carbonnode";{{#REACT_IMPORT}}
|
|
15
|
-
import {AxiosResponse} from "axios";{{/REACT_IMPORT}}
|
|
16
|
-
import {C6, {{TABLE_NAME_SHORT}}, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, {{TABLE_NAME_SHORT_PASCAL_CASE}}PrimaryKeys} from "./C6";{{#if REACT_IMPORT}}
|
|
17
|
-
{{{REACT_IMPORT}}};{{/if}}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
{{{TABLE_DEFINITION}}}
|
|
21
|
-
**/
|
|
22
|
-
|
|
23
|
-
type GetCustomAndRequiredFields = {}
|
|
24
|
-
|
|
25
|
-
type GetRequestTableOverrides = {}
|
|
26
|
-
|
|
27
|
-
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
28
|
-
const Get = restRequest<
|
|
29
|
-
'{{TABLE_NAME_SHORT}}',
|
|
30
|
-
i{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
31
|
-
{{TABLE_NAME_SHORT_PASCAL_CASE}}PrimaryKeys,
|
|
32
|
-
GetCustomAndRequiredFields,
|
|
33
|
-
GetRequestTableOverrides,
|
|
34
|
-
iGetC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>
|
|
35
|
-
>({
|
|
36
|
-
C6: C6,
|
|
37
|
-
restURL: {{{REST_URL_EXPRESSION}}},
|
|
38
|
-
restModel: {{TABLE_NAME_SHORT}},
|
|
39
|
-
requestMethod: GET,
|
|
40
|
-
queryCallback: (request) => {
|
|
41
|
-
request.success ??= 'Successfully received {{TABLE_NAME_SHORT}}!'
|
|
42
|
-
request.error ??= 'An unknown issue occurred creating the {{TABLE_NAME_SHORT}}!'
|
|
43
|
-
return request
|
|
44
|
-
},{{#if REACT_IMPORT}}
|
|
45
|
-
responseCallback: (response, _request) => {
|
|
46
|
-
const responseData = response?.data?.rest;
|
|
47
|
-
{{CARBON_REACT_INSTANCE}}.updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
48
|
-
dataOrCallback: Array.isArray(responseData) ? responseData : [responseData],
|
|
49
|
-
stateKey: "{{TABLE_NAME_SHORT}}",
|
|
50
|
-
uniqueObjectId: C6.{{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
|
|
51
|
-
})
|
|
52
|
-
}{{/if}}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
type PutCustomAndRequiredFields = {}
|
|
56
|
-
|
|
57
|
-
type PutRequestTableOverrides = {}
|
|
58
|
-
|
|
59
|
-
{{#if REACT_IMPORT}}
|
|
60
|
-
export function putState(response: AxiosResponse<iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>, request: iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
61
|
-
{{CARBON_REACT_INSTANCE}}.updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
62
|
-
dataOrCallback: [
|
|
63
|
-
removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
64
|
-
...request,
|
|
65
|
-
...response?.data?.rest,
|
|
66
|
-
}, C6.TABLES)
|
|
67
|
-
],
|
|
68
|
-
stateKey: "{{TABLE_NAME_SHORT}}",
|
|
69
|
-
uniqueObjectId: {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
{{/if}}
|
|
73
|
-
|
|
74
|
-
const Put = restRequest<
|
|
75
|
-
'{{TABLE_NAME_SHORT}}',
|
|
76
|
-
i{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
77
|
-
{{TABLE_NAME_SHORT_PASCAL_CASE}}PrimaryKeys,
|
|
78
|
-
GetCustomAndRequiredFields,
|
|
79
|
-
GetRequestTableOverrides,
|
|
80
|
-
iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>
|
|
81
|
-
>({
|
|
82
|
-
C6: C6,
|
|
83
|
-
restURL: {{{REST_URL_EXPRESSION}}},
|
|
84
|
-
restModel: {{TABLE_NAME_SHORT}},
|
|
85
|
-
requestMethod: PUT,
|
|
86
|
-
queryCallback: (request) => {
|
|
87
|
-
request.success ??= 'Successfully updated {{TABLE_NAME_SHORT}} data!'
|
|
88
|
-
request.error ??= 'An unknown issue occurred updating the {{TABLE_NAME_SHORT}} data!'
|
|
89
|
-
return request
|
|
90
|
-
},{{#if REACT_IMPORT}}
|
|
91
|
-
responseCallback: putState{{/if}}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
type PostCustomAndRequiredFields = {}
|
|
95
|
-
|
|
96
|
-
type PostRequestTableOverrides = {}
|
|
97
|
-
|
|
98
|
-
{{#if REACT_IMPORT}}export function postState(
|
|
99
|
-
response: AxiosResponse<iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>,
|
|
100
|
-
request: iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PostRequestTableOverrides>> & PostCustomAndRequiredFields,
|
|
101
|
-
success: i{{TABLE_NAME_SHORT_PASCAL_CASE}}[{{TABLE_NAME_SHORT_PASCAL_CASE}}PrimaryKeys] | string | number | boolean | undefined
|
|
102
|
-
) {
|
|
103
|
-
if ('number' === typeof id || 'string' === typeof success) {
|
|
104
|
-
if (1 !== {{TABLE_NAME_SHORT}}.PRIMARY_SHORT.length) {
|
|
105
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
106
|
-
} else {
|
|
107
|
-
request[{{TABLE_NAME_SHORT}}.PRIMARY_SHORT[0]] = success
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
{{CARBON_REACT_INSTANCE}}.updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
111
|
-
dataOrCallback: undefined !== request.dataInsertMultipleRows
|
|
112
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
113
|
-
return removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
114
|
-
...request,
|
|
115
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
116
|
-
}, C6.TABLES)
|
|
117
|
-
})
|
|
118
|
-
: [
|
|
119
|
-
removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
120
|
-
...request,
|
|
121
|
-
...response?.data?.rest,
|
|
122
|
-
}, C6.TABLES)
|
|
123
|
-
],
|
|
124
|
-
stateKey: "{{TABLE_NAME_SHORT}}",
|
|
125
|
-
uniqueObjectId: {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
|
|
126
|
-
})
|
|
127
|
-
}{{/if}}
|
|
128
|
-
|
|
129
|
-
const Post = restRequest<
|
|
130
|
-
'{{TABLE_NAME_SHORT}}',
|
|
131
|
-
i{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
132
|
-
{{TABLE_NAME_SHORT_PASCAL_CASE}}PrimaryKeys,
|
|
133
|
-
GetCustomAndRequiredFields,
|
|
134
|
-
GetRequestTableOverrides,
|
|
135
|
-
iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>
|
|
136
|
-
>({
|
|
137
|
-
C6: C6,
|
|
138
|
-
restURL: {{{REST_URL_EXPRESSION}}},
|
|
139
|
-
restModel: {{TABLE_NAME_SHORT}},
|
|
140
|
-
requestMethod: POST,
|
|
141
|
-
queryCallback: (request) => {
|
|
142
|
-
request.success ??= 'Successfully created the {{TABLE_NAME_SHORT}} data!'
|
|
143
|
-
request.error ??= 'An unknown issue occurred creating the {{TABLE_NAME_SHORT}} data!'
|
|
144
|
-
return request
|
|
145
|
-
},{{#if REACT_IMPORT}}
|
|
146
|
-
responseCallback: postState{{/if}}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
type DeleteCustomAndRequiredFields = {}
|
|
150
|
-
|
|
151
|
-
type DeleteRequestTableOverrides = {}
|
|
152
|
-
|
|
153
|
-
{{#if REACT_IMPORT}}
|
|
154
|
-
export function deleteState(_response: AxiosResponse<iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>, request: iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
155
|
-
{{CARBON_REACT_INSTANCE}}.deleteRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
|
|
156
|
-
dataOrCallback: [
|
|
157
|
-
request
|
|
158
|
-
],
|
|
159
|
-
stateKey: "{{TABLE_NAME_SHORT}}",
|
|
160
|
-
uniqueObjectId: {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
{{/if}}
|
|
164
|
-
|
|
165
|
-
const Delete = restRequest<
|
|
166
|
-
'{{TABLE_NAME_SHORT}}',
|
|
167
|
-
i{{TABLE_NAME_SHORT_PASCAL_CASE}},
|
|
168
|
-
{{TABLE_NAME_SHORT_PASCAL_CASE}}PrimaryKeys,
|
|
169
|
-
GetCustomAndRequiredFields,
|
|
170
|
-
GetRequestTableOverrides,
|
|
171
|
-
iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>
|
|
172
|
-
>({
|
|
173
|
-
C6: C6,
|
|
174
|
-
restURL: {{{REST_URL_EXPRESSION}}},
|
|
175
|
-
restModel: {{TABLE_NAME_SHORT}},
|
|
176
|
-
requestMethod: DELETE,
|
|
177
|
-
queryCallback: (request) => {
|
|
178
|
-
request.success ??= 'Successfully removed the {{TABLE_NAME_SHORT}} data!'
|
|
179
|
-
request.error ??= 'An unknown issue occurred removing the {{TABLE_NAME_SHORT}} data!'
|
|
180
|
-
return request
|
|
181
|
-
},{{#if REACT_IMPORT}}
|
|
182
|
-
responseCallback: deleteState{{/if}}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const {{TABLE_NAME_SHORT_PASCAL_CASE}} = {
|
|
186
|
-
// Export all GET, POST, PUT, DELETE functions for each table
|
|
187
|
-
Get,
|
|
188
|
-
Post,
|
|
189
|
-
Put,
|
|
190
|
-
Delete,
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export default {{TABLE_NAME_SHORT_PASCAL_CASE}};
|