@arrirpc/schema 0.70.1 → 0.71.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { TypeValues, isSchemaFormElements, isSchemaFormEnum, isSchemaFormDiscriminator, isSchemaFormValues, isSchemaFormProperties, isSchemaFormRef } from '@arrirpc/type-defs';
2
+ import 'scule';
2
3
 
3
4
  const int8Min = -128;
4
5
  const int8Max = 127;
@@ -67,24 +68,78 @@ function isARefSchema(input) {
67
68
  return isASchema(input) && isSchemaFormRef(input);
68
69
  }
69
70
 
70
- function any(options = {}) {
71
+ function createStandardSchemaProperty(validate, parse) {
71
72
  return {
73
+ version: 1,
74
+ vendor: "arri",
75
+ validate(input) {
76
+ if (validate(input)) {
77
+ return {
78
+ value: input
79
+ };
80
+ }
81
+ const ctx = {
82
+ instancePath: "",
83
+ schemaPath: "",
84
+ errors: []
85
+ };
86
+ try {
87
+ const result = parse(input, ctx);
88
+ if (ctx.errors.length) {
89
+ return {
90
+ issues: ctx.errors.map((err) => ({
91
+ message: err.message ?? "Unknown error",
92
+ path: err.instancePath.split("/").filter((val) => val.length > 0)
93
+ }))
94
+ };
95
+ }
96
+ return {
97
+ value: result
98
+ };
99
+ } catch (err) {
100
+ if (err instanceof ValidationError) {
101
+ return {
102
+ issues: err.errors.map((err2) => ({
103
+ message: err2.message ?? "Unknown error",
104
+ path: err2.instancePath.split("/").filter((item) => item.length > 0)
105
+ }))
106
+ };
107
+ }
108
+ return {
109
+ issues: [
110
+ {
111
+ message: err instanceof Error ? err.message : `${err}`
112
+ }
113
+ ]
114
+ };
115
+ }
116
+ }
117
+ };
118
+ }
119
+ function hideInvalidProperties(schema) {
120
+ Object.defineProperty(schema, "~standard", { enumerable: false });
121
+ }
122
+
123
+ function any(options = {}) {
124
+ const validate = (input) => true;
125
+ const parse = (input, context) => {
126
+ if (context.instancePath.length === 0 && typeof input === "string") {
127
+ try {
128
+ return JSON.parse(input);
129
+ } catch {
130
+ return input;
131
+ }
132
+ }
133
+ return input;
134
+ };
135
+ const result = {
72
136
  metadata: {
73
137
  id: options.id,
74
138
  description: options.description,
75
139
  isDeprecated: options.isDeprecated,
76
140
  [SCHEMA_METADATA]: {
77
- output: void 0,
78
- parse: (input, context) => {
79
- if (context.instancePath.length === 0 && typeof input === "string") {
80
- try {
81
- return JSON.parse(input);
82
- } catch {
83
- return input;
84
- }
85
- }
86
- return input;
87
- },
141
+ output: undefined,
142
+ parse,
88
143
  coerce: (input, context) => {
89
144
  if (context.instancePath.length === 0 && typeof input === "string") {
90
145
  try {
@@ -95,17 +150,26 @@ function any(options = {}) {
95
150
  }
96
151
  return input;
97
152
  },
98
- validate: (input) => true,
153
+ validate,
99
154
  serialize(input) {
100
155
  return JSON.stringify(input);
101
156
  }
102
157
  }
103
- }
158
+ },
159
+ "~standard": createStandardSchemaProperty(validate, parse)
104
160
  };
161
+ hideInvalidProperties(result);
162
+ return result;
105
163
  }
106
164
 
107
165
  function array(schema, opts = {}) {
108
- return {
166
+ const validateType = (input) => {
167
+ return validate$5(schema, input);
168
+ };
169
+ const parseType = (input, context) => {
170
+ return parse$6(schema, input, context, false);
171
+ };
172
+ const result = {
109
173
  elements: schema,
110
174
  metadata: {
111
175
  id: opts.id,
@@ -113,15 +177,11 @@ function array(schema, opts = {}) {
113
177
  isDeprecated: opts.isDeprecated,
114
178
  [SCHEMA_METADATA]: {
115
179
  output: [],
116
- parse(input, context) {
117
- return parse$6(schema, input, context, false);
118
- },
180
+ parse: parseType,
119
181
  coerce(input, context) {
120
182
  return parse$6(schema, input, context, true);
121
183
  },
122
- validate(input) {
123
- return validate$5(schema, input);
124
- },
184
+ validate: validateType,
125
185
  serialize(input, context) {
126
186
  const strParts = [];
127
187
  for (let i = 0; i < input.length; i++) {
@@ -137,8 +197,11 @@ function array(schema, opts = {}) {
137
197
  return `[${strParts.join(",")}]`;
138
198
  }
139
199
  }
140
- }
200
+ },
201
+ "~standard": createStandardSchemaProperty(validateType, parseType)
141
202
  };
203
+ hideInvalidProperties(result);
204
+ return result;
142
205
  }
143
206
  function validate$5(innerSchema, input) {
144
207
  if (!Array.isArray(input)) {
@@ -163,7 +226,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
163
226
  schemaPath: `${data.schemaPath}/elements`,
164
227
  message: `Error at ${data.instancePath}. Invalid JSON.`
165
228
  });
166
- return void 0;
229
+ return undefined;
167
230
  }
168
231
  }
169
232
  if (!Array.isArray(parsedInput)) {
@@ -172,7 +235,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
172
235
  schemaPath: `${data.schemaPath}/elements`,
173
236
  message: `Error at ${data.instancePath}. Expected array. Got ${typeof input}.`
174
237
  });
175
- return void 0;
238
+ return undefined;
176
239
  }
177
240
  const result = [];
178
241
  for (let i = 0; i < parsedInput.length; i++) {
@@ -200,13 +263,13 @@ function parse$6(innerSchema, input, data, coerce = false) {
200
263
  }
201
264
  }
202
265
  if (data.errors.length) {
203
- return void 0;
266
+ return undefined;
204
267
  }
205
268
  return result;
206
269
  }
