@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,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const typeDefs = require('@arrirpc/type-defs');
4
+ require('scule');
4
5
 
5
6
  const int8Min = -128;
6
7
  const int8Max = 127;
@@ -69,24 +70,78 @@ function isARefSchema(input) {
69
70
  return isASchema(input) && typeDefs.isSchemaFormRef(input);
70
71
  }
71
72
 
72
- function any(options = {}) {
73
+ function createStandardSchemaProperty(validate, parse) {
73
74
  return {
75
+ version: 1,
76
+ vendor: "arri",
77
+ validate(input) {
78
+ if (validate(input)) {
79
+ return {
80
+ value: input
81
+ };
82
+ }
83
+ const ctx = {
84
+ instancePath: "",
85
+ schemaPath: "",
86
+ errors: []
87
+ };
88
+ try {
89
+ const result = parse(input, ctx);
90
+ if (ctx.errors.length) {
91
+ return {
92
+ issues: ctx.errors.map((err) => ({
93
+ message: err.message ?? "Unknown error",
94
+ path: err.instancePath.split("/").filter((val) => val.length > 0)
95
+ }))
96
+ };
97
+ }
98
+ return {
99
+ value: result
100
+ };
101
+ } catch (err) {
102
+ if (err instanceof ValidationError) {
103
+ return {
104
+ issues: err.errors.map((err2) => ({
105
+ message: err2.message ?? "Unknown error",
106
+ path: err2.instancePath.split("/").filter((item) => item.length > 0)
107
+ }))
108
+ };
109
+ }
110
+ return {
111
+ issues: [
112
+ {
113
+ message: err instanceof Error ? err.message : `${err}`
114
+ }
115
+ ]
116
+ };
117
+ }
118
+ }
119
+ };
120
+ }
121
+ function hideInvalidProperties(schema) {
122
+ Object.defineProperty(schema, "~standard", { enumerable: false });
123
+ }
124
+
125
+ function any(options = {}) {
126
+ const validate = (input) => true;
127
+ const parse = (input, context) => {
128
+ if (context.instancePath.length === 0 && typeof input === "string") {
129
+ try {
130
+ return JSON.parse(input);
131
+ } catch {
132
+ return input;
133
+ }
134
+ }
135
+ return input;
136
+ };
137
+ const result = {
74
138
  metadata: {
75
139
  id: options.id,
76
140
  description: options.description,
77
141
  isDeprecated: options.isDeprecated,
78
142
  [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
- },
143
+ output: undefined,
144
+ parse,
90
145
  coerce: (input, context) => {
91
146
  if (context.instancePath.length === 0 && typeof input === "string") {
92
147
  try {
@@ -97,17 +152,26 @@ function any(options = {}) {
97
152
  }
98
153
  return input;
99
154
  },
100
- validate: (input) => true,
155
+ validate,
101
156
  serialize(input) {
102
157
  return JSON.stringify(input);
103
158
  }
104
159
  }
105
- }
160
+ },
161
+ "~standard": createStandardSchemaProperty(validate, parse)
106
162
  };
163
+ hideInvalidProperties(result);
164
+ return result;
107
165
  }
108
166
 
109
167
  function array(schema, opts = {}) {
110
- return {
168
+ const validateType = (input) => {
169
+ return validate$5(schema, input);
170
+ };
171
+ const parseType = (input, context) => {
172
+ return parse$6(schema, input, context, false);
173
+ };
174
+ const result = {
111
175
  elements: schema,
112
176
  metadata: {
113
177
  id: opts.id,
@@ -115,15 +179,11 @@ function array(schema, opts = {}) {
115
179
  isDeprecated: opts.isDeprecated,
116
180
  [SCHEMA_METADATA]: {
117
181
  output: [],
118
- parse(input, context) {
119
- return parse$6(schema, input, context, false);
120
- },
182
+ parse: parseType,
121
183
  coerce(input, context) {
122
184
  return parse$6(schema, input, context, true);
123
185
  },
124
- validate(input) {
125
- return validate$5(schema, input);
126
- },
186
+ validate: validateType,
127
187
  serialize(input, context) {
128
188
  const strParts = [];
129
189
  for (let i = 0; i < input.length; i++) {
@@ -139,8 +199,11 @@ function array(schema, opts = {}) {
139
199
  return `[${strParts.join(",")}]`;
140
200
  }
141
201
  }
142
- }
202
+ },
203
+ "~standard": createStandardSchemaProperty(validateType, parseType)
143
204
  };
205
+ hideInvalidProperties(result);
206
+ return result;
144
207
  }
145
208
  function validate$5(innerSchema, input) {
146
209
  if (!Array.isArray(input)) {
@@ -165,7 +228,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
165
228
  schemaPath: `${data.schemaPath}/elements`,
166
229
  message: `Error at ${data.instancePath}. Invalid JSON.`
167
230
  });
168
- return void 0;
231
+ return undefined;
169
232
  }
170
233
  }
171
234
  if (!Array.isArray(parsedInput)) {
@@ -174,7 +237,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
174
237
  schemaPath: `${data.schemaPath}/elements`,
175
238
  message: `Error at ${data.instancePath}. Expected array. Got ${typeof input}.`
176
239
  });
177
- return void 0;
240
+ return undefined;
178
241
  }
