@carbonorm/carbonnode 1.4.3 → 1.4.5

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 CHANGED
@@ -9,9 +9,9 @@
9
9
  # CarbonNode (Alpha Release)
10
10
 
11
11
  CarbonNode is a part of the CarbonORM series. It is a NodeJS MySQL ORM that is designed to work with CarbonPHP. This langauge
12
- will implement the same ORM as CarbonPHP, but will be written in Typescript. Currently only C6 enabled request can be sent
12
+ will implement the same ORM as CarbonPHP, but will be written in Typescript. Currently only C6 enabled requests can be sent
13
13
  using the bindings. Receiving API requests and handling it appropriately is not yet implemented. This is scheduled for
14
- early 2023. This repository is in the early stages of development an any support is greatly appreciated.
14
+ early 2024. This repository is in the early stages of development an any support is greatly appreciated.
15
15
 
16
16
  ## Alpha Release
17
17
 
@@ -65,6 +65,502 @@ generate. Here are the templates used to generate the code:
65
65
  2) [Table.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/Table.ts.handlebars)
66
66
  3) [Websocket.ts.handlebars](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/assets/handlebars/WsLiveUpdates.ts.handlebars)
67
67
 
68
+ #### Generation Example
69
+
70
+ 0) **npx generateRestBindings** is executed.
71
+ 1) **The MySQL dump tool** outputs a strcture for every table.
72
+ ```sql
73
+ --
74
+ -- Table structure for table `carbon_users`
75
+ --
76
+
77
+ DROP TABLE IF EXISTS `carbon_users`;
78
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
79
+ /*!50503 SET character_set_client = utf8mb4 */;
80
+ CREATE TABLE `carbon_users` (
81
+ `user_username` varchar(100) NOT NULL,
82
+ `user_password` varchar(225) NOT NULL,
83
+ `user_id` binary(16) NOT NULL,
84
+ `user_type` varchar(20) NOT NULL DEFAULT 'Athlete',
85
+ `user_sport` varchar(20) DEFAULT 'GOLF',
86
+ `user_session_id` varchar(225) DEFAULT NULL,
87
+ `user_facebook_id` varchar(225) DEFAULT NULL,
88
+ `user_first_name` varchar(25) NOT NULL,
89
+ `user_last_name` varchar(25) NOT NULL,
90
+ `user_profile_pic` varchar(225) DEFAULT NULL,
91
+ `user_profile_uri` varchar(225) DEFAULT NULL,
92
+ `user_cover_photo` varchar(225) DEFAULT NULL,
93
+ `user_birthday` varchar(9) DEFAULT NULL,
94
+ `user_gender` varchar(25) DEFAULT NULL,
95
+ `user_about_me` varchar(225) DEFAULT NULL,
96
+ `user_rank` int DEFAULT '0',
97
+ `user_email` varchar(50) NOT NULL,
98
+ `user_email_code` varchar(225) DEFAULT NULL,
99
+ `user_email_confirmed` tinyint DEFAULT '0' COMMENT 'need to change to enums, but no support in rest yet',
100
+ `user_generated_string` varchar(200) DEFAULT NULL,
101
+ `user_membership` int DEFAULT '0',
102
+ `user_deactivated` tinyint DEFAULT '0',
103
+ `user_last_login` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
104
+ `user_ip` varchar(20) NOT NULL,
105
+ `user_education_history` varchar(200) DEFAULT NULL,
106
+ `user_location` varchar(20) DEFAULT NULL,
107
+ `user_creation_date` datetime DEFAULT CURRENT_TIMESTAMP,
108
+ PRIMARY KEY (`user_id`),
109
+ UNIQUE KEY `carbon_users_user_username_uindex` (`user_username`),
110
+ UNIQUE KEY `user_user_profile_uri_uindex` (`user_profile_uri`),
111
+ UNIQUE KEY `carbon_users_user_facebook_id_uindex` (`user_facebook_id`),
112
+ CONSTRAINT `user_entity_entity_pk_fk` FOREIGN KEY (`user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
113
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
114
+ /*!40101 SET character_set_client = @saved_cs_client */;
115
+ ```
116
+ 3) **Profit**
117
+ - C6 will produce 1-1 constants.
118
+ ```typescript
119
+ export interface iUsers {
120
+ 'user_username'?: string;
121
+ 'user_password'?: string;
122
+ 'user_id'?: string;
123
+ 'user_type'?: string;
124
+ 'user_sport'?: string | null;
125
+ 'user_session_id'?: string | null;
126
+ 'user_facebook_id'?: string | null;
127
+ 'user_first_name'?: string;
128
+ 'user_last_name'?: string;
129
+ 'user_profile_pic'?: string | null;
130
+ 'user_profile_uri'?: string | null;
131
+ 'user_cover_photo'?: string | null;
132
+ 'user_birthday'?: string | null;
133
+ 'user_gender'?: string | null;
134
+ 'user_about_me'?: string | null;
135
+ 'user_rank'?: number | null;
136
+ 'user_email'?: string;
137
+ 'user_email_code'?: string | null;
138
+ 'user_email_confirmed'?: number | null;
139
+ 'user_generated_string'?: string | null;
140
+ 'user_membership'?: number | null;
141
+ 'user_deactivated'?: number | null;
142
+ 'user_last_login'?: string;
143
+ 'user_ip'?: string;
144
+ 'user_education_history'?: string | null;
145
+ 'user_location'?: string | null;
146
+ 'user_creation_date'?: string | null;
147
+ }
148
+
149
+ interface iDefineUsers {
150
+ 'USER_USERNAME': string;
151
+ 'USER_PASSWORD': string;
152
+ 'USER_ID': string;
153
+ 'USER_TYPE': string;
154
+ 'USER_SPORT': string;
155
+ 'USER_SESSION_ID': string;
156
+ 'USER_FACEBOOK_ID': string;
157
+ 'USER_FIRST_NAME': string;
158
+ 'USER_LAST_NAME': string;
159
+ 'USER_PROFILE_PIC': string;
160
+ 'USER_PROFILE_URI': string;
161
+ 'USER_COVER_PHOTO': string;
162
+ 'USER_BIRTHDAY': string;
163
+ 'USER_GENDER': string;
164
+ 'USER_ABOUT_ME': string;
165
+ 'USER_RANK': string;
166
+ 'USER_EMAIL': string;
167
+ 'USER_EMAIL_CODE': string;
168
+ 'USER_EMAIL_CONFIRMED': string;
169
+ 'USER_GENERATED_STRING': string;
170
+ 'USER_MEMBERSHIP': string;
171
+ 'USER_DEACTIVATED': string;
172
+ 'USER_LAST_LOGIN': string;
173
+ 'USER_IP': string;
174
+ 'USER_EDUCATION_HISTORY': string;
175
+ 'USER_LOCATION': string;
176
+ 'USER_CREATION_DATE': string;
177
+ }
178
+
179
+ export const users: iC6RestfulModel<RestTableNames> & iDefineUsers = {
180
+ TABLE_NAME: 'carbon_users',
181
+ USER_USERNAME: 'carbon_users.user_username',
182
+ USER_PASSWORD: 'carbon_users.user_password',
183
+ USER_ID: 'carbon_users.user_id',
184
+ USER_TYPE: 'carbon_users.user_type',
185
+ USER_SPORT: 'carbon_users.user_sport',
186
+ USER_SESSION_ID: 'carbon_users.user_session_id',
187
+ USER_FACEBOOK_ID: 'carbon_users.user_facebook_id',
188
+ USER_FIRST_NAME: 'carbon_users.user_first_name',
189
+ USER_LAST_NAME: 'carbon_users.user_last_name',
190
+ USER_PROFILE_PIC: 'carbon_users.user_profile_pic',
191
+ USER_PROFILE_URI: 'carbon_users.user_profile_uri',
192
+ USER_COVER_PHOTO: 'carbon_users.user_cover_photo',
193
+ USER_BIRTHDAY: 'carbon_users.user_birthday',
194
+ USER_GENDER: 'carbon_users.user_gender',
195
+ USER_ABOUT_ME: 'carbon_users.user_about_me',
196
+ USER_RANK: 'carbon_users.user_rank',
197
+ USER_EMAIL: 'carbon_users.user_email',
198
+ USER_EMAIL_CODE: 'carbon_users.user_email_code',
199
+ USER_EMAIL_CONFIRMED: 'carbon_users.user_email_confirmed',
200
+ USER_GENERATED_STRING: 'carbon_users.user_generated_string',
201
+ USER_MEMBERSHIP: 'carbon_users.user_membership',
202
+ USER_DEACTIVATED: 'carbon_users.user_deactivated',
203
+ USER_LAST_LOGIN: 'carbon_users.user_last_login',
204
+ USER_IP: 'carbon_users.user_ip',
205
+ USER_EDUCATION_HISTORY: 'carbon_users.user_education_history',
206
+ USER_LOCATION: 'carbon_users.user_location',
207
+ USER_CREATION_DATE: 'carbon_users.user_creation_date',
208
+ PRIMARY: [
209
+ 'carbon_users.user_id',
210
+ ],
211
+ PRIMARY_SHORT: [
212
+ 'user_id',
213
+ ],
214
+ COLUMNS: {
215
+ 'carbon_users.user_username': 'user_username',
216
+ 'carbon_users.user_password': 'user_password',
217
+ 'carbon_users.user_id': 'user_id',
218
+ 'carbon_users.user_type': 'user_type',
219
+ 'carbon_users.user_sport': 'user_sport',
220
+ 'carbon_users.user_session_id': 'user_session_id',
221
+ 'carbon_users.user_facebook_id': 'user_facebook_id',
222
+ 'carbon_users.user_first_name': 'user_first_name',
223
+ 'carbon_users.user_last_name': 'user_last_name',
224
+ 'carbon_users.user_profile_pic': 'user_profile_pic',
225
+ 'carbon_users.user_profile_uri': 'user_profile_uri',
226
+ 'carbon_users.user_cover_photo': 'user_cover_photo',
227
+ 'carbon_users.user_birthday': 'user_birthday',
228
+ 'carbon_users.user_gender': 'user_gender',
229
+ 'carbon_users.user_about_me': 'user_about_me',
230
+ 'carbon_users.user_rank': 'user_rank',
231
+ 'carbon_users.user_email': 'user_email',
232
+ 'carbon_users.user_email_code': 'user_email_code',
233
+ 'carbon_users.user_email_confirmed': 'user_email_confirmed',
234
+ 'carbon_users.user_generated_string': 'user_generated_string',
235
+ 'carbon_users.user_membership': 'user_membership',
236
+ 'carbon_users.user_deactivated': 'user_deactivated',
237
+ 'carbon_users.user_last_login': 'user_last_login',
238
+ 'carbon_users.user_ip': 'user_ip',
239
+ 'carbon_users.user_education_history': 'user_education_history',
240
+ 'carbon_users.user_location': 'user_location',
241
+ 'carbon_users.user_creation_date': 'user_creation_date',
242
+ },
243
+ TYPE_VALIDATION: {
244
+ 'carbon_users.user_username': {
245
+ MYSQL_TYPE: 'varchar',
246
+ MAX_LENGTH: '100',
247
+ AUTO_INCREMENT: false,
248
+ SKIP_COLUMN_IN_POST: false
249
+ },
250
+ 'carbon_users.user_password': {
251
+ MYSQL_TYPE: 'varchar',
252
+ MAX_LENGTH: '225',
253
+ AUTO_INCREMENT: false,
254
+ SKIP_COLUMN_IN_POST: false
255
+ },
256
+ 'carbon_users.user_id': {
257
+ MYSQL_TYPE: 'binary',
258
+ MAX_LENGTH: '16',
259
+ AUTO_INCREMENT: false,
260
+ SKIP_COLUMN_IN_POST: false
261
+ },
262
+ 'carbon_users.user_type': {
263
+ MYSQL_TYPE: 'varchar',
264
+ MAX_LENGTH: '20',
265
+ AUTO_INCREMENT: false,
266
+ SKIP_COLUMN_IN_POST: false
267
+ },
268
+ 'carbon_users.user_sport': {
269
+ MYSQL_TYPE: 'varchar',
270
+ MAX_LENGTH: '20',
271
+ AUTO_INCREMENT: false,
272
+ SKIP_COLUMN_IN_POST: false
273
+ },
274
+ 'carbon_users.user_session_id': {
275
+ MYSQL_TYPE: 'varchar',
276
+ MAX_LENGTH: '225',
277
+ AUTO_INCREMENT: false,
278
+ SKIP_COLUMN_IN_POST: false
279
+ },
280
+ 'carbon_users.user_facebook_id': {
281
+ MYSQL_TYPE: 'varchar',
282
+ MAX_LENGTH: '225',
283
+ AUTO_INCREMENT: false,
284
+ SKIP_COLUMN_IN_POST: false
285
+ },
286
+ 'carbon_users.user_first_name': {
287
+ MYSQL_TYPE: 'varchar',
288
+ MAX_LENGTH: '25',
289
+ AUTO_INCREMENT: false,
290
+ SKIP_COLUMN_IN_POST: false
291
+ },
292
+ 'carbon_users.user_last_name': {
293
+ MYSQL_TYPE: 'varchar',
294
+ MAX_LENGTH: '25',
295
+ AUTO_INCREMENT: false,
296
+ SKIP_COLUMN_IN_POST: false
297
+ },
298
+ 'carbon_users.user_profile_pic': {
299
+ MYSQL_TYPE: 'varchar',
300
+ MAX_LENGTH: '225',
301
+ AUTO_INCREMENT: false,
302
+ SKIP_COLUMN_IN_POST: false
303
+ },
304
+ 'carbon_users.user_profile_uri': {
305
+ MYSQL_TYPE: 'varchar',
306
+ MAX_LENGTH: '225',
307
+ AUTO_INCREMENT: false,
308
+ SKIP_COLUMN_IN_POST: false
309
+ },
310
+ 'carbon_users.user_cover_photo': {
311
+ MYSQL_TYPE: 'varchar',
312
+ MAX_LENGTH: '225',
313
+ AUTO_INCREMENT: false,
314
+ SKIP_COLUMN_IN_POST: false
315
+ },
316
+ 'carbon_users.user_birthday': {
317
+ MYSQL_TYPE: 'varchar',
318
+ MAX_LENGTH: '9',
319
+ AUTO_INCREMENT: false,
320
+ SKIP_COLUMN_IN_POST: false
321
+ },
322
+ 'carbon_users.user_gender': {
323
+ MYSQL_TYPE: 'varchar',
324
+ MAX_LENGTH: '25',
325
+ AUTO_INCREMENT: false,
326
+ SKIP_COLUMN_IN_POST: false
327
+ },
328
+ 'carbon_users.user_about_me': {
329
+ MYSQL_TYPE: 'varchar',
330
+ MAX_LENGTH: '225',
331
+ AUTO_INCREMENT: false,
332
+ SKIP_COLUMN_IN_POST: false
333
+ },
334
+ 'carbon_users.user_rank': {
335
+ MYSQL_TYPE: 'int',
336
+ MAX_LENGTH: '',
337
+ AUTO_INCREMENT: false,
338
+ SKIP_COLUMN_IN_POST: false
339
+ },
340
+ 'carbon_users.user_email': {
341
+ MYSQL_TYPE: 'varchar',
342
+ MAX_LENGTH: '50',
343
+ AUTO_INCREMENT: false,
344
+ SKIP_COLUMN_IN_POST: false
345
+ },
346
+ 'carbon_users.user_email_code': {
347
+ MYSQL_TYPE: 'varchar',
348
+ MAX_LENGTH: '225',
349
+ AUTO_INCREMENT: false,
350
+ SKIP_COLUMN_IN_POST: false
351
+ },
352
+ 'carbon_users.user_email_confirmed': {
353
+ MYSQL_TYPE: 'tinyint',
354
+ MAX_LENGTH: '',
355
+ AUTO_INCREMENT: false,
356
+ SKIP_COLUMN_IN_POST: false
357
+ },
358
+ 'carbon_users.user_generated_string': {
359
+ MYSQL_TYPE: 'varchar',
360
+ MAX_LENGTH: '200',
361
+ AUTO_INCREMENT: false,
362
+ SKIP_COLUMN_IN_POST: false
363
+ },
364
+ 'carbon_users.user_membership': {
365
+ MYSQL_TYPE: 'int',
366
+ MAX_LENGTH: '',
367
+ AUTO_INCREMENT: false,
368
+ SKIP_COLUMN_IN_POST: false
369
+ },
370
+ 'carbon_users.user_deactivated': {
371
+ MYSQL_TYPE: 'tinyint',
372
+ MAX_LENGTH: '',
373
+ AUTO_INCREMENT: false,
374
+ SKIP_COLUMN_IN_POST: false
375
+ },
376
+ 'carbon_users.user_last_login': {
377
+ MYSQL_TYPE: 'datetime',
378
+ MAX_LENGTH: '',
379
+ AUTO_INCREMENT: false,
380
+ SKIP_COLUMN_IN_POST: false
381
+ },
382
+ 'carbon_users.user_ip': {
383
+ MYSQL_TYPE: 'varchar',
384
+ MAX_LENGTH: '20',
385
+ AUTO_INCREMENT: false,
386
+ SKIP_COLUMN_IN_POST: false
387
+ },
388
+ 'carbon_users.user_education_history': {
389
+ MYSQL_TYPE: 'varchar',
390
+ MAX_LENGTH: '200',
391
+ AUTO_INCREMENT: false,
392
+ SKIP_COLUMN_IN_POST: false
393
+ },
394
+ 'carbon_users.user_location': {
395
+ MYSQL_TYPE: 'varchar',
396
+ MAX_LENGTH: '20',
397
+ AUTO_INCREMENT: false,
398
+ SKIP_COLUMN_IN_POST: false
399
+ },
400
+ 'carbon_users.user_creation_date': {
401
+ MYSQL_TYPE: 'datetime',
402
+ MAX_LENGTH: '',
403
+ AUTO_INCREMENT: false,
404
+ SKIP_COLUMN_IN_POST: false
405
+ },
406
+ },
407
+ REGEX_VALIDATION: {
408
+ },
409
+ TABLE_REFERENCES: {
410
+ 'user_id': [{
411
+ TABLE: 'carbon_carbons',
412
+ COLUMN: 'entity_pk',
413
+ CONSTRAINT: 'user_entity_entity_pk_fk',
414
+ },],
415
+ },
416
+ TABLE_REFERENCED_BY: {
417
+
418
+ }
419
+ }
420
+ ```
421
+ - A File named the pascal case formated table name will be created with bindings to query the middleware (backend langague) -> MySQL.
422
+ ```typescript
423
+ import {AxiosResponse} from "axios";
424
+ import {
425
+ iPostC6RestResponse,
426
+ restRequest,
427
+ GET,
428
+ POST,
429
+ PUT,
430
+ DELETE,
431
+ iDeleteC6RestResponse,
432
+ iGetC6RestResponse,
433
+ iPutC6RestResponse,
434
+ removeInvalidKeys,
435
+ iAPI,
436
+ Modify
437
+ } from "@carbonorm/carbonnode";
438
+ import {deleteRestfulObjectArrays, updateRestfulObjectArrays} from "@carbonorm/carbonreact";
439
+ import {C6, iUsers, users, RestTableNames} from "./C6";
440
+
441
+ type GetCustomAndRequiredFields = {}
442
+
443
+ type GetRequestTableOverrides = {}
444
+
445
+ // required parameters, optional parameters, parameter type overrides, response, and table names
446
+ const Get = restRequest<GetCustomAndRequiredFields, iUsers, GetRequestTableOverrides, iGetC6RestResponse<iUsers>, RestTableNames>({
447
+ C6: C6,
448
+ tableName: users.TABLE_NAME,
449
+ requestMethod: GET,
450
+ queryCallback: (request) => {
451
+ request.success ??= 'Successfully received users!'
452
+ request.error ??= 'An unknown issue occurred creating the users!'
453
+ return request
454
+ },
455
+ responseCallback: (response, _request) => {
456
+ const responseData = response?.data?.rest;
457
+ updateRestfulObjectArrays<iUsers>(Array.isArray(responseData) ? responseData : [responseData], "users", C6.users.PRIMARY_SHORT as (keyof iUsers)[])
458
+ }
459
+ });
460
+
461
+ type PutCustomAndRequiredFields = {}
462
+
463
+ type PutRequestTableOverrides = {}
464
+
465
+ export function putStateUsers(response : AxiosResponse<iPutC6RestResponse<iUsers>>, request : iAPI<Modify<iUsers, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
466
+ updateRestfulObjectArrays<iUsers>([
467
+ removeInvalidKeys<iUsers>({
468
+ ...request,
469
+ ...response?.data?.rest,
470
+ }, C6.TABLES)
471
+ ], "users", users.PRIMARY_SHORT as (keyof iUsers)[])
472
+ }
473
+
474
+ const Put = restRequest<PutCustomAndRequiredFields, iUsers, PutRequestTableOverrides, iPutC6RestResponse<iUsers>, RestTableNames>({
475
+ C6: C6,
476
+ tableName: users.TABLE_NAME,
477
+ requestMethod: PUT,
478
+ queryCallback: (request) => {
479
+ request.success ??= 'Successfully updated users data!'
480
+ request.error ??= 'An unknown issue occurred updating the users data!'
481
+ return request
482
+ },
483
+ responseCallback: putStateUsers
484
+ });
485
+
486
+ type PostCustomAndRequiredFields = {}
487
+
488
+ type PostRequestTableOverrides = {}
489
+
490
+ export function postStateUsers(response : AxiosResponse<iPostC6RestResponse<iUsers>>, request : iAPI<Modify<iUsers, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
491
+ if ('number' === typeof id || 'string' === typeof id) {
492
+ if (1 !== users.PRIMARY_SHORT.length) {
493
+ console.error("C6 received unexpected result's given the primary key length");
494
+ } else {
495
+ request[users.PRIMARY_SHORT[0]] = id
496
+ }
497
+ }
498
+ updateRestfulObjectArrays<iUsers>(
499
+ undefined !== request.dataInsertMultipleRows
500
+ ? request.dataInsertMultipleRows.map((request, index) => {
501
+ return removeInvalidKeys<iUsers>({
502
+ ...request,
503
+ ...(index === 0 ? response?.data?.rest : {}),
504
+ }, C6.TABLES)
505
+ })
506
+ : [
507
+ removeInvalidKeys<iUsers>({
508
+ ...request,
509
+ ...response?.data?.rest,
510
+ }, C6.TABLES)
511
+ ],
512
+ "users",
513
+ users.PRIMARY_SHORT as (keyof iUsers)[]
514
+ )
515
+ }
516
+
517
+ const Post = restRequest<PostCustomAndRequiredFields, iUsers, PostRequestTableOverrides, iPostC6RestResponse<iUsers>, RestTableNames>({
518
+ C6: C6,
519
+ tableName: users.TABLE_NAME,
520
+ requestMethod: POST,
521
+ queryCallback: (request) => {
522
+ request.success ??= 'Successfully created the users data!'
523
+ request.error ??= 'An unknown issue occurred creating the users data!'
524
+ return request
525
+ },
526
+ responseCallback: postStateUsers
527
+ });
528
+
529
+ type DeleteCustomAndRequiredFields = {}
530
+
531
+ type DeleteRequestTableOverrides = {}
532
+
533
+ export function deleteStateUsers(_response : AxiosResponse<iDeleteC6RestResponse<iUsers>>, request : iAPI<Modify<iUsers, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
534
+ deleteRestfulObjectArrays<iUsers>([
535
+ request
536
+ ], "users", users.PRIMARY_SHORT as (keyof iUsers)[])
537
+ }
538
+
539
+ const Delete = restRequest<DeleteCustomAndRequiredFields, iUsers, DeleteRequestTableOverrides, iDeleteC6RestResponse<iUsers>, RestTableNames>({
540
+ C6: C6,
541
+ tableName: users.TABLE_NAME,
542
+ requestMethod: DELETE,
543
+ queryCallback: (request) => {
544
+ request.success ??= 'Successfully removed the users data!'
545
+ request.error ??= 'An unknown issue occurred removing the users data!'
546
+ return request
547
+ },
548
+ responseCallback: deleteStateUsers
549
+ });
550
+
551
+ const Users = {
552
+ // Export all GET, POST, PUT, DELETE functions for each table
553
+ Get,
554
+ Post,
555
+ Put,
556
+ Delete,
557
+ }
558
+
559
+ export default Users;
560
+ ```
561
+
562
+
563
+
68
564
 
69
565
  # Support and Issues
70
566
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carbonorm/carbonnode",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "browser": "dist/index.umd.js",
@@ -42,7 +42,8 @@
42
42
  "pretest": "npm run build",
43
43
  "build:index": "npx barrelsby -d ./src --delete --exclude '(jestHoc|\\.test|\\.d).(js|tsx?)$' --exportDefault --verbose",
44
44
  "build:generateRestBindings": "cd ./scripts/ && tsc --downlevelIteration generateRestBindings.ts && mv generateRestBindings.js generateRestBindings.cjs",
45
- "generateRestBindings": "npm run build:generateRestBindings && node ./scripts/generateRestBindings.cjs"
45
+ "generateRestBindings": "npm run build:generateRestBindings && node ./scripts/generateRestBindings.cjs",
46
+ "c6": "npm run generateRestBindings"
46
47
  },
47
48
  "bin": {
48
49
  "generateRestBindings": "./scripts/generateRestBindings.cjs"
@@ -27,6 +27,7 @@ type GetRequestTableOverrides = {}
27
27
  // required parameters, optional parameters, parameter type overrides, response, and table names
28
28
  const Get = restRequest<GetCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, GetRequestTableOverrides, iGetC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
29
29
  C6: C6,
30
+ restURL: {{{REST_URL_EXPRESSION}}},
30
31
  tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
31
32
  requestMethod: GET,
32
33
  queryCallback: (request) => {
@@ -55,6 +56,7 @@ export function putState{{TABLE_NAME_SHORT_PASCAL_CASE}}(response : AxiosRespons
55
56
 
56
57
  const Put = restRequest<PutCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PutRequestTableOverrides, iPutC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
57
58
  C6: C6,
59
+ restURL: {{{REST_URL_EXPRESSION}}},
58
60
  tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
59
61
  requestMethod: PUT,
60
62
  queryCallback: (request) => {
@@ -98,6 +100,7 @@ export function postState{{TABLE_NAME_SHORT_PASCAL_CASE}}(response : AxiosRespon
98
100
 
99
101
  const Post = restRequest<PostCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, PostRequestTableOverrides, iPostC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
100
102
  C6: C6,
103
+ restURL: {{{REST_URL_EXPRESSION}}},
101
104
  tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
102
105
  requestMethod: POST,
103
106
  queryCallback: (request) => {
@@ -120,6 +123,7 @@ export function deleteState{{TABLE_NAME_SHORT_PASCAL_CASE}}(_response : AxiosRes
120
123
 
121
124
  const Delete = restRequest<DeleteCustomAndRequiredFields, i{{TABLE_NAME_SHORT_PASCAL_CASE}}, DeleteRequestTableOverrides, iDeleteC6RestResponse<i{{TABLE_NAME_SHORT_PASCAL_CASE}}>, RestTableNames>({
122
125
  C6: C6,
126
+ restURL: {{{REST_URL_EXPRESSION}}},
123
127
  tableName: {{TABLE_NAME_SHORT}}.TABLE_NAME,
124
128
  requestMethod: DELETE,
125
129
  queryCallback: (request) => {
@@ -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 = null; }
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
- cnfFile !== null && cnfFile !== void 0 ? cnfFile : (cnfFile = path.join(process.cwd(), '/mysql.cnf'));
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 = null; }
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 = null; }
60
+ if (outputFile === void 0) { outputFile = ''; }
59
61
  if (otherOption === void 0) { otherOption = ''; }
60
- if (specificTable === void 0) { specificTable = null; }
61
- specificTable = specificTable || '';
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 || '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
+ 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 (error) {
83
- console.log("The command >> ".concat(command, " \n\t returned with a status code (").concat(error.status, "). Expecting 0 for success."));
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(error.status);
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] || null;
174
- var onUpdateAction = foreignKeyMatch[8] || null;
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].TABLE_REFERENCED_BY) {
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).map(function (tableData, key) {
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, { recursive: true }) : undefined;
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 = null) {
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
- cnfFile ??= path.join(process.cwd(), '/mysql.cnf');
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 = null, data = false, schemas = true, outputFile = null, otherOption = '', specificTable = null) {
75
- specificTable = specificTable || '';
77
+ static MySQLDump(mysqldump: string = 'mysqldump', data = false, schemas = true, outputFile = '', otherOption = '', specificTable: string = '') {
76
78
 
77
- if (outputFile === null) {
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 || 'mysqldump'} --defaults-extra-file="${defaultsExtraFile}" ${otherOption} --skip-add-locks --single-transaction --quick ${createInfoOption}${hexBlobOption}${this.DB_NAME} ${specificTable} > '${outputFile}'`;
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 (error) {
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::\t ${error.stdout}`);
111
+ console.log(`Command output::`, e);
112
112
 
113
113
  if (exitOnFailure) {
114
114
 
115
- process.exit(error.status);
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] || null;
257
- const onUpdateAction = foreignKeyMatch[8] || null;
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].TABLE_REFERENCED_BY) {
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).map((tableData, key) => {
400
+ Object.values(tableData.TABLES).forEach((tableData) => {
394
401
 
395
402
  const tableName = tableData.TABLE_NAME_SHORT_PASCAL_CASE
396
403