@openapi-typescript-infra/service 5.15.0 → 6.1.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/.github/workflows/nodejs.yml +2 -2
- package/Makefile +2 -2
- package/build/bootstrap.d.ts +9 -0
- package/build/bootstrap.js +6 -0
- package/build/bootstrap.js.map +1 -1
- package/build/express-app/app.js +7 -5
- package/build/express-app/app.js.map +1 -1
- package/build/telemetry/instrumentations.d.ts +2 -2
- package/build/telemetry/instrumentations.js +2 -2
- package/build/telemetry/instrumentations.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +2 -2
- package/package.json +41 -41
- package/src/bootstrap.ts +10 -0
- package/src/express-app/app.ts +9 -7
- package/src/telemetry/instrumentations.ts +2 -2
- package/src/types.ts +2 -2
package/build/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Server } from 'http';
|
|
2
2
|
import type { REPLServer } from 'repl';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BaseLogger, Logger } from 'pino';
|
|
4
4
|
import type { Request, Response } from 'express';
|
|
5
5
|
import type { Application } from 'express-serve-static-core';
|
|
6
6
|
import type { middleware } from 'express-openapi-validator';
|
|
@@ -12,7 +12,7 @@ export interface InternalLocals<SLocals extends AnyServiceLocals = ServiceLocals
|
|
|
12
12
|
server?: Server;
|
|
13
13
|
mainApp: ServiceExpress<SLocals>;
|
|
14
14
|
}
|
|
15
|
-
export type ServiceLogger =
|
|
15
|
+
export type ServiceLogger = BaseLogger & Pick<Logger, 'isLevelEnabled'>;
|
|
16
16
|
export interface ServiceLocals<Config extends ConfigurationSchema = ConfigurationSchema> {
|
|
17
17
|
service: Service;
|
|
18
18
|
name: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "An opinionated framework for building configuration driven services - web, api, or ob. Uses OpenAPI, pino logging, express, confit, Typescript and vitest.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"coconfig": "@openapi-typescript-infra/coconfig"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
|
-
"node": ">=
|
|
36
|
+
"node": ">=22"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"service",
|
|
@@ -70,68 +70,68 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@godaddy/terminus": "^4.12.1",
|
|
72
72
|
"@opentelemetry/api": "^1.9.0",
|
|
73
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
74
|
-
"@opentelemetry/exporter-prometheus": "^0.
|
|
75
|
-
"@opentelemetry/instrumentation-dns": "^0.
|
|
76
|
-
"@opentelemetry/instrumentation-express": "^0.
|
|
77
|
-
"@opentelemetry/instrumentation-generic-pool": "^0.
|
|
78
|
-
"@opentelemetry/instrumentation-graphql": "^0.
|
|
79
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
80
|
-
"@opentelemetry/instrumentation-
|
|
81
|
-
"@opentelemetry/instrumentation-
|
|
82
|
-
"@opentelemetry/instrumentation-
|
|
83
|
-
"@opentelemetry/instrumentation-
|
|
84
|
-
"@opentelemetry/instrumentation-undici": "^0.
|
|
85
|
-
"@opentelemetry/resource-detector-container": "^0.7.
|
|
86
|
-
"@opentelemetry/resource-detector-gcp": "^0.
|
|
87
|
-
"@opentelemetry/sdk-node": "^0.
|
|
88
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
73
|
+
"@opentelemetry/auto-instrumentations-node": "^0.66.0",
|
|
74
|
+
"@opentelemetry/exporter-prometheus": "^0.207.0",
|
|
75
|
+
"@opentelemetry/instrumentation-dns": "^0.51.0",
|
|
76
|
+
"@opentelemetry/instrumentation-express": "^0.56.0",
|
|
77
|
+
"@opentelemetry/instrumentation-generic-pool": "^0.51.0",
|
|
78
|
+
"@opentelemetry/instrumentation-graphql": "^0.55.0",
|
|
79
|
+
"@opentelemetry/instrumentation-http": "^0.207.0",
|
|
80
|
+
"@opentelemetry/instrumentation-net": "^0.51.0",
|
|
81
|
+
"@opentelemetry/instrumentation-pg": "^0.60.0",
|
|
82
|
+
"@opentelemetry/instrumentation-pino": "^0.54.0",
|
|
83
|
+
"@opentelemetry/instrumentation-redis": "^0.56.0",
|
|
84
|
+
"@opentelemetry/instrumentation-undici": "^0.18.0",
|
|
85
|
+
"@opentelemetry/resource-detector-container": "^0.7.10",
|
|
86
|
+
"@opentelemetry/resource-detector-gcp": "^0.42.0",
|
|
87
|
+
"@opentelemetry/sdk-node": "^0.207.0",
|
|
88
|
+
"@opentelemetry/semantic-conventions": "^1.37.0",
|
|
89
89
|
"@sesamecare-oss/confit": "^2.2.1",
|
|
90
90
|
"@sesamecare-oss/opentelemetry-node-metrics": "^1.1.0",
|
|
91
91
|
"ajv": "^8.17.1",
|
|
92
|
-
"clean-stack": "^5.
|
|
92
|
+
"clean-stack": "^5.3.0",
|
|
93
93
|
"cookie-parser": "^1.4.7",
|
|
94
|
-
"dotenv": "^
|
|
94
|
+
"dotenv": "^17.2.3",
|
|
95
95
|
"express": "^5.1.0",
|
|
96
|
-
"express-openapi-validator": "^5.
|
|
96
|
+
"express-openapi-validator": "^5.6.0",
|
|
97
97
|
"glob": "^11.0.3",
|
|
98
|
-
"import-in-the-middle": "^
|
|
98
|
+
"import-in-the-middle": "^2.0.0",
|
|
99
99
|
"minimist": "^1.2.8",
|
|
100
100
|
"moderndash": "^4.0.0",
|
|
101
101
|
"opentelemetry-resource-detector-sync-api": "^0.30.0",
|
|
102
|
-
"pino": "^
|
|
102
|
+
"pino": "^10.1.0",
|
|
103
103
|
"read-package-up": "^11.0.0",
|
|
104
104
|
"request-ip": "^3.3.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
|
-
"@commitlint/cli": "^
|
|
108
|
-
"@commitlint/config-conventional": "^
|
|
107
|
+
"@commitlint/cli": "^20.1.0",
|
|
108
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
109
109
|
"@openapi-typescript-infra/coconfig": "^4.7.1",
|
|
110
110
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
111
111
|
"@semantic-release/exec": "^7.1.0",
|
|
112
|
-
"@semantic-release/github": "^
|
|
113
|
-
"@semantic-release/release-notes-generator": "^14.0
|
|
114
|
-
"@types/cookie-parser": "^1.4.
|
|
115
|
-
"@types/express": "^5.0.
|
|
112
|
+
"@semantic-release/github": "^12.0.1",
|
|
113
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
114
|
+
"@types/cookie-parser": "^1.4.10",
|
|
115
|
+
"@types/express": "^5.0.5",
|
|
116
116
|
"@types/minimist": "^1.2.5",
|
|
117
|
-
"@types/node": "^
|
|
117
|
+
"@types/node": "^24.10.0",
|
|
118
118
|
"@types/request-ip": "^0.0.41",
|
|
119
119
|
"@types/supertest": "^6.0.3",
|
|
120
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
121
|
-
"@typescript-eslint/parser": "^
|
|
120
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
121
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
122
122
|
"coconfig": "^1.6.2",
|
|
123
123
|
"eslint": "^8.57.1",
|
|
124
|
-
"eslint-config-prettier": "^
|
|
125
|
-
"eslint-import-resolver-typescript": "^4.4.
|
|
126
|
-
"eslint-plugin-import": "^2.
|
|
127
|
-
"pino-pretty": "^13.
|
|
124
|
+
"eslint-config-prettier": "^10.1.8",
|
|
125
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
126
|
+
"eslint-plugin-import": "^2.32.0",
|
|
127
|
+
"pino-pretty": "^13.1.2",
|
|
128
128
|
"pinst": "^3.0.0",
|
|
129
|
-
"prettier": "^3.
|
|
130
|
-
"supertest": "^7.1.
|
|
129
|
+
"prettier": "^3.6.2",
|
|
130
|
+
"supertest": "^7.1.4",
|
|
131
131
|
"tsconfig-paths": "^4.2.0",
|
|
132
|
-
"tsx": "^4.20.
|
|
133
|
-
"typescript": "^5.
|
|
134
|
-
"vitest": "^
|
|
132
|
+
"tsx": "^4.20.6",
|
|
133
|
+
"typescript": "^5.9.3",
|
|
134
|
+
"vitest": "^4.0.6"
|
|
135
135
|
},
|
|
136
136
|
"resolutions": {
|
|
137
137
|
"qs": "^6.11.0"
|
package/src/bootstrap.ts
CHANGED
|
@@ -143,3 +143,13 @@ export async function bootstrap<
|
|
|
143
143
|
const server = argv?.nobind ? undefined : await listen(app);
|
|
144
144
|
return { server, app, codepath };
|
|
145
145
|
}
|
|
146
|
+
|
|
147
|
+
export function bootstrapCli<
|
|
148
|
+
SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>,
|
|
149
|
+
RLocals extends RequestLocals = RequestLocals,
|
|
150
|
+
>(argv?: BootstrapArguments) {
|
|
151
|
+
return bootstrap<SLocals, RLocals>({
|
|
152
|
+
nobind: true,
|
|
153
|
+
...argv,
|
|
154
|
+
});
|
|
155
|
+
}
|
package/src/express-app/app.ts
CHANGED
|
@@ -3,7 +3,7 @@ import http from 'http';
|
|
|
3
3
|
import https from 'https';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
|
-
import { pino } from 'pino';
|
|
6
|
+
import { destination, type Logger, pino } from 'pino';
|
|
7
7
|
import cookieParser from 'cookie-parser';
|
|
8
8
|
import { context, metrics, trace } from '@opentelemetry/api';
|
|
9
9
|
import { setupNodeMetrics } from '@sesamecare-oss/opentelemetry-node-metrics';
|
|
@@ -47,7 +47,7 @@ export async function startApp<
|
|
|
47
47
|
>(startOptions: ServiceStartOptions<SLocals, RLocals>): Promise<ServiceExpress<SLocals>> {
|
|
48
48
|
const { service, rootDirectory, codepath = 'build', name, version } = startOptions;
|
|
49
49
|
const shouldPrettyPrint = isDev() && !process.env.NO_PRETTY_LOGS;
|
|
50
|
-
const
|
|
50
|
+
const pinoDestination = destination({
|
|
51
51
|
sync: isSyncLogging(),
|
|
52
52
|
dest: process.env.LOG_TO_FILE || process.stdout.fd,
|
|
53
53
|
minLength: process.env.LOG_BUFFER ? Number(process.env.LOG_BUFFER) : undefined,
|
|
@@ -79,7 +79,7 @@ export async function startApp<
|
|
|
79
79
|
},
|
|
80
80
|
mixin: poorMansOtlp,
|
|
81
81
|
},
|
|
82
|
-
|
|
82
|
+
pinoDestination,
|
|
83
83
|
)
|
|
84
84
|
: pino(
|
|
85
85
|
{
|
|
@@ -90,7 +90,7 @@ export async function startApp<
|
|
|
90
90
|
},
|
|
91
91
|
mixin: poorMansOtlp,
|
|
92
92
|
},
|
|
93
|
-
|
|
93
|
+
pinoDestination,
|
|
94
94
|
);
|
|
95
95
|
|
|
96
96
|
const serviceImpl = service();
|
|
@@ -302,7 +302,7 @@ export async function shutdownApp<
|
|
|
302
302
|
} catch (error) {
|
|
303
303
|
logger.warn(error, 'Shutdown failed');
|
|
304
304
|
}
|
|
305
|
-
(logger as
|
|
305
|
+
(logger as Logger).flush?.();
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
function httpServer<
|
|
@@ -368,7 +368,7 @@ export async function listen<SLocals extends AnyServiceLocals = ServiceLocals<Co
|
|
|
368
368
|
.then(shutdownHandler || (() => Promise.resolve()))
|
|
369
369
|
.then(() => logger.info('Graceful shutdown complete'))
|
|
370
370
|
.catch((error) => logger.error(error, 'Error terminating tracing'))
|
|
371
|
-
.then(() => (logger as
|
|
371
|
+
.then(() => (logger as Logger).flush?.());
|
|
372
372
|
},
|
|
373
373
|
logger: (msg, e) => {
|
|
374
374
|
logger.error(e, msg);
|
|
@@ -380,7 +380,9 @@ export async function listen<SLocals extends AnyServiceLocals = ServiceLocals<Co
|
|
|
380
380
|
shutdownInProgress = true;
|
|
381
381
|
app.locals.logger.info('Shutdown requested');
|
|
382
382
|
if (app.locals.internalApp) {
|
|
383
|
-
app.locals.internalApp.locals.server?.
|
|
383
|
+
if (app.locals.internalApp.locals.server?.listening) {
|
|
384
|
+
app.locals.internalApp.locals.server?.close();
|
|
385
|
+
}
|
|
384
386
|
}
|
|
385
387
|
shutdownApp(app);
|
|
386
388
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
HttpInstrumentation,
|
|
8
8
|
IgnoreIncomingRequestFunction,
|
|
9
9
|
} from '@opentelemetry/instrumentation-http';
|
|
10
|
-
import {
|
|
10
|
+
import { RedisInstrumentation } from '@opentelemetry/instrumentation-redis';
|
|
11
11
|
import { NetInstrumentation } from '@opentelemetry/instrumentation-net';
|
|
12
12
|
import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';
|
|
13
13
|
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
|
|
@@ -20,7 +20,7 @@ const InstrumentationMap = {
|
|
|
20
20
|
'@opentelemetry/instrumentation-graphql': GraphQLInstrumentation,
|
|
21
21
|
'@opentelemetry/instrumentation-undici': UndiciInstrumentation,
|
|
22
22
|
'@opentelemetry/instrumentation-generic-pool': GenericPoolInstrumentation,
|
|
23
|
-
'@opentelemetry/instrumentation-
|
|
23
|
+
'@opentelemetry/instrumentation-redis': RedisInstrumentation,
|
|
24
24
|
'@opentelemetry/instrumentation-net': NetInstrumentation,
|
|
25
25
|
'@opentelemetry/instrumentation-pg': PgInstrumentation,
|
|
26
26
|
'@opentelemetry/instrumentation-pino': PinoInstrumentation,
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Server } from 'http';
|
|
2
2
|
import type { REPLServer } from 'repl';
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { BaseLogger, Logger } from 'pino';
|
|
5
5
|
import type { Request, Response } from 'express';
|
|
6
6
|
import type { Application } from 'express-serve-static-core';
|
|
7
7
|
import type { middleware } from 'express-openapi-validator';
|
|
@@ -18,7 +18,7 @@ export interface InternalLocals<
|
|
|
18
18
|
mainApp: ServiceExpress<SLocals>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export type ServiceLogger =
|
|
21
|
+
export type ServiceLogger = BaseLogger & Pick<Logger, 'isLevelEnabled'>;
|
|
22
22
|
|
|
23
23
|
// Vanilla express wants this to extend Record<string, any> but this is a mistake
|
|
24
24
|
// because you lose type checking on it, even though I get that underneath it truly
|