@aeriajs/server 0.0.273 → 0.0.275
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +16 -0
- package/dist/constants.mjs +17 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.js +10 -8
- package/dist/init.mjs +10 -8
- package/dist/routes.d.ts +2 -2
- package/dist/warmup.js +5 -5
- package/dist/warmup.mjs +5 -5
- package/package.json +9 -9
package/dist/constants.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ export declare const DEFAULT_API_CONFIG: {
|
|
|
3
3
|
defaultPaginationLimit: number;
|
|
4
4
|
server: {
|
|
5
5
|
port: number;
|
|
6
|
+
cors: {
|
|
7
|
+
allowOrigin: string[];
|
|
8
|
+
allowMethods: string[];
|
|
9
|
+
allowHeaders: string[];
|
|
10
|
+
maxAge: string;
|
|
11
|
+
};
|
|
6
12
|
};
|
|
7
13
|
security: {
|
|
8
14
|
tokenExpiration: number;
|
package/dist/constants.js
CHANGED
|
@@ -6,6 +6,22 @@ exports.DEFAULT_API_CONFIG = {
|
|
|
6
6
|
defaultPaginationLimit: 10,
|
|
7
7
|
server: {
|
|
8
8
|
port: 3000,
|
|
9
|
+
cors: {
|
|
10
|
+
allowOrigin: ['*'],
|
|
11
|
+
allowMethods: ['*'],
|
|
12
|
+
allowHeaders: [
|
|
13
|
+
'Accept',
|
|
14
|
+
'Accept-Version',
|
|
15
|
+
'Authorization',
|
|
16
|
+
'Content-Length',
|
|
17
|
+
'Content-MD5',
|
|
18
|
+
'Content-Type',
|
|
19
|
+
'Date',
|
|
20
|
+
'X-Api-Version',
|
|
21
|
+
'X-Stream-Request',
|
|
22
|
+
],
|
|
23
|
+
maxAge: '2592000',
|
|
24
|
+
},
|
|
9
25
|
},
|
|
10
26
|
security: {
|
|
11
27
|
tokenExpiration: 36000,
|
package/dist/constants.mjs
CHANGED
|
@@ -3,7 +3,23 @@ export const DEFAULT_API_CONFIG = {
|
|
|
3
3
|
baseUrl: "/",
|
|
4
4
|
defaultPaginationLimit: 10,
|
|
5
5
|
server: {
|
|
6
|
-
port: 3e3
|
|
6
|
+
port: 3e3,
|
|
7
|
+
cors: {
|
|
8
|
+
allowOrigin: ["*"],
|
|
9
|
+
allowMethods: ["*"],
|
|
10
|
+
allowHeaders: [
|
|
11
|
+
"Accept",
|
|
12
|
+
"Accept-Version",
|
|
13
|
+
"Authorization",
|
|
14
|
+
"Content-Length",
|
|
15
|
+
"Content-MD5",
|
|
16
|
+
"Content-Type",
|
|
17
|
+
"Date",
|
|
18
|
+
"X-Api-Version",
|
|
19
|
+
"X-Stream-Request"
|
|
20
|
+
],
|
|
21
|
+
maxAge: "2592000"
|
|
22
|
+
}
|
|
7
23
|
},
|
|
8
24
|
security: {
|
|
9
25
|
tokenExpiration: 36e3,
|
package/dist/init.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RouteContext, Collection, GenericRequest, ApiConfig, AuthenticatedToken, NonCircularJsonSchema } from '@aeriajs/types';
|
|
2
2
|
import { type createRouter } from '@aeriajs/http';
|
|
3
3
|
import { DEFAULT_API_CONFIG } from './constants.js';
|
|
4
|
-
type DeepPartial<T> = T extends
|
|
4
|
+
type DeepPartial<T> = T extends Record<string, unknown> ? {
|
|
5
5
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
6
6
|
} : T;
|
|
7
7
|
export type InitApiConfig = Omit<ApiConfig, keyof typeof DEFAULT_API_CONFIG> & DeepPartial<Pick<ApiConfig, keyof typeof DEFAULT_API_CONFIG>>;
|
package/dist/init.js
CHANGED
|
@@ -67,26 +67,28 @@ const init = (_options = {}) => {
|
|
|
67
67
|
const options = Object.assign({
|
|
68
68
|
config: {},
|
|
69
69
|
}, _options);
|
|
70
|
-
Object.assign(options.config, (0, common_1.deepMerge)(constants_js_1.DEFAULT_API_CONFIG, options.config));
|
|
70
|
+
const config = Object.assign(options.config, (0, common_1.deepMerge)(constants_js_1.DEFAULT_API_CONFIG, options.config));
|
|
71
71
|
return {
|
|
72
72
|
options,
|
|
73
73
|
listen: async () => {
|
|
74
|
-
if (!
|
|
74
|
+
if (!config.server) {
|
|
75
75
|
throw new Error;
|
|
76
76
|
}
|
|
77
77
|
const parentContext = await (0, core_1.createContext)({
|
|
78
|
-
config
|
|
78
|
+
config,
|
|
79
79
|
});
|
|
80
80
|
if (options.setup) {
|
|
81
81
|
await options.setup(parentContext);
|
|
82
82
|
}
|
|
83
|
-
if (!
|
|
83
|
+
if (!config.server.noWarmup) {
|
|
84
84
|
await (0, warmup_js_1.warmup)();
|
|
85
85
|
}
|
|
86
86
|
const apiRouter = (0, routes_js_1.registerRoutes)();
|
|
87
|
-
const server = (0, node_http_1.registerServer)(
|
|
88
|
-
if (
|
|
89
|
-
|
|
87
|
+
const server = (0, node_http_1.registerServer)(config.server, async (request, response) => {
|
|
88
|
+
if (config.server && config.server.cors) {
|
|
89
|
+
if ((0, http_1.cors)(request, response, config.server.cors) === null) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
90
92
|
}
|
|
91
93
|
await (0, http_1.wrapRouteExecution)(response, async () => {
|
|
92
94
|
const { error, result: token } = await (0, exports.getToken)(request, parentContext);
|
|
@@ -114,7 +116,7 @@ const init = (_options = {}) => {
|
|
|
114
116
|
return apiRouter.handle(request, response, context);
|
|
115
117
|
});
|
|
116
118
|
});
|
|
117
|
-
if (!
|
|
119
|
+
if (!config.database?.noDatabase) {
|
|
118
120
|
await (0, core_1.getDatabase)();
|
|
119
121
|
}
|
|
120
122
|
server.listen();
|
package/dist/init.mjs
CHANGED
|
@@ -61,26 +61,28 @@ export const init = (_options = {}) => {
|
|
|
61
61
|
const options = Object.assign({
|
|
62
62
|
config: {}
|
|
63
63
|
}, _options);
|
|
64
|
-
Object.assign(options.config, deepMerge(DEFAULT_API_CONFIG, options.config));
|
|
64
|
+
const config = Object.assign(options.config, deepMerge(DEFAULT_API_CONFIG, options.config));
|
|
65
65
|
return {
|
|
66
66
|
options,
|
|
67
67
|
listen: async () => {
|
|
68
|
-
if (!
|
|
68
|
+
if (!config.server) {
|
|
69
69
|
throw new Error();
|
|
70
70
|
}
|
|
71
71
|
const parentContext = await createContext({
|
|
72
|
-
config
|
|
72
|
+
config
|
|
73
73
|
});
|
|
74
74
|
if (options.setup) {
|
|
75
75
|
await options.setup(parentContext);
|
|
76
76
|
}
|
|
77
|
-
if (!
|
|
77
|
+
if (!config.server.noWarmup) {
|
|
78
78
|
await warmup();
|
|
79
79
|
}
|
|
80
80
|
const apiRouter = registerRoutes();
|
|
81
|
-
const server = registerServer(
|
|
82
|
-
if (
|
|
83
|
-
|
|
81
|
+
const server = registerServer(config.server, async (request, response) => {
|
|
82
|
+
if (config.server && config.server.cors) {
|
|
83
|
+
if (cors(request, response, config.server.cors) === null) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
84
86
|
}
|
|
85
87
|
await wrapRouteExecution(response, async () => {
|
|
86
88
|
const { error, result: token } = await getToken(request, parentContext);
|
|
@@ -108,7 +110,7 @@ export const init = (_options = {}) => {
|
|
|
108
110
|
return apiRouter.handle(request, response, context);
|
|
109
111
|
});
|
|
110
112
|
});
|
|
111
|
-
if (!
|
|
113
|
+
if (!config.database?.noDatabase) {
|
|
112
114
|
await getDatabase();
|
|
113
115
|
}
|
|
114
116
|
server.listen();
|
package/dist/routes.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ export declare const registerRoutes: () => import("@aeriajs/http").ProxiedRouter
|
|
|
6
6
|
request: Omit<import("@aeriajs/types").GenericRequest, "payload" | "query"> & {
|
|
7
7
|
payload: TContractWithRoles extends {
|
|
8
8
|
payload: infer Payload;
|
|
9
|
-
} ? import("@aeriajs/types").PackReferences<import("@aeriajs/types").InferProperties<Payload>> : Record<string, unknown>;
|
|
9
|
+
} ? import("@aeriajs/types").PackReferences<import("@aeriajs/types").InferProperties<Payload, {}>> : Record<string, unknown>;
|
|
10
10
|
query: TContractWithRoles extends {
|
|
11
11
|
query: infer Query;
|
|
12
|
-
} ? import("@aeriajs/types").PackReferences<import("@aeriajs/types").InferProperties<Query>> : Record<string, unknown>;
|
|
12
|
+
} ? import("@aeriajs/types").PackReferences<import("@aeriajs/types").InferProperties<Query, {}>> : Record<string, unknown>;
|
|
13
13
|
};
|
|
14
14
|
}) => Response : never>(method: import("@aeriajs/types").RequestMethod | import("@aeriajs/types").RequestMethod[], exp: import("@aeriajs/types").RouteUri, cb: TCallback, contract?: TContractWithRoles) => void;
|
|
15
15
|
routes: ((_: unknown, context: RouteContext, groupOptions?: import("@aeriajs/http").RouteGroupOptions) => unknown)[];
|
package/dist/warmup.js
CHANGED
|
@@ -10,7 +10,7 @@ const colorizedRoute = async (method, endpointUri, endpoint) => {
|
|
|
10
10
|
const color = method in types_1.METHOD_COLORS
|
|
11
11
|
? types_1.METHOD_COLORS[method]
|
|
12
12
|
: 'white';
|
|
13
|
-
let rolesLine = '', hasContractLine = (0, node_util_1.styleText)('yellow', 'x');
|
|
13
|
+
let rolesLine = '', hasContractLine = (0, node_util_1.styleText)(['yellow'], 'x');
|
|
14
14
|
if (endpoint) {
|
|
15
15
|
if ('roles' in endpoint) {
|
|
16
16
|
const roles = await (async () => {
|
|
@@ -25,10 +25,10 @@ const colorizedRoute = async (method, endpointUri, endpoint) => {
|
|
|
25
25
|
}
|
|
26
26
|
return endpoint.roles;
|
|
27
27
|
})();
|
|
28
|
-
rolesLine = ` ${(0, node_util_1.styleText)('grey', `[${roles.join('|')}]`)}`;
|
|
28
|
+
rolesLine = ` ${(0, node_util_1.styleText)(['grey'], `[${roles.join('|')}]`)}`;
|
|
29
29
|
}
|
|
30
30
|
if ('response' in endpoint || endpoint.builtin) {
|
|
31
|
-
hasContractLine = (0, node_util_1.styleText)('green', '✓');
|
|
31
|
+
hasContractLine = (0, node_util_1.styleText)(['green'], '✓');
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
let line = (0, node_util_1.styleText)([
|
|
@@ -36,10 +36,10 @@ const colorizedRoute = async (method, endpointUri, endpoint) => {
|
|
|
36
36
|
color,
|
|
37
37
|
], method) + '\t';
|
|
38
38
|
line += hasContractLine;
|
|
39
|
-
line += (0, node_util_1.styleText)('grey', ` ${config.baseUrl === '/'
|
|
39
|
+
line += (0, node_util_1.styleText)(['grey'], ` ${config.baseUrl === '/'
|
|
40
40
|
? ''
|
|
41
41
|
: config.baseUrl}`);
|
|
42
|
-
line += (0, node_util_1.styleText)('bold', endpointUri);
|
|
42
|
+
line += (0, node_util_1.styleText)(['bold'], endpointUri);
|
|
43
43
|
line += rolesLine;
|
|
44
44
|
return line;
|
|
45
45
|
};
|
package/dist/warmup.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { styleText } from "node:util";
|
|
|
6
6
|
const colorizedRoute = async (method, endpointUri, endpoint) => {
|
|
7
7
|
const config = await getConfig();
|
|
8
8
|
const color = method in METHOD_COLORS ? METHOD_COLORS[method] : "white";
|
|
9
|
-
let rolesLine = "", hasContractLine = styleText("yellow", "x");
|
|
9
|
+
let rolesLine = "", hasContractLine = styleText(["yellow"], "x");
|
|
10
10
|
if (endpoint) {
|
|
11
11
|
if ("roles" in endpoint) {
|
|
12
12
|
const roles = await (async () => {
|
|
@@ -24,10 +24,10 @@ const colorizedRoute = async (method, endpointUri, endpoint) => {
|
|
|
24
24
|
}
|
|
25
25
|
return endpoint.roles;
|
|
26
26
|
})();
|
|
27
|
-
rolesLine = ` ${styleText("grey", `[${roles.join("|")}]`)}`;
|
|
27
|
+
rolesLine = ` ${styleText(["grey"], `[${roles.join("|")}]`)}`;
|
|
28
28
|
}
|
|
29
29
|
if ("response" in endpoint || endpoint.builtin) {
|
|
30
|
-
hasContractLine = styleText("green", "\u2713");
|
|
30
|
+
hasContractLine = styleText(["green"], "\u2713");
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
let line = styleText([
|
|
@@ -35,8 +35,8 @@ const colorizedRoute = async (method, endpointUri, endpoint) => {
|
|
|
35
35
|
color
|
|
36
36
|
], method) + " ";
|
|
37
37
|
line += hasContractLine;
|
|
38
|
-
line += styleText("grey", ` ${config.baseUrl === "/" ? "" : config.baseUrl}`);
|
|
39
|
-
line += styleText("bold", endpointUri);
|
|
38
|
+
line += styleText(["grey"], ` ${config.baseUrl === "/" ? "" : config.baseUrl}`);
|
|
39
|
+
line += styleText(["bold"], endpointUri);
|
|
40
40
|
line += rolesLine;
|
|
41
41
|
return line;
|
|
42
42
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.275",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"mongodb": "^6.17.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@aeriajs/core": "^0.0.
|
|
37
|
-
"@aeriajs/builtins": "^0.0.
|
|
38
|
-
"@aeriajs/common": "^0.0.
|
|
39
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
40
|
-
"@aeriajs/http": "^0.0.
|
|
41
|
-
"@aeriajs/node-http": "^0.0.
|
|
42
|
-
"@aeriajs/server": "^0.0.
|
|
43
|
-
"@aeriajs/types": "^0.0.
|
|
36
|
+
"@aeriajs/core": "^0.0.273",
|
|
37
|
+
"@aeriajs/builtins": "^0.0.273",
|
|
38
|
+
"@aeriajs/common": "^0.0.155",
|
|
39
|
+
"@aeriajs/entrypoint": "^0.0.161",
|
|
40
|
+
"@aeriajs/http": "^0.0.189",
|
|
41
|
+
"@aeriajs/node-http": "^0.0.189",
|
|
42
|
+
"@aeriajs/server": "^0.0.275",
|
|
43
|
+
"@aeriajs/types": "^0.0.133",
|
|
44
44
|
"mongodb": "^6.17.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|