@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.
@@ -69,24 +69,70 @@ function isARefSchema(input) {
69
69
  return isASchema(input) && typeDefs.isSchemaFormRef(input);
70
70
  }
71
71
 
72
- function any(options = {}) {
72
+ function createStandardSchemaProperty(validate, parse) {
73
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 = {
74
129
  metadata: {
75
130
  id: options.id,
76
131
  description: options.description,
77
132
  isDeprecated: options.isDeprecated,
78
133
  [SCHEMA_METADATA]: {
79
- output: void 0,
80
- parse: (input, context) => {
81
- if (context.instancePath.length === 0 && typeof input === "string") {
82
- try {
83
- return JSON.parse(input);
84
- } catch {
85
- return input;
86
- }
87
- }
88
- return input;
89
- },
134
+ output: undefined,
135
+ parse,
90
136
  coerce: (input, context) => {
91
137
  if (context.instancePath.length === 0 && typeof input === "string") {
92
138
  try {
@@ -97,17 +143,26 @@ function any(options = {}) {
97
143
  }
98
144
  return input;
99
145
  },
100
- validate: (input) => true,
146
+ validate,
101
147
  serialize(input) {
102
148
  return JSON.stringify(input);
103
149
  }
104
150
  }
105
- }
151
+ },
152
+ "~standard": createStandardSchemaProperty(validate, parse)
106
153
  };
154
+ hideInvalidProperties(result);
155
+ return result;
107
156
  }
108
157
 
109
158
  function array(schema, opts = {}) {
110
- 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 = {
111
166
  elements: schema,
112
167
  metadata: {
113
168
  id: opts.id,
@@ -115,15 +170,11 @@ function array(schema, opts = {}) {
115
170
  isDeprecated: opts.isDeprecated,
116
171
  [SCHEMA_METADATA]: {
117
172
  output: [],
118
- parse(input, context) {
119
- return parse$6(schema, input, context, false);
120
- },
173
+ parse: parseType,
121
174
  coerce(input, context) {
122
175
  return parse$6(schema, input, context, true);
123
176
  },
124
- validate(input) {
125
- return validate$5(schema, input);
126
- },
177
+ validate: validateType,
127
178
  serialize(input, context) {
128
179
  const strParts = [];
129
180
  for (let i = 0; i < input.length; i++) {
@@ -139,8 +190,11 @@ function array(schema, opts = {}) {
139
190
  return `[${strParts.join(",")}]`;
140
191
  }
141
192
  }
142
- }
193
+ },
194
+ "~standard": createStandardSchemaProperty(validateType, parseType)
143
195
  };
196
+ hideInvalidProperties(result);
197
+ return result;
144
198
  }
145
199
  function validate$5(innerSchema, input) {
146
200
  if (!Array.isArray(input)) {
@@ -165,7 +219,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
165
219
  schemaPath: `${data.schemaPath}/elements`,
166
220
  message: `Error at ${data.instancePath}. Invalid JSON.`
167
221
  });
168
- return void 0;
222
+ return undefined;
169
223
  }
170
224
  }
171
225
  if (!Array.isArray(parsedInput)) {
@@ -174,7 +228,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
174
228
  schemaPath: `${data.schemaPath}/elements`,
175
229
  message: `Error at ${data.instancePath}. Expected array. Got ${typeof input}.`
176
230
  });
177
- return void 0;
231
+ return undefined;
178
232
  }
179
233
  const result = [];
180
234
  for (let i = 0; i < parsedInput.length; i++) {
@@ -202,13 +256,13 @@ function parse$6(innerSchema, input, data, coerce = false) {
202
256
  }
203
257
  }
204
258
  if (data.errors.length) {
205
- return void 0;
259
+ return undefined;
206
260
  }
207
261
  return result;
208
262
  }
209
263
 
210
264
  function boolean(opts = {}) {
211
- return {
265
+ const result = {
212
266
  type: "boolean",
213
267
  metadata: {
214
268
  id: opts.id,
@@ -240,11 +294,14 @@ function boolean(opts = {}) {
240
294
  schemaPath: context.schemaPath,
241
295
  message: `Error at ${context.instancePath}. Unable to coerce ${input} to boolean.`
242
296
  });
243
- return void 0;
297
+ return undefined;
244
298
  }
245
299
  }
246
- }
300
+ },
301
+ "~standard": createStandardSchemaProperty(validate$4, parse$5)
247
302
  };
303
+ hideInvalidProperties(result);
304
+ return result;
248
305
  }
