@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.
Files changed (272) hide show
  1. package/CONTRIBUTING.md +45 -0
  2. package/LICENSE +21 -0
  3. package/README.md +60 -0
  4. package/dist/auth/auth.d.ts +18 -15
  5. package/dist/auth/auth.js +20 -203
  6. package/dist/auth/auth.js.map +1 -1
  7. package/dist/auth/create-access-token.d.ts +4 -0
  8. package/dist/auth/create-access-token.js +26 -0
  9. package/dist/auth/create-access-token.js.map +1 -0
  10. package/dist/auth/create-user-mail-token.d.ts +4 -0
  11. package/dist/auth/create-user-mail-token.js +19 -0
  12. package/dist/auth/create-user-mail-token.js.map +1 -0
  13. package/dist/auth/helpers/generate-agent-id.d.ts +1 -0
  14. package/dist/auth/helpers/generate-agent-id.js +7 -0
  15. package/dist/auth/helpers/generate-agent-id.js.map +1 -0
  16. package/dist/auth/helpers/get-request-ip.d.ts +1 -0
  17. package/dist/auth/helpers/get-request-ip.js +4 -0
  18. package/dist/auth/helpers/get-request-ip.js.map +1 -0
  19. package/dist/auth/helpers/get-user-permissions.d.ts +1 -0
  20. package/dist/auth/helpers/get-user-permissions.js +9 -0
  21. package/dist/auth/helpers/get-user-permissions.js.map +1 -0
  22. package/dist/auth/helpers/index.d.ts +3 -0
  23. package/dist/auth/helpers/index.js +4 -0
  24. package/dist/auth/helpers/index.js.map +1 -0
  25. package/dist/auth/list-user-sessions.d.ts +1 -0
  26. package/dist/auth/list-user-sessions.js +10 -0
  27. package/dist/auth/list-user-sessions.js.map +1 -0
  28. package/dist/auth/revalidate-user-permissions-by-role.d.ts +1 -0
  29. package/dist/auth/revalidate-user-permissions-by-role.js +12 -0
  30. package/dist/auth/revalidate-user-permissions-by-role.js.map +1 -0
  31. package/dist/auth/revalidate-user-permissions.d.ts +1 -0
  32. package/dist/auth/revalidate-user-permissions.js +21 -0
  33. package/dist/auth/revalidate-user-permissions.js.map +1 -0
  34. package/dist/auth/revoke-access-token.d.ts +1 -0
  35. package/dist/auth/revoke-access-token.js +5 -0
  36. package/dist/auth/revoke-access-token.js.map +1 -0
  37. package/dist/auth/verify-access-token.d.ts +1 -0
  38. package/dist/auth/verify-access-token.js +47 -0
  39. package/dist/auth/verify-access-token.js.map +1 -0
  40. package/dist/auth/verify-user-mail-token.d.ts +1 -0
  41. package/dist/auth/verify-user-mail-token.js +21 -0
  42. package/dist/auth/verify-user-mail-token.js.map +1 -0
  43. package/dist/commands/cli.js +5 -3
  44. package/dist/commands/cli.js.map +1 -1
  45. package/dist/commands/make/basic-controller.js +1 -1
  46. package/dist/commands/make/basic-controller.js.map +1 -1
  47. package/dist/commands/make/basic-migration.d.ts +1 -1
  48. package/dist/commands/make/basic-migration.js +2 -2
  49. package/dist/commands/make/basic-migration.js.map +1 -1
  50. package/dist/commands/make/basic-model.js +1 -1
  51. package/dist/commands/make/basic-model.js.map +1 -1
  52. package/dist/commands/make/basic-seeder.js +1 -1
  53. package/dist/commands/make/basic-seeder.js.map +1 -1
  54. package/dist/commands/make/blueprint.js +1 -1
  55. package/dist/commands/make/blueprint.js.map +1 -1
  56. package/dist/commands/make/da-migration.js +3 -3
  57. package/dist/commands/make/da-migration.js.map +1 -1
  58. package/dist/commands/make/mail.js +2 -2
  59. package/dist/commands/make/mail.js.map +1 -1
  60. package/dist/commands/make/notification.js +1 -1
  61. package/dist/commands/make/notification.js.map +1 -1
  62. package/dist/commands/make/queue.js +1 -1
  63. package/dist/commands/make/queue.js.map +1 -1
  64. package/dist/commands/make/resource.d.ts +2 -0
  65. package/dist/commands/make/resource.js +19 -0
  66. package/dist/commands/make/resource.js.map +1 -0
  67. package/dist/commands/make/{light-controller.js → skalfa-controller.js} +3 -3
  68. package/dist/commands/make/skalfa-controller.js.map +1 -0
  69. package/dist/commands/make/{light-model.js → skalfa-model.js} +4 -4
  70. package/dist/commands/make/skalfa-model.js.map +1 -0
  71. package/dist/commands/runner/barrels.js.map +1 -1
  72. package/dist/commands/runner/blueprint/controller-generation.js.map +1 -1
  73. package/dist/commands/runner/blueprint/documentation-generation.js.map +1 -1
  74. package/dist/commands/runner/blueprint/migration-generation.js +1 -1
  75. package/dist/commands/runner/blueprint/migration-generation.js.map +1 -1
  76. package/dist/commands/runner/blueprint/model-generation.js.map +1 -1
  77. package/dist/commands/runner/blueprint/runner.js +2 -2
  78. package/dist/commands/runner/blueprint/runner.js.map +1 -1
  79. package/dist/commands/runner/blueprint/seeder-generation.js +1 -1
  80. package/dist/commands/runner/blueprint/seeder-generation.js.map +1 -1
  81. package/dist/commands/runner/da-migration.js +1 -2
  82. package/dist/commands/runner/da-migration.js.map +1 -1
  83. package/dist/commands/runner/migration.js +1 -1
  84. package/dist/commands/runner/migration.js.map +1 -1
  85. package/dist/commands/runner/seeder.js +1 -1
  86. package/dist/commands/runner/seeder.js.map +1 -1
  87. package/dist/context/context.js +6 -0
  88. package/dist/context/context.js.map +1 -1
  89. package/dist/controller/controller.d.ts +17 -30
  90. package/dist/controller/controller.js +39 -121
  91. package/dist/controller/controller.js.map +1 -1
  92. package/dist/controller/response.d.ts +6 -0
  93. package/dist/controller/response.js +63 -0
  94. package/dist/controller/response.js.map +1 -0
  95. package/dist/controller/storage.d.ts +9 -0
  96. package/dist/controller/storage.js +56 -0
  97. package/dist/controller/storage.js.map +1 -0
  98. package/dist/conversion/conversion.d.ts +3 -0
  99. package/dist/conversion/conversion.js +28 -4
  100. package/dist/conversion/conversion.js.map +1 -1
  101. package/dist/conversion/date.d.ts +1 -0
  102. package/dist/conversion/date.js +77 -0
  103. package/dist/conversion/date.js.map +1 -0
  104. package/dist/index.d.ts +2 -0
  105. package/dist/index.js +2 -0
  106. package/dist/index.js.map +1 -1
  107. package/dist/logger/logger.js +33 -0
  108. package/dist/logger/logger.js.map +1 -1
  109. package/dist/mail/mail.js +6 -6
  110. package/dist/mail/mail.js.map +1 -1
  111. package/dist/middleware/access-log.d.ts +31 -0
  112. package/dist/middleware/access-log.js +13 -0
  113. package/dist/middleware/access-log.js.map +1 -0
  114. package/dist/middleware/auth.d.ts +37 -0
  115. package/dist/middleware/auth.js +16 -0
  116. package/dist/middleware/auth.js.map +1 -0
  117. package/dist/middleware/body-parse.d.ts +35 -0
  118. package/dist/middleware/body-parse.js +87 -0
  119. package/dist/middleware/body-parse.js.map +1 -0
  120. package/dist/middleware/context.d.ts +29 -0
  121. package/dist/middleware/context.js +8 -0
  122. package/dist/middleware/context.js.map +1 -0
  123. package/dist/middleware/cors.d.ts +31 -0
  124. package/dist/middleware/cors.js +27 -0
  125. package/dist/middleware/cors.js.map +1 -0
  126. package/dist/middleware/error-handler.d.ts +33 -0
  127. package/dist/middleware/error-handler.js +17 -0
  128. package/dist/middleware/error-handler.js.map +1 -0
  129. package/dist/middleware/middleware.d.ts +31 -10
  130. package/dist/middleware/middleware.js +41 -209
  131. package/dist/middleware/middleware.js.map +1 -1
  132. package/dist/middleware/private.d.ts +29 -0
  133. package/dist/middleware/private.js +8 -0
  134. package/dist/middleware/private.js.map +1 -0
  135. package/dist/middleware/rate-limiter.d.ts +32 -0
  136. package/dist/middleware/rate-limiter.js +30 -0
  137. package/dist/middleware/rate-limiter.js.map +1 -0
  138. package/dist/notification/index.d.ts +1 -0
  139. package/dist/notification/index.js +2 -0
  140. package/dist/notification/index.js.map +1 -0
  141. package/dist/notification/notification.d.ts +16 -0
  142. package/dist/notification/notification.js +64 -0
  143. package/dist/notification/notification.js.map +1 -0
  144. package/dist/permission/permission.js +9 -0
  145. package/dist/permission/permission.js.map +1 -1
  146. package/dist/registry/registry.d.ts +0 -6
  147. package/dist/registry/registry.js +6 -6
  148. package/dist/registry/registry.js.map +1 -1
  149. package/dist/storage/storage.d.ts +3 -3
  150. package/dist/storage/storage.js.map +1 -1
  151. package/dist/validation/validation.js +43 -51
  152. package/dist/validation/validation.js.map +1 -1
  153. package/package.json +4 -4
  154. package/src/auth/auth.ts +21 -252
  155. package/src/auth/create-access-token.ts +29 -0
  156. package/src/auth/create-user-mail-token.ts +24 -0
  157. package/src/auth/helpers/generate-agent-id.ts +8 -0
  158. package/src/auth/helpers/get-request-ip.ts +3 -0
  159. package/src/auth/helpers/get-user-permissions.ts +15 -0
  160. package/src/auth/helpers/index.ts +3 -0
  161. package/src/auth/list-user-sessions.ts +11 -0
  162. package/src/auth/revalidate-user-permissions-by-role.ts +13 -0
  163. package/src/auth/revalidate-user-permissions.ts +26 -0
  164. package/src/auth/revoke-access-token.ts +5 -0
  165. package/src/auth/verify-access-token.ts +56 -0
  166. package/src/auth/verify-user-mail-token.ts +24 -0
  167. package/src/commands/cli.ts +5 -3
  168. package/src/commands/make/basic-controller.ts +3 -1
  169. package/src/commands/make/basic-migration.ts +5 -3
  170. package/src/commands/make/basic-model.ts +3 -1
  171. package/src/commands/make/basic-seeder.ts +3 -1
  172. package/src/commands/make/blueprint.ts +3 -1
  173. package/src/commands/make/da-migration.ts +6 -5
  174. package/src/commands/make/mail.ts +4 -2
  175. package/src/commands/make/notification.ts +3 -1
  176. package/src/commands/make/queue.ts +3 -1
  177. package/src/commands/make/resource.ts +21 -0
  178. package/src/commands/make/{light-controller.ts → skalfa-controller.ts} +4 -2
  179. package/src/commands/make/{light-model.ts → skalfa-model.ts} +5 -3
  180. package/src/commands/runner/barrels.ts +4 -0
  181. package/src/commands/runner/blueprint/controller-generation.ts +2 -0
  182. package/src/commands/runner/blueprint/documentation-generation.ts +2 -0
  183. package/src/commands/runner/blueprint/migration-generation.ts +3 -1
  184. package/src/commands/runner/blueprint/model-generation.ts +2 -0
  185. package/src/commands/runner/blueprint/runner.ts +10 -2
  186. package/src/commands/runner/blueprint/seeder-generation.ts +3 -1
  187. package/src/commands/runner/da-migration.ts +3 -2
  188. package/src/commands/runner/migration.ts +1 -1
  189. package/src/commands/runner/seeder.ts +1 -1
  190. package/src/context/context.ts +23 -17
  191. package/src/controller/controller.ts +124 -239
  192. package/src/controller/response.ts +78 -0
  193. package/src/controller/storage.ts +78 -0
  194. package/src/conversion/conversion.ts +90 -64
  195. package/src/conversion/date.ts +74 -0
  196. package/src/index.ts +2 -0
  197. package/src/logger/logger.ts +217 -176
  198. package/src/mail/mail.ts +85 -85
  199. package/src/middleware/access-log.ts +15 -0
  200. package/src/middleware/auth.ts +19 -0
  201. package/src/middleware/body-parse.ts +83 -0
  202. package/src/middleware/context.ts +11 -0
  203. package/src/middleware/cors.ts +31 -0
  204. package/src/middleware/error-handler.ts +20 -0
  205. package/src/middleware/middleware.ts +91 -288
  206. package/src/middleware/private.ts +8 -0
  207. package/src/middleware/rate-limiter.ts +41 -0
  208. package/src/notification/index.ts +1 -0
  209. package/src/notification/notification.ts +86 -0
  210. package/src/permission/permission.ts +140 -136
  211. package/src/registry/registry.ts +17 -15
  212. package/src/route/route.ts +11 -11
  213. package/src/storage/storage.ts +104 -106
  214. package/src/validation/validation.ts +322 -346
  215. package/dist/auth.util.d.ts +0 -19
  216. package/dist/auth.util.js +0 -183
  217. package/dist/auth.util.js.map +0 -1
  218. package/dist/commands/make/light-controller.js.map +0 -1
  219. package/dist/commands/make/light-model.js.map +0 -1
  220. package/dist/context.util.d.ts +0 -7
  221. package/dist/context.util.js +0 -11
  222. package/dist/context.util.js.map +0 -1
  223. package/dist/controller.util.d.ts +0 -118
  224. package/dist/controller.util.js +0 -144
  225. package/dist/controller.util.js.map +0 -1
  226. package/dist/conversion.util.d.ts +0 -8
  227. package/dist/conversion.util.js +0 -52
  228. package/dist/conversion.util.js.map +0 -1
  229. package/dist/db/db.d.ts +0 -84
  230. package/dist/db/db.js +0 -177
  231. package/dist/db/db.js.map +0 -1
  232. package/dist/db/index.d.ts +0 -1
  233. package/dist/db/index.js +0 -2
  234. package/dist/db/index.js.map +0 -1
  235. package/dist/db.util.d.ts +0 -84
  236. package/dist/db.util.js +0 -177
  237. package/dist/db.util.js.map +0 -1
  238. package/dist/logger.util.d.ts +0 -30
  239. package/dist/logger.util.js +0 -126
  240. package/dist/logger.util.js.map +0 -1
  241. package/dist/mail.util.d.ts +0 -21
  242. package/dist/mail.util.js +0 -53
  243. package/dist/mail.util.js.map +0 -1
  244. package/dist/middleware.util.d.ts +0 -263
  245. package/dist/middleware.util.js +0 -233
  246. package/dist/middleware.util.js.map +0 -1
  247. package/dist/model/index.d.ts +0 -3
  248. package/dist/model/index.js +0 -4
  249. package/dist/model/index.js.map +0 -1
  250. package/dist/model/model.d.ts +0 -204
  251. package/dist/model/model.js +0 -1495
  252. package/dist/model/model.js.map +0 -1
  253. package/dist/model.util.d.ts +0 -204
  254. package/dist/model.util.js +0 -1495
  255. package/dist/model.util.js.map +0 -1
  256. package/dist/permission.util.d.ts +0 -38
  257. package/dist/permission.util.js +0 -91
  258. package/dist/permission.util.js.map +0 -1
  259. package/dist/registry.util.d.ts +0 -28
  260. package/dist/registry.util.js +0 -19
  261. package/dist/registry.util.js.map +0 -1
  262. package/dist/route.util.d.ts +0 -1
  263. package/dist/route.util.js +0 -12
  264. package/dist/route.util.js.map +0 -1
  265. package/dist/storage.util.d.ts +0 -56
  266. package/dist/storage.util.js +0 -82
  267. package/dist/storage.util.js.map +0 -1
  268. package/dist/validation.util.d.ts +0 -7
  269. package/dist/validation.util.js +0 -237
  270. package/dist/validation.util.js.map +0 -1
  271. /package/dist/commands/make/{light-controller.d.ts → skalfa-controller.d.ts} +0 -0
  272. /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(), "src", "models", filename);
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(), "src", "database", "seeders");
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(), "src", "blueprints");
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:migration")
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
- "src",
28
- "database",
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
- `DA Migration created: ${path.relative(baseDir, filePath)}`
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(), "src", "outputs", "mails");
15
- const templatePath = path.join(process.cwd(), "src", "outputs", "mails", "templates");
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(), "src", "outputs", "notifications");
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(), "src", "jobs", "queues");
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:light-controller")
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(), "src", "controllers");
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 "./light-controller";
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:light-model")
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(), "src", "models");
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(), "src", "database", "migrations", "0000_00");
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`;
@@ -4,6 +4,8 @@ import { conversion } from "@utils";
4
4
  import { resolveBlueprintPath } from "./runner";
5
5
  import { lightModelStub } from "../../stubs";
6
6
 
7
+
8
+
7
9
  // ============================>
8
10
  // ## Command: blueprint model generation
9
11
  // ============================>
@@ -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: "src/models",
157
+ root: "app/models",
150
158
  suffix: ".model",
151
159
  },
152
160
  controller: {
153
- root: "src/controllers",
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(), "src", "database", "seeders");
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("./src/database/da.migrations");
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("./src/database/migrations");
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(), "src", "database", "seeders");
24
+ : path.join(process.cwd(), "database", "seeders");
25
25
  if (!fs.existsSync(seedersDir)) {
26
26
  logger.info("No seeders directory found.");
27
27
  return;
@@ -1,17 +1,23 @@
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
- run<T>(ctx: AppContext, fn: () => T) {
11
- return storage.run(ctx, fn)
12
- },
13
-
14
- get<K extends keyof AppContext>(key: K): AppContext[K] {
15
- return storage.getStore()?.[key]
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
+ }