@openapi-typescript-infra/service 1.2.1 → 2.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.
Files changed (42) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +1 -1
  3. package/.prettierrc.js +1 -1
  4. package/.trunk/configs/.markdownlint.yaml +10 -0
  5. package/.trunk/configs/.yamllint.yaml +10 -0
  6. package/.trunk/trunk.yaml +35 -0
  7. package/CHANGELOG.md +12 -0
  8. package/README.md +10 -10
  9. package/build/express-app/app.js +4 -3
  10. package/build/express-app/app.js.map +1 -1
  11. package/build/express-app/modules.d.ts +2 -0
  12. package/build/express-app/modules.js +28 -0
  13. package/build/express-app/modules.js.map +1 -0
  14. package/build/express-app/route-loader.js +4 -12
  15. package/build/express-app/route-loader.js.map +1 -1
  16. package/build/openapi.d.ts +1 -1
  17. package/build/openapi.js +26 -6
  18. package/build/openapi.js.map +1 -1
  19. package/build/telemetry/index.js +3 -1
  20. package/build/telemetry/index.js.map +1 -1
  21. package/build/tsconfig.build.tsbuildinfo +1 -1
  22. package/package.json +51 -43
  23. package/src/express-app/app.ts +21 -20
  24. package/src/express-app/modules.ts +27 -0
  25. package/src/express-app/route-loader.ts +5 -16
  26. package/src/openapi.ts +43 -7
  27. package/src/telemetry/index.ts +3 -1
  28. package/tsconfig.build.json +2 -1
  29. package/tsconfig.json +2 -1
  30. package/vitest.config.ts +19 -0
  31. package/.husky/commit-msg +0 -4
  32. package/.husky/pre-commit +0 -6
  33. package/__tests__/config.test.ts +0 -32
  34. package/__tests__/fake-serv/api/fake-serv.yaml +0 -48
  35. package/__tests__/fake-serv/config/config.json +0 -16
  36. package/__tests__/fake-serv/src/handlers/hello.ts +0 -10
  37. package/__tests__/fake-serv/src/index.ts +0 -35
  38. package/__tests__/fake-serv/src/routes/error.ts +0 -13
  39. package/__tests__/fake-serv/src/routes/index.ts +0 -22
  40. package/__tests__/fake-serv/src/routes/other/world.ts +0 -7
  41. package/__tests__/fake-serv.test.ts +0 -74
  42. package/jest.config.js +0 -14
@@ -1,74 +0,0 @@
1
- import path from 'path';
2
-
3
- import request from 'supertest';
4
-
5
- import {
6
- listen, ServiceStartOptions, shutdownApp, startApp,
7
- } from '../src/index';
8
-
9
- import { FakeServLocals, service } from './fake-serv/src/index';
10
-
11
- describe('fake-serv', () => {
12
- test('basic service functionality', async () => {
13
- const options: ServiceStartOptions<FakeServLocals> = {
14
- service,
15
- name: 'fake-serv',
16
- rootDirectory: path.resolve(__dirname, './fake-serv'),
17
- codepath: 'src',
18
- };
19
- const app = await startApp(options).catch((error) => {
20
- console.error(error);
21
- throw error;
22
- });
23
- expect(app).toBeTruthy();
24
-
25
- let { body } = await request(app).get('/world').timeout(500).expect(200);
26
- expect(body.hello).toEqual('world');
27
-
28
- ({ body } = await request(app).get('/other/world').timeout(500).expect(200));
29
- expect(body.hello).toEqual('jupiter');
30
-
31
- ({ body } = await request(app).get('/hello').query({ greeting: 'Hello Pluto!', number: '6', break_things: true }).expect(200));
32
- expect(body.greeting).toEqual('Hello Pluto!');
33
-
34
- // Can't convert green to a number
35
- await request(app).get('/hello').query({ greeting: 'Hello Pluto!', number: 'green' }).expect(400);
36
-
37
- // Make sure body paramater conversion works
38
- await request(app).post('/hello').send({ number: 'green' }).expect(400);
39
- await request(app).post('/hello').send({ number: '6' }).expect(204);
40
- await request(app).post('/hello').send({ number: 6 }).expect(204);
41
-
42
- ({ body } = await request(app).get('/error/sync').timeout(1000).expect(500));
43
- expect(body.code).toEqual('SyncError');
44
-
45
- ({ body } = await request(app).get('/error/async').timeout(1000).expect(500));
46
- expect(body.code).toEqual('AsyncError');
47
-
48
- // Mocking
49
- await request(app).post('/world').expect(500);
50
-
51
- // Clean shutdown
52
- await expect(shutdownApp(app)).resolves.toBeUndefined();
53
- const secondApp = await startApp(options);
54
-
55
- // Make sure we can listen
56
- const server = await listen(secondApp);
57
-
58
- // Call metrics
59
- await request(secondApp).get('/world').expect(200);
60
- await request(secondApp.locals.internalApp).get('/metrics')
61
- .expect(200)
62
- .expect((res) => expect(res.text).toMatch(/world_requests_total{method="get"} 1/));
63
-
64
- await new Promise<void>((accept, reject) => {
65
- server.close((e) => {
66
- if (e) {
67
- reject(e);
68
- } else {
69
- accept();
70
- }
71
- });
72
- });
73
- });
74
- });
package/jest.config.js DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * This file is generated by coconfig. Do not edit it directly.
3
- * Instead, edit the coconfig.js or coconfig.ts file in your project root.
4
- *
5
- * See https://github.com/gas-buddy/coconfig for more information.
6
- * @version coconfig@0.12.2
7
- */
8
- const configModule = require('@openapi-typescript-infra/coconfig');
9
-
10
- const configItem = configModule.default || configModule.config || configModule;
11
- const { configuration } = configItem && configItem['jest.config.js'];
12
- const resolved = typeof configuration === 'function' ? configuration() : configuration;
13
-
14
- module.exports = resolved;