249
306
  function validate$4(input) {
250
307
  return typeof input === "boolean";
@@ -265,14 +322,14 @@ function parse$5(input, data) {
265
322
  schemaPath: `${data.schemaPath}/type`,
266
323
  message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
267
324
  });
268
- return void 0;
325
+ return undefined;
269
326
  }
270
327
  data.errors.push({
271
328
  instancePath: data.instancePath,
272
329
  schemaPath: `${data.schemaPath}/type`,
273
330
  message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
274
331
  });
275
- return void 0;
332
+ return undefined;
276
333
  }
277
334
  function serialize$2(input) {
278
335
  return `${input}`;
@@ -403,7 +460,13 @@ function discriminator(propA, propB, propC) {
403
460
  if (isIdShorthand) {
404
461
  opts.id = propA;
405
462
  }
406
- 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 = {
407
470
  discriminator: discriminator2,
408
471
  mapping,
409
472
  metadata: {
@@ -412,12 +475,8 @@ function discriminator(propA, propB, propC) {
412
475
  isDeprecated: opts.isDeprecated,
413
476
  [SCHEMA_METADATA]: {
414
477
  output: {},
415
- validate(input) {
416
- return validate$2(discriminator2, mapping, input);
417
- },
418
- parse(input, context) {
419
- return parse$3(discriminator2, mapping, input, context, false);
420
- },
478
+ validate: isType,
479
+ parse: parseType,
421
480
  coerce: (input, context) => {
422
481
  return parse$3(discriminator2, mapping, input, context, true);
423
482
  },
@@ -430,18 +489,21 @@ function discriminator(propA, propB, propC) {
430
489
  context
431
490
  );
432
491
  }
433
- const result = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
492
+ const result2 = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
434
493
  instancePath: context.instancePath,
435
494
  schemaPath: `${context.schemaPath}/mapping/${discriminatorVal}`,
436
495
  errors: context.errors,
437
496
  discriminatorKey: discriminator2,
438
497
  discriminatorValue: discriminatorVal
439
498
  });
440
- return result;
499
+ return result2;
441
500
  }
442
501
  }
443
- }
502
+ },
503
+ "~standard": createStandardSchemaProperty(isType, parseType)
444
504
  };
505
+ hideInvalidProperties(result);
506
+ return result;
445
507
  }
446
508
  function validate$2(discriminator2, mapping, input) {
447
509
  if (!isObject(input)) {
@@ -471,7 +533,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
471
533
  schemaPath: `${data.schemaPath}/discriminator`,
472
534
  message: `Error at ${data.instancePath}. Expected object. Got ${typeof parsedInput}.`
473
535
  });
474
- return void 0;
536
+ return undefined;
475
537
  }
476
538
  if (!(discriminator2 in parsedInput)) {
477
539
  data.errors.push({
@@ -479,7 +541,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
479
541
  schemaPath: `${data.schemaPath}/discriminator`,
480
542
  message: `Error at ${data.instancePath}/${discriminator2}. Discriminator field "${discriminator2}" cannot be undefined`
481
543
  });
482
- return void 0;
544
+ return undefined;
483
545
  }
484
546
  const acceptedDiscriminatorVals = Object.keys(mapping);
485
547
  const discriminatorVal = parsedInput[discriminator2];
@@ -491,7 +553,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
491
553
  ", "
492
554
  )}]`
493
555
  });
494
- return void 0;
556
+ return undefined;
495
557
  }
496
558
  const targetSchema = mapping[parsedInput[discriminator2]];
497
559
  if (!targetSchema) {
@@ -548,7 +610,20 @@ function enumerator(paramA, paramB) {
548
610
  }
549
611
  return false;
550
612
  };
551
- 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 = {
552
627
  enum: enumVal,
553
628
  metadata: {
554
629
  id: meta?.id,
@@ -556,19 +631,7 @@ function enumerator(paramA, paramB) {
556
631
  isDeprecated: meta?.isDeprecated,
557
632
  [SCHEMA_METADATA]: {
558
633
  output: paramA[0] ?? "",
559
- parse(input, context) {
560
- if (isType(input)) {
561
- return input;
562
- }
563
- context.errors.push({
564
- instancePath: context.instancePath,
565
- schemaPath: `${context.schemaPath}/enum`,
566
- message: `Error at ${context.instancePath}. Invalid enum value. Expected one of the following values: [${enumVal.join(
567
- ", "
568
- )}]`
569
- });
570
- return void 0;
571
- },
634
+ parse,
572
635
  coerce: (input, context) => {
573
636
  if (isType(input)) {
574
637
  return input;
@@ -580,7 +643,7 @@ function enumerator(paramA, paramB) {
580
643
  ", "
581
644
  )}]`
