This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
/
props.ts
54 lines (46 loc) · 1.51 KB
/
props.ts
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
import {
PipedreamPropTypes,
PropReturnDInterfaceTimer,
PropReturnDInterfaceHttp,
PropReturnDServiceDB,
PropDefaultDInterfaceTimer,
} from "./pipedream"
import { string2 } from "../types"
type PropTypes = "string" | "boolean" | PipedreamPropTypes
type Prop<T> = PropOptions<T> | PropTypes | string2
type PropTypesDefault = PropDefaultDInterfaceTimer
type PropOptions<T = any> = {
type?: PropTypes | string2
label?: string
description?: string
default?: PropTypesDefault | { [key: string]: any } | string | null
propDefinition?: [any, string]
optional?: boolean
options?: ((...args: any) => string[] | Promise<string[]>) | string[] | any[]
}
type ConvertPropTypes<T> = T extends null
? null
: T extends { type: "string" } | "string"
? string
: T extends { type: "boolean" } | "boolean"
? boolean
: T extends { type: "string[]" } | "string[]"
? string[]
: T extends { type: "$.interface.timer" } | "$.interface.timer"
? PropReturnDInterfaceTimer
: T extends { type: "$.interface.http" } | "$.interface.http"
? PropReturnDInterfaceHttp
: T extends { type: "$.service.db" } | "$.service.db"
? PropReturnDServiceDB
: any
type PropOptionalCheck<T> = T extends { optional: true }
? ConvertPropTypes<T> | undefined
: ConvertPropTypes<T>
export type ExtractPropTypes<P> = P extends object
? { [K in keyof P]: PropOptionalCheck<P[K]> }
: { [K in string]: any }
export type ComponentPropsOptions<P = Record<string, unknown>> =
| {
[K in keyof P]: Prop<P[K]> | null
}
| string[]