@devbro/pashmak 0.1.7 → 0.1.9

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 (128) hide show
  1. package/dist/{DatabaseServiceProvider.js → DatabaseServiceProvider.mjs} +5 -9
  2. package/dist/DatabaseServiceProvider.mjs.map +1 -0
  3. package/dist/app/console/{DefaultCommand.js → DefaultCommand.mjs} +2 -2
  4. package/dist/app/console/DefaultCommand.mjs.map +1 -0
  5. package/dist/app/console/{KeyGenerateCommand.js → KeyGenerateCommand.mjs} +6 -6
  6. package/dist/app/console/KeyGenerateCommand.mjs.map +1 -0
  7. package/dist/app/console/{StartCommand.js → StartCommand.mjs} +2 -2
  8. package/dist/app/console/StartCommand.mjs.map +1 -0
  9. package/dist/app/console/generate/{GenerateControllerCommand.js → GenerateControllerCommand.mjs} +3 -2
  10. package/dist/app/console/generate/GenerateControllerCommand.mjs.map +1 -0
  11. package/dist/app/console/generate/controller.tpl +14 -3
  12. package/dist/app/console/generate/{index.d.ts → index.d.mts} +1 -1
  13. package/dist/app/console/generate/{index.js → index.mjs} +1 -1
  14. package/dist/app/console/index.d.mts +9 -0
  15. package/dist/app/console/{index.js → index.mjs} +2 -2
  16. package/dist/app/console/index.mjs.map +1 -0
  17. package/dist/app/console/migrate/{MakeMigrateCommand.d.ts → GenerateMigrateCommand.d.mts} +2 -2
  18. package/dist/app/console/migrate/{MakeMigrateCommand.js → GenerateMigrateCommand.mjs} +8 -8
  19. package/dist/app/console/migrate/GenerateMigrateCommand.mjs.map +1 -0
  20. package/dist/app/console/migrate/{MigrateCommand.js → MigrateCommand.mjs} +2 -2
  21. package/dist/app/console/migrate/MigrateCommand.mjs.map +1 -0
  22. package/dist/app/console/migrate/{MigrateRollbackCommand.js → MigrateRollbackCommand.mjs} +2 -2
  23. package/dist/app/console/migrate/MigrateRollbackCommand.mjs.map +1 -0
  24. package/dist/app/console/migrate/index.d.mts +4 -0
  25. package/dist/app/console/migrate/{index.js → index.mjs} +2 -2
  26. package/dist/app/console/migrate/index.mjs.map +1 -0
  27. package/dist/app/console/project/{CreateProjectCommand.js → CreateProjectCommand.mjs} +2 -2
  28. package/dist/app/console/project/CreateProjectCommand.mjs.map +1 -0
  29. package/dist/app/console/project/base_project/package.json.tpl +1 -1
  30. package/dist/bin/DatabaseServiceProvider.cjs +88 -0
  31. package/dist/bin/app/console/DefaultCommand.cjs +506 -0
  32. package/dist/bin/app/console/KeyGenerateCommand.cjs +554 -0
  33. package/dist/bin/app/console/StartCommand.cjs +520 -0
  34. package/dist/bin/app/console/generate/GenerateControllerCommand.cjs +532 -0
  35. package/dist/bin/app/console/generate/index.cjs +532 -0
  36. package/dist/bin/app/console/index.cjs +2167 -0
  37. package/dist/bin/app/console/migrate/GenerateMigrateCommand.cjs +529 -0
  38. package/dist/bin/app/console/migrate/MigrateCommand.cjs +565 -0
  39. package/dist/bin/app/console/migrate/MigrateRollbackCommand.cjs +1684 -0
  40. package/dist/bin/app/console/migrate/index.cjs +1829 -0
  41. package/dist/bin/app/console/project/CreateProjectCommand.cjs +155 -0
  42. package/dist/bin/{pashmak_cli.cjs → bin/pashmak_cli.cjs} +4 -4
  43. package/dist/bin/config.cjs +24 -0
  44. package/dist/bin/context.cjs +24 -0
  45. package/dist/bin/facades.cjs +491 -0
  46. package/dist/bin/helper.cjs +24 -0
  47. package/dist/bin/http.cjs +24 -0
  48. package/dist/bin/index.cjs +2452 -0
  49. package/dist/bin/logger.cjs +24 -0
  50. package/dist/bin/mailer.cjs +24 -0
  51. package/dist/bin/middlewares.cjs +512 -0
  52. package/dist/bin/orm.cjs +24 -0
  53. package/dist/bin/{pashmak_cli.js → pashmak_cli.mjs} +1 -1
  54. package/dist/bin/router.cjs +547 -0
  55. package/dist/bin/sql.cjs +24 -0
  56. package/dist/{config.js → config.mjs} +1 -1
  57. package/dist/config.mjs.map +1 -0
  58. package/dist/{context.js → context.mjs} +1 -1
  59. package/dist/context.mjs.map +1 -0
  60. package/dist/{facades.js → facades.mjs} +30 -57
  61. package/dist/facades.mjs.map +1 -0
  62. package/dist/{helper.js → helper.mjs} +1 -1
  63. package/dist/helper.mjs.map +1 -0
  64. package/dist/{http.js → http.mjs} +1 -1
  65. package/dist/http.mjs.map +1 -0
  66. package/dist/{index.js → index.mjs} +2 -2
  67. package/dist/index.mjs.map +1 -0
  68. package/dist/{logger.js → logger.mjs} +1 -1
  69. package/dist/logger.mjs.map +1 -0
  70. package/dist/{mailer.js → mailer.mjs} +1 -1
  71. package/dist/mailer.mjs.map +1 -0
  72. package/dist/{middlewares.js → middlewares.mjs} +3 -5
  73. package/dist/middlewares.mjs.map +1 -0
  74. package/dist/{orm.js → orm.mjs} +1 -1
  75. package/dist/orm.mjs.map +1 -0
  76. package/dist/{router.d.ts → router.d.mts} +1 -1
  77. package/dist/{router.js → router.mjs} +2 -4
  78. package/dist/router.mjs.map +1 -0
  79. package/dist/{sql.js → sql.mjs} +1 -1
  80. package/dist/sql.mjs.map +1 -0
  81. package/package.json +14 -15
  82. package/dist/DatabaseServiceProvider.js.map +0 -1
  83. package/dist/app/console/DefaultCommand.js.map +0 -1
  84. package/dist/app/console/KeyGenerateCommand.js.map +0 -1
  85. package/dist/app/console/StartCommand.js.map +0 -1
  86. package/dist/app/console/generate/GenerateControllerCommand.js.map +0 -1
  87. package/dist/app/console/index.d.ts +0 -9
  88. package/dist/app/console/index.js.map +0 -1
  89. package/dist/app/console/migrate/MakeMigrateCommand.js.map +0 -1
  90. package/dist/app/console/migrate/MigrateCommand.js.map +0 -1
  91. package/dist/app/console/migrate/MigrateRollbackCommand.js.map +0 -1
  92. package/dist/app/console/migrate/index.d.ts +0 -4
  93. package/dist/app/console/migrate/index.js.map +0 -1
  94. package/dist/app/console/project/CreateProjectCommand.js.map +0 -1
  95. package/dist/config.js.map +0 -1
  96. package/dist/context.js.map +0 -1
  97. package/dist/facades.js.map +0 -1
  98. package/dist/helper.js.map +0 -1
  99. package/dist/http.js.map +0 -1
  100. package/dist/index.js.map +0 -1
  101. package/dist/logger.js.map +0 -1
  102. package/dist/mailer.js.map +0 -1
  103. package/dist/middlewares.js.map +0 -1
  104. package/dist/orm.js.map +0 -1
  105. package/dist/router.js.map +0 -1
  106. package/dist/sql.js.map +0 -1
  107. /package/dist/{DatabaseServiceProvider.d.ts → DatabaseServiceProvider.d.mts} +0 -0
  108. /package/dist/app/console/{DefaultCommand.d.ts → DefaultCommand.d.mts} +0 -0
  109. /package/dist/app/console/{KeyGenerateCommand.d.ts → KeyGenerateCommand.d.mts} +0 -0
  110. /package/dist/app/console/{StartCommand.d.ts → StartCommand.d.mts} +0 -0
  111. /package/dist/app/console/generate/{GenerateControllerCommand.d.ts → GenerateControllerCommand.d.mts} +0 -0
  112. /package/dist/app/console/generate/{index.js.map → index.mjs.map} +0 -0
  113. /package/dist/app/console/migrate/{MigrateCommand.d.ts → MigrateCommand.d.mts} +0 -0
  114. /package/dist/app/console/migrate/{MigrateRollbackCommand.d.ts → MigrateRollbackCommand.d.mts} +0 -0
  115. /package/dist/app/console/project/{CreateProjectCommand.d.ts → CreateProjectCommand.d.mts} +0 -0
  116. /package/dist/bin/{pashmak_cli.d.ts → pashmak_cli.d.mts} +0 -0
  117. /package/dist/bin/{pashmak_cli.js.map → pashmak_cli.mjs.map} +0 -0
  118. /package/dist/{config.d.ts → config.d.mts} +0 -0
  119. /package/dist/{context.d.ts → context.d.mts} +0 -0
  120. /package/dist/{facades.d.ts → facades.d.mts} +0 -0
  121. /package/dist/{helper.d.ts → helper.d.mts} +0 -0
  122. /package/dist/{http.d.ts → http.d.mts} +0 -0
  123. /package/dist/{index.d.ts → index.d.mts} +0 -0
  124. /package/dist/{logger.d.ts → logger.d.mts} +0 -0
  125. /package/dist/{mailer.d.ts → mailer.d.mts} +0 -0
  126. /package/dist/{middlewares.d.ts → middlewares.d.mts} +0 -0
  127. /package/dist/{orm.d.ts → orm.d.mts} +0 -0
  128. /package/dist/{sql.d.ts → sql.d.mts} +0 -0
