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

Function configure

ark/schema/runtime.ts:56–89  ·  view source on GitHub ↗
(
	config: ArkSchemaConfig,
	fingerprint?: string
)

Source from the content-addressed store, hash-verified

54let configureIslands: ((config: ArkSchemaConfig) => unknown) | undefined
55
56export const configure = (
57 config: ArkSchemaConfig,
58 fingerprint?: string
59): ArkSchemaConfig => {
60 // arktype's config is fixed at its first Type, and the build's is one
61 // call's. Called again, as when a test runner resets its modules and the
62 // config module runs again, the same values change nothing
63 if (Object.isFrozen(runtimeConfig) || checkConfigured) {
64 return isSameConfig(config, programConfig ?? {}) ? config : (
65 throwParseError(reconfiguredMessage)
66 )
67 }
68 const received = fingerprintOf(config)
69 // a loader can rewrite the config module after the build read it
70 if (fingerprint !== undefined && fingerprint !== received)
71 return throwParseError(configuredUnlikeBuildMessage)
72 configureIslands?.(config)
73 if ("onFail" in config)
74 (runtimeConfig as { onFail: unknown }).onFail = config.onFail
75 let isRechecked = false
76 checkConfigured = built => {
77 // configure()'s argument may be written after the call
78 if (!isRechecked && fingerprintOf(config) !== received)
79 throwParseError(writtenConfigMessage)
80 // only once it passes, so a validator after a caught throw checks again
81 isRechecked = true
82 // an untransformed call, e.g. a dependency's, has no fingerprint
83 if (fingerprint === undefined || built !== fingerprint)
84 throwParseError(configMismatchMessage)
85 }
86 // copied, as arktype copies configure()'s argument
87 programConfig = copyConfig(config)
88 return config
89}
90
91export const configuredWriterOf =
92 (code: string, k: string) =>

Callers 15

testJitless.tsFile · 0.50
config.tsFile · 0.50
node10.tsFile · 0.50
.otherCopy.tsFile · 0.50
arktypeConfig.tsFile · 0.50
ambient.test.tsFile · 0.50
config.test.tsFile · 0.50
locale.test.tsFile · 0.50
simpleConfig.tsFile · 0.50
allConfig.tsFile · 0.50

Calls 4

isSameConfigFunction · 0.90
throwParseErrorFunction · 0.90
copyConfigFunction · 0.90
fingerprintOfFunction · 0.70

Tested by 1

reconfigureFunction · 0.40