apeframework 0.0.0-dev.32 → 0.0.0-dev.34

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/dist/db/Db.d.ts CHANGED
@@ -1,3 +1,10 @@
1
- import type { Sequelize } from 'sequelize';
2
- type Db = Sequelize;
3
- export type { Db, };
1
+ import { Sequelize } from 'sequelize';
2
+ import type { Initializer } from './Initializer.js';
3
+ import type { Options } from 'sequelize';
4
+ declare abstract class Db extends Sequelize {
5
+ protected constructor(params: {
6
+ options: Options;
7
+ initializers?: Initializer[];
8
+ });
9
+ }
10
+ export { Db, };
package/dist/db/Db.js CHANGED
@@ -1 +1,16 @@
1
- export {};
1
+ import { Sequelize } from 'sequelize';
2
+ class Db extends Sequelize {
3
+ constructor(params) {
4
+ super({
5
+ ...params.options,
6
+ define: {
7
+ freezeTableName: true,
8
+ timestamps: false,
9
+ },
10
+ });
11
+ params.initializers?.forEach((initialize) => {
12
+ initialize(this);
13
+ });
14
+ }
15
+ }
16
+ export { Db, };
@@ -7,13 +7,13 @@ class Migrator {
7
7
  const glob = `${params.directory}/*.${params.extension}`;
8
8
  const resolve = ({ name: filename, context }) => {
9
9
  const name = basename(filename, extname(filename));
10
- const up = async ({ path: file }) => {
11
- const module = await import(String(file));
12
- await module.migration.up(context);
10
+ const up = async ({ path }) => {
11
+ const module = await import(String(path));
12
+ await module.default.up(context);
13
13
  };
14
- const down = async ({ path: file }) => {
15
- const module = await import(String(file));
16
- await module.migration.down(context);
14
+ const down = async ({ path }) => {
15
+ const module = await import(String(path));
16
+ await module.default.down(context);
17
17
  };
18
18
  return { name, up, down };
19
19
  };
@@ -0,0 +1,23 @@
1
+ import { Db } from '../../Db.js';
2
+ import type { Tls } from '../../../tls/Tls.js';
3
+ import type { Initializer } from '../../Initializer.js';
4
+ declare class MssqlDb extends Db {
5
+ constructor(params: {
6
+ host: string;
7
+ port?: number;
8
+ tls?: Tls | boolean;
9
+ user: string;
10
+ password: string;
11
+ database: string;
12
+ minConnections?: number;
13
+ maxConnections?: number;
14
+ connectionTimeout?: number;
15
+ connectionAcquireTimeout?: number;
16
+ connectionIdleTimeout?: number;
17
+ connectionEvictInterval?: number;
18
+ connectionMaxUses?: number;
19
+ initializers?: Initializer[];
20
+ onQuery?: (message: string) => void;
21
+ });
22
+ }
23
+ export { MssqlDb, };
@@ -0,0 +1,40 @@
1
+ import { getTls } from '../../../tls/getTls.js';
2
+ import { Db } from '../../Db.js';
3
+ class MssqlDb extends Db {
4
+ constructor(params) {
5
+ const tls = typeof params.tls === 'boolean'
6
+ ? undefined
7
+ : getTls(params.tls);
8
+ super({
9
+ options: {
10
+ dialect: 'mssql',
11
+ dialectOptions: {
12
+ options: {
13
+ encrypt: typeof params.tls === 'boolean'
14
+ ? params.tls
15
+ : Boolean(tls),
16
+ cryptoCredentialsDetails: tls,
17
+ trustServerCertificate: tls?.rejectUnauthorized === false,
18
+ connectTimeout: params.connectionTimeout ?? 10000,
19
+ },
20
+ },
21
+ host: params.host,
22
+ port: params.port ?? 1433,
23
+ username: params.user,
24
+ password: params.password,
25
+ database: params.database,
26
+ pool: {
27
+ min: params.minConnections ?? 0,
28
+ max: params.maxConnections ?? 10,
29
+ acquire: params.connectionAcquireTimeout ?? 30000,
30
+ idle: params.connectionIdleTimeout ?? 30000,
31
+ evict: params.connectionEvictInterval ?? 30000,
32
+ maxUses: params.connectionMaxUses ?? 100,
33
+ },
34
+ logging: params.onQuery,
35
+ },
36
+ initializers: params.initializers,
37
+ });
38
+ }
39
+ }
40
+ export { MssqlDb, };
@@ -1,16 +1,23 @@
1
- import { Sequelize } from 'sequelize';
2
- import type { Db } from '../../Db.js';
1
+ import { Db } from '../../Db.js';
2
+ import type { Tls } from '../../../tls/Tls.js';
3
3
  import type { Initializer } from '../../Initializer.js';
4
- declare class MysqlDb extends Sequelize implements Db {
4
+ declare class MysqlDb extends Db {
5
5
  constructor(params: {
6
6
  host: string;
7
7
  port?: number;
8
+ tls?: Tls | boolean;
8
9
  user: string;
9
10
  password: string;
10
11
  database: string;
12
+ minConnections?: number;
11
13
  maxConnections?: number;
14
+ connectionTimeout?: number;
15
+ connectionAcquireTimeout?: number;
16
+ connectionIdleTimeout?: number;
17
+ connectionEvictInterval?: number;
18
+ connectionMaxUses?: number;
12
19
  initializers?: Initializer[];
13
- onLog?: (message: string) => void;
20
+ onQuery?: (message: string) => void;
14
21
  });
15
22
  }
16
23
  export { MysqlDb, };
@@ -1,21 +1,32 @@
1
- import { Sequelize } from 'sequelize';
2
- class MysqlDb extends Sequelize {
1
+ import { getTls } from '../../../tls/getTls.js';
2
+ import { Db } from '../../Db.js';
3
+ class MysqlDb extends Db {
3
4
  constructor(params) {
4
- super(params.database, params.user, params.password, {
5
- dialect: 'mysql',
6
- host: params.host,
7
- port: params.port ?? 3306,
8
- pool: {
9
- max: params.maxConnections ?? 5,
5
+ super({
6
+ options: {
7
+ dialect: 'mysql',
8
+ dialectOptions: {
9
+ ssl: typeof params.tls === 'boolean'
10
+ ? params.tls
11
+ : getTls(params.tls),
12
+ connectTimeout: params.connectionTimeout ?? 10000,
13
+ },
14
+ host: params.host,
15
+ port: params.port ?? 3306,
16
+ username: params.user,
17
+ password: params.password,
18
+ database: params.database,
19
+ pool: {
20
+ min: params.minConnections ?? 0,
21
+ max: params.maxConnections ?? 10,
22
+ acquire: params.connectionAcquireTimeout ?? 30000,
23
+ idle: params.connectionIdleTimeout ?? 30000,
24
+ evict: params.connectionEvictInterval ?? 30000,
25
+ maxUses: params.connectionMaxUses ?? 100,
26
+ },
27
+ logging: params.onQuery,
10
28
  },
11
- define: {
12
- freezeTableName: true,
13
- timestamps: false,
14
- },
15
- logging: params.onLog,
16
- });
17
- params.initializers?.forEach((initialize) => {
18
- initialize(this);
29
+ initializers: params.initializers,
19
30
  });
20
31
  }
21
32
  }
@@ -0,0 +1,23 @@
1
+ import { Db } from '../../Db.js';
2
+ import type { Tls } from '../../../tls/Tls.js';
3
+ import type { Initializer } from '../../Initializer.js';
4
+ declare class PostgresDb extends Db {
5
+ constructor(params: {
6
+ host: string;
7
+ port?: number;
8
+ tls?: Tls | boolean;
9
+ user: string;
10
+ password: string;
11
+ database: string;
12
+ minConnections?: number;
13
+ maxConnections?: number;
14
+ connectionTimeout?: number;
15
+ connectionAcquireTimeout?: number;
16
+ connectionIdleTimeout?: number;
17
+ connectionEvictInterval?: number;
18
+ connectionMaxUses?: number;
19
+ initializers?: Initializer[];
20
+ onQuery?: (message: string) => void;
21
+ });
22
+ }
23
+ export { PostgresDb, };
@@ -0,0 +1,33 @@
1
+ import { getTls } from '../../../tls/getTls.js';
2
+ import { Db } from '../../Db.js';
3
+ class PostgresDb extends Db {
4
+ constructor(params) {
5
+ super({
6
+ options: {
7
+ dialect: 'postgres',
8
+ dialectOptions: {
9
+ ssl: typeof params.tls === 'boolean'
10
+ ? params.tls
11
+ : getTls(params.tls),
12
+ connectionTimeoutMillis: params.connectionTimeout ?? 10000,
13
+ },
14
+ host: params.host,
15
+ port: params.port ?? 5432,
16
+ username: params.user,
17
+ password: params.password,
18
+ database: params.database,
19
+ pool: {
20
+ min: params.minConnections ?? 0,
21
+ max: params.maxConnections ?? 10,
22
+ acquire: params.connectionAcquireTimeout ?? 30000,
23
+ idle: params.connectionIdleTimeout ?? 30000,
24
+ evict: params.connectionEvictInterval ?? 30000,
25
+ maxUses: params.connectionMaxUses ?? 100,
26
+ },
27
+ logging: params.onQuery,
28
+ },
29
+ initializers: params.initializers,
30
+ });
31
+ }
32
+ }
33
+ export { PostgresDb, };
@@ -0,0 +1,10 @@
1
+ import { Db } from '../../Db.js';
2
+ import type { Initializer } from '../../Initializer.js';
3
+ declare class SqliteDb extends Db {
4
+ constructor(params: {
5
+ storage: string;
6
+ initializers?: Initializer[];
7
+ onQuery?: (message: string) => void;
8
+ });
9
+ }
10
+ export { SqliteDb, };
@@ -0,0 +1,20 @@
1
+ import SQLite from 'sqlite3';
2
+ import { Db } from '../../Db.js';
3
+ class SqliteDb extends Db {
4
+ constructor(params) {
5
+ super({
6
+ options: {
7
+ dialect: 'sqlite',
8
+ dialectOptions: {
9
+ mode: SQLite.OPEN_FULLMUTEX
10
+ | SQLite.OPEN_READWRITE
11
+ | SQLite.OPEN_CREATE,
12
+ },
13
+ storage: params.storage,
14
+ logging: params.onQuery,
15
+ },
16
+ initializers: params.initializers,
17
+ });
18
+ }
19
+ }
20
+ export { SqliteDb, };
@@ -0,0 +1,4 @@
1
+ declare const Storage: {
2
+ MEMORY: string;
3
+ };
4
+ export { Storage, };
@@ -0,0 +1,4 @@
1
+ const Storage = {
2
+ MEMORY: ':memory:',
3
+ };
4
+ export { Storage, };
@@ -21,7 +21,7 @@ class SmtpMailer extends Mailer {
21
21
  }
22
22
  : undefined,
23
23
  pool: true,
24
- maxConnections: params.maxConnections ?? 5,
24
+ maxConnections: params.maxConnections ?? 10,
25
25
  });
26
26
  }
27
27
  async sendMail(mail) {
@@ -13,6 +13,13 @@ declare class Server {
13
13
  port?: number;
14
14
  routes: Route[];
15
15
  formats?: Format[];
16
+ trustProxy?: boolean;
17
+ connectionTimeout?: number;
18
+ requestTimeout?: number;
19
+ keepAliveTimeout?: number;
20
+ connectionMaxUses?: number;
21
+ maxParams?: number;
22
+ maxBodySize?: number;
16
23
  openapi?: {
17
24
  name?: string;
18
25
  version?: string;
@@ -13,7 +13,15 @@ class Server {
13
13
  constructor(params) {
14
14
  this.host = params.host;
15
15
  this.port = params.port;
16
- this.server = fastify();
16
+ this.server = fastify({
17
+ trustProxy: params.trustProxy ?? false,
18
+ connectionTimeout: params.connectionTimeout ?? 30000,
19
+ requestTimeout: params.requestTimeout ?? 30000,
20
+ keepAliveTimeout: params.keepAliveTimeout ?? 30000,
21
+ maxRequestsPerSocket: params.connectionMaxUses ?? 100,
22
+ maxParamLength: params.maxParams ?? 100,
23
+ bodyLimit: params.maxBodySize ?? 1000000,
24
+ });
17
25
  const ajv = getAjv(params.formats);
18
26
  this.server.setValidatorCompiler(({ schema }) => {
19
27
  return ajv.compile(schema);
@@ -6,7 +6,7 @@ const getTls = (tls) => {
6
6
  ...tls.cert ? { cert: readFile(tls.cert) } : {},
7
7
  ...tls.ca ? { ca: readFile(tls.ca) } : {},
8
8
  ...tls.verify === undefined
9
- ? {}
9
+ ? { rejectUnauthorized: true }
10
10
  : { rejectUnauthorized: tls.verify },
11
11
  }
12
12
  : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apeframework",
3
- "version": "0.0.0-dev.32",
3
+ "version": "0.0.0-dev.34",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -39,12 +39,16 @@
39
39
  "ical-generator": "^10.0",
40
40
  "ioredis": "^5.8",
41
41
  "jose": "^6.1",
42
+ "mariadb": "^3.4",
42
43
  "mysql2": "^3.15",
43
44
  "nodemailer": "^7.0",
44
45
  "openapi-types": "^12.1",
46
+ "pg": "^8.16",
47
+ "pg-hstore": "^2.3",
45
48
  "pino": "^10.1",
46
49
  "pino-pretty": "^13.1",
47
50
  "sequelize": "^6.37",
51
+ "sqlite3": "^5.1",
48
52
  "umzug": "^3.8",
49
53
  "yargs-parser": "^22.0"
50
54
  },
@@ -263,22 +267,22 @@
263
267
  "default": "./dist/db/ReferentialAction.js"
264
268
  }
265
269
  },
266
- "./db/Seed": {
270
+ "./db/Transaction": {
267
271
  "import": {
268
- "types": "./dist/db/Seed.d.ts",
269
- "default": "./dist/db/Seed.js"
272
+ "types": "./dist/db/Transaction.d.ts",
273
+ "default": "./dist/db/Transaction.js"
270
274
  }
271
275
  },
272
- "./db/Seeder": {
276
+ "./db/adapters/maria/MariaDb": {
273
277
  "import": {
274
- "types": "./dist/db/Seeder.d.ts",
275
- "default": "./dist/db/Seeder.js"
278
+ "types": "./dist/db/adapters/maria/MariaDb.d.ts",
279
+ "default": "./dist/db/adapters/maria/MariaDb.js"
276
280
  }
277
281
  },
278
- "./db/Transaction": {
282
+ "./db/adapters/mssql/MssqlDb": {
279
283
  "import": {
280
- "types": "./dist/db/Transaction.d.ts",
281
- "default": "./dist/db/Transaction.js"
284
+ "types": "./dist/db/adapters/mssql/MssqlDb.d.ts",
285
+ "default": "./dist/db/adapters/mssql/MssqlDb.js"
282
286
  }
283
287
  },
284
288
  "./db/adapters/mysql/MysqlDb": {
@@ -287,6 +291,24 @@
287
291
  "default": "./dist/db/adapters/mysql/MysqlDb.js"
288
292
  }
289
293
  },
294
+ "./db/adapters/postgres/PostgresDb": {
295
+ "import": {
296
+ "types": "./dist/db/adapters/postgres/PostgresDb.d.ts",
297
+ "default": "./dist/db/adapters/postgres/PostgresDb.js"
298
+ }
299
+ },
300
+ "./db/adapters/sqlite/SqliteDb": {
301
+ "import": {
302
+ "types": "./dist/db/adapters/sqlite/SqliteDb.d.ts",
303
+ "default": "./dist/db/adapters/sqlite/SqliteDb.js"
304
+ }
305
+ },
306
+ "./db/adapters/sqlite/Storage": {
307
+ "import": {
308
+ "types": "./dist/db/adapters/sqlite/Storage.d.ts",
309
+ "default": "./dist/db/adapters/sqlite/Storage.js"
310
+ }
311
+ },
290
312
  "./db/relationships": {
291
313
  "import": {
292
314
  "types": "./dist/db/relationships.d.ts",
package/dist/db/Seed.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Sequelize } from 'sequelize';
2
- type Seed = (db: Sequelize) => Promise<void>;
3
- export { type Seed, };
package/dist/db/Seed.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import type { Db } from './Db.js';
2
- declare class Seeder {
3
- private readonly db;
4
- private readonly directory;
5
- private readonly extension;
6
- private readonly onApply?;
7
- constructor(params: {
8
- db: Db;
9
- directory: string;
10
- extension: string;
11
- onApply?: (name: string) => void;
12
- });
13
- list(): string[];
14
- apply(name: string): Promise<void>;
15
- }
16
- export { Seeder, };
package/dist/db/Seeder.js DELETED
@@ -1,26 +0,0 @@
1
- import { basename, extname, resolve } from 'node:path';
2
- import fs from 'fs-extra';
3
- class Seeder {
4
- db;
5
- directory;
6
- extension;
7
- onApply;
8
- constructor(params) {
9
- this.db = params.db;
10
- this.directory = params.directory;
11
- this.extension = params.extension;
12
- this.onApply = params.onApply;
13
- }
14
- list() {
15
- return fs.readdirSync(this.directory).map((filename) => {
16
- return basename(filename, extname(filename));
17
- });
18
- }
19
- async apply(name) {
20
- this.onApply?.(name);
21
- const file = resolve(this.directory, `${name}.${this.extension}`);
22
- const { seed } = await import(file);
23
- await seed(this.db);
24
- }
25
- }
26
- export { Seeder, };