@arrirpc/schema 0.70.1 → 0.71.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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A type builder and validation library for [Arri Type Definitions](/specifications/arri_type_definition.md). A lot of inspiration was taken from both [Typebox](https://github.com/sinclairzx81/typebox) and [Zod](https://github.com/colinhacks/zod) when designing this library.
4
4
 
5
+ This library also supports [standard-schema](https://github.com/standard-schema/standard-schema) meaning it can be used with any third-party library that accepts standard schema.
6
+
5
7
  ## Project Philosophy
6
8
 
7
9
  The goals of this project are as follows:
@@ -66,7 +68,7 @@ pnpm install @arrirpc/schema
66
68
  ## Basic Example
67
69
 
68
70
  ```ts
69
- import { a } from "@arrirpc/schema";
71
+ import { a } from '@arrirpc/schema';
70
72
 
71
73
  const User = a.object({
72
74
  id: a.string(),
@@ -81,12 +83,12 @@ a.parse(User, `{"id": "1", "name": "John Doe"}`);
81
83
  a.parse(User, `{"id": "1", "name": null}`);
82
84
 
83
85
  // returns true
84
- a.validate(User, { id: "1", name: "John Doe" });
86
+ a.validate(User, { id: '1', name: 'John Doe' });
85
87
  // returns false
86
- a.validate(User, { id: "1", name: null });
88
+ a.validate(User, { id: '1', name: null });
87
89
 
88
90
  // outputs valid json
89
- a.serialize(User, { id: "1", name: "John Doe" });
91
+ a.serialize(User, { id: '1', name: 'John Doe' });
90
92
  ```
91
93
 
92
94
  ## Usage With @arrirpc/server
@@ -94,8 +96,8 @@ a.serialize(User, { id: "1", name: "John Doe" });
94
96
  See [here](/languages/ts/ts-server/README.md) for full details.
95
97
 
96
98
  ```ts
97
- import { a } from "@arrirpc/schema";
98
- import { defineRpc } from "@arrirpc/server";
99
+ import { a } from '@arrirpc/schema';
100
+ import { defineRpc } from '@arrirpc/server';
99
101
 
100
102
  export default defineRpc({
101
103
  params: a.object({
@@ -141,11 +143,11 @@ Enum schemas allow you to specify a predefine list of accepted strings
141
143
  **Usage**
142
144
 
143
145
  ```ts
144
- const Status = a.enumerator(["ACTIVE", "INACTIVE", "UNKNOWN"]);
146
+ const Status = a.enumerator(['ACTIVE', 'INACTIVE', 'UNKNOWN']);
145
147
  type Status = a.infer<typeof Status>; // "ACTIVE" | "INACTIVE" | "UNKNOWN";
146
148
 
147
- a.validate(Status, "BLAH"); // false
148
- a.validate(Status, "ACTIVE"); // true
149
+ a.validate(Status, 'BLAH'); // false
150
+ a.validate(Status, 'ACTIVE'); // true
149
151
  ```
150
152
 
151
153
  **Outputted JTD**
@@ -165,7 +167,7 @@ const MyList = a.array(a.string());
165
167
  type MyList = a.infer<typeof MyList>; // string[];
166
168
 
167
169
  a.validate(MyList, [1, 2]); // false
168
- a.validate(MyList, ["hello", "world"]); // true
170
+ a.validate(MyList, ['hello', 'world']); // true
169
171
  ```
170
172
 
171
173
  **Outputted JTD**
@@ -191,12 +193,12 @@ const User = a.object({
191
193
  type User = a.infer<typeof User>; // { id: string; email: string; created: Date; }
192
194
 
193
195
  a.validate({
194
- id: "1",
195
- email: "johndoe@example.com",
196
+ id: '1',
197
+ email: 'johndoe@example.com',
196
198
  created: new Date(),
197
199
  }); // true
198
200
  a.validate({
199
- id: "1",
201
+ id: '1',
200
202
  email: null,
201
203
  created: new Date(),
202
204
  }); // false
@@ -237,10 +239,10 @@ const UserStrict = a.object(
237
239
  );
238
240
 
239
241
  a.parse(UserStrict, {
240
- id: "1",
241
- name: "johndoe",
242
+ id: '1',
243
+ name: 'johndoe',
242
244
  created: new Date(),
243
- bio: "my name is joe",
245
+ bio: 'my name is joe',
244
246
  }); // fails parsing because of the additional field "bio"
245
247
  ```
246
248
 
@@ -276,7 +278,7 @@ a.validate(R, {
276
278
  world: false,
277
279
  }); // true;
278
280
  a.validate(R, {
279
- hello: "world",
281
+ hello: 'world',
280
282
  }); // false;
281
283
  ```
282
284
 
@@ -295,7 +297,7 @@ a.validate(R, {
295
297
  **Usage**
296
298
 
297
299
  ```ts
298
- const Shape = a.discriminator("type", {
300
+ const Shape = a.discriminator('type', {
299
301
  RECTANGLE: a.object({
300
302
  width: a.float32(),
301
303
  height: a.float32(),
@@ -307,20 +309,20 @@ const Shape = a.discriminator("type", {
307
309
  type Shape = a.infer<typeof Shape>; // { type: "RECTANGLE"; width: number; height: number; } | { type: "CIRCLE"; radius: number; }
308
310
 
309
311
  // Infer specific sub types of the union
310
- type ShapeTypeRectangle = a.inferSubType<Shape, "type", "RECTANGLE">; // { type "RECTANGLE"; width: number; height: number; };
311
- type ShapeTypeCircle = a.inferSubType<Shape, "type", "CIRCLE">; // { type "CIRCLE"; radius: number; }
312
+ type ShapeTypeRectangle = a.inferSubType<Shape, 'type', 'RECTANGLE'>; // { type "RECTANGLE"; width: number; height: number; };
313
+ type ShapeTypeCircle = a.inferSubType<Shape, 'type', 'CIRCLE'>; // { type "CIRCLE"; radius: number; }
312
314
 
313
315
  a.validate(Shape, {
314
- type: "RECTANGLE",
316
+ type: 'RECTANGLE',
315
317
  width: 1,
316
318
  height: 1.5,
317
319
  }); // true
318
320
  a.validate(Shape, {
319
- type: "CIRCLE",
321
+ type: 'CIRCLE',
320
322
  radius: 5,
321
323
  }); // true
322
324
  a.validate(Shape, {
323
- type: "CIRCLE",
325
+ type: 'CIRCLE',
324
326
  width: 1,
325
327
  height: 1.5,
326
328
  }); // false
@@ -385,7 +387,7 @@ const BinaryTree = a.recursive<BinaryTree>(
385
387
  right: a.nullable(self),
386
388
  }),
387
389
  {
388
- id: "BinaryTree",
390
+ id: 'BinaryTree',
389
391
  },
390
392
  );
391
393
 
@@ -506,7 +508,7 @@ const A = a.object(
506
508
  a: a.string(),
507
509
  b: a.float32(),
508
510
  },
509
- { id: "A" },
511
+ { id: 'A' },
510
512
  );
511
513
  console.log(A.metadata.id); // "A"
512
514
 
@@ -545,7 +547,7 @@ const A = a.object({
545
547
  });
546
548
  // { a: string; b: number; }
547
549
 
548
- const B = a.omit(A, ["a"]);
550
+ const B = a.omit(A, ['a']);
549
551
  // { b: number; }
550
552
  ```
551
553
 
@@ -561,7 +563,7 @@ const A = a.object({
561
563
  });
562
564
  // { a: string; b: number; c: Date; }
563
565
 
564
- const B = a.pick(A, ["a", "c"]);
566
+ const B = a.pick(A, ['a', 'c']);
565
567
  // { a: string; c: Date; }
566
568
  ```
567
569
 
@@ -593,7 +595,7 @@ const User = a.object({
593
595
  name: a.string(),
594
596
  });
595
597
  a.validate(User, true); // false
596
- a.validate(User, { id: "1", name: "john doe" }); // true
598
+ a.validate(User, { id: '1', name: 'john doe' }); // true
597
599
 
598
600
  if (a.validate(User, someInput)) {
599
601
  console.log(someInput.id); // intellisense works here
@@ -644,9 +646,9 @@ const A = a.object({
644
646
  });
645
647
 
646
648
  a.coerce(A, {
647
- a: "1",
648
- b: "true",
649
- c: "500.24",
649
+ a: '1',
650
+ b: 'true',
651
+ c: '500.24',
650
652
  });
651
653
  // { a: "1", b: true, c: 500.24 };
652
654
  ```
@@ -681,7 +683,7 @@ const User = a.object({
681
683
  name: a.string(),
682
684
  });
683
685
 
684
- a.serialize(User, { id: "1", name: "john doe" });
686
+ a.serialize(User, { id: '1', name: 'john doe' });
685
687
  // {"id":"1","name":"john doe"}
686
688
  ```
687
689
 
@@ -697,7 +699,7 @@ const User = a.object({
697
699
  date: a.timestamp(),
698
700
  });
699
701
 
700
- a.errors(User, { id: 1, date: "hello world" });
702
+ a.errors(User, { id: 1, date: 'hello world' });
701
703
  /**
702
704
  * [
703
705
  * {
@@ -730,7 +732,7 @@ const $$User = a.compile(User);
730
732
 
731
733
  $$User.validate(someInput);
732
734
  $$User.parse(someJson);
733
- $$User.serialize({ id: "1", email: null, created: new Date() });
735
+ $$User.serialize({ id: '1', email: null, created: new Date() });
734
736
  ```
735
737
 
736
738
  In most cases, the compiled validators will be much faster than the standard utilities. However there is some overhead with compiling the schemas so ideally each validator would be compiled once. Additionally the resulting methods make use of eval so they can only be used in an environment that you control such as a backend server. They WILL NOT work in a browser environment.
@@ -764,8 +766,8 @@ const BookSchema = a.object(
764
766
  publishDate: a.timestamp(),
765
767
  },
766
768
  {
767
- id: "Book",
768
- description: "This is a book",
769
+ id: 'Book',
770
+ description: 'This is a book',
769
771
  },
770
772
  );
771
773
  ```
@@ -831,14 +833,14 @@ Because IDs are really important for producing concise type names. Arri validate
831
833
 
832
834
  ```ts
833
835
  // ID will be set to "Book"
834
- const BookSchema = a.object("Book", {
836
+ const BookSchema = a.object('Book', {
835
837
  title: a.string(),
836
838
  author: a.string(),
837
839
  publishDate: a.timestamp(),
838
840
  });
839
841
 
840
842
  // ID will be set to "Message"
841
- const MessageSchema = a.discriminator("Message", "type", {
843
+ const MessageSchema = a.discriminator('Message', 'type', {
842
844
  TEXT: a.object({
843
845
  userId: a.string(),
844
846
  content: a.string(),
@@ -850,7 +852,7 @@ const MessageSchema = a.discriminator("Message", "type", {
850
852
  });
851
853
 
852
854
  // ID will be set to "BTree"
853
- const BinaryTreeSchema = a.recursive("BTree", (self) =>
855
+ const BinaryTreeSchema = a.recursive('BTree', (self) =>
854
856
  a.object({
855
857
  left: a.nullable(self),
856
858
  right: a.nullable(self),
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const typeDefs = require('@arrirpc/type-defs');
4
4
  const scule = require('scule');
5
- const timestamp = require('./shared/schema.TlNJgMz1.cjs');
5
+ const timestamp = require('./shared/schema.BcsXcrqv.cjs');
6
6
 
7
7
  function createParsingTemplate(input, schema) {
8
8
  const fallbackTemplate = `
@@ -1367,33 +1367,31 @@ function compile(schema) {
1367
1367
  const parseFn = parser.fn;
1368
1368
  const serializer = getCompiledSerializer(schema);
1369
1369
  const serializeFn = serializer.fn;
1370
- const validate = new Function(
1371
- "input",
1372
- validateCode
1373
- );
1374
- return {
1375
- validate,
1376
- parse(input) {
1377
- try {
1378
- return parseFn(input);
1379
- } catch (err) {
1380
- const errors = timestamp.errors(schema, input);
1381
- let errorMessage = err instanceof Error ? err.message : "";
1382
- if (errors.length) {
1383
- errorMessage = errors[0].message ?? `Parsing error at ${errors[0].instancePath}`;
1384
- }
1385
- throw new timestamp.ValidationError({
1386
- message: errorMessage,
1387
- errors
1388
- });
1370
+ const validate = new Function("input", validateCode);
1371
+ const parse = (input) => {
1372
+ try {
1373
+ return parseFn(input);
1374
+ } catch (err) {
1375
+ const errors = timestamp.errors(schema, input);
1376
+ let errorMessage = err instanceof Error ? err.message : "";
1377
+ if (errors.length) {
1378
+ errorMessage = errors[0].message ?? `Parsing error at ${errors[0].instancePath}`;
1389
1379
  }
1390
- },
1380
+ throw new timestamp.ValidationError({
1381
+ message: errorMessage,
1382
+ errors
1383
+ });
1384
+ }
1385
+ };
1386
+ const result = {
1387
+ validate,
1388
+ parse,
1391
1389
  safeParse(input) {
1392
1390
  try {
1393
- const result = parseFn(input);
1391
+ const result2 = parseFn(input);
1394
1392
  return {
1395
1393
  success: true,
1396
- value: result
1394
+ value: result2
1397
1395
  };
1398
1396
  } catch (err) {
1399
1397
  const errors = timestamp.errors(schema, input);
@@ -1426,8 +1424,10 @@ function compile(schema) {
1426
1424
  validate: validateCode,
1427
1425
  parse: parser.code,
1428
1426
  serialize: serializer.code
1429
- }
1427
+ },
1428
+ "~standard": timestamp.createStandardSchemaProperty(validate, parse)
1430
1429
  };
1430
+ return result;
1431
1431
  }
1432
1432
  function getCompiledParser(input, schema) {
1433
1433
  const code = createParsingTemplate(input, schema);
@@ -2134,7 +2134,7 @@ function isAdaptedSchema(input) {
2134
2134
  return input.metadata[timestamp.SCHEMA_METADATA]._isAdapted === true;
2135
2135
  }
2136
2136
  function validatorFromAdaptedSchema(schema) {
2137
- return {
2137
+ const result = {
2138
2138
  compiledCode: {
2139
2139
  parse: "",
2140
2140
  serialize: "",
@@ -2156,13 +2156,13 @@ function validatorFromAdaptedSchema(schema) {
2156
2156
  errors: []
2157
2157
  };
2158
2158
  try {
2159
- const result = schema.metadata[timestamp.SCHEMA_METADATA].parse(
2159
+ const result2 = schema.metadata[timestamp.SCHEMA_METADATA].parse(
2160
2160
  input,
2161
2161
  context
2162
2162
  );
2163
2163
  return {
2164
2164
  success: true,
2165
- value: result
2165
+ value: result2
2166
2166
  };
2167
2167
  } catch (err) {
2168
2168
  if (err instanceof timestamp.ValidationError) {
@@ -2187,8 +2187,13 @@ function validatorFromAdaptedSchema(schema) {
2187
2187
  errors: []
2188
2188
  };
2189
2189
  return schema.metadata[timestamp.SCHEMA_METADATA].serialize(input, context);
2190
- }
2190
+ },
2191
+ "~standard": timestamp.createStandardSchemaProperty(
2192
+ schema.metadata[timestamp.SCHEMA_METADATA].validate,
2193
+ schema.metadata[timestamp.SCHEMA_METADATA].parse
2194
+ )
2191
2195
  };
2196
+ return result;
2192
2197
  }
2193
2198
 
2194
2199
  exports.NumberTypeValues = timestamp.NumberTypeValues;
@@ -2200,12 +2205,14 @@ exports.array = timestamp.array;
2200
2205
  exports.boolean = timestamp.boolean;
2201
2206
  exports.clone = timestamp.clone;
2202
2207
  exports.coerce = timestamp.coerce;
2208
+ exports.createStandardSchemaProperty = timestamp.createStandardSchemaProperty;
2203
2209
  exports.discriminator = timestamp.discriminator;
2204
2210
  exports.enumerator = timestamp.enumerator;
2205
2211
  exports.errors = timestamp.errors;
2206
2212
  exports.extend = timestamp.extend;
2207
2213
  exports.float32 = timestamp.float32;
2208
2214
  exports.float64 = timestamp.float64;
2215
+ exports.hideInvalidProperties = timestamp.hideInvalidProperties;
2209
2216
  exports.int16 = timestamp.int16;
2210
2217
  exports.int16Max = timestamp.int16Max;
2211
2218
  exports.int16Min = timestamp.int16Min;
package/dist/index.d.cts CHANGED
@@ -1,5 +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.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';
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ 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.DLX0nTwB.cjs';
3
+ 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.DLX0nTwB.cjs';
3
4
  import { Schema } from '@arrirpc/type-defs';
4
5
 
5
6
  declare function createParsingTemplate(input: string, schema: Schema): string;
@@ -8,7 +9,7 @@ declare function createSerializationV2Template(inputName: string, schema: Schema
8
9
 
9
10
  declare function createValidationTemplate(inputName: string, schema: ASchema<any>): string;
10
11
 
11
- interface CompiledValidator<TSchema extends ASchema<any>> {
12
+ interface CompiledValidator<TSchema extends ASchema<any>> extends StandardSchemaV1<InferType<TSchema>> {
12
13
  /**
13
14
  * Determine if a type matches a schema. This is a type guard.
14
15
  */
@@ -35,7 +36,7 @@ interface CompiledValidator<TSchema extends ASchema<any>> {
35
36
  * Create compiled versions of the `parse()`, `validate()`, and `serialize()` functions
36
37
  */
37
38
  declare function compile<TSchema extends ASchema<any>>(schema: TSchema): CompiledValidator<TSchema>;
38
- type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>["parse"];
39
+ type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>['parse'];
39
40
  declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: TSchema): {
40
41
  fn: CompiledParser<TSchema>;
41
42
  code: string;
@@ -58,7 +59,7 @@ declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSc
58
59
  * a.validate(Schema, true) // true;
59
60
  * a.validate(Schema, false) // true;
60
61
  */
61
- declare function boolean(opts?: ASchemaOptions): AScalarSchema<"boolean", boolean>;
62
+ declare function boolean(opts?: ASchemaOptions): AScalarSchema<'boolean', boolean>;
62
63
 
63
64
  /**
64
65
  * Create a discriminated union / tagged union
@@ -173,8 +174,8 @@ declare function int16(opts?: ASchemaOptions): AScalarSchema<"int16", number>;
173
174
  declare function uint16(opts?: ASchemaOptions): AScalarSchema<"uint16", number>;
174
175
  declare function int32(opts?: ASchemaOptions): AScalarSchema<"int32", number>;
175
176
  declare function uint32(opts?: ASchemaOptions): AScalarSchema<"uint32", number>;
176
- declare function int64(opts?: ASchemaOptions): AScalarSchema<"int64", bigint>;
177
- declare function uint64(opts?: ASchemaOptions): AScalarSchema<"uint64", bigint>;
177
+ declare function int64(opts?: ASchemaOptions): AScalarSchema<'int64', bigint>;
178
+ declare function uint64(opts?: ASchemaOptions): AScalarSchema<'uint64', bigint>;
178
179
 
179
180
  /**
180
181
  * Create an object schema
@@ -285,7 +286,7 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
285
286
  * a.validate(StringSchema, "hello world") // true
286
287
  * a.validate(StringSchema, 10) // false
287
288
  */
288
- declare function string(opts?: ASchemaOptions): AScalarSchema<"string", string>;
289
+ declare function string(opts?: ASchemaOptions): AScalarSchema<'string', string>;
289
290
  declare function serializeString(input: string): string;
290
291
  declare const STR_ESCAPE: RegExp;
291
292
  declare function serializeSmallString(input: string): string;
@@ -297,7 +298,7 @@ declare function serializeSmallString(input: string): string;
297
298
  * const Schema = a.timestamp();
298
299
  * a.validate(Schema, new Date()) // true
299
300
  */
300
- declare function timestamp(opts?: ASchemaOptions): AScalarSchema<"timestamp", Date>;
301
+ declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
301
302
 
302
303
  declare const _namespace_any: typeof any;
303
304
  declare const _namespace_array: typeof array;
@@ -361,4 +362,10 @@ declare const int64Max: bigint;
361
362
  declare const uint64Min: bigint;
362
363
  declare const uint64Max: bigint;
363
364
 
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 };
365
+ declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined): StandardSchemaV1<T>['~standard'];
366
+ /**
367
+ * Ensure that non ATD compliant properties get hidden when serialized to JSON
368
+ */
369
+ declare function hideInvalidProperties(schema: ASchema): void;
370
+
371
+ 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, createStandardSchemaProperty, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, hideInvalidProperties, 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,5 +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.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';
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ 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.DLX0nTwB.mjs';
3
+ 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.DLX0nTwB.mjs';
3
4
  import { Schema } from '@arrirpc/type-defs';
4
5
 
5
6
  declare function createParsingTemplate(input: string, schema: Schema): string;
@@ -8,7 +9,7 @@ declare function createSerializationV2Template(inputName: string, schema: Schema
8
9
 
9
10
  declare function createValidationTemplate(inputName: string, schema: ASchema<any>): string;
10
11
 
11
- interface CompiledValidator<TSchema extends ASchema<any>> {
12
+ interface CompiledValidator<TSchema extends ASchema<any>> extends StandardSchemaV1<InferType<TSchema>> {
12
13
  /**
13
14
  * Determine if a type matches a schema. This is a type guard.
14
15
  */
@@ -35,7 +36,7 @@ interface CompiledValidator<TSchema extends ASchema<any>> {
35
36
  * Create compiled versions of the `parse()`, `validate()`, and `serialize()` functions
36
37
  */
37
38
  declare function compile<TSchema extends ASchema<any>>(schema: TSchema): CompiledValidator<TSchema>;
38
- type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>["parse"];
39
+ type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>['parse'];
39
40
  declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: TSchema): {
40
41
  fn: CompiledParser<TSchema>;
41
42
  code: string;
@@ -58,7 +59,7 @@ declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSc
58
59
  * a.validate(Schema, true) // true;
59
60
  * a.validate(Schema, false) // true;
60
61
  */
61
- declare function boolean(opts?: ASchemaOptions): AScalarSchema<"boolean", boolean>;
62
+ declare function boolean(opts?: ASchemaOptions): AScalarSchema<'boolean', boolean>;
62
63
 
63
64
  /**
64
65
  * Create a discriminated union / tagged union
@@ -173,8 +174,8 @@ declare function int16(opts?: ASchemaOptions): AScalarSchema<"int16", number>;
173
174
  declare function uint16(opts?: ASchemaOptions): AScalarSchema<"uint16", number>;
174
175
  declare function int32(opts?: ASchemaOptions): AScalarSchema<"int32", number>;
175
176
  declare function uint32(opts?: ASchemaOptions): AScalarSchema<"uint32", number>;
176
- declare function int64(opts?: ASchemaOptions): AScalarSchema<"int64", bigint>;
177
- declare function uint64(opts?: ASchemaOptions): AScalarSchema<"uint64", bigint>;
177
+ declare function int64(opts?: ASchemaOptions): AScalarSchema<'int64', bigint>;
178
+ declare function uint64(opts?: ASchemaOptions): AScalarSchema<'uint64', bigint>;
178
179
 
179
180
  /**
180
181
  * Create an object schema
@@ -285,7 +286,7 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
285
286
  * a.validate(StringSchema, "hello world") // true
286
287
  * a.validate(StringSchema, 10) // false
287
288
  */
288
- declare function string(opts?: ASchemaOptions): AScalarSchema<"string", string>;
289
+ declare function string(opts?: ASchemaOptions): AScalarSchema<'string', string>;
289
290
  declare function serializeString(input: string): string;
290
291
  declare const STR_ESCAPE: RegExp;
291
292
  declare function serializeSmallString(input: string): string;
@@ -297,7 +298,7 @@ declare function serializeSmallString(input: string): string;
297
298
  * const Schema = a.timestamp();
298
299
  * a.validate(Schema, new Date()) // true
299
300
  */
300
- declare function timestamp(opts?: ASchemaOptions): AScalarSchema<"timestamp", Date>;
301
+ declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
301
302
 
302
303
  declare const _namespace_any: typeof any;
303
304
  declare const _namespace_array: typeof array;
@@ -361,4 +362,10 @@ declare const int64Max: bigint;
361
362
  declare const uint64Min: bigint;
362
363
  declare const uint64Max: bigint;
363
364
 
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 };
365
+ declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined): StandardSchemaV1<T>['~standard'];
366
+ /**
367
+ * Ensure that non ATD compliant properties get hidden when serialized to JSON
368
+ */
369
+ declare function hideInvalidProperties(schema: ASchema): void;
370
+
371
+ 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, createStandardSchemaProperty, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, hideInvalidProperties, 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,5 +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.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';
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ 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.DLX0nTwB.js';
3
+ 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.DLX0nTwB.js';
3
4
  import { Schema } from '@arrirpc/type-defs';
4
5
 
5
6
  declare function createParsingTemplate(input: string, schema: Schema): string;
@@ -8,7 +9,7 @@ declare function createSerializationV2Template(inputName: string, schema: Schema
8
9
 
9
10
  declare function createValidationTemplate(inputName: string, schema: ASchema<any>): string;
10
11
 
11
- interface CompiledValidator<TSchema extends ASchema<any>> {
12
+ interface CompiledValidator<TSchema extends ASchema<any>> extends StandardSchemaV1<InferType<TSchema>> {
12
13
  /**
13
14
  * Determine if a type matches a schema. This is a type guard.
14
15
  */
@@ -35,7 +36,7 @@ interface CompiledValidator<TSchema extends ASchema<any>> {
35
36
  * Create compiled versions of the `parse()`, `validate()`, and `serialize()` functions
36
37
  */
37
38
  declare function compile<TSchema extends ASchema<any>>(schema: TSchema): CompiledValidator<TSchema>;
38
- type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>["parse"];
39
+ type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>['parse'];
39
40
  declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: TSchema): {
40
41
  fn: CompiledParser<TSchema>;
41
42
  code: string;
@@ -58,7 +59,7 @@ declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSc
58
59
  * a.validate(Schema, true) // true;
59
60
  * a.validate(Schema, false) // true;
60
61
  */
61
- declare function boolean(opts?: ASchemaOptions): AScalarSchema<"boolean", boolean>;
62
+ declare function boolean(opts?: ASchemaOptions): AScalarSchema<'boolean', boolean>;
62
63
 
63
64
  /**
64
65
  * Create a discriminated union / tagged union
@@ -173,8 +174,8 @@ declare function int16(opts?: ASchemaOptions): AScalarSchema<"int16", number>;
173
174
  declare function uint16(opts?: ASchemaOptions): AScalarSchema<"uint16", number>;
174
175
  declare function int32(opts?: ASchemaOptions): AScalarSchema<"int32", number>;
175
176
  declare function uint32(opts?: ASchemaOptions): AScalarSchema<"uint32", number>;
176
- declare function int64(opts?: ASchemaOptions): AScalarSchema<"int64", bigint>;
177
- declare function uint64(opts?: ASchemaOptions): AScalarSchema<"uint64", bigint>;
177
+ declare function int64(opts?: ASchemaOptions): AScalarSchema<'int64', bigint>;
178
+ declare function uint64(opts?: ASchemaOptions): AScalarSchema<'uint64', bigint>;
178
179
 
179
180
  /**
180
181
  * Create an object schema
@@ -285,7 +286,7 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
285
286
  * a.validate(StringSchema, "hello world") // true
286
287
  * a.validate(StringSchema, 10) // false
287
288
  */
288
- declare function string(opts?: ASchemaOptions): AScalarSchema<"string", string>;
289
+ declare function string(opts?: ASchemaOptions): AScalarSchema<'string', string>;
289
290
  declare function serializeString(input: string): string;
290
291
  declare const STR_ESCAPE: RegExp;
291
292
  declare function serializeSmallString(input: string): string;
@@ -297,7 +298,7 @@ declare function serializeSmallString(input: string): string;
297
298
  * const Schema = a.timestamp();
298
299
  * a.validate(Schema, new Date()) // true
299
300
  */
300
- declare function timestamp(opts?: ASchemaOptions): AScalarSchema<"timestamp", Date>;
301
+ declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
301
302
 
302
303
  declare const _namespace_any: typeof any;
303
304
  declare const _namespace_array: typeof array;
@@ -361,4 +362,10 @@ declare const int64Max: bigint;
361
362
  declare const uint64Min: bigint;
362
363
  declare const uint64Max: bigint;
363
364
 
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 };
365
+ declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined): StandardSchemaV1<T>['~standard'];
366
+ /**
367
+ * Ensure that non ATD compliant properties get hidden when serialized to JSON
368
+ */
369
+ declare function hideInvalidProperties(schema: ASchema): void;
370
+
371
+ 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, createStandardSchemaProperty, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, hideInvalidProperties, 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 };