@stack-spot/portal-network 0.184.0 → 0.185.0-beta.1
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/CHANGELOG.md +2444 -2412
- package/dist/api/account.js +1 -1
- package/dist/api/agent-tools.js +1 -1
- package/dist/api/agent.js +1 -1
- package/dist/api/ai.js +1 -1
- package/dist/api/apiManagement.js +1 -1
- package/dist/api/apiRuntime.js +1 -1
- package/dist/api/cloudAccount.js +1 -1
- package/dist/api/cloudPlatform.js +1 -1
- package/dist/api/cloudPlatformHorizon.js +1 -1
- package/dist/api/cloudRuntimes.js +1 -1
- package/dist/api/cloudServices.js +1 -1
- package/dist/api/codeShift.d.ts +63 -4
- package/dist/api/codeShift.d.ts.map +1 -1
- package/dist/api/codeShift.js +14 -1
- package/dist/api/codeShift.js.map +1 -1
- package/dist/api/content.js +1 -1
- package/dist/api/dataIntegration.js +1 -1
- package/dist/api/discover.js +1 -1
- package/dist/api/genAiInference.js +1 -1
- package/dist/api/insights.js +1 -1
- package/dist/api/notification.js +1 -1
- package/dist/api/secrets.js +1 -1
- package/dist/api/serviceCatalog.js +1 -1
- package/dist/api/workspace-ai.js +1 -1
- package/dist/api/workspace.js +1 -1
- package/dist/api/workspaceManager.js +1 -1
- package/dist/api/workspaceSearchEngine.js +1 -1
- package/dist/client/ai.d.ts.map +1 -1
- package/dist/client/ai.js +84 -14
- package/dist/client/ai.js.map +1 -1
- package/dist/client/code-shift.d.ts +30 -0
- package/dist/client/code-shift.d.ts.map +1 -1
- package/dist/client/code-shift.js +37 -1
- package/dist/client/code-shift.js.map +1 -1
- package/dist/client/types.d.ts +26 -6
- package/dist/client/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/readme.md +1 -1
- package/scripts/generate-apis.ts +134 -134
- package/src/api/account.ts +8368 -8367
- package/src/api/agent-tools.ts +2172 -2169
- package/src/api/agent.ts +1085 -1083
- package/src/api/ai.ts +3388 -3388
- package/src/api/apiManagement.ts +570 -570
- package/src/api/apiRuntime.ts +2103 -2103
- package/src/api/cloudAccount.ts +1239 -1239
- package/src/api/cloudPlatform.ts +927 -927
- package/src/api/cloudPlatformHorizon.ts +2655 -2655
- package/src/api/cloudRuntimes.ts +2043 -2043
- package/src/api/cloudServices.ts +1445 -1445
- package/src/api/codeShift.ts +3567 -3481
- package/src/api/content.ts +9785 -9785
- package/src/api/dataIntegration.ts +1657 -1657
- package/src/api/discover.ts +435 -435
- package/src/api/eventBus.ts +171 -171
- package/src/api/genAiInference.ts +603 -603
- package/src/api/insights.ts +310 -310
- package/src/api/notification.ts +336 -334
- package/src/api/secrets.ts +342 -342
- package/src/api/serviceCatalog.ts +2908 -2908
- package/src/api/workflows.ts +1669 -1669
- package/src/api/workspace-ai.ts +677 -677
- package/src/api/workspace.ts +5889 -5889
- package/src/api/workspaceManager.ts +2951 -2951
- package/src/api/workspaceSearchEngine.ts +153 -153
- package/src/api-addresses.ts +120 -120
- package/src/apis-itau.json +225 -225
- package/src/apis.json +225 -225
- package/src/client/account.ts +902 -902
- package/src/client/agent-tools.ts +210 -210
- package/src/client/agent.ts +81 -81
- package/src/client/ai.ts +469 -395
- package/src/client/api-management.ts +40 -40
- package/src/client/cloud-account.ts +70 -70
- package/src/client/cloud-platform-horizon.ts +113 -113
- package/src/client/cloud-platform.ts +163 -163
- package/src/client/cloud-runtimes.ts +129 -129
- package/src/client/cloud-services.ts +94 -94
- package/src/client/code-shift.ts +371 -349
- package/src/client/content.ts +538 -538
- package/src/client/data-integration.ts +191 -191
- package/src/client/discover.ts +89 -89
- package/src/client/event-bus.ts +84 -84
- package/src/client/gen-ai-inference.ts +65 -65
- package/src/client/insights.ts +28 -28
- package/src/client/notification.ts +32 -32
- package/src/client/runtime-manager.ts +76 -76
- package/src/client/secrets.ts +60 -60
- package/src/client/types.ts +398 -377
- package/src/client/workflow.ts +83 -83
- package/src/client/workspace-ai.ts +191 -191
- package/src/client/workspace-manager.ts +564 -564
- package/src/client/workspace-search.ts +39 -39
- package/src/client/workspace.ts +480 -480
- package/src/error/DefaultAPIError.ts +151 -151
- package/src/error/FileUploadError.ts +18 -18
- package/src/error/IgnoredErrorCodes.ts +3 -3
- package/src/error/StackspotAPIError.ts +101 -101
- package/src/error/StreamCanceledError.ts +10 -10
- package/src/error/StreamError.ts +7 -7
- package/src/error/StreamJsonError.ts +10 -10
- package/src/error/dictionary/account.ts +58 -58
- package/src/error/dictionary/action-details.ts +20 -20
- package/src/error/dictionary/action.ts +211 -211
- package/src/error/dictionary/agent-tools.ts +75 -75
- package/src/error/dictionary/ai-inference.ts +28 -28
- package/src/error/dictionary/base.ts +22 -22
- package/src/error/dictionary/cloud-platform.ts +82 -82
- package/src/error/dictionary/cnt-fields.ts +14 -14
- package/src/error/dictionary/cnt.ts +103 -103
- package/src/error/dictionary/code-shift.ts +12 -12
- package/src/error/dictionary/rte.ts +24 -24
- package/src/error/dictionary/rtm.ts +10 -10
- package/src/error/dictionary/secrets.ts +14 -14
- package/src/error/dictionary/workspace-ai.ts +10 -10
- package/src/error/dictionary/workspace-details.ts +15 -15
- package/src/error/dictionary/workspace-fields.ts +10 -10
- package/src/error/dictionary/workspace.ts +209 -209
- package/src/error/types.ts +21 -21
- package/src/index.ts +43 -43
- package/src/network/AutoInfiniteQuery.ts +115 -115
- package/src/network/AutoMutation.ts +27 -27
- package/src/network/AutoOperation.ts +73 -73
- package/src/network/AutoQuery.ts +75 -75
- package/src/network/ManualInfiniteQuery.ts +95 -95
- package/src/network/ManualMutation.ts +40 -40
- package/src/network/ManualOperation.ts +52 -52
- package/src/network/ManualQuery.ts +82 -82
- package/src/network/NetworkClient.ts +167 -167
- package/src/network/ReactQueryNetworkClient.ts +312 -312
- package/src/network/react-query-client.ts +14 -14
- package/src/network/types.ts +294 -294
- package/src/types.ts +1 -1
- package/src/utils/StreamedArray.tsx +146 -146
- package/src/utils/StreamedJson.tsx +166 -166
- package/src/utils/remove-authorization-param.ts +6 -6
- package/src/utils/string.ts +19 -19
- package/src/utils/use-extended-list.ts +80 -80
- package/src/utils/use-streamed-array.ts +17 -17
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +10 -10
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
import { InfiniteData, QueryFunctionContext, QueryKey, UseInfiniteQueryResult, useInfiniteQuery, useSuspenseInfiniteQuery } from '@tanstack/react-query'
|
|
3
|
-
import { get, set } from 'lodash'
|
|
4
|
-
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
5
|
-
import { ManualQuery } from './ManualQuery'
|
|
6
|
-
import { queryClient } from './react-query-client'
|
|
7
|
-
import { FullOperationConfig, InfiniteQueryConfig, InfiniteQueryObject, UseInfiniteQueryObjectOptions } from './types'
|
|
8
|
-
|
|
9
|
-
export class ManualInfiniteQuery<
|
|
10
|
-
Variables extends Record<string, any>,
|
|
11
|
-
Result,
|
|
12
|
-
PageParamName extends keyof Variables,
|
|
13
|
-
Accumulator extends keyof Result | ''
|
|
14
|
-
> extends ManualQuery<Variables, Result> implements InfiniteQueryObject<Variables, Result, Accumulator> {
|
|
15
|
-
constructor(
|
|
16
|
-
config: InfiniteQueryConfig<Variables, Result, PageParamName, Accumulator>
|
|
17
|
-
& { apiName: string, transformError: (error: any) => StackspotAPIError },
|
|
18
|
-
) {
|
|
19
|
-
super(config as FullOperationConfig<any, any>)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private getConfig() {
|
|
23
|
-
return this.config as unknown as InfiniteQueryConfig<Variables, Result, PageParamName, Accumulator>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private createInfiniteQueryFn(
|
|
27
|
-
variables: Variables,
|
|
28
|
-
): (context: QueryFunctionContext<QueryKey, Variables[PageParamName]>) => Promise<Result> {
|
|
29
|
-
return ({ pageParam, signal }) => {
|
|
30
|
-
const paginatedVariables = {
|
|
31
|
-
...variables,
|
|
32
|
-
}
|
|
33
|
-
set(paginatedVariables, this.getConfig().pageParamName, pageParam ?? get(variables, this.getConfig().pageParamName))
|
|
34
|
-
return this.makeRequest(paginatedVariables, signal)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private getListFromData(data: InfiniteData<Result> | undefined) {
|
|
39
|
-
return data?.pages.map(
|
|
40
|
-
page => this.getConfig().accumulator ? page[this.getConfig().accumulator as keyof Result] : page,
|
|
41
|
-
).flat() as Accumulator extends keyof Result ? Result[Accumulator] : Result
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private useInfiniteQueryResult(suspense: boolean, variables = {} as Variables, options?: UseInfiniteQueryObjectOptions<Result>) {
|
|
45
|
-
variables = { ...variables, ...this.getConfig().defaultVariables }
|
|
46
|
-
const use = suspense ? useSuspenseInfiniteQuery : useInfiniteQuery
|
|
47
|
-
return use<any, any, any, any, any>({
|
|
48
|
-
...options,
|
|
49
|
-
queryKey: ['infinite', ...this.getKey(variables)],
|
|
50
|
-
queryFn: this.createInfiniteQueryFn(variables),
|
|
51
|
-
initialPageParam: this.getConfig().initialPageParam,
|
|
52
|
-
getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) =>
|
|
53
|
-
this.getConfig().getNextPageParam({ variables, lastPage, allPages, lastPageParam, allPageParams }),
|
|
54
|
-
}, queryClient) as UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
useInfiniteQuery(
|
|
58
|
-
variables?: Variables,
|
|
59
|
-
options?: UseInfiniteQueryObjectOptions<Result>,
|
|
60
|
-
): [
|
|
61
|
-
Accumulator extends keyof Result ? Result[Accumulator] : Result,
|
|
62
|
-
UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>,
|
|
63
|
-
] {
|
|
64
|
-
const result = this.useInfiniteQueryResult(true, variables, options)
|
|
65
|
-
return [
|
|
66
|
-
this.getListFromData(result.data),
|
|
67
|
-
result,
|
|
68
|
-
]
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
useStatefulInfiniteQuery(
|
|
72
|
-
variables?: Variables,
|
|
73
|
-
options?: UseInfiniteQueryObjectOptions<Result>,
|
|
74
|
-
): [
|
|
75
|
-
Accumulator extends keyof Result ? Result[Accumulator] : Result,
|
|
76
|
-
boolean,
|
|
77
|
-
StackspotAPIError | undefined | null,
|
|
78
|
-
UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>,
|
|
79
|
-
] {
|
|
80
|
-
const result = this.useInfiniteQueryResult(false, variables, options)
|
|
81
|
-
return [
|
|
82
|
-
this.getListFromData(result.data),
|
|
83
|
-
result.isPending,
|
|
84
|
-
result.error,
|
|
85
|
-
result,
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async invalidate(variables?: Partial<Variables> | undefined): Promise<void> {
|
|
90
|
-
await Promise.all([
|
|
91
|
-
super.invalidate(variables),
|
|
92
|
-
queryClient.invalidateQueries({ queryKey: ['infinite', ...this.getKey(variables)] }),
|
|
93
|
-
])
|
|
94
|
-
}
|
|
95
|
-
}
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
import { InfiniteData, QueryFunctionContext, QueryKey, UseInfiniteQueryResult, useInfiniteQuery, useSuspenseInfiniteQuery } from '@tanstack/react-query'
|
|
3
|
+
import { get, set } from 'lodash'
|
|
4
|
+
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
5
|
+
import { ManualQuery } from './ManualQuery'
|
|
6
|
+
import { queryClient } from './react-query-client'
|
|
7
|
+
import { FullOperationConfig, InfiniteQueryConfig, InfiniteQueryObject, UseInfiniteQueryObjectOptions } from './types'
|
|
8
|
+
|
|
9
|
+
export class ManualInfiniteQuery<
|
|
10
|
+
Variables extends Record<string, any>,
|
|
11
|
+
Result,
|
|
12
|
+
PageParamName extends keyof Variables,
|
|
13
|
+
Accumulator extends keyof Result | ''
|
|
14
|
+
> extends ManualQuery<Variables, Result> implements InfiniteQueryObject<Variables, Result, Accumulator> {
|
|
15
|
+
constructor(
|
|
16
|
+
config: InfiniteQueryConfig<Variables, Result, PageParamName, Accumulator>
|
|
17
|
+
& { apiName: string, transformError: (error: any) => StackspotAPIError },
|
|
18
|
+
) {
|
|
19
|
+
super(config as FullOperationConfig<any, any>)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private getConfig() {
|
|
23
|
+
return this.config as unknown as InfiniteQueryConfig<Variables, Result, PageParamName, Accumulator>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private createInfiniteQueryFn(
|
|
27
|
+
variables: Variables,
|
|
28
|
+
): (context: QueryFunctionContext<QueryKey, Variables[PageParamName]>) => Promise<Result> {
|
|
29
|
+
return ({ pageParam, signal }) => {
|
|
30
|
+
const paginatedVariables = {
|
|
31
|
+
...variables,
|
|
32
|
+
}
|
|
33
|
+
set(paginatedVariables, this.getConfig().pageParamName, pageParam ?? get(variables, this.getConfig().pageParamName))
|
|
34
|
+
return this.makeRequest(paginatedVariables, signal)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private getListFromData(data: InfiniteData<Result> | undefined) {
|
|
39
|
+
return data?.pages.map(
|
|
40
|
+
page => this.getConfig().accumulator ? page[this.getConfig().accumulator as keyof Result] : page,
|
|
41
|
+
).flat() as Accumulator extends keyof Result ? Result[Accumulator] : Result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private useInfiniteQueryResult(suspense: boolean, variables = {} as Variables, options?: UseInfiniteQueryObjectOptions<Result>) {
|
|
45
|
+
variables = { ...variables, ...this.getConfig().defaultVariables }
|
|
46
|
+
const use = suspense ? useSuspenseInfiniteQuery : useInfiniteQuery
|
|
47
|
+
return use<any, any, any, any, any>({
|
|
48
|
+
...options,
|
|
49
|
+
queryKey: ['infinite', ...this.getKey(variables)],
|
|
50
|
+
queryFn: this.createInfiniteQueryFn(variables),
|
|
51
|
+
initialPageParam: this.getConfig().initialPageParam,
|
|
52
|
+
getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) =>
|
|
53
|
+
this.getConfig().getNextPageParam({ variables, lastPage, allPages, lastPageParam, allPageParams }),
|
|
54
|
+
}, queryClient) as UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
useInfiniteQuery(
|
|
58
|
+
variables?: Variables,
|
|
59
|
+
options?: UseInfiniteQueryObjectOptions<Result>,
|
|
60
|
+
): [
|
|
61
|
+
Accumulator extends keyof Result ? Result[Accumulator] : Result,
|
|
62
|
+
UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>,
|
|
63
|
+
] {
|
|
64
|
+
const result = this.useInfiniteQueryResult(true, variables, options)
|
|
65
|
+
return [
|
|
66
|
+
this.getListFromData(result.data),
|
|
67
|
+
result,
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
useStatefulInfiniteQuery(
|
|
72
|
+
variables?: Variables,
|
|
73
|
+
options?: UseInfiniteQueryObjectOptions<Result>,
|
|
74
|
+
): [
|
|
75
|
+
Accumulator extends keyof Result ? Result[Accumulator] : Result,
|
|
76
|
+
boolean,
|
|
77
|
+
StackspotAPIError | undefined | null,
|
|
78
|
+
UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>,
|
|
79
|
+
] {
|
|
80
|
+
const result = this.useInfiniteQueryResult(false, variables, options)
|
|
81
|
+
return [
|
|
82
|
+
this.getListFromData(result.data),
|
|
83
|
+
result.isPending,
|
|
84
|
+
result.error,
|
|
85
|
+
result,
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async invalidate(variables?: Partial<Variables> | undefined): Promise<void> {
|
|
90
|
+
await Promise.all([
|
|
91
|
+
super.invalidate(variables),
|
|
92
|
+
queryClient.invalidateQueries({ queryKey: ['infinite', ...this.getKey(variables)] }),
|
|
93
|
+
])
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
|
|
3
|
-
import { UseMutationOptions, useMutation } from '@tanstack/react-query'
|
|
4
|
-
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
5
|
-
import { ManualOperation } from './ManualOperation'
|
|
6
|
-
import { queryClient } from './react-query-client'
|
|
7
|
-
import { FullOperationConfig, MutationObject } from './types'
|
|
8
|
-
|
|
9
|
-
export class ManualMutation<
|
|
10
|
-
Variables extends Record<string, any> | void,
|
|
11
|
-
Result
|
|
12
|
-
> extends ManualOperation<Variables> implements MutationObject<Variables, Result> {
|
|
13
|
-
constructor(config: FullOperationConfig<Variables extends void ? [AbortSignal] : [AbortSignal, Variables], Result>) {
|
|
14
|
-
super(config)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private async makeRequest(variables?: Record<string, any>, signal: AbortSignal = new AbortController().signal) {
|
|
18
|
-
try {
|
|
19
|
-
return await this.config.request(
|
|
20
|
-
...[signal, variables] as Variables extends void ? [AbortSignal] : [AbortSignal, Variables],
|
|
21
|
-
)
|
|
22
|
-
} catch (error) {
|
|
23
|
-
throw this.config.transformError(error)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
mutate(...args: Variables extends void ? [signal?: AbortSignal] : [variables: Variables, signal?: AbortSignal]) {
|
|
28
|
-
const variables = args[0] instanceof AbortSignal ? undefined : args[0]
|
|
29
|
-
const signal = args[0] instanceof AbortSignal ? args[0] : args[1]
|
|
30
|
-
return this.makeRequest(variables, signal)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
useMutation(options?: Omit<UseMutationOptions<Result, StackspotAPIError, Variables>, 'mutationFn'> & { signal?: AbortSignal }) {
|
|
34
|
-
const result = useMutation<Result, StackspotAPIError, Variables>({
|
|
35
|
-
...options,
|
|
36
|
-
mutationFn: (variables: any) => this.makeRequest(variables, options?.signal),
|
|
37
|
-
}, queryClient)
|
|
38
|
-
return [result.mutateAsync as any, result.isPending, result.error as StackspotAPIError | undefined, result as any] as const
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
|
|
3
|
+
import { UseMutationOptions, useMutation } from '@tanstack/react-query'
|
|
4
|
+
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
5
|
+
import { ManualOperation } from './ManualOperation'
|
|
6
|
+
import { queryClient } from './react-query-client'
|
|
7
|
+
import { FullOperationConfig, MutationObject } from './types'
|
|
8
|
+
|
|
9
|
+
export class ManualMutation<
|
|
10
|
+
Variables extends Record<string, any> | void,
|
|
11
|
+
Result
|
|
12
|
+
> extends ManualOperation<Variables> implements MutationObject<Variables, Result> {
|
|
13
|
+
constructor(config: FullOperationConfig<Variables extends void ? [AbortSignal] : [AbortSignal, Variables], Result>) {
|
|
14
|
+
super(config)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private async makeRequest(variables?: Record<string, any>, signal: AbortSignal = new AbortController().signal) {
|
|
18
|
+
try {
|
|
19
|
+
return await this.config.request(
|
|
20
|
+
...[signal, variables] as Variables extends void ? [AbortSignal] : [AbortSignal, Variables],
|
|
21
|
+
)
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw this.config.transformError(error)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
mutate(...args: Variables extends void ? [signal?: AbortSignal] : [variables: Variables, signal?: AbortSignal]) {
|
|
28
|
+
const variables = args[0] instanceof AbortSignal ? undefined : args[0]
|
|
29
|
+
const signal = args[0] instanceof AbortSignal ? args[0] : args[1]
|
|
30
|
+
return this.makeRequest(variables, signal)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
useMutation(options?: Omit<UseMutationOptions<Result, StackspotAPIError, Variables>, 'mutationFn'> & { signal?: AbortSignal }) {
|
|
34
|
+
const result = useMutation<Result, StackspotAPIError, Variables>({
|
|
35
|
+
...options,
|
|
36
|
+
mutationFn: (variables: any) => this.makeRequest(variables, options?.signal),
|
|
37
|
+
}, queryClient)
|
|
38
|
+
return [result.mutateAsync as any, result.isPending, result.error as StackspotAPIError | undefined, result as any] as const
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
|
|
3
|
-
import { UseQueryOptions, UseQueryResult, useQuery } from '@tanstack/react-query'
|
|
4
|
-
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
5
|
-
import { queryClient } from './react-query-client'
|
|
6
|
-
import { FullOperationConfig, OperationObject } from './types'
|
|
7
|
-
|
|
8
|
-
export abstract class ManualOperation<Variables extends Record<string, any> | void> implements OperationObject<Variables> {
|
|
9
|
-
protected config: FullOperationConfig<Variables extends void ? [AbortSignal] : [AbortSignal, Variables], any>
|
|
10
|
-
|
|
11
|
-
constructor(config: FullOperationConfig<Variables extends void ? [AbortSignal] : [AbortSignal, Variables], any>) {
|
|
12
|
-
this.config = config
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
private async makePermissionRequest(variables: Partial<Record<string, any>> | undefined) {
|
|
16
|
-
try {
|
|
17
|
-
// @ts-ignore the following is correct. TS can't correctly infer the conditional type here =(
|
|
18
|
-
return await this.config.permission(variables)
|
|
19
|
-
} catch (error) {
|
|
20
|
-
throw this.config.transformError(error)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
isAllowed(...[variables]: Variables extends void ? [] : [variables?: Partial<Variables>]) {
|
|
25
|
-
return queryClient.fetchQuery({
|
|
26
|
-
queryKey: this.getPermissionKey(variables as Variables),
|
|
27
|
-
queryFn: () => this.makePermissionRequest(variables),
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
useAllowed(
|
|
32
|
-
...args: Variables extends void
|
|
33
|
-
? [options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]
|
|
34
|
-
: [variables?: Partial<Variables>, options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]
|
|
35
|
-
) {
|
|
36
|
-
/* `this.config.permission` is a function with arity 0 or 1. If it accepts variables, its arity is 1. If it doesn't accept variables,
|
|
37
|
-
its arity is zero. We can use this information to determine what the type of `args` actually is at runtime. If variables are accepted,
|
|
38
|
-
than the 1st argument is the variables and the 2nd is the query options, otherwise, it has a single argument, which is the query
|
|
39
|
-
options. */
|
|
40
|
-
const [variables, options] = this.config.permission.length === 1 ? args : [undefined, args[0]]
|
|
41
|
-
const result = useQuery({
|
|
42
|
-
...options,
|
|
43
|
-
queryKey: this.getPermissionKey(variables as Variables),
|
|
44
|
-
queryFn: () => this.makePermissionRequest(variables),
|
|
45
|
-
}, queryClient) as UseQueryResult<boolean, StackspotAPIError>
|
|
46
|
-
return [result.data, result.isPending, result.error, result] as const
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getPermissionKey(variables?: Partial<Variables>) {
|
|
50
|
-
return [this.config.apiName, `${this.config.name}.permission`, variables]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
|
|
3
|
+
import { UseQueryOptions, UseQueryResult, useQuery } from '@tanstack/react-query'
|
|
4
|
+
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
5
|
+
import { queryClient } from './react-query-client'
|
|
6
|
+
import { FullOperationConfig, OperationObject } from './types'
|
|
7
|
+
|
|
8
|
+
export abstract class ManualOperation<Variables extends Record<string, any> | void> implements OperationObject<Variables> {
|
|
9
|
+
protected config: FullOperationConfig<Variables extends void ? [AbortSignal] : [AbortSignal, Variables], any>
|
|
10
|
+
|
|
11
|
+
constructor(config: FullOperationConfig<Variables extends void ? [AbortSignal] : [AbortSignal, Variables], any>) {
|
|
12
|
+
this.config = config
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private async makePermissionRequest(variables: Partial<Record<string, any>> | undefined) {
|
|
16
|
+
try {
|
|
17
|
+
// @ts-ignore the following is correct. TS can't correctly infer the conditional type here =(
|
|
18
|
+
return await this.config.permission(variables)
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw this.config.transformError(error)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
isAllowed(...[variables]: Variables extends void ? [] : [variables?: Partial<Variables>]) {
|
|
25
|
+
return queryClient.fetchQuery({
|
|
26
|
+
queryKey: this.getPermissionKey(variables as Variables),
|
|
27
|
+
queryFn: () => this.makePermissionRequest(variables),
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
useAllowed(
|
|
32
|
+
...args: Variables extends void
|
|
33
|
+
? [options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]
|
|
34
|
+
: [variables?: Partial<Variables>, options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]
|
|
35
|
+
) {
|
|
36
|
+
/* `this.config.permission` is a function with arity 0 or 1. If it accepts variables, its arity is 1. If it doesn't accept variables,
|
|
37
|
+
its arity is zero. We can use this information to determine what the type of `args` actually is at runtime. If variables are accepted,
|
|
38
|
+
than the 1st argument is the variables and the 2nd is the query options, otherwise, it has a single argument, which is the query
|
|
39
|
+
options. */
|
|
40
|
+
const [variables, options] = this.config.permission.length === 1 ? args : [undefined, args[0]]
|
|
41
|
+
const result = useQuery({
|
|
42
|
+
...options,
|
|
43
|
+
queryKey: this.getPermissionKey(variables as Variables),
|
|
44
|
+
queryFn: () => this.makePermissionRequest(variables),
|
|
45
|
+
}, queryClient) as UseQueryResult<boolean, StackspotAPIError>
|
|
46
|
+
return [result.data, result.isPending, result.error, result] as const
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getPermissionKey(variables?: Partial<Variables>) {
|
|
50
|
+
return [this.config.apiName, `${this.config.name}.permission`, variables]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
|
|
3
|
-
import { DefinedUseQueryResult, UseSuspenseQueryResult, useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
|
4
|
-
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
5
|
-
import { ManualOperation } from './ManualOperation'
|
|
6
|
-
import { queryClient } from './react-query-client'
|
|
7
|
-
import { FullOperationConfig, QueryObject, UseQueryObjectOptions } from './types'
|
|
8
|
-
|
|
9
|
-
export class ManualQuery<
|
|
10
|
-
Variables extends Record<string, any> | void,
|
|
11
|
-
Result
|
|
12
|
-
> extends ManualOperation<Variables> implements QueryObject<Variables, Result> {
|
|
13
|
-
constructor(config: FullOperationConfig<Variables extends void ? [AbortSignal] : [AbortSignal, Variables], Result>) {
|
|
14
|
-
super(config)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
protected async makeRequest(variables: Record<string, any> | undefined, signal: AbortSignal) {
|
|
18
|
-
try {
|
|
19
|
-
return await this.config.request(
|
|
20
|
-
...[signal, variables] as Variables extends void ? [AbortSignal] : [AbortSignal, Variables],
|
|
21
|
-
)
|
|
22
|
-
} catch (error) {
|
|
23
|
-
throw this.config.transformError(error)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
query(...[variables]: Variables extends void ? [] : [variables: Variables]) {
|
|
28
|
-
return queryClient.fetchQuery({
|
|
29
|
-
queryKey: this.getKey(variables as Variables),
|
|
30
|
-
queryFn: ({ signal }) => this.makeRequest(variables, signal),
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
#useQueryResult<T extends boolean>(
|
|
35
|
-
suspense: T,
|
|
36
|
-
...args: Variables extends void
|
|
37
|
-
? [options?: UseQueryObjectOptions<Result>]
|
|
38
|
-
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
39
|
-
) {
|
|
40
|
-
/* `this.config.request` is a function with arity 1 or 2. If it accepts variables, its arity is 2: the 1st parameter is the
|
|
41
|
-
AbortSignal and the 2nd is the variables. If it doesn't accept variables, its arity is one: it accepts only the AbortSignal.
|
|
42
|
-
We can use this information to determine what the type of `args` actually is at runtime. If variables are accepted, than the 1st
|
|
43
|
-
argument is the variables and the 2nd is the query options, otherwise, it has a single argument, which is the query options. */
|
|
44
|
-
const [variables, options] = this.config.request.length === 2 ? args : [undefined, args[0]]
|
|
45
|
-
const use = suspense ? useSuspenseQuery : useQuery
|
|
46
|
-
return use({
|
|
47
|
-
...options,
|
|
48
|
-
queryKey: this.getKey(variables as Variables),
|
|
49
|
-
queryFn: ({ signal }) => this.makeRequest(variables, signal),
|
|
50
|
-
}, queryClient) as T extends true ? UseSuspenseQueryResult<Result, StackspotAPIError> : DefinedUseQueryResult<Result, StackspotAPIError>
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
useQuery(
|
|
54
|
-
...args: Variables extends void
|
|
55
|
-
? [options?: UseQueryObjectOptions<Result>]
|
|
56
|
-
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
57
|
-
) {
|
|
58
|
-
const result = this.#useQueryResult(true, ...args)
|
|
59
|
-
return result.data
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
useStatefulQuery(
|
|
63
|
-
...args: Variables extends void
|
|
64
|
-
? [options?: UseQueryObjectOptions<Result>]
|
|
65
|
-
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
66
|
-
) {
|
|
67
|
-
const result = this.#useQueryResult(false, ...args)
|
|
68
|
-
return [result.data, result.isPending, result.error as StackspotAPIError | undefined, result] as const
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
invalidate(variables?: Partial<Variables>) {
|
|
72
|
-
return queryClient.invalidateQueries({ queryKey: this.getKey(variables) })
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getKey(variables?: Partial<Variables>) {
|
|
76
|
-
return [this.config.apiName, this.config.name, variables]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
cancel(variables?: Partial<Variables>) {
|
|
80
|
-
queryClient.cancelQueries({ queryKey: this.getKey(variables) })
|
|
81
|
-
}
|
|
82
|
-
}
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
|
|
3
|
+
import { DefinedUseQueryResult, UseSuspenseQueryResult, useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
|
4
|
+
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
5
|
+
import { ManualOperation } from './ManualOperation'
|
|
6
|
+
import { queryClient } from './react-query-client'
|
|
7
|
+
import { FullOperationConfig, QueryObject, UseQueryObjectOptions } from './types'
|
|
8
|
+
|
|
9
|
+
export class ManualQuery<
|
|
10
|
+
Variables extends Record<string, any> | void,
|
|
11
|
+
Result
|
|
12
|
+
> extends ManualOperation<Variables> implements QueryObject<Variables, Result> {
|
|
13
|
+
constructor(config: FullOperationConfig<Variables extends void ? [AbortSignal] : [AbortSignal, Variables], Result>) {
|
|
14
|
+
super(config)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected async makeRequest(variables: Record<string, any> | undefined, signal: AbortSignal) {
|
|
18
|
+
try {
|
|
19
|
+
return await this.config.request(
|
|
20
|
+
...[signal, variables] as Variables extends void ? [AbortSignal] : [AbortSignal, Variables],
|
|
21
|
+
)
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw this.config.transformError(error)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
query(...[variables]: Variables extends void ? [] : [variables: Variables]) {
|
|
28
|
+
return queryClient.fetchQuery({
|
|
29
|
+
queryKey: this.getKey(variables as Variables),
|
|
30
|
+
queryFn: ({ signal }) => this.makeRequest(variables, signal),
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#useQueryResult<T extends boolean>(
|
|
35
|
+
suspense: T,
|
|
36
|
+
...args: Variables extends void
|
|
37
|
+
? [options?: UseQueryObjectOptions<Result>]
|
|
38
|
+
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
39
|
+
) {
|
|
40
|
+
/* `this.config.request` is a function with arity 1 or 2. If it accepts variables, its arity is 2: the 1st parameter is the
|
|
41
|
+
AbortSignal and the 2nd is the variables. If it doesn't accept variables, its arity is one: it accepts only the AbortSignal.
|
|
42
|
+
We can use this information to determine what the type of `args` actually is at runtime. If variables are accepted, than the 1st
|
|
43
|
+
argument is the variables and the 2nd is the query options, otherwise, it has a single argument, which is the query options. */
|
|
44
|
+
const [variables, options] = this.config.request.length === 2 ? args : [undefined, args[0]]
|
|
45
|
+
const use = suspense ? useSuspenseQuery : useQuery
|
|
46
|
+
return use({
|
|
47
|
+
...options,
|
|
48
|
+
queryKey: this.getKey(variables as Variables),
|
|
49
|
+
queryFn: ({ signal }) => this.makeRequest(variables, signal),
|
|
50
|
+
}, queryClient) as T extends true ? UseSuspenseQueryResult<Result, StackspotAPIError> : DefinedUseQueryResult<Result, StackspotAPIError>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
useQuery(
|
|
54
|
+
...args: Variables extends void
|
|
55
|
+
? [options?: UseQueryObjectOptions<Result>]
|
|
56
|
+
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
57
|
+
) {
|
|
58
|
+
const result = this.#useQueryResult(true, ...args)
|
|
59
|
+
return result.data
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
useStatefulQuery(
|
|
63
|
+
...args: Variables extends void
|
|
64
|
+
? [options?: UseQueryObjectOptions<Result>]
|
|
65
|
+
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
66
|
+
) {
|
|
67
|
+
const result = this.#useQueryResult(false, ...args)
|
|
68
|
+
return [result.data, result.isPending, result.error as StackspotAPIError | undefined, result] as const
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
invalidate(variables?: Partial<Variables>) {
|
|
72
|
+
return queryClient.invalidateQueries({ queryKey: this.getKey(variables) })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getKey(variables?: Partial<Variables>) {
|
|
76
|
+
return [this.config.apiName, this.config.name, variables]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
cancel(variables?: Partial<Variables>) {
|
|
80
|
+
queryClient.cancelQueries({ queryKey: this.getKey(variables) })
|
|
81
|
+
}
|
|
82
|
+
}
|