@event-driven-io/emmett-fastify 0.43.0-beta.13 → 0.43.0-beta.15

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/index.cjs CHANGED
@@ -1,56 +1,87 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
2
- var _compress = require('@fastify/compress'); var _compress2 = _interopRequireDefault(_compress);
3
- var _etag = require('@fastify/etag'); var _etag2 = _interopRequireDefault(_etag);
4
- var _formbody = require('@fastify/formbody'); var _formbody2 = _interopRequireDefault(_formbody);
5
- var _closewithgrace = require('close-with-grace'); var _closewithgrace2 = _interopRequireDefault(_closewithgrace);
6
- var _fastify = require('fastify'); var _fastify2 = _interopRequireDefault(_fastify);
7
- var defaultPlugins = [
8
- { plugin: _etag2.default, options: {} },
9
- { plugin: _compress2.default, options: { global: false } },
10
- { plugin: _formbody2.default, options: {} }
11
- ];
12
- var getApplication = async (options) => {
13
- const {
14
- registerRoutes,
15
- activeDefaultPlugins = defaultPlugins,
16
- serverOptions = {
17
- logger: true
18
- }
19
- } = options;
20
- const app = _fastify2.default.call(void 0, serverOptions);
21
- await Promise.all(
22
- activeDefaultPlugins.map(async ({ plugin, options: options2 }) => {
23
- await app.register(plugin, options2);
24
- })
25
- );
26
- if (registerRoutes) {
27
- registerRoutes(app);
28
- }
29
- const closeListeners = _closewithgrace2.default.call(void 0, { delay: 500 }, async (opts) => {
30
- if (opts.err) {
31
- app.log.error(opts.err);
32
- }
33
- await app.close();
34
- });
35
- app.addHook("onClose", (instance, done) => {
36
- closeListeners.uninstall();
37
- done();
38
- });
39
- return app;
40
- };
41
- var startAPI = async (app, options = { port: 5e3 }) => {
42
- const { port } = options;
43
- try {
44
- await app.listen({ port });
45
- const address = app.server.address();
46
- console.log(`Server listening on ${_optionalChain([address, 'optionalAccess', _ => _.address])}:${_optionalChain([address, 'optionalAccess', _2 => _2.port])}`);
47
- } catch (err) {
48
- app.log.error(err);
49
- process.exit(1);
50
- }
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
51
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
52
27
 
28
+ //#endregion
29
+ let _fastify_compress = require("@fastify/compress");
30
+ _fastify_compress = __toESM(_fastify_compress, 1);
31
+ let _fastify_etag = require("@fastify/etag");
32
+ _fastify_etag = __toESM(_fastify_etag, 1);
33
+ let _fastify_formbody = require("@fastify/formbody");
34
+ _fastify_formbody = __toESM(_fastify_formbody, 1);
35
+ let close_with_grace = require("close-with-grace");
36
+ close_with_grace = __toESM(close_with_grace, 1);
37
+ let fastify = require("fastify");
38
+ fastify = __toESM(fastify, 1);
53
39
 
40
+ //#region src/index.ts
41
+ const defaultPlugins = [
42
+ {
43
+ plugin: _fastify_etag.default,
44
+ options: {}
45
+ },
46
+ {
47
+ plugin: _fastify_compress.default,
48
+ options: { global: false }
49
+ },
50
+ {
51
+ plugin: _fastify_formbody.default,
52
+ options: {}
53
+ }
54
+ ];
55
+ const getApplication = async (options) => {
56
+ const { registerRoutes, activeDefaultPlugins = defaultPlugins, serverOptions = { logger: true } } = options;
57
+ const app = (0, fastify.default)(serverOptions);
58
+ await Promise.all(activeDefaultPlugins.map(async ({ plugin, options }) => {
59
+ await app.register(plugin, options);
60
+ }));
61
+ if (registerRoutes) registerRoutes(app);
62
+ const closeListeners = (0, close_with_grace.default)({ delay: 500 }, async (opts) => {
63
+ if (opts.err) app.log.error(opts.err);
64
+ await app.close();
65
+ });
66
+ app.addHook("onClose", (instance, done) => {
67
+ closeListeners.uninstall();
68
+ done();
69
+ });
70
+ return app;
71
+ };
72
+ const startAPI = async (app, options = { port: 5e3 }) => {
73
+ const { port } = options;
74
+ try {
75
+ await app.listen({ port });
76
+ const address = app.server.address();
77
+ console.log(`Server listening on ${address?.address}:${address?.port}`);
78
+ } catch (err) {
79
+ app.log.error(err);
80
+ process.exit(1);
81
+ }
82
+ };
54
83
 
55
- exports.getApplication = getApplication; exports.startAPI = startAPI;
84
+ //#endregion
85
+ exports.getApplication = getApplication;
86
+ exports.startAPI = startAPI;
56
87
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/emmett/emmett/src/packages/emmett-fastify/dist/index.cjs","../src/index.ts"],"names":["options"],"mappings":"AAAA;ACAA,iGAAsD;AACtD,iFAA8C;AAC9C,iGAAkD;AAClD,kHAA2B;AAC3B,oFAKO;AAQP,IAAM,eAAA,EAA2B;AAAA,EAC/B,EAAE,MAAA,EAAQ,cAAA,EAAM,OAAA,EAAS,CAAC,EAAwB,CAAA;AAAA,EAClD,EAAE,MAAA,EAAQ,kBAAA,EAAU,OAAA,EAAS,EAAE,MAAA,EAAQ,MAAM,EAA4B,CAAA;AAAA,EACzE,EAAE,MAAA,EAAQ,kBAAA,EAAM,OAAA,EAAS,CAAC,EAA4B;AACxD,CAAA;AAQO,IAAM,eAAA,EAAiB,MAAA,CAAO,OAAA,EAAA,GAAgC;AACnE,EAAA,MAAM;AAAA,IACJ,cAAA;AAAA,IACA,qBAAA,EAAuB,cAAA;AAAA,IACvB,cAAA,EAAgB;AAAA,MACd,MAAA,EAAQ;AAAA,IACV;AAAA,EACF,EAAA,EAAI,OAAA;AAEJ,EAAA,MAAM,IAAA,EAAuB,+BAAA,aAAqB,CAAA;AAElD,EAAA,MAAM,OAAA,CAAQ,GAAA;AAAA,IACZ,oBAAA,CAAqB,GAAA,CAAI,MAAA,CAAO,EAAE,MAAA,EAAQ,OAAA,EAAAA,SAAQ,CAAA,EAAA,GAAM;AACtD,MAAA,MAAM,GAAA,CAAI,QAAA,CAAS,MAAA,EAAQA,QAAO,CAAA;AAAA,IACpC,CAAC;AAAA,EACH,CAAA;AAEA,EAAA,GAAA,CAAI,cAAA,EAAgB;AAClB,IAAA,cAAA,CAAe,GAAG,CAAA;AAAA,EACpB;AAEA,EAAA,MAAM,eAAA,EAAiB,sCAAA,EAAiB,KAAA,EAAO,IAAI,CAAA,EAAG,MAAA,CAAO,IAAA,EAAA,GAAS;AACpE,IAAA,GAAA,CAAI,IAAA,CAAK,GAAA,EAAK;AACZ,MAAA,GAAA,CAAI,GAAA,CAAI,KAAA,CAAM,IAAA,CAAK,GAAG,CAAA;AAAA,IACxB;AAEA,IAAA,MAAM,GAAA,CAAI,KAAA,CAAM,CAAA;AAAA,EAClB,CAAC,CAAA;AAED,EAAA,GAAA,CAAI,OAAA,CAAQ,SAAA,EAAW,CAAC,QAAA,EAAU,IAAA,EAAA,GAAS;AACzC,IAAA,cAAA,CAAe,SAAA,CAAU,CAAA;AACzB,IAAA,IAAA,CAAK,CAAA;AAAA,EACP,CAAC,CAAA;AAED,EAAA,OAAO,GAAA;AACT,CAAA;AAMO,IAAM,SAAA,EAAW,MAAA,CACtB,GAAA,EACA,QAAA,EAA2B,EAAE,IAAA,EAAM,IAAK,CAAA,EAAA,GACrC;AACH,EAAA,MAAM,EAAE,KAAK,EAAA,EAAI,OAAA;AACjB,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,CAAI,MAAA,CAAO,EAAE,KAAK,CAAC,CAAA;AACzB,IAAA,MAAM,QAAA,EAAU,GAAA,CAAI,MAAA,CAAO,OAAA,CAAQ,CAAA;AAEnC,IAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,oBAAA,kBAAuB,OAAA,2BAAS,SAAO,CAAA,CAAA,kBAAI,OAAA,6BAAS,MAAI,CAAA,CAAA;AACxD,EAAA;AACK,IAAA;AACH,IAAA;AAChB,EAAA;AACF;ADjCyE;AACA;AACA;AACA","file":"/home/runner/work/emmett/emmett/src/packages/emmett-fastify/dist/index.cjs","sourcesContent":[null,"import Compress, { type FastifyCompressOptions } from '@fastify/compress';\nimport Etag, { type FastifyEtagOptions } from '@fastify/etag';\nimport Form, { type FastifyFormbodyOptions } from '@fastify/formbody';\nimport closeWithGrace from 'close-with-grace';\nimport Fastify, {\n type FastifyInstance,\n type FastifyPluginAsync,\n type FastifyPluginCallback,\n type FastifyPluginOptions,\n} from 'fastify';\n\n// TODO: THIS WILL NEED TO BE BETTER TYPED\ntype Plugin = {\n plugin: FastifyPluginAsync | FastifyPluginCallback;\n options: FastifyPluginOptions;\n};\n\nconst defaultPlugins: Plugin[] = [\n { plugin: Etag, options: {} as FastifyEtagOptions },\n { plugin: Compress, options: { global: false } as FastifyCompressOptions },\n { plugin: Form, options: {} as FastifyFormbodyOptions },\n];\n\nexport interface ApplicationOptions {\n serverOptions?: { logger: boolean };\n registerRoutes?: (app: FastifyInstance) => void;\n activeDefaultPlugins?: Plugin[];\n}\n\nexport const getApplication = async (options: ApplicationOptions) => {\n const {\n registerRoutes,\n activeDefaultPlugins = defaultPlugins,\n serverOptions = {\n logger: true,\n },\n } = options;\n\n const app: FastifyInstance = Fastify(serverOptions);\n\n await Promise.all(\n activeDefaultPlugins.map(async ({ plugin, options }) => {\n await app.register(plugin, options);\n }),\n );\n\n if (registerRoutes) {\n registerRoutes(app);\n }\n\n const closeListeners = closeWithGrace({ delay: 500 }, async (opts) => {\n if (opts.err) {\n app.log.error(opts.err);\n }\n\n await app.close();\n });\n\n app.addHook('onClose', (instance, done) => {\n closeListeners.uninstall();\n done();\n });\n\n return app;\n};\n\nexport type StartApiOptions = {\n port?: number;\n};\n\nexport const startAPI = async (\n app: FastifyInstance,\n options: StartApiOptions = { port: 5000 },\n) => {\n const { port } = options;\n try {\n await app.listen({ port });\n const address = app.server.address() as { address: string; port: number };\n\n console.log(`Server listening on ${address?.address}:${address?.port}`);\n } catch (err) {\n app.log.error(err);\n process.exit(1);\n }\n};\n"]}
1
+ {"version":3,"file":"index.cjs","names":["Etag","Compress","Form"],"sources":["../src/index.ts"],"sourcesContent":["import Compress from '@fastify/compress';\nimport Etag from '@fastify/etag';\nimport Form from '@fastify/formbody';\nimport closeWithGrace from 'close-with-grace';\nimport Fastify, {\n type FastifyInstance,\n type FastifyPluginAsync,\n type FastifyPluginCallback,\n type FastifyPluginOptions,\n} from 'fastify';\n\n// TODO: THIS WILL NEED TO BE BETTER TYPED\ntype Plugin = {\n plugin: FastifyPluginAsync | FastifyPluginCallback;\n options: FastifyPluginOptions;\n};\n\nconst defaultPlugins: Plugin[] = [\n { plugin: Etag, options: {} },\n { plugin: Compress, options: { global: false } },\n { plugin: Form, options: {} },\n];\n\nexport interface ApplicationOptions {\n serverOptions?: { logger: boolean };\n registerRoutes?: (app: FastifyInstance) => void;\n activeDefaultPlugins?: Plugin[];\n}\n\nexport const getApplication = async (options: ApplicationOptions) => {\n const {\n registerRoutes,\n activeDefaultPlugins = defaultPlugins,\n serverOptions = {\n logger: true,\n },\n } = options;\n\n const app: FastifyInstance = Fastify(serverOptions);\n\n await Promise.all(\n activeDefaultPlugins.map(async ({ plugin, options }) => {\n await app.register(plugin, options);\n }),\n );\n\n if (registerRoutes) {\n registerRoutes(app);\n }\n\n const closeListeners = closeWithGrace({ delay: 500 }, async (opts) => {\n if (opts.err) {\n app.log.error(opts.err);\n }\n\n await app.close();\n });\n\n app.addHook('onClose', (instance, done) => {\n closeListeners.uninstall();\n done();\n });\n\n return app;\n};\n\nexport type StartApiOptions = {\n port?: number;\n};\n\nexport const startAPI = async (\n app: FastifyInstance,\n options: StartApiOptions = { port: 5000 },\n) => {\n const { port } = options;\n try {\n await app.listen({ port });\n const address = app.server.address() as { address: string; port: number };\n\n console.log(`Server listening on ${address?.address}:${address?.port}`);\n } catch (err) {\n app.log.error(err);\n process.exit(1);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,iBAA2B;CAC/B;EAAE,QAAQA;EAAM,SAAS,EAAE;EAAE;CAC7B;EAAE,QAAQC;EAAU,SAAS,EAAE,QAAQ,OAAO;EAAE;CAChD;EAAE,QAAQC;EAAM,SAAS,EAAE;EAAE;CAC9B;AAQD,MAAa,iBAAiB,OAAO,YAAgC;CACnE,MAAM,EACJ,gBACA,uBAAuB,gBACvB,gBAAgB,EACd,QAAQ,MACT,KACC;CAEJ,MAAM,2BAA+B,cAAc;AAEnD,OAAM,QAAQ,IACZ,qBAAqB,IAAI,OAAO,EAAE,QAAQ,cAAc;AACtD,QAAM,IAAI,SAAS,QAAQ,QAAQ;GACnC,CACH;AAED,KAAI,eACF,gBAAe,IAAI;CAGrB,MAAM,+CAAgC,EAAE,OAAO,KAAK,EAAE,OAAO,SAAS;AACpE,MAAI,KAAK,IACP,KAAI,IAAI,MAAM,KAAK,IAAI;AAGzB,QAAM,IAAI,OAAO;GACjB;AAEF,KAAI,QAAQ,YAAY,UAAU,SAAS;AACzC,iBAAe,WAAW;AAC1B,QAAM;GACN;AAEF,QAAO;;AAOT,MAAa,WAAW,OACtB,KACA,UAA2B,EAAE,MAAM,KAAM,KACtC;CACH,MAAM,EAAE,SAAS;AACjB,KAAI;AACF,QAAM,IAAI,OAAO,EAAE,MAAM,CAAC;EAC1B,MAAM,UAAU,IAAI,OAAO,SAAS;AAEpC,UAAQ,IAAI,uBAAuB,SAAS,QAAQ,GAAG,SAAS,OAAO;UAChE,KAAK;AACZ,MAAI,IAAI,MAAM,IAAI;AAClB,UAAQ,KAAK,EAAE"}
package/dist/index.d.cts CHANGED
@@ -1,22 +1,24 @@
1
- import * as node_http from 'node:http';
2
- import * as fastify from 'fastify';
3
- import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from 'fastify';
1
+ import * as _$fastify from "fastify";
2
+ import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from "fastify";
3
+ import * as _$node_http0 from "node:http";
4
4
 
5
+ //#region src/index.d.ts
5
6
  type Plugin = {
6
- plugin: FastifyPluginAsync | FastifyPluginCallback;
7
- options: FastifyPluginOptions;
7
+ plugin: FastifyPluginAsync | FastifyPluginCallback;
8
+ options: FastifyPluginOptions;
8
9
  };
9
10
  interface ApplicationOptions {
10
- serverOptions?: {
11
- logger: boolean;
12
- };
13
- registerRoutes?: (app: FastifyInstance) => void;
14
- activeDefaultPlugins?: Plugin[];
11
+ serverOptions?: {
12
+ logger: boolean;
13
+ };
14
+ registerRoutes?: (app: FastifyInstance) => void;
15
+ activeDefaultPlugins?: Plugin[];
15
16
  }
16
- declare const getApplication: (options: ApplicationOptions) => Promise<FastifyInstance<fastify.RawServerDefault, node_http.IncomingMessage, node_http.ServerResponse<node_http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault>>;
17
+ declare const getApplication: (options: ApplicationOptions) => Promise<FastifyInstance<_$fastify.RawServerDefault, _$node_http0.IncomingMessage, _$node_http0.ServerResponse<_$node_http0.IncomingMessage>, _$fastify.FastifyBaseLogger, _$fastify.FastifyTypeProviderDefault>>;
17
18
  type StartApiOptions = {
18
- port?: number;
19
+ port?: number;
19
20
  };
20
21
  declare const startAPI: (app: FastifyInstance, options?: StartApiOptions) => Promise<void>;
21
-
22
- export { type ApplicationOptions, type StartApiOptions, getApplication, startAPI };
22
+ //#endregion
23
+ export { ApplicationOptions, StartApiOptions, getApplication, startAPI };
24
+ //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,22 +1,24 @@
1
- import * as node_http from 'node:http';
2
- import * as fastify from 'fastify';
3
- import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from 'fastify';
1
+ import * as _$fastify from "fastify";
2
+ import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from "fastify";
3
+ import * as _$node_http0 from "node:http";
4
4
 
5
+ //#region src/index.d.ts
5
6
  type Plugin = {
6
- plugin: FastifyPluginAsync | FastifyPluginCallback;
7
- options: FastifyPluginOptions;
7
+ plugin: FastifyPluginAsync | FastifyPluginCallback;
8
+ options: FastifyPluginOptions;
8
9
  };
9
10
  interface ApplicationOptions {
10
- serverOptions?: {
11
- logger: boolean;
12
- };
13
- registerRoutes?: (app: FastifyInstance) => void;
14
- activeDefaultPlugins?: Plugin[];
11
+ serverOptions?: {
12
+ logger: boolean;
13
+ };
14
+ registerRoutes?: (app: FastifyInstance) => void;
15
+ activeDefaultPlugins?: Plugin[];
15
16
  }
16
- declare const getApplication: (options: ApplicationOptions) => Promise<FastifyInstance<fastify.RawServerDefault, node_http.IncomingMessage, node_http.ServerResponse<node_http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault>>;
17
+ declare const getApplication: (options: ApplicationOptions) => Promise<FastifyInstance<_$fastify.RawServerDefault, _$node_http0.IncomingMessage, _$node_http0.ServerResponse<_$node_http0.IncomingMessage>, _$fastify.FastifyBaseLogger, _$fastify.FastifyTypeProviderDefault>>;
17
18
  type StartApiOptions = {
18
- port?: number;
19
+ port?: number;
19
20
  };
20
21
  declare const startAPI: (app: FastifyInstance, options?: StartApiOptions) => Promise<void>;
21
-
22
- export { type ApplicationOptions, type StartApiOptions, getApplication, startAPI };
22
+ //#endregion
23
+ export { ApplicationOptions, StartApiOptions, getApplication, startAPI };
24
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,56 +1,53 @@
1
- // src/index.ts
2
1
  import Compress from "@fastify/compress";
3
2
  import Etag from "@fastify/etag";
4
3
  import Form from "@fastify/formbody";
5
4
  import closeWithGrace from "close-with-grace";
6
5
  import Fastify from "fastify";
7
- var defaultPlugins = [
8
- { plugin: Etag, options: {} },
9
- { plugin: Compress, options: { global: false } },
10
- { plugin: Form, options: {} }
6
+
7
+ //#region src/index.ts
8
+ const defaultPlugins = [
9
+ {
10
+ plugin: Etag,
11
+ options: {}
12
+ },
13
+ {
14
+ plugin: Compress,
15
+ options: { global: false }
16
+ },
17
+ {
18
+ plugin: Form,
19
+ options: {}
20
+ }
11
21
  ];
12
- var getApplication = async (options) => {
13
- const {
14
- registerRoutes,
15
- activeDefaultPlugins = defaultPlugins,
16
- serverOptions = {
17
- logger: true
18
- }
19
- } = options;
20
- const app = Fastify(serverOptions);
21
- await Promise.all(
22
- activeDefaultPlugins.map(async ({ plugin, options: options2 }) => {
23
- await app.register(plugin, options2);
24
- })
25
- );
26
- if (registerRoutes) {
27
- registerRoutes(app);
28
- }
29
- const closeListeners = closeWithGrace({ delay: 500 }, async (opts) => {
30
- if (opts.err) {
31
- app.log.error(opts.err);
32
- }
33
- await app.close();
34
- });
35
- app.addHook("onClose", (instance, done) => {
36
- closeListeners.uninstall();
37
- done();
38
- });
39
- return app;
22
+ const getApplication = async (options) => {
23
+ const { registerRoutes, activeDefaultPlugins = defaultPlugins, serverOptions = { logger: true } } = options;
24
+ const app = Fastify(serverOptions);
25
+ await Promise.all(activeDefaultPlugins.map(async ({ plugin, options }) => {
26
+ await app.register(plugin, options);
27
+ }));
28
+ if (registerRoutes) registerRoutes(app);
29
+ const closeListeners = closeWithGrace({ delay: 500 }, async (opts) => {
30
+ if (opts.err) app.log.error(opts.err);
31
+ await app.close();
32
+ });
33
+ app.addHook("onClose", (instance, done) => {
34
+ closeListeners.uninstall();
35
+ done();
36
+ });
37
+ return app;
40
38
  };
41
- var startAPI = async (app, options = { port: 5e3 }) => {
42
- const { port } = options;
43
- try {
44
- await app.listen({ port });
45
- const address = app.server.address();
46
- console.log(`Server listening on ${address?.address}:${address?.port}`);
47
- } catch (err) {
48
- app.log.error(err);
49
- process.exit(1);
50
- }
51
- };
52
- export {
53
- getApplication,
54
- startAPI
39
+ const startAPI = async (app, options = { port: 5e3 }) => {
40
+ const { port } = options;
41
+ try {
42
+ await app.listen({ port });
43
+ const address = app.server.address();
44
+ console.log(`Server listening on ${address?.address}:${address?.port}`);
45
+ } catch (err) {
46
+ app.log.error(err);
47
+ process.exit(1);
48
+ }
55
49
  };
50
+
51
+ //#endregion
52
+ export { getApplication, startAPI };
56
53
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import Compress, { type FastifyCompressOptions } from '@fastify/compress';\nimport Etag, { type FastifyEtagOptions } from '@fastify/etag';\nimport Form, { type FastifyFormbodyOptions } from '@fastify/formbody';\nimport closeWithGrace from 'close-with-grace';\nimport Fastify, {\n type FastifyInstance,\n type FastifyPluginAsync,\n type FastifyPluginCallback,\n type FastifyPluginOptions,\n} from 'fastify';\n\n// TODO: THIS WILL NEED TO BE BETTER TYPED\ntype Plugin = {\n plugin: FastifyPluginAsync | FastifyPluginCallback;\n options: FastifyPluginOptions;\n};\n\nconst defaultPlugins: Plugin[] = [\n { plugin: Etag, options: {} as FastifyEtagOptions },\n { plugin: Compress, options: { global: false } as FastifyCompressOptions },\n { plugin: Form, options: {} as FastifyFormbodyOptions },\n];\n\nexport interface ApplicationOptions {\n serverOptions?: { logger: boolean };\n registerRoutes?: (app: FastifyInstance) => void;\n activeDefaultPlugins?: Plugin[];\n}\n\nexport const getApplication = async (options: ApplicationOptions) => {\n const {\n registerRoutes,\n activeDefaultPlugins = defaultPlugins,\n serverOptions = {\n logger: true,\n },\n } = options;\n\n const app: FastifyInstance = Fastify(serverOptions);\n\n await Promise.all(\n activeDefaultPlugins.map(async ({ plugin, options }) => {\n await app.register(plugin, options);\n }),\n );\n\n if (registerRoutes) {\n registerRoutes(app);\n }\n\n const closeListeners = closeWithGrace({ delay: 500 }, async (opts) => {\n if (opts.err) {\n app.log.error(opts.err);\n }\n\n await app.close();\n });\n\n app.addHook('onClose', (instance, done) => {\n closeListeners.uninstall();\n done();\n });\n\n return app;\n};\n\nexport type StartApiOptions = {\n port?: number;\n};\n\nexport const startAPI = async (\n app: FastifyInstance,\n options: StartApiOptions = { port: 5000 },\n) => {\n const { port } = options;\n try {\n await app.listen({ port });\n const address = app.server.address() as { address: string; port: number };\n\n console.log(`Server listening on ${address?.address}:${address?.port}`);\n } catch (err) {\n app.log.error(err);\n process.exit(1);\n }\n};\n"],"mappings":";AAAA,OAAO,cAA+C;AACtD,OAAO,UAAuC;AAC9C,OAAO,UAA2C;AAClD,OAAO,oBAAoB;AAC3B,OAAO,aAKA;AAQP,IAAM,iBAA2B;AAAA,EAC/B,EAAE,QAAQ,MAAM,SAAS,CAAC,EAAwB;AAAA,EAClD,EAAE,QAAQ,UAAU,SAAS,EAAE,QAAQ,MAAM,EAA4B;AAAA,EACzE,EAAE,QAAQ,MAAM,SAAS,CAAC,EAA4B;AACxD;AAQO,IAAM,iBAAiB,OAAO,YAAgC;AACnE,QAAM;AAAA,IACJ;AAAA,IACA,uBAAuB;AAAA,IACvB,gBAAgB;AAAA,MACd,QAAQ;AAAA,IACV;AAAA,EACF,IAAI;AAEJ,QAAM,MAAuB,QAAQ,aAAa;AAElD,QAAM,QAAQ;AAAA,IACZ,qBAAqB,IAAI,OAAO,EAAE,QAAQ,SAAAA,SAAQ,MAAM;AACtD,YAAM,IAAI,SAAS,QAAQA,QAAO;AAAA,IACpC,CAAC;AAAA,EACH;AAEA,MAAI,gBAAgB;AAClB,mBAAe,GAAG;AAAA,EACpB;AAEA,QAAM,iBAAiB,eAAe,EAAE,OAAO,IAAI,GAAG,OAAO,SAAS;AACpE,QAAI,KAAK,KAAK;AACZ,UAAI,IAAI,MAAM,KAAK,GAAG;AAAA,IACxB;AAEA,UAAM,IAAI,MAAM;AAAA,EAClB,CAAC;AAED,MAAI,QAAQ,WAAW,CAAC,UAAU,SAAS;AACzC,mBAAe,UAAU;AACzB,SAAK;AAAA,EACP,CAAC;AAED,SAAO;AACT;AAMO,IAAM,WAAW,OACtB,KACA,UAA2B,EAAE,MAAM,IAAK,MACrC;AACH,QAAM,EAAE,KAAK,IAAI;AACjB,MAAI;AACF,UAAM,IAAI,OAAO,EAAE,KAAK,CAAC;AACzB,UAAM,UAAU,IAAI,OAAO,QAAQ;AAEnC,YAAQ,IAAI,uBAAuB,SAAS,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACxE,SAAS,KAAK;AACZ,QAAI,IAAI,MAAM,GAAG;AACjB,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":["options"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import Compress from '@fastify/compress';\nimport Etag from '@fastify/etag';\nimport Form from '@fastify/formbody';\nimport closeWithGrace from 'close-with-grace';\nimport Fastify, {\n type FastifyInstance,\n type FastifyPluginAsync,\n type FastifyPluginCallback,\n type FastifyPluginOptions,\n} from 'fastify';\n\n// TODO: THIS WILL NEED TO BE BETTER TYPED\ntype Plugin = {\n plugin: FastifyPluginAsync | FastifyPluginCallback;\n options: FastifyPluginOptions;\n};\n\nconst defaultPlugins: Plugin[] = [\n { plugin: Etag, options: {} },\n { plugin: Compress, options: { global: false } },\n { plugin: Form, options: {} },\n];\n\nexport interface ApplicationOptions {\n serverOptions?: { logger: boolean };\n registerRoutes?: (app: FastifyInstance) => void;\n activeDefaultPlugins?: Plugin[];\n}\n\nexport const getApplication = async (options: ApplicationOptions) => {\n const {\n registerRoutes,\n activeDefaultPlugins = defaultPlugins,\n serverOptions = {\n logger: true,\n },\n } = options;\n\n const app: FastifyInstance = Fastify(serverOptions);\n\n await Promise.all(\n activeDefaultPlugins.map(async ({ plugin, options }) => {\n await app.register(plugin, options);\n }),\n );\n\n if (registerRoutes) {\n registerRoutes(app);\n }\n\n const closeListeners = closeWithGrace({ delay: 500 }, async (opts) => {\n if (opts.err) {\n app.log.error(opts.err);\n }\n\n await app.close();\n });\n\n app.addHook('onClose', (instance, done) => {\n closeListeners.uninstall();\n done();\n });\n\n return app;\n};\n\nexport type StartApiOptions = {\n port?: number;\n};\n\nexport const startAPI = async (\n app: FastifyInstance,\n options: StartApiOptions = { port: 5000 },\n) => {\n const { port } = options;\n try {\n await app.listen({ port });\n const address = app.server.address() as { address: string; port: number };\n\n console.log(`Server listening on ${address?.address}:${address?.port}`);\n } catch (err) {\n app.log.error(err);\n process.exit(1);\n }\n};\n"],"mappings":";;;;;;;AAiBA,MAAM,iBAA2B;CAC/B;EAAE,QAAQ;EAAM,SAAS,EAAE;EAAE;CAC7B;EAAE,QAAQ;EAAU,SAAS,EAAE,QAAQ,OAAO;EAAE;CAChD;EAAE,QAAQ;EAAM,SAAS,EAAE;EAAE;CAC9B;AAQD,MAAa,iBAAiB,OAAO,YAAgC;CACnE,MAAM,EACJ,gBACA,uBAAuB,gBACvB,gBAAgB,EACd,QAAQ,MACT,KACC;CAEJ,MAAM,MAAuB,QAAQ,cAAc;AAEnD,OAAM,QAAQ,IACZ,qBAAqB,IAAI,OAAO,EAAE,QAAQ,cAAc;AACtD,QAAM,IAAI,SAAS,QAAQ,QAAQ;GACnC,CACH;AAED,KAAI,eACF,gBAAe,IAAI;CAGrB,MAAM,iBAAiB,eAAe,EAAE,OAAO,KAAK,EAAE,OAAO,SAAS;AACpE,MAAI,KAAK,IACP,KAAI,IAAI,MAAM,KAAK,IAAI;AAGzB,QAAM,IAAI,OAAO;GACjB;AAEF,KAAI,QAAQ,YAAY,UAAU,SAAS;AACzC,iBAAe,WAAW;AAC1B,QAAM;GACN;AAEF,QAAO;;AAOT,MAAa,WAAW,OACtB,KACA,UAA2B,EAAE,MAAM,KAAM,KACtC;CACH,MAAM,EAAE,SAAS;AACjB,KAAI;AACF,QAAM,IAAI,OAAO,EAAE,MAAM,CAAC;EAC1B,MAAM,UAAU,IAAI,OAAO,SAAS;AAEpC,UAAQ,IAAI,uBAAuB,SAAS,QAAQ,GAAG,SAAS,OAAO;UAChE,KAAK;AACZ,MAAI,IAAI,MAAM,IAAI;AAClB,UAAQ,KAAK,EAAE"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@event-driven-io/emmett-fastify",
3
- "version": "0.43.0-beta.13",
3
+ "version": "0.43.0-beta.15",
4
4
  "type": "module",
5
5
  "description": "Emmett - Event Sourcing development made simple",
6
6
  "scripts": {
7
- "build": "tsup",
7
+ "build": "tsdown",
8
8
  "build:ts": "tsc",
9
9
  "build:ts:watch": "tsc -b --watch",
10
10
  "test": "run-s test:unit test:int test:e2e",
@@ -53,11 +53,11 @@
53
53
  "dependencies": {},
54
54
  "devDependencies": {},
55
55
  "peerDependencies": {
56
- "@event-driven-io/emmett": "0.43.0-beta.13",
57
- "fastify": "^5.7.2",
56
+ "@event-driven-io/emmett": "0.43.0-beta.15",
57
+ "fastify": "^5.8.5",
58
58
  "@fastify/compress": "^8.3.1",
59
59
  "@fastify/etag": "^6.1.0",
60
60
  "@fastify/formbody": "^8.0.2",
61
- "close-with-grace": "^2.4.0"
61
+ "close-with-grace": "^2.5.0"
62
62
  }
63
63
  }