@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.
@@ -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,45 +48,91 @@ 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
- function any(options = {}) {
72
+ function createStandardSchemaProperty(validate, parse) {
75
73
  return {
74
+ version: 1,
75
+ vendor: "arri",
76
+ validate(input) {
77
+ if (validate(input)) {
78
+ return {
79
+ value: input
80
+ };
81
+ }
82
+ const ctx = {
83
+ instancePath: "",
84
+ schemaPath: "",
85
+ errors: []
86
+ };
87
+ try {
88
+ const result = parse(input, ctx);
89
+ if (!result || ctx.errors.length) {
90
+ return {
91
+ issues: ctx.errors.map((err) => ({
92
+ message: err.message ?? "Unknown error",
93
+ path: err.instancePath.split("/").filter((val) => val.length > 0)
94
+ }))
95
+ };
96
+ }
97
+ return {
98
+ value: result
99
+ };
100
+ } catch (err) {
101
+ return {
102
+ issues: [
103
+ {
104
+ message: err instanceof Error ? err.message : `${err}`
105
+ }
106
+ ]
107
+ };
108
+ }
109
+ }
110
+ };
111
+ }
112
+ function hideInvalidProperties(schema) {
113
+ Object.defineProperty(schema, "~standard", { enumerable: false });
114
+ }
115
+
116
+ function any(options = {}) {
117
+ const validate = (input) => true;
118
+ const parse = (input, context) => {
119
+ if (context.instancePath.length === 0 && typeof input === "string") {
120
+ try {
121
+ return JSON.parse(input);
122
+ } catch {
123
+ return input;
124
+ }
125
+ }
126
+ return input;
127
+ };
128
+ const result = {
76
129
  metadata: {
77
130
  id: options.id,
78
131
  description: options.description,
79
132
  isDeprecated: options.isDeprecated,
80
133
  [SCHEMA_METADATA]: {
81
- output: void 0,
82
- parse: (input, context) => {
83
- if (context.instancePath.length === 0 && typeof input === "string") {
84
- try {
85
- return JSON.parse(input);
86
- } catch {
87
- return input;
88
- }
89
- }
90
- return input;
91
- },
134
+ output: undefined,
135
+ parse,
92
136
  coerce: (input, context) => {
93
137
  if (context.instancePath.length === 0 && typeof input === "string") {
94
138
  try {
@@ -99,17 +143,26 @@ function any(options = {}) {
99
143
  }
100
144
  return input;
101
145
  },
102
- validate: (input) => true,
146
+ validate,
103
147
  serialize(input) {
104
148
  return JSON.stringify(input);
105
149
  }
106
150
  }
107
- }
151
+ },
152
+ "~standard": createStandardSchemaProperty(validate, parse)
108
153
  };
154
+ hideInvalidProperties(result);
155
+ return result;
109
156
  }
110
157
 
111
158
  function array(schema, opts = {}) {
112
- return {
159
+ const validateType = (input) => {
160
+ return validate$5(schema, input);
161
+ };
162
+ const parseType = (input, context) => {
163
+ return parse$6(schema, input, context, false);
164
+ };
165
+ const result = {
113
166
  elements: schema,
114
167
  metadata: {
115
168
  id: opts.id,
@@ -117,15 +170,11 @@ function array(schema, opts = {}) {
117
170
  isDeprecated: opts.isDeprecated,
118
171
  [SCHEMA_METADATA]: {
119
172
  output: [],
120
- parse(input, context) {
121
- return parse$6(schema, input, context, false);
122
- },
173
+ parse: parseType,
123
174
  coerce(input, context) {
124
175
  return parse$6(schema, input, context, true);
125
176
  },
126
- validate(input) {
127
- return validate$5(schema, input);
128
- },
177
+ validate: validateType,
129
178
  serialize(input, context) {
130
179
  const strParts = [];
131
180
  for (let i = 0; i < input.length; i++) {
@@ -141,8 +190,11 @@ function array(schema, opts = {}) {
141
190
  return `[${strParts.join(",")}]`;
142
191
  }
143
192
  }
144
- }
193
+ },
194
+ "~standard": createStandardSchemaProperty(validateType, parseType)
145
195
  };
196
+ hideInvalidProperties(result);
197
+ return result;
146
198
  }
147
199
  function validate$5(innerSchema, input) {
148
200
  if (!Array.isArray(input)) {
@@ -167,7 +219,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
167
219
  schemaPath: `${data.schemaPath}/elements`,
168
220
  message: `Error at ${data.instancePath}. Invalid JSON.`
169
221
  });
170
- return void 0;
222
+ return undefined;
171
223
  }
172
224
  }
173
225
  if (!Array.isArray(parsedInput)) {
@@ -176,7 +228,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
176
228
  schemaPath: `${data.schemaPath}/elements`,
177
229
  message: `Error at ${data.instancePath}. Expected array. Got ${typeof input}.`
178
230
  });
179
- return void 0;
231
+ return undefined;
180
232
  }
181
233
  const result = [];
182
234
  for (let i = 0; i < parsedInput.length; i++) {
@@ -204,13 +256,13 @@ function parse$6(innerSchema, input, data, coerce = false) {
204
256
  }
205
257
  }
206
258
  if (data.errors.length) {
207
- return void 0;
259
+ return undefined;
208
260
  }
209
261
  return result;
210
262
  }
211
263
 
212
264
  function boolean(opts = {}) {
213
- return {
265
+ const result = {
214
266
  type: "boolean",
215
267
  metadata: {
216
268
  id: opts.id,
@@ -242,11 +294,14 @@ function boolean(opts = {}) {
242
294
  schemaPath: context.schemaPath,
243
295
  message: `Error at ${context.instancePath}. Unable to coerce ${input} to boolean.`
244
296
  });
245
- return void 0;
297
+ return undefined;
246
298
  }
247
299
  }
248
- }
300
+ },
301
+ "~standard": createStandardSchemaProperty(validate$4, parse$5)
249
302
  };
