Skip to content

Commit 6a01ed1

Browse files
committed
rename getCdkContext -> parseContext
1 parent 48170a1 commit 6a01ed1

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
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.10",
3+
"version": "0.1.0",
44
"description": "Validate AWS CDK context with Zod",
55
"keywords": [
66
"zod",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { z, type ZodRawShape } from 'zod'
44

55
export { z } from 'zod'
66

7-
export const getValidatedContext = <T extends ZodRawShape>(
7+
export const parseContext = <T extends ZodRawShape>(
88
node: Node,
99
schemaObject: T,
1010
): z.infer<z.ZodObject<T>> => {

test/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
import * as cdk from 'aws-cdk-lib'
22
import { describe, expect, test } from 'vitest'
33

4-
import { getValidatedContext, z } from '../src/index.js'
4+
import { parseContext, z } from '../src/index.js'
55

66
describe('validated context', () => {
77
test('get string context value', () => {
88
const app = new cdk.App({ context: { foo: 'bar' } })
9-
const { foo } = getValidatedContext(app.node, { foo: z.string() })
9+
const { foo } = parseContext(app.node, { foo: z.string() })
1010
expect(foo).toEqual('bar')
1111
})
1212

1313
test('get number context value', () => {
1414
const app = new cdk.App({ context: { foo: '99' } })
15-
const values = getValidatedContext(app.node, { foo: z.coerce.number() })
15+
const values = parseContext(app.node, { foo: z.coerce.number() })
1616

1717
expect(values).toEqual({ foo: 99 })
1818
})
1919

2020
test("pass when optional value doesn't exist in context", () => {
2121
const app = new cdk.App({ context: {} })
22-
const values = getValidatedContext(app.node, { buzz: z.string().optional() })
22+
const values = parseContext(app.node, { buzz: z.string().optional() })
2323
expect(values).toEqual({})
2424
})
2525

2626
test("throw when required value doesn't exist in context", () => {
2727
const app = new cdk.App({ context: {} })
28-
expect(() => getValidatedContext(app.node, { buzz: z.string() })).toThrow()
28+
expect(() => parseContext(app.node, { buzz: z.string() })).toThrow()
2929
})
3030

3131
test('enum of strings', () => {
3232
const app = new cdk.App({ context: { stage: 'prd' } })
3333

34-
expect(getValidatedContext(app.node, { stage: z.enum(['prd', 'dev']) })).toEqual({
34+
expect(parseContext(app.node, { stage: z.enum(['prd', 'dev']) })).toEqual({
3535
stage: 'prd',
3636
})
37-
expect(() => getValidatedContext(app.node, { stage: z.enum(['foo']) })).toThrow()
37+
expect(() => parseContext(app.node, { stage: z.enum(['foo']) })).toThrow()
3838
})
3939
})

0 commit comments

Comments
 (0)