@ic-reactor/codegen 0.12.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/index.cjs +226 -625
- package/dist/index.d.cts +111 -4
- package/dist/index.d.ts +111 -4
- package/dist/index.js +216 -26
- package/package.json +3 -13
- package/src/generators/reactor.ts +15 -4
- package/src/index.ts +19 -3
- package/src/pipeline.ts +36 -9
- package/src/validate.test.ts +393 -0
- package/src/validate.ts +369 -0
- package/dist/chunk-VBCR5IVT.js +0 -609
- package/dist/renderer.cjs +0 -639
- package/dist/renderer.d.cts +0 -33
- package/dist/renderer.d.ts +0 -33
- package/dist/renderer.js +0 -14
- package/src/metadata-rules.json +0 -144
- package/src/metadata.ts +0 -157
- package/src/renderer.test.ts +0 -573
- package/src/renderer.ts +0 -515
package/dist/renderer.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BUILT_IN_FORMAT_HELPERS,
|
|
3
|
-
BUILT_IN_JSDOC_FORMAT_TYPES,
|
|
4
|
-
generateCodecDeclarations,
|
|
5
|
-
renderType,
|
|
6
|
-
sortDeclarations
|
|
7
|
-
} from "./chunk-VBCR5IVT.js";
|
|
8
|
-
export {
|
|
9
|
-
BUILT_IN_FORMAT_HELPERS,
|
|
10
|
-
BUILT_IN_JSDOC_FORMAT_TYPES,
|
|
11
|
-
generateCodecDeclarations,
|
|
12
|
-
renderType,
|
|
13
|
-
sortDeclarations
|
|
14
|
-
};
|
package/src/metadata-rules.json
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"defaultValidationMessages": {
|
|
3
|
-
"minimum": {
|
|
4
|
-
"template": "Must be at least {value}"
|
|
5
|
-
},
|
|
6
|
-
"maximum": {
|
|
7
|
-
"template": "Must be at most {value}"
|
|
8
|
-
},
|
|
9
|
-
"minLength": {
|
|
10
|
-
"template": "Must be at least {value} character{plural}"
|
|
11
|
-
},
|
|
12
|
-
"maxLength": {
|
|
13
|
-
"template": "Must be at most {value} character{plural}"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"email": {
|
|
17
|
-
"helper": "email",
|
|
18
|
-
"regex": "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$",
|
|
19
|
-
"jsonSchemaFormat": "email",
|
|
20
|
-
"errorMessage": "Must be a valid email address"
|
|
21
|
-
},
|
|
22
|
-
"date-time": {
|
|
23
|
-
"helper": "dateTime",
|
|
24
|
-
"regex": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|[+-](?:[01]\\d|2[0-3]):[0-5]\\d))$",
|
|
25
|
-
"jsonSchemaFormat": "date-time",
|
|
26
|
-
"errorMessage": "Must be a valid ISO datetime"
|
|
27
|
-
},
|
|
28
|
-
"datetime": {
|
|
29
|
-
"helper": "datetime",
|
|
30
|
-
"regex": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|[+-](?:[01]\\d|2[0-3]):[0-5]\\d))$",
|
|
31
|
-
"jsonSchemaFormat": "date-time",
|
|
32
|
-
"errorMessage": "Must be a valid ISO datetime"
|
|
33
|
-
},
|
|
34
|
-
"date": {
|
|
35
|
-
"helper": "date",
|
|
36
|
-
"regex": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$",
|
|
37
|
-
"jsonSchemaFormat": "date",
|
|
38
|
-
"errorMessage": "Must be a valid ISO date"
|
|
39
|
-
},
|
|
40
|
-
"time": {
|
|
41
|
-
"helper": "time",
|
|
42
|
-
"regex": "^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?$",
|
|
43
|
-
"errorMessage": "Must be a valid ISO time"
|
|
44
|
-
},
|
|
45
|
-
"duration": {
|
|
46
|
-
"helper": "duration",
|
|
47
|
-
"regex": "^P(?:(\\d+W)|(?!.*W)(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+([.,]\\d+)?S)?)?)$",
|
|
48
|
-
"jsonSchemaFormat": "duration",
|
|
49
|
-
"errorMessage": "Must be a valid ISO duration"
|
|
50
|
-
},
|
|
51
|
-
"url": {
|
|
52
|
-
"helper": "url",
|
|
53
|
-
"regex": "^[a-zA-Z][a-zA-Z\\d+.-]*:.+",
|
|
54
|
-
"jsonSchemaFormat": "uri",
|
|
55
|
-
"errorMessage": "Must be a valid URL"
|
|
56
|
-
},
|
|
57
|
-
"uri": {
|
|
58
|
-
"helper": "uri",
|
|
59
|
-
"regex": "^[a-zA-Z][a-zA-Z\\d+.-]*:.+",
|
|
60
|
-
"jsonSchemaFormat": "uri",
|
|
61
|
-
"errorMessage": "Must be a valid URI"
|
|
62
|
-
},
|
|
63
|
-
"httpsUrl": {
|
|
64
|
-
"helper": "httpsUrl",
|
|
65
|
-
"regex": "^https://.+",
|
|
66
|
-
"jsonSchemaFormat": "uri",
|
|
67
|
-
"errorMessage": "Must be a valid HTTPS URL"
|
|
68
|
-
},
|
|
69
|
-
"ipv4": {
|
|
70
|
-
"helper": "ipv4",
|
|
71
|
-
"regex": "^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.|$)){4}$",
|
|
72
|
-
"jsonSchemaFormat": "ipv4",
|
|
73
|
-
"errorMessage": "Must be a valid IPv4 address"
|
|
74
|
-
},
|
|
75
|
-
"ipv6": {
|
|
76
|
-
"helper": "ipv6",
|
|
77
|
-
"regex": "^((?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}|::1|::|(?:[0-9A-Fa-f]{1,4}:){1,7}:|(?:[0-9A-Fa-f]{1,4}:){1,6}:[0-9A-Fa-f]{1,4}|(?:[0-9A-Fa-f]{1,4}:){1,5}(?::[0-9A-Fa-f]{1,4}){1,2}|(?:[0-9A-Fa-f]{1,4}:){1,4}(?::[0-9A-Fa-f]{1,4}){1,3}|(?:[0-9A-Fa-f]{1,4}:){1,3}(?::[0-9A-Fa-f]{1,4}){1,4}|(?:[0-9A-Fa-f]{1,4}:){1,2}(?::[0-9A-Fa-f]{1,4}){1,5}|[0-9A-Fa-f]{1,4}:(?:(?::[0-9A-Fa-f]{1,4}){1,6}))$",
|
|
78
|
-
"jsonSchemaFormat": "ipv6",
|
|
79
|
-
"errorMessage": "Must be a valid IPv6 address"
|
|
80
|
-
},
|
|
81
|
-
"uuid": {
|
|
82
|
-
"helper": "uuid",
|
|
83
|
-
"regex": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$",
|
|
84
|
-
"jsonSchemaFormat": "uuid",
|
|
85
|
-
"errorMessage": "Must be a valid UUID"
|
|
86
|
-
},
|
|
87
|
-
"guid": {
|
|
88
|
-
"helper": "guid",
|
|
89
|
-
"regex": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$",
|
|
90
|
-
"jsonSchemaFormat": "uuid",
|
|
91
|
-
"errorMessage": "Must be a valid GUID"
|
|
92
|
-
},
|
|
93
|
-
"base64": {
|
|
94
|
-
"helper": "base64",
|
|
95
|
-
"regex": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
|
|
96
|
-
"contentEncoding": "base64",
|
|
97
|
-
"errorMessage": "Must be valid base64"
|
|
98
|
-
},
|
|
99
|
-
"base64url": {
|
|
100
|
-
"helper": "base64url",
|
|
101
|
-
"regex": "^[A-Za-z0-9_-]+$",
|
|
102
|
-
"errorMessage": "Must be valid base64url"
|
|
103
|
-
},
|
|
104
|
-
"cuid": {
|
|
105
|
-
"helper": "cuid",
|
|
106
|
-
"regex": "^c[a-z0-9]{24}$",
|
|
107
|
-
"errorMessage": "Must be a valid CUID"
|
|
108
|
-
},
|
|
109
|
-
"cuid2": {
|
|
110
|
-
"helper": "cuid2",
|
|
111
|
-
"regex": "^[a-z][a-z0-9]*$",
|
|
112
|
-
"errorMessage": "Must be a valid CUID2"
|
|
113
|
-
},
|
|
114
|
-
"ulid": {
|
|
115
|
-
"helper": "ulid",
|
|
116
|
-
"regex": "^[0-9A-HJKMNP-TV-Z]{26}$",
|
|
117
|
-
"errorMessage": "Must be a valid ULID"
|
|
118
|
-
},
|
|
119
|
-
"nanoid": {
|
|
120
|
-
"helper": "nanoid",
|
|
121
|
-
"regex": "^[A-Za-z0-9_-]{21}$",
|
|
122
|
-
"errorMessage": "Must be a valid nanoid"
|
|
123
|
-
},
|
|
124
|
-
"emoji": {
|
|
125
|
-
"helper": "emoji",
|
|
126
|
-
"regex": "^\\p{Extended_Pictographic}+$",
|
|
127
|
-
"errorMessage": "Must contain only emoji characters"
|
|
128
|
-
},
|
|
129
|
-
"cidrv4": {
|
|
130
|
-
"helper": "cidrv4",
|
|
131
|
-
"regex": "^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)/(?:3[0-2]|[12]?\\d)$",
|
|
132
|
-
"errorMessage": "Must be a valid IPv4 CIDR range"
|
|
133
|
-
},
|
|
134
|
-
"cidrv6": {
|
|
135
|
-
"helper": "cidrv6",
|
|
136
|
-
"regex": "^[0-9A-Fa-f:]+/(?:12[0-8]|1[01]\\d|\\d?\\d)$",
|
|
137
|
-
"errorMessage": "Must be a valid IPv6 CIDR range"
|
|
138
|
-
},
|
|
139
|
-
"mac": {
|
|
140
|
-
"helper": "mac",
|
|
141
|
-
"regex": "^(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$",
|
|
142
|
-
"errorMessage": "Must be a valid MAC address"
|
|
143
|
-
}
|
|
144
|
-
}
|
package/src/metadata.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import type { CandidMetadata } from "@ic-reactor/parser"
|
|
2
|
-
import metadataRules from "./metadata-rules.json"
|
|
3
|
-
|
|
4
|
-
export type JSDocFormatDefinition = {
|
|
5
|
-
regex?: string
|
|
6
|
-
errorMessage?: string
|
|
7
|
-
jsonSchemaFormat?: string
|
|
8
|
-
contentEncoding?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type CustomJSDocFormatTypes = Record<
|
|
12
|
-
string,
|
|
13
|
-
string | JSDocFormatDefinition
|
|
14
|
-
>
|
|
15
|
-
|
|
16
|
-
type ValidationBoundRule = {
|
|
17
|
-
template?: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type MetadataRulesFile = {
|
|
21
|
-
defaultValidationMessages?: Record<string, ValidationBoundRule>
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const metadataRulesFile = metadataRules as MetadataRulesFile
|
|
25
|
-
const defaultValidationMessages =
|
|
26
|
-
metadataRulesFile.defaultValidationMessages ?? {}
|
|
27
|
-
|
|
28
|
-
const rawRuleEntries = Object.entries(metadataRules).filter(
|
|
29
|
-
([type]) => type !== "defaultValidationMessages"
|
|
30
|
-
) as Array<
|
|
31
|
-
[
|
|
32
|
-
string,
|
|
33
|
-
{
|
|
34
|
-
helper?: string
|
|
35
|
-
regex?: string
|
|
36
|
-
jsonSchemaFormat?: string
|
|
37
|
-
contentEncoding?: string
|
|
38
|
-
errorMessage?: string
|
|
39
|
-
},
|
|
40
|
-
]
|
|
41
|
-
>
|
|
42
|
-
|
|
43
|
-
export const BUILT_IN_JSDOC_FORMAT_TYPES: Readonly<
|
|
44
|
-
Record<string, JSDocFormatDefinition>
|
|
45
|
-
> = Object.fromEntries(
|
|
46
|
-
rawRuleEntries.map(([type, rule]) => [
|
|
47
|
-
type,
|
|
48
|
-
{
|
|
49
|
-
regex: rule.regex,
|
|
50
|
-
jsonSchemaFormat: rule.jsonSchemaFormat,
|
|
51
|
-
contentEncoding: rule.contentEncoding,
|
|
52
|
-
errorMessage: rule.errorMessage,
|
|
53
|
-
},
|
|
54
|
-
])
|
|
55
|
-
) as Record<string, JSDocFormatDefinition>
|
|
56
|
-
|
|
57
|
-
export const BUILT_IN_FORMAT_HELPERS: Readonly<Record<string, string>> =
|
|
58
|
-
Object.fromEntries(
|
|
59
|
-
rawRuleEntries
|
|
60
|
-
.filter(([, rule]) => rule.helper)
|
|
61
|
-
.map(([type, rule]) => [type, rule.helper as string])
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
export interface FormatResolutionOptions {
|
|
65
|
-
customJSDocFormatTypes?: CustomJSDocFormatTypes
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function normalizeFormatDefinition(
|
|
69
|
-
definition: CustomJSDocFormatTypes[string] | undefined
|
|
70
|
-
): JSDocFormatDefinition | undefined {
|
|
71
|
-
if (!definition) return undefined
|
|
72
|
-
return typeof definition === "string" ? { regex: definition } : definition
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function formatDefinitionFor(
|
|
76
|
-
type: string,
|
|
77
|
-
options: FormatResolutionOptions
|
|
78
|
-
): JSDocFormatDefinition | undefined {
|
|
79
|
-
const builtIn = BUILT_IN_JSDOC_FORMAT_TYPES[type]
|
|
80
|
-
const custom = normalizeFormatDefinition(
|
|
81
|
-
options.customJSDocFormatTypes?.[type]
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
if (!custom) return builtIn
|
|
85
|
-
return {
|
|
86
|
-
...builtIn,
|
|
87
|
-
...custom,
|
|
88
|
-
errorMessage: custom.errorMessage ?? builtIn?.errorMessage,
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function stripUndefined<T extends Record<string, unknown>>(value: T): T {
|
|
93
|
-
return Object.fromEntries(
|
|
94
|
-
Object.entries(value).filter(([, entry]) => entry !== undefined)
|
|
95
|
-
) as T
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function defaultBoundMessage(
|
|
99
|
-
kind: "minimum" | "maximum" | "minLength" | "maxLength",
|
|
100
|
-
value: string
|
|
101
|
-
): string {
|
|
102
|
-
const template =
|
|
103
|
-
defaultValidationMessages[kind]?.template ??
|
|
104
|
-
(kind === "minimum"
|
|
105
|
-
? "Must be at least {value}"
|
|
106
|
-
: kind === "maximum"
|
|
107
|
-
? "Must be at most {value}"
|
|
108
|
-
: kind === "minLength"
|
|
109
|
-
? "Must be at least {value} character{plural}"
|
|
110
|
-
: "Must be at most {value} character{plural}")
|
|
111
|
-
|
|
112
|
-
return template
|
|
113
|
-
.replace("{value}", value)
|
|
114
|
-
.replace("{plural}", value === "1" ? "" : "s")
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function withDefaultBoundMessage<
|
|
118
|
-
T extends { value: string; message?: string } | undefined,
|
|
119
|
-
>(bound: T, kind: "minimum" | "maximum" | "minLength" | "maxLength"): T {
|
|
120
|
-
if (!bound || bound.message !== undefined) return bound
|
|
121
|
-
return {
|
|
122
|
-
...bound,
|
|
123
|
-
message: defaultBoundMessage(kind, bound.value),
|
|
124
|
-
} as T
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function normalizeValidationMetadata(
|
|
128
|
-
validation: NonNullable<CandidMetadata["validation"]>,
|
|
129
|
-
options: FormatResolutionOptions
|
|
130
|
-
): NonNullable<CandidMetadata["validation"]> {
|
|
131
|
-
const normalized = {
|
|
132
|
-
...validation,
|
|
133
|
-
minimum: withDefaultBoundMessage(validation.minimum, "minimum"),
|
|
134
|
-
maximum: withDefaultBoundMessage(validation.maximum, "maximum"),
|
|
135
|
-
minLength: withDefaultBoundMessage(validation.minLength, "minLength"),
|
|
136
|
-
maxLength: withDefaultBoundMessage(validation.maxLength, "maxLength"),
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const format = validation.format
|
|
140
|
-
const formatDefinition = format
|
|
141
|
-
? formatDefinitionFor(format.type, options)
|
|
142
|
-
: undefined
|
|
143
|
-
|
|
144
|
-
if (format && formatDefinition) {
|
|
145
|
-
normalized.format = stripUndefined({
|
|
146
|
-
...format,
|
|
147
|
-
regex: formatDefinition.regex,
|
|
148
|
-
jsonSchemaFormat: formatDefinition.jsonSchemaFormat,
|
|
149
|
-
contentEncoding: formatDefinition.contentEncoding,
|
|
150
|
-
errorMessage: format.message ?? formatDefinition.errorMessage,
|
|
151
|
-
})
|
|
152
|
-
} else if (format) {
|
|
153
|
-
normalized.format = format
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return normalized
|
|
157
|
-
}
|