Skip to content

Commit 80ff356

Browse files
committed
add enum of strings allowed type
1 parent e2b1432 commit 80ff356

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zod-cdk-context",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Validate AWS CDK context with Zod",
55
"keywords": [
66
"zod",

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ export { z } from 'zod'
66

77
export const getValidatedContext = <
88
T extends {
9-
[key: string]: z.ZodString | z.ZodNumber | z.ZodOptional<z.ZodString | z.ZodNumber>
9+
[key: string]:
10+
| z.ZodString
11+
| z.ZodNumber
12+
| z.ZodOptional<z.ZodString | z.ZodNumber>
13+
| z.ZodEnum<[string, ...string[]]>
1014
},
1115
>(
1216
node: Node,

test/index.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ describe('validated context', () => {
2727
const app = new cdk.App({ context: {} })
2828
expect(() => getValidatedContext(app.node, { buzz: z.string() })).toThrow()
2929
})
30+
31+
test('enum of strings', () => {
32+
const app = new cdk.App({ context: { stage: 'prd' } })
33+
34+
expect(getValidatedContext(app.node, { stage: z.enum(['prd', 'dev']) })).toEqual({
35+
stage: 'prd',
36+
})
37+
expect(() => getValidatedContext(app.node, { stage: z.enum(['foo']) })).toThrow()
38+
})
3039
})

0 commit comments

Comments
 (0)