-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration-reply-data.ts
More file actions
37 lines (30 loc) · 1.04 KB
/
integration-reply-data.ts
File metadata and controls
37 lines (30 loc) · 1.04 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
import { z } from 'zod'
import { makeJsonCodecSimple } from '../utils'
import { JsonValueSchema } from './json-value-schema'
export const PlainTypeSchema = z.object({
type: z.literal('PlainType'),
value: z.string(),
})
export const IntegrationTypeSchema = z.object({
type: z.literal('IntegrationType'),
value: z.string(),
raw: JsonValueSchema,
})
export const IntegrationReplySchema = z.object({
type: z.literal('IntegrationReply'),
value: z.discriminatedUnion('type', [PlainTypeSchema, IntegrationTypeSchema]),
})
export type PlainType = z.infer<typeof PlainTypeSchema>
export type IntegrationType = z.infer<typeof IntegrationTypeSchema>
export type IntegrationReply = z.infer<typeof IntegrationReplySchema>
export const IntegrationReplyCodec = makeJsonCodecSimple(IntegrationReplySchema)
export function createIntegrationReply(value: string, raw: unknown): IntegrationReply {
return {
type: 'IntegrationReply',
value: {
type: 'IntegrationType',
value,
raw,
},
}
}