@spaceteams/warp 0.3.1 → 0.3.2
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.
- package/dist/index.d.mts +21 -6
- package/dist/index.mjs +11 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -17,6 +17,21 @@ type Run<AmbientContext, ScopeContext = unknown, RunOptions = unknown> = Ambient
|
|
|
17
17
|
warp?: WarpMeta;
|
|
18
18
|
};
|
|
19
19
|
//#endregion
|
|
20
|
+
//#region src/middleware.d.ts
|
|
21
|
+
type NoRunOptions = NonNullable<unknown>;
|
|
22
|
+
type NoScopeContext = NonNullable<unknown>;
|
|
23
|
+
type Middleware<AmbientContext, RunOptions = NoRunOptions, ScopeContext = NoScopeContext> = <T>(ctx: AmbientContext, options: Partial<RunOptions>, next: (ctx: AmbientContext & ScopeContext) => Promise<T> | T, warp?: WarpMeta | undefined) => Promise<T> | T;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/component/infer.d.ts
|
|
26
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
27
|
+
type AnyFactory = ((...args: never[]) => unknown) & {
|
|
28
|
+
meta?: ComponentMeta;
|
|
29
|
+
};
|
|
30
|
+
type InferCtx<T> = T extends ComponentFactory<infer Ctx, infer _SC, infer _RO, infer _Deps, infer _Out> ? Ctx : unknown;
|
|
31
|
+
type InferScopeContext<T> = T extends ComponentFactory<infer _Ctx, infer SC, infer _RO, infer _Deps, infer _Out> ? SC : NoScopeContext;
|
|
32
|
+
type InferRunOptions<T> = T extends ComponentFactory<infer _Ctx, infer _SC, infer RO, infer _Deps, infer _Out> ? RO : NoRunOptions;
|
|
33
|
+
type InferOut<T> = T extends ComponentFactory<infer _Ctx, infer _SC, infer _RO, infer _Deps, infer Out> ? Out : never;
|
|
34
|
+
//#endregion
|
|
20
35
|
//#region src/component/index.d.ts
|
|
21
36
|
type NoDeps = NonNullable<unknown>;
|
|
22
37
|
declare const COMPONENT: unique symbol;
|
|
@@ -45,11 +60,6 @@ type ComponentDefinition<Ctx, ScopeContext, RunOptions, Deps, Out> = {
|
|
|
45
60
|
declare function brandComponent<T extends object, Ctx, ScopeContext, RunOptions, Out>(obj: T): T & ComponentRef<Ctx, ScopeContext, RunOptions, Out>;
|
|
46
61
|
declare function isComponent(value: unknown): value is Component<unknown, unknown, unknown, unknown, unknown>;
|
|
47
62
|
//#endregion
|
|
48
|
-
//#region src/middleware.d.ts
|
|
49
|
-
type NoRunOptions = NonNullable<unknown>;
|
|
50
|
-
type NoScopeContext = NonNullable<unknown>;
|
|
51
|
-
type Middleware<AmbientContext, RunOptions = NoRunOptions, ScopeContext = NoScopeContext> = <T>(ctx: AmbientContext, options: Partial<RunOptions>, next: (ctx: AmbientContext & ScopeContext) => Promise<T> | T, warp?: WarpMeta | undefined) => Promise<T> | T;
|
|
52
|
-
//#endregion
|
|
53
63
|
//#region src/explain/index.d.ts
|
|
54
64
|
type ExplainResult = {
|
|
55
65
|
name: string | undefined;
|
|
@@ -115,6 +125,11 @@ type Client<Ctx, ScopeContext, Out, RunOptions> = ComponentFactory<Ctx, ScopeCon
|
|
|
115
125
|
declare function client<Ctx, Out, RunOptions = NoRunOptions, ScopeContext = NoScopeContext>(options: Omit<ComponentMeta, "kind">, fn: (app: Run<Ctx, ScopeContext, RunOptions>) => Out): Client<Ctx, ScopeContext, Out, RunOptions>;
|
|
116
126
|
type InferClient<T> = T extends Client<infer _Ctx, infer _ScopeContext, infer Out, infer _RunOptions> ? Out : never;
|
|
117
127
|
//#endregion
|
|
128
|
+
//#region src/semantic/combine.d.ts
|
|
129
|
+
type CombinedOutput<T extends Record<string, AnyFactory>> = { [K in keyof T]: ReturnType<T[K]> };
|
|
130
|
+
declare function combine<const T extends Record<string, AnyFactory>>(factories: T): ComponentFactory<UnionToIntersection<InferCtx<T[keyof T]>>, UnionToIntersection<InferScopeContext<T[keyof T]>>, UnionToIntersection<InferRunOptions<T[keyof T]>>, unknown, CombinedOutput<T>>;
|
|
131
|
+
type InferCombined<T> = T extends ComponentFactory<infer _Ctx, infer _ScopeContext, infer _RunOptions, infer _Deps, infer Out> ? Out : never;
|
|
132
|
+
//#endregion
|
|
118
133
|
//#region src/semantic/repo.d.ts
|
|
119
134
|
type Repo<Ctx, ScopeContext, Out, RunOptions> = ComponentFactory<Ctx, ScopeContext, RunOptions, unknown, Out>;
|
|
120
135
|
declare function repo<Ctx, Out, RunOptions = NoRunOptions, ScopeContext = NoScopeContext>(options: Omit<ComponentMeta, "kind">, fn: (app: Run<Ctx, ScopeContext, RunOptions>) => Out): Repo<Ctx, ScopeContext, Out, RunOptions>;
|
|
@@ -130,4 +145,4 @@ type Usecase<Ctx, ScopeContext, Args extends unknown[], Result, RunOptions> = Ca
|
|
|
130
145
|
declare function usecase<Ctx, Args extends unknown[], Result, RunOptions = NoRunOptions, ScopeContext = NoScopeContext>(options: RunOptions & Omit<ComponentMeta, "kind">, fn: (app: Run<Ctx, ScopeContext, RunOptions>) => (...args: Args) => Promise<Result>): Usecase<Ctx, ScopeContext, Args, Result, RunOptions>;
|
|
131
146
|
type InferUsecase<T> = InferCallable<T>;
|
|
132
147
|
//#endregion
|
|
133
|
-
export { Callable, Client, Component, ComponentDefinition, ComponentFactory, ComponentFactoryFn, ComponentInput, ComponentKind, ComponentMeta, ComponentRef, InferCallable, InferClient, InferRepo, InferService, InferUsecase, Middleware, NoDeps, NoRunOptions, NoScopeContext, Repo, Run, Service, Usecase, WarpMeta, brandComponent, buildRuntime, callable, client, isComponent, repo, service, usecase };
|
|
148
|
+
export { type AnyFactory, Callable, Client, CombinedOutput, Component, ComponentDefinition, ComponentFactory, ComponentFactoryFn, ComponentInput, ComponentKind, ComponentMeta, ComponentRef, InferCallable, InferClient, InferCombined, type InferCtx, type InferOut, InferRepo, type InferRunOptions, type InferScopeContext, InferService, InferUsecase, Middleware, NoDeps, NoRunOptions, NoScopeContext, Repo, Run, Service, type UnionToIntersection, Usecase, WarpMeta, brandComponent, buildRuntime, callable, client, combine, isComponent, repo, service, usecase };
|
package/dist/index.mjs
CHANGED
|
@@ -328,6 +328,16 @@ function client(options, fn) {
|
|
|
328
328
|
return factory;
|
|
329
329
|
}
|
|
330
330
|
//#endregion
|
|
331
|
+
//#region src/semantic/combine.ts
|
|
332
|
+
function combine(factories) {
|
|
333
|
+
const factory = (ctx) => {
|
|
334
|
+
const result = {};
|
|
335
|
+
for (const [key, f] of Object.entries(factories)) result[key] = f(ctx);
|
|
336
|
+
return result;
|
|
337
|
+
};
|
|
338
|
+
return factory;
|
|
339
|
+
}
|
|
340
|
+
//#endregion
|
|
331
341
|
//#region src/semantic/repo.ts
|
|
332
342
|
function repo(options, fn) {
|
|
333
343
|
const factory = fn;
|
|
@@ -358,4 +368,4 @@ function usecase(options, fn) {
|
|
|
358
368
|
}, fn);
|
|
359
369
|
}
|
|
360
370
|
//#endregion
|
|
361
|
-
export { brandComponent, buildRuntime, callable, client, isComponent, repo, service, usecase };
|
|
371
|
+
export { brandComponent, buildRuntime, callable, client, combine, isComponent, repo, service, usecase };
|