179
242
  const result = [];
180
243
  for (let i = 0; i < parsedInput.length; i++) {
@@ -202,13 +265,13 @@ function parse$6(innerSchema, input, data, coerce = false) {
202
265
  }
203
266
  }
204
267
  if (data.errors.length) {
205
- return void 0;
268
+ return undefined;
206
269
  }
207
270
  return result;
208
271
  }
209
272
 
210
273
  function boolean(opts = {}) {
211
- return {
274
+ const result = {
212
275
  type: "boolean",
213
276
  metadata: {
214
277
  id: opts.id,
@@ -240,11 +303,14 @@ function boolean(opts = {}) {
240
303
  schemaPath: context.schemaPath,
241
304
  message: `Error at ${context.instancePath}. Unable to coerce ${input} to boolean.`
242
305
  });
243
- return void 0;
306
+ return undefined;
244
307
  }
245
308
  }
246
- }
309
+ },
310
+ "~standard": createStandardSchemaProperty(validate$4, parse$5)
247
311
  };
312
+ hideInvalidProperties(result);
313
+ return result;
248
314
  }
249
315
  function validate$4(input) {
250
316
  return typeof input === "boolean";
@@ -265,14 +331,14 @@ function parse$5(input, data) {
265
331
  schemaPath: `${data.schemaPath}/type`,
266
332
  message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
267
333
  });
268
- return void 0;
334
+ return undefined;
269
335
  }
270
336
  data.errors.push({
271
337
  instancePath: data.instancePath,
272
338
  schemaPath: `${data.schemaPath}/type`,
273
339
  message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
274
340
  });
275
- return void 0;
341
+ return undefined;
276
342
  }
277
343
  function serialize$2(input) {
278
344
  return `${input}`;
@@ -403,7 +469,13 @@ function discriminator(propA, propB, propC) {
403
469
  if (isIdShorthand) {
404
470
  opts.id = propA;
405
471
  }
406
- return {
472
+ const isType = (input) => {
473
+ return validate$2(discriminator2, mapping, input);
474
+ };
475
+ const parseType = (input, context) => {
476
+ return parse$3(discriminator2, mapping, input, context, false);
477
+ };
478
+ const result = {
407
479
  discriminator: discriminator2,
408
480
  mapping,
409
481
  metadata: {
@@ -412,12 +484,8 @@ function discriminator(propA, propB, propC) {
412
484
  isDeprecated: opts.isDeprecated,
413
485
  [SCHEMA_METADATA]: {
414
486
  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
- },
487
+ validate: isType,
488
+ parse: parseType,
421
489
  coerce: (input, context) => {
422
490
  return parse$3(discriminator2, mapping, input, context, true);
423
491
  },
@@ -430,18 +498,21 @@ function discriminator(propA, propB, propC) {
430
498
  context
431
499
  );
432
500
  }
433
- const result = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
501
+ const result2 = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
434
502
  instancePath: context.instancePath,
435
503
  schemaPath: `${context.schemaPath}/mapping/${discriminatorVal}`,
436
504
  errors: context.errors,
437
505
  discriminatorKey: discriminator2,
438
506
  discriminatorValue: discriminatorVal
439
507
  });
440
- return result;
508
+ return result2;
441
509
  }
442
510
  }
443
- }
511
+ },
512
+ "~standard": createStandardSchemaProperty(isType, parseType)
444
513
  };
514
+ hideInvalidProperties(result);
515
+ return result;
445
516
  }
446
517
  function validate$2(discriminator2, mapping, input) {
447
518
  if (!isObject(input)) {
@@ -471,7 +542,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
471
542
  schemaPath: `${data.schemaPath}/discriminator`,
472
543
  message: `Error at ${data.instancePath}. Expected object. Got ${typeof parsedInput}.`
473
544
  });
474
- return void 0;
545
+ return undefined;
475
546
  }
476
547
  if (!(discriminator2 in parsedInput)) {
477
548
  data.errors.push({
@@ -479,7 +550,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
479
550
  schemaPath: `${data.schemaPath}/discriminator`,
480
551
  message: `Error at ${data.instancePath}/${discriminator2}. Discriminator field "${discriminator2}" cannot be undefined`
481
552
  });
482
- return void 0;
553
+ return undefined;
483
554
  }
484
555
  const acceptedDiscriminatorVals = Object.keys(mapping);
485
556
  const discriminatorVal = parsedInput[discriminator2];
@@ -491,7 +562,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
491
562
  ", "
