@openapi-typescript-infra/service 4.1.0 → 4.2.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/CHANGELOG.md +14 -0
- package/build/bootstrap.d.ts +1 -0
- package/build/bootstrap.js +5 -1
- package/build/bootstrap.js.map +1 -1
- package/build/express-app/app.js +3 -2
- package/build/express-app/app.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +2 -0
- package/package.json +4 -4
- package/src/bootstrap.ts +7 -1
- package/src/express-app/app.ts +3 -2
- package/src/types.ts +2 -0
package/build/types.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type ServiceLogger = pino.BaseLogger & Pick<pino.Logger, 'isLevelEnabled'
|
|
|
17
17
|
export interface ServiceLocals<Config extends ConfigurationSchema = ConfigurationSchema> {
|
|
18
18
|
service: Service;
|
|
19
19
|
name: string;
|
|
20
|
+
version: string;
|
|
20
21
|
logger: ServiceLogger;
|
|
21
22
|
config: Config;
|
|
22
23
|
meter: Meter;
|
|
@@ -53,6 +54,7 @@ export interface Service<SLocals extends AnyServiceLocals = ServiceLocals<Config
|
|
|
53
54
|
export type ServiceFactory<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>, RLocals extends RequestLocals = RequestLocals> = () => Service<SLocals, RLocals>;
|
|
54
55
|
export interface ServiceStartOptions<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>, RLocals extends RequestLocals = RequestLocals> {
|
|
55
56
|
name: string;
|
|
57
|
+
version: string;
|
|
56
58
|
rootDirectory: string;
|
|
57
59
|
codepath?: 'build' | 'src' | 'dist';
|
|
58
60
|
locals?: Partial<SLocals>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.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
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@opentelemetry/sdk-node": "^0.43.0",
|
|
81
81
|
"@opentelemetry/sdk-trace-base": "^1.17.1",
|
|
82
82
|
"@opentelemetry/semantic-conventions": "^1.17.1",
|
|
83
|
-
"@sesamecare-oss/confit": "^2.0.
|
|
83
|
+
"@sesamecare-oss/confit": "^2.0.1",
|
|
84
84
|
"@sesamecare-oss/opentelemetry-node-metrics": "^1.0.1",
|
|
85
85
|
"cookie-parser": "^1.4.6",
|
|
86
86
|
"dotenv": "^16.3.1",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"devDependencies": {
|
|
97
97
|
"@commitlint/cli": "^17.8.0",
|
|
98
98
|
"@commitlint/config-conventional": "^17.8.0",
|
|
99
|
-
"@openapi-typescript-infra/coconfig": "^4.2.
|
|
99
|
+
"@openapi-typescript-infra/coconfig": "^4.2.2",
|
|
100
100
|
"@semantic-release/changelog": "^6.0.3",
|
|
101
101
|
"@semantic-release/commit-analyzer": "^11.0.0",
|
|
102
102
|
"@semantic-release/exec": "^6.0.3",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"@types/lodash": "^4.14.200",
|
|
109
109
|
"@types/minimist": "^1.2.4",
|
|
110
110
|
"@types/node": "^20.8.7",
|
|
111
|
-
"@types/supertest": "^2.0.
|
|
111
|
+
"@types/supertest": "^2.0.15",
|
|
112
112
|
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
113
113
|
"@typescript-eslint/parser": "^6.8.0",
|
|
114
114
|
"coconfig": "^1.0.0",
|
package/src/bootstrap.ts
CHANGED
|
@@ -25,6 +25,8 @@ interface BootstrapArguments {
|
|
|
25
25
|
telemetry?: boolean;
|
|
26
26
|
// Don't bind to http port or expose metrics
|
|
27
27
|
nobind?: boolean;
|
|
28
|
+
// The version of the app, else discovered via read-pkg-up
|
|
29
|
+
version?: string;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
function resolveMain(packageJson: NormalizedPackageJson) {
|
|
@@ -39,6 +41,7 @@ async function getServiceDetails(argv: BootstrapArguments = {}) {
|
|
|
39
41
|
return {
|
|
40
42
|
rootDirectory: argv.root,
|
|
41
43
|
name: argv.name,
|
|
44
|
+
version: argv.version || '0.0.0',
|
|
42
45
|
main: argv.main || (isDev() && !argv.built ? 'src/index.ts' : 'build/index.js'),
|
|
43
46
|
};
|
|
44
47
|
}
|
|
@@ -55,6 +58,7 @@ async function getServiceDetails(argv: BootstrapArguments = {}) {
|
|
|
55
58
|
main,
|
|
56
59
|
rootDirectory: path.dirname(pkg.path),
|
|
57
60
|
name: parts[parts.length - 1],
|
|
61
|
+
version: pkg.packageJson.version,
|
|
58
62
|
};
|
|
59
63
|
}
|
|
60
64
|
|
|
@@ -72,7 +76,7 @@ export async function bootstrap<
|
|
|
72
76
|
SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>,
|
|
73
77
|
RLocals extends RequestLocals = RequestLocals,
|
|
74
78
|
>(argv?: BootstrapArguments) {
|
|
75
|
-
const { main, rootDirectory, name } = await getServiceDetails(argv);
|
|
79
|
+
const { main, rootDirectory, name, version } = await getServiceDetails(argv);
|
|
76
80
|
|
|
77
81
|
let entrypoint: string;
|
|
78
82
|
let codepath: 'build' | 'dist' | 'src' = 'build';
|
|
@@ -107,6 +111,7 @@ export async function bootstrap<
|
|
|
107
111
|
rootDirectory,
|
|
108
112
|
service: absoluteEntrypoint,
|
|
109
113
|
codepath,
|
|
114
|
+
version,
|
|
110
115
|
});
|
|
111
116
|
}
|
|
112
117
|
|
|
@@ -115,6 +120,7 @@ export async function bootstrap<
|
|
|
115
120
|
const impl = require(absoluteEntrypoint);
|
|
116
121
|
const opts: ServiceStartOptions<SLocals, RLocals> = {
|
|
117
122
|
name,
|
|
123
|
+
version,
|
|
118
124
|
rootDirectory,
|
|
119
125
|
service: impl.default || impl.service,
|
|
120
126
|
codepath,
|
package/src/express-app/app.ts
CHANGED
|
@@ -45,7 +45,7 @@ export async function startApp<
|
|
|
45
45
|
SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>,
|
|
46
46
|
RLocals extends RequestLocals = RequestLocals,
|
|
47
47
|
>(startOptions: ServiceStartOptions<SLocals, RLocals>): Promise<ServiceExpress<SLocals>> {
|
|
48
|
-
const { service, rootDirectory, codepath = 'build', name } = startOptions;
|
|
48
|
+
const { service, rootDirectory, codepath = 'build', name, version } = startOptions;
|
|
49
49
|
const shouldPrettyPrint = isDev() && !process.env.NO_PRETTY_LOGS;
|
|
50
50
|
const destination = pino.destination({
|
|
51
51
|
sync: isSyncLogging(),
|
|
@@ -99,11 +99,12 @@ export async function startApp<
|
|
|
99
99
|
app.disable('etag');
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
Object.assign(app.locals,
|
|
102
|
+
Object.assign(app.locals, startOptions.locals, {
|
|
103
103
|
service: serviceImpl,
|
|
104
104
|
logger,
|
|
105
105
|
config,
|
|
106
106
|
name,
|
|
107
|
+
version,
|
|
107
108
|
});
|
|
108
109
|
|
|
109
110
|
if (serviceImpl.attach) {
|
package/src/types.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type ServiceLogger = pino.BaseLogger & Pick<pino.Logger, 'isLevelEnabled'
|
|
|
24
24
|
export interface ServiceLocals<Config extends ConfigurationSchema = ConfigurationSchema> {
|
|
25
25
|
service: Service;
|
|
26
26
|
name: string;
|
|
27
|
+
version: string;
|
|
27
28
|
logger: ServiceLogger;
|
|
28
29
|
config: Config;
|
|
29
30
|
meter: Meter;
|
|
@@ -115,6 +116,7 @@ export interface ServiceStartOptions<
|
|
|
115
116
|
RLocals extends RequestLocals = RequestLocals,
|
|
116
117
|
> {
|
|
117
118
|
name: string;
|
|
119
|
+
version: string;
|
|
118
120
|
rootDirectory: string;
|
|
119
121
|
|
|
120
122
|
// Defaults to "build", but can be set to "src" to run off non-built source
|