apeframework 0.1.0 → 0.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.
@@ -0,0 +1,2 @@
1
+ import { DataTypes } from 'sequelize';
2
+ export { DataTypes as DataType, };
@@ -0,0 +1,2 @@
1
+ import { DataTypes } from 'sequelize';
2
+ export { DataTypes as DataType, };
@@ -0,0 +1,3 @@
1
+ import type { Sequelize } from 'sequelize';
2
+ type Db = Sequelize;
3
+ export type { Db, };
package/dist/db/Db.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ declare enum IndexType {
2
+ FULLTEXT = "FULLTEXT",
3
+ SPATIAL = "SPATIAL",
4
+ UNIQUE = "UNIQUE"
5
+ }
6
+ export { IndexType, };
@@ -0,0 +1,7 @@
1
+ var IndexType;
2
+ (function (IndexType) {
3
+ IndexType["FULLTEXT"] = "FULLTEXT";
4
+ IndexType["SPATIAL"] = "SPATIAL";
5
+ IndexType["UNIQUE"] = "UNIQUE";
6
+ })(IndexType || (IndexType = {}));
7
+ export { IndexType, };
@@ -0,0 +1,3 @@
1
+ import type { Sequelize } from 'sequelize';
2
+ type Initializer = (db: Sequelize) => void;
3
+ export { type Initializer, };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { QueryInterface } from 'sequelize';
2
+ interface Migration {
3
+ up: (db: QueryInterface) => Promise<void>;
4
+ down: (db: QueryInterface) => Promise<void>;
5
+ }
6
+ export { type Migration, };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ declare enum MigrationStatus {
2
+ APPLIED = "APPLIED",
3
+ PENDING = "PENDING"
4
+ }
5
+ export { MigrationStatus, };
@@ -0,0 +1,6 @@
1
+ var MigrationStatus;
2
+ (function (MigrationStatus) {
3
+ MigrationStatus["APPLIED"] = "APPLIED";
4
+ MigrationStatus["PENDING"] = "PENDING";
5
+ })(MigrationStatus || (MigrationStatus = {}));
6
+ export { MigrationStatus, };
@@ -0,0 +1,20 @@
1
+ import { MigrationStatus } from './MigrationStatus.js';
2
+ import type { Db } from './Db.js';
3
+ declare class Migrator {
4
+ private readonly umzug;
5
+ constructor(params: {
6
+ db: Db;
7
+ modelName: string;
8
+ directory: string;
9
+ extension: string;
10
+ onApply?: (name: string) => void;
11
+ onRevert?: (name: string) => void;
12
+ });
13
+ list(status?: MigrationStatus): Promise<{
14
+ name: string;
15
+ status: MigrationStatus;
16
+ }[]>;
17
+ apply(count?: number): Promise<string[]>;
18
+ revert(count?: number): Promise<string[]>;
19
+ }
20
+ export { Migrator, };
@@ -0,0 +1,69 @@
1
+ import { basename, extname } from 'node:path';
2
+ import { SequelizeStorage, Umzug } from 'umzug';
3
+ import { MigrationStatus } from './MigrationStatus.js';
4
+ class Migrator {
5
+ umzug;
6
+ constructor(params) {
7
+ const glob = `${params.directory}/*.${params.extension}`;
8
+ const resolve = ({ name: filename, context }) => {
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);
13
+ };
14
+ const down = async ({ path: file }) => {
15
+ const module = await import(String(file));
16
+ await module.migration.down(context);
17
+ };
18
+ return { name, up, down };
19
+ };
20
+ this.umzug = new Umzug({
21
+ storage: new SequelizeStorage({
22
+ sequelize: params.db,
23
+ modelName: params.modelName,
24
+ }),
25
+ migrations: { glob, resolve },
26
+ context: params.db.getQueryInterface(),
27
+ logger: undefined,
28
+ });
29
+ this.umzug.on('migrating', (e) => {
30
+ params.onApply?.(e.name);
31
+ });
32
+ this.umzug.on('reverting', (e) => {
33
+ params.onRevert?.(e.name);
34
+ });
35
+ }
36
+ async list(status) {
37
+ return [
38
+ ...status === MigrationStatus.PENDING
39
+ ? []
40
+ : (await this.umzug.executed()).map((migration) => {
41
+ return {
42
+ name: migration.name,
43
+ status: MigrationStatus.APPLIED,
44
+ };
45
+ }),
46
+ ...status === MigrationStatus.APPLIED
47
+ ? []
48
+ : (await this.umzug.pending()).map((migration) => {
49
+ return {
50
+ name: migration.name,
51
+ status: MigrationStatus.PENDING,
52
+ };
53
+ }),
54
+ ];
55
+ }
56
+ async apply(count) {
57
+ return (await this.umzug.up(count ? { step: count } : undefined))
58
+ .map((migration) => {
59
+ return migration.name;
60
+ });
61
+ }
62
+ async revert(count) {
63
+ return (await this.umzug.down(count ? { step: count } : { to: 0 }))
64
+ .map((migration) => {
65
+ return migration.name;
66
+ });
67
+ }
68
+ }
69
+ export { Migrator, };
@@ -0,0 +1,2 @@
1
+ import { Op } from 'sequelize';
2
+ export { Op as Operator, };
@@ -0,0 +1,2 @@
1
+ import { Op } from 'sequelize';
2
+ export { Op as Operator, };
@@ -0,0 +1,2 @@
1
+ import type { Order } from 'sequelize';
2
+ export { type Order, };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ declare const ReferentialAction: {
2
+ CASCADE: string;
3
+ RESTRICT: string;
4
+ SET_DEFAULT: string;
5
+ SET_NULL: string;
6
+ };
7
+ export { ReferentialAction, };
@@ -0,0 +1,7 @@
1
+ const ReferentialAction = {
2
+ CASCADE: 'CASCADE',
3
+ RESTRICT: 'RESTRICT',
4
+ SET_DEFAULT: 'SET DEFAULT',
5
+ SET_NULL: 'SET NULL',
6
+ };
7
+ export { ReferentialAction, };
@@ -0,0 +1,2 @@
1
+ import type { Transaction } from 'sequelize';
2
+ export { type Transaction, };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { Sequelize } from 'sequelize';
2
+ import type { Db } from '../../Db.js';
3
+ import type { Initializer } from '../../Initializer.js';
4
+ declare class MysqlDb extends Sequelize implements Db {
5
+ constructor(params: {
6
+ host: string;
7
+ port?: number;
8
+ user: string;
9
+ password: string;
10
+ database: string;
11
+ maxConnections?: number;
12
+ initializers?: Initializer[];
13
+ onLog?: (message: string) => void;
14
+ });
15
+ }
16
+ export { MysqlDb, };
@@ -0,0 +1,22 @@
1
+ import { Sequelize } from 'sequelize';
2
+ class MysqlDb extends Sequelize {
3
+ 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,
10
+ },
11
+ define: {
12
+ freezeTableName: true,
13
+ timestamps: false,
14
+ },
15
+ logging: params.onLog,
16
+ });
17
+ params.initializers?.forEach((initialize) => {
18
+ initialize(this);
19
+ });
20
+ }
21
+ }
22
+ export { MysqlDb, };
@@ -0,0 +1,28 @@
1
+ import type { Model, ModelStatic } from 'sequelize';
2
+ declare const oneToOne: (fk: string, a: {
3
+ model: ModelStatic<Model>;
4
+ asOne: string;
5
+ }, b: {
6
+ model: ModelStatic<Model>;
7
+ asOne: string;
8
+ }) => void;
9
+ declare const oneToMany: (fk: string, a: {
10
+ model: ModelStatic<Model>;
11
+ asOne: string;
12
+ }, b: {
13
+ model: ModelStatic<Model>;
14
+ asMany: string;
15
+ }) => void;
16
+ declare const manyToMany: (fkA: string, fkB: string, a: {
17
+ model: ModelStatic<Model>;
18
+ asOne: string;
19
+ asMany: string;
20
+ }, b: {
21
+ model: ModelStatic<Model>;
22
+ asOne: string;
23
+ asMany: string;
24
+ }, through: {
25
+ model: ModelStatic<Model>;
26
+ asMany: string;
27
+ }) => void;
28
+ export { manyToMany, oneToMany, oneToOne, };
@@ -0,0 +1,15 @@
1
+ const oneToOne = (fk, a, b) => {
2
+ a.model.hasOne(b.model, { foreignKey: fk, as: b.asOne });
3
+ b.model.belongsTo(a.model, { foreignKey: fk, as: a.asOne });
4
+ };
5
+ const oneToMany = (fk, a, b) => {
6
+ a.model.hasMany(b.model, { foreignKey: fk, as: b.asMany });
7
+ b.model.belongsTo(a.model, { foreignKey: fk, as: a.asOne });
8
+ };
9
+ const manyToMany = (fkA, fkB, a, b, through) => {
10
+ a.model.belongsToMany(b.model, { through: through.model, foreignKey: fkA, otherKey: fkB, as: b.asMany });
11
+ b.model.belongsToMany(a.model, { through: through.model, foreignKey: fkB, otherKey: fkA, as: a.asMany });
12
+ oneToMany(fkA, a, through);
13
+ oneToMany(fkB, b, through);
14
+ };
15
+ export { manyToMany, oneToMany, oneToOne, };
@@ -1,4 +1,4 @@
1
- import { pino } from 'pino';
1
+ import { destination, pino } from 'pino';
2
2
  import { Level } from '../../Level.js';
