@loutrejs/loutre 0.5.0 → 0.6.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.
- package/README.md +63 -32
- package/dist/adapters/aws-lambda.d.ts +5 -3
- package/dist/adapters/aws-lambda.js +53 -23
- package/dist/adapters/bun.d.ts +7 -4
- package/dist/adapters/bun.js +52 -42
- package/dist/adapters/cloudflare-workers.d.ts +5 -3
- package/dist/adapters/cloudflare-workers.js +23 -28
- package/dist/adapters/deno.d.ts +7 -4
- package/dist/adapters/deno.js +94 -57
- package/dist/adapters/electron.d.ts +13 -5
- package/dist/adapters/electron.js +76 -28
- package/dist/application/definition.d.ts +31 -0
- package/dist/application/definition.js +16 -0
- package/dist/application/index.d.ts +4 -63
- package/dist/application/index.js +2 -11
- package/dist/application/kernel-internal.d.ts +2 -0
- package/dist/application/kernel-internal.js +10 -0
- package/dist/application/kernel.d.ts +21 -0
- package/dist/application/kernel.js +65 -0
- package/dist/core/diagnostic.d.ts +9 -0
- package/dist/core/diagnostic.js +9 -0
- package/dist/core/extension.d.ts +107 -0
- package/dist/core/extension.js +73 -0
- package/dist/core/generic-layer.d.ts +26 -0
- package/dist/core/generic-layer.js +116 -0
- package/dist/core/index.d.ts +31 -15
- package/dist/core/index.js +15 -15
- package/dist/core/injection.d.ts +4 -13
- package/dist/core/injection.js +63 -0
- package/dist/core/model/context.d.ts +18 -0
- package/dist/core/model/context.js +34 -0
- package/dist/core/model/lifecycle.d.ts +5 -0
- package/dist/core/model/lifecycle.js +44 -0
- package/dist/core/model/modules.d.ts +2 -0
- package/dist/core/model/modules.js +101 -0
- package/dist/core/model/providers.d.ts +4 -0
- package/dist/core/model/providers.js +74 -0
- package/dist/core/model/snapshot.d.ts +6 -0
- package/dist/core/model/snapshot.js +31 -0
- package/dist/core/model/types.d.ts +78 -0
- package/dist/core/model/validation.d.ts +4 -0
- package/dist/core/model/validation.js +40 -0
- package/dist/core/model/visibility.d.ts +4 -0
- package/dist/core/model/visibility.js +20 -0
- package/dist/core/model.d.ts +10 -0
- package/dist/core/model.js +346 -0
- package/dist/core/module.d.ts +8 -13
- package/dist/core/source-location.d.ts +8 -0
- package/dist/core/source-location.js +31 -0
- package/dist/core/token-internal.d.ts +3 -0
- package/dist/core/token-internal.js +4 -0
- package/dist/core/type.d.ts +7 -0
- package/dist/core/type.js +4 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/graph/index.d.ts +2 -3
- package/dist/graph/index.js +1 -3
- package/dist/graph/model.d.ts +34 -0
- package/dist/graph/model.js +127 -0
- package/dist/http/auth.d.ts +46 -0
- package/dist/http/auth.js +96 -0
- package/dist/http/client.d.ts +28 -31
- package/dist/http/client.js +58 -44
- package/dist/http/cors-internal.d.ts +29 -0
- package/dist/http/cors-internal.js +160 -0
- package/dist/http/cors.d.ts +5 -8
- package/dist/http/cors.js +7 -165
- package/dist/http/extension.d.ts +348 -0
- package/dist/http/extension.js +947 -0
- package/dist/http/index.d.ts +9 -7
- package/dist/http/index.js +5 -7
- package/dist/{application → http}/openapi.d.ts +12 -3
- package/dist/{application → http}/openapi.js +164 -102
- package/dist/http/path.d.ts +1 -42
- package/dist/http/path.js +1 -2
- package/dist/http/runtime/request.d.ts +17 -0
- package/dist/http/runtime/request.js +109 -0
- package/dist/http/runtime/response.d.ts +18 -0
- package/dist/http/runtime/response.js +108 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/message-port/extension.d.ts +66 -0
- package/dist/message-port/extension.js +395 -0
- package/dist/message-port/index.d.ts +4 -73
- package/dist/message-port/index.js +2 -189
- package/dist/message-port/transport.d.ts +11 -0
- package/dist/message-port/transport.js +45 -0
- package/dist/runtime/async-iterator-lifecycle.d.ts +12 -0
- package/dist/runtime/async-iterator-lifecycle.js +95 -0
- package/dist/runtime/capability.d.ts +11 -11
- package/dist/runtime/capability.js +3 -3
- package/dist/runtime/di.d.ts +2 -22
- package/dist/runtime/di.js +8 -285
- package/dist/runtime/execution-tracker.d.ts +8 -0
- package/dist/runtime/execution-tracker.js +54 -0
- package/dist/runtime/index.d.ts +15 -9
- package/dist/runtime/index.js +9 -9
- package/dist/runtime/ingress-gate.d.ts +7 -0
- package/dist/runtime/ingress-gate.js +33 -0
- package/dist/runtime/kernel.d.ts +23 -0
- package/dist/runtime/kernel.js +354 -0
- package/dist/runtime/logger.d.ts +2 -0
- package/dist/runtime/logger.js +2 -0
- package/dist/runtime/node-capabilities.d.ts +1 -1
- package/dist/runtime/node-capabilities.js +1 -1
- package/dist/runtime/server-port.d.ts +2 -0
- package/dist/runtime/server-port.js +11 -0
- package/dist/tasks/extension.d.ts +144 -0
- package/dist/tasks/extension.js +499 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.js +1 -0
- package/dist/tasks/runtime/cron.d.ts +6 -0
- package/dist/tasks/runtime/cron.js +89 -0
- package/dist/websocket/errors.d.ts +9 -0
- package/dist/websocket/errors.js +18 -0
- package/dist/websocket/extension.d.ts +154 -0
- package/dist/websocket/extension.js +524 -0
- package/dist/websocket/index.d.ts +3 -0
- package/dist/websocket/index.js +2 -0
- package/package.json +12 -16
- package/dist/application/binding.d.ts +0 -33
- package/dist/application/binding.js +0 -295
- package/dist/application/host.d.ts +0 -8
- package/dist/application/host.js +0 -14
- package/dist/application/queue.d.ts +0 -3
- package/dist/application/queue.js +0 -4
- package/dist/application/scheduler.d.ts +0 -2
- package/dist/application/scheduler.js +0 -45
- package/dist/core/context-key.d.ts +0 -16
- package/dist/core/context-key.js +0 -17
- package/dist/core/contract-internal.d.ts +0 -22
- package/dist/core/contract-internal.js +0 -61
- package/dist/core/contract.d.ts +0 -96
- package/dist/core/contract.js +0 -88
- package/dist/core/execution.d.ts +0 -78
- package/dist/core/execution.js +0 -61
- package/dist/core/implementation.d.ts +0 -44
- package/dist/core/implementation.js +0 -35
- package/dist/core/layer.d.ts +0 -137
- package/dist/core/layer.js +0 -81
- package/dist/graph/compiler.d.ts +0 -4
- package/dist/graph/compiler.js +0 -228
- package/dist/graph/graph.d.ts +0 -18
- package/dist/graph/graph.js +0 -1118
- package/dist/graph/ir.d.ts +0 -175
- package/dist/http/application.d.ts +0 -18
- package/dist/http/application.js +0 -515
- package/dist/http/basic-auth.d.ts +0 -37
- package/dist/http/basic-auth.js +0 -67
- package/dist/http/definitions.d.ts +0 -363
- package/dist/http/definitions.js +0 -310
- package/dist/http/hosted-protocol.d.ts +0 -4
- package/dist/http/hosted-protocol.js +0 -4
- package/dist/http/internal.d.ts +0 -8
- package/dist/http/internal.js +0 -1
- package/dist/http/params.d.ts +0 -2
- package/dist/http/params.js +0 -19
- package/dist/http/request-body.d.ts +0 -4
- package/dist/http/request-body.js +0 -6
- package/dist/http/validate.d.ts +0 -20
- package/dist/http/validate.js +0 -6
- package/dist/message-port/environment.d.ts +0 -2
- package/dist/message-port/environment.js +0 -4
- package/dist/runtime/application.d.ts +0 -38
- package/dist/runtime/application.js +0 -339
- package/dist/runtime/pipeline.d.ts +0 -11
- package/dist/runtime/pipeline.js +0 -161
- /package/dist/{graph/ir.js → core/model/types.js} +0 -0
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import type { ContractBinding, ContractDefinition, ContractOfBinding, ResolvedContractNode, ContextProvidedBeforeTerminal, HasValidationBeforeTerminal, IsValidProtocolPipeline, PipelineItem, ProcedureDefinition, ProtocolDescriptor, ProtocolFactory, ProtocolGroup, SchemaInput, SchemaOutput, ShortCircuitDeclarationsOf, ShortCircuitResultOf, StandardSchemaV1, TerminalLayerDescriptor, ValidationLayerDescriptor } from '../core/index.js';
|
|
2
|
-
import { protocolNamespaceType } from '../core/contract-internal.js';
|
|
3
|
-
import { httpNodeMetadata } from './internal.js';
|
|
4
|
-
import type { Logger } from '../runtime/index.js';
|
|
5
|
-
import { type HttpDispatchKey, type IsValidHttpMethod, type IsValidHttpPath, type PathParamNames, type RawPathParams } from './path.js';
|
|
6
|
-
export type HttpParamsSchemas = Readonly<Record<string, StandardSchemaV1>>;
|
|
7
|
-
export interface HttpRequestBodyDefinition<TSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
8
|
-
readonly contentType: string;
|
|
9
|
-
readonly schema: TSchema;
|
|
10
|
-
}
|
|
11
|
-
export interface HttpRequestDefinition {
|
|
12
|
-
readonly params?: HttpParamsSchemas;
|
|
13
|
-
readonly query?: StandardSchemaV1;
|
|
14
|
-
readonly headers?: StandardSchemaV1;
|
|
15
|
-
readonly body?: HttpRequestBodyDefinition;
|
|
16
|
-
}
|
|
17
|
-
export type HttpHeaderValue = string | readonly string[];
|
|
18
|
-
export type HttpHeaders = Readonly<Record<string, HttpHeaderValue | undefined>>;
|
|
19
|
-
export interface HttpErrorMatcher<TError extends {
|
|
20
|
-
readonly data: unknown;
|
|
21
|
-
}> {
|
|
22
|
-
is(error: unknown): error is TError;
|
|
23
|
-
}
|
|
24
|
-
export interface HttpErrorMapping<TError extends {
|
|
25
|
-
readonly data: unknown;
|
|
26
|
-
} = {
|
|
27
|
-
readonly data: unknown;
|
|
28
|
-
}, TResult = unknown> {
|
|
29
|
-
readonly kind: 'http-error-mapping';
|
|
30
|
-
readonly definition: HttpErrorMatcher<TError>;
|
|
31
|
-
readonly map: (error: TError) => TResult | Promise<TResult>;
|
|
32
|
-
}
|
|
33
|
-
export interface HttpResponseDefinition {
|
|
34
|
-
readonly status: number;
|
|
35
|
-
readonly description?: string;
|
|
36
|
-
readonly body: StandardSchemaV1;
|
|
37
|
-
readonly headers?: StandardSchemaV1;
|
|
38
|
-
readonly staticHeaders?: HttpHeaders;
|
|
39
|
-
readonly error?: HttpErrorMapping<any, any>;
|
|
40
|
-
readonly stream?: 'server';
|
|
41
|
-
}
|
|
42
|
-
export interface HttpProtocolDefinition {
|
|
43
|
-
readonly method: string;
|
|
44
|
-
readonly path: string;
|
|
45
|
-
readonly summary?: string;
|
|
46
|
-
readonly description?: string;
|
|
47
|
-
readonly tags?: readonly string[];
|
|
48
|
-
readonly deprecated?: boolean;
|
|
49
|
-
readonly request?: HttpRequestDefinition;
|
|
50
|
-
readonly responses: Readonly<Record<string, HttpResponseDefinition>>;
|
|
51
|
-
readonly pipeline: readonly PipelineItem[];
|
|
52
|
-
readonly interaction?: 'unary' | 'server-stream';
|
|
53
|
-
}
|
|
54
|
-
export interface HttpBranchDefinition {
|
|
55
|
-
readonly path?: string;
|
|
56
|
-
readonly pipeline?: readonly PipelineItem[];
|
|
57
|
-
readonly responses?: Readonly<Record<string, HttpResponseDefinition>>;
|
|
58
|
-
readonly routes: HttpRouteTree;
|
|
59
|
-
}
|
|
60
|
-
export type HttpRouteTree = Readonly<Record<string, HttpProtocolDefinition | HttpBranchDefinition | HttpResolvedNode>>;
|
|
61
|
-
interface HttpResolvedNodeMetadata<TSource extends HttpProtocolDefinition | HttpBranchDefinition = HttpProtocolDefinition | HttpBranchDefinition, THandlerName extends string | never = string | never> {
|
|
62
|
-
readonly kind: 'leaf' | 'branch';
|
|
63
|
-
readonly source: TSource;
|
|
64
|
-
readonly handlerName: THandlerName;
|
|
65
|
-
}
|
|
66
|
-
export type HttpResolvedLeaf<THandlerName extends string = string, TSource extends HttpProtocolDefinition = HttpProtocolDefinition, TEffective extends HttpProtocolDefinition = HttpProtocolDefinition> = ResolvedContractNode<ContractDefinition<{
|
|
67
|
-
readonly [K in THandlerName]: {
|
|
68
|
-
readonly kind: 'procedure';
|
|
69
|
-
readonly protocols: {
|
|
70
|
-
readonly http: HttpProtocol<TEffective>;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
}>, 'leaf'> & {
|
|
74
|
-
readonly [httpNodeMetadata]: HttpResolvedNodeMetadata<TSource, THandlerName> & {
|
|
75
|
-
readonly kind: 'leaf';
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
type ResolvedContractOf<TNode> = TNode extends ResolvedContractNode<infer TContract> ? TContract : never;
|
|
79
|
-
type HttpProtocolOfResolvedLeaf<TNode> = ResolvedContractOf<TNode> extends ContractDefinition<infer TProcedures> ? TProcedures[keyof TProcedures & string]['protocols'] extends {
|
|
80
|
-
readonly http: infer TProtocol extends ProtocolDescriptor<'http'>;
|
|
81
|
-
} ? TProtocol : never : never;
|
|
82
|
-
type FlatResolvedHttpProcedures<TChildren extends Readonly<Record<string, unknown>>, TPrefix extends string = ''> = UnionToIntersection<{
|
|
83
|
-
[K in keyof TChildren & string]: TChildren[K] extends HttpResolvedLeaf<any, any, any> ? {
|
|
84
|
-
readonly [P in JoinProcedurePath<TPrefix, K>]: ProcedureDefinition<{
|
|
85
|
-
readonly http: HttpProtocolOfResolvedLeaf<TChildren[K]>;
|
|
86
|
-
}>;
|
|
87
|
-
} : TChildren[K] extends HttpResolvedBranch<any, infer TGrandchildren> ? FlatResolvedHttpProcedures<TGrandchildren, JoinProcedurePath<TPrefix, K>> : never;
|
|
88
|
-
}[keyof TChildren & string]> extends infer TProcedures extends Record<string, ProcedureDefinition> ? TProcedures : never;
|
|
89
|
-
export type HttpResolvedBranch<TSource extends HttpBranchDefinition = HttpBranchDefinition, TChildren extends Readonly<Record<string, HttpResolvedNode>> = Readonly<Record<string, HttpResolvedNode>>> = ResolvedContractNode<ContractDefinition<FlatResolvedHttpProcedures<TChildren>>, 'branch'> & TChildren & {
|
|
90
|
-
readonly [httpNodeMetadata]: HttpResolvedNodeMetadata<TSource, never> & {
|
|
91
|
-
readonly kind: 'branch';
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
export type HttpResolvedNode = ResolvedContractNode<ContractDefinition, 'leaf' | 'branch'> & {
|
|
95
|
-
readonly [httpNodeMetadata]: HttpResolvedNodeMetadata;
|
|
96
|
-
};
|
|
97
|
-
type SourceOfHttpNode<TNode> = TNode extends {
|
|
98
|
-
readonly [httpNodeMetadata]: HttpResolvedNodeMetadata<infer TSource, any>;
|
|
99
|
-
} ? TSource : TNode;
|
|
100
|
-
type HandlerNameOfHttpNode<TName extends string, TNode> = TNode extends {
|
|
101
|
-
readonly [httpNodeMetadata]: HttpResolvedNodeMetadata<any, infer THandlerName>;
|
|
102
|
-
} ? [THandlerName] extends [never] ? TName : THandlerName & string : TName;
|
|
103
|
-
type BranchPathOf<TBranch extends HttpBranchDefinition> = TBranch extends {
|
|
104
|
-
readonly path: infer TPath extends string;
|
|
105
|
-
} ? TPath : '';
|
|
106
|
-
type BranchPipelineOf<TBranch extends HttpBranchDefinition> = TBranch extends {
|
|
107
|
-
readonly pipeline: infer TPipeline extends readonly PipelineItem[];
|
|
108
|
-
} ? TPipeline : readonly [];
|
|
109
|
-
type BranchResponsesOf<TBranch extends HttpBranchDefinition> = TBranch extends {
|
|
110
|
-
readonly responses: infer TResponses extends Readonly<Record<string, HttpResponseDefinition>>;
|
|
111
|
-
} ? TResponses : {};
|
|
112
|
-
type JoinHttpPath<TParent extends string, TChild extends string> = TParent extends '' ? TChild : TChild extends '/' ? TParent : `${TParent}${TChild}`;
|
|
113
|
-
type MergeHttpResponses<TParent extends Readonly<Record<string, HttpResponseDefinition>>, TLocal extends Readonly<Record<string, HttpResponseDefinition>>> = Extract<keyof TParent, keyof TLocal> extends never ? TParent & TLocal : never;
|
|
114
|
-
type EffectiveHttpDefinition<TDefinition extends HttpProtocolDefinition, TParentPath extends string, TParentPipeline extends readonly PipelineItem[], TParentResponses extends Readonly<Record<string, HttpResponseDefinition>>> = {
|
|
115
|
-
readonly method: TDefinition['method'];
|
|
116
|
-
readonly path: JoinHttpPath<TParentPath, TDefinition['path']>;
|
|
117
|
-
readonly responses: MergeHttpResponses<TParentResponses, TDefinition['responses']>;
|
|
118
|
-
readonly pipeline: readonly [...TParentPipeline, ...TDefinition['pipeline']];
|
|
119
|
-
} & (TDefinition extends {
|
|
120
|
-
readonly summary: infer TValue extends string;
|
|
121
|
-
} ? {
|
|
122
|
-
readonly summary: TValue;
|
|
123
|
-
} : {}) & (TDefinition extends {
|
|
124
|
-
readonly description: infer TValue extends string;
|
|
125
|
-
} ? {
|
|
126
|
-
readonly description: TValue;
|
|
127
|
-
} : {}) & (TDefinition extends {
|
|
128
|
-
readonly tags: infer TValue extends readonly string[];
|
|
129
|
-
} ? {
|
|
130
|
-
readonly tags: TValue;
|
|
131
|
-
} : {}) & (TDefinition extends {
|
|
132
|
-
readonly deprecated: infer TValue extends boolean;
|
|
133
|
-
} ? {
|
|
134
|
-
readonly deprecated: TValue;
|
|
135
|
-
} : {}) & (TDefinition extends {
|
|
136
|
-
readonly request: infer TValue extends HttpRequestDefinition;
|
|
137
|
-
} ? {
|
|
138
|
-
readonly request: TValue;
|
|
139
|
-
} : {}) & (TDefinition extends {
|
|
140
|
-
readonly interaction: infer TValue extends 'unary' | 'server-stream';
|
|
141
|
-
} ? {
|
|
142
|
-
readonly interaction: TValue;
|
|
143
|
-
} : {});
|
|
144
|
-
type ResolvedHttpTree<TTree extends Readonly<Record<string, unknown>>, TParentPath extends string = '', TParentPipeline extends readonly PipelineItem[] = readonly [], TParentResponses extends Readonly<Record<string, HttpResponseDefinition>> = {}> = {
|
|
145
|
-
readonly [K in keyof TTree]: ResolveHttpNode<K & string, TTree[K], TParentPath, TParentPipeline, TParentResponses>;
|
|
146
|
-
};
|
|
147
|
-
type ResolveHttpNode<TName extends string, TNode, TParentPath extends string, TParentPipeline extends readonly PipelineItem[], TParentResponses extends Readonly<Record<string, HttpResponseDefinition>>> = SourceOfHttpNode<TNode> extends infer TSource ? TSource extends HttpProtocolDefinition ? HttpResolvedLeaf<HandlerNameOfHttpNode<TName, TNode>, TSource, EffectiveHttpDefinition<TSource, TParentPath, TParentPipeline, TParentResponses>> : TSource extends HttpBranchDefinition ? HttpResolvedBranch<TSource, ResolvedHttpTree<TSource['routes'], JoinHttpPath<TParentPath, BranchPathOf<TSource>>, readonly [...TParentPipeline, ...BranchPipelineOf<TSource>], MergeHttpResponses<TParentResponses, BranchResponsesOf<TSource>>>> : never : never;
|
|
148
|
-
type JoinProcedurePath<TPrefix extends string, TName extends string> = TPrefix extends '' ? TName : `${TPrefix}.${TName}`;
|
|
149
|
-
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer TIntersection) => void ? TIntersection : never;
|
|
150
|
-
type FlatHttpProtocols<TTree extends Readonly<Record<string, unknown>>, TParentPath extends string = '', TParentPipeline extends readonly PipelineItem[] = readonly [], TParentResponses extends Readonly<Record<string, HttpResponseDefinition>> = {}, TProcedurePrefix extends string = '', TRootTree extends Readonly<Record<string, unknown>> = TTree> = UnionToIntersection<{
|
|
151
|
-
[K in keyof TTree & string]: SourceOfHttpNode<TTree[K]> extends infer TSource ? TSource extends HttpProtocolDefinition ? {
|
|
152
|
-
readonly [P in JoinProcedurePath<TProcedurePrefix, K>]: HttpProtocol<EffectiveHttpDefinition<TSource, TParentPath, TParentPipeline, TParentResponses>, ResolvedHttpTree<TRootTree>>;
|
|
153
|
-
} : TSource extends HttpBranchDefinition ? FlatHttpProtocols<TSource['routes'], JoinHttpPath<TParentPath, BranchPathOf<TSource>>, readonly [...TParentPipeline, ...BranchPipelineOf<TSource>], MergeHttpResponses<TParentResponses, BranchResponsesOf<TSource>>, JoinProcedurePath<TProcedurePrefix, K>, TRootTree> : never : never;
|
|
154
|
-
}[keyof TTree & string]>;
|
|
155
|
-
export interface HttpProtocol<TDefinition extends HttpProtocolDefinition = HttpProtocolDefinition, TNamespace = unknown> extends ProtocolDescriptor<'http', HttpControllerContextDefinition<TDefinition>, DeclaredHttpResults<TDefinition['responses']>, HttpDispatchKey<TDefinition['method'], TDefinition['path']>> {
|
|
156
|
-
readonly definition: TDefinition;
|
|
157
|
-
readonly [protocolNamespaceType]: TNamespace;
|
|
158
|
-
readonly interaction: TDefinition extends {
|
|
159
|
-
readonly interaction: infer TInteraction;
|
|
160
|
-
} ? TInteraction & ('unary' | 'server-stream') : 'unary';
|
|
161
|
-
}
|
|
162
|
-
type IsHttpPipelineCompatible<TPipeline extends readonly PipelineItem[], TResponses extends HttpProtocolDefinition['responses']> = number extends TPipeline['length'] ? false : TPipeline extends readonly [infer THead, ...infer TTail] ? IsLayerShortCircuitCompatible<ShortCircuitResultOf<THead>, TResponses> extends true ? IsShortCircuitDeclarationsCompatible<ShortCircuitDeclarationsOf<THead>, TResponses> extends true ? IsHttpPipelineCompatible<Extract<TTail, readonly PipelineItem[]>, TResponses> : false : false : true;
|
|
163
|
-
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
164
|
-
type IsUnknown<T> = unknown extends T ? [keyof T] extends [never] ? true : false : false;
|
|
165
|
-
type ResponseBodyOutput<TResponse extends HttpResponseDefinition> = TResponse extends {
|
|
166
|
-
readonly stream: 'server';
|
|
167
|
-
} ? AsyncIterable<SchemaOutput<TResponse['body']>> : SchemaOutput<TResponse['body']>;
|
|
168
|
-
type ResponseHeadersOutput<TResponse extends HttpResponseDefinition> = TResponse extends {
|
|
169
|
-
readonly headers: infer THeaders extends StandardSchemaV1;
|
|
170
|
-
} ? SchemaOutput<THeaders> : never;
|
|
171
|
-
type DeclaredHttpResults<TResponses extends HttpProtocolDefinition['responses']> = string extends keyof TResponses ? LogicalHttpResult : {
|
|
172
|
-
[TVariant in keyof TResponses & string]: NonNullable<TResponses[TVariant]> extends infer TResponse extends HttpResponseDefinition ? LogicalHttpResult<TVariant, ResponseBodyOutput<TResponse>, ResponseHeadersOutput<TResponse>> : never;
|
|
173
|
-
}[keyof TResponses & string];
|
|
174
|
-
type IsResultHeadersCompatible<TResult, TResponses extends HttpProtocolDefinition['responses']> = string extends keyof TResponses ? true : TResult extends {
|
|
175
|
-
readonly variant: infer TVariant extends keyof TResponses;
|
|
176
|
-
} ? TResult extends {
|
|
177
|
-
readonly headers: infer TResultHeaders;
|
|
178
|
-
} ? NonNullable<TResponses[TVariant]> extends infer TResponse extends HttpResponseDefinition ? [ResponseHeadersOutput<TResponse>] extends [never] ? false : Exclude<keyof TResultHeaders, keyof NonNullable<ResponseHeadersOutput<TResponse>>> extends never ? true : false : false : true : false;
|
|
179
|
-
type AreResultHeadersCompatible<TResult, TResponses extends HttpProtocolDefinition['responses']> = false extends (TResult extends unknown ? IsResultHeadersCompatible<TResult, TResponses> : never) ? false : true;
|
|
180
|
-
type IsLayerShortCircuitCompatible<TResult, TResponses extends HttpProtocolDefinition['responses']> = IsAny<TResult> extends true ? true : IsUnknown<TResult> extends true ? true : [TResult] extends [never] ? true : [TResult] extends [DeclaredHttpResults<TResponses>] ? AreResultHeadersCompatible<TResult, TResponses> : false;
|
|
181
|
-
type IsShortCircuitDeclarationsCompatible<TDeclarations, TResponses extends HttpProtocolDefinition['responses']> = IsAny<TDeclarations> extends true ? true : IsUnknown<TDeclarations> extends true ? true : TDeclarations extends readonly unknown[] ? number extends TDeclarations['length'] ? true : TDeclarations extends readonly [infer THead, ...infer TTail] ? IsHttpShortCircuitDeclarationCompatible<THead, TResponses> extends true ? IsShortCircuitDeclarationsCompatible<TTail, TResponses> : false : true : true;
|
|
182
|
-
type IsHttpShortCircuitDeclarationCompatible<TDeclaration, TResponses extends HttpProtocolDefinition['responses']> = TDeclaration extends {
|
|
183
|
-
readonly protocol: 'http';
|
|
184
|
-
readonly variant: infer TVariant extends string;
|
|
185
|
-
} ? string extends TVariant ? true : TVariant extends keyof TResponses ? NonNullable<TResponses[TVariant]> extends HttpResponseDefinition ? TDeclaration extends {
|
|
186
|
-
readonly response: {
|
|
187
|
-
readonly status: infer TStatus extends number;
|
|
188
|
-
};
|
|
189
|
-
} ? NonNullable<TResponses[TVariant]>['status'] extends TStatus ? true : number extends NonNullable<TResponses[TVariant]>['status'] ? true : false : true : false : false : true;
|
|
190
|
-
type HttpPipelineConstraint<TDefinition extends HttpProtocolDefinition> = IsValidProtocolPipeline<TDefinition['pipeline'], 'http'> extends true ? IsHttpPipelineCompatible<TDefinition['pipeline'], TDefinition['responses']> extends true ? unknown : {
|
|
191
|
-
readonly pipeline: never;
|
|
192
|
-
} : {
|
|
193
|
-
readonly pipeline: never;
|
|
194
|
-
};
|
|
195
|
-
type HttpStatusDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
196
|
-
type HttpStatusHundreds = '2' | '3' | '4' | '5';
|
|
197
|
-
type IsValidHttpResponseStatus<TStatus extends number> = number extends TStatus ? false : `${TStatus}` extends `${HttpStatusHundreds}${HttpStatusDigit}${HttpStatusDigit}` ? true : false;
|
|
198
|
-
type IsBodylessHttpStatus<TStatus extends number> = TStatus extends 204 | 205 | 304 ? true : false;
|
|
199
|
-
type IsResponseStatusCompatible<TResponse> = TResponse extends HttpResponseDefinition ? IsValidHttpResponseStatus<TResponse['status']> extends true ? IsBodylessHttpStatus<TResponse['status']> extends true ? [SchemaOutput<TResponse['body']>] extends [undefined] ? true : false : true : false : false;
|
|
200
|
-
type AreResponseStatusesCompatible<TResponses extends HttpProtocolDefinition['responses']> = false extends {
|
|
201
|
-
[TVariant in keyof TResponses]: IsResponseStatusCompatible<TResponses[TVariant]>;
|
|
202
|
-
}[keyof TResponses] ? false : true;
|
|
203
|
-
type IsResponseHeadersSchemaCompatible<TResponse> = TResponse extends HttpResponseDefinition ? TResponse extends {
|
|
204
|
-
readonly headers: infer THeaders extends StandardSchemaV1;
|
|
205
|
-
} ? SchemaOutput<THeaders> extends HttpHeaders | undefined ? true : false : true : false;
|
|
206
|
-
type AreResponseHeadersSchemasCompatible<TResponses extends HttpProtocolDefinition['responses']> = false extends {
|
|
207
|
-
[TVariant in keyof TResponses]: IsResponseHeadersSchemaCompatible<TResponses[TVariant]>;
|
|
208
|
-
}[keyof TResponses] ? false : true;
|
|
209
|
-
type HttpResponseConstraint<TDefinition extends HttpProtocolDefinition> = string extends keyof TDefinition['responses'] ? {
|
|
210
|
-
readonly responses: never;
|
|
211
|
-
} : AreResponseStatusesCompatible<TDefinition['responses']> extends true ? AreResponseHeadersSchemasCompatible<TDefinition['responses']> extends true ? AreErrorMappingsCompatible<TDefinition['responses']> extends true ? unknown : {
|
|
212
|
-
readonly responses: never;
|
|
213
|
-
} : {
|
|
214
|
-
readonly responses: never;
|
|
215
|
-
} : {
|
|
216
|
-
readonly responses: never;
|
|
217
|
-
};
|
|
218
|
-
type IsExactParamsSchemaMap<TPath extends string, TSchemas extends HttpParamsSchemas> = Exclude<keyof TSchemas, PathParamNames<TPath>> extends never ? Exclude<PathParamNames<TPath>, keyof TSchemas> extends never ? true : false : false;
|
|
219
|
-
type DoParamsSchemasAcceptStrings<TSchemas extends HttpParamsSchemas> = false extends {
|
|
220
|
-
[TName in keyof TSchemas]: IsRawStringCompatible<SchemaInput<TSchemas[TName]>>;
|
|
221
|
-
}[keyof TSchemas] ? false : true;
|
|
222
|
-
type IsRawStringCompatible<TInput> = string extends TInput ? true : [Extract<TInput, string>] extends [never] ? false : true;
|
|
223
|
-
type IsUnion<TValue, TCandidate = TValue> = TValue extends unknown ? [TCandidate] extends [TValue] ? false : true : never;
|
|
224
|
-
type IsSingleStringLiteral<TValue extends string> = string extends TValue ? false : true extends IsUnion<TValue> ? false : true;
|
|
225
|
-
type HttpPathConstraint<TDefinition extends HttpProtocolDefinition> = IsSingleStringLiteral<TDefinition['method']> extends false ? {
|
|
226
|
-
readonly method: never;
|
|
227
|
-
} : IsValidHttpMethod<TDefinition['method']> extends false ? {
|
|
228
|
-
readonly method: never;
|
|
229
|
-
} : IsSingleStringLiteral<TDefinition['path']> extends false ? {
|
|
230
|
-
readonly path: never;
|
|
231
|
-
} : IsValidHttpPath<TDefinition['path']> extends true ? TDefinition['request'] extends {
|
|
232
|
-
readonly params: infer TSchemas extends HttpParamsSchemas;
|
|
233
|
-
} ? IsExactParamsSchemaMap<TDefinition['path'], TSchemas> extends true ? DoParamsSchemasAcceptStrings<TSchemas> extends true ? unknown : {
|
|
234
|
-
readonly request: never;
|
|
235
|
-
} : {
|
|
236
|
-
readonly request: never;
|
|
237
|
-
} : HasValidationBeforeTerminal<TDefinition['pipeline'], 'params'> extends true ? {
|
|
238
|
-
readonly pipeline: never;
|
|
239
|
-
} : unknown : {
|
|
240
|
-
readonly path: never;
|
|
241
|
-
};
|
|
242
|
-
type ErrorMappingResult<TResponse> = TResponse extends {
|
|
243
|
-
readonly error: infer TMapping extends HttpErrorMapping<any, any>;
|
|
244
|
-
} ? Awaited<ReturnType<TMapping['map']>> : never;
|
|
245
|
-
type IsErrorMappingCompatible<TResponse> = TResponse extends HttpResponseDefinition ? TResponse extends {
|
|
246
|
-
readonly error: HttpErrorMapping<any, any>;
|
|
247
|
-
} ? ErrorMappingResult<TResponse> extends HttpResponseResult<ResponseBodyOutput<TResponse>, ResponseHeadersOutput<TResponse>> ? true : false : true : false;
|
|
248
|
-
type AreErrorMappingsCompatible<TResponses extends HttpProtocolDefinition['responses']> = false extends {
|
|
249
|
-
[TVariant in keyof TResponses]: IsErrorMappingCompatible<TResponses[TVariant]>;
|
|
250
|
-
}[keyof TResponses] ? false : true;
|
|
251
|
-
type IsConstraintSatisfied<TConstraint> = keyof TConstraint extends never ? true : false;
|
|
252
|
-
type IsValidHttpRouteName<TName extends string> = TName extends '' ? false : TName extends '__proto__' ? false : TName extends `${string}.${string}` ? false : TName extends `${number}` ? false : true;
|
|
253
|
-
type HasOnlyHttpNodeProperties<TNode, TAllowed extends PropertyKey> = Exclude<keyof TNode, TAllowed> extends never ? true : false;
|
|
254
|
-
type IsExactHttpLeaf<TNode> = HasOnlyHttpNodeProperties<TNode, keyof HttpProtocolDefinition>;
|
|
255
|
-
type IsExactHttpBranch<TNode> = HasOnlyHttpNodeProperties<TNode, keyof HttpBranchDefinition>;
|
|
256
|
-
type IsBranchPipelineTerminalFree<TPipeline extends readonly PipelineItem[]> = number extends TPipeline['length'] ? false : TPipeline extends readonly [infer THead, ...infer TTail] ? THead extends TerminalLayerDescriptor ? false : THead extends {
|
|
257
|
-
readonly kind: 'layer';
|
|
258
|
-
readonly pipeline: infer TChild extends readonly PipelineItem[];
|
|
259
|
-
} ? IsBranchPipelineTerminalFree<TChild> extends true ? IsBranchPipelineTerminalFree<Extract<TTail, readonly PipelineItem[]>> : false : IsBranchPipelineTerminalFree<Extract<TTail, readonly PipelineItem[]>> : true;
|
|
260
|
-
type IsHttpBranchPathValid<TBranch extends HttpBranchDefinition> = TBranch extends {
|
|
261
|
-
readonly path: infer TPath extends string;
|
|
262
|
-
} ? string extends TPath ? false : TPath extends '/' ? true : IsValidHttpPath<TPath> : true;
|
|
263
|
-
type IsHttpBranchPipelineValid<TBranch extends HttpBranchDefinition> = TBranch extends {
|
|
264
|
-
readonly pipeline: infer TPipeline extends readonly PipelineItem[];
|
|
265
|
-
} ? IsBranchPipelineTerminalFree<TPipeline> : true;
|
|
266
|
-
type IsHttpBranchResponsesValid<TBranch extends HttpBranchDefinition> = TBranch extends {
|
|
267
|
-
readonly responses: infer TResponses extends Readonly<Record<string, HttpResponseDefinition>>;
|
|
268
|
-
} ? string extends keyof TResponses ? false : AreResponseHeadersSchemasCompatible<TResponses> extends true ? AreErrorMappingsCompatible<TResponses> : false : true;
|
|
269
|
-
type HasHttpResponseCollision<TParent extends Readonly<Record<string, HttpResponseDefinition>>, TLocal extends Readonly<Record<string, HttpResponseDefinition>>> = Extract<keyof TParent, keyof TLocal> extends never ? false : true;
|
|
270
|
-
type IsHttpResolvedLeafValid<TDefinition extends HttpProtocolDefinition, TParentPath extends string, TParentPipeline extends readonly PipelineItem[], TParentResponses extends Readonly<Record<string, HttpResponseDefinition>>, TEffective extends HttpProtocolDefinition = EffectiveHttpDefinition<TDefinition, TParentPath, TParentPipeline, TParentResponses>> = IsConstraintSatisfied<HttpPipelineConstraint<TEffective> & HttpResponseConstraint<TEffective> & HttpPathConstraint<TEffective>>;
|
|
271
|
-
type IsHttpTreeValid<TTree extends Readonly<Record<string, unknown>>, TParentPath extends string = '', TParentPipeline extends readonly PipelineItem[] = readonly [], TParentResponses extends Readonly<Record<string, HttpResponseDefinition>> = {}> = Extract<keyof TTree, number> extends never ? false extends {
|
|
272
|
-
[K in keyof TTree & string]: IsValidHttpRouteName<K> extends true ? SourceOfHttpNode<TTree[K]> extends infer TSource ? TSource extends HttpProtocolDefinition ? IsExactHttpLeaf<TSource> extends true ? IsHttpResolvedLeafValid<TSource, TParentPath, TParentPipeline, TParentResponses> : false : TSource extends HttpBranchDefinition ? IsExactHttpBranch<TSource> extends true ? IsHttpBranchPathValid<TSource> extends true ? IsHttpBranchPipelineValid<TSource> extends true ? IsHttpBranchResponsesValid<TSource> extends true ? HasHttpResponseCollision<TParentResponses, BranchResponsesOf<TSource>> extends false ? IsHttpTreeValid<TSource['routes'], JoinHttpPath<TParentPath, BranchPathOf<TSource>>, readonly [
|
|
273
|
-
...TParentPipeline,
|
|
274
|
-
...BranchPipelineOf<TSource>
|
|
275
|
-
], MergeHttpResponses<TParentResponses, BranchResponsesOf<TSource>>> : false : false : false : false : false : false : false : false;
|
|
276
|
-
}[keyof TTree & string] ? false : true : false;
|
|
277
|
-
type HttpTreeConstraint<TDefinitions extends HttpRouteTree> = IsHttpTreeValid<TDefinitions> extends true ? unknown : {
|
|
278
|
-
readonly __invalidHttpRouteTree__: never;
|
|
279
|
-
};
|
|
280
|
-
declare function defineHttp<const TDefinition extends HttpProtocolDefinition>(definition: TDefinition & HttpPipelineConstraint<TDefinition> & HttpResponseConstraint<TDefinition> & HttpPathConstraint<TDefinition>): HttpProtocol<TDefinition>;
|
|
281
|
-
type HttpProtocolGroup<TDefinitions extends HttpRouteTree> = ProtocolGroup<'http', FlatHttpProtocols<TDefinitions> extends infer TProtocols extends Record<string, ProtocolDescriptor<'http'>> ? TProtocols : never>;
|
|
282
|
-
export interface HttpProtocolFactory extends ProtocolFactory<'http'> {
|
|
283
|
-
<const TDefinitions extends HttpRouteTree>(definitions: TDefinitions & HttpTreeConstraint<TDefinitions>): HttpProtocolGroup<TDefinitions>;
|
|
284
|
-
readonly route: typeof defineHttp;
|
|
285
|
-
readonly controller: TerminalLayerDescriptor<'http'>;
|
|
286
|
-
readonly error: typeof httpError;
|
|
287
|
-
}
|
|
288
|
-
export declare const http: HttpProtocolFactory;
|
|
289
|
-
export declare const validate: Readonly<{
|
|
290
|
-
params: ValidationLayerDescriptor & {
|
|
291
|
-
readonly part: "params";
|
|
292
|
-
readonly name: "validate.params";
|
|
293
|
-
};
|
|
294
|
-
query: ValidationLayerDescriptor & {
|
|
295
|
-
readonly part: "query";
|
|
296
|
-
readonly name: "validate.query";
|
|
297
|
-
};
|
|
298
|
-
headers: ValidationLayerDescriptor & {
|
|
299
|
-
readonly part: "headers";
|
|
300
|
-
readonly name: "validate.headers";
|
|
301
|
-
};
|
|
302
|
-
body: ValidationLayerDescriptor & {
|
|
303
|
-
readonly part: "body";
|
|
304
|
-
readonly name: "validate.body";
|
|
305
|
-
};
|
|
306
|
-
}>;
|
|
307
|
-
type ProceduresForHttp<TBinding extends ContractBinding, TContract extends ContractDefinition = ContractOfBinding<TBinding>> = {
|
|
308
|
-
[K in keyof TContract['procedures']]: 'http' extends keyof TContract['procedures'][K]['protocols'] ? K : never;
|
|
309
|
-
}[keyof TContract['procedures']] & string;
|
|
310
|
-
type HttpProtocolAt<TBinding extends ContractBinding, TProcedure extends keyof ContractOfBinding<TBinding>['procedures'], TContract extends ContractDefinition = ContractOfBinding<TBinding>> = TContract['procedures'][TProcedure]['protocols']['http' & keyof TContract['procedures'][TProcedure]['protocols']] extends infer TProtocol ? TProtocol extends HttpProtocol<any, any> ? TProtocol : never : never;
|
|
311
|
-
type RequestBodySchema<TBody> = TBody extends HttpRequestBodyDefinition<infer TSchema> ? TSchema : never;
|
|
312
|
-
type PartOutput<TDefinition extends HttpProtocolDefinition, TPart extends keyof HttpRequestDefinition> = TPart extends 'params' ? HasValidationBeforeTerminal<TDefinition['pipeline'], 'params'> extends true ? TDefinition['request'] extends {
|
|
313
|
-
readonly params: infer TSchemas extends HttpParamsSchemas;
|
|
314
|
-
} ? ValidatedPathParams<TSchemas> : never : RawPathParams<TDefinition['path']> : HasValidationBeforeTerminal<TDefinition['pipeline'], TPart> extends false ? unknown : TDefinition['request'] extends HttpRequestDefinition ? TPart extends keyof TDefinition['request'] ? TPart extends 'body' ? SchemaOutput<RequestBodySchema<NonNullable<TDefinition['request'][TPart]>>> : NonNullable<TDefinition['request'][TPart]> extends StandardSchemaV1 ? SchemaOutput<NonNullable<TDefinition['request'][TPart]>> : unknown : unknown : unknown;
|
|
315
|
-
type ValidatedPathParams<TSchemas extends HttpParamsSchemas> = Readonly<{
|
|
316
|
-
[TName in keyof TSchemas]: SchemaOutput<TSchemas[TName]>;
|
|
317
|
-
}>;
|
|
318
|
-
type HttpResultHeaders<THeaders> = IsAny<THeaders> extends true ? {
|
|
319
|
-
readonly headers?: HttpHeaders;
|
|
320
|
-
} : IsUnknown<THeaders> extends true ? {
|
|
321
|
-
readonly headers?: HttpHeaders;
|
|
322
|
-
} : [THeaders] extends [never] ? {
|
|
323
|
-
readonly headers?: never;
|
|
324
|
-
} : undefined extends THeaders ? {
|
|
325
|
-
readonly headers?: Exclude<THeaders, undefined>;
|
|
326
|
-
} : {
|
|
327
|
-
readonly headers: THeaders;
|
|
328
|
-
};
|
|
329
|
-
export type HttpResponseResult<TBody, THeaders = unknown> = {
|
|
330
|
-
readonly body: TBody;
|
|
331
|
-
} & HttpResultHeaders<THeaders>;
|
|
332
|
-
type ErrorOf<TDefinition> = TDefinition extends HttpErrorMatcher<infer TError> ? TError : never;
|
|
333
|
-
export declare function httpError<TDefinition extends HttpErrorMatcher<{
|
|
334
|
-
readonly data: unknown;
|
|
335
|
-
}>>(definition: TDefinition): HttpErrorMapping<ErrorOf<TDefinition>, {
|
|
336
|
-
readonly body: ErrorOf<TDefinition>['data'];
|
|
337
|
-
}>;
|
|
338
|
-
export declare function httpError<TDefinition extends HttpErrorMatcher<{
|
|
339
|
-
readonly data: unknown;
|
|
340
|
-
}>, const TResult>(definition: TDefinition, map: (error: ErrorOf<TDefinition>) => TResult | Promise<TResult>): HttpErrorMapping<ErrorOf<TDefinition>, TResult>;
|
|
341
|
-
export type LogicalHttpResult<TVariant extends string = string, TBody = unknown, THeaders = unknown> = {
|
|
342
|
-
readonly kind: 'http-result';
|
|
343
|
-
readonly variant: TVariant;
|
|
344
|
-
readonly body: TBody;
|
|
345
|
-
} & HttpResultHeaders<THeaders>;
|
|
346
|
-
type ResponseHelpers<TDefinition extends HttpProtocolDefinition> = {
|
|
347
|
-
[TVariant in keyof TDefinition['responses'] & string]: (result: HttpResponseResult<ResponseBodyOutput<TDefinition['responses'][TVariant]>, ResponseHeadersOutput<TDefinition['responses'][TVariant]>>) => LogicalHttpResult<TVariant, ResponseBodyOutput<TDefinition['responses'][TVariant]>, ResponseHeadersOutput<TDefinition['responses'][TVariant]>>;
|
|
348
|
-
};
|
|
349
|
-
type HttpControllerContextDefinition<TDefinition extends HttpProtocolDefinition> = {
|
|
350
|
-
readonly params: PartOutput<TDefinition, 'params'>;
|
|
351
|
-
readonly query: PartOutput<TDefinition, 'query'>;
|
|
352
|
-
readonly headers: PartOutput<TDefinition, 'headers'>;
|
|
353
|
-
readonly body: PartOutput<TDefinition, 'body'>;
|
|
354
|
-
readonly response: ResponseHelpers<TDefinition>;
|
|
355
|
-
readonly logger: Logger;
|
|
356
|
-
readonly signal: AbortSignal;
|
|
357
|
-
} & ContextProvidedBeforeTerminal<TDefinition['pipeline']>;
|
|
358
|
-
export type HttpControllerContext<TProtocol extends HttpProtocol<any>> = HttpControllerContextDefinition<TProtocol['definition']>;
|
|
359
|
-
export type ControllerOf<TBinding extends ContractBinding, TProtocol extends 'http', TProcedures extends ProceduresForHttp<TBinding> = ProceduresForHttp<TBinding>> = TProtocol extends 'http' ? {
|
|
360
|
-
[K in TProcedures]: (context: HttpControllerContext<HttpProtocolAt<TBinding, K>>) => DeclaredHttpResults<HttpProtocolAt<TBinding, K>['definition']['responses']> | Promise<DeclaredHttpResults<HttpProtocolAt<TBinding, K>['definition']['responses']>>;
|
|
361
|
-
} : never;
|
|
362
|
-
export type ContextOf<TController, TProcedure extends keyof TController> = TController[TProcedure] extends (context: infer TContext, ...args: any[]) => any ? TContext : never;
|
|
363
|
-
export {};
|