mahameru 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/README.md +28 -0
  2. package/dist/api.error.cjs +107 -0
  3. package/dist/api.error.cjs.map +1 -0
  4. package/dist/api.error.d.cts +65 -0
  5. package/dist/api.error.d.ts +65 -0
  6. package/dist/api.error.js +83 -0
  7. package/dist/api.error.js.map +1 -0
  8. package/dist/base-class/base.controller.cjs +148 -0
  9. package/dist/base-class/base.controller.cjs.map +1 -0
  10. package/dist/base-class/base.controller.d.cts +38 -0
  11. package/dist/base-class/base.controller.d.ts +38 -0
  12. package/dist/base-class/base.controller.js +126 -0
  13. package/dist/base-class/base.controller.js.map +1 -0
  14. package/dist/base-class/base.entity.cjs +79 -0
  15. package/dist/base-class/base.entity.cjs.map +1 -0
  16. package/dist/base-class/base.entity.d.cts +8 -0
  17. package/dist/base-class/base.entity.d.ts +8 -0
  18. package/dist/base-class/base.entity.js +57 -0
  19. package/dist/base-class/base.entity.js.map +1 -0
  20. package/dist/base-class/base.model.cjs +204 -0
  21. package/dist/base-class/base.model.cjs.map +1 -0
  22. package/dist/base-class/base.model.d.cts +68 -0
  23. package/dist/base-class/base.model.d.ts +68 -0
  24. package/dist/base-class/base.model.js +182 -0
  25. package/dist/base-class/base.model.js.map +1 -0
  26. package/dist/base-class/base.service.cjs +37 -0
  27. package/dist/base-class/base.service.cjs.map +1 -0
  28. package/dist/base-class/base.service.d.cts +5 -0
  29. package/dist/base-class/base.service.d.ts +5 -0
  30. package/dist/base-class/base.service.js +15 -0
  31. package/dist/base-class/base.service.js.map +1 -0
  32. package/dist/base-class/index.cjs +392 -0
  33. package/dist/base-class/index.cjs.map +1 -0
  34. package/dist/base-class/index.d.cts +6 -0
  35. package/dist/base-class/index.d.ts +6 -0
  36. package/dist/base-class/index.js +365 -0
  37. package/dist/base-class/index.js.map +1 -0
  38. package/dist/cli/index.cjs +706 -0
  39. package/dist/cli/index.cjs.map +1 -0
  40. package/dist/cli/index.d.cts +3 -0
  41. package/dist/cli/index.d.ts +3 -0
  42. package/dist/cli/index.js +681 -0
  43. package/dist/cli/index.js.map +1 -0
  44. package/dist/cli/scripts/on-build.cjs +56 -0
  45. package/dist/cli/scripts/on-build.cjs.map +1 -0
  46. package/dist/cli/scripts/on-build.d.cts +3 -0
  47. package/dist/cli/scripts/on-build.d.ts +3 -0
  48. package/dist/cli/scripts/on-build.js +28 -0
  49. package/dist/cli/scripts/on-build.js.map +1 -0
  50. package/dist/cli/scripts/on-dev.cjs +483 -0
  51. package/dist/cli/scripts/on-dev.cjs.map +1 -0
  52. package/dist/cli/scripts/on-dev.d.cts +5 -0
  53. package/dist/cli/scripts/on-dev.d.ts +5 -0
  54. package/dist/cli/scripts/on-dev.js +449 -0
  55. package/dist/cli/scripts/on-dev.js.map +1 -0
  56. package/dist/cli/scripts/on-init.cjs +96 -0
  57. package/dist/cli/scripts/on-init.cjs.map +1 -0
  58. package/dist/cli/scripts/on-init.d.cts +3 -0
  59. package/dist/cli/scripts/on-init.d.ts +3 -0
  60. package/dist/cli/scripts/on-init.js +68 -0
  61. package/dist/cli/scripts/on-init.js.map +1 -0
  62. package/dist/cli/scripts/on-start.cjs +55 -0
  63. package/dist/cli/scripts/on-start.cjs.map +1 -0
  64. package/dist/cli/scripts/on-start.d.cts +3 -0
  65. package/dist/cli/scripts/on-start.d.ts +3 -0
  66. package/dist/cli/scripts/on-start.js +27 -0
  67. package/dist/cli/scripts/on-start.js.map +1 -0
  68. package/dist/client.cjs +405 -0
  69. package/dist/client.cjs.map +1 -0
  70. package/dist/client.d.cts +7 -0
  71. package/dist/client.d.ts +7 -0
  72. package/dist/client.js +371 -0
  73. package/dist/client.js.map +1 -0
  74. package/dist/constants.cjs +51 -0
  75. package/dist/constants.cjs.map +1 -0
  76. package/dist/constants.d.cts +7 -0
  77. package/dist/constants.d.ts +7 -0
  78. package/dist/constants.js +16 -0
  79. package/dist/constants.js.map +1 -0
  80. package/dist/database/column/index.cjs +34 -0
  81. package/dist/database/column/index.cjs.map +1 -0
  82. package/dist/database/column/index.d.cts +2 -0
  83. package/dist/database/column/index.d.ts +2 -0
  84. package/dist/database/column/index.js +8 -0
  85. package/dist/database/column/index.js.map +1 -0
  86. package/dist/database/index.cjs +83 -0
  87. package/dist/database/index.cjs.map +1 -0
  88. package/dist/database/index.d.cts +2 -0
  89. package/dist/database/index.d.ts +2 -0
  90. package/dist/database/index.js +60 -0
  91. package/dist/database/index.js.map +1 -0
  92. package/dist/database/snake-naming-strategy.class.cjs +78 -0
  93. package/dist/database/snake-naming-strategy.class.cjs.map +1 -0
  94. package/dist/database/snake-naming-strategy.class.d.cts +16 -0
  95. package/dist/database/snake-naming-strategy.class.d.ts +16 -0
  96. package/dist/database/snake-naming-strategy.class.js +56 -0
  97. package/dist/database/snake-naming-strategy.class.js.map +1 -0
  98. package/dist/error.cjs +46 -0
  99. package/dist/error.cjs.map +1 -0
  100. package/dist/error.d.cts +10 -0
  101. package/dist/error.d.ts +10 -0
  102. package/dist/error.js +28 -0
  103. package/dist/error.js.map +1 -0
  104. package/dist/express/app.cjs +233 -0
  105. package/dist/express/app.cjs.map +1 -0
  106. package/dist/express/app.d.cts +16 -0
  107. package/dist/express/app.d.ts +16 -0
  108. package/dist/express/app.js +205 -0
  109. package/dist/express/app.js.map +1 -0
  110. package/dist/express/index.cjs +239 -0
  111. package/dist/express/index.cjs.map +1 -0
  112. package/dist/express/index.d.cts +3 -0
  113. package/dist/express/index.d.ts +3 -0
  114. package/dist/express/index.js +205 -0
  115. package/dist/express/index.js.map +1 -0
  116. package/dist/express/middleware/cors.middleware.cjs +54 -0
  117. package/dist/express/middleware/cors.middleware.cjs.map +1 -0
  118. package/dist/express/middleware/cors.middleware.d.cts +9 -0
  119. package/dist/express/middleware/cors.middleware.d.ts +9 -0
  120. package/dist/express/middleware/cors.middleware.js +26 -0
  121. package/dist/express/middleware/cors.middleware.js.map +1 -0
  122. package/dist/express/middleware/error.middleware.cjs +136 -0
  123. package/dist/express/middleware/error.middleware.cjs.map +1 -0
  124. package/dist/express/middleware/error.middleware.d.cts +5 -0
  125. package/dist/express/middleware/error.middleware.d.ts +5 -0
  126. package/dist/express/middleware/error.middleware.js +116 -0
  127. package/dist/express/middleware/error.middleware.js.map +1 -0
  128. package/dist/express/middleware/filter.middleware.cjs +38 -0
  129. package/dist/express/middleware/filter.middleware.cjs.map +1 -0
  130. package/dist/express/middleware/filter.middleware.d.cts +5 -0
  131. package/dist/express/middleware/filter.middleware.d.ts +5 -0
  132. package/dist/express/middleware/filter.middleware.js +20 -0
  133. package/dist/express/middleware/filter.middleware.js.map +1 -0
  134. package/dist/express/middleware/index.cjs +206 -0
  135. package/dist/express/middleware/index.cjs.map +1 -0
  136. package/dist/express/middleware/index.d.cts +19 -0
  137. package/dist/express/middleware/index.d.ts +19 -0
  138. package/dist/express/middleware/index.js +169 -0
  139. package/dist/express/middleware/index.js.map +1 -0
  140. package/dist/express/middleware/not-found.middleware.cjs +79 -0
  141. package/dist/express/middleware/not-found.middleware.cjs.map +1 -0
  142. package/dist/express/middleware/not-found.middleware.d.cts +5 -0
  143. package/dist/express/middleware/not-found.middleware.d.ts +5 -0
  144. package/dist/express/middleware/not-found.middleware.js +59 -0
  145. package/dist/express/middleware/not-found.middleware.js.map +1 -0
  146. package/dist/generator.cjs +258 -0
  147. package/dist/generator.cjs.map +1 -0
  148. package/dist/generator.d.cts +10 -0
  149. package/dist/generator.d.ts +10 -0
  150. package/dist/generator.js +220 -0
  151. package/dist/generator.js.map +1 -0
  152. package/dist/http.cjs +82 -0
  153. package/dist/http.cjs.map +1 -0
  154. package/dist/http.d.cts +11 -0
  155. package/dist/http.d.ts +11 -0
  156. package/dist/http.js +64 -0
  157. package/dist/http.js.map +1 -0
  158. package/dist/index.cjs +831 -0
  159. package/dist/index.cjs.map +1 -0
  160. package/dist/index.d.cts +19 -0
  161. package/dist/index.d.ts +19 -0
  162. package/dist/index.js +783 -0
  163. package/dist/index.js.map +1 -0
  164. package/dist/lib/create-env-file.cjs +69 -0
  165. package/dist/lib/create-env-file.cjs.map +1 -0
  166. package/dist/lib/create-env-file.d.cts +3 -0
  167. package/dist/lib/create-env-file.d.ts +3 -0
  168. package/dist/lib/create-env-file.js +31 -0
  169. package/dist/lib/create-env-file.js.map +1 -0
  170. package/dist/lib/helper.cjs +94 -0
  171. package/dist/lib/helper.cjs.map +1 -0
  172. package/dist/lib/helper.d.cts +13 -0
  173. package/dist/lib/helper.d.ts +13 -0
  174. package/dist/lib/helper.js +62 -0
  175. package/dist/lib/helper.js.map +1 -0
  176. package/dist/lib/model.generator.cjs +212 -0
  177. package/dist/lib/model.generator.cjs.map +1 -0
  178. package/dist/lib/model.generator.d.cts +29 -0
  179. package/dist/lib/model.generator.d.ts +29 -0
  180. package/dist/lib/model.generator.js +174 -0
  181. package/dist/lib/model.generator.js.map +1 -0
  182. package/dist/lib/pre-init-dev-script.cjs +336 -0
  183. package/dist/lib/pre-init-dev-script.cjs.map +1 -0
  184. package/dist/lib/pre-init-dev-script.d.cts +2 -0
  185. package/dist/lib/pre-init-dev-script.d.ts +2 -0
  186. package/dist/lib/pre-init-dev-script.js +311 -0
  187. package/dist/lib/pre-init-dev-script.js.map +1 -0
  188. package/dist/mahameru.cjs +397 -0
  189. package/dist/mahameru.cjs.map +1 -0
  190. package/dist/mahameru.d.cts +78 -0
  191. package/dist/mahameru.d.ts +78 -0
  192. package/dist/mahameru.js +359 -0
  193. package/dist/mahameru.js.map +1 -0
  194. package/dist/request.cjs +35 -0
  195. package/dist/request.cjs.map +1 -0
  196. package/dist/request.d.cts +4 -0
  197. package/dist/request.d.ts +4 -0
  198. package/dist/request.js +13 -0
  199. package/dist/request.js.map +1 -0
  200. package/dist/response.cjs +35 -0
  201. package/dist/response.cjs.map +1 -0
  202. package/dist/response.d.cts +4 -0
  203. package/dist/response.d.ts +4 -0
  204. package/dist/response.js +13 -0
  205. package/dist/response.js.map +1 -0
  206. package/dist/types.cjs +1 -0
  207. package/dist/types.cjs.map +1 -0
  208. package/dist/types.d.cts +2 -0
  209. package/dist/types.d.ts +2 -0
  210. package/dist/types.js +1 -0
  211. package/dist/types.js.map +1 -0
  212. package/dist/utils/import-dynamic-module.cjs +34 -0
  213. package/dist/utils/import-dynamic-module.cjs.map +1 -0
  214. package/dist/utils/import-dynamic-module.d.cts +3 -0
  215. package/dist/utils/import-dynamic-module.d.ts +3 -0
  216. package/dist/utils/import-dynamic-module.js +12 -0
  217. package/dist/utils/import-dynamic-module.js.map +1 -0
  218. package/package.json +70 -0
