@h3ravel/router 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1303,7 +1303,7 @@ var Router = class {
1303
1303
  * @param methodName Method to invoke on the controller (defaults to 'index')
1304
1304
  */
1305
1305
  resolveControllerOrHandler(handler, methodName) {
1306
- if (typeof handler === "function") {
1306
+ if (typeof handler === "function" && typeof handler.prototype !== "undefined") {
1307
1307
  return (_ctx) => {
1308
1308
  let controller;
1309
1309
  if (import_core.Container.hasAnyDecorator(handler)) {
@@ -1316,7 +1316,7 @@ var Router = class {
1316
1316
  throw new Error(`Method "${String(action)}" not found on controller ${handler.name}`);
1317
1317
  }
1318
1318
  const paramTypes = Reflect.getMetadata("design:paramtypes", controller, action) || [];
1319
- const args = paramTypes.map((paramType) => {
1319
+ let args = paramTypes.map((paramType) => {
1320
1320
  switch (paramType?.name) {
1321
1321
  case "Application":
1322
1322
  return this.app;
@@ -1330,6 +1330,11 @@ var Router = class {
1330
1330
  return this.app.make(paramType);
1331
1331
  }
1332
1332
  });
1333
+ if (args.length < 1) {
1334
+ args = [
1335
+ _ctx
1336
+ ];
1337
+ }
1333
1338
  return controller[action](...args);
1334
1339
  };
1335
1340
  }
@@ -1426,13 +1431,30 @@ var Router = class {
1426
1431
  const basePath = `/${path2}`.replace(/\/+$/, "").replace(/(\/)+/g, "$1");
1427
1432
  const name = basePath.substring(basePath.lastIndexOf("/") + 1).replaceAll(/\/|:/g, "") || "";
1428
1433
  const param = (0, import_support.singularize)(name);
1429
- const controller = new Controller(this.app);
1430
- this.addRoute("get", basePath, controller.index.bind(controller), `${name}.index`, middleware);
1431
- this.addRoute("post", basePath, controller.store.bind(controller), `${name}.store`, middleware);
1432
- this.addRoute("get", `${basePath}/:${param}`, controller.show.bind(controller), `${name}.show`, middleware);
1433
- this.addRoute("put", `${basePath}/:${param}`, controller.update.bind(controller), `${name}.update`, middleware);
1434
- this.addRoute("patch", `${basePath}/:${param}`, controller.update.bind(controller), `${name}.update`, middleware);
1435
- this.addRoute("delete", `${basePath}/:${param}`, controller.destroy.bind(controller), `${name}.destroy`, middleware);
1434
+ this.get(basePath, [
1435
+ Controller,
1436
+ "index"
1437
+ ], `${name}.index`, middleware);
1438
+ this.post(basePath, [
1439
+ Controller,
1440
+ "store"
1441
+ ], `${name}.store`, middleware);
1442
+ this.get(`${basePath}/:${param}`, [
1443
+ Controller,
1444
+ "show"
1445
+ ], `${name}.show`, middleware);
1446
+ this.put(`${basePath}/:${param}`, [
1447
+ Controller,
1448
+ "update"
1449
+ ], `${name}.update`, middleware);
1450
+ this.patch(`${basePath}/:${param}`, [
1451
+ Controller,
1452
+ "update"
1453
+ ], `${name}.update`, middleware);
1454
+ this.delete(`${basePath}/:${param}`, [
1455
+ Controller,
1456
+ "destroy"
1457
+ ], `${name}.destroy`, middleware);
1436
1458
  return this;
1437
1459
  }
1438
1460
  /**
@@ -1465,7 +1487,7 @@ var Router = class {
1465
1487
  ];
1466
1488
  this.groupPrefix += options.prefix || "";
1467
1489
  this.groupMiddleware.push(...options.middleware || []);
1468
- callback();
1490
+ callback(this);
1469
1491
  this.groupPrefix = prevPrefix;
1470
1492
  this.groupMiddleware = prevMiddleware;
1471
1493
  return this;