@twin.org/api-server-fastify 0.0.2-next.11 → 0.0.2-next.13

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.
@@ -27,6 +27,10 @@ const fastifySocketIO = fp(async (fastify, opts) => {
27
27
  * Implementation of the web server using Fastify.
28
28
  */
29
29
  class FastifyWebServer {
30
+ /**
31
+ * Runtime name for the class.
32
+ */
33
+ static CLASS_NAME = "FastifyWebServer";
30
34
  /**
31
35
  * Default port for running the server.
32
36
  * @internal
@@ -37,10 +41,6 @@ class FastifyWebServer {
37
41
  * @internal
38
42
  */
39
43
  static _DEFAULT_HOST = "localhost";
40
- /**
41
- * Runtime name for the class.
42
- */
43
- CLASS_NAME = "FastifyWebServer";
44
44
  /**
45
45
  * The logging component type.
46
46
  * @internal
@@ -126,16 +126,16 @@ class FastifyWebServer {
126
126
  */
127
127
  async build(restRouteProcessors, restRoutes, socketRouteProcessors, socketRoutes, options) {
128
128
  if (core.Is.arrayValue(restRoutes) && !core.Is.arrayValue(restRouteProcessors)) {
129
- throw new core.GeneralError(this.CLASS_NAME, "noRestProcessors");
129
+ throw new core.GeneralError(FastifyWebServer.CLASS_NAME, "noRestProcessors");
130
130
  }
131
131
  if (core.Is.arrayValue(socketRoutes) && !core.Is.arrayValue(socketRouteProcessors)) {
132
- throw new core.GeneralError(this.CLASS_NAME, "noSocketProcessors");
132
+ throw new core.GeneralError(FastifyWebServer.CLASS_NAME, "noSocketProcessors");
133
133
  }
134
134
  await this._logging?.log({
135
135
  level: "info",
136
136
  ts: Date.now(),
137
- source: this.CLASS_NAME,
138
- message: `${"fastifyWebServer"}.building`
137
+ source: FastifyWebServer.CLASS_NAME,
138
+ message: "building"
139
139
  });
140
140
  this._options = options;
141
141
  await this._fastify.register(FastifyCompress);
@@ -165,7 +165,7 @@ class FastifyWebServer {
165
165
  let err;
166
166
  if (core.Is.number(error.code)) {
167
167
  err = {
168
- source: this.CLASS_NAME,
168
+ source: FastifyWebServer.CLASS_NAME,
169
169
  name: error.name,
170
170
  message: `${error.code}: ${error.message}`
171
171
  };
@@ -179,8 +179,8 @@ class FastifyWebServer {
179
179
  await this._logging?.log({
180
180
  level: "error",
181
181
  ts: Date.now(),
182
- source: this.CLASS_NAME,
183
- message: `${"fastifyWebServer"}.badRequest`,
182
+ source: FastifyWebServer.CLASS_NAME,
183
+ message: "badRequest",
184
184
  error: err
185
185
  });
186
186
  return reply.status(httpStatusCode).send({
@@ -200,8 +200,8 @@ class FastifyWebServer {
200
200
  await this._logging?.log({
201
201
  level: "info",
202
202
  ts: Date.now(),
203
- source: this.CLASS_NAME,
204
- message: `${"fastifyWebServer"}.starting`,
203
+ source: FastifyWebServer.CLASS_NAME,
204
+ message: "starting",
205
205
  data: {
206
206
  host,
207
207
  port
@@ -215,8 +215,8 @@ class FastifyWebServer {
215
215
  await this._logging?.log({
216
216
  level: "info",
217
217
  ts: Date.now(),
218
- source: this.CLASS_NAME,
219
- message: `${"fastifyWebServer"}.started`,
218
+ source: FastifyWebServer.CLASS_NAME,
219
+ message: "started",
220
220
  data: {
221
221
  addresses: addresses
222
222
  .map(a => `${protocol}${a.family === "IPv6" ? "[" : ""}${a.address}${a.family === "IPv6" ? "]" : ""}:${a.port}`)
@@ -229,8 +229,8 @@ class FastifyWebServer {
229
229
  await this._logging?.log({
230
230
  level: "error",
231
231
  ts: Date.now(),
232
- source: this.CLASS_NAME,
233
- message: `${"fastifyWebServer"}.startFailed`,
232
+ source: FastifyWebServer.CLASS_NAME,
233
+ message: "startFailed",
234
234
  error: core.BaseError.fromError(err)
235
235
  });
236
236
  }
@@ -247,8 +247,8 @@ class FastifyWebServer {
247
247
  await this._logging?.log({
248
248
  level: "info",
249
249
  ts: Date.now(),
250
- source: this.CLASS_NAME,
251
- message: `${"fastifyWebServer"}.stopped`
250
+ source: FastifyWebServer.CLASS_NAME,
251
+ message: "stopped"
252
252
  });
253
253
  }
254
254
  }
@@ -268,8 +268,8 @@ class FastifyWebServer {
268
268
  await this._logging?.log({
269
269
  level: "info",
270
270
  ts: Date.now(),
271
- source: this.CLASS_NAME,
272
- message: `${"fastifyWebServer"}.restRouteAdded`,
271
+ source: FastifyWebServer.CLASS_NAME,
272
+ message: "restRouteAdded",
273
273
  data: { route: path, method: restRoute.method }
274
274
  });
275
275
  const method = restRoute.method.toLowerCase();
@@ -295,8 +295,8 @@ class FastifyWebServer {
295
295
  await this._logging?.log({
296
296
  level: "info",
297
297
  ts: Date.now(),
298
- source: this.CLASS_NAME,
299
- message: `${"fastifyWebServer"}.socketRouteAdded`,
298
+ source: FastifyWebServer.CLASS_NAME,
299
+ message: "socketRouteAdded",
300
300
  data: {
301
301
  handshakePath: this._socketConfig.path,
302
302
  namespace,
@@ -494,8 +494,8 @@ class FastifyWebServer {
494
494
  this._logging?.log({
495
495
  level: "error",
496
496
  ts: Date.now(),
497
- source: this.CLASS_NAME,
498
- message: `${"fastifyWebServer"}.postProcessorError`,
497
+ source: FastifyWebServer.CLASS_NAME,
498
+ message: "postProcessorError",
499
499
  error: core.BaseError.fromError(err),
500
500
  data: {
501
501
  route: socketRoute.path
@@ -25,6 +25,10 @@ const fastifySocketIO = fp(async (fastify, opts) => {
25
25
  * Implementation of the web server using Fastify.
26
26
  */
27
27
  class FastifyWebServer {
28
+ /**
29
+ * Runtime name for the class.
30
+ */
31
+ static CLASS_NAME = "FastifyWebServer";
28
32
  /**
29
33
  * Default port for running the server.
30
34
  * @internal
@@ -35,10 +39,6 @@ class FastifyWebServer {
35
39
  * @internal
36
40
  */
37
41
  static _DEFAULT_HOST = "localhost";
38
- /**
39
- * Runtime name for the class.
40
- */
41
- CLASS_NAME = "FastifyWebServer";
42
42
  /**
43
43
  * The logging component type.
44
44
  * @internal
@@ -124,16 +124,16 @@ class FastifyWebServer {
124
124
  */
125
125
  async build(restRouteProcessors, restRoutes, socketRouteProcessors, socketRoutes, options) {
126
126
  if (Is.arrayValue(restRoutes) && !Is.arrayValue(restRouteProcessors)) {
127
- throw new GeneralError(this.CLASS_NAME, "noRestProcessors");
127
+ throw new GeneralError(FastifyWebServer.CLASS_NAME, "noRestProcessors");
128
128
  }
129
129
  if (Is.arrayValue(socketRoutes) && !Is.arrayValue(socketRouteProcessors)) {
130
- throw new GeneralError(this.CLASS_NAME, "noSocketProcessors");
130
+ throw new GeneralError(FastifyWebServer.CLASS_NAME, "noSocketProcessors");
131
131
  }
132
132
  await this._logging?.log({
133
133
  level: "info",
134
134
  ts: Date.now(),
135
- source: this.CLASS_NAME,
136
- message: `${"fastifyWebServer"}.building`
135
+ source: FastifyWebServer.CLASS_NAME,
136
+ message: "building"
137
137
  });
138
138
  this._options = options;
139
139
  await this._fastify.register(FastifyCompress);
@@ -163,7 +163,7 @@ class FastifyWebServer {
163
163
  let err;
164
164
  if (Is.number(error.code)) {
165
165
  err = {
166
- source: this.CLASS_NAME,
166
+ source: FastifyWebServer.CLASS_NAME,
167
167
  name: error.name,
168
168
  message: `${error.code}: ${error.message}`
169
169
  };
@@ -177,8 +177,8 @@ class FastifyWebServer {
177
177
  await this._logging?.log({
178
178
  level: "error",
179
179
  ts: Date.now(),
180
- source: this.CLASS_NAME,
181
- message: `${"fastifyWebServer"}.badRequest`,
180
+ source: FastifyWebServer.CLASS_NAME,
181
+ message: "badRequest",
182
182
  error: err
183
183
  });
184
184
  return reply.status(httpStatusCode).send({
@@ -198,8 +198,8 @@ class FastifyWebServer {
198
198
  await this._logging?.log({
199
199
  level: "info",
200
200
  ts: Date.now(),
201
- source: this.CLASS_NAME,
202
- message: `${"fastifyWebServer"}.starting`,
201
+ source: FastifyWebServer.CLASS_NAME,
202
+ message: "starting",
203
203
  data: {
204
204
  host,
205
205
  port
@@ -213,8 +213,8 @@ class FastifyWebServer {
213
213
  await this._logging?.log({
214
214
  level: "info",
215
215
  ts: Date.now(),
216
- source: this.CLASS_NAME,
217
- message: `${"fastifyWebServer"}.started`,
216
+ source: FastifyWebServer.CLASS_NAME,
217
+ message: "started",
218
218
  data: {
219
219
  addresses: addresses
220
220
  .map(a => `${protocol}${a.family === "IPv6" ? "[" : ""}${a.address}${a.family === "IPv6" ? "]" : ""}:${a.port}`)
@@ -227,8 +227,8 @@ class FastifyWebServer {
227
227
  await this._logging?.log({
228
228
  level: "error",
229
229
  ts: Date.now(),
230
- source: this.CLASS_NAME,
231
- message: `${"fastifyWebServer"}.startFailed`,
230
+ source: FastifyWebServer.CLASS_NAME,
231
+ message: "startFailed",
232
232
  error: BaseError.fromError(err)
233
233
  });
234
234
  }
@@ -245,8 +245,8 @@ class FastifyWebServer {
245
245
  await this._logging?.log({
246
246
  level: "info",
247
247
  ts: Date.now(),
248
- source: this.CLASS_NAME,
249
- message: `${"fastifyWebServer"}.stopped`
248
+ source: FastifyWebServer.CLASS_NAME,
249
+ message: "stopped"
250
250
  });
251
251
  }
252
252
  }
@@ -266,8 +266,8 @@ class FastifyWebServer {
266
266
  await this._logging?.log({
267
267
  level: "info",
268
268
  ts: Date.now(),
269
- source: this.CLASS_NAME,
270
- message: `${"fastifyWebServer"}.restRouteAdded`,
269
+ source: FastifyWebServer.CLASS_NAME,
270
+ message: "restRouteAdded",
271
271
  data: { route: path, method: restRoute.method }
272
272
  });
273
273
  const method = restRoute.method.toLowerCase();
@@ -293,8 +293,8 @@ class FastifyWebServer {
293
293
  await this._logging?.log({
294
294
  level: "info",
295
295
  ts: Date.now(),
296
- source: this.CLASS_NAME,
297
- message: `${"fastifyWebServer"}.socketRouteAdded`,
296
+ source: FastifyWebServer.CLASS_NAME,
297
+ message: "socketRouteAdded",
298
298
  data: {
299
299
  handshakePath: this._socketConfig.path,
300
300
  namespace,
@@ -492,8 +492,8 @@ class FastifyWebServer {
492
492
  this._logging?.log({
493
493
  level: "error",
494
494
  ts: Date.now(),
495
- source: this.CLASS_NAME,
496
- message: `${"fastifyWebServer"}.postProcessorError`,
495
+ source: FastifyWebServer.CLASS_NAME,
496
+ message: "postProcessorError",
497
497
  error: BaseError.fromError(err),
498
498
  data: {
499
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.13](https://github.com/twinfoundation/api/compare/api-server-fastify-v0.0.2-next.12...api-server-fastify-v0.0.2-next.13) (2025-10-09)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * use correct format for log messaging ([6b62a18](https://github.com/twinfoundation/api/commit/6b62a185e1da1150bb1e4331337e2799294b83c4))
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.12 to 0.0.2-next.13
16
+ * @twin.org/api-models bumped from 0.0.2-next.12 to 0.0.2-next.13
17
+ * @twin.org/api-processors bumped from 0.0.2-next.12 to 0.0.2-next.13
18
+
19
+ ## [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)
20
+
21
+
22
+ ### Features
23
+
24
+ * add validate-locales ([cdba610](https://github.com/twinfoundation/api/commit/cdba610a0acb5022d2e3ce729732e6646a297e5e))
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.11 to 0.0.2-next.12
32
+ * @twin.org/api-models bumped from 0.0.2-next.11 to 0.0.2-next.12
33
+ * @twin.org/api-processors bumped from 0.0.2-next.11 to 0.0.2-next.12
34
+
3
35
  ## [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)
4
36
 
5
37
 
@@ -30,7 +30,7 @@ The options for the server.
30
30
 
31
31
  ### CLASS\_NAME
32
32
 
33
- > `readonly` **CLASS\_NAME**: `string`
33
+ > `readonly` `static` **CLASS\_NAME**: `string`
34
34
 
35
35
  Runtime name for the class.
36
36
 
@@ -0,0 +1,2 @@
1
+ ^>=5.x.x$
2
+ ^socket.io$
package/locales/en.json CHANGED
@@ -1,15 +1,21 @@
1
1
  {
2
- "fastifyWebServer": {
3
- "building": "Building Web Server",
4
- "starting": "Starting Web Server at address \"{host}\" on port \"{port}\"",
5
- "startFailed": "The Web Server failed to start",
6
- "started": "The Web Server started on {addresses}",
7
- "stopped": "The Web Server was stopped",
8
- "badRequest": "The web server could not handle the request",
9
- "restRouteAdded": "Added REST route \"{route}\" \"{method}\"",
10
- "socketRouteAdded": "Added socket route: handshake path \"{handshakePath}\", namespace \"{namespace}\", event name \"{eventName}\"",
11
- "noRestProcessors": "You must configure at least one REST processor",
12
- "noSocketProcessors": "You must configure at least one socket processor",
13
- "postProcessorError": "There was a failure after in a post processor for route \"{route}\""
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.11",
3
+ "version": "0.0.2-next.13",
4
4
  "description": "Use Fastify as the core web server for APIs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,9 +16,9 @@
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.11",
20
- "@twin.org/api-models": "0.0.2-next.11",
21
- "@twin.org/api-processors": "0.0.2-next.11",
19
+ "@twin.org/api-core": "0.0.2-next.13",
20
+ "@twin.org/api-models": "0.0.2-next.13",
21
+ "@twin.org/api-processors": "0.0.2-next.13",
22
22
  "@twin.org/core": "next",
23
23
  "@twin.org/logging-models": "next",
24
24
  "@twin.org/nameof": "next",
@@ -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
  }