@openapi-typescript-infra/service 4.4.0 → 4.5.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 +7 -0
- package/Makefile +12 -0
- package/build/config/index.d.ts +1 -0
- package/build/config/index.js +1 -0
- package/build/config/index.js.map +1 -1
- package/build/config/schema.d.ts +1 -1
- package/build/config/validation.d.ts +10 -0
- package/build/config/validation.js +12 -0
- package/build/config/validation.js.map +1 -0
- package/build/express-app/app.js +1 -1
- package/build/express-app/app.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/config/index.ts +1 -0
- package/src/config/schema.ts +1 -1
- package/src/config/validation.ts +22 -0
- package/src/express-app/app.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.5.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": {
|
package/src/config/index.ts
CHANGED
package/src/config/schema.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface ConfigurationSchema extends BaseConfitSchema {
|
|
|
66
66
|
// Note that generally it's better to offload tls termination,
|
|
67
67
|
// but this is useful for dev.
|
|
68
68
|
key?: string | Uint8Array;
|
|
69
|
-
certificate?: string;
|
|
69
|
+
certificate?: string | Uint8Array;
|
|
70
70
|
// If you have an alternate host name (other than localhost) that
|
|
71
71
|
// should be used when referring to this service, set it here.
|
|
72
72
|
hostname?: string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ConfigurationSchema } from './schema';
|
|
2
|
+
|
|
3
|
+
export interface ConfigValidationError {
|
|
4
|
+
path: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type ConfigurationValidator<Config extends ConfigurationSchema> = (config: Config) => {
|
|
9
|
+
success: boolean;
|
|
10
|
+
errors: ConfigValidationError[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function validateConfiguration<Config extends ConfigurationSchema>(
|
|
14
|
+
config: Config,
|
|
15
|
+
validator: ConfigurationValidator<Config>,
|
|
16
|
+
) {
|
|
17
|
+
const result = validator(config);
|
|
18
|
+
if (!result.success) {
|
|
19
|
+
throw new Error(`Configuration validation failed:
|
|
20
|
+
${result.errors.map((e) => ` - ${e.path}: ${e.message}`).join('\n')}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/express-app/app.ts
CHANGED