207
270
 
208
271
  function boolean(opts = {}) {
209
- return {
272
+ const result = {
210
273
  type: "boolean",
211
274
  metadata: {
212
275
  id: opts.id,
@@ -238,11 +301,14 @@ function boolean(opts = {}) {
238
301
  schemaPath: context.schemaPath,
239
302
  message: `Error at ${context.instancePath}. Unable to coerce ${input} to boolean.`
240
303
  });
241
- return void 0;
304
+ return undefined;
242
305
  }
243
306
  }
244
- }
307
+ },
308
+ "~standard": createStandardSchemaProperty(validate$4, parse$5)
245
309
  };
310
+ hideInvalidProperties(result);
311
+ return result;
246
312
  }
247
313
  function validate$4(input) {
248
314
  return typeof input === "boolean";
@@ -263,14 +329,14 @@ function parse$5(input, data) {
263
329
  schemaPath: `${data.schemaPath}/type`,
264
330
  message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
265
331
  });
266
- return void 0;
332
+ return undefined;
267
333
  }
268
334
  data.errors.push({
269
335
  instancePath: data.instancePath,
270
336
  schemaPath: `${data.schemaPath}/type`,
271
337
  message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
272
338
  });
273
- return void 0;
339
+ return undefined;
274
340
  }
275
341
  function serialize$2(input) {
276
342
  return `${input}`;
@@ -401,7 +467,13 @@ function discriminator(propA, propB, propC) {
401
467
  if (isIdShorthand) {
402
468
  opts.id = propA;
403
469
  }
404
- return {
470
+ const isType = (input) => {
471
+ return validate$2(discriminator2, mapping, input);
472
+ };
473
+ const parseType = (input, context) => {
474
+ return parse$3(discriminator2, mapping, input, context, false);
475
+ };
476
+ const result = {
405
477
  discriminator: discriminator2,
406
478
  mapping,
407
479
  metadata: {
@@ -410,12 +482,8 @@ function discriminator(propA, propB, propC) {
410
482
  isDeprecated: opts.isDeprecated,
411
483
  [SCHEMA_METADATA]: {
412
484
  output: {},
413
- validate(input) {
414
- return validate$2(discriminator2, mapping, input);
415
- },
416
- parse(input, context) {
417
- return parse$3(discriminator2, mapping, input, context, false);
418
- },
485
+ validate: isType,
486
+ parse: parseType,
419
487
  coerce: (input, context) => {
420
488
  return parse$3(discriminator2, mapping, input, context, true);
421
489
  },
@@ -428,18 +496,21 @@ function discriminator(propA, propB, propC) {
428
496
  context
429
497
  );
430
498
  }
431
- const result = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
499
+ const result2 = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
432
500
  instancePath: context.instancePath,
433
501
  schemaPath: `${context.schemaPath}/mapping/${discriminatorVal}`,
434
502
  errors: context.errors,
435
503
  discriminatorKey: discriminator2,
436
504
  discriminatorValue: discriminatorVal
437
505
  });
438
- return result;
506
+ return result2;
439
507
  }
440
508
  }
441
- }
509
+ },
510
+ "~standard": createStandardSchemaProperty(isType, parseType)
442
511
  };
512
+ hideInvalidProperties(result);
513
+ return result;
443
514
  }
444
515
  function validate$2(discriminator2, mapping, input) {
445
516
  if (!isObject(input)) {
@@ -469,7 +540,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
469
540
  schemaPath: `${data.schemaPath}/discriminator`,
470
541
  message: `Error at ${data.instancePath}. Expected object. Got ${typeof parsedInput}.`
471
542
  });
472
- return void 0;
543
+ return undefined;
473
544
  }
474
545
  if (!(discriminator2 in parsedInput)) {
475
546
  data.errors.push({
@@ -477,7 +548,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
477
548
  schemaPath: `${data.schemaPath}/discriminator`,
478
549
  message: `Error at ${data.instancePath}/${discriminator2}. Discriminator field "${discriminator2}" cannot be undefined`
479
550
  });
480
- return void 0;
551
+ return undefined;
481
552
  }
482
553
  const acceptedDiscriminatorVals = Object.keys(mapping);
483
554
  const discriminatorVal = parsedInput[discriminator2];
@@ -489,7 +560,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
489
560
  ", "
490
561
  )}]`
491
562
  });
492
- return void 0;
563
+ return undefined;
493
564
  }
494
565
  const targetSchema = mapping[parsedInput[discriminator2]];
495
566
  if (!targetSchema) {
@@ -546,7 +617,20 @@ function enumerator(paramA, paramB) {
546
617
  }
547
618
  return false;
548
619
  };
549
- return {
620
+ const parse = (input, context) => {
621
+ if (isType(input)) {
622
+ return input;
623
+ }
624
+ context.errors.push({
625
+ instancePath: context.instancePath,
626
+ schemaPath: `${context.schemaPath}/enum`,
627
+ message: `Error at ${context.instancePath}. Invalid enum value. Expected one of the following values: [${enumVal.join(
628
+ ", "
629
+ )}]`
630
+ });
631
+ return undefined;
632
+ };
633
+ const result = {
550
634
  enum: enumVal,
551
635
  metadata: {
552
636
  id: meta?.id,
@@ -554,19 +638,7 @@ function enumerator(paramA, paramB) {
554
638
  isDeprecated: meta?.isDeprecated,
555
639
  [SCHEMA_METADATA]: {
556
640
  output: paramA[0] ?? "",
557
- parse(input, context) {
558
- if (isType(input)) {
559
- return input;
560
- }
561
- context.errors.push({
562
- instancePath: context.instancePath,
563
- schemaPath: `${context.schemaPath}/enum`,
564
- message: `Error at ${context.instancePath}. Invalid enum value. Expected one of the following values: [${enumVal.join(
565
- ", "
566
- )}]`
567
- });
568
- return void 0;
569
- },
641
+ parse,
570
642
  coerce: (input, context) => {
571
643
  if (isType(input)) {
572
644
  return input;
@@ -578,7 +650,7 @@ function enumerator(paramA, paramB) {
578
650
  ", "
579
651
  )}]`