303
+ hideInvalidProperties(result);
304
+ return result;
250
305
  }
251
306
  function validate$4(input) {
252
307
  return typeof input === "boolean";
@@ -267,25 +322,19 @@ function parse$5(input, data) {
267
322
  schemaPath: `${data.schemaPath}/type`,
268
323
  message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
269
324
  });
270
- return void 0;
325
+ return undefined;
271
326
  }
272
327
  data.errors.push({
273
328
  instancePath: data.instancePath,
274
329
  schemaPath: `${data.schemaPath}/type`,
275
330
  message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
276
331
  });
277
- return void 0;
332
+ return undefined;
278
333
  }
279
334
  function serialize$2(input) {
280
335
  return `${input}`;
281
336
  }
282
337
 
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
338
  function sanitizeJson(json) {
290
339
  return json.replace(/[\b]/g, "\\b").replace(/[\f]/g, "\\f").replace(/[\n]/g, "\\n").replace(/[\r]/g, "\\r").replace(/[\t]/g, "\\t");
291
340
  }
@@ -390,9 +439,9 @@ function errors(schema, input) {
390
439
  return errorList;
391
440
  }
392
441
  class ValidationError extends Error {
442
+ errors;
393
443
  constructor(options) {
394
444
  super(options.message);
395
- __publicField(this, "errors");
396
445
  this.errors = options.errors;
397
446
  }
398
447
  }
@@ -411,7 +460,13 @@ function discriminator(propA, propB, propC) {
411
460
  if (isIdShorthand) {
412
461
  opts.id = propA;
413
462
  }
414
- return {
463
+ const isType = (input) => {
464
+ return validate$2(discriminator2, mapping, input);
465
+ };
466
+ const parseType = (input, context) => {
467
+ return parse$3(discriminator2, mapping, input, context, false);
468
+ };
469
+ const result = {
415
470
  discriminator: discriminator2,
416
471
  mapping,
417
472
  metadata: {
@@ -420,12 +475,8 @@ function discriminator(propA, propB, propC) {
420
475
  isDeprecated: opts.isDeprecated,
421
476
  [SCHEMA_METADATA]: {
422
477
  output: {},
423
- validate(input) {
424
- return validate$2(discriminator2, mapping, input);
425
- },
426
- parse(input, context) {
427
- return parse$3(discriminator2, mapping, input, context, false);
428
- },
478
+ validate: isType,
479
+ parse: parseType,
429
480
  coerce: (input, context) => {
430
481
  return parse$3(discriminator2, mapping, input, context, true);
431
482
  },
@@ -438,18 +489,21 @@ function discriminator(propA, propB, propC) {
438
489
  context
439
490
  );
440
491
  }
441
- const result = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
492
+ const result2 = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
442
493
  instancePath: context.instancePath,
443
494
  schemaPath: `${context.schemaPath}/mapping/${discriminatorVal}`,
444
495
  errors: context.errors,
445
496
  discriminatorKey: discriminator2,
446
497
  discriminatorValue: discriminatorVal
447
498
  });
448
- return result;
499
+ return result2;
449
500
  }
450
501
  }
451
- }
502
+ },
503
+ "~standard": createStandardSchemaProperty(isType, parseType)
452
504
  };
505
+ hideInvalidProperties(result);
506
+ return result;
453
507
  }
454
508
  function validate$2(discriminator2, mapping, input) {
455
509
  if (!isObject(input)) {
@@ -479,7 +533,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
479
533
  schemaPath: `${data.schemaPath}/discriminator`,
480
534
  message: `Error at ${data.instancePath}. Expected object. Got ${typeof parsedInput}.`
481
535
  });
482
- return void 0;
536
+ return undefined;
483
537
  }
484
538
  if (!(discriminator2 in parsedInput)) {
485
539
  data.errors.push({
@@ -487,7 +541,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
487
541
  schemaPath: `${data.schemaPath}/discriminator`,
488
542
  message: `Error at ${data.instancePath}/${discriminator2}. Discriminator field "${discriminator2}" cannot be undefined`
489
543
  });
490
- return void 0;
544
+ return undefined;
491
545
  }
492
546
  const acceptedDiscriminatorVals = Object.keys(mapping);
493
547
  const discriminatorVal = parsedInput[discriminator2];
@@ -499,7 +553,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
499
553
  ", "
500
554
  )}]`
501
555
  });
502
- return void 0;
556
+ return undefined;
503
557
  }
504
558
  const targetSchema = mapping[parsedInput[discriminator2]];
505
559
  if (!targetSchema) {
@@ -556,7 +610,20 @@ function enumerator(paramA, paramB) {
556
610
  }
557
611
  return false;
558
612
  };
559
- return {
613
+ const parse = (input, context) => {
614
+ if (isType(input)) {
615
+ return input;
616
+ }
617
+ context.errors.push({
618
+ instancePath: context.instancePath,
619
+ schemaPath: `${context.schemaPath}/enum`,
620
+ message: `Error at ${context.instancePath}. Invalid enum value. Expected one of the following values: [${enumVal.join(
621
+ ", "
622
+ )}]`
623
+ });
624
+ return undefined;
625
+ };
626
+ const result = {
560
627
  enum: enumVal,
561
628
  metadata: {
562
629
  id: meta?.id,
@@ -564,19 +631,7 @@ function enumerator(paramA, paramB) {
564
631
  isDeprecated: meta?.isDeprecated,
565
632
  [SCHEMA_METADATA]: {
566
633
  output: paramA[0] ?? "",
567
- parse(input, context) {
568
- if (isType(input)) {
569
- return input;
570
- }
571
- context.errors.push({
572
- instancePath: context.instancePath,
573
- schemaPath: `${context.schemaPath}/enum`,
574
- message: `Error at ${context.instancePath}. Invalid enum value. Expected one of the following values: [${enumVal.join(
575
- ", "
576
- )}]`
577
- });
578
- return void 0;
579
- },
634
+ parse,
580
635
  coerce: (input, context) => {
581
636
  if (isType(input)) {
582
637
  return input;
@@ -588,7 +643,7 @@ function enumerator(paramA, paramB) {
588
643
  ", "
589
644
  )}]`
