@jsb188/graphql 1.1.10 → 1.1.11
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/cache/config.ts +64 -50
- package/cache/index.test.ts +671 -109
- package/cache/index.ts +1700 -1240
- package/cache/persist.ts +721 -0
- package/cache/store.ts +437 -0
- package/client/data-table-realtime-subscriptions.test.ts +740 -0
- package/client/data-table-realtime-subscriptions.ts +955 -0
- package/client/data-table-realtime.test.ts +792 -0
- package/client/data-table-realtime.ts +1218 -0
- package/client/fragment-realtime-sequence.ts +52 -0
- package/client/index.ts +2 -0
- package/client/open-sheet.ts +137 -0
- package/client/request-managed-session.test.ts +574 -0
- package/client/request-no-store.test.ts +157 -0
- package/client/request.ts +954 -163
- package/client/sse-ticket.test.ts +26 -0
- package/deno.lock +170 -0
- package/deno.test.json +8 -4
- package/drafts/index.ts +149 -0
- package/drafts/store.ts +397 -0
- package/gql/eagerQueryMap.ts +12 -0
- package/gql/fragments/accountAuthFragments.ts +5 -0
- package/gql/fragments/accountFragments.ts +0 -3
- package/gql/fragments/accountSessionFragments.ts +16 -0
- package/gql/fragments/agentDocFragments.ts +46 -0
- package/gql/fragments/agentMemoryFragments.ts +19 -0
- package/gql/fragments/aiChatFragments.ts +16 -0
- package/gql/fragments/billingFragments.ts +0 -11
- package/gql/fragments/campaignFragments.ts +277 -0
- package/gql/fragments/dataTableFragments.ts +18 -128
- package/gql/fragments/emailFragments.ts +19 -9
- package/gql/fragments/fieldDocFragments.ts +82 -0
- package/gql/fragments/logFragments.ts +20 -79
- package/gql/fragments/organizationFragments.ts +43 -5
- package/gql/fragments/scheduleFragments.ts +155 -0
- package/gql/fragments/sheetFragments.ts +552 -22
- package/gql/fragments/storageFragments.ts +21 -0
- package/gql/fragments/workflowFragments.ts +28 -4
- package/gql/mutations/accountMutations.ts +0 -2
- package/gql/mutations/agentDocMutations.ts +177 -0
- package/gql/mutations/agentMemoryMutations.ts +36 -0
- package/gql/mutations/aiChatMutations.ts +17 -4
- package/gql/mutations/authMutations.ts +158 -17
- package/gql/mutations/campaignMutations.ts +215 -0
- package/gql/mutations/dataTableMutations.ts +48 -26
- package/gql/mutations/fieldDocMutations.ts +24 -0
- package/gql/mutations/index.ts +6 -1
- package/gql/mutations/logMutations.ts +6 -29
- package/gql/mutations/organizationMutations.ts +13 -4
- package/gql/mutations/scheduleMutations.ts +423 -0
- package/gql/mutations/sheetMutations.ts +273 -56
- package/gql/mutations/storageMutations.ts +20 -0
- package/gql/mutations/workflowMutations.ts +42 -0
- package/gql/queries/agentDocQueries.ts +120 -0
- package/gql/queries/agentMemoryQueries.ts +22 -0
- package/gql/queries/aiChatQueries.ts +18 -2
- package/gql/queries/authQueries.ts +41 -0
- package/gql/queries/billingQueries.ts +23 -0
- package/gql/queries/campaignQueries.ts +127 -0
- package/gql/queries/dataTableQueries.ts +100 -11
- package/gql/queries/emailQueries.ts +55 -3
- package/gql/queries/fieldDocQueries.ts +158 -0
- package/gql/queries/index.ts +8 -2
- package/gql/queries/logQueries.ts +11 -28
- package/gql/queries/organizationQueries.ts +52 -1
- package/gql/queries/scheduleQueries.ts +315 -0
- package/gql/queries/sheetQueries.ts +336 -25
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +72 -3
- package/hooks/index.ts +2065 -971
- package/hooks/use-account-mtn.ts +76 -81
- package/hooks/use-agentDoc-mtn.ts +285 -0
- package/hooks/use-agentDoc-qry.ts +208 -0
- package/hooks/use-agentMemory-mtn.ts +73 -0
- package/hooks/use-agentMemory-qry.ts +44 -0
- package/hooks/use-aiChat-mtn.ts +232 -137
- package/hooks/use-aiChat-qry.ts +480 -222
- package/hooks/use-app-qry.ts +12 -9
- package/hooks/use-auth-mtn.ts +406 -252
- package/hooks/use-auth-qry.ts +51 -0
- package/hooks/use-campaign-mtn.ts +377 -0
- package/hooks/use-campaign-qry.ts +257 -0
- package/hooks/use-dataTable-mtn.ts +116 -33
- package/hooks/use-dataTable-qry.ts +859 -35
- package/hooks/use-email-qry.ts +194 -79
- package/hooks/use-fieldDoc-mtn.ts +50 -0
- package/hooks/use-fieldDoc-qry.ts +180 -0
- package/hooks/use-inboundContact-mtn.ts +19 -16
- package/hooks/use-inboundContact-qry.ts +63 -55
- package/hooks/use-integration-mtn.ts +56 -38
- package/hooks/use-integration-qry.ts +24 -9
- package/hooks/use-log-mtn.ts +72 -56
- package/hooks/use-log-qry.ts +93 -69
- package/hooks/use-organization-mtn.ts +334 -277
- package/hooks/use-organization-qry.ts +199 -129
- package/hooks/use-schedule-mtn.ts +416 -0
- package/hooks/use-schedule-qry.ts +157 -0
- package/hooks/use-sheet-mtn.ts +233 -47
- package/hooks/use-sheet-qry.ts +353 -70
- package/hooks/use-storage-mtn.ts +81 -41
- package/hooks/use-storage-qry.ts +104 -13
- package/hooks/use-workflow-mtn.ts +55 -0
- package/hooks/use-workflow-qry.ts +206 -48
- package/loaders/campaign.ts +137 -0
- package/package.json +94 -71
- package/sse.ts +157 -104
- package/tsconfig.json +11 -10
- package/types.d.ts +60 -30
- package/utils.ts +78 -49
- package/gql/fragments/productFragments.ts +0 -39
- package/gql/fragments/reportFragments.ts +0 -90
- package/gql/mutations/billingMutations.ts +0 -34
- package/gql/queries/productQueries.ts +0 -31
- package/gql/queries/reportQueries.ts +0 -134
- package/hooks/use-product-qry.ts +0 -67
- package/hooks/use-report-qry.ts +0 -153
package/package.json
CHANGED
|
@@ -1,73 +1,96 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
2
|
+
"name": "@jsb188/graphql",
|
|
3
|
+
"version": "1.1.11",
|
|
4
|
+
"description": "GraphQL client for react, using recoil",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "jsb188",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "types.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./fragments/account": "./gql/fragments/accountFragments.ts",
|
|
11
|
+
"./fragments/accountAuth": "./gql/fragments/accountAuthFragments.ts",
|
|
12
|
+
"./fragments/accountSession": "./gql/fragments/accountSessionFragments.ts",
|
|
13
|
+
"./fragments/aiChat": "./gql/fragments/aiChatFragments.ts",
|
|
14
|
+
"./fragments/billing": "./gql/fragments/billingFragments.ts",
|
|
15
|
+
"./fragments/email": "./gql/fragments/emailFragments.ts",
|
|
16
|
+
"./fragments/inboundContact": "./gql/fragments/inboundContactFragments.ts",
|
|
17
|
+
"./fragments/integration": "./gql/fragments/integrationFragments.ts",
|
|
18
|
+
"./fragments/log": "./gql/fragments/logFragments.ts",
|
|
19
|
+
"./fragments/schedule": "./gql/fragments/scheduleFragments.ts",
|
|
20
|
+
"./fragments/agentDoc": "./gql/fragments/agentDocFragments.ts",
|
|
21
|
+
"./fragments/organization": "./gql/fragments/organizationFragments.ts",
|
|
22
|
+
"./fragments/other": "./gql/fragments/otherFragments.ts",
|
|
23
|
+
"./fragments/fieldDoc": "./gql/fragments/fieldDocFragments.ts",
|
|
24
|
+
"./fragments/campaign": "./gql/fragments/campaignFragments.ts",
|
|
25
|
+
"./fragments/dataTable": "./gql/fragments/dataTableFragments.ts",
|
|
26
|
+
"./fragments/sheet": "./gql/fragments/sheetFragments.ts",
|
|
27
|
+
"./fragments/storage": "./gql/fragments/storageFragments.ts",
|
|
28
|
+
"./fragments/workflow": "./gql/fragments/workflowFragments.ts",
|
|
29
|
+
"./hooks": "./hooks/",
|
|
30
|
+
"./hooks/use-action-qry": "./hooks/use-action-qry.ts",
|
|
31
|
+
"./hooks/use-aiChat-qry": "./hooks/use-aiChat-qry.ts",
|
|
32
|
+
"./hooks/use-app-qry": "./hooks/use-app-qry.ts",
|
|
33
|
+
"./hooks/use-email-qry": "./hooks/use-email-qry.ts",
|
|
34
|
+
"./hooks/use-agentMemory-qry": "./hooks/use-agentMemory-qry.ts",
|
|
35
|
+
"./hooks/use-inboundContact-qry": "./hooks/use-inboundContact-qry.ts",
|
|
36
|
+
"./hooks/use-log-qry": "./hooks/use-log-qry.ts",
|
|
37
|
+
"./hooks/use-agentDoc-qry": "./hooks/use-agentDoc-qry.ts",
|
|
38
|
+
"./hooks/use-schedule-mtn": "./hooks/use-schedule-mtn.ts",
|
|
39
|
+
"./hooks/use-schedule-qry": "./hooks/use-schedule-qry.ts",
|
|
40
|
+
"./hooks/use-agentDoc-mtn": "./hooks/use-agentDoc-mtn.ts",
|
|
41
|
+
"./hooks/use-organization-qry": "./hooks/use-organization-qry.ts",
|
|
42
|
+
"./hooks/use-fieldDoc-qry": "./hooks/use-fieldDoc-qry.ts",
|
|
43
|
+
"./hooks/use-fieldDoc-mtn": "./hooks/use-fieldDoc-mtn.ts",
|
|
44
|
+
"./hooks/use-campaign-qry": "./hooks/use-campaign-qry.ts",
|
|
45
|
+
"./hooks/use-campaign-mtn": "./hooks/use-campaign-mtn.ts",
|
|
46
|
+
"./hooks/use-dataTable-mtn": "./hooks/use-dataTable-mtn.ts",
|
|
47
|
+
"./hooks/use-dataTable-qry": "./hooks/use-dataTable-qry.ts",
|
|
48
|
+
"./hooks/use-sheet-mtn": "./hooks/use-sheet-mtn.ts",
|
|
49
|
+
"./hooks/use-sheet-qry": "./hooks/use-sheet-qry.ts",
|
|
50
|
+
"./hooks/use-storage-qry": "./hooks/use-storage-qry.ts",
|
|
51
|
+
"./hooks/use-workflow-qry": "./hooks/use-workflow-qry.ts",
|
|
52
|
+
"./hooks/use-workflow-mtn": "./hooks/use-workflow-mtn.ts",
|
|
53
|
+
"./hooks/use-account-mtn": "./hooks/use-account-mtn.ts",
|
|
54
|
+
"./hooks/use-aiChat-mtn": "./hooks/use-aiChat-mtn.ts",
|
|
55
|
+
"./hooks/use-auth-mtn": "./hooks/use-auth-mtn.ts",
|
|
56
|
+
"./hooks/use-auth-qry": "./hooks/use-auth-qry.ts",
|
|
57
|
+
"./hooks/use-integration-qry": "./hooks/use-integration-qry.ts",
|
|
58
|
+
"./hooks/use-integration-mtn": "./hooks/use-integration-mtn.ts",
|
|
59
|
+
"./hooks/use-agentMemory-mtn": "./hooks/use-agentMemory-mtn.ts",
|
|
60
|
+
"./hooks/use-inboundContact-mtn": "./hooks/use-inboundContact-mtn.ts",
|
|
61
|
+
"./hooks/use-log-mtn": "./hooks/use-log-mtn.ts",
|
|
62
|
+
"./hooks/use-organization-mtn": "./hooks/use-organization-mtn.ts",
|
|
63
|
+
"./hooks/use-storage-mtn": "./hooks/use-storage-mtn.ts",
|
|
64
|
+
"./mutations/campaign": "./gql/mutations/campaignMutations.ts",
|
|
65
|
+
"./mutations/integration": "./gql/mutations/integrationMutations.ts",
|
|
66
|
+
"./mutations/dataTable": "./gql/mutations/dataTableMutations.ts",
|
|
67
|
+
"./mutations/schedule": "./gql/mutations/scheduleMutations.ts",
|
|
68
|
+
"./mutations/agentDoc": "./gql/mutations/agentDocMutations.ts",
|
|
69
|
+
"./mutations/fieldDoc": "./gql/mutations/fieldDocMutations.ts",
|
|
70
|
+
"./mutations/sheet": "./gql/mutations/sheetMutations.ts",
|
|
71
|
+
"./mutations": "./gql/mutations/index.ts",
|
|
72
|
+
"./queries": "./gql/queries/index.ts",
|
|
73
|
+
"./cache": "./cache/index.ts",
|
|
74
|
+
"./client": "./client/index.ts",
|
|
75
|
+
"./drafts": "./drafts/index.ts",
|
|
76
|
+
"./client/data-table-realtime": "./client/data-table-realtime.ts",
|
|
77
|
+
"./client/data-table-realtime-subscriptions": "./client/data-table-realtime-subscriptions.ts",
|
|
78
|
+
"./client/open-sheet": "./client/open-sheet.ts",
|
|
79
|
+
"./loaders/campaign": "./loaders/campaign.ts",
|
|
80
|
+
"./sse": "./sse.ts",
|
|
81
|
+
"./types.d": "./types.d.ts",
|
|
82
|
+
"./utils": "./utils.ts"
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"test": "deno test --no-check --allow-env --allow-read --unstable-sloppy-imports --config ./deno.test.json ./cache/index.test.ts ./client/request-no-store.test.ts ./client/request-managed-session.test.ts ./client/data-table-realtime.test.ts ./client/data-table-realtime-subscriptions.test.ts ./client/sse-ticket.test.ts"
|
|
86
|
+
},
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"graphql": "^16.14.2",
|
|
89
|
+
"graphql-tag": "^2.12.7"
|
|
90
|
+
},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"@jsb188/app": "1.1.11",
|
|
93
|
+
"@jsb188/mday": "1.1.11",
|
|
94
|
+
"@jsb188/react": "1.1.11"
|
|
95
|
+
}
|
|
73
96
|
}
|
package/sse.ts
CHANGED
|
@@ -1,143 +1,196 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
addFragmentToCache,
|
|
3
|
+
updateFragment,
|
|
4
|
+
updateQuery,
|
|
5
|
+
} from './cache/index.ts';
|
|
2
6
|
import type { UpdateObserversFn } from './types.d.ts';
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* Types
|
|
6
10
|
*/
|
|
7
11
|
|
|
8
|
-
type ValidSSEType =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
type ValidSSEType =
|
|
13
|
+
// Default SSE events
|
|
14
|
+
| 'CONNECTED'
|
|
15
|
+
// Query handlers
|
|
16
|
+
| 'QUERY_APPEND'
|
|
17
|
+
| 'QUERY_PREPEND'
|
|
18
|
+
// Fragment handlers
|
|
19
|
+
| 'DATA_APPEND'
|
|
20
|
+
| 'DATA_PREPEND'
|
|
21
|
+
| 'DATA_UPDATE';
|
|
16
22
|
|
|
17
23
|
export interface PublishPayload {
|
|
18
24
|
__type: ValidSSEType;
|
|
19
25
|
fragmentKey: string;
|
|
20
26
|
fragmentNamespace?: string;
|
|
21
|
-
|
|
27
|
+
dataFragmentKey?: string;
|
|
22
28
|
data: Record<string, any>;
|
|
23
|
-
|
|
29
|
+
otherData?: Record<string, any>;
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
/**
|
|
27
33
|
* Append or prepend data to a query
|
|
28
34
|
*/
|
|
29
35
|
|
|
30
|
-
function handleQueryConcat(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
36
|
+
function handleQueryConcat(
|
|
37
|
+
payload: PublishPayload,
|
|
38
|
+
updateObservers?: UpdateObserversFn,
|
|
39
|
+
) {
|
|
40
|
+
const {
|
|
41
|
+
__type,
|
|
42
|
+
fragmentKey,
|
|
43
|
+
fragmentNamespace,
|
|
44
|
+
dataFragmentKey,
|
|
45
|
+
data,
|
|
46
|
+
otherData,
|
|
47
|
+
} = payload;
|
|
48
|
+
|
|
49
|
+
if (fragmentKey && fragmentNamespace && dataFragmentKey && data) {
|
|
50
|
+
const isAppend = __type === 'QUERY_APPEND';
|
|
51
|
+
addFragmentToCache(dataFragmentKey, data);
|
|
52
|
+
|
|
53
|
+
const updateData = (currentData: any) => {
|
|
54
|
+
const currentList = currentData?.[fragmentNamespace]?.data;
|
|
55
|
+
if (
|
|
56
|
+
currentData?.[fragmentNamespace]?.__list &&
|
|
57
|
+
Array.isArray(currentList) &&
|
|
58
|
+
!currentList.find((a) => a[0] === dataFragmentKey)
|
|
59
|
+
) {
|
|
60
|
+
const updatedList = isAppend
|
|
61
|
+
? [...currentList, [dataFragmentKey]]
|
|
62
|
+
: [[dataFragmentKey], ...currentList];
|
|
63
|
+
|
|
64
|
+
// console.log('UPDATED !!!!')
|
|
65
|
+
// console.log('UPDATED !!!!')
|
|
66
|
+
// console.log('UPDATED !!!!')
|
|
67
|
+
// console.log('UPDATED !!!!')
|
|
68
|
+
// console.log(fragmentNamespace, {
|
|
69
|
+
// ...currentData?.[fragmentNamespace],
|
|
70
|
+
// data: updatedList
|
|
71
|
+
// });
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
...currentData,
|
|
75
|
+
...otherData,
|
|
76
|
+
[fragmentNamespace]: {
|
|
77
|
+
...currentData?.[fragmentNamespace],
|
|
78
|
+
data: updatedList,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return currentData;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
updateQuery(fragmentKey, updateData, false, updateObservers);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return null;
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
/**
|
|
79
92
|
* Append or prepend data to a fragment
|
|
80
93
|
*/
|
|
81
94
|
|
|
82
|
-
function handleFragmentConcat(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
95
|
+
function handleFragmentConcat(
|
|
96
|
+
payload: PublishPayload,
|
|
97
|
+
updateObservers?: UpdateObserversFn,
|
|
98
|
+
) {
|
|
99
|
+
const { __type, fragmentKey, fragmentNamespace, data, otherData } = payload;
|
|
100
|
+
const isAppend = __type === 'DATA_APPEND';
|
|
101
|
+
|
|
102
|
+
if (fragmentKey && fragmentNamespace && data) {
|
|
103
|
+
const namespaceType = typeof fragmentNamespace;
|
|
104
|
+
const seedData = {
|
|
105
|
+
...(otherData && typeof otherData === 'object' ? otherData : {}),
|
|
106
|
+
[fragmentNamespace]: data,
|
|
107
|
+
};
|
|
108
|
+
const updateData = (currentData: any) => {
|
|
109
|
+
if (typeof currentData[fragmentNamespace] === namespaceType) {
|
|
110
|
+
let nextValue;
|
|
111
|
+
if (namespaceType === 'string') {
|
|
112
|
+
nextValue = isAppend
|
|
113
|
+
? `${currentData[fragmentNamespace]}${data}`
|
|
114
|
+
: `${data}${currentData[fragmentNamespace]}`;
|
|
115
|
+
} else if (Array.isArray(currentData[fragmentNamespace])) {
|
|
116
|
+
nextValue = isAppend
|
|
117
|
+
? [...currentData[fragmentNamespace], data]
|
|
118
|
+
: [data, ...currentData[fragmentNamespace]];
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
...currentData,
|
|
122
|
+
...otherData,
|
|
123
|
+
[fragmentNamespace]: nextValue,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return currentData;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const updateFragmentKey = updateFragment(
|
|
130
|
+
fragmentKey,
|
|
131
|
+
updateData,
|
|
132
|
+
null,
|
|
133
|
+
false,
|
|
134
|
+
updateObservers,
|
|
135
|
+
);
|
|
136
|
+
if (!updateFragmentKey) {
|
|
137
|
+
addFragmentToCache(fragmentKey, seedData);
|
|
138
|
+
updateObservers?.({
|
|
139
|
+
fragmentIds: [fragmentKey],
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
108
143
|
}
|
|
109
144
|
|
|
110
145
|
/**
|
|
111
146
|
* Update data in a fragment
|
|
112
147
|
*/
|
|
113
148
|
|
|
114
|
-
function handleFragmentUpdate(
|
|
115
|
-
|
|
116
|
-
|
|
149
|
+
function handleFragmentUpdate(
|
|
150
|
+
payload: PublishPayload,
|
|
151
|
+
updateObservers?: UpdateObserversFn,
|
|
152
|
+
) {
|
|
153
|
+
const { fragmentKey, dataFragmentKey, data } = payload;
|
|
154
|
+
const updateFragmentKey = dataFragmentKey || fragmentKey;
|
|
155
|
+
const updatedFragmentKey = updateFragment(
|
|
156
|
+
updateFragmentKey,
|
|
157
|
+
data,
|
|
158
|
+
null,
|
|
159
|
+
false,
|
|
160
|
+
updateObservers,
|
|
161
|
+
);
|
|
162
|
+
if (!updatedFragmentKey) {
|
|
163
|
+
addFragmentToCache(updateFragmentKey, data);
|
|
164
|
+
updateObservers?.({
|
|
165
|
+
fragmentIds: [updateFragmentKey],
|
|
166
|
+
});
|
|
167
|
+
}
|
|
117
168
|
}
|
|
118
169
|
|
|
119
170
|
/**
|
|
120
171
|
* Data handler for SSE
|
|
121
172
|
*/
|
|
122
173
|
|
|
123
|
-
function handleSSEData(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
174
|
+
function handleSSEData(
|
|
175
|
+
payload: PublishPayload,
|
|
176
|
+
updateObservers?: UpdateObserversFn,
|
|
177
|
+
) {
|
|
178
|
+
switch (payload.__type) {
|
|
179
|
+
case 'CONNECTED':
|
|
180
|
+
// Do nothing
|
|
181
|
+
break;
|
|
182
|
+
case 'QUERY_APPEND':
|
|
183
|
+
case 'QUERY_PREPEND':
|
|
184
|
+
return handleQueryConcat(payload, updateObservers);
|
|
185
|
+
case 'DATA_APPEND':
|
|
186
|
+
case 'DATA_PREPEND':
|
|
187
|
+
return handleFragmentConcat(payload, updateObservers);
|
|
188
|
+
case 'DATA_UPDATE':
|
|
189
|
+
return handleFragmentUpdate(payload, updateObservers);
|
|
190
|
+
default:
|
|
191
|
+
console.log('Unknown {__type} in handleSSEData():', payload.__type);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
141
194
|
}
|
|
142
195
|
|
|
143
196
|
export default handleSSEData;
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["**/*.ts", "**/*.tsx", "**/*.d.ts"],
|
|
12
|
+
"exclude": ["**/*.test.ts"]
|
|
12
13
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ServerErrorObj,
|
|
3
|
+
SimpleErrorType,
|
|
4
|
+
} from '@jsb188/app/types/app.d.ts';
|
|
5
|
+
import type { QueryResetTarget } from '@jsb188/app/utils/queryReset.ts';
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* GraphQL API requests
|
|
5
9
|
*/
|
|
6
10
|
|
|
7
11
|
export interface APIRequestOutput {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
aborted?: boolean;
|
|
13
|
+
error: ServerErrorObj | null;
|
|
14
|
+
[apiName: string]: any; // Different name & data; it depends on API
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
export interface GraphQLHandlers {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
resetErrors: () => void;
|
|
19
|
+
setError: (error: SimpleErrorType) => void;
|
|
20
|
+
setSaving: (nextSaving: boolean, resetInMS?: number) => void;
|
|
21
|
+
refetch: () => void;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
export interface UpdateDataObserverArgs {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
queryId?: string | null;
|
|
26
|
+
// Set when the reset came from a structured target; observers match against
|
|
27
|
+
// this instead of parsing queryId, which is only a stable identity string
|
|
28
|
+
queryTarget?: QueryResetTarget | null;
|
|
29
|
+
fragmentIds?: (string | null)[];
|
|
30
|
+
forceRefetch?: boolean;
|
|
31
|
+
resetOnly?: boolean;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
/**
|
|
@@ -30,46 +37,69 @@ export interface UpdateDataObserverArgs {
|
|
|
30
37
|
|
|
31
38
|
export type AnyModalPopUpFn = (data: any, err?: ServerErrorObj) => void;
|
|
32
39
|
export type UpdateObserversFn = (args: UpdateDataObserverArgs) => void;
|
|
33
|
-
export type OnCompletedGQLFn = (
|
|
34
|
-
|
|
40
|
+
export type OnCompletedGQLFn = (
|
|
41
|
+
data: any,
|
|
42
|
+
error: ServerErrorObj | null,
|
|
43
|
+
variables?: any,
|
|
44
|
+
) => void;
|
|
45
|
+
export type OnErrorGQLFn = (
|
|
46
|
+
error: ServerErrorObj | null,
|
|
47
|
+
variables: any,
|
|
48
|
+
) => void;
|
|
35
49
|
|
|
36
50
|
/**
|
|
37
51
|
* GraphQL query hook params
|
|
38
52
|
*/
|
|
39
53
|
|
|
40
54
|
export interface GraphQLQueryOptions {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
authToken?: string | null;
|
|
56
|
+
name?: string;
|
|
57
|
+
eagerFragmentKeyMap?: any;
|
|
58
|
+
retryCount?: number;
|
|
59
|
+
rejectedResultRetryCount?: number;
|
|
60
|
+
retryTransientErrors?: boolean;
|
|
61
|
+
variables?: Record<string, any> | null;
|
|
62
|
+
cacheMap?: any;
|
|
63
|
+
skip?: boolean;
|
|
64
|
+
// Freshness window in ms: a complete cached result younger than this is
|
|
65
|
+
// served without any request; an older one is served instantly and then
|
|
66
|
+
// revalidated in the background (stale-while-revalidate). Defaults to the
|
|
67
|
+
// query's QUERY_EXPIRE_TIMES entry.
|
|
68
|
+
persistTime?: number;
|
|
69
|
+
testMode?: boolean;
|
|
70
|
+
openModalPopUp?: AnyModalPopUpFn | null;
|
|
71
|
+
onCompleted?: OnCompletedGQLFn;
|
|
72
|
+
onError?: OnErrorGQLFn;
|
|
73
|
+
shouldAcceptResult?: (
|
|
74
|
+
data: any,
|
|
75
|
+
variables?: Record<string, any> | null,
|
|
76
|
+
) => boolean;
|
|
51
77
|
}
|
|
52
78
|
|
|
53
79
|
// Params for most GraphQL (query) hooks
|
|
54
|
-
export type UseQueryParams = Omit<
|
|
80
|
+
export type UseQueryParams = Omit<
|
|
81
|
+
GraphQLQueryOptions,
|
|
82
|
+
'name' | 'retryCount' | 'cacheMap'
|
|
83
|
+
>;
|
|
55
84
|
|
|
56
85
|
// Params for most GraphQL (mutation) hooks
|
|
57
86
|
export type UseMutationParams = Partial<{
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
onCompleted: OnCompletedGQLFn;
|
|
88
|
+
onError: OnErrorGQLFn;
|
|
60
89
|
}>;
|
|
61
90
|
|
|
62
91
|
// Params for most GraphQL hooks with these options
|
|
63
92
|
export type UseMutationParamsExtra = Partial<{
|
|
64
|
-
|
|
65
|
-
}> &
|
|
93
|
+
checkMountedBeforeCallback?: boolean;
|
|
94
|
+
}> &
|
|
95
|
+
UseMutationParams;
|
|
66
96
|
|
|
67
97
|
/**
|
|
68
98
|
* Common query patterns
|
|
69
99
|
*/
|
|
70
100
|
|
|
71
101
|
export type PaginationArgs = Partial<{
|
|
72
|
-
cursor: [number | null, number | null];
|
|
102
|
+
cursor: [number | null, number | null, string?] | string | null;
|
|
73
103
|
after: boolean;
|
|
74
104
|
limit: number;
|
|
75
105
|
doNotThrowError: boolean;
|