@infra-blocks/zod-utils 0.8.0 → 0.9.0-alpha.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 +19 -0
- package/lib/cjs/aws/account-id.d.ts +13 -0
- package/lib/cjs/aws/account-id.js +20 -0
- package/lib/cjs/aws/account-id.js.map +1 -0
- package/lib/cjs/aws/arn.d.ts +18 -0
- package/lib/cjs/aws/arn.js +55 -0
- package/lib/cjs/aws/arn.js.map +1 -0
- package/lib/cjs/aws/index.d.ts +11 -0
- package/lib/cjs/aws/index.js +15 -0
- package/lib/cjs/aws/index.js.map +1 -0
- package/lib/cjs/aws/partition.d.ts +14 -0
- package/lib/cjs/aws/partition.js +20 -0
- package/lib/cjs/aws/partition.js.map +1 -0
- package/lib/cjs/aws/region.d.ts +49 -0
- package/lib/cjs/aws/region.js +57 -0
- package/lib/cjs/aws/region.js.map +1 -0
- package/lib/cjs/index.d.ts +8 -2
- package/lib/cjs/index.js +9 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/aws/account-id.d.ts +13 -0
- package/lib/esm/aws/account-id.js +17 -0
- package/lib/esm/aws/account-id.js.map +1 -0
- package/lib/esm/aws/arn.d.ts +18 -0
- package/lib/esm/aws/arn.js +52 -0
- package/lib/esm/aws/arn.js.map +1 -0
- package/lib/esm/aws/index.d.ts +11 -0
- package/lib/esm/aws/index.js +12 -0
- package/lib/esm/aws/index.js.map +1 -0
- package/lib/esm/aws/partition.d.ts +14 -0
- package/lib/esm/aws/partition.js +17 -0
- package/lib/esm/aws/partition.js.map +1 -0
- package/lib/esm/aws/region.d.ts +49 -0
- package/lib/esm/aws/region.js +54 -0
- package/lib/esm/aws/region.js.map +1 -0
- package/lib/esm/index.d.ts +8 -2
- package/lib/esm/index.js +5 -3
- package/lib/esm/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,12 +8,31 @@ This package exposes various utilities extending the [zod](https://www.npmjs.com
|
|
|
8
8
|
|
|
9
9
|
## API
|
|
10
10
|
|
|
11
|
+
- [aws](#aws)
|
|
11
12
|
- [geojson](#geojson)
|
|
12
13
|
- [json](#json)
|
|
13
14
|
- [csv](#csv)
|
|
14
15
|
- [typeGuard](#type-guard)
|
|
15
16
|
- [validate](#validate)
|
|
16
17
|
|
|
18
|
+
### AWS
|
|
19
|
+
|
|
20
|
+
The `aws` module contains utilities to validate various AWS elements.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { zu } from "@infra-blocks/zod-utils";
|
|
24
|
+
|
|
25
|
+
// Validates a 12 digit string, as describe here: https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html
|
|
26
|
+
zu.aws.accountId().parse("123456789012");
|
|
27
|
+
// Validates an AWS ARN, as described here: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
28
|
+
zu.aws.arn().parse("arn:aws:iam:us-east-1:123456789012:user/joe-cunt");
|
|
29
|
+
// Validates an AWS partition, as describe here: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
30
|
+
zu.aws.partition().parse("aws");
|
|
31
|
+
// Validates an AWS region, as described here: https://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html#available-regions
|
|
32
|
+
// "gov" and "cn" regions are included.
|
|
33
|
+
zu.aws.region().parse("us-east-1");
|
|
34
|
+
```
|
|
35
|
+
|
|
17
36
|
### GeoJson
|
|
18
37
|
|
|
19
38
|
The `geojson` module contains utilities to validate GeoJSON objects.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a string is a valid AWS account ID.
|
|
4
|
+
*
|
|
5
|
+
* The schema enforces the following rules:
|
|
6
|
+
* - The string must be exactly 12 characters long.
|
|
7
|
+
* - Each character must be a digit (0-9).
|
|
8
|
+
*
|
|
9
|
+
* @returns A schema that validates AWS account IDs.
|
|
10
|
+
*
|
|
11
|
+
* @see https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html
|
|
12
|
+
*/
|
|
13
|
+
export declare function accountId(): z.ZodString;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.accountId = accountId;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schema = zod_1.z.string().regex(zod_1.z.regexes.integer).length(12);
|
|
6
|
+
/**
|
|
7
|
+
* Validates that a string is a valid AWS account ID.
|
|
8
|
+
*
|
|
9
|
+
* The schema enforces the following rules:
|
|
10
|
+
* - The string must be exactly 12 characters long.
|
|
11
|
+
* - Each character must be a digit (0-9).
|
|
12
|
+
*
|
|
13
|
+
* @returns A schema that validates AWS account IDs.
|
|
14
|
+
*
|
|
15
|
+
* @see https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html
|
|
16
|
+
*/
|
|
17
|
+
function accountId() {
|
|
18
|
+
return schema;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=account-id.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a string is a valid AWS ARN.
|
|
4
|
+
*
|
|
5
|
+
* The schema enforces the following rules:
|
|
6
|
+
* - There must be at least 6 tokens separated by colons.
|
|
7
|
+
* - The first token must be "arn".
|
|
8
|
+
* - The second token must be a valid AWS partition, as validated by `zu.aws.partition()`.
|
|
9
|
+
* - The third token (service) cannot be empty. No further checks are done.
|
|
10
|
+
* - The fourth token (region) can be empty or must be a valid AWS region, as validated by `zu.aws.region()`.
|
|
11
|
+
* - The fifth token (account ID) can be empty or must be a valid AWS account ID, as validated by `zu.aws.accountId()`.
|
|
12
|
+
* - The sixth token (resource ID/type) cannot be empty. No further checks are done.
|
|
13
|
+
*
|
|
14
|
+
* @returns A schema that validates AWS ARNs.
|
|
15
|
+
*
|
|
16
|
+
* @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
17
|
+
*/
|
|
18
|
+
export declare function arn(): z.ZodString;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arn = arn;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const index_js_1 = require("../index.js");
|
|
6
|
+
function isValid(arn) {
|
|
7
|
+
const parts = arn.split(":");
|
|
8
|
+
if (parts.length < 6) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (parts[0] !== "arn") {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!index_js_1.zu.isValid(index_js_1.zu.aws.partition(), parts[1])) {
|
|
15
|
+
throw new Error(`invalid ARN ${arn}`);
|
|
16
|
+
}
|
|
17
|
+
// The service cannot be empty.
|
|
18
|
+
if (parts[2] === "") {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
// Region can be absent.
|
|
22
|
+
if (parts[3] !== "" && !index_js_1.zu.isValid(index_js_1.zu.aws.region(), parts[3])) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// Account ID can be absent.
|
|
26
|
+
if (parts[4] !== "" && !index_js_1.zu.isValid(index_js_1.zu.aws.accountId(), parts[4])) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
// Resource ID/type cannot be empty.
|
|
30
|
+
if (parts[5] === "") {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const schema = zod_1.z.string().refine(isValid, { error: "invalid AWS ARN" });
|
|
36
|
+
/**
|
|
37
|
+
* Validates that a string is a valid AWS ARN.
|
|
38
|
+
*
|
|
39
|
+
* The schema enforces the following rules:
|
|
40
|
+
* - There must be at least 6 tokens separated by colons.
|
|
41
|
+
* - The first token must be "arn".
|
|
42
|
+
* - The second token must be a valid AWS partition, as validated by `zu.aws.partition()`.
|
|
43
|
+
* - The third token (service) cannot be empty. No further checks are done.
|
|
44
|
+
* - The fourth token (region) can be empty or must be a valid AWS region, as validated by `zu.aws.region()`.
|
|
45
|
+
* - The fifth token (account ID) can be empty or must be a valid AWS account ID, as validated by `zu.aws.accountId()`.
|
|
46
|
+
* - The sixth token (resource ID/type) cannot be empty. No further checks are done.
|
|
47
|
+
*
|
|
48
|
+
* @returns A schema that validates AWS ARNs.
|
|
49
|
+
*
|
|
50
|
+
* @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
51
|
+
*/
|
|
52
|
+
function arn() {
|
|
53
|
+
return schema;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=arn.js.map
|
|
@@ -0,0 +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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
|
+
import { region } from "./region.js";
|
|
5
|
+
declare const aws: {
|
|
6
|
+
accountId: typeof accountId;
|
|
7
|
+
arn: typeof arn;
|
|
8
|
+
region: typeof region;
|
|
9
|
+
partition: typeof partition;
|
|
10
|
+
};
|
|
11
|
+
export { aws };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aws = void 0;
|
|
4
|
+
const account_id_js_1 = require("./account-id.js");
|
|
5
|
+
const arn_js_1 = require("./arn.js");
|
|
6
|
+
const partition_js_1 = require("./partition.js");
|
|
7
|
+
const region_js_1 = require("./region.js");
|
|
8
|
+
const aws = {
|
|
9
|
+
accountId: account_id_js_1.accountId,
|
|
10
|
+
arn: arn_js_1.arn,
|
|
11
|
+
region: region_js_1.region,
|
|
12
|
+
partition: partition_js_1.partition,
|
|
13
|
+
};
|
|
14
|
+
exports.aws = aws;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/aws/index.ts"],"names":[],"mappings":";;;AAAA,mDAA4C;AAC5C,qCAA+B;AAC/B,iDAA2C;AAC3C,2CAAqC;AAErC,MAAM,GAAG,GAAG;IACV,SAAS,EAAT,yBAAS;IACT,GAAG,EAAH,YAAG;IACH,MAAM,EAAN,kBAAM;IACN,SAAS,EAAT,wBAAS;CACV,CAAC;AAEO,kBAAG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a string is a valid AWS partition.
|
|
4
|
+
*
|
|
5
|
+
* The schema enforces the following rules:
|
|
6
|
+
* - The string must be one of the known AWS partitions: "aws", "aws-cn", "aws-us-gov".
|
|
7
|
+
*
|
|
8
|
+
* @returns A schema that validates AWS partitions.
|
|
9
|
+
*
|
|
10
|
+
* @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
11
|
+
*/
|
|
12
|
+
export declare function partition(): z.ZodEnum<{
|
|
13
|
+
[x: string]: string;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.partition = partition;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const AWS_PARTITIONS = ["aws", "aws-cn", "aws-us-gov"];
|
|
6
|
+
const schema = zod_1.z.enum(AWS_PARTITIONS);
|
|
7
|
+
/**
|
|
8
|
+
* Validates that a string is a valid AWS partition.
|
|
9
|
+
*
|
|
10
|
+
* The schema enforces the following rules:
|
|
11
|
+
* - The string must be one of the known AWS partitions: "aws", "aws-cn", "aws-us-gov".
|
|
12
|
+
*
|
|
13
|
+
* @returns A schema that validates AWS partitions.
|
|
14
|
+
*
|
|
15
|
+
* @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
16
|
+
*/
|
|
17
|
+
function partition() {
|
|
18
|
+
return schema;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=partition.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a string is a valid AWS region.
|
|
4
|
+
*
|
|
5
|
+
* The schema enforces the following rules:
|
|
6
|
+
* - The string must be one of the known AWS regions. Those are hardcoded in the schema.
|
|
7
|
+
*
|
|
8
|
+
* @returns A schema that validates AWS regions.
|
|
9
|
+
*/
|
|
10
|
+
export declare function region(): z.ZodEnum<{
|
|
11
|
+
"us-east-1": "us-east-1";
|
|
12
|
+
"us-east-2": "us-east-2";
|
|
13
|
+
"us-west-1": "us-west-1";
|
|
14
|
+
"us-west-2": "us-west-2";
|
|
15
|
+
"af-south-1": "af-south-1";
|
|
16
|
+
"ap-east-1": "ap-east-1";
|
|
17
|
+
"ap-east-2": "ap-east-2";
|
|
18
|
+
"ap-south-1": "ap-south-1";
|
|
19
|
+
"ap-south-2": "ap-south-2";
|
|
20
|
+
"ap-southeast-1": "ap-southeast-1";
|
|
21
|
+
"ap-southeast-2": "ap-southeast-2";
|
|
22
|
+
"ap-southeast-3": "ap-southeast-3";
|
|
23
|
+
"ap-southeast-4": "ap-southeast-4";
|
|
24
|
+
"ap-southeast-5": "ap-southeast-5";
|
|
25
|
+
"ap-southeast-6": "ap-southeast-6";
|
|
26
|
+
"ap-southeast-7": "ap-southeast-7";
|
|
27
|
+
"ap-northeast-1": "ap-northeast-1";
|
|
28
|
+
"ap-northeast-2": "ap-northeast-2";
|
|
29
|
+
"ap-northeast-3": "ap-northeast-3";
|
|
30
|
+
"ca-central-1": "ca-central-1";
|
|
31
|
+
"ca-west-1": "ca-west-1";
|
|
32
|
+
"cn-north-1": "cn-north-1";
|
|
33
|
+
"cn-northwest-1": "cn-northwest-1";
|
|
34
|
+
"eu-central-1": "eu-central-1";
|
|
35
|
+
"eu-central-2": "eu-central-2";
|
|
36
|
+
"eu-west-1": "eu-west-1";
|
|
37
|
+
"eu-west-2": "eu-west-2";
|
|
38
|
+
"eu-west-3": "eu-west-3";
|
|
39
|
+
"eu-south-1": "eu-south-1";
|
|
40
|
+
"eu-south-2": "eu-south-2";
|
|
41
|
+
"eu-north-1": "eu-north-1";
|
|
42
|
+
"il-central-1": "il-central-1";
|
|
43
|
+
"mx-central-1": "mx-central-1";
|
|
44
|
+
"me-central-1": "me-central-1";
|
|
45
|
+
"me-south-1": "me-south-1";
|
|
46
|
+
"sa-east-1": "sa-east-1";
|
|
47
|
+
"us-gov-east-1": "us-gov-east-1";
|
|
48
|
+
"us-gov-west-1": "us-gov-west-1";
|
|
49
|
+
}>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.region = region;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const AWS_REGIONS = [
|
|
6
|
+
"us-east-1",
|
|
7
|
+
"us-east-2",
|
|
8
|
+
"us-west-1",
|
|
9
|
+
"us-west-2",
|
|
10
|
+
"af-south-1",
|
|
11
|
+
"ap-east-1",
|
|
12
|
+
"ap-east-2",
|
|
13
|
+
"ap-south-1",
|
|
14
|
+
"ap-south-2",
|
|
15
|
+
"ap-southeast-1",
|
|
16
|
+
"ap-southeast-2",
|
|
17
|
+
"ap-southeast-3",
|
|
18
|
+
"ap-southeast-4",
|
|
19
|
+
"ap-southeast-5",
|
|
20
|
+
"ap-southeast-6",
|
|
21
|
+
"ap-southeast-7",
|
|
22
|
+
"ap-northeast-1",
|
|
23
|
+
"ap-northeast-2",
|
|
24
|
+
"ap-northeast-3",
|
|
25
|
+
"ca-central-1",
|
|
26
|
+
"ca-west-1",
|
|
27
|
+
"cn-north-1",
|
|
28
|
+
"cn-northwest-1",
|
|
29
|
+
"eu-central-1",
|
|
30
|
+
"eu-central-2",
|
|
31
|
+
"eu-west-1",
|
|
32
|
+
"eu-west-2",
|
|
33
|
+
"eu-west-3",
|
|
34
|
+
"eu-south-1",
|
|
35
|
+
"eu-south-2",
|
|
36
|
+
"eu-north-1",
|
|
37
|
+
"il-central-1",
|
|
38
|
+
"mx-central-1",
|
|
39
|
+
"me-central-1",
|
|
40
|
+
"me-south-1",
|
|
41
|
+
"sa-east-1",
|
|
42
|
+
"us-gov-east-1",
|
|
43
|
+
"us-gov-west-1",
|
|
44
|
+
];
|
|
45
|
+
const schema = zod_1.z.enum(AWS_REGIONS);
|
|
46
|
+
/**
|
|
47
|
+
* Validates that a string is a valid AWS region.
|
|
48
|
+
*
|
|
49
|
+
* The schema enforces the following rules:
|
|
50
|
+
* - The string must be one of the known AWS regions. Those are hardcoded in the schema.
|
|
51
|
+
*
|
|
52
|
+
* @returns A schema that validates AWS regions.
|
|
53
|
+
*/
|
|
54
|
+
function region() {
|
|
55
|
+
return schema;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=region.js.map
|
|
@@ -0,0 +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"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -42,8 +42,14 @@ declare function typeGuard<S extends z.ZodType>(schema: S): TypeGuard<z.infer<S>
|
|
|
42
42
|
*
|
|
43
43
|
* @returns Whether the value satisfies the schema.
|
|
44
44
|
*/
|
|
45
|
-
declare function
|
|
45
|
+
declare function isValid<S extends z.ZodType>(schema: S, value: unknown): value is z.infer<S>;
|
|
46
46
|
declare const zu: {
|
|
47
|
+
aws: {
|
|
48
|
+
accountId: typeof import("./aws/account-id.js").accountId;
|
|
49
|
+
arn: typeof import("./aws/arn.js").arn;
|
|
50
|
+
region: typeof import("./aws/region.js").region;
|
|
51
|
+
partition: typeof import("./aws/partition.js").partition;
|
|
52
|
+
};
|
|
47
53
|
geojson: {
|
|
48
54
|
(): z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
|
|
49
55
|
bbox: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>, z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>]>>;
|
|
@@ -156,6 +162,6 @@ declare const zu: {
|
|
|
156
162
|
csv: typeof csv;
|
|
157
163
|
stringtoInt: typeof stringtoInt;
|
|
158
164
|
typeGuard: typeof typeGuard;
|
|
159
|
-
|
|
165
|
+
isValid: typeof isValid;
|
|
160
166
|
};
|
|
161
167
|
export { zu };
|
package/lib/cjs/index.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zu = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const index_js_1 = require("./
|
|
6
|
-
const index_js_2 = require("./
|
|
5
|
+
const index_js_1 = require("./aws/index.js");
|
|
6
|
+
const index_js_2 = require("./geojson/index.js");
|
|
7
|
+
const index_js_3 = require("./json/index.js");
|
|
7
8
|
const csvSchema = zod_1.z.string().transform((str) => str.split(","));
|
|
8
9
|
csvSchema.brand("Toto");
|
|
9
10
|
/**
|
|
@@ -45,7 +46,7 @@ function stringtoInt() {
|
|
|
45
46
|
*/
|
|
46
47
|
function typeGuard(schema) {
|
|
47
48
|
return (value) => {
|
|
48
|
-
return
|
|
49
|
+
return isValid(schema, value);
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
@@ -60,16 +61,17 @@ function typeGuard(schema) {
|
|
|
60
61
|
*
|
|
61
62
|
* @returns Whether the value satisfies the schema.
|
|
62
63
|
*/
|
|
63
|
-
function
|
|
64
|
+
function isValid(schema, value) {
|
|
64
65
|
return schema.safeParse(value).success;
|
|
65
66
|
}
|
|
66
67
|
const zu = {
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
aws: index_js_1.aws,
|
|
69
|
+
geojson: index_js_2.geojson,
|
|
70
|
+
json: index_js_3.json,
|
|
69
71
|
csv,
|
|
70
72
|
stringtoInt,
|
|
71
73
|
typeGuard,
|
|
72
|
-
|
|
74
|
+
isValid,
|
|
73
75
|
};
|
|
74
76
|
exports.zu = zu;
|
|
75
77
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AACxB,iDAA6C;AAC7C,8CAAuC;AAEvC,MAAM,SAAS,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAEhE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAExB;;;;GAIG;AACH,SAAS,GAAG;IACV,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,gBAAgB,GAAG,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAC,CAAC,GAAG,EAAE,EAAE;IAC7E,MAAM,EAAE,CAAC,GAA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AO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,OAAO,CACd,MAAS,EACT,KAAc;IAEd,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzC,CAAC;AAED,MAAM,EAAE,GAAG;IACT,GAAG,EAAH,cAAG;IACH,OAAO,EAAP,kBAAO;IACP,IAAI,EAAJ,eAAI;IACJ,GAAG;IACH,WAAW;IACX,SAAS;IACT,OAAO;CACR,CAAC;AAEO,gBAAE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a string is a valid AWS account ID.
|
|
4
|
+
*
|
|
5
|
+
* The schema enforces the following rules:
|
|
6
|
+
* - The string must be exactly 12 characters long.
|
|
7
|
+
* - Each character must be a digit (0-9).
|
|
8
|
+
*
|
|
9
|
+
* @returns A schema that validates AWS account IDs.
|
|
10
|
+
*
|
|
11
|
+
* @see https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html
|
|
12
|
+
*/
|
|
13
|
+
export declare function accountId(): z.ZodString;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const schema = z.string().regex(z.regexes.integer).length(12);
|
|
3
|
+
/**
|
|
4
|
+
* Validates that a string is a valid AWS account ID.
|
|
5
|
+
*
|
|
6
|
+
* The schema enforces the following rules:
|
|
7
|
+
* - The string must be exactly 12 characters long.
|
|
8
|
+
* - Each character must be a digit (0-9).
|
|
9
|
+
*
|
|
10
|
+
* @returns A schema that validates AWS account IDs.
|
|
11
|
+
*
|
|
12
|
+
* @see https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html
|
|
13
|
+
*/
|
|
14
|
+
export function accountId() {
|
|
15
|
+
return schema;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=account-id.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a string is a valid AWS ARN.
|
|
4
|
+
*
|
|
5
|
+
* The schema enforces the following rules:
|
|
6
|
+
* - There must be at least 6 tokens separated by colons.
|
|
7
|
+
* - The first token must be "arn".
|
|
8
|
+
* - The second token must be a valid AWS partition, as validated by `zu.aws.partition()`.
|
|
9
|
+
* - The third token (service) cannot be empty. No further checks are done.
|
|
10
|
+
* - The fourth token (region) can be empty or must be a valid AWS region, as validated by `zu.aws.region()`.
|
|
11
|
+
* - The fifth token (account ID) can be empty or must be a valid AWS account ID, as validated by `zu.aws.accountId()`.
|
|
12
|
+
* - The sixth token (resource ID/type) cannot be empty. No further checks are done.
|
|
13
|
+
*
|
|
14
|
+
* @returns A schema that validates AWS ARNs.
|
|
15
|
+
*
|
|
16
|
+
* @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
17
|
+
*/
|
|
18
|
+
export declare function arn(): z.ZodString;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { zu } from "../index.js";
|
|
3
|
+
function isValid(arn) {
|
|
4
|
+
const parts = arn.split(":");
|
|
5
|
+
if (parts.length < 6) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (parts[0] !== "arn") {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (!zu.isValid(zu.aws.partition(), parts[1])) {
|
|
12
|
+
throw new Error(`invalid ARN ${arn}`);
|
|
13
|
+
}
|
|
14
|
+
// The service cannot be empty.
|
|
15
|
+
if (parts[2] === "") {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
// Region can be absent.
|
|
19
|
+
if (parts[3] !== "" && !zu.isValid(zu.aws.region(), parts[3])) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
// Account ID can be absent.
|
|
23
|
+
if (parts[4] !== "" && !zu.isValid(zu.aws.accountId(), parts[4])) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// Resource ID/type cannot be empty.
|
|
27
|
+
if (parts[5] === "") {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const schema = z.string().refine(isValid, { error: "invalid AWS ARN" });
|
|
33
|
+
/**
|
|
34
|
+
* Validates that a string is a valid AWS ARN.
|
|
35
|
+
*
|
|
36
|
+
* The schema enforces the following rules:
|
|
37
|
+
* - There must be at least 6 tokens separated by colons.
|
|
38
|
+
* - The first token must be "arn".
|
|
39
|
+
* - The second token must be a valid AWS partition, as validated by `zu.aws.partition()`.
|
|
40
|
+
* - The third token (service) cannot be empty. No further checks are done.
|
|
41
|
+
* - The fourth token (region) can be empty or must be a valid AWS region, as validated by `zu.aws.region()`.
|
|
42
|
+
* - The fifth token (account ID) can be empty or must be a valid AWS account ID, as validated by `zu.aws.accountId()`.
|
|
43
|
+
* - The sixth token (resource ID/type) cannot be empty. No further checks are done.
|
|
44
|
+
*
|
|
45
|
+
* @returns A schema that validates AWS ARNs.
|
|
46
|
+
*
|
|
47
|
+
* @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
48
|
+
*/
|
|
49
|
+
export function ar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AC,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,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { accountId } from "./account-id.js";
|
|
2
|
+
import { arn } from "./arn.js";
|
|
3
|
+
import { partition } from "./partition.js";
|
|
4
|
+
import { region } from "./region.js";
|
|
5
|
+
declare const aws: {
|
|
6
|
+
accountId: typeof accountId;
|
|
7
|
+
arn: typeof arn;
|
|
8
|
+
region: typeof region;
|
|
9
|
+
partition: typeof partition;
|
|
10
|
+
};
|
|
11
|
+
export { aws };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { accountId } from "./account-id.js";
|
|
2
|
+
import { arn } from "./arn.js";
|
|
3
|
+
import { partition } from "./partition.js";
|
|
4
|
+
import { region } from "./region.js";
|
|
5
|
+
const aws = {
|
|
6
|
+
accountId,
|
|
7
|
+
arn,
|
|
8
|
+
region,
|
|
9
|
+
partition,
|
|
10
|
+
};
|
|
11
|
+
export { aws };
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/aws/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,GAAG,GAAG;IACV,SAAS;IACT,GAAG;IACH,MAAM;IACN,SAAS;CACV,CAAC;AAEF,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a string is a valid AWS partition.
|
|
4
|
+
*
|
|
5
|
+
* The schema enforces the following rules:
|
|
6
|
+
* - The string must be one of the known AWS partitions: "aws", "aws-cn", "aws-us-gov".
|
|
7
|
+
*
|
|
8
|
+
* @returns A schema that validates AWS partitions.
|
|
9
|
+
*
|
|
10
|
+
* @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
11
|
+
*/
|
|
12
|
+
export declare function partition(): z.ZodEnum<{
|
|
13
|
+
[x: string]: string;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const AWS_PARTITIONS = ["aws", "aws-cn", "aws-us-gov"];
|
|
3
|
+
const schema = z.enum(AWS_PARTITIONS);
|
|
4
|
+
/**
|
|
5
|
+
* Validates that a string is a valid AWS partition.
|
|
6
|
+
*
|
|
7
|
+
* The schema enforces the following rules:
|
|
8
|
+
* - The string must be one of the known AWS partitions: "aws", "aws-cn", "aws-us-gov".
|
|
9
|
+
*
|
|
10
|
+
* @returns A schema that validates AWS partitions.
|
|
11
|
+
*
|
|
12
|
+
* @see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
13
|
+
*/
|
|
14
|
+
export function partition() {
|
|
15
|
+
return schema;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=partition.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a string is a valid AWS region.
|
|
4
|
+
*
|
|
5
|
+
* The schema enforces the following rules:
|
|
6
|
+
* - The string must be one of the known AWS regions. Those are hardcoded in the schema.
|
|
7
|
+
*
|
|
8
|
+
* @returns A schema that validates AWS regions.
|
|
9
|
+
*/
|
|
10
|
+
export declare function region(): z.ZodEnum<{
|
|
11
|
+
"us-east-1": "us-east-1";
|
|
12
|
+
"us-east-2": "us-east-2";
|
|
13
|
+
"us-west-1": "us-west-1";
|
|
14
|
+
"us-west-2": "us-west-2";
|
|
15
|
+
"af-south-1": "af-south-1";
|
|
16
|
+
"ap-east-1": "ap-east-1";
|
|
17
|
+
"ap-east-2": "ap-east-2";
|
|
18
|
+
"ap-south-1": "ap-south-1";
|
|
19
|
+
"ap-south-2": "ap-south-2";
|
|
20
|
+
"ap-southeast-1": "ap-southeast-1";
|
|
21
|
+
"ap-southeast-2": "ap-southeast-2";
|
|
22
|
+
"ap-southeast-3": "ap-southeast-3";
|
|
23
|
+
"ap-southeast-4": "ap-southeast-4";
|
|
24
|
+
"ap-southeast-5": "ap-southeast-5";
|
|
25
|
+
"ap-southeast-6": "ap-southeast-6";
|
|
26
|
+
"ap-southeast-7": "ap-southeast-7";
|
|
27
|
+
"ap-northeast-1": "ap-northeast-1";
|
|
28
|
+
"ap-northeast-2": "ap-northeast-2";
|
|
29
|
+
"ap-northeast-3": "ap-northeast-3";
|
|
30
|
+
"ca-central-1": "ca-central-1";
|
|
31
|
+
"ca-west-1": "ca-west-1";
|
|
32
|
+
"cn-north-1": "cn-north-1";
|
|
33
|
+
"cn-northwest-1": "cn-northwest-1";
|
|
34
|
+
"eu-central-1": "eu-central-1";
|
|
35
|
+
"eu-central-2": "eu-central-2";
|
|
36
|
+
"eu-west-1": "eu-west-1";
|
|
37
|
+
"eu-west-2": "eu-west-2";
|
|
38
|
+
"eu-west-3": "eu-west-3";
|
|
39
|
+
"eu-south-1": "eu-south-1";
|
|
40
|
+
"eu-south-2": "eu-south-2";
|
|
41
|
+
"eu-north-1": "eu-north-1";
|
|
42
|
+
"il-central-1": "il-central-1";
|
|
43
|
+
"mx-central-1": "mx-central-1";
|
|
44
|
+
"me-central-1": "me-central-1";
|
|
45
|
+
"me-south-1": "me-south-1";
|
|
46
|
+
"sa-east-1": "sa-east-1";
|
|
47
|
+
"us-gov-east-1": "us-gov-east-1";
|
|
48
|
+
"us-gov-west-1": "us-gov-west-1";
|
|
49
|
+
}>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const AWS_REGIONS = [
|
|
3
|
+
"us-east-1",
|
|
4
|
+
"us-east-2",
|
|
5
|
+
"us-west-1",
|
|
6
|
+
"us-west-2",
|
|
7
|
+
"af-south-1",
|
|
8
|
+
"ap-east-1",
|
|
9
|
+
"ap-east-2",
|
|
10
|
+
"ap-south-1",
|
|
11
|
+
"ap-south-2",
|
|
12
|
+
"ap-southeast-1",
|
|
13
|
+
"ap-southeast-2",
|
|
14
|
+
"ap-southeast-3",
|
|
15
|
+
"ap-southeast-4",
|
|
16
|
+
"ap-southeast-5",
|
|
17
|
+
"ap-southeast-6",
|
|
18
|
+
"ap-southeast-7",
|
|
19
|
+
"ap-northeast-1",
|
|
20
|
+
"ap-northeast-2",
|
|
21
|
+
"ap-northeast-3",
|
|
22
|
+
"ca-central-1",
|
|
23
|
+
"ca-west-1",
|
|
24
|
+
"cn-north-1",
|
|
25
|
+
"cn-northwest-1",
|
|
26
|
+
"eu-central-1",
|
|
27
|
+
"eu-central-2",
|
|
28
|
+
"eu-west-1",
|
|
29
|
+
"eu-west-2",
|
|
30
|
+
"eu-west-3",
|
|
31
|
+
"eu-south-1",
|
|
32
|
+
"eu-south-2",
|
|
33
|
+
"eu-north-1",
|
|
34
|
+
"il-central-1",
|
|
35
|
+
"mx-central-1",
|
|
36
|
+
"me-central-1",
|
|
37
|
+
"me-south-1",
|
|
38
|
+
"sa-east-1",
|
|
39
|
+
"us-gov-east-1",
|
|
40
|
+
"us-gov-west-1",
|
|
41
|
+
];
|
|
42
|
+
const schema = z.enum(AWS_REGIONS);
|
|
43
|
+
/**
|
|
44
|
+
* Validates that a string is a valid AWS region.
|
|
45
|
+
*
|
|
46
|
+
* The schema enforces the following rules:
|
|
47
|
+
* - The string must be one of the known AWS regions. Those are hardcoded in the schema.
|
|
48
|
+
*
|
|
49
|
+
* @returns A schema that validates AWS regions.
|
|
50
|
+
*/
|
|
51
|
+
export function region() {
|
|
52
|
+
return schema;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=region.js.map
|
|
@@ -0,0 +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"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -42,8 +42,14 @@ declare function typeGuard<S extends z.ZodType>(schema: S): TypeGuard<z.infer<S>
|
|
|
42
42
|
*
|
|
43
43
|
* @returns Whether the value satisfies the schema.
|
|
44
44
|
*/
|
|
45
|
-
declare function
|
|
45
|
+
declare function isValid<S extends z.ZodType>(schema: S, value: unknown): value is z.infer<S>;
|
|
46
46
|
declare const zu: {
|
|
47
|
+
aws: {
|
|
48
|
+
accountId: typeof import("./aws/account-id.js").accountId;
|
|
49
|
+
arn: typeof import("./aws/arn.js").arn;
|
|
50
|
+
region: typeof import("./aws/region.js").region;
|
|
51
|
+
partition: typeof import("./aws/partition.js").partition;
|
|
52
|
+
};
|
|
47
53
|
geojson: {
|
|
48
54
|
(): z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
|
|
49
55
|
bbox: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>, z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>]>>;
|
|
@@ -156,6 +162,6 @@ declare const zu: {
|
|
|
156
162
|
csv: typeof csv;
|
|
157
163
|
stringtoInt: typeof stringtoInt;
|
|
158
164
|
typeGuard: typeof typeGuard;
|
|
159
|
-
|
|
165
|
+
isValid: typeof isValid;
|
|
160
166
|
};
|
|
161
167
|
export { zu };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { aws } from "./aws/index.js";
|
|
2
3
|
import { geojson } from "./geojson/index.js";
|
|
3
4
|
import { json } from "./json/index.js";
|
|
4
5
|
const csvSchema = z.string().transform((str) => str.split(","));
|
|
@@ -42,7 +43,7 @@ function stringtoInt() {
|
|
|
42
43
|
*/
|
|
43
44
|
function typeGuard(schema) {
|
|
44
45
|
return (value) => {
|
|
45
|
-
return
|
|
46
|
+
return isValid(schema, value);
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
@@ -57,16 +58,17 @@ function typeGuard(schema) {
|
|
|
57
58
|
*
|
|
58
59
|
* @returns Whether the value satisfies the schema.
|
|
59
60
|
*/
|
|
60
|
-
function
|
|
61
|
+
function isValid(schema, value) {
|
|
61
62
|
return schema.safeParse(value).success;
|
|
62
63
|
}
|
|
63
64
|
const zu = {
|
|
65
|
+
aws,
|
|
64
66
|
geojson,
|
|
65
67
|
json,
|
|
66
68
|
csv,
|
|
67
69
|
stringtoInt,
|
|
68
70
|
typeGuard,
|
|
69
|
-
|
|
71
|
+
isValid,
|
|
70
72
|
};
|
|
71
73
|
export { zu };
|
|
72
74
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAEhE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAExB;;;;GAIG;AACH,SAAS,GAAG;IACV,OAAO,SAAS,CAAC;A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