@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
@@ -1,7 +1,13 @@
1
1
  import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
2
2
  import type { InboundContactsSortEnum } from '@jsb188/mday/types/inboundContact.d.ts';
3
- import { loadFragment } from '../cache/index.ts';
4
- import { inboundContactQry, inboundContactsQry } from '../gql/queries/inboundContactQueries.ts';
3
+ import {
4
+ FRAGMENT_NAMES,
5
+ makeFragmentKey,
6
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
7
+ import {
8
+ inboundContactQry,
9
+ inboundContactsQry,
10
+ } from '../gql/queries/inboundContactQueries.ts';
5
11
  import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
6
12
 
7
13
  /**
@@ -15,32 +21,32 @@ const INBOUND_CONTACTS_LIMIT = 250;
15
21
  */
16
22
 
17
23
  export function useInboundContact(
18
- variables: {
19
- organizationId?: string | null;
20
- inboundContactId?: string | null;
21
- },
22
- params: UseQueryParams = {},
24
+ variables: {
25
+ organizationId?: string | null;
26
+ inboundContactId?: string | null;
27
+ },
28
+ params: UseQueryParams = {},
23
29
  ) {
24
- const cachedInboundContact = variables.inboundContactId
25
- ? loadFragment(`$inboundContactFragment:${variables.inboundContactId}`)
26
- : null;
27
- const shouldFetchInboundContact = !!variables.organizationId && !!variables.inboundContactId && !cachedInboundContact && !params.skip;
28
- const { data, ...rest } = useQuery(inboundContactQry, {
29
- ...params,
30
- variables,
31
- skip: !shouldFetchInboundContact,
32
- });
33
- const inboundContact = useReactiveInboundContactFragment(
34
- variables.inboundContactId || '',
35
- data?.inboundContact || cachedInboundContact,
36
- rest.updatedCount,
37
- );
30
+ const cachedInboundContact = useReactiveInboundContactFragment(
31
+ variables.inboundContactId || '',
32
+ null,
33
+ );
34
+ const shouldFetchInboundContact =
35
+ !!variables.organizationId &&
36
+ !!variables.inboundContactId &&
37
+ !cachedInboundContact &&
38
+ !params.skip;
39
+ const { data, ...rest } = useQuery(inboundContactQry, {
40
+ ...params,
41
+ variables,
42
+ skip: !shouldFetchInboundContact,
43
+ });
38
44
 
39
- return {
40
- inboundContact,
41
- initialLoading: shouldFetchInboundContact && !data,
42
- ...rest
43
- };
45
+ return {
46
+ inboundContact: cachedInboundContact || data?.inboundContact,
47
+ initialLoading: shouldFetchInboundContact && !data,
48
+ ...rest,
49
+ };
44
50
  }
45
51
 
46
52
  /**
@@ -48,41 +54,43 @@ export function useInboundContact(
48
54
  */
49
55
 
50
56
  export function useInboundContacts(
51
- variables: PaginationArgs & {
52
- organizationId?: string | null;
53
- filter?: unknown;
54
- sort?: InboundContactsSortEnum | null;
55
- },
56
- params: UseQueryParams = {},
57
+ variables: PaginationArgs & {
58
+ organizationId?: string | null;
59
+ filter?: unknown;
60
+ sort?: InboundContactsSortEnum | null;
61
+ },
62
+ params: UseQueryParams = {},
57
63
  ) {
58
- const { filter: _filter, ...queryVariables } = variables;
59
- const { data, ...rest } = useQuery(inboundContactsQry, {
60
- ...params,
61
- variables: {
62
- ...queryVariables,
63
- cursor: null,
64
- after: true,
65
- limit: INBOUND_CONTACTS_LIMIT
66
- },
67
- skip: !variables.organizationId || params.skip,
68
- });
64
+ const { filter: _filter, ...queryVariables } = variables;
65
+ const { data, ...rest } = useQuery(inboundContactsQry, {
66
+ ...params,
67
+ variables: {
68
+ ...queryVariables,
69
+ cursor: null,
70
+ after: true,
71
+ limit: INBOUND_CONTACTS_LIMIT,
72
+ },
73
+ skip: !variables.organizationId || params.skip,
74
+ });
69
75
 
70
- return {
71
- inboundContacts: data?.inboundContacts,
72
- ...rest
73
- };
76
+ return {
77
+ inboundContacts: data?.inboundContacts,
78
+ ...rest,
79
+ };
74
80
  }
75
81
 
76
82
  /**
77
83
  * Get reactive inbound contact fragment.
78
84
  */
79
85
 
80
- export function useReactiveInboundContactFragment(inboundContactId: string, currentData?: any, queryCount?: number) {
81
- return useReactiveFragment(
82
- currentData,
83
- [
84
- `$inboundContactFragment:${inboundContactId}`,
85
- ],
86
- queryCount,
87
- );
86
+ export function useReactiveInboundContactFragment(
87
+ inboundContactId: string,
88
+ currentData?: any,
89
+ queryCount?: number,
90
+ ) {
91
+ return useReactiveFragment(
92
+ currentData,
93
+ [makeFragmentKey(FRAGMENT_NAMES.inboundContact, inboundContactId)],
94
+ queryCount,
95
+ );
88
96
  }
@@ -1,59 +1,77 @@
1
1
  import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
2
  import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import {
4
+ FRAGMENT_NAMES,
5
+ makeFragmentKey,
6
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
3
7
  import { updateFragment } from '../cache/index.ts';
4
8
  import {
5
- createIntegrationAuthorizationUrlMtn,
6
- disconnectIntegrationMtn,
9
+ createIntegrationAuthorizationUrlMtn,
10
+ disconnectIntegrationMtn,
7
11
  } from '../gql/mutations/integrationMutations.ts';
8
12
  import { useMutation } from './index.ts';
9
13
 
10
14
  /**
11
15
  * Create integration OAuth authorization URL.
12
16
  */
13
- export function useCreateIntegrationAuthorizationUrl(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
14
- const [createIntegrationAuthorizationUrl, mtnValues, mtnHandlers] = useMutation(createIntegrationAuthorizationUrlMtn, {
15
- openModalPopUp,
16
- ...params,
17
- });
17
+ export function useCreateIntegrationAuthorizationUrl(
18
+ params: UseMutationParams = {},
19
+ openModalPopUp?: OpenModalPopUpFn,
20
+ ) {
21
+ const [createIntegrationAuthorizationUrl, mtnValues, mtnHandlers] =
22
+ useMutation(createIntegrationAuthorizationUrlMtn, {
23
+ openModalPopUp,
24
+ ...params,
25
+ });
18
26
 
19
- return {
20
- createIntegrationAuthorizationUrl,
21
- ...mtnValues,
22
- ...mtnHandlers,
23
- };
27
+ return {
28
+ createIntegrationAuthorizationUrl,
29
+ ...mtnValues,
30
+ ...mtnHandlers,
31
+ };
24
32
  }
25
33
 
26
34
  /**
27
35
  * Disconnect an integration.
28
36
  */
29
- export function useDisconnectIntegration(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
30
- const { onCompleted, ...otherParams } = params;
31
- const [disconnectIntegration, mtnValues, mtnHandlers, updateObservers] = useMutation(disconnectIntegrationMtn, {
32
- openModalPopUp,
33
- onCompleted: (data: any, error: any, variables: any) => {
34
- const disconnectedIntegrationId = data?.disconnectIntegration;
37
+ export function useDisconnectIntegration(
38
+ params: UseMutationParams = {},
39
+ openModalPopUp?: OpenModalPopUpFn,
40
+ ) {
41
+ const { onCompleted, ...otherParams } = params;
42
+ const [disconnectIntegration, mtnValues, mtnHandlers, updateObservers] =
43
+ useMutation(disconnectIntegrationMtn, {
44
+ openModalPopUp,
45
+ onCompleted: (data: any, error: any, variables: any) => {
46
+ const disconnectedIntegrationId = data?.disconnectIntegration;
35
47
 
36
- if (disconnectedIntegrationId) {
37
- const organizationFragmentKey = `$organizationFragment:${variables.organizationId}`;
48
+ if (disconnectedIntegrationId) {
49
+ const organizationFragmentKey = makeFragmentKey(
50
+ FRAGMENT_NAMES.organization,
51
+ variables.organizationId,
52
+ );
38
53
 
39
- updateFragment(
40
- `$integrationConnectionFragment:${disconnectedIntegrationId}`,
41
- { status: 'DISCONNECTED' },
42
- null,
43
- false,
44
- updateObservers,
45
- [organizationFragmentKey],
46
- );
47
- }
54
+ updateFragment(
55
+ makeFragmentKey(
56
+ FRAGMENT_NAMES.integrationConnection,
57
+ disconnectedIntegrationId,
58
+ ),
59
+ { status: 'DISCONNECTED' },
60
+ null,
61
+ false,
62
+ updateObservers,
63
+ [organizationFragmentKey],
64
+ );
65
+ }
48
66
 
49
- onCompleted?.(disconnectedIntegrationId, error, variables);
50
- },
51
- ...otherParams,
52
- });
67
+ onCompleted?.(disconnectedIntegrationId, error, variables);
68
+ },
69
+ ...otherParams,
70
+ });
53
71
 
54
- return {
55
- disconnectIntegration,
56
- ...mtnValues,
57
- ...mtnHandlers,
58
- };
72
+ return {
73
+ disconnectIntegration,
74
+ ...mtnValues,
75
+ ...mtnHandlers,
76
+ };
59
77
  }
@@ -1,15 +1,30 @@
1
+ import {
2
+ FRAGMENT_NAMES,
3
+ makeFragmentKey,
4
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
1
5
  import { useReactiveFragment } from '../client/index.ts';
2
6
 
3
7
  /**
4
8
  * Get reactive integration connection fragment.
5
9
  */
6
- export function useReactiveIntegrationConnection(integrationConnectionId?: string | null, currentData?: any, queryCount?: number) {
7
- return useReactiveFragment(
8
- currentData,
9
- integrationConnectionId ? [`$integrationConnectionFragment:${integrationConnectionId}`] : [],
10
- queryCount,
11
- undefined,
12
- undefined,
13
- true,
14
- );
10
+ export function useReactiveIntegrationConnection(
11
+ integrationConnectionId?: string | null,
12
+ currentData?: any,
13
+ queryCount?: number,
14
+ ) {
15
+ return useReactiveFragment(
16
+ currentData,
17
+ integrationConnectionId
18
+ ? [
19
+ makeFragmentKey(
20
+ FRAGMENT_NAMES.integrationConnection,
21
+ integrationConnectionId,
22
+ ),
23
+ ]
24
+ : [],
25
+ queryCount,
26
+ undefined,
27
+ undefined,
28
+ true,
29
+ );
15
30
  }
@@ -1,9 +1,16 @@
1
1
  import { checkACLPermission } from '@jsb188/mday/utils/organization.ts';
2
2
  import type { UseMutationParams } from '@jsb188/graphql/types.d';
3
3
  import { OpenModalPopUpFn } from '@jsb188/react/states';
4
+ import {
5
+ FRAGMENT_NAMES,
6
+ makeFragmentKey,
7
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
4
8
  import { useMemo } from 'react';
5
9
  import { updateFragment } from '../cache/index.ts';
6
- import { deleteLogEntryMtn, editLogEntryMtn } from '../gql/mutations/logMutations.ts';
10
+ import {
11
+ deleteLogEntryMtn,
12
+ editLogEntryMtn,
13
+ } from '../gql/mutations/logMutations.ts';
7
14
  import { useMutation } from './index.ts';
8
15
  import { useReactiveLogFragment } from './use-log-qry.ts';
9
16
  import { useOrgRelFromMyOrganizations } from './use-organization-qry.ts';
@@ -14,45 +21,46 @@ import { useOrgRelFromMyOrganizations } from './use-organization-qry.ts';
14
21
  */
15
22
 
16
23
  export function useEditLogEntry(
17
- viewerAccountId: string,
18
- logEntryId: string,
19
- organizationId: string,
20
- params: UseMutationParams = {},
21
- openModalPopUp?: OpenModalPopUpFn
24
+ viewerAccountId: string,
25
+ logEntryId: string,
26
+ organizationId: string,
27
+ params: UseMutationParams = {},
28
+ openModalPopUp?: OpenModalPopUpFn,
22
29
  ) {
30
+ const { organizationRelationship } =
31
+ useOrgRelFromMyOrganizations(organizationId);
32
+ const notReady = !organizationRelationship;
23
33
 
24
- const { organizationRelationship } = useOrgRelFromMyOrganizations(organizationId);
25
- const notReady = !organizationRelationship;
34
+ const [editLogEntry, mtnValues, mtnHandlers] = useMutation(editLogEntryMtn, {
35
+ // checkMountedBeforeCallback: true,
36
+ openModalPopUp,
37
+ ...params,
38
+ });
26
39
 
27
- const [editLogEntry, mtnValues, mtnHandlers] = useMutation(
28
- editLogEntryMtn,
29
- {
30
- // checkMountedBeforeCallback: true,
31
- openModalPopUp,
32
- ...params,
33
- },
34
- );
40
+ const logEntry = useReactiveLogFragment(
41
+ logEntryId,
42
+ null,
43
+ mtnValues.mutationCount,
44
+ );
35
45
 
36
- const logEntry = useReactiveLogFragment(logEntryId, null, mtnValues.mutationCount);
37
- // const logEntry = useReactiveFragment(
38
- // null,
39
- // [`$logEntryFragment:${logEntryId}`, [`$logArableFragment:${logEntryId}`, 'details']],
40
- // mtnValues.mutationCount,
41
- // );
46
+ const isMyDocument =
47
+ !!viewerAccountId && logEntry?.accountId === viewerAccountId;
48
+ const allowEdit = useMemo(() => {
49
+ return checkACLPermission(
50
+ organizationRelationship,
51
+ 'logs',
52
+ isMyDocument ? 'WRITE' : 'MANAGE',
53
+ );
54
+ }, [organizationRelationship?.acl, organizationRelationship?.role]);
42
55
 
43
- const isMyDocument = !!viewerAccountId && logEntry?.accountId === viewerAccountId;
44
- const allowEdit = useMemo(() => {
45
- return checkACLPermission(organizationRelationship, 'logs', isMyDocument ? 'WRITE' : 'MANAGE');
46
- }, [organizationRelationship?.acl, organizationRelationship?.role]);
47
-
48
- return {
49
- logEntry,
50
- editLogEntry,
51
- notReady,
52
- allowEdit,
53
- ...mtnValues,
54
- ...mtnHandlers,
55
- };
56
+ return {
57
+ logEntry,
58
+ editLogEntry,
59
+ notReady,
60
+ allowEdit,
61
+ ...mtnValues,
62
+ ...mtnHandlers,
63
+ };
56
64
  }
57
65
 
58
66
  /**
@@ -60,26 +68,34 @@ export function useEditLogEntry(
60
68
  * NOTE: Don't check ACL and allow server to handle it.
61
69
  */
62
70
 
63
- export function useDeleteLogEntry(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
64
-
65
- const { onCompleted, ...rest } = params;
66
- const [deleteLogEntry, mtnValues, mtnHandlers, updateObservers] = useMutation(
67
- deleteLogEntryMtn,
68
- {
69
- openModalPopUp,
70
- onCompleted: (data, dataMtnValues, variables) => {
71
- if (data?.deleteLogEntry) {
72
- updateFragment(`$logEntryFragment:${variables.logEntryId}`, { __deleted: true }, null, false, updateObservers);
73
- }
74
- onCompleted?.(data, dataMtnValues, variables);
75
- },
76
- ...rest,
77
- },
78
- );
71
+ export function useDeleteLogEntry(
72
+ params: UseMutationParams = {},
73
+ openModalPopUp?: OpenModalPopUpFn,
74
+ ) {
75
+ const { onCompleted, ...rest } = params;
76
+ const [deleteLogEntry, mtnValues, mtnHandlers, updateObservers] = useMutation(
77
+ deleteLogEntryMtn,
78
+ {
79
+ openModalPopUp,
80
+ onCompleted: (data, dataMtnValues, variables) => {
81
+ if (data?.deleteLogEntry) {
82
+ updateFragment(
83
+ makeFragmentKey(FRAGMENT_NAMES.logEntry, variables.logEntryId),
84
+ { __deleted: true },
85
+ null,
86
+ false,
87
+ updateObservers,
88
+ );
89
+ }
90
+ onCompleted?.(data, dataMtnValues, variables);
91
+ },
92
+ ...rest,
93
+ },
94
+ );
79
95
 
80
- return {
81
- deleteLogEntry,
82
- ...mtnValues,
83
- ...mtnHandlers,
84
- };
96
+ return {
97
+ deleteLogEntry,
98
+ ...mtnValues,
99
+ ...mtnHandlers,
100
+ };
85
101
  }
@@ -1,6 +1,17 @@
1
- import type { FilterLogEntriesArgs } from '@jsb188/mday/types/log.d.ts';
1
+ import type {
2
+ FilterLogEntriesArgs,
3
+ LogSortEnum,
4
+ } from '@jsb188/mday/types/log.d.ts';
5
+ import {
6
+ FRAGMENT_NAMES,
7
+ makeFragmentKey,
8
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
2
9
  import { useQuery, useReactiveFragment } from '../client/index.ts';
3
- import { logEntriesForReportQry, logEntriesQry, logEntryQry } from '../gql/queries/logQueries.ts';
10
+ import {
11
+ logEntriesForFieldDocQry,
12
+ logEntriesQry,
13
+ logEntryQry,
14
+ } from '../gql/queries/logQueries.ts';
4
15
  import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
5
16
 
6
17
  /**
@@ -17,24 +28,31 @@ const LOG_ENTRIES_LIMIT = 250;
17
28
  */
18
29
 
19
30
  export function useLogEntry(
20
- variables: {
21
- organizationId?: string | null;
22
- logEntryId?: string | null;
23
- },
24
- params: UseQueryParams = {}
31
+ variables: {
32
+ organizationId?: string | null;
33
+ logEntryId?: string | null;
34
+ },
35
+ params: UseQueryParams = {},
25
36
  ) {
26
- const { logEntryId, organizationId } = variables;
27
- const reactiveLogEntry = useReactiveLogFragment(logEntryId || '');
28
- const { data, ...rest } = useQuery(logEntryQry, {
29
- ...params,
30
- variables,
31
- skip: !!reactiveLogEntry || !organizationId || !logEntryId || params.skip,
32
- });
37
+ const { logEntryId, organizationId } = variables;
38
+ const { data, ...rest } = useQuery(logEntryQry, {
39
+ ...params,
40
+ // A log can be changed outside the websocket mutation path, such as by a
41
+ // database repair. Revalidate it whenever the detail modal is opened.
42
+ persistTime: params.persistTime ?? 0,
43
+ variables,
44
+ skip: !organizationId || !logEntryId || params.skip,
45
+ });
46
+ const reactiveLogEntry = useReactiveLogFragment(
47
+ logEntryId || '',
48
+ data?.logEntry,
49
+ rest.updatedCount,
50
+ );
33
51
 
34
- return {
35
- logEntry: reactiveLogEntry || data?.logEntry,
36
- ...rest,
37
- };
52
+ return {
53
+ logEntry: reactiveLogEntry || data?.logEntry,
54
+ ...rest,
55
+ };
38
56
  }
39
57
 
40
58
  /**
@@ -42,70 +60,76 @@ export function useLogEntry(
42
60
  */
43
61
 
44
62
  export function useLogEntries(
45
- variables: PaginationArgs & {
46
- organizationId?: string | null;
47
- accountId?: string;
48
- filter: FilterLogEntriesArgs;
49
- },
50
- params: UseQueryParams = {}
63
+ variables: PaginationArgs & {
64
+ organizationId?: string | null;
65
+ accountId?: string;
66
+ filter: FilterLogEntriesArgs;
67
+ sort?: LogSortEnum;
68
+ },
69
+ params: UseQueryParams = {},
51
70
  ) {
52
- const { data, ...rest } = useQuery(logEntriesQry, {
53
- ...params,
54
- variables: {
55
- ...variables,
56
- cursor: null,
57
- after: true,
58
- limit: LOG_ENTRIES_LIMIT
59
- },
60
- // If this query is used for virtualized list pagination, set {params.skip=true}
61
- skip: !variables.organizationId || params.skip,
62
- });
71
+ const { data, ...rest } = useQuery(logEntriesQry, {
72
+ ...params,
73
+ variables: {
74
+ ...variables,
75
+ cursor: null,
76
+ after: true,
77
+ limit: variables.limit ?? LOG_ENTRIES_LIMIT,
78
+ },
79
+ // If this query is used for virtualized list pagination, set {params.skip=true}
80
+ skip: !variables.organizationId || params.skip,
81
+ });
63
82
 
64
- return {
65
- logEntries: data?.logEntries,
66
- ...rest
67
- };
83
+ return {
84
+ logEntries: data?.logEntries,
85
+ ...rest,
86
+ };
68
87
  }
69
88
 
70
89
  /**
71
- * Fetch all log entries for one report source.
90
+ * Fetch all log entries for one fieldDoc source.
72
91
  */
73
92
 
74
- export function useLogEntriesForReport(
75
- variables: {
76
- organizationId?: string | null;
77
- reportSourceId?: string | null;
78
- reportSubmissionId: string | null;
79
- },
80
- params: UseQueryParams = {}
93
+ export function useLogEntriesForFieldDoc(
94
+ variables: {
95
+ organizationId?: string | null;
96
+ fieldDocSourceId?: string | null;
97
+ fieldDocSubmissionId: string | null;
98
+ },
99
+ params: UseQueryParams = {},
81
100
  ) {
82
- const { organizationId, reportSourceId, reportSubmissionId } = variables;
83
- const { data, ...rest } = useQuery(logEntriesForReportQry, {
84
- ...params,
85
- variables,
86
- skip: !organizationId || !reportSourceId || !reportSubmissionId || params.skip,
87
- });
101
+ const { organizationId, fieldDocSourceId, fieldDocSubmissionId } = variables;
102
+ const { data, ...rest } = useQuery(logEntriesForFieldDocQry, {
103
+ ...params,
104
+ variables,
105
+ skip:
106
+ !organizationId ||
107
+ !fieldDocSourceId ||
108
+ !fieldDocSubmissionId ||
109
+ params.skip,
110
+ });
88
111
 
89
- return {
90
- logEntriesForReport: data?.logEntriesForReport,
91
- ...rest,
92
- };
112
+ return {
113
+ logEntriesForFieldDoc: data?.logEntriesForFieldDoc,
114
+ ...rest,
115
+ };
93
116
  }
94
117
 
95
118
  /**
96
119
  * Get reactive log fragment
97
120
  */
98
121
 
99
- export function useReactiveLogFragment(logEntryId: string, currentData?: any, queryCount?: number) {
100
- return useReactiveFragment(
101
- currentData,
102
- [
103
- `$logEntryFragment:${logEntryId}`,
104
- [`$logArableFragment:${logEntryId}`, 'details'],
105
- [`$logFarmersMarketFragment:${logEntryId}`, 'details'],
106
- [`$logGrowerNetworkFragment:${logEntryId}`, 'details'],
107
- [`$logLivestockFragment:${logEntryId}`, 'details'],
108
- ],
109
- queryCount,
110
- );
122
+ export function useReactiveLogFragment(
123
+ logEntryId: string,
124
+ currentData?: any,
125
+ queryCount?: number,
126
+ ) {
127
+ return useReactiveFragment(
128
+ currentData,
129
+ [
130
+ makeFragmentKey(FRAGMENT_NAMES.logEntry, logEntryId),
131
+ [makeFragmentKey(FRAGMENT_NAMES.logEntryDetails, logEntryId), 'details'],
132
+ ],
133
+ queryCount,
134
+ );
111
135
  }