492
563
  )}]`
493
564
  });
494
- return void 0;
565
+ return undefined;
495
566
  }
496
567
  const targetSchema = mapping[parsedInput[discriminator2]];
497
568
  if (!targetSchema) {
@@ -548,7 +619,20 @@ function enumerator(paramA, paramB) {
548
619
  }
549
620
  return false;
550
621
  };
551
- return {
622
+ const parse = (input, context) => {
623
+ if (isType(input)) {
624
+ return input;
625
+ }
626
+ context.errors.push({
627
+ instancePath: context.instancePath,
628
+ schemaPath: `${context.schemaPath}/enum`,
629
+ message: `Error at ${context.instancePath}. Invalid enum value. Expected one of the following values: [${enumVal.join(
630
+ ", "
631
+ )}]`
632
+ });
633
+ return undefined;
634
+ };
635
+ const result = {
552
636
  enum: enumVal,
553
637
  metadata: {
554
638
  id: meta?.id,
@@ -556,19 +640,7 @@ function enumerator(paramA, paramB) {
556
640
  isDeprecated: meta?.isDeprecated,
557
641
  [SCHEMA_METADATA]: {
558
642
  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
- },
643
+ parse,
572
644
  coerce: (input, context) => {
573
645
  if (isType(input)) {
574
646
  return input;
@@ -580,7 +652,7 @@ function enumerator(paramA, paramB) {
580
652
  ", "
581
653
  )}]`
582
654
  });
583
- return void 0;
655
+ return undefined;
584
656
  },
585
657
  validate: isType,
586
658
  serialize(input, context) {
@@ -590,8 +662,11 @@ function enumerator(paramA, paramB) {
590
662
  return `"${input}"`;
591
663
  }
592
664
  }
593
- }
665
+ },
666
+ "~standard": createStandardSchemaProperty(isType, parse)
594
667
  };
668
+ hideInvalidProperties(result);
669
+ return result;
595
670
  }
596
671
 
597
672
  function nullable(schema, opts = {}) {
@@ -601,7 +676,16 @@ function nullable(schema, opts = {}) {
601
676
  }
602
677
  return schema.metadata[SCHEMA_METADATA].validate(val);
603
678
  };
