@spaceteams/warp 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.d.mts +36 -34
  2. package/package.json +1 -1
package/dist/index.d.mts CHANGED
@@ -1,41 +1,43 @@
1
- //#region src/middleware.d.ts
2
- type NoRunOptions = NonNullable<unknown>;
3
- type NoScopeContext = NonNullable<unknown>;
4
- type Middleware<AmbientContext, RunOptions = NoRunOptions, ScopeContext = NoScopeContext> = <T>(ctx: AmbientContext, options: Partial<RunOptions>, next: (ctx: AmbientContext & ScopeContext) => Promise<T> | T) => Promise<T> | T;
5
- //#endregion
6
1
  //#region src/run.d.ts
7
- type Run<AmbientContext, RunOptions, ScopeContext = NoScopeContext> = AmbientContext & {
8
- run: <T>(options: RunOptions, inner: (app: Run<AmbientContext & Partial<ScopeContext>, RunOptions, ScopeContext>) => Promise<T> | T) => Promise<T> | T;
2
+ type Run<AmbientContext, ScopeContext = unknown, RunOptions = unknown> = AmbientContext & {
3
+ run: <T>(options: RunOptions, inner: (app: Run<AmbientContext & ScopeContext, ScopeContext, RunOptions>) => Promise<T> | T) => Promise<T> | T;
9
4
  };
10
5
  //#endregion
11
6
  //#region src/component/index.d.ts
12
7
  type NoDeps = NonNullable<unknown>;
13
8
  declare const COMPONENT: unique symbol;
14
- type ComponentRef<Ctx, RunOptions, Out> = {
9
+ type ComponentRef<Ctx, ScopeContext, RunOptions, Out> = {
15
10
  readonly [COMPONENT]: true;
16
11
  readonly __ctx?: Ctx;
12
+ readonly __scopeContext?: ScopeContext;
17
13
  readonly __runOptions?: RunOptions;
18
14
  readonly __out?: Out;
19
15
  };
20
- type ComponentFactory<Ctx, RunOptions, Deps, Out> = (ctx: Run<Ctx & Deps, RunOptions>) => Out;
21
- type ComponentInput<Ctx, RunOptions, Out> = ComponentRef<Ctx, RunOptions, Out> | Out;
22
- type Component<Ctx, RunOptions, Deps, Out> = ComponentRef<Ctx, RunOptions, Out> & {
23
- factory: ComponentFactory<Ctx, RunOptions, Deps, Out>;
24
- deps?: { [K in keyof Deps]: ComponentRef<Ctx, RunOptions, Deps[K]> };
16
+ type ComponentFactory<Ctx, ScopeContext, RunOptions, Deps, Out> = (ctx: Run<Ctx & Deps, ScopeContext, RunOptions>) => Out;
17
+ type ComponentInput<Ctx, ScopeContext, RunOptions, Out> = ComponentRef<Ctx, ScopeContext, RunOptions, Out> | Out;
18
+ type Component<Ctx, ScopeContext, RunOptions, Deps, Out> = ComponentRef<Ctx, ScopeContext, RunOptions, Out> & {
19
+ factory: ComponentFactory<Ctx, ScopeContext, RunOptions, Deps, Out>;
20
+ deps?: { [K in keyof Deps]: ComponentRef<Ctx, ScopeContext, RunOptions, Deps[K]> };
25
21
  name?: string;
26
22
  };
27
- type ComponentDefinition<Ctx, RunOptions, Deps, Out> = {
28
- factory: ComponentFactory<Ctx, RunOptions, Deps, Out>;
29
- deps?: { [K in keyof Deps]: ComponentInput<Ctx, RunOptions, Deps[K]> };
23
+ type ComponentDefinition<Ctx, ScopeContext, RunOptions, Deps, Out> = {
24
+ factory: ComponentFactory<Ctx, ScopeContext, RunOptions, Deps, Out>;
25
+ deps?: { [K in keyof Deps]: ComponentInput<Ctx, ScopeContext, RunOptions, Deps[K]> };
30
26
  name?: string;
31
27
  };
32
- type InferComponentParams<T> = T extends Component<infer Ctx, infer RunOptions, infer Deps, infer Out> ? [Ctx, RunOptions, Deps, Out] : never;
28
+ type InferComponentParams<T> = T extends Component<infer Ctx, infer ScopeContext, infer RunOptions, infer Deps, infer Out> ? [Ctx, ScopeContext, RunOptions, Deps, Out] : never;
33
29
  type InferComponentCtx<T> = InferComponentParams<T>[0];
34
- type InferComponentRunOptions<T> = InferComponentParams<T>[1];
35
- type InferComponentDeps<T> = InferComponentParams<T>[2];
36
- type InferComponentOut<T> = InferComponentParams<T>[3];
37
- declare function brandComponent<T extends object, Ctx, RunOptions, Out>(obj: T): T & ComponentRef<Ctx, RunOptions, Out>;
38
- declare function isComponent(value: unknown): value is Component<unknown, unknown, unknown, unknown>;
30
+ type InferComponentScopeContext<T> = InferComponentParams<T>[1];
31
+ type InferComponentRunOptions<T> = InferComponentParams<T>[2];
32
+ type InferComponentDeps<T> = InferComponentParams<T>[3];
33
+ type InferComponentOut<T> = InferComponentParams<T>[4];
34
+ declare function brandComponent<T extends object, Ctx, ScopeContext, RunOptions, Out>(obj: T): T & ComponentRef<Ctx, ScopeContext, RunOptions, Out>;
35
+ declare function isComponent(value: unknown): value is Component<unknown, unknown, unknown, unknown, unknown>;
36
+ //#endregion
37
+ //#region src/middleware.d.ts
38
+ type NoRunOptions = NonNullable<unknown>;
39
+ type NoScopeContext = NonNullable<unknown>;
40
+ type Middleware<AmbientContext, RunOptions = NoRunOptions, ScopeContext = NoScopeContext> = <T>(ctx: AmbientContext, options: Partial<RunOptions>, next: (ctx: AmbientContext & ScopeContext) => Promise<T> | T) => Promise<T> | T;
39
41
  //#endregion
40
42
  //#region src/runtime/explain.d.ts
41
43
  type ExplainResult = {
@@ -53,24 +55,24 @@ declare class Runtime<Ctx, ActualContext extends Ctx, ScopeContext, RunOptions,
53
55
  constructor(middleware: Middleware<Ctx, RunOptions, ScopeContext>, ctx: ActualContext);
54
56
  provide<Extension>(ext: Extension): Runtime<Ctx, ActualContext & Extension, ScopeContext, RunOptions, Requirements>;
55
57
  require<Extension>(): Runtime<Ctx, ActualContext, ScopeContext, RunOptions, SafeIntersect<Requirements, Extension>>;
56
- resolve: <Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps, Out>, ...requirements: OptionalArg<Requirements>) => Out | Promise<Out>;
57
- get component(): <Deps, F extends ComponentFactory<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps, ReturnType<F>>>(factory: F, deps?: { [T in keyof Deps]: ComponentInput<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps[T]> } | undefined, opts?: {
58
+ resolve: <Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps, Out>, ...requirements: OptionalArg<Requirements>) => Out | Promise<Out>;
59
+ get component(): <Deps, F extends ComponentFactory<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps, ReturnType<F>>>(factory: F, deps?: { [T in keyof Deps]: ComponentInput<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps[T]> } | undefined, opts?: {
58
60
  name?: string | undefined;
59
- } | undefined) => Component<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps, ReturnType<F>>;
60
- get classComponent(): <Deps, Ctor extends new (deps: Run<SafeIntersect<Requirements, ActualContext> & Deps, RunOptions>) => InstanceType<Ctor>>(ctor: Ctor, deps?: { [K in keyof Deps]: ComponentInput<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps[K]> } | undefined, opts?: {
61
+ } | undefined) => Component<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps, ReturnType<F>>;
62
+ get classComponent(): <Deps, Ctor extends new (deps: Run<SafeIntersect<Requirements, ActualContext> & Deps, ScopeContext, RunOptions>) => InstanceType<Ctor>>(ctor: Ctor, deps?: { [K in keyof Deps]: ComponentInput<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps[K]> } | undefined, opts?: {
61
63
  name?: string | undefined;
62
- } | undefined) => Component<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps, InstanceType<Ctor>>;
63
- explain<Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps, Out>, format: "native"): ExplainResult;
64
- explain<Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps, Out>, format: "ascii"): string;
65
- explain<Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps, Out>, format: "mermaid"): string;
66
- explain<Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, RunOptions, Deps, Out>): ExplainResult;
64
+ } | undefined) => Component<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps, InstanceType<Ctor>>;
65
+ explain<Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps, Out>, format: "native"): ExplainResult;
66
+ explain<Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps, Out>, format: "ascii"): string;
67
+ explain<Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps, Out>, format: "mermaid"): string;
68
+ explain<Deps, Out>(component: Component<SafeIntersect<Requirements, ActualContext>, ScopeContext, RunOptions, Deps, Out>): ExplainResult;
67
69
  }
