@intrig/react 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.
- package/.babelrc +12 -0
- package/README.md +20 -18
- package/eslint.config.cjs +12 -0
- package/package.json +5 -6
- package/project.json +9 -0
- package/rollup.config.cjs +28 -0
- package/src/extra/{index.d.ts → index.ts} +2 -2
- package/src/extra/useAsNetworkState.ts +53 -0
- package/src/extra/{useAsPromise.d.ts → useAsPromise.ts} +58 -7
- package/src/extra/{useResolvedCachedValue.d.ts → useResolvedCachedValue.ts} +39 -7
- package/src/extra/{useResolvedValue.d.ts → useResolvedValue.ts} +39 -7
- package/src/{index.d.ts → index.ts} +2 -2
- package/src/intrig-context.ts +66 -0
- package/src/intrig-provider.tsx +449 -0
- package/src/logger.ts +13 -0
- package/src/media-type-utils.ts +184 -0
- package/src/{network-state.d.ts → network-state.tsx} +172 -91
- package/tsconfig.json +27 -0
- package/tsconfig.lib.json +32 -0
- package/tsconfig.spec.json +26 -0
- package/vite.config.ts +25 -0
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -3856
- package/src/extra/useAsNetworkState.d.ts +0 -13
- package/src/intrig-context.d.ts +0 -43
- package/src/intrig-provider.d.ts +0 -101
- package/src/media-type-utils.d.ts +0 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ZodError } from 'zod';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* State of an asynchronous call. Network state follows the state diagram given below.
|
|
4
5
|
*
|
|
@@ -23,33 +24,44 @@ import { ZodError } from 'zod';
|
|
|
23
24
|
* </pre>
|
|
24
25
|
*/
|
|
25
26
|
export interface NetworkState<T = unknown, E = unknown> {
|
|
26
|
-
|
|
27
|
+
state: 'init' | 'pending' | 'success' | 'error';
|
|
27
28
|
}
|
|
29
|
+
|
|
28
30
|
/**
|
|
29
31
|
* Network call is not yet started
|
|
30
32
|
*/
|
|
31
33
|
export interface InitState<T, E = unknown> extends NetworkState<T, E> {
|
|
32
|
-
|
|
34
|
+
state: 'init';
|
|
33
35
|
}
|
|
36
|
+
|
|
34
37
|
/**
|
|
35
38
|
* Checks whether the state is init state
|
|
36
39
|
* @param state
|
|
37
40
|
*/
|
|
38
|
-
export
|
|
41
|
+
export function isInit<T, E = unknown>(state: NetworkState<T, E>): state is InitState<T, E> {
|
|
42
|
+
return state.state === 'init';
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
/**
|
|
40
46
|
* Initializes a new state.
|
|
41
47
|
*
|
|
42
48
|
* @template T The type of the state.
|
|
43
49
|
* @return {InitState<T>} An object representing the initial state.
|
|
44
50
|
*/
|
|
45
|
-
export
|
|
51
|
+
export function init<T, E = unknown>(): InitState<T, E> {
|
|
52
|
+
return {
|
|
53
|
+
state: 'init',
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
46
57
|
/**
|
|
47
58
|
* Network call is not yet completed
|
|
48
59
|
*/
|
|
49
60
|
export interface PendingState<T, E = unknown> extends NetworkState<T, E> {
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
state: 'pending';
|
|
62
|
+
progress?: Progress;
|
|
52
63
|
}
|
|
64
|
+
|
|
53
65
|
/**
|
|
54
66
|
* Interface representing progress information for an upload or download operation.
|
|
55
67
|
*
|
|
@@ -62,54 +74,80 @@ export interface PendingState<T, E = unknown> extends NetworkState<T, E> {
|
|
|
62
74
|
* @property {number} [total] - The total amount of data to be loaded (if known).
|
|
63
75
|
*/
|
|
64
76
|
export interface Progress {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
type?: 'upload' | 'download';
|
|
78
|
+
loaded: number;
|
|
79
|
+
total?: number;
|
|
68
80
|
}
|
|
81
|
+
|
|
69
82
|
/**
|
|
70
83
|
* Checks whether the state is pending state
|
|
71
84
|
* @param state
|
|
72
85
|
*/
|
|
73
|
-
export
|
|
86
|
+
export function isPending<T, E = unknown>(state: NetworkState<T, E>): state is PendingState<T, E> {
|
|
87
|
+
return state.state === 'pending';
|
|
88
|
+
}
|
|
89
|
+
|
|
74
90
|
/**
|
|
75
91
|
* Generates a PendingState object with a state of "pending".
|
|
76
92
|
*
|
|
77
93
|
* @return {PendingState<T>} An object representing the pending state.
|
|
78
94
|
*/
|
|
79
|
-
export
|
|
95
|
+
export function pending<T, E = unknown>(
|
|
96
|
+
progress: Progress | undefined = undefined
|
|
97
|
+
): PendingState<T, E> {
|
|
98
|
+
return {
|
|
99
|
+
state: 'pending',
|
|
100
|
+
progress,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
80
104
|
/**
|
|
81
105
|
* Network call is completed with success state
|
|
82
106
|
*/
|
|
83
107
|
export interface SuccessState<T, E = unknown> extends NetworkState<T, E> {
|
|
84
|
-
|
|
85
|
-
|
|
108
|
+
state: 'success';
|
|
109
|
+
data: T;
|
|
86
110
|
}
|
|
111
|
+
|
|
87
112
|
/**
|
|
88
113
|
* Checks whether the state is success response
|
|
89
114
|
* @param state
|
|
90
115
|
*/
|
|
91
|
-
export
|
|
116
|
+
export function isSuccess<T, E = unknown>(state: NetworkState<T, E>): state is SuccessState<T, E> {
|
|
117
|
+
return state.state === 'success';
|
|
118
|
+
}
|
|
119
|
+
|
|
92
120
|
/**
|
|
93
121
|
* Creates a success state object with the provided data.
|
|
94
122
|
*
|
|
95
123
|
* @param {T} data - The data to be included in the success state.
|
|
96
124
|
* @return {SuccessState<T>} An object representing a success state containing the provided data.
|
|
97
125
|
*/
|
|
98
|
-
export
|
|
126
|
+
export function success<T, E = unknown>(data: T): SuccessState<T, E> {
|
|
127
|
+
return {
|
|
128
|
+
state: 'success',
|
|
129
|
+
data,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
99
133
|
/**
|
|
100
134
|
* Network call is completed with error response
|
|
101
135
|
*/
|
|
102
136
|
export interface ErrorState<T, E = unknown> extends NetworkState<T, E> {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
137
|
+
state: 'error';
|
|
138
|
+
error: E;
|
|
139
|
+
statusCode?: number;
|
|
140
|
+
request?: any;
|
|
107
141
|
}
|
|
142
|
+
|
|
108
143
|
/**
|
|
109
144
|
* Checks whether the state is error state
|
|
110
145
|
* @param state
|
|
111
146
|
*/
|
|
112
|
-
export
|
|
147
|
+
export function isError<T, E = unknown>(state: NetworkState<T, E>): state is ErrorState<T, E> {
|
|
148
|
+
return state.state === 'error';
|
|
149
|
+
}
|
|
150
|
+
|
|
113
151
|
/**
|
|
114
152
|
* Constructs an ErrorState object representing an error.
|
|
115
153
|
*
|
|
@@ -117,7 +155,19 @@ export declare function isError<T, E = unknown>(state: NetworkState<T, E>): stat
|
|
|
117
155
|
* @param {string} [statusCode] - An optional status code associated with the error.
|
|
118
156
|
* @return {ErrorState<T>} An object representing the error state.
|
|
119
157
|
*/
|
|
120
|
-
export
|
|
158
|
+
export function error<T, E = unknown>(
|
|
159
|
+
error: E,
|
|
160
|
+
statusCode?: number,
|
|
161
|
+
request?: any
|
|
162
|
+
): ErrorState<T> {
|
|
163
|
+
return {
|
|
164
|
+
state: 'error',
|
|
165
|
+
error,
|
|
166
|
+
statusCode,
|
|
167
|
+
request,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
121
171
|
/**
|
|
122
172
|
* Represents an error state with additional contextual information.
|
|
123
173
|
*
|
|
@@ -130,10 +180,11 @@ export declare function error<T, E = unknown>(error: E, statusCode?: number, req
|
|
|
130
180
|
* @property {string} key - A unique key identifying the specific error instance.
|
|
131
181
|
*/
|
|
132
182
|
export interface ErrorWithContext<T = unknown, E = unknown> extends ErrorState<T, E> {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
183
|
+
source: string;
|
|
184
|
+
operation: string;
|
|
185
|
+
key: string;
|
|
136
186
|
}
|
|
187
|
+
|
|
137
188
|
/**
|
|
138
189
|
* Represents an action in the network context.
|
|
139
190
|
*
|
|
@@ -143,54 +194,33 @@ export interface ErrorWithContext<T = unknown, E = unknown> extends ErrorState<T
|
|
|
143
194
|
* @property {string} key - The unique identifier for the network action
|
|
144
195
|
*/
|
|
145
196
|
export interface NetworkAction<T, E> {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
197
|
+
key: string;
|
|
198
|
+
source: string;
|
|
199
|
+
operation: string;
|
|
200
|
+
state: NetworkState<T, E>;
|
|
201
|
+
handled?: boolean;
|
|
151
202
|
}
|
|
203
|
+
|
|
152
204
|
type HookWithKey = {
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
clearOnUnmount?: boolean;
|
|
159
|
-
} | {
|
|
160
|
-
key?: string;
|
|
161
|
-
fetchOnMount: true;
|
|
162
|
-
params?: Record<string, any>;
|
|
163
|
-
clearOnUnmount?: boolean;
|
|
164
|
-
};
|
|
205
|
+
key: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
export type UnitHookOptions = { key?: string; fetchOnMount?: false; clearOnUnmount?: boolean } | { key?: string; fetchOnMount: true; params?: Record<string, any>; clearOnUnmount?: boolean };
|
|
165
210
|
export type UnitHook<E = unknown> = ((options: UnitHookOptions) => [NetworkState<never, E>, (params?: Record<string, any>) => DispatchState<any>, () => void]) & HookWithKey;
|
|
166
211
|
export type ConstantHook<T, E = unknown> = ((options: UnitHookOptions) => [NetworkState<T, E>, (params?: Record<string, any>) => DispatchState<any>, () => void]) & HookWithKey;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
fetchOnMount?: false;
|
|
170
|
-
clearOnUnmount?: boolean;
|
|
171
|
-
} | {
|
|
172
|
-
key?: string;
|
|
173
|
-
fetchOnMount: true;
|
|
174
|
-
params: P;
|
|
175
|
-
clearOnUnmount?: boolean;
|
|
176
|
-
};
|
|
212
|
+
|
|
213
|
+
export type UnaryHookOptions<P> = { key?: string, fetchOnMount?: false, clearOnUnmount?: boolean } | { key?: string, fetchOnMount: true, params: P, clearOnUnmount?: boolean };
|
|
177
214
|
export type UnaryProduceHook<P, E = unknown> = ((options?: UnaryHookOptions<P>) => [NetworkState<never, E>, (params: P) => DispatchState<any>, () => void]) & HookWithKey;
|
|
178
215
|
export type UnaryFunctionHook<P, T, E = unknown> = ((options?: UnaryHookOptions<P>) => [NetworkState<T, E>, (params: P) => DispatchState<any>, () => void]) & HookWithKey;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
fetchOnMount?: false;
|
|
182
|
-
clearOnUnmount?: boolean;
|
|
183
|
-
} | {
|
|
184
|
-
key?: string;
|
|
185
|
-
fetchOnMount: true;
|
|
186
|
-
params: P;
|
|
187
|
-
body: B;
|
|
188
|
-
clearOnUnmount?: boolean;
|
|
189
|
-
};
|
|
216
|
+
|
|
217
|
+
export type BinaryHookOptions<P, B> = { key?: string, fetchOnMount?: false, clearOnUnmount?: boolean } | { key?: string, fetchOnMount: true, params: P, body: B, clearOnUnmount?: boolean };
|
|
190
218
|
export type BinaryProduceHook<P, B, E = unknown> = ((options?: BinaryHookOptions<P, B>) => [NetworkState<never, E>, (body: B, params: P) => DispatchState<any>, () => void]) & HookWithKey;
|
|
191
219
|
export type BinaryFunctionHook<P, B, T, E = unknown> = ((options?: BinaryHookOptions<P, B>) => [NetworkState<T, E>, (body: B, params: P) => DispatchState<any>, () => void]) & HookWithKey;
|
|
220
|
+
|
|
192
221
|
export type IntrigHookOptions<P = undefined, B = undefined> = UnitHookOptions | UnaryHookOptions<P> | BinaryHookOptions<P, B>;
|
|
193
222
|
export type IntrigHook<P = undefined, B = undefined, T = any, E = unknown> = UnitHook<E> | ConstantHook<T, E> | UnaryProduceHook<P, E> | UnaryFunctionHook<P, T, E> | BinaryProduceHook<P, B, E> | BinaryFunctionHook<P, B, T, E>;
|
|
223
|
+
|
|
194
224
|
/**
|
|
195
225
|
* Represents the dispatch state of a process.
|
|
196
226
|
*
|
|
@@ -200,8 +230,9 @@ export type IntrigHook<P = undefined, B = undefined, T = any, E = unknown> = Uni
|
|
|
200
230
|
* @property {string} state The current state of the dispatch process.
|
|
201
231
|
*/
|
|
202
232
|
export interface DispatchState<T> {
|
|
203
|
-
|
|
233
|
+
state: string
|
|
204
234
|
}
|
|
235
|
+
|
|
205
236
|
/**
|
|
206
237
|
* Represents a successful dispatch state.
|
|
207
238
|
*
|
|
@@ -211,46 +242,65 @@ export interface DispatchState<T> {
|
|
|
211
242
|
*
|
|
212
243
|
* @property {string} state - The state of the dispatch, always 'success'.
|
|
213
244
|
*/
|
|
214
|
-
export interface SuccessfulDispatch<T> extends DispatchState<T>
|
|
215
|
-
|
|
245
|
+
export interface SuccessfulDispatch<T> extends DispatchState<T>{
|
|
246
|
+
state: 'success'
|
|
216
247
|
}
|
|
248
|
+
|
|
217
249
|
/**
|
|
218
250
|
* Indicates a successful dispatch state.
|
|
219
251
|
*
|
|
220
252
|
* @return {DispatchState<T>} An object representing a successful state.
|
|
221
253
|
*/
|
|
222
|
-
export
|
|
254
|
+
export function successfulDispatch<T>(): DispatchState<T> {
|
|
255
|
+
return {
|
|
256
|
+
state: 'success'
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
223
260
|
/**
|
|
224
261
|
* Determines if the provided dispatch state represents a successful dispatch.
|
|
225
262
|
*
|
|
226
263
|
* @param {DispatchState<T>} value - The dispatch state to check.
|
|
227
264
|
* @return {value is SuccessfulDispatch<T>} - True if the dispatch state indicates success, false otherwise.
|
|
228
265
|
*/
|
|
229
|
-
export
|
|
266
|
+
export function isSuccessfulDispatch<T>(value: DispatchState<T>): value is SuccessfulDispatch<T> {
|
|
267
|
+
return value.state === 'success'
|
|
268
|
+
}
|
|
269
|
+
|
|
230
270
|
/**
|
|
231
271
|
* ValidationError interface represents a specific type of dispatch state
|
|
232
272
|
* where a validation error has occurred.
|
|
233
273
|
*
|
|
234
274
|
* @typeparam T - The type of the data associated with this dispatch state.
|
|
235
275
|
*/
|
|
236
|
-
export interface ValidationError<T> extends DispatchState<T>
|
|
237
|
-
|
|
238
|
-
|
|
276
|
+
export interface ValidationError<T> extends DispatchState<T>{
|
|
277
|
+
state: 'validation-error'
|
|
278
|
+
error: any
|
|
239
279
|
}
|
|
280
|
+
|
|
240
281
|
/**
|
|
241
282
|
* Generates a ValidationError object.
|
|
242
283
|
*
|
|
243
284
|
* @param error The error details that caused the validation to fail.
|
|
244
285
|
* @return The ValidationError object containing the error state and details.
|
|
245
286
|
*/
|
|
246
|
-
export
|
|
287
|
+
export function validationError<T>(error: any): ValidationError<T> {
|
|
288
|
+
return {
|
|
289
|
+
state: 'validation-error',
|
|
290
|
+
error
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
247
294
|
/**
|
|
248
295
|
* Determines if a provided DispatchState object is a ValidationError.
|
|
249
296
|
*
|
|
250
297
|
* @param {DispatchState<T>} value - The DispatchState object to evaluate.
|
|
251
298
|
* @return {boolean} - Returns true if the provided DispatchState object is a ValidationError, otherwise returns false.
|
|
252
299
|
*/
|
|
253
|
-
export
|
|
300
|
+
export function isValidationError<T>(value: DispatchState<T>): value is ValidationError<T> {
|
|
301
|
+
return value.state === 'validation-error'
|
|
302
|
+
}
|
|
303
|
+
|
|
254
304
|
/**
|
|
255
305
|
* Represents an error structure with a specified type and associated data.
|
|
256
306
|
*
|
|
@@ -260,8 +310,9 @@ export declare function isValidationError<T>(value: DispatchState<T>): value is
|
|
|
260
310
|
* @property {string} type - A string representing the type of the error.
|
|
261
311
|
*/
|
|
262
312
|
export interface IntrigError<T, E> {
|
|
263
|
-
|
|
313
|
+
type: string
|
|
264
314
|
}
|
|
315
|
+
|
|
265
316
|
/**
|
|
266
317
|
* Represents an error encountered during a network operation.
|
|
267
318
|
* Extends from the `IntrigError` interface, adding network-specific properties.
|
|
@@ -274,12 +325,13 @@ export interface IntrigError<T, E> {
|
|
|
274
325
|
* @property {E} error - The detailed error information specific to the failure, type extends from the generic E, allowing flexibility in the error details.
|
|
275
326
|
* @property {any} request - The request object that was attempted when the network error occurred, providing context for what operation failed.
|
|
276
327
|
*/
|
|
277
|
-
export interface NetworkError<T, E = unknown> extends IntrigError<T, E>
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
328
|
+
export interface NetworkError<T, E = unknown> extends IntrigError<T, E>{
|
|
329
|
+
type: 'network'
|
|
330
|
+
statusCode: string
|
|
331
|
+
error: E
|
|
332
|
+
request: any
|
|
282
333
|
}
|
|
334
|
+
|
|
283
335
|
/**
|
|
284
336
|
* Constructs a network error object.
|
|
285
337
|
*
|
|
@@ -288,14 +340,25 @@ export interface NetworkError<T, E = unknown> extends IntrigError<T, E> {
|
|
|
288
340
|
* @param request The request object associated with the network operation.
|
|
289
341
|
* @return A NetworkError object containing the error type, status code, error details, and the original request.
|
|
290
342
|
*/
|
|
291
|
-
export
|
|
343
|
+
export function networkError<T, E>(error: E, statusCode: string, request: any): NetworkError<T, E> {
|
|
344
|
+
return {
|
|
345
|
+
type: 'network',
|
|
346
|
+
statusCode,
|
|
347
|
+
error,
|
|
348
|
+
request
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
292
352
|
/**
|
|
293
353
|
* Determines if the provided IntrigError is of type 'network'.
|
|
294
354
|
*
|
|
295
355
|
* @param {IntrigError<T, E>} value - The error value to check the type of.
|
|
296
356
|
* @return {boolean} - Returns true if the error is of type 'network', otherwise false.
|
|
297
357
|
*/
|
|
298
|
-
export
|
|
358
|
+
export function isNetworkError<T, E>(value: IntrigError<T, E>): value is NetworkError<T, E> {
|
|
359
|
+
return value.type === 'network'
|
|
360
|
+
}
|
|
361
|
+
|
|
299
362
|
/**
|
|
300
363
|
* Interface representing a request validation error.
|
|
301
364
|
*
|
|
@@ -310,24 +373,34 @@ export declare function isNetworkError<T, E>(value: IntrigError<T, E>): value is
|
|
|
310
373
|
* @property {string} type - A string literal indicating the error type as 'request-validation'.
|
|
311
374
|
* @property {ZodError} error - An instance of ZodError containing detailed validation error information.
|
|
312
375
|
*/
|
|
313
|
-
export interface RequestValidationError<T, E = unknown> extends IntrigError<T, E>
|
|
314
|
-
|
|
315
|
-
|
|
376
|
+
export interface RequestValidationError<T, E = unknown> extends IntrigError<T, E>{
|
|
377
|
+
type: 'request-validation'
|
|
378
|
+
error: ZodError
|
|
316
379
|
}
|
|
380
|
+
|
|
317
381
|
/**
|
|
318
382
|
* Constructs a RequestValidationError object encapsulating the ZodError.
|
|
319
383
|
*
|
|
320
384
|
* @param {ZodError} error - The error object resulting from Zod schema validation.
|
|
321
385
|
* @return {RequestValidationError<T, E>} A RequestValidationError object containing the validation error information.
|
|
322
386
|
*/
|
|
323
|
-
export
|
|
387
|
+
export function requestValidationError<T, E>(error: ZodError): RequestValidationError<T, E> {
|
|
388
|
+
return {
|
|
389
|
+
type: 'request-validation',
|
|
390
|
+
error
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
324
394
|
/**
|
|
325
395
|
* Determines if a given error is of type RequestValidationError.
|
|
326
396
|
*
|
|
327
397
|
* @param value The error object to check, which implements the IntrigError interface.
|
|
328
398
|
* @return A boolean indicating whether the error is a RequestValidationError.
|
|
329
399
|
*/
|
|
330
|
-
export
|
|
400
|
+
export function isRequestValidationError<T, E>(value: IntrigError<T, E>): value is RequestValidationError<T, E> {
|
|
401
|
+
return value.type === 'request-validation'
|
|
402
|
+
}
|
|
403
|
+
|
|
331
404
|
/**
|
|
332
405
|
* ResponseValidationError interface is designed to extend the capabilities of the IntrigError interface,
|
|
333
406
|
* specifically for handling errors related to response validation.
|
|
@@ -340,22 +413,30 @@ export declare function isRequestValidationError<T, E>(value: IntrigError<T, E>)
|
|
|
340
413
|
* @property type - A string literal that identifies the type of error as 'response-validation'.
|
|
341
414
|
* @property error - An instance of ZodError representing the validation error encountered.
|
|
342
415
|
*/
|
|
343
|
-
export interface ResponseValidationError<T, E = unknown> extends IntrigError<T, E>
|
|
344
|
-
|
|
345
|
-
|
|
416
|
+
export interface ResponseValidationError<T, E = unknown> extends IntrigError<T, E>{
|
|
417
|
+
type: 'response-validation'
|
|
418
|
+
error: ZodError
|
|
346
419
|
}
|
|
420
|
+
|
|
347
421
|
/**
|
|
348
422
|
* Constructs a ResponseValidationError object with a specified error.
|
|
349
423
|
*
|
|
350
424
|
* @param {ZodError} error - The validation error encountered during response validation.
|
|
351
425
|
* @return {ResponseValidationError<T, E>} An error object containing the type of error and the validation error details.
|
|
352
426
|
*/
|
|
353
|
-
export
|
|
427
|
+
export function responseValidationError<T, E>(error: ZodError): ResponseValidationError<T, E> {
|
|
428
|
+
return {
|
|
429
|
+
type: 'response-validation',
|
|
430
|
+
error
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
354
434
|
/**
|
|
355
435
|
* Determines if the given error is a response validation error.
|
|
356
436
|
*
|
|
357
437
|
* @param {IntrigError<T, E>} value - The error object to assess.
|
|
358
438
|
* @return {boolean} True if the error is a response validation error, otherwise false.
|
|
359
439
|
*/
|
|
360
|
-
export
|
|
361
|
-
|
|
440
|
+
export function isResponseValidationError<T, E>(value: IntrigError<T, E>): value is ResponseValidationError<T, E> {
|
|
441
|
+
return value.type === 'response-validation'
|
|
442
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"baseUrl": ".",
|
|
11
|
+
"paths": {
|
|
12
|
+
"@intrig/react/*": ["./src/*"]
|
|
13
|
+
},
|
|
14
|
+
"jsx": "react-jsx"
|
|
15
|
+
},
|
|
16
|
+
"files": [],
|
|
17
|
+
"include": [],
|
|
18
|
+
"references": [
|
|
19
|
+
{
|
|
20
|
+
"path": "./tsconfig.lib.json"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "./tsconfig.spec.json"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"extends": "../../tsconfig.base.json"
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"node",
|
|
7
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
8
|
+
"@nx/react/typings/image.d.ts"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"**/*.spec.ts",
|
|
13
|
+
"**/*.test.ts",
|
|
14
|
+
"**/*.spec.tsx",
|
|
15
|
+
"**/*.test.tsx",
|
|
16
|
+
"**/*.spec.js",
|
|
17
|
+
"**/*.test.js",
|
|
18
|
+
"**/*.spec.jsx",
|
|
19
|
+
"**/*.test.jsx",
|
|
20
|
+
"vite.config.ts",
|
|
21
|
+
"vitest.config.ts",
|
|
22
|
+
"src/**/*.test.ts",
|
|
23
|
+
"src/**/*.spec.ts",
|
|
24
|
+
"src/**/*.test.tsx",
|
|
25
|
+
"src/**/*.spec.tsx",
|
|
26
|
+
"src/**/*.test.js",
|
|
27
|
+
"src/**/*.spec.js",
|
|
28
|
+
"src/**/*.test.jsx",
|
|
29
|
+
"src/**/*.spec.jsx"
|
|
30
|
+
],
|
|
31
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"vitest/globals",
|
|
7
|
+
"vitest/importMeta",
|
|
8
|
+
"vite/client",
|
|
9
|
+
"node",
|
|
10
|
+
"vitest"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"vite.config.ts",
|
|
15
|
+
"vitest.config.ts",
|
|
16
|
+
"src/**/*.test.ts",
|
|
17
|
+
"src/**/*.spec.ts",
|
|
18
|
+
"src/**/*.test.tsx",
|
|
19
|
+
"src/**/*.spec.tsx",
|
|
20
|
+
"src/**/*.test.js",
|
|
21
|
+
"src/**/*.spec.js",
|
|
22
|
+
"src/**/*.test.jsx",
|
|
23
|
+
"src/**/*.spec.jsx",
|
|
24
|
+
"src/**/*.d.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
4
|
+
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
root: __dirname,
|
|
8
|
+
cacheDir: '../../node_modules/.vite/lib/client-react',
|
|
9
|
+
plugins: [react(), nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
|
|
10
|
+
// Uncomment this if you are using workers.
|
|
11
|
+
// worker: {
|
|
12
|
+
// plugins: [ nxViteTsPaths() ],
|
|
13
|
+
// },
|
|
14
|
+
test: {
|
|
15
|
+
watch: false,
|
|
16
|
+
globals: true,
|
|
17
|
+
environment: 'jsdom',
|
|
18
|
+
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
19
|
+
reporters: ['default'],
|
|
20
|
+
coverage: {
|
|
21
|
+
reportsDirectory: '../../coverage/lib/client-react',
|
|
22
|
+
provider: 'v8',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|