604
- return {
679
+ const parse = (val, data) => {
680
+ if (data.instancePath.length === 0 && typeof val === "string" && val === "null") {
681
+ return null;
682
+ }
683
+ if (val === null) {
684
+ return null;
685
+ }
686
+ return schema.metadata[SCHEMA_METADATA].parse(val, data);
687
+ };
688
+ const result = {
605
689
  ...schema,
606
690
  nullable: true,
607
691
  metadata: {
@@ -612,15 +696,7 @@ function nullable(schema, opts = {}) {
612
696
  output: null,
613
697
  optional: schema.metadata[SCHEMA_METADATA].optional,
614
698
  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
- },
699
+ parse,
624
700
  coerce(val, data) {
625
701
  if (val === null) {
626
702
  return null;
@@ -642,39 +718,42 @@ function nullable(schema, opts = {}) {
642
718
  }
643
719
  }
644
720
  };
721
+ hideInvalidProperties(result);
722
+ return result;
645
723
  }
646
724
  function optional(input, opts = {}) {
647
725
  const isType = (val) => {
648
- if (val === void 0) {
726
+ if (val === undefined) {
649
727
  return true;
650
728
  }
651
729
  return input.metadata[SCHEMA_METADATA].validate(val);
652
730
  };
653
- return {
731
+ const parse = (val, context) => {
732
+ if (typeof val === "undefined") {
733
+ return undefined;
734
+ }
735
+ if (context.instancePath.length === 0 && val === "undefined") {
736
+ return undefined;
737
+ }
738
+ return input.metadata[SCHEMA_METADATA].parse(val, context);
739
+ };
740
+ const result = {
654
741
  ...input,
655
742
  metadata: {
656
743
  id: opts.id ?? input.metadata.id,
657
744
  description: opts.description ?? input.metadata.description,
658
745
  isDeprecated: opts.isDeprecated ?? input.metadata.isDeprecated,
659
746
  [SCHEMA_METADATA]: {
660
- output: void 0,
747
+ output: undefined,
661
748
  optional: true,
662
749
  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
- },
750
+ parse,
672
751
  coerce: (val, data) => {
673
752
  if (typeof val === "undefined") {
674
- return void 0;
753
+ return undefined;
675
754
  }
676
755
  if (val === "undefined") {
677
- return void 0;
756
+ return undefined;
678
757
  }
679
758
  return input.metadata[SCHEMA_METADATA].coerce(val, data);
680
759
  },
@@ -685,8 +764,11 @@ function optional(input, opts = {}) {
685
764
  return input.metadata[SCHEMA_METADATA].serialize(val, data);
686
765
  }
687
766
  }
688
- }
767
+ },
768
+ "~standard": createStandardSchemaProperty(isType, parse)
689
769
  };
770
+ hideInvalidProperties(result);
771
+ return result;
690
772
  }
691
773
  function clone(input, opts = {}) {
692
774
  const schema = {
@@ -698,8 +780,10 @@ function clone(input, opts = {}) {
698
780
  [SCHEMA_METADATA]: {
699
781
  ...input.metadata[SCHEMA_METADATA]
700
782
  }
701
- }
783
+ },
784
+ "~standard": input["~standard"]
702
785
  };
786
+ hideInvalidProperties(schema);
703
787
  return schema;
704
788
  }
705
789
 
@@ -715,7 +799,7 @@ function coerceNumber(input, options) {
715
799
  schemaPath: `${options.schemaPath}/type`,
716
800
  message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} into a number`
717
801
  });
718
- return void 0;
802
+ return undefined;
719
803
  }
720
804
  return parseNumber(parsedInput, options);
721
805
  }
@@ -840,7 +924,7 @@ function int64(opts = {}) {
840
924
  schemaPath: `${data.schemaPath}/type`,
841
925
  instancePath: data.instancePath
842
926
  });
843
- return void 0;
927
+ return undefined;
844
928
  }
845
929
  }
846
930
  if (isType(input)) {
@@ -851,9 +935,9 @@ function int64(opts = {}) {
851
935
  schemaPath: `${data.schemaPath}/type`,
852
936
  instancePath: data.instancePath
853
937
  });
854
- return void 0;
938
+ return undefined;
855
939
  }
856
- return {
940
+ const result = {
857
941
  type: "int64",
858
942
  metadata: {
859
943
  id: opts.id,
@@ -871,8 +955,11 @@ function int64(opts = {}) {
871
955
  return `"${input.toString()}"`;
872
956
  }
873
957
  }
874
- }
958
+ },
959
+ "~standard": createStandardSchemaProperty(isType, parse)
875
960
  };
961
+ hideInvalidProperties(result);
962
+ return result;
876
963
  }
877
964
  function uint64(opts = {}) {
878
965
  function isType(input) {
@@ -897,7 +984,7 @@ function uint64(opts = {}) {
897
984
  schemaPath: `${data.schemaPath}/type`,
898
985
  instancePath: data.instancePath
899
986
  });
900
- return void 0;
987
+ return undefined;
901
988
  }
902
989
  }
903
990
  if (isType(input)) {
@@ -908,9 +995,9 @@ function uint64(opts = {}) {
908
995
  schemaPath: `${data.schemaPath}/type`,
909
996
  instancePath: data.instancePath
910
997
  });
911
- return void 0;
998
+ return undefined;
912
999
  }
913
- return {
1000
+ const result = {
914
1001
  type: "uint64",
915
1002
  metadata: {
916
1003
  id: opts.id,
@@ -928,11 +1015,14 @@ function uint64(opts = {}) {
928
1015
  return `"${input.toString()}"`;
929
1016
  }
930
1017
  }
931
- }
1018
+ },
1019
+ "~standard": createStandardSchemaProperty(isType, parse)
932
1020
  };
1021
+ hideInvalidProperties(result);
1022
+ return result;
933
1023
  }
934
1024
  function validateNumber(input) {
935
- return typeof input === "number" || !Number.isNaN(input);
1025
+ return typeof input === "number";
936
1026
  }
937
1027
  function validateInt(input, minVal, maxValue) {
938
1028
  return Number.isInteger(input) && input >= minVal && input <= maxValue;
@@ -949,7 +1039,7 @@ function parseNumber(input, options) {
949
1039
  schemaPath: `${options.schemaPath}/type`,
950
1040
  message: `Error at ${options.instancePath}. Invalid number.`
951
1041
  });
952
- return void 0;
1042
+ return undefined;
953
1043
  }
954
1044
  return result;
955
1045
  }
@@ -961,10 +1051,41 @@ function parseNumber(input, options) {
961
1051
  schemaPath: `${options.schemaPath}/type`,
962
1052
  message: `Error at ${options.instancePath}. Invalid number.`
963
1053
  });
964
- return void 0;
1054
+ return undefined;
965
1055
  }
966
1056
  function numberScalarType(type, opts, numTypeMatcher) {
967
- return {
1057
+ const validate = (input) => {
1058
+ const isNum = validateNumber(input);
1059
+ if (!isNum) {
1060
+ return false;
1061
+ }
1062
+ return numTypeMatcher(input).success;
1063
+ };
1064
+ const parse = (input, context) => {
1065
+ const result2 = parseNumber(input, context);
1066
+ if (context.errors.length) {
1067
+ return undefined;
1068
+ }
1069
+ if (typeof result2 !== "number") {
1070
+ context?.errors.push({
1071
+ instancePath: context.instancePath,
1072
+ schemaPath: `${context.schemaPath}/type`,
1073
+ message: `Error at ${context.instancePath}. Invalid number.`
1074
+ });
1075
+ return undefined;
1076
+ }
1077
+ const matchResult = numTypeMatcher(result2);
1078
+ if (matchResult.success) {
1079
+ return result2;
1080
+ }
1081
+ context?.errors.push({
1082
+ instancePath: context.instancePath,
1083
+ schemaPath: `${context.schemaPath}/type`,
1084
+ message: `Error at ${context.instancePath}. ${matchResult.message}`
1085
+ });
1086
+ return undefined;
1087
+ };
1088
+ const result = {
968
1089
  type,
969
1090
  metadata: {
970
1091
  id: opts.id,
@@ -972,62 +1093,36 @@ function numberScalarType(type, opts, numTypeMatcher) {
972
1093
  isDeprecated: opts.isDeprecated,
973
1094
  [SCHEMA_METADATA]: {
974
1095
  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
- },
1096
+ validate,
1097
+ parse,
1006
1098
  serialize: serializeNumber,
1007
1099
  coerce(input, options) {
1008
- const result = coerceNumber(input, options);
1009
- if (typeof result !== "number") {
1100
+ const result2 = coerceNumber(input, options);
1101
+ if (typeof result2 !== "number") {
1010
1102
  options.errors.push({
1011
1103
  instancePath: options.instancePath,
1012
1104
  schemaPath: `${options.schemaPath}/type`,
1013
1105
  message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} to ${type}.`
1014
1106
  });
