From e5e7c9210ee221b5a3b5d1c0446a85ff43a5196d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?He=CC=84sperus?= Date: Mon, 22 Jun 2026 22:05:43 +0800 Subject: [PATCH] chore(context): clean up exports --- skill/example/index.ts | 6 +++--- src/context.ts | 18 +++++------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/skill/example/index.ts b/skill/example/index.ts index d4d55e4..4c88297 100644 --- a/skill/example/index.ts +++ b/skill/example/index.ts @@ -20,9 +20,9 @@ class PolisAlert { logs: Array; constructor(public options: MergeSingleKey) { - this.ctx = createContext(allModules, { mergeKeys: ['options', 'root'] }).__assign__({ - options, - }); + this.ctx = createContext(allModules, { + mergeKeys: ['options', 'root'], + }).__assign__({ options }); for (const ctor of allModules) this.ctx.__getModule__(ctor).onStart(); // Augmentation diff --git a/src/context.ts b/src/context.ts index cf83f92..32df462 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,16 +1,10 @@ type General = any; type GeneralObject = object; -type GeneralConstructor = - | (new (...args: Array) => General) - | (abstract new (...args: Array) => General); +type GeneralConstructor = new (...args: Array) => General; type ModuleConstructor = new (context: C) => General; type GeneralModuleInput = ReadonlyArray | ReadonlyArray; -export type ModuleInput = - | ReadonlyArray - | ReadonlyArray>; - type IsPlainObject = T extends object ? T extends Function | Date | RegExp | Array | Map | Set ? false @@ -76,7 +70,7 @@ export type Context< > = MergeResult & { __modules__: WeakMap>; __getModule__: (ctor: C) => InstanceType; - __addModule__: >>( + __addModule__: >>( newModule: N, ) => Context<[...M, N], K, Pr, Po>; __assign__: (obj: Partial>) => Context; @@ -127,25 +121,23 @@ function mergeShallow(target: Record, source: unknown) { * @param options Context build options. * @param options.preMerge Values merged before module construction. * @param options.postMerge Values merged after module merges. - * @param options.assign Final values assigned after all other merges. * @param options.mergeKeys Instance keys merged into context. * @param options.injectKeys Instance keys updated from final context. Defaults to * `mergeKeys`. * @returns Context object containing merged values plus module helper methods. */ export default function createContext< - Po extends object, - Pr extends object, M extends ReadonlyArray>>, K extends Keys[number]>, - I extends K = K, + Po extends object = {}, + Pr extends object = {}, >( classes: M, options: { preMerge?: Pr; postMerge?: Po; mergeKeys: ReadonlyArray; - injectKeys?: ReadonlyArray; + injectKeys?: ReadonlyArray>; }, ): Context { const context: Record = {};