@arrirpc/server 0.80.2 → 0.81.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 +37 -18
- package/dist/index.d.cts +3 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +37 -18
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -441,24 +441,40 @@ async function validateRpcRequestInput(event, httpMethod, validator) {
|
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
|
+
let useJitCompiler = true;
|
|
444
445
|
function getSchemaValidator(rpcName, type, schema$1) {
|
|
445
|
-
if (schema.isASchema(schema$1))
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
446
|
+
if (!schema.isASchema(schema$1)) return void 0;
|
|
447
|
+
if (!useJitCompiler) {
|
|
448
|
+
return {
|
|
449
|
+
validate: (input) => schema.a.validate(schema$1, input),
|
|
450
|
+
serialize: (input) => schema.a.serialize(schema$1, input),
|
|
451
|
+
parse: (input) => schema.a.parse(schema$1, input),
|
|
452
|
+
coerce: (input) => schema.a.coerce(schema$1, input),
|
|
453
|
+
errors: (input) => schema.a.errors(schema$1, input)
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
const validator = schema.a.compile(schema$1);
|
|
458
|
+
return {
|
|
459
|
+
validate: validator.validate,
|
|
460
|
+
serialize: validator.serialize,
|
|
461
|
+
parse: validator.parse,
|
|
462
|
+
coerce: validator.coerce,
|
|
463
|
+
errors: (input) => schema.a.errors(schema$1, input)
|
|
464
|
+
};
|
|
465
|
+
} catch (err) {
|
|
466
|
+
useJitCompiler = false;
|
|
467
|
+
console.warn(
|
|
468
|
+
`Encountered error compiling validator for ${rpcName}. Runtime validator will now be used instead. Error: ${err}. `
|
|
469
|
+
);
|
|
470
|
+
return {
|
|
471
|
+
validate: (input) => schema.a.validate(schema$1, input),
|
|
472
|
+
serialize: (input) => schema.a.serialize(schema$1, input),
|
|
473
|
+
parse: (input) => schema.a.parse(schema$1, input),
|
|
474
|
+
coerce: (input) => schema.a.coerce(schema$1, input),
|
|
475
|
+
errors: (input) => schema.a.errors(schema$1, input)
|
|
476
|
+
};
|
|
460
477
|
}
|
|
461
|
-
return void 0;
|
|
462
478
|
}
|
|
463
479
|
function getSchemaName(rpcName, type, schema) {
|
|
464
480
|
const cleanedName = rpcName.split(".").map(
|
|
@@ -616,7 +632,7 @@ function registerEventStreamRpc(router, path, procedure, opts) {
|
|
|
616
632
|
);
|
|
617
633
|
}
|
|
618
634
|
const stream = new EventStreamConnection(event, {
|
|
619
|
-
heartbeatMs: procedure.heartbeatMs,
|
|
635
|
+
heartbeatMs: procedure.heartbeatMs ?? opts.heartbeatMs,
|
|
620
636
|
heartbeatEnabled: procedure.heartbeatEnabled,
|
|
621
637
|
validator: responseValidator
|
|
622
638
|
});
|
|
@@ -836,6 +852,7 @@ class ArriApp {
|
|
|
836
852
|
_onError;
|
|
837
853
|
_debug;
|
|
838
854
|
definitionPath;
|
|
855
|
+
_heartbeatMs;
|
|
839
856
|
constructor(opts = {}) {
|
|
840
857
|
this.appInfo = opts?.appInfo;
|
|
841
858
|
this.h3App = h3.createApp({
|
|
@@ -846,6 +863,7 @@ class ArriApp {
|
|
|
846
863
|
this._onError = opts.onError;
|
|
847
864
|
this._onAfterResponse = opts.onAfterResponse;
|
|
848
865
|
this._onBeforeResponse = opts.onBeforeResponse;
|
|
866
|
+
this._heartbeatMs = opts.heartbeatMs ?? 2e4;
|
|
849
867
|
this._rpcRoutePrefix = opts?.rpcRoutePrefix ?? "";
|
|
850
868
|
this._rpcDefinitionPath = opts?.rpcDefinitionPath ?? "__definition";
|
|
851
869
|
this.h3App.use(this.h3Router);
|
|
@@ -950,7 +968,8 @@ class ArriApp {
|
|
|
950
968
|
onError: this._onError,
|
|
951
969
|
onAfterResponse: this._onAfterResponse,
|
|
952
970
|
onBeforeResponse: this._onBeforeResponse,
|
|
953
|
-
debug: this._debug
|
|
971
|
+
debug: this._debug,
|
|
972
|
+
heartbeatMs: this._heartbeatMs
|
|
954
973
|
});
|
|
955
974
|
return;
|
|
956
975
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -73,7 +73,7 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
|
|
|
73
73
|
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
74
74
|
}
|
|
75
75
|
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
76
|
-
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug'> & {
|
|
76
|
+
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug' | 'heartbeatMs'> & {
|
|
77
77
|
middleware: Middleware[];
|
|
78
78
|
};
|
|
79
79
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
@@ -216,6 +216,7 @@ declare class ArriApp {
|
|
|
216
216
|
private readonly _onError;
|
|
217
217
|
private readonly _debug;
|
|
218
218
|
readonly definitionPath: string;
|
|
219
|
+
private readonly _heartbeatMs;
|
|
219
220
|
constructor(opts?: ArriOptions);
|
|
220
221
|
use(input: Middleware): void;
|
|
221
222
|
use(input: ArriRouter): void;
|
|
@@ -239,6 +240,7 @@ interface ArriOptions {
|
|
|
239
240
|
rpcDefinitionPath?: string;
|
|
240
241
|
disableDefaultRoute?: boolean;
|
|
241
242
|
disableDefinitionRoute?: boolean;
|
|
243
|
+
heartbeatMs?: number;
|
|
242
244
|
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
243
245
|
onAfterResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
|
244
246
|
onBeforeResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
package/dist/index.d.mts
CHANGED
|
@@ -73,7 +73,7 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
|
|
|
73
73
|
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
74
74
|
}
|
|
75
75
|
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
76
|
-
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug'> & {
|
|
76
|
+
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug' | 'heartbeatMs'> & {
|
|
77
77
|
middleware: Middleware[];
|
|
78
78
|
};
|
|
79
79
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
@@ -216,6 +216,7 @@ declare class ArriApp {
|
|
|
216
216
|
private readonly _onError;
|
|
217
217
|
private readonly _debug;
|
|
218
218
|
readonly definitionPath: string;
|
|
219
|
+
private readonly _heartbeatMs;
|
|
219
220
|
constructor(opts?: ArriOptions);
|
|
220
221
|
use(input: Middleware): void;
|
|
221
222
|
use(input: ArriRouter): void;
|
|
@@ -239,6 +240,7 @@ interface ArriOptions {
|
|
|
239
240
|
rpcDefinitionPath?: string;
|
|
240
241
|
disableDefaultRoute?: boolean;
|
|
241
242
|
disableDefinitionRoute?: boolean;
|
|
243
|
+
heartbeatMs?: number;
|
|
242
244
|
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
243
245
|
onAfterResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
|
244
246
|
onBeforeResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ interface ArriRoute<TPath extends string, TQuery extends AObjectSchema<any, any>
|
|
|
73
73
|
postHandler?: (event: PostRouteEvent<TPath, InferType<TQuery>, InferType<TBody>, Awaited<TResponse>>) => any;
|
|
74
74
|
}
|
|
75
75
|
declare function defineRoute<TPath extends string, TQuery extends AObjectSchema<any, any> = any, TBody extends AObjectSchema<any, any> = any, TResponse = any>(route: ArriRoute<TPath, TQuery, TBody, TResponse>): ArriRoute<TPath, TQuery, TBody, TResponse>;
|
|
76
|
-
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug'> & {
|
|
76
|
+
type RouteOptions = Pick<ArriOptions, 'onAfterResponse' | 'onBeforeResponse' | 'onError' | 'onRequest' | 'debug' | 'heartbeatMs'> & {
|
|
77
77
|
middleware: Middleware[];
|
|
78
78
|
};
|
|
79
79
|
declare function registerRoute(router: Router, route: ArriRoute<any>, opts: RouteOptions): void;
|
|
@@ -216,6 +216,7 @@ declare class ArriApp {
|
|
|
216
216
|
private readonly _onError;
|
|
217
217
|
private readonly _debug;
|
|
218
218
|
readonly definitionPath: string;
|
|
219
|
+
private readonly _heartbeatMs;
|
|
219
220
|
constructor(opts?: ArriOptions);
|
|
220
221
|
use(input: Middleware): void;
|
|
221
222
|
use(input: ArriRouter): void;
|
|
@@ -239,6 +240,7 @@ interface ArriOptions {
|
|
|
239
240
|
rpcDefinitionPath?: string;
|
|
240
241
|
disableDefaultRoute?: boolean;
|
|
241
242
|
disableDefinitionRoute?: boolean;
|
|
243
|
+
heartbeatMs?: number;
|
|
242
244
|
onRequest?: (event: MiddlewareEvent) => void | Promise<void>;
|
|
243
245
|
onAfterResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
|
244
246
|
onBeforeResponse?: (event: RequestHookEvent) => void | Promise<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -440,24 +440,40 @@ async function validateRpcRequestInput(event, httpMethod, validator) {
|
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
|
+
let useJitCompiler = true;
|
|
443
444
|
function getSchemaValidator(rpcName, type, schema) {
|
|
444
|
-
if (isASchema(schema))
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
445
|
+
if (!isASchema(schema)) return void 0;
|
|
446
|
+
if (!useJitCompiler) {
|
|
447
|
+
return {
|
|
448
|
+
validate: (input) => a.validate(schema, input),
|
|
449
|
+
serialize: (input) => a.serialize(schema, input),
|
|
450
|
+
parse: (input) => a.parse(schema, input),
|
|
451
|
+
coerce: (input) => a.coerce(schema, input),
|
|
452
|
+
errors: (input) => a.errors(schema, input)
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
456
|
+
const validator = a.compile(schema);
|
|
457
|
+
return {
|
|
458
|
+
validate: validator.validate,
|
|
459
|
+
serialize: validator.serialize,
|
|
460
|
+
parse: validator.parse,
|
|
461
|
+
coerce: validator.coerce,
|
|
462
|
+
errors: (input) => a.errors(schema, input)
|
|
463
|
+
};
|
|
464
|
+
} catch (err) {
|
|
465
|
+
useJitCompiler = false;
|
|
466
|
+
console.warn(
|
|
467
|
+
`Encountered error compiling validator for ${rpcName}. Runtime validator will now be used instead. Error: ${err}. `
|
|
468
|
+
);
|
|
469
|
+
return {
|
|
470
|
+
validate: (input) => a.validate(schema, input),
|
|
471
|
+
serialize: (input) => a.serialize(schema, input),
|
|
472
|
+
parse: (input) => a.parse(schema, input),
|
|
473
|
+
coerce: (input) => a.coerce(schema, input),
|
|
474
|
+
errors: (input) => a.errors(schema, input)
|
|
475
|
+
};
|
|
459
476
|
}
|
|
460
|
-
return void 0;
|
|
461
477
|
}
|
|
462
478
|
function getSchemaName(rpcName, type, schema) {
|
|
463
479
|
const cleanedName = rpcName.split(".").map(
|
|
@@ -615,7 +631,7 @@ function registerEventStreamRpc(router, path, procedure, opts) {
|
|
|
615
631
|
);
|
|
616
632
|
}
|
|
617
633
|
const stream = new EventStreamConnection(event, {
|
|
618
|
-
heartbeatMs: procedure.heartbeatMs,
|
|
634
|
+
heartbeatMs: procedure.heartbeatMs ?? opts.heartbeatMs,
|
|
619
635
|
heartbeatEnabled: procedure.heartbeatEnabled,
|
|
620
636
|
validator: responseValidator
|
|
621
637
|
});
|
|
@@ -835,6 +851,7 @@ class ArriApp {
|
|
|
835
851
|
_onError;
|
|
836
852
|
_debug;
|
|
837
853
|
definitionPath;
|
|
854
|
+
_heartbeatMs;
|
|
838
855
|
constructor(opts = {}) {
|
|
839
856
|
this.appInfo = opts?.appInfo;
|
|
840
857
|
this.h3App = createApp({
|
|
@@ -845,6 +862,7 @@ class ArriApp {
|
|
|
845
862
|
this._onError = opts.onError;
|
|
846
863
|
this._onAfterResponse = opts.onAfterResponse;
|
|
847
864
|
this._onBeforeResponse = opts.onBeforeResponse;
|
|
865
|
+
this._heartbeatMs = opts.heartbeatMs ?? 2e4;
|
|
848
866
|
this._rpcRoutePrefix = opts?.rpcRoutePrefix ?? "";
|
|
849
867
|
this._rpcDefinitionPath = opts?.rpcDefinitionPath ?? "__definition";
|
|
850
868
|
this.h3App.use(this.h3Router);
|
|
@@ -949,7 +967,8 @@ class ArriApp {
|
|
|
949
967
|
onError: this._onError,
|
|
950
968
|
onAfterResponse: this._onAfterResponse,
|
|
951
969
|
onBeforeResponse: this._onBeforeResponse,
|
|
952
|
-
debug: this._debug
|
|
970
|
+
debug: this._debug,
|
|
971
|
+
heartbeatMs: this._heartbeatMs
|
|
953
972
|
});
|
|
954
973
|
return;
|
|
955
974
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.81.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@types/source-map-support": "^0.5.10",
|
|
26
26
|
"crossws": "^0.4.1",
|
|
27
|
-
"h3": "^1.15.
|
|
27
|
+
"h3": "^1.15.4",
|
|
28
28
|
"scule": "^1.3.0",
|
|
29
29
|
"source-map-support": "^0.5.21",
|
|
30
30
|
"uncrypto": "^0.1.3",
|
|
31
|
-
"
|
|
32
|
-
"@arrirpc/
|
|
33
|
-
"
|
|
31
|
+
"arri": "0.81.0",
|
|
32
|
+
"@arrirpc/codegen-utils": "0.81.0",
|
|
33
|
+
"@arrirpc/schema": "0.81.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"bun-types": "^1.
|
|
36
|
+
"bun-types": "^1.3.3"
|
|
37
37
|
}
|
|
38
38
|
}
|