mirror of
https://github.com/morten-olsen/bob.git
synced 2026-02-08 01:46:29 +01:00
docs: improved webpage
This commit is contained in:
@@ -5,4 +5,4 @@ export {
|
||||
type CalulationResult,
|
||||
type PlanableWithPlugins,
|
||||
} from './algorithm/calulation';
|
||||
export { plugins } from './plugins/index';
|
||||
export { plugins, type AllPlugins } from './plugins';
|
||||
|
||||
@@ -7,4 +7,9 @@ const plugins = {
|
||||
capabilities,
|
||||
} satisfies Record<string, (...args: any[]) => Plugin>;
|
||||
|
||||
type AllPlugins = {
|
||||
[K in keyof typeof plugins]: ReturnType<(typeof plugins)[K]>;
|
||||
};
|
||||
|
||||
export type { AllPlugins };
|
||||
export { plugins };
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Expand, UnionToIntersection } from '../types/utils';
|
||||
import { GraphNode } from './node';
|
||||
import { Planable } from './planable';
|
||||
|
||||
@@ -20,16 +21,20 @@ type Plugin<TAttributes = any, TContext = any> = {
|
||||
|
||||
type Plugins = Record<string, Plugin>;
|
||||
|
||||
type PluginAttributes<TPlugins extends Plugins> = {
|
||||
type PluginAttributes<TPlugins extends Plugins> = MergeRecords<{
|
||||
[K in keyof TPlugins]: TPlugins[K] extends Plugin<infer TAttributes, any>
|
||||
? TAttributes
|
||||
: never;
|
||||
}[keyof TPlugins];
|
||||
}>;
|
||||
|
||||
type PluginContext<TPlugins extends Plugins> = {
|
||||
type MergeRecords<T extends Record<string, any>> = Expand<
|
||||
UnionToIntersection<T[keyof T]>
|
||||
>;
|
||||
|
||||
type PluginContext<TPlugins extends Plugins> = MergeRecords<{
|
||||
[K in keyof TPlugins]: TPlugins[K] extends Plugin<any, infer TContext>
|
||||
? TContext
|
||||
: never;
|
||||
}[keyof TPlugins];
|
||||
}>;
|
||||
|
||||
export type { Plugin, Plugins, PluginAttributes, PluginContext };
|
||||
|
||||
17
packages/algorithm/src/types/utils.ts
Normal file
17
packages/algorithm/src/types/utils.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
// expands object types one level deep
|
||||
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
||||
|
||||
// expands object types recursively
|
||||
type ExpandRecursively<T> = T extends object
|
||||
? T extends infer O
|
||||
? { [K in keyof O]: ExpandRecursively<O[K]> }
|
||||
: never
|
||||
: T;
|
||||
|
||||
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
||||
k: infer I,
|
||||
) => void
|
||||
? I
|
||||
: never;
|
||||
|
||||
export type { Expand, ExpandRecursively, UnionToIntersection };
|
||||
Reference in New Issue
Block a user