Skip to content

Commit

Permalink
Upgrade production deps for hapi v21 and node v18 (#4361)
Browse files Browse the repository at this point in the history
* Upgrade production deps for hapi v21 and node v18

* Account for change to podium emit(), no longer can be awaited. Closes #4184
  • Loading branch information
devinivy authored Jun 23, 2022
1 parent 554294e commit 0f8238d
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 41 deletions.
20 changes: 13 additions & 7 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1539,11 +1539,11 @@ async function example() {
const server = Hapi.server({ port: 80 });
server.event('test');
server.events.on('test', (update) => console.log(update));
await server.events.emit('test', 'hello');
await server.events.gauge('test', 'hello');
}
```

### <a name="server.events.emit()" /> `await server.events.emit(criteria, data)`
### <a name="server.events.emit()" /> `server.events.emit(criteria, data)`

Emits a custom application event to all the subscribed listeners where:

Expand All @@ -1569,7 +1569,7 @@ async function example() {
const server = Hapi.server({ port: 80 });
server.event('test');
server.events.on('test', (update) => console.log(update));
await server.events.emit('test', 'hello'); // await is optional
server.events.emit('test', 'hello');
}
```

Expand Down Expand Up @@ -1633,7 +1633,7 @@ async function example() {
const server = Hapi.server({ port: 80 });
server.event('test');
server.events.on('test', (update) => console.log(update));
await server.events.emit('test', 'hello');
server.events.emit('test', 'hello');
}
```

Expand All @@ -1651,8 +1651,8 @@ async function example() {
const server = Hapi.server({ port: 80 });
server.event('test');
server.events.once('test', (update) => console.log(update));
await server.events.emit('test', 'hello');
await server.events.emit('test', 'hello'); // Ignored
server.events.emit('test', 'hello');
server.events.emit('test', 'hello'); // Ignored
}
```

Expand All @@ -1670,11 +1670,17 @@ async function example() {
const server = Hapi.server({ port: 80 });
server.event('test');
const pending = server.events.once('test');
await server.events.emit('test', 'hello');
server.events.emit('test', 'hello');
const update = await pending;
}
```

### <a name="server.events.gauge()" /> `await server.events.gauge(criteria, data)`

Behaves identically to [`server.events.emit()`](#server.events.emit()), but also returns an array of the results of all the event listeners that run. The return value is that of `Promise.allSettled()`, where each item in the resulting array is `{ status: 'fulfilled', value }` in the case of a successful handler, or `{ status: 'rejected', reason }` in the case of a handler that throws.

Please note that system errors such as a `TypeError` are not handled specially, and it's recommended to scrutinize any rejections using something like [bounce](https://hapi.dev/module/bounce/).

### <a name="server.expose()" /> `server.expose(key, value, [options])`

Used within a plugin to expose a property via [`server.plugins[name]`](#server.plugins) where:
Expand Down
10 changes: 5 additions & 5 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const Boom = require('@hapi/boom');
const Bounce = require('@hapi/bounce');
const Call = require('@hapi/call');
const Catbox = require('@hapi/catbox');
const CatboxMemory = require('@hapi/catbox-memory');
const Heavy = require('@hapi/heavy');
const { Engine: CatboxMemory } = require('@hapi/catbox-memory');
const { Heavy } = require('@hapi/heavy');
const Hoek = require('@hapi/hoek');
const { Mimos } = require('@hapi/mimos');
const Podium = require('@hapi/podium');
Expand Down Expand Up @@ -58,7 +58,7 @@ exports = module.exports = internals.Core = class {
compression = new Compression();
controlled = null; // Other servers linked to the phases of this server
dependencies = []; // Plugin dependencies
events = new Podium(internals.events);
events = new Podium.Podium(internals.events);
heavy = null;
info = null;
instances = new Set();
Expand Down Expand Up @@ -293,7 +293,7 @@ exports = module.exports = internals.Core = class {
}

this.phase = 'started';
await this.events.emit('start');
this.events.emit('start');

try {
if (this.controlled) {
Expand Down Expand Up @@ -415,7 +415,7 @@ exports = module.exports = internals.Core = class {
this.caches.forEach((cache) => caches.push(cache.client.stop()));
await Promise.all(caches);

await this.events.emit('stop');
this.events.emit('stop');
this.heavy.stop();

if (this.controlled) {
Expand Down
2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ exports = module.exports = internals.Request = class {
get events() {

if (!this._events) {
this._events = new Podium(internals.events);
this._events = new Podium.Podium(internals.events);
}

return this._events;
Expand Down
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ exports = module.exports = internals.Response = class {
get events() {

if (!this._events) {
this._events = new Podium(internals.events);
this._events = new Podium.Podium(internals.events);
}

return this._events;
Expand Down
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@
]
},
"dependencies": {
"@hapi/accept": "^5.0.1",
"@hapi/ammo": "^5.0.1",
"@hapi/boom": "^9.1.0",
"@hapi/bounce": "^2.0.0",
"@hapi/call": "^8.0.0",
"@hapi/catbox": "^11.1.1",
"@hapi/catbox-memory": "^5.0.0",
"@hapi/heavy": "^7.0.1",
"@hapi/hoek": "^9.0.4",
"@hapi/mimos": "^6.0.0",
"@hapi/podium": "^4.1.1",
"@hapi/shot": "6.0.0-beta.1",
"@hapi/somever": "^3.0.0",
"@hapi/statehood": "^7.0.3",
"@hapi/subtext": "^7.0.3",
"@hapi/teamwork": "^5.1.0",
"@hapi/topo": "^5.0.0",
"@hapi/validate": "^1.1.1"
"@hapi/accept": "^6.0.0",
"@hapi/ammo": "^6.0.0",
"@hapi/boom": "^10.0.0",
"@hapi/bounce": "^3.0.0",
"@hapi/call": "^9.0.0",
"@hapi/catbox": "^12.0.0",
"@hapi/catbox-memory": "^6.0.0",
"@hapi/heavy": "^8.0.0",
"@hapi/hoek": "^10.0.0",
"@hapi/mimos": "^7.0.0",
"@hapi/podium": "^5.0.0",
"@hapi/shot": "^6.0.0",
"@hapi/somever": "^4.0.0",
"@hapi/statehood": "^8.0.0",
"@hapi/subtext": "^8.0.0",
"@hapi/teamwork": "^6.0.0",
"@hapi/topo": "^6.0.0",
"@hapi/validate": "^2.0.0"
},
"devDependencies": {
"@hapi/code": "9.0.0-beta.0",
"@hapi/eslint-plugin": "^5.0.0",
"@hapi/code": "^9.0.0",
"@hapi/eslint-plugin": "^6.0.0",
"@hapi/inert": "^6.0.2",
"@hapi/joi-legacy-test": "npm:@hapi/joi@^15.0.0",
"@hapi/lab": "25.0.0-beta.0",
"@hapi/lab": "^25.0.1",
"@hapi/vision": "^6.0.1",
"@hapi/wreck": "^17.0.0",
"@hapi/wreck": "^18.0.0",
"handlebars": "^4.7.4",
"joi": "^17.0.0",
"legacy-readable-stream": "npm:readable-stream@^1.0.34"
Expand Down
2 changes: 1 addition & 1 deletion test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Stream = require('stream');
const TLS = require('tls');

const Boom = require('@hapi/boom');
const CatboxMemory = require('@hapi/catbox-memory');
const { Engine: CatboxMemory } = require('@hapi/catbox-memory');
const Code = require('@hapi/code');
const Handlebars = require('handlebars');
const Hapi = require('..');
Expand Down
2 changes: 1 addition & 1 deletion test/headers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Boom = require('@hapi/boom');
const CatboxMemory = require('@hapi/catbox-memory');
const { Engine: CatboxMemory } = require('@hapi/catbox-memory');
const Code = require('@hapi/code');
const Hapi = require('..');
const Inert = require('@hapi/inert');
Expand Down
2 changes: 1 addition & 1 deletion test/methods.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Catbox = require('@hapi/catbox');
const CatboxMemory = require('@hapi/catbox-memory');
const { Engine: CatboxMemory } = require('@hapi/catbox-memory');
const Code = require('@hapi/code');
const Hapi = require('..');
const Hoek = require('@hapi/hoek');
Expand Down
4 changes: 2 additions & 2 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Path = require('path');
const Zlib = require('zlib');

const Boom = require('@hapi/boom');
const CatboxMemory = require('@hapi/catbox-memory');
const { Engine: CatboxMemory } = require('@hapi/catbox-memory');
const Code = require('@hapi/code');
const Handlebars = require('handlebars');
const Hapi = require('..');
Expand Down Expand Up @@ -858,7 +858,7 @@ describe('Server', () => {

server.events.emit('test', 1);
server.events.emit({ name: 'test', channel: 'x' }, 2);
await plugin.events.emit({ name: 'test', channel: 'y' }, 3);
plugin.events.emit({ name: 'test', channel: 'y' }, 3);

expect(updates).to.equal([
{ id: 'server', update: 1 },
Expand Down

0 comments on commit 0f8238d

Please sign in to comment.