582
645
  });
583
- return void 0;
646
+ return undefined;
584
647
  },
585
648
  validate: isType,
586
649
  serialize(input, context) {
@@ -590,8 +653,11 @@ function enumerator(paramA, paramB) {
590
653
  return `"${input}"`;
591
654
  }
592
655
  }
593
- }
656
+ },
657
+ "~standard": createStandardSchemaProperty(isType, parse)
594
658
  };
659
+ hideInvalidProperties(result);
660
+ return result;
595
661
  }
596
662
 
597
663
  function nullable(schema, opts = {}) {
@@ -601,7 +667,16 @@ function nullable(schema, opts = {}) {
601
667
  }
602
668
  return schema.metadata[SCHEMA_METADATA].validate(val);
603
669
  };
604
- 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 = {
605
680
  ...schema,
606
681
  nullable: true,
607
682
  metadata: {
@@ -612,15 +687,7 @@ function nullable(schema, opts = {}) {
612
687
  output: null,
613
688
  optional: schema.metadata[SCHEMA_METADATA].optional,
614
689
  validate: isType,
615
- parse(val, data) {
616
- if (data.instancePath.length === 0 && typeof val === "string" && val === "null") {
617
- return null;
618
- }
619
- if (val === null) {
620
- return null;
621
- }
622
- return schema.metadata[SCHEMA_METADATA].parse(val, data);
623
- },
690
+ parse,
624
691
  coerce(val, data) {
625
692
  if (val === null) {
626
693
  return null;
@@ -642,39 +709,42 @@ function nullable(schema, opts = {}) {
642
709
  }
643
710
  }
644
711
  };
712
+ hideInvalidProperties(result);
713
+ return result;
645
714
  }
646
715
  function optional(input, opts = {}) {
647
716
  const isType = (val) => {
648
- if (val === void 0) {
717
+ if (val === undefined) {
649
718
  return true;
650
719
  }
651
720
  return input.metadata[SCHEMA_METADATA].validate(val);
652
721
  };
653
- 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 = {
654
732
  ...input,
655
733
  metadata: {
656
734
  id: opts.id ?? input.metadata.id,
657
735
  description: opts.description ?? input.metadata.description,
658
736
  isDeprecated: opts.isDeprecated ?? input.metadata.isDeprecated,
659
737
  [SCHEMA_METADATA]: {
660
- output: void 0,
738
+ output: undefined,
661
739
  optional: true,
662
740
  validate: isType,
663
- parse: (val, data) => {
664
- if (typeof val === "undefined") {
665
- return void 0;
666
- }
667
- if (data.instancePath.length === 0 && val === "undefined") {
668
- return void 0;
669
- }
670
- return input.metadata[SCHEMA_METADATA].parse(val, data);
671
- },
741
+ parse,
672
742
  coerce: (val, data) => {
673
743
  if (typeof val === "undefined") {
674
- return void 0;
744
+ return undefined;
675
745
  }
676
746
  if (val === "undefined") {
677
- return void 0;
747
+ return undefined;
678
748
  }
679
749
  return input.metadata[SCHEMA_METADATA].coerce(val, data);
680
750
  },
@@ -685,8 +755,11 @@ function optional(input, opts = {}) {
685
755
  return input.metadata[SCHEMA_METADATA].serialize(val, data);
686
756
  }
687
757
  }
688
- }
758
+ },
759
+ "~standard": createStandardSchemaProperty(isType, parse)
689
760
  };
761
+ hideInvalidProperties(result);
762
+ return result;
690
763
  }
691
764
  function clone(input, opts = {}) {
692
765
  const schema = {
@@ -698,8 +771,10 @@ function clone(input, opts = {}) {
698
771
  [SCHEMA_METADATA]: {
699
772
  ...input.metadata[SCHEMA_METADATA]
700
773
  }
701
- }
774
+ },
775
+ "~standard": input["~standard"]
702
776
  };
777
+ hideInvalidProperties(schema);
703
778
  return schema;
704
779
  }
705
780
 
@@ -715,7 +790,7 @@ function coerceNumber(input, options) {
715
790
  schemaPath: `${options.schemaPath}/type`,
716
791
  message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} into a number`
717
792
  });
718
- return void 0;
793
+ return undefined;
719
794
  }
720
795
  return parseNumber(parsedInput, options);
721
796
  }
@@ -840,7 +915,7 @@ function int64(opts = {}) {
840
915
  schemaPath: `${data.schemaPath}/type`,
841
916
  instancePath: data.instancePath
842
917
  });
843
- return void 0;
918
+ return undefined;
844
919
  }
845
920
  }
846
921
  if (isType(input)) {
@@ -851,9 +926,9 @@ function int64(opts = {}) {
851
926
  schemaPath: `${data.schemaPath}/type`,
852
927
  instancePath: data.instancePath
853
928
  });
854
- return void 0;
929
+ return undefined;
855
930
  }
856
- return {
931
+ const result = {
857
932
  type: "int64",
858
933
  metadata: {
859
934
  id: opts.id,
@@ -871,8 +946,11 @@ function int64(opts = {}) {
871
946
  return `"${input.toString()}"`;
872
947
  }
873
948
  }
874
- }
949
+ },
950
+ "~standard": createStandardSchemaProperty(isType, parse)
875
951
  };
952
+ hideInvalidProperties(result);
953
+ return result;
876
954
  }
877
955
  function uint64(opts = {}) {
878
956
  function isType(input) {
@@ -897,7 +975,7 @@ function uint64(opts = {}) {
897
975
  schemaPath: `${data.schemaPath}/type`,
898
976
  instancePath: data.instancePath
899
977
  });
900
- return void 0;
978
+ return undefined;
901
979
  }
902
980
  }
903
981
  if (isType(input)) {
@@ -908,9 +986,9 @@ function uint64(opts = {}) {
908
986
  schemaPath: `${data.schemaPath}/type`,
909
987
  instancePath: data.instancePath
910
988
  });
911
- return void 0;
989
+ return undefined;
912
990
  }
913
- return {
991
+ const result = {
914
992
  type: "uint64",
915
993
  metadata: {
916
994
  id: opts.id,
@@ -928,11 +1006,14 @@ function uint64(opts = {}) {
928
1006
  return `"${input.toString()}"`;
929
1007
  }
930
1008
  }
931
- }
1009
+ },
1010
+ "~standard": createStandardSchemaProperty(isType, parse)
932
1011
  };
1012
+ hideInvalidProperties(result);
1013
+ return result;
933
1014
  }
934
1015
  function validateNumber(input) {
935
- return typeof input === "number" || !Number.isNaN(input);
1016
+ return typeof input === "number";
936
1017
  }
937
1018
  function validateInt(input, minVal, maxValue) {
938
1019
  return Number.isInteger(input) && input >= minVal && input <= maxValue;
@@ -949,7 +1030,7 @@ function parseNumber(input, options) {
949
1030
  schemaPath: `${options.schemaPath}/type`,
950
1031
  message: `Error at ${options.instancePath}. Invalid number.`
951
1032
  });
952
- return void 0;
1033
+ return undefined;
953
1034
  }
954
1035
  return result;
955
1036
  }
@@ -961,10 +1042,41 @@ function parseNumber(input, options) {
961
1042
  schemaPath: `${options.schemaPath}/type`,
962
1043
  message: `Error at ${options.instancePath}. Invalid number.`
963
1044
  });
964
- return void 0;
1045
+ return undefined;
965
1046
  }
966
1047
  function numberScalarType(type, opts, numTypeMatcher) {
967
- 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 = {
968
1080
  type,
969
1081
  metadata: {
970
1082
  id: opts.id,
@@ -972,62 +1084,36 @@ function numberScalarType(type, opts, numTypeMatcher) {
972
1084
  isDeprecated: opts.isDeprecated,
973
1085
  [SCHEMA_METADATA]: {
974
1086
  output: 0,
975
- validate(input) {
976
- const isNum = validateNumber(input);
977
- if (!isNum) {
978
- return false;
979
- }
980
- return numTypeMatcher(input).success;
981
- },
982
- parse(input, options) {
983
- const result = parseNumber(input, options);
984
- if (options.errors.length) {
985
- return void 0;
986
- }
987
- if (typeof result !== "number") {
988
- options?.errors.push({
989
- instancePath: options.instancePath,
990
- schemaPath: `${options.schemaPath}/type`,
991
- message: `Error at ${options.instancePath}. Invalid number.`
992
- });
993
- return void 0;
994
- }
995
- const matchResult = numTypeMatcher(result);
996
- if (matchResult.success) {
997
- return result;
998
- }
999
- options?.errors.push({
1000
- instancePath: options.instancePath,
1001
- schemaPath: `${options.schemaPath}/type`,
1002
- message: `Error at ${options.instancePath}. ${matchResult.message}`
1003
- });
1004
- return void 0;
1005
- },
1087
+ validate,
1088
+ parse,
1006
1089
  serialize: serializeNumber,
1007
1090
  coerce(input, options) {
1008
- const result = coerceNumber(input, options);
1009
- if (typeof result !== "number") {
1091
+ const result2 = coerceNumber(input, options);
1092
+ if (typeof result2 !== "number") {
1010
1093
  options.errors.push({
1011
1094
  instancePath: options.instancePath,
1012
1095
  schemaPath: `${options.schemaPath}/type`,
1013
1096
  message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} to ${type}.`
1014
1097
  });
