@arrirpc/schema 0.78.0 → 0.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -649,7 +649,7 @@ const User = a.object({
649
649
  * Resulting type
650
650
  * {
651
651
  * id: string;
652
- * email: string | undefined;
652
+ * email?: string | undefined;
653
653
  * date: Date;
654
654
  * }
655
655
  */
@@ -697,6 +697,62 @@ const name = a.nullable(a.string());
697
697
  }
698
698
  ```
699
699
 
700
+ ### Undefinable
701
+
702
+ This is similar to `a.optional()` except that when initializing the object the key will still be required.
703
+
704
+ ```ts
705
+ const Foo = a.object({
706
+ foo: a.undefinable(a.string()),
707
+ });
708
+ type Foo = a.infer<typeof Foo>;
709
+
710
+ const fooInstance: Foo = {
711
+ // this field must still be present
712
+ // while with a.optional() we could omit the key
713
+ foo: undefined,
714
+ };
715
+ ```
716
+
717
+ As far as parsing and validating goes this functions exactly the same as `a.optional()`.
718
+
719
+ ```ts
720
+ const User = a.object({
721
+ id: a.string(),
722
+ email: a.undefinable(a.string()),
723
+ date: a.timestamp();
724
+ })
725
+
726
+ /**
727
+ * Resulting type (Notice how the email key is still required)
728
+ * {
729
+ * id: string;
730
+ * email: string | undefined;
731
+ * date: Date;
732
+ * }
733
+ */
734
+ ```
735
+
736
+ **Outputted ATD**
737
+
738
+ ```json
739
+ {
740
+ "properties": {
741
+ "id": {
742
+ "type": "string"
743
+ },
744
+ "date": {
745
+ "type": "timestamp"
746
+ }
747
+ },
748
+ "optionalProperties": {
749
+ "email": {
750
+ "type": "string"
751
+ }
752
+ }
753
+ }
754
+ ```
755
+
700
756
  ### Clone
701
757
 
702
758
  Copy another schema without copying it's metadata using the `a.clone()` helper
@@ -1,11 +1,11 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { V as ValidationContext, A as ASchema } from './shared/schema.hMebmI3A.cjs';
2
+ import { m as ValidationContext, A as ASchema } from './shared/schema.CS4qvHhE.cjs';
3
3
  import '@arrirpc/type-defs';
4
4
 
5
5
  declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined, vendor?: string): StandardSchemaV1<T>['~standard'];
6
6
  /**
7
7
  * Ensure that non ATD compliant properties get hidden when serialized to JSON
8
8
  */
9
- declare function hideInvalidProperties(schema: ASchema): void;
9
+ declare function hideInvalidProperties(schema: ASchema<any, any>): void;
10
10
 
11
11
  export { createStandardSchemaProperty, hideInvalidProperties };
@@ -1,11 +1,11 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { V as ValidationContext, A as ASchema } from './shared/schema.hMebmI3A.mjs';
2
+ import { m as ValidationContext, A as ASchema } from './shared/schema.CS4qvHhE.mjs';
3
3
  import '@arrirpc/type-defs';
4
4
 
5
5
  declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined, vendor?: string): StandardSchemaV1<T>['~standard'];
6
6
  /**
7
7
  * Ensure that non ATD compliant properties get hidden when serialized to JSON
8
8
  */
9
- declare function hideInvalidProperties(schema: ASchema): void;
9
+ declare function hideInvalidProperties(schema: ASchema<any, any>): void;
10
10
 
11
11
  export { createStandardSchemaProperty, hideInvalidProperties };
@@ -1,11 +1,11 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { V as ValidationContext, A as ASchema } from './shared/schema.hMebmI3A.js';
2
+ import { m as ValidationContext, A as ASchema } from './shared/schema.CS4qvHhE.js';
3
3
  import '@arrirpc/type-defs';
4
4
 
5
5
  declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined, vendor?: string): StandardSchemaV1<T>['~standard'];
6
6
  /**
7
7
  * Ensure that non ATD compliant properties get hidden when serialized to JSON
8
8
  */
9
- declare function hideInvalidProperties(schema: ASchema): void;
9
+ declare function hideInvalidProperties(schema: ASchema<any, any>): void;
10
10
 
11
11
  export { createStandardSchemaProperty, hideInvalidProperties };