1015
- return void 0;
1107
+ return undefined;
1016
1108
  }
1017
- const matchResult = numTypeMatcher(result);
1109
+ const matchResult = numTypeMatcher(result2);
1018
1110
  if (matchResult.success) {
1019
- return result;
1111
+ return result2;
1020
1112
  }
1021
1113
  options.errors.push({
1022
1114
  instancePath: options.instancePath,
1023
1115
  schemaPath: `${options.schemaPath}/type`,
1024
1116
  message: `Error at ${options.instancePath}. ${matchResult.message}`
1025
1117
  });
1026
- return void 0;
1118
+ return undefined;
1027
1119
  }
1028
1120
  }
1029
- }
1121
+ },
1122
+ "~standard": createStandardSchemaProperty(validate, parse)
1030
1123
  };
1124
+ hideInvalidProperties(result);
1125
+ return result;
1031
1126
  }
1032
1127
 
1033
1128
  function object(propA, propB) {
@@ -1051,6 +1146,17 @@ function object(propA, propB) {
1051
1146
  }
1052
1147
  schema.properties[key] = prop;
1053
1148
  }
1149
+ const validate = (input2) => {
1150
+ return validateObjectSchema(schema, input2);
1151
+ };
1152
+ const parse = (input2, context) => {
1153
+ return parseObjectSchema(
1154
+ schema,
1155
+ input2,
1156
+ context,
1157
+ false
1158
+ );
1159
+ };
1054
1160
  const result = {
1055
1161
  ...schema,
1056
1162
  metadata: {
@@ -1059,14 +1165,7 @@ function object(propA, propB) {
1059
1165
  isDeprecated: options.isDeprecated,
1060
1166
  [SCHEMA_METADATA]: {
1061
1167
  output: {},
1062
- parse(input2, context) {
1063
- return parseObjectSchema(
1064
- schema,
1065
- input2,
1066
- context,
1067
- false
1068
- );
1069
- },
1168
+ parse,
1070
1169
  coerce(input2, context) {
1071
1170
  return parseObjectSchema(
1072
1171
  schema,
@@ -1075,9 +1174,7 @@ function object(propA, propB) {
1075
1174
  true
1076
1175
  );
1077
1176
  },
1078
- validate(input2) {
1079
- return validateObjectSchema(schema, input2);
1080
- },
1177
+ validate,
1081
1178
  serialize(input2, context) {
1082
1179
  return serializeObject(
1083
1180
  schema,
@@ -1086,8 +1183,10 @@ function object(propA, propB) {
1086
1183
  );
1087
1184
  }
1088
1185
  }
1089
- }
1186
+ },
1187
+ "~standard": createStandardSchemaProperty(validate, parse)
1090
1188
  };
1189
+ hideInvalidProperties(result);
1091
1190
  return result;
1092
1191
  }
1093
1192
  function parseObjectSchema(schema, input, data, coerce = false) {
@@ -1102,7 +1201,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1102
1201
  schemaPath: `${data.schemaPath}/properties`,
1103
1202
  message: `Error at ${data.instancePath}. Invalid JSON.`
1104
1203
  });
1105
- return void 0;
1204
+ return undefined;
1106
1205
  }
1107
1206
  }
1108
1207
  if (!isObject(parsedInput)) {
@@ -1111,7 +1210,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1111
1210
  schemaPath: `${data.schemaPath}/properties`,
1112
1211
  message: `Error at ${data.instancePath}. Expected object`
1113
1212
  });
1114
- return void 0;
1213
+ return undefined;
1115
1214
  }
1116
1215
  const result = {};
1117
1216
  const optionalProps = schema.optionalProperties ?? {};
@@ -1130,7 +1229,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1130
1229
  }
1131
1230
  }
1132
1231
  if (data.errors.length) {
1133
- return void 0;
1232
+ return undefined;
1134
1233
  }
