apeframework 0.0.0-dev.35 → 0.0.0-dev.37

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.
@@ -1,5 +1,6 @@
1
1
  import { MigrationStatus } from './MigrationStatus.js';
2
2
  import type { Db } from './Db.js';
3
+ import type { Migration } from './Migration.js';
3
4
  declare class Migrator {
4
5
  private readonly umzug;
5
6
  constructor(params: {
@@ -7,6 +8,7 @@ declare class Migrator {
7
8
  modelName: string;
8
9
  directory: string;
9
10
  extension: string;
11
+ load: (path: string) => Promise<Migration>;
10
12
  onApply?: (name: string) => void;
11
13
  onRevert?: (name: string) => void;
12
14
  });
@@ -8,12 +8,12 @@ class Migrator {
8
8
  const resolve = ({ name: filename, context }) => {
9
9
  const name = basename(filename, extname(filename));
10
10
  const up = async ({ path }) => {
11
- const module = await import(String(path));
12
- await module.default.up(context);
11
+ const migration = await params.load(String(path));
12
+ await migration.up(context);
13
13
  };
14
14
  const down = async ({ path }) => {
15
- const module = await import(String(path));
16
- await module.default.down(context);
15
+ const migration = await params.load(String(path));
16
+ await migration.down(context);
17
17
  };
18
18
  return { name, up, down };
19
19
  };
@@ -0,0 +1,3 @@
1
+ import type { InjectOptions } from 'fastify';
2
+ type InjectParams = InjectOptions;
3
+ export { type InjectParams, };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { LightMyRequestResponse } from 'fastify';
2
+ type InjectResponse = LightMyRequestResponse;
3
+ export { type InjectResponse, };
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,8 @@ import { OpenApiFormat } from './OpenApiFormat.js';
2
2
  import type { ErrorHandler } from './ErrorHandler.js';
3
3
  import type { Format } from './Format.js';
4
4
  import type { Handler } from './Handler.js';
5
+ import type { InjectParams } from './InjectParams.js';
6
+ import type { InjectResponse } from './InjectResponse.js';
5
7
  import type { Route } from './Route.js';
6
8
  import type { OpenAPIV3 } from 'openapi-types';
7
9
  declare class Server {
@@ -11,20 +13,28 @@ declare class Server {
11
13
  constructor(params: {
12
14
  host: string;
13
15
  port?: number;
16
+ openapi?: {
17
+ name?: string;
18
+ version?: string;
19
+ };
14
20
  routes: Route[];
15
21
  formats?: Format[];
22
+ validateResponses?: boolean;
16
23
  trustProxy?: boolean;
17
24
  connectionTimeout?: number;
18
25
  requestTimeout?: number;
19
26
  keepAliveTimeout?: number;
20
27
  connectionMaxUses?: number;
21
- maxParams?: number;
22
- maxBodySize?: number;
23
- openapi?: {
24
- name?: string;
25
- version?: string;
28
+ bodyMaxSize?: number;
29
+ form?: {
30
+ enabled?: boolean;
31
+ };
32
+ multipart?: {
33
+ enabled?: boolean;
34
+ maxFiles?: number;
35
+ fileMaxSize?: number;
26
36
  };
27
- responseValidation?: {
37
+ cookies?: {
28
38
  enabled?: boolean;
29
39
  };
30
40
  compression?: {
@@ -39,9 +49,6 @@ declare class Server {
39
49
  exposedHeaders?: string[];
40
50
  allowCredentials?: boolean;
41
51
  };
42
- cookies?: {
43
- enabled?: boolean;
44
- };
45
52
  onRequest?: Handler;
46
53
  onResponse?: Handler;
47
54
  onNotFound?: Handler;
@@ -49,6 +56,7 @@ declare class Server {
49
56
  });
50
57
  start(): Promise<string>;
51
58
  close(): Promise<void>;
59
+ inject(params: InjectParams): Promise<InjectResponse>;
52
60
  openapi(format: OpenApiFormat): OpenAPIV3.Document;
53
61
  }
54
62
  export { Server, };
@@ -1,6 +1,8 @@
1
1
  import compress from '@fastify/compress';
2
- import cookies from '@fastify/cookie';
2
+ import cookie from '@fastify/cookie';
3
3
  import cors from '@fastify/cors';
4
+ import formbody from '@fastify/formbody';
5
+ import multipart from '@fastify/multipart';
4
6
  import responseValidation from '@fastify/response-validation';
5
7
  import swagger from '@fastify/swagger';
6
8
  import fastify from 'fastify';
@@ -19,8 +21,7 @@ class Server {
19
21
  requestTimeout: params.requestTimeout ?? 30000,
20
22
  keepAliveTimeout: params.keepAliveTimeout ?? 30000,
21
23
  maxRequestsPerSocket: params.connectionMaxUses ?? 100,
22
- maxParamLength: params.maxParams ?? 100,
23
- bodyLimit: params.maxBodySize ?? 1000000,
24
+ bodyLimit: params.bodyMaxSize ?? 1000000,
24
25
  });
25
26
  const ajv = getAjv(params.formats);
26
27
  this.server.setValidatorCompiler(({ schema }) => {
@@ -35,13 +36,28 @@ class Server {
35
36
  },
36
37
  },
37
38
  });
38
- if (params.responseValidation?.enabled) {
39
+ if (params.validateResponses) {
39
40
  this.server.register(responseValidation, { ajv });
40
41
  }
42
+ if (params.form?.enabled) {
43
+ this.server.register(formbody);
44
+ }
45
+ if (params.multipart?.enabled) {
46
+ this.server.register(multipart, {
47
+ attachFieldsToBody: true,
48
+ limits: {
49
+ files: params.multipart.maxFiles ?? 1,
50
+ fileSize: params.multipart.fileMaxSize ?? 1000000,
51
+ },
52
+ });
53
+ }
54
+ if (params.cookies?.enabled) {
55
+ this.server.register(cookie);
56
+ }
41
57
  if (params.compression?.enabled) {
42
58
  this.server.register(compress, {
43
59
  global: true,
44
- threshold: params.compression.threshold ?? 1024,
60
+ threshold: params.compression.threshold ?? 1000,
45
61
  });
46
62
  }
47
63
  if (params.cors?.enabled) {
@@ -53,9 +69,6 @@ class Server {
53
69
  credentials: params.cors.allowCredentials,
54
70
  });
55
71
  }
56
- if (params.cookies?.enabled) {
57
- this.server.register(cookies);
58
- }
59
72
  this.server.register((server, options, done) => {
60
73
  params.routes.forEach((route) => {
61
74
  server.route({
@@ -97,6 +110,9 @@ class Server {
97
110
  async close() {
98
111
  await this.server.close();
99
112
  }
113
+ async inject(params) {
114
+ return this.server.inject(params);
115
+ }
100
116
  openapi(format) {
101
117
  return this.server.swagger({
102
118
  yaml: format === OpenApiFormat.YAML,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apeframework",
3
- "version": "0.0.0-dev.35",
3
+ "version": "0.0.0-dev.37",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -24,6 +24,8 @@
24
24
  "@fastify/compress": "^8.1",
25
25
  "@fastify/cookie": "^11.0",
26
26
  "@fastify/cors": "^11.1",
27
+ "@fastify/formbody": "^8.0",
28
+ "@fastify/multipart": "^9.3",
27
29
  "@fastify/response-validation": "^3.0",
28
30
  "@fastify/swagger": "^9.5",
29
31
  "@types/fs-extra": "^11.0",
@@ -711,6 +713,18 @@
711
713
  "default": "./dist/server/Handler.js"
712
714
  }
713
715
  },
716
+ "./server/InjectParams": {
717
+ "import": {
718
+ "types": "./dist/server/InjectParams.d.ts",
719
+ "default": "./dist/server/InjectParams.js"
720
+ }
721
+ },
722
+ "./server/InjectResponse": {
723
+ "import": {
724
+ "types": "./dist/server/InjectResponse.d.ts",
725
+ "default": "./dist/server/InjectResponse.js"
726
+ }
727
+ },
714
728
  "./server/Method": {
715
729
  "import": {
716
730
  "types": "./dist/server/Method.d.ts",