-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.ts
More file actions
58 lines (53 loc) · 1.4 KB
/
helpers.ts
File metadata and controls
58 lines (53 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { parse } from 'yaml'
import { z } from 'zod'
const cfnTagNames = [
'And',
'Base64',
'Cidr',
'Condition',
'Equals',
'FindInMap',
'GetAtt',
'GetAZs',
'If',
'ImportValue',
'Join',
'Not',
'Or',
'Ref',
'Select',
'Split',
'Sub',
'Transform'
]
const cfnTags = cfnTagNames.flatMap((name) => [
{ collection: 'seq' as const, resolve: (seq: unknown) => seq, tag: `!${name}` },
{ resolve: (str: string) => str, tag: `!${name}` }
])
export const loadTemplate = (relativePath: string): Record<string, unknown> =>
parse(readFileSync(resolve(__dirname, '../../deploy', relativePath), 'utf-8'), {
customTags: cfnTags
}) as Record<string, unknown>
// Common CloudFormation schemas
export const cfnParameterSchema = z.object({
AllowedValues: z.array(z.string()).optional(),
Default: z.union([z.string(), z.number()]).optional(),
Description: z.string().optional(),
Type: z.string()
})
export const cfnOutputSchema = z.object({
Condition: z.string().optional(),
Description: z.string().optional(),
Export: z.object({ Name: z.unknown() }).optional(),
Value: z.unknown()
})
export const openApiSchema = z.object({
info: z.object({
title: z.string(),
version: z.string()
}),
openapi: z.string().regex(/^3\.\d+\.\d+$/),
paths: z.record(z.string(), z.record(z.string(), z.unknown()))
})