@openapi-typescript-infra/service 4.2.0 → 4.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openapi-typescript-infra/service",
3
- "version": "4.2.0",
3
+ "version": "4.3.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": {
@@ -17,6 +17,7 @@
17
17
  "url": "git+https://github.com/openapi-typescript-infra/service.git"
18
18
  },
19
19
  "bin": {
20
+ "generate-config-schema": "./build/bin/generate-config-schema.js",
20
21
  "start-service": "./build/bin/start-service.js"
21
22
  },
22
23
  "config": {
@@ -82,6 +83,7 @@
82
83
  "@opentelemetry/semantic-conventions": "^1.17.1",
83
84
  "@sesamecare-oss/confit": "^2.0.1",
84
85
  "@sesamecare-oss/opentelemetry-node-metrics": "^1.0.1",
86
+ "ajv": "^8.12.0",
85
87
  "cookie-parser": "^1.4.6",
86
88
  "dotenv": "^16.3.1",
87
89
  "express": "next",
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import { spawnSync } from 'child_process';
4
+
5
+ import Ajv from 'ajv';
6
+ import standaloneCode from 'ajv/dist/standalone';
7
+ import minimist from 'minimist';
8
+
9
+ // Generate an AJV validator from a Typescript type
10
+ // This is mostly included since we already have AJV,
11
+ // and we want you to use it to validate configurations.
12
+ const argv = minimist(process.argv.slice(2));
13
+
14
+ async function run() {
15
+ // First we need to run typescript-json-schema to
16
+ // generate the JSON schema. We use npx to avoid the
17
+ // runtime dependency.
18
+ const tsJsonSchema = spawnSync(
19
+ 'npx',
20
+ [
21
+ '-y',
22
+ 'typescript-json-schema',
23
+ argv.tsconfig || 'tsconfig.build.json',
24
+ argv.type,
25
+ '--required',
26
+ '--noExtraProps',
27
+ '--strictNullChecks',
28
+ '--include',
29
+ argv.source || 'src/types/config.ts',
30
+ ],
31
+ {
32
+ stdio: 'pipe',
33
+ encoding: 'utf-8',
34
+ },
35
+ );
36
+ if (tsJsonSchema.status !== 0) {
37
+ console.error(tsJsonSchema.stderr);
38
+ process.exit(1);
39
+ }
40
+ const schema = JSON.parse(tsJsonSchema.stdout);
41
+
42
+ const ajv = new Ajv({ code: { source: true, esm: true } });
43
+ const validate = ajv.compile(schema);
44
+ const moduleCode = standaloneCode(ajv, validate);
45
+ if (argv.output) {
46
+ fs.writeFileSync(argv.output, `// @ts-nocheck\n${moduleCode}\n`);
47
+ } else {
48
+ console.log(moduleCode);
49
+ }
50
+ }
51
+
52
+ run().catch((err) => {
53
+ console.error(err);
54
+ process.exit(1);
55
+ });