@intrig/next 0.0.2 → 1.0.2
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/package.json +11 -4
- package/src/axios.server.js +1 -0
- package/src/axios.server.js.map +1 -1
- package/src/extra.d.ts +1 -1
- package/src/extra.js +3 -2
- package/src/extra.js.map +1 -1
- package/src/intrig-context.d.ts +4 -4
- package/src/intrig-context.js +1 -0
- package/src/intrig-context.js.map +1 -1
- package/src/intrig-middleware.d.ts +1 -1
- package/src/intrig-middleware.js +16 -7
- package/src/intrig-middleware.js.map +1 -1
- package/src/intrig-provider.d.ts +6 -5
- package/src/intrig-provider.js +9 -5
- package/src/intrig-provider.js.map +1 -1
- package/src/network-state.d.ts +133 -25
- package/src/network-state.js +67 -0
- package/src/network-state.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intrig/next",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Placeholder module for autogenerated intrig next.js boilerplate",
|
|
6
6
|
"dependencies": {
|
|
@@ -21,13 +21,20 @@
|
|
|
21
21
|
"@types/glob": "^8.1.0"
|
|
22
22
|
},
|
|
23
23
|
"_moduleAliases": {
|
|
24
|
-
"@intrig/next
|
|
24
|
+
"@intrig/next": "./src/lib"
|
|
25
25
|
},
|
|
26
26
|
"type": "module",
|
|
27
27
|
"exports": {
|
|
28
|
-
"
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./src/index.js",
|
|
30
|
+
"types": "./src/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./*": {
|
|
33
|
+
"import": "./src/*.js",
|
|
34
|
+
"types": "./src/*.d.ts"
|
|
35
|
+
}
|
|
29
36
|
},
|
|
30
37
|
"module": "./src/index.js",
|
|
31
38
|
"main": "./src/index.js",
|
|
32
39
|
"types": "./src/index.d.ts"
|
|
33
|
-
}
|
|
40
|
+
}
|
package/src/axios.server.js
CHANGED
package/src/axios.server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios.server.js","sourceRoot":"","sources":["../../../../lib/client-next/src/axios.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAIN,MAAM,OAAO,CAAC;AAkBf,MAAM,cAAc,GAAkC,EAAE,CAAC;AACzD,MAAM,kBAAkB,GAAkB,EAAE,CAAC;AAC7C,MAAM,mBAAmB,GAAyC,EAAE,CAAC;AAErE,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAChC,uBAAuB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACvC,cAAc,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;IACjC,CAAC;IACD,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,WAA8B,EAC9B,WAAwB;IAExB,IAAI,WAAW,KAAK,QAAQ,EAAE,CAAC;QAC7B,kBAAkB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAC1C,gBAAgB,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,CACxD,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAC/C,gBAAgB,CAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,WAA8B;IAC9D,IAAI,WAAW,KAAK,QAAQ,EAAE,CAAC;QAC7B,kBAAkB,CAAC,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CAAC;IAED,mBAAmB,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;AACrC,CAAC;AAED,SAAS,uBAAuB,CAAC,QAAuB,EAAE,GAAW;IACnE,kBAAkB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CACzC,gBAAgB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,CAAC,CAC7C,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACpC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAE/C,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,EAAE;QAC5C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;AAChC,CAAC"}
|
package/src/extra.d.ts
CHANGED
package/src/extra.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { error, init, isError, isSuccess, isValidationError, pending, success } from '@intrig/next/network-state';
|
|
2
3
|
import { useCallback, useEffect, useId, useMemo, useRef } from 'react';
|
|
3
|
-
import { useIntrigContext } from '@intrig/next
|
|
4
|
+
import { useIntrigContext } from '@intrig/next/intrig-context';
|
|
4
5
|
/**
|
|
5
6
|
* Converts a given hook into a promise-based function.
|
|
6
7
|
*
|
package/src/extra.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extra.js","sourceRoot":"","sources":["../../../../lib/client-next/src/extra.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,IAAI,EACJ,OAAO,EACP,SAAS,EACT,iBAAiB,EAEjB,OAAO,EACP,OAAO,EACR,MAAM,
|
|
1
|
+
{"version":3,"file":"extra.js","sourceRoot":"","sources":["../../../../lib/client-next/src/extra.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AACZ,OAAO,EACL,KAAK,EACL,IAAI,EACJ,OAAO,EACP,SAAS,EACT,iBAAiB,EAEjB,OAAO,EACP,OAAO,EACR,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAU,IAAyB,EAAE,MAAc,SAAS;IACtF,MAAM,UAAU,GAAG,MAAM,EAAsB,CAAC;IAChD,MAAM,SAAS,GAAG,MAAM,EAA0B,CAAC;IAEnD,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAEzC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjC,KAAK,EAAE,CAAC;QACV,CAAC;aAAM,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,SAAS,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACjC,KAAK,EAAE,CAAA;QACT,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,GAAG,IAAo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QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;QACnB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CACrB,CAAC,IAAI,EAAE,EAAE;YACP,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QACzB,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;YACJ,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QACpB,CAAC,CACF,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAClB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,YAAY;QACZ,OAAO;QACP,KAAK;KACN,CAAA;AACH,CAAC"}
|
package/src/intrig-context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NetworkAction, NetworkState } from '@intrig/next
|
|
1
|
+
import { NetworkAction, NetworkState } from '@intrig/next/network-state';
|
|
2
2
|
import { AxiosProgressEvent } from 'axios';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
|
-
import { DefaultConfigs } from '@intrig/next
|
|
4
|
+
import { DefaultConfigs } from '@intrig/next/intrig-provider';
|
|
5
5
|
type GlobalState = Record<string, NetworkState>;
|
|
6
6
|
interface RequestType<T = any> {
|
|
7
7
|
method: 'get' | 'post' | 'put' | 'delete';
|
|
@@ -27,9 +27,9 @@ interface RequestType<T = any> {
|
|
|
27
27
|
export interface ContextType {
|
|
28
28
|
state: GlobalState;
|
|
29
29
|
filteredState: GlobalState;
|
|
30
|
-
dispatch: React.Dispatch<NetworkAction<unknown>>;
|
|
30
|
+
dispatch: React.Dispatch<NetworkAction<unknown, unknown>>;
|
|
31
31
|
configs: DefaultConfigs;
|
|
32
|
-
execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema: ZodSchema<T> | undefined) => Promise<void>;
|
|
32
|
+
execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema: ZodSchema<T> | undefined, errorSchema: ZodSchema<T> | undefined) => Promise<void>;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Context object created using `createContext` function. Provides a way to share state, dispatch functions,
|
package/src/intrig-context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intrig-context.js","sourceRoot":"","sources":["../../../../lib/client-next/src/intrig-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"intrig-context.js","sourceRoot":"","sources":["../../../../lib/client-next/src/intrig-context.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAIZ,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAmClD;;;;;GAKG;AACH,IAAI,OAAO,GAAG,aAAa,CAAc;IACvC,KAAK,EAAE,EAAE;IACT,aAAa,EAAE,EAAE;IACjB,QAAQ,KAAI,CAAC;IACb,OAAO,EAAE,EAAE;IACX,KAAK,CAAC,OAAO;IAEb,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED,OAAO,EACL,OAAO,GAGR,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getAxiosInstance(key: string): import("axios").AxiosInstance
|
|
1
|
+
export declare function getAxiosInstance(key: string): Promise<import("axios").AxiosInstance>;
|
package/src/intrig-middleware.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export async function getAxiosInstance(key) {
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
let insightHook;
|
|
5
|
+
try {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
insightHook = require('intrig-hook');
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
console.warn('intrig-hook is not available. Proceeding without request interceptor.', error);
|
|
11
|
+
}
|
|
12
|
+
const baseURL = process.env[`${key.toUpperCase()}_API_URL`];
|
|
13
|
+
if (!baseURL) {
|
|
14
|
+
throw new Error(`Environment variable ${key.toUpperCase()}_API_URL is not defined.`);
|
|
15
|
+
}
|
|
16
|
+
const axiosInstance = axios.create({ baseURL });
|
|
17
|
+
if (insightHook?.requestInterceptor) {
|
|
9
18
|
axiosInstance.interceptors.request.use(insightHook.requestInterceptor);
|
|
10
19
|
}
|
|
11
20
|
return axiosInstance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intrig-middleware.js","sourceRoot":"","sources":["../../../../lib/client-next/src/intrig-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"intrig-middleware.js","sourceRoot":"","sources":["../../../../lib/client-next/src/intrig-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAW;IAChD,aAAa;IACb,IAAI,WAAW,CAAC;IAChB,IAAI,CAAC;QACH,aAAa;QACb,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,uEAAuE,EAAE,KAAK,CAAC,CAAC;IAC/F,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAEhD,IAAI,WAAW,EAAE,kBAAkB,EAAE,CAAC;QACpC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
package/src/intrig-provider.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export interface NetworkStateProps<T> {
|
|
|
53
53
|
operation: string;
|
|
54
54
|
source: string;
|
|
55
55
|
schema?: ZodSchema<T>;
|
|
56
|
+
errorSchema?: ZodSchema<T>;
|
|
56
57
|
debounceDelay?: number;
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
@@ -71,11 +72,11 @@ export interface NetworkStateProps<T> {
|
|
|
71
72
|
* Returns a state object representing the current network state,
|
|
72
73
|
* a function to execute the network request, and a function to clear the request.
|
|
73
74
|
*/
|
|
74
|
-
export declare function useNetworkState<T>({ key, operation, source, schema, debounceDelay: requestDebounceDelay, }: NetworkStateProps<T>): [
|
|
75
|
-
NetworkState<T>,
|
|
75
|
+
export declare function useNetworkState<T, E = unknown>({ key, operation, source, schema, errorSchema, debounceDelay: requestDebounceDelay, }: NetworkStateProps<T>): [
|
|
76
|
+
NetworkState<T, E>,
|
|
76
77
|
(request: RequestType) => void,
|
|
77
78
|
clear: () => void,
|
|
78
|
-
(state: NetworkState<T>) => void
|
|
79
|
+
(state: NetworkState<T, E>) => void
|
|
79
80
|
];
|
|
80
81
|
/**
|
|
81
82
|
* Handles central error extraction from the provided context.
|
|
@@ -87,7 +88,7 @@ export declare function useCentralErrorHandling(): {
|
|
|
87
88
|
operation: string;
|
|
88
89
|
key: string;
|
|
89
90
|
state: "error";
|
|
90
|
-
error:
|
|
91
|
+
error: unknown;
|
|
91
92
|
statusCode?: number;
|
|
92
93
|
request?: any;
|
|
93
94
|
}[];
|
|
@@ -97,4 +98,4 @@ export declare function useCentralErrorHandling(): {
|
|
|
97
98
|
*
|
|
98
99
|
* @return {NetworkState} The aggregated network state based on the pending states and their progress.
|
|
99
100
|
*/
|
|
100
|
-
export declare function useCentralPendingStateHandling(): NetworkState<unknown>;
|
|
101
|
+
export declare function useCentralPendingStateHandling(): NetworkState<unknown, unknown>;
|
package/src/intrig-provider.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { useCallback, useContext, useMemo, useReducer, useState, } from 'react';
|
|
3
4
|
import { error, init, isError, isPending, pending, success } from './network-state';
|
|
@@ -35,7 +36,7 @@ export function IntrigProvider({ children, configs = {}, }) {
|
|
|
35
36
|
});
|
|
36
37
|
}, [configs]);
|
|
37
38
|
const contextValue = useMemo(() => {
|
|
38
|
-
async function execute(request, dispatch, schema) {
|
|
39
|
+
async function execute(request, dispatch, schema, errorSchema) {
|
|
39
40
|
try {
|
|
40
41
|
dispatch(pending());
|
|
41
42
|
let response = await axiosInstance.request(request);
|
|
@@ -53,12 +54,15 @@ export function IntrigProvider({ children, configs = {}, }) {
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
else {
|
|
56
|
-
|
|
57
|
+
let { data, error: validationError } = errorSchema?.safeParse(response.data ?? {}) ?? {};
|
|
58
|
+
//todo: handle error validation error.
|
|
59
|
+
dispatch(error(data ?? response.data ?? response.statusText, response.status));
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
catch (e) {
|
|
60
63
|
if (isAxiosError(e)) {
|
|
61
|
-
|
|
64
|
+
let { data, error: validationError } = errorSchema?.safeParse(e.response?.data ?? {}) ?? {};
|
|
65
|
+
dispatch(error(data ?? e.response?.data, e.response?.status, request));
|
|
62
66
|
}
|
|
63
67
|
else {
|
|
64
68
|
dispatch(error(e));
|
|
@@ -177,7 +181,7 @@ export function StatusTrap({ children, type, propagate = true, }) {
|
|
|
177
181
|
* Returns a state object representing the current network state,
|
|
178
182
|
* a function to execute the network request, and a function to clear the request.
|
|
179
183
|
*/
|
|
180
|
-
export function useNetworkState({ key, operation, source, schema, debounceDelay: requestDebounceDelay, }) {
|
|
184
|
+
export function useNetworkState({ key, operation, source, schema, errorSchema, debounceDelay: requestDebounceDelay, }) {
|
|
181
185
|
const context = useContext(Context);
|
|
182
186
|
const [abortController, setAbortController] = useState();
|
|
183
187
|
const networkState = useMemo(() => {
|
|
@@ -213,7 +217,7 @@ export function useNetworkState({ key, operation, source, schema, debounceDelay:
|
|
|
213
217
|
},
|
|
214
218
|
signal: abortController.signal,
|
|
215
219
|
};
|
|
216
|
-
await context.execute(requestConfig, dispatch, schema);
|
|
220
|
+
await context.execute(requestConfig, dispatch, schema, errorSchema);
|
|
217
221
|
}, [networkState, context.dispatch, axios]);
|
|
218
222
|
const deboundedExecute = useMemo(() => debounce(execute, debounceDelay ?? 0), [execute]);
|
|
219
223
|
const clear = useCallback(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intrig-provider.js","sourceRoot":"","sources":["../../../../lib/client-next/src/intrig-provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"intrig-provider.js","sourceRoot":"","sources":["../../../../lib/client-next/src/intrig-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AACZ,OAAO,EAGL,WAAW,EACX,UAAU,EACV,OAAO,EACP,UAAU,EACV,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EACL,KAAK,EAGL,IAAI,EACJ,OAAO,EACP,SAAS,EAGT,OAAO,EAEP,OAAO,EACR,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,EAKZ,YAAY,GACb,MAAM,OAAO,CAAC;AAGf,OAAO,EAAC,OAAO,EAA2B,MAAM,kBAAkB,CAAC;AAEnE;;;;;;GAMG;AACH,SAAS,cAAc,CACrB,KAAkB,EAClB,MAAuC;IAEvC,OAAO;QACL,GAAG,KAAK;QACR,CAAC,GAAG,MAAM,CAA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AqB,CAC3C,CAAC;QACJ,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;IAExB,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/src/network-state.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ZodError } from 'zod';
|
|
1
2
|
/**
|
|
2
3
|
* State of an asynchronous call. Network state follows the state diagram given below.
|
|
3
4
|
*
|
|
@@ -21,31 +22,31 @@
|
|
|
21
22
|
*
|
|
22
23
|
* </pre>
|
|
23
24
|
*/
|
|
24
|
-
export interface NetworkState<T = unknown> {
|
|
25
|
+
export interface NetworkState<T = unknown, E = unknown> {
|
|
25
26
|
state: 'init' | 'pending' | 'success' | 'error';
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Network call is not yet started
|
|
29
30
|
*/
|
|
30
|
-
export interface InitState<T> extends NetworkState<T> {
|
|
31
|
+
export interface InitState<T, E = unknown> extends NetworkState<T, E> {
|
|
31
32
|
state: 'init';
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Checks whether the state is init state
|
|
35
36
|
* @param state
|
|
36
37
|
*/
|
|
37
|
-
export declare function isInit<T>(state: NetworkState<T>): state is InitState<T>;
|
|
38
|
+
export declare function isInit<T, E = unknown>(state: NetworkState<T, E>): state is InitState<T, E>;
|
|
38
39
|
/**
|
|
39
40
|
* Initializes a new state.
|
|
40
41
|
*
|
|
41
42
|
* @template T The type of the state.
|
|
42
43
|
* @return {InitState<T>} An object representing the initial state.
|
|
43
44
|
*/
|
|
44
|
-
export declare function init<T>(): InitState<T>;
|
|
45
|
+
export declare function init<T, E = unknown>(): InitState<T, E>;
|
|
45
46
|
/**
|
|
46
47
|
* Network call is not yet completed
|
|
47
48
|
*/
|
|
48
|
-
export interface PendingState<T> extends NetworkState<T> {
|
|
49
|
+
export interface PendingState<T, E = unknown> extends NetworkState<T, E> {
|
|
49
50
|
state: 'pending';
|
|
50
51
|
progress?: Progress;
|
|
51
52
|
}
|
|
@@ -69,17 +70,17 @@ export interface Progress {
|
|
|
69
70
|
* Checks whether the state is pending state
|
|
70
71
|
* @param state
|
|
71
72
|
*/
|
|
72
|
-
export declare function isPending<T>(state: NetworkState<T>): state is PendingState<T>;
|
|
73
|
+
export declare function isPending<T, E = unknown>(state: NetworkState<T, E>): state is PendingState<T, E>;
|
|
73
74
|
/**
|
|
74
75
|
* Generates a PendingState object with a state of "pending".
|
|
75
76
|
*
|
|
76
77
|
* @return {PendingState<T>} An object representing the pending state.
|
|
77
78
|
*/
|
|
78
|
-
export declare function pending<T>(progress?: Progress | undefined): PendingState<T>;
|
|
79
|
+
export declare function pending<T, E = unknown>(progress?: Progress | undefined): PendingState<T, E>;
|
|
79
80
|
/**
|
|
80
81
|
* Network call is completed with success state
|
|
81
82
|
*/
|
|
82
|
-
export interface SuccessState<T> extends NetworkState<T> {
|
|
83
|
+
export interface SuccessState<T, E = unknown> extends NetworkState<T, E> {
|
|
83
84
|
state: 'success';
|
|
84
85
|
data: T;
|
|
85
86
|
}
|
|
@@ -87,20 +88,20 @@ export interface SuccessState<T> extends NetworkState<T> {
|
|
|
87
88
|
* Checks whether the state is success response
|
|
88
89
|
* @param state
|
|
89
90
|
*/
|
|
90
|
-
export declare function isSuccess<T>(state: NetworkState<T>): state is SuccessState<T>;
|
|
91
|
+
export declare function isSuccess<T, E = unknown>(state: NetworkState<T, E>): state is SuccessState<T, E>;
|
|
91
92
|
/**
|
|
92
93
|
* Creates a success state object with the provided data.
|
|
93
94
|
*
|
|
94
95
|
* @param {T} data - The data to be included in the success state.
|
|
95
96
|
* @return {SuccessState<T>} An object representing a success state containing the provided data.
|
|
96
97
|
*/
|
|
97
|
-
export declare function success<T>(data: T): SuccessState<T>;
|
|
98
|
+
export declare function success<T, E = unknown>(data: T): SuccessState<T, E>;
|
|
98
99
|
/**
|
|
99
100
|
* Network call is completed with error response
|
|
100
101
|
*/
|
|
101
|
-
export interface ErrorState<T> extends NetworkState<T> {
|
|
102
|
+
export interface ErrorState<T, E = unknown> extends NetworkState<T, E> {
|
|
102
103
|
state: 'error';
|
|
103
|
-
error:
|
|
104
|
+
error: E;
|
|
104
105
|
statusCode?: number;
|
|
105
106
|
request?: any;
|
|
106
107
|
}
|
|
@@ -108,7 +109,7 @@ export interface ErrorState<T> extends NetworkState<T> {
|
|
|
108
109
|
* Checks whether the state is error state
|
|
109
110
|
* @param state
|
|
110
111
|
*/
|
|
111
|
-
export declare function isError<T>(state: NetworkState<T>): state is ErrorState<T>;
|
|
112
|
+
export declare function isError<T, E = unknown>(state: NetworkState<T, E>): state is ErrorState<T, E>;
|
|
112
113
|
/**
|
|
113
114
|
* Constructs an ErrorState object representing an error.
|
|
114
115
|
*
|
|
@@ -116,7 +117,7 @@ export declare function isError<T>(state: NetworkState<T>): state is ErrorState<
|
|
|
116
117
|
* @param {string} [statusCode] - An optional status code associated with the error.
|
|
117
118
|
* @return {ErrorState<T>} An object representing the error state.
|
|
118
119
|
*/
|
|
119
|
-
export declare function error<T>(error:
|
|
120
|
+
export declare function error<T, E = unknown>(error: E, statusCode?: number, request?: any): ErrorState<T>;
|
|
120
121
|
/**
|
|
121
122
|
* Represents an error state with additional contextual information.
|
|
122
123
|
*
|
|
@@ -128,7 +129,7 @@ export declare function error<T>(error: any, statusCode?: number, request?: any)
|
|
|
128
129
|
* @property {string} operation - The operation being performed when the error occurred.
|
|
129
130
|
* @property {string} key - A unique key identifying the specific error instance.
|
|
130
131
|
*/
|
|
131
|
-
export interface ErrorWithContext<T = unknown> extends ErrorState<T> {
|
|
132
|
+
export interface ErrorWithContext<T = unknown, E = unknown> extends ErrorState<T, E> {
|
|
132
133
|
source: string;
|
|
133
134
|
operation: string;
|
|
134
135
|
key: string;
|
|
@@ -141,24 +142,24 @@ export interface ErrorWithContext<T = unknown> extends ErrorState<T> {
|
|
|
141
142
|
* @property {NetworkState<any>} state - The current state of the network action
|
|
142
143
|
* @property {string} key - The unique identifier for the network action
|
|
143
144
|
*/
|
|
144
|
-
export interface NetworkAction<T> {
|
|
145
|
+
export interface NetworkAction<T, E> {
|
|
145
146
|
key: string;
|
|
146
147
|
source: string;
|
|
147
148
|
operation: string;
|
|
148
|
-
state: NetworkState<T>;
|
|
149
|
+
state: NetworkState<T, E>;
|
|
149
150
|
handled?: boolean;
|
|
150
151
|
}
|
|
151
152
|
type HookWithKey = {
|
|
152
153
|
key: string;
|
|
153
154
|
};
|
|
154
|
-
export type DeleteHook<P> = ((key?: string) => [NetworkState<never>, (params: P) => void, () => void]) & HookWithKey;
|
|
155
|
-
export type DeleteHookOp<P> = ((key?: string) => [NetworkState<never>, (params?: P) => void, () => void]) & HookWithKey;
|
|
156
|
-
export type GetHook<P, T> = ((key?: string) => [NetworkState<T>, (params: P) => void, () => void]) & HookWithKey;
|
|
157
|
-
export type GetHookOp<P, T> = ((key?: string) => [NetworkState<T>, (params?: P) => void, () => void]) & HookWithKey;
|
|
158
|
-
export type PostHook<P, T, B> = ((key?: string) => [NetworkState<T>, (body: B, params: P) => void, () => void]) & HookWithKey;
|
|
159
|
-
export type PostHookOp<P, T, B> = ((key?: string) => [NetworkState<T>, (body: B, params?: P) => void, () => void]) & HookWithKey;
|
|
160
|
-
export type PutHook<P, T, B> = ((key?: string) => [NetworkState<T>, (body: B, params: P) => void, () => void]) & HookWithKey;
|
|
161
|
-
export type PutHookOp<P, T, B> = ((key?: string) => [NetworkState<T>, (body: B, params?: P) => void, () => void]) & HookWithKey;
|
|
155
|
+
export type DeleteHook<P, E = unknown> = ((key?: string) => [NetworkState<never, E>, (params: P) => void, () => void]) & HookWithKey;
|
|
156
|
+
export type DeleteHookOp<P, E = unknown> = ((key?: string) => [NetworkState<never, E>, (params?: P) => void, () => void]) & HookWithKey;
|
|
157
|
+
export type GetHook<P, T, E = unknown> = ((key?: string) => [NetworkState<T, E>, (params: P) => void, () => void]) & HookWithKey;
|
|
158
|
+
export type GetHookOp<P, T, E = unknown> = ((key?: string) => [NetworkState<T, E>, (params?: P) => void, () => void]) & HookWithKey;
|
|
159
|
+
export type PostHook<P, T, B, E = unknown> = ((key?: string) => [NetworkState<T, E>, (body: B, params: P) => void, () => void]) & HookWithKey;
|
|
160
|
+
export type PostHookOp<P, T, B, E = unknown> = ((key?: string) => [NetworkState<T, E>, (body: B, params?: P) => void, () => void]) & HookWithKey;
|
|
161
|
+
export type PutHook<P, T, B, E = unknown> = ((key?: string) => [NetworkState<T, E>, (body: B, params: P) => void, () => void]) & HookWithKey;
|
|
162
|
+
export type PutHookOp<P, T, B, E = unknown> = ((key?: string) => [NetworkState<T, E>, (body: B, params?: P) => void, () => void]) & HookWithKey;
|
|
162
163
|
export type IntrigHook<P = undefined, B = undefined, T = any> = DeleteHook<P> | GetHook<P, T> | PostHook<P, T, B> | PutHook<P, T, B> | PostHookOp<P, T, B> | PutHookOp<P, T, B> | GetHookOp<P, T> | DeleteHookOp<P>;
|
|
163
164
|
/**
|
|
164
165
|
* Represents the dispatch state of a process.
|
|
@@ -220,4 +221,111 @@ export declare function validationError<T>(error: any): ValidationError<T>;
|
|
|
220
221
|
* @return {boolean} - Returns true if the provided DispatchState object is a ValidationError, otherwise returns false.
|
|
221
222
|
*/
|
|
222
223
|
export declare function isValidationError<T>(value: DispatchState<T>): value is ValidationError<T>;
|
|
224
|
+
/**
|
|
225
|
+
* Represents an error structure with a specified type and associated data.
|
|
226
|
+
*
|
|
227
|
+
* @template T - The type of the data associated with the error.
|
|
228
|
+
* @template E - The type of the error detail.
|
|
229
|
+
*
|
|
230
|
+
* @property {string} type - A string representing the type of the error.
|
|
231
|
+
*/
|
|
232
|
+
export interface IntrigError<T, E> {
|
|
233
|
+
type: string;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Represents an error encountered during a network operation.
|
|
237
|
+
* Extends from the `IntrigError` interface, adding network-specific properties.
|
|
238
|
+
*
|
|
239
|
+
* @template T - The type of the intrinsic data associated with the error.
|
|
240
|
+
* @template E - The type of the error details, defaulting to `unknown`.
|
|
241
|
+
*
|
|
242
|
+
* @property {string} type - A constant property representing the error type, always set to 'network'.
|
|
243
|
+
* @property {string} statusCode - A string representation of the HTTP status code associated with the error, indicating the nature of the network failure.
|
|
244
|
+
* @property {E} error - The detailed error information specific to the failure, type extends from the generic E, allowing flexibility in the error details.
|
|
245
|
+
* @property {any} request - The request object that was attempted when the network error occurred, providing context for what operation failed.
|
|
246
|
+
*/
|
|
247
|
+
export interface NetworkError<T, E = unknown> extends IntrigError<T, E> {
|
|
248
|
+
type: 'network';
|
|
249
|
+
statusCode: string;
|
|
250
|
+
error: E;
|
|
251
|
+
request: any;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Constructs a network error object.
|
|
255
|
+
*
|
|
256
|
+
* @param error The error object corresponding to the network request.
|
|
257
|
+
* @param statusCode A string representing the HTTP status code returned.
|
|
258
|
+
* @param request The request object associated with the network operation.
|
|
259
|
+
* @return A NetworkError object containing the error type, status code, error details, and the original request.
|
|
260
|
+
*/
|
|
261
|
+
export declare function networkError<T, E>(error: E, statusCode: string, request: any): NetworkError<T, E>;
|
|
262
|
+
/**
|
|
263
|
+
* Determines if the provided IntrigError is of type 'network'.
|
|
264
|
+
*
|
|
265
|
+
* @param {IntrigError<T, E>} value - The error value to check the type of.
|
|
266
|
+
* @return {boolean} - Returns true if the error is of type 'network', otherwise false.
|
|
267
|
+
*/
|
|
268
|
+
export declare function isNetworkError<T, E>(value: IntrigError<T, E>): value is NetworkError<T, E>;
|
|
269
|
+
/**
|
|
270
|
+
* Interface representing a request validation error.
|
|
271
|
+
*
|
|
272
|
+
* This error occurs when a validation process on a request fails. It extends the IntrigError interface
|
|
273
|
+
* by adding specific properties related to request validation.
|
|
274
|
+
*
|
|
275
|
+
* @template T - The type of the data associated with the error.
|
|
276
|
+
* @template E - The optional type of additional error information. Defaults to unknown.
|
|
277
|
+
*
|
|
278
|
+
* @extends IntrigError<T, E>
|
|
279
|
+
*
|
|
280
|
+
* @property {string} type - A string literal indicating the error type as 'request-validation'.
|
|
281
|
+
* @property {ZodError} error - An instance of ZodError containing detailed validation error information.
|
|
282
|
+
*/
|
|
283
|
+
export interface RequestValidationError<T, E = unknown> extends IntrigError<T, E> {
|
|
284
|
+
type: 'request-validation';
|
|
285
|
+
error: ZodError;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Constructs a RequestValidationError object encapsulating the ZodError.
|
|
289
|
+
*
|
|
290
|
+
* @param {ZodError} error - The error object resulting from Zod schema validation.
|
|
291
|
+
* @return {RequestValidationError<T, E>} A RequestValidationError object containing the validation error information.
|
|
292
|
+
*/
|
|
293
|
+
export declare function requestValidationError<T, E>(error: ZodError): RequestValidationError<T, E>;
|
|
294
|
+
/**
|
|
295
|
+
* Determines if a given error is of type RequestValidationError.
|
|
296
|
+
*
|
|
297
|
+
* @param value The error object to check, which implements the IntrigError interface.
|
|
298
|
+
* @return A boolean indicating whether the error is a RequestValidationError.
|
|
299
|
+
*/
|
|
300
|
+
export declare function isRequestValidationError<T, E>(value: IntrigError<T, E>): value is RequestValidationError<T, E>;
|
|
301
|
+
/**
|
|
302
|
+
* ResponseValidationError interface is designed to extend the capabilities of the IntrigError interface,
|
|
303
|
+
* specifically for handling errors related to response validation.
|
|
304
|
+
*
|
|
305
|
+
* @template T - Represents the type of the data or payload associated with the error.
|
|
306
|
+
* @template E - Represents the type of any additional error information. Defaults to unknown.
|
|
307
|
+
*
|
|
308
|
+
* @extends IntrigError
|
|
309
|
+
*
|
|
310
|
+
* @property type - A string literal that identifies the type of error as 'response-validation'.
|
|
311
|
+
* @property error - An instance of ZodError representing the validation error encountered.
|
|
312
|
+
*/
|
|
313
|
+
export interface ResponseValidationError<T, E = unknown> extends IntrigError<T, E> {
|
|
314
|
+
type: 'response-validation';
|
|
315
|
+
error: ZodError;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Constructs a ResponseValidationError object with a specified error.
|
|
319
|
+
*
|
|
320
|
+
* @param {ZodError} error - The validation error encountered during response validation.
|
|
321
|
+
* @return {ResponseValidationError<T, E>} An error object containing the type of error and the validation error details.
|
|
322
|
+
*/
|
|
323
|
+
export declare function responseValidationError<T, E>(error: ZodError): ResponseValidationError<T, E>;
|
|
324
|
+
/**
|
|
325
|
+
* Determines if the given error is a response validation error.
|
|
326
|
+
*
|
|
327
|
+
* @param {IntrigError<T, E>} value - The error object to assess.
|
|
328
|
+
* @return {boolean} True if the error is a response validation error, otherwise false.
|
|
329
|
+
*/
|
|
330
|
+
export declare function isResponseValidationError<T, E>(value: IntrigError<T, E>): value is ResponseValidationError<T, E>;
|
|
223
331
|
export {};
|
package/src/network-state.js
CHANGED
|
@@ -115,4 +115,71 @@ export function validationError(error) {
|
|
|
115
115
|
export function isValidationError(value) {
|
|
116
116
|
return value.state === 'validation-error';
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Constructs a network error object.
|
|
120
|
+
*
|
|
121
|
+
* @param error The error object corresponding to the network request.
|
|
122
|
+
* @param statusCode A string representing the HTTP status code returned.
|
|
123
|
+
* @param request The request object associated with the network operation.
|
|
124
|
+
* @return A NetworkError object containing the error type, status code, error details, and the original request.
|
|
125
|
+
*/
|
|
126
|
+
export function networkError(error, statusCode, request) {
|
|
127
|
+
return {
|
|
128
|
+
type: 'network',
|
|
129
|
+
statusCode,
|
|
130
|
+
error,
|
|
131
|
+
request
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Determines if the provided IntrigError is of type 'network'.
|
|
136
|
+
*
|
|
137
|
+
* @param {IntrigError<T, E>} value - The error value to check the type of.
|
|
138
|
+
* @return {boolean} - Returns true if the error is of type 'network', otherwise false.
|
|
139
|
+
*/
|
|
140
|
+
export function isNetworkError(value) {
|
|
141
|
+
return value.type === 'network';
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Constructs a RequestValidationError object encapsulating the ZodError.
|
|
145
|
+
*
|
|
146
|
+
* @param {ZodError} error - The error object resulting from Zod schema validation.
|
|
147
|
+
* @return {RequestValidationError<T, E>} A RequestValidationError object containing the validation error information.
|
|
148
|
+
*/
|
|
149
|
+
export function requestValidationError(error) {
|
|
150
|
+
return {
|
|
151
|
+
type: 'request-validation',
|
|
152
|
+
error
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Determines if a given error is of type RequestValidationError.
|
|
157
|
+
*
|
|
158
|
+
* @param value The error object to check, which implements the IntrigError interface.
|
|
159
|
+
* @return A boolean indicating whether the error is a RequestValidationError.
|
|
160
|
+
*/
|
|
161
|
+
export function isRequestValidationError(value) {
|
|
162
|
+
return value.type === 'request-validation';
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Constructs a ResponseValidationError object with a specified error.
|
|
166
|
+
*
|
|
167
|
+
* @param {ZodError} error - The validation error encountered during response validation.
|
|
168
|
+
* @return {ResponseValidationError<T, E>} An error object containing the type of error and the validation error details.
|
|
169
|
+
*/
|
|
170
|
+
export function responseValidationError(error) {
|
|
171
|
+
return {
|
|
172
|
+
type: 'response-validation',
|
|
173
|
+
error
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Determines if the given error is a response validation error.
|
|
178
|
+
*
|
|
179
|
+
* @param {IntrigError<T, E>} value - The error object to assess.
|
|
180
|
+
* @return {boolean} True if the error is a response validation error, otherwise false.
|
|
181
|
+
*/
|
|
182
|
+
export function isResponseValidationError(value) {
|
|
183
|
+
return value.type === 'response-validation';
|
|
184
|
+
}
|
|
118
185
|
//# sourceMappingURL=network-state.js.map
|
package/src/network-state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-state.js","sourceRoot":"","sources":["../../../../lib/client-next/src/network-state.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"network-state.js","sourceRoot":"","sources":["../../../../lib/client-next/src/network-state.tsx"],"names":[],"mappings":"AAoCA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAiB,KAAyB;IAC9D,OAAO,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,KAAK,EAAE,MAAM;KACd,CAAC;AACJ,CAAC;AA2BD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAiB,KAAyB;IACjE,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CACrB,WAAiC,SAAS;IAE1C,OAAO;QACL,KAAK,EAAE,SAAS;QAChB,QAAQ;KACT,CAAC;AACJ,CAAC;AAUD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAiB,KAAyB;IACjE,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAiB,IAAO;IAC7C,OAAO;QACL,KAAK,EAAE,SAAS;QAChB,IAAI;KACL,CAAC;AACJ,CAAC;AAYD;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAiB,KAAyB;IAC/D,OAAO,KAAK,CAAC,KAAK,KAAK,OAAO,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CACnB,KAAQ,EACR,UAAmB,EACnB,OAAa;IAEb,OAAO;QACL,KAAK,EAAE,OAAO;QACd,KAAK;QACL,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC;AA2ED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,KAAK,EAAE,SAAS;KACjB,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAI,KAAuB;IAC7D,OAAO,KAAK,CAAC,KAAK,KAAK,SAA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