1135
1234
  if (data.discriminatorKey) {
1136
1235
  result[data.discriminatorKey] = data.discriminatorValue;
@@ -1155,7 +1254,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1155
1254
  for (const key of optionalKeys) {
1156
1255
  const val = parsedInput[key];
1157
1256
  const prop = optionalProps[key];
1158
- if (val === void 0) {
1257
+ if (val === undefined) {
1159
1258
  continue;
1160
1259
  }
1161
1260
  if (coerce) {
@@ -1175,7 +1274,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
1175
1274
  }
1176
1275
  }
1177
1276
  if (data.errors.length) {
1178
- return void 0;
1277
+ return undefined;
1179
1278
  }
1180
1279
  return result;
1181
1280
  }
@@ -1183,17 +1282,28 @@ function validateObjectSchema(schema, input) {
1183
1282
  if (!isObject(input)) {
1184
1283
  return false;
1185
1284
  }
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;
1285
+ const allowedKeys = schema.strict ? [] : undefined;
1286
+ for (const key of Object.keys(schema.properties)) {
1287
+ const propSchema = schema.properties[key];
1288
+ const isValid = propSchema.metadata[SCHEMA_METADATA].validate(
1289
+ input[key]
1290
+ );
1291
+ if (!isValid) return false;
1292
+ allowedKeys?.push(key);
1293
+ }
1294
+ if (schema.optionalProperties) {
1295
+ for (const key of Object.keys(schema.optionalProperties)) {
1296
+ const propsSchema = schema.optionalProperties[key];
1297
+ const isValid = propsSchema.metadata[SCHEMA_METADATA].validate(
1298
+ input[key]
1299
+ );
1300
+ if (!isValid) return false;
1301
+ allowedKeys?.push(key);
1191
1302
  }
1192
- if (prop) {
1193
- const isValid = prop.metadata[SCHEMA_METADATA].validate(input[key]);
1194
- if (!isValid) {
1195
- return false;
1196
- }
1303
+ }
1304
+ if (allowedKeys) {
1305
+ for (const key of Object.keys(input)) {
1306
+ if (!allowedKeys.includes(key)) return false;
1197
1307
  }
1198
1308
  }
1199
1309
  return true;
@@ -1225,7 +1335,13 @@ function pick(inputSchema, keys, options = {}) {
1225
1335
  }
1226
1336
  });
1227
1337
  }
1228
- return {
1338
+ const parse = (input, context) => {
1339
+ return parseObjectSchema(schema, input, context, false);
1340
+ };
1341
+ const validate = (input) => {
1342
+ return validateObjectSchema(schema, input);
1343
+ };
1344
+ const result = {
1229
1345
  ...schema,
1230
1346
  metadata: {
1231
1347
  id: options.id,
@@ -1233,14 +1349,7 @@ function pick(inputSchema, keys, options = {}) {
1233
1349
  isDeprecated: options.isDeprecated,
1234
1350
  [SCHEMA_METADATA]: {
1235
1351
  output: {},
1236
- parse: (input, context) => {
1237
- return parseObjectSchema(
1238
- schema,
1239
- input,
1240
- context,
1241
- true
1242
- );
1243
- },
1352
+ parse,
1244
1353
  coerce(input, context) {
1245
1354
  return parseObjectSchema(
1246
1355
  schema,
@@ -1249,15 +1358,16 @@ function pick(inputSchema, keys, options = {}) {
1249
1358
  false
1250
1359
  );
1251
1360
  },
1252
- validate(input) {
1253
- return validateObjectSchema(schema, input);
1254
- },
1361
+ validate,
1255
1362
  serialize(input, context) {
1256
1363
  return serializeObject(schema, input, context);
1257
1364
  }
1258
1365
  }
1259
- }
1366
+ },
1367
+ "~standard": createStandardSchemaProperty(validate, parse)
1260
1368
  };
1369
+ hideInvalidProperties(result);
1370
+ return result;
1261
1371
  }
1262
1372
  function omit(inputSchema, keys, options = {}) {
1263
1373
  const schema = {
@@ -1287,7 +1397,9 @@ function omit(inputSchema, keys, options = {}) {
1287
1397
  }
1288
1398
  });
1289
1399
  }
1290
- return {
1400
+ const validate = (input) => validateObjectSchema(schema, input);
1401
+ const parse = (input, context) => parseObjectSchema(schema, input, context, false);
1402
+ const result = {
1291
1403
  ...schema,
1292
1404
  metadata: {
1293
1405
  id: options.id,
@@ -1295,12 +1407,8 @@ function omit(inputSchema, keys, options = {}) {
1295
1407
  isDeprecated: options.isDeprecated,
1296
1408
  [SCHEMA_METADATA]: {
1297
1409
  output: {},
1298
- validate(input) {
1299
- return validateObjectSchema(schema, input);
1300
- },
1301
- parse(input, data) {
1302
- return parseObjectSchema(schema, input, data, false);
1303
- },
1410
+ validate,
1411
+ parse,
1304
1412
  serialize(input, context) {
1305
1413
  return serializeObject(schema, input, context);
1306
1414
  },
@@ -1313,8 +1421,11 @@ function omit(inputSchema, keys, options = {}) {
1313
1421
  );
1314
1422
  }
1315
1423
  }
1316
- }
1424
+ },
1425
+ "~standard": createStandardSchemaProperty(validate, parse)
1317
1426
  };
