@jsb188/graphql 1.1.8 → 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 (122) hide show
  1. package/cache/config.ts +66 -42
  2. package/cache/index.test.ts +881 -0
  3. package/cache/index.ts +1815 -979
  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 +4 -2
  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 +973 -143
  16. package/client/sse-ticket.test.ts +26 -0
  17. package/deno.lock +170 -0
  18. package/deno.test.json +10 -0
  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 +1 -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 +17 -0
  28. package/gql/fragments/billingFragments.ts +0 -11
  29. package/gql/fragments/campaignFragments.ts +277 -0
  30. package/gql/fragments/dataTableFragments.ts +102 -0
  31. package/gql/fragments/emailFragments.ts +36 -0
  32. package/gql/fragments/fieldDocFragments.ts +82 -0
  33. package/gql/fragments/inboundContactFragments.ts +15 -0
  34. package/gql/fragments/integrationFragments.ts +22 -0
  35. package/gql/fragments/logFragments.ts +33 -64
  36. package/gql/fragments/organizationFragments.ts +94 -21
  37. package/gql/fragments/scheduleFragments.ts +155 -0
  38. package/gql/fragments/sheetFragments.ts +675 -0
  39. package/gql/fragments/storageFragments.ts +21 -1
  40. package/gql/fragments/workflowFragments.ts +67 -0
  41. package/gql/mutations/accountMutations.ts +24 -4
  42. package/gql/mutations/agentDocMutations.ts +177 -0
  43. package/gql/mutations/agentMemoryMutations.ts +36 -0
  44. package/gql/mutations/aiChatMutations.ts +43 -3
  45. package/gql/mutations/authMutations.ts +160 -19
  46. package/gql/mutations/campaignMutations.ts +215 -0
  47. package/gql/mutations/dataTableMutations.ts +106 -0
  48. package/gql/mutations/fieldDocMutations.ts +24 -0
  49. package/gql/mutations/inboundContactMutations.ts +24 -0
  50. package/gql/mutations/index.ts +17 -8
  51. package/gql/mutations/integrationMutations.ts +25 -0
  52. package/gql/mutations/logMutations.ts +10 -19
  53. package/gql/mutations/organizationMutations.ts +160 -2
  54. package/gql/mutations/scheduleMutations.ts +423 -0
  55. package/gql/mutations/sheetMutations.ts +385 -0
  56. package/gql/mutations/storageMutations.ts +21 -2
  57. package/gql/mutations/workflowMutations.ts +42 -0
  58. package/gql/queries/agentDocQueries.ts +120 -0
  59. package/gql/queries/agentMemoryQueries.ts +22 -0
  60. package/gql/queries/aiChatQueries.ts +18 -2
  61. package/gql/queries/authQueries.ts +41 -0
  62. package/gql/queries/billingQueries.ts +24 -1
  63. package/gql/queries/campaignQueries.ts +127 -0
  64. package/gql/queries/dataTableQueries.ts +134 -0
  65. package/gql/queries/emailQueries.ts +96 -0
  66. package/gql/queries/fieldDocQueries.ts +158 -0
  67. package/gql/queries/inboundContactQueries.ts +40 -0
  68. package/gql/queries/index.ts +17 -6
  69. package/gql/queries/logQueries.ts +42 -32
  70. package/gql/queries/organizationQueries.ts +113 -8
  71. package/gql/queries/scheduleQueries.ts +315 -0
  72. package/gql/queries/sheetQueries.ts +383 -0
  73. package/gql/queries/storageQueries.ts +38 -0
  74. package/gql/queries/workflowQueries.ts +99 -0
  75. package/hooks/index.ts +2104 -860
  76. package/hooks/use-account-mtn.ts +91 -48
  77. package/hooks/use-agentDoc-mtn.ts +285 -0
  78. package/hooks/use-agentDoc-qry.ts +208 -0
  79. package/hooks/use-agentMemory-mtn.ts +73 -0
  80. package/hooks/use-agentMemory-qry.ts +44 -0
  81. package/hooks/use-aiChat-mtn.ts +248 -97
  82. package/hooks/use-aiChat-qry.ts +501 -191
  83. package/hooks/use-app-qry.ts +14 -11
  84. package/hooks/use-auth-mtn.ts +410 -256
  85. package/hooks/use-auth-qry.ts +51 -0
  86. package/hooks/use-campaign-mtn.ts +377 -0
  87. package/hooks/use-campaign-qry.ts +257 -0
  88. package/hooks/use-dataTable-mtn.ts +170 -0
  89. package/hooks/use-dataTable-qry.ts +996 -0
  90. package/hooks/use-email-qry.ts +227 -0
  91. package/hooks/use-fieldDoc-mtn.ts +50 -0
  92. package/hooks/use-fieldDoc-qry.ts +180 -0
  93. package/hooks/use-inboundContact-mtn.ts +34 -0
  94. package/hooks/use-inboundContact-qry.ts +96 -0
  95. package/hooks/use-integration-mtn.ts +77 -0
  96. package/hooks/use-integration-qry.ts +30 -0
  97. package/hooks/use-log-mtn.ts +77 -61
  98. package/hooks/use-log-qry.ts +99 -72
  99. package/hooks/use-organization-mtn.ts +409 -80
  100. package/hooks/use-organization-qry.ts +211 -92
  101. package/hooks/use-schedule-mtn.ts +416 -0
  102. package/hooks/use-schedule-qry.ts +157 -0
  103. package/hooks/use-sheet-mtn.ts +367 -0
  104. package/hooks/use-sheet-qry.ts +440 -0
  105. package/hooks/use-storage-mtn.ts +83 -42
  106. package/hooks/use-storage-qry.ts +104 -13
  107. package/hooks/use-workflow-mtn.ts +55 -0
  108. package/hooks/use-workflow-qry.ts +230 -0
  109. package/loaders/campaign.ts +137 -0
  110. package/package.json +94 -52
  111. package/sse.ts +158 -105
  112. package/tsconfig.json +13 -0
  113. package/types.d.ts +60 -29
  114. package/utils.ts +77 -50
  115. package/gql/fragments/actionFragments.ts +0 -16
  116. package/gql/fragments/productFragments.ts +0 -63
  117. package/gql/fragments/reportFragments.ts +0 -48
  118. package/gql/mutations/billingMutations.ts +0 -34
  119. package/gql/queries/productQueries.ts +0 -70
  120. package/gql/queries/reportQueries.ts +0 -66
  121. package/hooks/use-product-qry.ts +0 -109
  122. package/hooks/use-report-qry.ts +0 -69
