-
Notifications
You must be signed in to change notification settings - Fork 19
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
Showing
3 changed files
with
64 additions
and
60 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 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 |
---|---|---|
@@ -1,15 +1,41 @@ | ||
import type { TagNodeObject } from "@bbob/plugin-helper"; | ||
import type { BbobPluginOptions } from "@bbob/core"; | ||
import type { BBobCoreTagNodeTree, BBobPluginFunction, BBobPluginOptions } from "@bbob/core"; | ||
import type { process } from "./preset"; | ||
|
||
export type PresetFactoryOptions = Record<string, unknown> | ||
type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>> | ||
|
||
export type PresetTagFunction<Node extends object = TagNodeObject> = ( | ||
node: Node, | ||
core: BbobPluginOptions, | ||
options: PresetFactoryOptions | ||
) => Node | ||
|
||
export type PresetTagsDefinition<Name extends string = string> = Record<Name | string, PresetTagFunction> | ||
export type PresetTagsDefinition<Key extends string = string> = PartialRecord<Key, PresetTagFunction> | ||
|
||
export type PresetOptions = Record<string, unknown> | ||
export type PresetExtendCallback<Names extends string> = (defTags: PresetTagsDefinition<Names>, options: PresetOptions) => PresetTagsDefinition<Names> | ||
|
||
export type ProcessorFunction<Tags extends PresetTagsDefinition = PresetTagsDefinition> = typeof process<Tags>; | ||
|
||
export type ProcessorReturnType<Tags extends PresetTagsDefinition = PresetTagsDefinition> = ReturnType<ProcessorFunction<Tags>>; | ||
|
||
export interface PresetTagFunction<Node extends TagNodeObject = TagNodeObject, Options extends PresetOptions = PresetOptions> { | ||
( | ||
node: Node, | ||
data: BBobPluginOptions, | ||
options: Options | ||
): Node | ||
} | ||
|
||
export interface PresetExtendCallback<Tags, NewTags = Tags, Options extends PresetOptions = PresetOptions> { | ||
(defTags: Tags, options?: Options): NewTags | ||
} | ||
|
||
export interface PresetExecutor<Tags extends PresetTagsDefinition = PresetTagsDefinition, Options extends PresetOptions = PresetOptions> extends BBobPluginFunction { | ||
(tree: BBobCoreTagNodeTree, core?: BBobPluginOptions): ProcessorReturnType<Tags>; | ||
options: Options; | ||
} | ||
|
||
export interface PresetFactory< | ||
Tags extends PresetTagsDefinition = PresetTagsDefinition, | ||
RootOptions extends PresetOptions = PresetOptions, | ||
> { | ||
<Options extends RootOptions>(opts: Options): PresetExecutor<Tags, Options>; | ||
options?: RootOptions; | ||
extend: <NewTags extends PresetTagsDefinition = PresetTagsDefinition>( | ||
cb: PresetExtendCallback<Tags, NewTags, RootOptions> | ||
) => PresetFactory<NewTags, RootOptions>; | ||
} |
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