@intrig/next 1.0.6 → 1.0.10

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 (53) hide show
  1. package/eslint.config.cjs +19 -0
  2. package/jest.config.ts +10 -0
  3. package/package.json +7 -7
  4. package/project.json +20 -0
  5. package/src/extra/{index.d.ts → index.ts} +2 -2
  6. package/src/extra/useAsNetworkState.ts +53 -0
  7. package/src/extra/{useAsPromise.d.ts → useAsPromise.ts} +58 -7
  8. package/src/extra/useLocalReducer.ts +61 -0
  9. package/src/extra/{useResolvedCachedValue.d.ts → useResolvedCachedValue.ts} +39 -7
  10. package/src/extra/{useResolvedValue.d.ts → useResolvedValue.ts} +39 -7
  11. package/src/extra.ts +190 -0
  12. package/src/index.ts +3 -0
  13. package/src/intrig-context.ts +66 -0
  14. package/src/intrig-layout.tsx +18 -0
  15. package/src/intrig-middleware.ts +31 -0
  16. package/src/intrig-provider.tsx +454 -0
  17. package/src/logger.ts +13 -0
  18. package/src/media-type-utils.ts +184 -0
  19. package/src/{network-state.d.ts → network-state.tsx} +176 -91
  20. package/tsconfig.json +28 -0
  21. package/tsconfig.lib.json +10 -0
  22. package/tsconfig.spec.json +14 -0
  23. package/src/extra/index.js +0 -5
  24. package/src/extra/index.js.map +0 -1
  25. package/src/extra/useAsNetworkState.d.ts +0 -13
  26. package/src/extra/useAsNetworkState.js +0 -41
  27. package/src/extra/useAsNetworkState.js.map +0 -1
  28. package/src/extra/useAsPromise.js +0 -30
  29. package/src/extra/useAsPromise.js.map +0 -1
  30. package/src/extra/useResolvedCachedValue.js +0 -15
  31. package/src/extra/useResolvedCachedValue.js.map +0 -1
  32. package/src/extra/useResolvedValue.js +0 -17
  33. package/src/extra/useResolvedValue.js.map +0 -1
  34. package/src/extra.d.ts +0 -52
  35. package/src/extra.js +0 -92
  36. package/src/extra.js.map +0 -1
  37. package/src/index.d.ts +0 -5
  38. package/src/index.js +0 -6
  39. package/src/index.js.map +0 -1
  40. package/src/intrig-context.d.ts +0 -42
  41. package/src/intrig-context.js +0 -21
  42. package/src/intrig-context.js.map +0 -1
  43. package/src/intrig-middleware.d.ts +0 -1
  44. package/src/intrig-middleware.js +0 -15
  45. package/src/intrig-middleware.js.map +0 -1
  46. package/src/intrig-provider.d.ts +0 -101
  47. package/src/intrig-provider.js +0 -289
  48. package/src/intrig-provider.js.map +0 -1
  49. package/src/media-type-utils.d.ts +0 -3
  50. package/src/media-type-utils.js +0 -89
  51. package/src/media-type-utils.js.map +0 -1
  52. package/src/network-state.js +0 -185
  53. package/src/network-state.js.map +0 -1