1427
+ hideInvalidProperties(result);
1428
+ return result;
1318
1429
  }
1319
1430
  function serializeObject(schema, input, data) {
1320
1431
  const strParts = [];
@@ -1411,23 +1522,20 @@ function partial(schema, options = {}) {
1411
1522
  }
1412
1523
  }
1413
1524
  }
1525
+ const validate = (input) => {
1526
+ return validateObjectSchema(newSchema, input);
1527
+ };
1528
+ const parse = (input, context) => {
1529
+ return parseObjectSchema(newSchema, input, context, false);
1530
+ };
1414
1531
  const meta = {
1415
1532
  id: options.id,
1416
1533
  description: options.description,
1417
1534
  [SCHEMA_METADATA]: {
1418
1535
  output: {},
1419
1536
  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
- },
1537
+ validate,
1538
+ parse,
1431
1539
  coerce(input, context) {
1432
1540
  return parseObjectSchema(
1433
1541
  newSchema,
@@ -1442,11 +1550,16 @@ function partial(schema, options = {}) {
1442
1550
  }
1443
1551
  };
1444
1552
  newSchema.metadata = meta;
1553
+ newSchema["~standard"] = createStandardSchemaProperty(
1554
+ validate,
1555
+ parse
1556
+ );
1557
+ hideInvalidProperties(newSchema);
1445
1558
  return newSchema;
1446
1559
  }
1447
1560
 
1448
1561
  function string(opts = {}) {
1449
- return {
1562
+ const result = {
1450
1563
  type: "string",
1451
1564
  metadata: {
1452
1565
  id: opts.id,
@@ -1470,8 +1583,11 @@ function string(opts = {}) {
1470
1583
  return JSON.stringify(input);
1471
1584
  }
1472
1585
  }
1473
- }
1586
+ },
1587
+ "~standard": createStandardSchemaProperty(validate$1, parse$2)
1474
1588
  };
1589
+ hideInvalidProperties(result);
1590
+ return result;
1475
1591
  }
1476
1592
  function serializeString(input) {
1477
1593
  if (input.length < 42) {
@@ -1494,7 +1610,7 @@ function parse$2(input, context) {
1494
1610
  schemaPath: `${context.schemaPath}/type`,
1495
1611
  message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
1496
1612
  });
1497
- return void 0;
1613
+ return undefined;
1498
1614
  }
1499
1615
  function coerce$1(input, context) {
1500
1616
  return parse$2(input, context);
@@ -1529,7 +1645,23 @@ function serializeSmallString(input) {
1529
1645
  }
1530
1646
 
1531
1647
  function record(schema, opts = {}) {
1532
- return {
1648
+ const validateFn = (input) => {
1649
+ if (!isObject(input)) {
1650
+ return false;
1651
+ }
1652
+ for (const key of Object.keys(input)) {
1653
+ const val = input[key];
1654
+ const isValid = schema.metadata[SCHEMA_METADATA].validate(val);
1655
+ if (!isValid) {
1656
+ return false;
1657
+ }
1658
+ }
1659
+ return true;
1660
+ };
1661
+ const parseFn = (input, ctx) => {
1662
+ return parse$1(schema, input, ctx, false);
1663
+ };
1664
+ const result = {
1533
1665
  values: schema,
1534
1666
  metadata: {
1535
1667
  id: opts.id,
@@ -1537,35 +1669,21 @@ function record(schema, opts = {}) {
1537
1669
  isDeprecated: opts.isDeprecated,
1538
1670
  [SCHEMA_METADATA]: {
1539
1671
  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
- },
1672
+ validate: validateFn,
1673
+ parse: parseFn,
1556
1674
  coerce(input, data) {
1557
1675
  return parse$1(schema, input, data, true);
1558
1676
  },
1559
1677
  serialize(input, context) {
1560
- let result = "{";
1678
+ let result2 = "{";
1561
1679
  const keys = Object.keys(input);
1562
1680
  for (let i = 0; i < keys.length; i++) {
1563
1681
  const key = keys[i];
1564
1682
  const val = input[key];
1565
- if (i > 0) result += ",";
1566
- result += serializeString(key);
1567
- result += ":";
1568
- result += schema.metadata[SCHEMA_METADATA].serialize(
1683
+ if (i > 0) result2 += ",";
1684
+ result2 += serializeString(key);
1685
+ result2 += ":";
1686
+ result2 += schema.metadata[SCHEMA_METADATA].serialize(
1569
1687
  val,
1570
1688
  {
1571
1689
  instancePath: `${context.instancePath}/${key}`,
@@ -1574,12 +1692,15 @@ function record(schema, opts = {}) {
1574
1692
  }
1575
1693
  );
1576
1694
  }
1577
- result += "}";
1578
- return result;
1695
+ result2 += "}";
1696
+ return result2;
1579
1697
  }
1580
1698
  }
1581
- }
1699
+ },
1700
+ "~standard": createStandardSchemaProperty(validateFn, parseFn)
1582
1701
  };
1702
+ hideInvalidProperties(result);
1703
+ return result;
1583
1704
  }
1584
1705
  function parse$1(schema, input, data, coerce = false) {
1585
1706
  let parsedInput = input;
@@ -1592,7 +1713,7 @@ function parse$1(schema, input, data, coerce = false) {
1592
1713
  schemaPath: `${data.schemaPath}/values`,
1593
1714
  message: `Error at ${data.instancePath} Expected object`
1594
1715
  });
1595
- return void 0;
1716
+ return undefined;
1596
1717
  }
1597
1718
  const result = {};
1598
1719
  for (const key of Object.keys(parsedInput)) {
@@ -1612,7 +1733,7 @@ function parse$1(schema, input, data, coerce = false) {
1612
1733
  }
1613
1734
  }
1614
1735
  if (data.errors.length) {
1615
- return void 0;
1736
+ return undefined;
1616
1737
  }
1617
1738
  return result;
1618
1739
  }
@@ -1630,36 +1751,43 @@ function recursive(propA, propB) {
1630
1751
  );
1631
1752
  }
