@carbonorm/carbonreact 3.4.4 → 3.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.
Files changed (105) hide show
  1. package/dist/CarbonReact.d.ts +3 -0
  2. package/dist/index.cjs.js +2133 -5049
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.d.ts +0 -49
  5. package/dist/index.esm.js +2114 -4952
  6. package/dist/index.esm.js.map +1 -1
  7. package/package.json +2 -2
  8. package/src/CarbonReact.tsx +3 -0
  9. package/src/index.ts +0 -49
  10. package/dist/api/rest/C6.d.ts +0 -579
  11. package/dist/api/rest/Carbons.d.ts +0 -88
  12. package/dist/api/rest/Carbons.test.d.ts +0 -14
  13. package/dist/api/rest/Chat_Messages.d.ts +0 -88
  14. package/dist/api/rest/Chat_Messages.test.d.ts +0 -20
  15. package/dist/api/rest/Documentation.d.ts +0 -88
  16. package/dist/api/rest/Documentation.test.d.ts +0 -11
  17. package/dist/api/rest/Feature_Group_References.d.ts +0 -88
  18. package/dist/api/rest/Feature_Group_References.test.d.ts +0 -13
  19. package/dist/api/rest/Features.d.ts +0 -88
  20. package/dist/api/rest/Features.test.d.ts +0 -14
  21. package/dist/api/rest/Group_References.d.ts +0 -88
  22. package/dist/api/rest/Group_References.test.d.ts +0 -13
  23. package/dist/api/rest/Groups.d.ts +0 -88
  24. package/dist/api/rest/Groups.test.d.ts +0 -15
  25. package/dist/api/rest/History_Logs.d.ts +0 -88
  26. package/dist/api/rest/History_Logs.test.d.ts +0 -13
  27. package/dist/api/rest/Likes.d.ts +0 -88
  28. package/dist/api/rest/Likes.test.d.ts +0 -13
  29. package/dist/api/rest/Location_References.d.ts +0 -88
  30. package/dist/api/rest/Location_References.test.d.ts +0 -14
  31. package/dist/api/rest/Locations.d.ts +0 -88
  32. package/dist/api/rest/Locations.test.d.ts +0 -18
  33. package/dist/api/rest/Photos.d.ts +0 -88
  34. package/dist/api/rest/Photos.test.d.ts +0 -20
  35. package/dist/api/rest/Posts.d.ts +0 -88
  36. package/dist/api/rest/Posts.test.d.ts +0 -22
  37. package/dist/api/rest/Projects.d.ts +0 -88
  38. package/dist/api/rest/Projects.test.d.ts +0 -21
  39. package/dist/api/rest/Reports.d.ts +0 -88
  40. package/dist/api/rest/Reports.test.d.ts +0 -11
  41. package/dist/api/rest/Sessions.d.ts +0 -88
  42. package/dist/api/rest/Sessions.test.d.ts +0 -14
  43. package/dist/api/rest/Subscription.d.ts +0 -88
  44. package/dist/api/rest/Subscription.test.d.ts +0 -20
  45. package/dist/api/rest/User_Followers.d.ts +0 -88
  46. package/dist/api/rest/User_Followers.test.d.ts +0 -16
  47. package/dist/api/rest/User_Groups.d.ts +0 -88
  48. package/dist/api/rest/User_Groups.test.d.ts +0 -13
  49. package/dist/api/rest/User_Messages.d.ts +0 -88
  50. package/dist/api/rest/User_Messages.test.d.ts +0 -20
  51. package/dist/api/rest/User_Sessions.d.ts +0 -88
  52. package/dist/api/rest/User_Sessions.test.d.ts +0 -14
  53. package/dist/api/rest/User_Tasks.d.ts +0 -88
  54. package/dist/api/rest/User_Tasks.test.d.ts +0 -22
  55. package/dist/api/rest/Users.d.ts +0 -88
  56. package/dist/api/rest/Users.test.d.ts +0 -44
  57. package/dist/api/rest/WsLiveUpdates.d.ts +0 -3
  58. package/src/api/rest/C6.tsx +0 -2687
  59. package/src/api/rest/Carbons.test.tsx +0 -128
  60. package/src/api/rest/Carbons.tsx +0 -145
  61. package/src/api/rest/Chat_Messages.test.tsx +0 -138
  62. package/src/api/rest/Chat_Messages.tsx +0 -151
  63. package/src/api/rest/Documentation.test.tsx +0 -128
  64. package/src/api/rest/Documentation.tsx +0 -142
  65. package/src/api/rest/Feature_Group_References.test.tsx +0 -126
  66. package/src/api/rest/Feature_Group_References.tsx +0 -144
  67. package/src/api/rest/Features.test.tsx +0 -128
  68. package/src/api/rest/Features.tsx +0 -145
  69. package/src/api/rest/Group_References.test.tsx +0 -126
  70. package/src/api/rest/Group_References.tsx +0 -144
  71. package/src/api/rest/Groups.test.tsx +0 -130
  72. package/src/api/rest/Groups.tsx +0 -146
  73. package/src/api/rest/History_Logs.test.tsx +0 -130
  74. package/src/api/rest/History_Logs.tsx +0 -144
  75. package/src/api/rest/Likes.test.tsx +0 -126
  76. package/src/api/rest/Likes.tsx +0 -144
  77. package/src/api/rest/Location_References.test.tsx +0 -128
  78. package/src/api/rest/Location_References.tsx +0 -145
  79. package/src/api/rest/Locations.test.tsx +0 -137
  80. package/src/api/rest/Locations.tsx +0 -149
  81. package/src/api/rest/Photos.test.tsx +0 -139
  82. package/src/api/rest/Photos.tsx +0 -151
  83. package/src/api/rest/Posts.test.tsx +0 -142
  84. package/src/api/rest/Posts.tsx +0 -153
  85. package/src/api/rest/Projects.test.tsx +0 -144
  86. package/src/api/rest/Projects.tsx +0 -152
  87. package/src/api/rest/Reports.test.tsx +0 -128
  88. package/src/api/rest/Reports.tsx +0 -142
  89. package/src/api/rest/Sessions.test.tsx +0 -133
  90. package/src/api/rest/Sessions.tsx +0 -145
  91. package/src/api/rest/Subscription.test.tsx +0 -138
  92. package/src/api/rest/Subscription.tsx +0 -151
  93. package/src/api/rest/User_Followers.test.tsx +0 -130
  94. package/src/api/rest/User_Followers.tsx +0 -147
  95. package/src/api/rest/User_Groups.test.tsx +0 -126
  96. package/src/api/rest/User_Groups.tsx +0 -144
  97. package/src/api/rest/User_Messages.test.tsx +0 -137
  98. package/src/api/rest/User_Messages.tsx +0 -151
  99. package/src/api/rest/User_Sessions.test.tsx +0 -133
  100. package/src/api/rest/User_Sessions.tsx +0 -145
  101. package/src/api/rest/User_Tasks.test.tsx +0 -141
  102. package/src/api/rest/User_Tasks.tsx +0 -153
  103. package/src/api/rest/Users.test.tsx +0 -193
  104. package/src/api/rest/Users.tsx +0 -175
  105. package/src/api/rest/WsLiveUpdates.tsx +0 -150