1015
- return void 0;
1098
+ return undefined;
1016
1099
  }
1017
- const matchResult = numTypeMatcher(result);
1100
+ const matchResult = numTypeMatcher(result2);
1018
1101
  if (matchResult.success) {
1019
- return result;
1102
+ return result2;
1020
1103
  }
1021
1104
  options.errors.push({
1022
1105
  instancePath: options.instancePath,
1023
1106
  schemaPath: `${options.schemaPath}/type`,
1024
1107
  message: `Error at ${options.instancePath}. ${matchResult.message}`
1025
1108
  });
1026
- return void 0;
1109
+ return undefined;
1027
1110
  }
1028
1111
  }
1029
- }
1112
+ },
1113
+ "~standard": createStandardSchemaProperty(validate, parse)
1030
1114
  };
1115
+ hideInvalidProperties(result);
1116
+ return result;
1031
1117
  }
1032
1118
 
1033
1119
  function object(propA, propB) {
@@ -1051,6 +1137,17 @@ function object(propA, propB) {
1051
1137
  }
1052
1138
  schema.properties[key] = prop;
1053
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
+ };
1054
1151
  const result = {
1055
1152
  ...schema,
1056
1153
  metadata: {
@@ -1059,14 +1156,7 @@ function object(propA, propB) {
1059
1156
  isDeprecated: options.isDeprecated,
1060
1157
  [SCHEMA_METADATA]: {
1061
1158
  output: {},
1062
- parse(input2, context) {
1063
- return parseObjectSchema(
1064
- schema,
1065
- input2,
1066
- context,
1067
- false
1068
- );
1069
- },
1159
+ parse,
1070
1160
  coerce(input2, context) {
1071
1161
  return parseObjectSchema(
1072
1162
  schema,
@@ -1075,9 +1165,7 @@ function object(propA, propB) {
1075
1165
  true
1076
1166
  );
1077
1167
  },
1078
- validate(input2) {
1079
- return validateObjectSchema(schema, input2);
1080
- },
1168
+ validate,
1081
1169
  serialize(input2, context) {
1082
1170
  return serializeObject(
1083
1171
  schema,
@@ -1086,8 +1174,10 @@ function object(propA, propB) {
1086
1174
  );
1087
1175
  }
1088
1176
  }
1089
- }
1177
+ },
1178
+ "~standard": createStandardSchemaProperty(validate, parse)
1090
1179
  };
1180
+ hideInvalidProperties(result);
1091
1181
  return result;
1092
1182
  }
1093
1183
  function parseObjectSchema(schema, input, data, coerce = false) {
@@ -1102,7 +1192,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1102
1192
  schemaPath: `${data.schemaPath}/properties`,
1103
1193
  message: `Error at ${data.instancePath}. Invalid JSON.`
1104
1194
  });
