zynapse 0.1.11 → 0.1.13
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/dist/cli/index.js +24 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/schema/client_side.d.ts.map +1 -1
- package/dist/schema/client_side.js +29 -115
- package/dist/schema/client_side.js.map +1 -1
- package/dist/schema/index.d.ts +3 -14
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/useWebSocket.d.ts +124 -0
- package/dist/schema/useWebSocket.d.ts.map +1 -0
- package/dist/schema/useWebSocket.js +257 -0
- package/dist/schema/useWebSocket.js.map +1 -0
- package/dist/schema/useWebSocket.ts +428 -0
- package/dist/server/index.d.ts +2 -4
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +42 -31
- package/dist/server/index.js.map +1 -1
- package/package.json +12 -9
package/dist/cli/index.js
CHANGED
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { parseArgs } from "util";
|
|
4
4
|
import { GenerateCode } from "../schema/client_side";
|
|
5
|
-
import { readdirSync,
|
|
5
|
+
import { readdirSync, readFileSync } from "fs";
|
|
6
|
+
import { rm } from "fs/promises";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
// Read the WebSocket template file
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const templatePath = path.join(__dirname, "../schema/useWebSocket.ts");
|
|
12
|
+
const useWebsocketTemplate = readFileSync(templatePath, "utf-8");
|
|
6
13
|
const { values: { inputFile, outputFolder }, } = parseArgs({
|
|
7
14
|
args: Bun.argv || process.argv,
|
|
8
15
|
allowPositionals: true,
|
|
@@ -29,15 +36,23 @@ const oldFilesDirectory = path.join(process.cwd(), outputFolder);
|
|
|
29
36
|
const files = readdirSync(oldFilesDirectory);
|
|
30
37
|
for (const file of files) {
|
|
31
38
|
const toDelete = path.join(oldFilesDirectory, file);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}
|
|
39
|
+
try {
|
|
40
|
+
await rm(toDelete, {
|
|
41
|
+
maxRetries: 3,
|
|
42
|
+
recursive: true,
|
|
43
|
+
force: true,
|
|
44
|
+
});
|
|
45
|
+
console.log(`${toDelete} deleted`);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
console.error("Fialed at deleting file", e);
|
|
49
|
+
}
|
|
40
50
|
}
|
|
51
|
+
// First, update the websocket lib.
|
|
52
|
+
const wsFileName = path.join(process.cwd(), outputFolder, "useWebsocket.ts");
|
|
53
|
+
const wsFHandle = Bun.file(wsFileName);
|
|
54
|
+
const bytes = await wsFHandle.write(useWebsocketTemplate);
|
|
55
|
+
console.log(`Websocket lib updated with ${bytes} at ${wsFileName}`);
|
|
41
56
|
// TODO: Add some sort of validation to make sure the mentioned file is actually a schema
|
|
42
57
|
const services_buffers = await GenerateCode(file);
|
|
43
58
|
let total_bytes = 0;
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAiC,WAAW,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9E,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,mCAAmC;AACnC,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,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AAC;IACpD,WAAW,IAAI,KAAK,CAAC;AACtB,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,GAAG,WAAW,sBAAsB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client_side.d.ts","sourceRoot":"","sources":["../../src/schema/client_side.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAW,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"client_side.d.ts","sourceRoot":"","sources":["../../src/schema/client_side.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAW,MAAM,GAAG,CAAC;AAwVvC,KAAK,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAWtD,KAAK,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAEtC,wBAAsB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAgC1E"}
|
|
@@ -30,7 +30,7 @@ async function mutationProcedureCodeGen(proc, parentService) {
|
|
|
30
30
|
name: inputAliasIdentifier,
|
|
31
31
|
});
|
|
32
32
|
let buff = `export ${stringifiedAlias}\nexport ${zodCode}\nexport function use${parentService.name}${proc.name}Mutation`;
|
|
33
|
-
buff += `(extraOptions?: Omit<UseMutationOptions<${outputTypeIdentifier}, Error, z.infer<typeof ${inputAliasIdentifier}>, unknown>, "mutationFn"
|
|
33
|
+
buff += `(extraOptions?: Omit<UseMutationOptions<${outputTypeIdentifier}, Error, z.infer<typeof ${inputAliasIdentifier}>, unknown>, "mutationFn">, headers?: HeadersInit) {
|
|
34
34
|
/*${proc.description}*/
|
|
35
35
|
return useMutation({
|
|
36
36
|
...extraOptions,
|
|
@@ -41,14 +41,11 @@ return useMutation({
|
|
|
41
41
|
throw new Error(validationResult.error.message)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
const response = await fetch("/_api",{
|
|
44
|
+
|
|
45
|
+
const response = await fetch("/_api/${parentService.name}/${proc.name}",{
|
|
46
46
|
method: "POST",
|
|
47
|
-
body: JSON.stringify(
|
|
48
|
-
|
|
49
|
-
procedure: '${proc.name}',
|
|
50
|
-
data: validationResult.data
|
|
51
|
-
}),
|
|
47
|
+
body: JSON.stringify(validationResult.data),
|
|
48
|
+
headers: headers,
|
|
52
49
|
})
|
|
53
50
|
|
|
54
51
|
if (!response.ok) {
|
|
@@ -84,94 +81,14 @@ async function bidirectionalProcedureCodeGen(proc, parentService) {
|
|
|
84
81
|
name: inputIdentifier,
|
|
85
82
|
});
|
|
86
83
|
let buff = `export ${schema}\nexport ${stringifiedAlias}\n\nexport function use${parentService.name}${proc.name}Bidirectional`;
|
|
87
|
-
buff += `(
|
|
88
|
-
onError?: (errorMessage: string) => void;
|
|
89
|
-
onClose?: () => void;
|
|
90
|
-
})`;
|
|
84
|
+
buff += `(options: UseWebSocketOptions = {}): UseWebSocketReturn<z.infer<typeof ${inputIdentifier}>, ${outputTypeIdentifier}>`;
|
|
91
85
|
buff += "{\n";
|
|
92
86
|
buff += `/*${proc.description}*/\n`;
|
|
93
|
-
// Initial setup of state.
|
|
94
|
-
buff += `const socketRef = useRef<WebSocket>();\n`;
|
|
95
|
-
buff += `const [messages, setMessages] = useState<Array<${outputTypeIdentifier}>>([]);\n`;
|
|
96
|
-
buff += `const [isConnected, setIsConnected] = useState<boolean>(false);\n`;
|
|
97
|
-
// Avoid re-render on callback change.
|
|
98
|
-
buff += `
|
|
99
|
-
const onErrorRef = useRef(extraOptions?.onError);
|
|
100
|
-
const onCloseRef = useRef(extraOptions?.onClose);
|
|
101
|
-
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
onErrorRef.current = extraOptions?.onError;
|
|
104
|
-
onCloseRef.current = extraOptions?.onClose;
|
|
105
|
-
}, [extraOptions]);\n`;
|
|
106
|
-
// Send function
|
|
107
|
-
buff += `
|
|
108
|
-
const send = useCallback((data: z.infer<typeof ${inputIdentifier}>) => {
|
|
109
|
-
if (socketRef.current && socketRef.current.readyState === WebSocket.OPEN) {
|
|
110
|
-
socketRef.current.send(JSON.stringify(data));
|
|
111
|
-
}
|
|
112
|
-
}, []);\n`;
|
|
113
87
|
// Use effect main logic.
|
|
114
|
-
buff += `
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
120
|
-
const targetURL = new URL(\`\${protocol}//\${window.location.host}/_api\`);
|
|
121
|
-
const fullPayload = {
|
|
122
|
-
service: "${parentService.name}",
|
|
123
|
-
procedure: "${proc.name}",
|
|
124
|
-
data: {}
|
|
125
|
-
};
|
|
126
|
-
const stringifiedArguments = JSON.stringify(fullPayload);
|
|
127
|
-
const encodedArguments = encodeURIComponent(stringifiedArguments);
|
|
128
|
-
targetURL.searchParams.set("payload", encodedArguments);
|
|
129
|
-
|
|
130
|
-
const socket = new WebSocket(targetURL);
|
|
131
|
-
socketRef.current = socket;
|
|
132
|
-
|
|
133
|
-
socket.addEventListener("open", () => {
|
|
134
|
-
setIsConnected(true);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
socket.addEventListener("error", () => {
|
|
138
|
-
if (onErrorRef.current) {
|
|
139
|
-
onErrorRef.current("WebSocket connection error.");
|
|
140
|
-
}
|
|
141
|
-
setIsConnected(false);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
socket.addEventListener("message", (ev) => {
|
|
145
|
-
try {
|
|
146
|
-
const data = JSON.parse(ev.data);
|
|
147
|
-
setMessages((prev) => [...prev, data]);
|
|
148
|
-
} catch {
|
|
149
|
-
if (onErrorRef.current) {
|
|
150
|
-
onErrorRef.current("Failed to decode data");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
socket.addEventListener("close", () => {
|
|
156
|
-
if (onCloseRef.current) {
|
|
157
|
-
onCloseRef.current();
|
|
158
|
-
}
|
|
159
|
-
setIsConnected(false);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return () => {
|
|
163
|
-
socket.close();
|
|
164
|
-
socketRef.current = undefined;
|
|
165
|
-
setIsConnected(false);
|
|
166
|
-
};
|
|
167
|
-
}, [active]);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
messages,
|
|
172
|
-
isConnected,
|
|
173
|
-
send,
|
|
174
|
-
};
|
|
88
|
+
buff += `
|
|
89
|
+
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
90
|
+
const targetURL = new URL(\`\${protocol}//\${window.location.host}/_api/${parentService.name}/${proc.name}\`);
|
|
91
|
+
return useWebSocket<z.infer<typeof ${inputIdentifier}>, ${outputTypeIdentifier}>(targetURL.href,options);
|
|
175
92
|
}
|
|
176
93
|
`;
|
|
177
94
|
return await prettier.format(buff, { parser: "babel-ts" });
|
|
@@ -214,13 +131,8 @@ useEffect(() => {
|
|
|
214
131
|
return
|
|
215
132
|
}
|
|
216
133
|
|
|
217
|
-
const targetURL = new URL("/_api", window.location.origin);
|
|
218
|
-
const
|
|
219
|
-
service: "${parentService.name}",
|
|
220
|
-
procedure: "${proc.name}",
|
|
221
|
-
data: args,
|
|
222
|
-
};
|
|
223
|
-
const stringifiedArguments = JSON.stringify(fullPayload);
|
|
134
|
+
const targetURL = new URL("/_api/${parentService.name}/${proc.name}", window.location.origin);
|
|
135
|
+
const stringifiedArguments = JSON.stringify(args);
|
|
224
136
|
const encodedArguments = encodeURIComponent(stringifiedArguments);
|
|
225
137
|
targetURL.searchParams.set("payload", encodedArguments);
|
|
226
138
|
|
|
@@ -300,13 +212,13 @@ async function queryProcedureCodeGen(proc, parentService) {
|
|
|
300
212
|
});
|
|
301
213
|
let buff = `export ${jsonSchema}\nexport ${stringifiedAlias}\n\nexport function use${parentService.name}${proc.name}Query`;
|
|
302
214
|
const extraOptionsType = `Omit<UseQueryOptions<${outputTypeIdentifier}, Error, ${outputTypeIdentifier}, Array<string | z.infer<typeof ${inputIdentifier}>>>, "queryKey" | "queryFn">`;
|
|
303
|
-
buff += `(args: z.infer<typeof ${inputIdentifier}>, extraOptions?: ${extraOptionsType})`;
|
|
215
|
+
buff += `(args: z.infer<typeof ${inputIdentifier}>, extraOptions?: ${extraOptionsType}, headers?: HeadersInit)`;
|
|
304
216
|
// Actual logic of the buffer here
|
|
305
217
|
buff += "{\n";
|
|
306
218
|
buff += `/*${proc.description}*/\n`;
|
|
307
219
|
// Form the keys array with args included
|
|
308
220
|
const staticKeys = [parentService.name, proc.name];
|
|
309
|
-
buff += `\treturn useQuery({queryKey: [${staticKeys.map((k) => `"${k}"`).join(", ")}, args],
|
|
221
|
+
buff += `\treturn useQuery({queryKey: [${staticKeys.map((k) => `"${k}"`).join(", ")}, args],
|
|
310
222
|
queryFn: async () => {
|
|
311
223
|
const validationResult = await ${inputIdentifier}.safeParseAsync(args)
|
|
312
224
|
if (validationResult.error) {
|
|
@@ -315,14 +227,15 @@ async function queryProcedureCodeGen(proc, parentService) {
|
|
|
315
227
|
}
|
|
316
228
|
|
|
317
229
|
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
230
|
+
|
|
231
|
+
const targetURL = new URL("/_api/${parentService.name}/${proc.name}", window.location.origin);
|
|
232
|
+
const stringifiedArguments = JSON.stringify(validationResult.data);
|
|
233
|
+
const encodedArguments = encodeURIComponent(stringifiedArguments);
|
|
234
|
+
targetURL.searchParams.set("payload", encodedArguments);
|
|
235
|
+
|
|
236
|
+
const response = await fetch(targetURL, {
|
|
237
|
+
method: "GET",
|
|
238
|
+
headers: headers,
|
|
326
239
|
})
|
|
327
240
|
|
|
328
241
|
if (!response.ok) {
|
|
@@ -380,7 +293,7 @@ async function getServiceCode(service, code) {
|
|
|
380
293
|
const prettified = await prettier.format(code, { parser: "babel-ts" });
|
|
381
294
|
return {
|
|
382
295
|
filename: service.name.toLowerCase() + ".service.ts",
|
|
383
|
-
code:
|
|
296
|
+
code: prettified,
|
|
384
297
|
};
|
|
385
298
|
}
|
|
386
299
|
export async function GenerateCode(schema) {
|
|
@@ -395,13 +308,14 @@ export async function GenerateCode(schema) {
|
|
|
395
308
|
}
|
|
396
309
|
const hasSubscription = serviceHasMethod(service, "SUBSCRIPTION");
|
|
397
310
|
const hasBidirectional = serviceHasMethod(service, "BIDIRECTIONAL");
|
|
398
|
-
if (hasSubscription
|
|
311
|
+
if (hasSubscription) {
|
|
399
312
|
const reactImports = ["useEffect", "useRef", "useState"];
|
|
400
|
-
if (hasBidirectional) {
|
|
401
|
-
reactImports.unshift("useCallback");
|
|
402
|
-
}
|
|
403
313
|
finalBuffer += `import { ${reactImports.join(", ")} } from "react";\n`;
|
|
404
314
|
}
|
|
315
|
+
if (hasBidirectional) {
|
|
316
|
+
// Import the websocket library
|
|
317
|
+
finalBuffer += `import {useWebSocket, UseWebSocketReturn, UseWebSocketOptions} from "./useWebsocket";\n`;
|
|
318
|
+
}
|
|
405
319
|
finalBuffer += 'import {z} from "zod"\n\n';
|
|
406
320
|
const buffers = await GenerateServiceCode(service);
|
|
407
321
|
finalBuffer += `// ---- Service Name: ${service.name} ----\n`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client_side.js","sourceRoot":"","sources":["../../src/schema/client_side.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,GAAG,MAAM,oBAAoB,CAAC;AAErC,MAAM,MAAM,GAAW;;;;;;;CAOtB,CAAC;AAEF,SAAS,cAAc,CAAC,IAAe,EAAE,aAAsB,EAAE;IAChE,MAAM,oBAAoB,GAAG,GAAG,aAAa,CAAC,IAAI,GAAG,IAAI,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,EAAE,UAAU,CAAC,CAAC;YACzD,WAAW,IAAI,YAAY,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC;QACxE,CAAC;QAED,IAAI,gBAAgB,EAAE,CAAC;YACtB,+BAA+B;YAC/B,WAAW,IAAI,yFAAyF,CAAC;QAC1G,CAAC;QAED,WAAW,IAAI,2BAA2B,CAAC;QAC3C,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;QACnD,WAAW,IAAI,yBAAyB,OAAO,CAAC,IAAI,SAAS,CAAC;QAC9D,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,WAAW,IAAI,QAAQ,CAAC;QACxB,GAAG,CAAC,IAAI,CAAC,MAAM,cAAc,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,GAAG,CAAC;AAAA,CACX"}
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -4,15 +4,10 @@ export type ProcedureType = `MUTATION` | `QUERY` | `SUBSCRIPTION` | `BIDIRECTION
|
|
|
4
4
|
* Represents a single procedure.
|
|
5
5
|
*/
|
|
6
6
|
export interface Procedure<TMethod extends ProcedureType = ProcedureType, TInput extends z.Schema = z.AnyZodObject, TOuput extends z.Schema = z.AnyZodObject> {
|
|
7
|
-
// The name of the procdedure, must be unique and URI safe.
|
|
8
7
|
name: string;
|
|
9
|
-
// A description of what the procedure is supposed to do
|
|
10
8
|
description: string;
|
|
11
|
-
// The method to be used for the procedure
|
|
12
9
|
method: TMethod;
|
|
13
|
-
// If the method requires an input.
|
|
14
10
|
input: TInput;
|
|
15
|
-
// The output of the endpoint
|
|
16
11
|
output: TOuput;
|
|
17
12
|
}
|
|
18
13
|
/**
|
|
@@ -29,19 +24,13 @@ export declare class Service<TProcedures extends ServiceProcedures = {
|
|
|
29
24
|
procedures: TProcedures;
|
|
30
25
|
constructor(name: string);
|
|
31
26
|
setMiddlewareDescription(middlewareDescription: string): this;
|
|
32
|
-
|
|
33
|
-
addProcedure<M extends ProcedureType, N extends string,
|
|
34
|
-
// Ensure Desc matches the Procedure interface (string | undefined if optional)
|
|
35
|
-
Desc extends string, // Or string | undefined if description is optional
|
|
36
|
-
I extends z.Schema, O extends z.Schema>(procDefinition: {
|
|
27
|
+
addProcedure<M extends ProcedureType, N extends string, Desc extends string, I extends z.Schema, O extends z.Schema>(procDefinition: {
|
|
37
28
|
method: M;
|
|
38
29
|
name: N;
|
|
39
|
-
description: Desc;
|
|
30
|
+
description: Desc;
|
|
40
31
|
input: I;
|
|
41
32
|
output: O;
|
|
42
|
-
}): Service<
|
|
43
|
-
// The return *type* reflects the added procedure
|
|
44
|
-
TProcedures & {
|
|
33
|
+
}): Service<TProcedures & {
|
|
45
34
|
[K in N]: Procedure<M, I, O> & {
|
|
46
35
|
method: M;
|
|
47
36
|
name: N;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,aAAa,GACtB,UAAU,GACV,OAAO,GACP,cAAc,GACd,eAAe,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,SAAS,CACzB,OAAO,SAAS,aAAa,GAAG,aAAa,EAC7C,MAAM,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,YAAY,EACxC,MAAM,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,aAAa,GACtB,UAAU,GACV,OAAO,GACP,cAAc,GACd,eAAe,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,SAAS,CACzB,OAAO,SAAS,aA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C,IAAI,EAAE,CAAC,CAAC;YAAC,WAAW,EAAE,IAAI,CAAA;SAAE;KACxE,CACD,CA6BA;IAED,YAAY,CAAC,KAAK,SAAS,MAAM,WAAW,EAC3C,IAAI,EAAE,KAAK,GACT,WAAW,CAAC,KAAK,CAAC,CAIpB;CACD;AAED,qBAAa,SAAS,CACrB,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG;IAChD,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACpC;IAEM,QAAQ,EAAE,SAAS,CAAC;IAE3B,YAAY,QAAQ,GAAE,SAA2B,EAEhD;CACD"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export declare enum WebSocketConnectionStatus {
|
|
2
|
+
CONNECTING = "CONNECTING",
|
|
3
|
+
CONNECTED = "CONNECTED",
|
|
4
|
+
DISCONNECTED = "DISCONNECTED",
|
|
5
|
+
ERROR = "ERROR"
|
|
6
|
+
}
|
|
7
|
+
export interface UseWebSocketOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Callback fired when a message is received
|
|
10
|
+
*/
|
|
11
|
+
onMessage?: (event: MessageEvent) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Callback fired when connection opens
|
|
14
|
+
*/
|
|
15
|
+
onOpen?: (event: Event) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Callback fired when connection closes
|
|
18
|
+
*/
|
|
19
|
+
onClose?: (event: CloseEvent) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Callback fired on error
|
|
22
|
+
*/
|
|
23
|
+
onError?: (event: Event) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Enable automatic reconnection
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
reconnect?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum number of reconnection attempts
|
|
31
|
+
* @default Infinity
|
|
32
|
+
*/
|
|
33
|
+
maxReconnectAttempts?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Initial reconnection delay in milliseconds
|
|
36
|
+
* @default 1000
|
|
37
|
+
*/
|
|
38
|
+
reconnectInterval?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Maximum reconnection delay in milliseconds
|
|
41
|
+
* @default 30000
|
|
42
|
+
*/
|
|
43
|
+
maxReconnectInterval?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Multiplier for exponential backoff
|
|
46
|
+
* @default 1.5
|
|
47
|
+
*/
|
|
48
|
+
reconnectBackoffMultiplier?: number;
|
|
49
|
+
/**
|
|
50
|
+
* WebSocket protocols
|
|
51
|
+
*/
|
|
52
|
+
protocols?: string | string[];
|
|
53
|
+
/**
|
|
54
|
+
* Should connect immediately on mount
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
connectOnMount?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface UseWebSocketReturn<TInput = any, TOutput = any> {
|
|
60
|
+
/**
|
|
61
|
+
* Send a message through the WebSocket (client to server)
|
|
62
|
+
*/
|
|
63
|
+
sendMessage: (message: TInput) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Send a raw string message
|
|
66
|
+
*/
|
|
67
|
+
sendRawMessage: (message: string) => void;
|
|
68
|
+
/**
|
|
69
|
+
* The last received message (raw MessageEvent)
|
|
70
|
+
*/
|
|
71
|
+
lastRawMessage: MessageEvent | null;
|
|
72
|
+
/**
|
|
73
|
+
* The last received message parsed as JSON (server to client)
|
|
74
|
+
*/
|
|
75
|
+
lastMessage: TOutput | null;
|
|
76
|
+
/**
|
|
77
|
+
* Current connection status
|
|
78
|
+
*/
|
|
79
|
+
connectionStatus: WebSocketConnectionStatus;
|
|
80
|
+
/**
|
|
81
|
+
* Manually connect to the WebSocket
|
|
82
|
+
*/
|
|
83
|
+
connect: () => void;
|
|
84
|
+
/**
|
|
85
|
+
* Manually disconnect from the WebSocket
|
|
86
|
+
*/
|
|
87
|
+
disconnect: () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Check if currently connected
|
|
90
|
+
*/
|
|
91
|
+
isConnected: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Number of reconnection attempts made
|
|
94
|
+
*/
|
|
95
|
+
reconnectAttempts: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Advanced WebSocket hook with reconnection logic and type safety
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* interface ClientMessage {
|
|
103
|
+
* type: 'subscribe';
|
|
104
|
+
* channel: string;
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* interface ServerMessage {
|
|
108
|
+
* type: 'update';
|
|
109
|
+
* data: any;
|
|
110
|
+
* }
|
|
111
|
+
*
|
|
112
|
+
* const { sendMessage, lastParsedMessage, connectionStatus, isConnected } =
|
|
113
|
+
* useWebSocket<ClientMessage, ServerMessage>(
|
|
114
|
+
* 'wss://api.example.com',
|
|
115
|
+
* {
|
|
116
|
+
* onMessage: (event) => console.log('Received:', event.data),
|
|
117
|
+
* reconnect: true,
|
|
118
|
+
* maxReconnectAttempts: 10,
|
|
119
|
+
* }
|
|
120
|
+
* );
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function useWebSocket<TInput = any, TOutput = any>(url: string | null, options?: UseWebSocketOptions): UseWebSocketReturn<TInput, TOutput>;
|
|
124
|
+
//# sourceMappingURL=useWebSocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWebSocket.d.ts","sourceRoot":"","sources":["../../src/schema/useWebSocket.ts"],"names":[],"mappings":"AAEA,oBAAY,yBAAyB;IACpC,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,YAAY,iBAAiB;IAC7B,KAAK,UAAU;CACf;AAED,MAAM,WAAW,mBAAmB;IACnC;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAE1C;;OA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