@@ -0,0 +1,52 @@
1
+ const FRAGMENT_REALTIME_SEQUENCES = new Map<string, string>();
2
+
3
+ /*
4
+ * Compare two unsigned decimal sequence strings without narrowing them to
5
+ * JavaScript's unsafe integer range.
6
+ */
7
+ function compareFragmentRealtimeSequences(left: string, right: string) {
8
+ const normalizedLeft = left.replace(/^0+(?=\d)/, '');
9
+ const normalizedRight = right.replace(/^0+(?=\d)/, '');
10
+
11
+ if (normalizedLeft.length !== normalizedRight.length) {
12
+ return normalizedLeft.length > normalizedRight.length ? 1 : -1;
13
+ }
14
+
15
+ return normalizedLeft === normalizedRight
16
+ ? 0
17
+ : normalizedLeft > normalizedRight
18
+ ? 1
19
+ : -1;
20
+ }
21
+
22
+ /*
23
+ * Accept an unsequenced fragment or a sequenced fragment that is not older
24
+ * than the latest event already applied to the same cache key.
25
+ */
26
+ export function shouldApplyFragmentRealtimeSequence(
27
+ fragmentKey: string,
28
+ sequence?: string,
29
+ ) {
30
+ if (!sequence || !/^\d+$/.test(sequence)) {
31
+ return true;
32
+ }
33
+
34
+ const currentSequence = FRAGMENT_REALTIME_SEQUENCES.get(fragmentKey);
35
+ if (
36
+ currentSequence &&
37
+ compareFragmentRealtimeSequences(sequence, currentSequence) < 0
38
+ ) {
39
+ return false;
40
+ }
41
+
42
+ FRAGMENT_REALTIME_SEQUENCES.set(fragmentKey, sequence);
43
+ return true;
44
+ }
45
+
46
+ /*
47
+ * Clear fragment sequence fences when authorization-bound cache state is
48
+ * discarded.
49
+ */
50
+ export function clearFragmentRealtimeSequences() {
51
+ FRAGMENT_REALTIME_SEQUENCES.clear();
52
+ }
package/client/index.ts CHANGED
@@ -1,2 +1,4 @@
1
- export * from '../hooks/index';
2
- export * from './request';
1
+ export * from '../hooks/index.ts';
2
+ export * from './fragment-realtime-sequence.ts';
3
+ export * from './open-sheet.ts';
4
+ export * from './request.ts';
@@ -0,0 +1,137 @@
1
+ import type {
2
+ SheetBootstrapGQL,
3
+ SheetGridViewportObj,
4
+ SheetTabBootstrapGQL,
5
+ } from '@jsb188/mday/types/sheet.d.ts';
6
+ import { openSheetQry, openSheetTabQry } from '../gql/queries/sheetQueries.ts';
7
+ import { graphqlRequestNoStore } from './request.ts';
8
+
9
+ export type FetchOpenSheetOnceParams = {
10
+ selectedTabId?: string | null;
11
+ sinceSeq?: string | null;
12
+ baseSnapshotSeq?: string | null;
13
+ baseSnapshotEncodingVersion?: number | null;
14
+ baseSnapshotChecksum?: string | null;
15
+ viewport?: SheetGridViewportObj | null;
16
+ authToken?: string | null;
17
+ signal?: AbortSignal | null;
18
+ };
19
+
20
+ export type FetchOpenSheetTabOnceParams = Omit<
21
+ FetchOpenSheetOnceParams,
22
+ 'selectedTabId'
23
+ >;
24
+
25
+ /*
26
+ * Return canonical variables shared by mounted and imperative openSheet calls.
27
+ */
28
+ export function getOpenSheetQueryVariables(
29
+ sheetId: string | null | undefined,
30
+ selectedTabId?: string | null,
31
+ sinceSeq?: string | null,
32
+ baseSnapshotSeq?: string | null,
33
+ baseSnapshotEncodingVersion?: number | null,
34
+ baseSnapshotChecksum?: string | null,
35
+ viewport?: SheetGridViewportObj | null,
36
+ ) {
37
+ return {
38
+ sheetId,
39
+ selectedTabId: selectedTabId || null,
40
+ sinceSeq: sinceSeq ?? null,
41
+ baseSnapshotSeq: baseSnapshotSeq ?? null,
42
+ baseSnapshotEncodingVersion: baseSnapshotEncodingVersion ?? null,
43
+ baseSnapshotChecksum: baseSnapshotChecksum || null,
44
+ viewport: viewport || null,
45
+ };
46
+ }
47
+
48
+ /*
49
+ * Return canonical variables for one post-manifest tab-only negotiation.
50
+ */
51
+ export function getOpenSheetTabQueryVariables(
52
+ sheetId: string | null | undefined,
53
+ sheetTabId: string | null | undefined,
54
+ sinceSeq?: string | null,
55
+ baseSnapshotSeq?: string | null,
56
+ baseSnapshotEncodingVersion?: number | null,
57
+ baseSnapshotChecksum?: string | null,
58
+ viewport?: SheetGridViewportObj | null,
59
+ ) {
60
+ return {
61
+ sheetId,
62
+ sheetTabId,
63
+ sinceSeq: sinceSeq ?? null,
64
+ baseSnapshotSeq: baseSnapshotSeq ?? null,
65
+ baseSnapshotEncodingVersion: baseSnapshotEncodingVersion ?? null,
66
+ baseSnapshotChecksum: baseSnapshotChecksum || null,
67
+ viewport: viewport || null,
68
+ };
69
+ }
70
+
71
+ /*
72
+ * Imperatively fetch one openSheet response exactly once without reading,
73
+ * writing, or joining the normalized GraphQL cache. Each invocation owns its
74
+ * network request and carries its authorization token only in request headers.
75
+ */
76
+ export async function fetchOpenSheetOnce(
77
+ sheetId: string,
78
+ params: FetchOpenSheetOnceParams = {},
79
+ ): Promise<SheetBootstrapGQL | null> {
80
+ const result = await graphqlRequestNoStore(
81
+ openSheetQry,
82
+ getOpenSheetQueryVariables(
83
+ sheetId,
84
+ params.selectedTabId,
85
+ params.sinceSeq,
86
+ params.baseSnapshotSeq,
87
+ params.baseSnapshotEncodingVersion,
88
+ params.baseSnapshotChecksum,
89
+ params.viewport,
90
+ ),
91
+ { authToken: params.authToken },
92
+ params.signal,
93
+ );
94
+
95
+ if (result?.aborted) {
96
+ throw new DOMException('openSheet request was aborted.', 'AbortError');
97
+ }
98
+ if (result?.error) {
99
+ throw result.error;
100
+ }
101
+
102
+ return result?.openSheet || null;
103
+ }
104
+
105
+ /*
106
+ * Imperatively fetch one lean post-manifest tab bootstrap without touching the
107
+ * normalized GraphQL cache.
108
+ */
109
+ export async function fetchOpenSheetTabOnce(
110
+ sheetId: string,
111
+ sheetTabId: string,
112
+ params: FetchOpenSheetTabOnceParams = {},
113
+ ): Promise<SheetTabBootstrapGQL | null> {
114
+ const result = await graphqlRequestNoStore(
115
+ openSheetTabQry,
116
+ getOpenSheetTabQueryVariables(
117
+ sheetId,
118
+ sheetTabId,
119
+ params.sinceSeq,
120
+ params.baseSnapshotSeq,
121
+ params.baseSnapshotEncodingVersion,
122
+ params.baseSnapshotChecksum,
123
+ params.viewport,
124
+ ),
125
+ { authToken: params.authToken },
126
+ params.signal,
127
+ );
128
+
129
+ if (result?.aborted) {
130
+ throw new DOMException('openSheetTab request was aborted.', 'AbortError');
131
+ }
132
+ if (result?.error) {
133
+ throw result.error;
134
+ }
135
+
136
+ return result?.openSheetTab || null;
137
+ }