@orpc/json-schema 1.15.6 → 1.16.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.d.mts CHANGED
@@ -18,12 +18,23 @@ declare enum JsonSchemaXNativeType {
18
18
  interface JsonSchemaCoerceOptions {
19
19
  components?: Record<string, JsonSchema>;
20
20
  }
21
+ interface JsonSchemaCoercerOptions {
22
+ /**
23
+ * Maximum digits, excluding a leading `-`, of a string coerced to `bigint`. Longer strings are left unchanged.
24
+ * `Number.POSITIVE_INFINITY` disables it.
25
+ *
26
+ * @default 4300
27
+ */
28
+ maxBigIntDigits?: number | undefined;
29
+ }
21
30
  declare class JsonSchemaCoercer {
22
31
  #private;
32
+ private readonly maxBigIntDigits;
33
+ constructor(options?: JsonSchemaCoercerOptions);
23
34
  coerce(schema: JsonSchema, value: unknown, options?: JsonSchemaCoerceOptions): unknown;
24
35
  }
25
36
 
26
- interface SmartCoercionPluginOptions {
37
+ interface SmartCoercionPluginOptions extends JsonSchemaCoercerOptions {
27
38
  schemaConverters?: readonly ConditionalSchemaConverter[];
28
39
  }
29
40
  declare class SmartCoercionPlugin<T extends Context> implements StandardHandlerPlugin<T> {
@@ -36,4 +47,4 @@ declare class SmartCoercionPlugin<T extends Context> implements StandardHandlerP
36
47
  }
37
48
 
38
49
  export { JsonSchemaCoercer, JsonSchemaXNativeType, SmartCoercionPlugin };
39
- export type { JsonSchema, JsonSchemaCoerceOptions, SmartCoercionPluginOptions };
50
+ export type { JsonSchema, JsonSchemaCoerceOptions, JsonSchemaCoercerOptions, SmartCoercionPluginOptions };
package/dist/index.d.ts CHANGED
@@ -18,12 +18,23 @@ declare enum JsonSchemaXNativeType {
18
18
  interface JsonSchemaCoerceOptions {
19
19
  components?: Record<string, JsonSchema>;
20
20
  }
21
+ interface JsonSchemaCoercerOptions {
22
+ /**
23
+ * Maximum digits, excluding a leading `-`, of a string coerced to `bigint`. Longer strings are left unchanged.
24
+ * `Number.POSITIVE_INFINITY` disables it.
25
+ *
26
+ * @default 4300
27
+ */
28
+ maxBigIntDigits?: number | undefined;
29
+ }
21
30
  declare class JsonSchemaCoercer {
22
31
  #private;
32
+ private readonly maxBigIntDigits;
33
+ constructor(options?: JsonSchemaCoercerOptions);
23
34
  coerce(schema: JsonSchema, value: unknown, options?: JsonSchemaCoerceOptions): unknown;
24
35
  }
25
36
 
26
- interface SmartCoercionPluginOptions {
37
+ interface SmartCoercionPluginOptions extends JsonSchemaCoercerOptions {
27
38
  schemaConverters?: readonly ConditionalSchemaConverter[];
28
39
  }
29
40
  declare class SmartCoercionPlugin<T extends Context> implements StandardHandlerPlugin<T> {
@@ -36,4 +47,4 @@ declare class SmartCoercionPlugin<T extends Context> implements StandardHandlerP
36
47
  }
37
48
 
38
49
  export { JsonSchemaCoercer, JsonSchemaXNativeType, SmartCoercionPlugin };
39
- export type { JsonSchema, JsonSchemaCoerceOptions, SmartCoercionPluginOptions };
50
+ export type { JsonSchema, JsonSchemaCoerceOptions, JsonSchemaCoercerOptions, SmartCoercionPluginOptions };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isObject, NullProtoObj, toArray, guard } from '@orpc/shared';
1
+ import { DEFAULT_MAX_BIGINT_DIGITS, isObject, NullProtoObj, toArray, parseBigIntString, guard } from '@orpc/shared';
2
2
  import { CompositeSchemaConverter } from '@orpc/openapi';
3
3
 
4
4
  var JsonSchemaXNativeType = /* @__PURE__ */ ((JsonSchemaXNativeType2) => {
@@ -13,6 +13,10 @@ var JsonSchemaXNativeType = /* @__PURE__ */ ((JsonSchemaXNativeType2) => {
13
13
 
14
14
  const FLEXIBLE_DATE_FORMAT_REGEX = /^[^-]+-[^-]+-[^-]+$/;
15
15
  class JsonSchemaCoercer {
16
+ maxBigIntDigits;
17
+ constructor(options = {}) {
18
+ this.maxBigIntDigits = options.maxBigIntDigits ?? DEFAULT_MAX_BIGINT_DIGITS;
19
+ }
16
20
  coerce(schema, value, options = {}) {
17
21
  const [, coerced] = this.#coerce(schema, value, options);
18
22
  return coerced;
@@ -289,7 +293,7 @@ class JsonSchemaCoercer {
289
293
  return value;
290
294
  }
291
295
  #stringToBigInt(value) {
292
- return guard(() => BigInt(value)) ?? value;
296
+ return parseBigIntString(value, this.maxBigIntDigits) ?? value;
293
297
  }
294
298
  #numberToBigInt(value) {
295
299
  return guard(() => BigInt(value)) ?? value;
@@ -337,7 +341,7 @@ class SmartCoercionPlugin {
337
341
  cache = /* @__PURE__ */ new WeakMap();
338
342
  constructor(options = {}) {
339
343
  this.converter = new CompositeSchemaConverter(toArray(options.schemaConverters));
340
- this.coercer = new JsonSchemaCoercer();
344
+ this.coercer = new JsonSchemaCoercer(options);
341
345
  }
342
346
  init(options) {
343
347
  options.clientInterceptors ??= [];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/json-schema",
3
3
  "type": "module",
4
- "version": "1.15.6",
4
+ "version": "1.16.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.dev",
7
7
  "repository": {
@@ -25,11 +25,11 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "json-schema-typed": "^8.0.2",
28
- "@orpc/contract": "1.15.6",
29
- "@orpc/interop": "1.15.6",
30
- "@orpc/openapi": "1.15.6",
31
- "@orpc/server": "1.15.6",
32
- "@orpc/shared": "1.15.6"
28
+ "@orpc/contract": "1.16.0",
29
+ "@orpc/openapi": "1.16.0",
30
+ "@orpc/interop": "1.16.0",
31
+ "@orpc/shared": "1.16.0",
32
+ "@orpc/server": "1.16.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "zod": "^4.6.2"