@arrirpc/schema 0.69.2 → 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/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.BcsXcrqv.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);
@@ -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);
@@ -1410,7 +1408,6 @@ function compile(schema) {
1410
1408
  };
1411
1409
  }
1412
1410
  },
1413
- // eslint-disable-next-line no-eval
1414
1411
  serialize(input) {
1415
1412
  try {
1416
1413
  return serializeFn(input);
@@ -1427,12 +1424,14 @@ function compile(schema) {
1427
1424
  validate: validateCode,
1428
1425
  parse: parser.code,
1429
1426
  serialize: serializer.code
1430
- }
1427
+ },
1428
+ "~standard": timestamp.createStandardSchemaProperty(validate, parse)
1431
1429
  };
1430
+ return result;
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) {
@@ -2135,7 +2134,7 @@ function isAdaptedSchema(input) {
2135
2134
  return input.metadata[timestamp.SCHEMA_METADATA]._isAdapted === true;
2136
2135
  }
2137
2136
  function validatorFromAdaptedSchema(schema) {
2138
- return {
2137
+ const result = {
2139
2138
  compiledCode: {
2140
2139
  parse: "",
2141
2140
  serialize: "",
@@ -2157,13 +2156,13 @@ function validatorFromAdaptedSchema(schema) {
2157
2156
  errors: []
2158
2157
  };
2159
2158
  try {
2160
- const result = schema.metadata[timestamp.SCHEMA_METADATA].parse(
2159
+ const result2 = schema.metadata[timestamp.SCHEMA_METADATA].parse(
2161
2160
  input,
2162
2161
  context
2163
2162
  );
2164
2163
  return {
2165
2164
  success: true,
2166
- value: result
2165
+ value: result2
2167
2166
  };
2168
2167
  } catch (err) {
2169
2168
  if (err instanceof timestamp.ValidationError) {
@@ -2188,24 +2187,32 @@ function validatorFromAdaptedSchema(schema) {
2188
2187
  errors: []
2189
2188
  };
2190
2189
  return schema.metadata[timestamp.SCHEMA_METADATA].serialize(input, context);
2191
- }
2190
+ },
2191
+ "~standard": timestamp.createStandardSchemaProperty(
2192
+ schema.metadata[timestamp.SCHEMA_METADATA].validate,
2193
+ schema.metadata[timestamp.SCHEMA_METADATA].parse
2194
+ )
2192
2195
  };
2196
+ return result;
2193
2197
  }
2194
2198
 
2195
2199
  exports.NumberTypeValues = timestamp.NumberTypeValues;
2196
2200
  exports.SCHEMA_METADATA = timestamp.SCHEMA_METADATA;
2201
+ exports.STR_ESCAPE = timestamp.STR_ESCAPE;
2197
2202
  exports.ValidationError = timestamp.ValidationError;
2198
2203
  exports.any = timestamp.any;
2199
2204
  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;
@@ -2245,6 +2252,7 @@ exports.sanitizeJson = timestamp.sanitizeJson;
2245
2252
  exports.serialize = timestamp.serialize;
2246
2253
  exports.serializeObject = timestamp.serializeObject;
2247
2254
  exports.serializeSmallString = timestamp.serializeSmallString;
2255
+ exports.serializeString = timestamp.serializeString;
2248
2256
  exports.string = timestamp.string;
2249
2257
  exports.stringEnum = timestamp.stringEnum;
2250
2258
  exports.timestamp = timestamp.timestamp;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
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 { 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';
4
+ import { Schema } from '@arrirpc/type-defs';
4
5
 
5
6
  declare function createParsingTemplate(input: string, schema: Schema): string;
6
7
 
@@ -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,9 @@ 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>;
290
+ declare function serializeString(input: string): string;
291
+ declare const STR_ESCAPE: RegExp;
289
292
  declare function serializeSmallString(input: string): string;
290
293
 
291
294
  /**
@@ -295,7 +298,7 @@ declare function serializeSmallString(input: string): string;
295
298
  * const Schema = a.timestamp();
296
299
  * a.validate(Schema, new Date()) // true
297
300
  */
298
- declare function timestamp(opts?: ASchemaOptions): AScalarSchema<"timestamp", Date>;
301
+ declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
299
302
 
300
303
  declare const _namespace_any: typeof any;
301
304
  declare const _namespace_array: typeof array;
@@ -359,4 +362,10 @@ declare const int64Max: bigint;
359
362
  declare const uint64Min: bigint;
360
363
  declare const uint64Max: bigint;
361
364
 
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 };
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,6 +1,7 @@
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 { 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';
4
+ import { Schema } from '@arrirpc/type-defs';
4
5
 
5
6
  declare function createParsingTemplate(input: string, schema: Schema): string;
6
7
 
@@ -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,9 @@ 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>;
290
+ declare function serializeString(input: string): string;
291
+ declare const STR_ESCAPE: RegExp;
289
292
  declare function serializeSmallString(input: string): string;
290
293
 
291
294
  /**
@@ -295,7 +298,7 @@ declare function serializeSmallString(input: string): string;
295
298
  * const Schema = a.timestamp();
296
299
  * a.validate(Schema, new Date()) // true
297
300
  */
298
- declare function timestamp(opts?: ASchemaOptions): AScalarSchema<"timestamp", Date>;
301
+ declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
299
302
 
300
303
  declare const _namespace_any: typeof any;
301
304
  declare const _namespace_array: typeof array;
@@ -359,4 +362,10 @@ declare const int64Max: bigint;
359
362
  declare const uint64Min: bigint;
360
363
  declare const uint64Max: bigint;
361
364
 
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 };
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,6 +1,7 @@
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 { 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';
4
+ import { Schema } from '@arrirpc/type-defs';
4
5
 
5
6
  declare function createParsingTemplate(input: string, schema: Schema): string;
6
7
 
@@ -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,9 @@ 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>;
290
+ declare function serializeString(input: string): string;
291
+ declare const STR_ESCAPE: RegExp;
289
292
  declare function serializeSmallString(input: string): string;
290
293
 
291
294
  /**
@@ -295,7 +298,7 @@ declare function serializeSmallString(input: string): string;
295
298
  * const Schema = a.timestamp();
296
299
  * a.validate(Schema, new Date()) // true
297
300
  */
298
- declare function timestamp(opts?: ASchemaOptions): AScalarSchema<"timestamp", Date>;
301
+ declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
299
302
 
300
303
  declare const _namespace_any: typeof any;
301
304
  declare const _namespace_array: typeof array;
@@ -359,4 +362,10 @@ declare const int64Max: bigint;
359
362
  declare const uint64Min: bigint;
360
363
  declare const uint64Max: bigint;
361
364
 
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 };
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 };