alepha 0.7.6 → 0.7.7

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.
@@ -0,0 +1,42 @@
1
+ import * as _alepha_server5 from "@alepha/server";
2
+ import { Alepha } from "@alepha/core";
3
+ import { DateTimeProvider } from "@alepha/datetime";
4
+ import * as _sinclair_typebox0 from "@sinclair/typebox";
5
+
6
+ //#region src/providers/ServerHealthProvider.d.ts
7
+
8
+ /**
9
+ * Register `/health` endpoint.
10
+ *
11
+ * - Provides basic health information about the server.
12
+ */
13
+ declare class ServerHealthProvider {
14
+ protected readonly dateTimeProvider: DateTimeProvider;
15
+ protected readonly alepha: Alepha;
16
+ readonly health: _alepha_server5.RouteDescriptor<{
17
+ response: _sinclair_typebox0.TObject<{
18
+ message: _sinclair_typebox0.TString;
19
+ uptime: _sinclair_typebox0.TNumber;
20
+ date: _sinclair_typebox0.TString;
21
+ ready: _sinclair_typebox0.TBoolean;
22
+ }>;
23
+ }>;
24
+ }
25
+ //#endregion
26
+ //#region src/index.d.ts
27
+ /**
28
+ * Alepha Server Health Module
29
+ *
30
+ * @description
31
+ * Plugin for Alepha Server that provides health-check endpoints.
32
+ *
33
+ * @see {@link ServerHealthProvider}
34
+ * @module alepha.server.health
35
+ */
36
+ declare class AlephaServerHealth {
37
+ readonly name = "alepha.server.health";
38
+ readonly $services: (alepha: any) => void;
39
+ }
40
+ //#endregion
41
+ export { AlephaServerHealth, ServerHealthProvider };
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ export * from '@alepha/server-health'
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/server-links');
3
+ Object.keys(m).forEach(function (k) {
4
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
+ enumerable: true,
6
+ get: function () { return m[k]; }
7
+ });
8
+ });
@@ -0,0 +1,188 @@
1
+ import * as _alepha_core23 from "@alepha/core";
2
+ import * as _alepha_core24 from "@alepha/core";
3
+ import * as _alepha_core0 from "@alepha/core";
4
+ import { Alepha, KIND, Module, OPTIONS } from "@alepha/core";
5
+ import * as _alepha_server16 from "@alepha/server";
6
+ import { ActionDescriptor, ActionDescriptorHelper, ApiLink, ApiLinksResponse, ClientRequestOptions, FetchResponse, HttpClient, RequestConfigSchema, ServerActionDescriptorProvider, ServerHandler, ServerRemote, ServerRequestConfigEntry } from "@alepha/server";
7
+ import * as _alepha_retry27 from "@alepha/retry";
8
+ import { ProxyDescriptorOptions, ProxyDescriptorProvider } from "@alepha/server-proxy";
9
+ import { ServiceAccountDescriptor, UserAccountToken } from "@alepha/security";
10
+ import * as _sinclair_typebox1 from "@sinclair/typebox";
11
+
12
+ //#region src/providers/LinkProvider.d.ts
13
+ declare class LinkProvider {
14
+ readonly URL_LINKS = "/api/_links";
15
+ protected readonly log: _alepha_core23.Logger;
16
+ protected readonly alepha: Alepha;
17
+ protected readonly httpClient: HttpClient;
18
+ links?: Array<HttpClientLink>;
19
+ pushLink(link: HttpClientLink): void;
20
+ getLinks(force?: boolean): Promise<HttpClientLink[]>;
21
+ client<T extends object>(scope?: ClientScope): HttpVirtualClient<T>;
22
+ /**
23
+ * Resolve a link by its name and call it.
24
+ * - If link is local, it will call the local handler.
25
+ * - If link is remote, it will make a fetch request to the remote server.
26
+ */
27
+ follow(name: string, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions & ClientScope): Promise<any>;
28
+ protected followRemote(link: HttpClientLink, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions): Promise<FetchResponse>;
29
+ can(name: string): boolean;
30
+ protected getLinkByName(name: string, options?: ClientScope): Promise<HttpClientLink>;
31
+ }
32
+ interface HttpClientLink extends ApiLink {
33
+ secured?: boolean;
34
+ prefix?: string;
35
+ host?: string;
36
+ service?: string;
37
+ schema?: RequestConfigSchema;
38
+ handler?: ServerHandler;
39
+ }
40
+ interface ClientScope {
41
+ group?: string;
42
+ service?: string;
43
+ }
44
+ type HttpVirtualClient<T> = { [K in keyof T as T[K] extends ActionDescriptor ? K : never]: T[K] extends ActionDescriptor<infer Schema> ? T[K] & {
45
+ can: () => boolean;
46
+ schema: Schema;
47
+ } : never };
48
+ //#endregion
49
+ //#region src/descriptors/$client.d.ts
50
+ declare const $client: <T extends object>(scope?: ClientScope) => HttpVirtualClient<T>;
51
+ //#endregion
52
+ //#region src/descriptors/$remote.d.ts
53
+ declare const KEY = "REMOTE";
54
+ interface RemoteDescriptorOptions {
55
+ /**
56
+ * The URL of the remote service.
57
+ * You can use a function to generate the URL dynamically.
58
+ * You probably should use $inject(env) to get the URL from the environment.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { $remote } from "@alepha/server";
63
+ * import { $inject, t } from "@alepha/core";
64
+ *
65
+ * class App {
66
+ * env = $inject(t.object({
67
+ * REMOTE_URL: t.string({default: "http://localhost:3000"}),
68
+ * }));
69
+ * remote = $remote({
70
+ * url: this.env.REMOTE_URL,
71
+ * });
72
+ * }
73
+ * ```
74
+ */
75
+ url: string | (() => string);
76
+ /**
77
+ * The name of the remote service.
78
+ *
79
+ * @default Member of the class containing the remote service.
80
+ */
81
+ name?: string;
82
+ /**
83
+ * If true, all methods of the remote service will be exposed as actions in this context.
84
+ * > Note: Proxy will never use the service account, it just... proxies the request.
85
+ */
86
+ proxy?: boolean | Partial<ProxyDescriptorOptions & {
87
+ /**
88
+ * If true, the remote service won't be available internally, only through the proxy.
89
+ */
90
+ noInternal: boolean;
91
+ }>;
92
+ /**
93
+ * For communication between the server and the remote service with a security layer.
94
+ * This will be used for internal communication and will not be exposed to the client.
95
+ */
96
+ serviceAccount?: ServiceAccountDescriptor;
97
+ }
98
+ interface RemoteDescriptor {
99
+ [KIND]: typeof KEY;
100
+ [OPTIONS]: RemoteDescriptorOptions;
101
+ }
102
+ /**
103
+ * $remote is a descriptor that allows you to define a remote service access.
104
+ *
105
+ * Use it only when you have 2 or more services that need to communicate with each other.
106
+ *
107
+ * All remote services can be exposed as actions, ... or not.
108
+ *
109
+ * You can add a service account if you want to use a security layer.
110
+ */
111
+ declare const $remote: {
112
+ (options: RemoteDescriptorOptions): RemoteDescriptor;
113
+ [KIND]: string;
114
+ };
115
+ //#endregion
116
+ //#region src/providers/RemoteDescriptorProvider.d.ts
117
+ declare class RemoteDescriptorProvider {
118
+ static path: {
119
+ apiLinks: string;
120
+ };
121
+ protected readonly alepha: Alepha;
122
+ protected readonly client: LinkProvider;
123
+ protected readonly proxyProvider: ProxyDescriptorProvider;
124
+ protected readonly remotes: Array<ServerRemote>;
125
+ protected readonly log: _alepha_core24.Logger;
126
+ getRemotes(): ServerRemote[];
127
+ readonly configure: _alepha_core24.HookDescriptor<"configure">;
128
+ readonly start: _alepha_core24.HookDescriptor<"start">;
129
+ registerRemote(value: RemoteDescriptor, key: string): Promise<void>;
130
+ protected readonly fetchLinks: _alepha_retry27.RetryDescriptor<(opts: {
131
+ service: string;
132
+ url: string;
133
+ authorization?: string;
134
+ }) => Promise<{
135
+ prefix?: string | undefined;
136
+ links: {
137
+ method?: string | undefined;
138
+ group?: string | undefined;
139
+ requestBodyType?: string | undefined;
140
+ service?: string | undefined;
141
+ name: string;
142
+ path: string;
143
+ }[];
144
+ }>>;
145
+ }
146
+ //#endregion
147
+ //#region src/providers/ServerLinksProvider.d.ts
148
+ declare class ServerLinksProvider {
149
+ protected readonly alepha: Alepha;
150
+ protected readonly client: LinkProvider;
151
+ protected readonly helper: ActionDescriptorHelper;
152
+ protected readonly remoteProvider: RemoteDescriptorProvider;
153
+ protected readonly serverActionDescriptorProvider: ServerActionDescriptorProvider;
154
+ readonly onRoute: _alepha_core0.HookDescriptor<"server:onRoute">;
155
+ readonly links: _alepha_server16.RouteDescriptor<{
156
+ response: _sinclair_typebox1.TObject<{
157
+ prefix: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
158
+ links: _sinclair_typebox1.TArray<_sinclair_typebox1.TObject<{
159
+ name: _sinclair_typebox1.TString;
160
+ path: _sinclair_typebox1.TString;
161
+ method: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
162
+ group: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
163
+ requestBodyType: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
164
+ service: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
165
+ }>>;
166
+ }>;
167
+ }>;
168
+ readonly schema: _alepha_server16.RouteDescriptor<{
169
+ params: _sinclair_typebox1.TObject<{
170
+ name: _sinclair_typebox1.TString;
171
+ }>;
172
+ response: _sinclair_typebox1.TRecord<_sinclair_typebox1.TString, _sinclair_typebox1.TAny>;
173
+ }>;
174
+ getLinks(options: GetLinksOptions): Promise<ApiLinksResponse>;
175
+ }
176
+ interface GetLinksOptions {
177
+ user?: UserAccountToken;
178
+ authorization?: string;
179
+ }
180
+ //#endregion
181
+ //#region src/index.d.ts
182
+ declare class AlephaServerLinks implements Module {
183
+ readonly name = "alepha.server.links";
184
+ readonly $services: (alepha: Alepha) => void;
185
+ }
186
+ //#endregion
187
+ export { $client, $remote, AlephaServerLinks, ClientScope, GetLinksOptions, HttpClientLink, HttpVirtualClient, LinkProvider, RemoteDescriptor, RemoteDescriptorOptions, RemoteDescriptorProvider, ServerLinksProvider };
188
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ export * from '@alepha/server-links'
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/server-proxy');
3
+ Object.keys(m).forEach(function (k) {
4
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
+ enumerable: true,
6
+ get: function () { return m[k]; }
7
+ });
8
+ });
@@ -0,0 +1,41 @@
1
+ import * as _alepha_core0 from "@alepha/core";
2
+ import { Alepha, Async, KIND, Module, OPTIONS } from "@alepha/core";
3
+ import { ServerHandler, ServerRequest, ServerRouterProvider } from "@alepha/server";
4
+
5
+ //#region src/descriptors/$proxy.d.ts
6
+ type ProxyDescriptorOptions = {
7
+ path: string;
8
+ target: string;
9
+ disabled?: boolean;
10
+ beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
11
+ afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
12
+ rewrite?: (url: URL) => void;
13
+ };
14
+ interface ProxyDescriptor {
15
+ [KIND]: "PROXY";
16
+ [OPTIONS]: ProxyDescriptorOptions;
17
+ }
18
+ declare const $proxy: {
19
+ (options: ProxyDescriptorOptions): ProxyDescriptor;
20
+ [KIND]: string;
21
+ };
22
+ //#endregion
23
+ //#region src/providers/ProxyDescriptorProvider.d.ts
24
+ declare class ProxyDescriptorProvider {
25
+ protected readonly log: _alepha_core0.Logger;
26
+ protected readonly routerProvider: ServerRouterProvider;
27
+ protected readonly alepha: Alepha;
28
+ readonly configure: _alepha_core0.HookDescriptor<"configure">;
29
+ createProxyHandler(options: Omit<ProxyDescriptorOptions, "path">): ServerHandler;
30
+ proxy(options: ProxyDescriptorOptions): Promise<void>;
31
+ private getRawRequestBody;
32
+ }
33
+ //#endregion
34
+ //#region src/index.d.ts
35
+ declare class AlephaServerProxy implements Module {
36
+ readonly name = "alepha.server.proxy";
37
+ readonly $services: (alepha: Alepha) => void;
38
+ }
39
+ //#endregion
40
+ export { $proxy, AlephaServerProxy, ProxyDescriptor, ProxyDescriptorOptions, ProxyDescriptorProvider };
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ export * from '@alepha/server-proxy'