@gasket/core
Advanced tools
Comparing version
@@ -0,7 +1,22 @@ | ||
/* eslint-disable no-use-before-define */ | ||
declare module '@gasket/core' { | ||
/** | ||
* Allows a type to be a single value or an array of that type. | ||
* Useful for handling cases where a function accepts multiple values. | ||
*/ | ||
export type MaybeMultiple<T> = T | Array<T>; | ||
/** | ||
* Allows a type to be synchronous or asynchronous. | ||
* Used for functions that may return a Promise or a direct value. | ||
*/ | ||
export type MaybeAsync<T> = T | Promise<T>; | ||
/** | ||
* Extracts the resolved value from a Promise type. | ||
* If the type is not a Promise, it remains unchanged. | ||
*/ | ||
export type ResolvedType<T> = T extends Promise<infer Value> ? Value : T; | ||
export interface GasketActions {} | ||
export interface GasketActions { } | ||
@@ -15,12 +30,20 @@ export type ActionId = keyof GasketActions; | ||
// To be extended by plugins | ||
/** | ||
* Defines the lifecycle hooks that Gasket supports. | ||
* Plugins can extend this interface to add additional lifecycle hooks. | ||
*/ | ||
export interface HookExecTypes { | ||
// add makeGasket lifecycles | ||
init(): void | ||
configure(config: GasketConfig): GasketConfig | ||
ready(): MaybeAsync<void> | ||
prepare(config: GasketConfig): MaybeAsync<GasketConfig> | ||
/** Runs during initialization */ | ||
init(): void; | ||
/** Runs during configuration and can modify the configuration */ | ||
configure(config: GasketConfig): GasketConfig; | ||
/** Runs when the application is ready */ | ||
ready(): MaybeAsync<void>; | ||
/** Runs when preparing the application */ | ||
prepare(config: GasketConfig): MaybeAsync<GasketConfig>; | ||
} | ||
/** | ||
* Extracts the available hook names from `HookExecTypes`. | ||
*/ | ||
export type HookId = keyof HookExecTypes; | ||
@@ -67,19 +90,29 @@ | ||
// This is the config | ||
/** | ||
* Defines the base configuration for a Gasket application. | ||
*/ | ||
export interface GasketConfig { | ||
plugins: Array<Plugin>; | ||
plugins: Plugin[]; | ||
root: string; | ||
env: string; | ||
command?: string; | ||
} | ||
/** | ||
* Represents a Gasket configuration before it has been fully normalized. | ||
* Supports both direct Plugin objects and ES module Plugin imports. | ||
*/ | ||
export type PreNormalizedGasketConfig = Omit<GasketConfig, 'plugins'> & { | ||
plugins: Array<Plugin | { default: Plugin }>; | ||
} | ||
plugins: (Plugin | { default: Plugin })[]; | ||
}; | ||
/** | ||
* The core Gasket engine that manages plugins and lifecycle hooks. | ||
*/ | ||
export class GasketEngine { | ||
constructor(plugins: Array<Plugin>); | ||
constructor(plugins: Plugin[]); | ||
actions: GasketActions | ||
actions: GasketActions; | ||
registerPlugins(plugins: Array<Plugin>): void; | ||
registerPlugins(plugins: Plugin[]): void; | ||
exec<Id extends HookId>( | ||
@@ -101,2 +134,10 @@ hook: Id, | ||
): ResolvedType<ReturnType<HookExecTypes[Id]>>; | ||
execMap<Id extends HookId>( | ||
hook: Id, | ||
...args: Parameters<HookExecTypes[Id]> | ||
): Promise<Record<string, ResolvedType<ReturnType<HookExecTypes[Id]>>>>; | ||
execMapSync<Id extends HookId>( | ||
hook: Id, | ||
...args: Parameters<HookExecTypes[Id]> | ||
): Record<string, ResolvedType<ReturnType<HookExecTypes[Id]>>>; | ||
execApply<Id extends HookId, Return = void>( | ||
@@ -122,5 +163,8 @@ hook: Id, | ||
/** | ||
* Represents a Gasket instance. | ||
*/ | ||
export interface Gasket extends GasketEngine { | ||
constructor(config: GasketConfigDefinition); | ||
new (config: GasketConfigDefinition): Gasket | ||
new(config: GasketConfigDefinition): Gasket; | ||
@@ -132,6 +176,9 @@ isReady: Promise<void>; | ||
symbol: Symbol; | ||
traceBranch(): GasketTrace | ||
traceRoot(): Gasket | ||
traceBranch(): GasketTrace; | ||
traceRoot(): Gasket; | ||
} | ||
/** | ||
* A proxy type for tracing Gasket operations. | ||
*/ | ||
export type GasketTrace = Proxy<Gasket> & { | ||
@@ -159,4 +206,4 @@ trace: (msg: string) => void | ||
/** | ||
* Expected request shape for GasketActions | ||
* @deprecated - use class from @gasket/request | ||
* Represents a simplified request shape for actions. | ||
* @deprecated - Use class from `@gasket/request` instead. | ||
*/ | ||
@@ -169,3 +216,6 @@ export interface GasketRequest { | ||
export function makeGasket(config: GasketConfigDefinition): Gasket | ||
/** | ||
* Creates a new Gasket application with the given configuration. | ||
*/ | ||
export function makeGasket(config: GasketConfigDefinition): Gasket; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ActionHandler, GasketTrace, HookHandler } from '@gasket/core'; | ||
import type { ActionHandler, GasketTrace, HookHandler, GasketActions, Gasket } from '@gasket/core'; | ||
@@ -3,0 +3,0 @@ type isolateLifecycle<T> = (source: GasketTrace, name: string, fn: HookHandler<T>) => HookHandler<T> |
{ | ||
"name": "@gasket/core", | ||
"version": "7.2.2", | ||
"version": "7.2.3", | ||
"description": "Entry point to setting up Gasket instances", | ||
@@ -54,3 +54,3 @@ "type": "module", | ||
"dependencies": { | ||
"@gasket/utils": "^7.2.2", | ||
"@gasket/utils": "^7.2.3", | ||
"debug": "^4.3.4" | ||
@@ -67,4 +67,4 @@ }, | ||
"eslint-config-godaddy": "^7.1.1", | ||
"eslint-config-godaddy-typescript": "^4.0.3", | ||
"eslint-plugin-jest": "^28.6.0", | ||
"eslint-plugin-json": "^3.1.0", | ||
"eslint-plugin-unicorn": "^55.0.0", | ||
@@ -100,2 +100,13 @@ "jest": "^29.7.0", | ||
} | ||
}, | ||
{ | ||
"files": [ | ||
"lib/*.ts" | ||
], | ||
"extends": [ | ||
"godaddy-typescript" | ||
], | ||
"rules": { | ||
"jsdoc/*": "off" | ||
} | ||
} | ||
@@ -134,3 +145,3 @@ ] | ||
}, | ||
"gitHead": "f34775900acd2c6a6b3a224751c6dc091b7f50fe" | ||
"gitHead": "3fb21dbc6f75b8b9619a1e70073a504f84a29943" | ||
} |
@@ -50,3 +50,3 @@ # @gasket/core | ||
gasket.isReady.then(() => { | ||
gasket.actions.startServer(); | ||
gasket.actions.doSomething(); | ||
}); | ||
@@ -53,0 +53,0 @@ ``` |
140379
1.36%1844
2.73%Updated