@gravito/core 1.1.0 → 1.2.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.
package/dist/compat.d.cts CHANGED
@@ -273,7 +273,7 @@ interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
273
273
  /**
274
274
  * Next function for middleware chain
275
275
  */
276
- type GravitoNext = () => Promise<void>;
276
+ type GravitoNext = () => Promise<Response | undefined>;
277
277
  /**
278
278
  * GravitoHandler - Standard route handler type
279
279
  *
package/dist/compat.d.ts CHANGED
@@ -273,7 +273,7 @@ interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
273
273
  /**
274
274
  * Next function for middleware chain
275
275
  */
276
- type GravitoNext = () => Promise<void>;
276
+ type GravitoNext = () => Promise<Response | undefined>;
277
277
  /**
278
278
  * GravitoHandler - Standard route handler type
279
279
  *
@@ -402,7 +402,7 @@ var AOTRouter = class {
402
402
  * @param path - Matched path
403
403
  * @returns Route key or null
404
404
  */
405
- findDynamicRouteKey(method, path) {
405
+ findDynamicRouteKey(method, _path) {
406
406
  for (const key of this.pathMiddleware.keys()) {
407
407
  if (key.startsWith(`${method}:`)) {
408
408
  return key;
@@ -533,7 +533,7 @@ var FastRequestImpl = class {
533
533
  };
534
534
  var FastContext = class {
535
535
  _req = new FastRequestImpl();
536
- _statusCode = 200;
536
+ // private _statusCode = 200
537
537
  _headers = new Headers();
538
538
  // Reuse this object
539
539
  /**
@@ -544,7 +544,6 @@ var FastContext = class {
544
544
  */
545
545
  reset(request, params = {}) {
546
546
  this._req.reset(request, params);
547
- this._statusCode = 200;
548
547
  this._headers = new Headers();
549
548
  return this;
550
549
  }
@@ -594,8 +593,7 @@ var FastContext = class {
594
593
  header(name, value) {
595
594
  this._headers.set(name, value);
596
595
  }
597
- status(code) {
598
- this._statusCode = code;
596
+ status(_code) {
599
597
  }
600
598
  };
601
599
 
@@ -925,7 +923,7 @@ var Gravito = class {
925
923
  * // Now accessible at /api/users
926
924
  * ```
927
925
  */
928
- route(path, app) {
926
+ route(_path, _app) {
929
927
  console.warn("route() method is not yet fully implemented");
930
928
  return this;
931
929
  }
@@ -1130,21 +1128,26 @@ var Gravito = class {
1130
1128
  const next = async () => {
1131
1129
  if (index < middleware.length) {
1132
1130
  const mw = middleware[index++];
1133
- await mw(ctx, next);
1131
+ return await mw(ctx, next);
1134
1132
  }
1133
+ return void 0;
1135
1134
  };
1136
- await next();
1135
+ const result = await next();
1136
+ if (result instanceof Response) {
1137
+ return result;
1138
+ }
1137
1139
  return await handler(ctx);
1138
1140
  }
1139
- /**
1141
+ /*
1140
1142
  * Handle 404 Not Found (Async version for dynamic/middleware paths)
1143
+ * Note: Currently unused as we handle 404s via handleNotFoundSync or inline
1141
1144
  */
1142
- async handleNotFound(ctx) {
1143
- if (this.notFoundHandler) {
1144
- return await this.notFoundHandler(ctx);
1145
- }
1146
- return ctx.json({ error: "Not Found" }, 404);
1147
- }
1145
+ // private async handleNotFound(ctx: FastContext): Promise<Response> {
1146
+ // if (this.notFoundHandler) {
1147
+ // return await this.notFoundHandler(ctx)
1148
+ // }
1149
+ // return ctx.json({ error: 'Not Found' }, 404)
1150
+ // }
1148
1151
  /**
1149
1152
  * Handle errors (Async version for dynamic/middleware paths)
1150
1153
  */
@@ -83,7 +83,7 @@ type Handler = (ctx: FastContext$1) => Response | Promise<Response>;
83
83
  /**
84
84
  * Middleware function
85
85
  */
86
- type Middleware = (ctx: FastContext$1, next: () => Promise<void>) => void | Promise<void>;
86
+ type Middleware = (ctx: FastContext$1, next: () => Promise<Response | undefined>) => Response | undefined | Promise<Response | undefined>;
87
87
  /**
88
88
  * Error handler function
89
89
  */
@@ -232,7 +232,7 @@ declare class Gravito {
232
232
  * // Now accessible at /api/users
233
233
  * ```
234
234
  */
235
- route(path: string, app: Gravito): this;
235
+ route(_path: string, _app: Gravito): this;
236
236
  /**
237
237
  * Set custom error handler
238
238
  *
@@ -303,10 +303,6 @@ declare class Gravito {
303
303
  * Each middleware can call next() to continue the chain.
304
304
  */
305
305
  private executeMiddleware;
306
- /**
307
- * Handle 404 Not Found (Async version for dynamic/middleware paths)
308
- */
309
- private handleNotFound;
310
306
  /**
311
307
  * Handle errors (Async version for dynamic/middleware paths)
312
308
  */
@@ -447,7 +443,6 @@ declare class AOTRouter {
447
443
  */
448
444
  declare class FastContext implements FastContext$1 {
449
445
  private _req;
450
- private _statusCode;
451
446
  private _headers;
452
447
  /**
453
448
  * Reset context for pooling
@@ -463,7 +458,7 @@ declare class FastContext implements FastContext$1 {
463
458
  redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
464
459
  body(data: BodyInit | null, status?: number): Response;
465
460
  header(name: string, value: string): void;
466
- status(code: number): void;
461
+ status(_code: number): void;
467
462
  }
468
463
 
469
464
  /**
@@ -83,7 +83,7 @@ type Handler = (ctx: FastContext$1) => Response | Promise<Response>;
83
83
  /**
84
84
  * Middleware function
85
85
  */
86
- type Middleware = (ctx: FastContext$1, next: () => Promise<void>) => void | Promise<void>;
86
+ type Middleware = (ctx: FastContext$1, next: () => Promise<Response | undefined>) => Response | undefined | Promise<Response | undefined>;
87
87
  /**
88
88
  * Error handler function
89
89
  */
@@ -232,7 +232,7 @@ declare class Gravito {
232
232
  * // Now accessible at /api/users
233
233
  * ```
234
234
  */
235
- route(path: string, app: Gravito): this;
235
+ route(_path: string, _app: Gravito): this;
236
236
  /**
237
237
  * Set custom error handler
238
238
  *
@@ -303,10 +303,6 @@ declare class Gravito {
303
303
  * Each middleware can call next() to continue the chain.
304
304
  */
305
305
  private executeMiddleware;
306
- /**
307
- * Handle 404 Not Found (Async version for dynamic/middleware paths)
308
- */
309
- private handleNotFound;
310
306
  /**
311
307
  * Handle errors (Async version for dynamic/middleware paths)
312
308
  */
@@ -447,7 +443,6 @@ declare class AOTRouter {
447
443
  */
448
444
  declare class FastContext implements FastContext$1 {
449
445
  private _req;
450
- private _statusCode;
451
446
  private _headers;
452
447
  /**
453
448
  * Reset context for pooling
@@ -463,7 +458,7 @@ declare class FastContext implements FastContext$1 {
463
458
  redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
464
459
  body(data: BodyInit | null, status?: number): Response;
465
460
  header(name: string, value: string): void;
466
- status(code: number): void;
461
+ status(_code: number): void;
467
462
  }
468
463
 
469
464
  /**
@@ -371,7 +371,7 @@ var AOTRouter = class {
371
371
  * @param path - Matched path
372
372
  * @returns Route key or null
373
373
  */
374
- findDynamicRouteKey(method, path) {
374
+ findDynamicRouteKey(method, _path) {
375
375
  for (const key of this.pathMiddleware.keys()) {
376
376
  if (key.startsWith(`${method}:`)) {
377
377
  return key;
@@ -502,7 +502,7 @@ var FastRequestImpl = class {
502
502
  };
503
503
  var FastContext = class {
504
504
  _req = new FastRequestImpl();
505
- _statusCode = 200;
505
+ // private _statusCode = 200
506
506
  _headers = new Headers();
507
507
  // Reuse this object
508
508
  /**
@@ -513,7 +513,6 @@ var FastContext = class {
513
513
  */
514
514
  reset(request, params = {}) {
515
515
  this._req.reset(request, params);
516
- this._statusCode = 200;
517
516
  this._headers = new Headers();
518
517
  return this;
519
518
  }
@@ -563,8 +562,7 @@ var FastContext = class {
563
562
  header(name, value) {
564
563
  this._headers.set(name, value);
565
564
  }
566
- status(code) {
567
- this._statusCode = code;
565
+ status(_code) {
568
566
  }
569
567
  };
570
568
 
@@ -894,7 +892,7 @@ var Gravito = class {
894
892
  * // Now accessible at /api/users
895
893
  * ```
896
894
  */
897
- route(path, app) {
895
+ route(_path, _app) {
898
896
  console.warn("route() method is not yet fully implemented");
899
897
  return this;
900
898
  }
@@ -1099,21 +1097,26 @@ var Gravito = class {
1099
1097
  const next = async () => {
1100
1098
  if (index < middleware.length) {
1101
1099
  const mw = middleware[index++];
1102
- await mw(ctx, next);
1100
+ return await mw(ctx, next);
1103
1101
  }
1102
+ return void 0;
1104
1103
  };
1105
- await next();
1104
+ const result = await next();
1105
+ if (result instanceof Response) {
1106
+ return result;
1107
+ }
1106
1108
  return await handler(ctx);
1107
1109
  }
1108
- /**
1110
+ /*
1109
1111
  * Handle 404 Not Found (Async version for dynamic/middleware paths)
1112
+ * Note: Currently unused as we handle 404s via handleNotFoundSync or inline
1110
1113
  */
1111
- async handleNotFound(ctx) {
1112
- if (this.notFoundHandler) {
1113
- return await this.notFoundHandler(ctx);
1114
- }
1115
- return ctx.json({ error: "Not Found" }, 404);
1116
- }
1114
+ // private async handleNotFound(ctx: FastContext): Promise<Response> {
1115
+ // if (this.notFoundHandler) {
1116
+ // return await this.notFoundHandler(ctx)
1117
+ // }
1118
+ // return ctx.json({ error: 'Not Found' }, 404)
1119
+ // }
1117
1120
  /**
1118
1121
  * Handle errors (Async version for dynamic/middleware paths)
1119
1122
  */
package/dist/index.cjs CHANGED
@@ -54,6 +54,7 @@ __export(index_exports, {
54
54
  PhotonRequestWrapper: () => PhotonRequestWrapper,
55
55
  PlanetCore: () => PlanetCore,
56
56
  Route: () => Route,
57
+ RouteGroup: () => RouteGroup,
57
58
  Router: () => Router,
58
59
  ServiceProvider: () => ServiceProvider,
59
60
  Str: () => Str,
@@ -113,7 +114,7 @@ module.exports = __toCommonJS(index_exports);
113
114
  // package.json
114
115
  var package_default = {
115
116
  name: "@gravito/core",
116
- version: "1.1.0",
117
+ version: "1.2.0",
117
118
  description: "",
118
119
  module: "./dist/index.js",
119
120
  main: "./dist/index.cjs",
@@ -185,10 +186,45 @@ var package_default = {
185
186
  };
186
187
 
187
188
  // src/adapters/PhotonAdapter.ts
188
- var PhotonRequestWrapper = class {
189
+ var PhotonRequestWrapper = class _PhotonRequestWrapper {
189
190
  constructor(photonCtx) {
190
191
  this.photonCtx = photonCtx;
191
192
  }
193
+ /**
194
+ * Create a proxied instance to delegate to Photon's request
195
+ */
196
+ static create(photonCtx) {
197
+ const instance = new _PhotonRequestWrapper(photonCtx);
198
+ return new Proxy(instance, {
199
+ get(target, prop, receiver) {
200
+ if (prop in target) {
201
+ const value2 = Reflect.get(target, prop, receiver);
202
+ if (typeof value2 === "function") {
203
+ return value2.bind(target);
204
+ }
205
+ return value2;
206
+ }
207
+ const nativeReq = target.photonCtx.req;
208
+ if (prop in nativeReq) {
209
+ const value2 = nativeReq[prop];
210
+ if (typeof value2 === "function") {
211
+ return value2.bind(nativeReq);
212
+ }
213
+ return value2;
214
+ }
215
+ return void 0;
216
+ },
217
+ // Allow setting properties (for addValidated etc.)
218
+ set(target, prop, value2) {
219
+ if (prop in target) {
220
+ return Reflect.set(target, prop, value2);
221
+ }
222
+ ;
223
+ target.photonCtx.req[prop] = value2;
224
+ return true;
225
+ }
226
+ });
227
+ }
192
228
  get url() {
193
229
  return this.photonCtx.req.url;
194
230
  }
@@ -247,7 +283,7 @@ var PhotonRequestWrapper = class {
247
283
  var PhotonContextWrapper = class _PhotonContextWrapper {
248
284
  constructor(photonCtx) {
249
285
  this.photonCtx = photonCtx;
250
- this._req = new PhotonRequestWrapper(photonCtx);
286
+ this._req = PhotonRequestWrapper.create(photonCtx);
251
287
  }
252
288
  _req;
253
289
  /**
@@ -359,7 +395,7 @@ function toPhotonMiddleware(middleware) {
359
395
  return async (c, next) => {
360
396
  const ctx = PhotonContextWrapper.create(c);
361
397
  const gravitoNext = async () => {
362
- await next();
398
+ return await next();
363
399
  };
364
400
  return middleware(ctx, gravitoNext);
365
401
  };
@@ -2823,20 +2859,20 @@ var RouteGroup = class _RouteGroup {
2823
2859
  group(callback) {
2824
2860
  callback(this);
2825
2861
  }
2826
- get(path2, requestOrHandler, handler) {
2827
- return this.router.req("get", path2, requestOrHandler, handler, this.options);
2862
+ get(path2, requestOrHandlerOrMiddleware, handler) {
2863
+ return this.router.req("get", path2, requestOrHandlerOrMiddleware, handler, this.options);
2828
2864
  }
2829
- post(path2, requestOrHandler, handler) {
2830
- return this.router.req("post", path2, requestOrHandler, handler, this.options);
2865
+ post(path2, requestOrHandlerOrMiddleware, handler) {
2866
+ return this.router.req("post", path2, requestOrHandlerOrMiddleware, handler, this.options);
2831
2867
  }
2832
- put(path2, requestOrHandler, handler) {
2833
- return this.router.req("put", path2, requestOrHandler, handler, this.options);
2868
+ put(path2, requestOrHandlerOrMiddleware, handler) {
2869
+ return this.router.req("put", path2, requestOrHandlerOrMiddleware, handler, this.options);
2834
2870
  }
2835
- delete(path2, requestOrHandler, handler) {
2836
- return this.router.req("delete", path2, requestOrHandler, handler, this.options);
2871
+ delete(path2, requestOrHandlerOrMiddleware, handler) {
2872
+ return this.router.req("delete", path2, requestOrHandlerOrMiddleware, handler, this.options);
2837
2873
  }
2838
- patch(path2, requestOrHandler, handler) {
2839
- return this.router.req("patch", path2, requestOrHandler, handler, this.options);
2874
+ patch(path2, requestOrHandlerOrMiddleware, handler) {
2875
+ return this.router.req("patch", path2, requestOrHandlerOrMiddleware, handler, this.options);
2840
2876
  }
2841
2877
  resource(name, controller, options = {}) {
2842
2878
  const actions = [
@@ -3012,20 +3048,20 @@ var Router = class {
3012
3048
  middleware(...handlers) {
3013
3049
  return new RouteGroup(this, { middleware: handlers.flat() });
3014
3050
  }
3015
- get(path2, requestOrHandler, handler) {
3016
- return this.req("get", path2, requestOrHandler, handler);
3051
+ get(path2, requestOrHandlerOrMiddleware, handler) {
3052
+ return this.req("get", path2, requestOrHandlerOrMiddleware, handler);
3017
3053
  }
3018
- post(path2, requestOrHandler, handler) {
3019
- return this.req("post", path2, requestOrHandler, handler);
3054
+ post(path2, requestOrHandlerOrMiddleware, handler) {
3055
+ return this.req("post", path2, requestOrHandlerOrMiddleware, handler);
3020
3056
  }
3021
- put(path2, requestOrHandler, handler) {
3022
- return this.req("put", path2, requestOrHandler, handler);
3057
+ put(path2, requestOrHandlerOrMiddleware, handler) {
3058
+ return this.req("put", path2, requestOrHandlerOrMiddleware, handler);
3023
3059
  }
3024
- delete(path2, requestOrHandler, handler) {
3025
- return this.req("delete", path2, requestOrHandler, handler);
3060
+ delete(path2, requestOrHandlerOrMiddleware, handler) {
3061
+ return this.req("delete", path2, requestOrHandlerOrMiddleware, handler);
3026
3062
  }
3027
- patch(path2, requestOrHandler, handler) {
3028
- return this.req("patch", path2, requestOrHandler, handler);
3063
+ patch(path2, requestOrHandlerOrMiddleware, handler) {
3064
+ return this.req("patch", path2, requestOrHandlerOrMiddleware, handler);
3029
3065
  }
3030
3066
  /**
3031
3067
  * Register a resource route (Laravel-style).
@@ -3071,17 +3107,25 @@ var Router = class {
3071
3107
  /**
3072
3108
  * Internal Request Registration
3073
3109
  */
3074
- req(method, path2, requestOrHandler, handler, options = {}) {
3110
+ req(method, path2, requestOrHandlerOrMiddleware, handler, options = {}) {
3075
3111
  const fullPath = (options.prefix || "") + path2;
3076
3112
  let formRequestMiddleware = null;
3113
+ let routeMiddleware = [];
3077
3114
  let finalRouteHandler;
3078
3115
  if (handler !== void 0) {
3079
- if (isFormRequestClass(requestOrHandler)) {
3080
- formRequestMiddleware = formRequestToMiddleware(requestOrHandler);
3116
+ if (isFormRequestClass(requestOrHandlerOrMiddleware)) {
3117
+ formRequestMiddleware = formRequestToMiddleware(requestOrHandlerOrMiddleware);
3118
+ } else {
3119
+ const middleware = requestOrHandlerOrMiddleware;
3120
+ if (Array.isArray(middleware)) {
3121
+ routeMiddleware = middleware;
3122
+ } else {
3123
+ routeMiddleware = [middleware];
3124
+ }
3081
3125
  }
3082
3126
  finalRouteHandler = handler;
3083
3127
  } else {
3084
- finalRouteHandler = requestOrHandler;
3128
+ finalRouteHandler = requestOrHandlerOrMiddleware;
3085
3129
  }
3086
3130
  let resolvedHandler;
3087
3131
  if (Array.isArray(finalRouteHandler)) {
@@ -3097,6 +3141,9 @@ var Router = class {
3097
3141
  if (formRequestMiddleware) {
3098
3142
  handlers.push(formRequestMiddleware);
3099
3143
  }
3144
+ if (routeMiddleware.length > 0) {
3145
+ handlers.push(...routeMiddleware);
3146
+ }
3100
3147
  handlers.push(resolvedHandler);
3101
3148
  if (options.domain) {
3102
3149
  const domainCheck = async (c, next) => {
@@ -3371,8 +3418,7 @@ var PlanetCore = class _PlanetCore {
3371
3418
  const cookieJar = new CookieJar(this.encrypter);
3372
3419
  c.set("cookieJar", cookieJar);
3373
3420
  c.route = (name, params, query) => this.router.url(name, params, query);
3374
- await next();
3375
- return void 0;
3421
+ return await next();
3376
3422
  });
3377
3423
  this.router = new Router(this);
3378
3424
  this.adapter.onError(async (err, c) => {
@@ -4891,7 +4937,7 @@ var AOTRouter = class {
4891
4937
  * @param path - Matched path
4892
4938
  * @returns Route key or null
4893
4939
  */
4894
- findDynamicRouteKey(method, path2) {
4940
+ findDynamicRouteKey(method, _path) {
4895
4941
  for (const key of this.pathMiddleware.keys()) {
4896
4942
  if (key.startsWith(`${method}:`)) {
4897
4943
  return key;
@@ -5022,7 +5068,7 @@ var FastRequestImpl = class {
5022
5068
  };
5023
5069
  var FastContext = class {
5024
5070
  _req = new FastRequestImpl();
5025
- _statusCode = 200;
5071
+ // private _statusCode = 200
5026
5072
  _headers = new Headers();
5027
5073
  // Reuse this object
5028
5074
  /**
@@ -5033,7 +5079,6 @@ var FastContext = class {
5033
5079
  */
5034
5080
  reset(request, params = {}) {
5035
5081
  this._req.reset(request, params);
5036
- this._statusCode = 200;
5037
5082
  this._headers = new Headers();
5038
5083
  return this;
5039
5084
  }
@@ -5083,8 +5128,7 @@ var FastContext = class {
5083
5128
  header(name, value2) {
5084
5129
  this._headers.set(name, value2);
5085
5130
  }
5086
- status(code) {
5087
- this._statusCode = code;
5131
+ status(_code) {
5088
5132
  }
5089
5133
  };
5090
5134
 
@@ -5414,7 +5458,7 @@ var Gravito = class {
5414
5458
  * // Now accessible at /api/users
5415
5459
  * ```
5416
5460
  */
5417
- route(path2, app2) {
5461
+ route(_path, _app) {
5418
5462
  console.warn("route() method is not yet fully implemented");
5419
5463
  return this;
5420
5464
  }
@@ -5619,21 +5663,26 @@ var Gravito = class {
5619
5663
  const next = async () => {
5620
5664
  if (index < middleware.length) {
5621
5665
  const mw = middleware[index++];
5622
- await mw(ctx, next);
5666
+ return await mw(ctx, next);
5623
5667
  }
5668
+ return void 0;
5624
5669
  };
5625
- await next();
5670
+ const result = await next();
5671
+ if (result instanceof Response) {
5672
+ return result;
5673
+ }
5626
5674
  return await handler(ctx);
5627
5675
  }
5628
- /**
5676
+ /*
5629
5677
  * Handle 404 Not Found (Async version for dynamic/middleware paths)
5678
+ * Note: Currently unused as we handle 404s via handleNotFoundSync or inline
5630
5679
  */
5631
- async handleNotFound(ctx) {
5632
- if (this.notFoundHandler) {
5633
- return await this.notFoundHandler(ctx);
5634
- }
5635
- return ctx.json({ error: "Not Found" }, 404);
5636
- }
5680
+ // private async handleNotFound(ctx: FastContext): Promise<Response> {
5681
+ // if (this.notFoundHandler) {
5682
+ // return await this.notFoundHandler(ctx)
5683
+ // }
5684
+ // return ctx.json({ error: 'Not Found' }, 404)
5685
+ // }
5637
5686
  /**
5638
5687
  * Handle errors (Async version for dynamic/middleware paths)
5639
5688
  */
@@ -5683,6 +5732,7 @@ function defineConfig(config2) {
5683
5732
  PhotonRequestWrapper,
5684
5733
  PlanetCore,
5685
5734
  Route,
5735
+ RouteGroup,
5686
5736
  Router,
5687
5737
  ServiceProvider,
5688
5738
  Str,
package/dist/index.d.cts CHANGED
@@ -764,14 +764,19 @@ declare class Route {
764
764
  name(name: string): this;
765
765
  static get(path: string, handler: RouteHandler): Route;
766
766
  static get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
767
+ static get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
767
768
  static post(path: string, handler: RouteHandler): Route;
768
769
  static post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
770
+ static post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
769
771
  static put(path: string, handler: RouteHandler): Route;
770
772
  static put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
773
+ static put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
771
774
  static delete(path: string, handler: RouteHandler): Route;
772
775
  static delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
776
+ static delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
773
777
  static patch(path: string, handler: RouteHandler): Route;
774
778
  static patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
779
+ static patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
775
780
  static resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
776
781
  static prefix(path: string): RouteGroup;
777
782
  static middleware(...handlers: any[]): RouteGroup;
@@ -824,14 +829,19 @@ declare class RouteGroup {
824
829
  group(callback: (router: Router | RouteGroup) => void): void;
825
830
  get(path: string, handler: RouteHandler): Route;
826
831
  get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
832
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
827
833
  post(path: string, handler: RouteHandler): Route;
828
834
  post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
835
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
829
836
  put(path: string, handler: RouteHandler): Route;
830
837
  put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
838
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
831
839
  delete(path: string, handler: RouteHandler): Route;
832
840
  delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
841
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
833
842
  patch(path: string, handler: RouteHandler): Route;
834
843
  patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
844
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
835
845
  resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
836
846
  }
837
847
  /**
@@ -844,6 +854,7 @@ declare class RouteGroup {
844
854
  * - Domain-based routing: router.domain('api.app').group(...)
845
855
  * - Middleware chaining: router.middleware(auth).group(...)
846
856
  * - FormRequest validation: router.post('/users', StoreUserRequest, [UserController, 'store'])
857
+ * - Inline Middleware: router.get('/users', authMiddleware, [UserController, 'index'])
847
858
  */
848
859
  declare class Router {
849
860
  private core;
@@ -911,83 +922,34 @@ declare class Router {
911
922
  middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): RouteGroup;
912
923
  /**
913
924
  * Register a GET route.
914
- *
915
- * @param path - The URL path for the route.
916
- * @param handler - The handler function or controller method.
917
- * @returns The registered Route instance for chaining.
918
- *
919
- * @example
920
- * ```typescript
921
- * router.get('/users', [UserController, 'index']);
922
- * ```
923
925
  */
924
926
  get(path: string, handler: RouteHandler): Route;
925
- /**
926
- * Register a GET route with a FormRequest for validation.
927
- *
928
- * @param path - The URL path.
929
- * @param request - The FormRequest class for validation.
930
- * @param handler - The handler function or controller method.
931
- *
932
- * @example
933
- * ```typescript
934
- * router.get('/search', SearchRequest, [Controller, 'search']);
935
- * ```
936
- */
937
927
  get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
928
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
938
929
  /**
939
930
  * Register a POST route.
940
- *
941
- * @param path - The URL path.
942
- * @param handler - The handler function or controller method.
943
- * @returns The registered Route instance.
944
- *
945
- * @example
946
- * ```typescript
947
- * router.post('/users', [UserController, 'store']);
948
- * ```
949
931
  */
950
932
  post(path: string, handler: RouteHandler): Route;
951
- /**
952
- * Register a POST route with validation.
953
- *
954
- * @param path - The URL path.
955
- * @param request - The FormRequest class.
956
- * @param handler - The handler.
957
- *
958
- * @example
959
- * ```typescript
960
- * router.post('/users', StoreUserRequest, [UserController, 'store']);
961
- * ```
962
- */
963
933
  post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
934
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
964
935
  /**
965
936
  * Register a PUT route.
966
- *
967
- * @param path - The URL path.
968
- * @param handler - The handler function.
969
- * @returns The registered Route instance.
970
937
  */
971
938
  put(path: string, handler: RouteHandler): Route;
972
939
  put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
940
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
973
941
  /**
974
942
  * Register a DELETE route.
975
- *
976
- * @param path - The URL path.
977
- * @param handler - The handler function.
978
- * @returns The registered Route instance.
979
943
  */
980
944
  delete(path: string, handler: RouteHandler): Route;
981
945
  delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
946
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
982
947
  /**
983
948
  * Register a PATCH route.
984
- *
985
- * @param path - The URL path.
986
- * @param handler - The handler function.
987
- * @returns The registered Route instance.
988
949
  */
989
950
  patch(path: string, handler: RouteHandler): Route;
990
951
  patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
952
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
991
953
  /**
992
954
  * Register a resource route (Laravel-style).
993
955
  */
@@ -995,7 +957,7 @@ declare class Router {
995
957
  /**
996
958
  * Internal Request Registration
997
959
  */
998
- req(method: HttpMethod, path: string, requestOrHandler: FormRequestClass | RouteHandler, handler?: RouteHandler, options?: RouteOptions): Route;
960
+ req(method: HttpMethod, path: string, requestOrHandlerOrMiddleware: FormRequestClass | RouteHandler | GravitoMiddleware | GravitoMiddleware[], handler?: RouteHandler, options?: RouteOptions): Route;
999
961
  /**
1000
962
  * Resolve Controller Instance and Method
1001
963
  */
@@ -1273,8 +1235,12 @@ declare class PlanetCore {
1273
1235
  * Wraps Photon's request object to implement GravitoRequest
1274
1236
  */
1275
1237
  declare class PhotonRequestWrapper implements GravitoRequest {
1276
- private photonCtx;
1238
+ readonly photonCtx: Context;
1277
1239
  constructor(photonCtx: Context);
1240
+ /**
1241
+ * Create a proxied instance to delegate to Photon's request
1242
+ */
1243
+ static create(photonCtx: Context): PhotonRequestWrapper;
1278
1244
  get url(): string;
1279
1245
  get method(): string;
1280
1246
  get path(): string;
@@ -2065,7 +2031,7 @@ type Handler = (ctx: FastContext$1) => Response | Promise<Response>;
2065
2031
  /**
2066
2032
  * Middleware function
2067
2033
  */
2068
- type Middleware = (ctx: FastContext$1, next: () => Promise<void>) => void | Promise<void>;
2034
+ type Middleware = (ctx: FastContext$1, next: () => Promise<Response | undefined>) => Response | undefined | Promise<Response | undefined>;
2069
2035
  /**
2070
2036
  * Error handler function
2071
2037
  */
@@ -2214,7 +2180,7 @@ declare class Gravito {
2214
2180
  * // Now accessible at /api/users
2215
2181
  * ```
2216
2182
  */
2217
- route(path: string, app: Gravito): this;
2183
+ route(_path: string, _app: Gravito): this;
2218
2184
  /**
2219
2185
  * Set custom error handler
2220
2186
  *
@@ -2285,10 +2251,6 @@ declare class Gravito {
2285
2251
  * Each middleware can call next() to continue the chain.
2286
2252
  */
2287
2253
  private executeMiddleware;
2288
- /**
2289
- * Handle 404 Not Found (Async version for dynamic/middleware paths)
2290
- */
2291
- private handleNotFound;
2292
2254
  /**
2293
2255
  * Handle errors (Async version for dynamic/middleware paths)
2294
2256
  */
@@ -2429,7 +2391,6 @@ declare class AOTRouter {
2429
2391
  */
2430
2392
  declare class FastContext implements FastContext$1 {
2431
2393
  private _req;
2432
- private _statusCode;
2433
2394
  private _headers;
2434
2395
  /**
2435
2396
  * Reset context for pooling
@@ -2445,7 +2406,7 @@ declare class FastContext implements FastContext$1 {
2445
2406
  redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
2446
2407
  body(data: BodyInit | null, status?: number): Response;
2447
2408
  header(name: string, value: string): void;
2448
- status(code: number): void;
2409
+ status(_code: number): void;
2449
2410
  }
2450
2411
 
2451
2412
  /**
@@ -2659,4 +2620,4 @@ declare const VERSION: string;
2659
2620
  */
2660
2621
  declare function defineConfig(config: GravitoConfig): GravitoConfig;
2661
2622
 
2662
- export { type ActionCallback, type AdapterConfig, type AdapterFactory, type ApiFailure, type ApiSuccess, Application, type ApplicationConfig, Arr, AuthenticationException, AuthorizationException, type BodySizeLimitOptions, type CacheService, type Channel, ConfigManager, ConsoleLogger, Container, ContentfulStatusCode, type ControllerClass, CookieJar, type CookieOptions, type CorsOptions, type CorsOrigin, type CsrfOptions, type DataPath, DumpDieError, type DumpOptions, Encrypter, type EncrypterOptions, type ErrorBag, type ErrorHandlerContext, Event, EventManager, type ExceptionOptions, type Factory, type FilterCallback, type FormRequestClass, type FormRequestLike, type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, GravitoAdapter, type GravitoConfig, GravitoContext, GravitoErrorHandler, GravitoException, GravitoHandler, type GravitoManifest, GravitoMiddleware, GravitoNotFoundHandler, type GravitoOrbit, GravitoRequest, GravitoServer, GravitoVariables, type HeaderTokenGateOptions, HookManager, type HstsOptions, type HttpAdapter, HttpException, HttpMethod, HttpTester, type Listener, type Logger, ModelNotFoundException, type PathSegment, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, PlanetCore, type RegisterGlobalErrorHandlersOptions, type RequireHeaderTokenOptions, Route, type RouteDefinition, type RouteHandler, type RouteOptions, Router, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, type SecurityHeadersOptions, ServiceProvider, type ShouldBroadcast, type ShouldQueue, StatusCode, Str, TestResponse, ThrottleRequests, VERSION, type ValidationError, ValidationException, type ViewService, abort, abortIf, abortUnless, app, blank, bodySizeLimit, config, cors, createErrorBag, createGravitoAdapter, createHeaderGate, createHttpTester, createPhotonAdapter, createSqliteDatabase, csrfProtection, dataGet, dataHas, dataSet, dd, defineConfig, dump, index as engine, env, errors, fail, filled, getCsrfToken, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, hasApp, isHttpAdapter, jsonFail, jsonSuccess, logger, ok, old, registerGlobalErrorHandlers, requireHeaderToken, router, securityHeaders, setApp, tap, throwIf, throwUnless, value };
2623
+ export { type ActionCallback, type AdapterConfig, type AdapterFactory, type ApiFailure, type ApiSuccess, Application, type ApplicationConfig, Arr, AuthenticationException, AuthorizationException, type BodySizeLimitOptions, type CacheService, type Channel, ConfigManager, ConsoleLogger, Container, ContentfulStatusCode, type ControllerClass, CookieJar, type CookieOptions, type CorsOptions, type CorsOrigin, type CsrfOptions, type DataPath, DumpDieError, type DumpOptions, Encrypter, type EncrypterOptions, type ErrorBag, type ErrorHandlerContext, Event, EventManager, type ExceptionOptions, type Factory, type FilterCallback, type FormRequestClass, type FormRequestLike, type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, GravitoAdapter, type GravitoConfig, GravitoContext, GravitoErrorHandler, GravitoException, GravitoHandler, type GravitoManifest, GravitoMiddleware, GravitoNotFoundHandler, type GravitoOrbit, GravitoRequest, GravitoServer, GravitoVariables, type HeaderTokenGateOptions, HookManager, type HstsOptions, type HttpAdapter, HttpException, HttpMethod, HttpTester, type Listener, type Logger, ModelNotFoundException, type PathSegment, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, PlanetCore, type RegisterGlobalErrorHandlersOptions, type RequireHeaderTokenOptions, Route, type RouteDefinition, RouteGroup, type RouteHandler, type RouteOptions, Router, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, type SecurityHeadersOptions, ServiceProvider, type ShouldBroadcast, type ShouldQueue, StatusCode, Str, TestResponse, ThrottleRequests, VERSION, type ValidationError, ValidationException, type ViewService, abort, abortIf, abortUnless, app, blank, bodySizeLimit, config, cors, createErrorBag, createGravitoAdapter, createHeaderGate, createHttpTester, createPhotonAdapter, createSqliteDatabase, csrfProtection, dataGet, dataHas, dataSet, dd, defineConfig, dump, index as engine, env, errors, fail, filled, getCsrfToken, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, hasApp, isHttpAdapter, jsonFail, jsonSuccess, logger, ok, old, registerGlobalErrorHandlers, requireHeaderToken, router, securityHeaders, setApp, tap, throwIf, throwUnless, value };
package/dist/index.d.ts CHANGED
@@ -764,14 +764,19 @@ declare class Route {
764
764
  name(name: string): this;
765
765
  static get(path: string, handler: RouteHandler): Route;
766
766
  static get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
767
+ static get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
767
768
  static post(path: string, handler: RouteHandler): Route;
768
769
  static post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
770
+ static post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
769
771
  static put(path: string, handler: RouteHandler): Route;
770
772
  static put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
773
+ static put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
771
774
  static delete(path: string, handler: RouteHandler): Route;
772
775
  static delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
776
+ static delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
773
777
  static patch(path: string, handler: RouteHandler): Route;
774
778
  static patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
779
+ static patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
775
780
  static resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
776
781
  static prefix(path: string): RouteGroup;
777
782
  static middleware(...handlers: any[]): RouteGroup;
@@ -824,14 +829,19 @@ declare class RouteGroup {
824
829
  group(callback: (router: Router | RouteGroup) => void): void;
825
830
  get(path: string, handler: RouteHandler): Route;
826
831
  get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
832
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
827
833
  post(path: string, handler: RouteHandler): Route;
828
834
  post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
835
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
829
836
  put(path: string, handler: RouteHandler): Route;
830
837
  put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
838
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
831
839
  delete(path: string, handler: RouteHandler): Route;
832
840
  delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
841
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
833
842
  patch(path: string, handler: RouteHandler): Route;
834
843
  patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
844
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
835
845
  resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
836
846
  }
837
847
  /**
@@ -844,6 +854,7 @@ declare class RouteGroup {
844
854
  * - Domain-based routing: router.domain('api.app').group(...)
845
855
  * - Middleware chaining: router.middleware(auth).group(...)
846
856
  * - FormRequest validation: router.post('/users', StoreUserRequest, [UserController, 'store'])
857
+ * - Inline Middleware: router.get('/users', authMiddleware, [UserController, 'index'])
847
858
  */
848
859
  declare class Router {
849
860
  private core;
@@ -911,83 +922,34 @@ declare class Router {
911
922
  middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): RouteGroup;
912
923
  /**
913
924
  * Register a GET route.
914
- *
915
- * @param path - The URL path for the route.
916
- * @param handler - The handler function or controller method.
917
- * @returns The registered Route instance for chaining.
918
- *
919
- * @example
920
- * ```typescript
921
- * router.get('/users', [UserController, 'index']);
922
- * ```
923
925
  */
924
926
  get(path: string, handler: RouteHandler): Route;
925
- /**
926
- * Register a GET route with a FormRequest for validation.
927
- *
928
- * @param path - The URL path.
929
- * @param request - The FormRequest class for validation.
930
- * @param handler - The handler function or controller method.
931
- *
932
- * @example
933
- * ```typescript
934
- * router.get('/search', SearchRequest, [Controller, 'search']);
935
- * ```
936
- */
937
927
  get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
928
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
938
929
  /**
939
930
  * Register a POST route.
940
- *
941
- * @param path - The URL path.
942
- * @param handler - The handler function or controller method.
943
- * @returns The registered Route instance.
944
- *
945
- * @example
946
- * ```typescript
947
- * router.post('/users', [UserController, 'store']);
948
- * ```
949
931
  */
950
932
  post(path: string, handler: RouteHandler): Route;
951
- /**
952
- * Register a POST route with validation.
953
- *
954
- * @param path - The URL path.
955
- * @param request - The FormRequest class.
956
- * @param handler - The handler.
957
- *
958
- * @example
959
- * ```typescript
960
- * router.post('/users', StoreUserRequest, [UserController, 'store']);
961
- * ```
962
- */
963
933
  post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
934
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
964
935
  /**
965
936
  * Register a PUT route.
966
- *
967
- * @param path - The URL path.
968
- * @param handler - The handler function.
969
- * @returns The registered Route instance.
970
937
  */
971
938
  put(path: string, handler: RouteHandler): Route;
972
939
  put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
940
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
973
941
  /**
974
942
  * Register a DELETE route.
975
- *
976
- * @param path - The URL path.
977
- * @param handler - The handler function.
978
- * @returns The registered Route instance.
979
943
  */
980
944
  delete(path: string, handler: RouteHandler): Route;
981
945
  delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
946
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
982
947
  /**
983
948
  * Register a PATCH route.
984
- *
985
- * @param path - The URL path.
986
- * @param handler - The handler function.
987
- * @returns The registered Route instance.
988
949
  */
989
950
  patch(path: string, handler: RouteHandler): Route;
990
951
  patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
952
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
991
953
  /**
992
954
  * Register a resource route (Laravel-style).
993
955
  */
@@ -995,7 +957,7 @@ declare class Router {
995
957
  /**
996
958
  * Internal Request Registration
997
959
  */
998
- req(method: HttpMethod, path: string, requestOrHandler: FormRequestClass | RouteHandler, handler?: RouteHandler, options?: RouteOptions): Route;
960
+ req(method: HttpMethod, path: string, requestOrHandlerOrMiddleware: FormRequestClass | RouteHandler | GravitoMiddleware | GravitoMiddleware[], handler?: RouteHandler, options?: RouteOptions): Route;
999
961
  /**
1000
962
  * Resolve Controller Instance and Method
1001
963
  */
@@ -1273,8 +1235,12 @@ declare class PlanetCore {
1273
1235
  * Wraps Photon's request object to implement GravitoRequest
1274
1236
  */
1275
1237
  declare class PhotonRequestWrapper implements GravitoRequest {
1276
- private photonCtx;
1238
+ readonly photonCtx: Context;
1277
1239
  constructor(photonCtx: Context);
1240
+ /**
1241
+ * Create a proxied instance to delegate to Photon's request
1242
+ */
1243
+ static create(photonCtx: Context): PhotonRequestWrapper;
1278
1244
  get url(): string;
1279
1245
  get method(): string;
1280
1246
  get path(): string;
@@ -2065,7 +2031,7 @@ type Handler = (ctx: FastContext$1) => Response | Promise<Response>;
2065
2031
  /**
2066
2032
  * Middleware function
2067
2033
  */
2068
- type Middleware = (ctx: FastContext$1, next: () => Promise<void>) => void | Promise<void>;
2034
+ type Middleware = (ctx: FastContext$1, next: () => Promise<Response | undefined>) => Response | undefined | Promise<Response | undefined>;
2069
2035
  /**
2070
2036
  * Error handler function
2071
2037
  */
@@ -2214,7 +2180,7 @@ declare class Gravito {
2214
2180
  * // Now accessible at /api/users
2215
2181
  * ```
2216
2182
  */
2217
- route(path: string, app: Gravito): this;
2183
+ route(_path: string, _app: Gravito): this;
2218
2184
  /**
2219
2185
  * Set custom error handler
2220
2186
  *
@@ -2285,10 +2251,6 @@ declare class Gravito {
2285
2251
  * Each middleware can call next() to continue the chain.
2286
2252
  */
2287
2253
  private executeMiddleware;
2288
- /**
2289
- * Handle 404 Not Found (Async version for dynamic/middleware paths)
2290
- */
2291
- private handleNotFound;
2292
2254
  /**
2293
2255
  * Handle errors (Async version for dynamic/middleware paths)
2294
2256
  */
@@ -2429,7 +2391,6 @@ declare class AOTRouter {
2429
2391
  */
2430
2392
  declare class FastContext implements FastContext$1 {
2431
2393
  private _req;
2432
- private _statusCode;
2433
2394
  private _headers;
2434
2395
  /**
2435
2396
  * Reset context for pooling
@@ -2445,7 +2406,7 @@ declare class FastContext implements FastContext$1 {
2445
2406
  redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
2446
2407
  body(data: BodyInit | null, status?: number): Response;
2447
2408
  header(name: string, value: string): void;
2448
- status(code: number): void;
2409
+ status(_code: number): void;
2449
2410
  }
2450
2411
 
2451
2412
  /**
@@ -2659,4 +2620,4 @@ declare const VERSION: string;
2659
2620
  */
2660
2621
  declare function defineConfig(config: GravitoConfig): GravitoConfig;
2661
2622
 
2662
- export { type ActionCallback, type AdapterConfig, type AdapterFactory, type ApiFailure, type ApiSuccess, Application, type ApplicationConfig, Arr, AuthenticationException, AuthorizationException, type BodySizeLimitOptions, type CacheService, type Channel, ConfigManager, ConsoleLogger, Container, ContentfulStatusCode, type ControllerClass, CookieJar, type CookieOptions, type CorsOptions, type CorsOrigin, type CsrfOptions, type DataPath, DumpDieError, type DumpOptions, Encrypter, type EncrypterOptions, type ErrorBag, type ErrorHandlerContext, Event, EventManager, type ExceptionOptions, type Factory, type FilterCallback, type FormRequestClass, type FormRequestLike, type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, GravitoAdapter, type GravitoConfig, GravitoContext, GravitoErrorHandler, GravitoException, GravitoHandler, type GravitoManifest, GravitoMiddleware, GravitoNotFoundHandler, type GravitoOrbit, GravitoRequest, GravitoServer, GravitoVariables, type HeaderTokenGateOptions, HookManager, type HstsOptions, type HttpAdapter, HttpException, HttpMethod, HttpTester, type Listener, type Logger, ModelNotFoundException, type PathSegment, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, PlanetCore, type RegisterGlobalErrorHandlersOptions, type RequireHeaderTokenOptions, Route, type RouteDefinition, type RouteHandler, type RouteOptions, Router, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, type SecurityHeadersOptions, ServiceProvider, type ShouldBroadcast, type ShouldQueue, StatusCode, Str, TestResponse, ThrottleRequests, VERSION, type ValidationError, ValidationException, type ViewService, abort, abortIf, abortUnless, app, blank, bodySizeLimit, config, cors, createErrorBag, createGravitoAdapter, createHeaderGate, createHttpTester, createPhotonAdapter, createSqliteDatabase, csrfProtection, dataGet, dataHas, dataSet, dd, defineConfig, dump, index as engine, env, errors, fail, filled, getCsrfToken, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, hasApp, isHttpAdapter, jsonFail, jsonSuccess, logger, ok, old, registerGlobalErrorHandlers, requireHeaderToken, router, securityHeaders, setApp, tap, throwIf, throwUnless, value };
2623
+ export { type ActionCallback, type AdapterConfig, type AdapterFactory, type ApiFailure, type ApiSuccess, Application, type ApplicationConfig, Arr, AuthenticationException, AuthorizationException, type BodySizeLimitOptions, type CacheService, type Channel, ConfigManager, ConsoleLogger, Container, ContentfulStatusCode, type ControllerClass, CookieJar, type CookieOptions, type CorsOptions, type CorsOrigin, type CsrfOptions, type DataPath, DumpDieError, type DumpOptions, Encrypter, type EncrypterOptions, type ErrorBag, type ErrorHandlerContext, Event, EventManager, type ExceptionOptions, type Factory, type FilterCallback, type FormRequestClass, type FormRequestLike, type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, GravitoAdapter, type GravitoConfig, GravitoContext, GravitoErrorHandler, GravitoException, GravitoHandler, type GravitoManifest, GravitoMiddleware, GravitoNotFoundHandler, type GravitoOrbit, GravitoRequest, GravitoServer, GravitoVariables, type HeaderTokenGateOptions, HookManager, type HstsOptions, type HttpAdapter, HttpException, HttpMethod, HttpTester, type Listener, type Logger, ModelNotFoundException, type PathSegment, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, PlanetCore, type RegisterGlobalErrorHandlersOptions, type RequireHeaderTokenOptions, Route, type RouteDefinition, RouteGroup, type RouteHandler, type RouteOptions, Router, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, type SecurityHeadersOptions, ServiceProvider, type ShouldBroadcast, type ShouldQueue, StatusCode, Str, TestResponse, ThrottleRequests, VERSION, type ValidationError, ValidationException, type ViewService, abort, abortIf, abortUnless, app, blank, bodySizeLimit, config, cors, createErrorBag, createGravitoAdapter, createHeaderGate, createHttpTester, createPhotonAdapter, createSqliteDatabase, csrfProtection, dataGet, dataHas, dataSet, dd, defineConfig, dump, index as engine, env, errors, fail, filled, getCsrfToken, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, hasApp, isHttpAdapter, jsonFail, jsonSuccess, logger, ok, old, registerGlobalErrorHandlers, requireHeaderToken, router, securityHeaders, setApp, tap, throwIf, throwUnless, value };
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ var __export = (target, all) => {
13
13
  // package.json
14
14
  var package_default = {
15
15
  name: "@gravito/core",
16
- version: "1.1.0",
16
+ version: "1.2.0",
17
17
  description: "",
18
18
  module: "./dist/index.js",
19
19
  main: "./dist/index.cjs",
@@ -85,10 +85,45 @@ var package_default = {
85
85
  };
86
86
 
87
87
  // src/adapters/PhotonAdapter.ts
88
- var PhotonRequestWrapper = class {
88
+ var PhotonRequestWrapper = class _PhotonRequestWrapper {
89
89
  constructor(photonCtx) {
90
90
  this.photonCtx = photonCtx;
91
91
  }
92
+ /**
93
+ * Create a proxied instance to delegate to Photon's request
94
+ */
95
+ static create(photonCtx) {
96
+ const instance = new _PhotonRequestWrapper(photonCtx);
97
+ return new Proxy(instance, {
98
+ get(target, prop, receiver) {
99
+ if (prop in target) {
100
+ const value2 = Reflect.get(target, prop, receiver);
101
+ if (typeof value2 === "function") {
102
+ return value2.bind(target);
103
+ }
104
+ return value2;
105
+ }
106
+ const nativeReq = target.photonCtx.req;
107
+ if (prop in nativeReq) {
108
+ const value2 = nativeReq[prop];
109
+ if (typeof value2 === "function") {
110
+ return value2.bind(nativeReq);
111
+ }
112
+ return value2;
113
+ }
114
+ return void 0;
115
+ },
116
+ // Allow setting properties (for addValidated etc.)
117
+ set(target, prop, value2) {
118
+ if (prop in target) {
119
+ return Reflect.set(target, prop, value2);
120
+ }
121
+ ;
122
+ target.photonCtx.req[prop] = value2;
123
+ return true;
124
+ }
125
+ });
126
+ }
92
127
  get url() {
93
128
  return this.photonCtx.req.url;
94
129
  }
@@ -147,7 +182,7 @@ var PhotonRequestWrapper = class {
147
182
  var PhotonContextWrapper = class _PhotonContextWrapper {
148
183
  constructor(photonCtx) {
149
184
  this.photonCtx = photonCtx;
150
- this._req = new PhotonRequestWrapper(photonCtx);
185
+ this._req = PhotonRequestWrapper.create(photonCtx);
151
186
  }
152
187
  _req;
153
188
  /**
@@ -259,7 +294,7 @@ function toPhotonMiddleware(middleware) {
259
294
  return async (c, next) => {
260
295
  const ctx = PhotonContextWrapper.create(c);
261
296
  const gravitoNext = async () => {
262
- await next();
297
+ return await next();
263
298
  };
264
299
  return middleware(ctx, gravitoNext);
265
300
  };
@@ -2722,20 +2757,20 @@ var RouteGroup = class _RouteGroup {
2722
2757
  group(callback) {
2723
2758
  callback(this);
2724
2759
  }
2725
- get(path2, requestOrHandler, handler) {
2726
- return this.router.req("get", path2, requestOrHandler, handler, this.options);
2760
+ get(path2, requestOrHandlerOrMiddleware, handler) {
2761
+ return this.router.req("get", path2, requestOrHandlerOrMiddleware, handler, this.options);
2727
2762
  }
2728
- post(path2, requestOrHandler, handler) {
2729
- return this.router.req("post", path2, requestOrHandler, handler, this.options);
2763
+ post(path2, requestOrHandlerOrMiddleware, handler) {
2764
+ return this.router.req("post", path2, requestOrHandlerOrMiddleware, handler, this.options);
2730
2765
  }
2731
- put(path2, requestOrHandler, handler) {
2732
- return this.router.req("put", path2, requestOrHandler, handler, this.options);
2766
+ put(path2, requestOrHandlerOrMiddleware, handler) {
2767
+ return this.router.req("put", path2, requestOrHandlerOrMiddleware, handler, this.options);
2733
2768
  }
2734
- delete(path2, requestOrHandler, handler) {
2735
- return this.router.req("delete", path2, requestOrHandler, handler, this.options);
2769
+ delete(path2, requestOrHandlerOrMiddleware, handler) {
2770
+ return this.router.req("delete", path2, requestOrHandlerOrMiddleware, handler, this.options);
2736
2771
  }
2737
- patch(path2, requestOrHandler, handler) {
2738
- return this.router.req("patch", path2, requestOrHandler, handler, this.options);
2772
+ patch(path2, requestOrHandlerOrMiddleware, handler) {
2773
+ return this.router.req("patch", path2, requestOrHandlerOrMiddleware, handler, this.options);
2739
2774
  }
2740
2775
  resource(name, controller, options = {}) {
2741
2776
  const actions = [
@@ -2911,20 +2946,20 @@ var Router = class {
2911
2946
  middleware(...handlers) {
2912
2947
  return new RouteGroup(this, { middleware: handlers.flat() });
2913
2948
  }
2914
- get(path2, requestOrHandler, handler) {
2915
- return this.req("get", path2, requestOrHandler, handler);
2949
+ get(path2, requestOrHandlerOrMiddleware, handler) {
2950
+ return this.req("get", path2, requestOrHandlerOrMiddleware, handler);
2916
2951
  }
2917
- post(path2, requestOrHandler, handler) {
2918
- return this.req("post", path2, requestOrHandler, handler);
2952
+ post(path2, requestOrHandlerOrMiddleware, handler) {
2953
+ return this.req("post", path2, requestOrHandlerOrMiddleware, handler);
2919
2954
  }
2920
- put(path2, requestOrHandler, handler) {
2921
- return this.req("put", path2, requestOrHandler, handler);
2955
+ put(path2, requestOrHandlerOrMiddleware, handler) {
2956
+ return this.req("put", path2, requestOrHandlerOrMiddleware, handler);
2922
2957
  }
2923
- delete(path2, requestOrHandler, handler) {
2924
- return this.req("delete", path2, requestOrHandler, handler);
2958
+ delete(path2, requestOrHandlerOrMiddleware, handler) {
2959
+ return this.req("delete", path2, requestOrHandlerOrMiddleware, handler);
2925
2960
  }
2926
- patch(path2, requestOrHandler, handler) {
2927
- return this.req("patch", path2, requestOrHandler, handler);
2961
+ patch(path2, requestOrHandlerOrMiddleware, handler) {
2962
+ return this.req("patch", path2, requestOrHandlerOrMiddleware, handler);
2928
2963
  }
2929
2964
  /**
2930
2965
  * Register a resource route (Laravel-style).
@@ -2970,17 +3005,25 @@ var Router = class {
2970
3005
  /**
2971
3006
  * Internal Request Registration
2972
3007
  */
2973
- req(method, path2, requestOrHandler, handler, options = {}) {
3008
+ req(method, path2, requestOrHandlerOrMiddleware, handler, options = {}) {
2974
3009
  const fullPath = (options.prefix || "") + path2;
2975
3010
  let formRequestMiddleware = null;
3011
+ let routeMiddleware = [];
2976
3012
  let finalRouteHandler;
2977
3013
  if (handler !== void 0) {
2978
- if (isFormRequestClass(requestOrHandler)) {
2979
- formRequestMiddleware = formRequestToMiddleware(requestOrHandler);
3014
+ if (isFormRequestClass(requestOrHandlerOrMiddleware)) {
3015
+ formRequestMiddleware = formRequestToMiddleware(requestOrHandlerOrMiddleware);
3016
+ } else {
3017
+ const middleware = requestOrHandlerOrMiddleware;
3018
+ if (Array.isArray(middleware)) {
3019
+ routeMiddleware = middleware;
3020
+ } else {
3021
+ routeMiddleware = [middleware];
3022
+ }
2980
3023
  }
2981
3024
  finalRouteHandler = handler;
2982
3025
  } else {
2983
- finalRouteHandler = requestOrHandler;
3026
+ finalRouteHandler = requestOrHandlerOrMiddleware;
2984
3027
  }
2985
3028
  let resolvedHandler;
2986
3029
  if (Array.isArray(finalRouteHandler)) {
@@ -2996,6 +3039,9 @@ var Router = class {
2996
3039
  if (formRequestMiddleware) {
2997
3040
  handlers.push(formRequestMiddleware);
2998
3041
  }
3042
+ if (routeMiddleware.length > 0) {
3043
+ handlers.push(...routeMiddleware);
3044
+ }
2999
3045
  handlers.push(resolvedHandler);
3000
3046
  if (options.domain) {
3001
3047
  const domainCheck = async (c, next) => {
@@ -3270,8 +3316,7 @@ var PlanetCore = class _PlanetCore {
3270
3316
  const cookieJar = new CookieJar(this.encrypter);
3271
3317
  c.set("cookieJar", cookieJar);
3272
3318
  c.route = (name, params, query) => this.router.url(name, params, query);
3273
- await next();
3274
- return void 0;
3319
+ return await next();
3275
3320
  });
3276
3321
  this.router = new Router(this);
3277
3322
  this.adapter.onError(async (err, c) => {
@@ -4790,7 +4835,7 @@ var AOTRouter = class {
4790
4835
  * @param path - Matched path
4791
4836
  * @returns Route key or null
4792
4837
  */
4793
- findDynamicRouteKey(method, path2) {
4838
+ findDynamicRouteKey(method, _path) {
4794
4839
  for (const key of this.pathMiddleware.keys()) {
4795
4840
  if (key.startsWith(`${method}:`)) {
4796
4841
  return key;
@@ -4921,7 +4966,7 @@ var FastRequestImpl = class {
4921
4966
  };
4922
4967
  var FastContext = class {
4923
4968
  _req = new FastRequestImpl();
4924
- _statusCode = 200;
4969
+ // private _statusCode = 200
4925
4970
  _headers = new Headers();
4926
4971
  // Reuse this object
4927
4972
  /**
@@ -4932,7 +4977,6 @@ var FastContext = class {
4932
4977
  */
4933
4978
  reset(request, params = {}) {
4934
4979
  this._req.reset(request, params);
4935
- this._statusCode = 200;
4936
4980
  this._headers = new Headers();
4937
4981
  return this;
4938
4982
  }
@@ -4982,8 +5026,7 @@ var FastContext = class {
4982
5026
  header(name, value2) {
4983
5027
  this._headers.set(name, value2);
4984
5028
  }
4985
- status(code) {
4986
- this._statusCode = code;
5029
+ status(_code) {
4987
5030
  }
4988
5031
  };
4989
5032
 
@@ -5313,7 +5356,7 @@ var Gravito = class {
5313
5356
  * // Now accessible at /api/users
5314
5357
  * ```
5315
5358
  */
5316
- route(path2, app2) {
5359
+ route(_path, _app) {
5317
5360
  console.warn("route() method is not yet fully implemented");
5318
5361
  return this;
5319
5362
  }
@@ -5518,21 +5561,26 @@ var Gravito = class {
5518
5561
  const next = async () => {
5519
5562
  if (index < middleware.length) {
5520
5563
  const mw = middleware[index++];
5521
- await mw(ctx, next);
5564
+ return await mw(ctx, next);
5522
5565
  }
5566
+ return void 0;
5523
5567
  };
5524
- await next();
5568
+ const result = await next();
5569
+ if (result instanceof Response) {
5570
+ return result;
5571
+ }
5525
5572
  return await handler(ctx);
5526
5573
  }
5527
- /**
5574
+ /*
5528
5575
  * Handle 404 Not Found (Async version for dynamic/middleware paths)
5576
+ * Note: Currently unused as we handle 404s via handleNotFoundSync or inline
5529
5577
  */
5530
- async handleNotFound(ctx) {
5531
- if (this.notFoundHandler) {
5532
- return await this.notFoundHandler(ctx);
5533
- }
5534
- return ctx.json({ error: "Not Found" }, 404);
5535
- }
5578
+ // private async handleNotFound(ctx: FastContext): Promise<Response> {
5579
+ // if (this.notFoundHandler) {
5580
+ // return await this.notFoundHandler(ctx)
5581
+ // }
5582
+ // return ctx.json({ error: 'Not Found' }, 404)
5583
+ // }
5536
5584
  /**
5537
5585
  * Handle errors (Async version for dynamic/middleware paths)
5538
5586
  */
@@ -5581,6 +5629,7 @@ export {
5581
5629
  PhotonRequestWrapper,
5582
5630
  PlanetCore,
5583
5631
  Route,
5632
+ RouteGroup,
5584
5633
  Router,
5585
5634
  ServiceProvider,
5586
5635
  Str,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "module": "./dist/index.js",
6
6
  "main": "./dist/index.cjs",