@akanjs/signal 0.0.28 → 0.0.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/signal",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type Client as GqlClient } from "@urql/core";
2
+ import type * as dgram from "dgram";
2
3
  import { type Socket } from "socket.io-client";
3
4
  interface SubscribeOption {
4
5
  key: string;
@@ -34,6 +35,7 @@ declare class Client {
34
35
  isInitialized: boolean;
35
36
  uri: string;
36
37
  ws: string;
38
+ udp: dgram.Socket | null;
37
39
  gql: GqlClient;
38
40
  jwt: string | undefined | null;
39
41
  getJwt(): Promise<string | null>;
@@ -46,6 +48,7 @@ declare class Client {
46
48
  reset(): void;
47
49
  clone(data?: Partial<Client>): Client;
48
50
  terminate(): void;
51
+ setUdp(udp: dgram.Socket): void;
49
52
  }
50
53
  export declare const client: Client;
51
54
  export type { Client, SocketIo };
package/src/client.js CHANGED
@@ -84,6 +84,7 @@ class Client {
84
84
  isInitialized = false;
85
85
  uri = import_base.baseClientEnv.serverGraphqlUri;
86
86
  ws = import_base.baseClientEnv.serverWsUri;
87
+ udp = null;
87
88
  gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
88
89
  jwt = null;
89
90
  async getJwt() {
@@ -156,6 +157,9 @@ class Client {
156
157
  Client.globalIoMap.forEach((io2) => io2.disconnect());
157
158
  this.isInitialized = false;
158
159
  }
160
+ setUdp(udp) {
161
+ this.udp = udp;
162
+ }
159
163
  }
160
164
  const client = new Client();
161
165
  // Annotate the CommonJS export names for ESM import in node:
package/src/gql.js CHANGED
@@ -676,11 +676,21 @@ const fetchOf = (sigRef) => {
676
676
  const message = Object.fromEntries(
677
677
  argMetas.map((argMeta) => [argMeta.name, serializeArg(argMeta, args[argMeta.idx]) ?? null])
678
678
  );
679
- const io = this.client.getIo(fetchPolicy.url);
680
- void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
681
- io.emit(gqlMeta.key, message);
682
- import_common.Logger.debug(`socket emit: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
683
- });
679
+ if (fetchPolicy.transport === "udp") {
680
+ if (!this.client.udp)
681
+ throw new Error("UDP is not set");
682
+ const uri = fetchPolicy.url ?? "udpout:localhost:4000";
683
+ const [host, port] = uri.split(":").slice(1);
684
+ this.client.udp.send(JSON.stringify(message), parseInt(port), host);
685
+ import_common.Logger.debug(`udp emit: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
686
+ return;
687
+ } else {
688
+ const io = this.client.getIo(fetchPolicy.url);
689
+ void this.client.waitUntilWebSocketConnected(fetchPolicy.url).then(() => {
690
+ io.emit(gqlMeta.key, message);
691
+ import_common.Logger.debug(`socket emit: ${gqlMeta.key}: ${(0, import_base.dayjs)().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
692
+ });
693
+ }
684
694
  };
685
695
  const listenEvent = function(handleEvent, fetchPolicy = {}) {
686
696
  const crystalize2 = (data) => {