@@ -1,142 +0,0 @@
1
- import {xdescribe, expect, test} from '@jest/globals';
2
- import {CarbonReact} from "@carbonorm/carbonreact";
3
- import {checkAllRequestsComplete} from "@carbonorm/carbonnode";
4
- import {act, waitFor} from '@testing-library/react';
5
- import {C6, iRestfulObjectArrayTypes, iPosts, posts } from "api/rest/C6";
6
- import Posts from "./Posts";
7
-
8
- const randomString = Math.random().toString(36).substring(7);
9
- const randomInt = Math.floor(Math.random() * 1000000);
10
- const fillString = 'string' + randomString + randomInt;
11
-
12
- /**
13
- CREATE TABLE `carbon_posts` (
14
- `post_id` binary(16) NOT NULL,
15
- `post_data` blob,
16
- `post_author` binary(16) DEFAULT NULL,
17
- `post_status` varchar(16) DEFAULT NULL,
18
- `post_created_datetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
19
- `post_project_id` binary(16) DEFAULT NULL,
20
- `post_parent_id` binary(16) DEFAULT NULL,
21
- PRIMARY KEY (`post_id`),
22
- KEY `carbon_posts_carbon_carbons_entity_pk_fk2` (`post_author`),
23
- KEY `carbon_posts_carbon_carbons_entity_pk_fk3` (`post_project_id`),
24
- KEY `carbon_posts_carbon_carbons_entity_pk_fk4` (`post_parent_id`),
25
- CONSTRAINT `carbon_posts_carbon_carbons_entity_pk_fk` FOREIGN KEY (`post_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
26
- CONSTRAINT `carbon_posts_carbon_carbons_entity_pk_fk2` FOREIGN KEY (`post_author`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
27
- CONSTRAINT `carbon_posts_carbon_carbons_entity_pk_fk3` FOREIGN KEY (`post_project_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
28
- CONSTRAINT `carbon_posts_carbon_carbons_entity_pk_fk4` FOREIGN KEY (`post_parent_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
29
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
30
- **/
31
-
32
- const Test_Data: iPosts = {
33
-
34
- post_data: fillString.substring(0, ),
35
-
36
- }
37
-
38
- export default Test_Data;
39
-
40
- xdescribe('REST Posts api', () => {
41
-
42
- let testData = Test_Data;
43
-
44
- test('GET POST PUT DELETE', async () => {
45
-
46
- await act(async () => {
47
-
48
- let selectAllResponse = await Posts.Get({})
49
-
50
- if ('function' === typeof selectAllResponse) {
51
- throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
52
- }
53
-
54
- // We don't care if it is filled or not, just that the request can be made.
55
- expect(selectAllResponse?.data?.rest).not.toBeUndefined();
56
-
57
- const postResponse = await Posts.Post(testData);
58
-
59
- console.log('postResponse', postResponse?.data)
60
-
61
- expect(postResponse?.data?.created).not.toBeUndefined();
62
-
63
- const primaryKey = posts.PRIMARY_SHORT[0];
64
-
65
- const postID = postResponse?.data?.created
66
-
67
- const singleRowSelect = await Posts.Get({
68
- [C6.WHERE]: {
69
- [posts[primaryKey.toUpperCase()]]: postID,
70
- }
71
- })
72
-
73
- if ('function' === typeof singleRowSelect) {
74
- throw Error('singleRowSelect is a promise, this is unexpected.');
75
- }
76
-
77
- console.log('singleRowSelect', singleRowSelect?.data)
78
-
79
- // Ensure the expected response datastructure is returned
80
- expect(singleRowSelect?.data?.rest).not.toBeUndefined();
81
-
82
- // Make sure the previously created post is now returned
83
- expect(typeof singleRowSelect?.data?.rest).toEqual('object');
84
-
85
- // todo - make this work correctly with multiple primary keys
86
- const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
87
-
88
- expect(selectedPostId).toEqual(postID);
89
-
90
- const multipleRowSelect = await Posts.Get({
91
- [C6.WHERE]: {
92
- [posts[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
93
- }
94
- })
95
-
96
- if ('function' === typeof multipleRowSelect) {
97
- throw Error('singleRowSelect is a promise, this is unexpected.');
98
- }
99
-
100
- console.log('singleRowSelect', multipleRowSelect?.data)
101
-
102
- // Ensure the expected response datastructure is returned
103
- expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
104
-
105
- // Make sure the previously created post is now returned
106
- expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
107
-
108
- testData[primaryKey] = postID
109
-
110
- testData.post_id = fillString.substring(0, 16);
111
- testData.post_data = fillString.substring(0, );
112
- testData.post_author = fillString.substring(0, 16);
113
- testData.post_status = fillString.substring(0, 16);
114
- testData.post_created_datetime = fillString.substring(0, );
115
- testData.post_project_id = fillString.substring(0, 16);
116
- testData.post_parent_id = fillString.substring(0, 16);
117
-
118
- // wait for the global state to be updated
119
- expect(CarbonReact.getState<iRestfulObjectArrayTypes>().posts).not.toBeUndefined();
120
-
121
- const updateResponse = await Posts.Put(testData)
122
-
123
- expect(updateResponse?.data?.updated).not.toBeUndefined();
124
-
125
- const deleteResponse = await Posts.Delete({
126
- [primaryKey]: postID
127
- })
128
-
129
- console.log('deleteResponse', deleteResponse?.data)
130
-
131
- expect(deleteResponse?.data?.deleted).not.toBeUndefined();
132
-
133
- await waitFor(async () => {
134
- expect(checkAllRequestsComplete()).toEqual(true);
135
- }, {timeout: 10000, interval: 1000});
136
-
137
- })
138
-
139
- }, 100000);
140
-
141
- })
142
-
@@ -1,153 +0,0 @@
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, iPosts, posts, RestTableNames} from "./C6";
17
-
18
- /**
19
- CREATE TABLE `carbon_posts` (
20
- `post_id` binary(16) NOT NULL,
21
- `post_data` blob,
22
- `post_author` binary(16) DEFAULT NULL,
23
- `post_status` varchar(16) DEFAULT NULL,
24
- `post_created_datetime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
25
- `post_project_id` binary(16) DEFAULT NULL,
26
- `post_parent_id` binary(16) DEFAULT NULL,
27
- PRIMARY KEY (`post_id`),
28
- KEY `carbon_posts_carbon_carbons_entity_pk_fk2` (`post_author`),
29
- KEY `carbon_posts_carbon_carbons_entity_pk_fk3` (`post_project_id`),
30
- KEY `carbon_posts_carbon_carbons_entity_pk_fk4` (`post_parent_id`),
31
- CONSTRAINT `carbon_posts_carbon_carbons_entity_pk_fk` FOREIGN KEY (`post_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
32
- CONSTRAINT `carbon_posts_carbon_carbons_entity_pk_fk2` FOREIGN KEY (`post_author`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
33
- CONSTRAINT `carbon_posts_carbon_carbons_entity_pk_fk3` FOREIGN KEY (`post_project_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
34
- CONSTRAINT `carbon_posts_carbon_carbons_entity_pk_fk4` FOREIGN KEY (`post_parent_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
35
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
36
- **/
37
-
38
- type GetCustomAndRequiredFields = {}
39
-
40
- type GetRequestTableOverrides = {}
41
-
42
- // required parameters, optional parameters, parameter type overrides, response, and table names
43
- export const Get = restRequest<GetCustomAndRequiredFields, iPosts, GetRequestTableOverrides, iGetC6RestResponse<iPosts>, RestTableNames>({
44
- C6: C6,
45
- tableName: posts.TABLE_NAME,
46
- requestMethod: GET,
47
- queryCallback: (request) => {
48
- request.success ??= 'Successfully received posts!'
49
- request.error ??= 'An unknown issue occurred creating the posts!'
50
- return request
51
- },
52
- responseCallback: (response, _request) => {
53
- updateRestfulObjectArrays<iPosts>(response?.data?.rest, "posts", C6.posts.PRIMARY_SHORT as (keyof iPosts)[])
54
- }
55
- });
56
-
57
- type PutCustomAndRequiredFields = {}
58
-
59
- type PutRequestTableOverrides = {}
60
-
61
- export function putStatePosts(response : AxiosResponse<iPutC6RestResponse<iPosts>>, request : iAPI<Modify<iPosts, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
62
- updateRestfulObjectArrays<iPosts>([
63
- removeInvalidKeys<iPosts>({
64
- ...request,
65
- ...response?.data?.rest,
66
- }, C6.TABLES)
67
- ], "posts", posts.PRIMARY_SHORT as (keyof iPosts)[])
68
- }
69
-
70
- export const Put = restRequest<PutCustomAndRequiredFields, iPosts, PutRequestTableOverrides, iPutC6RestResponse<iPosts>, RestTableNames>({
71
- C6: C6,
72
- tableName: posts.TABLE_NAME,
73
- requestMethod: PUT,
74
- queryCallback: (request) => {
75
- request.success ??= 'Successfully updated posts data!'
76
- request.error ??= 'An unknown issue occurred updating the posts data!'
77
- return request
78
- },
79
- responseCallback: putStatePosts
80
- });
81
-
82
- type PostCustomAndRequiredFields = {}
83
-
84
- type PostRequestTableOverrides = {}
85
-
86
- export function postStatePosts(response : AxiosResponse<iPostC6RestResponse<iPosts>>, request : iAPI<Modify<iPosts, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
87
- if ('number' === typeof id || 'string' === typeof id) {
88
- if (1 !== posts.PRIMARY_SHORT.length) {
89
- console.error("C6 received unexpected result's given the primary key length");
90
- } else {
91
- request[posts.PRIMARY_SHORT[0]] = id
92
- }
93
- }
94
- updateRestfulObjectArrays<iPosts>(
95
- undefined !== request.dataInsertMultipleRows
96
- ? request.dataInsertMultipleRows.map((request, index) => {
97
- return removeInvalidKeys<iPosts>({
98
- ...request,
99
- ...(index === 0 ? response?.data?.rest : {}),
100
- }, C6.TABLES)
101
- })
102
- : [
103
- removeInvalidKeys<iPosts>({
104
- ...request,
105
- ...response?.data?.rest,
106
- }, C6.TABLES)
107
- ],
108
- "posts",
109
- posts.PRIMARY_SHORT as (keyof iPosts)[]
110
- )
111
- }
112
-
113
- export const Post = restRequest<PostCustomAndRequiredFields, iPosts, PostRequestTableOverrides, iPostC6RestResponse<iPosts>, RestTableNames>({
114
- C6: C6,
115
- tableName: posts.TABLE_NAME,
116
- requestMethod: POST,
117
- queryCallback: (request) => {
118
- request.success ??= 'Successfully created the posts data!'
119
- request.error ??= 'An unknown issue occurred creating the posts data!'
120
- return request
121
- },
122
- responseCallback: postStatePosts
123
- });
124
-
125
- type DeleteCustomAndRequiredFields = {}
126
-
127
- type DeleteRequestTableOverrides = {}
128
-
129
- export function deleteStatePosts(_response : AxiosResponse<iDeleteC6RestResponse<iPosts>>, request : iAPI<Modify<iPosts, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
130
- deleteRestfulObjectArrays<iPosts>([
131
- request
132
- ], "posts", posts.PRIMARY_SHORT as (keyof iPosts)[])
133
- }
134
-
135
- export const Delete = restRequest<DeleteCustomAndRequiredFields, iPosts, DeleteRequestTableOverrides, iDeleteC6RestResponse<iPosts>, RestTableNames>({
136
- C6: C6,
137
- tableName: posts.TABLE_NAME,
138
- requestMethod: DELETE,
139
- queryCallback: (request) => {
140
- request.success ??= 'Successfully removed the posts data!'
141
- request.error ??= 'An unknown issue occurred removing the posts data!'
142
- return request
143
- },
144
- responseCallback: deleteStatePosts
145
- });
146
-
147
- export default {
148
- // Export all GET, POST, PUT, DELETE functions for each table
149
- Get,
150
- Post,
151
- Put,
152
- Delete,
153
- }
@@ -1,144 +0,0 @@
1
- import {xdescribe, expect, test} from '@jest/globals';
2
- import {CarbonReact} from "@carbonorm/carbonreact";
3
- import {checkAllRequestsComplete} from "@carbonorm/carbonnode";
4
- import {act, waitFor} from '@testing-library/react';
5
- import {C6, iRestfulObjectArrayTypes, iProjects, projects } from "api/rest/C6";
6
- import Projects from "./Projects";
7
-
8
- const randomString = Math.random().toString(36).substring(7);
9
- const randomInt = Math.floor(Math.random() * 1000000);
10
- const fillString = 'string' + randomString + randomInt;
11
-
12
- /**
13
- CREATE TABLE `carbon_projects` (
14
- `project_id` binary(16) NOT NULL,
15
- `project_name` varchar(255) DEFAULT NULL,
16
- `project_start_date` datetime DEFAULT NULL,
17
- `project_end_date` datetime DEFAULT NULL,
18
- `project_description` text,
19
- `project_leader` binary(16) DEFAULT NULL,
20
- `project_cost` float DEFAULT NULL,
21
- `project_overview_top` varchar(255) DEFAULT NULL COMMENT 'ie estimated monthly return',
22
- `project_overview_bottom` varchar(255) DEFAULT NULL,
23
- `project_ends` tinyint(1) DEFAULT NULL,
24
- PRIMARY KEY (`project_id`),
25
- KEY `carbon_projects_carbon_carbons_entity_pk_fk2` (`project_leader`),
26
- CONSTRAINT `carbon_projects_carbon_carbons_entity_pk_fk` FOREIGN KEY (`project_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
27
- CONSTRAINT `carbon_projects_carbon_carbons_entity_pk_fk2` FOREIGN KEY (`project_leader`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
28
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
29
- **/
30
-
31
- const Test_Data: iProjects = {
32
-
33
- project_description: fillString.substring(0, ),
34
-
35
- }
36
-
37
- export default Test_Data;
38
-
39
- xdescribe('REST Projects api', () => {
40
-
41
- let testData = Test_Data;
42
-
43
- test('GET POST PUT DELETE', async () => {
44
-
45
- await act(async () => {
46
-
47
- let selectAllResponse = await Projects.Get({})
48
-
49
- if ('function' === typeof selectAllResponse) {
50
- throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
51
- }
52
-
53
- // We don't care if it is filled or not, just that the request can be made.
54
- expect(selectAllResponse?.data?.rest).not.toBeUndefined();
55
-
56
- const postResponse = await Projects.Post(testData);
57
-
58
- console.log('postResponse', postResponse?.data)
59
-
60
- expect(postResponse?.data?.created).not.toBeUndefined();
61
-
62
- const primaryKey = projects.PRIMARY_SHORT[0];
63
-
64
- const postID = postResponse?.data?.created
65
-
66
- const singleRowSelect = await Projects.Get({
67
- [C6.WHERE]: {
68
- [projects[primaryKey.toUpperCase()]]: postID,
69
- }
70
- })
71
-
72
- if ('function' === typeof singleRowSelect) {
73
- throw Error('singleRowSelect is a promise, this is unexpected.');
74
- }
75
-
76
- console.log('singleRowSelect', singleRowSelect?.data)
77
-
78
- // Ensure the expected response datastructure is returned
79
- expect(singleRowSelect?.data?.rest).not.toBeUndefined();
80
-
81
- // Make sure the previously created post is now returned
82
- expect(typeof singleRowSelect?.data?.rest).toEqual('object');
83
-
84
- // todo - make this work correctly with multiple primary keys
85
- const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
86
-
87
- expect(selectedPostId).toEqual(postID);
88
-
89
- const multipleRowSelect = await Projects.Get({
90
- [C6.WHERE]: {
91
- [projects[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
92
- }
93
- })
94
-
95
- if ('function' === typeof multipleRowSelect) {
96
- throw Error('singleRowSelect is a promise, this is unexpected.');
97
- }
98
-
99
- console.log('singleRowSelect', multipleRowSelect?.data)
100
-
101
- // Ensure the expected response datastructure is returned
102
- expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
103
-
104
- // Make sure the previously created post is now returned
105
- expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
106
-
107
- testData[primaryKey] = postID
108
-
109
- testData.project_id = fillString.substring(0, 16);
110
- testData.project_name = fillString.substring(0, 255);
111
- testData.project_start_date = fillString.substring(0, );
112
- testData.project_end_date = fillString.substring(0, );
113
- testData.project_description = fillString.substring(0, );
114
- testData.project_leader = fillString.substring(0, 16);
115
- testData.project_cost = randomInt;
116
- testData.project_overview_top = fillString.substring(0, 255);
117
- testData.project_overview_bottom = fillString.substring(0, 255);
118
- testData.project_ends = fillString.substring(0, 1);
119
-
120
- // wait for the global state to be updated
121
- expect(CarbonReact.getState<iRestfulObjectArrayTypes>().projects).not.toBeUndefined();
122
-
123
- const updateResponse = await Projects.Put(testData)
124
-
125
- expect(updateResponse?.data?.updated).not.toBeUndefined();
126
-
127
- const deleteResponse = await Projects.Delete({
128
- [primaryKey]: postID
129
- })
130
-
131
- console.log('deleteResponse', deleteResponse?.data)
132
-
133
- expect(deleteResponse?.data?.deleted).not.toBeUndefined();
134
-
135
- await waitFor(async () => {
136
- expect(checkAllRequestsComplete()).toEqual(true);
137
- }, {timeout: 10000, interval: 1000});
138
-
139
- })
140
-
141
- }, 100000);
142
-
143
- })
144
-
@@ -1,152 +0,0 @@
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, iProjects, projects, RestTableNames} from "./C6";
17
-
18
- /**
19
- CREATE TABLE `carbon_projects` (
20
- `project_id` binary(16) NOT NULL,
21
- `project_name` varchar(255) DEFAULT NULL,
22
- `project_start_date` datetime DEFAULT NULL,
23
- `project_end_date` datetime DEFAULT NULL,
24
- `project_description` text,
25
- `project_leader` binary(16) DEFAULT NULL,
26
- `project_cost` float DEFAULT NULL,
27
- `project_overview_top` varchar(255) DEFAULT NULL COMMENT 'ie estimated monthly return',
28
- `project_overview_bottom` varchar(255) DEFAULT NULL,
29
- `project_ends` tinyint(1) DEFAULT NULL,
30
- PRIMARY KEY (`project_id`),
31
- KEY `carbon_projects_carbon_carbons_entity_pk_fk2` (`project_leader`),
32
- CONSTRAINT `carbon_projects_carbon_carbons_entity_pk_fk` FOREIGN KEY (`project_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
33
- CONSTRAINT `carbon_projects_carbon_carbons_entity_pk_fk2` FOREIGN KEY (`project_leader`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
34
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
35
- **/
36
-
37
- type GetCustomAndRequiredFields = {}
38
-
39
- type GetRequestTableOverrides = {}
40
-
41
- // required parameters, optional parameters, parameter type overrides, response, and table names
42
- export const Get = restRequest<GetCustomAndRequiredFields, iProjects, GetRequestTableOverrides, iGetC6RestResponse<iProjects>, RestTableNames>({
43
- C6: C6,
44
- tableName: projects.TABLE_NAME,
45
- requestMethod: GET,
46
- queryCallback: (request) => {
47
- request.success ??= 'Successfully received projects!'
48
- request.error ??= 'An unknown issue occurred creating the projects!'
49
- return request
50
- },
51
- responseCallback: (response, _request) => {
52
- updateRestfulObjectArrays<iProjects>(response?.data?.rest, "projects", C6.projects.PRIMARY_SHORT as (keyof iProjects)[])
53
- }
54
- });
55
-
56
- type PutCustomAndRequiredFields = {}
57
-
58
- type PutRequestTableOverrides = {}
59
-
60
- export function putStateProjects(response : AxiosResponse<iPutC6RestResponse<iProjects>>, request : iAPI<Modify<iProjects, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
61
- updateRestfulObjectArrays<iProjects>([
62
- removeInvalidKeys<iProjects>({
63
- ...request,
64
- ...response?.data?.rest,
65
- }, C6.TABLES)
66
- ], "projects", projects.PRIMARY_SHORT as (keyof iProjects)[])
67
- }
68
-
69
- export const Put = restRequest<PutCustomAndRequiredFields, iProjects, PutRequestTableOverrides, iPutC6RestResponse<iProjects>, RestTableNames>({
70
- C6: C6,
71
- tableName: projects.TABLE_NAME,
72
- requestMethod: PUT,
73
- queryCallback: (request) => {
74
- request.success ??= 'Successfully updated projects data!'
75
- request.error ??= 'An unknown issue occurred updating the projects data!'
76
- return request
77
- },
78
- responseCallback: putStateProjects
79
- });
80
-
81
- type PostCustomAndRequiredFields = {}
82
-
83
- type PostRequestTableOverrides = {}
84
-
85
- export function postStateProjects(response : AxiosResponse<iPostC6RestResponse<iProjects>>, request : iAPI<Modify<iProjects, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
86
- if ('number' === typeof id || 'string' === typeof id) {
87
- if (1 !== projects.PRIMARY_SHORT.length) {
88
- console.error("C6 received unexpected result's given the primary key length");
89
- } else {
90
- request[projects.PRIMARY_SHORT[0]] = id
91
- }
92
- }
93
- updateRestfulObjectArrays<iProjects>(
94
- undefined !== request.dataInsertMultipleRows
95
- ? request.dataInsertMultipleRows.map((request, index) => {
96
- return removeInvalidKeys<iProjects>({
97
- ...request,
98
- ...(index === 0 ? response?.data?.rest : {}),
99
- }, C6.TABLES)
100
- })
101
- : [
102
- removeInvalidKeys<iProjects>({
103
- ...request,
104
- ...response?.data?.rest,
105
- }, C6.TABLES)
106
- ],
107
- "projects",
108
- projects.PRIMARY_SHORT as (keyof iProjects)[]
109
- )
110
- }
111
-
112
- export const Post = restRequest<PostCustomAndRequiredFields, iProjects, PostRequestTableOverrides, iPostC6RestResponse<iProjects>, RestTableNames>({
113
- C6: C6,
114
- tableName: projects.TABLE_NAME,
115
- requestMethod: POST,
116
- queryCallback: (request) => {
117
- request.success ??= 'Successfully created the projects data!'
118
- request.error ??= 'An unknown issue occurred creating the projects data!'
119
- return request
120
- },
121
- responseCallback: postStateProjects
122
- });
123
-
124
- type DeleteCustomAndRequiredFields = {}
125
-
126
- type DeleteRequestTableOverrides = {}
127
-
128
- export function deleteStateProjects(_response : AxiosResponse<iDeleteC6RestResponse<iProjects>>, request : iAPI<Modify<iProjects, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
129
- deleteRestfulObjectArrays<iProjects>([
130
- request
131
- ], "projects", projects.PRIMARY_SHORT as (keyof iProjects)[])
132
- }
133
-
134
- export const Delete = restRequest<DeleteCustomAndRequiredFields, iProjects, DeleteRequestTableOverrides, iDeleteC6RestResponse<iProjects>, RestTableNames>({
135
- C6: C6,
136
- tableName: projects.TABLE_NAME,
137
- requestMethod: DELETE,
138
- queryCallback: (request) => {
139
- request.success ??= 'Successfully removed the projects data!'
140
- request.error ??= 'An unknown issue occurred removing the projects data!'
141
- return request
142
- },
143
- responseCallback: deleteStateProjects
144
- });
145
-
146
- export default {
147
- // Export all GET, POST, PUT, DELETE functions for each table
148
- Get,
149
- Post,
150
- Put,
151
- Delete,
152
- }