@@ -0,0 +1,681 @@
1
+ #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __export = (target, all) => {
5
+ for (var name2 in all)
6
+ __defProp(target, name2, { get: all[name2], enumerable: true });
7
+ };
8
+
9
+ // src/cli/index.ts
10
+ import { Command } from "commander";
11
+
12
+ // package.json
13
+ var package_exports = {};
14
+ __export(package_exports, {
15
+ author: () => author,
16
+ bin: () => bin,
17
+ default: () => package_default,
18
+ dependencies: () => dependencies,
19
+ description: () => description,
20
+ devDependencies: () => devDependencies,
21
+ exports: () => exports,
22
+ files: () => files,
23
+ keywords: () => keywords,
24
+ license: () => license,
25
+ main: () => main,
26
+ module: () => module2,
27
+ name: () => name,
28
+ peerDependencies: () => peerDependencies,
29
+ scripts: () => scripts,
30
+ type: () => type,
31
+ types: () => types,
32
+ version: () => version
33
+ });
34
+ var name = "mahameru";
35
+ var version = "0.1.0";
36
+ var description = "";
37
+ var main = "./dist/index.cjs";
38
+ var module2 = "./dist/index.js";
39
+ var types = "./dist/index.d.ts";
40
+ var bin = "./dist/cli/index.js";
41
+ var scripts = {
42
+ dev: "set NODE_ENV=development && tsx watch --tsconfig tsconfig.json --conditions=development src/index.ts",
43
+ build: "tsup --config tsup.config.ts && npm pack",
44
+ start: "node dist/index.js",
45
+ typecheck: "tsc --noEmit --project tsconfig.json"
46
+ };
47
+ var exports = {
48
+ ".": {
49
+ types: "./dist/index.d.ts",
50
+ import: "./dist/index.js",
51
+ require: "./dist/index.cjs"
52
+ },
53
+ "./database": {
54
+ types: "./dist/database/index.d.ts",
55
+ import: "./dist/database/index.js",
56
+ require: "./dist/database/index.cjs"
57
+ },
58
+ "./database/column": {
59
+ types: "./dist/database/column/index.d.ts",
60
+ import: "./dist/database/column/index.js",
61
+ require: "./dist/database/column/index.cjs"
62
+ }
63
+ };
64
+ var files = [
65
+ "dist"
66
+ ];
67
+ var keywords = [];
68
+ var author = "Bintan <hello@bintvn.co>";
69
+ var license = "ISC";
70
+ var type = "module";
71
+ var peerDependencies = {
72
+ "@types/node": "^26.0.0",
73
+ "tsc-alias": "^1.8.17",
74
+ tsx: "^4.22.4",
75
+ typeorm: "^1.0.0",
76
+ typescript: "^6.0.3"
77
+ };
78
+ var dependencies = {
79
+ commander: "^15.0.0",
80
+ "cookie-parser": "^1.4.7",
81
+ cors: "^2.8.6",
82
+ degit: "^3.4.7",
83
+ express: "^5.2.1",
84
+ helmet: "^8.2.0",
85
+ inquirer: "^14.0.2",
86
+ "lite-env": "^1.1.0",
87
+ ora: "^9.4.0",
88
+ picocolors: "^1.1.1",
89
+ "typeorm-dto-generator": "^1.0.6"
90
+ };
91
+ var devDependencies = {
92
+ "@swc/core": "^1.15.41",
93
+ "@types/cookie-parser": "^1.4.10",
94
+ "@types/cors": "^2.8.19",
95
+ "@types/express": "^5.0.6",
96
+ "@types/helmet": "^0.0.48",
97
+ "@types/node": "^26.0.0",
98
+ "tsc-alias": "^1.8.17",
99
+ tsup: "^8.5.1",
100
+ tsx: "^4.22.4",
101
+ typeorm: "^1.0.0",
102
+ typescript: "^6.0.3"
103
+ };
104
+ var package_default = {
105
+ name,
106
+ version,
107
+ description,
108
+ main,
109
+ module: module2,
110
+ types,
111
+ bin,
112
+ scripts,
113
+ exports,
114
+ files,
115
+ keywords,
116
+ author,
117
+ license,
118
+ type,
119
+ peerDependencies,
120
+ dependencies,
121
+ devDependencies
122
+ };
123
+
124
+ // src/cli/scripts/on-init.ts
125
+ import inquirer from "inquirer";
126
+ import { existsSync } from "fs";
127
+ import path from "path";
128
+ import degit from "degit";
129
+ import ora from "ora";
130
+ import pc from "picocolors";
131
+ import { execSync } from "child_process";
132
+ async function onInit() {
133
+ const repo = "bintvn/typeorm-dto-generator";
134
+ const answers = await inquirer.prompt([
135
+ {
136
+ type: "input",
137
+ name: "projectName",
138
+ message: "Enter your project name:",
139
+ default: "my-awesome-project",
140
+ validate: /* @__PURE__ */ __name((input) => {
141
+ if (/^([A-Za-z\-_\d])+$/.test(input)) return true;
142
+ return "Project name may only contain letters, numbers, underscores, or dashes.";
143
+ }, "validate")
144
+ }
145
+ ]);
146
+ const targetDir = path.join(process.cwd(), answers.projectName);
147
+ if (existsSync(targetDir)) {
148
+ console.log(pc.red(`
149
+ Error: Folder ${answers.projectName} already exists!`));
150
+ process.exit(1);
151
+ }
152
+ const emitter = degit(repo, {
153
+ cache: false,
154
+ force: true
155
+ });
156
+ const downloadSpinner = ora("Downloading template from GitHub...").start();
157
+ try {
158
+ await emitter.clone(targetDir);
159
+ downloadSpinner.succeed(pc.green("Template downloaded successfully!"));
160
+ } catch (err) {
161
+ downloadSpinner.fail(pc.red("Failed to download template."));
162
+ console.error(err);
163
+ process.exit(1);
164
+ }
165
+ const installSpinner = ora("Installing dependencies (npm install)...").start();
166
+ try {
167
+ execSync("npm install", {
168
+ cwd: targetDir,
169
+ stdio: "ignore"
170
+ });
171
+ installSpinner.succeed(pc.green("Dependencies installed successfully!"));
172
+ } catch (err) {
173
+ installSpinner.fail(pc.red("Failed to install dependencies."));
174
+ console.log(pc.yellow('\nPlease enter the folder and run "npm install" manually.'));
175
+ }
176
+ console.log("\n---");
177
+ console.log(pc.cyan(`Project ${pc.bold(answers.projectName)} was created successfully!`));
178
+ console.log(`
179
+ To get started, run the following commands:`);
180
+ console.log(pc.yellow(` cd ${answers.projectName}`));
181
+ console.log(pc.yellow(` npm run dev (or your preferred start command)`));
182
+ console.log("---\n");
183
+ }
184
+ __name(onInit, "onInit");
185
+
186
+ // src/cli/scripts/on-build.ts
187
+ import { execSync as execSync2 } from "child_process";
188
+ import { renameSync } from "fs";
189
+ import path2 from "path";
190
+ async function onBuild() {
191
+ console.log("\x1B[32m%s\x1B[0m", "\u25B2 Mahameru - Compiling TypeScript with tsc...");
192
+ try {
193
+ const tscPath = path2.join(process.cwd(), "node_modules", "typescript", "bin", "tsc");
194
+ const tscAliasPath = path2.join(process.cwd(), "node_modules", "tsc-alias", "dist", "bin", "index.js");
195
+ execSync2(`node "${tscPath}" -p tsconfig.json && node "${tscAliasPath}" -p tsconfig.json`, {
196
+ stdio: "inherit",
197
+ cwd: process.cwd()
198
+ });
199
+ renameSync(path2.join(process.cwd(), "dist"), path2.join(process.cwd(), ".mahameru"));
200
+ console.log("\x1B[32m%s\x1B[0m", "\u2714 Build berhasil selesai.");
201
+ } catch (error) {
202
+ console.error("\x1B[31m%s\x1B[0m", "\u2716 Build gagal.");
203
+ process.exit(1);
204
+ }
205
+ }
206
+ __name(onBuild, "onBuild");
207
+
208
+ // src/cli/scripts/on-start.ts
209
+ import { spawn } from "child_process";
210
+ import path3 from "path";
211
+ async function onStart() {
212
+ console.log("\x1B[36m%s\x1B[0m", "\u25B2 Mahameru - Starting production server...");
213
+ const distPath = path3.join(process.cwd(), ".mahameru", "index.js");
214
+ const child = spawn("node", [
215
+ distPath
216
+ ], {
217
+ stdio: "inherit",
218
+ env: {
219
+ ...process.env,
220
+ NODE_ENV: "production"
221
+ }
222
+ });
223
+ child.on("close", (code) => {
224
+ process.exit(code ?? 0);
225
+ });
226
+ }
227
+ __name(onStart, "onStart");
228
+
229
+ // src/cli/scripts/on-dev.ts
230
+ import { pathToFileURL } from "url";
231
+
232
+ // src/error.ts
233
+ var MahameruError = class extends Error {
234
+ static {
235
+ __name(this, "MahameruError");
236
+ }
237
+ constructor(message) {
238
+ super(message);
239
+ this.name = "MahameruError";
240
+ this.message = message;
241
+ Error.captureStackTrace(this, this.constructor);
242
+ }
243
+ toString() {
244
+ return `${this.name}: ${this.message}`;
245
+ }
246
+ toJSON() {
247
+ return {
248
+ name: this.name,
249
+ message: this.message
250
+ };
251
+ }
252
+ };
253
+
254
+ // src/http.ts
255
+ import { createServer } from "http";
256
+ function createHttpServer(app, existingHttpServer, options = {}) {
257
+ return new Promise((resolve, reject) => {
258
+ const httpServer = createServer(app);
259
+ const PORT = options.port || 3e3;
260
+ const HOST = options.host || "localhost";
261
+ if (existingHttpServer) return resolve(existingHttpServer);
262
+ httpServer.listen(PORT, HOST, void 0, async () => {
263
+ const address = httpServer.address();
264
+ if (address && typeof address !== "string") {
265
+ console.log("HTTP Server", `Listening on http://${HOST} ${PORT} ${address.family}`);
266
+ } else {
267
+ console.log("HTTP Server", `Listening on ${address}`);
268
+ }
269
+ resolve(httpServer);
270
+ });
271
+ httpServer.on("close", () => {
272
+ console.log("HTTP Server", "Server closed");
273
+ process.exit(0);
274
+ });
275
+ httpServer.on("error", (err) => {
276
+ if (err.code === "EADDRINUSE") {
277
+ reject(new MahameruError(`Port ${PORT} is already in use`));
278
+ return;
279
+ } else {
280
+ console.error("System", err);
281
+ }
282
+ reject(err);
283
+ });
284
+ });
285
+ }
286
+ __name(createHttpServer, "createHttpServer");
287
+
288
+ // src/mahameru.ts
289
+ import { writeFile } from "fs/promises";
290
+ import path4 from "path";
291
+ import { existsSync as existsSync2 } from "fs";
292
+ import { spawn as spawn2 } from "child_process";
293
+
294
+ // src/constants.ts
295
+ import { dirname } from "path";
296
+ import { fileURLToPath } from "url";
297
+ var root = process.cwd();
298
+ var __filename2 = fileURLToPath(import.meta.url);
299
+ var __dirname2 = dirname(__filename2);
300
+ var isCommonJS = typeof module !== "undefined" && !!module.exports;
301
+
302
+ // src/express/app.ts
303
+ import express from "express";
304
+ import helmet from "helmet";
305
+
306
+ // src/express/middleware/cors.middleware.ts
307
+ import cors from "cors";
308
+ var createCorsMiddleware = /* @__PURE__ */ __name((allowedOrigins) => {
309
+ return cors((req, callback) => {
310
+ let origin = req.headers["origin"];
311
+ if (!origin || allowedOrigins.indexOf(origin) !== -1) {
312
+ callback(null, {
313
+ origin: true,
314
+ methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
315
+ credentials: true
316
+ });
317
+ } else {
318
+ callback(null, {
319
+ origin: false
320
+ });
321
+ }
322
+ });
323
+ }, "createCorsMiddleware");
324
+ var cors_middleware_default = createCorsMiddleware;
325
+
326
+ // src/express/middleware/filter.middleware.ts
327
+ async function filterMiddleware(request, response, next) {
328
+ if (!request.ip || !request.headers["user-agent"]) throw new Error("Access denied");
329
+ request.ipAddress = request.ip;
330
+ request.userAgent = request.headers["user-agent"];
331
+ if (request.path.length > 1 && request.path.endsWith("/")) {
332
+ const newPath = request.path.slice(0, -1);
333
+ const query = request.url.slice(request.path.length);
334
+ return response.redirect(301, newPath + query);
335
+ }
336
+ return next();
337
+ }
338
+ __name(filterMiddleware, "filterMiddleware");
339
+
340
+ // src/api.error.ts
341
+ var API_ERROR_STATUS = {
342
+ BAD_REQUEST: 400,
343
+ UNAUTHORIZED: 401,
344
+ FORBIDDEN: 403,
345
+ NOT_FOUND: 404,
346
+ ROUTE_NOT_FOUND: 404,
347
+ TOO_MANY_REQUESTS: 429,
348
+ CONFLICT: 409,
349
+ INTERNAL_SERVER_ERROR: 500,
350
+ TOKEN_EXPIRED: 401,
351
+ REFRESH_TOKEN_EXPIRED: 401,
352
+ ACCESS_TOKEN_EXPIRED: 401,
353
+ ACCESS_TOKEN_REQUIRED: 401,
354
+ TOKEN_REFRESH_TOO_EARLY: 403,
355
+ EMAIL_NOT_VERIFIED: 401,
356
+ PHONE_NOT_VERIFIED: 401,
357
+ TOKEN_NOT_FOUND: 404,
358
+ INVALID_TOKEN: 401,
359
+ RESET_PASSWORD_TOKEN_USED: 401,
360
+ RESET_PASSWORD_NEEDED: 400,
361
+ ROLE_DISABLED: 403,
362
+ SESSION_NOT_FOUND: 404,
363
+ SESSION_DISABLED: 401,
364
+ INVALID_RESPONSE: 500,
365
+ UNKNOWN_CLIENT_ERROR: 400,
366
+ INVALID_CREDENTIALS: 400,
367
+ VALIDATION_ERROR: 400
368
+ };
369
+ var APIError = class _APIError extends Error {
370
+ static {
371
+ __name(this, "APIError");
372
+ }
373
+ code;
374
+ status;
375
+ details;
376
+ constructor(...args) {
377
+ const [code, message, details] = args;
378
+ super(message);
379
+ this.name = "APIError";
380
+ this.code = code;
381
+ this.status = API_ERROR_STATUS[code];
382
+ this.details = details;
383
+ Object.setPrototypeOf(this, _APIError.prototype);
384
+ }
385
+ };
386
+
387
+ // src/express/middleware/not-found.middleware.ts
388
+ async function notFoundMiddleware(request) {
389
+ throw new APIError("ROUTE_NOT_FOUND", `Route ${request.path} is not found!`);
390
+ }
391
+ __name(notFoundMiddleware, "notFoundMiddleware");
392
+
393
+ // src/express/middleware/error.middleware.ts
394
+ function isPlainObject(value) {
395
+ return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
396
+ }
397
+ __name(isPlainObject, "isPlainObject");
398
+ var createErrorMiddleware = /* @__PURE__ */ __name((cookieTokenOptions) => (error, req, res, _) => {
399
+ try {
400
+ res.setHeader("Cache-Control", "no-store");
401
+ if (error instanceof APIError) {
402
+ if (error.code === "INTERNAL_SERVER_ERROR") {
403
+ console.error(error);
404
+ return res.status(error.status).json({
405
+ success: false,
406
+ error: error.code,
407
+ message: "An internal error is happening. Please contact developer as soon as possible!"
408
+ });
409
+ }
410
+ if (error.code === "TOKEN_NOT_FOUND") {
411
+ if (req.cookies.token) res.clearCookie("token", cookieTokenOptions);
412
+ }
413
+ if (isPlainObject(error.details) && "retryIn" in error.details && typeof error.details.retryIn === "number") res.setHeader("Retry-After", error.details.retryIn);
414
+ const responseBody = {
415
+ success: false,
416
+ error: error.code,
417
+ ...error.message ? {
418
+ message: error.message
419
+ } : {},
420
+ ...isPlainObject(error.details) ? error.details : {}
421
+ };
422
+ return res.status(error.status).json(responseBody);
423
+ }
424
+ if (error instanceof SyntaxError) {
425
+ return res.status(error.statusCode).json({
426
+ success: false,
427
+ error: "JSON_PARSE_ERROR",
428
+ message: error.message
429
+ });
430
+ }
431
+ if (error instanceof Error) {
432
+ console.error(error);
433
+ return res.status(500).json({
434
+ success: false,
435
+ error: "UNKNOWN_ERROR",
436
+ message: "An unknown error is happening. Please contact developer as soon as possible!"
437
+ });
438
+ }
439
+ console.error("errorHandlerMiddleware", error);
440
+ return res.status(500).json({
441
+ success: false,
442
+ error: "INTERNAL_SERVER_ERROR",
443
+ message: "An internal error is happening. Please contact developer as soon as possible!"
444
+ });
445
+ } catch (error2) {
446
+ console.error("errorHandlerMiddleware", error2);
447
+ return res.status(500).json({
448
+ success: false,
449
+ error: "INTERNAL_SERVER_ERROR",
450
+ message: "An internal error is happening. Please contact developer as soon as possible!"
451
+ });
452
+ }
453
+ }, "createErrorMiddleware");
454
+ var error_middleware_default = createErrorMiddleware;
455
+
456
+ // src/express/app.ts
457
+ import cookieParser from "cookie-parser";
458
+ var createExpressApp = /* @__PURE__ */ __name((options) => {
459
+ const app = express();
460
+ app.set("trust proxy", 1);
461
+ app.disable("x-powered-by");
462
+ app.use(helmet());
463
+ app.use(cors_middleware_default(options.allowedOrigins));
464
+ app.use(filterMiddleware);
465
+ app.use(express.json({
466
+ limit: "1mb"
467
+ }));
468
+ app.use(cookieParser(options.cookieSecret));
469
+ app.use(express.urlencoded({
470
+ extended: true,
471
+ limit: "1mb"
472
+ }));
473
+ app.use(express.static("public", {
474
+ dotfiles: "deny",
475
+ etag: true,
476
+ immutable: false,
477
+ index: false,
478
+ lastModified: true,
479
+ maxAge: "1h"
480
+ }));
481
+ app.get("/", (request, response) => {
482
+ return response.status(200).json({
483
+ success: true,
484
+ message: `Welcome to ${options.appName}`,
485
+ data: {
486
+ userAgent: request.userAgent,
487
+ ipAddress: request.ipAddress
488
+ }
489
+ });
490
+ });
491
+ if (options.routes) {
492
+ app.use(options.routes.public);
493
+ app.use(options.routes.private);
494
+ }
495
+ app.use(notFoundMiddleware);
496
+ app.use(error_middleware_default(options.cookieOptions));
497
+ return app;
498
+ }, "createExpressApp");
499
+ var app_default = createExpressApp;
500
+
501
+ // src/mahameru.ts
502
+ var Mahameru = class {
503
+ static {
504
+ __name(this, "Mahameru");
505
+ }
506
+ config;
507
+ rootDir = process.cwd();
508
+ databasesDir = path4.join(this.rootDir, "src", "databases");
509
+ isCommonJS = typeof module !== "undefined" && !!module.exports;
510
+ isBuild = __dirname2.includes("dist");
511
+ shouldInitDB = true;
512
+ constructor(config) {
513
+ this.config = config;
514
+ if (!this.config) throw new MahameruError("Mahameru config is not provided");
515
+ if (!this.config.options) throw new MahameruError("Mahameru config.options is not provided");
516
+ if (!existsSync2(this.rootDir)) throw new MahameruError("Root directory does not exist");
517
+ if (!existsSync2(path4.join(this.rootDir, "src"))) throw new MahameruError("src directory does not exist");
518
+ if (typeof this.config.options.dev === "undefined") this.config.options.dev = false;
519
+ if (!existsSync2(this.databasesDir)) this.shouldInitDB = false;
520
+ }
521
+ async initialize() {
522
+ console.log("Preparing mahameru...");
523
+ if (this.config.options.dev) await this.preInitDevelopment(this.shouldInitDB);
524
+ console.log(`Starting mahameru on port ${this.config.options.port} in ${this.config.options.dev ? "development" : "production"} mode...`);
525
+ const app = app_default({
526
+ allowedOrigins: this.config.httpAllowedOrigins || [],
527
+ cookieSecret: this.config.cookieSecret || "secret",
528
+ cookieOptions: this.config.cookieOptions || {},
529
+ appName: this.config.options.appName || "Mahameru"
530
+ });
531
+ const httpServer = await createHttpServer(app, this.config.httpServer, {
532
+ port: this.config.options.port,
533
+ host: this.config.options.host
534
+ });
535
+ console.log("Mahameru is ready!");
536
+ const shutdown = /* @__PURE__ */ __name(async (signal) => {
537
+ if (signal) console.log("shutdown", `Received signal ${signal}`);
538
+ httpServer.close();
539
+ console.log("shutdown", `Shutdown complete.`);
540
+ }, "shutdown");
541
+ process.on("SIGINT", this.config.onSigint || shutdown);
542
+ process.on("SIGTERM", this.config.onSigterm || shutdown);
543
+ }
544
+ async preInitDevelopment(shouldInitDB = false) {
545
+ await this.createRequiredEnvFile();
546
+ const tsxPath = path4.join(process.cwd(), "node_modules", "tsx", "dist", this.isCommonJS ? "cli.cjs" : "cli.mjs");
547
+ const preInitScriptPath = `node_modules${path4.sep}mahameru${path4.sep}${this.isBuild ? "dist" : "src"}${path4.sep}lib${path4.sep}pre-init-dev-script.${this.isCommonJS ? "cjs" : "js"}`;
548
+ const args = [
549
+ tsxPath,
550
+ "--tsconfig",
551
+ "tsconfig.json",
552
+ preInitScriptPath,
553
+ shouldInitDB ? "--init-db" : null
554
+ ].filter(Boolean);
555
+ return await new Promise((resolve, reject) => {
556
+ const child = spawn2("node", args, {
557
+ stdio: "inherit",
558
+ env: {
559
+ ...process.env,
560
+ NODE_ENV: "development"
561
+ }
562
+ });
563
+ child.on("close", (code) => {
564
+ resolve(code);
565
+ });
566
+ child.on("error", (err) => {
567
+ reject(err);
568
+ });
569
+ });
570
+ }
571
+ async createRequiredEnvFile() {
572
+ const envDefaultPath = path4.join(this.rootDir, ".env");
573
+ const envDevelopmentPath = path4.join(this.rootDir, ".env.development");
574
+ if (!existsSync2(envDefaultPath)) await writeFile(envDefaultPath, "APP_NAME=Mahameru Node.js Framework", "utf-8");
575
+ if (!existsSync2(envDevelopmentPath)) {
576
+ const devEnv = ``;
577
+ await writeFile(envDevelopmentPath, devEnv, "utf-8");
578
+ }
579
+ }
580
+ isClass(v) {
581
+ return typeof v === "function" && /^\s*class\s+/.test(v.toString());
582
+ }
583
+ };
584
+
585
+ // src/client.ts
586
+ var mahameru = /* @__PURE__ */ __name((config) => {
587
+ try {
588
+ const mahameru2 = new Mahameru(config);
589
+ return mahameru2;
590
+ } catch (err) {
591
+ console.error(err);
592
+ process.exit(1);
593
+ }
594
+ }, "mahameru");
595
+ var client_default = mahameru;
596
+
597
+ // src/base-class/base.entity.ts
598
+ import { Column, CreateDateColumn, PrimaryGeneratedColumn } from "typeorm";
599
+ function _ts_decorate(decorators, target, key, desc) {
600
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
601
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
602
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
603
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
604
+ }
605
+ __name(_ts_decorate, "_ts_decorate");
606
+ function _ts_metadata(k, v) {
607
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
608
+ }
609
+ __name(_ts_metadata, "_ts_metadata");
610
+ var BaseEntity = class {
611
+ static {
612
+ __name(this, "BaseEntity");
613
+ }
614
+ id;
615
+ createdAt;
616
+ updatedAt;
617
+ isDisabled;
618
+ };
619
+ _ts_decorate([
620
+ PrimaryGeneratedColumn("uuid"),
621
+ _ts_metadata("design:type", String)
622
+ ], BaseEntity.prototype, "id", void 0);
623
+ _ts_decorate([
624
+ CreateDateColumn({
625
+ type: "datetime",
626
+ precision: 3,
627
+ default: /* @__PURE__ */ __name(() => "UTC_TIMESTAMP(3)", "default")
628
+ }),
629
+ _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
630
+ ], BaseEntity.prototype, "createdAt", void 0);
631
+ _ts_decorate([
632
+ Column({
633
+ type: "datetime",
634
+ precision: 3,
635
+ default: null,
636
+ nullable: true
637
+ }),
638
+ _ts_metadata("design:type", Object)
639
+ ], BaseEntity.prototype, "updatedAt", void 0);
640
+ _ts_decorate([
641
+ Column({
642
+ type: "boolean",
643
+ default: false
644
+ }),
645
+ _ts_metadata("design:type", Boolean)
646
+ ], BaseEntity.prototype, "isDisabled", void 0);
647
+
648
+ // src/base-class/base.model.ts
649
+ import { Like } from "typeorm";
650
+
651
+ // src/index.ts
652
+ var index_default = client_default;
653
+
654
+ // src/cli/scripts/on-dev.ts
655
+ import path5 from "path";
656
+ async function onDev(cliOptions) {
657
+ try {
658
+ console.log("\x1B[36m%s\x1B[0m", "\u25B2 Mahameru - Starting development server...");
659
+ const root2 = process.cwd();
660
+ const configPath = pathToFileURL(path5.join(root2, "mahameru.config.ts")).href;
661
+ const module3 = await import(configPath);
662
+ if (!module3.default) throw new MahameruError("Mahameru config not found");
663
+ const mahameruConfig = module3.default;
664
+ const app = index_default(mahameruConfig);
665
+ await app.initialize();
666
+ } catch (error) {
667
+ console.error(error);
668
+ }
669
+ }
670
+ __name(onDev, "onDev");
671
+
672
+ // src/cli/index.ts
673
+ var { default: { version: version2 } } = package_exports;
674
+ var program = new Command();
675
+ program.name("mahameru").version(version2).description("Mahameru - A minimal and fast Node.js framework for building HTTP servers");
676
+ program.command("init").description("Initialize a new project from a GitHub template").action(onInit);
677
+ program.command("dev").description("Start the development server").option("-p, --port <port>", "Port to run the development server on", "3000").action(onDev);
678
+ program.command("build").description("Build project").action(onBuild);
679
+ program.command("start").description("Start the production server").action(onStart);
680
+ program.parse(process.argv);
681
+ //# sourceMappingURL=index.js.map