@gasket/plugin-fastify 7.5.1 → 8.0.0-next.1

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/lib/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  /// <reference types="@gasket/core" />
2
2
  /// <reference types="@gasket/plugin-metadata" />
3
3
 
4
- import create from './create.js';
5
4
  import createServers from './create-servers.js';
6
5
  import actions from './actions.js';
7
6
  import packageJson from '../package.json' with { type: 'json' };
@@ -14,7 +13,6 @@ const plugin = {
14
13
  description,
15
14
  actions,
16
15
  hooks: {
17
- create,
18
16
  createServers,
19
17
  metadata(gasket, meta) {
20
18
  return {
package/package.json CHANGED
@@ -1,12 +1,10 @@
1
1
  {
2
2
  "name": "@gasket/plugin-fastify",
3
- "version": "7.5.1",
3
+ "version": "8.0.0-next.1",
4
4
  "description": "Adds fastify support to your application",
5
5
  "type": "module",
6
- "main": "./lib/index.js",
7
6
  "types": "./lib/index.d.ts",
8
7
  "files": [
9
- "cjs",
10
8
  "generator",
11
9
  "lib",
12
10
  "EXAMPLES.md"
@@ -14,8 +12,7 @@
14
12
  "exports": {
15
13
  ".": {
16
14
  "types": "./lib/index.d.ts",
17
- "import": "./lib/index.js",
18
- "require": "./cjs/index.cjs"
15
+ "import": "./lib/index.js"
19
16
  },
20
17
  "./package.json": "./package.json"
21
18
  },
@@ -40,18 +37,16 @@
40
37
  "@types/connect": "^3.4.38",
41
38
  "fastify": "^4.29.1",
42
39
  "vitest": "^3.2.0",
43
- "@gasket/cjs": "^7.1.0",
44
- "@gasket/core": "^7.7.1",
45
- "@gasket/plugin-https": "^7.4.0",
46
- "@gasket/plugin-logger": "^7.4.0",
47
- "@gasket/plugin-metadata": "^7.5.7",
48
- "create-gasket-app": "^7.4.17"
40
+ "@gasket/core": "^8.0.0-next.1",
41
+ "@gasket/plugin-https": "^8.0.0-next.1",
42
+ "@gasket/plugin-logger": "^8.0.0-next.1",
43
+ "@gasket/plugin-metadata": "^8.0.0-next.1",
44
+ "create-gasket-app": "^8.0.0-next.1"
49
45
  },
50
46
  "peerDependencies": {
51
47
  "fastify": "^4.29.1"
52
48
  },
53
49
  "scripts": {
54
- "build": "gasket-cjs ./lib",
55
50
  "lint": "eslint .",
56
51
  "lint:fix": "pnpm run lint --fix",
57
52
  "posttest": "pnpm run lint && pnpm run typecheck",
package/cjs/actions.cjs DELETED
@@ -1,21 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", {
2
- value: true
3
- });
4
- Object.defineProperty(exports, "default", {
5
- enumerable: true,
6
- get: function() {
7
- return _default;
8
- }
9
- });
10
- const _utils = require("./utils.cjs");
11
- const actions = {
12
- /**
13
- * @deprecated
14
- * @param {import('@gasket/core').Gasket} gasket - Gasket instance
15
- * @returns {import('fastify').FastifyInstance} - Fastify instance
16
- */ getFastifyApp (gasket) {
17
- gasket.logger.warn(`DEPRECATED \`getFastifyApp\` action will not be support in future major release.`);
18
- return (0, _utils.getAppInstance)(gasket);
19
- }
20
- };
21
- const _default = actions;
@@ -1,34 +0,0 @@
1
- /// <reference types="@gasket/plugin-https" />
2
- /// <reference types="@gasket/plugin-logger" />
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, /**
7
- * Create the Fastify instance and setup the lifecycle hooks.
8
- * Fastify is compatible with express middleware out of the box, so we can
9
- * use the same middleware lifecycles.
10
- * @type {import('@gasket/core').HookHandler<'createServers'>}
11
- */ "default", {
12
- enumerable: true,
13
- get: function() {
14
- return createServers;
15
- }
16
- });
17
- const _utils = require("./utils.cjs");
18
- async function createServers(gasket, serverOpts) {
19
- /** Cast to Fastify + Express hybrid because Gasket adds `.use()` via @fastify/express plugin */ const app = /** @type {import('fastify').FastifyInstance & { use: Function }} */ (0, _utils.getAppInstance)(gasket);
20
- // allow consuming apps to directly append options to their server
21
- await gasket.exec('fastify', app);
22
- const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
23
- postRenderingStacks.forEach((stack)=>{
24
- /** @type {import('connect').NextHandleFunction} */ const middleware = stack;
25
- app.use(middleware);
26
- });
27
- return {
28
- ...serverOpts,
29
- handler: async function handler(...args) {
30
- await app.ready();
31
- app.server.emit('request', ...args);
32
- }
33
- };
34
- }
package/cjs/create.cjs DELETED
@@ -1,72 +0,0 @@
1
- /// <reference types="@gasket/core" />
2
- /// <reference types="create-gasket-app" />
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, /**
7
- * Add files & extend package.json for new apps.
8
- * @type {import('@gasket/core').HookHandler<'create'>}
9
- */ "default", {
10
- enumerable: true,
11
- get: function() {
12
- return create;
13
- }
14
- });
15
- const _url = require("url");
16
- const _path = require("path");
17
- const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
18
- function _interop_require_default(obj) {
19
- return obj && obj.__esModule ? obj : {
20
- default: obj
21
- };
22
- }
23
- const __filename1 = (0, _url.fileURLToPath)(require("url").pathToFileURL(__filename).toString());
24
- const __dirname = (0, _path.dirname)(__filename1);
25
- const { name, version, devDependencies } = _packagejson.default;
26
- const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore })=>{
27
- if (!testPlugins || testPlugins.length === 0) return;
28
- const unit = [
29
- 'jest',
30
- 'mocha',
31
- 'vitest'
32
- ];
33
- const integration = [
34
- 'cypress'
35
- ];
36
- const frameworks = [
37
- ...unit,
38
- ...integration
39
- ];
40
- const frameworksRegex = new RegExp(frameworks.join('|'));
41
- testPlugins.forEach((testPlugin)=>{
42
- const match = frameworksRegex.exec(testPlugin);
43
- if (match) {
44
- const matchedFramework = match[0];
45
- if (unit.includes(matchedFramework)) {
46
- files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/${globIgnore}`);
47
- } else {
48
- files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/*`);
49
- }
50
- }
51
- });
52
- };
53
- async function create(gasket, context) {
54
- const { files, typescript, apiApp, addApiRoutes = true, testPlugins, pkg, gasketConfig } = context;
55
- const generatorDir = `${__dirname}/../generator`;
56
- gasketConfig.addPlugin('pluginFastify', name);
57
- pkg.add('dependencies', {
58
- [name]: `^${version}`,
59
- fastify: devDependencies.fastify
60
- });
61
- if (apiApp && addApiRoutes) {
62
- const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
63
- files.add(`${generatorDir}/app/**/${globIgnore}`);
64
- gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js');
65
- createTestFiles({
66
- files,
67
- generatorDir,
68
- testPlugins,
69
- globIgnore
70
- });
71
- }
72
- }
package/cjs/index.cjs DELETED
@@ -1,84 +0,0 @@
1
- /// <reference types="@gasket/core" />
2
- /// <reference types="@gasket/plugin-metadata" />
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "default", {
7
- enumerable: true,
8
- get: function() {
9
- return _default;
10
- }
11
- });
12
- const _create = /*#__PURE__*/ _interop_require_default(require("./create.cjs"));
13
- const _createservers = /*#__PURE__*/ _interop_require_default(require("./create-servers.cjs"));
14
- const _actions = /*#__PURE__*/ _interop_require_default(require("./actions.cjs"));
15
- const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
16
- function _interop_require_default(obj) {
17
- return obj && obj.__esModule ? obj : {
18
- default: obj
19
- };
20
- }
21
- const { name, version, description } = _packagejson.default;
22
- /** @type {import('@gasket/core').Plugin} */ const plugin = {
23
- name,
24
- version,
25
- description,
26
- actions: _actions.default,
27
- hooks: {
28
- create: _create.default,
29
- createServers: _createservers.default,
30
- metadata (gasket, meta) {
31
- return {
32
- ...meta,
33
- actions: [
34
- {
35
- name: 'getFastifyApp',
36
- description: 'Get the Fastify app instance',
37
- link: 'README.md#getFastifyApp',
38
- deprecated: true
39
- }
40
- ],
41
- lifecycles: [
42
- {
43
- name: 'fastify',
44
- method: 'exec',
45
- description: 'Modify the Fastify instance to for adding endpoints',
46
- link: 'README.md#express',
47
- parent: 'createServers',
48
- after: 'middleware'
49
- },
50
- {
51
- name: 'errorMiddleware',
52
- method: 'exec',
53
- description: 'Add Express style middleware for handling errors with Fastify',
54
- link: 'README.md#errorMiddleware',
55
- parent: 'createServers',
56
- after: 'express'
57
- }
58
- ],
59
- configurations: [
60
- {
61
- name: 'fastify',
62
- link: 'README.md#configuration',
63
- description: 'Fastify configuration object',
64
- type: 'object'
65
- },
66
- {
67
- name: 'fastify.compression',
68
- link: 'README.md#configuration',
69
- description: 'Automatic compression',
70
- type: 'boolean',
71
- default: true
72
- },
73
- {
74
- name: 'fastify.excludedRoutesRegex',
75
- link: 'README.md#configuration',
76
- description: 'Routes to be excluded based on a regex',
77
- type: 'RegExp'
78
- }
79
- ]
80
- };
81
- }
82
- }
83
- };
84
- const _default = plugin;
package/cjs/package.json DELETED
@@ -1 +0,0 @@
1
- {}
package/cjs/utils.cjs DELETED
@@ -1,66 +0,0 @@
1
- // @ts-nocheck
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- alignLogger: function() {
13
- return alignLogger;
14
- },
15
- getAppInstance: function() {
16
- return getAppInstance;
17
- },
18
- testClearAppInstance: function() {
19
- return testClearAppInstance;
20
- }
21
- });
22
- const _fastify = /*#__PURE__*/ _interop_require_default(require("fastify"));
23
- function _interop_require_default(obj) {
24
- return obj && obj.__esModule ? obj : {
25
- default: obj
26
- };
27
- }
28
- const fallbackMap = {
29
- fatal: 'error',
30
- trace: 'debug'
31
- };
32
- /**
33
- * A helper function to ensure that all the required log levels
34
- * for a Fastify server are present.
35
- * @type {import('@gasket/plugin-fastify').alignLogger}
36
- */ function alignLogger(logger) {
37
- const fastifyLogger = logger;
38
- [
39
- 'fatal',
40
- 'trace'
41
- ].map((level)=>{
42
- if (!logger[level]) {
43
- fastifyLogger[level] = logger[fallbackMap[level]];
44
- }
45
- });
46
- return fastifyLogger;
47
- }
48
- let instance = null;
49
- function getAppInstance(gasket) {
50
- if (!instance) {
51
- const { fastify: fastifyConfig = {}, http2, https } = gasket.config;
52
- const { trustProxy = false, disableRequestLogging = true } = fastifyConfig;
53
- const fastifyLogger = alignLogger(gasket.logger);
54
- instance = (0, _fastify.default)({
55
- logger: fastifyLogger,
56
- trustProxy,
57
- https,
58
- http2,
59
- disableRequestLogging
60
- });
61
- }
62
- return instance;
63
- }
64
- function testClearAppInstance() {
65
- instance = null;
66
- }
@@ -1,11 +0,0 @@
1
- # Local Plugins
2
-
3
- ### Routes plugin
4
-
5
- A local plugin is used to define Fastify routes. The plugin hooks the `fastify` lifecycle and mutates the Fastify app.
6
-
7
- The following routes are available:
8
-
9
- ```javascript
10
- GET /default
11
- ```
@@ -1,30 +0,0 @@
1
- export const defaultHandler = async (req, res) => {
2
- if (res.statusCode === 200) {
3
- res.send({ message: 'Welcome to your default route...' });
4
- }
5
- };
6
-
7
- export default {
8
- name: 'routes-plugin',
9
- hooks: {
10
- fastify(gasket, app) {
11
- {{#if useSwagger }}
12
- /**
13
- * @swagger
14
- *
15
- * /default:
16
- * get:
17
- * summary: "Get default route"
18
- * produces:
19
- * - "application/json"
20
- * responses:
21
- * "200":
22
- * description: "Returns welcome message."
23
- * content:
24
- * application/json
25
- */
26
- {{/if }}
27
- app.get('/default', defaultHandler);
28
- }
29
- }
30
- }
@@ -1,29 +0,0 @@
1
- export const defaultHandler = async (req, res) => {
2
- if (res.statusCode === 200) {
3
- res.send({ message: 'Welcome to your default route...' });
4
- }
5
- };
6
- export default {
7
- name: 'routes-plugin',
8
- hooks: {
9
- fastify(gasket, app) {
10
- {{#if useSwagger }}
11
- /**
12
- * @swagger
13
- *
14
- * /default:
15
- * get:
16
- * summary: "Get default route"
17
- * produces:
18
- * - "application/json"
19
- * responses:
20
- * "200":
21
- * description: "Returns welcome message."
22
- * content:
23
- * application/json
24
- */
25
- {{/if }}
26
- app.get('/default', defaultHandler);
27
- }
28
- }
29
- }
@@ -1,21 +0,0 @@
1
- {{#if typescript}}
2
- const config = {
3
- preset: 'ts-jest/presets/default-esm',
4
- testEnvironment: 'node',
5
- injectGlobals: true,
6
- moduleDirectories: ['node_modules', '<rootDir>'],
7
- moduleNameMapper: {
8
- '^(\\.{1,2}/.*)\\.js$': '$1'
9
- },
10
- transform: {
11
- '^.+.ts$': ['ts-jest', { useESM: true }]
12
- }
13
- };
14
-
15
- export default config;
16
- {{else}}
17
- export default {
18
- testEnvironment: 'node',
19
- injectGlobals: true
20
- };
21
- {{/if}}
@@ -1,20 +0,0 @@
1
- import { jest } from '@jest/globals';
2
- import { defaultHandler } from '../plugins/routes-plugin.js';
3
-
4
- describe('Routes', () => {
5
- let mockRequest, mockResponse;
6
- beforeEach(() => {
7
- mockRequest = {};
8
- mockResponse = {
9
- statusCode: 200,
10
- send: jest.fn()
11
- };
12
- });
13
-
14
- it('defaultHandler should use expeced message', async () => {
15
- await defaultHandler(mockRequest, mockResponse);
16
- expect(mockResponse.send).toHaveBeenCalledWith({
17
- message: 'Welcome to your default route...'
18
- });
19
- });
20
- });
@@ -1,26 +0,0 @@
1
- import {
2
- jest,
3
- describe,
4
- beforeEach,
5
- it,
6
- expect
7
- } from '@jest/globals';
8
- import { defaultHandler } from '../plugins/routes-plugin.js';
9
-
10
- describe('Routes', () => {
11
- let mockRequest, mockResponse;
12
- beforeEach(() => {
13
- mockRequest = {};
14
- mockResponse = {
15
- statusCode: 200,
16
- send: jest.fn()
17
- };
18
- });
19
-
20
- it('defaultHandler should use expeced message', async () => {
21
- await defaultHandler(mockRequest, mockResponse);
22
- expect(mockResponse.send).toHaveBeenCalledWith({
23
- message: 'Welcome to your default route...'
24
- });
25
- });
26
- });
@@ -1,23 +0,0 @@
1
- import { expect } from 'chai';
2
- import sinon from 'sinon';
3
- import { defaultHandler } from '../plugins/routes-plugin.js';
4
-
5
- describe('Routes', () => {
6
- let mockRequest, mockResponse, sendSpy;
7
-
8
- beforeEach(() => {
9
- mockRequest = {};
10
- sendSpy = sinon.spy();
11
- mockResponse = {
12
- statusCode: 200,
13
- send: sendSpy
14
- };
15
- });
16
-
17
- it('defaultHandler should use expected message', async () => {
18
- await defaultHandler(mockRequest, mockResponse);
19
- expect(sendSpy.calledWith({
20
- message: 'Welcome to your default route...'
21
- })).to.be.true;
22
- });
23
- });
@@ -1,23 +0,0 @@
1
- import { expect } from 'chai';
2
- import sinon from 'sinon';
3
- import { defaultHandler } from '../plugins/routes-plugin.js';
4
-
5
- describe('Routes', () => {
6
- let mockRequest, mockResponse, sendSpy;
7
-
8
- beforeEach(() => {
9
- mockRequest = {};
10
- sendSpy = sinon.spy();
11
- mockResponse = {
12
- statusCode: 200,
13
- send: sendSpy
14
- };
15
- });
16
-
17
- it('defaultHandler should use expected message', async () => {
18
- await defaultHandler(mockRequest, mockResponse);
19
- expect(sendSpy.calledWith({
20
- message: 'Welcome to your default route...'
21
- })).to.be.true;
22
- });
23
- });
@@ -1,21 +0,0 @@
1
- import { vi, expect } from 'vitest';
2
- import { defaultHandler } from '../plugins/routes-plugin.js';
3
-
4
- describe('Routes', () => {
5
- let mockRequest, mockResponse;
6
-
7
- beforeEach(() => {
8
- mockRequest = {};
9
- mockResponse = {
10
- statusCode: 200,
11
- send: vi.fn()
12
- };
13
- });
14
-
15
- it('defaultHeader should use expected message', async () => {
16
- await defaultHandler(mockRequest, mockResponse);
17
- expect(mockResponse.send).toHaveBeenCalledWith({
18
- message: 'Welcome to your default route...'
19
- });
20
- });
21
- });
@@ -1,21 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from 'vitest';
2
- import { defaultHandler } from '../plugins/routes-plugin.js';
3
-
4
- describe('Routes', () => {
5
- let mockRequest, mockResponse;
6
-
7
- beforeEach(() => {
8
- mockRequest = {};
9
- mockResponse = {
10
- statusCode: 200,
11
- send: vi.fn()
12
- };
13
- });
14
-
15
- it('defaultHeader should use expected message', async () => {
16
- await defaultHandler(mockRequest, mockResponse);
17
- expect(mockResponse.send).toHaveBeenCalledWith({
18
- message: 'Welcome to your default route...'
19
- });
20
- });
21
- });
package/lib/create.js DELETED
@@ -1,61 +0,0 @@
1
- /// <reference types="@gasket/core" />
2
- /// <reference types="create-gasket-app" />
3
-
4
- import { fileURLToPath } from 'url';
5
- import { dirname } from 'path';
6
- import packageJson from '../package.json' with { type: 'json' };
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
- const { name, version, devDependencies } = packageJson;
10
-
11
- const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore }) => {
12
- if (!testPlugins || testPlugins.length === 0) return;
13
- const unit = ['jest', 'mocha', 'vitest'];
14
- const integration = ['cypress'];
15
- const frameworks = [...unit, ...integration];
16
- const frameworksRegex = new RegExp(frameworks.join('|'));
17
-
18
- testPlugins.forEach((testPlugin) => {
19
- const match = frameworksRegex.exec(testPlugin);
20
- if (match) {
21
- const matchedFramework = match[0];
22
- if (unit.includes(matchedFramework)) {
23
- files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/${globIgnore}`);
24
- } else {
25
- files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/*`);
26
- }
27
- }
28
- });
29
- };
30
-
31
- /**
32
- * Add files & extend package.json for new apps.
33
- * @type {import('@gasket/core').HookHandler<'create'>}
34
- */
35
- export default async function create(gasket, context) {
36
- const {
37
- files,
38
- typescript,
39
- apiApp,
40
- addApiRoutes = true,
41
- testPlugins,
42
- pkg,
43
- gasketConfig
44
- } = context;
45
- const generatorDir = `${__dirname}/../generator`;
46
-
47
- gasketConfig.addPlugin('pluginFastify', name);
48
-
49
- pkg.add('dependencies', {
50
- [name]: `^${version}`,
51
- fastify: devDependencies.fastify
52
- });
53
-
54
- if (apiApp && addApiRoutes) {
55
- const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
56
- files.add(`${generatorDir}/app/**/${globIgnore}`);
57
- gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js');
58
-
59
- createTestFiles({ files, generatorDir, testPlugins, globIgnore });
60
- }
61
- }