1105
- return void 0;
1195
+ return undefined;
1106
1196
  }
1107
1197
  }
1108
1198
  if (!isObject(parsedInput)) {
@@ -1111,7 +1201,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1111
1201
  schemaPath: `${data.schemaPath}/properties`,
1112
1202
  message: `Error at ${data.instancePath}. Expected object`
1113
1203
  });
1114
- return void 0;
1204
+ return undefined;
1115
1205
  }
1116
1206
  const result = {};
1117
1207
  const optionalProps = schema.optionalProperties ?? {};
@@ -1130,7 +1220,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1130
1220
  }
1131
1221
  }
1132
1222
  if (data.errors.length) {
1133
- return void 0;
1223
+ return undefined;
1134
1224
  }
1135
1225
  if (data.discriminatorKey) {
1136
1226
  result[data.discriminatorKey] = data.discriminatorValue;
@@ -1155,7 +1245,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1155
1245
  for (const key of optionalKeys) {
1156
1246
  const val = parsedInput[key];
1157
1247
  const prop = optionalProps[key];
1158
- if (val === void 0) {
1248
+ if (val === undefined) {
1159
1249
  continue;
1160
1250
  }
1161
1251
  if (coerce) {
@@ -1175,7 +1265,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1175
1265
  }
1176
1266
  }
1177
1267
  if (data.errors.length) {
1178
- return void 0;
1268
+ return undefined;
1179
1269
  }
1180
1270
  return result;
1181
1271
  }
@@ -1183,17 +1273,28 @@ function validateObjectSchema(schema, input) {
1183
1273
  if (!isObject(input)) {
1184
1274
  return false;
1185
1275
  }
1186
- const optionalProps = schema.optionalProperties ?? {};
1187
- for (const key of Object.keys(input)) {
1188
- const prop = schema.properties[key] ?? optionalProps[key];
1189
- if (!prop && schema.strict) {
1190
- 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);
1191
1293
  }
1192
- if (prop) {
1193
- const isValid = prop.metadata[SCHEMA_METADATA].validate(input[key]);
1194
- if (!isValid) {
1195
- return false;
1196
- }
1294
+ }
1295
+ if (allowedKeys) {
1296
+ for (const key of Object.keys(input)) {
1297
+ if (!allowedKeys.includes(key)) return false;
1197
1298
  }
1198
1299
  }
1199
1300
  return true;
@@ -1225,7 +1326,13 @@ function pick(inputSchema, keys, options = {}) {
1225
1326
  }
1226
1327
  });