580
652
  });
581
- return void 0;
653
+ return undefined;
582
654
  },
583
655
  validate: isType,
584
656
  serialize(input, context) {
@@ -588,8 +660,11 @@ function enumerator(paramA, paramB) {
588
660
  return `"${input}"`;
589
661
  }
590
662
  }
591
- }
663
+ },
664
+ "~standard": createStandardSchemaProperty(isType, parse)
592
665
  };
666
+ hideInvalidProperties(result);
667
+ return result;
593
668
  }
594
669
 
595
670
  function nullable(schema, opts = {}) {
@@ -599,7 +674,16 @@ function nullable(schema, opts = {}) {
599
674
  }
600
675
  return schema.metadata[SCHEMA_METADATA].validate(val);
601
676
  };
602
- return {
677
+ const parse = (val, data) => {
678
+ if (data.instancePath.length === 0 && typeof val === "string" && val === "null") {
679
+ return null;
680
+ }
681
+ if (val === null) {
682
+ return null;
683
+ }
684
+ return schema.metadata[SCHEMA_METADATA].parse(val, data);
685
+ };
686
+ const result = {
603
687
  ...schema,
604
688
  nullable: true,
605
689
  metadata: {
@@ -610,15 +694,7 @@ function nullable(schema, opts = {}) {
610
694
  output: null,
611
695
  optional: schema.metadata[SCHEMA_METADATA].optional,
612
696
  validate: isType,
613
- parse(val, data) {
614
- if (data.instancePath.length === 0 && typeof val === "string" && val === "null") {
615
- return null;
616
- }
617
- if (val === null) {
618
- return null;
619
- }
620
- return schema.metadata[SCHEMA_METADATA].parse(val, data);
621
- },
697
+ parse,
622
698
  coerce(val, data) {
623
699
  if (val === null) {
624
700
  return null;
@@ -640,39 +716,42 @@ function nullable(schema, opts = {}) {
640
716
  }
641
717
  }
642
718
  };
719
+ hideInvalidProperties(result);
720
+ return result;
643
721
  }
644
722
  function optional(input, opts = {}) {
645
723
  const isType = (val) => {
646
- if (val === void 0) {
724
+ if (val === undefined) {
647
725
  return true;
648
726
  }
649
727
  return input.metadata[SCHEMA_METADATA].validate(val);
650
728
  };
651
- return {
729
+ const parse = (val, context) => {
730
+ if (typeof val === "undefined") {
731
+ return undefined;
732
+ }
733
+ if (context.instancePath.length === 0 && val === "undefined") {
734
+ return undefined;
735
+ }
736
+ return input.metadata[SCHEMA_METADATA].parse(val, context);
737
+ };
738
+ const result = {
652
739
  ...input,
653
740
  metadata: {
654
741
  id: opts.id ?? input.metadata.id,
655
742
  description: opts.description ?? input.metadata.description,
656
743
  isDeprecated: opts.isDeprecated ?? input.metadata.isDeprecated,
657
744
  [SCHEMA_METADATA]: {
658
- output: void 0,
745
+ output: undefined,
659
746
  optional: true,
660
747
  validate: isType,
661
- parse: (val, data) => {
662
- if (typeof val === "undefined") {
663
- return void 0;
664
- }
665
- if (data.instancePath.length === 0 && val === "undefined") {
666
- return void 0;
667
- }
668
- return input.metadata[SCHEMA_METADATA].parse(val, data);
669
- },
748
+ parse,
670
749
  coerce: (val, data) => {
671
750
  if (typeof val === "undefined") {
672
- return void 0;
751
+ return undefined;
673
752
  }
674
753
  if (val === "undefined") {
675
- return void 0;
754
+ return undefined;
676
755
  }
677
756
  return input.metadata[SCHEMA_METADATA].coerce(val, data);
678
757
  },
@@ -683,8 +762,11 @@ function optional(input, opts = {}) {
683
762
  return input.metadata[SCHEMA_METADATA].serialize(val, data);
684
763
  }
685
764
  }
686
- }
765
+ },
766
+ "~standard": createStandardSchemaProperty(isType, parse)
687
767
  };
768
+ hideInvalidProperties(result);
769
+ return result;
688
770
  }
689
771
  function clone(input, opts = {}) {
690
772
  const schema = {
@@ -696,8 +778,10 @@ function clone(input, opts = {}) {
696
778
  [SCHEMA_METADATA]: {
697
779
  ...input.metadata[SCHEMA_METADATA]
698
780
  }
699
- }
781
+ },
782
+ "~standard": input["~standard"]
700
783
  };
784
+ hideInvalidProperties(schema);
701
785
  return schema;
702
786
  }
703
787
 
@@ -713,7 +797,7 @@ function coerceNumber(input, options) {
713
797
  schemaPath: `${options.schemaPath}/type`,
714
798
  message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} into a number`
715
799
  });
716
- return void 0;
800
+ return undefined;
717
801
  }
718
802
  return parseNumber(parsedInput, options);
719
803
  }
@@ -838,7 +922,7 @@ function int64(opts = {}) {
838
922
  schemaPath: `${data.schemaPath}/type`,
839
923
  instancePath: data.instancePath
840
924
  });
841
- return void 0;
925
+ return undefined;
842
926
  }
843
927
  }
844
928
  if (isType(input)) {
@@ -849,9 +933,9 @@ function int64(opts = {}) {
849
933
  schemaPath: `${data.schemaPath}/type`,
850
934
  instancePath: data.instancePath
851
935
  });
852
- return void 0;
936
+ return undefined;
853
937
  }
854
- return {
938
+ const result = {
855
939
  type: "int64",
856
940
  metadata: {
857
941
  id: opts.id,
@@ -869,8 +953,11 @@ function int64(opts = {}) {
869
953
  return `"${input.toString()}"`;
870
954
  }
871
955
  }
872
- }
956
+ },
957
+ "~standard": createStandardSchemaProperty(isType, parse)
873
958
  };
959
+ hideInvalidProperties(result);
960
+ return result;
874
961
  }
875
962
  function uint64(opts = {}) {
876
963
  function isType(input) {
@@ -895,7 +982,7 @@ function uint64(opts = {}) {
895
982
  schemaPath: `${data.schemaPath}/type`,
896
983
  instancePath: data.instancePath
897
984
  });
898
- return void 0;
985
+ return undefined;
899
986
  }
900
987
  }
901
988
  if (isType(input)) {
@@ -906,9 +993,9 @@ function uint64(opts = {}) {
906
993
  schemaPath: `${data.schemaPath}/type`,
907
994
  instancePath: data.instancePath
908
995
  });
909
- return void 0;
996
+ return undefined;
910
997
  }
911
- return {
998
+ const result = {
912
999
  type: "uint64",
913
1000
  metadata: {
914
1001
  id: opts.id,
@@ -926,11 +1013,14 @@ function uint64(opts = {}) {
926
1013
  return `"${input.toString()}"`;
927
1014
  }
928
1015
  }
929
- }
1016
+ },
1017
+ "~standard": createStandardSchemaProperty(isType, parse)
930
1018
  };
1019
+ hideInvalidProperties(result);
1020
+ return result;
931
1021
  }
932
1022
  function validateNumber(input) {
933
- return typeof input === "number" || !Number.isNaN(input);
1023
+ return typeof input === "number";
934
1024
  }
935
1025
  function validateInt(input, minVal, maxValue) {
936
1026
  return Number.isInteger(input) && input >= minVal && input <= maxValue;
@@ -947,7 +1037,7 @@ function parseNumber(input, options) {
947
1037
  schemaPath: `${options.schemaPath}/type`,
948
1038
  message: `Error at ${options.instancePath}. Invalid number.`
949
1039
  });
950
- return void 0;
1040
+ return undefined;
951
1041
  }
952
1042
  return result;
953
1043
  }
@@ -959,10 +1049,41 @@ function parseNumber(input, options) {
959
1049
  schemaPath: `${options.schemaPath}/type`,
960
1050
  message: `Error at ${options.instancePath}. Invalid number.`
961
1051
  });
962
- return void 0;
1052
+ return undefined;
963
1053
  }
964
1054
  function numberScalarType(type, opts, numTypeMatcher) {
965
- return {
1055
+ const validate = (input) => {
1056
+ const isNum = validateNumber(input);
1057
+ if (!isNum) {
1058
+ return false;
1059
+ }
1060
+ return numTypeMatcher(input).success;
1061
+ };
1062
+ const parse = (input, context) => {
1063
+ const result2 = parseNumber(input, context);
1064
+ if (context.errors.length) {
1065
+ return undefined;
1066
+ }
1067
+ if (typeof result2 !== "number") {
1068
+ context?.errors.push({
1069
+ instancePath: context.instancePath,
1070
+ schemaPath: `${context.schemaPath}/type`,
1071
+ message: `Error at ${context.instancePath}. Invalid number.`
1072
+ });
1073
+ return undefined;
1074
+ }
1075
+ const matchResult = numTypeMatcher(result2);
1076
+ if (matchResult.success) {
1077
+ return result2;
1078
+ }
1079
+ context?.errors.push({
1080
+ instancePath: context.instancePath,
1081
+ schemaPath: `${context.schemaPath}/type`,
1082
+ message: `Error at ${context.instancePath}. ${matchResult.message}`
1083
+ });
1084
+ return undefined;
1085
+ };
1086
+ const result = {
966
1087
  type,
967
1088
  metadata: {
968
1089
  id: opts.id,
@@ -970,62 +1091,36 @@ function numberScalarType(type, opts, numTypeMatcher) {
970
1091
  isDeprecated: opts.isDeprecated,
971
1092
  [SCHEMA_METADATA]: {
972
1093
  output: 0,
973
- validate(input) {
974
- const isNum = validateNumber(input);
975
- if (!isNum) {
976
- return false;
977
- }
978
- return numTypeMatcher(input).success;
979
- },
980
- parse(input, options) {
981
- const result = parseNumber(input, options);
982
- if (options.errors.length) {
983
- return void 0;
984
- }
985
- if (typeof result !== "number") {
986
- options?.errors.push({
987
- instancePath: options.instancePath,
988
- schemaPath: `${options.schemaPath}/type`,
989
- message: `Error at ${options.instancePath}. Invalid number.`
990
- });
991
- return void 0;
992
- }
993
- const matchResult = numTypeMatcher(result);
994
- if (matchResult.success) {
995
- return result;
996
- }
997
- options?.errors.push({
998
- instancePath: options.instancePath,
999
- schemaPath: `${options.schemaPath}/type`,
1000
- message: `Error at ${options.instancePath}. ${matchResult.message}`
1001
- });
1002
- return void 0;
1003
- },
1094
+ validate,
1095
+ parse,
1004
1096
  serialize: serializeNumber,
1005
1097
  coerce(input, options) {
1006
- const result = coerceNumber(input, options);
1007
- if (typeof result !== "number") {
1098
+ const result2 = coerceNumber(input, options);
1099
+ if (typeof result2 !== "number") {
1008
1100
  options.errors.push({
1009
1101
  instancePath: options.instancePath,
1010
1102
  schemaPath: `${options.schemaPath}/type`,
1011
1103
  message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} to ${type}.`
1012
1104
  });
1013
- return void 0;
1105
+ return undefined;
1014
1106
  }
