@twin.org/api-server-fastify 0.0.2-next.10 → 0.0.2-next.12
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/cjs/index.cjs +23 -28
- package/dist/esm/index.mjs +24 -29
- package/dist/types/fastifyWebServer.d.ts +1 -1
- package/docs/changelog.md +32 -0
- package/docs/reference/classes/FastifyWebServer.md +1 -1
- package/locales/.validate-ignore +2 -0
- package/locales/en.json +18 -12
- package/package.json +18 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -28,10 +28,9 @@ const fastifySocketIO = fp(async (fastify, opts) => {
|
|
|
28
28
|
*/
|
|
29
29
|
class FastifyWebServer {
|
|
30
30
|
/**
|
|
31
|
-
* Runtime name for the class
|
|
32
|
-
* @internal
|
|
31
|
+
* Runtime name for the class.
|
|
33
32
|
*/
|
|
34
|
-
static
|
|
33
|
+
static CLASS_NAME = "FastifyWebServer";
|
|
35
34
|
/**
|
|
36
35
|
* Default port for running the server.
|
|
37
36
|
* @internal
|
|
@@ -42,10 +41,6 @@ class FastifyWebServer {
|
|
|
42
41
|
* @internal
|
|
43
42
|
*/
|
|
44
43
|
static _DEFAULT_HOST = "localhost";
|
|
45
|
-
/**
|
|
46
|
-
* Runtime name for the class.
|
|
47
|
-
*/
|
|
48
|
-
CLASS_NAME = "FastifyWebServer";
|
|
49
44
|
/**
|
|
50
45
|
* The logging component type.
|
|
51
46
|
* @internal
|
|
@@ -131,16 +126,16 @@ class FastifyWebServer {
|
|
|
131
126
|
*/
|
|
132
127
|
async build(restRouteProcessors, restRoutes, socketRouteProcessors, socketRoutes, options) {
|
|
133
128
|
if (core.Is.arrayValue(restRoutes) && !core.Is.arrayValue(restRouteProcessors)) {
|
|
134
|
-
throw new core.GeneralError(
|
|
129
|
+
throw new core.GeneralError(FastifyWebServer.CLASS_NAME, "noRestProcessors");
|
|
135
130
|
}
|
|
136
131
|
if (core.Is.arrayValue(socketRoutes) && !core.Is.arrayValue(socketRouteProcessors)) {
|
|
137
|
-
throw new core.GeneralError(
|
|
132
|
+
throw new core.GeneralError(FastifyWebServer.CLASS_NAME, "noSocketProcessors");
|
|
138
133
|
}
|
|
139
134
|
await this._logging?.log({
|
|
140
135
|
level: "info",
|
|
141
136
|
ts: Date.now(),
|
|
142
|
-
source:
|
|
143
|
-
message: `${
|
|
137
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
138
|
+
message: `${"fastifyWebServer"}.building`
|
|
144
139
|
});
|
|
145
140
|
this._options = options;
|
|
146
141
|
await this._fastify.register(FastifyCompress);
|
|
@@ -170,7 +165,7 @@ class FastifyWebServer {
|
|
|
170
165
|
let err;
|
|
171
166
|
if (core.Is.number(error.code)) {
|
|
172
167
|
err = {
|
|
173
|
-
source:
|
|
168
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
174
169
|
name: error.name,
|
|
175
170
|
message: `${error.code}: ${error.message}`
|
|
176
171
|
};
|
|
@@ -184,8 +179,8 @@ class FastifyWebServer {
|
|
|
184
179
|
await this._logging?.log({
|
|
185
180
|
level: "error",
|
|
186
181
|
ts: Date.now(),
|
|
187
|
-
source:
|
|
188
|
-
message: `${
|
|
182
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
183
|
+
message: `${"fastifyWebServer"}.badRequest`,
|
|
189
184
|
error: err
|
|
190
185
|
});
|
|
191
186
|
return reply.status(httpStatusCode).send({
|
|
@@ -205,8 +200,8 @@ class FastifyWebServer {
|
|
|
205
200
|
await this._logging?.log({
|
|
206
201
|
level: "info",
|
|
207
202
|
ts: Date.now(),
|
|
208
|
-
source:
|
|
209
|
-
message: `${
|
|
203
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
204
|
+
message: `${"fastifyWebServer"}.starting`,
|
|
210
205
|
data: {
|
|
211
206
|
host,
|
|
212
207
|
port
|
|
@@ -220,8 +215,8 @@ class FastifyWebServer {
|
|
|
220
215
|
await this._logging?.log({
|
|
221
216
|
level: "info",
|
|
222
217
|
ts: Date.now(),
|
|
223
|
-
source:
|
|
224
|
-
message: `${
|
|
218
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
219
|
+
message: `${"fastifyWebServer"}.started`,
|
|
225
220
|
data: {
|
|
226
221
|
addresses: addresses
|
|
227
222
|
.map(a => `${protocol}${a.family === "IPv6" ? "[" : ""}${a.address}${a.family === "IPv6" ? "]" : ""}:${a.port}`)
|
|
@@ -234,8 +229,8 @@ class FastifyWebServer {
|
|
|
234
229
|
await this._logging?.log({
|
|
235
230
|
level: "error",
|
|
236
231
|
ts: Date.now(),
|
|
237
|
-
source:
|
|
238
|
-
message: `${
|
|
232
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
233
|
+
message: `${"fastifyWebServer"}.startFailed`,
|
|
239
234
|
error: core.BaseError.fromError(err)
|
|
240
235
|
});
|
|
241
236
|
}
|
|
@@ -252,8 +247,8 @@ class FastifyWebServer {
|
|
|
252
247
|
await this._logging?.log({
|
|
253
248
|
level: "info",
|
|
254
249
|
ts: Date.now(),
|
|
255
|
-
source:
|
|
256
|
-
message: `${
|
|
250
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
251
|
+
message: `${"fastifyWebServer"}.stopped`
|
|
257
252
|
});
|
|
258
253
|
}
|
|
259
254
|
}
|
|
@@ -273,8 +268,8 @@ class FastifyWebServer {
|
|
|
273
268
|
await this._logging?.log({
|
|
274
269
|
level: "info",
|
|
275
270
|
ts: Date.now(),
|
|
276
|
-
source:
|
|
277
|
-
message: `${
|
|
271
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
272
|
+
message: `${"fastifyWebServer"}.restRouteAdded`,
|
|
278
273
|
data: { route: path, method: restRoute.method }
|
|
279
274
|
});
|
|
280
275
|
const method = restRoute.method.toLowerCase();
|
|
@@ -300,8 +295,8 @@ class FastifyWebServer {
|
|
|
300
295
|
await this._logging?.log({
|
|
301
296
|
level: "info",
|
|
302
297
|
ts: Date.now(),
|
|
303
|
-
source:
|
|
304
|
-
message: `${
|
|
298
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
299
|
+
message: `${"fastifyWebServer"}.socketRouteAdded`,
|
|
305
300
|
data: {
|
|
306
301
|
handshakePath: this._socketConfig.path,
|
|
307
302
|
namespace,
|
|
@@ -499,8 +494,8 @@ class FastifyWebServer {
|
|
|
499
494
|
this._logging?.log({
|
|
500
495
|
level: "error",
|
|
501
496
|
ts: Date.now(),
|
|
502
|
-
source:
|
|
503
|
-
message: `${
|
|
497
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
498
|
+
message: `${"fastifyWebServer"}.postProcessorError`,
|
|
504
499
|
error: core.BaseError.fromError(err),
|
|
505
500
|
data: {
|
|
506
501
|
route: socketRoute.path
|
package/dist/esm/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import FastifyCompress from '@fastify/compress';
|
|
|
2
2
|
import FastifyCors from '@fastify/cors';
|
|
3
3
|
import { HttpErrorHelper } from '@twin.org/api-models';
|
|
4
4
|
import { JsonLdMimeTypeProcessor } from '@twin.org/api-processors';
|
|
5
|
-
import {
|
|
5
|
+
import { ComponentFactory, Is, GeneralError, BaseError, StringHelper } from '@twin.org/core';
|
|
6
6
|
import { HttpStatusCode, HttpMethod, HeaderTypes } from '@twin.org/web';
|
|
7
7
|
import Fastify from 'fastify';
|
|
8
8
|
import fp from 'fastify-plugin';
|
|
@@ -26,10 +26,9 @@ const fastifySocketIO = fp(async (fastify, opts) => {
|
|
|
26
26
|
*/
|
|
27
27
|
class FastifyWebServer {
|
|
28
28
|
/**
|
|
29
|
-
* Runtime name for the class
|
|
30
|
-
* @internal
|
|
29
|
+
* Runtime name for the class.
|
|
31
30
|
*/
|
|
32
|
-
static
|
|
31
|
+
static CLASS_NAME = "FastifyWebServer";
|
|
33
32
|
/**
|
|
34
33
|
* Default port for running the server.
|
|
35
34
|
* @internal
|
|
@@ -40,10 +39,6 @@ class FastifyWebServer {
|
|
|
40
39
|
* @internal
|
|
41
40
|
*/
|
|
42
41
|
static _DEFAULT_HOST = "localhost";
|
|
43
|
-
/**
|
|
44
|
-
* Runtime name for the class.
|
|
45
|
-
*/
|
|
46
|
-
CLASS_NAME = "FastifyWebServer";
|
|
47
42
|
/**
|
|
48
43
|
* The logging component type.
|
|
49
44
|
* @internal
|
|
@@ -129,16 +124,16 @@ class FastifyWebServer {
|
|
|
129
124
|
*/
|
|
130
125
|
async build(restRouteProcessors, restRoutes, socketRouteProcessors, socketRoutes, options) {
|
|
131
126
|
if (Is.arrayValue(restRoutes) && !Is.arrayValue(restRouteProcessors)) {
|
|
132
|
-
throw new GeneralError(
|
|
127
|
+
throw new GeneralError(FastifyWebServer.CLASS_NAME, "noRestProcessors");
|
|
133
128
|
}
|
|
134
129
|
if (Is.arrayValue(socketRoutes) && !Is.arrayValue(socketRouteProcessors)) {
|
|
135
|
-
throw new GeneralError(
|
|
130
|
+
throw new GeneralError(FastifyWebServer.CLASS_NAME, "noSocketProcessors");
|
|
136
131
|
}
|
|
137
132
|
await this._logging?.log({
|
|
138
133
|
level: "info",
|
|
139
134
|
ts: Date.now(),
|
|
140
|
-
source:
|
|
141
|
-
message: `${
|
|
135
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
136
|
+
message: `${"fastifyWebServer"}.building`
|
|
142
137
|
});
|
|
143
138
|
this._options = options;
|
|
144
139
|
await this._fastify.register(FastifyCompress);
|
|
@@ -168,7 +163,7 @@ class FastifyWebServer {
|
|
|
168
163
|
let err;
|
|
169
164
|
if (Is.number(error.code)) {
|
|
170
165
|
err = {
|
|
171
|
-
source:
|
|
166
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
172
167
|
name: error.name,
|
|
173
168
|
message: `${error.code}: ${error.message}`
|
|
174
169
|
};
|
|
@@ -182,8 +177,8 @@ class FastifyWebServer {
|
|
|
182
177
|
await this._logging?.log({
|
|
183
178
|
level: "error",
|
|
184
179
|
ts: Date.now(),
|
|
185
|
-
source:
|
|
186
|
-
message: `${
|
|
180
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
181
|
+
message: `${"fastifyWebServer"}.badRequest`,
|
|
187
182
|
error: err
|
|
188
183
|
});
|
|
189
184
|
return reply.status(httpStatusCode).send({
|
|
@@ -203,8 +198,8 @@ class FastifyWebServer {
|
|
|
203
198
|
await this._logging?.log({
|
|
204
199
|
level: "info",
|
|
205
200
|
ts: Date.now(),
|
|
206
|
-
source:
|
|
207
|
-
message: `${
|
|
201
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
202
|
+
message: `${"fastifyWebServer"}.starting`,
|
|
208
203
|
data: {
|
|
209
204
|
host,
|
|
210
205
|
port
|
|
@@ -218,8 +213,8 @@ class FastifyWebServer {
|
|
|
218
213
|
await this._logging?.log({
|
|
219
214
|
level: "info",
|
|
220
215
|
ts: Date.now(),
|
|
221
|
-
source:
|
|
222
|
-
message: `${
|
|
216
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
217
|
+
message: `${"fastifyWebServer"}.started`,
|
|
223
218
|
data: {
|
|
224
219
|
addresses: addresses
|
|
225
220
|
.map(a => `${protocol}${a.family === "IPv6" ? "[" : ""}${a.address}${a.family === "IPv6" ? "]" : ""}:${a.port}`)
|
|
@@ -232,8 +227,8 @@ class FastifyWebServer {
|
|
|
232
227
|
await this._logging?.log({
|
|
233
228
|
level: "error",
|
|
234
229
|
ts: Date.now(),
|
|
235
|
-
source:
|
|
236
|
-
message: `${
|
|
230
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
231
|
+
message: `${"fastifyWebServer"}.startFailed`,
|
|
237
232
|
error: BaseError.fromError(err)
|
|
238
233
|
});
|
|
239
234
|
}
|
|
@@ -250,8 +245,8 @@ class FastifyWebServer {
|
|
|
250
245
|
await this._logging?.log({
|
|
251
246
|
level: "info",
|
|
252
247
|
ts: Date.now(),
|
|
253
|
-
source:
|
|
254
|
-
message: `${
|
|
248
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
249
|
+
message: `${"fastifyWebServer"}.stopped`
|
|
255
250
|
});
|
|
256
251
|
}
|
|
257
252
|
}
|
|
@@ -271,8 +266,8 @@ class FastifyWebServer {
|
|
|
271
266
|
await this._logging?.log({
|
|
272
267
|
level: "info",
|
|
273
268
|
ts: Date.now(),
|
|
274
|
-
source:
|
|
275
|
-
message: `${
|
|
269
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
270
|
+
message: `${"fastifyWebServer"}.restRouteAdded`,
|
|
276
271
|
data: { route: path, method: restRoute.method }
|
|
277
272
|
});
|
|
278
273
|
const method = restRoute.method.toLowerCase();
|
|
@@ -298,8 +293,8 @@ class FastifyWebServer {
|
|
|
298
293
|
await this._logging?.log({
|
|
299
294
|
level: "info",
|
|
300
295
|
ts: Date.now(),
|
|
301
|
-
source:
|
|
302
|
-
message: `${
|
|
296
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
297
|
+
message: `${"fastifyWebServer"}.socketRouteAdded`,
|
|
303
298
|
data: {
|
|
304
299
|
handshakePath: this._socketConfig.path,
|
|
305
300
|
namespace,
|
|
@@ -497,8 +492,8 @@ class FastifyWebServer {
|
|
|
497
492
|
this._logging?.log({
|
|
498
493
|
level: "error",
|
|
499
494
|
ts: Date.now(),
|
|
500
|
-
source:
|
|
501
|
-
message: `${
|
|
495
|
+
source: FastifyWebServer.CLASS_NAME,
|
|
496
|
+
message: `${"fastifyWebServer"}.postProcessorError`,
|
|
502
497
|
error: BaseError.fromError(err),
|
|
503
498
|
data: {
|
|
504
499
|
route: socketRoute.path
|
|
@@ -8,7 +8,7 @@ export declare class FastifyWebServer implements IWebServer<FastifyInstance> {
|
|
|
8
8
|
/**
|
|
9
9
|
* Runtime name for the class.
|
|
10
10
|
*/
|
|
11
|
-
readonly CLASS_NAME: string;
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
12
|
/**
|
|
13
13
|
* Create a new instance of FastifyWebServer.
|
|
14
14
|
* @param options The options for the server.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @twin.org/api-server-fastify - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.12](https://github.com/twinfoundation/api/compare/api-server-fastify-v0.0.2-next.11...api-server-fastify-v0.0.2-next.12) (2025-10-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add validate-locales ([cdba610](https://github.com/twinfoundation/api/commit/cdba610a0acb5022d2e3ce729732e6646a297e5e))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/api-core bumped from 0.0.2-next.11 to 0.0.2-next.12
|
|
16
|
+
* @twin.org/api-models bumped from 0.0.2-next.11 to 0.0.2-next.12
|
|
17
|
+
* @twin.org/api-processors bumped from 0.0.2-next.11 to 0.0.2-next.12
|
|
18
|
+
|
|
19
|
+
## [0.0.2-next.11](https://github.com/twinfoundation/api/compare/api-server-fastify-v0.0.2-next.10...api-server-fastify-v0.0.2-next.11) (2025-09-29)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* update IComponent signatures ([915ce37](https://github.com/twinfoundation/api/commit/915ce37712326ab4aa6869c350eabaa4622e8430))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* The following workspace dependencies were updated
|
|
30
|
+
* dependencies
|
|
31
|
+
* @twin.org/api-core bumped from 0.0.2-next.10 to 0.0.2-next.11
|
|
32
|
+
* @twin.org/api-models bumped from 0.0.2-next.10 to 0.0.2-next.11
|
|
33
|
+
* @twin.org/api-processors bumped from 0.0.2-next.10 to 0.0.2-next.11
|
|
34
|
+
|
|
3
35
|
## [0.0.2-next.10](https://github.com/twinfoundation/api/compare/api-server-fastify-v0.0.2-next.9...api-server-fastify-v0.0.2-next.10) (2025-09-23)
|
|
4
36
|
|
|
5
37
|
|
package/locales/en.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
2
|
+
"error": {
|
|
3
|
+
"fastifyWebServer": {
|
|
4
|
+
"startFailed": "The Web Server failed to start",
|
|
5
|
+
"badRequest": "The web server could not handle the request",
|
|
6
|
+
"noRestProcessors": "You must configure at least one REST processor",
|
|
7
|
+
"noSocketProcessors": "You must configure at least one socket processor",
|
|
8
|
+
"postProcessorError": "There was a failure after in a post processor for route \"{route}\""
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"info": {
|
|
12
|
+
"fastifyWebServer": {
|
|
13
|
+
"building": "Building Web Server",
|
|
14
|
+
"starting": "Starting Web Server at address \"{host}\" on port \"{port}\"",
|
|
15
|
+
"started": "The Web Server started on {addresses}",
|
|
16
|
+
"stopped": "The Web Server was stopped",
|
|
17
|
+
"restRouteAdded": "Added REST route \"{route}\" \"{method}\"",
|
|
18
|
+
"socketRouteAdded": "Added socket route: handshake path \"{handshakePath}\", namespace \"{namespace}\", event name \"{eventName}\""
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-server-fastify",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.12",
|
|
4
4
|
"description": "Use Fastify as the core web server for APIs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@fastify/compress": "8.1.0",
|
|
18
18
|
"@fastify/cors": "11.1.0",
|
|
19
|
-
"@twin.org/api-core": "0.0.2-next.
|
|
20
|
-
"@twin.org/api-models": "0.0.2-next.
|
|
21
|
-
"@twin.org/api-processors": "0.0.2-next.
|
|
19
|
+
"@twin.org/api-core": "0.0.2-next.12",
|
|
20
|
+
"@twin.org/api-models": "0.0.2-next.12",
|
|
21
|
+
"@twin.org/api-processors": "0.0.2-next.12",
|
|
22
22
|
"@twin.org/core": "next",
|
|
23
23
|
"@twin.org/logging-models": "next",
|
|
24
24
|
"@twin.org/nameof": "next",
|
|
25
25
|
"@twin.org/web": "next",
|
|
26
|
-
"fastify": "5.
|
|
26
|
+
"fastify": "5.6.1",
|
|
27
27
|
"socket.io": "4.8.1"
|
|
28
28
|
},
|
|
29
29
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -42,5 +42,17 @@
|
|
|
42
42
|
"dist/types",
|
|
43
43
|
"locales",
|
|
44
44
|
"docs"
|
|
45
|
-
]
|
|
45
|
+
],
|
|
46
|
+
"keywords": [
|
|
47
|
+
"twin",
|
|
48
|
+
"trade",
|
|
49
|
+
"iota",
|
|
50
|
+
"framework",
|
|
51
|
+
"blockchain",
|
|
52
|
+
"api"
|
|
53
|
+
],
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "git+https://github.com/twinfoundation/api/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://twindev.org"
|
|
46
58
|
}
|