@carbonorm/carbonnode 3.0.1 → 3.0.3

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.
@@ -1,161 +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}}, RestTableNames} 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<GetCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, GetRequestTableOverrides, iGetC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
29
- C6: C6,
30
- restURL: {{{REST_URL_EXPRESSION}}},
31
- tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
32
- requestMethod: GET,
33
- queryCallback: (request) => {
34
- request.success ??= 'Successfully received {{TABLE_NAME_SHORT}}!'
35
- request.error ??= 'An unknown issue occurred creating the {{TABLE_NAME_SHORT}}!'
36
- return request
37
- },{{#if REACT_IMPORT}}
38
- responseCallback: (response, _request) => {
39
- const responseData = response?.data?.rest;
40
- {{CARBON_REACT_INSTANCE}}.updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
41
- dataOrCallback: Array.isArray(responseData) ? responseData : [responseData],
42
- stateKey: "{{TABLE_NAME_SHORT}}",
43
- uniqueObjectId: C6.{{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
44
- })
45
- }{{/if}}
46
- });
47
-
48
- type PutCustomAndRequiredFields = {}
49
-
50
- type PutRequestTableOverrides = {}
51
-
52
- {{#if REACT_IMPORT}}
53
- export function putState(response: AxiosResponse<iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>, request: iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
54
- {{CARBON_REACT_INSTANCE}}.updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
55
- dataOrCallback: [
56
- removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
57
- ...request,
58
- ...response?.data?.rest,
59
- }, C6.TABLES)
60
- ],
61
- stateKey: "{{TABLE_NAME_SHORT}}",
62
- uniqueObjectId: {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
63
- })
64
- }
65
- {{/if}}
66
-
67
- const Put = restRequest<PutCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides, iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
68
- C6: C6,
69
- restURL: {{{REST_URL_EXPRESSION}}},
70
- tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
71
- requestMethod: PUT,
72
- queryCallback: (request) => {
73
- request.success ??= 'Successfully updated {{TABLE_NAME_SHORT}} data!'
74
- request.error ??= 'An unknown issue occurred updating the {{TABLE_NAME_SHORT}} data!'
75
- return request
76
- },{{#if REACT_IMPORT}}
77
- responseCallback: putState{{/if}}
78
- });
79
-
80
- type PostCustomAndRequiredFields = {}
81
-
82
- type PostRequestTableOverrides = {}
83
-
84
- {{#if REACT_IMPORT}}export function postState(response: AxiosResponse<iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>, request: iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
85
- if ('number' === typeof id || 'string' === typeof id) {
86
- if (1 !== {{TABLE_NAME_SHORT}}.PRIMARY_SHORT.length) {
87
- console.error("C6 received unexpected result's given the primary key length");
88
- } else {
89
- request[{{TABLE_NAME_SHORT}}.PRIMARY_SHORT[0]] = id
90
- }
91
- }
92
- {{CARBON_REACT_INSTANCE}}.updateRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
93
- dataOrCallback: undefined !== request.dataInsertMultipleRows
94
- ? request.dataInsertMultipleRows.map((request, index) => {
95
- return removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
96
- ...request,
97
- ...(index === 0 ? response?.data?.rest : {}),
98
- }, C6.TABLES)
99
- })
100
- : [
101
- removeInvalidKeys<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
102
- ...request,
103
- ...response?.data?.rest,
104
- }, C6.TABLES)
105
- ],
106
- stateKey: "{{TABLE_NAME_SHORT}}",
107
- uniqueObjectId: {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
108
- })
109
- }{{/if}}
110
-
111
- const Post = restRequest<PostCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PostRequestTableOverrides, iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
112
- C6: C6,
113
- restURL: {{{REST_URL_EXPRESSION}}},
114
- tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
115
- requestMethod: POST,
116
- queryCallback: (request) => {
117
- request.success ??= 'Successfully created the {{TABLE_NAME_SHORT}} data!'
118
- request.error ??= 'An unknown issue occurred creating the {{TABLE_NAME_SHORT}} data!'
119
- return request
120
- },{{#if REACT_IMPORT}}
121
- responseCallback: postState{{/if}}
122
- });
123
-
124
- type DeleteCustomAndRequiredFields = {}
125
-
126
- type DeleteRequestTableOverrides = {}
127
-
128
- {{#if REACT_IMPORT}}
129
- export function deleteState(_response: AxiosResponse<iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>>, request: iAPI<Modify<i{{TABLE_NAME_SHORT_PASCAL_CASE}}, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
130
- {{CARBON_REACT_INSTANCE}}.deleteRestfulObjectArrays<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>({
131
- dataOrCallback: [
132
- request
133
- ],
134
- stateKey: "{{TABLE_NAME_SHORT}}",
135
- uniqueObjectId: {{TABLE_NAME_SHORT}}.PRIMARY_SHORT as (keyof i{{TABLE_NAME_SHORT_PASCAL_CASE}})[]
136
- })
137
- }
138
- {{/if}}
139
-
140
- const Delete = restRequest<DeleteCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, DeleteRequestTableOverrides, iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
141
- C6: C6,
142
- restURL: {{{REST_URL_EXPRESSION}}},
143
- tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
144
- requestMethod: DELETE,
145
- queryCallback: (request) => {
146
- request.success ??= 'Successfully removed the {{TABLE_NAME_SHORT}} data!'
147
- request.error ??= 'An unknown issue occurred removing the {{TABLE_NAME_SHORT}} data!'
148
- return request
149
- },{{#if REACT_IMPORT}}
150
- responseCallback: deleteState{{/if}}
151
- });
152
-
153
- const {{TABLE_NAME_SHORT_PASCAL_CASE}} = {
154
- // Export all GET, POST, PUT, DELETE functions for each table
155
- Get,
156
- Post,
157
- Put,
158
- Delete,
159
- }
160
-
161
- export default {{TABLE_NAME_SHORT_PASCAL_CASE}};