1015
- const matchResult = numTypeMatcher(result);
1107
+ const matchResult = numTypeMatcher(result2);
1016
1108
  if (matchResult.success) {
1017
- return result;
1109
+ return result2;
1018
1110
  }
1019
1111
  options.errors.push({
1020
1112
  instancePath: options.instancePath,
1021
1113
  schemaPath: `${options.schemaPath}/type`,
1022
1114
  message: `Error at ${options.instancePath}. ${matchResult.message}`
1023
1115
  });
1024
- return void 0;
1116
+ return undefined;
1025
1117
  }
1026
1118
  }
1027
- }
1119
+ },
1120
+ "~standard": createStandardSchemaProperty(validate, parse)
1028
1121
  };
1122
+ hideInvalidProperties(result);
1123
+ return result;
1029
1124
  }
1030
1125
 
1031
1126
  function object(propA, propB) {
@@ -1049,6 +1144,17 @@ function object(propA, propB) {
1049
1144
  }
1050
1145
  schema.properties[key] = prop;
1051
1146
  }
1147
+ const validate = (input2) => {
1148
+ return validateObjectSchema(schema, input2);
1149
+ };
1150
+ const parse = (input2, context) => {
1151
+ return parseObjectSchema(
1152
+ schema,
1153
+ input2,
1154
+ context,
1155
+ false
1156
+ );
1157
+ };
1052
1158
  const result = {
1053
1159
  ...schema,
1054
1160
  metadata: {
@@ -1057,14 +1163,7 @@ function object(propA, propB) {
1057
1163
  isDeprecated: options.isDeprecated,
1058
1164
  [SCHEMA_METADATA]: {
1059
1165
  output: {},
1060
- parse(input2, context) {
1061
- return parseObjectSchema(
1062
- schema,
1063
- input2,
1064
- context,
1065
- false
1066
- );
1067
- },
1166
+ parse,
1068
1167
  coerce(input2, context) {
1069
1168
  return parseObjectSchema(
1070
1169
  schema,
@@ -1073,9 +1172,7 @@ function object(propA, propB) {
1073
1172
  true
1074
1173
  );
1075
1174
  },
1076
- validate(input2) {
1077
- return validateObjectSchema(schema, input2);
1078
- },
1175
+ validate,
1079
1176
  serialize(input2, context) {
1080
1177
  return serializeObject(
1081
1178
  schema,
@@ -1084,8 +1181,10 @@ function object(propA, propB) {
1084
1181
  );
1085
1182
  }
1086
1183
  }
1087
- }
1184
+ },
1185
+ "~standard": createStandardSchemaProperty(validate, parse)
1088
1186
  };
1187
+ hideInvalidProperties(result);
1089
1188
  return result;
1090
1189
  }
1091
1190
  function parseObjectSchema(schema, input, data, coerce = false) {
@@ -1100,7 +1199,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1100
1199
  schemaPath: `${data.schemaPath}/properties`,
1101
1200
  message: `Error at ${data.instancePath}. Invalid JSON.`
1102
1201
  });
