-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtypes.ts
More file actions
70 lines (61 loc) · 1.94 KB
/
types.ts
File metadata and controls
70 lines (61 loc) · 1.94 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
59
60
61
62
63
64
65
66
67
68
69
70
import { z } from 'zod'
import type { Steps } from '../alphalib/types/template.ts'
import { optionalStepsSchema } from '../alphalib/types/template.ts'
// Zod schemas for runtime validation
const APIErrorSchema = z.object({
error: z.string(),
message: z.string(),
})
export type APIError = z.infer<typeof APIErrorSchema>
const TransloaditAPIErrorSchema = z.object({
error: z.string().optional(),
message: z.string(),
code: z.string().optional(),
transloaditErrorCode: z.string().optional(),
response: z
.object({
body: z
.object({
error: z.string().optional(),
})
.optional(),
statusCode: z.number().optional(),
})
.optional(),
})
export type TransloaditAPIError = z.infer<typeof TransloaditAPIErrorSchema>
// Template file data - explicit type to avoid TS inference limits
export interface TemplateFileData {
transloadit_template_id?: string
steps?: Steps
[key: string]: unknown // passthrough
}
export const TemplateFileDataSchema: z.ZodType<TemplateFileData> = z
.object({
transloadit_template_id: z.string().optional(),
steps: optionalStepsSchema,
})
.passthrough() as z.ZodType<TemplateFileData>
export interface TemplateFile {
file: string
data: TemplateFileData
}
// Helper to ensure error is Error type
export function ensureError(value: unknown): Error {
if (value instanceof Error) {
return value
}
return new Error(`Non-error was thrown: ${String(value)}`)
}
// Type guard for APIError
export function isAPIError(value: unknown): value is APIError {
return APIErrorSchema.safeParse(value).success
}
// Type guard for TransloaditAPIError
export function isTransloaditAPIError(value: unknown): value is TransloaditAPIError {
return TransloaditAPIErrorSchema.safeParse(value).success
}
// Type guard for NodeJS.ErrnoException
export function isErrnoException(value: unknown): value is NodeJS.ErrnoException {
return value instanceof Error && 'code' in value
}