@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.
- package/dist/CarbonReact.d.ts +3 -0
- package/dist/index.cjs.js +2133 -5049
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -49
- package/dist/index.esm.js +2114 -4952
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/CarbonReact.tsx +3 -0
- package/src/index.ts +0 -49
- package/dist/api/rest/C6.d.ts +0 -579
- package/dist/api/rest/Carbons.d.ts +0 -88
- package/dist/api/rest/Carbons.test.d.ts +0 -14
- package/dist/api/rest/Chat_Messages.d.ts +0 -88
- package/dist/api/rest/Chat_Messages.test.d.ts +0 -20
- package/dist/api/rest/Documentation.d.ts +0 -88
- package/dist/api/rest/Documentation.test.d.ts +0 -11
- package/dist/api/rest/Feature_Group_References.d.ts +0 -88
- package/dist/api/rest/Feature_Group_References.test.d.ts +0 -13
- package/dist/api/rest/Features.d.ts +0 -88
- package/dist/api/rest/Features.test.d.ts +0 -14
- package/dist/api/rest/Group_References.d.ts +0 -88
- package/dist/api/rest/Group_References.test.d.ts +0 -13
- package/dist/api/rest/Groups.d.ts +0 -88
- package/dist/api/rest/Groups.test.d.ts +0 -15
- package/dist/api/rest/History_Logs.d.ts +0 -88
- package/dist/api/rest/History_Logs.test.d.ts +0 -13
- package/dist/api/rest/Likes.d.ts +0 -88
- package/dist/api/rest/Likes.test.d.ts +0 -13
- package/dist/api/rest/Location_References.d.ts +0 -88
- package/dist/api/rest/Location_References.test.d.ts +0 -14
- package/dist/api/rest/Locations.d.ts +0 -88
- package/dist/api/rest/Locations.test.d.ts +0 -18
- package/dist/api/rest/Photos.d.ts +0 -88
- package/dist/api/rest/Photos.test.d.ts +0 -20
- package/dist/api/rest/Posts.d.ts +0 -88
- package/dist/api/rest/Posts.test.d.ts +0 -22
- package/dist/api/rest/Projects.d.ts +0 -88
- package/dist/api/rest/Projects.test.d.ts +0 -21
- package/dist/api/rest/Reports.d.ts +0 -88
- package/dist/api/rest/Reports.test.d.ts +0 -11
- package/dist/api/rest/Sessions.d.ts +0 -88
- package/dist/api/rest/Sessions.test.d.ts +0 -14
- package/dist/api/rest/Subscription.d.ts +0 -88
- package/dist/api/rest/Subscription.test.d.ts +0 -20
- package/dist/api/rest/User_Followers.d.ts +0 -88
- package/dist/api/rest/User_Followers.test.d.ts +0 -16
- package/dist/api/rest/User_Groups.d.ts +0 -88
- package/dist/api/rest/User_Groups.test.d.ts +0 -13
- package/dist/api/rest/User_Messages.d.ts +0 -88
- package/dist/api/rest/User_Messages.test.d.ts +0 -20
- package/dist/api/rest/User_Sessions.d.ts +0 -88
- package/dist/api/rest/User_Sessions.test.d.ts +0 -14
- package/dist/api/rest/User_Tasks.d.ts +0 -88
- package/dist/api/rest/User_Tasks.test.d.ts +0 -22
- package/dist/api/rest/Users.d.ts +0 -88
- package/dist/api/rest/Users.test.d.ts +0 -44
- package/dist/api/rest/WsLiveUpdates.d.ts +0 -3
- package/src/api/rest/C6.tsx +0 -2687
- package/src/api/rest/Carbons.test.tsx +0 -128
- package/src/api/rest/Carbons.tsx +0 -145
- package/src/api/rest/Chat_Messages.test.tsx +0 -138
- package/src/api/rest/Chat_Messages.tsx +0 -151
- package/src/api/rest/Documentation.test.tsx +0 -128
- package/src/api/rest/Documentation.tsx +0 -142
- package/src/api/rest/Feature_Group_References.test.tsx +0 -126
- package/src/api/rest/Feature_Group_References.tsx +0 -144
- package/src/api/rest/Features.test.tsx +0 -128
- package/src/api/rest/Features.tsx +0 -145
- package/src/api/rest/Group_References.test.tsx +0 -126
- package/src/api/rest/Group_References.tsx +0 -144
- package/src/api/rest/Groups.test.tsx +0 -130
- package/src/api/rest/Groups.tsx +0 -146
- package/src/api/rest/History_Logs.test.tsx +0 -130
- package/src/api/rest/History_Logs.tsx +0 -144
- package/src/api/rest/Likes.test.tsx +0 -126
- package/src/api/rest/Likes.tsx +0 -144
- package/src/api/rest/Location_References.test.tsx +0 -128
- package/src/api/rest/Location_References.tsx +0 -145
- package/src/api/rest/Locations.test.tsx +0 -137
- package/src/api/rest/Locations.tsx +0 -149
- package/src/api/rest/Photos.test.tsx +0 -139
- package/src/api/rest/Photos.tsx +0 -151
- package/src/api/rest/Posts.test.tsx +0 -142
- package/src/api/rest/Posts.tsx +0 -153
- package/src/api/rest/Projects.test.tsx +0 -144
- package/src/api/rest/Projects.tsx +0 -152
- package/src/api/rest/Reports.test.tsx +0 -128
- package/src/api/rest/Reports.tsx +0 -142
- package/src/api/rest/Sessions.test.tsx +0 -133
- package/src/api/rest/Sessions.tsx +0 -145
- package/src/api/rest/Subscription.test.tsx +0 -138
- package/src/api/rest/Subscription.tsx +0 -151
- package/src/api/rest/User_Followers.test.tsx +0 -130
- package/src/api/rest/User_Followers.tsx +0 -147
- package/src/api/rest/User_Groups.test.tsx +0 -126
- package/src/api/rest/User_Groups.tsx +0 -144
- package/src/api/rest/User_Messages.test.tsx +0 -137
- package/src/api/rest/User_Messages.tsx +0 -151
- package/src/api/rest/User_Sessions.test.tsx +0 -133
- package/src/api/rest/User_Sessions.tsx +0 -145
- package/src/api/rest/User_Tasks.test.tsx +0 -141
- package/src/api/rest/User_Tasks.tsx +0 -153
- package/src/api/rest/Users.test.tsx +0 -193
- package/src/api/rest/Users.tsx +0 -175
- package/src/api/rest/WsLiveUpdates.tsx +0 -150
|
@@ -1,128 +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, iCarbons, carbons } from "api/rest/C6";
|
|
6
|
-
import Carbons from "./Carbons";
|
|
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_carbons` (
|
|
14
|
-
`entity_pk` binary(16) NOT NULL,
|
|
15
|
-
`entity_fk` binary(16) DEFAULT NULL,
|
|
16
|
-
`entity_tag` varchar(100) NOT NULL DEFAULT 'manually',
|
|
17
|
-
PRIMARY KEY (`entity_pk`),
|
|
18
|
-
UNIQUE KEY `entity_entity_pk_uindex` (`entity_pk`),
|
|
19
|
-
KEY `entity_entity_entity_pk_fk` (`entity_fk`),
|
|
20
|
-
CONSTRAINT `entity_entity_entity_pk_fk` FOREIGN KEY (`entity_fk`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
21
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
22
|
-
**/
|
|
23
|
-
|
|
24
|
-
const Test_Data: iCarbons = {
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default Test_Data;
|
|
29
|
-
|
|
30
|
-
xdescribe('REST Carbons api', () => {
|
|
31
|
-
|
|
32
|
-
let testData = Test_Data;
|
|
33
|
-
|
|
34
|
-
test('GET POST PUT DELETE', async () => {
|
|
35
|
-
|
|
36
|
-
await act(async () => {
|
|
37
|
-
|
|
38
|
-
let selectAllResponse = await Carbons.Get({})
|
|
39
|
-
|
|
40
|
-
if ('function' === typeof selectAllResponse) {
|
|
41
|
-
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// We don't care if it is filled or not, just that the request can be made.
|
|
45
|
-
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
46
|
-
|
|
47
|
-
const postResponse = await Carbons.Post(testData);
|
|
48
|
-
|
|
49
|
-
console.log('postResponse', postResponse?.data)
|
|
50
|
-
|
|
51
|
-
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
52
|
-
|
|
53
|
-
const primaryKey = carbons.PRIMARY_SHORT[0];
|
|
54
|
-
|
|
55
|
-
const postID = postResponse?.data?.created
|
|
56
|
-
|
|
57
|
-
const singleRowSelect = await Carbons.Get({
|
|
58
|
-
[C6.WHERE]: {
|
|
59
|
-
[carbons[primaryKey.toUpperCase()]]: postID,
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
if ('function' === typeof singleRowSelect) {
|
|
64
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
console.log('singleRowSelect', singleRowSelect?.data)
|
|
68
|
-
|
|
69
|
-
// Ensure the expected response datastructure is returned
|
|
70
|
-
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
71
|
-
|
|
72
|
-
// Make sure the previously created post is now returned
|
|
73
|
-
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
74
|
-
|
|
75
|
-
// todo - make this work correctly with multiple primary keys
|
|
76
|
-
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
77
|
-
|
|
78
|
-
expect(selectedPostId).toEqual(postID);
|
|
79
|
-
|
|
80
|
-
const multipleRowSelect = await Carbons.Get({
|
|
81
|
-
[C6.WHERE]: {
|
|
82
|
-
[carbons[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
if ('function' === typeof multipleRowSelect) {
|
|
87
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
91
|
-
|
|
92
|
-
// Ensure the expected response datastructure is returned
|
|
93
|
-
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
94
|
-
|
|
95
|
-
// Make sure the previously created post is now returned
|
|
96
|
-
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
97
|
-
|
|
98
|
-
testData[primaryKey] = postID
|
|
99
|
-
|
|
100
|
-
testData.entity_pk = fillString.substring(0, 16);
|
|
101
|
-
testData.entity_fk = fillString.substring(0, 16);
|
|
102
|
-
testData.entity_tag = fillString.substring(0, 100);
|
|
103
|
-
|
|
104
|
-
// wait for the global state to be updated
|
|
105
|
-
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().carbons).not.toBeUndefined();
|
|
106
|
-
|
|
107
|
-
const updateResponse = await Carbons.Put(testData)
|
|
108
|
-
|
|
109
|
-
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
110
|
-
|
|
111
|
-
const deleteResponse = await Carbons.Delete({
|
|
112
|
-
[primaryKey]: postID
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
console.log('deleteResponse', deleteResponse?.data)
|
|
116
|
-
|
|
117
|
-
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
118
|
-
|
|
119
|
-
await waitFor(async () => {
|
|
120
|
-
expect(checkAllRequestsComplete()).toEqual(true);
|
|
121
|
-
}, {timeout: 10000, interval: 1000});
|
|
122
|
-
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
}, 100000);
|
|
126
|
-
|
|
127
|
-
})
|
|
128
|
-
|
package/src/api/rest/Carbons.tsx
DELETED
|
@@ -1,145 +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, iCarbons, carbons, RestTableNames} from "./C6";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
CREATE TABLE `carbon_carbons` (
|
|
20
|
-
`entity_pk` binary(16) NOT NULL,
|
|
21
|
-
`entity_fk` binary(16) DEFAULT NULL,
|
|
22
|
-
`entity_tag` varchar(100) NOT NULL DEFAULT 'manually',
|
|
23
|
-
PRIMARY KEY (`entity_pk`),
|
|
24
|
-
UNIQUE KEY `entity_entity_pk_uindex` (`entity_pk`),
|
|
25
|
-
KEY `entity_entity_entity_pk_fk` (`entity_fk`),
|
|
26
|
-
CONSTRAINT `entity_entity_entity_pk_fk` FOREIGN KEY (`entity_fk`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
27
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
28
|
-
**/
|
|
29
|
-
|
|
30
|
-
type GetCustomAndRequiredFields = {}
|
|
31
|
-
|
|
32
|
-
type GetRequestTableOverrides = {}
|
|
33
|
-
|
|
34
|
-
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
35
|
-
export const Get = restRequest<GetCustomAndRequiredFields, iCarbons, GetRequestTableOverrides, iGetC6RestResponse<iCarbons>, RestTableNames>({
|
|
36
|
-
C6: C6,
|
|
37
|
-
tableName: carbons.TABLE_NAME,
|
|
38
|
-
requestMethod: GET,
|
|
39
|
-
queryCallback: (request) => {
|
|
40
|
-
request.success ??= 'Successfully received carbons!'
|
|
41
|
-
request.error ??= 'An unknown issue occurred creating the carbons!'
|
|
42
|
-
return request
|
|
43
|
-
},
|
|
44
|
-
responseCallback: (response, _request) => {
|
|
45
|
-
updateRestfulObjectArrays<iCarbons>(response?.data?.rest, "carbons", C6.carbons.PRIMARY_SHORT as (keyof iCarbons)[])
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
type PutCustomAndRequiredFields = {}
|
|
50
|
-
|
|
51
|
-
type PutRequestTableOverrides = {}
|
|
52
|
-
|
|
53
|
-
export function putStateCarbons(response : AxiosResponse<iPutC6RestResponse<iCarbons>>, request : iAPI<Modify<iCarbons, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
54
|
-
updateRestfulObjectArrays<iCarbons>([
|
|
55
|
-
removeInvalidKeys<iCarbons>({
|
|
56
|
-
...request,
|
|
57
|
-
...response?.data?.rest,
|
|
58
|
-
}, C6.TABLES)
|
|
59
|
-
], "carbons", carbons.PRIMARY_SHORT as (keyof iCarbons)[])
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const Put = restRequest<PutCustomAndRequiredFields, iCarbons, PutRequestTableOverrides, iPutC6RestResponse<iCarbons>, RestTableNames>({
|
|
63
|
-
C6: C6,
|
|
64
|
-
tableName: carbons.TABLE_NAME,
|
|
65
|
-
requestMethod: PUT,
|
|
66
|
-
queryCallback: (request) => {
|
|
67
|
-
request.success ??= 'Successfully updated carbons data!'
|
|
68
|
-
request.error ??= 'An unknown issue occurred updating the carbons data!'
|
|
69
|
-
return request
|
|
70
|
-
},
|
|
71
|
-
responseCallback: putStateCarbons
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
type PostCustomAndRequiredFields = {}
|
|
75
|
-
|
|
76
|
-
type PostRequestTableOverrides = {}
|
|
77
|
-
|
|
78
|
-
export function postStateCarbons(response : AxiosResponse<iPostC6RestResponse<iCarbons>>, request : iAPI<Modify<iCarbons, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
79
|
-
if ('number' === typeof id || 'string' === typeof id) {
|
|
80
|
-
if (1 !== carbons.PRIMARY_SHORT.length) {
|
|
81
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
82
|
-
} else {
|
|
83
|
-
request[carbons.PRIMARY_SHORT[0]] = id
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
updateRestfulObjectArrays<iCarbons>(
|
|
87
|
-
undefined !== request.dataInsertMultipleRows
|
|
88
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
89
|
-
return removeInvalidKeys<iCarbons>({
|
|
90
|
-
...request,
|
|
91
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
92
|
-
}, C6.TABLES)
|
|
93
|
-
})
|
|
94
|
-
: [
|
|
95
|
-
removeInvalidKeys<iCarbons>({
|
|
96
|
-
...request,
|
|
97
|
-
...response?.data?.rest,
|
|
98
|
-
}, C6.TABLES)
|
|
99
|
-
],
|
|
100
|
-
"carbons",
|
|
101
|
-
carbons.PRIMARY_SHORT as (keyof iCarbons)[]
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export const Post = restRequest<PostCustomAndRequiredFields, iCarbons, PostRequestTableOverrides, iPostC6RestResponse<iCarbons>, RestTableNames>({
|
|
106
|
-
C6: C6,
|
|
107
|
-
tableName: carbons.TABLE_NAME,
|
|
108
|
-
requestMethod: POST,
|
|
109
|
-
queryCallback: (request) => {
|
|
110
|
-
request.success ??= 'Successfully created the carbons data!'
|
|
111
|
-
request.error ??= 'An unknown issue occurred creating the carbons data!'
|
|
112
|
-
return request
|
|
113
|
-
},
|
|
114
|
-
responseCallback: postStateCarbons
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
type DeleteCustomAndRequiredFields = {}
|
|
118
|
-
|
|
119
|
-
type DeleteRequestTableOverrides = {}
|
|
120
|
-
|
|
121
|
-
export function deleteStateCarbons(_response : AxiosResponse<iDeleteC6RestResponse<iCarbons>>, request : iAPI<Modify<iCarbons, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
122
|
-
deleteRestfulObjectArrays<iCarbons>([
|
|
123
|
-
request
|
|
124
|
-
], "carbons", carbons.PRIMARY_SHORT as (keyof iCarbons)[])
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export const Delete = restRequest<DeleteCustomAndRequiredFields, iCarbons, DeleteRequestTableOverrides, iDeleteC6RestResponse<iCarbons>, RestTableNames>({
|
|
128
|
-
C6: C6,
|
|
129
|
-
tableName: carbons.TABLE_NAME,
|
|
130
|
-
requestMethod: DELETE,
|
|
131
|
-
queryCallback: (request) => {
|
|
132
|
-
request.success ??= 'Successfully removed the carbons data!'
|
|
133
|
-
request.error ??= 'An unknown issue occurred removing the carbons data!'
|
|
134
|
-
return request
|
|
135
|
-
},
|
|
136
|
-
responseCallback: deleteStateCarbons
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
export default {
|
|
140
|
-
// Export all GET, POST, PUT, DELETE functions for each table
|
|
141
|
-
Get,
|
|
142
|
-
Post,
|
|
143
|
-
Put,
|
|
144
|
-
Delete,
|
|
145
|
-
}
|
|
@@ -1,138 +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, iChat_Messages, chat_messages } from "api/rest/C6";
|
|
6
|
-
import Chat_Messages from "./Chat_Messages";
|
|
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_chat_messages` (
|
|
14
|
-
`chat_message_id` binary(16) NOT NULL,
|
|
15
|
-
`chat_message_from_user` binary(16) NOT NULL,
|
|
16
|
-
`chat_private_group` binary(16) DEFAULT NULL,
|
|
17
|
-
`chat_message` varchar(255) NOT NULL,
|
|
18
|
-
`chat_message_datetime` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
19
|
-
`chat_message_advertisement` smallint DEFAULT '0',
|
|
20
|
-
`chat_message_unfiltered` varchar(255) DEFAULT NULL,
|
|
21
|
-
PRIMARY KEY (`chat_message_id`),
|
|
22
|
-
UNIQUE KEY `chat_chat_messages_chat_message_id_uindex` (`chat_message_id`),
|
|
23
|
-
KEY `chat_chat_messages_dig_chat_advertisements_advertisement_id_fk` (`chat_message_advertisement`),
|
|
24
|
-
KEY `chat_chat_messages_users_ID_fk_2` (`chat_message_from_user`),
|
|
25
|
-
CONSTRAINT `carbon_chat_messages_carbon_carbons_entity_pk_fk` FOREIGN KEY (`chat_message_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
26
|
-
CONSTRAINT `chat_chat_messages_users_ID_fk` FOREIGN KEY (`chat_message_from_user`) REFERENCES `carbon_users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
27
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
28
|
-
**/
|
|
29
|
-
|
|
30
|
-
const Test_Data: iChat_Messages = {
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default Test_Data;
|
|
35
|
-
|
|
36
|
-
xdescribe('REST Chat_Messages api', () => {
|
|
37
|
-
|
|
38
|
-
let testData = Test_Data;
|
|
39
|
-
|
|
40
|
-
test('GET POST PUT DELETE', async () => {
|
|
41
|
-
|
|
42
|
-
await act(async () => {
|
|
43
|
-
|
|
44
|
-
let selectAllResponse = await Chat_Messages.Get({})
|
|
45
|
-
|
|
46
|
-
if ('function' === typeof selectAllResponse) {
|
|
47
|
-
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// We don't care if it is filled or not, just that the request can be made.
|
|
51
|
-
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
52
|
-
|
|
53
|
-
const postResponse = await Chat_Messages.Post(testData);
|
|
54
|
-
|
|
55
|
-
console.log('postResponse', postResponse?.data)
|
|
56
|
-
|
|
57
|
-
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
58
|
-
|
|
59
|
-
const primaryKey = chat_messages.PRIMARY_SHORT[0];
|
|
60
|
-
|
|
61
|
-
const postID = postResponse?.data?.created
|
|
62
|
-
|
|
63
|
-
const singleRowSelect = await Chat_Messages.Get({
|
|
64
|
-
[C6.WHERE]: {
|
|
65
|
-
[chat_messages[primaryKey.toUpperCase()]]: postID,
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
if ('function' === typeof singleRowSelect) {
|
|
70
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
console.log('singleRowSelect', singleRowSelect?.data)
|
|
74
|
-
|
|
75
|
-
// Ensure the expected response datastructure is returned
|
|
76
|
-
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
77
|
-
|
|
78
|
-
// Make sure the previously created post is now returned
|
|
79
|
-
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
80
|
-
|
|
81
|
-
// todo - make this work correctly with multiple primary keys
|
|
82
|
-
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
83
|
-
|
|
84
|
-
expect(selectedPostId).toEqual(postID);
|
|
85
|
-
|
|
86
|
-
const multipleRowSelect = await Chat_Messages.Get({
|
|
87
|
-
[C6.WHERE]: {
|
|
88
|
-
[chat_messages[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
if ('function' === typeof multipleRowSelect) {
|
|
93
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
97
|
-
|
|
98
|
-
// Ensure the expected response datastructure is returned
|
|
99
|
-
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
100
|
-
|
|
101
|
-
// Make sure the previously created post is now returned
|
|
102
|
-
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
103
|
-
|
|
104
|
-
testData[primaryKey] = postID
|
|
105
|
-
|
|
106
|
-
testData.chat_message_id = fillString.substring(0, 16);
|
|
107
|
-
testData.chat_message_from_user = fillString.substring(0, 16);
|
|
108
|
-
testData.chat_private_group = fillString.substring(0, 16);
|
|
109
|
-
testData.chat_message = fillString.substring(0, 255);
|
|
110
|
-
testData.chat_message_datetime = fillString.substring(0, );
|
|
111
|
-
testData.chat_message_advertisement = randomInt;
|
|
112
|
-
testData.chat_message_unfiltered = fillString.substring(0, 255);
|
|
113
|
-
|
|
114
|
-
// wait for the global state to be updated
|
|
115
|
-
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().chat_messages).not.toBeUndefined();
|
|
116
|
-
|
|
117
|
-
const updateResponse = await Chat_Messages.Put(testData)
|
|
118
|
-
|
|
119
|
-
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
120
|
-
|
|
121
|
-
const deleteResponse = await Chat_Messages.Delete({
|
|
122
|
-
[primaryKey]: postID
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
console.log('deleteResponse', deleteResponse?.data)
|
|
126
|
-
|
|
127
|
-
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
128
|
-
|
|
129
|
-
await waitFor(async () => {
|
|
130
|
-
expect(checkAllRequestsComplete()).toEqual(true);
|
|
131
|
-
}, {timeout: 10000, interval: 1000});
|
|
132
|
-
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
}, 100000);
|
|
136
|
-
|
|
137
|
-
})
|
|
138
|
-
|
|
@@ -1,151 +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, iChat_Messages, chat_messages, RestTableNames} from "./C6";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
CREATE TABLE `carbon_chat_messages` (
|
|
20
|
-
`chat_message_id` binary(16) NOT NULL,
|
|
21
|
-
`chat_message_from_user` binary(16) NOT NULL,
|
|
22
|
-
`chat_private_group` binary(16) DEFAULT NULL,
|
|
23
|
-
`chat_message` varchar(255) NOT NULL,
|
|
24
|
-
`chat_message_datetime` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
25
|
-
`chat_message_advertisement` smallint DEFAULT '0',
|
|
26
|
-
`chat_message_unfiltered` varchar(255) DEFAULT NULL,
|
|
27
|
-
PRIMARY KEY (`chat_message_id`),
|
|
28
|
-
UNIQUE KEY `chat_chat_messages_chat_message_id_uindex` (`chat_message_id`),
|
|
29
|
-
KEY `chat_chat_messages_dig_chat_advertisements_advertisement_id_fk` (`chat_message_advertisement`),
|
|
30
|
-
KEY `chat_chat_messages_users_ID_fk_2` (`chat_message_from_user`),
|
|
31
|
-
CONSTRAINT `carbon_chat_messages_carbon_carbons_entity_pk_fk` FOREIGN KEY (`chat_message_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
32
|
-
CONSTRAINT `chat_chat_messages_users_ID_fk` FOREIGN KEY (`chat_message_from_user`) REFERENCES `carbon_users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
33
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
34
|
-
**/
|
|
35
|
-
|
|
36
|
-
type GetCustomAndRequiredFields = {}
|
|
37
|
-
|
|
38
|
-
type GetRequestTableOverrides = {}
|
|
39
|
-
|
|
40
|
-
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
41
|
-
export const Get = restRequest<GetCustomAndRequiredFields, iChat_Messages, GetRequestTableOverrides, iGetC6RestResponse<iChat_Messages>, RestTableNames>({
|
|
42
|
-
C6: C6,
|
|
43
|
-
tableName: chat_messages.TABLE_NAME,
|
|
44
|
-
requestMethod: GET,
|
|
45
|
-
queryCallback: (request) => {
|
|
46
|
-
request.success ??= 'Successfully received chat_messages!'
|
|
47
|
-
request.error ??= 'An unknown issue occurred creating the chat_messages!'
|
|
48
|
-
return request
|
|
49
|
-
},
|
|
50
|
-
responseCallback: (response, _request) => {
|
|
51
|
-
updateRestfulObjectArrays<iChat_Messages>(response?.data?.rest, "chat_messages", C6.chat_messages.PRIMARY_SHORT as (keyof iChat_Messages)[])
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
type PutCustomAndRequiredFields = {}
|
|
56
|
-
|
|
57
|
-
type PutRequestTableOverrides = {}
|
|
58
|
-
|
|
59
|
-
export function putStateChat_Messages(response : AxiosResponse<iPutC6RestResponse<iChat_Messages>>, request : iAPI<Modify<iChat_Messages, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
60
|
-
updateRestfulObjectArrays<iChat_Messages>([
|
|
61
|
-
removeInvalidKeys<iChat_Messages>({
|
|
62
|
-
...request,
|
|
63
|
-
...response?.data?.rest,
|
|
64
|
-
}, C6.TABLES)
|
|
65
|
-
], "chat_messages", chat_messages.PRIMARY_SHORT as (keyof iChat_Messages)[])
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const Put = restRequest<PutCustomAndRequiredFields, iChat_Messages, PutRequestTableOverrides, iPutC6RestResponse<iChat_Messages>, RestTableNames>({
|
|
69
|
-
C6: C6,
|
|
70
|
-
tableName: chat_messages.TABLE_NAME,
|
|
71
|
-
requestMethod: PUT,
|
|
72
|
-
queryCallback: (request) => {
|
|
73
|
-
request.success ??= 'Successfully updated chat_messages data!'
|
|
74
|
-
request.error ??= 'An unknown issue occurred updating the chat_messages data!'
|
|
75
|
-
return request
|
|
76
|
-
},
|
|
77
|
-
responseCallback: putStateChat_Messages
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
type PostCustomAndRequiredFields = {}
|
|
81
|
-
|
|
82
|
-
type PostRequestTableOverrides = {}
|
|
83
|
-
|
|
84
|
-
export function postStateChat_Messages(response : AxiosResponse<iPostC6RestResponse<iChat_Messages>>, request : iAPI<Modify<iChat_Messages, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
85
|
-
if ('number' === typeof id || 'string' === typeof id) {
|
|
86
|
-
if (1 !== chat_messages.PRIMARY_SHORT.length) {
|
|
87
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
88
|
-
} else {
|
|
89
|
-
request[chat_messages.PRIMARY_SHORT[0]] = id
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
updateRestfulObjectArrays<iChat_Messages>(
|
|
93
|
-
undefined !== request.dataInsertMultipleRows
|
|
94
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
95
|
-
return removeInvalidKeys<iChat_Messages>({
|
|
96
|
-
...request,
|
|
97
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
98
|
-
}, C6.TABLES)
|
|
99
|
-
})
|
|
100
|
-
: [
|
|
101
|
-
removeInvalidKeys<iChat_Messages>({
|
|
102
|
-
...request,
|
|
103
|
-
...response?.data?.rest,
|
|
104
|
-
}, C6.TABLES)
|
|
105
|
-
],
|
|
106
|
-
"chat_messages",
|
|
107
|
-
chat_messages.PRIMARY_SHORT as (keyof iChat_Messages)[]
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export const Post = restRequest<PostCustomAndRequiredFields, iChat_Messages, PostRequestTableOverrides, iPostC6RestResponse<iChat_Messages>, RestTableNames>({
|
|
112
|
-
C6: C6,
|
|
113
|
-
tableName: chat_messages.TABLE_NAME,
|
|
114
|
-
requestMethod: POST,
|
|
115
|
-
queryCallback: (request) => {
|
|
116
|
-
request.success ??= 'Successfully created the chat_messages data!'
|
|
117
|
-
request.error ??= 'An unknown issue occurred creating the chat_messages data!'
|
|
118
|
-
return request
|
|
119
|
-
},
|
|
120
|
-
responseCallback: postStateChat_Messages
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
type DeleteCustomAndRequiredFields = {}
|
|
124
|
-
|
|
125
|
-
type DeleteRequestTableOverrides = {}
|
|
126
|
-
|
|
127
|
-
export function deleteStateChat_Messages(_response : AxiosResponse<iDeleteC6RestResponse<iChat_Messages>>, request : iAPI<Modify<iChat_Messages, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
128
|
-
deleteRestfulObjectArrays<iChat_Messages>([
|
|
129
|
-
request
|
|
130
|
-
], "chat_messages", chat_messages.PRIMARY_SHORT as (keyof iChat_Messages)[])
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export const Delete = restRequest<DeleteCustomAndRequiredFields, iChat_Messages, DeleteRequestTableOverrides, iDeleteC6RestResponse<iChat_Messages>, RestTableNames>({
|
|
134
|
-
C6: C6,
|
|
135
|
-
tableName: chat_messages.TABLE_NAME,
|
|
136
|
-
requestMethod: DELETE,
|
|
137
|
-
queryCallback: (request) => {
|
|
138
|
-
request.success ??= 'Successfully removed the chat_messages data!'
|
|
139
|
-
request.error ??= 'An unknown issue occurred removing the chat_messages data!'
|
|
140
|
-
return request
|
|
141
|
-
},
|
|
142
|
-
responseCallback: deleteStateChat_Messages
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
export default {
|
|
146
|
-
// Export all GET, POST, PUT, DELETE functions for each table
|
|
147
|
-
Get,
|
|
148
|
-
Post,
|
|
149
|
-
Put,
|
|
150
|
-
Delete,
|
|
151
|
-
}
|
|
@@ -1,128 +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, iDocumentation, documentation } from "api/rest/C6";
|
|
6
|
-
import Documentation from "./Documentation";
|
|
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_documentation` (
|
|
14
|
-
`documentation_uri` varchar(255) NOT NULL,
|
|
15
|
-
`documentation_data` longblob,
|
|
16
|
-
`documentation_version` varchar(40) NOT NULL,
|
|
17
|
-
`documentation_active` tinyint NOT NULL
|
|
18
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
19
|
-
**/
|
|
20
|
-
|
|
21
|
-
const Test_Data: iDocumentation = {
|
|
22
|
-
|
|
23
|
-
documentation_data: fillString.substring(0, ),
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default Test_Data;
|
|
28
|
-
|
|
29
|
-
xdescribe('REST Documentation api', () => {
|
|
30
|
-
|
|
31
|
-
let testData = Test_Data;
|
|
32
|
-
|
|
33
|
-
test('GET POST PUT DELETE', async () => {
|
|
34
|
-
|
|
35
|
-
await act(async () => {
|
|
36
|
-
|
|
37
|
-
let selectAllResponse = await Documentation.Get({})
|
|
38
|
-
|
|
39
|
-
if ('function' === typeof selectAllResponse) {
|
|
40
|
-
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// We don't care if it is filled or not, just that the request can be made.
|
|
44
|
-
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
45
|
-
|
|
46
|
-
const postResponse = await Documentation.Post(testData);
|
|
47
|
-
|
|
48
|
-
console.log('postResponse', postResponse?.data)
|
|
49
|
-
|
|
50
|
-
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
51
|
-
|
|
52
|
-
const primaryKey = documentation.PRIMARY_SHORT[0];
|
|
53
|
-
|
|
54
|
-
const postID = postResponse?.data?.created
|
|
55
|
-
|
|
56
|
-
const singleRowSelect = await Documentation.Get({
|
|
57
|
-
[C6.WHERE]: {
|
|
58
|
-
[documentation[primaryKey.toUpperCase()]]: postID,
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
if ('function' === typeof singleRowSelect) {
|
|
63
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log('singleRowSelect', singleRowSelect?.data)
|
|
67
|
-
|
|
68
|
-
// Ensure the expected response datastructure is returned
|
|
69
|
-
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
70
|
-
|
|
71
|
-
// Make sure the previously created post is now returned
|
|
72
|
-
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
73
|
-
|
|
74
|
-
// todo - make this work correctly with multiple primary keys
|
|
75
|
-
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
76
|
-
|
|
77
|
-
expect(selectedPostId).toEqual(postID);
|
|
78
|
-
|
|
79
|
-
const multipleRowSelect = await Documentation.Get({
|
|
80
|
-
[C6.WHERE]: {
|
|
81
|
-
[documentation[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
if ('function' === typeof multipleRowSelect) {
|
|
86
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
90
|
-
|
|
91
|
-
// Ensure the expected response datastructure is returned
|
|
92
|
-
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
93
|
-
|
|
94
|
-
// Make sure the previously created post is now returned
|
|
95
|
-
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
96
|
-
|
|
97
|
-
testData[primaryKey] = postID
|
|
98
|
-
|
|
99
|
-
testData.documentation_uri = fillString.substring(0, 255);
|
|
100
|
-
testData.documentation_data = fillString.substring(0, );
|
|
101
|
-
testData.documentation_version = fillString.substring(0, 40);
|
|
102
|
-
testData.documentation_active = fillString.substring(0, );
|
|
103
|
-
|
|
104
|
-
// wait for the global state to be updated
|
|
105
|
-
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().documentation).not.toBeUndefined();
|
|
106
|
-
|
|
107
|
-
const updateResponse = await Documentation.Put(testData)
|
|
108
|
-
|
|
109
|
-
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
110
|
-
|
|
111
|
-
const deleteResponse = await Documentation.Delete({
|
|
112
|
-
[primaryKey]: postID
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
console.log('deleteResponse', deleteResponse?.data)
|
|
116
|
-
|
|
117
|
-
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
118
|
-
|
|
119
|
-
await waitFor(async () => {
|
|
120
|
-
expect(checkAllRequestsComplete()).toEqual(true);
|
|
121
|
-
}, {timeout: 10000, interval: 1000});
|
|
122
|
-
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
}, 100000);
|
|
126
|
-
|
|
127
|
-
})
|
|
128
|
-
|