@event-driven-io/emmett-fastify 0.20.2-alpha2 → 0.21.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/dist/index.cjs +55 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +55 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,56 @@
|
|
|
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; }
|
|
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
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
exports.getApplication = getApplication; exports.startAPI = startAPI;
|
|
2
56
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["
|
|
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"]}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import Compress from "@fastify/compress";
|
|
3
|
+
import Etag from "@fastify/etag";
|
|
4
|
+
import Form from "@fastify/formbody";
|
|
5
|
+
import closeWithGrace from "close-with-grace";
|
|
6
|
+
import Fastify from "fastify";
|
|
7
|
+
var defaultPlugins = [
|
|
8
|
+
{ plugin: Etag, options: {} },
|
|
9
|
+
{ plugin: Compress, options: { global: false } },
|
|
10
|
+
{ plugin: Form, 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 = 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;
|
|
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 ${address?.address}:${address?.port}`);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
app.log.error(err);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
getApplication,
|
|
54
|
+
startAPI
|
|
55
|
+
};
|
|
2
56
|
//# 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,
|
|
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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AAE;AAAA,EACxE,SAAS,KAAK;AACZ,QAAI,IAAI,MAAM,GAAG;AACjB,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":["options"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@event-driven-io/emmett-fastify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Emmett - Event Sourcing development made simple",
|
|
6
6
|
"scripts": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {},
|
|
54
54
|
"devDependencies": {},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@event-driven-io/emmett": "0.
|
|
56
|
+
"@event-driven-io/emmett": "0.21.0",
|
|
57
57
|
"fastify": "^4.28.1",
|
|
58
58
|
"@fastify/compress": "^7.0.3",
|
|
59
59
|
"@fastify/etag": "^5.2.0",
|