@infra-blocks/zod-utils 0.9.0 → 0.10.0-alpha.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.
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # ts-zod-utils
2
2
  [![Build](https://github.com/infra-blocks/ts-zod-utils/actions/workflows/build.yml/badge.svg)](https://github.com/infra-blocks/ts-zod-utils/actions/workflows/build.yml)
3
3
  [![Release](https://github.com/infra-blocks/ts-zod-utils/actions/workflows/release.yml/badge.svg)](https://github.com/infra-blocks/ts-zod-utils/actions/workflows/release.yml)
4
- [![Update From Template](https://github.com/infra-blocks/ts-zod-utils/actions/workflows/update-from-template.yml/badge.svg)](https://github.com/infra-blocks/ts-zod-utils/actions/workflows/update-from-template.yml)
5
4
  [![codecov](https://codecov.io/gh/infra-blocks/ts-zod-utils/graph/badge.svg?token=Q9ZLX7AMPH)](https://codecov.io/gh/infra-blocks/ts-zod-utils)
6
5
 
7
6
  This package exposes various utilities extending the [zod](https://www.npmjs.com/package/zod) package.
@@ -13,7 +12,7 @@ This package exposes various utilities extending the [zod](https://www.npmjs.com
13
12
  - [json](#json)
14
13
  - [csv](#csv)
15
14
  - [typeGuard](#type-guard)
16
- - [validate](#validate)
15
+ - [isValid](#is-valid)
17
16
 
18
17
  ### AWS
19
18
 
@@ -33,6 +32,25 @@ zu.aws.partition().parse("aws");
33
32
  zu.aws.region().parse("us-east-1");
34
33
  ```
35
34
 
35
+ #### Branded types
36
+
37
+ `aws` utilities that return primitive types are branded. Here is an example with an AWS arn:
38
+
39
+ ```typescript
40
+ import { zu } from "@infra-blocks/zod-utils";
41
+ import { AwsArn } from "@infra-blocks/zod-utils/aws";
42
+
43
+ const arn = zu.aws.arn().parse("arn:aws:iam:us-east-1:123456789012:user/joe-cunt"); // The type of arn is AwsArn.
44
+ const splitTokensString = (x: string) => x.split(":");
45
+ // AwsArn is an alias for string & z.$brand<"AwsArn">. All string functionalities are still available.
46
+ splitTokensString(arn);
47
+ const splitTokensArn = (x: AwsArn) => x.split(":");
48
+ // Works as you'd expect.
49
+ splitTokensArn(arn);
50
+ // @ts-expect-error: string is not assignable to AwsArn
51
+ splitTokensArn("arn:aws:iam:us-east-1:123456789012:user/joe-cunt"); // This does not compile, as string is not assignable to AwsArn.
52
+ ```
53
+
36
54
  ### GeoJson
37
55
 
38
56
  The `geojson` module contains utilities to validate GeoJSON objects.
@@ -285,8 +303,8 @@ not as strong. In our specific case, the type guard would assert that `myString`
285
303
  despite the fact that it also checked that its length has to be greater than 5. That information
286
304
  has been lost.
287
305
 
288
- ### Validate
306
+ ### Is Valid
289
307
 
290
- The validate API is very similar to the [type guard](#type-guard) one, except it doesn't bind
308
+ The `isValid` API is very similar to the [type guard](#type-guard) one, except it doesn't bind
291
309
  to a schema. The schema is passed as argument. Where you would write `zu.typeGuard(schema)(value)`,
292
- you instead write `zu.validate(schema, value)`. Both behave the same.
310
+ you instead write `zu.isValid(schema, value)`. Both behave the same and narrow the result type.
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodString, "AwsAccountId">;
3
+ export type AwsAccountId = z.infer<typeof schema>;
2
4
  /**
3
5
  * Validates that a string is a valid AWS account ID.
4
6
  *
@@ -10,4 +12,5 @@ import { z } from "zod";
10
12
  *
11
13
  * @see https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html
12
14
  */
13
- export declare function accountId(): z.ZodString;
15
+ export declare function accountId(): z.core.$ZodBranded<z.ZodString, "AwsAccountId">;
16
+ export {};
@@ -2,7 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.accountId = accountId;
4
4
  const zod_1 = require("zod");
5
- const schema = zod_1.z.string().regex(zod_1.z.regexes.integer).length(12);
5
+ const schema = zod_1.z
6
+ .string()
7
+ .regex(zod_1.z.regexes.integer)
8
+ .length(12)
9
+ .brand("AwsAccountId");
6
10
  /**
7
11
  * Validates that a string is a valid AWS account ID.
8
12
  *
@@ -1 +1 @@
1
- {"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../../src/aws/account-id.ts"],"names":[],"mappings":";;AAeA,8BAEC;AAjBD,6BAAwB;AAExB,MAAM,MAAM,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,SAAgB,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../../src/aws/account-id.ts"],"names":[],"mappings":";;AAqBA,8BAEC;AAvBD,6BAAwB;AAExB,MAAM,MAAM,GAAG,OAAC;KACb,MAAM,EAAE;KACR,KAAK,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC;KACxB,MAAM,CAAC,EAAE,CAAC;KACV,KAAK,CAAC,cAAc,CAAC,CAAC;AAIzB;;;;;;;;;;GAUG;AACH,SAAgB,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodString, "AwsArn">;
3
+ export type AwsArn = z.infer<typeof schema>;
2
4
  /**
3
5
  * Validates that a string is a valid AWS ARN.
4
6
  *
@@ -15,4 +17,5 @@ import { z } from "zod";
15
17
  *
16
18
  * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
17
19
  */
18
- export declare function arn(): z.ZodString;
20
+ export declare function arn(): z.core.$ZodBranded<z.ZodString, "AwsArn">;
21
+ export {};
@@ -32,7 +32,10 @@ function isValid(arn) {
32
32
  }
33
33
  return true;
34
34
  }
35
- const schema = zod_1.z.string().refine(isValid, { error: "invalid AWS ARN" });
35
+ const schema = zod_1.z
36
+ .string()
37
+ .refine(isValid, { error: "invalid AWS ARN" })
38
+ .brand("AwsArn");
36
39
  /**
37
40
  * Validates that a string is a valid AWS ARN.
38
41
  *
@@ -1 +1 @@
1
- {"version":3,"file":"arn.js","sourceRoot":"","sources":["../../../src/aws/arn.ts"],"names":[],"mappings":";;AA2DA,kBAEC;AA7DD,6BAAwB;AACxB,0CAAiC;AAEjC,SAAS,OAAO,CAAC,GAAW;IAC1B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE7B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,aAAE,CAAC,OAAO,CAAC,aAAE,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,+BAA+B;IAC/B,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,wBAAwB;IACxB,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,aAAE,CAAC,OAAO,CAAC,aAAE,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4BAA4B;IAC5B,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,aAAE,CAAC,OAAO,CAAC,aAAE,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oCAAoC;IACpC,IAAI,KAA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IACf,CAAC;IAED,4BAA4B;IAC5B,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,aAAE,CAAC,OAAO,CAAC,aAAE,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oCAAoC;IACpC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,MAAM,GAAG,OAAC;KACb,MAAM,EAAE;KACR,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;KAC7C,KAAK,CAAC,QAAQ,CAAC,CAAC;AAInB;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,GAAG;IACjB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +1,8 @@
1
1
  import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodEnum<{
3
+ [x: string]: string;
4
+ }>, "AwsPartition">;
5
+ export type AwsPartition = z.infer<typeof schema>;
2
6
  /**
3
7
  * Validates that a string is a valid AWS partition.
4
8
  *
@@ -9,6 +13,7 @@ import { z } from "zod";
9
13
  *
10
14
  * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
11
15
  */
12
- export declare function partition(): z.ZodEnum<{
16
+ export declare function partition(): z.core.$ZodBranded<z.ZodEnum<{
13
17
  [x: string]: string;
14
- }>;
18
+ }>, "AwsPartition">;
19
+ export {};
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.partition = partition;
4
4
  const zod_1 = require("zod");
5
5
  const AWS_PARTITIONS = ["aws", "aws-cn", "aws-us-gov"];
6
- const schema = zod_1.z.enum(AWS_PARTITIONS);
6
+ const schema = zod_1.z.enum(AWS_PARTITIONS).brand("AwsPartition");
7
7
  /**
8
8
  * Validates that a string is a valid AWS partition.
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"partition.js","sourceRoot":"","sources":["../../../src/aws/partition.ts"],"names":[],"mappings":";;AAgBA,8BAEC;AAlBD,6BAAwB;AAExB,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAEvD,MAAM,MAAM,GAAG,OAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAEtC;;;;;;;;;GASG;AACH,SAAgB,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"partition.js","sourceRoot":"","sources":["../../../src/aws/partition.ts"],"names":[],"mappings":";;AAkBA,8BAEC;AApBD,6BAAwB;AAExB,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAEvD,MAAM,MAAM,GAAG,OAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAI5D;;;;;;;;;GASG;AACH,SAAgB,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +1,45 @@
1
1
  import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodEnum<{
3
+ "us-east-1": "us-east-1";
4
+ "us-east-2": "us-east-2";
5
+ "us-west-1": "us-west-1";
6
+ "us-west-2": "us-west-2";
7
+ "af-south-1": "af-south-1";
8
+ "ap-east-1": "ap-east-1";
9
+ "ap-east-2": "ap-east-2";
10
+ "ap-south-1": "ap-south-1";
11
+ "ap-south-2": "ap-south-2";
12
+ "ap-southeast-1": "ap-southeast-1";
13
+ "ap-southeast-2": "ap-southeast-2";
14
+ "ap-southeast-3": "ap-southeast-3";
15
+ "ap-southeast-4": "ap-southeast-4";
16
+ "ap-southeast-5": "ap-southeast-5";
17
+ "ap-southeast-6": "ap-southeast-6";
18
+ "ap-southeast-7": "ap-southeast-7";
19
+ "ap-northeast-1": "ap-northeast-1";
20
+ "ap-northeast-2": "ap-northeast-2";
21
+ "ap-northeast-3": "ap-northeast-3";
22
+ "ca-central-1": "ca-central-1";
23
+ "ca-west-1": "ca-west-1";
24
+ "cn-north-1": "cn-north-1";
25
+ "cn-northwest-1": "cn-northwest-1";
26
+ "eu-central-1": "eu-central-1";
27
+ "eu-central-2": "eu-central-2";
28
+ "eu-west-1": "eu-west-1";
29
+ "eu-west-2": "eu-west-2";
30
+ "eu-west-3": "eu-west-3";
31
+ "eu-south-1": "eu-south-1";
32
+ "eu-south-2": "eu-south-2";
33
+ "eu-north-1": "eu-north-1";
34
+ "il-central-1": "il-central-1";
35
+ "mx-central-1": "mx-central-1";
36
+ "me-central-1": "me-central-1";
37
+ "me-south-1": "me-south-1";
38
+ "sa-east-1": "sa-east-1";
39
+ "us-gov-east-1": "us-gov-east-1";
40
+ "us-gov-west-1": "us-gov-west-1";
41
+ }>, "AwsRegion">;
42
+ export type AwsRegion = z.infer<typeof schema>;
2
43
  /**
3
44
  * Validates that a string is a valid AWS region.
4
45
  *
@@ -7,7 +48,7 @@ import { z } from "zod";
7
48
  *
8
49
  * @returns A schema that validates AWS regions.
9
50
  */
10
- export declare function region(): z.ZodEnum<{
51
+ export declare function region(): z.core.$ZodBranded<z.ZodEnum<{
11
52
  "us-east-1": "us-east-1";
12
53
  "us-east-2": "us-east-2";
13
54
  "us-west-1": "us-west-1";
@@ -46,4 +87,5 @@ export declare function region(): z.ZodEnum<{
46
87
  "sa-east-1": "sa-east-1";
47
88
  "us-gov-east-1": "us-gov-east-1";
48
89
  "us-gov-west-1": "us-gov-west-1";
49
- }>;
90
+ }>, "AwsRegion">;
91
+ export {};
@@ -42,7 +42,7 @@ const AWS_REGIONS = [
42
42
  "us-gov-east-1",
43
43
  "us-gov-west-1",
44
44
  ];
45
- const schema = zod_1.z.enum(AWS_REGIONS);
45
+ const schema = zod_1.z.enum(AWS_REGIONS).brand("AwsRegion");
46
46
  /**
47
47
  * Validates that a string is a valid AWS region.
48
48
  *
@@ -1 +1 @@
1
- {"version":3,"file":"region.js","sourceRoot":"","sources":["../../../src/aws/region.ts"],"names":[],"mappings":";;AAqDA,wBAEC;AAvDD,6BAAwB;AAExB,MAAM,WAAW,GAAG;IAClB,WAAW;IACX,WAAW;IACX,WAAW;IACX,WAAW;IACX,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,cAAc;IACd,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,cAAc;IACd,WAAW;IACX,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,cAAc;IACd,cAAc;IACd,YAAY;IACZ,WAAW;IACX,eAAe;IACf,eAAe;CACP,CAAC;AAEX,MAAM,MAAM,GAAG,OAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAEnC;;;;;;;GAOG;AACH,SAAgB,MAAM;IACpB,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"region.js","sourceRoot":"","sources":["../../../src/aws/region.ts"],"names":[],"mappings":";;AAuDA,wBAEC;AAzDD,6BAAwB;AAExB,MAAM,WAAW,GAAG;IAClB,WAAW;IACX,WAAW;IACX,WAAW;IACX,WAAW;IACX,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,cAAc;IACd,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,cAAc;IACd,WAAW;IACX,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,cAAc;IACd,cAAc;IACd,YAAY;IACZ,WAAW;IACX,eAAe;IACf,eAAe;CACP,CAAC;AAEX,MAAM,MAAM,GAAG,OAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAItD;;;;;;;GAOG;AACH,SAAgB,MAAM;IACpB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type { AwsAccountId } from "./account-id.js";
2
+ export type { AwsArn } from "./arn.js";
3
+ export type { AwsPartition } from "./partition.js";
4
+ export type { AwsRegion } from "./region.js";
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/aws/types.ts"],"names":[],"mappings":""}
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodString, "AwsAccountId">;
3
+ export type AwsAccountId = z.infer<typeof schema>;
2
4
  /**
3
5
  * Validates that a string is a valid AWS account ID.
4
6
  *
@@ -10,4 +12,5 @@ import { z } from "zod";
10
12
  *
11
13
  * @see https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html
12
14
  */
13
- export declare function accountId(): z.ZodString;
15
+ export declare function accountId(): z.core.$ZodBranded<z.ZodString, "AwsAccountId">;
16
+ export {};
@@ -1,5 +1,9 @@
1
1
  import { z } from "zod";
2
- const schema = z.string().regex(z.regexes.integer).length(12);
2
+ const schema = z
3
+ .string()
4
+ .regex(z.regexes.integer)
5
+ .length(12)
6
+ .brand("AwsAccountId");
3
7
  /**
4
8
  * Validates that a string is a valid AWS account ID.
5
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../../src/aws/account-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../../src/aws/account-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,GAAG,CAAC;KACb,MAAM,EAAE;KACR,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;KACxB,MAAM,CAAC,EAAE,CAAC;KACV,KAAK,CAAC,cAAc,CAAC,CAAC;AAIzB;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodString, "AwsArn">;
3
+ export type AwsArn = z.infer<typeof schema>;
2
4
  /**
3
5
  * Validates that a string is a valid AWS ARN.
4
6
  *
@@ -15,4 +17,5 @@ import { z } from "zod";
15
17
  *
16
18
  * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
17
19
  */
18
- export declare function arn(): z.ZodString;
20
+ export declare function arn(): z.core.$ZodBranded<z.ZodString, "AwsArn">;
21
+ export {};
@@ -29,7 +29,10 @@ function isValid(arn) {
29
29
  }
30
30
  return true;
31
31
  }
32
- const schema = z.string().refine(isValid, { error: "invalid AWS ARN" });
32
+ const schema = z
33
+ .string()
34
+ .refine(isValid, { error: "invalid AWS ARN" })
35
+ .brand("AwsArn");
33
36
  /**
34
37
  * Validates that a string is a valid AWS ARN.
35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AAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4BAA4B;IAC5B,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oCAAoC;IACpC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,MAAM,GAAG,CAAC;KACb,MAAM,EAAE;KACR,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;KAC7C,KAAK,CAAC,QAAQ,CAAC,CAAC;AAInB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +1,8 @@
1
1
  import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodEnum<{
3
+ [x: string]: string;
4
+ }>, "AwsPartition">;
5
+ export type AwsPartition = z.infer<typeof schema>;
2
6
  /**
3
7
  * Validates that a string is a valid AWS partition.
4
8
  *
@@ -9,6 +13,7 @@ import { z } from "zod";
9
13
  *
10
14
  * @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
11
15
  */
12
- export declare function partition(): z.ZodEnum<{
16
+ export declare function partition(): z.core.$ZodBranded<z.ZodEnum<{
13
17
  [x: string]: string;
14
- }>;
18
+ }>, "AwsPartition">;
19
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  const AWS_PARTITIONS = ["aws", "aws-cn", "aws-us-gov"];
3
- const schema = z.enum(AWS_PARTITIONS);
3
+ const schema = z.enum(AWS_PARTITIONS).brand("AwsPartition");
4
4
  /**
5
5
  * Validates that a string is a valid AWS partition.
6
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"partition.js","sourceRoot":"","sources":["../../../src/aws/partition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAEvD,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAEtC;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"partition.js","sourceRoot":"","sources":["../../../src/aws/partition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAEvD,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAI5D;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +1,45 @@
1
1
  import { z } from "zod";
2
+ declare const schema: z.core.$ZodBranded<z.ZodEnum<{
3
+ "us-east-1": "us-east-1";
4
+ "us-east-2": "us-east-2";
5
+ "us-west-1": "us-west-1";
6
+ "us-west-2": "us-west-2";
7
+ "af-south-1": "af-south-1";
8
+ "ap-east-1": "ap-east-1";
9
+ "ap-east-2": "ap-east-2";
10
+ "ap-south-1": "ap-south-1";
11
+ "ap-south-2": "ap-south-2";
12
+ "ap-southeast-1": "ap-southeast-1";
13
+ "ap-southeast-2": "ap-southeast-2";
14
+ "ap-southeast-3": "ap-southeast-3";
15
+ "ap-southeast-4": "ap-southeast-4";
16
+ "ap-southeast-5": "ap-southeast-5";
17
+ "ap-southeast-6": "ap-southeast-6";
18
+ "ap-southeast-7": "ap-southeast-7";
19
+ "ap-northeast-1": "ap-northeast-1";
20
+ "ap-northeast-2": "ap-northeast-2";
21
+ "ap-northeast-3": "ap-northeast-3";
22
+ "ca-central-1": "ca-central-1";
23
+ "ca-west-1": "ca-west-1";
24
+ "cn-north-1": "cn-north-1";
25
+ "cn-northwest-1": "cn-northwest-1";
26
+ "eu-central-1": "eu-central-1";
27
+ "eu-central-2": "eu-central-2";
28
+ "eu-west-1": "eu-west-1";
29
+ "eu-west-2": "eu-west-2";
30
+ "eu-west-3": "eu-west-3";
31
+ "eu-south-1": "eu-south-1";
32
+ "eu-south-2": "eu-south-2";
33
+ "eu-north-1": "eu-north-1";
34
+ "il-central-1": "il-central-1";
35
+ "mx-central-1": "mx-central-1";
36
+ "me-central-1": "me-central-1";
37
+ "me-south-1": "me-south-1";
38
+ "sa-east-1": "sa-east-1";
39
+ "us-gov-east-1": "us-gov-east-1";
40
+ "us-gov-west-1": "us-gov-west-1";
41
+ }>, "AwsRegion">;
42
+ export type AwsRegion = z.infer<typeof schema>;
2
43
  /**
3
44
  * Validates that a string is a valid AWS region.
4
45
  *
@@ -7,7 +48,7 @@ import { z } from "zod";
7
48
  *
8
49
  * @returns A schema that validates AWS regions.
9
50
  */
10
- export declare function region(): z.ZodEnum<{
51
+ export declare function region(): z.core.$ZodBranded<z.ZodEnum<{
11
52
  "us-east-1": "us-east-1";
12
53
  "us-east-2": "us-east-2";
13
54
  "us-west-1": "us-west-1";
@@ -46,4 +87,5 @@ export declare function region(): z.ZodEnum<{
46
87
  "sa-east-1": "sa-east-1";
47
88
  "us-gov-east-1": "us-gov-east-1";
48
89
  "us-gov-west-1": "us-gov-west-1";
49
- }>;
90
+ }>, "AwsRegion">;
91
+ export {};
@@ -39,7 +39,7 @@ const AWS_REGIONS = [
39
39
  "us-gov-east-1",
40
40
  "us-gov-west-1",
41
41
  ];
42
- const schema = z.enum(AWS_REGIONS);
42
+ const schema = z.enum(AWS_REGIONS).brand("AwsRegion");
43
43
  /**
44
44
  * Validates that a string is a valid AWS region.
45
45
  *
@@ -1 +1 @@
1
- {"version":3,"file":"region.js","sourceRoot":"","sources":["../../../src/aws/region.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,GAAG;IAClB,WAAW;IACX,WAAW;IACX,WAAW;IACX,WAAW;IACX,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,cAAc;IACd,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,cAAc;IACd,WAAW;IACX,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,cAAc;IACd,cAAc;IACd,YAAY;IACZ,WAAW;IACX,eAAe;IACf,eAAe;CACP,CAAC;AAEX,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"region.js","sourceRoot":"","sources":["../../../src/aws/region.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,GAAG;IAClB,WAAW;IACX,WAAW;IACX,WAAW;IACX,WAAW;IACX,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,cAAc;IACd,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,cAAc;IACd,WAAW;IACX,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,cAAc;IACd,cAAc;IACd,YAAY;IACZ,WAAW;IACX,eAAe;IACf,eAAe;CACP,CAAC;AAEX,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAItD;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type { AwsAccountId } from "./account-id.js";
2
+ export type { AwsArn } from "./arn.js";
3
+ export type { AwsPartition } from "./partition.js";
4
+ export type { AwsRegion } from "./region.js";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/aws/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infra-blocks/zod-utils",
3
- "version": "0.9.0",
3
+ "version": "0.10.0-alpha.1",
4
4
  "description": "Extensions to the zod package.",
5
5
  "keywords": [
6
6
  "zod",
@@ -21,6 +21,11 @@
21
21
  "require": "./lib/cjs/index.js",
22
22
  "default": "./lib/esm/index.js"
23
23
  },
24
+ "./aws": {
25
+ "import": "./lib/esm/aws/types.js",
26
+ "require": "./lib/cjs/index.js",
27
+ "default": "./lib/esm/aws/types.js"
28
+ },
24
29
  "./json": {
25
30
  "import": "./lib/esm/json/types.js",
26
31
  "require": "./lib/cjs/json/types.js",