1632
1753
  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
- }
1754
+ const metadata = {
1755
+ [SCHEMA_METADATA]: {
1756
+ output: "",
1757
+ parse(input, context) {
1758
+ if (recursiveFns[id]) {
1759
+ return recursiveFns[id].parse(input, context);
1760
+ }
1761
+ },
1762
+ serialize(input, context) {
1763
+ if (recursiveFns[id]) {
1764
+ return recursiveFns[id].serialize(input, context);
1765
+ }
1766
+ return "";
1767
+ },
1768
+ validate(input) {
1769
+ if (recursiveFns[id]) {
1770
+ return recursiveFns[id].validate(input);
1771
+ }
1772
+ return false;
1773
+ },
1774
+ coerce(input, context) {
1775
+ if (recursiveFns[id]) {
1776
+ return recursiveFns[id].coerce(input, context);
1659
1777
  }
1660
1778
  }
1661
1779
  }
1662
- });
1780
+ };
1781
+ const schema = {
1782
+ ref: id,
1783
+ metadata,
1784
+ "~standard": createStandardSchemaProperty(
1785
+ metadata[SCHEMA_METADATA].validate,
1786
+ metadata[SCHEMA_METADATA].parse
1787
+ )
1788
+ };
1789
+ hideInvalidProperties(schema);
1790
+ const mainSchema = callback(schema);
1663
1791
  mainSchema.metadata.id = id;
1664
1792
  mainSchema.metadata.description = options?.description ?? mainSchema.metadata.description;
1665
1793
  mainSchema.metadata.isDeprecated = options?.isDeprecated ?? mainSchema.metadata.isDeprecated;
@@ -1673,7 +1801,7 @@ function recursive(propA, propB) {
1673
1801
  }
1674
1802
 
1675
1803
  function timestamp(opts = {}) {
1676
- return {
1804
+ const result = {
1677
1805
  type: "timestamp",
1678
1806
  metadata: {
1679
1807
  id: opts.id,
@@ -1686,8 +1814,11 @@ function timestamp(opts = {}) {
1686
1814
  coerce,
1687
1815
  serialize
1688
1816
  }
1689
- }
1817
+ },
1818
+ "~standard": createStandardSchemaProperty(validate, parse)
1690
1819
  };
1820
+ hideInvalidProperties(result);
1821
+ return result;
1691
1822
  }
1692
1823
  function validate(input) {
1693
1824
  return typeof input === "object" && input instanceof Date;
@@ -1704,7 +1835,7 @@ function parse(input, data) {
1704
1835
  instancePath: data.instancePath,
1705
1836
  schemaPath: `${data.schemaPath}/type`
1706
1837
  });
1707
- return void 0;
1838
+ return undefined;
1708
1839
  }
1709
1840
  return new Date(result);
1710
1841
  }
@@ -1713,7 +1844,7 @@ function parse(input, data) {
1713
1844
  instancePath: data.instancePath,
1714
1845
  schemaPath: `${data.schemaPath}/type`
1715
1846
  });
1716
- return void 0;
1847
+ return undefined;
1717
1848
  }
1718
1849
  function coerce(input, options) {
1719
1850
  if (typeof input === "number") {
@@ -1737,12 +1868,14 @@ exports.array = array;
1737
1868
  exports.boolean = boolean;
1738
1869
  exports.clone = clone;
1739
1870
  exports.coerce = coerce$2;
1871
+ exports.createStandardSchemaProperty = createStandardSchemaProperty;
1740
1872
  exports.discriminator = discriminator;
1741
1873
  exports.enumerator = enumerator;
1742
1874
  exports.errors = errors;
1743
1875
  exports.extend = extend;
1744
1876
  exports.float32 = float32;
1745
1877
  exports.float64 = float64;
1878
+ exports.hideInvalidProperties = hideInvalidProperties;
1746
1879
  exports.int16 = int16;
1747
1880
  exports.int16Max = int16Max;
1748
1881
  exports.int16Min = int16Min;