@arrirpc/server 0.61.0 → 0.62.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/dist/index.cjs +6 -58
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +6 -58
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -863,7 +863,7 @@ class WsPeer {
|
|
|
863
863
|
__publicField$1(this, "url");
|
|
864
864
|
this._peer = peer;
|
|
865
865
|
this._validator = opts.validator;
|
|
866
|
-
this.url = peer.url;
|
|
866
|
+
this.url = peer.websocket.url ?? "";
|
|
867
867
|
this.context = opts.context;
|
|
868
868
|
}
|
|
869
869
|
send(data) {
|
|
@@ -908,72 +908,20 @@ data: ${JSON.stringify(err)}`);
|
|
|
908
908
|
const payload = this._validator.serialize(message);
|
|
909
909
|
this._peer.publish(channel, payload);
|
|
910
910
|
}
|
|
911
|
-
readyState() {
|
|
912
|
-
return this._peer.readyState;
|
|
913
|
-
}
|
|
914
911
|
}
|
|
915
912
|
function defineWebsocketRpc(def) {
|
|
916
913
|
def.transport = "ws";
|
|
917
914
|
return def;
|
|
918
915
|
}
|
|
919
|
-
function registerWebsocketRpc(router, path,
|
|
920
|
-
let responseValidator;
|
|
921
|
-
let paramValidator;
|
|
922
|
-
try {
|
|
923
|
-
responseValidator = rpc.response ? schema.a.compile(rpc.response) : void 0;
|
|
924
|
-
} catch (err) {
|
|
925
|
-
console.error("ERROR COMPILING VALIDATOR", err);
|
|
926
|
-
}
|
|
927
|
-
try {
|
|
928
|
-
paramValidator = rpc.params ? schema.a.compile(rpc.params) : void 0;
|
|
929
|
-
} catch (err) {
|
|
930
|
-
console.error("ERROR COMPILING PARAMS", err);
|
|
931
|
-
}
|
|
932
|
-
const rpcHandler = typeof rpc.handler === "function" ? rpc.handler() : rpc.handler;
|
|
916
|
+
function registerWebsocketRpc(router, path, _rpc) {
|
|
933
917
|
const handler = h3.defineWebSocketHandler({
|
|
934
918
|
upgrade(_req) {
|
|
935
919
|
},
|
|
936
|
-
open(
|
|
937
|
-
const urlParts = peer.url.split("?");
|
|
938
|
-
const context = {
|
|
939
|
-
rpcName: rpc.name,
|
|
940
|
-
clientAddress: peer.addr
|
|
941
|
-
};
|
|
942
|
-
if (urlParts.length > 1) {
|
|
943
|
-
urlParts.shift();
|
|
944
|
-
const queryStr = new URLSearchParams(urlParts.join("?"));
|
|
945
|
-
const query = {};
|
|
946
|
-
for (const [key, val] of queryStr.entries()) {
|
|
947
|
-
query[key] = val;
|
|
948
|
-
}
|
|
949
|
-
context.queryParams = query;
|
|
950
|
-
}
|
|
951
|
-
const wsPeer = new WsPeer(peer, {
|
|
952
|
-
validator: responseValidator,
|
|
953
|
-
context
|
|
954
|
-
});
|
|
955
|
-
peer.ctx.__wsPeer = wsPeer;
|
|
956
|
-
rpcHandler.onOpen(peer.ctx.__wsPeer);
|
|
920
|
+
open(_) {
|
|
957
921
|
},
|
|
958
|
-
message(
|
|
959
|
-
if (!paramValidator) {
|
|
960
|
-
return;
|
|
961
|
-
}
|
|
962
|
-
const data = paramValidator.safeParse(message.text());
|
|
963
|
-
if (!data.success) {
|
|
964
|
-
const errorResponse = {
|
|
965
|
-
code: 400,
|
|
966
|
-
message: data.error.message,
|
|
967
|
-
data: data.error.errors,
|
|
968
|
-
stack: data.error.stack?.split("\n")
|
|
969
|
-
};
|
|
970
|
-
peer.ctx.__wsPeer.sendError(errorResponse);
|
|
971
|
-
return;
|
|
972
|
-
}
|
|
973
|
-
rpcHandler.onMessage(peer.ctx.__wsPeer, data.value);
|
|
922
|
+
message(_, __) {
|
|
974
923
|
},
|
|
975
|
-
close(
|
|
976
|
-
rpcHandler.onClose(peer.ctx.__wsPeer, details);
|
|
924
|
+
close(_, __) {
|
|
977
925
|
}
|
|
978
926
|
});
|
|
979
927
|
router.use(path, handler);
|
|
@@ -1143,7 +1091,7 @@ class ArriApp {
|
|
|
1143
1091
|
return;
|
|
1144
1092
|
}
|
|
1145
1093
|
if (p.transport === "ws") {
|
|
1146
|
-
registerWebsocketRpc(this.h3Router, path
|
|
1094
|
+
registerWebsocketRpc(this.h3Router, path);
|
|
1147
1095
|
}
|
|
1148
1096
|
}
|
|
1149
1097
|
route(route) {
|
package/dist/index.d.cts
CHANGED
|
@@ -170,13 +170,12 @@ declare class WsPeer<TResponse> {
|
|
|
170
170
|
context: WsPeerContext;
|
|
171
171
|
url: string;
|
|
172
172
|
constructor(peer: Peer, opts: WsPeerOpts<TResponse>);
|
|
173
|
-
send(data: TResponse): number |
|
|
174
|
-
sendError(err: ArriServerErrorResponse): number;
|
|
173
|
+
send(data: TResponse): number | void;
|
|
174
|
+
sendError(err: ArriServerErrorResponse): number | void | undefined;
|
|
175
175
|
close(): void;
|
|
176
176
|
subscribe(channel: string): void;
|
|
177
177
|
unsubscribe(channel: string): void;
|
|
178
178
|
publish(channel: string, message: TResponse): void;
|
|
179
|
-
readyState(): (0 | 1 | 2 | 3) | -1;
|
|
180
179
|
}
|
|
181
180
|
interface WebSocketRpcHandler<TParams, TResponse> {
|
|
182
181
|
onOpen: (peer: WsPeer<TResponse>) => void;
|
|
@@ -194,7 +193,7 @@ declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined,
|
|
|
194
193
|
/**
|
|
195
194
|
* @experimental
|
|
196
195
|
*/
|
|
197
|
-
declare function registerWebsocketRpc(router: Router, path: string,
|
|
196
|
+
declare function registerWebsocketRpc(router: Router, path: string, _rpc: NamedWebsocketRpc<any, any>): void;
|
|
198
197
|
/**
|
|
199
198
|
* @experimental
|
|
200
199
|
*/
|
package/dist/index.d.mts
CHANGED
|
@@ -170,13 +170,12 @@ declare class WsPeer<TResponse> {
|
|
|
170
170
|
context: WsPeerContext;
|
|
171
171
|
url: string;
|
|
172
172
|
constructor(peer: Peer, opts: WsPeerOpts<TResponse>);
|
|
173
|
-
send(data: TResponse): number |
|
|
174
|
-
sendError(err: ArriServerErrorResponse): number;
|
|
173
|
+
send(data: TResponse): number | void;
|
|
174
|
+
sendError(err: ArriServerErrorResponse): number | void | undefined;
|
|
175
175
|
close(): void;
|
|
176
176
|
subscribe(channel: string): void;
|
|
177
177
|
unsubscribe(channel: string): void;
|
|
178
178
|
publish(channel: string, message: TResponse): void;
|
|
179
|
-
readyState(): (0 | 1 | 2 | 3) | -1;
|
|
180
179
|
}
|
|
181
180
|
interface WebSocketRpcHandler<TParams, TResponse> {
|
|
182
181
|
onOpen: (peer: WsPeer<TResponse>) => void;
|
|
@@ -194,7 +193,7 @@ declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined,
|
|
|
194
193
|
/**
|
|
195
194
|
* @experimental
|
|
196
195
|
*/
|
|
197
|
-
declare function registerWebsocketRpc(router: Router, path: string,
|
|
196
|
+
declare function registerWebsocketRpc(router: Router, path: string, _rpc: NamedWebsocketRpc<any, any>): void;
|
|
198
197
|
/**
|
|
199
198
|
* @experimental
|
|
200
199
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -170,13 +170,12 @@ declare class WsPeer<TResponse> {
|
|
|
170
170
|
context: WsPeerContext;
|
|
171
171
|
url: string;
|
|
172
172
|
constructor(peer: Peer, opts: WsPeerOpts<TResponse>);
|
|
173
|
-
send(data: TResponse): number |
|
|
174
|
-
sendError(err: ArriServerErrorResponse): number;
|
|
173
|
+
send(data: TResponse): number | void;
|
|
174
|
+
sendError(err: ArriServerErrorResponse): number | void | undefined;
|
|
175
175
|
close(): void;
|
|
176
176
|
subscribe(channel: string): void;
|
|
177
177
|
unsubscribe(channel: string): void;
|
|
178
178
|
publish(channel: string, message: TResponse): void;
|
|
179
|
-
readyState(): (0 | 1 | 2 | 3) | -1;
|
|
180
179
|
}
|
|
181
180
|
interface WebSocketRpcHandler<TParams, TResponse> {
|
|
182
181
|
onOpen: (peer: WsPeer<TResponse>) => void;
|
|
@@ -194,7 +193,7 @@ declare function defineWebsocketRpc<TParams extends RpcParamSchema | undefined,
|
|
|
194
193
|
/**
|
|
195
194
|
* @experimental
|
|
196
195
|
*/
|
|
197
|
-
declare function registerWebsocketRpc(router: Router, path: string,
|
|
196
|
+
declare function registerWebsocketRpc(router: Router, path: string, _rpc: NamedWebsocketRpc<any, any>): void;
|
|
198
197
|
/**
|
|
199
198
|
* @experimental
|
|
200
199
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -862,7 +862,7 @@ class WsPeer {
|
|
|
862
862
|
__publicField$1(this, "url");
|
|
863
863
|
this._peer = peer;
|
|
864
864
|
this._validator = opts.validator;
|
|
865
|
-
this.url = peer.url;
|
|
865
|
+
this.url = peer.websocket.url ?? "";
|
|
866
866
|
this.context = opts.context;
|
|
867
867
|
}
|
|
868
868
|
send(data) {
|
|
@@ -907,72 +907,20 @@ data: ${JSON.stringify(err)}`);
|
|
|
907
907
|
const payload = this._validator.serialize(message);
|
|
908
908
|
this._peer.publish(channel, payload);
|
|
909
909
|
}
|
|
910
|
-
readyState() {
|
|
911
|
-
return this._peer.readyState;
|
|
912
|
-
}
|
|
913
910
|
}
|
|
914
911
|
function defineWebsocketRpc(def) {
|
|
915
912
|
def.transport = "ws";
|
|
916
913
|
return def;
|
|
917
914
|
}
|
|
918
|
-
function registerWebsocketRpc(router, path,
|
|
919
|
-
let responseValidator;
|
|
920
|
-
let paramValidator;
|
|
921
|
-
try {
|
|
922
|
-
responseValidator = rpc.response ? a.compile(rpc.response) : void 0;
|
|
923
|
-
} catch (err) {
|
|
924
|
-
console.error("ERROR COMPILING VALIDATOR", err);
|
|
925
|
-
}
|
|
926
|
-
try {
|
|
927
|
-
paramValidator = rpc.params ? a.compile(rpc.params) : void 0;
|
|
928
|
-
} catch (err) {
|
|
929
|
-
console.error("ERROR COMPILING PARAMS", err);
|
|
930
|
-
}
|
|
931
|
-
const rpcHandler = typeof rpc.handler === "function" ? rpc.handler() : rpc.handler;
|
|
915
|
+
function registerWebsocketRpc(router, path, _rpc) {
|
|
932
916
|
const handler = defineWebSocketHandler({
|
|
933
917
|
upgrade(_req) {
|
|
934
918
|
},
|
|
935
|
-
open(
|
|
936
|
-
const urlParts = peer.url.split("?");
|
|
937
|
-
const context = {
|
|
938
|
-
rpcName: rpc.name,
|
|
939
|
-
clientAddress: peer.addr
|
|
940
|
-
};
|
|
941
|
-
if (urlParts.length > 1) {
|
|
942
|
-
urlParts.shift();
|
|
943
|
-
const queryStr = new URLSearchParams(urlParts.join("?"));
|
|
944
|
-
const query = {};
|
|
945
|
-
for (const [key, val] of queryStr.entries()) {
|
|
946
|
-
query[key] = val;
|
|
947
|
-
}
|
|
948
|
-
context.queryParams = query;
|
|
949
|
-
}
|
|
950
|
-
const wsPeer = new WsPeer(peer, {
|
|
951
|
-
validator: responseValidator,
|
|
952
|
-
context
|
|
953
|
-
});
|
|
954
|
-
peer.ctx.__wsPeer = wsPeer;
|
|
955
|
-
rpcHandler.onOpen(peer.ctx.__wsPeer);
|
|
919
|
+
open(_) {
|
|
956
920
|
},
|
|
957
|
-
message(
|
|
958
|
-
if (!paramValidator) {
|
|
959
|
-
return;
|
|
960
|
-
}
|
|
961
|
-
const data = paramValidator.safeParse(message.text());
|
|
962
|
-
if (!data.success) {
|
|
963
|
-
const errorResponse = {
|
|
964
|
-
code: 400,
|
|
965
|
-
message: data.error.message,
|
|
966
|
-
data: data.error.errors,
|
|
967
|
-
stack: data.error.stack?.split("\n")
|
|
968
|
-
};
|
|
969
|
-
peer.ctx.__wsPeer.sendError(errorResponse);
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
972
|
-
rpcHandler.onMessage(peer.ctx.__wsPeer, data.value);
|
|
921
|
+
message(_, __) {
|
|
973
922
|
},
|
|
974
|
-
close(
|
|
975
|
-
rpcHandler.onClose(peer.ctx.__wsPeer, details);
|
|
923
|
+
close(_, __) {
|
|
976
924
|
}
|
|
977
925
|
});
|
|
978
926
|
router.use(path, handler);
|
|
@@ -1142,7 +1090,7 @@ class ArriApp {
|
|
|
1142
1090
|
return;
|
|
1143
1091
|
}
|
|
1144
1092
|
if (p.transport === "ws") {
|
|
1145
|
-
registerWebsocketRpc(this.h3Router, path
|
|
1093
|
+
registerWebsocketRpc(this.h3Router, path);
|
|
1146
1094
|
}
|
|
1147
1095
|
}
|
|
1148
1096
|
route(route) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@types/source-map-support": "^0.5.10",
|
|
26
|
-
"crossws": "^0.
|
|
27
|
-
"h3": "^1.
|
|
26
|
+
"crossws": "^0.3.1",
|
|
27
|
+
"h3": "^1.13.0",
|
|
28
28
|
"scule": "^1.3.0",
|
|
29
29
|
"source-map-support": "^0.5.21",
|
|
30
30
|
"uncrypto": "^0.1.3",
|
|
31
|
-
"@arrirpc/codegen-dart": "0.
|
|
32
|
-
"@arrirpc/codegen-ts": "0.
|
|
33
|
-
"@arrirpc/codegen-kotlin": "0.
|
|
34
|
-
"@arrirpc/
|
|
35
|
-
"@arrirpc/
|
|
36
|
-
"arri": "0.
|
|
31
|
+
"@arrirpc/codegen-dart": "0.62.0",
|
|
32
|
+
"@arrirpc/codegen-ts": "0.62.0",
|
|
33
|
+
"@arrirpc/codegen-kotlin": "0.62.0",
|
|
34
|
+
"@arrirpc/codegen-utils": "0.62.0",
|
|
35
|
+
"@arrirpc/schema": "0.62.0",
|
|
36
|
+
"arri": "0.62.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"bun-types": "^1.1.
|
|
39
|
+
"bun-types": "^1.1.29"
|
|
40
40
|
}
|
|
41
41
|
}
|