@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.
Files changed (116) hide show
  1. package/cache/config.ts +64 -50
  2. package/cache/index.test.ts +671 -109
  3. package/cache/index.ts +1700 -1240
  4. package/cache/persist.ts +721 -0
  5. package/cache/store.ts +437 -0
  6. package/client/data-table-realtime-subscriptions.test.ts +740 -0
  7. package/client/data-table-realtime-subscriptions.ts +955 -0
  8. package/client/data-table-realtime.test.ts +792 -0
  9. package/client/data-table-realtime.ts +1218 -0
  10. package/client/fragment-realtime-sequence.ts +52 -0
  11. package/client/index.ts +2 -0
  12. package/client/open-sheet.ts +137 -0
  13. package/client/request-managed-session.test.ts +574 -0
  14. package/client/request-no-store.test.ts +157 -0
  15. package/client/request.ts +954 -163
  16. package/client/sse-ticket.test.ts +26 -0
  17. package/deno.lock +170 -0
  18. package/deno.test.json +8 -4
  19. package/drafts/index.ts +149 -0
  20. package/drafts/store.ts +397 -0
  21. package/gql/eagerQueryMap.ts +12 -0
  22. package/gql/fragments/accountAuthFragments.ts +5 -0
  23. package/gql/fragments/accountFragments.ts +0 -3
  24. package/gql/fragments/accountSessionFragments.ts +16 -0
  25. package/gql/fragments/agentDocFragments.ts +46 -0
  26. package/gql/fragments/agentMemoryFragments.ts +19 -0
  27. package/gql/fragments/aiChatFragments.ts +16 -0
  28. package/gql/fragments/billingFragments.ts +0 -11
  29. package/gql/fragments/campaignFragments.ts +277 -0
  30. package/gql/fragments/dataTableFragments.ts +18 -128
  31. package/gql/fragments/emailFragments.ts +19 -9
  32. package/gql/fragments/fieldDocFragments.ts +82 -0
  33. package/gql/fragments/logFragments.ts +20 -79
  34. package/gql/fragments/organizationFragments.ts +43 -5
  35. package/gql/fragments/scheduleFragments.ts +155 -0
  36. package/gql/fragments/sheetFragments.ts +552 -22
  37. package/gql/fragments/storageFragments.ts +21 -0
  38. package/gql/fragments/workflowFragments.ts +28 -4
  39. package/gql/mutations/accountMutations.ts +0 -2
  40. package/gql/mutations/agentDocMutations.ts +177 -0
  41. package/gql/mutations/agentMemoryMutations.ts +36 -0
  42. package/gql/mutations/aiChatMutations.ts +17 -4
  43. package/gql/mutations/authMutations.ts +158 -17
  44. package/gql/mutations/campaignMutations.ts +215 -0
  45. package/gql/mutations/dataTableMutations.ts +48 -26
  46. package/gql/mutations/fieldDocMutations.ts +24 -0
  47. package/gql/mutations/index.ts +6 -1
  48. package/gql/mutations/logMutations.ts +6 -29
  49. package/gql/mutations/organizationMutations.ts +13 -4
  50. package/gql/mutations/scheduleMutations.ts +423 -0
  51. package/gql/mutations/sheetMutations.ts +273 -56
  52. package/gql/mutations/storageMutations.ts +20 -0
  53. package/gql/mutations/workflowMutations.ts +42 -0
  54. package/gql/queries/agentDocQueries.ts +120 -0
  55. package/gql/queries/agentMemoryQueries.ts +22 -0
  56. package/gql/queries/aiChatQueries.ts +18 -2
  57. package/gql/queries/authQueries.ts +41 -0
  58. package/gql/queries/billingQueries.ts +23 -0
  59. package/gql/queries/campaignQueries.ts +127 -0
  60. package/gql/queries/dataTableQueries.ts +100 -11
  61. package/gql/queries/emailQueries.ts +55 -3
  62. package/gql/queries/fieldDocQueries.ts +158 -0
  63. package/gql/queries/index.ts +8 -2
  64. package/gql/queries/logQueries.ts +11 -28
  65. package/gql/queries/organizationQueries.ts +52 -1
  66. package/gql/queries/scheduleQueries.ts +315 -0
  67. package/gql/queries/sheetQueries.ts +336 -25
  68. package/gql/queries/storageQueries.ts +38 -0
  69. package/gql/queries/workflowQueries.ts +72 -3
  70. package/hooks/index.ts +2065 -971
  71. package/hooks/use-account-mtn.ts +76 -81
  72. package/hooks/use-agentDoc-mtn.ts +285 -0
  73. package/hooks/use-agentDoc-qry.ts +208 -0
  74. package/hooks/use-agentMemory-mtn.ts +73 -0
  75. package/hooks/use-agentMemory-qry.ts +44 -0
  76. package/hooks/use-aiChat-mtn.ts +232 -137
  77. package/hooks/use-aiChat-qry.ts +480 -222
  78. package/hooks/use-app-qry.ts +12 -9
  79. package/hooks/use-auth-mtn.ts +406 -252
  80. package/hooks/use-auth-qry.ts +51 -0
  81. package/hooks/use-campaign-mtn.ts +377 -0
  82. package/hooks/use-campaign-qry.ts +257 -0
  83. package/hooks/use-dataTable-mtn.ts +116 -33
  84. package/hooks/use-dataTable-qry.ts +859 -35
  85. package/hooks/use-email-qry.ts +194 -79
  86. package/hooks/use-fieldDoc-mtn.ts +50 -0
  87. package/hooks/use-fieldDoc-qry.ts +180 -0
  88. package/hooks/use-inboundContact-mtn.ts +19 -16
  89. package/hooks/use-inboundContact-qry.ts +63 -55
  90. package/hooks/use-integration-mtn.ts +56 -38
  91. package/hooks/use-integration-qry.ts +24 -9
  92. package/hooks/use-log-mtn.ts +72 -56
  93. package/hooks/use-log-qry.ts +93 -69
  94. package/hooks/use-organization-mtn.ts +334 -277
  95. package/hooks/use-organization-qry.ts +199 -129
  96. package/hooks/use-schedule-mtn.ts +416 -0
  97. package/hooks/use-schedule-qry.ts +157 -0
  98. package/hooks/use-sheet-mtn.ts +233 -47
  99. package/hooks/use-sheet-qry.ts +353 -70
  100. package/hooks/use-storage-mtn.ts +81 -41
  101. package/hooks/use-storage-qry.ts +104 -13
  102. package/hooks/use-workflow-mtn.ts +55 -0
  103. package/hooks/use-workflow-qry.ts +206 -48
  104. package/loaders/campaign.ts +137 -0
  105. package/package.json +94 -71
  106. package/sse.ts +157 -104
  107. package/tsconfig.json +11 -10
  108. package/types.d.ts +60 -30
  109. package/utils.ts +78 -49
  110. package/gql/fragments/productFragments.ts +0 -39
  111. package/gql/fragments/reportFragments.ts +0 -90
  112. package/gql/mutations/billingMutations.ts +0 -34
  113. package/gql/queries/productQueries.ts +0 -31
  114. package/gql/queries/reportQueries.ts +0 -134
  115. package/hooks/use-product-qry.ts +0 -67
  116. package/hooks/use-report-qry.ts +0 -153
