alp-node 6.2.0 → 8.0.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/CHANGELOG.md +38 -0
- package/README.md +7 -7
- package/dist/AlpNodeApp-node20.mjs +367 -0
- package/dist/AlpNodeApp-node20.mjs.map +1 -0
- package/dist/definitions/AlpNodeApp.d.ts +21 -14
- package/dist/definitions/AlpNodeApp.d.ts.map +1 -1
- package/dist/definitions/config.d.ts +17 -0
- package/dist/definitions/config.d.ts.map +1 -0
- package/dist/definitions/errors.d.ts +3 -0
- package/dist/definitions/errors.d.ts.map +1 -0
- package/dist/definitions/index.d.ts +9 -7
- package/dist/definitions/index.d.ts.map +1 -1
- package/dist/definitions/language.d.ts +7 -0
- package/dist/definitions/language.d.ts.map +1 -0
- package/dist/definitions/listen.d.ts +6 -0
- package/dist/definitions/listen.d.ts.map +1 -0
- package/dist/definitions/params/ParamValid.d.ts +8 -0
- package/dist/definitions/params/ParamValid.d.ts.map +1 -0
- package/dist/definitions/params/ParamValidationResult.d.ts +9 -0
- package/dist/definitions/params/ParamValidationResult.d.ts.map +1 -0
- package/dist/definitions/params/ParamValidationResult.test.d.ts +2 -0
- package/dist/definitions/params/ParamValidationResult.test.d.ts.map +1 -0
- package/dist/definitions/params/ParamValueFromContext.d.ts +12 -0
- package/dist/definitions/params/ParamValueFromContext.d.ts.map +1 -0
- package/dist/definitions/params/ParamValueModelValidator.d.ts +4 -0
- package/dist/definitions/params/ParamValueModelValidator.d.ts.map +1 -0
- package/dist/definitions/params/ParamValueStringValidator.d.ts +5 -0
- package/dist/definitions/params/ParamValueStringValidator.d.ts.map +1 -0
- package/dist/definitions/params/ParamValueValidator.d.ts +10 -0
- package/dist/definitions/params/ParamValueValidator.d.ts.map +1 -0
- package/dist/definitions/params/index.d.ts +19 -0
- package/dist/definitions/params/index.d.ts.map +1 -0
- package/dist/definitions/router.d.ts +13 -0
- package/dist/definitions/router.d.ts.map +1 -0
- package/dist/definitions/translate/index.d.ts +11 -0
- package/dist/definitions/translate/index.d.ts.map +1 -0
- package/dist/definitions/translate/load.d.ts +4 -0
- package/dist/definitions/translate/load.d.ts.map +1 -0
- package/dist/definitions/types.d.ts +53 -0
- package/dist/definitions/types.d.ts.map +1 -0
- package/dist/index-node20.mjs +495 -0
- package/dist/index-node20.mjs.map +1 -0
- package/package.json +27 -28
- package/src/AlpNodeApp.ts +71 -50
- package/src/config.ts +116 -0
- package/src/errors.ts +70 -0
- package/src/index.ts +33 -18
- package/src/language.ts +35 -0
- package/src/listen.ts +68 -0
- package/src/params/ParamValid.ts +15 -0
- package/src/params/ParamValidationResult.test.ts +65 -0
- package/src/params/ParamValidationResult.ts +38 -0
- package/src/params/ParamValueFromContext.ts +42 -0
- package/src/params/ParamValueModelValidator.ts +36 -0
- package/src/params/ParamValueStringValidator.ts +13 -0
- package/src/params/ParamValueValidator.ts +23 -0
- package/src/params/index.ts +70 -0
- package/src/router.ts +64 -0
- package/src/translate/index.ts +45 -0
- package/src/translate/load.ts +31 -0
- package/src/types.ts +67 -0
- package/dist/AlpNodeApp-node18.mjs +0 -94
- package/dist/AlpNodeApp-node18.mjs.map +0 -1
- package/dist/index-node18.mjs +0 -124
- package/dist/index-node18.mjs.map +0 -1
- package/src/.eslintrc.json +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,44 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [8.0.0](https://github.com/christophehurpeau/alp/compare/alp-node@7.0.0...alp-node@8.0.0) (2025-08-02)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* update dependencies and drop node 20
|
|
11
|
+
* update dev dependencies, replace parse-json-object-as-map with native JSON.parse, update koa
|
|
12
|
+
* remove deprecated packageDirname
|
|
13
|
+
* namedRouteParam and otherRouteParam
|
|
14
|
+
* update koa
|
|
15
|
+
* update router-segments
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* remove deprecated packageDirname ([82f6f16](https://github.com/christophehurpeau/alp/commit/82f6f163d40bdfe40df181a1d009072cd1eb3c82))
|
|
20
|
+
* update dependencies and drop node 20 ([fc5b322](https://github.com/christophehurpeau/alp/commit/fc5b322e076e9a3c7c4a235d16734b89fd85e211))
|
|
21
|
+
* update dev dependencies, replace parse-json-object-as-map with native JSON.parse, update koa ([5ae7723](https://github.com/christophehurpeau/alp/commit/5ae77238cafc573fe72c5eb63b103802b8b2e537))
|
|
22
|
+
* update koa ([e678114](https://github.com/christophehurpeau/alp/commit/e67811429d951287de715c3dffdbee7b798f3358))
|
|
23
|
+
* update router-segments ([07ff52b](https://github.com/christophehurpeau/alp/commit/07ff52b3f851204256509056d0a4b25e1f630e5b))
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* namedRouteParam and otherRouteParam ([73e9e2a](https://github.com/christophehurpeau/alp/commit/73e9e2aaf00fe956628efd1380f8e44329562c41))
|
|
28
|
+
* properly call callback ([89cedd4](https://github.com/christophehurpeau/alp/commit/89cedd44a2edb99e9fcc050172f9ac75e1747e20))
|
|
29
|
+
|
|
30
|
+
## [7.0.0](https://github.com/christophehurpeau/alp/compare/alp-node@6.2.0...alp-node@7.0.0) (2024-01-06)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### ⚠ BREAKING CHANGES
|
|
34
|
+
|
|
35
|
+
* merge to alp-node to improve maintenability, remove alp-types
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
* merge to alp-node to improve maintenability, remove alp-types ([ead9a2f](https://github.com/christophehurpeau/alp/commit/ead9a2fd1bcbedce0be29ea0e444c5cead99c64d))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
6
44
|
## [6.2.0](https://github.com/christophehurpeau/alp/compare/alp-node@6.1.1...alp-node@6.2.0) (2024-01-06)
|
|
7
45
|
|
|
8
46
|
Note: no notable changes
|
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<
|
|
1
|
+
<h1 align="center">
|
|
2
2
|
alp-node
|
|
3
|
-
</
|
|
3
|
+
</h1>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
framework based on koa 2
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
<a href="https://npmjs.org/package/alp-node"><img src="https://img.shields.io/npm/v/alp-node.svg?style=flat-square"></a>
|
|
11
|
-
<a href="https://npmjs.org/package/alp-node"><img src="https://img.shields.io/npm/dw/alp-node.svg?style=flat-square"></a>
|
|
12
|
-
<a href="https://npmjs.org/package/alp-node"><img src="https://img.shields.io/node/v/alp-node.svg?style=flat-square"></a>
|
|
13
|
-
<a href="https://npmjs.org/package/alp-node"><img src="https://img.shields.io/npm/types/alp-node.svg?style=flat-square"></a>
|
|
10
|
+
<a href="https://npmjs.org/package/alp-node"><img src="https://img.shields.io/npm/v/alp-node.svg?style=flat-square" alt="npm version"></a>
|
|
11
|
+
<a href="https://npmjs.org/package/alp-node"><img src="https://img.shields.io/npm/dw/alp-node.svg?style=flat-square" alt="npm downloads"></a>
|
|
12
|
+
<a href="https://npmjs.org/package/alp-node"><img src="https://img.shields.io/node/v/alp-node.svg?style=flat-square" alt="node version"></a>
|
|
13
|
+
<a href="https://npmjs.org/package/alp-node"><img src="https://img.shields.io/npm/types/alp-node.svg?style=flat-square" alt="types"></a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
16
|
## Install
|
|
@@ -22,7 +22,7 @@ npm install --save alp-node
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
-
import Alp from
|
|
25
|
+
import Alp from "alp-node";
|
|
26
26
|
|
|
27
27
|
const app = new Alp();
|
|
28
28
|
app.servePublic();
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import Koa from 'koa';
|
|
3
|
+
import compress from 'koa-compress';
|
|
4
|
+
import serve from 'koa-static';
|
|
5
|
+
import { Logger } from 'nightingale-logger';
|
|
6
|
+
import { STATUS_CODES, createServer as createServer$2 } from 'node:http';
|
|
7
|
+
import ErrorHtmlRenderer from 'error-html';
|
|
8
|
+
import { defineLazyProperty } from 'object-properties';
|
|
9
|
+
import { unlinkSync, chmodSync, readFileSync } from 'node:fs';
|
|
10
|
+
import { createServer as createServer$1 } from 'node:https';
|
|
11
|
+
import IntlMessageFormatDefault from 'intl-messageformat';
|
|
12
|
+
|
|
13
|
+
const logger$3 = new Logger("alp:errors");
|
|
14
|
+
const errorHtmlRenderer = new ErrorHtmlRenderer({
|
|
15
|
+
appPath: `${process.cwd()}/`
|
|
16
|
+
});
|
|
17
|
+
async function alpNodeErrors(ctx, next) {
|
|
18
|
+
try {
|
|
19
|
+
await next();
|
|
20
|
+
} catch (error) {
|
|
21
|
+
// eslint-disable-next-line no-ex-assign
|
|
22
|
+
if (!error) error = new Error("Unknown error");
|
|
23
|
+
// eslint-disable-next-line no-ex-assign
|
|
24
|
+
if (typeof error === "string") error = new Error(error);
|
|
25
|
+
ctx.status = error.status || 500;
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
27
|
+
logger$3.error(error);
|
|
28
|
+
switch (ctx.request.accepts("html", "text", "json")) {
|
|
29
|
+
case "json":
|
|
30
|
+
ctx.type = "application/json";
|
|
31
|
+
if (process.env.NODE_ENV !== "production" || error.expose) {
|
|
32
|
+
ctx.body = {
|
|
33
|
+
error: error.message
|
|
34
|
+
};
|
|
35
|
+
} else {
|
|
36
|
+
ctx.body = {
|
|
37
|
+
error: STATUS_CODES[ctx.status]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case "html":
|
|
42
|
+
ctx.type = "text/html";
|
|
43
|
+
if (process.env.NODE_ENV !== "production") {
|
|
44
|
+
ctx.body = errorHtmlRenderer.render(error);
|
|
45
|
+
} else if (error.expose) {
|
|
46
|
+
ctx.body = error.message;
|
|
47
|
+
} else {
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case "text":
|
|
52
|
+
case false:
|
|
53
|
+
default:
|
|
54
|
+
ctx.type = "text/plain";
|
|
55
|
+
if (process.env.NODE_ENV !== "production" || error.expose) {
|
|
56
|
+
ctx.body = error.message;
|
|
57
|
+
} else {
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function alpLanguage(app) {
|
|
66
|
+
const config = app.context.config;
|
|
67
|
+
const availableLanguages = config.get("availableLanguages");
|
|
68
|
+
if (!availableLanguages) {
|
|
69
|
+
throw new Error('Missing config "availableLanguages"');
|
|
70
|
+
}
|
|
71
|
+
defineLazyProperty(app.context, "language", function language() {
|
|
72
|
+
return this.acceptsLanguages(availableLanguages) || availableLanguages[0] || "en";
|
|
73
|
+
});
|
|
74
|
+
defineLazyProperty(app.context, "firstAcceptedLanguage", function firstAcceptedLanguage() {
|
|
75
|
+
return this.acceptsLanguages()[0] || availableLanguages[0] || "en";
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const logger$2 = new Logger("alp:listen");
|
|
80
|
+
const createServer = (callback, socketPath, tls, dirname = ""
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
82
|
+
) => {
|
|
83
|
+
const createHttpServer = !socketPath && tls ? createServer$1 : createServer$2;
|
|
84
|
+
if (!tls) {
|
|
85
|
+
return createHttpServer(callback);
|
|
86
|
+
}
|
|
87
|
+
const options = {
|
|
88
|
+
key: readFileSync(`${dirname}/server.key`),
|
|
89
|
+
cert: readFileSync(`${dirname}/server.crt`)
|
|
90
|
+
};
|
|
91
|
+
return createHttpServer(options, callback);
|
|
92
|
+
};
|
|
93
|
+
function alpListen(config, callback, dirname) {
|
|
94
|
+
return new Promise(resolve => {
|
|
95
|
+
const socketPath = config.get("socketPath");
|
|
96
|
+
const port = config.get("port");
|
|
97
|
+
const hostname = config.get("hostname");
|
|
98
|
+
const tls = config.get("tls");
|
|
99
|
+
logger$2.info("Creating server", socketPath ? {
|
|
100
|
+
socketPath
|
|
101
|
+
} : {
|
|
102
|
+
port
|
|
103
|
+
});
|
|
104
|
+
const server = createServer(callback, socketPath, tls, dirname);
|
|
105
|
+
if (socketPath) {
|
|
106
|
+
try {
|
|
107
|
+
unlinkSync(socketPath);
|
|
108
|
+
} catch {}
|
|
109
|
+
server.listen(socketPath, () => {
|
|
110
|
+
if (socketPath) {
|
|
111
|
+
chmodSync(socketPath, "777");
|
|
112
|
+
}
|
|
113
|
+
logger$2.info("Server listening", {
|
|
114
|
+
socketPath
|
|
115
|
+
});
|
|
116
|
+
resolve(server);
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
server.listen(port, hostname, () => {
|
|
120
|
+
logger$2.info("Server listening", {
|
|
121
|
+
port
|
|
122
|
+
});
|
|
123
|
+
resolve(server);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
class ParamValidationResult {
|
|
130
|
+
_error(name, key, value) {
|
|
131
|
+
if (!this._errors) {
|
|
132
|
+
this._errors = {};
|
|
133
|
+
}
|
|
134
|
+
this._errors[name] = {
|
|
135
|
+
error: key,
|
|
136
|
+
value
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
getErrors() {
|
|
140
|
+
return this._errors;
|
|
141
|
+
}
|
|
142
|
+
hasErrors() {
|
|
143
|
+
return this._errors !== undefined;
|
|
144
|
+
}
|
|
145
|
+
isValid() {
|
|
146
|
+
return this._errors === undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// string(name: string): ParamValueStringValidator {
|
|
150
|
+
// return new ParamValueStringValidator(this, name, this.context.param(name));
|
|
151
|
+
// }
|
|
152
|
+
/* int(name, position) {
|
|
153
|
+
return new ParamValueIntValidator(this, name, this.context.param(name, position));
|
|
154
|
+
}
|
|
155
|
+
model(modelName, name) {
|
|
156
|
+
name = name || S.string.lcFirst(modelName);
|
|
157
|
+
console.log('paramvalidator model', modelName, M[modelName]);
|
|
158
|
+
let data = this.context.getOrPostParam(name);
|
|
159
|
+
return new ParamValueModelValidator(this, name, !data ? null : new M[modelName](data));
|
|
160
|
+
} */
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
class ParamValid extends ParamValidationResult {
|
|
164
|
+
constructor(context) {
|
|
165
|
+
super();
|
|
166
|
+
this.context = context;
|
|
167
|
+
}
|
|
168
|
+
_error() {
|
|
169
|
+
this.context.throw(400, "Invalid params", {
|
|
170
|
+
validator: this
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
class ParamValueValidator {
|
|
176
|
+
constructor(validationResult, name, value) {
|
|
177
|
+
this.validationResult = validationResult;
|
|
178
|
+
this.name = name;
|
|
179
|
+
this.value = value;
|
|
180
|
+
}
|
|
181
|
+
isValid() {
|
|
182
|
+
return this.validationResult.isValid();
|
|
183
|
+
}
|
|
184
|
+
_error(key) {
|
|
185
|
+
this.validationResult._error(this.name, key, this.value);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
class ParamValueStringValidator extends ParamValueValidator {
|
|
190
|
+
notEmpty() {
|
|
191
|
+
if (this.value == null || this.value.trim() === "") {
|
|
192
|
+
this._error("notEmpty");
|
|
193
|
+
}
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
class ParamValueFromContext {
|
|
199
|
+
constructor(context, validationResult) {
|
|
200
|
+
this.validationResult = validationResult;
|
|
201
|
+
this.context = context;
|
|
202
|
+
}
|
|
203
|
+
namedParam(name) {
|
|
204
|
+
return new ParamValueStringValidator(this.validationResult, name, this.context.namedRouteParam(name));
|
|
205
|
+
}
|
|
206
|
+
otherParam(position) {
|
|
207
|
+
return new ParamValueStringValidator(this.validationResult, String(position), this.context.otherRouteParam(position));
|
|
208
|
+
}
|
|
209
|
+
queryParam(name) {
|
|
210
|
+
return new ParamValueStringValidator(this.validationResult, name, this.context.queryParam(name));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// bodyParam: <T>(name: string): ParamValueValidator<string | undefined> {
|
|
214
|
+
|
|
215
|
+
// }
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function alpParams(app) {
|
|
219
|
+
Object.assign(app.context, {
|
|
220
|
+
namedRouteParam(name) {
|
|
221
|
+
const namedParams = this.route.namedParams;
|
|
222
|
+
return namedParams?.get(name);
|
|
223
|
+
},
|
|
224
|
+
otherRouteParam(position) {
|
|
225
|
+
const otherParams = this.route.otherParams;
|
|
226
|
+
return otherParams?.[position - 1];
|
|
227
|
+
},
|
|
228
|
+
queryParam(name) {
|
|
229
|
+
const searchParams = this.request.searchParams;
|
|
230
|
+
return searchParams.get(name) ?? undefined;
|
|
231
|
+
},
|
|
232
|
+
bodyParam(name) {
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
|
|
234
|
+
return this.body[name];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
defineLazyProperty(app.request, "searchParams", function searchParams() {
|
|
238
|
+
return new URLSearchParams(this.search);
|
|
239
|
+
});
|
|
240
|
+
defineLazyProperty(app.context, "params", function params() {
|
|
241
|
+
return new ParamValueFromContext(this, new ParamValidationResult());
|
|
242
|
+
});
|
|
243
|
+
defineLazyProperty(app.context, "validParams", function validParams() {
|
|
244
|
+
return new ParamValueFromContext(this, new ParamValid(this));
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
249
|
+
const IntlMessageFormat =
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
251
|
+
IntlMessageFormatDefault.default || IntlMessageFormatDefault;
|
|
252
|
+
function load(translations, language) {
|
|
253
|
+
const result = {};
|
|
254
|
+
(function loadMap(record, prefix) {
|
|
255
|
+
Object.entries(record).forEach(([key, value]) => {
|
|
256
|
+
if (typeof value === "object" && value !== null) {
|
|
257
|
+
loadMap(value, `${prefix}${key}.`);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
result[`${prefix}${key}`] = new IntlMessageFormat(value, language);
|
|
261
|
+
});
|
|
262
|
+
})(translations, "");
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const logger$1 = new Logger("alp:translate");
|
|
267
|
+
function alpTranslate(dirname) {
|
|
268
|
+
dirname = dirname.replace(/\/*$/, "/");
|
|
269
|
+
return app => {
|
|
270
|
+
const appTranslations = new Map();
|
|
271
|
+
Object.assign(app.context, {
|
|
272
|
+
t(id, args) {
|
|
273
|
+
const msg = appTranslations.get(this.language)?.[id];
|
|
274
|
+
if (!msg) {
|
|
275
|
+
logger$1.warn("invalid msg", {
|
|
276
|
+
language: this.language,
|
|
277
|
+
id
|
|
278
|
+
});
|
|
279
|
+
return id;
|
|
280
|
+
}
|
|
281
|
+
return msg.format(args);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
const config = app.config;
|
|
285
|
+
config.get("availableLanguages").forEach(language => {
|
|
286
|
+
const translations = app.loadConfigSync(dirname + language);
|
|
287
|
+
appTranslations.set(language, load(translations, language));
|
|
288
|
+
});
|
|
289
|
+
return appTranslations;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const logger = new Logger("alp");
|
|
294
|
+
class AlpNodeApp extends Koa {
|
|
295
|
+
/**
|
|
296
|
+
* @param {Object} [options]
|
|
297
|
+
* @param {string} [options.certPath] directory of the ssl certificates
|
|
298
|
+
* @param {string} [options.publicPath] directory of public files
|
|
299
|
+
*/
|
|
300
|
+
constructor({
|
|
301
|
+
appDirname,
|
|
302
|
+
packageDirname,
|
|
303
|
+
config,
|
|
304
|
+
certPath,
|
|
305
|
+
publicPath
|
|
306
|
+
}) {
|
|
307
|
+
super();
|
|
308
|
+
this.dirname = path.normalize(appDirname);
|
|
309
|
+
this.certPath = certPath || `${packageDirname}/config/cert`;
|
|
310
|
+
this.publicPath = publicPath || `${packageDirname}/public/`;
|
|
311
|
+
this.config = config;
|
|
312
|
+
this.context.config = this.config;
|
|
313
|
+
alpParams(this);
|
|
314
|
+
alpLanguage(this);
|
|
315
|
+
alpTranslate("locales")(this);
|
|
316
|
+
this.use(compress());
|
|
317
|
+
}
|
|
318
|
+
existsConfigSync(name) {
|
|
319
|
+
return this.config.existsConfigSync(name);
|
|
320
|
+
}
|
|
321
|
+
loadConfigSync(name) {
|
|
322
|
+
return this.config.loadConfigSync(name);
|
|
323
|
+
}
|
|
324
|
+
createContext(req, res) {
|
|
325
|
+
const ctx = super.createContext(req, res);
|
|
326
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
327
|
+
ctx.sanitizedState = {};
|
|
328
|
+
return ctx;
|
|
329
|
+
}
|
|
330
|
+
servePublic() {
|
|
331
|
+
this.use(serve(this.publicPath)); // static files
|
|
332
|
+
}
|
|
333
|
+
catchErrors() {
|
|
334
|
+
this.use(alpNodeErrors);
|
|
335
|
+
}
|
|
336
|
+
listen() {
|
|
337
|
+
throw new Error("Use start instead");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Close server and emit close event
|
|
342
|
+
*/
|
|
343
|
+
close() {
|
|
344
|
+
if (this._server) {
|
|
345
|
+
this._server.close();
|
|
346
|
+
this.emit("close");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async start(fn) {
|
|
350
|
+
await fn();
|
|
351
|
+
try {
|
|
352
|
+
const server = await alpListen(this.config, this.callback(), this.certPath);
|
|
353
|
+
this._server = server;
|
|
354
|
+
logger.success("started");
|
|
355
|
+
if (process.send) process.send("ready");
|
|
356
|
+
return server;
|
|
357
|
+
} catch (error) {
|
|
358
|
+
logger.error("start fail", {
|
|
359
|
+
err: error
|
|
360
|
+
});
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export { AlpNodeApp };
|
|
367
|
+
//# sourceMappingURL=AlpNodeApp-node20.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlpNodeApp-node20.mjs","sources":["../src/errors.ts","../src/language.ts","../src/listen.ts","../src/params/ParamValidationResult.ts","../src/params/ParamValid.ts","../src/params/ParamValueValidator.ts","../src/params/ParamValueStringValidator.ts","../src/params/ParamValueFromContext.ts","../src/params/index.ts","../src/translate/load.ts","../src/translate/index.ts","../src/AlpNodeApp.ts"],"sourcesContent":["import { STATUS_CODES } from \"node:http\";\nimport ErrorHtmlRenderer from \"error-html\";\nimport { Logger } from \"nightingale-logger\";\nimport type { Context } from \"./AlpNodeApp\";\nimport type { HtmlError } from \"./types\";\n\nconst logger = new Logger(\"alp:errors\");\nconst errorHtmlRenderer = new ErrorHtmlRenderer({\n appPath: `${process.cwd()}/`,\n});\n\nexport default async function alpNodeErrors(\n ctx: Context,\n next: () => Promise<void> | void,\n): Promise<void> {\n try {\n await next();\n } catch (error: unknown) {\n // eslint-disable-next-line no-ex-assign\n if (!error) error = new Error(\"Unknown error\");\n // eslint-disable-next-line no-ex-assign\n if (typeof error === \"string\") error = new Error(error);\n\n ctx.status = (error as HtmlError).status || 500;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n logger.error(error as any);\n\n switch (ctx.request.accepts(\"html\", \"text\", \"json\")) {\n case \"json\":\n ctx.type = \"application/json\";\n if (\n process.env.NODE_ENV !== \"production\" ||\n (error as HtmlError).expose\n ) {\n ctx.body = { error: (error as Error).message };\n } else {\n ctx.body = { error: STATUS_CODES[ctx.status] };\n }\n\n break;\n\n case \"html\":\n ctx.type = \"text/html\";\n if (process.env.NODE_ENV !== \"production\") {\n ctx.body = errorHtmlRenderer.render(error as Error);\n } else if ((error as HtmlError).expose) {\n ctx.body = (error as Error).message;\n } else {\n throw error;\n }\n\n break;\n\n case \"text\":\n case false:\n default:\n ctx.type = \"text/plain\";\n if (\n process.env.NODE_ENV !== \"production\" ||\n (error as HtmlError).expose\n ) {\n ctx.body = (error as Error).message;\n } else {\n throw error;\n }\n\n break;\n }\n }\n}\n","import type { Context } from \"koa\";\nimport { defineLazyProperty } from \"object-properties\";\nimport type { AlpNodeApp } from \"./AlpNodeApp\";\n\nexport interface AlpLanguageContext {\n readonly firstAcceptedLanguage: string;\n readonly language: string;\n}\nexport default function alpLanguage(app: AlpNodeApp): void {\n const config = app.context.config;\n const availableLanguages: string[] = config.get(\"availableLanguages\");\n if (!availableLanguages) {\n throw new Error('Missing config \"availableLanguages\"');\n }\n\n defineLazyProperty(\n app.context,\n \"language\",\n function language(this: Context): string {\n return (\n this.acceptsLanguages(availableLanguages) ||\n availableLanguages[0] ||\n \"en\"\n );\n },\n );\n\n defineLazyProperty(\n app.context,\n \"firstAcceptedLanguage\",\n function firstAcceptedLanguage(this: Context): string {\n return this.acceptsLanguages()[0] || availableLanguages[0] || \"en\";\n },\n );\n}\n","import { chmodSync, readFileSync, unlinkSync } from \"node:fs\";\nimport { createServer as createServerHttp } from \"node:http\";\nimport type { IncomingMessage, Server, ServerResponse } from \"node:http\";\nimport { createServer as createServerHttps } from \"node:https\";\nimport { Logger } from \"nightingale-logger\";\nimport type { Config } from \"./config\";\n\nconst logger = new Logger(\"alp:listen\");\n\ntype RequestListener = (req: IncomingMessage, res: ServerResponse) => void;\n\nconst createServer = (\n callback: RequestListener,\n socketPath?: string,\n tls?: boolean,\n dirname = \"\",\n // eslint-disable-next-line @typescript-eslint/max-params\n): Server => {\n const createHttpServer =\n !socketPath && tls ? createServerHttps : createServerHttp;\n\n if (!tls) {\n return (createHttpServer as typeof createServerHttps)(callback);\n }\n\n const options = {\n key: readFileSync(`${dirname}/server.key`),\n cert: readFileSync(`${dirname}/server.crt`),\n };\n\n return (createHttpServer as typeof createServerHttps)(options, callback);\n};\n\nexport default function alpListen(\n config: Config,\n callback: RequestListener,\n dirname?: string,\n): Promise<Server> {\n return new Promise((resolve) => {\n const socketPath = config.get<string>(\"socketPath\");\n const port = config.get<number>(\"port\");\n const hostname = config.get<string>(\"hostname\");\n const tls = config.get<boolean>(\"tls\");\n\n logger.info(\"Creating server\", socketPath ? { socketPath } : { port });\n const server = createServer(callback, socketPath, tls, dirname);\n\n if (socketPath) {\n try {\n unlinkSync(socketPath);\n } catch {}\n\n server.listen(socketPath, () => {\n if (socketPath) {\n chmodSync(socketPath, \"777\");\n }\n\n logger.info(\"Server listening\", { socketPath });\n resolve(server);\n });\n } else {\n server.listen(port, hostname, () => {\n logger.info(\"Server listening\", { port });\n resolve(server);\n });\n }\n });\n}\n","export type Errors = Record<string, any>;\n\nexport class ParamValidationResult {\n _errors?: Errors;\n\n _error(name: string, key: string, value: unknown): void {\n if (!this._errors) {\n this._errors = {};\n }\n\n this._errors[name] = { error: key, value };\n }\n\n getErrors(): Errors | undefined {\n return this._errors;\n }\n\n hasErrors(): boolean {\n return this._errors !== undefined;\n }\n\n isValid(): boolean {\n return this._errors === undefined;\n }\n\n // string(name: string): ParamValueStringValidator {\n // return new ParamValueStringValidator(this, name, this.context.param(name));\n // }\n /* int(name, position) {\n return new ParamValueIntValidator(this, name, this.context.param(name, position));\n }\n model(modelName, name) {\n name = name || S.string.lcFirst(modelName);\n console.log('paramvalidator model', modelName, M[modelName]);\n let data = this.context.getOrPostParam(name);\n return new ParamValueModelValidator(this, name, !data ? null : new M[modelName](data));\n } */\n}\n","import type { Context } from \"../AlpNodeApp\";\nimport { ParamValidationResult } from \"./ParamValidationResult\";\n\nexport default class ParamValid extends ParamValidationResult {\n context: Context;\n\n constructor(context: Context) {\n super();\n this.context = context;\n }\n\n override _error(): void {\n this.context.throw(400, \"Invalid params\", { validator: this });\n }\n}\n","import type { ParamValidationResult } from \"./ParamValidationResult\";\n\nexport default class ParamValueValidator<T> {\n readonly validationResult: ParamValidationResult;\n\n readonly name: string;\n\n readonly value: T;\n\n constructor(validationResult: ParamValidationResult, name: string, value: T) {\n this.validationResult = validationResult;\n this.name = name;\n this.value = value;\n }\n\n isValid(): boolean {\n return this.validationResult.isValid();\n }\n\n _error(key: string): void {\n this.validationResult._error(this.name, key, this.value);\n }\n}\n","import ParamValueValidator from \"./ParamValueValidator\";\n\nexport default class ParamValueStringValidator<\n T extends string = string,\n> extends ParamValueValidator<T | null | undefined> {\n notEmpty(): ParamValueValidator<T> {\n if (this.value == null || this.value.trim() === \"\") {\n this._error(\"notEmpty\");\n }\n\n return this as ParamValueValidator<T>;\n }\n}\n","import type { Context } from \"../AlpNodeApp\";\nimport type { ParamValidationResult } from \"./ParamValidationResult\";\nimport ParamValueStringValidator from \"./ParamValueStringValidator\";\n\nexport class ParamValueFromContext {\n readonly validationResult: ParamValidationResult;\n\n readonly context: Context;\n\n constructor(context: Context, validationResult: ParamValidationResult) {\n this.validationResult = validationResult;\n this.context = context;\n }\n\n namedParam(name: string): ParamValueStringValidator {\n return new ParamValueStringValidator(\n this.validationResult,\n name,\n this.context.namedRouteParam(name),\n );\n }\n\n otherParam(position: number): ParamValueStringValidator {\n return new ParamValueStringValidator(\n this.validationResult,\n String(position),\n this.context.otherRouteParam(position),\n );\n }\n\n queryParam(name: string): ParamValueStringValidator {\n return new ParamValueStringValidator(\n this.validationResult,\n name,\n this.context.queryParam(name),\n );\n }\n\n // bodyParam: <T>(name: string): ParamValueValidator<string | undefined> {\n\n // }\n}\n","import { defineLazyProperty } from \"object-properties\";\nimport type { AlpNodeApp, Context } from \"../AlpNodeApp\";\nimport ParamValid from \"./ParamValid\";\nimport { ParamValidationResult } from \"./ParamValidationResult\";\nimport { ParamValueFromContext } from \"./ParamValueFromContext\";\n\nexport interface AlpParamsContext {\n params: ParamValueFromContext;\n validParams: ParamValueFromContext;\n namedRouteParam: (name: string) => string | undefined;\n otherRouteParam: (position: number) => string | undefined;\n /** @deprecated use namedRouteParam */\n namedParam: never;\n /** @deprecated use otherRouteParam */\n otherParam: never;\n queryParam: (name: string) => string | undefined;\n bodyParam: <T>(name: string) => T | undefined;\n}\n\nexport interface AlpParamsRequest {\n searchParams: URLSearchParams;\n}\n\nexport default function alpParams(app: AlpNodeApp): void {\n Object.assign(app.context, {\n namedRouteParam(this: Context, name: string): string | undefined {\n const namedParams = this.route.namedParams;\n return namedParams?.get(name);\n },\n\n otherRouteParam(this: Context, position: number): string | undefined {\n const otherParams = this.route.otherParams;\n return otherParams?.[position - 1];\n },\n\n queryParam(this: Context, name: string): string | undefined {\n const searchParams = this.request.searchParams;\n return searchParams.get(name) ?? undefined;\n },\n\n bodyParam<T>(this: Context, name: string): T | undefined {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access\n return (this.body as any)[name];\n },\n });\n\n defineLazyProperty(\n app.request,\n \"searchParams\",\n function searchParams(this: Context[\"request\"]): URLSearchParams {\n return new URLSearchParams(this.search);\n },\n );\n\n defineLazyProperty(\n app.context,\n \"params\",\n function params(this: Context): ParamValueFromContext {\n return new ParamValueFromContext(this, new ParamValidationResult());\n },\n );\n\n defineLazyProperty(\n app.context,\n \"validParams\",\n function validParams(this: Context): ParamValueFromContext {\n return new ParamValueFromContext(this, new ParamValid(this));\n },\n );\n}\n","import IntlMessageFormatDefault from \"intl-messageformat\";\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nconst IntlMessageFormat: typeof IntlMessageFormatDefault =\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n (IntlMessageFormatDefault as any).default || IntlMessageFormatDefault;\n\nexport type Translations = Readonly<Record<string, IntlMessageFormatDefault>>;\n\nexport default function load(\n translations: Readonly<Record<string, unknown>>,\n language: string,\n): Translations {\n const result: Record<string, IntlMessageFormatDefault> = {};\n\n (function loadMap(record: Record<string, unknown>, prefix: string) {\n Object.entries(record).forEach(([key, value]) => {\n if (typeof value === \"object\" && value !== null) {\n loadMap(value as Record<string, unknown>, `${prefix}${key}.`);\n return;\n }\n\n result[`${prefix}${key}`] = new IntlMessageFormat(\n value as string,\n language,\n );\n });\n })(translations, \"\");\n\n return result;\n}\n","import { Logger } from \"nightingale-logger\";\nimport type { AlpNodeApp, Context } from \"../AlpNodeApp\";\nimport type { Translations } from \"./load\";\nimport load from \"./load\";\n\nconst logger = new Logger(\"alp:translate\");\n\ntype Args = Record<string, any>;\n\nexport interface TranslateBaseContext {\n t: (id: string, args: Args) => string;\n}\nexport interface TranslateContext {\n readonly language: string;\n}\n\nexport default function alpTranslate(\n dirname: string,\n): (app: AlpNodeApp) => void {\n dirname = dirname.replace(/\\/*$/, \"/\");\n return (app: AlpNodeApp) => {\n const appTranslations = new Map<string, Translations>();\n\n Object.assign(app.context, {\n t(this: Context, id: string, args: Args): string {\n const msg = appTranslations.get(this.language)?.[id];\n if (!msg) {\n logger.warn(\"invalid msg\", { language: this.language, id });\n return id;\n }\n\n return msg.format(args) as string;\n },\n });\n\n const config = app.config;\n\n config.get<string[]>(\"availableLanguages\").forEach((language) => {\n const translations = app.loadConfigSync(dirname + language);\n appTranslations.set(language, load(translations, language));\n });\n\n return appTranslations;\n };\n}\n","import type {\n IncomingMessage,\n RequestListener,\n Server,\n ServerResponse,\n} from \"node:http\";\nimport path from \"node:path\";\nimport Koa from \"koa\";\nimport type { DefaultState, ParameterizedContext } from \"koa\";\nimport compress from \"koa-compress\";\nimport serve from \"koa-static\";\nimport { Logger } from \"nightingale-logger\";\nimport type { Router } from \"router-segments\";\nimport type { Config } from \"./config\";\nimport errors from \"./errors\";\nimport type { AlpLanguageContext } from \"./language\";\nimport language from \"./language\";\nimport _listen from \"./listen\";\nimport type { AlpParamsContext, AlpParamsRequest } from \"./params/index\";\nimport params from \"./params/index\";\nimport type {\n AlpRouteRef,\n RouterContext as AlpRouterContext,\n UrlGenerator,\n} from \"./router\";\nimport type { TranslateBaseContext, TranslateContext } from \"./translate/index\";\nimport translate from \"./translate/index\";\nimport type {\n Context as AlpContext,\n ContextSanitizedState,\n ContextState,\n NodeApplication,\n NodeConfig,\n} from \"./types\";\n\nconst logger = new Logger(\"alp\");\n\nexport interface AlpNodeAppOptions {\n appDirname: string;\n packageDirname: string;\n config: Config & NodeConfig;\n certPath?: string;\n publicPath?: string;\n}\n\ndeclare module \"koa\" {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface DefaultState extends ContextState {}\n\n interface DefaultContext\n extends AlpContext,\n AlpParamsContext,\n AlpRouterContext,\n AlpLanguageContext,\n TranslateContext {}\n\n interface BaseContext extends AlpContext, TranslateBaseContext {\n urlGenerator: UrlGenerator;\n redirectTo: <P extends Record<string, unknown>>(\n to: string,\n params?: P,\n ) => void;\n }\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface BaseRequest extends AlpParamsRequest {}\n}\n\nexport class AlpNodeApp extends Koa<ContextState> implements NodeApplication {\n dirname: string;\n\n certPath: string;\n\n publicPath: string;\n\n config: Config & NodeConfig;\n\n _server?: Server;\n\n router?: Router<any, AlpRouteRef>;\n\n /**\n * @param {Object} [options]\n * @param {string} [options.certPath] directory of the ssl certificates\n * @param {string} [options.publicPath] directory of public files\n */\n constructor({\n appDirname,\n packageDirname,\n config,\n certPath,\n publicPath,\n }: AlpNodeAppOptions) {\n super();\n\n this.dirname = path.normalize(appDirname);\n this.certPath = certPath || `${packageDirname}/config/cert`;\n this.publicPath = publicPath || `${packageDirname}/public/`;\n\n this.config = config;\n this.context.config = this.config;\n\n params(this);\n language(this);\n translate(\"locales\")(this);\n\n this.use(compress());\n }\n\n existsConfigSync(name: string): ReturnType<Config[\"existsConfigSync\"]> {\n return this.config.existsConfigSync(name);\n }\n\n loadConfigSync(name: string): ReturnType<Config[\"loadConfigSync\"]> {\n return this.config.loadConfigSync(name);\n }\n\n override createContext<StateT = DefaultState>(\n req: IncomingMessage,\n res: ServerResponse,\n ): ParameterizedContext<StateT> {\n const ctx = super.createContext<StateT>(req, res);\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n ctx.sanitizedState = {} as ContextSanitizedState;\n return ctx;\n }\n\n servePublic(): void {\n this.use(serve(this.publicPath)); // static files\n }\n\n catchErrors(): void {\n this.use(errors);\n }\n\n override listen(): never {\n throw new Error(\"Use start instead\");\n }\n\n /**\n * Close server and emit close event\n */\n close(): void {\n if (this._server) {\n this._server.close();\n this.emit(\"close\");\n }\n }\n\n async start(fn: () => Promise<void> | void): Promise<Server> {\n await fn();\n try {\n const server = await _listen(\n this.config,\n this.callback() as RequestListener,\n this.certPath,\n );\n this._server = server;\n logger.success(\"started\");\n if (process.send) process.send(\"ready\");\n return server;\n } catch (error: unknown) {\n logger.error(\"start fail\", { err: error });\n throw error;\n }\n }\n}\n\nexport type { Context } from \"koa\";\n\nexport { type NodeApplication } from \"./types\";\n"],"names":["logger","Logger","errorHtmlRenderer","ErrorHtmlRenderer","appPath","process","cwd","alpNodeErrors","ctx","next","error","Error","status","request","accepts","type","env","NODE_ENV","expose","body","message","STATUS_CODES","render","alpLanguage","app","config","context","availableLanguages","get","defineLazyProperty","language","acceptsLanguages","firstAcceptedLanguage","createServer","callback","socketPath","tls","dirname","createHttpServer","createServerHttps","createServerHttp","options","key","readFileSync","cert","alpListen","Promise","resolve","port","hostname","info","server","unlinkSync","listen","chmodSync","ParamValidationResult","_error","name","value","_errors","getErrors","hasErrors","undefined","isValid","ParamValid","constructor","throw","validator","ParamValueValidator","validationResult","ParamValueStringValidator","notEmpty","trim","ParamValueFromContext","namedParam","namedRouteParam","otherParam","position","String","otherRouteParam","queryParam","alpParams","Object","assign","namedParams","route","otherParams","searchParams","bodyParam","URLSearchParams","search","params","validParams","IntlMessageFormat","IntlMessageFormatDefault","default","load","translations","result","loadMap","record","prefix","entries","forEach","alpTranslate","replace","appTranslations","Map","t","id","args","msg","warn","format","loadConfigSync","set","AlpNodeApp","Koa","appDirname","packageDirname","certPath","publicPath","path","normalize","translate","use","compress","existsConfigSync","createContext","req","res","sanitizedState","servePublic","serve","catchErrors","errors","close","_server","emit","start","fn","_listen","success","send","err"],"mappings":";;;;;;;;;;;;AAMA,MAAMA,QAAM,GAAG,IAAIC,MAAM,CAAC,YAAY,CAAC;AACvC,MAAMC,iBAAiB,GAAG,IAAIC,iBAAiB,CAAC;AAC9CC,EAAAA,OAAO,EAAE,CAAA,EAAGC,OAAO,CAACC,GAAG,EAAE,CAAA,CAAA;AAC3B,CAAC,CAAC;AAEa,eAAeC,aAAaA,CACzCC,GAAY,EACZC,IAAgC,EACjB;EACf,IAAI;IACF,MAAMA,IAAI,EAAE;GACb,CAAC,OAAOC,KAAc,EAAE;AACvB;IACA,IAAI,CAACA,KAAK,EAAEA,KAAK,GAAG,IAAIC,KAAK,CAAC,eAAe,CAAC;AAC9C;IACA,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAEA,KAAK,GAAG,IAAIC,KAAK,CAACD,KAAK,CAAC;AAEvDF,IAAAA,GAAG,CAACI,MAAM,GAAIF,KAAK,CAAeE,MAAM,IAAI,GAAG;AAC/C;AACAZ,IAAAA,QAAM,CAACU,KAAK,CAACA,KAAY,CAAC;IAE1B,QAAQF,GAAG,CAACK,OAAO,CAACC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;AACjD,MAAA,KAAK,MAAM;QACTN,GAAG,CAACO,IAAI,GAAG,kBAAkB;QAC7B,IACEV,OAAO,CAACW,GAAG,CAACC,QAAQ,KAAK,YAAY,IACpCP,KAAK,CAAeQ,MAAM,EAC3B;UACAV,GAAG,CAACW,IAAI,GAAG;YAAET,KAAK,EAAGA,KAAK,CAAWU;WAAS;AAChD,SAAC,MAAM;UACLZ,GAAG,CAACW,IAAI,GAAG;AAAET,YAAAA,KAAK,EAAEW,YAAY,CAACb,GAAG,CAACI,MAAM;WAAG;AAChD;AAEA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AACF;AACF;;;;"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
import type {
|
|
1
|
+
import type { IncomingMessage, Server, ServerResponse } from "node:http";
|
|
2
|
+
import Koa from "koa";
|
|
3
|
+
import type { DefaultState, ParameterizedContext } from "koa";
|
|
4
|
+
import type { Router } from "router-segments";
|
|
5
|
+
import type { Config } from "./config";
|
|
6
|
+
import type { AlpLanguageContext } from "./language";
|
|
7
|
+
import type { AlpParamsContext, AlpParamsRequest } from "./params/index";
|
|
8
|
+
import type { AlpRouteRef, RouterContext as AlpRouterContext, UrlGenerator } from "./router";
|
|
9
|
+
import type { TranslateBaseContext, TranslateContext } from "./translate/index";
|
|
10
|
+
import type { Context as AlpContext, ContextState, NodeApplication, NodeConfig } from "./types";
|
|
7
11
|
export interface AlpNodeAppOptions {
|
|
8
12
|
appDirname: string;
|
|
9
13
|
packageDirname: string;
|
|
@@ -11,14 +15,16 @@ export interface AlpNodeAppOptions {
|
|
|
11
15
|
certPath?: string;
|
|
12
16
|
publicPath?: string;
|
|
13
17
|
}
|
|
14
|
-
declare module
|
|
18
|
+
declare module "koa" {
|
|
15
19
|
interface DefaultState extends ContextState {
|
|
16
20
|
}
|
|
17
|
-
interface DefaultContext extends AlpContext {
|
|
21
|
+
interface DefaultContext extends AlpContext, AlpParamsContext, AlpRouterContext, AlpLanguageContext, TranslateContext {
|
|
18
22
|
}
|
|
19
|
-
interface BaseContext extends AlpContext {
|
|
23
|
+
interface BaseContext extends AlpContext, TranslateBaseContext {
|
|
24
|
+
urlGenerator: UrlGenerator;
|
|
25
|
+
redirectTo: <P extends Record<string, unknown>>(to: string, params?: P) => void;
|
|
20
26
|
}
|
|
21
|
-
interface BaseRequest extends
|
|
27
|
+
interface BaseRequest extends AlpParamsRequest {
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
export declare class AlpNodeApp extends Koa<ContextState> implements NodeApplication {
|
|
@@ -26,16 +32,16 @@ export declare class AlpNodeApp extends Koa<ContextState> implements NodeApplica
|
|
|
26
32
|
certPath: string;
|
|
27
33
|
publicPath: string;
|
|
28
34
|
config: Config & NodeConfig;
|
|
29
|
-
request: BaseRequest & ContextRequest;
|
|
30
35
|
_server?: Server;
|
|
36
|
+
router?: Router<any, AlpRouteRef>;
|
|
31
37
|
/**
|
|
32
38
|
* @param {Object} [options]
|
|
33
39
|
* @param {string} [options.certPath] directory of the ssl certificates
|
|
34
40
|
* @param {string} [options.publicPath] directory of public files
|
|
35
41
|
*/
|
|
36
42
|
constructor({ appDirname, packageDirname, config, certPath, publicPath, }: AlpNodeAppOptions);
|
|
37
|
-
existsConfigSync(name: string): ReturnType<Config[
|
|
38
|
-
loadConfigSync(name: string): ReturnType<Config[
|
|
43
|
+
existsConfigSync(name: string): ReturnType<Config["existsConfigSync"]>;
|
|
44
|
+
loadConfigSync(name: string): ReturnType<Config["loadConfigSync"]>;
|
|
39
45
|
createContext<StateT = DefaultState>(req: IncomingMessage, res: ServerResponse): ParameterizedContext<StateT>;
|
|
40
46
|
servePublic(): void;
|
|
41
47
|
catchErrors(): void;
|
|
@@ -46,5 +52,6 @@ export declare class AlpNodeApp extends Koa<ContextState> implements NodeApplica
|
|
|
46
52
|
close(): void;
|
|
47
53
|
start(fn: () => Promise<void> | void): Promise<Server>;
|
|
48
54
|
}
|
|
49
|
-
export type { Context } from
|
|
55
|
+
export type { Context } from "koa";
|
|
56
|
+
export { type NodeApplication } from "./types";
|
|
50
57
|
//# sourceMappingURL=AlpNodeApp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlpNodeApp.d.ts","sourceRoot":"","sources":["../../src/AlpNodeApp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AlpNodeApp.d.ts","sourceRoot":"","sources":["../../src/AlpNodeApp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAA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ig?: PackageConfig;
|
|
5
|
+
version?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class Config {
|
|
8
|
+
packageConfig?: PackageConfig;
|
|
9
|
+
private _record;
|
|
10
|
+
private readonly _dirname;
|
|
11
|
+
constructor(dirname: string, options?: ConfigOptions);
|
|
12
|
+
loadSync(options?: ConfigOptions): Config & NodeConfig;
|
|
13
|
+
get<T>(key: string): Readonly<T>;
|
|
14
|
+
existsConfigSync(name: string): boolean;
|
|
15
|
+
loadConfigSync(name: string): Readonly<Record<string, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAgBzD,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,MAAM;IACjB,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B,OAAO,CAAC,OAAO,CAA0B;IAEzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa;IAQpD,QAAQ,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,GAAG,UAAU;IAgE1D,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;IAIhC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIvC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAGhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAQ5C,wBAA8B,aAAa,CACzC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAC/B,OAAO,CAAC,IAAI,CAAC,CAuDf"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
export type {
|
|
5
|
-
export {
|
|
1
|
+
import type { AlpNodeAppOptions } from "./AlpNodeApp";
|
|
2
|
+
import { AlpNodeApp } from "./AlpNodeApp";
|
|
3
|
+
import { Config } from "./config";
|
|
4
|
+
export type { BaseContext, NodeApplication, NodeConfig, ContextState, ContextSanitizedState, } from "./types";
|
|
5
|
+
export type { Context } from "./AlpNodeApp";
|
|
6
6
|
export declare const appDirname: string;
|
|
7
7
|
export declare const packageDirname: string;
|
|
8
8
|
export declare const packageConfig: Record<string, unknown>;
|
|
9
|
-
export declare const config: Config & import("
|
|
10
|
-
export type AppOptions = Omit<AlpNodeAppOptions,
|
|
9
|
+
export declare const config: Config & import("./types").NodeConfig;
|
|
10
|
+
export type AppOptions = Omit<AlpNodeAppOptions, "appDirname" | "config" | "packageDirname">;
|
|
11
11
|
export default class App extends AlpNodeApp {
|
|
12
12
|
constructor(options?: AppOptions);
|
|
13
13
|
}
|
|
14
|
+
export { Config } from "./config";
|
|
15
|
+
export { default as router, createAlpRouterBuilder, type AlpRouteRef, type AlpRouter, } from "./router";
|
|
14
16
|
//# sourceMappingURL=index.d.ts.map
|