@arrirpc/schema 0.69.2 → 0.70.1

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/README.md CHANGED
@@ -6,9 +6,9 @@ A type builder and validation library for [Arri Type Definitions](/specification
6
6
 
7
7
  The goals of this project are as follows:
8
8
 
9
- - Portable type definitions
10
- - High performance validation, parsing, and serialization
11
- - Consistent error reporting for parsing and serialization errors
9
+ - Portable type definitions
10
+ - High performance validation, parsing, and serialization
11
+ - Consistent error reporting for parsing and serialization errors
12
12
 
13
13
  I am not looking to support every feature of Typescript's type system or even every possible representation of JSON. The goal is that the data models defined through this library can be used as a source of truth across multiple programming languages. Both JSON and Typescript have to be limited to accomplish this.
14
14
 
@@ -16,42 +16,42 @@ I am not looking to support every feature of Typescript's type system or even ev
16
16
 
17
17
  Originally this library was created as a way for building schemas for [Json Type Definition](https://jsontypedef.com/). However over time parts of the internal schema were modified to better suite the goals of Arri RPC. Some of these modifications include:
18
18
 
19
- - Adding support for 64-bit integers
20
- - Replacing the `additionalProperties` field with `strict` to allow for additional properties by default.
21
- - Restrict `ref` to only be used for recursive references.
19
+ - Adding support for 64-bit integers
20
+ - Replacing the `additionalProperties` field with `strict` to allow for additional properties by default.
21
+ - Restrict `ref` to only be used for recursive references.
22
22
 
23
23
  ## Table of Contents
24
24
 
25
- - [Installation](#installation)
26
- - [Basic Example](#basic-example)
27
- - [Usage With @arrirpc/server](#usage-with-arrirpcserver)
28
- - [Supported Types](#supported-types)
29
- - [Primitives](#primitives)
30
- - [Enums](#enums)
31
- - [Arrays / Lists](#arrays--lists)
32
- - [Objects](#objects)
33
- - [Records / Maps](#records--maps)
34
- - [Discriminated Unions](#discriminated-unions)
35
- - [Recursive Types](#recursive-types)
36
- - [Modifiers](#modifiers)
37
- - [Optional](#optional)
38
- - [Nullable](#nullable)
39
- - [Extend](#extend)
40
- - [Omit](#omit)
41
- - [Pick](#pick)
42
- - [Partial](#partial)
43
- - [Utilities](#utilities)
44
- - [Validate](#validate)
45
- - [Parse](#parse)
46
- - [Safe Parse](#safe-parse)
47
- - [Coerce](#coerce)
48
- - [Safe Coerce](#safe-coerce)
49
- - [Serialize](#serialize)
50
- - [Errors](#errors)
51
- - [Compiled Validators](#compiled-validators)
52
- - [Metadata](#metadata)
53
- - [Benchmarks](#benchmarks)
54
- - [Development](#development)
25
+ - [Installation](#installation)
26
+ - [Basic Example](#basic-example)
27
+ - [Usage With @arrirpc/server](#usage-with-arrirpcserver)
28
+ - [Supported Types](#supported-types)
29
+ - [Primitives](#primitives)
30
+ - [Enums](#enums)
31
+ - [Arrays / Lists](#arrays--lists)
32
+ - [Objects](#objects)
33
+ - [Records / Maps](#records--maps)
34
+ - [Discriminated Unions](#discriminated-unions)
35
+ - [Recursive Types](#recursive-types)
36
+ - [Modifiers](#modifiers)
37
+ - [Optional](#optional)
38
+ - [Nullable](#nullable)
39
+ - [Extend](#extend)
40
+ - [Omit](#omit)
41
+ - [Pick](#pick)
42
+ - [Partial](#partial)
43
+ - [Utilities](#utilities)
44
+ - [Validate](#validate)
45
+ - [Parse](#parse)
46
+ - [Safe Parse](#safe-parse)
47
+ - [Coerce](#coerce)
48
+ - [Safe Coerce](#safe-coerce)
49
+ - [Serialize](#serialize)
50
+ - [Errors](#errors)
51
+ - [Compiled Validators](#compiled-validators)
52
+ - [Metadata](#metadata)
53
+ - [Benchmarks](#benchmarks)
54
+ - [Development](#development)
55
55
 
56
56
  ## Installation
57
57
 
@@ -747,9 +747,9 @@ $$User.compiledCode.serialize; // the generated serialization code
747
747
 
748
748
  Metadata is used during cross-language code generation. Arri schemas allow you to specify the following metadata fields:
749
749
 
750
- - id - Will be used as the type name in any arri client generators
751
- - description - Will be added as a description comment above any generated types
752
- - isDeprecated - Will mark any generated code with the deprecation annotation of target language
750
+ - id - Will be used as the type name in any arri client generators
751
+ - description - Will be added as a description comment above any generated types
752
+ - isDeprecated - Will mark any generated code with the deprecation annotation of target language
753
753
 
754
754
  ### Examples
755
755
 
@@ -862,7 +862,7 @@ const BinaryTreeSchema = a.recursive("BTree", (self) =>
862
862
 
863
863
  ## Benchmarks
864
864
 
865
- _Last Updated: 2024-03-19_
865
+ _Last Updated: 2024-12-27_
866
866
 
867
867
  All benchmarks were run on my personal desktop. You can view the methodology used in [./benchmarks/src](./benchmark/src).
868
868
 
@@ -907,44 +907,44 @@ The following data was used in these benchmarks. Relevant schemas were created i
907
907
 
908
908
  #### Validation
909
909
 
910
- | Library | op/s |
911
- | ---------------------------- | ----------- |
912
- | **Arri (Compiled)** | 122,753,978 |
913
- | Typebox (Compiled) | 63,131,651 |
914
- | Ajv -JTD (Compiled) | 37,814,896 |
915
- | Ajv - JTD | 29,402,413 |
916
- | Ajv - JSON Schema (Compiled) | 12,003,432 |
917
- | Ajv -JSON Schema | 10,057,501 |
918
- | **Arri** | 2,131,823 |
919
- | Typebox | 93,5599 |
920
- | Zod | 52,1357 |
910
+ | Library | op/s |
911
+ | ---------------------------- | -------------- |
912
+ | **Arri (Compiled)** | **51,149,033** |
913
+ | Typebox (Compiled) | 47,826,755 |
914
+ | Ajv -JTD (Compiled) | 32,001,140 |
915
+ | Ajv - JTD | 12,731,224 |
916
+ | Ajv - JSON Schema (Compiled) | 12,371,095 |
917
+ | Ajv -JSON Schema | 8,811,605 |
918
+ | **Arri** | **2,151,961** |
919
+ | Typebox | 1,024,386 |
920
+ | Zod | 471,700 |
921
921
 
922
922
  #### Parsing
923
923
 
924
- | Library | op/s |
925
- | ------------------- | ------- |
926
- | JSON.parse | 749,534 |
927
- | **Arri (Compiled)** | 728,382 |
928
- | **Arri** | 378,175 |
929
- | Ajv -JTD (Compiled) | 241,107 |
924
+ | Library | op/s |
925
+ | ------------------- | ----------- |
926
+ | JSON.parse | 785,364 |
927
+ | **Arri (Compiled)** | **736,957** |
928
+ | **Arri** | **378,841** |
929
+ | Ajv -JTD (Compiled) | 230,124 |
930
930
 
931
931
  #### Serialization
932
932
 
933
- | Library | op/s |
934
- | ------------------------------------------ | --------- |
935
- | **Arri (Compiled)** | 4,272,430 |
936
- | **Arri (Compiled) Validate and Serialize** | 3,846,453 |
937
- | Ajv - JTD (Compiled) | 2,012,894 |
938
- | JSON.stringify | 938,289 |
939
- | Arri | 481,985 |
933
+ | Library | op/s |
934
+ | ------------------------------------------ | ------------- |
935
+ | **Arri (Compiled)** | **4,131,382** |
936
+ | **Arri (Compiled) Validate and Serialize** | **3,710,794** |
937
+ | Ajv - JTD (Compiled) | 2,066,041 |
938
+ | JSON.stringify | 1,599,758 |
939
+ | Arri | 467,417 |
940
940
 
941
941
  #### Coercion
942
942
 
943
- | Library | op/s |
944
- | -------- | ------- |
945
- | **Arri** | 818,963 |
946
- | Zod | 466,092 |
947
- | Typebox | 209,363 |
943
+ | Library | op/s |
944
+ | -------- | ----------- |
945
+ | **Arri** | **820,103** |
946
+ | Zod | 465,466 |
947
+ | Typebox | 405,292 |
948
948
 
949
949
  ### Integers
950
950
 
@@ -952,44 +952,44 @@ The following benchmarks measure how quickly each library operates on a single i
952
952
 
953
953
  #### Validation
954
954
 
955
- | Library | op/s |
956
- | ---------------------------- | ----------- |
957
- | Ajv - JSON Schema (Compiled) | 329,332,736 |
958
- | **Arri (Compiled)** | 201,644,167 |
959
- | **Arri** | 186,634,732 |
960
- | Ajv - JTD (Compiled) | 151,044,902 |
961
- | Typebox (Compiled) | 110,692,029 |
962
- | Ajv - JTD | 48,200,004 |
963
- | Ajv - JSON Schema | 47,840,571 |
964
- | Typebox | 42,363,980 |
965
- | Zod | 1,266,268 |
955
+ | Library | op/s |
956
+ | ---------------------------- | --------------- |
957
+ | Typebox (Compiled) | 196,718,452 |
958
+ | **Arri (Compiled)** | **190,853,038** |
959
+ | Ajv - JSON Schema (Compiled) | 189,905,832 |
960
+ | Ajv - JTD (Compiled) | 143,619,126 |
961
+ | **Arri** | **89,428,888** |
962
+ | Typebox | 48,408,435 |
963
+ | Ajv - JSON Schema | 36,560,467 |
964
+ | Ajv - JTD | 35,639,616 |
965
+ | Zod | 1,286,707 |
966
966
 
967
967
  #### Parsing
968
968
 
969
- | Library | op/s |
970
- | -------------------- | ----------- |
971
- | **Arri (Compiled)** | 138,189,123 |
972
- | **Arri** | 136,995,619 |
973
- | JSON.parse() | 19,911,721 |
974
- | Ajv - JTD (Compiled) | 8,996,081 |
969
+ | Library | op/s |
970
+ | -------------------- | --------------- |
971
+ | **Arri (Compiled)** | **131,214,018** |
972
+ | **Arri** | **56,134,552** |
973
+ | JSON.parse() | 21,001,320 |
974
+ | Ajv - JTD (Compiled) | 9,441,285 |
975
975
 
976
976
  #### Serialization
977
977
 
978
- | Library | op/s |
979
- | -------------------- | ----------- |
980
- | Ajv - JTD (Compiled) | 198,980,679 |
981
- | **Arri (Compiled)** | 190,386,426 |
982
- | **Arri** | 114,799,692 |
983
- | JSON.stringify | 21,433,854 |
978
+ | Library | op/s |
979
+ | -------------------- | --------------- |
980
+ | Ajv - JTD (Compiled) | 199,802,584 |
981
+ | **Arri (Compiled)** | **194,399,849** |
982
+ | **Arri** | **65,097,829** |
983
+ | JSON.stringify | 16,853,237 |
984
984
 
985
985
  #### Coercion
986
986
 
987
- | Library | op/s |
988
- | ----------------- | ----------- |
989
- | Arri | 117,854,219 |
990
- | TypeBox | 34,633,126 |
991
- | Ajv - JSON Schema | 28,016,735 |
992
- | Zod | 1,586,546 |
987
+ | Library | op/s |
988
+ | ----------------- | -------------- |
989
+ | **Arri** | **55,840,221** |
990
+ | TypeBox | 34,403,424 |
991
+ | Ajv - JSON Schema | 22,190,607 |
992
+ | Zod | 1,195,111 |
993
993
 
994
994
  ## Development
995
995
 
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const jtdUtils = require('jtd-utils');
3
+ const typeDefs = require('@arrirpc/type-defs');
4
4
  const scule = require('scule');
5
- const timestamp = require('./shared/schema.4e2863ed.cjs');
5
+ const timestamp = require('./shared/schema.TlNJgMz1.cjs');
6
6
 
7
7
  function createParsingTemplate(input, schema) {
8
8
  const fallbackTemplate = `
@@ -27,7 +27,7 @@ function createParsingTemplate(input, schema) {
27
27
  schemaPath: "",
28
28
  subFunctions
29
29
  });
30
- if (jtdUtils.isSchemaFormProperties(schema) || jtdUtils.isSchemaFormValues(schema) || jtdUtils.isSchemaFormElements(schema) || jtdUtils.isSchemaFormDiscriminator(schema)) {
30
+ if (typeDefs.isSchemaFormProperties(schema) || typeDefs.isSchemaFormValues(schema) || typeDefs.isSchemaFormElements(schema) || typeDefs.isSchemaFormDiscriminator(schema)) {
31
31
  jsonParseCheck = `if (typeof ${input} === 'string') {
32
32
  const json = JSON.parse(${input});
33
33
  let result = {};
@@ -35,7 +35,7 @@ function createParsingTemplate(input, schema) {
35
35
  return result;
36
36
  }`;
37
37
  }
38
- if (jtdUtils.isSchemaFormEmpty(schema)) {
38
+ if (typeDefs.isSchemaFormEmpty(schema)) {
39
39
  jsonParseCheck = `try {
40
40
  const json = JSON.parse(${input});
41
41
  return json;
@@ -55,7 +55,7 @@ function createParsingTemplate(input, schema) {
55
55
  return finalTemplate;
56
56
  }
57
57
  function schemaTemplate$1(input) {
58
- if (jtdUtils.isSchemaFormType(input.schema)) {
58
+ if (typeDefs.isSchemaFormType(input.schema)) {
59
59
  switch (input.schema.type) {
60
60
  case "boolean":
61
61
  return booleanTemplate$2(input);
@@ -84,22 +84,22 @@ function schemaTemplate$1(input) {
84
84
  return bigIntTemplate$2(input, true);
85
85
  }
86
86
  }
87
- if (jtdUtils.isSchemaFormEnum(input.schema)) {
87
+ if (typeDefs.isSchemaFormEnum(input.schema)) {
88
88
  return enumTemplate$2(input);
89
89
  }
90
- if (jtdUtils.isSchemaFormProperties(input.schema)) {
90
+ if (typeDefs.isSchemaFormProperties(input.schema)) {
91
91
  return objectTemplate$2(input);
92
92
  }
93
- if (jtdUtils.isSchemaFormElements(input.schema)) {
93
+ if (typeDefs.isSchemaFormElements(input.schema)) {
94
94
  return arrayTemplate$2(input);
95
95
  }
96
- if (jtdUtils.isSchemaFormValues(input.schema)) {
96
+ if (typeDefs.isSchemaFormValues(input.schema)) {
97
97
  return recordTemplate$2(input);
98
98
  }
99
- if (jtdUtils.isSchemaFormDiscriminator(input.schema)) {
99
+ if (typeDefs.isSchemaFormDiscriminator(input.schema)) {
100
100
  return discriminatorTemplate$2(input);
101
101
  }
102
- if (jtdUtils.isSchemaFormRef(input.schema)) {
102
+ if (typeDefs.isSchemaFormRef(input.schema)) {
103
103
  return refTemplate$2(input);
104
104
  }
105
105
  return anyTemplate$1(input);
@@ -596,7 +596,7 @@ function createSerializationV2Template(inputName, schema) {
596
596
  subFunctions
597
597
  };
598
598
  const result = template(context);
599
- if (jtdUtils.isSchemaFormType(schema) || jtdUtils.isSchemaFormEnum(schema)) {
599
+ if (typeDefs.isSchemaFormType(schema) || typeDefs.isSchemaFormEnum(schema)) {
600
600
  return result;
601
601
  }
602
602
  const subFunctionParts = Object.keys(subFunctions).map(
@@ -610,25 +610,25 @@ function createSerializationV2Template(inputName, schema) {
610
610
  return json;`;
611
611
  }
612
612
  function template(input) {
613
- if (jtdUtils.isSchemaFormType(input.schema)) {
613
+ if (typeDefs.isSchemaFormType(input.schema)) {
614
614
  return scalarTemplate(input);
615
615
  }
616
- if (jtdUtils.isSchemaFormEnum(input.schema)) {
616
+ if (typeDefs.isSchemaFormEnum(input.schema)) {
617
617
  return enumTemplate$1(input);
618
618
  }
619
- if (jtdUtils.isSchemaFormProperties(input.schema)) {
619
+ if (typeDefs.isSchemaFormProperties(input.schema)) {
620
620
  return objectTemplate$1(input);
621
621
  }
622
- if (jtdUtils.isSchemaFormElements(input.schema)) {
622
+ if (typeDefs.isSchemaFormElements(input.schema)) {
623
623
  return arrayTemplate$1(input);
624
624
  }
625
- if (jtdUtils.isSchemaFormValues(input.schema)) {
625
+ if (typeDefs.isSchemaFormValues(input.schema)) {
626
626
  return recordTemplate$1(input);
627
627
  }
628
- if (jtdUtils.isSchemaFormDiscriminator(input.schema)) {
628
+ if (typeDefs.isSchemaFormDiscriminator(input.schema)) {
629
629
  return discriminatorTemplate$1(input);
630
630
  }
631
- if (jtdUtils.isSchemaFormRef(input.schema)) {
631
+ if (typeDefs.isSchemaFormRef(input.schema)) {
632
632
  return refTemplate$1(input);
633
633
  }
634
634
  return anyTemplate(input);
@@ -1410,7 +1410,6 @@ function compile(schema) {
1410
1410
  };
1411
1411
  }
1412
1412
  },
1413
- // eslint-disable-next-line no-eval
1414
1413
  serialize(input) {
1415
1414
  try {
1416
1415
  return serializeFn(input);
@@ -1432,7 +1431,7 @@ function compile(schema) {
1432
1431
  }
1433
1432
  function getCompiledParser(input, schema) {
1434
1433
  const code = createParsingTemplate(input, schema);
1435
- if (jtdUtils.isSchemaFormType(schema)) {
1434
+ if (typeDefs.isSchemaFormType(schema)) {
1436
1435
  switch (schema.type) {
1437
1436
  case "float32":
1438
1437
  case "float64":
@@ -1725,7 +1724,7 @@ function getCompiledParser(input, schema) {
1725
1724
  };
1726
1725
  }
1727
1726
  }
1728
- if (jtdUtils.isSchemaFormEnum(schema)) {
1727
+ if (typeDefs.isSchemaFormEnum(schema)) {
1729
1728
  if (schema.nullable) {
1730
1729
  return {
1731
1730
  fn(input2) {
@@ -1962,7 +1961,7 @@ function intParser(input, minNum, maxNum) {
1962
1961
  }
1963
1962
  function getCompiledSerializer(schema) {
1964
1963
  const code = createSerializationV2Template("input", schema);
1965
- if (jtdUtils.isSchemaFormType(schema)) {
1964
+ if (typeDefs.isSchemaFormType(schema)) {
1966
1965
  switch (schema.type) {
1967
1966
  case "string":
1968
1967
  if (schema.nullable) {
@@ -2064,7 +2063,7 @@ function getCompiledSerializer(schema) {
2064
2063
  };
2065
2064
  }
2066
2065
  }
2067
- if (jtdUtils.isSchemaFormEnum(schema)) {
2066
+ if (typeDefs.isSchemaFormEnum(schema)) {
2068
2067
  if (schema.nullable) {
2069
2068
  return {
2070
2069
  fn(input) {
@@ -2194,6 +2193,7 @@ function validatorFromAdaptedSchema(schema) {
2194
2193
 
2195
2194
  exports.NumberTypeValues = timestamp.NumberTypeValues;
2196
2195
  exports.SCHEMA_METADATA = timestamp.SCHEMA_METADATA;
2196
+ exports.STR_ESCAPE = timestamp.STR_ESCAPE;
2197
2197
  exports.ValidationError = timestamp.ValidationError;
2198
2198
  exports.any = timestamp.any;
2199
2199
  exports.array = timestamp.array;
@@ -2245,6 +2245,7 @@ exports.sanitizeJson = timestamp.sanitizeJson;
2245
2245
  exports.serialize = timestamp.serialize;
2246
2246
  exports.serializeObject = timestamp.serializeObject;
2247
2247
  exports.serializeSmallString = timestamp.serializeSmallString;
2248
+ exports.serializeString = timestamp.serializeString;
2248
2249
  exports.string = timestamp.string;
2249
2250
  exports.stringEnum = timestamp.stringEnum;
2250
2251
  exports.timestamp = timestamp.timestamp;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { A as ASchema, I as InferType, S as SafeResult, a as ASchemaOptions, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, R as ResolveObject, f as AStringEnumSchema, g as AObjectSchemaOptions, h as InferObjectOutput, V as ValidationContext, i as ARecordSchema, j as ARefSchema, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate } from './shared/schema.cdac4a20.cjs';
2
- export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as SCHEMA_METADATA, y as SchemaMetadata, x as SchemaValidator, t as ValidationError, r as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, u as isValidationError, q as sanitizeJson } from './shared/schema.cdac4a20.cjs';
3
- import { Schema } from 'jtd-utils';
1
+ import { A as ASchema, I as InferType, S as SafeResult, a as ASchemaOptions, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, R as ResolveObject, f as AStringEnumSchema, g as AObjectSchemaOptions, h as InferObjectOutput, V as ValidationContext, i as ARecordSchema, j as ARefSchema, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate } from './shared/schema.C-0ZU_OQ.cjs';
2
+ export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as SCHEMA_METADATA, y as SchemaMetadata, x as SchemaValidator, t as ValidationError, r as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, u as isValidationError, q as sanitizeJson } from './shared/schema.C-0ZU_OQ.cjs';
3
+ import { Schema } from '@arrirpc/type-defs';
4
4
 
5
5
  declare function createParsingTemplate(input: string, schema: Schema): string;
6
6
 
@@ -286,6 +286,8 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
286
286
  * a.validate(StringSchema, 10) // false
287
287
  */
288
288
  declare function string(opts?: ASchemaOptions): AScalarSchema<"string", string>;
289
+ declare function serializeString(input: string): string;
290
+ declare const STR_ESCAPE: RegExp;
289
291
  declare function serializeSmallString(input: string): string;
290
292
 
291
293
  /**
@@ -359,4 +361,4 @@ declare const int64Max: bigint;
359
361
  declare const uint64Min: bigint;
360
362
  declare const uint64Max: bigint;
361
363
 
362
- export { AArraySchema, ADiscriminatorSchema, AObjectSchema, AObjectSchemaOptions, ARecordSchema, ARefSchema, AScalarSchema, ASchema, ASchemaOptions, AStringEnumSchema, type CompiledValidator, InferObjectOutput, InferSubType, InferType, ResolveObject, SafeResult, type ValidationAdapter, ValidationContext, _namespace as a, any, array, boolean, clone, coerce, compile, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int64Max, int64Min, int8, int8Max, int8Min, isAdaptedSchema, nullable, number, object, omit, optional, parse, parseObjectSchema, partial, pick, record, recursive, safeCoerce, safeParse, serialize, serializeObject, serializeSmallString, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, validate, validateObjectSchema, validatorFromAdaptedSchema };
364
+ export { AArraySchema, ADiscriminatorSchema, AObjectSchema, AObjectSchemaOptions, ARecordSchema, ARefSchema, AScalarSchema, ASchema, ASchemaOptions, AStringEnumSchema, type CompiledValidator, InferObjectOutput, InferSubType, InferType, ResolveObject, STR_ESCAPE, SafeResult, type ValidationAdapter, ValidationContext, _namespace as a, any, array, boolean, clone, coerce, compile, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int64Max, int64Min, int8, int8Max, int8Min, isAdaptedSchema, nullable, number, object, omit, optional, parse, parseObjectSchema, partial, pick, record, recursive, safeCoerce, safeParse, serialize, serializeObject, serializeSmallString, serializeString, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, validate, validateObjectSchema, validatorFromAdaptedSchema };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { A as ASchema, I as InferType, S as SafeResult, a as ASchemaOptions, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, R as ResolveObject, f as AStringEnumSchema, g as AObjectSchemaOptions, h as InferObjectOutput, V as ValidationContext, i as ARecordSchema, j as ARefSchema, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate } from './shared/schema.cdac4a20.mjs';
2
- export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as SCHEMA_METADATA, y as SchemaMetadata, x as SchemaValidator, t as ValidationError, r as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, u as isValidationError, q as sanitizeJson } from './shared/schema.cdac4a20.mjs';
3
- import { Schema } from 'jtd-utils';
1
+ import { A as ASchema, I as InferType, S as SafeResult, a as ASchemaOptions, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, R as ResolveObject, f as AStringEnumSchema, g as AObjectSchemaOptions, h as InferObjectOutput, V as ValidationContext, i as ARecordSchema, j as ARefSchema, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate } from './shared/schema.C-0ZU_OQ.mjs';
2
+ export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as SCHEMA_METADATA, y as SchemaMetadata, x as SchemaValidator, t as ValidationError, r as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, u as isValidationError, q as sanitizeJson } from './shared/schema.C-0ZU_OQ.mjs';
3
+ import { Schema } from '@arrirpc/type-defs';
4
4
 
5
5
  declare function createParsingTemplate(input: string, schema: Schema): string;
6
6
 
@@ -286,6 +286,8 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
286
286
  * a.validate(StringSchema, 10) // false
287
287
  */
288
288
  declare function string(opts?: ASchemaOptions): AScalarSchema<"string", string>;
289
+ declare function serializeString(input: string): string;
290
+ declare const STR_ESCAPE: RegExp;
289
291
  declare function serializeSmallString(input: string): string;
290
292
 
291
293
  /**
@@ -359,4 +361,4 @@ declare const int64Max: bigint;
359
361
  declare const uint64Min: bigint;
360
362
  declare const uint64Max: bigint;
361
363
 
362
- export { AArraySchema, ADiscriminatorSchema, AObjectSchema, AObjectSchemaOptions, ARecordSchema, ARefSchema, AScalarSchema, ASchema, ASchemaOptions, AStringEnumSchema, type CompiledValidator, InferObjectOutput, InferSubType, InferType, ResolveObject, SafeResult, type ValidationAdapter, ValidationContext, _namespace as a, any, array, boolean, clone, coerce, compile, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int64Max, int64Min, int8, int8Max, int8Min, isAdaptedSchema, nullable, number, object, omit, optional, parse, parseObjectSchema, partial, pick, record, recursive, safeCoerce, safeParse, serialize, serializeObject, serializeSmallString, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, validate, validateObjectSchema, validatorFromAdaptedSchema };
364
+ export { AArraySchema, ADiscriminatorSchema, AObjectSchema, AObjectSchemaOptions, ARecordSchema, ARefSchema, AScalarSchema, ASchema, ASchemaOptions, AStringEnumSchema, type CompiledValidator, InferObjectOutput, InferSubType, InferType, ResolveObject, STR_ESCAPE, SafeResult, type ValidationAdapter, ValidationContext, _namespace as a, any, array, boolean, clone, coerce, compile, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int64Max, int64Min, int8, int8Max, int8Min, isAdaptedSchema, nullable, number, object, omit, optional, parse, parseObjectSchema, partial, pick, record, recursive, safeCoerce, safeParse, serialize, serializeObject, serializeSmallString, serializeString, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, validate, validateObjectSchema, validatorFromAdaptedSchema };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { A as ASchema, I as InferType, S as SafeResult, a as ASchemaOptions, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, R as ResolveObject, f as AStringEnumSchema, g as AObjectSchemaOptions, h as InferObjectOutput, V as ValidationContext, i as ARecordSchema, j as ARefSchema, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate } from './shared/schema.cdac4a20.js';
2
- export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as SCHEMA_METADATA, y as SchemaMetadata, x as SchemaValidator, t as ValidationError, r as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, u as isValidationError, q as sanitizeJson } from './shared/schema.cdac4a20.js';
3
- import { Schema } from 'jtd-utils';
1
+ import { A as ASchema, I as InferType, S as SafeResult, a as ASchemaOptions, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, R as ResolveObject, f as AStringEnumSchema, g as AObjectSchemaOptions, h as InferObjectOutput, V as ValidationContext, i as ARecordSchema, j as ARefSchema, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate } from './shared/schema.C-0ZU_OQ.js';
2
+ export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as SCHEMA_METADATA, y as SchemaMetadata, x as SchemaValidator, t as ValidationError, r as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, u as isValidationError, q as sanitizeJson } from './shared/schema.C-0ZU_OQ.js';
3
+ import { Schema } from '@arrirpc/type-defs';
4
4
 
5
5
  declare function createParsingTemplate(input: string, schema: Schema): string;
6
6
 
@@ -286,6 +286,8 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
286
286
  * a.validate(StringSchema, 10) // false
287
287
  */
288
288
  declare function string(opts?: ASchemaOptions): AScalarSchema<"string", string>;
289
+ declare function serializeString(input: string): string;
290
+ declare const STR_ESCAPE: RegExp;
289
291
  declare function serializeSmallString(input: string): string;
290
292
 
291
293
  /**
@@ -359,4 +361,4 @@ declare const int64Max: bigint;
359
361
  declare const uint64Min: bigint;
360
362
  declare const uint64Max: bigint;
361
363
 
362
- export { AArraySchema, ADiscriminatorSchema, AObjectSchema, AObjectSchemaOptions, ARecordSchema, ARefSchema, AScalarSchema, ASchema, ASchemaOptions, AStringEnumSchema, type CompiledValidator, InferObjectOutput, InferSubType, InferType, ResolveObject, SafeResult, type ValidationAdapter, ValidationContext, _namespace as a, any, array, boolean, clone, coerce, compile, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int64Max, int64Min, int8, int8Max, int8Min, isAdaptedSchema, nullable, number, object, omit, optional, parse, parseObjectSchema, partial, pick, record, recursive, safeCoerce, safeParse, serialize, serializeObject, serializeSmallString, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, validate, validateObjectSchema, validatorFromAdaptedSchema };
364
+ export { AArraySchema, ADiscriminatorSchema, AObjectSchema, AObjectSchemaOptions, ARecordSchema, ARefSchema, AScalarSchema, ASchema, ASchemaOptions, AStringEnumSchema, type CompiledValidator, InferObjectOutput, InferSubType, InferType, ResolveObject, STR_ESCAPE, SafeResult, type ValidationAdapter, ValidationContext, _namespace as a, any, array, boolean, clone, coerce, compile, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int64Max, int64Min, int8, int8Max, int8Min, isAdaptedSchema, nullable, number, object, omit, optional, parse, parseObjectSchema, partial, pick, record, recursive, safeCoerce, safeParse, serialize, serializeObject, serializeSmallString, serializeString, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, validate, validateObjectSchema, validatorFromAdaptedSchema };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { isSchemaFormProperties, isSchemaFormValues, isSchemaFormElements, isSchemaFormDiscriminator, isSchemaFormEmpty, isSchemaFormType, isSchemaFormEnum, isSchemaFormRef } from 'jtd-utils';
1
+ import { isSchemaFormProperties, isSchemaFormValues, isSchemaFormElements, isSchemaFormDiscriminator, isSchemaFormEmpty, isSchemaFormType, isSchemaFormEnum, isSchemaFormRef } from '@arrirpc/type-defs';
2
2
  import { camelCase } from 'scule';
3
- import { u as uint8Max, a as uint8Min, b as uint16Max, c as uint16Min, d as uint32Max, e as uint32Min, i as int8Max, f as int8Min, g as int16Max, h as int16Min, j as int32Max, k as int32Min, l as isAScalarSchema, m as isAObjectSchema, n as isAStringEnumSchema, o as isAAraySchema, p as isARecordSchema, q as isADiscriminatorSchema, r as isARefSchema, s as errors, V as ValidationError, t as any, v as array, w as boolean, x as clone, y as coerce, z as discriminator, A as enumerator, B as extend, C as float32, D as float64, E as int16, F as int32, G as int64, H as int8, I as nullable, J as number, K as object, L as omit, M as optional, N as parse, O as partial, P as pick, Q as record, R as recursive, S as safeCoerce, T as safeParse, U as serialize, W as string, X as stringEnum, Y as timestamp, Z as uint16, _ as uint32, $ as uint64, a0 as uint8, a1 as validate, a2 as SCHEMA_METADATA } from './shared/schema.25b78dac.mjs';
4
- export { ae as NumberTypeValues, a4 as int64Max, a3 as int64Min, ad as isASchema, af as isObject, ac as isValidationError, a7 as parseObjectSchema, ab as sanitizeJson, a9 as serializeObject, aa as serializeSmallString, a6 as uint64Max, a5 as uint64Min, a8 as validateObjectSchema } from './shared/schema.25b78dac.mjs';
3
+ import { u as uint8Max, a as uint8Min, b as uint16Max, c as uint16Min, d as uint32Max, e as uint32Min, i as int8Max, f as int8Min, g as int16Max, h as int16Min, j as int32Max, k as int32Min, l as isAScalarSchema, m as isAObjectSchema, n as isAStringEnumSchema, o as isAAraySchema, p as isARecordSchema, q as isADiscriminatorSchema, r as isARefSchema, s as errors, V as ValidationError, t as any, v as array, w as boolean, x as clone, y as coerce, z as discriminator, A as enumerator, B as extend, C as float32, D as float64, E as int16, F as int32, G as int64, H as int8, I as nullable, J as number, K as object, L as omit, M as optional, N as parse, O as partial, P as pick, Q as record, R as recursive, S as safeCoerce, T as safeParse, U as serialize, W as string, X as stringEnum, Y as timestamp, Z as uint16, _ as uint32, $ as uint64, a0 as uint8, a1 as validate, a2 as SCHEMA_METADATA } from './shared/schema.lowJcmic.mjs';
4
+ export { ag as NumberTypeValues, ab as STR_ESCAPE, a4 as int64Max, a3 as int64Min, af as isASchema, ah as isObject, ae as isValidationError, a7 as parseObjectSchema, ad as sanitizeJson, a9 as serializeObject, ac as serializeSmallString, aa as serializeString, a6 as uint64Max, a5 as uint64Min, a8 as validateObjectSchema } from './shared/schema.lowJcmic.mjs';
5
5
 
6
6
  function createParsingTemplate(input, schema) {
7
7
  const fallbackTemplate = `
@@ -1409,7 +1409,6 @@ function compile(schema) {
1409
1409
  };
1410
1410
  }
1411
1411
  },
1412
- // eslint-disable-next-line no-eval
1413
1412
  serialize(input) {
1414
1413
  try {
1415
1414
  return serializeFn(input);
@@ -1,4 +1,4 @@
1
- import { Type } from 'jtd-utils';
1
+ import { Type } from '@arrirpc/type-defs';
2
2
 
3
3
  declare function sanitizeJson(json: string): string;
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { Type } from 'jtd-utils';
1
+ import { Type } from '@arrirpc/type-defs';
2
2
 
3
3
  declare function sanitizeJson(json: string): string;
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { Type } from 'jtd-utils';
1
+ import { Type } from '@arrirpc/type-defs';
2
2
 
3
3
  declare function sanitizeJson(json: string): string;
4
4
  /**
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const jtdUtils = require('jtd-utils');
3
+ const typeDefs = require('@arrirpc/type-defs');
4
4
 
5
5
  const int8Min = -128;
6
6
  const int8Max = 127;
@@ -33,9 +33,7 @@ function isASchema(input) {
33
33
  return "parse" in input.metadata[SCHEMA_METADATA] && typeof input.metadata[SCHEMA_METADATA] === "object";
34
34
  }
35
35
  function isAScalarSchema(input) {
36
- return isASchema(input) && "type" in input && typeof input.type === "string" && // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
37
- (jtdUtils.TypeValues.includes(input.type) || // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
38
- NumberTypeValues.includes(input.type));
36
+ return isASchema(input) && "type" in input && typeof input.type === "string" && (typeDefs.TypeValues.includes(input.type) || NumberTypeValues.includes(input.type));
39
37
  }
40
38
  const NumberTypeValues = [
41
39
  "float32",
@@ -50,25 +48,25 @@ const NumberTypeValues = [
50
48
  "uint64"
51
49
  ];
52
50
  function isAAraySchema(input) {
53
- return isASchema(input) && jtdUtils.isSchemaFormElements(input);
51
+ return isASchema(input) && typeDefs.isSchemaFormElements(input);
54
52
  }
55
53
  function isAStringEnumSchema(input) {
56
- return isASchema(input) && jtdUtils.isSchemaFormEnum(input);
54
+ return isASchema(input) && typeDefs.isSchemaFormEnum(input);
57
55
  }
58
56
  function isADiscriminatorSchema(input) {
59
- return isASchema(input) && jtdUtils.isSchemaFormDiscriminator(input);
57
+ return isASchema(input) && typeDefs.isSchemaFormDiscriminator(input);
60
58
  }
61
59
  function isARecordSchema(input) {
62
- return isASchema(input) && jtdUtils.isSchemaFormValues(input);
60
+ return isASchema(input) && typeDefs.isSchemaFormValues(input);
63
61
  }
64
62
  function isAObjectSchema(input) {
65
- return isASchema(input) && jtdUtils.isSchemaFormProperties(input);
63
+ return isASchema(input) && typeDefs.isSchemaFormProperties(input);
66
64
  }
67
65
  function isObject(input) {
68
66
  return typeof input === "object" && input !== null;
69
67
  }
70
68
  function isARefSchema(input) {
71
- return isASchema(input) && jtdUtils.isSchemaFormRef(input);
69
+ return isASchema(input) && typeDefs.isSchemaFormRef(input);
72
70
  }
73
71
 
74
72
  function any(options = {}) {
@@ -280,12 +278,6 @@ function serialize$2(input) {
280
278
  return `${input}`;
281
279
  }
282
280
 
283
- var __defProp = Object.defineProperty;
284
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
285
- var __publicField = (obj, key, value) => {
286
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
287
- return value;
288
- };
289
281
  function sanitizeJson(json) {
290
282
  return json.replace(/[\b]/g, "\\b").replace(/[\f]/g, "\\f").replace(/[\n]/g, "\\n").replace(/[\r]/g, "\\r").replace(/[\t]/g, "\\t");
291
283
  }
@@ -390,9 +382,9 @@ function errors(schema, input) {
390
382
  return errorList;
391
383
  }
392
384
  class ValidationError extends Error {
385
+ errors;
393
386
  constructor(options) {
394
387
  super(options.message);
395
- __publicField(this, "errors");
396
388
  this.errors = options.errors;
397
389
  }
398
390
  }
@@ -1453,6 +1445,89 @@ function partial(schema, options = {}) {
1453
1445
  return newSchema;
1454
1446
  }
1455
1447
 
1448
+ function string(opts = {}) {
1449
+ return {
1450
+ type: "string",
1451
+ metadata: {
1452
+ id: opts.id,
1453
+ description: opts.description,
1454
+ isDeprecated: opts.isDeprecated,
1455
+ [SCHEMA_METADATA]: {
1456
+ output: "",
1457
+ parse: parse$2,
1458
+ coerce: coerce$1,
1459
+ validate: validate$1,
1460
+ serialize(input, context) {
1461
+ if (context.instancePath.length === 0) {
1462
+ return input;
1463
+ }
1464
+ if (input.length < 42) {
1465
+ return serializeSmallString(input);
1466
+ }
1467
+ if (input.length < 5e3 && !STR_ESCAPE.test(input)) {
1468
+ return `"${input}"`;
1469
+ }
1470
+ return JSON.stringify(input);
1471
+ }
1472
+ }
1473
+ }
1474
+ };
1475
+ }
1476
+ function serializeString(input) {
1477
+ if (input.length < 42) {
1478
+ return serializeSmallString(input);
1479
+ }
1480
+ if (input.length < 5e3 && !STR_ESCAPE.test(input)) {
1481
+ return `"${input}"`;
1482
+ }
1483
+ return JSON.stringify(input);
1484
+ }
1485
+ function validate$1(input) {
1486
+ return typeof input === "string";
1487
+ }
1488
+ function parse$2(input, context) {
1489
+ if (validate$1(input)) {
1490
+ return input;
1491
+ }
1492
+ context.errors.push({
1493
+ instancePath: context.instancePath,
1494
+ schemaPath: `${context.schemaPath}/type`,
1495
+ message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
1496
+ });
1497
+ return void 0;
1498
+ }
1499
+ function coerce$1(input, context) {
1500
+ return parse$2(input, context);
1501
+ }
1502
+ const STR_ESCAPE = (
1503
+ // eslint-disable-next-line no-control-regex
1504
+ /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/
1505
+ );
1506
+ function serializeSmallString(input) {
1507
+ const len = input.length;
1508
+ let result = "";
1509
+ let last = -1;
1510
+ let point = 255;
1511
+ for (let i = 0; i < len; i++) {
1512
+ point = input.charCodeAt(i);
1513
+ if (point < 32 || point >= 55296 && point <= 57343) {
1514
+ return JSON.stringify(input);
1515
+ }
1516
+ if (point === 34 || // '"'
1517
+ point === 92) {
1518
+ if (last === -1) {
1519
+ last = 0;
1520
+ }
1521
+ result += input.slice(last, i) + "\\";
1522
+ last = i;
1523
+ }
1524
+ }
1525
+ if (last === -1) {
1526
+ return `"${input}"`;
1527
+ }
1528
+ return `"${result}${input.slice(last)}"`;
1529
+ }
1530
+
1456
1531
  function record(schema, opts = {}) {
1457
1532
  return {
1458
1533
  values: schema,
@@ -1476,34 +1551,37 @@ function record(schema, opts = {}) {
1476
1551
  return true;
1477
1552
  },
1478
1553
  parse(input, context) {
1479
- return parse$2(schema, input, context, false);
1554
+ return parse$1(schema, input, context, false);
1480
1555
  },
1481
1556
  coerce(input, data) {
1482
- return parse$2(schema, input, data, true);
1557
+ return parse$1(schema, input, data, true);
1483
1558
  },
1484
1559
  serialize(input, context) {
1485
- const strParts = [];
1486
- for (const key of Object.keys(input)) {
1560
+ let result = "{";
1561
+ const keys = Object.keys(input);
1562
+ for (let i = 0; i < keys.length; i++) {
1563
+ const key = keys[i];
1487
1564
  const val = input[key];
1488
- strParts.push(
1489
- `${JSON.stringify(key)}:${schema.metadata[SCHEMA_METADATA].serialize(val, {
1565
+ if (i > 0) result += ",";
1566
+ result += serializeString(key);
1567
+ result += ":";
1568
+ result += schema.metadata[SCHEMA_METADATA].serialize(
1569
+ val,
1570
+ {
1490
1571
  instancePath: `${context.instancePath}/${key}`,
1491
1572
  schemaPath: `${context.schemaPath}/values`,
1492
1573
  errors: context.errors
1493
- })}`
1574
+ }
1494
1575
  );
1495
1576
  }
1496
- const result = `{${strParts.join(",")}}`;
1497
- if (context.instancePath.length === 0) {
1498
- return sanitizeJson(result);
1499
- }
1577
+ result += "}";
1500
1578
  return result;
1501
1579
  }
1502
1580
  }
1503
1581
  }
1504
1582
  };
1505
1583
  }
1506
- function parse$2(schema, input, data, coerce = false) {
1584
+ function parse$1(schema, input, data, coerce = false) {
1507
1585
  let parsedInput = input;
1508
1586
  if (data.instancePath.length === 0 && typeof input === "string") {
1509
1587
  parsedInput = JSON.parse(input);
@@ -1594,80 +1672,6 @@ function recursive(propA, propB) {
1594
1672
  return mainSchema;
1595
1673
  }
1596
1674
 
1597
- function string(opts = {}) {
1598
- return {
1599
- type: "string",
1600
- metadata: {
1601
- id: opts.id,
1602
- description: opts.description,
1603
- isDeprecated: opts.isDeprecated,
1604
- [SCHEMA_METADATA]: {
1605
- output: "",
1606
- parse: parse$1,
1607
- coerce: coerce$1,
1608
- validate: validate$1,
1609
- serialize(input, context) {
1610
- if (context.instancePath.length === 0) {
1611
- return input;
1612
- }
1613
- if (input.length < 42) {
1614
- return serializeSmallString(input);
1615
- }
1616
- if (input.length < 5e3 && !STR_ESCAPE.test(input)) {
1617
- return `"${input}"`;
1618
- }
1619
- return JSON.stringify(input);
1620
- }
1621
- }
1622
- }
1623
- };
1624
- }
1625
- function validate$1(input) {
1626
- return typeof input === "string";
1627
- }
1628
- function parse$1(input, context) {
1629
- if (validate$1(input)) {
1630
- return input;
1631
- }
1632
- context.errors.push({
1633
- instancePath: context.instancePath,
1634
- schemaPath: `${context.schemaPath}/type`,
1635
- message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
1636
- });
1637
- return void 0;
1638
- }
1639
- function coerce$1(input, context) {
1640
- return parse$1(input, context);
1641
- }
1642
- const STR_ESCAPE = (
1643
- // eslint-disable-next-line no-control-regex
1644
- /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/
1645
- );
1646
- function serializeSmallString(input) {
1647
- const len = input.length;
1648
- let result = "";
1649
- let last = -1;
1650
- let point = 255;
1651
- for (let i = 0; i < len; i++) {
1652
- point = input.charCodeAt(i);
1653
- if (point < 32 || point >= 55296 && point <= 57343) {
1654
- return JSON.stringify(input);
1655
- }
1656
- if (point === 34 || // '"'
1657
- point === 92) {
1658
- if (last === -1) {
1659
- last = 0;
1660
- }
1661
- result += input.slice(last, i) + "\\";
1662
- last = i;
1663
- }
1664
- }
1665
- if (last === -1) {
1666
- return `"${input}"`;
1667
- }
1668
- return `"${result}${input.slice(last)}"`;
1669
- }
1670
-
1671
1675
  function timestamp(opts = {}) {
1672
1676
  return {
1673
1677
  type: "timestamp",
@@ -1726,6 +1730,7 @@ function serialize(input, data) {
1726
1730
 
1727
1731
  exports.NumberTypeValues = NumberTypeValues;
1728
1732
  exports.SCHEMA_METADATA = SCHEMA_METADATA;
1733
+ exports.STR_ESCAPE = STR_ESCAPE;
1729
1734
  exports.ValidationError = ValidationError;
1730
1735
  exports.any = any;
1731
1736
  exports.array = array;
@@ -1777,6 +1782,7 @@ exports.sanitizeJson = sanitizeJson;
1777
1782
  exports.serialize = serialize$1;
1778
1783
  exports.serializeObject = serializeObject;
1779
1784
  exports.serializeSmallString = serializeSmallString;
1785
+ exports.serializeString = serializeString;
1780
1786
  exports.string = string;
1781
1787
  exports.stringEnum = stringEnum;
1782
1788
  exports.timestamp = timestamp;
@@ -1,4 +1,4 @@
1
- import { TypeValues, isSchemaFormElements, isSchemaFormEnum, isSchemaFormDiscriminator, isSchemaFormValues, isSchemaFormProperties, isSchemaFormRef } from 'jtd-utils';
1
+ import { TypeValues, isSchemaFormElements, isSchemaFormEnum, isSchemaFormDiscriminator, isSchemaFormValues, isSchemaFormProperties, isSchemaFormRef } from '@arrirpc/type-defs';
2
2
 
3
3
  const int8Min = -128;
4
4
  const int8Max = 127;
@@ -31,9 +31,7 @@ function isASchema(input) {
31
31
  return "parse" in input.metadata[SCHEMA_METADATA] && typeof input.metadata[SCHEMA_METADATA] === "object";
32
32
  }
33
33
  function isAScalarSchema(input) {
34
- return isASchema(input) && "type" in input && typeof input.type === "string" && // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
35
- (TypeValues.includes(input.type) || // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
36
- NumberTypeValues.includes(input.type));
34
+ return isASchema(input) && "type" in input && typeof input.type === "string" && (TypeValues.includes(input.type) || NumberTypeValues.includes(input.type));
37
35
  }
38
36
  const NumberTypeValues = [
39
37
  "float32",
@@ -278,12 +276,6 @@ function serialize$2(input) {
278
276
  return `${input}`;
279
277
  }
280
278
 
281
- var __defProp = Object.defineProperty;
282
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
283
- var __publicField = (obj, key, value) => {
284
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
285
- return value;
286
- };
287
279
  function sanitizeJson(json) {
288
280
  return json.replace(/[\b]/g, "\\b").replace(/[\f]/g, "\\f").replace(/[\n]/g, "\\n").replace(/[\r]/g, "\\r").replace(/[\t]/g, "\\t");
289
281
  }
@@ -388,9 +380,9 @@ function errors(schema, input) {
388
380
  return errorList;
389
381
  }
390
382
  class ValidationError extends Error {
383
+ errors;
391
384
  constructor(options) {
392
385
  super(options.message);
393
- __publicField(this, "errors");
394
386
  this.errors = options.errors;
395
387
  }
396
388
  }
@@ -1451,6 +1443,89 @@ function partial(schema, options = {}) {
1451
1443
  return newSchema;
1452
1444
  }
1453
1445
 
1446
+ function string(opts = {}) {
1447
+ return {
1448
+ type: "string",
1449
+ metadata: {
1450
+ id: opts.id,
1451
+ description: opts.description,
1452
+ isDeprecated: opts.isDeprecated,
1453
+ [SCHEMA_METADATA]: {
1454
+ output: "",
1455
+ parse: parse$2,
1456
+ coerce: coerce$1,
1457
+ validate: validate$1,
1458
+ serialize(input, context) {
1459
+ if (context.instancePath.length === 0) {
1460
+ return input;
1461
+ }
1462
+ if (input.length < 42) {
1463
+ return serializeSmallString(input);
1464
+ }
1465
+ if (input.length < 5e3 && !STR_ESCAPE.test(input)) {
1466
+ return `"${input}"`;
1467
+ }
1468
+ return JSON.stringify(input);
1469
+ }
1470
+ }
1471
+ }
1472
+ };
1473
+ }
1474
+ function serializeString(input) {
1475
+ if (input.length < 42) {
1476
+ return serializeSmallString(input);
1477
+ }
1478
+ if (input.length < 5e3 && !STR_ESCAPE.test(input)) {
1479
+ return `"${input}"`;
1480
+ }
1481
+ return JSON.stringify(input);
1482
+ }
1483
+ function validate$1(input) {
1484
+ return typeof input === "string";
1485
+ }
1486
+ function parse$2(input, context) {
1487
+ if (validate$1(input)) {
1488
+ return input;
1489
+ }
1490
+ context.errors.push({
1491
+ instancePath: context.instancePath,
1492
+ schemaPath: `${context.schemaPath}/type`,
1493
+ message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
1494
+ });
1495
+ return void 0;
1496
+ }
1497
+ function coerce$1(input, context) {
1498
+ return parse$2(input, context);
1499
+ }
1500
+ const STR_ESCAPE = (
1501
+ // eslint-disable-next-line no-control-regex
1502
+ /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/
1503
+ );
1504
+ function serializeSmallString(input) {
1505
+ const len = input.length;
1506
+ let result = "";
1507
+ let last = -1;
1508
+ let point = 255;
1509
+ for (let i = 0; i < len; i++) {
1510
+ point = input.charCodeAt(i);
1511
+ if (point < 32 || point >= 55296 && point <= 57343) {
1512
+ return JSON.stringify(input);
1513
+ }
1514
+ if (point === 34 || // '"'
1515
+ point === 92) {
1516
+ if (last === -1) {
1517
+ last = 0;
1518
+ }
1519
+ result += input.slice(last, i) + "\\";
1520
+ last = i;
1521
+ }
1522
+ }
1523
+ if (last === -1) {
1524
+ return `"${input}"`;
1525
+ }
1526
+ return `"${result}${input.slice(last)}"`;
1527
+ }
1528
+
1454
1529
  function record(schema, opts = {}) {
1455
1530
  return {
1456
1531
  values: schema,
@@ -1474,34 +1549,37 @@ function record(schema, opts = {}) {
1474
1549
  return true;
1475
1550
  },
1476
1551
  parse(input, context) {
1477
- return parse$2(schema, input, context, false);
1552
+ return parse$1(schema, input, context, false);
1478
1553
  },
1479
1554
  coerce(input, data) {
1480
- return parse$2(schema, input, data, true);
1555
+ return parse$1(schema, input, data, true);
1481
1556
  },
1482
1557
  serialize(input, context) {
1483
- const strParts = [];
1484
- for (const key of Object.keys(input)) {
1558
+ let result = "{";
1559
+ const keys = Object.keys(input);
1560
+ for (let i = 0; i < keys.length; i++) {
1561
+ const key = keys[i];
1485
1562
  const val = input[key];
1486
- strParts.push(
1487
- `${JSON.stringify(key)}:${schema.metadata[SCHEMA_METADATA].serialize(val, {
1563
+ if (i > 0) result += ",";
1564
+ result += serializeString(key);
1565
+ result += ":";
1566
+ result += schema.metadata[SCHEMA_METADATA].serialize(
1567
+ val,
1568
+ {
1488
1569
  instancePath: `${context.instancePath}/${key}`,
1489
1570
  schemaPath: `${context.schemaPath}/values`,
1490
1571
  errors: context.errors
1491
- })}`
1572
+ }
1492
1573
  );
1493
1574
  }
1494
- const result = `{${strParts.join(",")}}`;
1495
- if (context.instancePath.length === 0) {
1496
- return sanitizeJson(result);
1497
- }
1575
+ result += "}";
1498
1576
  return result;
1499
1577
  }
1500
1578
  }
1501
1579
  }
1502
1580
  };
1503
1581
  }
1504
- function parse$2(schema, input, data, coerce = false) {
1582
+ function parse$1(schema, input, data, coerce = false) {
1505
1583
  let parsedInput = input;
1506
1584
  if (data.instancePath.length === 0 && typeof input === "string") {
1507
1585
  parsedInput = JSON.parse(input);
@@ -1592,80 +1670,6 @@ function recursive(propA, propB) {
1592
1670
  return mainSchema;
1593
1671
  }
1594
1672
 
1595
- function string(opts = {}) {
1596
- return {
1597
- type: "string",
1598
- metadata: {
1599
- id: opts.id,
1600
- description: opts.description,
1601
- isDeprecated: opts.isDeprecated,
1602
- [SCHEMA_METADATA]: {
1603
- output: "",
1604
- parse: parse$1,
1605
- coerce: coerce$1,
1606
- validate: validate$1,
1607
- serialize(input, context) {
1608
- if (context.instancePath.length === 0) {
1609
- return input;
1610
- }
1611
- if (input.length < 42) {
1612
- return serializeSmallString(input);
1613
- }
1614
- if (input.length < 5e3 && !STR_ESCAPE.test(input)) {
1615
- return `"${input}"`;
1616
- }
1617
- return JSON.stringify(input);
1618
- }
1619
- }
1620
- }
1621
- };
1622
- }
1623
- function validate$1(input) {
1624
- return typeof input === "string";
1625
- }
1626
- function parse$1(input, context) {
1627
- if (validate$1(input)) {
1628
- return input;
1629
- }
1630
- context.errors.push({
1631
- instancePath: context.instancePath,
1632
- schemaPath: `${context.schemaPath}/type`,
1633
- message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
1634
- });
1635
- return void 0;
1636
- }
1637
- function coerce$1(input, context) {
1638
- return parse$1(input, context);
1639
- }
1640
- const STR_ESCAPE = (
1641
- // eslint-disable-next-line no-control-regex
1642
- /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/
1643
- );
1644
- function serializeSmallString(input) {
1645
- const len = input.length;
1646
- let result = "";
1647
- let last = -1;
1648
- let point = 255;
1649
- for (let i = 0; i < len; i++) {
1650
- point = input.charCodeAt(i);
1651
- if (point < 32 || point >= 55296 && point <= 57343) {
1652
- return JSON.stringify(input);
1653
- }
1654
- if (point === 34 || // '"'
1655
- point === 92) {
1656
- if (last === -1) {
1657
- last = 0;
1658
- }
1659
- result += input.slice(last, i) + "\\";
1660
- last = i;
1661
- }
1662
- }
1663
- if (last === -1) {
1664
- return `"${input}"`;
1665
- }
1666
- return `"${result}${input.slice(last)}"`;
1667
- }
1668
-
1669
1673
  function timestamp(opts = {}) {
1670
1674
  return {
1671
1675
  type: "timestamp",
@@ -1722,4 +1726,4 @@ function serialize(input, data) {
1722
1726
  return `"${input.toISOString()}"`;
1723
1727
  }
1724
1728
 
1725
- export { uint64 as $, enumerator as A, extend as B, float32 as C, float64 as D, int16 as E, int32 as F, int64 as G, int8 as H, nullable as I, number as J, object as K, omit as L, optional as M, parse$4 as N, partial as O, pick as P, record as Q, recursive as R, safeCoerce as S, safeParse as T, serialize$1 as U, ValidationError as V, string as W, stringEnum as X, timestamp as Y, uint16 as Z, uint32 as _, uint8Min as a, uint8 as a0, validate$3 as a1, SCHEMA_METADATA as a2, int64Min as a3, int64Max as a4, uint64Min as a5, uint64Max as a6, parseObjectSchema as a7, validateObjectSchema as a8, serializeObject as a9, serializeSmallString as aa, sanitizeJson as ab, isValidationError as ac, isASchema as ad, NumberTypeValues as ae, isObject as af, uint16Max as b, uint16Min as c, uint32Max as d, uint32Min as e, int8Min as f, int16Max as g, int16Min as h, int8Max as i, int32Max as j, int32Min as k, isAScalarSchema as l, isAObjectSchema as m, isAStringEnumSchema as n, isAAraySchema as o, isARecordSchema as p, isADiscriminatorSchema as q, isARefSchema as r, errors as s, any as t, uint8Max as u, array as v, boolean as w, clone as x, coerce$2 as y, discriminator as z };
1729
+ export { uint64 as $, enumerator as A, extend as B, float32 as C, float64 as D, int16 as E, int32 as F, int64 as G, int8 as H, nullable as I, number as J, object as K, omit as L, optional as M, parse$4 as N, partial as O, pick as P, record as Q, recursive as R, safeCoerce as S, safeParse as T, serialize$1 as U, ValidationError as V, string as W, stringEnum as X, timestamp as Y, uint16 as Z, uint32 as _, uint8Min as a, uint8 as a0, validate$3 as a1, SCHEMA_METADATA as a2, int64Min as a3, int64Max as a4, uint64Min as a5, uint64Max as a6, parseObjectSchema as a7, validateObjectSchema as a8, serializeObject as a9, serializeString as aa, STR_ESCAPE as ab, serializeSmallString as ac, sanitizeJson as ad, isValidationError as ae, isASchema as af, NumberTypeValues as ag, isObject as ah, uint16Max as b, uint16Min as c, uint32Max as d, uint32Min as e, int8Min as f, int16Max as g, int16Min as h, int8Max as i, int32Max as j, int32Min as k, isAScalarSchema as l, isAObjectSchema as m, isAStringEnumSchema as n, isAAraySchema as o, isARecordSchema as p, isADiscriminatorSchema as q, isARefSchema as r, errors as s, any as t, uint8Max as u, array as v, boolean as w, clone as x, coerce$2 as y, discriminator as z };
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- require('jtd-utils');
3
+ require('@arrirpc/type-defs');
4
4
  require('scule');
5
- const timestamp = require('./shared/schema.4e2863ed.cjs');
5
+ const timestamp = require('./shared/schema.TlNJgMz1.cjs');
6
6
 
7
7
  const User = timestamp.object({
8
8
  id: timestamp.string(),
@@ -1,5 +1,5 @@
1
- import { d as AObjectSchema, e as ADiscriminatorSchema, A as ASchema } from './shared/schema.cdac4a20.cjs';
2
- import 'jtd-utils';
1
+ import { d as AObjectSchema, e as ADiscriminatorSchema, A as ASchema } from './shared/schema.C-0ZU_OQ.cjs';
2
+ import '@arrirpc/type-defs';
3
3
 
4
4
  type RecursiveUnion = {
5
5
  type: "CHILD";
@@ -1,5 +1,5 @@
1
- import { d as AObjectSchema, e as ADiscriminatorSchema, A as ASchema } from './shared/schema.cdac4a20.mjs';
2
- import 'jtd-utils';
1
+ import { d as AObjectSchema, e as ADiscriminatorSchema, A as ASchema } from './shared/schema.C-0ZU_OQ.mjs';
2
+ import '@arrirpc/type-defs';
3
3
 
4
4
  type RecursiveUnion = {
5
5
  type: "CHILD";
@@ -1,5 +1,5 @@
1
- import { d as AObjectSchema, e as ADiscriminatorSchema, A as ASchema } from './shared/schema.cdac4a20.js';
2
- import 'jtd-utils';
1
+ import { d as AObjectSchema, e as ADiscriminatorSchema, A as ASchema } from './shared/schema.C-0ZU_OQ.js';
2
+ import '@arrirpc/type-defs';
3
3
 
4
4
  type RecursiveUnion = {
5
5
  type: "CHILD";
@@ -1,6 +1,6 @@
1
- import 'jtd-utils';
1
+ import '@arrirpc/type-defs';
2
2
  import 'scule';
3
- import { K as object, W as string, M as optional, I as nullable, F as int32, z as discriminator, w as boolean, X as stringEnum, v as array, Y as timestamp, _ as uint32, t as any, J as number, Q as record, R as recursive, D as float64, C as float32, G as int64, E as int16, Z as uint16, H as int8, a0 as uint8, O as partial, $ as uint64, P as pick, A as enumerator } from './shared/schema.25b78dac.mjs';
3
+ import { K as object, W as string, M as optional, I as nullable, F as int32, z as discriminator, w as boolean, X as stringEnum, v as array, Y as timestamp, _ as uint32, t as any, J as number, Q as record, R as recursive, D as float64, C as float32, G as int64, E as int16, Z as uint16, H as int8, a0 as uint8, O as partial, $ as uint64, P as pick, A as enumerator } from './shared/schema.lowJcmic.mjs';
4
4
 
5
5
  const User = object({
6
6
  id: string(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/schema",
3
- "version": "0.69.2",
3
+ "version": "0.70.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -13,7 +13,7 @@
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "https://github.com/modiimedia/arri.git",
16
- "directory": "tooling/schema"
16
+ "directory": "languages/ts/ts-schema"
17
17
  },
18
18
  "main": "./dist/index.cjs",
19
19
  "module": "./dist/index.mjs",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "scule": "^1.3.0",
26
26
  "uncrypto": "^0.1.3",
27
- "jtd-utils": "0.69.2"
27
+ "@arrirpc/type-defs": "0.70.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "ajv": "^8.17.1",