1227
1328
  }
1228
- 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 = {
1229
1336
  ...schema,
1230
1337
  metadata: {
1231
1338
  id: options.id,
@@ -1233,14 +1340,7 @@ function pick(inputSchema, keys, options = {}) {
1233
1340
  isDeprecated: options.isDeprecated,
1234
1341
  [SCHEMA_METADATA]: {
1235
1342
  output: {},
1236
- parse: (input, context) => {
1237
- return parseObjectSchema(
1238
- schema,
1239
- input,
1240
- context,
1241
- true
1242
- );
1243
- },
1343
+ parse,
1244
1344
  coerce(input, context) {
1245
1345
  return parseObjectSchema(
1246
1346
  schema,
@@ -1249,15 +1349,16 @@ function pick(inputSchema, keys, options = {}) {
1249
1349
  false
1250
1350
  );
1251
1351
  },
1252
- validate(input) {
1253
- return validateObjectSchema(schema, input);
1254
- },
1352
+ validate,
1255
1353
  serialize(input, context) {
1256
1354
  return serializeObject(schema, input, context);
1257
1355
  }
1258
1356
  }
1259
- }
1357
+ },
1358
+ "~standard": createStandardSchemaProperty(validate, parse)
1260
1359
  };
1360
+ hideInvalidProperties(result);
1361
+ return result;
1261
1362
  }
1262
1363
  function omit(inputSchema, keys, options = {}) {
1263
1364
  const schema = {
@@ -1287,7 +1388,9 @@ function omit(inputSchema, keys, options = {}) {
1287
1388
  }
1288
1389
  });
1289
1390
  }
1290
- return {
1391
+ const validate = (input) => validateObjectSchema(schema, input);
1392
+ const parse = (input, context) => parseObjectSchema(schema, input, context, false);
1393
+ const result = {
1291
1394
  ...schema,
1292
1395
  metadata: {
1293
1396
  id: options.id,
@@ -1295,12 +1398,8 @@ function omit(inputSchema, keys, options = {}) {
1295
1398
  isDeprecated: options.isDeprecated,
1296
1399
  [SCHEMA_METADATA]: {
1297
1400
  output: {},
1298
- validate(input) {
1299
- return validateObjectSchema(schema, input);
1300
- },
1301
- parse(input, data) {
1302
- return parseObjectSchema(schema, input, data, false);
1303
- },
1401
+ validate,
1402
+ parse,
1304
1403
  serialize(input, context) {
1305
1404
  return serializeObject(schema, input, context);
1306
1405
  },
@@ -1313,8 +1412,11 @@ function omit(inputSchema, keys, options = {}) {
1313
1412
  );
1314
1413
  }
1315
1414
  }
1316
- }
1415
+ },
1416
+ "~standard": createStandardSchemaProperty(validate, parse)
1317
1417
  };
1418
+ hideInvalidProperties(result);
1419
+ return result;
1318
1420
  }
1319
1421
  function serializeObject(schema, input, data) {
1320
1422
  const strParts = [];
@@ -1411,23 +1513,20 @@ function partial(schema, options = {}) {
1411
1513
  }
1412
1514
  }
1413
1515
  }