3
3
  import { Logger } from '../../Logger.js';
4
4
  import { initFile } from './initFile.js';
@@ -8,7 +8,7 @@ class FileLogger extends Logger {
8
8
  constructor(params) {
9
9
  super();
10
10
  initFile(params.path);
11
- const stream = pino.destination(params.path);
11
+ const stream = destination(params.path);
12
12
  this.logger = pino({
13
13
  enabled: params.level !== Level.OFF,
14
14
  level: params.level ?? Level.INFO,
@@ -1,4 +1,4 @@
1
- import { pino } from 'pino';
1
+ import { destination, pino } from 'pino';
2
2
  import pretty from 'pino-pretty';
3
3
  import { Level } from '../../Level.js';
4
4
  import { Logger } from '../../Logger.js';
@@ -9,7 +9,7 @@ class StdioLogger extends Logger {
9
9
  super();
10
10
  const stream = params?.pretty
11
11
  ? pretty()
12
- : pino.destination(process.stdout.fd);
12
+ : destination(process.stdout.fd);
13
13
  this.logger = pino({
14
14
  enabled: params?.level !== Level.OFF,
15
15
  level: params?.level ?? Level.INFO,
@@ -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
+ maxRequestsPerSocket?: number;
21
+ maxParamLength?: number;
22
+ bodyLimit?: 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.maxRequestsPerSocket ?? 100,
22
+ maxParamLength: params.maxParamLength ?? 100,
23
+ bodyLimit: params.bodyLimit ?? 1000000,
24
+ });
17
25
  const ajv = getAjv(params.formats);
18
26
  this.server.setValidatorCompiler(({ schema }) => {
19
27
  return ajv.compile(schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apeframework",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -23,31 +23,34 @@
23
23
  "dependencies": {
24
24
  "@fastify/compress": "^8.1",
25
25
  "@fastify/cookie": "^11.0",
26
- "@fastify/cors": "^11.0",
26
+ "@fastify/cors": "^11.1",
27
27
  "@fastify/response-validation": "^3.0",
28
28
  "@fastify/swagger": "^9.5",
29
29
  "@types/fs-extra": "^11.0",
30
- "@types/nodemailer": "^6.4",
30
+ "@types/nodemailer": "^7.0",
31
31
  "@types/yargs-parser": "^21.0",
32
32
  "ajv": "^8.17",
33
- "argon2": "^0.43",
34
- "bullmq": "^5.56",
35
- "dotenv": "^17.0",
36
- "fast-uri": "^3.0",
37
- "fastify": "^5.4",
33
+ "argon2": "^0.44",
34
+ "bullmq": "^5.63",
35
+ "dotenv": "^17.2",
36
+ "fast-uri": "^3.1",
37
+ "fastify": "^5.6",
38
38
  "fs-extra": "^11.3",
39
- "ical-generator": "^9.0",
40
- "ioredis": "^5.6",
41
- "jose": "^6.0",
39
+ "ical-generator": "^10.0",
40
+ "ioredis": "^5.8",
41
+ "jose": "^6.1",
42
+ "mysql2": "^3.15",
42
43
  "nodemailer": "^7.0",
43
44
  "openapi-types": "^12.1",
44
- "pino": "^9.7",
45
- "pino-pretty": "^13.0",
45
+ "pino": "^10.1",
46
+ "pino-pretty": "^13.1",
47
+ "sequelize": "^6.37",
48
+ "umzug": "^3.8",
46
49
  "yargs-parser": "^22.0"
47
50
  },
48
51
  "peerDependencies": {
49
- "@types/node": "^24.0",
50
- "typescript": "^5.8"
52
+ "@types/node": "^24.10",
53
+ "typescript": "^5.9"
51
54
  },
52
55
  "exports": {
53
56
  "./cipher/Algorithm": {
@@ -200,6 +203,84 @@
200
203
  "default": "./dist/config/validatePropertyName.js"
201
204
  }
202
205
  },
206
+ "./db/DataType": {
207
+ "import": {
208
+ "types": "./dist/db/DataType.d.ts",
209
+ "default": "./dist/db/DataType.js"
210
+ }
211
+ },
212
+ "./db/Db": {
213
+ "import": {
214
+ "types": "./dist/db/Db.d.ts",
215
+ "default": "./dist/db/Db.js"
216
+ }
217
+ },
218
+ "./db/IndexType": {
219
+ "import": {
220
+ "types": "./dist/db/IndexType.d.ts",
221
+ "default": "./dist/db/IndexType.js"
222
+ }
223
+ },
224
+ "./db/Initializer": {
225
+ "import": {
226
+ "types": "./dist/db/Initializer.d.ts",
227
+ "default": "./dist/db/Initializer.js"
228
+ }
229
+ },
230
+ "./db/Migration": {
231
+ "import": {
232
+ "types": "./dist/db/Migration.d.ts",
233
+ "default": "./dist/db/Migration.js"
234
+ }
235
+ },
236
+ "./db/MigrationStatus": {
237
+ "import": {
238
+ "types": "./dist/db/MigrationStatus.d.ts",
239
+ "default": "./dist/db/MigrationStatus.js"
240
+ }
241
+ },
242
+ "./db/Migrator": {
243
+ "import": {
244
+ "types": "./dist/db/Migrator.d.ts",
245
+ "default": "./dist/db/Migrator.js"
246
+ }
247
+ },
248
+ "./db/Operator": {
249
+ "import": {
250
+ "types": "./dist/db/Operator.d.ts",
251
+ "default": "./dist/db/Operator.js"
252
+ }
253
+ },
254
+ "./db/Order": {
255
+ "import": {
256
+ "types": "./dist/db/Order.d.ts",
257
+ "default": "./dist/db/Order.js"
258
+ }
259
+ },
260
+ "./db/ReferentialAction": {
261
+ "import": {
262
+ "types": "./dist/db/ReferentialAction.d.ts",
263
+ "default": "./dist/db/ReferentialAction.js"
264
+ }
265
+ },
266
+ "./db/Transaction": {
267
+ "import": {
268
+ "types": "./dist/db/Transaction.d.ts",
269
+ "default": "./dist/db/Transaction.js"
270
+ }
271
+ },
272
+ "./db/adapters/mysql/MysqlDb": {
273
+ "import": {
274
+ "types": "./dist/db/adapters/mysql/MysqlDb.d.ts",
275
+ "default": "./dist/db/adapters/mysql/MysqlDb.js"
276
+ }
277
+ },
278
+ "./db/relationships": {
279
+ "import": {
280
+ "types": "./dist/db/relationships.d.ts",
281
+ "default": "./dist/db/relationships.js"
282
+ }
283
+ },
203
284
  "./env/Env": {
204
285
  "import": {
205
286
  "types": "./dist/env/Env.d.ts",