MCPcopy Create free account
hub / github.com/arktypeio/arktype / writeValidators

Function writeValidators

ark/aot/output.ts:43–80  ·  view source on GitHub ↗
(
	exportsByName: Record<string, StandaloneExport>,
	opts: StandaloneOptions,
	refusalsByName: Record<string, string[]>,
	inline: boolean
)

Source from the content-addressed store, hash-verified

41
42// one bad export refuses a whole artifact, so retry each alone
43export const writeValidators = (
44 exportsByName: Record<string, StandaloneExport>,
45 opts: StandaloneOptions,
46 refusalsByName: Record<string, string[]>,
47 inline: boolean
48): StandaloneModules => {
49 const write = (names: string[], combines = true): StandaloneModules => {
50 const exports = Object.fromEntries(
51 names.map(name => [name, exportsByName[name]])
52 )
53 return (inline ? precompileStandalone : precompileStandaloneModules)(
54 exports,
55 combines ? opts : { ...opts, combines: false }
56 )
57 }
58 let names = Object.keys(exportsByName)
59 let written: StandaloneModules
60 try {
61 written = write(names)
62 } catch {
63 names = names.filter(name => {
64 try {
65 write([name])
66 return true
67 } catch (e) {
68 refusalsByName[name] = reasonsOf(e)
69 return false
70 }
71 })
72 // e.g. every export under a configured locale
73 if (!names.length) return noValidators
74 written = write(names)
75 }
76 // a program choosing for its modules has chosen checkers
77 return combinesChecks(opts) && opts.combines === undefined ?
78 smallerOf(written, () => write(names, false), minifiedSizeOf)
79 : written
80}
81
82// fixes the configuration as a failed definition does
83export const writeParseErrorThrower = (

Callers 1

writeMethod · 0.90

Calls 5

reasonsOfFunction · 0.90
combinesChecksFunction · 0.90
smallerOfFunction · 0.90
filterMethod · 0.80
writeFunction · 0.70

Tested by

no test coverage detected