@skalfa/skalfa-api-core 1.0.2 → 1.0.7
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 +5 -3
- 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/{light-controller.js → skalfa-controller.js} +3 -3
- package/dist/commands/make/skalfa-controller.js.map +1 -0
- package/dist/commands/make/{light-model.js → skalfa-model.js} +4 -4
- 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.map +1 -1
- package/dist/commands/runner/blueprint/documentation-generation.js.map +1 -1
- package/dist/commands/runner/blueprint/migration-generation.js +1 -1
- package/dist/commands/runner/blueprint/migration-generation.js.map +1 -1
- package/dist/commands/runner/blueprint/model-generation.js.map +1 -1
- package/dist/commands/runner/blueprint/runner.js +2 -2
- package/dist/commands/runner/blueprint/runner.js.map +1 -1
- package/dist/commands/runner/blueprint/seeder-generation.js +1 -1
- 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/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/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 +5 -3
- package/src/commands/make/basic-controller.ts +3 -1
- 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} +4 -2
- package/src/commands/make/{light-model.ts → skalfa-model.ts} +5 -3
- package/src/commands/runner/barrels.ts +4 -0
- package/src/commands/runner/blueprint/controller-generation.ts +2 -0
- package/src/commands/runner/blueprint/documentation-generation.ts +2 -0
- package/src/commands/runner/blueprint/migration-generation.ts +3 -1
- package/src/commands/runner/blueprint/model-generation.ts +2 -0
- package/src/commands/runner/blueprint/runner.ts +10 -2
- package/src/commands/runner/blueprint/seeder-generation.ts +3 -1
- package/src/commands/runner/da-migration.ts +3 -2
- package/src/commands/runner/migration.ts +1 -1
- package/src/commands/runner/seeder.ts +1 -1
- 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.js.map +0 -1
- 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/commands/make/{light-controller.d.ts → skalfa-controller.d.ts} +0 -0
- /package/dist/commands/make/{light-model.d.ts → skalfa-model.d.ts} +0 -0
|
@@ -4,6 +4,8 @@ import { Command } from "commander";
|
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
5
|
import { basicMigrationStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:migration
|
|
9
11
|
// =====================================>
|
|
@@ -13,8 +15,11 @@ export const makeMigrationCommand = new Command("make:migration")
|
|
|
13
15
|
.description("Membuat file migration baru")
|
|
14
16
|
.action((name, options) => {
|
|
15
17
|
makeMigration(name, options);
|
|
18
|
+
process.exit(0);
|
|
16
19
|
});
|
|
17
20
|
|
|
21
|
+
|
|
22
|
+
|
|
18
23
|
// =====================================>
|
|
19
24
|
// ## Command: migration helpers
|
|
20
25
|
// =====================================>
|
|
@@ -28,7 +33,6 @@ export const makeMigration = (
|
|
|
28
33
|
|
|
29
34
|
const baseDir = path.join(
|
|
30
35
|
process.cwd(),
|
|
31
|
-
"src",
|
|
32
36
|
"database",
|
|
33
37
|
"migrations"
|
|
34
38
|
);
|
|
@@ -66,8 +70,6 @@ export const makeMigration = (
|
|
|
66
70
|
writeFileSync(filePath, content);
|
|
67
71
|
|
|
68
72
|
logger.info(`Migration created: ${path.relative(baseDir, filePath)}`);
|
|
69
|
-
|
|
70
|
-
process.exit(0);
|
|
71
73
|
};
|
|
72
74
|
|
|
73
75
|
const migrationPrefixFile = (date: Date) => {
|
|
@@ -4,6 +4,8 @@ import { Command } from "commander";
|
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
5
|
import { basicModelStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:model
|
|
9
11
|
// =====================================>
|
|
@@ -14,7 +16,7 @@ export const makeModelCommand = new Command("make:model")
|
|
|
14
16
|
const name = conversion.strPascal(modelName);
|
|
15
17
|
const filename = conversion.strSlug(modelName) + ".model.ts";
|
|
16
18
|
|
|
17
|
-
const filePath = path.join(process.cwd(), "
|
|
19
|
+
const filePath = path.join(process.cwd(), "app", "models", filename);
|
|
18
20
|
|
|
19
21
|
if (!existsSync(path.dirname(filePath))) {
|
|
20
22
|
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
@@ -4,6 +4,8 @@ import { Command } from "commander";
|
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
5
|
import { basicSeederStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:seeder
|
|
9
11
|
// =====================================>
|
|
@@ -21,7 +23,7 @@ export const makeSeeder = (seederName: string, model?: string) => {
|
|
|
21
23
|
const filename = conversion.strSlug(seederName) + ".seeder.ts";
|
|
22
24
|
const modelName = model || conversion.strPascal(seederName);
|
|
23
25
|
|
|
24
|
-
const dir = path.join(process.cwd(), "
|
|
26
|
+
const dir = path.join(process.cwd(), "database", "seeders");
|
|
25
27
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
26
28
|
|
|
27
29
|
const filePath = path.join(dir, filename);
|
|
@@ -4,6 +4,8 @@ import { Command } from "commander";
|
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
5
|
import { blueprintStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:blueprint
|
|
9
11
|
// =====================================>
|
|
@@ -11,7 +13,7 @@ export const makeBlueprintCommand = new Command("make:blueprint")
|
|
|
11
13
|
.argument("<name>", "Name of blueprint")
|
|
12
14
|
.description("Create new blueprint")
|
|
13
15
|
.action((name) => {
|
|
14
|
-
const basePath = path.join(process.cwd(), "
|
|
16
|
+
const basePath = path.join(process.cwd(), "blueprints");
|
|
15
17
|
|
|
16
18
|
if (!name || name.trim() === "") {
|
|
17
19
|
logger.error("Blueprint name invalid!");
|
|
@@ -4,10 +4,12 @@ import { Command } from "commander";
|
|
|
4
4
|
import { logger } from "@utils";
|
|
5
5
|
import { daMigrationStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:da:migration
|
|
9
11
|
// =====================================>
|
|
10
|
-
export const makeDaMigrationCommand = new Command("make:da
|
|
12
|
+
export const makeDaMigrationCommand = new Command("make:da-migration")
|
|
11
13
|
.argument("<name>", "Nama migration")
|
|
12
14
|
.option("--init", "Buat migration init (0000_00)")
|
|
13
15
|
.description("Membuat file migration baru")
|
|
@@ -24,9 +26,8 @@ export const makeDaMigration = (
|
|
|
24
26
|
|
|
25
27
|
const baseDir = path.join(
|
|
26
28
|
process.cwd(),
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"da.migrations"
|
|
29
|
+
"analytic",
|
|
30
|
+
"migrations"
|
|
30
31
|
);
|
|
31
32
|
|
|
32
33
|
let targetDir: string;
|
|
@@ -62,7 +63,7 @@ export const makeDaMigration = (
|
|
|
62
63
|
writeFileSync(filePath, content);
|
|
63
64
|
|
|
64
65
|
logger.info(
|
|
65
|
-
`
|
|
66
|
+
`Analytics Migration created: ${path.relative(baseDir, filePath)}`
|
|
66
67
|
);
|
|
67
68
|
|
|
68
69
|
process.exit(0);
|
|
@@ -4,6 +4,8 @@ import { Command } from "commander";
|
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
5
|
import { mailStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:mail
|
|
9
11
|
// =====================================>
|
|
@@ -11,8 +13,8 @@ export const makeMailCommand = new Command("make:mail")
|
|
|
11
13
|
.argument("<name>", "Name of mail")
|
|
12
14
|
.description("Create new mail")
|
|
13
15
|
.action((name) => {
|
|
14
|
-
const basePath = path.join(process.cwd(), "
|
|
15
|
-
const templatePath = path.join(process.cwd(), "
|
|
16
|
+
const basePath = path.join(process.cwd(), "app", "outputs", "mails");
|
|
17
|
+
const templatePath = path.join(process.cwd(), "app", "outputs", "mails", "templates");
|
|
16
18
|
|
|
17
19
|
if (!name || name.trim() === "") {
|
|
18
20
|
logger.error("Mail name invalid!");
|
|
@@ -4,6 +4,8 @@ import { Command } from "commander";
|
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
5
|
import { notificationStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:notification
|
|
9
11
|
// =====================================>
|
|
@@ -11,7 +13,7 @@ export const makeNotificationCommand = new Command("make:notification")
|
|
|
11
13
|
.argument("<name>", "Name of notification")
|
|
12
14
|
.description("Create new notification")
|
|
13
15
|
.action((name) => {
|
|
14
|
-
const basePath = path.join(process.cwd(), "
|
|
16
|
+
const basePath = path.join(process.cwd(), "app", "outputs", "notifications");
|
|
15
17
|
|
|
16
18
|
if (!name || name.trim() === "") {
|
|
17
19
|
logger.error("Notification name invalid!");
|
|
@@ -4,6 +4,8 @@ import { Command } from "commander";
|
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
5
|
import { queueStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:queue
|
|
9
11
|
// =====================================>
|
|
@@ -11,7 +13,7 @@ export const makeQueueCommand = new Command("make:queue")
|
|
|
11
13
|
.argument("<name>", "Name of queue")
|
|
12
14
|
.description("Create new queue")
|
|
13
15
|
.action((name) => {
|
|
14
|
-
const basePath = path.join(process.cwd(), "
|
|
16
|
+
const basePath = path.join(process.cwd(), "app", "jobs", "queues");
|
|
15
17
|
|
|
16
18
|
if (!name || name.trim() === "") {
|
|
17
19
|
logger.error("Queue name invalid!");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { makeLightModel } from "./skalfa-model";
|
|
3
|
+
import { makeLightController } from "./skalfa-controller";
|
|
4
|
+
import { makeMigration } from "./basic-migration";
|
|
5
|
+
import { makeSeeder } from "./basic-seeder";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// =====================================>
|
|
10
|
+
// ## Command: make:resource
|
|
11
|
+
// =====================================>
|
|
12
|
+
export const makeResourceCommand = new Command("make:resource")
|
|
13
|
+
.argument("<name>", "Name of resource")
|
|
14
|
+
.description("Create a new model, migration, seeder, and controller for a resource")
|
|
15
|
+
.action((name) => {
|
|
16
|
+
makeLightModel(name);
|
|
17
|
+
makeLightController(name);
|
|
18
|
+
makeMigration("create_" + name, { init: true });
|
|
19
|
+
makeSeeder(name);
|
|
20
|
+
process.exit(0);
|
|
21
|
+
});
|
|
@@ -4,10 +4,12 @@ import { Command } from "commander";
|
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
5
|
import { lightControllerStub } from "../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: make:light-controller
|
|
9
11
|
// =====================================>
|
|
10
|
-
export const makeLightControllerCommand = new Command("make:
|
|
12
|
+
export const makeLightControllerCommand = new Command("make:skalfa-controller")
|
|
11
13
|
.argument("<name>", "Name of controller")
|
|
12
14
|
.option("-m, --model <model>", "Attach model to controller")
|
|
13
15
|
.description("Make the Light Controller")
|
|
@@ -17,7 +19,7 @@ export const makeLightControllerCommand = new Command("make:light-controller")
|
|
|
17
19
|
});
|
|
18
20
|
|
|
19
21
|
export const makeLightController = (controllerName: string, modelName?: string) => {
|
|
20
|
-
const basePath = path.join(process.cwd(), "
|
|
22
|
+
const basePath = path.join(process.cwd(), "app", "controllers");
|
|
21
23
|
|
|
22
24
|
if (!controllerName || controllerName.trim() === "") {
|
|
23
25
|
logger.error("Controller name invalid!");
|
|
@@ -2,15 +2,17 @@ import path from "path";
|
|
|
2
2
|
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { conversion, logger } from "@utils";
|
|
5
|
-
import { makeLightController } from "./
|
|
5
|
+
import { makeLightController } from "./skalfa-controller";
|
|
6
6
|
import { makeMigration } from "./basic-migration";
|
|
7
7
|
import { makeSeeder } from "./basic-seeder";
|
|
8
8
|
import { lightModelStub } from "../stubs";
|
|
9
9
|
|
|
10
|
+
|
|
11
|
+
|
|
10
12
|
// =====================================>
|
|
11
13
|
// ## Command: make:light-model
|
|
12
14
|
// =====================================>
|
|
13
|
-
export const makeLightModelCommand = new Command("make:
|
|
15
|
+
export const makeLightModelCommand = new Command("make:skalfa-model")
|
|
14
16
|
.argument("<name>", "Name of model")
|
|
15
17
|
.option("-r", "Generate all resource (controller, migration, seeder)")
|
|
16
18
|
.description("Make the Light Model")
|
|
@@ -30,7 +32,7 @@ export const makeLightModel = (modelName: string) => {
|
|
|
30
32
|
const name = conversion.strPascal(modelName);
|
|
31
33
|
const filename = conversion.strSlug(modelName) + ".model.ts";
|
|
32
34
|
|
|
33
|
-
const basePath = path.join(process.cwd(), "
|
|
35
|
+
const basePath = path.join(process.cwd(), "app", "models");
|
|
34
36
|
|
|
35
37
|
if (!existsSync(basePath)) {
|
|
36
38
|
mkdirSync(basePath, { recursive: true });
|
|
@@ -4,6 +4,8 @@ import { exec, execSync } from "child_process";
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import { logger } from "@utils";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// =====================================>
|
|
8
10
|
// ## Command: barrels (run once)
|
|
9
11
|
// =====================================>
|
|
@@ -29,6 +31,8 @@ export const barrelsCommand = new Command("barrels")
|
|
|
29
31
|
}
|
|
30
32
|
});
|
|
31
33
|
|
|
34
|
+
|
|
35
|
+
|
|
32
36
|
// =====================================>
|
|
33
37
|
// ## Command: watch:barrels (file watcher)
|
|
34
38
|
// =====================================>
|
|
@@ -4,6 +4,8 @@ import { conversion } from "@utils";
|
|
|
4
4
|
import { resolveBlueprintPath } from "./runner";
|
|
5
5
|
import { lightControllerStub, routeStub } from "../../stubs";
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
// ================================>
|
|
8
10
|
// ## Command: Blueprint controller generation
|
|
9
11
|
// ================================>
|
|
@@ -5,6 +5,8 @@ import { conversion } from "@utils";
|
|
|
5
5
|
const ERD_PATH = path.join(process.cwd(), "storage", "documentation", "entity");
|
|
6
6
|
const API_PATH = path.join(process.cwd(), "storage", "documentation", "api");
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
|
|
8
10
|
// =========================================>
|
|
9
11
|
// ## Command: Blueprint documentation generation
|
|
10
12
|
// =========================================>
|
|
@@ -3,6 +3,8 @@ import fs from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { lightMigrationStub } from "../../stubs";
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
|
|
6
8
|
// ==================================>
|
|
7
9
|
// ## Command: Blueprint migration generation
|
|
8
10
|
// ==================================>
|
|
@@ -13,7 +15,7 @@ export async function migrationGeneration(
|
|
|
13
15
|
marker: string
|
|
14
16
|
): Promise<boolean> {
|
|
15
17
|
const name = conversion.strSnake(conversion.strPlural(model.split("/").pop() || ""));
|
|
16
|
-
const basePath = path.join(process.cwd(), "
|
|
18
|
+
const basePath = path.join(process.cwd(), "database", "migrations", "0000_00");
|
|
17
19
|
const filename = `${name}.ts`;
|
|
18
20
|
const filePath = path.join(basePath, filename);
|
|
19
21
|
const className = `create${conversion.strPascal(name)}Table`;
|
|
@@ -10,6 +10,8 @@ import { generateDrawioEntityDocumentation, generateMermaidEntityDocumentation,
|
|
|
10
10
|
import { exec as execCb } from "child_process";
|
|
11
11
|
import { promisify } from "util";
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
|
|
13
15
|
const exec = promisify(execCb);
|
|
14
16
|
|
|
15
17
|
export interface BlueprintSchema {
|
|
@@ -32,6 +34,8 @@ const blueprintMarker = `// ============================================
|
|
|
32
34
|
|
|
33
35
|
`;
|
|
34
36
|
|
|
37
|
+
|
|
38
|
+
|
|
35
39
|
// =====================================>
|
|
36
40
|
// ## Command: blueprint
|
|
37
41
|
// =====================================>
|
|
@@ -50,6 +54,8 @@ export const blueprintCommand = new Command("blueprint")
|
|
|
50
54
|
process.exit(0);
|
|
51
55
|
});
|
|
52
56
|
|
|
57
|
+
|
|
58
|
+
|
|
53
59
|
// =======================>
|
|
54
60
|
// ## Command: Blueprint engine
|
|
55
61
|
// =======================>
|
|
@@ -115,6 +121,8 @@ export async function runBlueprints(options?: { only?: string[] }) {
|
|
|
115
121
|
await generatePostmanAPIDocumentation(postmanSchemas);
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
|
|
125
|
+
|
|
118
126
|
// =======================>
|
|
119
127
|
// ## Command: Blueprint load json files
|
|
120
128
|
// =======================>
|
|
@@ -146,11 +154,11 @@ type BlueprintFileType = "model" | "controller";
|
|
|
146
154
|
|
|
147
155
|
const TYPE_MAP: Record<BlueprintFileType, { root: string; suffix: string }> = {
|
|
148
156
|
model: {
|
|
149
|
-
root: "
|
|
157
|
+
root: "app/models",
|
|
150
158
|
suffix: ".model",
|
|
151
159
|
},
|
|
152
160
|
controller: {
|
|
153
|
-
root: "
|
|
161
|
+
root: "app/controllers",
|
|
154
162
|
suffix: ".controller",
|
|
155
163
|
},
|
|
156
164
|
};
|
|
@@ -3,6 +3,8 @@ import fs from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { lightSeederStub } from "../../stubs";
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
|
|
6
8
|
// =================================>
|
|
7
9
|
// ## Command: Blueprint seeder generation
|
|
8
10
|
// =================================>
|
|
@@ -14,7 +16,7 @@ export async function seederGeneration(
|
|
|
14
16
|
): Promise<boolean> {
|
|
15
17
|
const modelName = conversion.strPascal(model?.split("/")?.pop() || "");
|
|
16
18
|
const name = modelName + "Seeder";
|
|
17
|
-
const basePath = path.join(process.cwd(), "
|
|
19
|
+
const basePath = path.join(process.cwd(), "database", "seeders");
|
|
18
20
|
const filename = conversion.strSlug(modelName);
|
|
19
21
|
const filePath = path.join(basePath, `${filename}.seeder.ts`);
|
|
20
22
|
|
|
@@ -2,16 +2,17 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { logger } from "@utils";
|
|
5
|
-
// @ts-ignore
|
|
6
5
|
import * as utils from "@utils";
|
|
7
6
|
|
|
8
7
|
const da = (utils as any).da;
|
|
9
8
|
const daClient = (utils as any).daClient;
|
|
10
9
|
|
|
11
|
-
const DW_MIGRATIONS_DIR = path.resolve("./
|
|
10
|
+
const DW_MIGRATIONS_DIR = path.resolve("./analytic/migrations");
|
|
12
11
|
|
|
13
12
|
const MIGRATION_TABLE = `${process.env.DA_DATABASE || "default"}.migrations`;
|
|
14
13
|
|
|
14
|
+
|
|
15
|
+
|
|
15
16
|
// ================================
|
|
16
17
|
// ## Create Migration Table
|
|
17
18
|
// ================================
|
|
@@ -117,7 +117,7 @@ async function runMigrationFile() {
|
|
|
117
117
|
|
|
118
118
|
const migrationsDir = fs.existsSync(path.resolve("./database/migrations"))
|
|
119
119
|
? path.resolve("./database/migrations")
|
|
120
|
-
: path.resolve("./
|
|
120
|
+
: path.resolve("./database/migrations");
|
|
121
121
|
if (!fs.existsSync(migrationsDir)) {
|
|
122
122
|
logger.info("No migrations directory found.");
|
|
123
123
|
return;
|
|
@@ -21,7 +21,7 @@ export const seederCommand = new Command("seeder")
|
|
|
21
21
|
export const runSeeder = async () => {
|
|
22
22
|
const seedersDir = fs.existsSync(path.join(process.cwd(), "database", "seeders"))
|
|
23
23
|
? path.join(process.cwd(), "database", "seeders")
|
|
24
|
-
: path.join(process.cwd(), "
|
|
24
|
+
: path.join(process.cwd(), "database", "seeders");
|
|
25
25
|
if (!fs.existsSync(seedersDir)) {
|
|
26
26
|
logger.info("No seeders directory found.");
|
|
27
27
|
return;
|
package/src/context/context.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
|
-
|
|
3
|
-
export type AppContext = {
|
|
4
|
-
user_id?:
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const storage = new AsyncLocalStorage<AppContext>()
|
|
8
|
-
|
|
9
|
-
export const context = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
|
+
|
|
3
|
+
export type AppContext = {
|
|
4
|
+
user_id ?: number,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const storage = new AsyncLocalStorage<AppContext>()
|
|
8
|
+
|
|
9
|
+
export const context = {
|
|
10
|
+
// =====================================>
|
|
11
|
+
// ## Context: run a function within context
|
|
12
|
+
// =====================================>
|
|
13
|
+
run<T>(ctx: AppContext, fn: () => T) {
|
|
14
|
+
return storage.run(ctx, fn)
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
// =====================================>
|
|
18
|
+
// ## Context: retrieve context property value
|
|
19
|
+
// =====================================>
|
|
20
|
+
get<K extends keyof AppContext>(key: K): AppContext[K] {
|
|
21
|
+
return storage.getStore()?.[key]
|
|
22
|
+
},
|
|
23
|
+
}
|