@@ -1,289 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useCallback, useContext, useMemo, useReducer, useState, } from 'react';
4
- import { error, init, isError, isPending, pending, success } from './network-state';
5
- import axios, { isAxiosError, } from 'axios';
6
- import { Context } from './intrig-context';
7
- /**
8
- * Handles state updates for network requests based on the provided action.
9
- *
10
- * @param {GlobalState} state - The current state of the application.
11
- * @param {NetworkAction<unknown>} action - The action containing source, operation, key, and state.
12
- * @return {GlobalState} - The updated state after applying the action.
13
- */
14
- function requestReducer(state, action) {
15
- return {
16
- ...state,
17
- [`${action.source}:${action.operation}:${action.key}`]: action.state,
18
- };
19
- }
20
- /**
21
- * IntrigProvider is a context provider component that sets up global state management
22
- * and provides Axios instances for API requests.
23
- *
24
- * @param {Object} props - The properties object.
25
- * @param {React.ReactNode} props.children - The child components to be wrapped by the provider.
26
- * @param {Object} [props.configs={}] - Configuration object for Axios instances.
27
- * @param {Object} [props.configs.defaults={}] - Default configuration for Axios.
28
- * @param {Object} [props.configs.petstore={}] - Configuration specific to the petstore API.
29
- * @return {JSX.Element} A context provider component that wraps the provided children.
30
- */
31
- export function IntrigProvider({ children, configs = {}, }) {
32
- const [state, dispatch] = useReducer(requestReducer, {});
33
- const axiosInstance = useMemo(() => {
34
- return axios.create({
35
- ...(configs ?? {}),
36
- });
37
- }, [configs]);
38
- const contextValue = useMemo(() => {
39
- async function execute(request, dispatch, schema, errorSchema) {
40
- try {
41
- dispatch(pending());
42
- let response = await axiosInstance.request(request);
43
- if (response.status >= 200 && response.status < 300) {
44
- if (schema) {
45
- let data = schema.safeParse(response.data);
46
- if (!data.success) {
47
- dispatch(error(data.error.issues, response.status, request));
48
- return;
49
- }
50
- dispatch(success(data.data));
51
- }
52
- else {
53
- dispatch(success(response.data));
54
- }
55
- }
56
- else {
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));
60
- }
61
- }
62
- catch (e) {
63
- if (isAxiosError(e)) {
64
- let { data, error: validationError } = errorSchema?.safeParse(e.response?.data ?? {}) ?? {};
65
- dispatch(error(data ?? e.response?.data, e.response?.status, request));
66
- }
67
- else {
68
- dispatch(error(e));
69
- }
70
- }
71
- }
72
- return {
73
- state,
74
- dispatch,
75
- filteredState: state,
76
- configs,
77
- execute,
78
- };
79
- }, [state, axiosInstance]);
80
- return _jsx(Context.Provider, { value: contextValue, children: children });
81
- }
82
- export function IntrigProviderStub({ children, configs = {}, stubs = () => { } }) {
83
- const [state, dispatch] = useReducer(requestReducer, {});
84
- const collectedStubs = useMemo(() => {
85
- let fns = {};
86
- function stub(hook, fn) {
87
- fns[hook.key] = fn;
88
- }
89
- stubs(stub);
90
- return fns;
91
- }, [stubs]);
92
- const contextValue = useMemo(() => {
93
- async function execute(request, dispatch, schema) {
94
- let stub = collectedStubs[request.key];
95
- if (!!stub) {
96
- try {
97
- await stub(request.params, request.data, dispatch);
98
- }
99
- catch (e) {
100
- dispatch(error(e));
101
- }
102
- }
103
- else {
104
- dispatch(init());
105
- }
106
- }
107
- return {
108
- state,
109
- dispatch,
110
- filteredState: state,
111
- configs,
112
- execute,
113
- };
114
- }, [state, dispatch, configs, collectedStubs]);
115
- return _jsx(Context.Provider, { value: contextValue, children: children });
116
- }
117
- /**
118
- * StatusTrap component is used to track and manage network request states.
119
- *
120
- * @param {Object} props - The properties object.
121
- * @param {React.ReactNode} props.children - The child elements to be rendered.
122
- * @param {string} props.type - The type of network state to handle ("error", "pending", "pending + error").
123
- * @param {boolean} [props.propagate=true] - Whether to propagate the event to the parent context.
124
- * @return {React.ReactElement} The context provider component with filtered state and custom dispatch.
125
- */
126
- export function StatusTrap({ children, type, propagate = true, }) {
127
- const ctx = useContext(Context);
128
- const [requests, setRequests] = useState([]);
129
- const shouldHandleEvent = useCallback((state) => {
130
- switch (type) {
131
- case 'error':
132
- return isError(state);
133
- case 'pending':
134
- return isPending(state);
135
- case 'pending + error':
136
- return isPending(state) || isError(state);
137
- default:
138
- return false;
139
- }
140
- }, [type]);
141
- const dispatch = useCallback((event) => {
142
- if (!event.handled) {
143
- if (shouldHandleEvent(event.state)) {
144
- setRequests((prev) => [...prev, event.key]);
145
- if (!propagate) {
146
- ctx.dispatch({
147
- ...event,
148
- handled: true,
149
- });
150
- return;
151
- }
152
- }
153
- else {
154
- setRequests((prev) => prev.filter((k) => k !== event.key));
155
- }
156
- }
157
- ctx.dispatch(event);
158
- }, [ctx, propagate, shouldHandleEvent]);
159
- const filteredState = useMemo(() => {
160
- return Object.fromEntries(Object.entries(ctx.state).filter(([key]) => requests.includes(key)));
161
- }, [ctx.state, requests]);
162
- return (_jsx(Context.Provider, { value: {
163
- ...ctx,
164
- dispatch,
165
- filteredState,
166
- }, children: children }));
167
- }
168
- /**
169
- * useNetworkState is a custom hook that manages the network state within the specified context.
170
- * It handles making network requests, dispatching appropriate states based on the request lifecycle,
171
- * and allows aborting ongoing requests.
172
- *
173
- * @param {Object} params - The parameters required to configure and use the network state.
174
- * @param {string} params.key - A unique identifier for the network request.
175
- * @param {string} params.operation - The operation type related to the request.
176
- * @param {string} params.source - The source or endpoint for the network request.
177
- * @param {Object} params.schema - The schema used for validating the response data.
178
- * @param {number} [params.debounceDelay] - The debounce delay for executing the network request.
179
- *
180
- * @return {[NetworkState<T>, (request: AxiosRequestConfig) => void, () => void]}
181
- * Returns a state object representing the current network state,
182
- * a function to execute the network request, and a function to clear the request.
183
- */
184
- export function useNetworkState({ key, operation, source, schema, errorSchema, debounceDelay: requestDebounceDelay, }) {
185
- const context = useContext(Context);
186
- const [abortController, setAbortController] = useState();
187
- const networkState = useMemo(() => {
188
- return (context.state?.[`${source}:${operation}:${key}`] ??
189
- init());
190
- }, [context.state?.[`${source}:${operation}:${key}`]]);
191
- const dispatch = useCallback((state) => {
192
- context.dispatch({ key, operation, source, state });
193
- }, [key, operation, source, context.dispatch]);
194
- const debounceDelay = useMemo(() => {
195
- return requestDebounceDelay ?? context.configs?.debounceDelay ?? 0;
196
- }, [context.configs, requestDebounceDelay]);
197
- const execute = useCallback(async (request) => {
198
- let abortController = new AbortController();
199
- setAbortController(abortController);
200
- let requestConfig = {
201
- ...request,
202
- onUploadProgress(event) {
203
- dispatch(pending({
204
- type: 'upload',
205
- loaded: event.loaded,
206
- total: event.total,
207
- }));
208
- request.onUploadProgress?.(event);
209
- },
210
- onDownloadProgress(event) {
211
- dispatch(pending({
212
- type: 'download',
213
- loaded: event.loaded,
214
- total: event.total,
215
- }));
216
- request.onDownloadProgress?.(event);
217
- },
218
- signal: abortController.signal,
219
- };
220
- await context.execute(requestConfig, dispatch, schema, errorSchema);
221
- }, [networkState, context.dispatch, axios]);
222
- const deboundedExecute = useMemo(() => debounce(execute, debounceDelay ?? 0), [execute]);
223
- const clear = useCallback(() => {
224
- dispatch(init());
225
- setAbortController((abortController) => {
226
- abortController?.abort();
227
- return undefined;
228
- });
229
- }, [dispatch, abortController]);
230
- return [networkState, deboundedExecute, clear, dispatch];
231
- }
232
- function debounce(func, delay) {
233
- let timeoutId;
234
- return (...args) => {
235
- if (timeoutId) {
236
- clearTimeout(timeoutId);
237
- }
238
- timeoutId = setTimeout(() => {
239
- func(...args);
240
- }, delay);
241
- };
242
- }
243
- /**
244
- * Handles central error extraction from the provided context.
245
- * It filters the state to retain error states and maps them to a structured error object with additional context information.
246
- * @return {Object[]} An array of objects representing the error states with context information such as source, operation, and key.
247
- */
248
- export function useCentralError() {
249
- const ctx = useContext(Context);
250
- return useMemo(() => {
251
- return Object.entries(ctx.filteredState)
252
- .filter(([, state]) => isError(state))
253
- .map(([k, state]) => {
254
- let [source, operation, key] = k.split(':');
255
- return {
256
- ...state,
257
- source,
258
- operation,
259
- key,
260
- };
261
- });
262
- }, [ctx.filteredState]);
263
- }
264
- /**
265
- * Uses central pending state handling by aggregating pending states from context.
266
- * It calculates the overall progress of pending states if any, or returns an initial state otherwise.
267
- *
268
- * @return {NetworkState} The aggregated network state based on the pending states and their progress.
269
- */
270
- export function useCentralPendingState() {
271
- const ctx = useContext(Context);
272
- const result = useMemo(() => {
273
- let pendingStates = Object.values(ctx.filteredState).filter(isPending);
274
- if (!pendingStates.length) {
275
- return init();
276
- }
277
- let progress = pendingStates
278
- .filter((a) => a.progress)
279
- .reduce((progress, current) => {
280
- return {
281
- total: progress.total + (current.progress?.total ?? 0),
282
- loaded: progress.loaded + (current.progress?.loaded ?? 0),
283
- };
284
- }, { total: 0, loaded: 0 });
285
- return pending(!!progress.total ? progress : undefined);
286
- }, [ctx.filteredState]);
287
- return result;
288
- }
289
- //# sourceMappingURL=intrig-provider.js.map
@@ -1 +0,0 @@
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,C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AC1D,CAAC;QACJ,CAAC,EACD,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAqB,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"}
@@ -1,3 +0,0 @@
1
- import { ZodSchema } from 'zod';
2
- export declare function transform<T>(request: Request, mediaType: string, schema: ZodSchema): Promise<T>;
3
- export declare function transformResponse<T>(data: any, mediaType: string, schema: ZodSchema): Promise<T>;
@@ -1,89 +0,0 @@
1
- import { XMLParser } from 'fast-xml-parser';
2
- const encoders = {};
3
- function encode(request, mediaType, schema) {
4
- if (encoders[mediaType]) {
5
- return encoders[mediaType](request, mediaType, schema);
6
- }
7
- return request;
8
- }
9
- encoders['application/json'] = async (request, mediaType, schema) => {
10
- return request;
11
- };
12
- encoders['multipart/form-data'] = async (request, mediaType, schema) => {
13
- let formData = new FormData();
14
- for (let key in request) {
15
- const value = request[key];
16
- formData.append(key, value instanceof Blob || typeof value === 'string' ? value : String(value));
17
- }
18
- return formData;
19
- };
20
- encoders['application/octet-stream'] = async (request, mediaType, schema) => {
21
- return request;
22
- };
23
- encoders['application/x-www-form-urlencoded'] = async (request, mediaType, schema) => {
24
- let formData = new FormData();
25
- for (let key in request) {
26
- const value = request[key];
27
- formData.append(key, value instanceof Blob || typeof value === 'string' ? value : String(value));
28
- }
29
- return formData;
30
- };
31
- const transformers = {};
32
- export function transform(request, mediaType, schema) {
33
- if (transformers[mediaType]) {
34
- return transformers[mediaType](request, mediaType, schema);
35
- }
36
- throw new Error(`Unsupported media type: ` + mediaType);
37
- }
38
- transformers['application/json'] = async (request, mediaType, schema) => {
39
- return schema.parse(await request.json());
40
- };
41
- transformers['multipart/form-data'] = async (request, mediaType, schema) => {
42
- let formData = await request.formData();
43
- let content = {};
44
- formData.forEach((value, key) => (content[key] = value));
45
- return schema.parse(content);
46
- };
47
- transformers['application/octet-stream'] = async (request, mediaType, schema) => {
48
- return schema.parse(new Blob([await request.arrayBuffer()], {
49
- type: 'application/octet-stream',
50
- }));
51
- };
52
- transformers['application/x-www-form-urlencoded'] = async (request, mediaType, schema) => {
53
- let formData = await request.formData();
54
- let content = {};
55
- formData.forEach((value, key) => (content[key] = value));
56
- return schema.parse(content);
57
- };
58
- transformers['application/xml'] = async (request, mediaType, schema) => {
59
- let xmlParser = new XMLParser();
60
- let content = await xmlParser.parse(await request.text());
61
- return schema.parse(await content);
62
- };
63
- transformers['text/plain'] = async (request, mediaType, schema) => {
64
- return schema.parse(await request.text());
65
- };
66
- transformers['text/html'] = async (request, mediaType, schema) => {
67
- return schema.parse(await request.text());
68
- };
69
- transformers['text/css'] = async (request, mediaType, schema) => {
70
- return schema.parse(await request.text());
71
- };
72
- transformers['text/javascript'] = async (request, mediaType, schema) => {
73
- return schema.parse(await request.text());
74
- };
75
- const responseTransformers = {};
76
- responseTransformers['application/json'] = async (data, mediaType, schema) => {
77
- return schema.parse(data);
78
- };
79
- responseTransformers['application/xml'] = async (data, mediaType, schema) => {
80
- let parsed = new XMLParser().parse(data);
81
- return schema.parse(parsed);
82
- };
83
- export async function transformResponse(data, mediaType, schema) {
84
- if (responseTransformers[mediaType]) {
85
- return await responseTransformers[mediaType](data, mediaType, schema);
86
- }
87
- return data;
88
- }
89
- //# sourceMappingURL=media-type-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"media-type-utils.js","sourceRoot":"","sources":["../../../../lib/client-next/src/media-type-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,QAAQ,GAAa,EAAE,CAAC;AAE9B,SAAS,MAAM,CAAI,OAAU,EAAE,SAAiB,EAAE,MAAiB;IACjE,IAAI,Q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O,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE;IAC9D,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,YAAY,CAAC,iBAAiB,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE;IACrE,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC;AAUF,MAAM,oBAAoB,GAAyB,EAAE,CAAC;AAEtD,oBAAoB,CAAC,kBAAkB,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE;IAC3E,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC,CAAC;AAEF,oBAAoB,CAAC,iBAAiB,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE;IAC1E,IAAI,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAS,EACT,SAAiB,EACjB,MAAiB;IAEjB,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;QACpC,OAAO,MAAM,oBAAoB,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -1,185 +0,0 @@
1
- /**
2
- * Checks whether the state is init state
3
- * @param state
4
- */
5
- export function isInit(state) {
6
- return state.state === 'init';
7
- }
8
- /**
9
- * Initializes a new state.
10
- *
11
- * @template T The type of the state.
12
- * @return {InitState<T>} An object representing the initial state.
13
- */
14
- export function init() {
15
- return {
16
- state: 'init',
17
- };
18
- }
19
- /**
20
- * Checks whether the state is pending state
21
- * @param state
22
- */
23
- export function isPending(state) {
24
- return state.state === 'pending';
25
- }
26
- /**
27
- * Generates a PendingState object with a state of "pending".
28
- *
29
- * @return {PendingState<T>} An object representing the pending state.
30
- */
31
- export function pending(progress = undefined) {
32
- return {
33
- state: 'pending',
34
- progress,
35
- };
36
- }
37
- /**
38
- * Checks whether the state is success response
39
- * @param state
40
- */
41
- export function isSuccess(state) {
42
- return state.state === 'success';
43
- }
44
- /**
45
- * Creates a success state object with the provided data.
46
- *
47
- * @param {T} data - The data to be included in the success state.
48
- * @return {SuccessState<T>} An object representing a success state containing the provided data.
49
- */
50
- export function success(data) {
51
- return {
52
- state: 'success',
53
- data,
54
- };
55
- }
56
- /**
57
- * Checks whether the state is error state
58
- * @param state
59
- */
60
- export function isError(state) {
61
- return state.state === 'error';
62
- }
63
- /**
64
- * Constructs an ErrorState object representing an error.
65
- *
66
- * @param {any} error - The error object or message.
67
- * @param {string} [statusCode] - An optional status code associated with the error.
68
- * @return {ErrorState<T>} An object representing the error state.
69
- */
70
- export function error(error, statusCode, request) {
71
- return {
72
- state: 'error',
73
- error,
74
- statusCode,
75
- request,
76
- };
77
- }
78
- /**
79
- * Indicates a successful dispatch state.
80
- *
81
- * @return {DispatchState<T>} An object representing a successful state.
82
- */
83
- export function successfulDispatch() {
84
- return {
85
- state: 'success'
86
- };
87
- }
88
- /**
89
- * Determines if the provided dispatch state represents a successful dispatch.
90
- *
91
- * @param {DispatchState<T>} value - The dispatch state to check.
92
- * @return {value is SuccessfulDispatch<T>} - True if the dispatch state indicates success, false otherwise.
93
- */
94
- export function isSuccessfulDispatch(value) {
95
- return value.state === 'success';
96
- }
97
- /**
98
- * Generates a ValidationError object.
99
- *
100
- * @param error The error details that caused the validation to fail.
101
- * @return The ValidationError object containing the error state and details.
102
- */
103
- export function validationError(error) {
104
- return {
105
- state: 'validation-error',
106
- error
107
- };
108
- }
109
- /**
110
- * Determines if a provided DispatchState object is a ValidationError.
111
- *
112
- * @param {DispatchState<T>} value - The DispatchState object to evaluate.
113
- * @return {boolean} - Returns true if the provided DispatchState object is a ValidationError, otherwise returns false.
114
- */
115
- export function isValidationError(value) {
116
- return value.state === 'validation-error';
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
- }
185
- //# sourceMappingURL=network-state.js.map
@@ -1 +0,0 @@
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;AAgFD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,KAAK,EAAE,SAAS;KACjB,CAAA;AACH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