@@ -0,0 +1,547 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/router.mts
32
+ var router_exports = {};
33
+ __export(router_exports, {
34
+ BaseController: () => BaseController,
35
+ CompiledRoute: () => CompiledRoute,
36
+ Controller: () => Controller,
37
+ Delete: () => Delete,
38
+ Get: () => Get,
39
+ Middleware: () => Middleware,
40
+ MiddlewareFactory: () => MiddlewareFactory,
41
+ Model: () => Model,
42
+ Options: () => Options,
43
+ Param: () => Param,
44
+ Patch: () => Patch,
45
+ Post: () => Post,
46
+ Put: () => Put,
47
+ Route: () => Route,
48
+ Router: () => Router,
49
+ ValidatedRequest: () => ValidatedRequest,
50
+ createParamDecorator: () => createParamDecorator,
51
+ runNext: () => runNext
52
+ });
53
+ module.exports = __toCommonJS(router_exports);
54
+ var import_neko_context = require("@devbro/neko-context");
55
+ var import_errors = require("@devbro/neko-http/errors");
56
+
57
+ // ../neko-router/dist/Middleware.mjs
58
+ var Middleware = class {
59
+ static {
60
+ __name(this, "Middleware");
61
+ }
62
+ constructor(params = {}) {
63
+ }
64
+ static getInstance(params) {
65
+ throw new Error("Method not implemented. Please implement a static getInstance method.");
66
+ }
67
+ };
68
+
69
+ // ../neko-router/dist/MiddlewareFactory.mjs
70
+ var MiddlewareFactory = class {
71
+ static {
72
+ __name(this, "MiddlewareFactory");
73
+ }
74
+ static create(func) {
75
+ const cls = class extends Middleware {
76
+ static {
77
+ __name(this, "cls");
78
+ }
79
+ call(req, res, next) {
80
+ return func(req, res, next);
81
+ }
82
+ constructor(params = {}) {
83
+ super(params);
84
+ }
85
+ };
86
+ return new cls();
87
+ }
88
+ };
89
+
90
+ // ../neko-router/dist/CompiledRoute.mjs
91
+ var CompiledRoute = class {
92
+ static {
93
+ __name(this, "CompiledRoute");
94
+ }
95
+ constructor(route, request, response, globalMiddlewares = []) {
96
+ this.route = route;
97
+ this.request = request;
98
+ this.response = response;
99
+ this.globalMiddlewares = globalMiddlewares;
100
+ this.prepareMiddlewares();
101
+ }
102
+ middlewares = [];
103
+ getMiddlewares() {
104
+ return this.middlewares;
105
+ }
106
+ prepareMiddlewares() {
107
+ this.middlewares = [];
108
+ for (const middleware of [...this.globalMiddlewares, ...this.route.getMiddlewares()]) {
109
+ if (middleware instanceof Middleware) {
110
+ this.middlewares.push(middleware);
111
+ } else if (this.isClass(middleware)) {
112
+ this.middlewares.push(middleware.getInstance({}));
113
+ } else if (typeof middleware === "function") {
114
+ this.middlewares.push(MiddlewareFactory.create(middleware));
115
+ } else {
116
+ throw new Error("Invalid middleware type");
117
+ }
118
+ }
119
+ }
120
+ isClass(func) {
121
+ return typeof func === "function" && /^class\s/.test(Function.prototype.toString.call(func));
122
+ }
123
+ async run() {
124
+ return await this.runMiddlewares(this.middlewares, this.request, this.response);
125
+ }
126
+ prepareOutputJsonFormat(obj) {
127
+ function traverse(value) {
128
+ if (!value || typeof value !== "object") {
129
+ return value;
130
+ }
131
+ if (typeof value.toJson === "function") {
132
+ return traverse(value.toJson());
133
+ }
134
+ if (Array.isArray(value)) {
135
+ return value.map(traverse);
136
+ }
137
+ const result = {};
138
+ for (const key in value) {
139
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
140
+ result[key] = traverse(value[key]);
141
+ }
142
+ }
143
+ return result;
144
+ }
145
+ __name(traverse, "traverse");
146
+ return traverse(obj);
147
+ }
148
+ convertToString(obj) {
149
+ if (typeof obj === "string") {
150
+ return obj;
151
+ } else if (obj instanceof Buffer) {
152
+ return obj.toString();
153
+ } else if (typeof obj === "object") {
154
+ return JSON.stringify(this.prepareOutputJsonFormat(obj));
155
+ }
156
+ return String(obj);
157
+ }
158
+ processResponseBody(res, controller_rc) {
159
+ if (controller_rc && res.writableEnded) {
160
+ throw new Error("cannot write to response, response has already ended");
161
+ }
162
+ if (res.writableEnded) {
163
+ return;
164
+ }
165
+ if (controller_rc) {
166
+ const header_content_type = res.getHeader("Content-Type");
167
+ if (!header_content_type && typeof controller_rc === "object") {
168
+ res.setHeader("Content-Type", "application/json");
169
+ } else if (!header_content_type) {
170
+ res.setHeader("Content-Type", "text/plain");
171
+ }
172
+ res.end(this.convertToString(controller_rc));
173
+ return;
174
+ } else {
175
+ res.statusCode = [200].includes(res.statusCode) ? 204 : res.statusCode;
176
+ res.end();
177
+ }
178
+ }
179
+ async runMiddlewares(middlewares, req, res) {
180
+ let index = 0;
181
+ const me = this;
182
+ async function next() {
183
+ if (index >= middlewares.length) {
184
+ const controller_rc = await me.route.callHanlder(req, res);
185
+ await me.processResponseBody(res, controller_rc);
186
+ return;
187
+ }
188
+ const middleware = middlewares[index++];
189
+ if (middleware instanceof Middleware) {
190
+ await middleware.call(req, res, next);
191
+ } else if (typeof middleware === "function") {
192
+ await middleware(req, res, next);
193
+ } else {
194
+ throw new Error("does not know how to run middleware");
195
+ }
196
+ }
197
+ __name(next, "next");
198
+ await next();
199
+ }
200
+ };
201
+
202
+ // ../neko-router/dist/Controller.mjs
203
+ var BaseController = class {
204
+ static {
205
+ __name(this, "BaseController");
206
+ }
207
+ static basePath = "";
208
+ static baseMiddlewares;
209
+ static getInstance() {
210
+ return new this();
211
+ }
212
+ };
213
+ function Controller(path2, options = {}) {
214
+ return function(target) {
215
+ target.routes = target.routes || [];
216
+ target.basePath = path2;
217
+ target.baseMiddlewares = options.middlewares || [];
218
+ };
219
+ }
220
+ __name(Controller, "Controller");
221
+ function createHttpDecorator(data) {
222
+ return function(target, propertyKey, descriptor) {
223
+ const ctor = target.constructor;
224
+ if (!ctor.routes) ctor.routes = [];
225
+ ctor.routes.push({
226
+ methods: data.methods,
227
+ path: data.path,
228
+ handler: propertyKey,
229
+ middlewares: data.middlewares || []
230
+ });
231
+ const originalMethod = descriptor.value;
232
+ const paramKeys = Reflect.ownKeys(target.constructor);
233
+ const methodName = propertyKey.toString();
234
+ descriptor.value = async function(...args) {
235
+ const paramCustomKeys = paramKeys.filter(
236
+ (key) => typeof key === "string" && key.startsWith(`${methodName}:`) && key.endsWith(":custom")
237
+ );
238
+ for (const paramKey of paramCustomKeys) {
239
+ const paramIndex = parseInt(paramKey.split(":")[1]);
240
+ let method = Reflect.get(target.constructor, paramKey.toString());
241
+ if (typeof paramIndex === "number" && typeof method === "function") {
242
+ args[paramIndex] = await method();
243
+ }
244
+ }
245
+ return originalMethod.apply(this, args);
246
+ };
247
+ };
248
+ }
249
+ __name(createHttpDecorator, "createHttpDecorator");
250
+ function Get(data = {}) {
251
+ return createHttpDecorator({
252
+ methods: ["GET", "HEAD"],
253
+ path: data.path || "/",
254
+ middlewares: data.middlewares || []
255
+ });
256
+ }
257
+ __name(Get, "Get");
258
+ function Post(data = {}) {
259
+ return createHttpDecorator({
260
+ methods: ["POST"],
261
+ path: data.path || "/",
262
+ middlewares: data.middlewares || []
263
+ });
264
+ }
265
+ __name(Post, "Post");
266
+ function Put(data = {}) {
267
+ return createHttpDecorator({
268
+ methods: ["PUT"],
269
+ path: data.path || "/",
270
+ middlewares: data.middlewares || []
271
+ });
272
+ }
273
+ __name(Put, "Put");
274
+ function Patch(data = {}) {
275
+ return createHttpDecorator({
276
+ methods: ["PATCH"],
277
+ path: data.path || "/",
278
+ middlewares: data.middlewares || []
279
+ });
280
+ }
281
+ __name(Patch, "Patch");
282
+ function Delete(data = {}) {
283
+ return createHttpDecorator({
284
+ methods: ["DELETE"],
285
+ path: data.path || "/",
286
+ middlewares: data.middlewares || []
287
+ });
288
+ }
289
+ __name(Delete, "Delete");
290
+ function Options(data = {}) {
291
+ return createHttpDecorator({
292
+ methods: ["OPTIONS"],
293
+ path: data.path || "/",
294
+ middlewares: data.middlewares || []
295
+ });
296
+ }
297
+ __name(Options, "Options");
298
+ function createParamDecorator(func) {
299
+ return /* @__PURE__ */ __name(function MyParamDecorator(target, propertyKey, parameterIndex) {
300
+ Reflect.set(target.constructor, `${propertyKey?.toString()}:${parameterIndex}:custom`, func);
301
+ }, "MyParamDecorator");
302
+ }
303
+ __name(createParamDecorator, "createParamDecorator");
304
+
305
+ // ../neko-router/dist/Route.mjs
306
+ var Route = class {
307
+ static {
308
+ __name(this, "Route");
309
+ }
310
+ constructor(methods, path2, handler) {
311
+ this.methods = methods;
312
+ this.path = path2;
313
+ this.handler = handler;
314
+ this.urlRegex = this.pathToRegex(path2);
315
+ }
316
+ middlewares = [];
317
+ urlRegex;
318
+ pathToRegex(path2) {
319
+ const lex = this.lexUrlPath(path2);
320
+ return this.tokensToRegex(lex);
321
+ }
322
+ lexUrlPath(path2) {
323
+ const tokens = [];
324
+ let i = 0;
325
+ while (i < path2.length) {
326
+ const char = path2[i];
327
+ if (char === "/") {
328
+ tokens.push({ type: "SLASH", value: "/" });
329
+ i++;
330
+ } else if (char === ":") {
331
+ let start = i + 1;
332
+ while (start < path2.length && /[a-zA-Z0-9_]/.test(path2[start])) {
333
+ start++;
334
+ }
335
+ tokens.push({ type: "PARAM", value: path2.slice(i + 1, start) });
336
+ i = start;
337
+ } else if (char === "*") {
338
+ let start = i + 1;
339
+ while (start < path2.length && /[a-zA-Z0-9_]/.test(path2[start])) {
340
+ start++;
341
+ }
342
+ tokens.push({ type: "WILDCARD", value: path2.slice(i + 1, start) });
343
+ i = start;
344
+ } else {
345
+ let start = i;
346
+ while (start < path2.length && !["/", ":", "*"].includes(path2[start])) {
347
+ start++;
348
+ }
349
+ tokens.push({ type: "TEXT", value: path2.slice(i, start) });
350
+ i = start;
351
+ }
352
+ }
353
+ return tokens;
354
+ }
355
+ tokensToRegex(tokens) {
356
+ const regexParts = [];
357
+ for (const token of tokens) {
358
+ if (token.type === "SLASH") {
359
+ regexParts.push("\\/");
360
+ } else if (token.type === "PARAM") {
361
+ regexParts.push(`(?<${token.value}>[^\\/]+)`);
362
+ } else if (token.type === "WILDCARD") {
363
+ regexParts.push("(.+)");
364
+ } else if (token.type === "TEXT") {
365
+ regexParts.push(token.value.replace(/[-\/\\^$.*+?()[\]{}|]/g, "\\$&"));
366
+ }
367
+ }
368
+ if (regexParts.length > 0 && regexParts[regexParts.length - 1] === "\\/") {
369
+ regexParts[regexParts.length - 1] = "\\/?";
370
+ } else {
371
+ regexParts.push("\\/?");
372
+ }
373
+ return new RegExp(`^${regexParts.join("")}$`);
374
+ }
375
+ /**
376
+ * to evaludate if request is a match for this route
377
+ * @param request http request
378
+ * @returns return true if route is a match for this request
379
+ */
380
+ test(request) {
381
+ if (this.methods.indexOf(request.method) === -1) {
382
+ return false;
383
+ }
384
+ const url = new URL(request.url || "/", "http://localhost");
385
+ return this.testPath(url.pathname);
386
+ }
387
+ testPath(pathname) {
388
+ return this.urlRegex.test(pathname);
389
+ }
390
+ /**
391
+ * returns details of the match, otherwise it returns false
392
+ * @param request the request to match
393
+ * @returns object cotaining details of match including matched params
394
+ */
395
+ match(request) {
396
+ if (this.methods.indexOf(request.method) === -1) {
397
+ return false;
398
+ }
399
+ const url = new URL(request.url || "/", "http://localhost");
400
+ const r = this.urlRegex.exec(url.pathname);
401
+ if (!r) {
402
+ return false;
403
+ }
404
+ return {
405
+ url,
406
+ params: r.groups || {}
407
+ };
408
+ }
409
+ addMiddleware(middlewares) {
410
+ this.middlewares = this.middlewares.concat(middlewares);
411
+ return this;
412
+ }
413
+ getMiddlewares() {
414
+ return this.middlewares;
415
+ }
416
+ callHanlder(request, response) {
417
+ return this.handler(request, response);
418
+ }
419
+ };
420
+
421
+ // ../neko-router/dist/Router.mjs
422
+ var import_path = __toESM(require("path"), 1);
423
+ var Router = class {
424
+ static {
425
+ __name(this, "Router");
426
+ }
427
+ middlewares = [];
428
+ routes = [];
429
+ addRoute(methods, path2, handler) {
430
+ const route = new Route(methods, path2, handler);
431
+ this.routes.push(route);
432
+ return route;
433
+ }
434
+ getMiddlewares() {
435
+ return [...this.middlewares];
436
+ }
437
+ addController(controller) {
438
+ const basePath = controller.basePath || "";
439
+ for (const route of controller.routes) {
440
+ const urlPath = import_path.default.join(basePath, route.path);
441
+ this.addRoute(route.methods, urlPath, async (req, res) => {
442
+ const controllerInstance = controller.getInstance();
443
+ return await controllerInstance[route.handler]();
444
+ }).addMiddleware([...controller.baseMiddlewares, ...route.middlewares]);
445
+ }
446
+ }
447
+ addGlobalMiddleware(middlewares) {
448
+ this.middlewares = this.middlewares.concat(middlewares);
449
+ }
450
+ resolve(request) {
451
+ for (const route of this.routes) {
452
+ if (route.test(request)) {
453
+ return route;
454
+ }
455
+ }
456
+ return void 0;
457
+ }
458
+ resolveMultiple(request) {
459
+ const rc = [];
460
+ const url = new URL(request.url || "/", "http://localhost");
461
+ for (const route of this.routes) {
462
+ if (route.testPath(url.pathname)) {
463
+ rc.push(route);
464
+ }
465
+ }
466
+ return rc;
467
+ }
468
+ getCompiledRoute(request, response) {
469
+ const route = this.resolve(request);
470
+ if (!route) {
471
+ return void 0;
472
+ }
473
+ const match = route.match(request);
474
+ if (!match) {
475
+ return void 0;
476
+ }
477
+ request.params = match.params;
478
+ return new CompiledRoute(route, request, response, this.middlewares);
479
+ }
480
+ };
481
+
482
+ // ../neko-router/dist/helpers.mjs
483
+ async function runNext(middlewares, req, res, final) {
484
+ let index = 0;
485
+ async function next() {
486
+ if (index >= middlewares.length) {
487
+ return await final(req, res);
488
+ }
489
+ const middleware = middlewares[index++];
490
+ if (middleware instanceof Middleware) {
491
+ await middleware.call(req, res, next);
492
+ } else if (typeof middleware === "function") {
493
+ await middleware(req, res, next);
494
+ } else {
495
+ throw new Error("does not know how to run middleware");
496
+ }
497
+ }
498
+ __name(next, "next");
499
+ await next();
500
+ }
501
+ __name(runNext, "runNext");
502
+
503
+ // src/router.mts
504
+ function Model(model, paramName) {
505
+ return createParamDecorator(async () => {
506
+ let rc = await model.find((0, import_neko_context.ctx)().get("request").params[paramName]);
507
+ if (!rc) {
508
+ throw new import_errors.HttpNotFoundError("Object not found");
509
+ }
510
+ return rc;
511
+ });
512
+ }
513
+ __name(Model, "Model");
514
+ function Param(paramName) {
515
+ return createParamDecorator(() => {
516
+ return (0, import_neko_context.ctx)().get("request").params[paramName];
517
+ });
518
+ }
519
+ __name(Param, "Param");
520
+ function ValidatedRequest(validationRules) {
521
+ return createParamDecorator(async () => {
522
+ const rc = await (typeof validationRules === "function" ? validationRules() : validationRules).noUnknown().validate((0, import_neko_context.ctx)().get("request").body, { abortEarly: false });
523
+ return rc;
524
+ });
525
+ }
526
+ __name(ValidatedRequest, "ValidatedRequest");
527
+ // Annotate the CommonJS export names for ESM import in node:
528
+ 0 && (module.exports = {
529
+ BaseController,
530
+ CompiledRoute,
531
+ Controller,
532
+ Delete,
533
+ Get,
534
+ Middleware,
535
+ MiddlewareFactory,
536
+ Model,
537
+ Options,
538
+ Param,
539
+ Patch,
540
+ Post,
541
+ Put,
542
+ Route,
543
+ Router,
544
+ ValidatedRequest,
545
+ createParamDecorator,
546
+ runNext
547
+ });
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/sql.mts
18
+ var sql_exports = {};
19
+ module.exports = __toCommonJS(sql_exports);
20
+ __reExport(sql_exports, require("@devbro/neko-sql"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("@devbro/neko-sql")
24
+ });
@@ -1,2 +1,2 @@
1
1
  export * from "@devbro/neko-config";
2
- //# sourceMappingURL=config.js.map
2
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config.mts"],"sourcesContent":["export * from \"@devbro/neko-config\";\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -1,2 +1,2 @@
1
1
  export * from "@devbro/neko-context";
2
- //# sourceMappingURL=context.js.map
2
+ //# sourceMappingURL=context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/context.mts"],"sourcesContent":["export * from \"@devbro/neko-context\";\n"],"mappings":"AAAA,cAAc;","names":[]}