590
645
  });
591
- return void 0;
646
+ return undefined;
592
647
  },
593
648
  validate: isType,
594
649
  serialize(input, context) {
@@ -598,8 +653,11 @@ function enumerator(paramA, paramB) {
598
653
  return `"${input}"`;
599
654
  }
600
655
  }
601
- }
656
+ },
657
+ "~standard": createStandardSchemaProperty(isType, parse)
602
658
  };
659
+ hideInvalidProperties(result);
660
+ return result;
603
661
  }
604
662
 
605
663
  function nullable(schema, opts = {}) {
@@ -609,7 +667,16 @@ function nullable(schema, opts = {}) {
609
667
  }
610
668
  return schema.metadata[SCHEMA_METADATA].validate(val);
611
669
  };
612
- return {
670
+ const parse = (val, data) => {
671
+ if (data.instancePath.length === 0 && typeof val === "string" && val === "null") {
672
+ return null;
673
+ }
674
+ if (val === null) {
675
+ return null;
676
+ }
677
+ return schema.metadata[SCHEMA_METADATA].parse(val, data);
678
+ };
679
+ const result = {
613
680
  ...schema,
614
681
  nullable: true,
615
682
  metadata: {
@@ -620,15 +687,7 @@ function nullable(schema, opts = {}) {
620
687
  output: null,
621
688
  optional: schema.metadata[SCHEMA_METADATA].optional,
622
689
  validate: isType,
623
- parse(val, data) {
624
- if (data.instancePath.length === 0 && typeof val === "string" && val === "null") {
625
- return null;
626
- }
627
- if (val === null) {
628
- return null;
629
- }
630
- return schema.metadata[SCHEMA_METADATA].parse(val, data);
631
- },
690
+ parse,
632
691
  coerce(val, data) {
633
692
  if (val === null) {
634
693
  return null;
@@ -650,39 +709,42 @@ function nullable(schema, opts = {}) {
650
709
  }
651
710
  }
652
711
  };
712
+ hideInvalidProperties(result);
713
+ return result;
653
714
  }
654
715
  function optional(input, opts = {}) {
655
716
  const isType = (val) => {
656
- if (val === void 0) {
717
+ if (val === undefined) {
657
718
  return true;
658
719
  }
659
720
  return input.metadata[SCHEMA_METADATA].validate(val);
660
721
  };
661
- return {
722
+ const parse = (val, context) => {
723
+ if (typeof val === "undefined") {
724
+ return undefined;
725
+ }
726
+ if (context.instancePath.length === 0 && val === "undefined") {
727
+ return undefined;
728
+ }
729
+ return input.metadata[SCHEMA_METADATA].parse(val, context);
730
+ };
731
+ const result = {
662
732
  ...input,
663
733
  metadata: {
664
734
  id: opts.id ?? input.metadata.id,
665
735
  description: opts.description ?? input.metadata.description,
666
736
  isDeprecated: opts.isDeprecated ?? input.metadata.isDeprecated,
667
737
  [SCHEMA_METADATA]: {
668
- output: void 0,
738
+ output: undefined,
669
739
  optional: true,
670
740
  validate: isType,
671
- parse: (val, data) => {
672
- if (typeof val === "undefined") {
673
- return void 0;
674
- }
675
- if (data.instancePath.length === 0 && val === "undefined") {
676
- return void 0;
677
- }
678
- return input.metadata[SCHEMA_METADATA].parse(val, data);
679
- },
741
+ parse,
680
742
  coerce: (val, data) => {
681
743
  if (typeof val === "undefined") {
682
- return void 0;
744
+ return undefined;
683
745
  }
684
746
  if (val === "undefined") {
685
- return void 0;
747
+ return undefined;
686
748
  }
687
749
  return input.metadata[SCHEMA_METADATA].coerce(val, data);
688
750
  },
@@ -693,8 +755,11 @@ function optional(input, opts = {}) {
693
755
  return input.metadata[SCHEMA_METADATA].serialize(val, data);
694
756
  }
695
757
  }
696
- }
758
+ },
759
+ "~standard": createStandardSchemaProperty(isType, parse)
697
760
  };
761
+ hideInvalidProperties(result);
762
+ return result;
698
763
  }
699
764
  function clone(input, opts = {}) {
700
765
  const schema = {
@@ -706,8 +771,10 @@ function clone(input, opts = {}) {
706
771
  [SCHEMA_METADATA]: {
707
772
  ...input.metadata[SCHEMA_METADATA]
708
773
  }
709
- }
774
+ },
775
+ "~standard": input["~standard"]
710
776
  };
777
+ hideInvalidProperties(schema);
711
778
  return schema;
712
779
  }
713
780
 
@@ -723,7 +790,7 @@ function coerceNumber(input, options) {
723
790
  schemaPath: `${options.schemaPath}/type`,
724
791
  message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} into a number`
725
792
  });
726
- return void 0;
793
+ return undefined;
727
794
  }
728
795
  return parseNumber(parsedInput, options);
729
796
  }
@@ -848,7 +915,7 @@ function int64(opts = {}) {
848
915
  schemaPath: `${data.schemaPath}/type`,
849
916
  instancePath: data.instancePath
850
917
  });
851
- return void 0;
918
+ return undefined;
852
919
  }
853
920
  }
854
921
  if (isType(input)) {
@@ -859,9 +926,9 @@ function int64(opts = {}) {
859
926
  schemaPath: `${data.schemaPath}/type`,
860
927
  instancePath: data.instancePath
861
928
  });
862
- return void 0;
929
+ return undefined;
863
930
  }
864
- return {
931
+ const result = {
865
932
  type: "int64",
866
933
  metadata: {
867
934
  id: opts.id,
@@ -879,8 +946,11 @@ function int64(opts = {}) {
879
946
  return `"${input.toString()}"`;
880
947
  }
881
948
  }
882
- }
949
+ },
950
+ "~standard": createStandardSchemaProperty(isType, parse)
883
951
  };
952
+ hideInvalidProperties(result);
953
+ return result;
884
954
  }
885
955
  function uint64(opts = {}) {
886
956
  function isType(input) {
@@ -905,7 +975,7 @@ function uint64(opts = {}) {
905
975
  schemaPath: `${data.schemaPath}/type`,
906
976
  instancePath: data.instancePath
907
977
  });
908
- return void 0;
978
+ return undefined;
909
979
  }
910
980
  }
911
981
  if (isType(input)) {
@@ -916,9 +986,9 @@ function uint64(opts = {}) {
916
986
  schemaPath: `${data.schemaPath}/type`,
917
987
  instancePath: data.instancePath
918
988
  });
919
- return void 0;
989
+ return undefined;
920
990
  }
921
- return {
991
+ const result = {
922
992
  type: "uint64",
923
993
  metadata: {
924
994
  id: opts.id,
@@ -936,11 +1006,14 @@ function uint64(opts = {}) {
936
1006
  return `"${input.toString()}"`;
937
1007
  }
938
1008
  }
939
- }
1009
+ },
1010
+ "~standard": createStandardSchemaProperty(isType, parse)
940
1011
  };
1012
+ hideInvalidProperties(result);
1013
+ return result;
941
1014
  }
942
1015
  function validateNumber(input) {
943
- return typeof input === "number" || !Number.isNaN(input);
1016
+ return typeof input === "number";
944
1017
  }
945
1018
  function validateInt(input, minVal, maxValue) {
946
1019
  return Number.isInteger(input) && input >= minVal && input <= maxValue;
@@ -957,7 +1030,7 @@ function parseNumber(input, options) {
957
1030
  schemaPath: `${options.schemaPath}/type`,
958
1031
  message: `Error at ${options.instancePath}. Invalid number.`
959
1032
  });
960
- return void 0;
1033
+ return undefined;
961
1034
  }
962
1035
  return result;
963
1036
  }
@@ -969,10 +1042,41 @@ function parseNumber(input, options) {
969
1042
  schemaPath: `${options.schemaPath}/type`,
970
1043
  message: `Error at ${options.instancePath}. Invalid number.`
971
1044
  });
972
- return void 0;
1045
+ return undefined;
973
1046
  }
974
1047
  function numberScalarType(type, opts, numTypeMatcher) {
975
- return {
1048
+ const validate = (input) => {
1049
+ const isNum = validateNumber(input);
1050
+ if (!isNum) {
1051
+ return false;
1052
+ }
1053
+ return numTypeMatcher(input).success;
1054
+ };
1055
+ const parse = (input, context) => {
1056
+ const result2 = parseNumber(input, context);
1057
+ if (context.errors.length) {
1058
+ return undefined;
1059
+ }
1060
+ if (typeof result2 !== "number") {
1061
+ context?.errors.push({
1062
+ instancePath: context.instancePath,
1063
+ schemaPath: `${context.schemaPath}/type`,
1064
+ message: `Error at ${context.instancePath}. Invalid number.`
1065
+ });
1066
+ return undefined;
1067
+ }
1068
+ const matchResult = numTypeMatcher(result2);
1069
+ if (matchResult.success) {
1070
+ return result2;
1071
+ }
1072
+ context?.errors.push({
1073
+ instancePath: context.instancePath,
1074
+ schemaPath: `${context.schemaPath}/type`,
1075
+ message: `Error at ${context.instancePath}. ${matchResult.message}`
1076
+ });
1077
+ return undefined;
1078
+ };
1079
+ const result = {
976
1080
  type,
977
1081
  metadata: {
978
1082
  id: opts.id,
@@ -980,62 +1084,36 @@ function numberScalarType(type, opts, numTypeMatcher) {
980
1084
  isDeprecated: opts.isDeprecated,
981
1085
  [SCHEMA_METADATA]: {
982
1086
  output: 0,
983
- validate(input) {
984
- const isNum = validateNumber(input);
985
- if (!isNum) {
986
- return false;
987
- }
988
- return numTypeMatcher(input).success;
989
- },
990
- parse(input, options) {
991
- const result = parseNumber(input, options);
992
- if (options.errors.length) {
993
- return void 0;
994
- }
995
- if (typeof result !== "number") {
996
- options?.errors.push({
997
- instancePath: options.instancePath,
998
- schemaPath: `${options.schemaPath}/type`,
999
- message: `Error at ${options.instancePath}. Invalid number.`
1000
- });
1001
- return void 0;
1002
- }
1003
- const matchResult = numTypeMatcher(result);
1004
- if (matchResult.success) {
1005
- return result;
1006
- }
1007
- options?.errors.push({
1008
- instancePath: options.instancePath,
1009
- schemaPath: `${options.schemaPath}/type`,
1010
- message: `Error at ${options.instancePath}. ${matchResult.message}`
1011
- });
1012
- return void 0;
1013
- },
1087
+ validate,
1088
+ parse,
1014
1089
  serialize: serializeNumber,
1015
1090
  coerce(input, options) {
1016
- const result = coerceNumber(input, options);
1017
- if (typeof result !== "number") {
1091
+ const result2 = coerceNumber(input, options);
1092
+ if (typeof result2 !== "number") {
1018
1093
  options.errors.push({
1019
1094
  instancePath: options.instancePath,
1020
1095
  schemaPath: `${options.schemaPath}/type`,
1021
1096
  message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} to ${type}.`
1022
1097
  });
1023
- return void 0;
1098
+ return undefined;
1024
1099
  }
