Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: migrate to fastify v5 #135

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ on:

jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
with:
lint: true
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ function fastifyOverview (fastify, options, next) {
instance[kTrackerMe] = trackingToken

const trackStructure = getPluginNode(trackingToken, instance.pluginName)
if (opts.addSource && this) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the README?

(I would add a note that the addSource flag has been removed in fastify v5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddSource is actually used elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eomm an example is on line 35 of this file

trackStructure.source = this._current.find(loadPipe => loadPipe.func[kSourceRegister] !== undefined).func[kSourceRegister]
}
contextMap.set(trackingToken, trackStructure)
instance[kStructure] = trackStructure

Expand Down Expand Up @@ -192,7 +189,7 @@ function getJsonOverview (request, reply) {

const plugin = fp(fastifyOverview, {
name: 'fastify-overview',
fastify: '^4.23.x'
fastify: '5.x'
})

module.exports = plugin
Expand Down
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "standard && npm run lint:typescript",
"lint:fix": "standard --fix && npm run lint:typescript -- --fix",
"lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin *.ts test/**/*.ts",
"test": "tap test/**/*.test.js && npm run test:typescript",
"test": "node --test && npm run test:typescript",
"test:typescript": "tsd"
},
"repository": {
Expand All @@ -28,22 +28,21 @@
"url": "https://github.com/Eomm/fastify-overview/issues"
},
"engines": {
"node": ">=14"
"node": ">=20"
},
"homepage": "https://github.com/Eomm/fastify-overview#readme",
"devDependencies": {
"@fastify/autoload": "^5.0.0",
"@types/node": "^20.1.0",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.0.0",
"fastify": "^4.23.0",
"standard": "^17.0.0",
"tap": "^16.0.1",
"tsd": "^0.31.0"
"@fastify/autoload": "^6.0.2",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"fastify": "^5.1.0",
"standard": "^17.1.2",
"tsd": "^0.31.2"
},
"dependencies": {
"fastify-plugin": "^4.0.0",
"object-hash": "^2.2.0"
"fastify-plugin": "^5.0.1",
"object-hash": "^3.0.0"
},
"tsd": {
"directory": "test/types"
Expand Down
4 changes: 2 additions & 2 deletions test/application-hooks.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const fastify = require('fastify')
const plugin = require('../index')

Expand Down Expand Up @@ -29,5 +29,5 @@ test('should track all the application hooks', {
await app.ready()
const structure = app.overview({ hideEmpty: true })

t.same(structure.hooks, require('./fixture/app-hooks.json').hooks)
t.assert.deepStrictEqual(structure.hooks, require('./fixture/app-hooks.json').hooks)
})
64 changes: 32 additions & 32 deletions test/decorator.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const fastify = require('fastify')
const plugin = require('../index')

Expand All @@ -14,7 +14,7 @@ test('decorator', async t => {
app.decorateReply('root-reply', function () {})

app.decorate('root-symbol', Symbol('testSymbol'))
app.decorateReply('root-reply-array', [])
app.decorateReply('root-reply-array', () => ({ getter: [] }))
app.decorateRequest('root-req-boolean', true)

app.register(function register1 (instance, opts, next) {
Expand All @@ -28,7 +28,7 @@ test('decorator', async t => {
instance.register(function register3 (sub, opts, next) {
sub.decorate('sub-instance', 50)
sub.decorateReply('sub', 50)
sub.decorateRequest('sub-object', {})
sub.decorateRequest('sub-object', () => ({ getter: {} }))
next()
})
next()
Expand All @@ -40,28 +40,28 @@ test('decorator', async t => {
await app.ready()
const root = app.overview()

t.equal(root.children.length, 2)
t.equal(root.children[0].name, 'register1')
t.equal(root.children[1].name, 'sibling')
t.same(root.decorators.decorate, [{ name: 'root-func', type: 'function' }, { name: 'root-symbol', type: 'symbol' }])
t.same(root.decorators.decorateRequest, [{ name: 'root-req', type: 'function' }, { name: 'root-req-two', type: 'function' }, { name: 'root-req-boolean', type: 'boolean' }])
t.same(root.decorators.decorateReply, [{ name: 'root-reply', type: 'function' }, { name: 'root-reply-array', type: 'array' }])
t.assert.deepEqual(root.children.length, 2)
t.assert.deepEqual(root.children[0].name, 'register1')
t.assert.deepEqual(root.children[1].name, 'sibling')
t.assert.deepStrictEqual(root.decorators.decorate, [{ name: 'root-func', type: 'function' }, { name: 'root-symbol', type: 'symbol' }])
t.assert.deepStrictEqual(root.decorators.decorateRequest, [{ name: 'root-req', type: 'function' }, { name: 'root-req-two', type: 'function' }, { name: 'root-req-boolean', type: 'boolean' }])
t.assert.deepStrictEqual(root.decorators.decorateReply, [{ name: 'root-reply', type: 'function' }, { name: 'root-reply-array', type: 'function' }])

const reg1 = root.children[0]
t.same(reg1.decorators.decorate, [{ name: 'child-1-bigint', type: 'bigint' }, { name: 'child-1-undefined', type: 'undefined' }])
t.same(reg1.decorators.decorateRequest, [{ name: 'child-1', type: 'number' }])
t.same(reg1.decorators.decorateReply, [])
t.equal(reg1.children.length, 2)
t.assert.deepStrictEqual(reg1.decorators.decorate, [{ name: 'child-1-bigint', type: 'bigint' }, { name: 'child-1-undefined', type: 'undefined' }])
t.assert.deepStrictEqual(reg1.decorators.decorateRequest, [{ name: 'child-1', type: 'number' }])
t.assert.deepStrictEqual(reg1.decorators.decorateReply, [])
t.assert.deepEqual(reg1.children.length, 2)

const reg2 = reg1.children[0]
t.same(reg2.decorators.decorate, [])
t.same(reg2.decorators.decorateRequest, [])
t.same(reg2.decorators.decorateReply, [{ name: 'sub', type: 'number' }])
t.assert.deepStrictEqual(reg2.decorators.decorate, [])
t.assert.deepStrictEqual(reg2.decorators.decorateRequest, [])
t.assert.deepStrictEqual(reg2.decorators.decorateReply, [{ name: 'sub', type: 'number' }])

const reg3 = reg1.children[1]
t.same(reg3.decorators.decorate, [{ name: 'sub-instance', type: 'number' }])
t.same(reg3.decorators.decorateRequest, [{ name: 'sub-object', type: 'object' }])
t.same(reg3.decorators.decorateReply, [{ name: 'sub', type: 'number' }])
t.assert.deepStrictEqual(reg3.decorators.decorate, [{ name: 'sub-instance', type: 'number' }])
t.assert.deepStrictEqual(reg3.decorators.decorateRequest, [{ name: 'sub-object', type: 'function' }])
t.assert.deepStrictEqual(reg3.decorators.decorateReply, [{ name: 'sub', type: 'number' }])
})

test('onDecorateDefinition', async t => {
Expand All @@ -83,14 +83,14 @@ test('onDecorateDefinition', async t => {
}
})

app.decorate('emptyObj', {})
app.decorate('emptyObj', () => ({ getter: {} }))
app.decorate('obj1', {
run: () => {}
})
app.decorateRequest('emptyObj', {})
app.decorateReply('obj2', {
test: 'str'
})
app.decorateRequest('emptyObj', () => ({ getter: {} }))
app.decorateReply('obj2', () => ({
getter: { test: 'str' }
}))

app.register(async function child1 (instance) {
instance.decorate('encapsulatedObj', {
Expand All @@ -105,14 +105,14 @@ test('onDecorateDefinition', async t => {

const root = app.overview()

t.equal(root.children.length, 1)
t.same(root.decorators.decorate, [{ name: 'emptyObj', type: 'object', recursive: [] }, { name: 'obj1', type: 'object', recursive: [{ name: 'run', type: 'function' }] }])
t.same(root.decorators.decorateReply, [{ name: 'obj2', type: 'object', recursive: [{ name: 'test', type: 'string' }] }])
t.same(root.decorators.decorateRequest, [{ name: 'emptyObj', type: 'object', recursive: [] }])
t.assert.deepEqual(root.children.length, 1)
t.assert.deepStrictEqual(root.decorators.decorate, [{ name: 'emptyObj', type: 'function' }, { name: 'obj1', type: 'object', recursive: [{ name: 'run', type: 'function' }] }])
t.assert.deepStrictEqual(root.decorators.decorateReply, [{ name: 'obj2', type: 'function' }])
t.assert.deepStrictEqual(root.decorators.decorateRequest, [{ name: 'emptyObj', type: 'function' }])

t.equal(root.children[0].name, 'child1')
t.assert.deepEqual(root.children[0].name, 'child1')
const child1 = root.children[0]
t.same(child1.decorators.decorate, [{ name: 'encapsulatedObj', type: 'object', recursive: [{ name: 'a', type: 'function' }, { name: 'b', type: 'string' }, { name: 'c', type: 'boolean' }, { name: 'd', type: 'number' }] }])
t.equal(child1.decorators.decorateRequest.length, 0)
t.equal(child1.decorators.decorateReply.length, 0)
t.assert.deepStrictEqual(child1.decorators.decorate, [{ name: 'encapsulatedObj', type: 'object', recursive: [{ name: 'a', type: 'function' }, { name: 'b', type: 'string' }, { name: 'c', type: 'boolean' }, { name: 'd', type: 'number' }] }])
t.assert.deepEqual(child1.decorators.decorateRequest.length, 0)
t.assert.deepEqual(child1.decorators.decorateReply.length, 0)
})
Loading
Loading