1516
+ const validate = (input) => {
1517
+ return validateObjectSchema(newSchema, input);
1518
+ };
1519
+ const parse = (input, context) => {
1520
+ return parseObjectSchema(newSchema, input, context, false);
1521
+ };
1414
1522
  const meta = {
1415
1523
  id: options.id,
1416
1524
  description: options.description,
1417
1525
  [SCHEMA_METADATA]: {
1418
1526
  output: {},
1419
1527
  optional: schema.metadata[SCHEMA_METADATA].optional,
1420
- validate(input) {
1421
- return validateObjectSchema(newSchema, input);
1422
- },
1423
- parse(input, context) {
1424
- return parseObjectSchema(
1425
- newSchema,
1426
- input,
1427
- context,
1428
- false
1429
- );
1430
- },
1528
+ validate,
1529
+ parse,
1431
1530
  coerce(input, context) {
1432
1531
  return parseObjectSchema(
1433
1532
  newSchema,
@@ -1442,11 +1541,16 @@ function partial(schema, options = {}) {
1442
1541
  }
1443
1542
  };
1444
1543
  newSchema.metadata = meta;
1544
+ newSchema["~standard"] = createStandardSchemaProperty(
1545
+ validate,
1546
+ parse
1547
+ );
1548
+ hideInvalidProperties(newSchema);
1445
1549
  return newSchema;
1446
1550
  }
1447
1551
 
1448
1552
  function string(opts = {}) {
1449
- return {
1553
+ const result = {
1450
1554
  type: "string",
1451
1555
  metadata: {
1452
1556
  id: opts.id,
@@ -1470,8 +1574,11 @@ function string(opts = {}) {
1470
1574
  return JSON.stringify(input);
1471
1575
  }
1472
1576
  }
1473
- }
1577
+ },
1578
+ "~standard": createStandardSchemaProperty(validate$1, parse$2)
1474
1579
  };
1580
+ hideInvalidProperties(result);
1581
+ return result;
1475
1582
  }
1476
1583
  function serializeString(input) {
1477
1584
  if (input.length < 42) {
@@ -1494,7 +1601,7 @@ function parse$2(input, context) {
1494
1601
  schemaPath: `${context.schemaPath}/type`,
1495
1602
  message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
1496
1603
  });
1497
- return void 0;
1604
+ return undefined;
1498
1605
  }
1499
1606
  function coerce$1(input, context) {
1500
1607
  return parse$2(input, context);
@@ -1529,7 +1636,23 @@ function serializeSmallString(input) {
1529
1636
  }
1530
1637
 
1531
1638
  function record(schema, opts = {}) {
1532
- 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 = {
1533
1656
  values: schema,
1534
1657
  metadata: {
1535
1658
  id: opts.id,
@@ -1537,35 +1660,21 @@ function record(schema, opts = {}) {
1537
1660
  isDeprecated: opts.isDeprecated,
1538
1661
  [SCHEMA_METADATA]: {
1539
1662
  output: {},
1540
- validate(input) {
1541
- if (!isObject(input)) {
1542
- return false;
1543
- }
1544
- for (const key of Object.keys(input)) {
1545
- const val = input[key];
1546
- const isValid = schema.metadata[SCHEMA_METADATA].validate(val);
1547
- if (!isValid) {
1548
- return false;
1549
- }
1550
- }
1551
- return true;
1552
- },
1553
- parse(input, context) {
1554
- return parse$1(schema, input, context, false);
1555
- },
1663
+ validate: validateFn,
1664
+ parse: parseFn,
1556
1665
  coerce(input, data) {
1557
1666
  return parse$1(schema, input, data, true);
1558
1667
  },
1559
1668
  serialize(input, context) {
1560
- let result = "{";
1669
+ let result2 = "{";
1561
1670
  const keys = Object.keys(input);
1562
1671
  for (let i = 0; i < keys.length; i++) {
1563
1672
  const key = keys[i];
1564
1673
  const val = input[key];
1565
- if (i > 0) result += ",";
1566
- result += serializeString(key);
1567
- result += ":";
1568
- result += schema.metadata[SCHEMA_METADATA].serialize(
1674
+ if (i > 0) result2 += ",";
1675
+ result2 += serializeString(key);
1676
+ result2 += ":";
1677
+ result2 += schema.metadata[SCHEMA_METADATA].serialize(
1569
1678
  val,
1570
1679
  {
1571
1680
  instancePath: `${context.instancePath}/${key}`,
@@ -1574,12 +1683,15 @@ function record(schema, opts = {}) {
1574
1683
  }
1575
1684
  );
1576
1685
  }
1577
- result += "}";
1578
- return result;
1686
+ result2 += "}";
1687
+ return result2;
1579
1688
  }
1580
1689
  }
1581
- }
1690
+ },
1691
+ "~standard": createStandardSchemaProperty(validateFn, parseFn)
1582
1692
  };
1693
+ hideInvalidProperties(result);
1694
+ return result;
1583
1695
  }
1584
1696
  function parse$1(schema, input, data, coerce = false) {
1585
1697
  let parsedInput = input;
@@ -1592,7 +1704,7 @@ function parse$1(schema, input, data, coerce = false) {
1592
1704
  schemaPath: `${data.schemaPath}/values`,
1593
1705
  message: `Error at ${data.instancePath} Expected object`
1594
1706
  });
1595
- return void 0;
1707
+ return undefined;
1596
1708
  }
1597
1709
  const result = {};
1598
1710
  for (const key of Object.keys(parsedInput)) {
@@ -1612,7 +1724,7 @@ function parse$1(schema, input, data, coerce = false) {
1612
1724
  }
1613
1725
  }
1614
1726
  if (data.errors.length) {
1615
- return void 0;
1727
+ return undefined;
1616
1728
  }
1617
1729
  return result;
1618
1730
  }
@@ -1630,36 +1742,43 @@ function recursive(propA, propB) {
1630
1742
  );
1631
1743
  }
1632
1744
  const id = options.id ?? `TypeRef${recursiveTypeCount}`;
1633
- const mainSchema = callback({
1634
- ref: id,
1635
- metadata: {
1636
- [SCHEMA_METADATA]: {
1637
- output: "",
1638
- parse(input, context) {
1639
- if (recursiveFns[id]) {
1640
- return recursiveFns[id].parse(input, context);
1641
- }
1642
- },
1643
- serialize(input, context) {
1644
- if (recursiveFns[id]) {
1645
- return recursiveFns[id].serialize(input, context);
1646
- }
1647
- return "";
1648
- },
1649
- validate(input) {
1650
- if (recursiveFns[id]) {
1651
- return recursiveFns[id].validate(input);
1652
- }
1653
- return false;
1654
- },
1655
- coerce(input, context) {
1656
- if (recursiveFns[id]) {
1657
- return recursiveFns[id].coerce(input, context);
1658
- }
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);
1659
1768
  }
1660
1769
  }
1661
1770
  }
1662
- });
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);
1663
1782
  mainSchema.metadata.id = id;