1025
- const matchResult = numTypeMatcher(result);
1100
+ const matchResult = numTypeMatcher(result2);
1026
1101
  if (matchResult.success) {
1027
- return result;
1102
+ return result2;
1028
1103
  }
1029
1104
  options.errors.push({
1030
1105
  instancePath: options.instancePath,
1031
1106
  schemaPath: `${options.schemaPath}/type`,
1032
1107
  message: `Error at ${options.instancePath}. ${matchResult.message}`
1033
1108
  });
1034
- return void 0;
1109
+ return undefined;
1035
1110
  }
1036
1111
  }
1037
- }
1112
+ },
1113
+ "~standard": createStandardSchemaProperty(validate, parse)
1038
1114
  };
1115
+ hideInvalidProperties(result);
1116
+ return result;
1039
1117
  }
1040
1118
 
1041
1119
  function object(propA, propB) {
@@ -1059,6 +1137,17 @@ function object(propA, propB) {
1059
1137
  }
1060
1138
  schema.properties[key] = prop;
1061
1139
  }
1140
+ const validate = (input2) => {
1141
+ return validateObjectSchema(schema, input2);
1142
+ };
1143
+ const parse = (input2, context) => {
1144
+ return parseObjectSchema(
1145
+ schema,
1146
+ input2,
1147
+ context,
1148
+ false
1149
+ );
1150
+ };
1062
1151
  const result = {
1063
1152
  ...schema,
1064
1153
  metadata: {
@@ -1067,14 +1156,7 @@ function object(propA, propB) {
1067
1156
  isDeprecated: options.isDeprecated,
1068
1157
  [SCHEMA_METADATA]: {
1069
1158
  output: {},
1070
- parse(input2, context) {
1071
- return parseObjectSchema(
1072
- schema,
1073
- input2,
1074
- context,
1075
- false
1076
- );
1077
- },
1159
+ parse,
1078
1160
  coerce(input2, context) {
1079
1161
  return parseObjectSchema(
1080
1162
  schema,
@@ -1083,9 +1165,7 @@ function object(propA, propB) {
1083
1165
  true
1084
1166
  );
1085
1167
  },
1086
- validate(input2) {
1087
- return validateObjectSchema(schema, input2);
1088
- },
1168
+ validate,
1089
1169
  serialize(input2, context) {
1090
1170
  return serializeObject(
1091
1171
  schema,
@@ -1094,8 +1174,10 @@ function object(propA, propB) {
1094
1174
  );
1095
1175
  }
1096
1176
  }
1097
- }
1177
+ },
1178
+ "~standard": createStandardSchemaProperty(validate, parse)
1098
1179
  };
1180
+ hideInvalidProperties(result);
1099
1181
  return result;
1100
1182
  }
1101
1183
  function parseObjectSchema(schema, input, data, coerce = false) {
@@ -1110,7 +1192,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1110
1192
  schemaPath: `${data.schemaPath}/properties`,
1111
1193
  message: `Error at ${data.instancePath}. Invalid JSON.`
1112
1194
  });
