@alterior/fastify 3.4.0 → 3.5.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.
@@ -1,17 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import fastify from "fastify";
3
- import { WebEvent, WebServerEngine, WebServerOptions, ConnectMiddleware } from '@alterior/web-server';
3
+ import { WebEvent, WebServerEngine, ConnectMiddleware } from '@alterior/web-server';
4
4
  import * as http from 'http';
5
5
  export type FastifyConnectMiddleware = ConnectMiddleware & fastify.FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse>;
6
- export declare class FastifyEngine implements WebServerEngine {
7
- app: FastifyConnectMiddleware;
8
- providers: any[];
6
+ export declare class FastifyEngine extends WebServerEngine {
7
+ readonly app: ConnectMiddleware & fastify.FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>> & fastify.FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>>;
8
+ readonly providers: any[];
9
9
  sendJsonBody(routeEvent: WebEvent, body: any): void;
10
- private readonly supportedMethods;
11
- private getRegistrarName;
12
10
  addConnectMiddleware(path: string, middleware: any): void;
13
- listen(options: WebServerOptions): Promise<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>>;
14
11
  addRoute(method: string, path: string, handler: (event: WebEvent) => void, middleware?: any): void;
15
12
  addAnyRoute(handler: (event: WebEvent) => void): void;
13
+ private getRegistrarName;
16
14
  }
17
15
  //# sourceMappingURL=fastify-engine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastify-engine.d.ts","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":";AAAA,OAAO,OAA4B,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC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U,EAAG,QAAQ,EAAE,IAAI,EAAG,GAAG;IAKvD,oBAAoB,CAAC,IAAI,EAAG,MAAM,EAAE,UAAU,EAAG,GAAG;IAIpD,QAAQ,CAAC,MAAM,EAAG,MAAM,EAAE,IAAI,EAAG,MAAM,EAAE,OAAO,EAAG,CAAC,KAAK,EAAG,QAAQ,KAAK,IAAI,EAAE,UAAU,CAAC,KAAA;IAY1F,WAAW,CAAC,OAAO,EAAG,CAAC,KAAK,EAAG,QAAQ,KAAK,IAAI;IAIhD,OAAO,CAAC,gBAAgB;CAOxB"}
@@ -4,38 +4,18 @@ exports.FastifyEngine = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fastify_1 = tslib_1.__importDefault(require("fastify"));
6
6
  const web_server_1 = require("@alterior/web-server");
7
- class FastifyEngine {
7
+ class FastifyEngine extends web_server_1.WebServerEngine {
8
8
  constructor() {
9
+ super(...arguments);
9
10
  this.app = (0, fastify_1.default)();
10
11
  this.providers = [];
11
- this.supportedMethods = [
12
- "checkout", "copy", "delete", "get", "head", "lock", "merge",
13
- "mkactivity", "mkcol", "move", "m-search", "notify", "options",
14
- "patch", "post", "purge", "put", "report", "search", "subscribe",
15
- "trace", "unlock", "unsubscribe",
16
- ];
17
12
  }
18
13
  sendJsonBody(routeEvent, body) {
19
14
  routeEvent.response.setHeader('Content-Type', 'application/json');
20
15
  routeEvent.response['send'](body);
21
16
  }
22
- getRegistrarName(method) {
23
- let registrar = method.toLowerCase();
24
- if (!this.supportedMethods.includes(registrar))
25
- throw new Error(`The specified method '${method}' is not supported by Express.`);
26
- return registrar;
27
- }
28
17
  addConnectMiddleware(path, middleware) {
29
- // TODO: bodyParser.json() cannot be used with fastify
30
- if (middleware.name === 'jsonParser')
31
- return;
32
- this.app['use'](path, middleware);
33
- }
34
- listen(options) {
35
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
36
- yield this.app.listen(options.port);
37
- return this.app.server;
38
- });
18
+ this.app.use(path, middleware);
39
19
  }
40
20
  addRoute(method, path, handler, middleware) {
41
21
  if (!middleware)
@@ -47,6 +27,12 @@ class FastifyEngine {
47
27
  addAnyRoute(handler) {
48
28
  this.app.use((req, res) => handler(new web_server_1.WebEvent(req, res)));
49
29
  }
30
+ getRegistrarName(method) {
31
+ let registrar = method.toLowerCase();
32
+ if (!this.supportedMethods.includes(registrar))
33
+ throw new Error(`The specified method '${method}' is not supported by Express.`);
34
+ return registrar;
35
+ }
50
36
  }
51
37
  exports.FastifyEngine = FastifyEngine;
52
38
  //# sourceMappingURL=fastify-engine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastify-engine.js","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":";;;;AAAA,8DAAmD;AACnD,qDAAsG;AAKtG,MAAa,aAAa;IAA1B;QACC,QAAG,GAA6B,IAAA,iBAAO,GAAE,CAAC;QAE1C,cAAS,GAAG,EAAE,CAAC;QAOE,qBAAgB,GAAG;YACnC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;YAC5D,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS;YAC9D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW;YAChE,OAAO,EAAE,QAAQ,EAAE,aAAa;SAChC,CAAC;IAuCH,CAAC;IAjDA,YAAY,CAAC,UAAqB,EAAE,IAAU;QAC7C,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAClE,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IASO,gBAAgB,CAAC,MAAe;QACvC,IAAI,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,C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}
@@ -1,17 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import fastify from "fastify";
3
- import { WebEvent, WebServerEngine, WebServerOptions, ConnectMiddleware } from '@alterior/web-server';
3
+ import { WebEvent, WebServerEngine, ConnectMiddleware } from '@alterior/web-server';
4
4
  import * as http from 'http';
5
5
  export type FastifyConnectMiddleware = ConnectMiddleware & fastify.FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse>;
6
- export declare class FastifyEngine implements WebServerEngine {
7
- app: FastifyConnectMiddleware;
8
- providers: any[];
6
+ export declare class FastifyEngine extends WebServerEngine {
7
+ readonly app: ConnectMiddleware & fastify.FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>> & fastify.FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>>;
8
+ readonly providers: any[];
9
9
  sendJsonBody(routeEvent: WebEvent, body: any): void;
10
- private readonly supportedMethods;
11
- private getRegistrarName;
12
10
  addConnectMiddleware(path: string, middleware: any): void;
13
- listen(options: WebServerOptions): Promise<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>>;
14
11
  addRoute(method: string, path: string, handler: (event: WebEvent) => void, middleware?: any): void;
15
12
  addAnyRoute(handler: (event: WebEvent) => void): void;
13
+ private getRegistrarName;
16
14
  }
17
15
  //# sourceMappingURL=fastify-engine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastify-engine.d.ts","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":";AAAA,OAAO,OAA4B,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtG,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,GAAG,OAAO,CAAC,eAAe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D,QAAQ,CAAC,MAAM,EAAG,MAAM,EAAE,IAAI,EAAG,MAAM,EAAE,OAAO,EAAG,CAAC,KAAK,EAAG,QAAQ,KAAK,IAAI,EAAE,UAAU,CAAC,KAAA;IAY1F,WAAW,CAAC,OAAO,EAAG,CAAC,KAAK,EAAG,QAAQ,KAAK,IAAI;IAIhD,OAAO,CAAC,gBAAgB;CAOxB"}
@@ -1,38 +1,17 @@
1
- import { __awaiter } from "tslib";
2
1
  import fastify from "fastify";
3
- import { WebEvent } from '@alterior/web-server';
4
- export class FastifyEngine {
2
+ import { WebEvent, WebServerEngine } from '@alterior/web-server';
3
+ export class FastifyEngine extends WebServerEngine {
5
4
  constructor() {
5
+ super(...arguments);
6
6
  this.app = fastify();
7
7
  this.providers = [];
8
- this.supportedMethods = [
9
- "checkout", "copy", "delete", "get", "head", "lock", "merge",
10
- "mkactivity", "mkcol", "move", "m-search", "notify", "options",
11
- "patch", "post", "purge", "put", "report", "search", "subscribe",
12
- "trace", "unlock", "unsubscribe",
13
- ];
14
8
  }
15
9
  sendJsonBody(routeEvent, body) {
16
10
  routeEvent.response.setHeader('Content-Type', 'application/json');
17
11
  routeEvent.response['send'](body);
18
12
  }
19
- getRegistrarName(method) {
20
- let registrar = method.toLowerCase();
21
- if (!this.supportedMethods.includes(registrar))
22
- throw new Error(`The specified method '${method}' is not supported by Express.`);
23
- return registrar;
24
- }
25
13
  addConnectMiddleware(path, middleware) {
26
- // TODO: bodyParser.json() cannot be used with fastify
27
- if (middleware.name === 'jsonParser')
28
- return;
29
- this.app['use'](path, middleware);
30
- }
31
- listen(options) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- yield this.app.listen(options.port);
34
- return this.app.server;
35
- });
14
+ this.app.use(path, middleware);
36
15
  }
37
16
  addRoute(method, path, handler, middleware) {
38
17
  if (!middleware)
@@ -44,5 +23,11 @@ export class FastifyEngine {
44
23
  addAnyRoute(handler) {
45
24
  this.app.use((req, res) => handler(new WebEvent(req, res)));
46
25
  }
26
+ getRegistrarName(method) {
27
+ let registrar = method.toLowerCase();
28
+ if (!this.supportedMethods.includes(registrar))
29
+ throw new Error(`The specified method '${method}' is not supported by Express.`);
30
+ return registrar;
31
+ }
47
32
  }
48
33
  //# sourceMappingURL=fastify-engine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastify-engine.js","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":";AAAA,OAAO,OAA4B,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAwD,MAAM,sBAAsB,CAAC;AAKtG,MAAM,OAAO,aAAa;IAA1B;QACC,QAAG,GAA6B,OAAO,EAAE,CAAC;QAE1C,cAAS,GAAG,EAAE,CAAC;QAOE,qBAAgB,GAAG;YACnC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;YAC5D,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS;YAC9D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW;YAChE,OAAO,EAAE,QAAQ,EAAE,aAAa;SAChC,CAAC;IAuCH,CAAC;IAjDA,YAAY,CAAC,UAAqB,EAAE,IAAU;QAC7C,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAClE,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IASO,gBAAgB,CAAC,MAAe;QACvC,IAAI,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,gCAAgC,CAAC,CAAC;QAElF,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,oBA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3
+ "version": "3.5.0",
4
4
  "description": "Access Fastify state within an Alterior app",
5
5
  "author": "The Alterior Project (https://github.com/alterior-mvc)",
6
6
  "license": "MIT",
@@ -37,8 +37,9 @@
37
37
  "docs": "typedoc ."
38
38
  },
39
39
  "dependencies": {
40
- "@alterior/web-server": "^3.4.0",
40
+ "@alterior/logging": "^3.5.0",
41
+ "@alterior/web-server": "^3.5.0",
41
42
  "fastify": "^2.15.3"
42
43
  },
43
- "gitHead": "33b7ce9fa0c1cd53a4a7b46f948be3ffa3e54132"
44
+ "gitHead": "1fb8fea8c8d957fe543f7b6f69ae99c6bcc20156"
44
45
  }
@@ -1,48 +1,23 @@
1
1
  import fastify, { FastifyInstance } from "fastify";
2
- import { WebEvent, WebServerEngine, WebServerOptions, ConnectMiddleware } from '@alterior/web-server';
2
+ import { WebEvent, WebServerEngine, ConnectMiddleware } from '@alterior/web-server';
3
+
3
4
  import * as http from 'http';
4
5
 
5
6
  export type FastifyConnectMiddleware = ConnectMiddleware & fastify.FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse>;
6
7
 
7
- export class FastifyEngine implements WebServerEngine {
8
- app = <FastifyConnectMiddleware>fastify();
9
-
10
- providers = [];
8
+ export class FastifyEngine extends WebServerEngine {
9
+ readonly app = <FastifyConnectMiddleware & FastifyInstance>fastify();
10
+ readonly providers = [];
11
11
 
12
- sendJsonBody(routeEvent : WebEvent, body : any) {
12
+ override sendJsonBody(routeEvent : WebEvent, body : any) {
13
13
  routeEvent.response.setHeader('Content-Type', 'application/json');
14
14
  routeEvent.response['send'](body);
15
15
  }
16
-
17
- private readonly supportedMethods = [
18
- "checkout", "copy", "delete", "get", "head", "lock", "merge",
19
- "mkactivity", "mkcol", "move", "m-search", "notify", "options",
20
- "patch", "post", "purge", "put", "report", "search", "subscribe",
21
- "trace", "unlock", "unsubscribe",
22
- ];
23
-
24
- private getRegistrarName(method : string) {
25
- let registrar = method.toLowerCase();
26
- if (!this.supportedMethods.includes(registrar))
27
- throw new Error(`The specified method '${method}' is not supported by Express.`);
28
-
29
- return registrar;
30
- }
31
16
 
32
17
  addConnectMiddleware(path : string, middleware : any) {
33
-
34
- // TODO: bodyParser.json() cannot be used with fastify
35
- if (middleware.name === 'jsonParser')
36
- return;
37
-
38
- this.app['use'](path, middleware);
18
+ this.app.use(path, middleware);
39
19
  }
40
20
 
41
- async listen(options : WebServerOptions) {
42
- await this.app.listen(options.port);
43
- return this.app.server;
44
- }
45
-
46
21
  addRoute(method : string, path : string, handler : (event : WebEvent) => void, middleware?) {
47
22
  if (!middleware)
48
23
  middleware = [];
@@ -58,4 +33,12 @@ export class FastifyEngine implements WebServerEngine {
58
33
  addAnyRoute(handler : (event : WebEvent) => void) {
59
34
  this.app.use((req, res) => handler(new WebEvent(<any>req, <any>res)));
60
35
  }
36
+
37
+ private getRegistrarName(method : string) {
38
+ let registrar = method.toLowerCase();
39
+ if (!this.supportedMethods.includes(registrar))
40
+ throw new Error(`The specified method '${method}' is not supported by Express.`);
41
+
42
+ return registrar;
43
+ }
61
44
  }