@openapi-typescript-infra/service 4.27.2 → 5.0.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/{.eslintrc.js → .eslintrc.cjs} +1 -1
- package/{.prettierrc.js → .prettierrc.cjs} +1 -1
- package/Makefile +1 -1
- package/build/bin/start-service.js +8 -13
- package/build/bin/start-service.js.map +1 -1
- package/build/bootstrap.d.ts +4 -4
- package/build/bootstrap.js +17 -29
- package/build/bootstrap.js.map +1 -1
- package/build/config/index.d.ts +3 -3
- package/build/config/index.js +15 -36
- package/build/config/index.js.map +1 -1
- package/build/config/schema.js +1 -2
- package/build/config/shortstops.js +19 -25
- package/build/config/shortstops.js.map +1 -1
- package/build/config/validation.d.ts +1 -1
- package/build/config/validation.js +1 -4
- package/build/config/validation.js.map +1 -1
- package/build/development/port-finder.js +6 -12
- package/build/development/port-finder.js.map +1 -1
- package/build/development/repl.d.ts +2 -2
- package/build/development/repl.js +16 -24
- package/build/development/repl.js.map +1 -1
- package/build/env.js +5 -12
- package/build/env.js.map +1 -1
- package/build/error.d.ts +2 -2
- package/build/error.js +1 -5
- package/build/error.js.map +1 -1
- package/build/express-app/app.d.ts +2 -2
- package/build/express-app/app.js +44 -52
- package/build/express-app/app.js.map +1 -1
- package/build/express-app/index.d.ts +3 -3
- package/build/express-app/index.js +3 -19
- package/build/express-app/index.js.map +1 -1
- package/build/express-app/internal-server.d.ts +2 -2
- package/build/express-app/internal-server.js +5 -11
- package/build/express-app/internal-server.js.map +1 -1
- package/build/express-app/modules.d.ts +0 -1
- package/build/express-app/modules.js +6 -24
- package/build/express-app/modules.js.map +1 -1
- package/build/express-app/route-loader.d.ts +2 -2
- package/build/express-app/route-loader.js +10 -16
- package/build/express-app/route-loader.js.map +1 -1
- package/build/express-app/types.d.ts +2 -2
- package/build/express-app/types.js +1 -2
- package/build/hook.d.ts +2 -2
- package/build/hook.js +1 -4
- package/build/hook.js.map +1 -1
- package/build/index.d.ts +9 -9
- package/build/index.js +9 -27
- package/build/index.js.map +1 -1
- package/build/openapi.d.ts +3 -3
- package/build/openapi.js +17 -46
- package/build/openapi.js.map +1 -1
- package/build/telemetry/DummyExporter.js +3 -7
- package/build/telemetry/DummyExporter.js.map +1 -1
- package/build/telemetry/index.d.ts +3 -3
- package/build/telemetry/index.js +22 -51
- package/build/telemetry/index.js.map +1 -1
- package/build/telemetry/instrumentations.js +19 -22
- package/build/telemetry/instrumentations.js.map +1 -1
- package/build/telemetry/requestLogger.d.ts +2 -2
- package/build/telemetry/requestLogger.js +10 -18
- package/build/telemetry/requestLogger.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +2 -2
- package/build/types.js +1 -2
- package/package.json +14 -13
- package/src/bin/start-service.ts +3 -3
- package/src/bootstrap.ts +12 -17
- package/src/config/index.ts +4 -4
- package/src/config/validation.ts +1 -1
- package/src/development/port-finder.ts +1 -1
- package/src/development/repl.ts +6 -7
- package/src/error.ts +2 -2
- package/src/express-app/app.ts +11 -11
- package/src/express-app/index.ts +3 -3
- package/src/express-app/internal-server.ts +3 -3
- package/src/express-app/modules.ts +4 -22
- package/src/express-app/route-loader.ts +6 -6
- package/src/express-app/types.ts +2 -2
- package/src/hook.ts +2 -2
- package/src/index.ts +9 -9
- package/src/openapi.ts +6 -6
- package/src/telemetry/index.ts +5 -5
- package/src/telemetry/requestLogger.ts +7 -7
- package/src/types.ts +2 -2
- package/tsconfig.json +4 -3
package/build/types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Server } from 'http';
|
|
2
2
|
import type { REPLServer } from 'repl';
|
|
3
|
-
import type pino from 'pino';
|
|
3
|
+
import type { pino } 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';
|
|
7
7
|
import type { Meter } from '@opentelemetry/api';
|
|
8
8
|
import { ShortstopHandler } from '@sesamecare-oss/confit';
|
|
9
|
-
import { ConfigurationSchema } from './config/schema';
|
|
9
|
+
import { ConfigurationSchema } from './config/schema.js';
|
|
10
10
|
export interface InternalLocals<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>> extends Record<string, unknown> {
|
|
11
11
|
server?: Server;
|
|
12
12
|
mainApp: ServiceExpress<SLocals>;
|
package/build/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.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": "./build/index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "vitest",
|
|
8
9
|
"lint": "eslint .",
|
|
@@ -68,10 +69,10 @@
|
|
|
68
69
|
"@opentelemetry/instrumentation-http": "^0.53.0",
|
|
69
70
|
"@opentelemetry/instrumentation-ioredis": "^0.43.0",
|
|
70
71
|
"@opentelemetry/instrumentation-net": "^0.39.0",
|
|
71
|
-
"@opentelemetry/instrumentation-pg": "^0.
|
|
72
|
+
"@opentelemetry/instrumentation-pg": "^0.46.0",
|
|
72
73
|
"@opentelemetry/instrumentation-pino": "^0.42.0",
|
|
73
74
|
"@opentelemetry/instrumentation-undici": "^0.6.0",
|
|
74
|
-
"@opentelemetry/resource-detector-container": "^0.4.
|
|
75
|
+
"@opentelemetry/resource-detector-container": "^0.4.4",
|
|
75
76
|
"@opentelemetry/resource-detector-gcp": "^0.29.12",
|
|
76
77
|
"@opentelemetry/sdk-node": "^0.53.0",
|
|
77
78
|
"@opentelemetry/semantic-conventions": "^1.27.0",
|
|
@@ -82,11 +83,11 @@
|
|
|
82
83
|
"dotenv": "^16.4.5",
|
|
83
84
|
"express": "^5.0.1",
|
|
84
85
|
"express-openapi-validator": "^5.3.7",
|
|
85
|
-
"glob": "^
|
|
86
|
+
"glob": "^11.0.0",
|
|
86
87
|
"lodash": "^4.17.21",
|
|
87
88
|
"minimist": "^1.2.8",
|
|
88
|
-
"pino": "^9.
|
|
89
|
-
"read-
|
|
89
|
+
"pino": "^9.5.0",
|
|
90
|
+
"read-package-up": "^11.0.0",
|
|
90
91
|
"request-ip": "^3.3.0"
|
|
91
92
|
},
|
|
92
93
|
"devDependencies": {
|
|
@@ -99,25 +100,25 @@
|
|
|
99
100
|
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
100
101
|
"@types/cookie-parser": "^1.4.7",
|
|
101
102
|
"@types/express": "^5.0.0",
|
|
102
|
-
"@types/glob": "^8.1.0",
|
|
103
103
|
"@types/lodash": "^4.17.10",
|
|
104
104
|
"@types/minimist": "^1.2.5",
|
|
105
|
-
"@types/node": "^
|
|
105
|
+
"@types/node": "^22.7.6",
|
|
106
106
|
"@types/request-ip": "^0.0.41",
|
|
107
107
|
"@types/supertest": "^6.0.2",
|
|
108
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
109
|
-
"@typescript-eslint/parser": "^
|
|
108
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
109
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
110
110
|
"coconfig": "^1.5.2",
|
|
111
111
|
"eslint": "^8.57.1",
|
|
112
112
|
"eslint-config-prettier": "^9.1.0",
|
|
113
|
+
"eslint-import-resolver-typescript": "^3.6.3",
|
|
113
114
|
"eslint-plugin-import": "^2.31.0",
|
|
114
|
-
"pino-pretty": "^11.
|
|
115
|
+
"pino-pretty": "^11.3.0",
|
|
115
116
|
"pinst": "^3.0.0",
|
|
116
117
|
"supertest": "^7.0.0",
|
|
117
118
|
"ts-node": "^10.9.2",
|
|
118
119
|
"tsconfig-paths": "^4.2.0",
|
|
119
120
|
"typescript": "^5.6.3",
|
|
120
|
-
"vitest": "^2.1.
|
|
121
|
+
"vitest": "^2.1.3"
|
|
121
122
|
},
|
|
122
123
|
"resolutions": {
|
|
123
124
|
"qs": "^6.11.0"
|
package/src/bin/start-service.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import minimist from 'minimist';
|
|
3
3
|
|
|
4
|
-
import { serviceRepl } from '../development/repl';
|
|
5
|
-
import { isDev } from '../env';
|
|
6
|
-
import { bootstrap } from '../bootstrap';
|
|
4
|
+
import { serviceRepl } from '../development/repl.js';
|
|
5
|
+
import { isDev } from '../env.js';
|
|
6
|
+
import { bootstrap } from '../bootstrap.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* built - forces the use of the build directory. Defaults to true in stage/prod, not in dev
|
package/src/bootstrap.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import assert from 'node:assert';
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import readPackageUp from 'read-
|
|
6
|
-
import type { NormalizedPackageJson } from 'read-
|
|
4
|
+
import { config } from 'dotenv';
|
|
5
|
+
import { readPackageUp } from 'read-package-up';
|
|
6
|
+
import type { NormalizedPackageJson } from 'read-package-up';
|
|
7
7
|
|
|
8
|
-
import type { AnyServiceLocals, RequestLocals, ServiceLocals, ServiceStartOptions } from './types';
|
|
9
|
-
import { isDev } from './env';
|
|
10
|
-
import { startWithTelemetry } from './telemetry/index';
|
|
11
|
-
import { ConfigurationSchema } from './config/schema';
|
|
8
|
+
import type { AnyServiceLocals, RequestLocals, ServiceLocals, ServiceStartOptions } from './types.js';
|
|
9
|
+
import { isDev } from './env.js';
|
|
10
|
+
import { startWithTelemetry } from './telemetry/index.js';
|
|
11
|
+
import { ConfigurationSchema } from './config/schema.js';
|
|
12
12
|
|
|
13
13
|
interface BootstrapArguments {
|
|
14
|
-
// The name of the service, else discovered via read-
|
|
14
|
+
// The name of the service, else discovered via read-package-up
|
|
15
15
|
name?: string;
|
|
16
16
|
// The name of the file with the service function, relative to root
|
|
17
17
|
main?: string;
|
|
18
|
-
// Root directory of the app, else discovered via read-
|
|
18
|
+
// Root directory of the app, else discovered via read-package-up
|
|
19
19
|
root?: string;
|
|
20
20
|
// Use built directory. Omitting lets us determine a sensible default
|
|
21
21
|
built?: boolean;
|
|
@@ -25,7 +25,7 @@ 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-
|
|
28
|
+
// The version of the app, else discovered via read-package-up
|
|
29
29
|
version?: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -84,11 +84,6 @@ export async function bootstrap<
|
|
|
84
84
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
85
85
|
const { register } = await import('ts-node');
|
|
86
86
|
register();
|
|
87
|
-
try {
|
|
88
|
-
require('tsconfig-paths/register');
|
|
89
|
-
} catch (error) {
|
|
90
|
-
// No action needed
|
|
91
|
-
}
|
|
92
87
|
if (main) {
|
|
93
88
|
entrypoint = main.replace(/^(\.?\/?)(build|dist)\//, '$1src/').replace(/\.js$/, '.ts');
|
|
94
89
|
} else {
|
|
@@ -102,7 +97,7 @@ export async function bootstrap<
|
|
|
102
97
|
entrypoint = './build/index.js';
|
|
103
98
|
}
|
|
104
99
|
|
|
105
|
-
|
|
100
|
+
config();
|
|
106
101
|
|
|
107
102
|
const absoluteEntrypoint = path.resolve(rootDirectory, entrypoint);
|
|
108
103
|
if (argv?.telemetry) {
|
|
@@ -117,7 +112,7 @@ export async function bootstrap<
|
|
|
117
112
|
|
|
118
113
|
// This needs to be required for TS on-the-fly to work
|
|
119
114
|
// eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
|
|
120
|
-
const impl =
|
|
115
|
+
const impl = await import(absoluteEntrypoint);
|
|
121
116
|
const opts: ServiceStartOptions<SLocals, RLocals> = {
|
|
122
117
|
name,
|
|
123
118
|
version,
|
package/src/config/index.ts
CHANGED
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
confit,
|
|
10
10
|
} from '@sesamecare-oss/confit';
|
|
11
11
|
|
|
12
|
-
import { getAvailablePort } from '../development/port-finder';
|
|
12
|
+
import { getAvailablePort } from '../development/port-finder.js';
|
|
13
13
|
|
|
14
|
-
import type { ConfigurationSchema } from './schema';
|
|
14
|
+
import type { ConfigurationSchema } from './schema.js';
|
|
15
15
|
|
|
16
16
|
// Order matters here.
|
|
17
17
|
const ENVIRONMENTS = ['production', 'staging', 'test', 'development'] as const;
|
|
@@ -121,5 +121,5 @@ export function insertConfigurationBefore(
|
|
|
121
121
|
return copy;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
export * from './schema';
|
|
125
|
-
export * from './validation';
|
|
124
|
+
export * from './schema.js';
|
|
125
|
+
export * from './validation.js';
|
package/src/config/validation.ts
CHANGED
package/src/development/repl.ts
CHANGED
|
@@ -5,8 +5,8 @@ import path from 'path';
|
|
|
5
5
|
import { glob } from 'glob';
|
|
6
6
|
import { set } from 'lodash';
|
|
7
7
|
|
|
8
|
-
import { AnyServiceLocals, ServiceExpress, ServiceLocals } from '../types';
|
|
9
|
-
import { ConfigurationSchema } from '../config/schema';
|
|
8
|
+
import { AnyServiceLocals, ServiceExpress, ServiceLocals } from '../types.js';
|
|
9
|
+
import { ConfigurationSchema } from '../config/schema.js';
|
|
10
10
|
|
|
11
11
|
const REPL_PROP = '$$repl$$';
|
|
12
12
|
|
|
@@ -42,7 +42,7 @@ export function serviceRepl<SLocals extends AnyServiceLocals = ServiceLocals<Con
|
|
|
42
42
|
rl.on('exit', onExit);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function loadReplFunctions<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(
|
|
45
|
+
async function loadReplFunctions<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(
|
|
46
46
|
app: ServiceExpress<SLocals>,
|
|
47
47
|
codepath: string | undefined,
|
|
48
48
|
rl: REPLServer,
|
|
@@ -53,15 +53,14 @@ function loadReplFunctions<SLocals extends AnyServiceLocals = ServiceLocals<Conf
|
|
|
53
53
|
|
|
54
54
|
const files = glob.sync(path.join(codepath, '**/*.{js,ts}'));
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
for (const file of files) {
|
|
57
57
|
try {
|
|
58
58
|
// Read the file content as text
|
|
59
59
|
const fileContent = fs.readFileSync(file, 'utf-8');
|
|
60
60
|
|
|
61
61
|
// Check if repl$ is present, in a very rudimentary way (note built JS has close paren not open)
|
|
62
62
|
if (/repl\$[()]/.test(fileContent)) {
|
|
63
|
-
|
|
64
|
-
const module = require(path.resolve(file));
|
|
63
|
+
const module = await import(path.resolve(file));
|
|
65
64
|
|
|
66
65
|
// Look for functions with the REPL_PROP marker
|
|
67
66
|
Object.values(module).forEach((exported) => {
|
|
@@ -79,7 +78,7 @@ function loadReplFunctions<SLocals extends AnyServiceLocals = ServiceLocals<Conf
|
|
|
79
78
|
} catch (err) {
|
|
80
79
|
console.error(`Failed to load REPL functions from ${file}:`, err);
|
|
81
80
|
}
|
|
82
|
-
}
|
|
81
|
+
}
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
// Can't seem to sort out proper generics here, so we'll just use any since it's dev only
|
package/src/error.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConfigurationSchema } from './config/schema';
|
|
2
|
-
import type { AnyServiceLocals, ServiceLike, ServiceLocals } from './types';
|
|
1
|
+
import { ConfigurationSchema } from './config/schema.js';
|
|
2
|
+
import type { AnyServiceLocals, ServiceLike, ServiceLocals } from './types.js';
|
|
3
3
|
|
|
4
4
|
export interface ServiceErrorSpec {
|
|
5
5
|
status?: number;
|
package/src/express-app/app.ts
CHANGED
|
@@ -10,13 +10,13 @@ import { setupNodeMetrics } from '@sesamecare-oss/opentelemetry-node-metrics';
|
|
|
10
10
|
import { createTerminus } from '@godaddy/terminus';
|
|
11
11
|
import type { RequestHandler, Response } from 'express';
|
|
12
12
|
|
|
13
|
-
import { loadConfiguration } from '../config/index';
|
|
14
|
-
import { openApi } from '../openapi';
|
|
13
|
+
import { loadConfiguration } from '../config/index.js';
|
|
14
|
+
import { openApi } from '../openapi.js';
|
|
15
15
|
import {
|
|
16
16
|
errorHandlerMiddleware,
|
|
17
17
|
loggerMiddleware,
|
|
18
18
|
notFoundMiddleware,
|
|
19
|
-
} from '../telemetry/requestLogger';
|
|
19
|
+
} from '../telemetry/requestLogger.js';
|
|
20
20
|
import type {
|
|
21
21
|
AnyServiceLocals,
|
|
22
22
|
RequestLocals,
|
|
@@ -25,14 +25,14 @@ import type {
|
|
|
25
25
|
ServiceLocals,
|
|
26
26
|
ServiceOptions,
|
|
27
27
|
ServiceStartOptions,
|
|
28
|
-
} from '../types';
|
|
29
|
-
import { ConfigurationSchema } from '../config/schema';
|
|
30
|
-
import { shortstops } from '../config/shortstops';
|
|
31
|
-
import { getNodeEnv, isDev } from '../env';
|
|
32
|
-
import { getGlobalPrometheusExporter } from '../telemetry/index';
|
|
33
|
-
|
|
34
|
-
import { loadRoutes } from './route-loader';
|
|
35
|
-
import { startInternalApp } from './internal-server';
|
|
28
|
+
} from '../types.js';
|
|
29
|
+
import { ConfigurationSchema } from '../config/schema.js';
|
|
30
|
+
import { shortstops } from '../config/shortstops.js';
|
|
31
|
+
import { getNodeEnv, isDev } from '../env.js';
|
|
32
|
+
import { getGlobalPrometheusExporter } from '../telemetry/index.js';
|
|
33
|
+
|
|
34
|
+
import { loadRoutes } from './route-loader.js';
|
|
35
|
+
import { startInternalApp } from './internal-server.js';
|
|
36
36
|
|
|
37
37
|
function isSyncLogging() {
|
|
38
38
|
if (process.env.LOG_SYNC) {
|
package/src/express-app/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './app';
|
|
2
|
-
export * from './types';
|
|
3
|
-
export * from './modules';
|
|
1
|
+
export * from './app.js';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export * from './modules.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import type { Application } from 'express-serve-static-core';
|
|
3
3
|
|
|
4
|
-
import { AnyServiceLocals, InternalLocals, ServiceExpress, ServiceLocals } from '../types';
|
|
5
|
-
import { getAvailablePort } from '../development/port-finder';
|
|
6
|
-
import { ConfigurationSchema } from '../config/schema';
|
|
4
|
+
import { AnyServiceLocals, InternalLocals, ServiceExpress, ServiceLocals } from '../types.js';
|
|
5
|
+
import { getAvailablePort } from '../development/port-finder.js';
|
|
6
|
+
import { ConfigurationSchema } from '../config/schema.js';
|
|
7
7
|
|
|
8
8
|
export async function startInternalApp<
|
|
9
9
|
SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>,
|
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
import { glob } from 'glob';
|
|
2
2
|
|
|
3
|
-
export async function loadModule(path: string): Promise<Record<string, unknown>> {
|
|
4
|
-
try {
|
|
5
|
-
return require(path);
|
|
6
|
-
} catch (error) {
|
|
7
|
-
if ((error as Error).message.includes('Cannot use import statement outside a module')) {
|
|
8
|
-
return import(path);
|
|
9
|
-
}
|
|
10
|
-
throw error;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
3
|
export async function getFilesInDir(pattern: string, dir: string) {
|
|
15
|
-
const files
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
nodir: true,
|
|
20
|
-
strict: true,
|
|
21
|
-
cwd: dir,
|
|
22
|
-
ignore: ['**/*.spec.@(js|ts)', '**/*.test.@(js|ts)', '**/*.fixtures.@(js|ts)'],
|
|
23
|
-
},
|
|
24
|
-
(error, matches) => (error ? reject(error) : accept(matches)),
|
|
25
|
-
);
|
|
4
|
+
const files = await glob(pattern, {
|
|
5
|
+
nodir: true,
|
|
6
|
+
cwd: dir,
|
|
7
|
+
ignore: ['**/*.spec.@(js|ts)', '**/*.test.@(js|ts)', '**/*.fixtures.@(js|ts)'],
|
|
26
8
|
});
|
|
27
9
|
return files;
|
|
28
10
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Router } from 'express';
|
|
4
4
|
|
|
5
|
-
import type { AnyServiceLocals, ServiceExpress, ServiceLocals } from '../types';
|
|
6
|
-
import { ConfigurationSchema } from '../config/schema';
|
|
5
|
+
import type { AnyServiceLocals, ServiceExpress, ServiceLocals } from '../types.js';
|
|
6
|
+
import { ConfigurationSchema } from '../config/schema.js';
|
|
7
7
|
|
|
8
|
-
import { getFilesInDir
|
|
8
|
+
import { getFilesInDir } from './modules.js';
|
|
9
9
|
|
|
10
10
|
export async function loadRoutes<
|
|
11
11
|
SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>,
|
|
@@ -16,10 +16,10 @@ export async function loadRoutes<
|
|
|
16
16
|
files.map(async (filename) => {
|
|
17
17
|
const routeBase = path.dirname(filename);
|
|
18
18
|
const modulePath = path.resolve(routingDir, filename);
|
|
19
|
-
const module = await
|
|
19
|
+
const module = await import(modulePath);
|
|
20
20
|
const mounter = module.default || module.route;
|
|
21
21
|
if (typeof mounter === 'function') {
|
|
22
|
-
const childRouter =
|
|
22
|
+
const childRouter = Router();
|
|
23
23
|
mounter(childRouter, app);
|
|
24
24
|
const pathParts = [''];
|
|
25
25
|
if (routeBase !== '.') {
|
package/src/express-app/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NextFunction, Response } from 'express';
|
|
2
2
|
|
|
3
|
-
import type { AnyServiceLocals, RequestLocals, RequestWithApp, ServiceLocals } from '../types';
|
|
4
|
-
import { ConfigurationSchema } from '../config/schema';
|
|
3
|
+
import type { AnyServiceLocals, RequestLocals, RequestWithApp, ServiceLocals } from '../types.js';
|
|
4
|
+
import { ConfigurationSchema } from '../config/schema.js';
|
|
5
5
|
|
|
6
6
|
export type ServiceHandler<
|
|
7
7
|
SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>,
|
package/src/hook.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConfigurationSchema } from './config/schema';
|
|
2
|
-
import type { AnyServiceLocals, RequestLocals, Service, ServiceLocals } from './types';
|
|
1
|
+
import { ConfigurationSchema } from './config/schema.js';
|
|
2
|
+
import type { AnyServiceLocals, RequestLocals, Service, ServiceLocals } from './types.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Your service should call this function and then "inherit"
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './telemetry';
|
|
2
|
-
export * from './express-app';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export * from './env';
|
|
5
|
-
export * from './config';
|
|
6
|
-
export * from './error';
|
|
7
|
-
export * from './bootstrap';
|
|
8
|
-
export * from './hook';
|
|
9
|
-
export { repl$ } from './development/repl';
|
|
1
|
+
export * from './telemetry/index.js';
|
|
2
|
+
export * from './express-app/index.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './env.js';
|
|
5
|
+
export * from './config/index.js';
|
|
6
|
+
export * from './error.js';
|
|
7
|
+
export * from './bootstrap.js';
|
|
8
|
+
export * from './hook.js';
|
|
9
|
+
export { repl$ } from './development/repl.js';
|
package/src/openapi.ts
CHANGED
|
@@ -2,13 +2,13 @@ import path from 'path';
|
|
|
2
2
|
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import * as OpenApiValidator from 'express-openapi-validator';
|
|
5
|
-
import { OpenAPIFramework } from 'express-openapi-validator/dist/framework/index';
|
|
5
|
+
import { OpenAPIFramework } from 'express-openapi-validator/dist/framework/index.js';
|
|
6
6
|
import type { Handler, Request, RequestHandler } from 'express';
|
|
7
7
|
|
|
8
|
-
import type { AnyServiceLocals, ServiceExpress, ServiceLocals } from './types';
|
|
9
|
-
import { getNodeEnv } from './env';
|
|
10
|
-
import { getFilesInDir
|
|
11
|
-
import { ConfigurationSchema } from './config/schema';
|
|
8
|
+
import type { AnyServiceLocals, ServiceExpress, ServiceLocals } from './types.js';
|
|
9
|
+
import { getNodeEnv } from './env.js';
|
|
10
|
+
import { getFilesInDir } from './express-app/modules.js';
|
|
11
|
+
import { ConfigurationSchema } from './config/schema.js';
|
|
12
12
|
|
|
13
13
|
const notImplementedHandler: Handler = (req, res) => {
|
|
14
14
|
res.status(501).json({
|
|
@@ -46,7 +46,7 @@ export async function openApi<
|
|
|
46
46
|
const preloadedModules = await Promise.all(
|
|
47
47
|
moduleFiles.map((file) => {
|
|
48
48
|
const fullPath = path.join(basePath, file);
|
|
49
|
-
return
|
|
49
|
+
return import(fullPath).catch((error) => {
|
|
50
50
|
app.locals.logger.warn(
|
|
51
51
|
{ file: fullPath, message: error.message },
|
|
52
52
|
'Could not load potential API handler',
|
package/src/telemetry/index.ts
CHANGED
|
@@ -16,12 +16,12 @@ import type {
|
|
|
16
16
|
RequestLocals,
|
|
17
17
|
ServiceLocals,
|
|
18
18
|
ServiceStartOptions,
|
|
19
|
-
} from '../types';
|
|
20
|
-
import type { ListenFn, StartAppFn } from '../express-app/index';
|
|
21
|
-
import type { ConfigurationSchema } from '../config/schema';
|
|
19
|
+
} from '../types.js';
|
|
20
|
+
import type { ListenFn, StartAppFn } from '../express-app/index.js';
|
|
21
|
+
import type { ConfigurationSchema } from '../config/schema.js';
|
|
22
22
|
|
|
23
|
-
import { getAutoInstrumentations } from './instrumentations';
|
|
24
|
-
import { DummySpanExporter } from './DummyExporter';
|
|
23
|
+
import { getAutoInstrumentations } from './instrumentations.js';
|
|
24
|
+
import { DummySpanExporter } from './DummyExporter.js';
|
|
25
25
|
|
|
26
26
|
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
|
|
27
27
|
opentelemetry.api.diag.setLogger(new (opentelemetry.api.DiagConsoleLogger)(), opentelemetry.api.DiagLogLevel.INFO);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { RequestHandler, Request, Response, ErrorRequestHandler } from 'express';
|
|
2
|
-
import
|
|
2
|
+
import { getClientIp } from 'request-ip';
|
|
3
3
|
import { Histogram } from '@opentelemetry/api';
|
|
4
4
|
|
|
5
|
-
import { ServiceError } from '../error';
|
|
6
|
-
import type { AnyServiceLocals, RequestWithApp, ServiceExpress, ServiceLocals } from '../types';
|
|
7
|
-
import type { ServiceHandler } from '../express-app/types';
|
|
8
|
-
import { ConfigurationSchema } from '../config/schema';
|
|
9
|
-
import { getNodeEnv } from '../env';
|
|
5
|
+
import { ServiceError } from '../error.js';
|
|
6
|
+
import type { AnyServiceLocals, RequestWithApp, ServiceExpress, ServiceLocals } from '../types.js';
|
|
7
|
+
import type { ServiceHandler } from '../express-app/types.js';
|
|
8
|
+
import { ConfigurationSchema } from '../config/schema.js';
|
|
9
|
+
import { getNodeEnv } from '../env.js';
|
|
10
10
|
|
|
11
11
|
const LOG_PREFS = Symbol('Logging information');
|
|
12
12
|
|
|
@@ -36,7 +36,7 @@ function getBasicInfo(req: Request): [string, Record<string, string | number>] {
|
|
|
36
36
|
const url = req.originalUrl || req.url;
|
|
37
37
|
|
|
38
38
|
const preInfo: Record<string, string> = {
|
|
39
|
-
ip:
|
|
39
|
+
ip: getClientIp(req) || '',
|
|
40
40
|
m: req.method,
|
|
41
41
|
};
|
|
42
42
|
|
package/src/types.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Server } from 'http';
|
|
2
2
|
import type { REPLServer } from 'repl';
|
|
3
3
|
|
|
4
|
-
import type pino from 'pino';
|
|
4
|
+
import type { pino } 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';
|
|
8
8
|
import type { Meter } from '@opentelemetry/api';
|
|
9
9
|
import { ShortstopHandler } from '@sesamecare-oss/confit';
|
|
10
10
|
|
|
11
|
-
import { ConfigurationSchema } from './config/schema';
|
|
11
|
+
import { ConfigurationSchema } from './config/schema.js';
|
|
12
12
|
|
|
13
13
|
export interface InternalLocals<
|
|
14
14
|
SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>,
|
package/tsconfig.json
CHANGED
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
],
|
|
15
15
|
"ts-node": {
|
|
16
16
|
"transpileOnly": true,
|
|
17
|
-
"files": true
|
|
17
|
+
"files": true,
|
|
18
|
+
"esm": true
|
|
18
19
|
},
|
|
19
20
|
"compilerOptions": {
|
|
20
21
|
"lib": [
|
|
21
22
|
"ES2022",
|
|
22
23
|
"DOM"
|
|
23
24
|
],
|
|
24
|
-
"module": "
|
|
25
|
-
"moduleResolution": "
|
|
25
|
+
"module": "Node16",
|
|
26
|
+
"moduleResolution": "node16",
|
|
26
27
|
"target": "ES2022",
|
|
27
28
|
"declaration": true,
|
|
28
29
|
"sourceMap": true,
|