-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20d0b74
commit 993f3e7
Showing
26 changed files
with
271 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { hasNonUndefinedKeys, type Writeable } from '../../lib/prelude.js' | ||
import type { ConfigurationIndex } from '../../types/ConfigurationIndex.js' | ||
import type { Configurator } from '../../types/configurator.js' | ||
import { Configurators } from '../../types/configurators/_namespace.js' | ||
import type { Context } from '../../types/context.js' | ||
|
||
export const contextFragmentConfigurationConfigure = < | ||
context extends Context, | ||
configurationInput extends ConfigurationIndex.Input, | ||
>(context: context, configurationInput: configurationInput): null | Writeable<ContextFragmentConfiguration> => { | ||
if (!hasNonUndefinedKeys(configurationInput)) return null | ||
// todo: performant checking if input changes configuration. If no change, then no copy context. | ||
// For default input resolvers we can do this automatically (shallow merge) | ||
// Any custom input resolvers would need to implement their own "is changed" logic. | ||
|
||
const configuration: Writeable<ContextFragmentConfiguration['configuration'] & ConfigurationIndex> = { | ||
...context.configuration, | ||
} | ||
|
||
for (const configuratorName in configurationInput) { | ||
const entry = configuration[configuratorName] | ||
const current = entry.configurator.inputResolver({ | ||
current: entry.current, | ||
input: configurationInput[configuratorName]!, | ||
}) | ||
const newEntry = Object.freeze({ | ||
...entry, | ||
current, | ||
}) | ||
configuration[configuratorName] = newEntry | ||
} | ||
|
||
const fragment = { | ||
configuration, | ||
} | ||
|
||
return fragment | ||
} | ||
|
||
export type ContextFragmentConfigurationConfigure< | ||
$Context extends Context, | ||
$ConfigurationInput extends ConfigurationIndex.Input, | ||
__ = { | ||
[_ in keyof $Context]: _ extends 'configuration' ? { | ||
readonly [_ in keyof $Context['configuration']]: _ extends keyof $ConfigurationInput | ||
? $ConfigurationInput[_] extends object ? { | ||
// @ts-expect-error Non-index type being used | ||
configurator: $Context['configuration'][_]['configurator'] | ||
current: Configurator.ApplyInputResolver$Func< | ||
// @ts-expect-error Non-index type being used | ||
$Context['configuration'][_]['configurator'], | ||
// @ts-expect-error Non-index type being used | ||
$Context['configuration'][_]['current'], | ||
$ConfigurationInput[_] | ||
> | ||
} | ||
: $Context['configuration'][_] | ||
: $Context['configuration'][_] | ||
} | ||
: $Context[_] | ||
}, | ||
> = __ | ||
|
||
// ------------------------------------------------------------ | ||
// Context Fragment | ||
// ------------------------------------------------------------ | ||
|
||
export interface ContextFragmentConfiguration { | ||
readonly configuration: { | ||
readonly output: { | ||
readonly configurator: Configurators.Output.OutputConfigurator | ||
readonly current: Configurators.Output.OutputConfigurator['default'] | ||
} | ||
readonly check: { | ||
readonly configurator: Configurators.Check.CheckConfigurator | ||
readonly current: Configurators.Check.CheckConfigurator['default'] | ||
} | ||
readonly schema: { | ||
readonly configurator: Configurators.Schema.SchemaConfigurator | ||
readonly current: Configurators.Schema.SchemaConfigurator['default'] | ||
} | ||
} | ||
} | ||
|
||
export const contextFragmentConfigurationEmpty: ContextFragmentConfiguration = { | ||
configuration: Object.freeze({ | ||
output: Object.freeze({ | ||
configurator: Configurators.Output.configurator, | ||
current: Configurators.Output.configurator.default, | ||
}), | ||
check: Object.freeze({ | ||
configurator: Configurators.Check.configurator, | ||
current: Configurators.Check.configurator.default, | ||
}), | ||
schema: Object.freeze({ | ||
configurator: Configurators.Schema.configurator, | ||
current: Configurators.Schema.configurator.default, | ||
}), | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../properties/addRequestInterceptor.test.ts → ...nt/properties/requestInterceptors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.