@arrirpc/server 0.80.3 → 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 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
- try {
447
- const validator = schema.a.compile(schema$1);
448
- return {
449
- validate: validator.validate,
450
- serialize: validator.serialize,
451
- parse: validator.parse,
452
- coerce: validator.coerce,
453
- errors: (input) => schema.a.errors(schema$1, input)
454
- };
455
- } catch (err) {
456
- console.error(
457
- `Error compiling ${type} validator for ${rpcName}. Error: ${err}`
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(
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
- try {
446
- const validator = a.compile(schema);
447
- return {
448
- validate: validator.validate,
449
- serialize: validator.serialize,
450
- parse: validator.parse,
451
- coerce: validator.coerce,
452
- errors: (input) => a.errors(schema, input)
453
- };
454
- } catch (err) {
455
- console.error(
456
- `Error compiling ${type} validator for ${rpcName}. Error: ${err}`
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(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/server",
3
- "version": "0.80.3",
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.3",
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
- "@arrirpc/codegen-utils": "0.80.3",
32
- "@arrirpc/schema": "0.80.3",
33
- "arri": "0.80.3"
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.2.16"
36
+ "bun-types": "^1.3.3"
37
37
  }
38
38
  }