1113
- return void 0;
1195
+ return undefined;
1114
1196
  }
1115
1197
  }
1116
1198
  if (!isObject(parsedInput)) {
@@ -1119,7 +1201,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1119
1201
  schemaPath: `${data.schemaPath}/properties`,
1120
1202
  message: `Error at ${data.instancePath}. Expected object`
1121
1203
  });
1122
- return void 0;
1204
+ return undefined;
1123
1205
  }
1124
1206
  const result = {};
1125
1207
  const optionalProps = schema.optionalProperties ?? {};
@@ -1138,7 +1220,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1138
1220
  }
1139
1221
  }
1140
1222
  if (data.errors.length) {
1141
- return void 0;
1223
+ return undefined;
1142
1224
  }
1143
1225
  if (data.discriminatorKey) {
1144
1226
  result[data.discriminatorKey] = data.discriminatorValue;
@@ -1163,7 +1245,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1163
1245
  for (const key of optionalKeys) {
1164
1246
  const val = parsedInput[key];
1165
1247
  const prop = optionalProps[key];
1166
- if (val === void 0) {
1248
+ if (val === undefined) {
1167
1249
  continue;
1168
1250
  }
1169
1251
  if (coerce) {
@@ -1183,7 +1265,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1183
1265
  }
1184
1266
  }
1185
1267
  if (data.errors.length) {
1186
- return void 0;
1268
+ return undefined;
1187
1269
  }
1188
1270
  return result;
1189
1271
  }
@@ -1191,17 +1273,28 @@ function validateObjectSchema(schema, input) {
1191
1273
  if (!isObject(input)) {
1192
1274
  return false;
1193
1275
  }
1194
- const optionalProps = schema.optionalProperties ?? {};
1195
- for (const key of Object.keys(input)) {
1196
- const prop = schema.properties[key] ?? optionalProps[key];
1197
- if (!prop && schema.strict) {
1198
- return false;
1276
+ const allowedKeys = schema.strict ? [] : undefined;
1277
+ for (const key of Object.keys(schema.properties)) {
1278
+ const propSchema = schema.properties[key];
1279
+ const isValid = propSchema.metadata[SCHEMA_METADATA].validate(
1280
+ input[key]
1281
+ );
1282
+ if (!isValid) return false;
1283
+ allowedKeys?.push(key);
1284
+ }
1285
+ if (schema.optionalProperties) {
1286
+ for (const key of Object.keys(schema.optionalProperties)) {
1287
+ const propsSchema = schema.optionalProperties[key];
1288
+ const isValid = propsSchema.metadata[SCHEMA_METADATA].validate(
1289
+ input[key]
1290
+ );
1291
+ if (!isValid) return false;
1292
+ allowedKeys?.push(key);
1199
1293
  }
1200
- if (prop) {
1201
- const isValid = prop.metadata[SCHEMA_METADATA].validate(input[key]);
1202
- if (!isValid) {
1203
- return false;
1204
- }
1294
+ }
1295
+ if (allowedKeys) {
1296
+ for (const key of Object.keys(input)) {
1297
+ if (!allowedKeys.includes(key)) return false;
1205
1298
  }
1206
1299
  }
1207
1300
  return true;
@@ -1233,7 +1326,13 @@ function pick(inputSchema, keys, options = {}) {
1233
1326
  }
1234
1327
  });
1235
1328
  }
1236
- return {
1329
+ const parse = (input, context) => {
1330
+ return parseObjectSchema(schema, input, context, false);
1331
+ };
1332
+ const validate = (input) => {
1333
+ return validateObjectSchema(schema, input);
1334
+ };
1335
+ const result = {
1237
1336
  ...schema,
1238
1337
  metadata: {
1239
1338
  id: options.id,
@@ -1241,14 +1340,7 @@ function pick(inputSchema, keys, options = {}) {
1241
1340
  isDeprecated: options.isDeprecated,
1242
1341
  [SCHEMA_METADATA]: {
1243
1342
  output: {},
1244
- parse: (input, context) => {
1245
- return parseObjectSchema(
1246
- schema,
1247
- input,
1248
- context,
1249
- true
1250
- );
1251
- },
1343
+ parse,
1252
1344
  coerce(input, context) {
1253
1345
  return parseObjectSchema(
1254
1346
  schema,
@@ -1257,15 +1349,16 @@ function pick(inputSchema, keys, options = {}) {
1257
1349
  false
1258
1350
  );
1259
1351
  },
1260
- validate(input) {
1261
- return validateObjectSchema(schema, input);
1262
- },
1352
+ validate,
1263
1353
  serialize(input, context) {
1264
1354
  return serializeObject(schema, input, context);
1265
1355
  }
1266
1356
  }
1267
- }
1357
+ },
1358
+ "~standard": createStandardSchemaProperty(validate, parse)
1268
1359
  };
1360
+ hideInvalidProperties(result);
1361
+ return result;
1269
1362
  }
1270
1363
  function omit(inputSchema, keys, options = {}) {
1271
1364
  const schema = {
@@ -1295,7 +1388,9 @@ function omit(inputSchema, keys, options = {}) {
1295
1388
  }
1296
1389
  });
1297
1390
  }
1298
- return {
1391
+ const validate = (input) => validateObjectSchema(schema, input);
1392
+ const parse = (input, context) => parseObjectSchema(schema, input, context, false);
1393
+ const result = {
1299
1394
  ...schema,
1300
1395
  metadata: {
1301
1396
  id: options.id,
@@ -1303,12 +1398,8 @@ function omit(inputSchema, keys, options = {}) {
1303
1398
  isDeprecated: options.isDeprecated,
1304
1399
  [SCHEMA_METADATA]: {
1305
1400
  output: {},
1306
- validate(input) {
1307
- return validateObjectSchema(schema, input);
1308
- },
1309
- parse(input, data) {
1310
- return parseObjectSchema(schema, input, data, false);
1311
- },
1401
+ validate,
1402
+ parse,
1312
1403
  serialize(input, context) {
1313
1404
  return serializeObject(schema, input, context);
1314
1405
  },
@@ -1321,8 +1412,11 @@ function omit(inputSchema, keys, options = {}) {
1321
1412
  );
1322
1413
  }
1323
1414
  }
1324
- }
1415
+ },
1416
+ "~standard": createStandardSchemaProperty(validate, parse)
1325
1417
  };
1418
+ hideInvalidProperties(result);
1419
+ return result;
1326
1420
  }
1327
1421
  function serializeObject(schema, input, data) {
1328
1422
  const strParts = [];
@@ -1419,23 +1513,20 @@ function partial(schema, options = {}) {
1419
1513
  }
1420
1514
  }
1421
1515
  }
