@intrig/react 0.0.15-26 → 0.0.15-27
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/index.esm.js +48 -4
- package/package.json +1 -1
- package/src/intrig-provider.d.ts +12 -0
- package/src/intrig-provider.d.ts.map +1 -1
package/index.esm.js
CHANGED
|
@@ -4004,7 +4004,7 @@ function IntrigProvider({
|
|
|
4004
4004
|
children: children
|
|
4005
4005
|
}, void 0, false, {
|
|
4006
4006
|
fileName: _jsxFileName,
|
|
4007
|
-
lineNumber:
|
|
4007
|
+
lineNumber: 217,
|
|
4008
4008
|
columnNumber: 10
|
|
4009
4009
|
}, this);
|
|
4010
4010
|
}
|
|
@@ -4050,7 +4050,7 @@ function IntrigProviderStub({
|
|
|
4050
4050
|
children: children
|
|
4051
4051
|
}, void 0, false, {
|
|
4052
4052
|
fileName: _jsxFileName,
|
|
4053
|
-
lineNumber:
|
|
4053
|
+
lineNumber: 301,
|
|
4054
4054
|
columnNumber: 10
|
|
4055
4055
|
}, this);
|
|
4056
4056
|
}
|
|
@@ -4109,7 +4109,7 @@ function StatusTrap({
|
|
|
4109
4109
|
children: children
|
|
4110
4110
|
}, void 0, false, {
|
|
4111
4111
|
fileName: _jsxFileName,
|
|
4112
|
-
lineNumber:
|
|
4112
|
+
lineNumber: 371,
|
|
4113
4113
|
columnNumber: 5
|
|
4114
4114
|
}, this);
|
|
4115
4115
|
}
|
|
@@ -4255,6 +4255,50 @@ function useCentralPendingState() {
|
|
|
4255
4255
|
return result;
|
|
4256
4256
|
}
|
|
4257
4257
|
|
|
4258
|
+
/**
|
|
4259
|
+
* A hook for making transient calls that can be aborted and validated against schemas.
|
|
4260
|
+
* Returns a promise-based call function and an abort function.
|
|
4261
|
+
*
|
|
4262
|
+
* @param schema - Optional Zod schema for validating the response
|
|
4263
|
+
* @param errorSchema - Optional Zod schema for validating error responses
|
|
4264
|
+
* @returns A tuple of [call function, abort function]
|
|
4265
|
+
*/
|
|
4266
|
+
function useTransitionCall({
|
|
4267
|
+
schema,
|
|
4268
|
+
errorSchema
|
|
4269
|
+
}) {
|
|
4270
|
+
const ctx = useContext(Context);
|
|
4271
|
+
const controller = useRef(undefined);
|
|
4272
|
+
const schemaRef = useRef(schema);
|
|
4273
|
+
const errorSchemaRef = useRef(errorSchema);
|
|
4274
|
+
useEffect(() => {
|
|
4275
|
+
schemaRef.current = schema;
|
|
4276
|
+
errorSchemaRef.current = errorSchema;
|
|
4277
|
+
});
|
|
4278
|
+
const call = useCallback(async request => {
|
|
4279
|
+
var _controller$current;
|
|
4280
|
+
(_controller$current = controller.current) == null || _controller$current.abort();
|
|
4281
|
+
const abort = new AbortController();
|
|
4282
|
+
controller.current = abort;
|
|
4283
|
+
return new Promise((resolve, reject) => {
|
|
4284
|
+
ctx.execute(Object.assign({}, request, {
|
|
4285
|
+
signal: abort.signal
|
|
4286
|
+
}), state => {
|
|
4287
|
+
if (isSuccess(state)) {
|
|
4288
|
+
resolve(state.data);
|
|
4289
|
+
} else if (isError(state)) {
|
|
4290
|
+
reject(state.error);
|
|
4291
|
+
}
|
|
4292
|
+
}, schemaRef.current, errorSchemaRef.current);
|
|
4293
|
+
});
|
|
4294
|
+
}, [ctx]);
|
|
4295
|
+
const abort = useCallback(() => {
|
|
4296
|
+
var _controller$current2;
|
|
4297
|
+
(_controller$current2 = controller.current) == null || _controller$current2.abort();
|
|
4298
|
+
}, []);
|
|
4299
|
+
return [call, abort];
|
|
4300
|
+
}
|
|
4301
|
+
|
|
4258
4302
|
/**
|
|
4259
4303
|
* Converts a given hook into a promise-based function.
|
|
4260
4304
|
*
|
|
@@ -4824,4 +4868,4 @@ async function transformResponse(data, mediaType, schema) {
|
|
|
4824
4868
|
return data;
|
|
4825
4869
|
}
|
|
4826
4870
|
|
|
4827
|
-
export { IntrigProvider, IntrigProviderStub, StatusTrap, encode, error, init, isError, isInit, isNetworkError, isPending, isRequestValidationError, isResponseValidationError, isSuccess, isSuccessfulDispatch, isValidationError, networkError, pending, requestValidationError, responseValidationError, success, successfulDispatch, transform, transformResponse, useAsNetworkState, useAsPromise, useCentralError, useCentralPendingState, useNetworkState, useResolvedCachedValue, useResolvedValue, validationError };
|
|
4871
|
+
export { IntrigProvider, IntrigProviderStub, StatusTrap, encode, error, init, isError, isInit, isNetworkError, isPending, isRequestValidationError, isResponseValidationError, isSuccess, isSuccessfulDispatch, isValidationError, networkError, pending, requestValidationError, responseValidationError, success, successfulDispatch, transform, transformResponse, useAsNetworkState, useAsPromise, useCentralError, useCentralPendingState, useNetworkState, useResolvedCachedValue, useResolvedValue, useTransitionCall, validationError };
|
package/package.json
CHANGED
package/src/intrig-provider.d.ts
CHANGED
|
@@ -101,4 +101,16 @@ export declare function useCentralError(): {
|
|
|
101
101
|
* @return {NetworkState} The aggregated network state based on the pending states and their progress.
|
|
102
102
|
*/
|
|
103
103
|
export declare function useCentralPendingState(): NetworkState<unknown, unknown>;
|
|
104
|
+
/**
|
|
105
|
+
* A hook for making transient calls that can be aborted and validated against schemas.
|
|
106
|
+
* Returns a promise-based call function and an abort function.
|
|
107
|
+
*
|
|
108
|
+
* @param schema - Optional Zod schema for validating the response
|
|
109
|
+
* @param errorSchema - Optional Zod schema for validating error responses
|
|
110
|
+
* @returns A tuple of [call function, abort function]
|
|
111
|
+
*/
|
|
112
|
+
export declare function useTransitionCall<T>({ schema, errorSchema, }: {
|
|
113
|
+
schema?: ZodSchema<T>;
|
|
114
|
+
errorSchema?: ZodSchema<any>;
|
|
115
|
+
}): [(request: RequestType) => Promise<T>, () => void];
|
|
104
116
|
//# sourceMappingURL=intrig-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intrig-provider.d.ts","sourceRoot":"","sources":["../../../lib/src/intrig-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,iBAAiB,
|
|
1
|
+
{"version":3,"file":"intrig-provider.d.ts","sourceRoot":"","sources":["../../../lib/src/intrig-provider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