docs: improved webpage

This commit is contained in:
Morten Olsen
2023-09-26 21:14:31 +02:00
parent c00b073d37
commit 5d8cba0ddd
54 changed files with 1358 additions and 693 deletions

View File

@@ -5,4 +5,4 @@ export {
type CalulationResult,
type PlanableWithPlugins,
} from './algorithm/calulation';
export { plugins } from './plugins/index';
export { plugins, type AllPlugins } from './plugins';

View File

@@ -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 };

View File

@@ -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 };

View 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 };