@openapi-typescript-infra/service 4.26.0 → 4.27.1
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/build/bin/start-service.js +2 -2
- package/build/bin/start-service.js.map +1 -1
- package/build/bootstrap.d.ts +5 -0
- package/build/bootstrap.js +1 -1
- package/build/bootstrap.js.map +1 -1
- package/build/development/repl.d.ts +16 -1
- package/build/development/repl.js +61 -1
- package/build/development/repl.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/telemetry/index.d.ts +1 -0
- package/build/telemetry/index.js +1 -1
- package/build/telemetry/index.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +14 -14
- package/src/bin/start-service.ts +2 -2
- package/src/bootstrap.ts +1 -1
- package/src/development/repl.ts +85 -1
- package/src/index.ts +1 -0
- package/src/telemetry/index.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.27.1",
|
|
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": {
|
|
@@ -62,25 +62,25 @@
|
|
|
62
62
|
"@opentelemetry/api": "^1.9.0",
|
|
63
63
|
"@opentelemetry/exporter-prometheus": "^0.53.0",
|
|
64
64
|
"@opentelemetry/instrumentation-dns": "^0.39.0",
|
|
65
|
-
"@opentelemetry/instrumentation-express": "^0.
|
|
65
|
+
"@opentelemetry/instrumentation-express": "^0.43.0",
|
|
66
66
|
"@opentelemetry/instrumentation-generic-pool": "^0.39.0",
|
|
67
67
|
"@opentelemetry/instrumentation-graphql": "^0.43.0",
|
|
68
68
|
"@opentelemetry/instrumentation-http": "^0.53.0",
|
|
69
69
|
"@opentelemetry/instrumentation-ioredis": "^0.43.0",
|
|
70
70
|
"@opentelemetry/instrumentation-net": "^0.39.0",
|
|
71
|
-
"@opentelemetry/instrumentation-pg": "^0.
|
|
71
|
+
"@opentelemetry/instrumentation-pg": "^0.45.1",
|
|
72
72
|
"@opentelemetry/instrumentation-pino": "^0.42.0",
|
|
73
73
|
"@opentelemetry/instrumentation-undici": "^0.6.0",
|
|
74
|
-
"@opentelemetry/resource-detector-container": "^0.4.
|
|
75
|
-
"@opentelemetry/resource-detector-gcp": "^0.29.
|
|
74
|
+
"@opentelemetry/resource-detector-container": "^0.4.3",
|
|
75
|
+
"@opentelemetry/resource-detector-gcp": "^0.29.12",
|
|
76
76
|
"@opentelemetry/sdk-node": "^0.53.0",
|
|
77
77
|
"@opentelemetry/semantic-conventions": "^1.27.0",
|
|
78
78
|
"@sesamecare-oss/confit": "^2.2.1",
|
|
79
79
|
"@sesamecare-oss/opentelemetry-node-metrics": "^1.1.0",
|
|
80
80
|
"ajv": "^8.17.1",
|
|
81
|
-
"cookie-parser": "^1.4.
|
|
81
|
+
"cookie-parser": "^1.4.7",
|
|
82
82
|
"dotenv": "^16.4.5",
|
|
83
|
-
"express": "^5.0.
|
|
83
|
+
"express": "^5.0.1",
|
|
84
84
|
"express-openapi-validator": "^5.3.7",
|
|
85
85
|
"glob": "^8.1.0",
|
|
86
86
|
"lodash": "^4.17.21",
|
|
@@ -95,14 +95,14 @@
|
|
|
95
95
|
"@openapi-typescript-infra/coconfig": "^4.4.0",
|
|
96
96
|
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
97
97
|
"@semantic-release/exec": "^6.0.3",
|
|
98
|
-
"@semantic-release/github": "^
|
|
98
|
+
"@semantic-release/github": "^11.0.0",
|
|
99
99
|
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
100
100
|
"@types/cookie-parser": "^1.4.7",
|
|
101
|
-
"@types/express": "^
|
|
101
|
+
"@types/express": "^5.0.0",
|
|
102
102
|
"@types/glob": "^8.1.0",
|
|
103
|
-
"@types/lodash": "^4.17.
|
|
103
|
+
"@types/lodash": "^4.17.10",
|
|
104
104
|
"@types/minimist": "^1.2.5",
|
|
105
|
-
"@types/node": "^20.16.
|
|
105
|
+
"@types/node": "^20.16.11",
|
|
106
106
|
"@types/request-ip": "^0.0.41",
|
|
107
107
|
"@types/supertest": "^6.0.2",
|
|
108
108
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
@@ -110,14 +110,14 @@
|
|
|
110
110
|
"coconfig": "^1.5.2",
|
|
111
111
|
"eslint": "^8.57.1",
|
|
112
112
|
"eslint-config-prettier": "^9.1.0",
|
|
113
|
-
"eslint-plugin-import": "^2.
|
|
113
|
+
"eslint-plugin-import": "^2.31.0",
|
|
114
114
|
"pino-pretty": "^11.2.2",
|
|
115
115
|
"pinst": "^3.0.0",
|
|
116
116
|
"supertest": "^7.0.0",
|
|
117
117
|
"ts-node": "^10.9.2",
|
|
118
118
|
"tsconfig-paths": "^4.2.0",
|
|
119
|
-
"typescript": "^5.6.
|
|
120
|
-
"vitest": "^2.1.
|
|
119
|
+
"typescript": "^5.6.3",
|
|
120
|
+
"vitest": "^2.1.2"
|
|
121
121
|
},
|
|
122
122
|
"resolutions": {
|
|
123
123
|
"qs": "^6.11.0"
|
package/src/bin/start-service.ts
CHANGED
|
@@ -19,9 +19,9 @@ const noTelemetry = (argv.repl || isDev()) && !argv.telemetry;
|
|
|
19
19
|
bootstrap({
|
|
20
20
|
...argv,
|
|
21
21
|
telemetry: !noTelemetry,
|
|
22
|
-
}).then(({ app, server }) => {
|
|
22
|
+
}).then(({ app, codepath, server }) => {
|
|
23
23
|
if (argv.repl) {
|
|
24
|
-
serviceRepl(app, () => {
|
|
24
|
+
serviceRepl(app, codepath, () => {
|
|
25
25
|
server?.close();
|
|
26
26
|
});
|
|
27
27
|
}
|
package/src/bootstrap.ts
CHANGED
|
@@ -129,5 +129,5 @@ export async function bootstrap<
|
|
|
129
129
|
const { startApp, listen } = await import('./express-app/app.js');
|
|
130
130
|
const app = await startApp<SLocals, RLocals>(opts);
|
|
131
131
|
const server = argv?.nobind ? undefined : await listen(app);
|
|
132
|
-
return { server, app };
|
|
132
|
+
return { server, app, codepath };
|
|
133
133
|
}
|
package/src/development/repl.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import repl from 'repl';
|
|
1
|
+
import repl, { REPLServer } from 'repl';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
|
|
5
|
+
import { glob } from 'glob';
|
|
6
|
+
import { set } from 'lodash';
|
|
7
|
+
|
|
4
8
|
import { AnyServiceLocals, ServiceExpress, ServiceLocals } from '../types';
|
|
5
9
|
import { ConfigurationSchema } from '../config/schema';
|
|
6
10
|
|
|
11
|
+
const REPL_PROP = '$$repl$$';
|
|
12
|
+
|
|
13
|
+
interface WithReplProp {
|
|
14
|
+
[REPL_PROP]?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
export function serviceRepl<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(
|
|
8
18
|
app: ServiceExpress<SLocals>,
|
|
19
|
+
codepath: string | undefined,
|
|
9
20
|
onExit: () => void,
|
|
10
21
|
) {
|
|
11
22
|
const rl = repl.start({
|
|
@@ -25,5 +36,78 @@ export function serviceRepl<SLocals extends AnyServiceLocals = ServiceLocals<Con
|
|
|
25
36
|
}
|
|
26
37
|
});
|
|
27
38
|
app.locals.service.attachRepl?.(app, rl);
|
|
39
|
+
|
|
40
|
+
loadReplFunctions(app, codepath, rl);
|
|
41
|
+
|
|
28
42
|
rl.on('exit', onExit);
|
|
29
43
|
}
|
|
44
|
+
|
|
45
|
+
function loadReplFunctions<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(
|
|
46
|
+
app: ServiceExpress<SLocals>,
|
|
47
|
+
codepath: string | undefined,
|
|
48
|
+
rl: REPLServer,
|
|
49
|
+
) {
|
|
50
|
+
if (!codepath) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const files = glob.sync(path.join(codepath, '**/*.{js,ts}'));
|
|
55
|
+
|
|
56
|
+
files.forEach((file) => {
|
|
57
|
+
try {
|
|
58
|
+
// Read the file content as text
|
|
59
|
+
const fileContent = fs.readFileSync(file, 'utf-8');
|
|
60
|
+
|
|
61
|
+
// Check if repl$ is present, in a very rudimentary way
|
|
62
|
+
if (/repl\$\(/.test(fileContent)) {
|
|
63
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
|
|
64
|
+
const module = require(path.resolve(file));
|
|
65
|
+
|
|
66
|
+
// Look for functions with the REPL_PROP marker
|
|
67
|
+
Object.values(module).forEach((exported) => {
|
|
68
|
+
if (!exported) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (typeof exported === 'function') {
|
|
72
|
+
const replName = (exported as WithReplProp)[REPL_PROP];
|
|
73
|
+
if (replName) {
|
|
74
|
+
set(rl.context, replName, exported.bind(null, app));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error(`Failed to load REPL functions from ${file}:`, err);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Can't seem to sort out proper generics here, so we'll just use any since it's dev only
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
+
type ReplAny = any;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* This decorator-like function can be applied to functions and the service will load and expose
|
|
91
|
+
* the function when the repl is engaged.
|
|
92
|
+
*
|
|
93
|
+
* async function myFunction(app: MyService['App'], arg1: string, arg2: number) {
|
|
94
|
+
* }
|
|
95
|
+
* repl$(myFunction);
|
|
96
|
+
*
|
|
97
|
+
* or
|
|
98
|
+
*
|
|
99
|
+
* repl(myFunction, 'some.func.name');
|
|
100
|
+
*/
|
|
101
|
+
export function repl$<
|
|
102
|
+
S extends ServiceExpress<ReplAny>,
|
|
103
|
+
T extends (app: S, ...args: ReplAny[]) => ReplAny
|
|
104
|
+
>(fn: T, name?: string) {
|
|
105
|
+
const functionName = name || fn.name;
|
|
106
|
+
if (!functionName) {
|
|
107
|
+
throw new Error('Function must have a name or a name must be provided.');
|
|
108
|
+
}
|
|
109
|
+
Object.defineProperty(fn, REPL_PROP, {
|
|
110
|
+
enumerable: false,
|
|
111
|
+
value: functionName,
|
|
112
|
+
});
|
|
113
|
+
}
|
package/src/index.ts
CHANGED
package/src/telemetry/index.ts
CHANGED