alepha 0.6.10 → 0.7.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/core.d.ts +15 -2
- package/package.json +20 -20
- package/postgres.d.ts +235 -46
- package/react/auth.d.ts +29 -28
- package/react.d.ts +80 -52
- package/security.d.ts +25 -18
- package/server/metrics.d.ts +1 -1
- package/server/proxy.d.ts +1 -35
- package/server/static.d.ts +5 -0
- package/server/swagger.d.ts +1 -0
- package/server.d.ts +429 -211
- package/vite.d.ts +11 -1
package/server.d.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import * as _alepha_core from '@alepha/core';
|
|
2
|
-
import { Static as Static$1, TObject as TObject$1, TSchema as TSchema$
|
|
2
|
+
import { Static as Static$1, TObject as TObject$1, TSchema as TSchema$2, Async, StreamLike, Alepha, OPTIONS, KIND, FileLike } from '@alepha/core';
|
|
3
3
|
export { KIND } from '@alepha/core';
|
|
4
|
-
import { UserAccountToken, Permission, SecurityProvider, JwtProvider } from '@alepha/security';
|
|
4
|
+
import { UserAccountToken, Permission, ServiceAccountDescriptor as ServiceAccountDescriptor$1, SecurityProvider, JwtProvider } from '@alepha/security';
|
|
5
5
|
import { IncomingMessage, ServerResponse as ServerResponse$1 } from 'node:http';
|
|
6
6
|
import { Readable } from 'node:stream';
|
|
7
7
|
import { ReadableStream } from 'node:stream/web';
|
|
8
8
|
import { Route, RouterProvider } from '@alepha/router';
|
|
9
9
|
import * as _alepha_cache from '@alepha/cache';
|
|
10
|
-
import { DurationLike } from '@alepha/datetime';
|
|
10
|
+
import { DurationLike, DateTimeProvider } from '@alepha/datetime';
|
|
11
11
|
import { BusboyConfig } from '@fastify/busboy';
|
|
12
12
|
import * as http from 'http';
|
|
13
13
|
|
|
14
14
|
/** Symbol key applied to readonly types */
|
|
15
|
-
declare const ReadonlyKind: unique symbol;
|
|
15
|
+
declare const ReadonlyKind$1: unique symbol;
|
|
16
16
|
/** Symbol key applied to optional types */
|
|
17
|
-
declare const OptionalKind: unique symbol;
|
|
17
|
+
declare const OptionalKind$1: unique symbol;
|
|
18
18
|
/** Symbol key applied to types */
|
|
19
|
-
declare const Hint: unique symbol;
|
|
19
|
+
declare const Hint$1: unique symbol;
|
|
20
20
|
/** Symbol key applied to types */
|
|
21
|
-
declare const Kind: unique symbol;
|
|
21
|
+
declare const Kind$1: unique symbol;
|
|
22
22
|
|
|
23
|
-
type TReadonly<T extends TSchema> = T & {
|
|
24
|
-
[ReadonlyKind]: 'Readonly';
|
|
23
|
+
type TReadonly<T extends TSchema$1> = T & {
|
|
24
|
+
[ReadonlyKind$1]: 'Readonly';
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
type UnionStatic<T extends TSchema[], P extends unknown[]> = {
|
|
28
|
-
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
|
|
27
|
+
type UnionStatic<T extends TSchema$1[], P extends unknown[]> = {
|
|
28
|
+
[K in keyof T]: T[K] extends TSchema$1 ? Static<T[K], P> : never;
|
|
29
29
|
}[number];
|
|
30
|
-
interface TUnion<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
31
|
-
[Kind]: 'Union';
|
|
30
|
+
interface TUnion<T extends TSchema$1[] = TSchema$1[]> extends TSchema$1 {
|
|
31
|
+
[Kind$1]: 'Union';
|
|
32
32
|
static: UnionStatic<T, this['params']>;
|
|
33
33
|
anyOf: T;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
|
|
37
|
-
type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
|
|
38
|
-
interface StringOptions extends SchemaOptions {
|
|
36
|
+
type StringFormatOption$1 = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
|
|
37
|
+
type StringContentEncodingOption$1 = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
|
|
38
|
+
interface StringOptions$1 extends SchemaOptions$1 {
|
|
39
39
|
/** The maximum string length */
|
|
40
40
|
maxLength?: number;
|
|
41
41
|
/** The minimum string length */
|
|
@@ -43,67 +43,67 @@ interface StringOptions extends SchemaOptions {
|
|
|
43
43
|
/** A regular expression pattern this string should match */
|
|
44
44
|
pattern?: string;
|
|
45
45
|
/** A format this string should match */
|
|
46
|
-
format?: StringFormatOption;
|
|
46
|
+
format?: StringFormatOption$1;
|
|
47
47
|
/** The content encoding for this string */
|
|
48
|
-
contentEncoding?: StringContentEncodingOption;
|
|
48
|
+
contentEncoding?: StringContentEncodingOption$1;
|
|
49
49
|
/** The content media type for this string */
|
|
50
50
|
contentMediaType?: string;
|
|
51
51
|
}
|
|
52
|
-
interface TString extends TSchema, StringOptions {
|
|
53
|
-
[Kind]: 'String';
|
|
52
|
+
interface TString$1 extends TSchema$1, StringOptions$1 {
|
|
53
|
+
[Kind$1]: 'String';
|
|
54
54
|
static: string;
|
|
55
55
|
type: 'string';
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
interface TBoolean extends TSchema {
|
|
59
|
-
[Kind]: 'Boolean';
|
|
58
|
+
interface TBoolean extends TSchema$1 {
|
|
59
|
+
[Kind$1]: 'Boolean';
|
|
60
60
|
static: boolean;
|
|
61
61
|
type: 'boolean';
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
interface NumberOptions extends SchemaOptions {
|
|
64
|
+
interface NumberOptions extends SchemaOptions$1 {
|
|
65
65
|
exclusiveMaximum?: number;
|
|
66
66
|
exclusiveMinimum?: number;
|
|
67
67
|
maximum?: number;
|
|
68
68
|
minimum?: number;
|
|
69
69
|
multipleOf?: number;
|
|
70
70
|
}
|
|
71
|
-
interface TNumber extends TSchema, NumberOptions {
|
|
72
|
-
[Kind]: 'Number';
|
|
71
|
+
interface TNumber extends TSchema$1, NumberOptions {
|
|
72
|
+
[Kind$1]: 'Number';
|
|
73
73
|
static: number;
|
|
74
74
|
type: 'number';
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
interface IntegerOptions extends SchemaOptions {
|
|
77
|
+
interface IntegerOptions extends SchemaOptions$1 {
|
|
78
78
|
exclusiveMaximum?: number;
|
|
79
79
|
exclusiveMinimum?: number;
|
|
80
80
|
maximum?: number;
|
|
81
81
|
minimum?: number;
|
|
82
82
|
multipleOf?: number;
|
|
83
83
|
}
|
|
84
|
-
interface TInteger extends TSchema, IntegerOptions {
|
|
85
|
-
[Kind]: 'Integer';
|
|
84
|
+
interface TInteger extends TSchema$1, IntegerOptions {
|
|
85
|
+
[Kind$1]: 'Integer';
|
|
86
86
|
static: number;
|
|
87
87
|
type: 'integer';
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
type TOptional<T extends TSchema> = T & {
|
|
91
|
-
[OptionalKind]: 'Optional';
|
|
90
|
+
type TOptional<T extends TSchema$1> = T & {
|
|
91
|
+
[OptionalKind$1]: 'Optional';
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
/** Creates a static type from a TypeBox type */
|
|
95
|
-
type Static<Type extends TSchema, Params extends unknown[] = [], Result = (Type & {
|
|
95
|
+
type Static<Type extends TSchema$1, Params extends unknown[] = [], Result = (Type & {
|
|
96
96
|
params: Params;
|
|
97
97
|
})['static']> = Result;
|
|
98
98
|
|
|
99
99
|
type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
|
|
100
|
-
[K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? K : never) : never;
|
|
100
|
+
[K in keyof T]: T[K] extends TReadonly<TSchema$1> ? (T[K] extends TOptional<T[K]> ? K : never) : never;
|
|
101
101
|
}[keyof T];
|
|
102
102
|
type ReadonlyPropertyKeys<T extends TProperties> = {
|
|
103
|
-
[K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? never : K) : never;
|
|
103
|
+
[K in keyof T]: T[K] extends TReadonly<TSchema$1> ? (T[K] extends TOptional<T[K]> ? never : K) : never;
|
|
104
104
|
}[keyof T];
|
|
105
105
|
type OptionalPropertyKeys<T extends TProperties> = {
|
|
106
|
-
[K in keyof T]: T[K] extends TOptional<TSchema> ? (T[K] extends TReadonly<T[K]> ? never : K) : never;
|
|
106
|
+
[K in keyof T]: T[K] extends TOptional<TSchema$1> ? (T[K] extends TReadonly<T[K]> ? never : K) : never;
|
|
107
107
|
}[keyof T];
|
|
108
108
|
type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
|
|
109
109
|
type ObjectStaticProperties<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)>;
|
|
@@ -111,9 +111,9 @@ type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProp
|
|
|
111
111
|
[K in keyof T]: Static<T[K], P>;
|
|
112
112
|
}>;
|
|
113
113
|
type TPropertyKey = string | number;
|
|
114
|
-
type TProperties = Record<TPropertyKey, TSchema>;
|
|
115
|
-
type TAdditionalProperties = undefined | TSchema | boolean;
|
|
116
|
-
interface ObjectOptions extends SchemaOptions {
|
|
114
|
+
type TProperties = Record<TPropertyKey, TSchema$1>;
|
|
115
|
+
type TAdditionalProperties = undefined | TSchema$1 | boolean;
|
|
116
|
+
interface ObjectOptions extends SchemaOptions$1 {
|
|
117
117
|
/** Additional property constraints for this object */
|
|
118
118
|
additionalProperties?: TAdditionalProperties;
|
|
119
119
|
/** The minimum number of properties allowed on this object */
|
|
@@ -121,8 +121,8 @@ interface ObjectOptions extends SchemaOptions {
|
|
|
121
121
|
/** The maximum number of properties allowed on this object */
|
|
122
122
|
maxProperties?: number;
|
|
123
123
|
}
|
|
124
|
-
interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
|
|
125
|
-
[Kind]: 'Object';
|
|
124
|
+
interface TObject<T extends TProperties = TProperties> extends TSchema$1, ObjectOptions {
|
|
125
|
+
[Kind$1]: 'Object';
|
|
126
126
|
static: ObjectStatic<T, this['params']>;
|
|
127
127
|
additionalProperties?: TAdditionalProperties;
|
|
128
128
|
type: 'object';
|
|
@@ -135,7 +135,7 @@ type Evaluate<T> = T extends infer O ? {
|
|
|
135
135
|
} : never;
|
|
136
136
|
type Ensure<T> = T extends infer U ? U : never;
|
|
137
137
|
|
|
138
|
-
interface ArrayOptions extends SchemaOptions {
|
|
138
|
+
interface ArrayOptions extends SchemaOptions$1 {
|
|
139
139
|
/** The minimum number of items in this array */
|
|
140
140
|
minItems?: number;
|
|
141
141
|
/** The maximum number of items in this array */
|
|
@@ -143,21 +143,21 @@ interface ArrayOptions extends SchemaOptions {
|
|
|
143
143
|
/** Should this schema contain unique items */
|
|
144
144
|
uniqueItems?: boolean;
|
|
145
145
|
/** A schema for which some elements should match */
|
|
146
|
-
contains?: TSchema;
|
|
146
|
+
contains?: TSchema$1;
|
|
147
147
|
/** A minimum number of contains schema matches */
|
|
148
148
|
minContains?: number;
|
|
149
149
|
/** A maximum number of contains schema matches */
|
|
150
150
|
maxContains?: number;
|
|
151
151
|
}
|
|
152
|
-
type ArrayStatic<T extends TSchema, P extends unknown[]> = Ensure<Static<T, P>[]>;
|
|
153
|
-
interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
|
|
154
|
-
[Kind]: 'Array';
|
|
152
|
+
type ArrayStatic<T extends TSchema$1, P extends unknown[]> = Ensure<Static<T, P>[]>;
|
|
153
|
+
interface TArray<T extends TSchema$1 = TSchema$1> extends TSchema$1, ArrayOptions {
|
|
154
|
+
[Kind$1]: 'Array';
|
|
155
155
|
static: ArrayStatic<T, this['params']>;
|
|
156
156
|
type: 'array';
|
|
157
157
|
items: T;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
interface SchemaOptions {
|
|
160
|
+
interface SchemaOptions$1 {
|
|
161
161
|
$schema?: string;
|
|
162
162
|
/** Id for this schema */
|
|
163
163
|
$id?: string;
|
|
@@ -175,13 +175,13 @@ interface SchemaOptions {
|
|
|
175
175
|
writeOnly?: boolean;
|
|
176
176
|
[prop: string]: any;
|
|
177
177
|
}
|
|
178
|
-
interface TKind {
|
|
179
|
-
[Kind]: string;
|
|
178
|
+
interface TKind$1 {
|
|
179
|
+
[Kind$1]: string;
|
|
180
180
|
}
|
|
181
|
-
interface TSchema extends TKind, SchemaOptions {
|
|
182
|
-
[ReadonlyKind]?: string;
|
|
183
|
-
[OptionalKind]?: string;
|
|
184
|
-
[Hint]?: string;
|
|
181
|
+
interface TSchema$1 extends TKind$1, SchemaOptions$1 {
|
|
182
|
+
[ReadonlyKind$1]?: string;
|
|
183
|
+
[OptionalKind$1]?: string;
|
|
184
|
+
[Hint$1]?: string;
|
|
185
185
|
params: unknown[];
|
|
186
186
|
static: unknown;
|
|
187
187
|
}
|
|
@@ -189,11 +189,11 @@ interface TSchema extends TKind, SchemaOptions {
|
|
|
189
189
|
declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
|
|
190
190
|
type RouteMethod = (typeof routeMethods)[number];
|
|
191
191
|
|
|
192
|
-
declare const envSchema$
|
|
192
|
+
declare const envSchema$5: TObject$1<{
|
|
193
193
|
SERVER_ALS_ENABLED: TBoolean;
|
|
194
194
|
}>;
|
|
195
195
|
declare module "alepha" {
|
|
196
|
-
interface Env extends Partial<Static$1<typeof envSchema$
|
|
196
|
+
interface Env extends Partial<Static$1<typeof envSchema$5>> {
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
declare class ServerRouterProvider extends RouterProvider<ServerRouteWithHandler> {
|
|
@@ -220,14 +220,14 @@ declare class ServerRouterProvider extends RouterProvider<ServerRouteWithHandler
|
|
|
220
220
|
serializeResponse(route: ServerRoute, reply: ServerReply, responseType: ResponseType): void;
|
|
221
221
|
}
|
|
222
222
|
interface RequestConfigSchema {
|
|
223
|
-
body?: TSchema$
|
|
223
|
+
body?: TSchema$2;
|
|
224
224
|
params?: TObject$1;
|
|
225
225
|
query?: TObject$1;
|
|
226
226
|
headers?: TObject$1;
|
|
227
|
-
response?: TSchema$
|
|
227
|
+
response?: TSchema$2;
|
|
228
228
|
}
|
|
229
229
|
interface ServerRequestConfig<TConfig extends RequestConfigSchema = RequestConfigSchema> {
|
|
230
|
-
body: TConfig["body"] extends TSchema$
|
|
230
|
+
body: TConfig["body"] extends TSchema$2 ? Static$1<TConfig["body"]> : any;
|
|
231
231
|
headers: TConfig["headers"] extends TObject$1 ? Static$1<TConfig["headers"]> : Record<string, string>;
|
|
232
232
|
params: TConfig["params"] extends TObject$1 ? Static$1<TConfig["params"]> : Record<string, string>;
|
|
233
233
|
query: TConfig["query"] extends TObject$1 ? Static$1<TConfig["query"]> : Record<string, string>;
|
|
@@ -252,7 +252,7 @@ interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>
|
|
|
252
252
|
handler: ServerHandler<TConfig>;
|
|
253
253
|
schema?: TConfig;
|
|
254
254
|
}
|
|
255
|
-
type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TSchema$
|
|
255
|
+
type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TSchema$2 ? Static$1<TConfig["response"]> : ResponseBodyType;
|
|
256
256
|
type ResponseType = "json" | "text" | "void" | "file" | "any";
|
|
257
257
|
type ResponseBodyType = string | Buffer | StreamLike | undefined | null | void;
|
|
258
258
|
type ServerHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
|
|
@@ -286,10 +286,8 @@ interface ServerRawRequest {
|
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
*/
|
|
292
|
-
interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema"> {
|
|
289
|
+
declare const KEY$2 = "ACTION";
|
|
290
|
+
interface ActionDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema"> {
|
|
293
291
|
/**
|
|
294
292
|
* Name the route.
|
|
295
293
|
*/
|
|
@@ -304,8 +302,15 @@ interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestCo
|
|
|
304
302
|
* If false, disabled the security check for this route.
|
|
305
303
|
*
|
|
306
304
|
* @default true when SecurityModule is enabled, false otherwise.
|
|
305
|
+
* @deprecated
|
|
307
306
|
*/
|
|
308
307
|
security?: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* If true, the route is secure.
|
|
310
|
+
*
|
|
311
|
+
* Can be a string or an array of strings to specify required roles or permissions.
|
|
312
|
+
*/
|
|
313
|
+
secure?: boolean | string | string[];
|
|
309
314
|
/**
|
|
310
315
|
* Pathname of the route.
|
|
311
316
|
*/
|
|
@@ -314,7 +319,7 @@ interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestCo
|
|
|
314
319
|
* Inherit options from another route.
|
|
315
320
|
*/
|
|
316
321
|
use?: {
|
|
317
|
-
[OPTIONS]:
|
|
322
|
+
[OPTIONS]: ActionDescriptorOptions<TConfig>;
|
|
318
323
|
};
|
|
319
324
|
/**
|
|
320
325
|
* The route method.
|
|
@@ -343,7 +348,9 @@ interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestCo
|
|
|
343
348
|
*/
|
|
344
349
|
disabled?: boolean;
|
|
345
350
|
/**
|
|
346
|
-
* Mark the route as private.
|
|
351
|
+
* Mark the route as private.
|
|
352
|
+
* - It won't be exposed in the API documentation.
|
|
353
|
+
* - It won't be exposed in _links.
|
|
347
354
|
*/
|
|
348
355
|
internal?: boolean;
|
|
349
356
|
/**
|
|
@@ -351,9 +358,9 @@ interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestCo
|
|
|
351
358
|
*/
|
|
352
359
|
handler?: ServerHandler<TConfig>;
|
|
353
360
|
}
|
|
354
|
-
interface
|
|
355
|
-
[KIND]:
|
|
356
|
-
[OPTIONS]:
|
|
361
|
+
interface ActionDescriptor<TConfig extends RequestConfigSchema = RequestConfigSchema> {
|
|
362
|
+
[KIND]: typeof KEY$2;
|
|
363
|
+
[OPTIONS]: ActionDescriptorOptions<TConfig>;
|
|
357
364
|
/**
|
|
358
365
|
* Fetch or just call local route when available.
|
|
359
366
|
*/
|
|
@@ -367,37 +374,18 @@ interface RouteDescriptor<TConfig extends RequestConfigSchema = RequestConfigSch
|
|
|
367
374
|
*/
|
|
368
375
|
permission: () => string;
|
|
369
376
|
}
|
|
370
|
-
/**
|
|
371
|
-
* Declare a new route.
|
|
372
|
-
*
|
|
373
|
-
* ```ts
|
|
374
|
-
* class A {
|
|
375
|
-
* hello = $route({
|
|
376
|
-
* url: "/hello",
|
|
377
|
-
* handler: () => "Hello, World!",
|
|
378
|
-
* });
|
|
379
|
-
* }
|
|
380
|
-
* ```
|
|
381
|
-
*
|
|
382
|
-
* @param options The route options.
|
|
383
|
-
* @returns The route.
|
|
384
|
-
*/
|
|
385
|
-
declare const $route: {
|
|
386
|
-
<TConfig extends RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
|
|
387
|
-
[KIND]: string;
|
|
388
|
-
};
|
|
389
377
|
declare const $action: {
|
|
390
|
-
<TConfig extends RequestConfigSchema>(options:
|
|
378
|
+
<TConfig extends RequestConfigSchema>(options: ActionDescriptorOptions<TConfig>): ActionDescriptor<TConfig>;
|
|
391
379
|
[KIND]: string;
|
|
392
380
|
};
|
|
393
381
|
type ClientRequestEntry<TConfig extends RequestConfigSchema = RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = {
|
|
394
382
|
[K in keyof T as T[K] extends undefined ? never : K]: T[K];
|
|
395
383
|
};
|
|
396
384
|
type ClientRequestEntryContainer<TConfig extends RequestConfigSchema = RequestConfigSchema> = {
|
|
397
|
-
body: TConfig["body"] extends TSchema$
|
|
398
|
-
params: TConfig["params"] extends TSchema$
|
|
399
|
-
headers?: TConfig["headers"] extends TSchema$
|
|
400
|
-
query?: TConfig["query"] extends TSchema$
|
|
385
|
+
body: TConfig["body"] extends TSchema$2 ? Static$1<TConfig["body"]> : undefined;
|
|
386
|
+
params: TConfig["params"] extends TSchema$2 ? Static$1<TConfig["params"]> : undefined;
|
|
387
|
+
headers?: TConfig["headers"] extends TSchema$2 ? Static$1<TConfig["headers"]> : undefined;
|
|
388
|
+
query?: TConfig["query"] extends TSchema$2 ? Partial<Static$1<TConfig["query"]>> : undefined;
|
|
401
389
|
};
|
|
402
390
|
interface ClientRequestOptions {
|
|
403
391
|
/**
|
|
@@ -416,7 +404,7 @@ interface ClientRequestOptions {
|
|
|
416
404
|
*/
|
|
417
405
|
request?: RequestInit;
|
|
418
406
|
}
|
|
419
|
-
type ClientRequestResponse<TConfig extends RequestConfigSchema> = Promise<TConfig["response"] extends TSchema$
|
|
407
|
+
type ClientRequestResponse<TConfig extends RequestConfigSchema> = Promise<TConfig["response"] extends TSchema$2 ? Static$1<TConfig["response"]> : Response>;
|
|
420
408
|
|
|
421
409
|
declare class HttpError extends Error {
|
|
422
410
|
static toJSON(error: HttpError): {
|
|
@@ -451,41 +439,61 @@ declare class HttpError extends Error {
|
|
|
451
439
|
}
|
|
452
440
|
declare const errorNameByStatus: Record<number, string>;
|
|
453
441
|
|
|
454
|
-
declare class
|
|
455
|
-
name(options:
|
|
456
|
-
path(options:
|
|
457
|
-
link(options:
|
|
442
|
+
declare class ActionDescriptorHelper {
|
|
443
|
+
name(options: ActionDescriptorOptions, instance: any, key: string): string;
|
|
444
|
+
path(options: ActionDescriptorOptions, instance: any, key: string): string;
|
|
445
|
+
link(options: ActionDescriptorOptions, instance: any, key: string, prefix?: string): HttpClientLink;
|
|
458
446
|
method(options: {
|
|
459
447
|
method?: string;
|
|
460
448
|
schema?: any;
|
|
461
449
|
}): RouteMethod;
|
|
462
|
-
permission(options:
|
|
463
|
-
group(options:
|
|
450
|
+
permission(options: ActionDescriptorOptions, instance: any, key: string): Permission;
|
|
451
|
+
group(options: ActionDescriptorOptions, instance: any): string;
|
|
464
452
|
isMultipart(options: {
|
|
465
453
|
schema?: RequestConfigSchema;
|
|
466
454
|
}): boolean;
|
|
467
|
-
bodyContentType(options:
|
|
455
|
+
bodyContentType(options: ActionDescriptorOptions): string | undefined;
|
|
468
456
|
protected short(name: string): string;
|
|
457
|
+
fetchLinks(url: string): void;
|
|
469
458
|
}
|
|
470
459
|
|
|
460
|
+
declare const apiLinkSchema: TObject<{
|
|
461
|
+
name: TString$1;
|
|
462
|
+
path: TString$1;
|
|
463
|
+
method: TOptional<TString$1>;
|
|
464
|
+
group: TOptional<TString$1>;
|
|
465
|
+
requestBodyType: TOptional<TString$1>;
|
|
466
|
+
service: TOptional<TString$1>;
|
|
467
|
+
}>;
|
|
468
|
+
declare const apiLinksResponseSchema: TObject<{
|
|
469
|
+
userId: TOptional<TString$1>;
|
|
470
|
+
prefix: TOptional<TString$1>;
|
|
471
|
+
links: TArray<TObject<{
|
|
472
|
+
name: TString$1;
|
|
473
|
+
path: TString$1;
|
|
474
|
+
method: TOptional<TString$1>;
|
|
475
|
+
group: TOptional<TString$1>;
|
|
476
|
+
requestBodyType: TOptional<TString$1>;
|
|
477
|
+
service: TOptional<TString$1>;
|
|
478
|
+
}>>;
|
|
479
|
+
}>;
|
|
480
|
+
type ApiLinksResponse = Static$1<typeof apiLinksResponseSchema>;
|
|
481
|
+
type ApiLink = Static$1<typeof apiLinkSchema>;
|
|
482
|
+
|
|
471
483
|
declare class HttpClient {
|
|
472
484
|
protected readonly alepha: Alepha;
|
|
473
|
-
protected readonly
|
|
474
|
-
|
|
475
|
-
CLIENT_API_PREFIX: string;
|
|
476
|
-
};
|
|
477
|
-
protected readonly helper: RouteDescriptorHelper;
|
|
478
|
-
readonly URL_LINKS = "/_links";
|
|
485
|
+
protected readonly helper: ActionDescriptorHelper;
|
|
486
|
+
readonly URL_LINKS = "/api/_links";
|
|
479
487
|
readonly cache: _alepha_cache.CacheDescriptor<any, any[]>;
|
|
480
|
-
links?: Array<HttpClientLink>;
|
|
488
|
+
protected links?: Array<HttpClientLink>;
|
|
481
489
|
protected readonly pendingRequests: HttpClientPendingRequests;
|
|
482
|
-
|
|
490
|
+
pushLink(link: HttpClientLink): void;
|
|
483
491
|
clear(): Promise<void>;
|
|
484
|
-
createFetchFunction(link: HttpClientLink,
|
|
492
|
+
createFetchFunction(link: HttpClientLink, args?: FetchFactoryAdditionalOptions): (config?: Partial<ClientRequestEntry>, options?: ClientRequestOptions) => Promise<any>;
|
|
485
493
|
request(args: {
|
|
486
494
|
config?: ServerRequestConfigEntry;
|
|
487
495
|
link: HttpClientLink;
|
|
488
|
-
|
|
496
|
+
options?: ClientRequestOptions;
|
|
489
497
|
host?: string;
|
|
490
498
|
}): Promise<any>;
|
|
491
499
|
protected url(host: string, link: HttpClientLink, args: ServerRequestConfigEntry): string;
|
|
@@ -507,97 +515,246 @@ declare class HttpClient {
|
|
|
507
515
|
query?: TObject$1;
|
|
508
516
|
};
|
|
509
517
|
}, args?: ServerRequestConfigEntry): string;
|
|
510
|
-
of<T extends object>(
|
|
518
|
+
of<T extends object>(link?: {
|
|
511
519
|
group?: string;
|
|
512
|
-
host?: string | (() => string);
|
|
513
520
|
}): HttpVirtualClient<T>;
|
|
514
|
-
follow(name: string, config?:
|
|
515
|
-
request?: ClientRequestOptions;
|
|
521
|
+
follow(name: string, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions & {
|
|
516
522
|
group?: string;
|
|
517
|
-
|
|
523
|
+
service?: string;
|
|
518
524
|
}): Promise<any>;
|
|
519
525
|
can(name: string): boolean;
|
|
520
|
-
getLinks(
|
|
521
|
-
|
|
522
|
-
host?: string;
|
|
523
|
-
}): Promise<HttpClientLink[]>;
|
|
526
|
+
getLinks(): Promise<HttpClientLink[]>;
|
|
527
|
+
json<T = any>(url: string, options?: RequestInit): Promise<T>;
|
|
524
528
|
}
|
|
525
529
|
type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
|
|
526
530
|
interface FetchFactoryAdditionalOptions {
|
|
527
531
|
host?: string | (() => string);
|
|
528
532
|
}
|
|
529
533
|
interface FetchRunOptions {
|
|
530
|
-
schema?: TSchema$
|
|
534
|
+
schema?: TSchema$2;
|
|
531
535
|
raw?: boolean;
|
|
532
536
|
cache?: boolean | DurationLike;
|
|
533
537
|
}
|
|
534
|
-
interface HttpClientLink {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
contentType?: string;
|
|
540
|
-
protected?: boolean;
|
|
538
|
+
interface HttpClientLink extends ApiLink {
|
|
539
|
+
secured?: boolean;
|
|
540
|
+
prefix?: string;
|
|
541
|
+
host?: string;
|
|
542
|
+
service?: string;
|
|
541
543
|
schema?: RequestConfigSchema;
|
|
542
544
|
handler?: ServerHandler;
|
|
543
|
-
host?: string;
|
|
544
|
-
proxy?: boolean;
|
|
545
545
|
}
|
|
546
546
|
type HttpVirtualClient<T> = {
|
|
547
|
-
[K in keyof T as T[K] extends
|
|
547
|
+
[K in keyof T as T[K] extends ActionDescriptor ? K : never]: T[K] & {
|
|
548
548
|
can: () => boolean;
|
|
549
549
|
};
|
|
550
550
|
};
|
|
551
551
|
|
|
552
|
-
|
|
552
|
+
/** Symbol key applied to readonly types */
|
|
553
|
+
declare const ReadonlyKind: unique symbol;
|
|
554
|
+
/** Symbol key applied to optional types */
|
|
555
|
+
declare const OptionalKind: unique symbol;
|
|
556
|
+
/** Symbol key applied to types */
|
|
557
|
+
declare const Hint: unique symbol;
|
|
558
|
+
/** Symbol key applied to types */
|
|
559
|
+
declare const Kind: unique symbol;
|
|
560
|
+
|
|
561
|
+
type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
|
|
562
|
+
type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
|
|
563
|
+
interface StringOptions extends SchemaOptions {
|
|
564
|
+
/** The maximum string length */
|
|
565
|
+
maxLength?: number;
|
|
566
|
+
/** The minimum string length */
|
|
567
|
+
minLength?: number;
|
|
568
|
+
/** A regular expression pattern this string should match */
|
|
569
|
+
pattern?: string;
|
|
570
|
+
/** A format this string should match */
|
|
571
|
+
format?: StringFormatOption;
|
|
572
|
+
/** The content encoding for this string */
|
|
573
|
+
contentEncoding?: StringContentEncodingOption;
|
|
574
|
+
/** The content media type for this string */
|
|
575
|
+
contentMediaType?: string;
|
|
576
|
+
}
|
|
577
|
+
interface TString extends TSchema, StringOptions {
|
|
578
|
+
[Kind]: 'String';
|
|
579
|
+
static: string;
|
|
580
|
+
type: 'string';
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
interface SchemaOptions {
|
|
584
|
+
$schema?: string;
|
|
585
|
+
/** Id for this schema */
|
|
586
|
+
$id?: string;
|
|
587
|
+
/** Title of this schema */
|
|
588
|
+
title?: string;
|
|
589
|
+
/** Description of this schema */
|
|
590
|
+
description?: string;
|
|
591
|
+
/** Default value for this schema */
|
|
592
|
+
default?: any;
|
|
593
|
+
/** Example values matching this schema */
|
|
594
|
+
examples?: any;
|
|
595
|
+
/** Optional annotation for readOnly */
|
|
596
|
+
readOnly?: boolean;
|
|
597
|
+
/** Optional annotation for writeOnly */
|
|
598
|
+
writeOnly?: boolean;
|
|
599
|
+
[prop: string]: any;
|
|
600
|
+
}
|
|
601
|
+
interface TKind {
|
|
602
|
+
[Kind]: string;
|
|
603
|
+
}
|
|
604
|
+
interface TSchema extends TKind, SchemaOptions {
|
|
605
|
+
[ReadonlyKind]?: string;
|
|
606
|
+
[OptionalKind]?: string;
|
|
607
|
+
[Hint]?: string;
|
|
608
|
+
params: unknown[];
|
|
609
|
+
static: unknown;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
declare const envSchema$4: _alepha_core.TObject<{
|
|
613
|
+
SECURITY_SECRET_KEY: TString;
|
|
614
|
+
}>;
|
|
615
|
+
declare module "alepha/core" {
|
|
616
|
+
interface Env extends Partial<Static$1<typeof envSchema$4>> {
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
type ServiceAccountDescriptorOptions = {
|
|
620
|
+
oauth2: {
|
|
621
|
+
/**
|
|
622
|
+
* Get Token URL.
|
|
623
|
+
*/
|
|
624
|
+
url: string;
|
|
625
|
+
/**
|
|
626
|
+
* Client ID.
|
|
627
|
+
*/
|
|
628
|
+
clientId: string;
|
|
629
|
+
/**
|
|
630
|
+
* Client Secret.
|
|
631
|
+
*/
|
|
632
|
+
clientSecret: string;
|
|
633
|
+
/**
|
|
634
|
+
* Scopes to request.
|
|
635
|
+
*/
|
|
636
|
+
scope?: string;
|
|
637
|
+
};
|
|
638
|
+
} | {
|
|
639
|
+
jwt: {
|
|
640
|
+
secret: string;
|
|
641
|
+
roles?: string[];
|
|
642
|
+
};
|
|
643
|
+
};
|
|
644
|
+
interface ServiceAccountDescriptor {
|
|
645
|
+
options: ServiceAccountDescriptorOptions;
|
|
646
|
+
store: ServiceAccountStore;
|
|
647
|
+
token: () => Promise<string>;
|
|
648
|
+
fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
649
|
+
}
|
|
650
|
+
interface AccessTokenResponse {
|
|
651
|
+
access_token: string;
|
|
652
|
+
expires_in: number;
|
|
653
|
+
at: number;
|
|
654
|
+
}
|
|
655
|
+
interface ServiceAccountStore {
|
|
656
|
+
response?: AccessTokenResponse;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
type ProxyDescriptorOptions = {
|
|
660
|
+
path: string;
|
|
661
|
+
target: string;
|
|
662
|
+
disabled?: boolean;
|
|
663
|
+
beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
|
|
664
|
+
afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
|
|
665
|
+
rewrite?: (url: URL) => void;
|
|
666
|
+
};
|
|
667
|
+
interface ProxyDescriptor {
|
|
668
|
+
[KIND]: "PROXY";
|
|
669
|
+
[OPTIONS]: ProxyDescriptorOptions;
|
|
670
|
+
}
|
|
671
|
+
declare const $proxy: {
|
|
672
|
+
(options: ProxyDescriptorOptions): ProxyDescriptor;
|
|
673
|
+
[KIND]: string;
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
declare const KEY$1 = "REMOTE";
|
|
553
677
|
interface RemoteDescriptorOptions {
|
|
554
678
|
/**
|
|
555
679
|
* The URL of the remote service.
|
|
680
|
+
* You can use a function to generate the URL dynamically.
|
|
681
|
+
* You probably should use $inject(env) to get the URL from the environment.
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```ts
|
|
685
|
+
* import { $remote } from "@alepha/server";
|
|
686
|
+
* import { $inject, t } from "@alepha/core";
|
|
687
|
+
*
|
|
688
|
+
* class App {
|
|
689
|
+
* env = $inject(t.object({
|
|
690
|
+
* REMOTE_URL: t.string({default: "http://localhost:3000"}),
|
|
691
|
+
* }));
|
|
692
|
+
* remote = $remote({
|
|
693
|
+
* url: this.env.REMOTE_URL,
|
|
694
|
+
* });
|
|
695
|
+
* }
|
|
696
|
+
* ```
|
|
556
697
|
*/
|
|
557
698
|
url: string | (() => string);
|
|
558
|
-
/**
|
|
559
|
-
* @default "/api/_links"
|
|
560
|
-
*/
|
|
561
|
-
linkPath?: string;
|
|
562
|
-
/**
|
|
563
|
-
* If true, all methods of the remote service will be exposed as actions.
|
|
564
|
-
*/
|
|
565
|
-
proxy?: boolean | {
|
|
566
|
-
beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
|
|
567
|
-
afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
|
|
568
|
-
rewrite?: (url: URL) => void;
|
|
569
|
-
};
|
|
570
|
-
/**
|
|
571
|
-
* One or many instance of classes to be registered as remote services.
|
|
572
|
-
* Services must contain some $action() descriptors.
|
|
573
|
-
*/
|
|
574
|
-
services?: object | Array<object>;
|
|
575
699
|
/**
|
|
576
700
|
* The name of the remote service.
|
|
577
701
|
*
|
|
578
702
|
* @default Member of the class containing the remote service.
|
|
579
703
|
*/
|
|
580
704
|
name?: string;
|
|
705
|
+
/**
|
|
706
|
+
* If true, all methods of the remote service will be exposed as actions in this context.
|
|
707
|
+
* > Note: Proxy will never use the service account, it just... proxies the request.
|
|
708
|
+
*/
|
|
709
|
+
proxy?: boolean | Partial<ProxyDescriptorOptions>;
|
|
710
|
+
/**
|
|
711
|
+
* For communication between the server and the remote service with a security layer.
|
|
712
|
+
* This will be used for internal communication and will not be exposed to the client.
|
|
713
|
+
*/
|
|
714
|
+
serviceAccount?: ServiceAccountDescriptor;
|
|
581
715
|
}
|
|
582
716
|
interface RemoteDescriptor {
|
|
583
|
-
[KIND]: typeof
|
|
717
|
+
[KIND]: typeof KEY$1;
|
|
584
718
|
[OPTIONS]: RemoteDescriptorOptions;
|
|
585
719
|
}
|
|
720
|
+
/**
|
|
721
|
+
* $remote is a descriptor that allows you to define a remote service access.
|
|
722
|
+
*
|
|
723
|
+
* Use it only when you have 2 or more services that need to communicate with each other.
|
|
724
|
+
*
|
|
725
|
+
* All remote services can be exposed as actions, ... or not.
|
|
726
|
+
*
|
|
727
|
+
* You can add a service account if you want to use a security layer.
|
|
728
|
+
*/
|
|
586
729
|
declare const $remote: {
|
|
587
730
|
(options: RemoteDescriptorOptions): RemoteDescriptor;
|
|
588
731
|
[KIND]: string;
|
|
589
732
|
};
|
|
590
733
|
|
|
734
|
+
declare const $client: <T extends object>() => HttpVirtualClient<T>;
|
|
735
|
+
|
|
736
|
+
declare const KEY = "ROUTE";
|
|
737
|
+
interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {
|
|
738
|
+
}
|
|
739
|
+
type RouteDescriptor<TConfig extends RequestConfigSchema = RequestConfigSchema> = {
|
|
740
|
+
[KIND]: typeof KEY;
|
|
741
|
+
[OPTIONS]: RouteDescriptorOptions<TConfig>;
|
|
742
|
+
};
|
|
743
|
+
declare const $route: {
|
|
744
|
+
<TConfig extends RequestConfigSchema = RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
|
|
745
|
+
[KIND]: string;
|
|
746
|
+
};
|
|
747
|
+
|
|
591
748
|
declare class ServerProvider {
|
|
592
749
|
constructor();
|
|
593
750
|
get hostname(): string;
|
|
594
751
|
}
|
|
595
752
|
|
|
596
753
|
declare const envSchema$3: _alepha_core.TObject<{
|
|
597
|
-
SERVER_API_PREFIX: TString;
|
|
754
|
+
SERVER_API_PREFIX: TString$1;
|
|
598
755
|
SERVER_SECURITY_ENABLED: TBoolean;
|
|
599
756
|
}>;
|
|
600
|
-
declare module "alepha/core" {
|
|
757
|
+
declare module "@alepha/core" {
|
|
601
758
|
interface Env extends Partial<Static$1<typeof envSchema$3>> {
|
|
602
759
|
}
|
|
603
760
|
}
|
|
@@ -610,51 +767,17 @@ declare class ServerActionDescriptorProvider {
|
|
|
610
767
|
};
|
|
611
768
|
protected readonly client: HttpClient;
|
|
612
769
|
protected readonly serverProvider: ServerProvider;
|
|
613
|
-
protected readonly helper:
|
|
770
|
+
protected readonly helper: ActionDescriptorHelper;
|
|
614
771
|
protected readonly routerProvider: ServerRouterProvider;
|
|
615
|
-
protected readonly remotes: Array<ServerRemote>;
|
|
616
772
|
protected readonly actions: ServerRouteAction[];
|
|
617
773
|
getActions(): ServerRouteAction<RequestConfigSchema>[];
|
|
774
|
+
getPrefix(): string;
|
|
618
775
|
readonly configure: _alepha_core.HookDescriptor<"configure">;
|
|
619
|
-
|
|
620
|
-
loadRemoteLinks: (options: RemoteDescriptorOptions) => Promise<Promise<void>>;
|
|
621
|
-
proxy(url: string, link: HttpClientLink, options: {
|
|
622
|
-
beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
|
|
623
|
-
afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
|
|
624
|
-
rewrite?: (url: URL) => void;
|
|
625
|
-
}): Promise<void>;
|
|
626
|
-
private getRawRequestBody;
|
|
627
|
-
registerAction(value: RouteDescriptor, key: string, instance: any, prefix?: string): Promise<void>;
|
|
776
|
+
registerAction(value: ActionDescriptor, key: string, instance: any, prefix?: string): Promise<void>;
|
|
628
777
|
/**
|
|
629
|
-
*
|
|
630
|
-
* Instead of creating an http route, create a bridge to a local or remote function.
|
|
631
|
-
*
|
|
632
|
-
* ```ts
|
|
633
|
-
* class Api {
|
|
634
|
-
* hello = $action(); // <- route 'Api'
|
|
635
|
-
* }
|
|
636
|
-
*
|
|
637
|
-
* class Controller {
|
|
638
|
-
* api = $inject(Api);
|
|
639
|
-
* hello = $action({ // <-- route
|
|
640
|
-
* use: this.api.hello,
|
|
641
|
-
* handler: () => new Response("Hello world"),
|
|
642
|
-
* })
|
|
643
|
-
* }
|
|
644
|
-
*
|
|
645
|
-
* const api = alepha.get(Api);
|
|
646
|
-
*
|
|
647
|
-
* api.hello(); // <-- call the local controller function if available
|
|
648
|
-
*
|
|
649
|
-
* // or with $remote
|
|
650
|
-
* class Remotes {
|
|
651
|
-
* api = $remote({ url: "http://localhost:8080", services: [Api] });
|
|
652
|
-
* }
|
|
653
|
-
*
|
|
654
|
-
* // or with future auto-discovery
|
|
655
|
-
* ```
|
|
778
|
+
* @deprecated
|
|
656
779
|
*/
|
|
657
|
-
registerActionApi(routeDescriptor:
|
|
780
|
+
registerActionApi(routeDescriptor: ActionDescriptor, instance: any, key: string): void;
|
|
658
781
|
/**
|
|
659
782
|
* Check a mock function for the specified route.
|
|
660
783
|
*
|
|
@@ -664,7 +787,7 @@ declare class ServerActionDescriptorProvider {
|
|
|
664
787
|
* @param permission
|
|
665
788
|
* @protected
|
|
666
789
|
*/
|
|
667
|
-
protected createLocalFunction(value:
|
|
790
|
+
protected createLocalFunction(value: ActionDescriptor, permission: Permission): (config?: ServerRequestConfigEntry, options?: ClientRequestOptions) => Promise<any>;
|
|
668
791
|
/**
|
|
669
792
|
* Security adapted for local function.
|
|
670
793
|
*/
|
|
@@ -679,20 +802,60 @@ declare class ServerActionDescriptorProvider {
|
|
|
679
802
|
declare const isServerAction: (value: any) => value is ServerRouteAction;
|
|
680
803
|
interface ServerRemote {
|
|
681
804
|
url: string;
|
|
682
|
-
services: object[];
|
|
683
805
|
name: string;
|
|
684
806
|
proxy: boolean;
|
|
807
|
+
links: (authorization?: string) => Promise<ApiLinksResponse>;
|
|
808
|
+
serviceAccount?: ServiceAccountDescriptor$1;
|
|
809
|
+
prefix: string;
|
|
685
810
|
}
|
|
686
811
|
interface ServerRouteAction<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {
|
|
812
|
+
prefix: string;
|
|
687
813
|
method: RouteMethod;
|
|
688
814
|
name: string;
|
|
689
815
|
group: string;
|
|
690
816
|
permission: Permission;
|
|
691
|
-
options:
|
|
817
|
+
options: ActionDescriptorOptions;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
declare class ProxyDescriptorProvider {
|
|
821
|
+
protected readonly routerProvider: ServerRouterProvider;
|
|
822
|
+
protected readonly alepha: Alepha;
|
|
823
|
+
readonly configure: _alepha_core.HookDescriptor<"configure">;
|
|
824
|
+
createProxyHandler(options: Omit<ProxyDescriptorOptions, "path">): ServerHandler;
|
|
825
|
+
proxy(options: ProxyDescriptorOptions): Promise<void>;
|
|
826
|
+
private getRawRequestBody;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
declare class RemoteDescriptorProvider {
|
|
830
|
+
protected readonly alepha: Alepha;
|
|
831
|
+
protected readonly client: HttpClient;
|
|
832
|
+
protected readonly proxyProvider: ProxyDescriptorProvider;
|
|
833
|
+
protected readonly remotes: Array<ServerRemote>;
|
|
834
|
+
protected readonly log: _alepha_core.Logger;
|
|
835
|
+
getRemotes(): ServerRemote[];
|
|
836
|
+
readonly configure: _alepha_core.HookDescriptor<"configure">;
|
|
837
|
+
readonly start: _alepha_core.HookDescriptor<"start">;
|
|
838
|
+
registerRemote(value: RemoteDescriptor, key: string): Promise<void>;
|
|
839
|
+
protected readonly fetchLinks: (opts: {
|
|
840
|
+
service: string;
|
|
841
|
+
url: string;
|
|
842
|
+
authorization?: string;
|
|
843
|
+
}) => Promise<{
|
|
844
|
+
userId?: string | undefined;
|
|
845
|
+
prefix?: string | undefined;
|
|
846
|
+
links: {
|
|
847
|
+
method?: string | undefined;
|
|
848
|
+
group?: string | undefined;
|
|
849
|
+
requestBodyType?: string | undefined;
|
|
850
|
+
service?: string | undefined;
|
|
851
|
+
path: string;
|
|
852
|
+
name: string;
|
|
853
|
+
}[];
|
|
854
|
+
}>;
|
|
692
855
|
}
|
|
693
856
|
|
|
694
857
|
declare const envSchema$2: _alepha_core.TObject<{
|
|
695
|
-
SERVER_API_URL: TString;
|
|
858
|
+
SERVER_API_URL: TString$1;
|
|
696
859
|
}>;
|
|
697
860
|
declare module "@alepha/core" {
|
|
698
861
|
interface Env extends Partial<Static$1<typeof envSchema$2>> {
|
|
@@ -705,10 +868,10 @@ declare class BrowserActionDescriptorProvider {
|
|
|
705
868
|
protected readonly env: {
|
|
706
869
|
SERVER_API_URL: string;
|
|
707
870
|
};
|
|
708
|
-
protected readonly helper:
|
|
871
|
+
protected readonly helper: ActionDescriptorHelper;
|
|
709
872
|
readonly configure: _alepha_core.HookDescriptor<"configure">;
|
|
710
873
|
configureActions(): void;
|
|
711
|
-
registerAction(value:
|
|
874
|
+
registerAction(value: ActionDescriptor, instance: any, key: string): void;
|
|
712
875
|
}
|
|
713
876
|
|
|
714
877
|
declare class ServerSecurityProvider {
|
|
@@ -724,15 +887,36 @@ declare class ServerSecurityProvider {
|
|
|
724
887
|
declare class ServerLinksProvider {
|
|
725
888
|
protected readonly alepha: Alepha;
|
|
726
889
|
protected readonly client: HttpClient;
|
|
890
|
+
protected readonly remoteProvider: RemoteDescriptorProvider;
|
|
891
|
+
protected readonly serverActionDescriptorProvider: ServerActionDescriptorProvider;
|
|
727
892
|
readonly links: RouteDescriptor<{
|
|
728
|
-
response:
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
893
|
+
response: TObject<{
|
|
894
|
+
userId: TOptional<TString$1>;
|
|
895
|
+
prefix: TOptional<TString$1>;
|
|
896
|
+
links: TArray<TObject<{
|
|
897
|
+
name: TString$1;
|
|
898
|
+
path: TString$1;
|
|
899
|
+
method: TOptional<TString$1>;
|
|
900
|
+
group: TOptional<TString$1>;
|
|
901
|
+
requestBodyType: TOptional<TString$1>;
|
|
902
|
+
service: TOptional<TString$1>;
|
|
903
|
+
}>>;
|
|
904
|
+
}>;
|
|
905
|
+
}>;
|
|
906
|
+
getLinks(options: {
|
|
907
|
+
user?: UserAccountToken;
|
|
908
|
+
authorization?: string;
|
|
909
|
+
}): Promise<{
|
|
910
|
+
userId: string | undefined;
|
|
911
|
+
prefix: string;
|
|
912
|
+
links: {
|
|
913
|
+
method?: string | undefined;
|
|
914
|
+
group?: string | undefined;
|
|
915
|
+
requestBodyType?: string | undefined;
|
|
916
|
+
service?: string | undefined;
|
|
917
|
+
path: string;
|
|
918
|
+
name: string;
|
|
919
|
+
}[];
|
|
736
920
|
}>;
|
|
737
921
|
}
|
|
738
922
|
|
|
@@ -744,8 +928,38 @@ declare class ServerLoggerProvider {
|
|
|
744
928
|
readonly onResponse: _alepha_core.HookDescriptor<"server:onResponse">;
|
|
745
929
|
}
|
|
746
930
|
|
|
931
|
+
/**
|
|
932
|
+
* Register `/health` endpoint.
|
|
933
|
+
*
|
|
934
|
+
* - Provides basic health information about the server.
|
|
935
|
+
*/
|
|
936
|
+
declare class ServerHealthProvider {
|
|
937
|
+
protected readonly dateTimeProvider: DateTimeProvider;
|
|
938
|
+
protected readonly alepha: Alepha;
|
|
939
|
+
readonly health: RouteDescriptor<{
|
|
940
|
+
response: TObject<{
|
|
941
|
+
message: TString$1;
|
|
942
|
+
uptime: TNumber;
|
|
943
|
+
date: TString$1;
|
|
944
|
+
ready: TBoolean;
|
|
945
|
+
}>;
|
|
946
|
+
}>;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* On every request, this provider checks if the server is ready.
|
|
951
|
+
*
|
|
952
|
+
* If the server is not ready, it responds with a 503 status code and a message indicating that the server is not ready yet.
|
|
953
|
+
*
|
|
954
|
+
* The response also includes a `Retry-After` header indicating that the client should retry after 5 seconds.
|
|
955
|
+
*/
|
|
956
|
+
declare class ServerNotReadyProvider {
|
|
957
|
+
protected readonly alepha: Alepha;
|
|
958
|
+
readonly onRequest: _alepha_core.HookDescriptor<"server:onRequest">;
|
|
959
|
+
}
|
|
960
|
+
|
|
747
961
|
declare class ServerMultipartProvider {
|
|
748
|
-
protected readonly helper:
|
|
962
|
+
protected readonly helper: ActionDescriptorHelper;
|
|
749
963
|
protected readonly alepha: Alepha;
|
|
750
964
|
readonly onRequest: _alepha_core.HookDescriptor<"server:onRequest">;
|
|
751
965
|
readonly onSend: _alepha_core.HookDescriptor<"server:onResponse">;
|
|
@@ -781,7 +995,7 @@ declare const getContentType: (filename: string) => string;
|
|
|
781
995
|
|
|
782
996
|
declare const envSchema$1: _alepha_core.TObject<{
|
|
783
997
|
SERVER_PORT: TNumber;
|
|
784
|
-
SERVER_HOST: TString;
|
|
998
|
+
SERVER_HOST: TString$1;
|
|
785
999
|
}>;
|
|
786
1000
|
declare module "@alepha/core" {
|
|
787
1001
|
interface Env extends Partial<Static$1<typeof envSchema$1>> {
|
|
@@ -807,19 +1021,19 @@ declare class NodeHttpServerProvider implements ServerProvider {
|
|
|
807
1021
|
}
|
|
808
1022
|
|
|
809
1023
|
declare const errorSchema: TObject<{
|
|
810
|
-
error: TString;
|
|
1024
|
+
error: TString$1;
|
|
811
1025
|
status: TNumber;
|
|
812
|
-
message: TString;
|
|
813
|
-
details: TOptional<TString>;
|
|
1026
|
+
message: TString$1;
|
|
1027
|
+
details: TOptional<TString$1>;
|
|
814
1028
|
cause: TOptional<TObject<{
|
|
815
|
-
name: TString;
|
|
816
|
-
message: TString;
|
|
1029
|
+
name: TString$1;
|
|
1030
|
+
message: TString$1;
|
|
817
1031
|
}>>;
|
|
818
1032
|
}>;
|
|
819
1033
|
|
|
820
1034
|
declare const okSchema: TObject<{
|
|
821
1035
|
ok: TBoolean;
|
|
822
|
-
id: TOptional<TUnion<[TString, TInteger]>>;
|
|
1036
|
+
id: TOptional<TUnion<[TString$1, TInteger]>>;
|
|
823
1037
|
count: TOptional<TNumber>;
|
|
824
1038
|
}>;
|
|
825
1039
|
type Ok = Static$1<typeof okSchema>;
|
|
@@ -850,6 +1064,8 @@ declare class ValidationError extends HttpError {
|
|
|
850
1064
|
|
|
851
1065
|
declare const envSchema: _alepha_core.TObject<{
|
|
852
1066
|
SERVER_LINKS_ENABLED: TBoolean;
|
|
1067
|
+
SERVER_HEALTH_ENABLED: TBoolean;
|
|
1068
|
+
SERVER_NOT_READY_ENABLED: TBoolean;
|
|
853
1069
|
}>;
|
|
854
1070
|
declare module "@alepha/core" {
|
|
855
1071
|
interface Hooks {
|
|
@@ -899,9 +1115,11 @@ declare module "@alepha/core" {
|
|
|
899
1115
|
declare class ServerModule {
|
|
900
1116
|
protected readonly env: {
|
|
901
1117
|
SERVER_LINKS_ENABLED: boolean;
|
|
1118
|
+
SERVER_HEALTH_ENABLED: boolean;
|
|
1119
|
+
SERVER_NOT_READY_ENABLED: boolean;
|
|
902
1120
|
};
|
|
903
1121
|
protected readonly alepha: Alepha;
|
|
904
1122
|
constructor();
|
|
905
1123
|
}
|
|
906
1124
|
|
|
907
|
-
export { $action, $remote, $route, BadRequestError, BrowserActionDescriptorProvider, type ClientRequestEntry, type ClientRequestEntryContainer, type ClientRequestOptions, type ClientRequestResponse, ConflictError, type FetchFactoryAdditionalOptions, type FetchRunOptions, ForbiddenError, HttpClient, type HttpClientLink, type HttpClientPendingRequests, HttpError, type HttpVirtualClient, NodeHttpServerProvider, NotFoundError, type Ok,
|
|
1125
|
+
export { $action, $client, $proxy, $remote, $route, type ActionDescriptor, type ActionDescriptorOptions, type ApiLink, type ApiLinksResponse, BadRequestError, BrowserActionDescriptorProvider, type ClientRequestEntry, type ClientRequestEntryContainer, type ClientRequestOptions, type ClientRequestResponse, ConflictError, type FetchFactoryAdditionalOptions, type FetchRunOptions, ForbiddenError, HttpClient, type HttpClientLink, type HttpClientPendingRequests, HttpError, type HttpVirtualClient, NodeHttpServerProvider, NotFoundError, type Ok, type ProxyDescriptor, type ProxyDescriptorOptions, ProxyDescriptorProvider, type RemoteDescriptor, type RemoteDescriptorOptions, RemoteDescriptorProvider, type RequestConfigSchema, type ResponseBodyType, type ResponseType, type RouteDescriptor, type RouteDescriptorOptions, type RouteMethod, ServerActionDescriptorProvider, type ServerHandler, ServerHealthProvider, ServerLinksProvider, ServerLoggerProvider, ServerModule, ServerMultipartProvider, ServerNotReadyProvider, ServerProvider, type ServerRawRequest, type ServerRemote, type ServerReply, type ServerRequest, type ServerRequestConfig, type ServerRequestConfigEntry, type ServerResponse, type ServerResponseBody, type ServerRoute, type ServerRouteAction, type ServerRouteWithHandler, ServerRouterProvider, ServerSecurityProvider, UnauthorizedError, ValidationError, apiLinkSchema, apiLinksResponseSchema, bufferToArrayBuffer, bufferToStream, errorNameByStatus, errorSchema, file, getContentType, isServerAction, okSchema, routeMethods, streamToBuffer };
|