@pixotope/query 0.6.0 → 0.8.0
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/.turbo/turbo-build.log +10 -10
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-test.log +11 -7
- package/CHANGELOG.md +13 -0
- package/dist/index.cjs +68 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -91
- package/dist/index.d.ts +50 -91
- package/dist/index.js +68 -71
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/factories.test.ts +65 -0
- package/src/factories.ts +48 -31
- package/src/proxyBinders.test.ts +42 -0
- package/src/proxyBinders.ts +8 -5
- package/src/useMutation.test.ts +106 -0
- package/src/useMutation.ts +87 -116
- package/src/useQuery.test.ts +77 -139
- package/src/useQuery.ts +5 -8
- package/src/useSubscription.test.ts +79 -0
- package/src/useSubscription.ts +23 -13
- package/src/useSubscriptionCore.ts +6 -3
- package/src/mock/useQuery.ts +0 -48
package/dist/index.js
CHANGED
|
@@ -183,63 +183,61 @@ var useMutation = (options) => {
|
|
|
183
183
|
};
|
|
184
184
|
const internalCallbackRef = useRef(internalCallbackRefistry);
|
|
185
185
|
internalCallbackRef.current = internalCallbackRefistry;
|
|
186
|
-
const mutateAsync = useCallback(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
)
|
|
186
|
+
const mutateAsync = useCallback((params2, meta) => __async(null, null, function* () {
|
|
187
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
188
|
+
setStatus("loading");
|
|
189
|
+
setError(null);
|
|
190
|
+
try {
|
|
191
|
+
const promises = [
|
|
192
|
+
mutationFnRef.current(
|
|
193
|
+
internalCallbackRef.current.prepareParams ? internalCallbackRef.current.prepareParams(
|
|
194
|
+
params2,
|
|
195
|
+
internalOptionsRef.current.params,
|
|
196
|
+
meta
|
|
197
|
+
) : params2,
|
|
198
|
+
meta
|
|
199
|
+
),
|
|
200
|
+
...internalOptionsRef.current.timeout ? [
|
|
201
|
+
new Promise(
|
|
202
|
+
(resolve) => setTimeout(
|
|
203
|
+
() => resolve("timeout"),
|
|
204
|
+
internalOptionsRef.current.timeout
|
|
206
205
|
)
|
|
207
|
-
|
|
208
|
-
]
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if ((_b = (_a = internalCallbackRef.current).compareOrThrow) == null ? void 0 : _b.call(_a, res)) {
|
|
214
|
-
throw new ComparisonFailError(JSON.stringify(res), res);
|
|
215
|
-
}
|
|
216
|
-
setResult(res);
|
|
217
|
-
setStatus("success");
|
|
218
|
-
(_d = (_c = internalCallbackRef.current).onSuccess) == null ? void 0 : _d.call(_c, res, params2);
|
|
219
|
-
(_f = (_e = internalCallbackRef.current).onSettled) == null ? void 0 : _f.call(_e, res, null, params2);
|
|
220
|
-
return res;
|
|
221
|
-
} catch (error2) {
|
|
222
|
-
setError(error2);
|
|
223
|
-
setStatus("error");
|
|
224
|
-
(_h = (_g = internalCallbackRef.current).onError) == null ? void 0 : _h.call(_g, error2, params2);
|
|
225
|
-
(_j = (_i = internalCallbackRef.current).onSettled) == null ? void 0 : _j.call(_i, void 0, error2, params2);
|
|
226
|
-
throw error2;
|
|
206
|
+
)
|
|
207
|
+
] : []
|
|
208
|
+
];
|
|
209
|
+
const res = yield Promise.race(promises);
|
|
210
|
+
if (res === "timeout") {
|
|
211
|
+
throw new Error("timeout");
|
|
227
212
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
213
|
+
if ((_b = (_a = internalCallbackRef.current).compareOrThrow) == null ? void 0 : _b.call(_a, res)) {
|
|
214
|
+
throw new ComparisonFailError(JSON.stringify(res), res);
|
|
215
|
+
}
|
|
216
|
+
setResult(res);
|
|
217
|
+
setStatus("success");
|
|
218
|
+
(_d = (_c = internalCallbackRef.current).onSuccess) == null ? void 0 : _d.call(_c, res, params2, meta);
|
|
219
|
+
(_f = (_e = internalCallbackRef.current).onSettled) == null ? void 0 : _f.call(_e, res, null, params2, meta);
|
|
220
|
+
return res;
|
|
221
|
+
} catch (error2) {
|
|
222
|
+
setError(error2);
|
|
223
|
+
setStatus("error");
|
|
224
|
+
(_h = (_g = internalCallbackRef.current).onError) == null ? void 0 : _h.call(_g, error2, params2, meta);
|
|
225
|
+
(_j = (_i = internalCallbackRef.current).onSettled) == null ? void 0 : _j.call(_i, void 0, error2, params2, meta);
|
|
226
|
+
throw error2;
|
|
227
|
+
}
|
|
228
|
+
}), []);
|
|
231
229
|
const mutate = useCallback(
|
|
232
230
|
(variables, options2) => {
|
|
233
|
-
mutateAsync(variables, options2 == null ? void 0 : options2.
|
|
231
|
+
mutateAsync(variables, options2 == null ? void 0 : options2.meta).then(
|
|
234
232
|
(data) => {
|
|
235
233
|
var _a, _b;
|
|
236
|
-
(_a = options2 == null ? void 0 : options2.onSuccess) == null ? void 0 : _a.call(options2, data, variables);
|
|
237
|
-
(_b = options2 == null ? void 0 : options2.onSettled) == null ? void 0 : _b.call(options2, data, null, variables);
|
|
234
|
+
(_a = options2 == null ? void 0 : options2.onSuccess) == null ? void 0 : _a.call(options2, data, variables, options2 == null ? void 0 : options2.meta);
|
|
235
|
+
(_b = options2 == null ? void 0 : options2.onSettled) == null ? void 0 : _b.call(options2, data, null, variables, options2 == null ? void 0 : options2.meta);
|
|
238
236
|
},
|
|
239
237
|
(error2) => {
|
|
240
238
|
var _a, _b;
|
|
241
|
-
(_a = options2 == null ? void 0 : options2.onError) == null ? void 0 : _a.call(options2, error2, variables);
|
|
242
|
-
(_b = options2 == null ? void 0 : options2.onSettled) == null ? void 0 : _b.call(options2, void 0, error2, variables);
|
|
239
|
+
(_a = options2 == null ? void 0 : options2.onError) == null ? void 0 : _a.call(options2, error2, variables, options2 == null ? void 0 : options2.meta);
|
|
240
|
+
(_b = options2 == null ? void 0 : options2.onSettled) == null ? void 0 : _b.call(options2, void 0, error2, variables, options2 == null ? void 0 : options2.meta);
|
|
243
241
|
}
|
|
244
242
|
);
|
|
245
243
|
},
|
|
@@ -408,14 +406,11 @@ var useQuery = (_a) => {
|
|
|
408
406
|
});
|
|
409
407
|
}
|
|
410
408
|
if (refetchInterval > 0) {
|
|
411
|
-
const interval = setInterval(
|
|
412
|
-
()
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
},
|
|
417
|
-
Math.max(refetchInterval, 1e3)
|
|
418
|
-
);
|
|
409
|
+
const interval = setInterval(() => {
|
|
410
|
+
if (shouldRefetch()) {
|
|
411
|
+
refetch();
|
|
412
|
+
}
|
|
413
|
+
}, refetchInterval);
|
|
419
414
|
cleanups.push(() => {
|
|
420
415
|
clearInterval(interval);
|
|
421
416
|
});
|
|
@@ -449,16 +444,17 @@ var useCallMutationBase = (promiseFunc, functionName, service, options) => {
|
|
|
449
444
|
const timeout = options == null ? void 0 : options.timeout;
|
|
450
445
|
const rest = __objRest(useMemo(() => options != null ? options : {}, [options]), []);
|
|
451
446
|
const mutationFn = useCallback3(
|
|
452
|
-
(parameters) => __async(null, null, function* () {
|
|
447
|
+
(parameters, meta) => __async(null, null, function* () {
|
|
453
448
|
try {
|
|
454
449
|
return yield promiseFunc({
|
|
455
|
-
service,
|
|
450
|
+
service: service(meta),
|
|
456
451
|
functionName: functionName.toString(),
|
|
457
452
|
parameters,
|
|
458
453
|
options: {
|
|
459
454
|
avoidTimeout: !timeout,
|
|
460
455
|
customTimeout: timeout
|
|
461
|
-
}
|
|
456
|
+
},
|
|
457
|
+
meta
|
|
462
458
|
});
|
|
463
459
|
} catch (e) {
|
|
464
460
|
if (e instanceof Error) {
|
|
@@ -475,24 +471,24 @@ var useCallMutationBase = (promiseFunc, functionName, service, options) => {
|
|
|
475
471
|
};
|
|
476
472
|
function buildMutationHook(promiseFunc, genTargetService) {
|
|
477
473
|
return function useCallMutationBuilder(func, options) {
|
|
478
|
-
|
|
479
|
-
return useCallMutationBase(promiseFunc, func, targetService, options);
|
|
474
|
+
return useCallMutationBase(promiseFunc, func, genTargetService, options);
|
|
480
475
|
};
|
|
481
476
|
}
|
|
482
477
|
var useCallQueryBase = (promiseFunction, functionName, params, service, options) => {
|
|
483
478
|
const timeout = options == null ? void 0 : options.timeout;
|
|
484
479
|
const rest = __objRest(useMemo(() => options != null ? options : {}, [options]), []);
|
|
485
480
|
const queryFn = useCallback3(
|
|
486
|
-
(refetchParams
|
|
481
|
+
(refetchParams) => __async(null, null, function* () {
|
|
487
482
|
try {
|
|
488
483
|
return yield promiseFunction({
|
|
489
|
-
service:
|
|
484
|
+
service: service(options == null ? void 0 : options.meta),
|
|
490
485
|
functionName: functionName.toString(),
|
|
491
486
|
parameters: refetchParams != null ? refetchParams : params,
|
|
492
487
|
options: {
|
|
493
488
|
avoidTimeout: !timeout,
|
|
494
489
|
customTimeout: timeout
|
|
495
|
-
}
|
|
490
|
+
},
|
|
491
|
+
meta: options == null ? void 0 : options.meta
|
|
496
492
|
});
|
|
497
493
|
} catch (e) {
|
|
498
494
|
if (e instanceof Error) {
|
|
@@ -509,8 +505,7 @@ var useCallQueryBase = (promiseFunction, functionName, params, service, options)
|
|
|
509
505
|
};
|
|
510
506
|
function buildQueryHook(promiseFunction, getTargetService) {
|
|
511
507
|
return function useCallQueryBuilder(func, params, options) {
|
|
512
|
-
|
|
513
|
-
return useCallQueryBase(promiseFunction, func, params, targetService, options);
|
|
508
|
+
return useCallQueryBase(promiseFunction, func, params, getTargetService, options);
|
|
514
509
|
};
|
|
515
510
|
}
|
|
516
511
|
|
|
@@ -575,6 +570,7 @@ function useSubscriptionCore(options) {
|
|
|
575
570
|
(message) => __async(null, null, function* () {
|
|
576
571
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
577
572
|
if ((_b = (_a = internalCallbacksRef.current).compareOrThrow) == null ? void 0 : _b.call(_a, message)) {
|
|
573
|
+
updateStatus("error");
|
|
578
574
|
(_d = (_c = internalCallbacksRef.current).onError) == null ? void 0 : _d.call(_c, message);
|
|
579
575
|
return;
|
|
580
576
|
}
|
|
@@ -624,8 +620,8 @@ function useSubscriptionCore(options) {
|
|
|
624
620
|
|
|
625
621
|
// src/useSubscription.ts
|
|
626
622
|
function useSubscription(subscriptionHandler, options) {
|
|
627
|
-
const { topic, service, maxDownwardDepth = 1e3 } =
|
|
628
|
-
return useSubscriptionCore(__spreadProps(__spreadValues({},
|
|
623
|
+
const _a = options, { topic, service, maxDownwardDepth = 1e3, meta } = _a, rest = __objRest(_a, ["topic", "service", "maxDownwardDepth", "meta"]);
|
|
624
|
+
return useSubscriptionCore(__spreadProps(__spreadValues({}, rest), {
|
|
629
625
|
subscriberFn: (handler) => {
|
|
630
626
|
const unsubscribe = subscriptionHandler({
|
|
631
627
|
service,
|
|
@@ -633,7 +629,8 @@ function useSubscription(subscriptionHandler, options) {
|
|
|
633
629
|
callback: (message) => {
|
|
634
630
|
handler(message);
|
|
635
631
|
},
|
|
636
|
-
maxDownwardDepth
|
|
632
|
+
maxDownwardDepth,
|
|
633
|
+
meta
|
|
637
634
|
});
|
|
638
635
|
return unsubscribe;
|
|
639
636
|
}
|
|
@@ -653,8 +650,8 @@ function buildServiceSubscriptionHook(subscriptionHandler, targetMachine) {
|
|
|
653
650
|
|
|
654
651
|
// src/proxyBinders.ts
|
|
655
652
|
function bindClientSocketProxy(socketClientProxy) {
|
|
656
|
-
return (
|
|
657
|
-
const _a = args
|
|
653
|
+
return (args) => {
|
|
654
|
+
const _a = args, { callback: cbHook } = _a, rest = __objRest(_a, ["callback"]);
|
|
658
655
|
return socketClientProxy.mirror(__spreadProps(__spreadValues({}, rest), {
|
|
659
656
|
callback: (message) => {
|
|
660
657
|
cbHook(message.message);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../utils/dist/comparison/index.js","../src/factories.ts","../src/useMutation.ts","../src/useQuery.ts","../src/useSubscriptionCore.ts","../src/useSubscription.ts","../src/proxyBinders.ts"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/comparison/index.ts\nvar comparison_exports = {};\n__export(comparison_exports, {\n shallowEqual: () => shallowEqual\n});\nmodule.exports = __toCommonJS(comparison_exports);\n\n// src/comparison/shallowEqual.ts\nfunction shallowEqual(objA, objB) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== \"object\" || objA === null || typeof objB !== \"object\" || objB === null) {\n return false;\n }\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false;\n for (const [key, value] of objA) {\n if (!Object.is(value, objB.get(key))) {\n return false;\n }\n }\n return true;\n }\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false;\n for (const value of objA) {\n if (!objB.has(value)) {\n return false;\n }\n }\n return true;\n }\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (let i = 0; i < keysA.length; i++) {\n if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {\n return false;\n }\n }\n return true;\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n shallowEqual\n});\n","import type { TSocketServerCallOptions, ZMQClient } from \"@pixotope/zmq-client\";\nimport { useCallback, useMemo } from \"react\";\nimport { MutationOptions, useMutation } from \"./useMutation\";\nimport { QueryOptions, useQuery } from \"./useQuery\";\n\nexport type MutationInfo<TData, TError, TParams> = {\n data: TData;\n error: TError;\n params: TParams;\n};\n\ntype FnToParamsBase = Record<string, MutationInfo<unknown, unknown, unknown>>;\n\nexport type TPromiseFunction<TResponse, TParams> = (\n args: Omit<\n ZMQClient.Call<\n TResponse,\n {\n functionName: string;\n parameters: TParams;\n options?: Omit<TSocketServerCallOptions, \"toCallIfNoResponse\">;\n }\n >,\n \"id\"\n >\n) => Promise<TResponse>;\n\nconst useCallMutationBase = <\n TFnToParams extends FnToParamsBase,\n TData = unknown,\n TError = unknown,\n TParams = unknown,\n>(\n promiseFunc: TPromiseFunction<TData, TParams>,\n functionName: keyof TFnToParams,\n service: string,\n options?: Omit<MutationOptions<TData, TError, TParams>, \"mutationFn\">\n) => {\n const timeout = options?.timeout;\n const { ...rest } = useMemo(() => options ?? {}, [options]);\n const mutationFn = useCallback(\n async (parameters: TParams) => {\n try {\n return await promiseFunc({\n service,\n functionName: functionName.toString(),\n parameters,\n options: {\n avoidTimeout: !timeout,\n customTimeout: timeout,\n },\n });\n } catch (e) {\n if (e instanceof Error) {\n throw e;\n }\n throw new Error(e as string);\n }\n },\n [functionName, service, timeout]\n );\n\n return useMutation<TData, TError, TParams>({\n mutationFn,\n ...rest,\n });\n};\n\nexport function buildMutationHook<TFnToParams extends FnToParamsBase>(\n promiseFunc: TPromiseFunction<unknown, unknown>,\n genTargetService: (machine: string | undefined) => string\n) {\n return function useCallMutationBuilder<TFn extends keyof TFnToParams>(\n func: TFn,\n options?: Parameters<\n typeof useCallMutationBase<\n TFnToParams,\n TFnToParams[TFn][\"data\"],\n TFnToParams[TFn][\"error\"],\n TFnToParams[TFn][\"params\"]\n >\n >[3] & { machine?: string }\n ) {\n const targetService = genTargetService(options?.machine);\n\n return useCallMutationBase<\n TFnToParams,\n TFnToParams[TFn][\"data\"],\n TFnToParams[TFn][\"error\"],\n TFnToParams[TFn][\"params\"]\n >(promiseFunc, func, targetService, options);\n };\n}\n\nconst useCallQueryBase = <\n TFnToParams extends FnToParamsBase,\n TData = unknown,\n TError = unknown,\n TParams = unknown,\n TSelect = TData,\n>(\n promiseFunction: TPromiseFunction<TData, TParams>,\n functionName: keyof TFnToParams,\n params: TParams,\n service: string,\n options?: Omit<QueryOptions<TData, TError, TParams, TSelect>, \"queryFn\">\n) => {\n const timeout = options?.timeout;\n const { ...rest } = useMemo(() => options ?? {}, [options]);\n const queryFn = useCallback(\n async (refetchParams: TParams | void, overrideTargetMachine?: string) => {\n try {\n return await promiseFunction({\n service: overrideTargetMachine ?? service,\n functionName: functionName.toString(),\n parameters: refetchParams ?? params,\n options: {\n avoidTimeout: !timeout,\n customTimeout: timeout,\n },\n });\n } catch (e) {\n if (e instanceof Error) {\n throw e;\n }\n throw new Error(e as string);\n }\n },\n [functionName, service, params, timeout]\n );\n\n return useQuery<TData, TError, TParams, TSelect>({\n queryFn,\n ...rest,\n });\n};\n\nexport function buildQueryHook<TFnToParams extends FnToParamsBase>(\n promiseFunction: TPromiseFunction<unknown, unknown>,\n getTargetService: (machine: string | undefined) => string\n) {\n return function useCallQueryBuilder<\n TFn extends keyof TFnToParams,\n TSelect = TFnToParams[TFn][\"data\"],\n >(\n func: TFn,\n params: TFnToParams[TFn][\"params\"],\n options?: Parameters<\n typeof useCallQueryBase<\n TFnToParams,\n TFnToParams[TFn][\"data\"],\n TFnToParams[TFn][\"error\"],\n TFnToParams[TFn][\"params\"],\n TSelect\n >\n >[4] & { machine?: string }\n ) {\n const targetService = getTargetService(options?.machine);\n\n return useCallQueryBase<\n TFnToParams,\n TFnToParams[TFn][\"data\"],\n TFnToParams[TFn][\"error\"],\n TFnToParams[TFn][\"params\"],\n TSelect\n >(promiseFunction, func, params, targetService, options);\n };\n}\n","import { useCallback, useRef, useState } from \"react\";\n\nexport type MutationFunction<TData = unknown, TParams = unknown> = (\n params: TParams,\n overrideTargetMachine?: string\n) => Promise<TData>;\n\nexport interface MutationOptions<\n TData = unknown,\n TError = unknown,\n TParams = void,\n> {\n mutationFn: MutationFunction<TData, TParams>;\n params?: TParams;\n onSuccess?: (data: TData, variables: TParams) => Promise<unknown> | unknown;\n onError?: (\n error: TMutationError<TError>,\n variables: TParams\n ) => Promise<unknown> | unknown;\n onSettled?: (\n data: TData | undefined,\n error: TMutationError<TError> | null,\n variables: TParams\n ) => Promise<unknown> | unknown;\n compareOrThrow?: (result: TData | TError) => boolean;\n timeout?: number;\n prepareParams?: (variables: TParams, defaults?: TParams) => TParams;\n}\n\ntype TMutationError<TError> = TError | Error | null;\n\nexport interface MutateOptions<\n TData = unknown,\n TError = unknown,\n TParams = void,\n> {\n onSuccess?: (data: TData, variables: TParams) => void;\n onError?: (error: TMutationError<TError>, variables: TParams) => void;\n onSettled?: (\n data: TData | undefined,\n error: TMutationError<TError> | null,\n variables: TParams\n ) => void;\n}\n\ntype MutationStatus = \"idle\" | \"loading\" | \"success\" | \"error\";\ntype RaceErrorReason = \"timeout\";\ntype RacePromises<T> = Promise<T | RaceErrorReason>;\n\nexport class ComparisonFailError<TPayload = unknown> extends Error {\n public readonly payload: TPayload;\n\n constructor(message: string, payload: TPayload) {\n super(message);\n this.name = this.constructor.name;\n this.payload = payload;\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, ComparisonFailError);\n }\n }\n}\n\n/**\n * `useMutation` is a hook that allows you to perform a mutation/push updates to the services while\n * providing extensive API to tap into the status and results of the mutation.\n * @param mutationFn The mutation function to be called when the `mutate` function is called.\n * `useMutation` does not care about what the function does, all it needs it a function that returns\n * a promise.\n * @param options Options to configure the mutation.\n * @returns An object with the following properties:\n * - `mutateAsync`: A function that takes in the variables and returns a promise that resolves to the\n * result of the mutation. This function can be awaited to get the result of the mutation. Callbacks can\n * be passed to this function to be called when the mutation is successful or when it fails. It's good idea\n * to wrap this function in a try/catch block.\n * - `mutate`: A function that takes in the variables and returns nothing. This function does not\n * return a promise. Callbacks can be passed to this function to be called when the mutation is\n * successful or when it fails.\n * - `status`: The status of the mutation. Can be one of `idle`, `loading`, `success` or `error`.\n * - `result`: The result of the mutation. This is undefined until the mutation is successful.\n * - `reset`: A function that resets the mutation to the initial state.\n * - `error`: The error object if the mutation has failed.\n * @example\n * ```typescript\n * const mutationRes = useMutation({\n * mutationFn: (variables) => {\n * return ZMQHelper.callSomethingAsync(variables)\n * },\n * onSuccess: (data) => {\n * // do something with the result\n * },\n * onError: (error) => {\n * // do something with the error\n * },\n * onSettled: (data, error) => {\n * // do something when the mutation is done\n * }});\n *\n * // call the mutation\n * const res = await mutationRes.mutateAsync({ foo: \"bar\" });\n * // OR\n * mutationRes.mutate({ foo: \"bar\" }, {\n * onSuccess: (data) => {\n * // do something with the result\n * // for example show a toast message\n * // stop local loading state\n * });\n * ```\n */\nexport const useMutation = <\n TData = unknown,\n TError = TMutationError<unknown>,\n TParams = void,\n>(\n options: MutationOptions<TData, TError, TParams>\n) => {\n const {\n mutationFn,\n compareOrThrow,\n onError,\n onSettled,\n onSuccess,\n prepareParams,\n params,\n timeout,\n } = options;\n const [status, setStatus] = useState<MutationStatus>(\"idle\");\n const [error, setError] = useState<TMutationError<TError>>(null);\n const [result, setResult] = useState<TData | undefined>(undefined);\n const mutationFnRef = useRef(mutationFn);\n const internalOptionsRef = useRef({\n params,\n timeout,\n });\n const internalCallbackRefistry = <const>{\n onSuccess,\n onError,\n onSettled,\n compareOrThrow,\n prepareParams,\n };\n const internalCallbackRef = useRef(internalCallbackRefistry);\n internalCallbackRef.current = internalCallbackRefistry;\n\n const mutateAsync = useCallback(\n async (params: TParams, overrideTargetMachine?: string) => {\n setStatus(\"loading\");\n setError(null);\n\n try {\n const promises: RacePromises<TData>[] = [\n mutationFnRef.current(\n internalCallbackRef.current.prepareParams\n ? internalCallbackRef.current.prepareParams(\n params,\n internalOptionsRef.current.params\n )\n : params,\n overrideTargetMachine\n ),\n ...(internalOptionsRef.current.timeout\n ? [\n new Promise<RaceErrorReason>((resolve) =>\n setTimeout(\n () => resolve(\"timeout\"),\n internalOptionsRef.current.timeout\n )\n ),\n ]\n : []),\n ];\n\n const res = await Promise.race(promises);\n\n if (res === \"timeout\") {\n throw new Error(\"timeout\");\n }\n\n if (internalCallbackRef.current.compareOrThrow?.(res)) {\n throw new ComparisonFailError(JSON.stringify(res), res);\n }\n\n setResult(res);\n setStatus(\"success\");\n\n internalCallbackRef.current.onSuccess?.(res, params);\n internalCallbackRef.current.onSettled?.(res, null, params);\n\n return res;\n } catch (error: any) {\n setError(error);\n setStatus(\"error\");\n\n internalCallbackRef.current.onError?.(error, params);\n internalCallbackRef.current.onSettled?.(undefined, error, params);\n\n throw error;\n }\n },\n []\n );\n\n const mutate = useCallback(\n (\n variables: TParams,\n options?: MutateOptions<TData, TError, TParams> & {\n overrideTargetMachine?: string;\n }\n ) => {\n mutateAsync(variables, options?.overrideTargetMachine).then(\n (data) => {\n options?.onSuccess?.(data, variables);\n options?.onSettled?.(data, null, variables);\n },\n (error) => {\n options?.onError?.(error, variables);\n options?.onSettled?.(undefined, error, variables);\n }\n );\n },\n [mutateAsync]\n );\n\n return {\n mutateAsync,\n status,\n result,\n mutate,\n reset: () => {\n setStatus(\"idle\");\n setError(null);\n setResult(undefined);\n },\n error,\n };\n};\n","import { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport interface QueryOptions<\n TData = unknown,\n TError = unknown,\n TParams = void,\n TSelectData = TData,\n Stateless extends true | undefined = undefined,\n> {\n queryFn: (params: TParams | undefined | void) => Promise<TData>;\n onSuccess?: (data: TData) => Promise<void> | void;\n onError?: (error: TQueryError<TError>) => Promise<void> | void;\n onSettled?: (\n data: TData | undefined,\n error: TQueryError<TError> | undefined\n ) => Promise<void> | void;\n timeout?: number;\n enabled?: boolean;\n initialData?: TData | Functionize<TData>;\n select?: (data: TData) => TSelectData;\n refetchOnWindowFocus?: boolean;\n refetchInterval?: number;\n compareOrThrow?: (data: TData) => boolean;\n stateless?: Stateless;\n key?: TQueryKey;\n}\n\ntype Functionize<T> = () => T;\ntype QueryStatus = \"idle\" | \"loading\" | \"success\" | \"error\" | \"timeout\";\ntype RaceErrorReason = \"timeout\";\ntype RacePromises<T> = Promise<T | RaceErrorReason>;\ntype WithData<TData> = { data: TData | undefined };\ntype TQueryKey = readonly any[];\n\ntype TQueryError<TError> = TError | Error | null;\n\nexport type UseQueryResult<\n TData = unknown,\n TError = unknown,\n TParams = void,\n TSelectData = TData,\n Stateless extends true | undefined = undefined,\n> = {\n error: TQueryError<TError>;\n status: QueryStatus;\n refetch: (params: TParams | void | undefined) => Promise<void>;\n reset: () => void;\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n} & (Stateless extends true ? {} : WithData<TSelectData>);\n\nfunction normalizeQueryKey(queryKey: TQueryKey): string {\n return JSON.stringify(queryKey);\n}\n\ntype TInternalCallbackRef<TData, TError, TSelectData> = {\n onError?: (error: TQueryError<TError>) => Promise<void> | void;\n onSuccess?: (data: TData) => Promise<void> | void;\n onSettled?: (\n data: TData | undefined,\n error: TQueryError<TError> | undefined\n ) => Promise<void> | void;\n compareOrThrow?: (data: TData) => boolean;\n select?: (data: TData) => TSelectData;\n};\n\ntype TInternalOptionsRef<TData> = {\n timeout?: number;\n enabled: boolean;\n refetchOnWindowFocus: boolean;\n refetchInterval: number;\n compareOrThrow?: (data: TData) => boolean;\n stateless?: boolean;\n};\n\nconst getRandomUUID = () => Math.random().toString(36).substring(2, 15);\n\nexport const useQuery = <\n TData = unknown,\n TError = TQueryError<unknown>,\n TParams = void,\n TSelected = TData,\n Stateless extends true | undefined = undefined,\n>({\n queryFn,\n ...options\n}: QueryOptions<TData, TError, TParams, TSelected, Stateless>): UseQueryResult<\n TSelected,\n TError,\n TParams,\n TSelected,\n Stateless\n> => {\n const {\n enabled = true,\n refetchOnWindowFocus = false,\n refetchInterval = 0,\n initialData,\n select,\n onError,\n onSuccess,\n onSettled,\n timeout,\n compareOrThrow,\n stateless,\n key: queryKeyPassed,\n } = options;\n const queryKey = normalizeQueryKey(queryKeyPassed ?? []);\n const lastFetchedAt = useRef<number | null>(null);\n const lastQueryKey = useRef<string | undefined>(undefined);\n const queryFnRef = useRef(queryFn);\n queryFnRef.current = queryFn;\n const internalCallbackRef = useRef<\n TInternalCallbackRef<TData, TError, TSelected>\n >({});\n internalCallbackRef.current = {\n onError,\n onSuccess,\n onSettled,\n compareOrThrow,\n select,\n };\n const internalOptionsRef = useRef<TInternalOptionsRef<TData>>({\n enabled,\n refetchOnWindowFocus,\n refetchInterval,\n compareOrThrow,\n stateless,\n timeout,\n });\n internalOptionsRef.current = {\n enabled,\n refetchOnWindowFocus,\n refetchInterval,\n compareOrThrow,\n stateless,\n timeout,\n };\n const requestIdRef = useRef(getRandomUUID());\n\n const [status, setStatus] = useState<QueryStatus>(() => {\n return \"idle\";\n });\n const [error, setError] = useState<TQueryError<TError>>(null);\n const [data, setData] = useState<TData | undefined>(() => {\n if (initialData !== undefined) {\n if (typeof initialData === \"function\") {\n return (initialData as Functionize<TData>)();\n }\n\n return initialData as TData;\n }\n\n return undefined;\n });\n\n const handleSetData = useCallback((data: TData) => {\n if (internalOptionsRef.current.stateless) {\n return;\n }\n\n setData(data);\n }, []);\n\n const shouldRefetch = useCallback(() => {\n if (!internalOptionsRef.current.enabled) {\n return false;\n }\n\n if (lastFetchedAt.current === null) {\n return true;\n }\n\n return (\n new Date().getTime() - lastFetchedAt.current >\n internalOptionsRef.current?.refetchInterval\n );\n }, []);\n\n const refetch = useCallback(\n async (params: TParams | void | undefined = undefined) => {\n const requestId = getRandomUUID();\n requestIdRef.current = requestId;\n if (!internalOptionsRef.current.enabled) {\n return;\n }\n\n setStatus(\"loading\");\n setError(null);\n\n try {\n const promises: RacePromises<TData>[] = [\n queryFnRef.current(params),\n ...(internalOptionsRef.current.timeout\n ? [\n new Promise<RaceErrorReason>((resolve) =>\n setTimeout(\n () => resolve(\"timeout\"),\n internalOptionsRef.current.timeout\n )\n ),\n ]\n : []),\n ];\n\n const res = await Promise.race(promises);\n if (requestIdRef.current !== requestId) {\n return;\n }\n\n if (res === \"timeout\") {\n throw new Error(\"timeout\");\n }\n\n handleSetData(res);\n\n if (\n internalCallbackRef.current.compareOrThrow &&\n internalCallbackRef.current.compareOrThrow(res) === true\n ) {\n throw new Error(\"failedComparison\");\n }\n\n setStatus(\"success\");\n lastFetchedAt.current = new Date().getTime();\n internalCallbackRef.current.onSuccess?.(res);\n internalCallbackRef.current.onSettled?.(res, undefined);\n } catch (error: any) {\n setError(error);\n setStatus(\"error\");\n internalCallbackRef.current.onError?.(error);\n internalCallbackRef.current.onSettled?.(undefined, error);\n }\n },\n [handleSetData]\n );\n\n const reset = useCallback(() => {\n setData(undefined);\n setStatus(\"idle\");\n setError(null);\n refetch();\n }, [refetch]);\n\n useEffect(() => {\n const cleanups: (() => void)[] = [];\n\n // If the query should be refetched on window focus, add a listener\n if (refetchOnWindowFocus) {\n const queryHandleFocus = () => {\n refetch();\n };\n\n window.addEventListener(\"focus\", queryHandleFocus);\n\n cleanups.push(() => {\n window.removeEventListener(\"focus\", queryHandleFocus);\n });\n }\n\n // If the query should be refetched on an interval, add an interval\n if (refetchInterval > 0) {\n const interval = setInterval(\n () => {\n if (shouldRefetch()) {\n refetch();\n }\n },\n Math.max(refetchInterval, 1000)\n );\n\n cleanups.push(() => {\n clearInterval(interval);\n });\n }\n\n // If the query key has changed, refetch\n if (\n lastQueryKey.current === undefined ||\n queryKey !== lastQueryKey.current\n ) {\n lastQueryKey.current = queryKey;\n refetch();\n }\n\n return () => {\n cleanups.forEach((cleanup) => cleanup());\n };\n }, [\n queryKey,\n enabled,\n refetchOnWindowFocus,\n refetchInterval,\n shouldRefetch,\n refetch,\n ]);\n\n return {\n data:\n select && data !== undefined\n ? select(data as TData)\n : (data as unknown as TSelected),\n error,\n status,\n refetch,\n reset,\n };\n};\n","/**\n * @fileoverview useSubscriptionCore\n * @name useSubscriptionCore.ts\n * @description useSubscriptionCore | This hook handle core subscription logic\n * and provides a way to subscribe and unsubscribe to a topic via any callback\n */\n\nimport { shallowEqual } from \"@pixotope/utils/comparison\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\ntype SubscriptionState = \"idle\" | \"subscribed\" | \"subscribing\";\nexport type MessageHandler<TMessage> = (message: TMessage) => void;\nexport type Connection = {\n acknowledge: () => void;\n};\nexport type SubscriptionCoreOptions<\n TData,\n TMessage = TData,\n Stateless extends true | undefined = undefined,\n> = {\n /**\n * @description Function that will be called when the message is received.\n */\n onMessage?: (message: TMessage) => void;\n /**\n * @description Function that will be called when the subscription is created.\n */\n onSubscribed?: (message: TMessage) => void;\n /**\n * @description Function that will be called when the subscription is created.\n */\n onError?: (error: TMessage) => void;\n /**\n * @description Whether the subscription is enabled.\n * @default true\n */\n enabled?: boolean;\n /**\n * @description Function that will be called to compare the message with the\n * previous message. If the function returns true, the message will be ignored.\n */\n compareOrThrow?: (data: TMessage) => boolean;\n /**\n * @description Function that will be called to select the data from the message.\n */\n select?: (data: TMessage) => TData;\n /**\n * @description Initial state of the subscription.\n * @default undefined\n */\n initialState?: TData;\n /**\n * @description Function that will be called when the subscription is created.\n */\n subscriberFn: (\n handler: MessageHandler<TMessage>,\n connection: Connection\n ) => () => void /** unsubscribe Fn */;\n /**\n * @description Whether the subscription is stateless. Data will not be\n * stored by the hook internally.\n * @default false\n */\n stateless?: Stateless;\n /**\n * @description Custom equality function for comparing data.\n * @default shallowEqual\n */\n isEqual?: <T = TData>(a: T, b: T) => boolean;\n};\n\ntype WithStatus = {\n status: SubscriptionState;\n};\n\ntype WithData<TData> = {\n data: TData;\n};\n\nexport type SubscriptionCoreReturnType<\n TData,\n Stateless extends true | undefined,\n> = {\n reSubscribe: () => void;\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n} & (Stateless extends true ? {} : WithStatus & WithData<TData>);\n\n/**\n * @description `useSubscriptionCore` | This hook handle core subscription logic\n * and provides a way to subscribe and unsubscribe to a topic via any callback.\n * The hook expose a handler function. All the consumer code need to do is to\n * call this handler function with the message received from the topic or pass\n * it directly to the callback function that is passed to the subscriberFn.\n * - `status` - current status of the subscription\n * - `data` - the data after the select function is applied to the message\n * - `reSubscribe` - function that can be called to re-subscribe to the topic\n *\n * An example how this hook works can be found in {@link ./useSubscription.ts}\n */\nexport function useSubscriptionCore<\n TData = unknown,\n TMessage = TData,\n Stateless extends true | undefined = undefined,\n>(\n options: SubscriptionCoreOptions<TData, TMessage, Stateless>\n): SubscriptionCoreReturnType<TData, Stateless> {\n const {\n enabled = true,\n initialState = undefined,\n onSubscribed,\n stateless,\n compareOrThrow,\n subscriberFn,\n onMessage,\n onError,\n select,\n isEqual = shallowEqual,\n } = options;\n const [status, setStatus] = useState<SubscriptionState>(\"idle\");\n const [data, setData] = useState<TData | undefined>(initialState);\n const unsubcribeRef = useRef<() => void | undefined>(undefined);\n const initialStateRef = useRef(initialState);\n const subscriberFnRef = useRef(subscriberFn);\n const callbackRefRegistry = <const>{\n onMessage,\n onError,\n select,\n compareOrThrow,\n onSubscribed,\n isEqual,\n };\n const internalCallbacksRef = useRef(callbackRefRegistry);\n internalCallbacksRef.current = callbackRefRegistry;\n\n const updateStatus = useCallback(\n (newStatus: SubscriptionState, message?: TMessage) => {\n if (stateless) {\n return;\n }\n\n setStatus((prev) => {\n if (prev === newStatus) {\n return prev;\n }\n\n if (newStatus === \"subscribed\" && message) {\n internalCallbacksRef.current.onSubscribed?.(message);\n }\n\n return newStatus;\n });\n },\n [stateless]\n );\n\n const connection: Connection = useMemo(\n () => ({\n acknowledge: () => {\n updateStatus(\"subscribed\");\n },\n }),\n [updateStatus]\n );\n\n const handler = useCallback(\n async (message: TMessage) => {\n if (internalCallbacksRef.current.compareOrThrow?.(message)) {\n internalCallbacksRef.current.onError?.(message);\n\n return;\n }\n\n const selectedMessage = <TData>(\n (internalCallbacksRef.current.select?.(message) ?? message)\n );\n\n if (!stateless) {\n setData((prev) => {\n if (isEqual(prev, selectedMessage)) {\n return prev;\n }\n\n return selectedMessage;\n });\n }\n\n updateStatus(\"subscribed\", message);\n internalCallbacksRef.current.onMessage?.(message);\n },\n [stateless, updateStatus]\n );\n\n const unsubscribe = useCallback(() => {\n updateStatus(\"idle\");\n unsubcribeRef.current?.();\n unsubcribeRef.current = undefined;\n }, [updateStatus]);\n\n const subscribe = useCallback(() => {\n unsubcribeRef.current?.();\n updateStatus(\"subscribing\");\n setData(initialStateRef.current);\n unsubcribeRef.current = subscriberFnRef.current(handler, connection);\n }, [connection, handler, updateStatus]);\n\n useEffect(() => {\n if (enabled) {\n subscribe();\n } else {\n unsubscribe();\n }\n\n return () => {\n unsubscribe();\n };\n }, [enabled, subscribe, unsubscribe]);\n\n return {\n status,\n data,\n reSubscribe: subscribe,\n } as unknown as any;\n}\n","import {\n SubscriptionCoreOptions,\n useSubscriptionCore,\n} from \"./useSubscriptionCore\";\n\nexport type SubscriptionOptions<\n TData,\n TMessage = unknown,\n Stateless extends true | undefined = undefined,\n> = Omit<\n SubscriptionCoreOptions<TData, TMessage, Stateless>,\n \"subscriberFn\"\n> & {\n service: string;\n topic: string;\n maxDownwardDepth?: number;\n};\n\nexport type TSubscriptionHandlerFunction<TMessage> = (opts: {\n service: string;\n name: string;\n callback: (message: TMessage) => void;\n maxDownwardDepth?: number;\n}) => () => void;\n\nexport function useSubscription<\n TData = unknown,\n TMessage = TData,\n Stateless extends true | undefined = undefined,\n>(\n subscriptionHandler: TSubscriptionHandlerFunction<TMessage>,\n options: SubscriptionOptions<TData, TMessage, Stateless>\n) {\n const { topic, service, maxDownwardDepth = 1000 } = options;\n\n return useSubscriptionCore<TData, TMessage, Stateless>({\n ...options,\n subscriberFn: (handler) => {\n const unsubscribe = subscriptionHandler({\n service,\n name: topic,\n callback: (message: TMessage) => {\n handler(message);\n },\n maxDownwardDepth,\n });\n\n return unsubscribe;\n },\n });\n}\n\nexport function buildServiceSubscriptionHook(\n subscriptionHandler: TSubscriptionHandlerFunction<unknown>,\n targetMachine: (machine: string | undefined) => string\n) {\n return function useSubscriptionBuilder<\n TData,\n TMessage = TData,\n Stateless extends true | undefined = undefined,\n >(\n options: Omit<\n SubscriptionOptions<TData, TMessage, Stateless>,\n \"service\"\n > & {\n machine?: string;\n }\n ) {\n const targetService = targetMachine(options.machine);\n return useSubscription<TData, TMessage, Stateless>(\n <TSubscriptionHandlerFunction<TMessage>>subscriptionHandler,\n {\n service: targetService,\n ...options,\n }\n );\n };\n}\n","import type { ZMQProxyWSClient } from \"@pixotope/zmq-client\";\nimport type { TPromiseFunction } from \"./factories\";\nimport type { buildServiceSubscriptionHook } from \"./useSubscription\";\n\nexport function bindClientSocketProxy(socketClientProxy: ZMQProxyWSClient) {\n return (\n ...args: Parameters<Parameters<typeof buildServiceSubscriptionHook>[0]>\n ) => {\n const { callback: cbHook, ...rest } = args[0];\n return socketClientProxy.mirror({\n ...rest,\n callback: (message) => {\n cbHook(message.message);\n },\n })[0];\n };\n}\n\nexport function bindPromiseFunction(clientSocketProxy: ZMQProxyWSClient) {\n return async (...args: Parameters<TPromiseFunction<unknown, unknown>>) => {\n const res = await clientSocketProxy.callAsync(...args);\n return res.message.Result;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AACA,QAAIA,aAAY,OAAO;AACvB,QAAIC,oBAAmB,OAAO;AAC9B,QAAIC,qBAAoB,OAAO;AAC/B,QAAIC,gBAAe,OAAO,UAAU;AACpC,QAAI,WAAW,CAAC,QAAQ,QAAQ;AAC9B,eAAS,QAAQ;AACf,QAAAH,WAAU,QAAQ,MAAM,EAAE,KAAK,IAAI,IAAI,GAAG,YAAY,KAAK,CAAC;AAAA,IAChE;AACA,QAAII,eAAc,CAAC,IAAI,MAAM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;AACH;AAEO,SAAS,6BACd,qBACA,eACA;AACA,SAAO,SAAS,uBAKd,SAMA;AACA,UAAM,gBAAgB,cAAc,QAAQ,OAAO;AACnD,WAAO;AAAA,MACmC;AAAA,MACxC;AAAA,QACE,SAAS;AAAA,SACN;AAAA,IAEP;AAAA,EACF;AACF;;;ACzEO,SAAS,sBAAsB,mBAAqC;AACzE,SAAO,IACF,SACA;AACH,UAAsC,UAAK,CAAC,GAApC,YAAU,OARtB,IAQ0C,IAAT,iBAAS,IAAT,CAArB;AACR,WAAO,kBAAkB,OAAO,iCAC3B,OAD2B;AAAA,MAE9B,UAAU,CAAC,YAAY;AACrB,eAAO,QAAQ,OAAO;AAAA,MACxB;AAAA,IACF,EAAC,EAAE,CAAC;AAAA,EACN;AACF;AAEO,SAAS,oBAAoB,mBAAqC;AACvE,SAAO,IAAU,SAAyD;AACxE,UAAM,MAAM,MAAM,kBAAkB,UAAU,GAAG,IAAI;AACrD,WAAO,IAAI,QAAQ;AAAA,EACrB;AACF;","names":["__defProp","__getOwnPropDesc","__getOwnPropNames","__hasOwnProp","__copyProps","shallowEqual","useCallback","params","error","options","useCallback","useRef","useState","useRef","useState","useCallback","data","_a","_b","error","useCallback","useCallback","useEffect","useMemo","useRef","useState","useState","useRef","useCallback","useMemo","useEffect"]}
|
|
1
|
+
{"version":3,"sources":["../../utils/dist/comparison/index.js","../src/factories.ts","../src/useMutation.ts","../src/useQuery.ts","../src/useSubscriptionCore.ts","../src/useSubscription.ts","../src/proxyBinders.ts"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/comparison/index.ts\nvar comparison_exports = {};\n__export(comparison_exports, {\n shallowEqual: () => shallowEqual\n});\nmodule.exports = __toCommonJS(comparison_exports);\n\n// src/comparison/shallowEqual.ts\nfunction shallowEqual(objA, objB) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== \"object\" || objA === null || typeof objB !== \"object\" || objB === null) {\n return false;\n }\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false;\n for (const [key, value] of objA) {\n if (!Object.is(value, objB.get(key))) {\n return false;\n }\n }\n return true;\n }\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false;\n for (const value of objA) {\n if (!objB.has(value)) {\n return false;\n }\n }\n return true;\n }\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (let i = 0; i < keysA.length; i++) {\n if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {\n return false;\n }\n }\n return true;\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n shallowEqual\n});\n","import type { TSocketServerCallOptions, ZMQClient } from \"@pixotope/zmq-client\";\nimport { useCallback, useMemo } from \"react\";\nimport { MutationOptions, useMutation } from \"./useMutation\";\nimport { QueryOptions, useQuery } from \"./useQuery\";\n\nexport type MutationInfo<TData, TError, TParams> = {\n data: TData;\n error: TError;\n params: TParams;\n};\n\ntype FnToParamsBase = Record<string, MutationInfo<unknown, unknown, unknown>>;\n\nexport type TPromiseFunction<TResponse, TParams, TExtraParams> = (\n args: Omit<\n ZMQClient.Call<\n TResponse,\n {\n functionName: string;\n parameters: TParams;\n options?: Omit<TSocketServerCallOptions, \"toCallIfNoResponse\">;\n }\n >,\n \"id\"\n > & {\n meta?: TExtraParams;\n }\n) => Promise<TResponse>;\n\nconst useCallMutationBase = <\n TFnToParams extends FnToParamsBase,\n TData = unknown,\n TError = unknown,\n TParams = unknown,\n TMetadata = unknown,\n>(\n promiseFunc: TPromiseFunction<TData, TParams, TMetadata>,\n functionName: keyof TFnToParams,\n service: (meta?: TMetadata) => string,\n options?: Omit<\n MutationOptions<TData, TError, TParams, TMetadata>,\n \"mutationFn\"\n >\n) => {\n const timeout = options?.timeout;\n const { ...rest } = useMemo(() => options ?? {}, [options]);\n const mutationFn = useCallback(\n async (parameters: TParams, meta?: TMetadata) => {\n try {\n return await promiseFunc({\n service: service(meta),\n functionName: functionName.toString(),\n parameters,\n options: {\n avoidTimeout: !timeout,\n customTimeout: timeout,\n },\n meta,\n });\n } catch (e) {\n if (e instanceof Error) {\n throw e;\n }\n throw new Error(e as string);\n }\n },\n [functionName, service, timeout]\n );\n\n return useMutation<TData, TError, TParams, TMetadata>({\n mutationFn,\n ...rest,\n });\n};\n\nexport function buildMutationHook<\n TFnToParams extends FnToParamsBase,\n TMetadata = unknown,\n>(\n promiseFunc: TPromiseFunction<unknown, unknown, unknown>,\n genTargetService: (meta?: TMetadata) => string\n) {\n return function useCallMutationBuilder<TFn extends keyof TFnToParams>(\n func: TFn,\n options?: Parameters<\n typeof useCallMutationBase<\n TFnToParams,\n TFnToParams[TFn][\"data\"],\n TFnToParams[TFn][\"error\"],\n TFnToParams[TFn][\"params\"],\n TMetadata\n >\n >[3]\n ) {\n return useCallMutationBase<\n TFnToParams,\n TFnToParams[TFn][\"data\"],\n TFnToParams[TFn][\"error\"],\n TFnToParams[TFn][\"params\"],\n TMetadata\n >(promiseFunc, func, genTargetService, options);\n };\n}\n\nconst useCallQueryBase = <\n TFnToParams extends FnToParamsBase,\n TData = unknown,\n TError = unknown,\n TParams = unknown,\n TSelect = TData,\n TMetadata = unknown,\n>(\n promiseFunction: TPromiseFunction<TData, TParams, TMetadata>,\n functionName: keyof TFnToParams,\n params: TParams,\n service: (meta?: TMetadata) => string,\n options?: Omit<QueryOptions<TData, TError, TParams, TSelect>, \"queryFn\"> & {\n meta?: TMetadata;\n }\n) => {\n const timeout = options?.timeout;\n const { ...rest } = useMemo(() => options ?? {}, [options]);\n const queryFn = useCallback(\n async (refetchParams: TParams | void) => {\n try {\n return await promiseFunction({\n service: service(options?.meta),\n functionName: functionName.toString(),\n parameters: refetchParams ?? params,\n options: {\n avoidTimeout: !timeout,\n customTimeout: timeout,\n },\n meta: options?.meta,\n });\n } catch (e) {\n if (e instanceof Error) {\n throw e;\n }\n throw new Error(e as string);\n }\n },\n [functionName, service, params, timeout]\n );\n\n return useQuery<TData, TError, TParams, TSelect>({\n queryFn,\n ...rest,\n });\n};\n\nexport function buildQueryHook<\n TFnToParams extends FnToParamsBase,\n TMetadata = unknown,\n>(\n promiseFunction: TPromiseFunction<unknown, unknown, unknown>,\n getTargetService: (meta?: TMetadata) => string\n) {\n return function useCallQueryBuilder<\n TFn extends keyof TFnToParams,\n TSelect = TFnToParams[TFn][\"data\"],\n >(\n func: TFn,\n params: TFnToParams[TFn][\"params\"],\n options?: Parameters<\n typeof useCallQueryBase<\n TFnToParams,\n TFnToParams[TFn][\"data\"],\n TFnToParams[TFn][\"error\"],\n TFnToParams[TFn][\"params\"],\n TSelect,\n TMetadata\n >\n >[4] & { meta?: TMetadata }\n ) {\n return useCallQueryBase<\n TFnToParams,\n TFnToParams[TFn][\"data\"],\n TFnToParams[TFn][\"error\"],\n TFnToParams[TFn][\"params\"],\n TSelect,\n TMetadata\n >(promiseFunction, func, params, getTargetService, options);\n };\n}\n","import { useCallback, useRef, useState } from \"react\";\n\nexport type MutationFunction<\n TData = unknown,\n TParams = unknown,\n TMetadata = unknown,\n> = (params: TParams, meta?: TMetadata) => Promise<TData>;\n\nexport interface MutationOptions<\n TData = unknown,\n TError = unknown,\n TParams = void,\n TMetadata = unknown,\n> {\n mutationFn: MutationFunction<TData, TParams, TMetadata>;\n params?: TParams;\n onSuccess?: (\n data: TData,\n variables: TParams,\n meta?: TMetadata\n ) => Promise<unknown> | unknown;\n onError?: (\n error: TMutationError<TError>,\n variables: TParams,\n meta?: TMetadata\n ) => Promise<unknown> | unknown;\n onSettled?: (\n data: TData | undefined,\n error: TMutationError<TError> | null,\n variables: TParams,\n meta?: TMetadata\n ) => Promise<unknown> | unknown;\n compareOrThrow?: (result: TData | TError) => boolean;\n timeout?: number;\n prepareParams?: (\n variables: TParams,\n defaults?: TParams,\n meta?: TMetadata\n ) => TParams;\n}\n\ntype TMutationError<TError> = TError | Error | null;\n\nexport interface MutateOptions<\n TData = unknown,\n TError = unknown,\n TParams = void,\n TMetadata = unknown,\n> {\n onSuccess?: (data: TData, variables: TParams, meta?: TMetadata) => void;\n onError?: (\n error: TMutationError<TError>,\n variables: TParams,\n meta?: TMetadata\n ) => void;\n onSettled?: (\n data: TData | undefined,\n error: TMutationError<TError> | null,\n variables: TParams,\n meta?: TMetadata\n ) => void;\n}\n\ntype MutationStatus = \"idle\" | \"loading\" | \"success\" | \"error\";\ntype RaceErrorReason = \"timeout\";\ntype RacePromises<T> = Promise<T | RaceErrorReason>;\n\nexport class ComparisonFailError<TPayload = unknown> extends Error {\n public readonly payload: TPayload;\n\n constructor(message: string, payload: TPayload) {\n super(message);\n this.name = this.constructor.name;\n this.payload = payload;\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, ComparisonFailError);\n }\n }\n}\n\nexport const useMutation = <\n TData = unknown,\n TError = TMutationError<unknown>,\n TParams = void,\n TMetadata = unknown,\n>(\n options: MutationOptions<TData, TError, TParams, TMetadata>\n) => {\n const {\n mutationFn,\n compareOrThrow,\n onError,\n onSettled,\n onSuccess,\n prepareParams,\n params,\n timeout,\n } = options;\n const [status, setStatus] = useState<MutationStatus>(\"idle\");\n const [error, setError] = useState<TMutationError<TError>>(null);\n const [result, setResult] = useState<TData | undefined>(undefined);\n const mutationFnRef = useRef(mutationFn);\n const internalOptionsRef = useRef({\n params,\n timeout,\n });\n const internalCallbackRefistry = <const>{\n onSuccess,\n onError,\n onSettled,\n compareOrThrow,\n prepareParams,\n };\n const internalCallbackRef = useRef(internalCallbackRefistry);\n internalCallbackRef.current = internalCallbackRefistry;\n\n const mutateAsync = useCallback(async (params: TParams, meta?: TMetadata) => {\n setStatus(\"loading\");\n setError(null);\n\n try {\n const promises: RacePromises<TData>[] = [\n mutationFnRef.current(\n internalCallbackRef.current.prepareParams\n ? internalCallbackRef.current.prepareParams(\n params,\n internalOptionsRef.current.params,\n meta\n )\n : params,\n meta\n ),\n ...(internalOptionsRef.current.timeout\n ? [\n new Promise<RaceErrorReason>((resolve) =>\n setTimeout(\n () => resolve(\"timeout\"),\n internalOptionsRef.current.timeout\n )\n ),\n ]\n : []),\n ];\n\n const res = await Promise.race(promises);\n\n if (res === \"timeout\") {\n throw new Error(\"timeout\");\n }\n\n if (internalCallbackRef.current.compareOrThrow?.(res)) {\n throw new ComparisonFailError(JSON.stringify(res), res);\n }\n\n setResult(res);\n setStatus(\"success\");\n\n internalCallbackRef.current.onSuccess?.(res, params, meta);\n internalCallbackRef.current.onSettled?.(res, null, params, meta);\n\n return res;\n } catch (error: any) {\n setError(error);\n setStatus(\"error\");\n\n internalCallbackRef.current.onError?.(error, params, meta);\n internalCallbackRef.current.onSettled?.(undefined, error, params, meta);\n\n throw error;\n }\n }, []);\n\n const mutate = useCallback(\n (\n variables: TParams,\n options?: MutateOptions<TData, TError, TParams, TMetadata> & {\n meta?: TMetadata;\n }\n ) => {\n mutateAsync(variables, options?.meta).then(\n (data) => {\n options?.onSuccess?.(data, variables, options?.meta);\n options?.onSettled?.(data, null, variables, options?.meta);\n },\n (error) => {\n options?.onError?.(error, variables, options?.meta);\n options?.onSettled?.(undefined, error, variables, options?.meta);\n }\n );\n },\n [mutateAsync]\n );\n\n return {\n mutateAsync,\n status,\n result,\n mutate,\n reset: () => {\n setStatus(\"idle\");\n setError(null);\n setResult(undefined);\n },\n error,\n };\n};\n","import { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport interface QueryOptions<\n TData = unknown,\n TError = unknown,\n TParams = void,\n TSelectData = TData,\n Stateless extends true | undefined = undefined,\n> {\n queryFn: (params: TParams | undefined | void) => Promise<TData>;\n onSuccess?: (data: TData) => Promise<void> | void;\n onError?: (error: TQueryError<TError>) => Promise<void> | void;\n onSettled?: (\n data: TData | undefined,\n error: TQueryError<TError> | undefined\n ) => Promise<void> | void;\n timeout?: number;\n enabled?: boolean;\n initialData?: TData | Functionize<TData>;\n select?: (data: TData) => TSelectData;\n refetchOnWindowFocus?: boolean;\n refetchInterval?: number;\n compareOrThrow?: (data: TData) => boolean;\n stateless?: Stateless;\n key?: TQueryKey;\n}\n\ntype Functionize<T> = () => T;\ntype QueryStatus = \"idle\" | \"loading\" | \"success\" | \"error\" | \"timeout\";\ntype RaceErrorReason = \"timeout\";\ntype RacePromises<T> = Promise<T | RaceErrorReason>;\ntype WithData<TData> = { data: TData | undefined };\ntype TQueryKey = readonly any[];\n\ntype TQueryError<TError> = TError | Error | null;\n\nexport type UseQueryResult<\n TData = unknown,\n TError = unknown,\n TParams = void,\n TSelectData = TData,\n Stateless extends true | undefined = undefined,\n> = {\n error: TQueryError<TError>;\n status: QueryStatus;\n refetch: (params: TParams | void | undefined) => Promise<void>;\n reset: () => void;\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n} & (Stateless extends true ? {} : WithData<TSelectData>);\n\nfunction normalizeQueryKey(queryKey: TQueryKey): string {\n return JSON.stringify(queryKey);\n}\n\ntype TInternalCallbackRef<TData, TError, TSelectData> = {\n onError?: (error: TQueryError<TError>) => Promise<void> | void;\n onSuccess?: (data: TData) => Promise<void> | void;\n onSettled?: (\n data: TData | undefined,\n error: TQueryError<TError> | undefined\n ) => Promise<void> | void;\n compareOrThrow?: (data: TData) => boolean;\n select?: (data: TData) => TSelectData;\n};\n\ntype TInternalOptionsRef<TData> = {\n timeout?: number;\n enabled: boolean;\n refetchOnWindowFocus: boolean;\n refetchInterval: number;\n compareOrThrow?: (data: TData) => boolean;\n stateless?: boolean;\n};\n\nconst getRandomUUID = () => Math.random().toString(36).substring(2, 15);\n\nexport const useQuery = <\n TData = unknown,\n TError = TQueryError<unknown>,\n TParams = void,\n TSelected = TData,\n Stateless extends true | undefined = undefined,\n>({\n queryFn,\n ...options\n}: QueryOptions<TData, TError, TParams, TSelected, Stateless>): UseQueryResult<\n TSelected,\n TError,\n TParams,\n TSelected,\n Stateless\n> => {\n const {\n enabled = true,\n refetchOnWindowFocus = false,\n refetchInterval = 0,\n initialData,\n select,\n onError,\n onSuccess,\n onSettled,\n timeout,\n compareOrThrow,\n stateless,\n key: queryKeyPassed,\n } = options;\n const queryKey = normalizeQueryKey(queryKeyPassed ?? []);\n const lastFetchedAt = useRef<number | null>(null);\n const lastQueryKey = useRef<string | undefined>(undefined);\n const queryFnRef = useRef(queryFn);\n queryFnRef.current = queryFn;\n const internalCallbackRef = useRef<\n TInternalCallbackRef<TData, TError, TSelected>\n >({});\n internalCallbackRef.current = {\n onError,\n onSuccess,\n onSettled,\n compareOrThrow,\n select,\n };\n const internalOptionsRef = useRef<TInternalOptionsRef<TData>>({\n enabled,\n refetchOnWindowFocus,\n refetchInterval,\n compareOrThrow,\n stateless,\n timeout,\n });\n internalOptionsRef.current = {\n enabled,\n refetchOnWindowFocus,\n refetchInterval,\n compareOrThrow,\n stateless,\n timeout,\n };\n const requestIdRef = useRef(getRandomUUID());\n\n const [status, setStatus] = useState<QueryStatus>(() => {\n return \"idle\";\n });\n const [error, setError] = useState<TQueryError<TError>>(null);\n const [data, setData] = useState<TData | undefined>(() => {\n if (initialData !== undefined) {\n if (typeof initialData === \"function\") {\n return (initialData as Functionize<TData>)();\n }\n\n return initialData as TData;\n }\n\n return undefined;\n });\n\n const handleSetData = useCallback((data: TData) => {\n if (internalOptionsRef.current.stateless) {\n return;\n }\n\n setData(data);\n }, []);\n\n const shouldRefetch = useCallback(() => {\n if (!internalOptionsRef.current.enabled) {\n return false;\n }\n\n if (lastFetchedAt.current === null) {\n return true;\n }\n\n return (\n new Date().getTime() - lastFetchedAt.current >\n internalOptionsRef.current?.refetchInterval\n );\n }, []);\n\n const refetch = useCallback(\n async (params: TParams | void | undefined = undefined) => {\n const requestId = getRandomUUID();\n requestIdRef.current = requestId;\n if (!internalOptionsRef.current.enabled) {\n return;\n }\n\n setStatus(\"loading\");\n setError(null);\n\n try {\n const promises: RacePromises<TData>[] = [\n queryFnRef.current(params),\n ...(internalOptionsRef.current.timeout\n ? [\n new Promise<RaceErrorReason>((resolve) =>\n setTimeout(\n () => resolve(\"timeout\"),\n internalOptionsRef.current.timeout\n )\n ),\n ]\n : []),\n ];\n\n const res = await Promise.race(promises);\n if (requestIdRef.current !== requestId) {\n return;\n }\n\n if (res === \"timeout\") {\n throw new Error(\"timeout\");\n }\n\n handleSetData(res);\n\n if (\n internalCallbackRef.current.compareOrThrow &&\n internalCallbackRef.current.compareOrThrow(res) === true\n ) {\n throw new Error(\"failedComparison\");\n }\n\n setStatus(\"success\");\n lastFetchedAt.current = new Date().getTime();\n internalCallbackRef.current.onSuccess?.(res);\n internalCallbackRef.current.onSettled?.(res, undefined);\n } catch (error: any) {\n setError(error);\n setStatus(\"error\");\n internalCallbackRef.current.onError?.(error);\n internalCallbackRef.current.onSettled?.(undefined, error);\n }\n },\n [handleSetData]\n );\n\n const reset = useCallback(() => {\n setData(undefined);\n setStatus(\"idle\");\n setError(null);\n refetch();\n }, [refetch]);\n\n useEffect(() => {\n const cleanups: (() => void)[] = [];\n\n // If the query should be refetched on window focus, add a listener\n if (refetchOnWindowFocus) {\n const queryHandleFocus = () => {\n refetch();\n };\n\n window.addEventListener(\"focus\", queryHandleFocus);\n\n cleanups.push(() => {\n window.removeEventListener(\"focus\", queryHandleFocus);\n });\n }\n\n // If the query should be refetched on an interval, add an interval\n if (refetchInterval > 0) {\n const interval = setInterval(() => {\n if (shouldRefetch()) {\n refetch();\n }\n }, refetchInterval);\n\n cleanups.push(() => {\n clearInterval(interval);\n });\n }\n\n // If the query key has changed, refetch\n if (\n lastQueryKey.current === undefined ||\n queryKey !== lastQueryKey.current\n ) {\n lastQueryKey.current = queryKey;\n refetch();\n }\n\n return () => {\n cleanups.forEach((cleanup) => cleanup());\n };\n }, [\n queryKey,\n enabled,\n refetchOnWindowFocus,\n refetchInterval,\n shouldRefetch,\n refetch,\n ]);\n\n return {\n data:\n select && data !== undefined\n ? select(data as TData)\n : (data as unknown as TSelected),\n error,\n status,\n refetch,\n reset,\n };\n};\n","/**\n * @fileoverview useSubscriptionCore\n * @name useSubscriptionCore.ts\n * @description useSubscriptionCore | This hook handle core subscription logic\n * and provides a way to subscribe and unsubscribe to a topic via any callback\n */\n\nimport { shallowEqual } from \"@pixotope/utils/comparison\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\ntype SubscriptionState = \"idle\" | \"subscribed\" | \"subscribing\" | \"error\";\n\nexport type MessageHandler<TMessage> = (message: TMessage) => void;\nexport type Connection = {\n acknowledge: () => void;\n};\nexport type SubscriptionCoreOptions<\n TData,\n TMessage = TData,\n Stateless extends true | undefined = undefined,\n> = {\n /**\n * @description Function that will be called when the message is received.\n */\n onMessage?: (message: TMessage) => void;\n /**\n * @description Function that will be called when the subscription is created.\n */\n onSubscribed?: (message: TMessage) => void;\n /**\n * @description Function that will be called when the subscription is created.\n */\n onError?: (error: TMessage) => void;\n /**\n * @description Whether the subscription is enabled.\n * @default true\n */\n enabled?: boolean;\n /**\n * @description Function that will be called before the message is processed.\n * Returning `true` will cause the message to not be set to state and call {@link onError} if provided.\n * Status will be set to `error`.\n */\n compareOrThrow?: (data: TMessage) => boolean;\n /**\n * @description Function that will be called to select the data from the message.\n */\n select?: (data: TMessage) => TData;\n /**\n * @description Initial state of the subscription.\n * @default undefined\n */\n initialState?: TData;\n /**\n * @description Function that will be called when the subscription is created.\n */\n subscriberFn: (\n handler: MessageHandler<TMessage>,\n connection: Connection\n ) => () => void /** unsubscribe Fn */;\n /**\n * @description Whether the subscription is stateless. Data will not be\n * stored by the hook internally.\n * @default false\n */\n stateless?: Stateless;\n /**\n * @description Custom equality function for comparing data.\n * @default shallowEqual\n */\n isEqual?: <T = TData>(a: T, b: T) => boolean;\n};\n\ntype WithStatus = {\n status: SubscriptionState;\n};\n\ntype WithData<TData> = {\n data: TData;\n};\n\nexport type SubscriptionCoreReturnType<\n TData,\n Stateless extends true | undefined,\n> = {\n reSubscribe: () => void;\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n} & (Stateless extends true ? {} : WithStatus & WithData<TData>);\n\n/**\n * @description `useSubscriptionCore` | This hook handle core subscription logic\n * and provides a way to subscribe and unsubscribe to a topic via any callback.\n * The hook expose a handler function. All the consumer code need to do is to\n * call this handler function with the message received from the topic or pass\n * it directly to the callback function that is passed to the subscriberFn.\n * - `status` - current status of the subscription\n * - `data` - the data after the select function is applied to the message\n * - `reSubscribe` - function that can be called to re-subscribe to the topic\n *\n * An example how this hook works can be found in {@link ./useSubscription.ts}\n */\nexport function useSubscriptionCore<\n TData = unknown,\n TMessage = TData,\n Stateless extends true | undefined = undefined,\n>(\n options: SubscriptionCoreOptions<TData, TMessage, Stateless>\n): SubscriptionCoreReturnType<TData, Stateless> {\n const {\n enabled = true,\n initialState = undefined,\n onSubscribed,\n stateless,\n compareOrThrow,\n subscriberFn,\n onMessage,\n onError,\n select,\n isEqual = shallowEqual,\n } = options;\n const [status, setStatus] = useState<SubscriptionState>(\"idle\");\n const [data, setData] = useState<TData | undefined>(initialState);\n const unsubcribeRef = useRef<() => void | undefined>(undefined);\n const initialStateRef = useRef(initialState);\n const subscriberFnRef = useRef(subscriberFn);\n const callbackRefRegistry = <const>{\n onMessage,\n onError,\n select,\n compareOrThrow,\n onSubscribed,\n isEqual,\n };\n const internalCallbacksRef = useRef(callbackRefRegistry);\n internalCallbacksRef.current = callbackRefRegistry;\n\n const updateStatus = useCallback(\n (newStatus: SubscriptionState, message?: TMessage) => {\n if (stateless) {\n return;\n }\n\n setStatus((prev) => {\n if (prev === newStatus) {\n return prev;\n }\n\n if (newStatus === \"subscribed\" && message) {\n internalCallbacksRef.current.onSubscribed?.(message);\n }\n\n return newStatus;\n });\n },\n [stateless]\n );\n\n const connection: Connection = useMemo(\n () => ({\n acknowledge: () => {\n updateStatus(\"subscribed\");\n },\n }),\n [updateStatus]\n );\n\n const handler = useCallback(\n async (message: TMessage) => {\n if (internalCallbacksRef.current.compareOrThrow?.(message)) {\n updateStatus(\"error\");\n internalCallbacksRef.current.onError?.(message);\n\n return;\n }\n\n const selectedMessage = <TData>(\n (internalCallbacksRef.current.select?.(message) ?? message)\n );\n\n if (!stateless) {\n setData((prev) => {\n if (isEqual(prev, selectedMessage)) {\n return prev;\n }\n\n return selectedMessage;\n });\n }\n\n updateStatus(\"subscribed\", message);\n internalCallbacksRef.current.onMessage?.(message);\n },\n [stateless, updateStatus]\n );\n\n const unsubscribe = useCallback(() => {\n updateStatus(\"idle\");\n unsubcribeRef.current?.();\n unsubcribeRef.current = undefined;\n }, [updateStatus]);\n\n const subscribe = useCallback(() => {\n unsubcribeRef.current?.();\n updateStatus(\"subscribing\");\n setData(initialStateRef.current);\n unsubcribeRef.current = subscriberFnRef.current(handler, connection);\n }, [connection, handler, updateStatus]);\n\n useEffect(() => {\n if (enabled) {\n subscribe();\n } else {\n unsubscribe();\n }\n\n return () => {\n unsubscribe();\n };\n }, [enabled, subscribe, unsubscribe]);\n\n return {\n status,\n data,\n reSubscribe: subscribe,\n } as unknown as any;\n}\n","import {\n SubscriptionCoreOptions,\n useSubscriptionCore,\n} from \"./useSubscriptionCore\";\n\nexport type SubscriptionOptions<\n TData,\n TMessage = unknown,\n Stateless extends true | undefined = undefined,\n TMetadata extends {} = {},\n> = Omit<\n SubscriptionCoreOptions<TData, TMessage, Stateless>,\n \"subscriberFn\"\n> & {\n service: string;\n topic: string;\n maxDownwardDepth?: number;\n} & {\n meta?: TMetadata;\n};\n\nexport type TSubscriptionHandlerFunction<\n TMessage,\n TMetadata extends {} = {},\n> = (\n opts: {\n service: string;\n name: string;\n callback: (message: TMessage) => void;\n maxDownwardDepth?: number;\n } & { meta?: TMetadata }\n) => () => void;\n\nexport function useSubscription<\n TData = unknown,\n TMessage = TData,\n Stateless extends true | undefined = undefined,\n TMetadata extends {} = {},\n>(\n subscriptionHandler: TSubscriptionHandlerFunction<TMessage, TMetadata>,\n options: SubscriptionOptions<TData, TMessage, Stateless, TMetadata>\n) {\n const { topic, service, maxDownwardDepth = 1000, meta, ...rest } = options;\n\n return useSubscriptionCore<TData, TMessage, Stateless>({\n ...rest,\n subscriberFn: (handler) => {\n const unsubscribe = subscriptionHandler({\n service,\n name: topic,\n callback: (message: TMessage) => {\n handler(message);\n },\n maxDownwardDepth,\n meta,\n });\n\n return unsubscribe;\n },\n });\n}\n\nexport function buildServiceSubscriptionHook<TMetadata extends {} = {}>(\n subscriptionHandler: TSubscriptionHandlerFunction<unknown, TMetadata>,\n targetMachine: (machine: string | undefined) => string\n) {\n return function useSubscriptionBuilder<\n TData,\n TMessage = TData,\n Stateless extends true | undefined = undefined,\n >(\n options: Omit<\n SubscriptionOptions<TData, TMessage, Stateless, TMetadata>,\n \"service\"\n > & {\n machine?: string;\n }\n ) {\n const targetService = targetMachine(options.machine);\n return useSubscription<TData, TMessage, Stateless>(\n <TSubscriptionHandlerFunction<TMessage>>subscriptionHandler,\n {\n service: targetService,\n ...options,\n }\n );\n };\n}\n","import type { ZMQProxyWSClient } from \"@pixotope/zmq-client\";\nimport type { TPromiseFunction } from \"./factories\";\nimport type { buildServiceSubscriptionHook } from \"./useSubscription\";\n\nexport type TProxySubscriptionHandlerParams<TMetadata extends {} = {}> =\n Parameters<Parameters<typeof buildServiceSubscriptionHook<TMetadata>>[0]>[0];\n\nexport function bindClientSocketProxy(socketClientProxy: ZMQProxyWSClient) {\n return (args: TProxySubscriptionHandlerParams) => {\n const { callback: cbHook, ...rest } = args;\n return socketClientProxy.mirror({\n ...rest,\n callback: (message) => {\n cbHook(message.message);\n },\n })[0];\n };\n}\n\nexport function bindPromiseFunction(clientSocketProxy: ZMQProxyWSClient) {\n return async (\n ...args: Parameters<TPromiseFunction<unknown, unknown, unknown>>\n ) => {\n const res = await clientSocketProxy.callAsync(...args);\n return res.message.Result;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AACA,QAAIA,aAAY,OAAO;AACvB,QAAIC,oBAAmB,OAAO;AAC9B,QAAIC,qBAAoB,OAAO;AAC/B,QAAIC,gBAAe,OAAO,UAAU;AACpC,QAAI,WAAW,CAAC,QAAQ,QAAQ;AAC9B,eAAS,QAAQ;AACf,QAAAH,WAAU,QAAQ,MAAM,EAAE,KAAK,IAAI,IAAI,GAAG,YAAY,KAAK,CAAC;AAAA,IAChE;AACA,QAAII,eAAc,CAAC,IAAI,MAAM,QAAQ,SAAS;AAC5C,UAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;AAClE,iBAAS,OAAOF,mBAAkB,IAAI;AACpC,cAAI,CAACC,cAAa,KAAK,IAAI,GAAG,KAAK,QAAQ;AACzC,YAAAH,WAAU,IAAI,KAAK,EAAE,KAAK,MAAM,KAAK,GAAG,GAAG,YAAY,EAAE,OAAOC,kBAAiB,MAAM,GAAG,MAAM,KAAK,WAAW,CAAC;AAAA,MACvH;AACA,aAAO;AAAA,IACT;AACA,QAAI,eAAe,CAAC,QAAQG,aAAYJ,WAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AAGzF,QAAI,qBAAqB,CAAC;AAC1B,aAAS,oBAAoB;AAAA,MAC3B,cAAc,MAAMK;AAAA,IACtB,CAAC;AACD,WAAO,UAAU,aAAa,kBAAkB;AAGhD,aAASA,cAAa,MAAM,MAAM;AAChC,UAAI,OAAO,GAAG,MAAM,IAAI,GAAG;AACzB,eAAO;AA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oBAAoB,mBAAqC;AACvE,SAAO,IACF,SACA;AACH,UAAM,MAAM,MAAM,kBAAkB,UAAU,GAAG,IAAI;AACrD,WAAO,IAAI,QAAQ;AAAA,EACrB;AACF;","names":["__defProp","__getOwnPropDesc","__getOwnPropNames","__hasOwnProp","__copyProps","shallowEqual","useCallback","params","error","options","useCallback","useRef","useState","useRef","useState","useCallback","data","_a","_b","error","useCallback","useCallback","useEffect","useMemo","useRef","useState","useState","useRef","useCallback","useMemo","useEffect"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixotope/query",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"tsup": "^8.5.0",
|
|
21
21
|
"typescript": "^5.7.2",
|
|
22
22
|
"vitest": "^3.2.4",
|
|
23
|
-
"@pixotope/utils": "0.
|
|
24
|
-
"@pixotope/zmq-client": "0.9.
|
|
23
|
+
"@pixotope/utils": "0.2.0",
|
|
24
|
+
"@pixotope/zmq-client": "0.9.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=17.0.0"
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
3
|
+
import { buildMutationHook, buildQueryHook, MutationInfo } from "./factories";
|
|
4
|
+
|
|
5
|
+
describe("factories", () => {
|
|
6
|
+
it("should build mutation hook", () => {
|
|
7
|
+
const mutationHook = buildMutationHook(vi.fn(), vi.fn());
|
|
8
|
+
expect(mutationHook).toBeDefined();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should build query hook", () => {
|
|
12
|
+
const queryHook = buildQueryHook(vi.fn(), vi.fn());
|
|
13
|
+
expect(queryHook).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("mutation hook should call promise function", async () => {
|
|
17
|
+
const promiseFunction = vi.fn();
|
|
18
|
+
const getServiceName = vi.fn();
|
|
19
|
+
const useCustomMutationHook = buildMutationHook(
|
|
20
|
+
promiseFunction,
|
|
21
|
+
getServiceName
|
|
22
|
+
);
|
|
23
|
+
const { result } = renderHook(() => useCustomMutationHook("testFunction"));
|
|
24
|
+
act(() => result.current.mutate({}, { meta: { foo: "bar" } }));
|
|
25
|
+
await waitFor(() => expect(promiseFunction).toBeCalledTimes(1));
|
|
26
|
+
expect(promiseFunction).toBeCalledWith({
|
|
27
|
+
service: getServiceName(),
|
|
28
|
+
functionName: "testFunction",
|
|
29
|
+
parameters: {},
|
|
30
|
+
options: {
|
|
31
|
+
avoidTimeout: true,
|
|
32
|
+
customTimeout: undefined,
|
|
33
|
+
},
|
|
34
|
+
meta: { foo: "bar" },
|
|
35
|
+
});
|
|
36
|
+
expect(getServiceName).toBeCalledWith({ foo: "bar" });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("query hook should call promise function", async () => {
|
|
40
|
+
const promiseFunction = vi.fn();
|
|
41
|
+
const getServiceName = vi.fn();
|
|
42
|
+
const useCustomQueryHook = buildQueryHook<{
|
|
43
|
+
testFunction: MutationInfo<unknown, unknown, { foo: string }>;
|
|
44
|
+
}>(promiseFunction, getServiceName);
|
|
45
|
+
renderHook(() =>
|
|
46
|
+
useCustomQueryHook(
|
|
47
|
+
"testFunction",
|
|
48
|
+
{ foo: "bar" },
|
|
49
|
+
{ meta: { machine: "machine" } }
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
await waitFor(() => expect(promiseFunction).toBeCalledTimes(1));
|
|
53
|
+
expect(getServiceName).toBeCalledWith({ machine: "machine" });
|
|
54
|
+
expect(promiseFunction).toBeCalledWith({
|
|
55
|
+
service: getServiceName({ machine: "machine" }),
|
|
56
|
+
functionName: "testFunction",
|
|
57
|
+
parameters: { foo: "bar" },
|
|
58
|
+
options: {
|
|
59
|
+
avoidTimeout: true,
|
|
60
|
+
customTimeout: undefined,
|
|
61
|
+
},
|
|
62
|
+
meta: { machine: "machine" },
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|