1103
- return void 0;
1202
+ return undefined;
1104
1203
  }
1105
1204
  }
1106
1205
  if (!isObject(parsedInput)) {
@@ -1109,7 +1208,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1109
1208
  schemaPath: `${data.schemaPath}/properties`,
1110
1209
  message: `Error at ${data.instancePath}. Expected object`
1111
1210
  });
1112
- return void 0;
1211
+ return undefined;
1113
1212
  }
1114
1213
  const result = {};
1115
1214
  const optionalProps = schema.optionalProperties ?? {};
@@ -1128,7 +1227,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1128
1227
  }
1129
1228
  }
1130
1229
  if (data.errors.length) {
1131
- return void 0;
1230
+ return undefined;
1132
1231
  }
1133
1232
  if (data.discriminatorKey) {
1134
1233
  result[data.discriminatorKey] = data.discriminatorValue;
@@ -1153,7 +1252,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1153
1252
  for (const key of optionalKeys) {
1154
1253
  const val = parsedInput[key];
1155
1254
  const prop = optionalProps[key];
1156
- if (val === void 0) {
1255
+ if (val === undefined) {
1157
1256
  continue;
1158
1257
  }
1159
1258
  if (coerce) {
@@ -1173,7 +1272,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1173
1272
  }
1174
1273
  }
1175
1274
  if (data.errors.length) {
1176
- return void 0;
1275
+ return undefined;
1177
1276
  }
1178
1277
  return result;
1179
1278
  }
@@ -1181,17 +1280,28 @@ function validateObjectSchema(schema, input) {
1181
1280
  if (!isObject(input)) {
1182
1281
  return false;
1183
1282
  }
1184
- const optionalProps = schema.optionalProperties ?? {};
1185
- for (const key of Object.keys(input)) {
1186
- const prop = schema.properties[key] ?? optionalProps[key];
1187
- if (!prop && schema.strict) {
1188
- return false;
1283
+ const allowedKeys = schema.strict ? [] : undefined;
1284
+ for (const key of Object.keys(schema.properties)) {
1285
+ const propSchema = schema.properties[key];
1286
+ const isValid = propSchema.metadata[SCHEMA_METADATA].validate(
1287
+ input[key]
1288
+ );
1289
+ if (!isValid) return false;
1290
+ allowedKeys?.push(key);
1291
+ }
1292
+ if (schema.optionalProperties) {
1293
+ for (const key of Object.keys(schema.optionalProperties)) {
1294
+ const propsSchema = schema.optionalProperties[key];
1295
+ const isValid = propsSchema.metadata[SCHEMA_METADATA].validate(
1296
+ input[key]
1297
+ );
1298
+ if (!isValid) return false;
1299
+ allowedKeys?.push(key);
1189
1300
  }
1190
- if (prop) {
1191
- const isValid = prop.metadata[SCHEMA_METADATA].validate(input[key]);
1192
- if (!isValid) {
1193
- return false;
1194
- }
1301
+ }
1302
+ if (allowedKeys) {
1303
+ for (const key of Object.keys(input)) {
1304
+ if (!allowedKeys.includes(key)) return false;
1195
1305
  }
1196
1306
  }
1197
1307
  return true;
@@ -1223,7 +1333,13 @@ function pick(inputSchema, keys, options = {}) {
1223
1333
  }
1224
1334
  });
1225
1335
  }
1226
- return {
1336
+ const parse = (input, context) => {
1337
+ return parseObjectSchema(schema, input, context, false);
1338
+ };
1339
+ const validate = (input) => {
1340
+ return validateObjectSchema(schema, input);
1341
+ };
1342
+ const result = {
1227
1343
  ...schema,
1228
1344
  metadata: {
1229
1345
  id: options.id,
@@ -1231,14 +1347,7 @@ function pick(inputSchema, keys, options = {}) {
1231
1347
  isDeprecated: options.isDeprecated,
1232
1348
  [SCHEMA_METADATA]: {
1233
1349
  output: {},
1234
- parse: (input, context) => {
1235
- return parseObjectSchema(
1236
- schema,
1237
- input,
1238
- context,
1239
- true
1240
- );
1241
- },
1350
+ parse,
1242
1351
  coerce(input, context) {
1243
1352
  return parseObjectSchema(
1244
1353
  schema,
@@ -1247,15 +1356,16 @@ function pick(inputSchema, keys, options = {}) {
1247
1356
  false
1248
1357
  );
1249
1358
  },
1250
- validate(input) {
1251
- return validateObjectSchema(schema, input);
1252
- },
1359
+ validate,
1253
1360
  serialize(input, context) {
1254
1361
  return serializeObject(schema, input, context);
1255
1362
  }
1256
1363
  }
1257
- }
1364
+ },
1365
+ "~standard": createStandardSchemaProperty(validate, parse)
1258
1366
  };
1367
+ hideInvalidProperties(result);
1368
+ return result;
1259
1369
  }
1260
1370
  function omit(inputSchema, keys, options = {}) {
1261
1371
  const schema = {
@@ -1285,7 +1395,9 @@ function omit(inputSchema, keys, options = {}) {
1285
1395
  }
1286
1396
  });
1287
1397
  }
1288
- return {
1398
+ const validate = (input) => validateObjectSchema(schema, input);
1399
+ const parse = (input, context) => parseObjectSchema(schema, input, context, false);
1400
+ const result = {
1289
1401
  ...schema,
1290
1402
  metadata: {
1291
1403
  id: options.id,
@@ -1293,12 +1405,8 @@ function omit(inputSchema, keys, options = {}) {
1293
1405
  isDeprecated: options.isDeprecated,
1294
1406
  [SCHEMA_METADATA]: {
1295
1407
  output: {},
1296
- validate(input) {
1297
- return validateObjectSchema(schema, input);
1298
- },
1299
- parse(input, data) {
1300
- return parseObjectSchema(schema, input, data, false);
1301
- },
1408
+ validate,
1409
+ parse,
1302
1410
  serialize(input, context) {
1303
1411
  return serializeObject(schema, input, context);
1304
1412
  },
@@ -1311,8 +1419,11 @@ function omit(inputSchema, keys, options = {}) {
1311
1419
  );
1312
1420
  }
1313
1421
  }
1314
- }
1422
+ },
1423
+ "~standard": createStandardSchemaProperty(validate, parse)
1315
1424
  };
1425
+ hideInvalidProperties(result);
1426
+ return result;
1316
1427
  }
1317
1428
  function serializeObject(schema, input, data) {
1318
1429
  const strParts = [];
@@ -1409,23 +1520,20 @@ function partial(schema, options = {}) {
1409
1520
  }
1410
1521
  }
1411
1522
  }