68
70
  //#endregion
69
71
  //#region src/runtime/runtime-builder.d.ts
70
- declare class RuntimeBuilder<AmbientContext, Options, ScopeContext = NoScopeContext> {
72
+ declare class RuntimeBuilder<AmbientContext, ScopeContext = unknown, Options = unknown> {
71
73
  private readonly middlewares;
72
74
  constructor(middlewares?: Middleware<AmbientContext, Options, ScopeContext>[]);
73
- use<A, H, S>(mw: Middleware<A, H, S>): RuntimeBuilder<AmbientContext & A, Options & H, ScopeContext & S>;
75
+ use<A, S, H>(mw: Middleware<A, H, S>): RuntimeBuilder<AmbientContext & A, ScopeContext & S, Options & H>;
74
76
  provide<ActualCtx extends AmbientContext>(ctx: ActualCtx): Runtime<AmbientContext, ActualCtx, ScopeContext, Options, undefined>;
75
77
  private buildMiddleware;
76
78
  }
@@ -78,4 +80,4 @@ declare class RuntimeBuilder<AmbientContext, Options, ScopeContext = NoScopeCont
78
80
  //#region src/runtime/index.d.ts
79
81
  declare function buildRuntime(): RuntimeBuilder<Record<string, unknown>, unknown>;
80
82
  //#endregion
81
- export { Component, ComponentDefinition, ComponentFactory, ComponentInput, ComponentRef, InferComponentCtx, InferComponentDeps, InferComponentOut, InferComponentParams, InferComponentRunOptions, Middleware, NoDeps, NoRunOptions, NoScopeContext, Run, brandComponent, buildRuntime, isComponent };
83
+ export { Component, ComponentDefinition, ComponentFactory, ComponentInput, ComponentRef, InferComponentCtx, InferComponentDeps, InferComponentOut, InferComponentParams, InferComponentRunOptions, InferComponentScopeContext, Middleware, NoDeps, NoRunOptions, NoScopeContext, Run, brandComponent, buildRuntime, isComponent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spaceteams/warp",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Type-safe composition with execution scopes ",
5
5
  "type": "module",
6
6
  "files": [