1516
+ const validate = (input) => {
1517
+ return validateObjectSchema(newSchema, input);
1518
+ };
1519
+ const parse = (input, context) => {
1520
+ return parseObjectSchema(newSchema, input, context, false);
1521
+ };
1422
1522
  const meta = {
1423
1523
  id: options.id,
1424
1524
  description: options.description,
1425
1525
  [SCHEMA_METADATA]: {
1426
1526
  output: {},
1427
1527
  optional: schema.metadata[SCHEMA_METADATA].optional,
1428
- validate(input) {
1429
- return validateObjectSchema(newSchema, input);
1430
- },
1431
- parse(input, context) {
1432
- return parseObjectSchema(
1433
- newSchema,
1434
- input,
1435
- context,
1436
- false
1437
- );
1438
- },
1528
+ validate,
1529
+ parse,
1439
1530
  coerce(input, context) {
1440
1531
  return parseObjectSchema(
1441
1532
  newSchema,
@@ -1450,11 +1541,118 @@ function partial(schema, options = {}) {
1450
1541
  }
1451
1542
  };
1452
1543
  newSchema.metadata = meta;
1544
+ newSchema["~standard"] = createStandardSchemaProperty(
1545
+ validate,
1546
+ parse
1547
+ );
1548
+ hideInvalidProperties(newSchema);
1453
1549
  return newSchema;
1454
1550
  }
1455
1551
 
1552
+ function string(opts = {}) {
1553
+ const result = {
1554
+ type: "string",
1555
+ metadata: {
1556
+ id: opts.id,
1557
+ description: opts.description,
1558
+ isDeprecated: opts.isDeprecated,
1559
+ [SCHEMA_METADATA]: {
1560
+ output: "",
1561
+ parse: parse$2,
1562
+ coerce: coerce$1,
1563
+ validate: validate$1,
1564
+ serialize(input, context) {
1565
+ if (context.instancePath.length === 0) {
1566
+ return input;
1567
+ }
1568
+ if (input.length < 42) {
1569
+ return serializeSmallString(input);
1570
+ }
1571
+ if (input.length < 5e3 && !STR_ESCAPE.test(input)) {
1572
+ return `"${input}"`;
1573
+ }
1574
+ return JSON.stringify(input);
1575
+ }
1576
+ }
1577
+ },
1578
+ "~standard": createStandardSchemaProperty(validate$1, parse$2)
1579
+ };
1580
+ hideInvalidProperties(result);
1581
+ return result;
1582
+ }
1583
+ function serializeString(input) {
1584
+ if (input.length < 42) {
1585
+ return serializeSmallString(input);
1586
+ }
1587
+ if (input.length < 5e3 && !STR_ESCAPE.test(input)) {
1588
+ return `"${input}"`;
1589
+ }
1590
+ return JSON.stringify(input);
1591
+ }
1592
+ function validate$1(input) {
1593
+ return typeof input === "string";
1594
+ }
1595
+ function parse$2(input, context) {
1596
+ if (validate$1(input)) {
1597
+ return input;
1598
+ }
1599
+ context.errors.push({
1600
+ instancePath: context.instancePath,
1601
+ schemaPath: `${context.schemaPath}/type`,
1602
+ message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
1603
+ });
1604
+ return undefined;
1605
+ }
1606
+ function coerce$1(input, context) {
1607
+ return parse$2(input, context);
1608
+ }
1609
+ const STR_ESCAPE = (
1610
+ // eslint-disable-next-line no-control-regex
1611
+ /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/
1612
+ );
1613
+ function serializeSmallString(input) {
1614
+ const len = input.length;
1615
+ let result = "";
1616
+ let last = -1;
1617
+ let point = 255;
1618
+ for (let i = 0; i < len; i++) {
1619
+ point = input.charCodeAt(i);
1620
+ if (point < 32 || point >= 55296 && point <= 57343) {
1621
+ return JSON.stringify(input);
1622
+ }
1623
+ if (point === 34 || // '"'
1624
+ point === 92) {
1625
+ if (last === -1) {
1626
+ last = 0;
1627
+ }
1628
+ result += input.slice(last, i) + "\\";
1629
+ last = i;
1630
+ }
1631
+ }
1632
+ if (last === -1) {
1633
+ return `"${input}"`;
1634
+ }
1635
+ return `"${result}${input.slice(last)}"`;
1636
+ }
1637
+
1456
1638
  function record(schema, opts = {}) {
1457
- return {
1639
+ const validateFn = (input) => {
1640
+ if (!isObject(input)) {
1641
+ return false;
1642
+ }
1643
+ for (const key of Object.keys(input)) {
1644
+ const val = input[key];
1645
+ const isValid = schema.metadata[SCHEMA_METADATA].validate(val);
1646
+ if (!isValid) {
1647
+ return false;
1648
+ }
1649
+ }
1650
+ return true;
1651
+ };
1652
+ const parseFn = (input, ctx) => {
1653
+ return parse$1(schema, input, ctx, false);
1654
+ };
1655
+ const result = {
1458
1656
  values: schema,
1459
1657
  metadata: {
1460
1658
  id: opts.id,
@@ -1462,48 +1660,40 @@ function record(schema, opts = {}) {
1462
1660
  isDeprecated: opts.isDeprecated,
1463
1661
  [SCHEMA_METADATA]: {
1464
1662
  output: {},
1465
- validate(input) {
1466
- if (!isObject(input)) {
1467
- return false;
1468
- }
1469
- for (const key of Object.keys(input)) {
1470
- const val = input[key];
1471
- const isValid = schema.metadata[SCHEMA_METADATA].validate(val);
1472
- if (!isValid) {
1473
- return false;
1474
- }
1475
- }
1476
- return true;
1477
- },
1478
- parse(input, context) {
1479
- return parse$2(schema, input, context, false);
1480
- },
1663
+ validate: validateFn,
1664
+ parse: parseFn,
1481
1665
  coerce(input, data) {
1482
- return parse$2(schema, input, data, true);
1666
+ return parse$1(schema, input, data, true);
1483
1667
  },
1484
1668
  serialize(input, context) {
1485
- const strParts = [];
1486
- for (const key of Object.keys(input)) {
1669
+ let result2 = "{";
1670
+ const keys = Object.keys(input);
1671
+ for (let i = 0; i < keys.length; i++) {
1672
+ const key = keys[i];
1487
1673
  const val = input[key];
1488
- strParts.push(
1489
- `${JSON.stringify(key)}:${schema.metadata[SCHEMA_METADATA].serialize(val, {
1674
+ if (i > 0) result2 += ",";
1675
+ result2 += serializeString(key);
1676
+ result2 += ":";
1677
+ result2 += schema.metadata[SCHEMA_METADATA].serialize(
1678
+ val,
1679
+ {
1490
1680
  instancePath: `${context.instancePath}/${key}`,
1491
1681
  schemaPath: `${context.schemaPath}/values`,
1492
1682
  errors: context.errors
1493
- })}`
1683
+ }
1494
1684
  );
1495
1685
  }
1496
- const result = `{${strParts.join(",")}}`;
1497
- if (context.instancePath.length === 0) {
1498
- return sanitizeJson(result);
1499
- }
1500
- return result;
1686
+ result2 += "}";
1687
+ return result2;
1501
1688
  }
1502
1689
  }
1503
- }
1690
+ },
1691
+ "~standard": createStandardSchemaProperty(validateFn, parseFn)
1504
1692
  };
1693
+ hideInvalidProperties(result);
1694
+ return result;
1505
1695
  }
1506
- function parse$2(schema, input, data, coerce = false) {
1696
+ function parse$1(schema, input, data, coerce = false) {
1507
1697
  let parsedInput = input;
1508
1698
  if (data.instancePath.length === 0 && typeof input === "string") {
1509
1699
  parsedInput = JSON.parse(input);
@@ -1514,7 +1704,7 @@ function parse$2(schema, input, data, coerce = false) {
1514
1704
  schemaPath: `${data.schemaPath}/values`,
1515
1705
  message: `Error at ${data.instancePath} Expected object`
1516
1706
  });
1517
- return void 0;
1707
+ return undefined;
1518
1708
  }
1519
1709
  const result = {};
1520
1710
  for (const key of Object.keys(parsedInput)) {
@@ -1534,7 +1724,7 @@ function parse$2(schema, input, data, coerce = false) {
1534
1724
  }
1535
1725
  }
1536
1726
  if (data.errors.length) {
1537
- return void 0;
1727
+ return undefined;
1538
1728
  }
1539
1729
  return result;
1540
1730
  }
@@ -1552,36 +1742,43 @@ function recursive(propA, propB) {
1552
1742
  );
1553
1743
  }
1554
1744
  const id = options.id ?? `TypeRef${recursiveTypeCount}`;
1555
- const mainSchema = callback({
1556
- ref: id,
1557
- metadata: {
1558
- [SCHEMA_METADATA]: {
1559
- output: "",
1560
- parse(input, context) {
1561
- if (recursiveFns[id]) {
1562
- return recursiveFns[id].parse(input, context);
1563
- }
1564
- },
1565
- serialize(input, context) {
1566
- if (recursiveFns[id]) {
1567
- return recursiveFns[id].serialize(input, context);
1568
- }
1569
- return "";
1570
- },
1571
- validate(input) {
1572
- if (recursiveFns[id]) {
1573
- return recursiveFns[id].validate(input);
1574
- }
1575
- return false;
1576
- },
1577
- coerce(input, context) {
1578
- if (recursiveFns[id]) {
1579
- return recursiveFns[id].coerce(input, context);
1580
- }
1745
+ const metadata = {
1746
+ [SCHEMA_METADATA]: {
1747
+ output: "",
1748
+ parse(input, context) {
1749
+ if (recursiveFns[id]) {
1750
+ return recursiveFns[id].parse(input, context);
1751
+ }
1752
+ },
1753
+ serialize(input, context) {
1754
+ if (recursiveFns[id]) {
1755
+ return recursiveFns[id].serialize(input, context);
1756
+ }
1757
+ return "";
1758
+ },
1759
+ validate(input) {
1760
+ if (recursiveFns[id]) {
1761
+ return recursiveFns[id].validate(input);
1762
+ }
1763
+ return false;
1764
+ },
1765
+ coerce(input, context) {
1766
+ if (recursiveFns[id]) {
1767
+ return recursiveFns[id].coerce(input, context);
1581
1768
  }
1582
1769
  }
1583
1770
  }
1584
- });
1771
+ };
1772
+ const schema = {
1773
+ ref: id,
1774
+ metadata,
1775
+ "~standard": createStandardSchemaProperty(
1776
+ metadata[SCHEMA_METADATA].validate,
1777
+ metadata[SCHEMA_METADATA].parse
1778
+ )
1779
+ };
1780
+ hideInvalidProperties(schema);
1781
+ const mainSchema = callback(schema);
1585
1782
  mainSchema.metadata.id = id;
1586
1783
  mainSchema.metadata.description = options?.description ?? mainSchema.metadata.description;
1587
1784
  mainSchema.metadata.isDeprecated = options?.isDeprecated ?? mainSchema.metadata.isDeprecated;
@@ -1594,82 +1791,8 @@ function recursive(propA, propB) {
1594
1791
  return mainSchema;
1595
1792
  }
1596
1793
 
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
1794
  function timestamp(opts = {}) {
1672
- return {
1795
+ const result = {
1673
1796
  type: "timestamp",
1674
1797
  metadata: {
1675
1798
  id: opts.id,
@@ -1682,8 +1805,11 @@ function timestamp(opts = {}) {
1682
1805
  coerce,
1683
1806
  serialize
1684
1807
  }
1685
- }
1808
+ },
1809
+ "~standard": createStandardSchemaProperty(validate, parse)
1686
1810
  };
1811
+ hideInvalidProperties(result);
1812
+ return result;
1687
1813
  }
1688
1814
  function validate(input) {
1689
1815
  return typeof input === "object" && input instanceof Date;
@@ -1700,7 +1826,7 @@ function parse(input, data) {
1700
1826
  instancePath: data.instancePath,
1701
1827
  schemaPath: `${data.schemaPath}/type`
1702
1828
  });
1703
- return void 0;
1829
+ return undefined;
1704
1830
  }
1705
1831
  return new Date(result);
1706
1832
  }
@@ -1709,7 +1835,7 @@ function parse(input, data) {
1709
1835
  instancePath: data.instancePath,
1710
1836
  schemaPath: `${data.schemaPath}/type`
1711
1837
  });
1712
- return void 0;
1838
+ return undefined;
1713
1839
  }
1714
1840
  function coerce(input, options) {
1715
1841
  if (typeof input === "number") {
@@ -1726,18 +1852,21 @@ function serialize(input, data) {
1726
1852
 
1727
1853
  exports.NumberTypeValues = NumberTypeValues;
1728
1854
  exports.SCHEMA_METADATA = SCHEMA_METADATA;
1855
+ exports.STR_ESCAPE = STR_ESCAPE;
1729
1856
  exports.ValidationError = ValidationError;
1730
1857
  exports.any = any;
1731
1858
  exports.array = array;
1732
1859
  exports.boolean = boolean;
1733
1860
  exports.clone = clone;
1734
1861
  exports.coerce = coerce$2;
1862
+ exports.createStandardSchemaProperty = createStandardSchemaProperty;
1735
1863
  exports.discriminator = discriminator;
1736
1864
  exports.enumerator = enumerator;
1737
1865
  exports.errors = errors;
1738
1866
  exports.extend = extend;
1739
1867
  exports.float32 = float32;
1740
1868
  exports.float64 = float64;
1869
+ exports.hideInvalidProperties = hideInvalidProperties;
1741
1870
  exports.int16 = int16;
1742
1871
  exports.int16Max = int16Max;
1743
1872
  exports.int16Min = int16Min;
@@ -1777,6 +1906,7 @@ exports.sanitizeJson = sanitizeJson;
1777
1906
  exports.serialize = serialize$1;
1778
1907
  exports.serializeObject = serializeObject;
1779
1908
  exports.serializeSmallString = serializeSmallString;
1909
+ exports.serializeString = serializeString;
1780
1910
  exports.string = string;
1781
1911
  exports.stringEnum = stringEnum;
1782
1912
  exports.timestamp = timestamp;