moost 0.6.4 → 0.6.6

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
@@ -248,14 +248,16 @@ const scopeVarsMap = /* @__PURE__ */ new Map();
248
248
  const controllerInstanceKey = (0, __wooksjs_event_core.key)("controller.instance");
249
249
  const controllerMethodKey = (0, __wooksjs_event_core.key)("controller.method");
250
250
  const controllerRouteKey = (0, __wooksjs_event_core.key)("controller.route");
251
+ const controllerPrefixKey = (0, __wooksjs_event_core.key)("controller.prefix");
251
252
  /**
252
253
  * Sets the controller context for the current event scope.
253
254
  * Called internally by adapters when dispatching events to handlers.
254
- */ function setControllerContext(controller, method, route, ctx) {
255
- const _ctx = ctx || (0, __wooksjs_event_core.current)();
255
+ */ function setControllerContext(controller, method, route, opts) {
256
+ const _ctx = opts?.ctx || (0, __wooksjs_event_core.current)();
256
257
  _ctx.set(controllerInstanceKey, controller);
257
258
  _ctx.set(controllerMethodKey, method);
258
259
  _ctx.set(controllerRouteKey, route);
260
+ if (opts?.prefix !== void 0) _ctx.set(controllerPrefixKey, opts.prefix);
259
261
  }
260
262
  /**
261
263
  * Provides access to the current controller context within an event handler.
@@ -265,6 +267,7 @@ const controllerRouteKey = (0, __wooksjs_event_core.key)("controller.route");
265
267
  const getController = () => _ctx.get(controllerInstanceKey);
266
268
  const getMethod = () => _ctx.get(controllerMethodKey);
267
269
  const getRoute = () => _ctx.get(controllerRouteKey);
270
+ const getPrefix = () => _ctx.get(controllerPrefixKey);
268
271
  const getControllerMeta = () => getMoostMate().read(getController());
269
272
  const getMethodMeta = (name) => getMoostMate().read(getController(), name || getMethod());
270
273
  function instantiate(c) {
@@ -273,6 +276,7 @@ const controllerRouteKey = (0, __wooksjs_event_core.key)("controller.route");
273
276
  return {
274
277
  instantiate,
275
278
  getRoute,
279
+ getPrefix,
276
280
  getController,
277
281
  getMethod,
278
282
  getControllerMeta,
@@ -370,7 +374,7 @@ function nextScopeId() {
370
374
  }
371
375
  function afterInstance(instance) {
372
376
  if (instance) {
373
- setControllerContext(instance, options.controllerMethod || "", options.targetPath);
377
+ setControllerContext(instance, options.controllerMethod || "", options.targetPath, { prefix: options.controllerPrefix });
374
378
  ci?.hook(options.handlerType, "Controller:registered");
375
379
  }
376
380
  interceptorHandler = options.getIterceptorHandler();
@@ -1512,6 +1516,8 @@ function _define_property(obj, key$3, value) {
1512
1516
  const classMeta = mate$1.read(controller);
1513
1517
  const infact = getMoostInfact();
1514
1518
  const isControllerConsructor = (0, __prostojs_mate.isConstructor)(controller);
1519
+ const ownPrefix = typeof replaceOwnPrefix === "string" ? replaceOwnPrefix : classMeta?.controller?.prefix || "";
1520
+ const computedPrefix = `${globalPrefix}/${ownPrefix}`;
1515
1521
  const pipes = mergeSorted(this.pipes, classMeta?.pipes);
1516
1522
  let instance;
1517
1523
  const infactOpts = {
@@ -1520,7 +1526,7 @@ function _define_property(obj, key$3, value) {
1520
1526
  customData: { pipes }
1521
1527
  };
1522
1528
  if (isControllerConsructor && (classMeta?.injectable === "SINGLETON" || classMeta?.injectable === true)) await (0, __wooksjs_event_core.createEventContext)({ logger: this.logger }, async () => {
1523
- setControllerContext(this, "bindController", "");
1529
+ setControllerContext(this, "bindController", "", { prefix: computedPrefix });
1524
1530
  instance = await infact.get(controller, infactOpts);
1525
1531
  });
1526
1532
  else if (!isControllerConsructor) {
package/dist/index.d.ts CHANGED
@@ -577,6 +577,7 @@ interface TMoostEventHandlerOptions<T> {
577
577
  end?: (opts: TMoostEventHandlerHookOptions<T>) => unknown;
578
578
  };
579
579
  targetPath: string;
580
+ controllerPrefix?: string;
580
581
  handlerType: string;
581
582
  }
582
583
  /** Composable returning the moost scope ID for the current event. Generates on first call, caches for subsequent calls. */
@@ -774,7 +775,10 @@ interface TMoostAdapter<H> {
774
775
  * Sets the controller context for the current event scope.
775
776
  * Called internally by adapters when dispatching events to handlers.
776
777
  */
777
- declare function setControllerContext<T>(controller: T, method: keyof T, route: string, ctx?: EventContext): void;
778
+ declare function setControllerContext<T>(controller: T, method: keyof T, route: string, opts?: {
779
+ prefix?: string;
780
+ ctx?: EventContext;
781
+ }): void;
778
782
  /**
779
783
  * Provides access to the current controller context within an event handler.
780
784
  * Returns utilities for accessing the controller instance, method metadata, and DI.
@@ -782,6 +786,7 @@ declare function setControllerContext<T>(controller: T, method: keyof T, route:
782
786
  declare function useControllerContext<T extends object>(ctx?: EventContext): {
783
787
  instantiate: <TT>(c: TClassConstructor<TT>) => Promise<TT>;
784
788
  getRoute: () => string;
789
+ getPrefix: () => string;
785
790
  getController: () => T;
786
791
  getMethod: () => string | undefined;
787
792
  getControllerMeta: <TT extends object>() => (TMoostMetadata<TEmpty> & TT & {
package/dist/index.mjs CHANGED
@@ -225,14 +225,16 @@ const scopeVarsMap = /* @__PURE__ */ new Map();
225
225
  const controllerInstanceKey = key$1("controller.instance");
226
226
  const controllerMethodKey = key$1("controller.method");
227
227
  const controllerRouteKey = key$1("controller.route");
228
+ const controllerPrefixKey = key$1("controller.prefix");
228
229
  /**
229
230
  * Sets the controller context for the current event scope.
230
231
  * Called internally by adapters when dispatching events to handlers.
231
- */ function setControllerContext(controller, method, route, ctx) {
232
- const _ctx = ctx || current$1();
232
+ */ function setControllerContext(controller, method, route, opts) {
233
+ const _ctx = opts?.ctx || current$1();
233
234
  _ctx.set(controllerInstanceKey, controller);
234
235
  _ctx.set(controllerMethodKey, method);
235
236
  _ctx.set(controllerRouteKey, route);
237
+ if (opts?.prefix !== void 0) _ctx.set(controllerPrefixKey, opts.prefix);
236
238
  }
237
239
  /**
238
240
  * Provides access to the current controller context within an event handler.
@@ -242,6 +244,7 @@ const controllerRouteKey = key$1("controller.route");
242
244
  const getController = () => _ctx.get(controllerInstanceKey);
243
245
  const getMethod = () => _ctx.get(controllerMethodKey);
244
246
  const getRoute = () => _ctx.get(controllerRouteKey);
247
+ const getPrefix = () => _ctx.get(controllerPrefixKey);
245
248
  const getControllerMeta = () => getMoostMate().read(getController());
246
249
  const getMethodMeta = (name) => getMoostMate().read(getController(), name || getMethod());
247
250
  function instantiate(c) {
@@ -250,6 +253,7 @@ const controllerRouteKey = key$1("controller.route");
250
253
  return {
251
254
  instantiate,
252
255
  getRoute,
256
+ getPrefix,
253
257
  getController,
254
258
  getMethod,
255
259
  getControllerMeta,
@@ -347,7 +351,7 @@ function nextScopeId() {
347
351
  }
348
352
  function afterInstance(instance) {
349
353
  if (instance) {
350
- setControllerContext(instance, options.controllerMethod || "", options.targetPath);
354
+ setControllerContext(instance, options.controllerMethod || "", options.targetPath, { prefix: options.controllerPrefix });
351
355
  ci?.hook(options.handlerType, "Controller:registered");
352
356
  }
353
357
  interceptorHandler = options.getIterceptorHandler();
@@ -1489,6 +1493,8 @@ function _define_property(obj, key$2, value) {
1489
1493
  const classMeta = mate$1.read(controller);
1490
1494
  const infact = getMoostInfact();
1491
1495
  const isControllerConsructor = isConstructor$1(controller);
1496
+ const ownPrefix = typeof replaceOwnPrefix === "string" ? replaceOwnPrefix : classMeta?.controller?.prefix || "";
1497
+ const computedPrefix = `${globalPrefix}/${ownPrefix}`;
1492
1498
  const pipes = mergeSorted(this.pipes, classMeta?.pipes);
1493
1499
  let instance;
1494
1500
  const infactOpts = {
@@ -1497,7 +1503,7 @@ function _define_property(obj, key$2, value) {
1497
1503
  customData: { pipes }
1498
1504
  };
1499
1505
  if (isControllerConsructor && (classMeta?.injectable === "SINGLETON" || classMeta?.injectable === true)) await createEventContext$1({ logger: this.logger }, async () => {
1500
- setControllerContext(this, "bindController", "");
1506
+ setControllerContext(this, "bindController", "", { prefix: computedPrefix });
1501
1507
  instance = await infact.get(controller, infactOpts);
1502
1508
  });
1503
1509
  else if (!isControllerConsructor) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moost",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "moost",
5
5
  "keywords": [
6
6
  "composables",
@@ -46,15 +46,15 @@
46
46
  "@prostojs/infact": "^0.4.1",
47
47
  "@prostojs/logger": "^0.4.3",
48
48
  "@prostojs/mate": "^0.4.0",
49
- "@wooksjs/event-core": "^0.7.7",
49
+ "@wooksjs/event-core": "^0.7.8",
50
50
  "hookable": "^5.5.3",
51
- "wooks": "^0.7.7"
51
+ "wooks": "^0.7.8"
52
52
  },
53
53
  "devDependencies": {
54
- "@wooksjs/event-http": "^0.7.7",
55
- "@wooksjs/http-body": "^0.7.7",
54
+ "@wooksjs/event-http": "^0.7.8",
55
+ "@wooksjs/http-body": "^0.7.8",
56
56
  "vitest": "3.2.4",
57
- "@moostjs/event-http": "^0.6.4"
57
+ "@moostjs/event-http": "^0.6.6"
58
58
  },
59
59
  "scripts": {
60
60
  "pub": "pnpm publish --access public",