-
Notifications
You must be signed in to change notification settings - Fork 2
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
2b7cbc4
commit e45bb0c
Showing
7 changed files
with
59 additions
and
781 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,8 @@ | ||
declare const _default: (code: string, message: string | (string | undefined)[], ...contexts: Record<string, object>[]) => { | ||
[index: string]: unknown; | ||
code: string; | ||
name: string; | ||
message: string; | ||
stack?: string; | ||
}; | ||
export default _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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export type HookHandler<T> = (args: T, handler?: HookHandler<T>) => null | void | HookHandler<T> | Promise<HookHandler<T>>; | ||
export interface Hook<T> { | ||
after?: string | string[]; | ||
before?: string | string[]; | ||
handler: HookHandler<T>; | ||
name?: PropertyKey; | ||
plugin?: string; | ||
require?: string | string[]; | ||
} | ||
export interface Plugin<T> { | ||
hooks: { | ||
[name in keyof T]: Hook<T[name]>[] | Hook<T[name]> | HookHandler<T[name]>; | ||
}; | ||
name: PropertyKey; | ||
require?: string[]; | ||
} | ||
interface callArguments<T, K extends keyof T> { | ||
args: T[K]; | ||
handler: HookHandler<T[K]>; | ||
hooks?: Hook<T[K]>[]; | ||
name: K; | ||
} | ||
interface getArguments<T, K extends keyof T> { | ||
hooks?: Hook<T[K]>[]; | ||
name: K; | ||
sort?: boolean; | ||
} | ||
type CallFunction<T> = <K extends keyof T>(args: callArguments<T, K>) => Promise<unknown>; | ||
type CallSyncFunction<T> = <K extends keyof T>(args: callArguments<T, K>) => unknown; | ||
type GetFunction<T> = <K extends keyof T>(args: getArguments<T, K>) => Hook<T[K]>[]; | ||
interface Registry<T> { | ||
call: CallFunction<T>; | ||
call_sync: CallSyncFunction<T>; | ||
get: GetFunction<T>; | ||
register: (userPlugin: Plugin<T> | ((...args: unknown[]) => Plugin<T>)) => Registry<T>; | ||
registered: (name: PropertyKey) => boolean; | ||
} | ||
interface plugangplayArguments<T> { | ||
args?: unknown[]; | ||
chain?: Registry<T>; | ||
parent?: Registry<T>; | ||
plugins?: Plugin<T>[]; | ||
} | ||
declare const plugandplay: <T extends Record<string, unknown> = Record<string, unknown>>({ args, chain, parent, plugins, }?: plugangplayArguments<T>) => Registry<T>; | ||
export { plugandplay }; |
Oops, something went wrong.