@skalfa/skalfa-api-core 1.0.3 → 1.0.8
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/CONTRIBUTING.md +45 -0
- package/LICENSE +21 -0
- package/README.md +60 -0
- package/dist/auth/auth.d.ts +18 -15
- package/dist/auth/auth.js +20 -203
- package/dist/auth/auth.js.map +1 -1
- package/dist/auth/create-access-token.d.ts +4 -0
- package/dist/auth/create-access-token.js +26 -0
- package/dist/auth/create-access-token.js.map +1 -0
- package/dist/auth/create-user-mail-token.d.ts +4 -0
- package/dist/auth/create-user-mail-token.js +19 -0
- package/dist/auth/create-user-mail-token.js.map +1 -0
- package/dist/auth/helpers/generate-agent-id.d.ts +1 -0
- package/dist/auth/helpers/generate-agent-id.js +7 -0
- package/dist/auth/helpers/generate-agent-id.js.map +1 -0
- package/dist/auth/helpers/get-request-ip.d.ts +1 -0
- package/dist/auth/helpers/get-request-ip.js +4 -0
- package/dist/auth/helpers/get-request-ip.js.map +1 -0
- package/dist/auth/helpers/get-user-permissions.d.ts +1 -0
- package/dist/auth/helpers/get-user-permissions.js +9 -0
- package/dist/auth/helpers/get-user-permissions.js.map +1 -0
- package/dist/auth/helpers/index.d.ts +3 -0
- package/dist/auth/helpers/index.js +4 -0
- package/dist/auth/helpers/index.js.map +1 -0
- package/dist/auth/list-user-sessions.d.ts +1 -0
- package/dist/auth/list-user-sessions.js +10 -0
- package/dist/auth/list-user-sessions.js.map +1 -0
- package/dist/auth/revalidate-user-permissions-by-role.d.ts +1 -0
- package/dist/auth/revalidate-user-permissions-by-role.js +12 -0
- package/dist/auth/revalidate-user-permissions-by-role.js.map +1 -0
- package/dist/auth/revalidate-user-permissions.d.ts +1 -0
- package/dist/auth/revalidate-user-permissions.js +21 -0
- package/dist/auth/revalidate-user-permissions.js.map +1 -0
- package/dist/auth/revoke-access-token.d.ts +1 -0
- package/dist/auth/revoke-access-token.js +5 -0
- package/dist/auth/revoke-access-token.js.map +1 -0
- package/dist/auth/verify-access-token.d.ts +1 -0
- package/dist/auth/verify-access-token.js +47 -0
- package/dist/auth/verify-access-token.js.map +1 -0
- package/dist/auth/verify-user-mail-token.d.ts +1 -0
- package/dist/auth/verify-user-mail-token.js +21 -0
- package/dist/auth/verify-user-mail-token.js.map +1 -0
- package/dist/commands/cli.js +18 -27
- package/dist/commands/cli.js.map +1 -1
- package/dist/commands/make/basic-controller.js +1 -1
- package/dist/commands/make/basic-controller.js.map +1 -1
- package/dist/commands/make/basic-migration.d.ts +1 -1
- package/dist/commands/make/basic-migration.js +2 -2
- package/dist/commands/make/basic-migration.js.map +1 -1
- package/dist/commands/make/basic-model.js +1 -1
- package/dist/commands/make/basic-model.js.map +1 -1
- package/dist/commands/make/basic-seeder.js +1 -1
- package/dist/commands/make/basic-seeder.js.map +1 -1
- package/dist/commands/make/blueprint.js +1 -1
- package/dist/commands/make/blueprint.js.map +1 -1
- package/dist/commands/make/da-migration.js +3 -3
- package/dist/commands/make/da-migration.js.map +1 -1
- package/dist/commands/make/mail.js +2 -2
- package/dist/commands/make/mail.js.map +1 -1
- package/dist/commands/make/notification.js +1 -1
- package/dist/commands/make/notification.js.map +1 -1
- package/dist/commands/make/queue.js +1 -1
- package/dist/commands/make/queue.js.map +1 -1
- package/dist/commands/make/resource.d.ts +2 -0
- package/dist/commands/make/resource.js +19 -0
- package/dist/commands/make/resource.js.map +1 -0
- package/dist/commands/make/skalfa-controller.d.ts +3 -0
- package/dist/commands/make/{light-controller.js → skalfa-controller.js} +9 -9
- package/dist/commands/make/skalfa-controller.js.map +1 -0
- package/dist/commands/make/skalfa-model.d.ts +3 -0
- package/dist/commands/make/{light-model.js → skalfa-model.js} +11 -11
- package/dist/commands/make/skalfa-model.js.map +1 -0
- package/dist/commands/runner/barrels.js.map +1 -1
- package/dist/commands/runner/blueprint/controller-generation.js +2 -2
- package/dist/commands/runner/blueprint/controller-generation.js.map +1 -1
- package/dist/commands/runner/blueprint/documentation-generation.js.map +1 -1
- package/dist/commands/runner/blueprint/migration-generation.js +3 -3
- package/dist/commands/runner/blueprint/migration-generation.js.map +1 -1
- package/dist/commands/runner/blueprint/model-generation.js +2 -2
- package/dist/commands/runner/blueprint/model-generation.js.map +1 -1
- package/dist/commands/runner/blueprint/runner.js +7 -8
- package/dist/commands/runner/blueprint/runner.js.map +1 -1
- package/dist/commands/runner/blueprint/seeder-generation.js +3 -3
- package/dist/commands/runner/blueprint/seeder-generation.js.map +1 -1
- package/dist/commands/runner/da-migration.js +1 -2
- package/dist/commands/runner/da-migration.js.map +1 -1
- package/dist/commands/runner/generate-docs.d.ts +2 -0
- package/dist/commands/runner/generate-docs.js +400 -0
- package/dist/commands/runner/generate-docs.js.map +1 -0
- package/dist/commands/runner/migration.js +1 -1
- package/dist/commands/runner/migration.js.map +1 -1
- package/dist/commands/runner/seeder.js +1 -1
- package/dist/commands/runner/seeder.js.map +1 -1
- package/dist/commands/stubs/index.d.ts +4 -4
- package/dist/commands/stubs/index.js +4 -4
- package/dist/commands/stubs/index.js.map +1 -1
- package/dist/context/context.js +6 -0
- package/dist/context/context.js.map +1 -1
- package/dist/controller/controller.d.ts +17 -30
- package/dist/controller/controller.js +39 -121
- package/dist/controller/controller.js.map +1 -1
- package/dist/controller/response.d.ts +6 -0
- package/dist/controller/response.js +63 -0
- package/dist/controller/response.js.map +1 -0
- package/dist/controller/storage.d.ts +9 -0
- package/dist/controller/storage.js +56 -0
- package/dist/controller/storage.js.map +1 -0
- package/dist/conversion/conversion.d.ts +3 -0
- package/dist/conversion/conversion.js +28 -4
- package/dist/conversion/conversion.js.map +1 -1
- package/dist/conversion/date.d.ts +1 -0
- package/dist/conversion/date.js +77 -0
- package/dist/conversion/date.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/logger/logger.js +33 -0
- package/dist/logger/logger.js.map +1 -1
- package/dist/mail/mail.js +6 -6
- package/dist/mail/mail.js.map +1 -1
- package/dist/middleware/access-log.d.ts +31 -0
- package/dist/middleware/access-log.js +13 -0
- package/dist/middleware/access-log.js.map +1 -0
- package/dist/middleware/auth.d.ts +37 -0
- package/dist/middleware/auth.js +16 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/body-parse.d.ts +35 -0
- package/dist/middleware/body-parse.js +87 -0
- package/dist/middleware/body-parse.js.map +1 -0
- package/dist/middleware/context.d.ts +29 -0
- package/dist/middleware/context.js +8 -0
- package/dist/middleware/context.js.map +1 -0
- package/dist/middleware/cors.d.ts +31 -0
- package/dist/middleware/cors.js +27 -0
- package/dist/middleware/cors.js.map +1 -0
- package/dist/middleware/error-handler.d.ts +33 -0
- package/dist/middleware/error-handler.js +17 -0
- package/dist/middleware/error-handler.js.map +1 -0
- package/dist/middleware/middleware.d.ts +31 -10
- package/dist/middleware/middleware.js +41 -209
- package/dist/middleware/middleware.js.map +1 -1
- package/dist/middleware/private.d.ts +29 -0
- package/dist/middleware/private.js +8 -0
- package/dist/middleware/private.js.map +1 -0
- package/dist/middleware/rate-limiter.d.ts +32 -0
- package/dist/middleware/rate-limiter.js +30 -0
- package/dist/middleware/rate-limiter.js.map +1 -0
- package/dist/notification/index.d.ts +1 -0
- package/dist/notification/index.js +2 -0
- package/dist/notification/index.js.map +1 -0
- package/dist/notification/notification.d.ts +16 -0
- package/dist/notification/notification.js +64 -0
- package/dist/notification/notification.js.map +1 -0
- package/dist/permission/permission.js +9 -0
- package/dist/permission/permission.js.map +1 -1
- package/dist/registry/registry.d.ts +0 -6
- package/dist/registry/registry.js +6 -6
- package/dist/registry/registry.js.map +1 -1
- package/dist/storage/storage.d.ts +3 -3
- package/dist/storage/storage.js.map +1 -1
- package/dist/validation/validation.js +43 -51
- package/dist/validation/validation.js.map +1 -1
- package/package.json +4 -4
- package/src/auth/auth.ts +21 -252
- package/src/auth/create-access-token.ts +29 -0
- package/src/auth/create-user-mail-token.ts +24 -0
- package/src/auth/helpers/generate-agent-id.ts +8 -0
- package/src/auth/helpers/get-request-ip.ts +3 -0
- package/src/auth/helpers/get-user-permissions.ts +15 -0
- package/src/auth/helpers/index.ts +3 -0
- package/src/auth/list-user-sessions.ts +11 -0
- package/src/auth/revalidate-user-permissions-by-role.ts +13 -0
- package/src/auth/revalidate-user-permissions.ts +26 -0
- package/src/auth/revoke-access-token.ts +5 -0
- package/src/auth/verify-access-token.ts +56 -0
- package/src/auth/verify-user-mail-token.ts +24 -0
- package/src/commands/cli.ts +19 -29
- package/src/commands/make/basic-controller.ts +4 -2
- package/src/commands/make/basic-migration.ts +5 -3
- package/src/commands/make/basic-model.ts +3 -1
- package/src/commands/make/basic-seeder.ts +3 -1
- package/src/commands/make/blueprint.ts +3 -1
- package/src/commands/make/da-migration.ts +6 -5
- package/src/commands/make/mail.ts +4 -2
- package/src/commands/make/notification.ts +3 -1
- package/src/commands/make/queue.ts +3 -1
- package/src/commands/make/resource.ts +21 -0
- package/src/commands/make/{light-controller.ts → skalfa-controller.ts} +10 -8
- package/src/commands/make/{light-model.ts → skalfa-model.ts} +12 -10
- package/src/commands/runner/barrels.ts +4 -0
- package/src/commands/runner/blueprint/controller-generation.ts +4 -2
- package/src/commands/runner/blueprint/documentation-generation.ts +2 -0
- package/src/commands/runner/blueprint/migration-generation.ts +5 -3
- package/src/commands/runner/blueprint/model-generation.ts +4 -2
- package/src/commands/runner/blueprint/runner.ts +15 -8
- package/src/commands/runner/blueprint/seeder-generation.ts +5 -3
- package/src/commands/runner/da-migration.ts +3 -2
- package/src/commands/runner/generate-docs.ts +495 -0
- package/src/commands/runner/migration.ts +1 -1
- package/src/commands/runner/seeder.ts +1 -1
- package/src/commands/stubs/index.ts +4 -4
- package/src/context/context.ts +23 -17
- package/src/controller/controller.ts +124 -239
- package/src/controller/response.ts +78 -0
- package/src/controller/storage.ts +78 -0
- package/src/conversion/conversion.ts +90 -64
- package/src/conversion/date.ts +74 -0
- package/src/index.ts +2 -0
- package/src/logger/logger.ts +217 -176
- package/src/mail/mail.ts +85 -85
- package/src/middleware/access-log.ts +15 -0
- package/src/middleware/auth.ts +19 -0
- package/src/middleware/body-parse.ts +83 -0
- package/src/middleware/context.ts +11 -0
- package/src/middleware/cors.ts +31 -0
- package/src/middleware/error-handler.ts +20 -0
- package/src/middleware/middleware.ts +91 -288
- package/src/middleware/private.ts +8 -0
- package/src/middleware/rate-limiter.ts +41 -0
- package/src/notification/index.ts +1 -0
- package/src/notification/notification.ts +86 -0
- package/src/permission/permission.ts +140 -136
- package/src/registry/registry.ts +17 -15
- package/src/route/route.ts +11 -11
- package/src/storage/storage.ts +104 -106
- package/src/validation/validation.ts +322 -346
- package/dist/auth.util.d.ts +0 -19
- package/dist/auth.util.js +0 -183
- package/dist/auth.util.js.map +0 -1
- package/dist/commands/make/light-controller.d.ts +0 -3
- package/dist/commands/make/light-controller.js.map +0 -1
- package/dist/commands/make/light-model.d.ts +0 -3
- package/dist/commands/make/light-model.js.map +0 -1
- package/dist/context.util.d.ts +0 -7
- package/dist/context.util.js +0 -11
- package/dist/context.util.js.map +0 -1
- package/dist/controller.util.d.ts +0 -118
- package/dist/controller.util.js +0 -144
- package/dist/controller.util.js.map +0 -1
- package/dist/conversion.util.d.ts +0 -8
- package/dist/conversion.util.js +0 -52
- package/dist/conversion.util.js.map +0 -1
- package/dist/db/db.d.ts +0 -84
- package/dist/db/db.js +0 -177
- package/dist/db/db.js.map +0 -1
- package/dist/db/index.d.ts +0 -1
- package/dist/db/index.js +0 -2
- package/dist/db/index.js.map +0 -1
- package/dist/db.util.d.ts +0 -84
- package/dist/db.util.js +0 -177
- package/dist/db.util.js.map +0 -1
- package/dist/logger.util.d.ts +0 -30
- package/dist/logger.util.js +0 -126
- package/dist/logger.util.js.map +0 -1
- package/dist/mail.util.d.ts +0 -21
- package/dist/mail.util.js +0 -53
- package/dist/mail.util.js.map +0 -1
- package/dist/middleware.util.d.ts +0 -263
- package/dist/middleware.util.js +0 -233
- package/dist/middleware.util.js.map +0 -1
- package/dist/model/index.d.ts +0 -3
- package/dist/model/index.js +0 -4
- package/dist/model/index.js.map +0 -1
- package/dist/model/model.d.ts +0 -204
- package/dist/model/model.js +0 -1495
- package/dist/model/model.js.map +0 -1
- package/dist/model.util.d.ts +0 -204
- package/dist/model.util.js +0 -1495
- package/dist/model.util.js.map +0 -1
- package/dist/permission.util.d.ts +0 -38
- package/dist/permission.util.js +0 -91
- package/dist/permission.util.js.map +0 -1
- package/dist/registry.util.d.ts +0 -28
- package/dist/registry.util.js +0 -19
- package/dist/registry.util.js.map +0 -1
- package/dist/route.util.d.ts +0 -1
- package/dist/route.util.js +0 -12
- package/dist/route.util.js.map +0 -1
- package/dist/storage.util.d.ts +0 -56
- package/dist/storage.util.js +0 -82
- package/dist/storage.util.js.map +0 -1
- package/dist/validation.util.d.ts +0 -7
- package/dist/validation.util.js +0 -237
- package/dist/validation.util.js.map +0 -1
package/dist/db/db.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Knex } from 'knex';
|
|
2
|
-
export declare const db: Knex;
|
|
3
|
-
export declare function useDB(name: string, config?: {
|
|
4
|
-
client?: string;
|
|
5
|
-
host?: string;
|
|
6
|
-
port?: number;
|
|
7
|
-
user?: string;
|
|
8
|
-
password?: string;
|
|
9
|
-
database?: string;
|
|
10
|
-
}): Knex;
|
|
11
|
-
export declare function closeAllDB(): Promise<void>;
|
|
12
|
-
declare module "knex" {
|
|
13
|
-
namespace Knex {
|
|
14
|
-
interface TableBuilder {
|
|
15
|
-
softDelete(): Knex.ColumnBuilder;
|
|
16
|
-
foreignIdFor(tableName: string, columnName?: string): Knex.ColumnBuilder;
|
|
17
|
-
}
|
|
18
|
-
interface QueryBuilder<TRecord = any, TResult = any> {
|
|
19
|
-
where(...args: any[]): this;
|
|
20
|
-
orWhere(...args: any[]): this;
|
|
21
|
-
whereNot(...args: any[]): this;
|
|
22
|
-
whereNull(...args: any[]): this;
|
|
23
|
-
whereNotNull(...args: any[]): this;
|
|
24
|
-
whereIn(...args: any[]): this;
|
|
25
|
-
whereNotIn(...args: any[]): this;
|
|
26
|
-
whereBetween(...args: any[]): this;
|
|
27
|
-
whereNotBetween(...args: any[]): this;
|
|
28
|
-
whereExists(...args: any[]): this;
|
|
29
|
-
whereNotExists(...args: any[]): this;
|
|
30
|
-
join(...args: any[]): this;
|
|
31
|
-
leftJoin(...args: any[]): this;
|
|
32
|
-
rightJoin(...args: any[]): this;
|
|
33
|
-
innerJoin(...args: any[]): this;
|
|
34
|
-
select(...args: any[]): this;
|
|
35
|
-
distinct(...args: any[]): this;
|
|
36
|
-
orderBy(...args: any[]): this;
|
|
37
|
-
orderByRaw(...args: any[]): this;
|
|
38
|
-
limit(...args: any[]): this;
|
|
39
|
-
offset(...args: any[]): this;
|
|
40
|
-
groupBy(...args: any[]): this;
|
|
41
|
-
having(...args: any[]): this;
|
|
42
|
-
whereRaw(...args: any[]): this;
|
|
43
|
-
selectRaw(...args: any[]): this;
|
|
44
|
-
joinWith(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: {
|
|
45
|
-
localKey: string;
|
|
46
|
-
foreignKey: string;
|
|
47
|
-
} | {
|
|
48
|
-
pivotTable: string;
|
|
49
|
-
localKey: string;
|
|
50
|
-
pivotLocalKey: string;
|
|
51
|
-
pivotForeignKey: string;
|
|
52
|
-
foreignKey: string;
|
|
53
|
-
}, as: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
54
|
-
whereJoinHas(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: string | {
|
|
55
|
-
pivotTable: string;
|
|
56
|
-
localKey: string;
|
|
57
|
-
pivotLocalKey: string;
|
|
58
|
-
pivotForeignKey: string;
|
|
59
|
-
foreignKey: string;
|
|
60
|
-
}, foreignKey?: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
61
|
-
orWhereJoinHas(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: string | {
|
|
62
|
-
pivotTable: string;
|
|
63
|
-
localKey: string;
|
|
64
|
-
pivotLocalKey: string;
|
|
65
|
-
pivotForeignKey: string;
|
|
66
|
-
foreignKey: string;
|
|
67
|
-
}, foreignKey?: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
68
|
-
whereJoinDoesntHave(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: string | {
|
|
69
|
-
pivotTable: string;
|
|
70
|
-
localKey: string;
|
|
71
|
-
pivotLocalKey: string;
|
|
72
|
-
pivotForeignKey: string;
|
|
73
|
-
foreignKey: string;
|
|
74
|
-
}, foreignKey?: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
75
|
-
orWhereJoinDoesntHave(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: string | {
|
|
76
|
-
pivotTable: string;
|
|
77
|
-
localKey: string;
|
|
78
|
-
pivotLocalKey: string;
|
|
79
|
-
pivotForeignKey: string;
|
|
80
|
-
foreignKey: string;
|
|
81
|
-
}, foreignKey?: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
package/dist/db/db.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import knex from 'knex';
|
|
2
|
-
import { conversion } from '@utils/conversion';
|
|
3
|
-
// ==============================
|
|
4
|
-
// ## Driver resolver
|
|
5
|
-
// ==============================
|
|
6
|
-
function resolveDriver(conn) {
|
|
7
|
-
if (!conn)
|
|
8
|
-
return 'pg';
|
|
9
|
-
const v = conn.toLowerCase();
|
|
10
|
-
if (['pg', 'pgsql', 'postgres'].includes(v))
|
|
11
|
-
return 'pg';
|
|
12
|
-
if (['mysql', 'mysql2'].includes(v))
|
|
13
|
-
return 'mysql2';
|
|
14
|
-
throw new Error(`Unsupported DB_CONNECTION: ${conn}`);
|
|
15
|
-
}
|
|
16
|
-
// ==============================
|
|
17
|
-
// ## Knex factory
|
|
18
|
-
// ==============================
|
|
19
|
-
function createKnex(config) {
|
|
20
|
-
const client = resolveDriver(config.client);
|
|
21
|
-
return knex({
|
|
22
|
-
client,
|
|
23
|
-
connection: {
|
|
24
|
-
host: config.host ?? '127.0.0.1',
|
|
25
|
-
port: config.port ?? (client === 'mysql2' ? 3306 : 5432),
|
|
26
|
-
user: config.user ?? 'postgres',
|
|
27
|
-
password: config.password ?? 'password',
|
|
28
|
-
database: config.database ?? 'db_elysia_light',
|
|
29
|
-
},
|
|
30
|
-
pool: { min: 2, max: 10 },
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
// ==============================
|
|
34
|
-
// ## Connection registry
|
|
35
|
-
// ==============================
|
|
36
|
-
const connections = {};
|
|
37
|
-
// ==============================
|
|
38
|
-
// ## Default connection
|
|
39
|
-
// ==============================
|
|
40
|
-
const DEFAULT_NAME = 'default';
|
|
41
|
-
connections[DEFAULT_NAME] = createKnex({
|
|
42
|
-
client: process.env.DB_CONNECTION,
|
|
43
|
-
host: process.env.DB_HOST,
|
|
44
|
-
port: Number(process.env.DB_PORT),
|
|
45
|
-
user: process.env.DB_USERNAME,
|
|
46
|
-
password: process.env.DB_PASSWORD,
|
|
47
|
-
database: process.env.DB_DATABASE,
|
|
48
|
-
});
|
|
49
|
-
// ==============================
|
|
50
|
-
// ## Export default db
|
|
51
|
-
// ==============================
|
|
52
|
-
export const db = connections[DEFAULT_NAME];
|
|
53
|
-
// ==============================
|
|
54
|
-
// ## Named connection (multiple DB)
|
|
55
|
-
// ==============================
|
|
56
|
-
export function useDB(name, config) {
|
|
57
|
-
if (!connections[name]) {
|
|
58
|
-
if (!config) {
|
|
59
|
-
throw new Error(`DB connection "${name}" not found`);
|
|
60
|
-
}
|
|
61
|
-
connections[name] = createKnex(config);
|
|
62
|
-
}
|
|
63
|
-
return connections[name];
|
|
64
|
-
}
|
|
65
|
-
// ==============================
|
|
66
|
-
// ## Close all connections (CLI safe)
|
|
67
|
-
// ==============================
|
|
68
|
-
export async function closeAllDB() {
|
|
69
|
-
await Promise.all(Object.values(connections).map(db => db.destroy()));
|
|
70
|
-
}
|
|
71
|
-
// ==============================
|
|
72
|
-
// ## Schema Builder Extensions
|
|
73
|
-
// ==============================
|
|
74
|
-
knex.TableBuilder.extend("softDelete", function () {
|
|
75
|
-
return this.timestamp("deleted_at").nullable();
|
|
76
|
-
});
|
|
77
|
-
knex.TableBuilder.extend("foreignIdFor", function (tableName, columnName) {
|
|
78
|
-
const col = columnName || `${conversion.strSingular(tableName)}_id`;
|
|
79
|
-
return this.bigInteger(col).unsigned().references("id").inTable(tableName);
|
|
80
|
-
});
|
|
81
|
-
function getBaseTable(qb) {
|
|
82
|
-
return qb._single?.table;
|
|
83
|
-
}
|
|
84
|
-
function buildWhereHas(qb, type, table, localKeyOrRelation, foreignKey, callback) {
|
|
85
|
-
const baseTable = getBaseTable(qb);
|
|
86
|
-
if (!baseTable) {
|
|
87
|
-
throw new Error("whereHas harus dipanggil setelah table()");
|
|
88
|
-
}
|
|
89
|
-
qb.select(1).from(table);
|
|
90
|
-
if (type != "BELONGSTOMANY") {
|
|
91
|
-
qb.whereRaw(`${foreignKey} = ${baseTable}.${localKeyOrRelation}`);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const r = localKeyOrRelation;
|
|
95
|
-
qb.join(r.pivotTable, `${r.pivotTable}.${r.pivotForeignKey}`, `${table}.${r.foreignKey}`).whereRaw(`${r.pivotTable}.${r.pivotLocalKey} = ${baseTable}.${r.localKey}`);
|
|
96
|
-
}
|
|
97
|
-
if (callback)
|
|
98
|
-
callback(qb);
|
|
99
|
-
}
|
|
100
|
-
knex.QueryBuilder.extend("joinWith", function (type, table, relation, as, callback) {
|
|
101
|
-
const baseTable = getBaseTable(this);
|
|
102
|
-
if (!baseTable)
|
|
103
|
-
throw new Error("joinWith() must be after table()");
|
|
104
|
-
let subquery = null;
|
|
105
|
-
if (type === "BELONGSTO") {
|
|
106
|
-
const r = relation;
|
|
107
|
-
subquery = `
|
|
108
|
-
(
|
|
109
|
-
select row_to_json(${table})
|
|
110
|
-
from ${table}
|
|
111
|
-
where ${table}.${r.foreignKey} = ${baseTable}.${r.localKey}
|
|
112
|
-
limit 1
|
|
113
|
-
)
|
|
114
|
-
`;
|
|
115
|
-
}
|
|
116
|
-
if (type === "HASONE") {
|
|
117
|
-
const r = relation;
|
|
118
|
-
subquery = `
|
|
119
|
-
(
|
|
120
|
-
select row_to_json(${table})
|
|
121
|
-
from ${table}
|
|
122
|
-
where ${table}.${r.foreignKey} = ${baseTable}.${r.localKey}
|
|
123
|
-
limit 1
|
|
124
|
-
)
|
|
125
|
-
`;
|
|
126
|
-
}
|
|
127
|
-
if (type === "HASMANY") {
|
|
128
|
-
const r = relation;
|
|
129
|
-
subquery = `
|
|
130
|
-
(
|
|
131
|
-
select coalesce(json_agg(${table}), '[]'::json)
|
|
132
|
-
from ${table}
|
|
133
|
-
where ${table}.${r.foreignKey} = ${baseTable}.${r.localKey}
|
|
134
|
-
)
|
|
135
|
-
`;
|
|
136
|
-
}
|
|
137
|
-
if (type === "BELONGSTOMANY") {
|
|
138
|
-
const r = relation;
|
|
139
|
-
subquery = `
|
|
140
|
-
(
|
|
141
|
-
select coalesce(json_agg(${table}), '[]'::json)
|
|
142
|
-
from ${table}
|
|
143
|
-
inner join ${r.pivotTable}
|
|
144
|
-
on ${r.pivotTable}.${r.pivotForeignKey} = ${table}.${r.foreignKey}
|
|
145
|
-
where ${r.pivotTable}.${r.pivotLocalKey} = ${baseTable}.${r.localKey}
|
|
146
|
-
)
|
|
147
|
-
`;
|
|
148
|
-
}
|
|
149
|
-
if (!subquery) {
|
|
150
|
-
throw new Error(`Unsupported relation type: ${type}`);
|
|
151
|
-
}
|
|
152
|
-
if (callback) {
|
|
153
|
-
callback(this);
|
|
154
|
-
}
|
|
155
|
-
return this.select(this.client.raw(`${subquery} as "${as}"`));
|
|
156
|
-
});
|
|
157
|
-
knex.QueryBuilder.extend("whereJoinHas", function (type, table, localKeyOrRelation, foreignKey, callback) {
|
|
158
|
-
return this.whereExists(function () {
|
|
159
|
-
buildWhereHas(this, type, table, localKeyOrRelation, foreignKey, callback);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
knex.QueryBuilder.extend("orJoinWhereHas", function (type, table, localKeyOrRelation, foreignKey, callback) {
|
|
163
|
-
return this.orWhereExists(function () {
|
|
164
|
-
buildWhereHas(this, type, table, localKeyOrRelation, foreignKey, callback);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
knex.QueryBuilder.extend("whereJoinDoesntHave", function (type, table, localKeyOrRelation, foreignKey, callback) {
|
|
168
|
-
return this.whereNotExists(function () {
|
|
169
|
-
buildWhereHas(this, type, table, localKeyOrRelation, foreignKey, callback);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
knex.QueryBuilder.extend("orWhereJoinDoesntHave", function (type, table, localKeyOrRelation, foreignKey, callback) {
|
|
173
|
-
return this.orWhereNotExists(function () {
|
|
174
|
-
buildWhereHas(this, type, table, localKeyOrRelation, foreignKey, callback);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
//# sourceMappingURL=db.js.map
|
package/dist/db/db.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/db/db.ts"],"names":[],"mappings":"AAAA,OAAO,IAAc,MAAM,MAAM,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,iCAAiC;AACjC,qBAAqB;AACrB,iCAAiC;AACjC,SAAS,aAAa,CAAC,IAAa;IAClC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IAEtB,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;IAC5B,IAAI,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QAAQ,CACT,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAGF,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,uBAAuB,EAAE,UAAmC,IAAI,EAAE,KAAK,EAAE,kBAAkB,EAAE,UAAW,EAAE,QAAS;IAC1I,OAAO,IAAI,CAAC,gBAAgB,CAAC;QAC3B,aAAa,CACX,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,kBAAkB,EAClB,UAAU,EACV,QAAQ,CACT,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/db/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const db: any;
|
package/dist/db/index.js
DELETED
package/dist/db/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,EAAE,GAAQ,IAAI,CAAC"}
|
package/dist/db.util.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Knex } from 'knex';
|
|
2
|
-
export declare const db: Knex;
|
|
3
|
-
export declare function useDB(name: string, config?: {
|
|
4
|
-
client?: string;
|
|
5
|
-
host?: string;
|
|
6
|
-
port?: number;
|
|
7
|
-
user?: string;
|
|
8
|
-
password?: string;
|
|
9
|
-
database?: string;
|
|
10
|
-
}): Knex;
|
|
11
|
-
export declare function closeAllDB(): Promise<void>;
|
|
12
|
-
declare module "knex" {
|
|
13
|
-
namespace Knex {
|
|
14
|
-
interface TableBuilder {
|
|
15
|
-
softDelete(): Knex.ColumnBuilder;
|
|
16
|
-
foreignIdFor(tableName: string, columnName?: string): Knex.ColumnBuilder;
|
|
17
|
-
}
|
|
18
|
-
interface QueryBuilder<TRecord = any, TResult = any> {
|
|
19
|
-
where(...args: any[]): this;
|
|
20
|
-
orWhere(...args: any[]): this;
|
|
21
|
-
whereNot(...args: any[]): this;
|
|
22
|
-
whereNull(...args: any[]): this;
|
|
23
|
-
whereNotNull(...args: any[]): this;
|
|
24
|
-
whereIn(...args: any[]): this;
|
|
25
|
-
whereNotIn(...args: any[]): this;
|
|
26
|
-
whereBetween(...args: any[]): this;
|
|
27
|
-
whereNotBetween(...args: any[]): this;
|
|
28
|
-
whereExists(...args: any[]): this;
|
|
29
|
-
whereNotExists(...args: any[]): this;
|
|
30
|
-
join(...args: any[]): this;
|
|
31
|
-
leftJoin(...args: any[]): this;
|
|
32
|
-
rightJoin(...args: any[]): this;
|
|
33
|
-
innerJoin(...args: any[]): this;
|
|
34
|
-
select(...args: any[]): this;
|
|
35
|
-
distinct(...args: any[]): this;
|
|
36
|
-
orderBy(...args: any[]): this;
|
|
37
|
-
orderByRaw(...args: any[]): this;
|
|
38
|
-
limit(...args: any[]): this;
|
|
39
|
-
offset(...args: any[]): this;
|
|
40
|
-
groupBy(...args: any[]): this;
|
|
41
|
-
having(...args: any[]): this;
|
|
42
|
-
whereRaw(...args: any[]): this;
|
|
43
|
-
selectRaw(...args: any[]): this;
|
|
44
|
-
joinWith(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: {
|
|
45
|
-
localKey: string;
|
|
46
|
-
foreignKey: string;
|
|
47
|
-
} | {
|
|
48
|
-
pivotTable: string;
|
|
49
|
-
localKey: string;
|
|
50
|
-
pivotLocalKey: string;
|
|
51
|
-
pivotForeignKey: string;
|
|
52
|
-
foreignKey: string;
|
|
53
|
-
}, as: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
54
|
-
whereJoinHas(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: string | {
|
|
55
|
-
pivotTable: string;
|
|
56
|
-
localKey: string;
|
|
57
|
-
pivotLocalKey: string;
|
|
58
|
-
pivotForeignKey: string;
|
|
59
|
-
foreignKey: string;
|
|
60
|
-
}, foreignKey?: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
61
|
-
orWhereJoinHas(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: string | {
|
|
62
|
-
pivotTable: string;
|
|
63
|
-
localKey: string;
|
|
64
|
-
pivotLocalKey: string;
|
|
65
|
-
pivotForeignKey: string;
|
|
66
|
-
foreignKey: string;
|
|
67
|
-
}, foreignKey?: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
68
|
-
whereJoinDoesntHave(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: string | {
|
|
69
|
-
pivotTable: string;
|
|
70
|
-
localKey: string;
|
|
71
|
-
pivotLocalKey: string;
|
|
72
|
-
pivotForeignKey: string;
|
|
73
|
-
foreignKey: string;
|
|
74
|
-
}, foreignKey?: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
75
|
-
orWhereJoinDoesntHave(type: "BELONGSTO" | "HASONE" | "HASMANY" | "BELONGSTOMANY", table: string, relation: string | {
|
|
76
|
-
pivotTable: string;
|
|
77
|
-
localKey: string;
|
|
78
|
-
pivotLocalKey: string;
|
|
79
|
-
pivotForeignKey: string;
|
|
80
|
-
foreignKey: string;
|
|
81
|
-
}, foreignKey?: string, callback?: (qb: Knex.QueryBuilder) => void): Knex.QueryBuilder<TRecord, TResult>;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
package/dist/db.util.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import knex from 'knex';
|
|
2
|
-
import { conversion } from './conversion.util';
|
|
3
|
-
// ==============================
|
|
4
|
-
// ## Driver resolver
|
|
5
|
-
// ==============================
|
|
6
|
-
function resolveDriver(conn) {
|
|
7
|
-
if (!conn)
|
|
8
|
-
return 'pg';
|
|
9
|
-
const v = conn.toLowerCase();
|
|
10
|
-
if (['pg', 'pgsql', 'postgres'].includes(v))
|
|
11
|
-
return 'pg';
|
|
12
|
-
if (['mysql', 'mysql2'].includes(v))
|
|
13
|
-
return 'mysql2';
|
|
14
|
-
throw new Error(`Unsupported DB_CONNECTION: ${conn}`);
|
|
15
|
-
}
|
|
16
|
-
// ==============================
|
|
17
|
-
// ## Knex factory
|
|
18
|
-
// ==============================
|
|
19
|
-
function createKnex(config) {
|
|
20
|
-
const client = resolveDriver(config.client);
|
|
21
|
-
return knex({
|
|
22
|
-
client,
|
|
23
|
-
connection: {
|
|
24
|
-
host: config.host ?? '127.0.0.1',
|
|
25
|
-
port: config.port ?? (client === 'mysql2' ? 3306 : 5432),
|
|
26
|
-
user: config.user ?? 'postgres',
|
|
27
|
-
password: config.password ?? 'password',
|
|
28
|
-
database: config.database ?? 'db_elysia_light',
|
|
29
|
-
},
|
|
30
|
-
pool: { min: 2, max: 10 },
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
// ==============================
|
|
34
|
-
// ## Connection registry
|
|
35
|
-
// ==============================
|
|
36
|
-
const connections = {};
|
|
37
|
-
// ==============================
|
|
38
|
-
// ## Default connection
|
|
39
|
-
// ==============================
|
|
40
|
-
const DEFAULT_NAME = 'default';
|
|
41
|
-
connections[DEFAULT_NAME] = createKnex({
|
|
42
|
-
client: process.env.DB_CONNECTION,
|
|
43
|
-
host: process.env.DB_HOST,
|
|
44
|
-
port: Number(process.env.DB_PORT),
|
|
45
|
-
user: process.env.DB_USERNAME,
|
|
46
|
-
password: process.env.DB_PASSWORD,
|
|
47
|
-
database: process.env.DB_DATABASE,
|
|
48
|
-
});
|
|
49
|
-
// ==============================
|
|
50
|
-
// ## Export default db
|
|
51
|
-
// ==============================
|
|
52
|
-
export const db = connections[DEFAULT_NAME];
|
|
53
|
-
// ==============================
|
|
54
|
-
// ## Named connection (multiple DB)
|
|
55
|
-
// ==============================
|
|
56
|
-
export function useDB(name, config) {
|
|
57
|
-
if (!connections[name]) {
|
|
58
|
-
if (!config) {
|
|
59
|
-
throw new Error(`DB connection "${name}" not found`);
|
|
60
|
-
}
|
|
61
|
-
connections[name] = createKnex(config);
|
|
62
|
-
}
|
|
63
|
-
return connections[name];
|
|
64
|
-
}
|
|
65
|
-
// ==============================
|
|
66
|
-
// ## Close all connections (CLI safe)
|
|
67
|
-
// ==============================
|
|
68
|
-
export async function closeAllDB() {
|
|
69
|
-
await Promise.all(Object.values(connections).map(db => db.destroy()));
|
|
70
|
-
}
|
|
71
|
-
// ==============================
|
|
72
|
-
// ## Schema Builder Extensions
|
|
73
|
-
// ==============================
|
|
74
|
-
knex.TableBuilder.extend("softDelete", function () {
|
|
75
|
-
return this.timestamp("deleted_at").nullable();
|
|
76
|
-
});
|
|
77
|
-
knex.TableBuilder.extend("foreignIdFor", function (tableName, columnName) {
|
|
78
|
-
const col = columnName || `${conversion.strSingular(tableName)}_id`;
|
|
79
|
-
return this.bigInteger(col).unsigned().references("id").inTable(tableName);
|
|
80
|
-
});
|
|
81
|
-
function getBaseTable(qb) {
|
|
82
|
-
return qb._single?.table;
|
|
83
|
-
}
|
|
84
|
-
function buildWhereHas(qb, type, table, localKeyOrRelation, foreignKey, callback) {
|
|
85
|
-
const baseTable = getBaseTable(qb);
|
|
86
|
-
if (!baseTable) {
|
|
87
|
-
throw new Error("whereHas harus dipanggil setelah table()");
|
|
88
|
-
}
|
|
89
|
-
qb.select(1).from(table);
|
|
90
|
-
if (type != "BELONGSTOMANY") {
|
|
91
|
-
qb.whereRaw(`${foreignKey} = ${baseTable}.${localKeyOrRelation}`);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const r = localKeyOrRelation;
|
|
95
|
-
qb.join(r.pivotTable, `${r.pivotTable}.${r.pivotForeignKey}`, `${table}.${r.foreignKey}`).whereRaw(`${r.pivotTable}.${r.pivotLocalKey} = ${baseTable}.${r.localKey}`);
|
|
96
|
-
}
|
|
97
|
-
if (callback)
|
|
98
|
-
callback(qb);
|
|
99
|
-
}
|
|
100
|
-
knex.QueryBuilder.extend("joinWith", function (type, table, relation, as, callback) {
|
|
101
|
-
const baseTable = getBaseTable(this);
|
|
102
|
-
if (!baseTable)
|
|
103
|
-
throw new Error("joinWith() must be after table()");
|
|
104
|
-
let subquery = null;
|
|
105
|
-
if (type === "BELONGSTO") {
|
|
106
|
-
const r = relation;
|
|
107
|
-
subquery = `
|
|
108
|
-
(
|
|
109
|
-
select row_to_json(${table})
|
|
110
|
-
from ${table}
|
|
111
|
-
where ${table}.${r.foreignKey} = ${baseTable}.${r.localKey}
|
|
112
|
-
limit 1
|
|
113
|
-
)
|
|
114
|
-
`;
|
|
115
|
-
}
|
|
116
|
-
if (type === "HASONE") {
|
|
117
|
-
const r = relation;
|
|
118
|
-
subquery = `
|
|
119
|
-
(
|
|
120
|
-
select row_to_json(${table})
|
|
121
|
-
from ${table}
|
|
122
|
-
where ${table}.${r.foreignKey} = ${baseTable}.${r.localKey}
|
|
123
|
-
limit 1
|
|
124
|
-
)
|
|
125
|
-
`;
|
|
126
|
-
}
|
|
127
|
-
if (type === "HASMANY") {
|
|
128
|
-
const r = relation;
|
|
129
|
-
subquery = `
|
|
130
|
-
(
|
|
131
|
-
select coalesce(json_agg(${table}), '[]'::json)
|
|
132
|
-
from ${table}
|
|
133
|
-
where ${table}.${r.foreignKey} = ${baseTable}.${r.localKey}
|
|
134
|
-
)
|
|
135
|
-
`;
|
|
136
|
-
}
|
|
137
|
-
if (type === "BELONGSTOMANY") {
|
|
138
|
-
const r = relation;
|
|
139
|
-
subquery = `
|
|
140
|
-
(
|
|
141
|
-
select coalesce(json_agg(${table}), '[]'::json)
|
|
142
|
-
from ${table}
|
|
143
|
-
inner join ${r.pivotTable}
|
|
144
|
-
on ${r.pivotTable}.${r.pivotForeignKey} = ${table}.${r.foreignKey}
|
|
145
|
-
where ${r.pivotTable}.${r.pivotLocalKey} = ${baseTable}.${r.localKey}
|
|
146
|
-
)
|
|
147
|
-
`;
|
|
148
|
-
}
|
|
149
|
-
if (!subquery) {
|
|
150
|
-
throw new Error(`Unsupported relation type: ${type}`);
|
|
151
|
-
}
|
|
152
|
-
if (callback) {
|
|
153
|
-
callback(this);
|
|
154
|
-
}
|
|
155
|
-
return this.select(this.client.raw(`${subquery} as "${as}"`));
|
|
156
|
-
});
|
|
157
|
-
knex.QueryBuilder.extend("whereJoinHas", function (type, table, localKeyOrRelation, foreignKey, callback) {
|
|
158
|
-
return this.whereExists(function () {
|
|
159
|
-
buildWhereHas(this, type, table, localKeyOrRelation, foreignKey, callback);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
knex.QueryBuilder.extend("orJoinWhereHas", function (type, table, localKeyOrRelation, foreignKey, callback) {
|
|
163
|
-
return this.orWhereExists(function () {
|
|
164
|
-
buildWhereHas(this, type, table, localKeyOrRelation, foreignKey, callback);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
knex.QueryBuilder.extend("whereJoinDoesntHave", function (type, table, localKeyOrRelation, foreignKey, callback) {
|
|
168
|
-
return this.whereNotExists(function () {
|
|
169
|
-
buildWhereHas(this, type, table, localKeyOrRelation, foreignKey, callback);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
knex.QueryBuilder.extend("orWhereJoinDoesntHave", function (type, table, localKeyOrRelation, foreignKey, callback) {
|
|
173
|
-
return this.orWhereNotExists(function () {
|
|
174
|
-
buildWhereHas(this, type, table, localKeyOrRelation, foreignKey, callback);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
//# sourceMappingURL=db.util.js.map
|
package/dist/db.util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db.util.js","sourceRoot":"","sources":["../src/db.util.ts"],"names":[],"mappings":"AAAA,OAAO,IAAc,MAAM,MAAM,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,iCAAiC;AACjC,qBAAqB;AACrB,iCAAiC;AACjC,SAAS,aAAa,CAAC,IAAa;IAClC,IAA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OAAO,IAAI,CAAC,cAAc,CAAC;QACzB,aAAa,CACX,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,kBAAkB,EAClB,UAAU,EACV,QAAQ,CACT,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAGF,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,uBAAuB,EAAE,UAAmC,IAAI,EAAE,KAAK,EAAE,kBAAkB,EAAE,UAAW,EAAE,QAAS;IAC1I,OAAO,IAAI,CAAC,gBAAgB,CAAC;QAC3B,aAAa,CACX,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,kBAAkB,EAClB,UAAU,EACV,QAAQ,CACT,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/logger.util.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface AccessLog {
|
|
2
|
-
method: string;
|
|
3
|
-
path: string;
|
|
4
|
-
status: number;
|
|
5
|
-
latency: number;
|
|
6
|
-
ip?: string | null;
|
|
7
|
-
agent?: string | null;
|
|
8
|
-
at?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface ErrorLog {
|
|
11
|
-
service?: string;
|
|
12
|
-
key?: string;
|
|
13
|
-
feature?: string;
|
|
14
|
-
error: string | null;
|
|
15
|
-
reference?: string | null;
|
|
16
|
-
at?: string;
|
|
17
|
-
}
|
|
18
|
-
export declare const logger: {
|
|
19
|
-
start: (msg: string) => void;
|
|
20
|
-
info: (msg: string) => void;
|
|
21
|
-
warning: (msg: string) => void;
|
|
22
|
-
queue: (msg: string) => void;
|
|
23
|
-
cron: (msg: string) => void;
|
|
24
|
-
socket: (msg: string) => void;
|
|
25
|
-
access: (msg: AccessLog) => void;
|
|
26
|
-
error: (msg: string, payload?: ErrorLog) => void;
|
|
27
|
-
queueError: (msg: string, payload?: ErrorLog) => void;
|
|
28
|
-
cronError: (msg: string, payload?: ErrorLog) => void;
|
|
29
|
-
socketError: (msg: string, payload?: ErrorLog) => void;
|
|
30
|
-
};
|