@pixotope/query 0.1.0 → 0.4.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.
@@ -0,0 +1,24 @@
1
+ import type { ZMQProxyWSClient } from "@pixotope/zmq-client";
2
+ import type { TPromiseFunction } from "./factories";
3
+ import type { buildServiceSubscriptionHook } from "./useSubscription";
4
+
5
+ export function bindClientSocketProxy(socketClientProxy: ZMQProxyWSClient) {
6
+ return (
7
+ ...args: Parameters<Parameters<typeof buildServiceSubscriptionHook>[0]>
8
+ ) => {
9
+ const { callback: cbHook, ...rest } = args[0];
10
+ return socketClientProxy.mirror({
11
+ ...rest,
12
+ callback: (message) => {
13
+ cbHook(message.message);
14
+ },
15
+ })[0];
16
+ };
17
+ }
18
+
19
+ export function bindPromiseFunction(clientSocketProxy: ZMQProxyWSClient) {
20
+ return async (...args: Parameters<TPromiseFunction<unknown, unknown>>) => {
21
+ const res = await clientSocketProxy.callAsync(...args);
22
+ return res.message.Result;
23
+ };
24
+ }
@@ -1,4 +1,3 @@
1
- import type { DHClientWebSocketProxy } from "@pixotope/zmq-client";
2
1
  import {
3
2
  SubscriptionCoreOptions,
4
3
  useSubscriptionCore,
@@ -19,7 +18,7 @@ export type SubscriptionOptions<
19
18
 
20
19
  export type TSubscriptionHandlerFunction<TMessage> = (opts: {
21
20
  service: string;
22
- topic: string;
21
+ name: string;
23
22
  callback: (message: TMessage) => void;
24
23
  maxDownwardDepth?: number;
25
24
  }) => () => void;
@@ -39,7 +38,7 @@ export function useSubscription<
39
38
  subscriberFn: (handler) => {
40
39
  const unsubscribe = subscriptionHandler({
41
40
  service,
42
- topic,
41
+ name: topic,
43
42
  callback: (message: TMessage) => {
44
43
  handler(message);
45
44
  },
@@ -77,11 +76,3 @@ export function buildServiceSubscriptionHook(
77
76
  );
78
77
  };
79
78
  }
80
-
81
- export function bindClientSocketProxy(
82
- socketClientProxy: DHClientWebSocketProxy
83
- ) {
84
- return (
85
- ...args: Parameters<Parameters<typeof buildServiceSubscriptionHook>[0]>
86
- ) => socketClientProxy.mirror(...args)[0];
87
- }