package/package.json CHANGED
@@ -1,73 +1,96 @@
1
1
  {
2
- "name": "@jsb188/graphql",
3
- "version": "1.1.10",
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/aiChat": "./gql/fragments/aiChatFragments.ts",
13
- "./fragments/billing": "./gql/fragments/billingFragments.ts",
14
- "./fragments/email": "./gql/fragments/emailFragments.ts",
15
- "./fragments/inboundContact": "./gql/fragments/inboundContactFragments.ts",
16
- "./fragments/integration": "./gql/fragments/integrationFragments.ts",
17
- "./fragments/log": "./gql/fragments/logFragments.ts",
18
- "./fragments/organization": "./gql/fragments/organizationFragments.ts",
19
- "./fragments/other": "./gql/fragments/otherFragments.ts",
20
- "./fragments/product": "./gql/fragments/productFragments.ts",
21
- "./fragments/report": "./gql/fragments/reportFragments.ts",
22
- "./fragments/dataTable": "./gql/fragments/dataTableFragments.ts",
23
- "./fragments/sheet": "./gql/fragments/sheetFragments.ts",
24
- "./fragments/storage": "./gql/fragments/storageFragments.ts",
25
- "./fragments/workflow": "./gql/fragments/workflowFragments.ts",
26
- "./hooks": "./hooks/",
27
- "./hooks/use-action-qry": "./hooks/use-action-qry.ts",
28
- "./hooks/use-aiChat-qry": "./hooks/use-aiChat-qry.ts",
29
- "./hooks/use-app-qry": "./hooks/use-app-qry.ts",
30
- "./hooks/use-email-qry": "./hooks/use-email-qry.ts",
31
- "./hooks/use-inboundContact-qry": "./hooks/use-inboundContact-qry.ts",
32
- "./hooks/use-log-qry": "./hooks/use-log-qry.ts",
33
- "./hooks/use-organization-qry": "./hooks/use-organization-qry.ts",
34
- "./hooks/use-product-qry": "./hooks/use-product-qry.ts",
35
- "./hooks/use-report-qry": "./hooks/use-report-qry.ts",
36
- "./hooks/use-dataTable-mtn": "./hooks/use-dataTable-mtn.ts",
37
- "./hooks/use-dataTable-qry": "./hooks/use-dataTable-qry.ts",
38
- "./hooks/use-sheet-mtn": "./hooks/use-sheet-mtn.ts",
39
- "./hooks/use-sheet-qry": "./hooks/use-sheet-qry.ts",
40
- "./hooks/use-storage-qry": "./hooks/use-storage-qry.ts",
41
- "./hooks/use-workflow-qry": "./hooks/use-workflow-qry.ts",
42
- "./hooks/use-account-mtn": "./hooks/use-account-mtn.ts",
43
- "./hooks/use-aiChat-mtn": "./hooks/use-aiChat-mtn.ts",
44
- "./hooks/use-auth-mtn": "./hooks/use-auth-mtn.ts",
45
- "./hooks/use-integration-qry": "./hooks/use-integration-qry.ts",
46
- "./hooks/use-integration-mtn": "./hooks/use-integration-mtn.ts",
47
- "./hooks/use-inboundContact-mtn": "./hooks/use-inboundContact-mtn.ts",
48
- "./hooks/use-log-mtn": "./hooks/use-log-mtn.ts",
49
- "./hooks/use-organization-mtn": "./hooks/use-organization-mtn.ts",
50
- "./hooks/use-storage-mtn": "./hooks/use-storage-mtn.ts",
51
- "./mutations/integration": "./gql/mutations/integrationMutations.ts",
52
- "./mutations/dataTable": "./gql/mutations/dataTableMutations.ts",
53
- "./mutations/sheet": "./gql/mutations/sheetMutations.ts",
54
- "./mutations": "./gql/mutations/index.ts",
55
- "./queries": "./gql/queries/index.ts",
56
- "./cache": "./cache/index.ts",
57
- "./client": "./client/index.ts",
58
- "./sse": "./sse.ts",
59
- "./types.d": "./types.d.ts",
60
- "./utils": "./utils.ts"
61
- },
62
- "scripts": {
63
- "test": "deno test --no-check --unstable-sloppy-imports --config ./deno.test.json ./cache/index.test.ts"
64
- },
65
- "dependencies": {
66
- "graphql": "^16.11.0",
67
- "graphql-tag": "^2.12.6"
68
- },
69
- "peerDependencies": {
70
- "@jsb188/app": "1.1.10",
71
- "@jsb188/react": "1.1.10"
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 { addFragmentToCache, updateFragment, updateQuery } from './cache/index.ts';
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
- // Default SSE events
10
- 'CONNECTED' |
11
- // Query handlers
12
- 'QUERY_APPEND' | 'QUERY_PREPEND' |
13
- // Fragment handlers
14
- 'DATA_APPEND' | 'DATA_PREPEND' | 'DATA_UPDATE'
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
- dataFragmentKey?: string;
27
+ dataFragmentKey?: string;
22
28
  data: Record<string, any>;
23
- otherData?: Record<string, any>;
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(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
31
-
32
- const { __type, fragmentKey, fragmentNamespace, dataFragmentKey, data, otherData } = payload;
33
-
34
- if (fragmentKey && fragmentNamespace && dataFragmentKey && data) {
35
- const isAppend = __type === 'QUERY_APPEND';
36
- const updateData = (currentData: any) => {
37
- const currentList = currentData?.[fragmentNamespace]?.data;
38
- if (
39
- currentData?.[fragmentNamespace]?.__list &&
40
- Array.isArray(currentList) &&
41
- !currentList.find(a => a[0] === dataFragmentKey)
42
- ) {
43
- addFragmentToCache(dataFragmentKey, data);
44
- const updatedList = isAppend ? [...currentList, [dataFragmentKey]] : [[dataFragmentKey], ...currentList];
45
-
46
- // console.log('UPDATED !!!!')
47
- // console.log('UPDATED !!!!')
48
- // console.log('UPDATED !!!!')
49
- // console.log('UPDATED !!!!')
50
- // console.log(fragmentNamespace, {
51
- // ...currentData?.[fragmentNamespace],
52
- // data: updatedList
53
- // });
54
-
55
- return {
56
- ...currentData,
57
- ...otherData,
58
- [fragmentNamespace]: {
59
- ...currentData?.[fragmentNamespace],
60
- data: updatedList
61
- }
62
- };
63
- }
64
- return currentData;
65
- }
66
-
67
- updateQuery(
68
- fragmentKey,
69
- updateData,
70
- false,
71
- updateObservers
72
- );
73
- }
74
-
75
- return null;
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(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
83
- const { __type, fragmentKey, fragmentNamespace, data, otherData } = payload;
84
- const isAppend = __type === 'DATA_APPEND';
85
-
86
- if (fragmentKey && fragmentNamespace && data) {
87
- const namespaceType = typeof fragmentNamespace;
88
- const updateData = (currentData: any) => {
89
- if (typeof currentData[fragmentNamespace] === namespaceType) {
90
- let nextValue;
91
- if (namespaceType === 'string') {
92
- nextValue = isAppend ? `${currentData[fragmentNamespace]}${data}` : `${data}${currentData[fragmentNamespace]}`;
93
- } else if (Array.isArray(currentData[fragmentNamespace])) {
94
- nextValue = isAppend ? [...currentData[fragmentNamespace], data] : [data, ...currentData[fragmentNamespace]];
95
- }
96
- return {
97
- ...currentData,
98
- ...otherData,
99
- [fragmentNamespace]: nextValue
100
- }
101
- }
102
- return currentData;
103
- };
104
-
105
- updateFragment(fragmentKey, updateData, null, false, updateObservers);
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(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
115
- const { fragmentKey, dataFragmentKey, data } = payload;
116
- updateFragment(dataFragmentKey || fragmentKey, data, null, false, updateObservers);
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(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
124
-
125
- switch (payload.__type) {
126
- case 'CONNECTED':
127
- // Do nothing
128
- break;
129
- case 'QUERY_APPEND':
130
- case 'QUERY_PREPEND':
131
- return handleQueryConcat(payload, updateObservers)
132
- case 'DATA_APPEND':
133
- case 'DATA_PREPEND':
134
- return handleFragmentConcat(payload, updateObservers)
135
- case 'DATA_UPDATE':
136
- return handleFragmentUpdate(payload, updateObservers)
137
- default:
138
- console.log('Unknown {__type} in handleSSEData():', payload.__type);
139
- break;
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
- "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"]
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 { ServerErrorObj, SimpleErrorType } from '@jsb188/app/types/app.d.ts';
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
- aborted?: boolean;
9
- error: ServerErrorObj | null;
10
- [apiName: string]: any; // Different name & data; it depends on API
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
- resetErrors: () => void;
15
- setError: (error: SimpleErrorType) => void;
16
- setSaving: (nextSaving: boolean, resetInMS?: number) => void;
17
- refetch: () => void;
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
- queryId?: string | null;
22
- fragmentIds?: (string | null)[];
23
- forceRefetch?: boolean;
24
- resetOnly?: boolean;
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 = (data: any, error: ServerErrorObj | null, variables?: any) => void;
34
- export type OnErrorGQLFn = (error: ServerErrorObj | null, variables: any) => void;
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
- name?: string;
42
- eagerFragmentKeyMap?: any;
43
- retryCount?: number;
44
- variables?: Record<string, any> | null;
45
- cacheMap?: any;
46
- skip?: boolean;
47
- testMode?: boolean;
48
- openModalPopUp?: AnyModalPopUpFn | null;
49
- onCompleted?: OnCompletedGQLFn
50
- onError?: OnErrorGQLFn;
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<GraphQLQueryOptions, 'name' | 'retryCount' | 'cacheMap'>;
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
- onCompleted: OnCompletedGQLFn;
59
- onError: OnErrorGQLFn;
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
- checkMountedBeforeCallback?: boolean;
65
- }> & UseMutationParams;
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;