1664
1783
  mainSchema.metadata.description = options?.description ?? mainSchema.metadata.description;
1665
1784
  mainSchema.metadata.isDeprecated = options?.isDeprecated ?? mainSchema.metadata.isDeprecated;
@@ -1673,7 +1792,7 @@ function recursive(propA, propB) {
1673
1792
  }
1674
1793
 
1675
1794
  function timestamp(opts = {}) {
1676
- return {
1795
+ const result = {
1677
1796
  type: "timestamp",
1678
1797
  metadata: {
1679
1798
  id: opts.id,
@@ -1686,8 +1805,11 @@ function timestamp(opts = {}) {
1686
1805
  coerce,
1687
1806
  serialize
1688
1807
  }
1689
- }
1808
+ },
1809
+ "~standard": createStandardSchemaProperty(validate, parse)
1690
1810
  };
1811
+ hideInvalidProperties(result);
1812
+ return result;
1691
1813
  }
1692
1814
  function validate(input) {
1693
1815
  return typeof input === "object" && input instanceof Date;
@@ -1704,7 +1826,7 @@ function parse(input, data) {
1704
1826
  instancePath: data.instancePath,
1705
1827
  schemaPath: `${data.schemaPath}/type`
1706
1828
  });
1707
- return void 0;
1829
+ return undefined;
1708
1830
  }
1709
1831
  return new Date(result);
1710
1832
  }
@@ -1713,7 +1835,7 @@ function parse(input, data) {
1713
1835
  instancePath: data.instancePath,
1714
1836
  schemaPath: `${data.schemaPath}/type`
1715
1837
  });
1716
- return void 0;
1838
+ return undefined;
1717
1839
  }
1718
1840
  function coerce(input, options) {
1719
1841
  if (typeof input === "number") {
@@ -1737,12 +1859,14 @@ exports.array = array;
1737
1859
  exports.boolean = boolean;
1738
1860
  exports.clone = clone;
1739
1861
  exports.coerce = coerce$2;
1862
+ exports.createStandardSchemaProperty = createStandardSchemaProperty;
1740
1863
  exports.discriminator = discriminator;
1741
1864
  exports.enumerator = enumerator;
1742
1865
  exports.errors = errors;
1743
1866
  exports.extend = extend;
1744
1867
  exports.float32 = float32;
1745
1868
  exports.float64 = float64;
1869
+ exports.hideInvalidProperties = hideInvalidProperties;
1746
1870
  exports.int16 = int16;
1747
1871
  exports.int16Max = int16Max;
1748
1872
  exports.int16Min = int16Min;