1523
+ const validate = (input) => {
1524
+ return validateObjectSchema(newSchema, input);
1525
+ };
1526
+ const parse = (input, context) => {
1527
+ return parseObjectSchema(newSchema, input, context, false);
1528
+ };
1412
1529
  const meta = {
1413
1530
  id: options.id,
1414
1531
  description: options.description,
1415
1532
  [SCHEMA_METADATA]: {
1416
1533
  output: {},
1417
1534
  optional: schema.metadata[SCHEMA_METADATA].optional,
1418
- validate(input) {
1419
- return validateObjectSchema(newSchema, input);
1420
- },
1421
- parse(input, context) {
1422
- return parseObjectSchema(
1423
- newSchema,
1424
- input,
1425
- context,
1426
- false
1427
- );
1428
- },
1535
+ validate,
1536
+ parse,
1429
1537
  coerce(input, context) {
1430
1538
  return parseObjectSchema(
1431
1539
  newSchema,
@@ -1440,11 +1548,16 @@ function partial(schema, options = {}) {
1440
1548
  }
1441
1549
  };
1442
1550
  newSchema.metadata = meta;
1551
+ newSchema["~standard"] = createStandardSchemaProperty(
1552
+ validate,
1553
+ parse
1554
+ );
1555
+ hideInvalidProperties(newSchema);
1443
1556
  return newSchema;
1444
1557
  }
1445
1558
 
1446
1559
  function string(opts = {}) {
1447
- return {
1560
+ const result = {
1448
1561
  type: "string",
1449
1562
  metadata: {
1450
1563
  id: opts.id,
@@ -1468,8 +1581,11 @@ function string(opts = {}) {
1468
1581
  return JSON.stringify(input);
1469
1582
  }
1470
1583
  }
1471
- }
1584
+ },
1585
+ "~standard": createStandardSchemaProperty(validate$1, parse$2)
1472
1586
  };
1587
+ hideInvalidProperties(result);
1588
+ return result;
1473
1589
  }
1474
1590
  function serializeString(input) {
1475
1591
  if (input.length < 42) {
@@ -1492,7 +1608,7 @@ function parse$2(input, context) {
1492
1608
  schemaPath: `${context.schemaPath}/type`,
1493
1609
  message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
1494
1610
  });
1495
- return void 0;
1611
+ return undefined;
1496
1612
  }
1497
1613
  function coerce$1(input, context) {
1498
1614
  return parse$2(input, context);
@@ -1527,7 +1643,23 @@ function serializeSmallString(input) {
1527
1643
  }
1528
1644
 
1529
1645
  function record(schema, opts = {}) {
1530
- return {
1646
+ const validateFn = (input) => {
1647
+ if (!isObject(input)) {
1648
+ return false;
1649
+ }
1650
+ for (const key of Object.keys(input)) {
1651
+ const val = input[key];
1652
+ const isValid = schema.metadata[SCHEMA_METADATA].validate(val);
1653
+ if (!isValid) {
1654
+ return false;
1655
+ }
1656
+ }
1657
+ return true;
1658
+ };
1659
+ const parseFn = (input, ctx) => {
1660
+ return parse$1(schema, input, ctx, false);
1661
+ };
1662
+ const result = {
1531
1663
  values: schema,
1532
1664
  metadata: {
1533
1665
  id: opts.id,
@@ -1535,35 +1667,21 @@ function record(schema, opts = {}) {
1535
1667
  isDeprecated: opts.isDeprecated,
1536
1668
  [SCHEMA_METADATA]: {
1537
1669
  output: {},
1538
- validate(input) {
1539
- if (!isObject(input)) {
1540
- return false;
1541
- }
1542
- for (const key of Object.keys(input)) {
1543
- const val = input[key];
1544
- const isValid = schema.metadata[SCHEMA_METADATA].validate(val);
1545
- if (!isValid) {
1546
- return false;
1547
- }
1548
- }
1549
- return true;
1550
- },
1551
- parse(input, context) {
1552
- return parse$1(schema, input, context, false);
1553
- },
1670
+ validate: validateFn,
1671
+ parse: parseFn,
1554
1672
  coerce(input, data) {
1555
1673
  return parse$1(schema, input, data, true);
1556
1674
  },
1557
1675
  serialize(input, context) {
1558
- let result = "{";
1676
+ let result2 = "{";
1559
1677
  const keys = Object.keys(input);
1560
1678
  for (let i = 0; i < keys.length; i++) {
1561
1679
  const key = keys[i];
1562
1680
  const val = input[key];
1563
- if (i > 0) result += ",";
1564
- result += serializeString(key);
1565
- result += ":";
1566
- result += schema.metadata[SCHEMA_METADATA].serialize(
1681
+ if (i > 0) result2 += ",";
1682
+ result2 += serializeString(key);
1683
+ result2 += ":";
1684
+ result2 += schema.metadata[SCHEMA_METADATA].serialize(
1567
1685
  val,
1568
1686
  {
1569
1687
  instancePath: `${context.instancePath}/${key}`,
@@ -1572,12 +1690,15 @@ function record(schema, opts = {}) {
1572
1690
  }
1573
1691
  );
1574
1692
  }
1575
- result += "}";
1576
- return result;
1693
+ result2 += "}";
1694
+ return result2;
1577
1695
  }
1578
1696
  }
1579
- }
1697
+ },
1698
+ "~standard": createStandardSchemaProperty(validateFn, parseFn)
1580
1699
  };
1700
+ hideInvalidProperties(result);
1701
+ return result;
1581
1702
  }
1582
1703
  function parse$1(schema, input, data, coerce = false) {
1583
1704
  let parsedInput = input;
@@ -1590,7 +1711,7 @@ function parse$1(schema, input, data, coerce = false) {
1590
1711
  schemaPath: `${data.schemaPath}/values`,
1591
1712
  message: `Error at ${data.instancePath} Expected object`
1592
1713
  });
1593
- return void 0;
1714
+ return undefined;
1594
1715
  }
1595
1716
  const result = {};
1596
1717
  for (const key of Object.keys(parsedInput)) {
@@ -1610,7 +1731,7 @@ function parse$1(schema, input, data, coerce = false) {
1610
1731
  }
1611
1732
  }
1612
1733
  if (data.errors.length) {
1613
- return void 0;
1734
+ return undefined;
1614
1735
  }
1615
1736
  return result;
1616
1737
  }
@@ -1628,36 +1749,43 @@ function recursive(propA, propB) {
1628
1749
  );
1629
1750
  }
1630
1751
  const id = options.id ?? `TypeRef${recursiveTypeCount}`;
1631
- const mainSchema = callback({
1632
- ref: id,
1633
- metadata: {
1634
- [SCHEMA_METADATA]: {
1635
- output: "",
1636
- parse(input, context) {
1637
- if (recursiveFns[id]) {
1638
- return recursiveFns[id].parse(input, context);
1639
- }
1640
- },
1641
- serialize(input, context) {
1642
- if (recursiveFns[id]) {
1643
- return recursiveFns[id].serialize(input, context);
1644
- }
1645
- return "";
1646
- },
1647
- validate(input) {
1648
- if (recursiveFns[id]) {
1649
- return recursiveFns[id].validate(input);
1650
- }
1651
- return false;
1652
- },
1653
- coerce(input, context) {
1654
- if (recursiveFns[id]) {
1655
- return recursiveFns[id].coerce(input, context);
1656
- }
1752
+ const metadata = {
1753
+ [SCHEMA_METADATA]: {
1754
+ output: "",
1755
+ parse(input, context) {
1756
+ if (recursiveFns[id]) {
1757
+ return recursiveFns[id].parse(input, context);
1758
+ }
1759
+ },
1760
+ serialize(input, context) {
1761
+ if (recursiveFns[id]) {
1762
+ return recursiveFns[id].serialize(input, context);
1763
+ }
1764
+ return "";
1765
+ },
1766
+ validate(input) {
1767
+ if (recursiveFns[id]) {
1768
+ return recursiveFns[id].validate(input);
1769
+ }
1770
+ return false;
1771
+ },
1772
+ coerce(input, context) {
1773
+ if (recursiveFns[id]) {
1774
+ return recursiveFns[id].coerce(input, context);
1657
1775
  }
1658
1776
  }
1659
1777
  }
1660
- });
1778
+ };
1779
+ const schema = {
1780
+ ref: id,
1781
+ metadata,
1782
+ "~standard": createStandardSchemaProperty(
1783
+ metadata[SCHEMA_METADATA].validate,
1784
+ metadata[SCHEMA_METADATA].parse
1785
+ )
1786
+ };
1787
+ hideInvalidProperties(schema);
1788
+ const mainSchema = callback(schema);
1661
1789
  mainSchema.metadata.id = id;
1662
1790
  mainSchema.metadata.description = options?.description ?? mainSchema.metadata.description;
1663
1791
  mainSchema.metadata.isDeprecated = options?.isDeprecated ?? mainSchema.metadata.isDeprecated;
@@ -1671,7 +1799,7 @@ function recursive(propA, propB) {
1671
1799
  }
1672
1800
 
1673
1801
  function timestamp(opts = {}) {
1674
- return {
1802
+ const result = {
1675
1803
  type: "timestamp",
1676
1804
  metadata: {
1677
1805
  id: opts.id,
@@ -1684,8 +1812,11 @@ function timestamp(opts = {}) {
1684
1812
  coerce,
1685
1813
  serialize
1686
1814
  }
1687
- }
1815
+ },
1816
+ "~standard": createStandardSchemaProperty(validate, parse)
1688
1817
  };
1818
+ hideInvalidProperties(result);
1819
+ return result;
1689
1820
  }
1690
1821
  function validate(input) {
1691
1822
  return typeof input === "object" && input instanceof Date;
@@ -1702,7 +1833,7 @@ function parse(input, data) {
1702
1833
  instancePath: data.instancePath,
1703
1834
  schemaPath: `${data.schemaPath}/type`
1704
1835
  });
1705
- return void 0;
1836
+ return undefined;
1706
1837
  }
1707
1838
  return new Date(result);
1708
1839
  }
@@ -1711,7 +1842,7 @@ function parse(input, data) {
1711
1842
  instancePath: data.instancePath,
1712
1843
  schemaPath: `${data.schemaPath}/type`
1713
1844
  });
1714
- return void 0;
1845
+ return undefined;
1715
1846
  }
1716
1847
  function coerce(input, options) {
1717
1848
  if (typeof input === "number") {
@@ -1726,4 +1857,4 @@ function serialize(input, data) {
1726
1857
  return `"${input.toISOString()}"`;
1727
1858
  }
1728
1859
 
1729
- export { uint64 as $, enumerator as A, extend as B, float32 as C, float64 as D, int16 as E, int32 as F, int64 as G, int8 as H, nullable as I, number as J, object as K, omit as L, optional as M, parse$4 as N, partial as O, pick as P, record as Q, recursive as R, safeCoerce as S, safeParse as T, serialize$1 as U, ValidationError as V, string as W, stringEnum as X, timestamp as Y, uint16 as Z, uint32 as _, uint8Min as a, uint8 as a0, validate$3 as a1, SCHEMA_METADATA as a2, int64Min as a3, int64Max as a4, uint64Min as a5, uint64Max as a6, parseObjectSchema as a7, validateObjectSchema as a8, serializeObject as a9, serializeString as aa, STR_ESCAPE as ab, serializeSmallString as ac, sanitizeJson as ad, isValidationError as ae, isASchema as af, NumberTypeValues as ag, isObject as ah, uint16Max as b, uint16Min as c, uint32Max as d, uint32Min as e, int8Min as f, int16Max as g, int16Min as h, int8Max as i, int32Max as j, int32Min as k, isAScalarSchema as l, isAObjectSchema as m, isAStringEnumSchema as n, isAAraySchema as o, isARecordSchema as p, isADiscriminatorSchema as q, isARefSchema as r, errors as s, any as t, uint8Max as u, array as v, boolean as w, clone as x, coerce$2 as y, discriminator as z };
1860
+ export { uint32 as $, discriminator as A, enumerator as B, extend as C, float32 as D, float64 as E, int16 as F, int32 as G, int64 as H, int8 as I, nullable as J, number as K, object as L, omit as M, optional as N, parse$4 as O, partial as P, pick as Q, record as R, recursive as S, safeCoerce as T, safeParse as U, ValidationError as V, serialize$1 as W, string as X, stringEnum as Y, timestamp as Z, uint16 as _, uint8Min as a, uint64 as a0, uint8 as a1, validate$3 as a2, SCHEMA_METADATA as a3, int64Min as a4, int64Max as a5, uint64Min as a6, uint64Max as a7, parseObjectSchema as a8, validateObjectSchema as a9, serializeObject as aa, serializeString as ab, STR_ESCAPE as ac, serializeSmallString as ad, sanitizeJson as ae, isValidationError as af, isASchema as ag, NumberTypeValues as ah, isObject as ai, hideInvalidProperties as aj, uint16Max as b, uint16Min as c, uint32Max as d, uint32Min as e, int8Min as f, int16Max as g, int16Min as h, int8Max as i, int32Max as j, int32Min as k, isAScalarSchema as l, isAObjectSchema as m, isAStringEnumSchema as n, isAAraySchema as o, isARecordSchema as p, isADiscriminatorSchema as q, isARefSchema as r, errors as s, createStandardSchemaProperty as t, uint8Max as u, any as v, array as w, boolean as x, clone as y, coerce$2 as z };