-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
24 changed files
with
980 additions
and
442 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,4 +1,12 @@ | ||
import { Injected } from "nwire" | ||
import { AppContext } from "./AppContext" | ||
|
||
export class Service extends Injected<AppContext> {} | ||
export class Service extends Injected<AppContext> { | ||
get db() { | ||
return this._context.db | ||
} | ||
|
||
get tasks() { | ||
return this._context.tasks | ||
} | ||
} |
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
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
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
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
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,40 @@ | ||
export type Context = { | ||
[key: string]: unknown; | ||
}; | ||
export type Instance<TValue> = { | ||
new (context: any, ...args: any[]): TValue; | ||
}; | ||
type Flatten<T> = {} & { | ||
[P in keyof T]: T[P]; | ||
}; | ||
type AppendContext<TExisting, TKey extends string, TValue> = Flatten<TExisting & { | ||
[P in TKey]: TValue; | ||
}>; | ||
type RegistrationOptions = { | ||
transient?: boolean; | ||
}; | ||
export declare class Container<TContext extends Context = {}> { | ||
private _registry; | ||
private _resolvers; | ||
private _cache; | ||
private _transient; | ||
private _base; | ||
private _rootContainer; | ||
private _parentContainer; | ||
constructor(rootContainer?: Container, _parentContainer?: Container); | ||
get root(): this | Container<{}>; | ||
get parent(): this | Container<{}>; | ||
static new<T extends Context = {}>(): Container<T>; | ||
static build<T extends Context = {}>(): Container<T>; | ||
base<TBase extends Context>(base: TBase): Container<TContext & TBase>; | ||
createContextProxy(): Context; | ||
context<TWriteContext extends Context = TContext, TOverride extends Context = {}>(override?: TOverride | {}): Flatten<TWriteContext & TOverride>; | ||
group<TNewKey extends string, TNewContext extends Context>(key: TNewKey, decorator: (container: Container<{}>) => Container<TNewContext>): Container<TContext & { [key in TNewKey]: TNewContext; }>; | ||
singleton<TNewKey extends string, TValue>(key: TNewKey, ClassConstructor: Instance<TValue>, ...args: any[]): Container<TContext & { [P_1 in TNewKey]: TValue; } extends infer T ? { [P in keyof T]: (TContext & { [P_1 in TNewKey]: TValue; })[P]; } : never>; | ||
instance<TNewKey extends string, TValue>(key: TNewKey, ClassConstructor: Instance<TValue>, ...args: any[]): Container<TContext & { [P_1 in TNewKey]: TValue; } extends infer T ? { [P in keyof T]: (TContext & { [P_1 in TNewKey]: TValue; })[P]; } : never>; | ||
register<TNewKey extends string, TValue>(key: TNewKey, resolver: (context: TContext) => TValue, { transient }?: RegistrationOptions): Container<AppendContext<TContext, TNewKey, TValue>>; | ||
unregister<TNewKey extends string>(key: TNewKey): Container<Omit<TContext, TNewKey>>; | ||
resolve<TValue>(key: keyof TContext): TValue; | ||
middleware<TNewContext extends Context>(middleware: (container: Container<TContext>) => Container<TNewContext>): Container<TNewContext>; | ||
} | ||
export {}; |
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,12 @@ | ||
export declare class CountingSet<T> { | ||
private readonly _map; | ||
private readonly _set; | ||
add(value: T): this; | ||
delete(value: T): boolean; | ||
has(value: T): boolean; | ||
count(value: T): number; | ||
clear(): void; | ||
get size(): number; | ||
[Symbol.iterator](): Iterator<T>; | ||
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void; | ||
} |
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,10 @@ | ||
import { Context } from "./Container"; | ||
type PopulatedSingleton<T> = T & { | ||
[key in keyof T]: T[key]; | ||
}; | ||
export declare function WithContextProperties<T extends Context>(Base: any): new (context: T) => PopulatedSingleton<T>; | ||
export declare class Singleton<TContext extends Context> { | ||
protected _context: TContext; | ||
constructor(context: TContext); | ||
} | ||
export {}; |
Oops, something went wrong.