moost 0.2.32 → 0.2.34

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/README.md CHANGED
@@ -9,51 +9,41 @@
9
9
  </a>
10
10
  </p>
11
11
 
12
- Moost is a Metadata driven Web App Framework inspired by [nestjs](https://nestjs.com/) and powered by [wooks](https://github.com/wooksjs/wooks).
12
+ Welcome to Moostjs, a metadata-driven Event Processing Framework inspired by [NestJS](https://nestjs.com/) and powered by [Wooks](https://wooks.moost.org). While Moost is currently a work-in-progress library, we're excited about its potential and invite you to explore, experiment, and contribute to its development.
13
13
 
14
- The main ideas behind Moost are:
14
+ **Note:** As Moostjs is under active development, breaking changes can be expected.
15
15
 
16
- 1. Use the power of TS decorators to describe your app
17
- 2. Use the power of [wooks](https://github.com/wooksjs/wooks) to process events
18
- 3. Make it easier to control dependency injections
19
- 4. Use as less external dependencies as possible
16
+ ## Motivation
20
17
 
21
- What's the difference to [nestjs](https://nestjs.com/)?
18
+ Moostjs emerged from the belief that TypeScript decorators could significantly simplify application design. By employing the robust event processing capabilities of Wooks, the efficiency of dependency injections, and minimizing external dependencies, Moostjs aims to provide a streamlined, intuitive framework for web app development.
22
19
 
23
- 1. It does not use additional `modules` abstraction
24
- 2. It utilizes reusable dependency injection framework [@prostojs/infact](https://github.com/prostojs/infact)
25
- 3. It uses metadata layer powered by [@prostojs/mate](https://github.com/prostojs/mate)
26
- 4. It supports DTOs and validations powered by [@prostojs/valido](https://github.com/prostojs/valido)
27
- 5. It does not use express or fastify (although you can use express/fastify with an adapter)
28
- 6. Currently it does not support any of additional techniques (like ORMs, Queues etc.)
20
+ Here's what sets Moost apart from NestJS:
29
21
 
30
- ## Quick Start
22
+ 1. Abstraction of `modules` is not used, promoting a simpler architecture.
23
+ 2. Utilizes the reusable dependency injection framework [@prostojs/infact](https://github.com/prostojs/infact).
24
+ 3. Uses a metadata layer powered by [@prostojs/mate](https://github.com/prostojs/mate).
25
+ 4. Supports DTOs and validations powered by [@prostojs/valido](https://github.com/prostojs/valido).
26
+ 5. Does not use Express or Fastify, but these can be employed with an adapter.
27
+ 6. Currently, Moost does not support additional techniques like ORMs, Queues, etc.
31
28
 
32
- ### An example with [@moostjs/event-http](https://github.com/moostjs/moostjs/tree/main/packages/event-http) adapter
29
+ ## [Official Documentation](https://moost.org/)
33
30
 
34
- ```ts
35
- import { MoostHttp, Get } from '@moostjs/event-http'
36
- import { Moost, Param } from 'moost'
31
+ ## Contributing
37
32
 
38
- class MyServer extends Moost {
39
- @Get('test/:name')
40
- test(@Param('name') name: string) {
41
- return { message: `Hello ${name}!` }
42
- }
43
- }
33
+ We are excited to welcome contributors who are passionate about improving Moostjs. No matter your level of experience, your unique perspective and skills can make valuable contributions to our growing community.
44
34
 
45
- const app = new MyServer()
46
- const http = new MoostHttp()
47
- app.adapter(http).listen(3000, () => {
48
- app.getLogger('MyApp').log('Up on port 3000')
49
- })
50
- app.init()
51
- // curl http://localhost:3000/test/World
52
- // {"message":"Hello World!"}
53
- ```
35
+ Here are some basic steps to get you started:
54
36
 
55
- ## Install
37
+ 1. **Fork the Repo:** Navigate to [moostjs](https://github.com/moostjs/moostjs) and fork the repository to your own GitHub account.
56
38
 
57
- `npm install moost @moostjs/event-http`
39
+ 2. **Clone the Repo:** Clone the forked repository to your local machine.
58
40
 
59
- ## To be Documented...
41
+ 3. **Create a Branch:** Make a new branch for your feature or bug fix.
42
+
43
+ 4. **Make your Changes:** Implement your feature or fix the bug and commit the changes to your branch.
44
+
45
+ 5. **Make a Pull Request:** Navigate back to your forked repo and press the "New pull request" button.
46
+
47
+ Don't hesitate to ask for help if you need it. We believe in fostering a friendly and respectful environment for all contributors.
48
+
49
+ Thank you for your interest in Moostjs. We look forward to building something amazing together!
package/dist/index.cjs CHANGED
@@ -3,7 +3,6 @@
3
3
  var mate$1 = require('@prostojs/mate');
4
4
  var infact$1 = require('@prostojs/infact');
5
5
  var eventCore = require('@wooksjs/event-core');
6
- var valido$1 = require('@prostojs/valido');
7
6
  var logger = require('@prostojs/logger');
8
7
 
9
8
  /******************************************************************************
@@ -83,11 +82,15 @@ function getNewMoostInfact() {
83
82
  };
84
83
  return infactMeta;
85
84
  },
86
- resolveParam({ paramMeta, classMeta, customData }) {
85
+ resolveParam({ paramMeta, classMeta, customData, classConstructor, index }) {
87
86
  if (paramMeta && customData && customData.pipes) {
88
87
  return runPipes(customData.pipes, undefined, {
89
88
  paramMeta,
89
+ type: classConstructor,
90
+ key: 'constructor',
90
91
  classMeta: classMeta,
92
+ index,
93
+ targetMeta: paramMeta,
91
94
  }, 'PARAM');
92
95
  }
93
96
  },
@@ -95,12 +98,14 @@ function getNewMoostInfact() {
95
98
  const meta = getMoostMate().read(classConstructor, key);
96
99
  return meta;
97
100
  },
98
- resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, }) {
101
+ resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, classConstructor, }) {
99
102
  if (propMeta && customData && customData.pipes) {
100
103
  return runPipes(customData.pipes, initialValue, {
101
104
  instance,
105
+ type: classConstructor,
102
106
  key,
103
107
  propMeta,
108
+ targetMeta: propMeta,
104
109
  classMeta: classMeta,
105
110
  }, 'PROP');
106
111
  }
@@ -265,8 +270,15 @@ function bindControllerMethods(options) {
265
270
  ? opts.replaceOwnPrefix
266
271
  : ((_a = meta.controller) === null || _a === void 0 ? void 0 : _a.prefix) || '';
267
272
  const prefix = `${opts.globalPrefix}/${ownPrefix}`;
273
+ const controllerOverview = {
274
+ meta,
275
+ computedPrefix: prefix,
276
+ type: classConstructor,
277
+ handlers: [],
278
+ };
268
279
  for (const method of methods) {
269
280
  const methodMeta = getMoostMate().read(fakeInstance, method) || {};
281
+ methodMeta.handlers;
270
282
  if (!methodMeta.handlers || !methodMeta.handlers.length)
271
283
  continue;
272
284
  const pipes = [...(opts.pipes || []), ...(methodMeta.pipes || [])].sort((a, b) => a.priority - b.priority);
@@ -294,12 +306,27 @@ function bindControllerMethods(options) {
294
306
  classMeta: meta,
295
307
  methodMeta,
296
308
  paramMeta,
309
+ type: classConstructor,
310
+ key: method,
311
+ index: i,
312
+ targetMeta: paramMeta,
297
313
  }, 'PARAM', restoreCtx);
298
314
  }
299
315
  return args;
300
316
  });
301
- // preparing provide
302
- // const provide = {...(opts.provide || {}), ...(meta.provide || {})}
317
+ const wm = new WeakMap();
318
+ controllerOverview.handlers.push(...methodMeta.handlers.map(h => {
319
+ const data = {
320
+ meta: methodMeta,
321
+ path: h.path,
322
+ type: h.type,
323
+ method,
324
+ handler: h,
325
+ registeredAs: [],
326
+ };
327
+ wm.set(h, data);
328
+ return data;
329
+ }));
303
330
  for (const adapter of adapters) {
304
331
  yield adapter.bindHandler({
305
332
  prefix,
@@ -310,9 +337,19 @@ function bindControllerMethods(options) {
310
337
  getIterceptorHandler,
311
338
  resolveArgs,
312
339
  logHandler: (eventName) => options.logger.info(`• ${eventName} ${'' + '' + ''}→ ${classConstructor.name}.${''}${method}${''}()`),
340
+ register(h, path, args) {
341
+ const data = wm.get(h);
342
+ if (data) {
343
+ data.registeredAs.push({
344
+ path,
345
+ args,
346
+ });
347
+ }
348
+ },
313
349
  });
314
350
  }
315
351
  }
352
+ return controllerOverview;
316
353
  });
317
354
  }
318
355
 
@@ -417,7 +454,7 @@ function Resolve(resolver, label) {
417
454
  * @paramType string
418
455
  */
419
456
  function Param(name) {
420
- return getMoostMate().apply(getMoostMate().decorate('isRouteParam', name), Resolve(() => eventCore.useRouteParams().get(name), name));
457
+ return getMoostMate().apply(getMoostMate().decorate('paramSource', 'ROUTE'), getMoostMate().decorate('paramName', name), Resolve(() => eventCore.useRouteParams().get(name), name));
421
458
  }
422
459
  /**
423
460
  * Get Parsed Params from url parh
@@ -562,54 +599,11 @@ function Provide(type, fn) {
562
599
  * ## Inject
563
600
  * ### @Decorator
564
601
  * Defines a key from provide registry to inject value
565
- * (For optional values use with @Nullable())
602
+ * (For optional values use with @Optional())
566
603
  * @param type - string or class constructor
567
604
  */
568
605
  function Inject(type) {
569
606
  return getMoostMate().decorate('inject', type);
570
- }
571
- /**
572
- * ## Nullable
573
- * ### @Decorator
574
- * Makes injectable value optional
575
- * @param value default true
576
- */
577
- function Nullable(v = true) {
578
- return getMoostMate().decorate('nullable', v);
579
- }
580
-
581
- function Dto(dtoOptions = {}) {
582
- return getMoostMate().decorate('dto', dtoOptions || {});
583
- }
584
- let isArrayItemValidator = false;
585
- function Validate(validator) {
586
- return getMoostMate().decorate(isArrayItemValidator ? 'validatorsOfItem' : 'validators', validator, true);
587
- }
588
- function IsArray(opts) {
589
- const mate = getMoostMate();
590
- const decorators = [mate.decorate('arrayType', opts || true)];
591
- if ((opts === null || opts === void 0 ? void 0 : opts.itemValidators) && !isArrayItemValidator) {
592
- isArrayItemValidator = true;
593
- decorators.push(...opts.itemValidators());
594
- isArrayItemValidator = false;
595
- }
596
- else if ((opts === null || opts === void 0 ? void 0 : opts.itemValidators) && isArrayItemValidator) {
597
- throw new Error('IsArray validator is not supported inside of array type');
598
- }
599
- const decorator = mate.apply(...decorators);
600
- return decorator;
601
- }
602
- function IsTypeOf(type, errorText) {
603
- return Validate(valido$1.validoIsTypeOf(type, errorText));
604
- }
605
- function IsString(...args) {
606
- return Validate(valido$1.validoIsString(...args));
607
- }
608
- function IsNumber(...args) {
609
- return Validate(valido$1.validoIsNumber(...args));
610
- }
611
- function IsBoolean(...args) {
612
- return Validate(valido$1.validoIsBoolean(...args));
613
607
  }
614
608
 
615
609
  /**
@@ -633,152 +627,6 @@ exports.TPipePriority = void 0;
633
627
  TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
634
628
  })(exports.TPipePriority || (exports.TPipePriority = {}));
635
629
 
636
- const genericTypesCastPipe = (strict) => {
637
- const handler = (value, { paramMeta: meta }) => {
638
- if (meta === null || meta === void 0 ? void 0 : meta.type) {
639
- if ((value === undefined ||
640
- value === null ||
641
- (meta.type !== String && value === '')) &&
642
- meta.optional) {
643
- return undefined;
644
- }
645
- switch (meta.type) {
646
- case Date: {
647
- let d;
648
- if (typeof value === 'string') {
649
- d = new Date(/^\d+$/.test(value) ? Number(value) : value);
650
- }
651
- else {
652
- d = new Date(value);
653
- }
654
- if (strict && Number.isNaN(d.getTime())) {
655
- typeError(value, 'Date', meta.label);
656
- }
657
- return Number.isNaN(d.getTime()) ? value : d;
658
- }
659
- case Boolean:
660
- if ([
661
- true,
662
- 'true',
663
- 'TRUE',
664
- 'True',
665
- 1,
666
- '1',
667
- 'X',
668
- 'x',
669
- ].includes(value)) {
670
- return true;
671
- }
672
- if ([
673
- false,
674
- 'false',
675
- 'FALSE',
676
- 'False',
677
- 0,
678
- '0',
679
- '',
680
- ' ',
681
- null,
682
- undefined,
683
- ].includes(value)) {
684
- return false;
685
- }
686
- if (strict) {
687
- typeError(value, 'boolean', meta.label);
688
- }
689
- return value;
690
- case Number: {
691
- if (strict && !value && value !== 0) {
692
- typeError(value, 'numeric', meta.label);
693
- }
694
- const n = typeof value === 'string' && value.length > 0
695
- ? Number(value)
696
- : NaN;
697
- if (strict && Number.isNaN(n)) {
698
- typeError(value, 'numeric', meta.label);
699
- }
700
- return Number.isNaN(n) ? value : n;
701
- }
702
- case String:
703
- if (strict &&
704
- ['object', 'function'].includes(typeof value)) {
705
- typeError(value, 'string', meta.label);
706
- }
707
- return (value && String(value)) || value;
708
- default:
709
- return value;
710
- }
711
- }
712
- };
713
- handler.priority = exports.TPipePriority.AFTER_TRANSFORM;
714
- return handler;
715
- };
716
- function typeError(value, targetType, label) {
717
- const prefix = label ? `Argument "${label}" with value ` : '';
718
- throw new Error(`${prefix}${JSON.stringify(value)} is not a ${targetType} type`);
719
- }
720
-
721
- const valido = new valido$1.Valido({
722
- getDtoMeta(value, _type) {
723
- let type = _type;
724
- if (!type) {
725
- type = mate$1.getConstructor(value);
726
- }
727
- const mate = getMoostMate();
728
- return mate.read(type);
729
- },
730
- getDtoParamMeta(value, type, key) {
731
- const mate = getMoostMate();
732
- return mate.read(type, key);
733
- },
734
- });
735
- function getMoostValido() {
736
- return valido;
737
- }
738
-
739
- const DEFAULT_ERROR_LIMIT = 10;
740
- function firstString(errors) {
741
- const keys = Object.keys(errors);
742
- for (const key of keys) {
743
- if (typeof errors[key] === 'string')
744
- return errors[key];
745
- return firstString(errors[key]);
746
- }
747
- return '';
748
- }
749
- const validatePipe = (opts) => {
750
- const pipe = (_value, metas, level) => __awaiter(void 0, void 0, void 0, function* () {
751
- const { restoreCtx } = eventCore.useEventContext();
752
- const valido = getMoostValido();
753
- let meta = {};
754
- if (level === 'PARAM') {
755
- meta = metas.paramMeta || {};
756
- }
757
- else if (level === 'PROP') {
758
- meta = metas.propMeta || {};
759
- }
760
- else if (level === 'METHOD') {
761
- meta = metas.methodMeta || {};
762
- }
763
- else if (level === 'CLASS') {
764
- meta = metas.classMeta || {};
765
- }
766
- const result = yield valido.validateParam(_value, meta, metas.key, undefined, metas.instance, undefined, 0, 0, (opts === null || opts === void 0 ? void 0 : opts.errorLimit) || DEFAULT_ERROR_LIMIT, restoreCtx);
767
- if (result !== true) {
768
- const message = typeof result === 'string' ? result : firstString(result);
769
- if (opts === null || opts === void 0 ? void 0 : opts.errorCb) {
770
- opts.errorCb(message, result);
771
- }
772
- else {
773
- throw new Error('Validation error: ' + message);
774
- }
775
- }
776
- return _value;
777
- });
778
- pipe.priority = exports.TPipePriority.VALIDATE;
779
- return pipe;
780
- };
781
-
782
630
  /**
783
631
  * ### Define Interceptor Function
784
632
  *
@@ -829,20 +677,8 @@ function definePipeFn(fn, priority = exports.TPipePriority.TRANSFORM) {
829
677
  }
830
678
 
831
679
  const resolvePipe = definePipeFn((_value, metas, level) => {
832
- var _a, _b, _c, _d;
833
- let resolver;
834
- if (level === 'PARAM') {
835
- resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
836
- }
837
- else if (level === 'PROP') {
838
- resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
839
- }
840
- else if (level === 'METHOD') {
841
- resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
842
- }
843
- else if (level === 'CLASS') {
844
- resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
845
- }
680
+ var _a;
681
+ const resolver = (_a = metas.targetMeta) === null || _a === void 0 ? void 0 : _a.resolver;
846
682
  if (resolver) {
847
683
  return resolver(metas, level);
848
684
  }
@@ -923,7 +759,8 @@ class Moost {
923
759
  this.pipes = [...sharedPipes];
924
760
  this.interceptors = [];
925
761
  this.adapters = [];
926
- this.provide = infact$1.createProvideRegistry([infact$1.Infact, getMoostInfact], [mate$1.Mate, getMoostMate], [valido$1.Valido, getMoostValido]);
762
+ this.controllersOverview = [];
763
+ this.provide = infact$1.createProvideRegistry([infact$1.Infact, getMoostInfact], [mate$1.Mate, getMoostMate]);
927
764
  this.unregisteredControllers = [];
928
765
  this.logger = (options === null || options === void 0 ? void 0 : options.logger) || getDefaultLogger('moost');
929
766
  getMoostInfact().setLogger(this.getLogger('infact'));
@@ -951,13 +788,16 @@ class Moost {
951
788
  this.adapters.push(a);
952
789
  return a;
953
790
  }
791
+ getControllersOverview() {
792
+ return this.controllersOverview;
793
+ }
954
794
  /**
955
795
  * ### init
956
796
  * Ititializes adapter. Must be called after adapters are attached.
957
797
  */
958
798
  init() {
959
799
  return __awaiter(this, void 0, void 0, function* () {
960
- this.setProvideRegistry(infact$1.createProvideRegistry([Moost, () => this]));
800
+ this.setProvideRegistry(infact$1.createProvideRegistry([Moost, () => this], [logger.ProstoLogger, () => this.logger], ['MOOST_LOGGER', () => this.logger]));
961
801
  for (const a of this.adapters) {
962
802
  const constructor = mate$1.getConstructor(a);
963
803
  if (constructor) {
@@ -985,8 +825,14 @@ class Moost {
985
825
  const meta = getMoostMate();
986
826
  const thisMeta = meta.read(this);
987
827
  const provide = Object.assign(Object.assign({}, ((thisMeta === null || thisMeta === void 0 ? void 0 : thisMeta.provide) || {})), this.provide);
988
- for (const controller of this.unregisteredControllers) {
989
- yield this.bindController(controller, provide, ((_a = this.options) === null || _a === void 0 ? void 0 : _a.globalPrefix) || '');
828
+ for (const _controller of this.unregisteredControllers) {
829
+ let newPrefix = undefined;
830
+ let controller = _controller;
831
+ if (Array.isArray(_controller) && typeof _controller[0] === 'string') {
832
+ newPrefix = _controller[0];
833
+ controller = _controller[1];
834
+ }
835
+ yield this.bindController(controller, provide, ((_a = this.options) === null || _a === void 0 ? void 0 : _a.globalPrefix) || '', newPrefix);
990
836
  }
991
837
  this.unregisteredControllers = [];
992
838
  });
@@ -1025,7 +871,7 @@ class Moost {
1025
871
  const classConstructor = mate$1.isConstructor(controller)
1026
872
  ? controller
1027
873
  : mate$1.getConstructor(controller);
1028
- yield bindControllerMethods({
874
+ this.controllersOverview.push(yield bindControllerMethods({
1029
875
  getInstance,
1030
876
  classConstructor,
1031
877
  adapters: this.adapters,
@@ -1035,7 +881,7 @@ class Moost {
1035
881
  pipes,
1036
882
  provide: (classMeta === null || classMeta === void 0 ? void 0 : classMeta.provide) || {},
1037
883
  logger: this.logger,
1038
- });
884
+ }));
1039
885
  if (classMeta && classMeta.importController) {
1040
886
  const prefix = typeof replaceOwnPrefix === 'string'
1041
887
  ? replaceOwnPrefix
@@ -1289,12 +1135,19 @@ Object.defineProperty(exports, 'EventLogger', {
1289
1135
  enumerable: true,
1290
1136
  get: function () { return eventCore.EventLogger; }
1291
1137
  });
1138
+ Object.defineProperty(exports, 'useEventContext', {
1139
+ enumerable: true,
1140
+ get: function () { return eventCore.useEventContext; }
1141
+ });
1142
+ Object.defineProperty(exports, 'useEventLogger', {
1143
+ enumerable: true,
1144
+ get: function () { return eventCore.useEventLogger; }
1145
+ });
1292
1146
  exports.Circular = Circular;
1293
1147
  exports.Const = Const;
1294
1148
  exports.ConstFactory = ConstFactory;
1295
1149
  exports.Controller = Controller;
1296
1150
  exports.Description = Description;
1297
- exports.Dto = Dto;
1298
1151
  exports.Id = Id;
1299
1152
  exports.ImportController = ImportController;
1300
1153
  exports.Inherit = Inherit;
@@ -1303,26 +1156,18 @@ exports.InjectEventLogger = InjectEventLogger;
1303
1156
  exports.Injectable = Injectable;
1304
1157
  exports.Intercept = Intercept;
1305
1158
  exports.InterceptorHandler = InterceptorHandler;
1306
- exports.IsArray = IsArray;
1307
- exports.IsBoolean = IsBoolean;
1308
- exports.IsNumber = IsNumber;
1309
- exports.IsString = IsString;
1310
- exports.IsTypeOf = IsTypeOf;
1311
1159
  exports.Label = Label;
1312
1160
  exports.Moost = Moost;
1313
- exports.Nullable = Nullable;
1314
1161
  exports.Optional = Optional;
1315
1162
  exports.Param = Param;
1316
1163
  exports.Params = Params;
1317
1164
  exports.Provide = Provide;
1318
1165
  exports.Required = Required;
1319
1166
  exports.Resolve = Resolve;
1320
- exports.Validate = Validate;
1321
1167
  exports.Value = Value;
1322
1168
  exports.defineInterceptorFn = defineInterceptorFn;
1323
1169
  exports.defineMoostEventHandler = defineMoostEventHandler;
1324
1170
  exports.definePipeFn = definePipeFn;
1325
- exports.genericTypesCastPipe = genericTypesCastPipe;
1326
1171
  exports.getMoostInfact = getMoostInfact;
1327
1172
  exports.getMoostMate = getMoostMate;
1328
1173
  exports.getNewMoostInfact = getNewMoostInfact;
@@ -1330,4 +1175,3 @@ exports.registerEventScope = registerEventScope;
1330
1175
  exports.resolvePipe = resolvePipe;
1331
1176
  exports.setControllerContext = setControllerContext;
1332
1177
  exports.useControllerContext = useControllerContext;
1333
- exports.validatePipe = validatePipe;
package/dist/index.d.ts CHANGED
@@ -9,12 +9,8 @@ import { TMateParamMeta } from '@prostojs/mate';
9
9
  import { TMatePropMeta } from '@prostojs/mate';
10
10
  import { TProvideFn } from '@prostojs/infact';
11
11
  import { TProvideRegistry } from '@prostojs/infact';
12
- import { TValidoDtoOptions } from '@prostojs/valido';
13
- import { TValidoFn } from '@prostojs/valido';
12
+ import { useEventContext } from '@wooksjs/event-core';
14
13
  import { useEventLogger } from '@wooksjs/event-core';
15
- import { validoIsBoolean } from '@prostojs/valido';
16
- import { validoIsNumber } from '@prostojs/valido';
17
- import { validoIsString } from '@prostojs/valido';
18
14
 
19
15
  export declare function Circular<T = unknown>(resolver: () => TClassConstructor<T>): ParameterDecorator;
20
16
 
@@ -90,7 +86,7 @@ export declare function defineMoostEventHandler<T>(options: TMoostEventHandlerOp
90
86
  * @param priority priority of the pipe where BEFORE_RESOLVE = 0, RESOLVE = 1, AFTER_RESOLVE = 2, BEFORE_TRANSFORM = 3, TRANSFORM = 4, AFTER_TRANSFORM = 5, BEFORE_VALIDATE = 6, VALIDATE = 7, AFTER_VALIDATE = 8
91
87
  * @returns
92
88
  */
93
- export declare function definePipeFn(fn: TPipeFn, priority?: TPipePriority): TPipeFn<TEmpty>;
89
+ export declare function definePipeFn<T extends TObject = TEmpty>(fn: TPipeFn<T>, priority?: TPipePriority): TPipeFn<T>;
94
90
 
95
91
  /**
96
92
  * ## Description
@@ -101,17 +97,17 @@ export declare function definePipeFn(fn: TPipeFn, priority?: TPipePriority): TPi
101
97
  */
102
98
  export declare function Description(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
103
99
 
104
- export declare function Dto(dtoOptions?: TValidoDtoOptions): ClassDecorator;
105
-
106
100
  export { EventLogger }
107
101
 
108
- export declare const genericTypesCastPipe: (strict?: boolean) => TPipeFn;
109
-
110
- export declare function getMoostInfact(): Infact<TMoostMetadata, TMoostMetadata, TMoostParamsMetadata, TCustom>;
102
+ export declare function getMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
111
103
 
112
- export declare function getMoostMate<Class extends TObject = TEmpty, Prop extends TObject = TEmpty, Param extends TObject = TEmpty>(): Mate<TMoostMetadata & Class, TMoostMetadata & Prop, TMoostMetadata & TMoostParamsMetadata & Param>;
104
+ export declare function getMoostMate<Class extends TObject = TEmpty, Prop extends TObject = TEmpty, Param extends TObject = TEmpty>(): Mate<TMoostMetadata<TEmpty> & Class & {
105
+ params: (Param & TMateParamMeta)[];
106
+ }, TMoostMetadata<TEmpty> & Prop & {
107
+ params: (Param & TMateParamMeta)[];
108
+ }>;
113
109
 
114
- export declare function getNewMoostInfact(): Infact<TMoostMetadata, TMoostMetadata, TMoostParamsMetadata, TCustom>;
110
+ export declare function getNewMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
115
111
 
116
112
  /**
117
113
  * ## Id
@@ -153,7 +149,7 @@ export declare const Inherit: () => MethodDecorator & ClassDecorator & Parameter
153
149
  * ## Inject
154
150
  * ### @Decorator
155
151
  * Defines a key from provide registry to inject value
156
- * (For optional values use with @Nullable())
152
+ * (For optional values use with @Optional())
157
153
  * @param type - string or class constructor
158
154
  */
159
155
  export declare function Inject(type: string | TClassConstructor): ParameterDecorator;
@@ -200,16 +196,6 @@ export declare class InterceptorHandler {
200
196
  fireAfter(response: unknown): Promise<unknown>;
201
197
  }
202
198
 
203
- export declare function IsArray<T = unknown>(opts?: TValidateArrayOptions<T>): PropertyDecorator & ParameterDecorator;
204
-
205
- export declare function IsBoolean(...args: Parameters<typeof validoIsBoolean>): PropertyDecorator & ParameterDecorator;
206
-
207
- export declare function IsNumber(...args: Parameters<typeof validoIsNumber>): PropertyDecorator & ParameterDecorator;
208
-
209
- export declare function IsString(...args: Parameters<typeof validoIsString>): PropertyDecorator & ParameterDecorator;
210
-
211
- export declare function IsTypeOf(type: 'string' | 'object' | 'number' | 'boolean', errorText?: string): PropertyDecorator & ParameterDecorator;
212
-
213
199
  /**
214
200
  * ## Label
215
201
  * ### @Decorator
@@ -275,8 +261,9 @@ export declare class Moost {
275
261
  protected pipes: TPipeData[];
276
262
  protected interceptors: TInterceptorData[];
277
263
  protected adapters: TMoostAdapter<TAny>[];
264
+ protected controllersOverview: TControllerOverview[];
278
265
  protected provide: TProvideRegistry;
279
- protected unregisteredControllers: (TObject | TFunction)[];
266
+ protected unregisteredControllers: (TObject | TFunction | [string, TObject | TFunction])[];
280
267
  constructor(options?: TMoostOptions | undefined);
281
268
  /**
282
269
  * ### getLogger
@@ -291,6 +278,7 @@ export declare class Moost {
291
278
  */
292
279
  getLogger(topic: string): TConsoleBase;
293
280
  adapter<T extends TMoostAdapter<TAny>>(a: T): T;
281
+ getControllersOverview(): TControllerOverview[];
294
282
  /**
295
283
  * ### init
296
284
  * Ititializes adapter. Must be called after adapters are attached.
@@ -319,17 +307,9 @@ export declare class Moost {
319
307
  * @param controllers - list of target controllers (instances)
320
308
  * @returns
321
309
  */
322
- registerControllers(...controllers: (TObject | TFunction)[]): this;
310
+ registerControllers(...controllers: (TObject | TFunction | [string, TObject | TFunction])[]): this;
323
311
  }
324
312
 
325
- /**
326
- * ## Nullable
327
- * ### @Decorator
328
- * Makes injectable value optional
329
- * @param value default true
330
- */
331
- export declare function Nullable(v?: boolean): ParameterDecorator;
332
-
333
313
  /**
334
314
  * ## Optional
335
315
  * ### @Decorator
@@ -420,9 +400,13 @@ declare interface TCommonMoostMeta {
420
400
  pipes?: TPipeData[];
421
401
  resolver?: (metas: TPipeMetas<TAny>, level: TDecoratorLevel) => unknown;
422
402
  type?: TFunction;
423
- validators?: TValidoFn<TAny>[];
424
- validatorsOfItem?: TValidoFn<TAny>[];
425
- arrayType?: true | TValidateArrayOptions<TAny>;
403
+ }
404
+
405
+ export declare interface TControllerOverview {
406
+ meta: TMoostMetadata;
407
+ computedPrefix: string;
408
+ type: TFunction;
409
+ handlers: THandlerOverview[];
426
410
  }
427
411
 
428
412
  declare interface TCustom {
@@ -436,6 +420,18 @@ declare interface TEmpty {
436
420
 
437
421
  declare type TFunction = Function;
438
422
 
423
+ declare interface THandlerOverview {
424
+ meta: TMoostMetadata;
425
+ path?: string;
426
+ type: string;
427
+ method: string;
428
+ handler: TMoostHandler<TEmpty>;
429
+ registeredAs: {
430
+ path: string;
431
+ args: string[];
432
+ }[];
433
+ }
434
+
439
435
  export { THook }
440
436
 
441
437
  export declare type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
@@ -483,6 +479,7 @@ export declare interface TMoostAdapterOptions<H, T> {
483
479
  getIterceptorHandler: () => Promise<InterceptorHandler>;
484
480
  resolveArgs: () => Promise<unknown[]>;
485
481
  logHandler: (eventName: string) => void;
482
+ register: (handler: TMoostHandler<TEmpty>, path: string, args: string[]) => void;
486
483
  }
487
484
 
488
485
  export declare interface TMoostEventHandlerHookOptions<T> {
@@ -512,12 +509,12 @@ export declare interface TMoostEventHandlerOptions<T> {
512
509
  };
513
510
  }
514
511
 
515
- export declare type TMoostHandler<T> = T & {
512
+ export declare type TMoostHandler<T> = {
516
513
  type: string;
517
- };
514
+ path?: string;
515
+ } & T;
518
516
 
519
- export declare interface TMoostMetadata extends TCommonMetaFields, TCommonMoostMeta {
520
- dto?: TValidoDtoOptions;
517
+ export declare interface TMoostMetadata<H extends TObject = TEmpty> extends TCommonMetaFields, TCommonMoostMeta {
521
518
  requiredProps?: (string | symbol)[];
522
519
  controller?: {
523
520
  prefix?: string;
@@ -530,8 +527,10 @@ export declare interface TMoostMetadata extends TCommonMetaFields, TCommonMoostM
530
527
  properties?: (string | symbol)[];
531
528
  injectable?: true | TInjectableScope;
532
529
  interceptors?: TInterceptorData[];
533
- handlers?: TMoostHandler<TAny>[];
530
+ handlers?: TMoostHandler<H>[];
531
+ returnType?: TFunction;
534
532
  provide?: TProvideRegistry;
533
+ params: (TMateParamMeta & TMoostParamsMetadata)[];
535
534
  }
536
535
 
537
536
  export declare interface TMoostOptions {
@@ -546,7 +545,8 @@ export declare interface TMoostParamsMetadata extends TCommonMetaFields, TCommon
546
545
  circular?: () => TAny;
547
546
  inject?: string | symbol | TClassConstructor;
548
547
  nullable?: boolean;
549
- isRouteParam?: string;
548
+ paramSource?: string;
549
+ paramName?: string;
550
550
  }
551
551
 
552
552
  declare type TObject = object;
@@ -566,8 +566,11 @@ export declare interface TPipeMetas<T extends TObject = TEmpty> {
566
566
  methodMeta?: TMoostMetadata & T;
567
567
  propMeta?: TMoostMetadata & T;
568
568
  paramMeta?: TMoostParamsMetadata & T;
569
+ targetMeta?: TMoostParamsMetadata & T;
569
570
  instance?: TObject;
570
- key?: string | symbol;
571
+ type: TFunction;
572
+ index?: number;
573
+ key: string | symbol;
571
574
  }
572
575
 
573
576
  export declare enum TPipePriority {
@@ -582,33 +585,35 @@ export declare enum TPipePriority {
582
585
  AFTER_VALIDATE = 8
583
586
  }
584
587
 
585
- export declare interface TValidateArrayOptions<T = unknown> {
586
- itemType?: (item: T, index: number) => Promise<TFunction> | TFunction;
587
- itemValidators?: () => (PropertyDecorator | ParameterDecorator)[];
588
- minLength?: number;
589
- maxLength?: number;
590
- }
591
-
592
- declare interface TValidatePipeOptions {
593
- errorLimit?: number;
594
- errorCb?: (message: string, details: string | TObject) => unknown;
595
- }
596
-
597
588
  export declare function useControllerContext<T extends object>(): {
598
589
  instantiate: <T_1>(c: TClassConstructor<T_1>) => Promise<T_1>;
599
590
  getController: () => T;
600
591
  getMethod: () => keyof T;
601
- getControllerMeta: () => Partial<TMoostMetadata & TEmpty & TMateClassMeta & TMatePropMeta<TMoostMetadata & TMoostParamsMetadata & TEmpty> & TMoostParamsMetadata & TMateParamMeta> | undefined;
602
- getMethodMeta: (name?: string) => Partial<TMoostMetadata & TEmpty & TMateClassMeta & TMatePropMeta<TMoostMetadata & TMoostParamsMetadata & TEmpty> & TMoostParamsMetadata & TMateParamMeta> | undefined;
592
+ getControllerMeta: () => (TMoostMetadata<TEmpty> & TEmpty & {
593
+ params: (TEmpty & TMateParamMeta)[];
594
+ }) | (TMoostMetadata<TEmpty> & TEmpty & {
595
+ params: (TEmpty & TMateParamMeta)[];
596
+ } & {
597
+ params: (TEmpty & TMateParamMeta)[];
598
+ } & TMateClassMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty> & TMatePropMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty>);
599
+ getMethodMeta: (name?: string) => TMoostMetadata<TEmpty> & TEmpty & {
600
+ params: (TEmpty & TMateParamMeta)[];
601
+ } & {
602
+ params: (TEmpty & TMateParamMeta)[];
603
+ } & TMateClassMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty> & TMatePropMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty>;
603
604
  getPropertiesList: () => (string | symbol)[];
604
605
  getScope: () => true | TInjectableScope;
605
- getParamsMeta: () => (TMoostMetadata & TMoostParamsMetadata & TEmpty & TMateParamMeta)[];
606
- getPropMeta: (name: string) => Partial<TMoostMetadata & TEmpty & TMateClassMeta & TMatePropMeta<TMoostMetadata & TMoostParamsMetadata & TEmpty> & TMoostParamsMetadata & TMateParamMeta> | undefined;
606
+ getParamsMeta: () => (TMateParamMeta & TMoostParamsMetadata)[] & (TEmpty & TMateParamMeta)[] & (TMateParamMeta & TMoostParamsMetadata & TEmpty)[];
607
+ getPropMeta: (name: string) => TMoostMetadata<TEmpty> & TEmpty & {
608
+ params: (TEmpty & TMateParamMeta)[];
609
+ } & {
610
+ params: (TEmpty & TMateParamMeta)[];
611
+ } & TMateClassMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty> & TMatePropMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty>;
607
612
  };
608
613
 
609
- export declare function Validate<T = unknown>(validator: TValidoFn<T>): PropertyDecorator & ParameterDecorator;
614
+ export { useEventContext }
610
615
 
611
- export declare const validatePipe: (opts?: TValidatePipeOptions) => TPipeFn;
616
+ export { useEventLogger }
612
617
 
613
618
  /**
614
619
  * ## Value
package/dist/index.mjs CHANGED
@@ -2,8 +2,7 @@ import { Mate, getConstructor, isConstructor } from '@prostojs/mate';
2
2
  import { Infact, createProvideRegistry } from '@prostojs/infact';
3
3
  export { createProvideRegistry } from '@prostojs/infact';
4
4
  import { useEventId, useEventContext, useRouteParams, useEventLogger } from '@wooksjs/event-core';
5
- export { EventLogger } from '@wooksjs/event-core';
6
- import { validoIsTypeOf, validoIsString, validoIsNumber, validoIsBoolean, Valido } from '@prostojs/valido';
5
+ export { EventLogger, useEventContext, useEventLogger } from '@wooksjs/event-core';
7
6
  import { ProstoLogger, createConsoleTransort, coloredConsole } from '@prostojs/logger';
8
7
 
9
8
  /******************************************************************************
@@ -83,11 +82,15 @@ function getNewMoostInfact() {
83
82
  };
84
83
  return infactMeta;
85
84
  },
86
- resolveParam({ paramMeta, classMeta, customData }) {
85
+ resolveParam({ paramMeta, classMeta, customData, classConstructor, index }) {
87
86
  if (paramMeta && customData && customData.pipes) {
88
87
  return runPipes(customData.pipes, undefined, {
89
88
  paramMeta,
89
+ type: classConstructor,
90
+ key: 'constructor',
90
91
  classMeta: classMeta,
92
+ index,
93
+ targetMeta: paramMeta,
91
94
  }, 'PARAM');
92
95
  }
93
96
  },
@@ -95,12 +98,14 @@ function getNewMoostInfact() {
95
98
  const meta = getMoostMate().read(classConstructor, key);
96
99
  return meta;
97
100
  },
98
- resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, }) {
101
+ resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, classConstructor, }) {
99
102
  if (propMeta && customData && customData.pipes) {
100
103
  return runPipes(customData.pipes, initialValue, {
101
104
  instance,
105
+ type: classConstructor,
102
106
  key,
103
107
  propMeta,
108
+ targetMeta: propMeta,
104
109
  classMeta: classMeta,
105
110
  }, 'PROP');
106
111
  }
@@ -265,8 +270,15 @@ function bindControllerMethods(options) {
265
270
  ? opts.replaceOwnPrefix
266
271
  : ((_a = meta.controller) === null || _a === void 0 ? void 0 : _a.prefix) || '';
267
272
  const prefix = `${opts.globalPrefix}/${ownPrefix}`;
273
+ const controllerOverview = {
274
+ meta,
275
+ computedPrefix: prefix,
276
+ type: classConstructor,
277
+ handlers: [],
278
+ };
268
279
  for (const method of methods) {
269
280
  const methodMeta = getMoostMate().read(fakeInstance, method) || {};
281
+ methodMeta.handlers;
270
282
  if (!methodMeta.handlers || !methodMeta.handlers.length)
271
283
  continue;
272
284
  const pipes = [...(opts.pipes || []), ...(methodMeta.pipes || [])].sort((a, b) => a.priority - b.priority);
@@ -294,12 +306,27 @@ function bindControllerMethods(options) {
294
306
  classMeta: meta,
295
307
  methodMeta,
296
308
  paramMeta,
309
+ type: classConstructor,
310
+ key: method,
311
+ index: i,
312
+ targetMeta: paramMeta,
297
313
  }, 'PARAM', restoreCtx);
298
314
  }
299
315
  return args;
300
316
  });
301
- // preparing provide
302
- // const provide = {...(opts.provide || {}), ...(meta.provide || {})}
317
+ const wm = new WeakMap();
318
+ controllerOverview.handlers.push(...methodMeta.handlers.map(h => {
319
+ const data = {
320
+ meta: methodMeta,
321
+ path: h.path,
322
+ type: h.type,
323
+ method,
324
+ handler: h,
325
+ registeredAs: [],
326
+ };
327
+ wm.set(h, data);
328
+ return data;
329
+ }));
303
330
  for (const adapter of adapters) {
304
331
  yield adapter.bindHandler({
305
332
  prefix,
@@ -310,9 +337,19 @@ function bindControllerMethods(options) {
310
337
  getIterceptorHandler,
311
338
  resolveArgs,
312
339
  logHandler: (eventName) => options.logger.info(`• ${eventName} ${'' + '' + ''}→ ${classConstructor.name}.${''}${method}${''}()`),
340
+ register(h, path, args) {
341
+ const data = wm.get(h);
342
+ if (data) {
343
+ data.registeredAs.push({
344
+ path,
345
+ args,
346
+ });
347
+ }
348
+ },
313
349
  });
314
350
  }
315
351
  }
352
+ return controllerOverview;
316
353
  });
317
354
  }
318
355
 
@@ -417,7 +454,7 @@ function Resolve(resolver, label) {
417
454
  * @paramType string
418
455
  */
419
456
  function Param(name) {
420
- return getMoostMate().apply(getMoostMate().decorate('isRouteParam', name), Resolve(() => useRouteParams().get(name), name));
457
+ return getMoostMate().apply(getMoostMate().decorate('paramSource', 'ROUTE'), getMoostMate().decorate('paramName', name), Resolve(() => useRouteParams().get(name), name));
421
458
  }
422
459
  /**
423
460
  * Get Parsed Params from url parh
@@ -562,54 +599,11 @@ function Provide(type, fn) {
562
599
  * ## Inject
563
600
  * ### @Decorator
564
601
  * Defines a key from provide registry to inject value
565
- * (For optional values use with @Nullable())
602
+ * (For optional values use with @Optional())
566
603
  * @param type - string or class constructor
567
604
  */
568
605
  function Inject(type) {
569
606
  return getMoostMate().decorate('inject', type);
570
- }
571
- /**
572
- * ## Nullable
573
- * ### @Decorator
574
- * Makes injectable value optional
575
- * @param value default true
576
- */
577
- function Nullable(v = true) {
578
- return getMoostMate().decorate('nullable', v);
579
- }
580
-
581
- function Dto(dtoOptions = {}) {
582
- return getMoostMate().decorate('dto', dtoOptions || {});
583
- }
584
- let isArrayItemValidator = false;
585
- function Validate(validator) {
586
- return getMoostMate().decorate(isArrayItemValidator ? 'validatorsOfItem' : 'validators', validator, true);
587
- }
588
- function IsArray(opts) {
589
- const mate = getMoostMate();
590
- const decorators = [mate.decorate('arrayType', opts || true)];
591
- if ((opts === null || opts === void 0 ? void 0 : opts.itemValidators) && !isArrayItemValidator) {
592
- isArrayItemValidator = true;
593
- decorators.push(...opts.itemValidators());
594
- isArrayItemValidator = false;
595
- }
596
- else if ((opts === null || opts === void 0 ? void 0 : opts.itemValidators) && isArrayItemValidator) {
597
- throw new Error('IsArray validator is not supported inside of array type');
598
- }
599
- const decorator = mate.apply(...decorators);
600
- return decorator;
601
- }
602
- function IsTypeOf(type, errorText) {
603
- return Validate(validoIsTypeOf(type, errorText));
604
- }
605
- function IsString(...args) {
606
- return Validate(validoIsString(...args));
607
- }
608
- function IsNumber(...args) {
609
- return Validate(validoIsNumber(...args));
610
- }
611
- function IsBoolean(...args) {
612
- return Validate(validoIsBoolean(...args));
613
607
  }
614
608
 
615
609
  /**
@@ -633,152 +627,6 @@ var TPipePriority;
633
627
  TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
634
628
  })(TPipePriority || (TPipePriority = {}));
635
629
 
636
- const genericTypesCastPipe = (strict) => {
637
- const handler = (value, { paramMeta: meta }) => {
638
- if (meta === null || meta === void 0 ? void 0 : meta.type) {
639
- if ((value === undefined ||
640
- value === null ||
641
- (meta.type !== String && value === '')) &&
642
- meta.optional) {
643
- return undefined;
644
- }
645
- switch (meta.type) {
646
- case Date: {
647
- let d;
648
- if (typeof value === 'string') {
649
- d = new Date(/^\d+$/.test(value) ? Number(value) : value);
650
- }
651
- else {
652
- d = new Date(value);
653
- }
654
- if (strict && Number.isNaN(d.getTime())) {
655
- typeError(value, 'Date', meta.label);
656
- }
657
- return Number.isNaN(d.getTime()) ? value : d;
658
- }
659
- case Boolean:
660
- if ([
661
- true,
662
- 'true',
663
- 'TRUE',
664
- 'True',
665
- 1,
666
- '1',
667
- 'X',
668
- 'x',
669
- ].includes(value)) {
670
- return true;
671
- }
672
- if ([
673
- false,
674
- 'false',
675
- 'FALSE',
676
- 'False',
677
- 0,
678
- '0',
679
- '',
680
- ' ',
681
- null,
682
- undefined,
683
- ].includes(value)) {
684
- return false;
685
- }
686
- if (strict) {
687
- typeError(value, 'boolean', meta.label);
688
- }
689
- return value;
690
- case Number: {
691
- if (strict && !value && value !== 0) {
692
- typeError(value, 'numeric', meta.label);
693
- }
694
- const n = typeof value === 'string' && value.length > 0
695
- ? Number(value)
696
- : NaN;
697
- if (strict && Number.isNaN(n)) {
698
- typeError(value, 'numeric', meta.label);
699
- }
700
- return Number.isNaN(n) ? value : n;
701
- }
702
- case String:
703
- if (strict &&
704
- ['object', 'function'].includes(typeof value)) {
705
- typeError(value, 'string', meta.label);
706
- }
707
- return (value && String(value)) || value;
708
- default:
709
- return value;
710
- }
711
- }
712
- };
713
- handler.priority = TPipePriority.AFTER_TRANSFORM;
714
- return handler;
715
- };
716
- function typeError(value, targetType, label) {
717
- const prefix = label ? `Argument "${label}" with value ` : '';
718
- throw new Error(`${prefix}${JSON.stringify(value)} is not a ${targetType} type`);
719
- }
720
-
721
- const valido = new Valido({
722
- getDtoMeta(value, _type) {
723
- let type = _type;
724
- if (!type) {
725
- type = getConstructor(value);
726
- }
727
- const mate = getMoostMate();
728
- return mate.read(type);
729
- },
730
- getDtoParamMeta(value, type, key) {
731
- const mate = getMoostMate();
732
- return mate.read(type, key);
733
- },
734
- });
735
- function getMoostValido() {
736
- return valido;
737
- }
738
-
739
- const DEFAULT_ERROR_LIMIT = 10;
740
- function firstString(errors) {
741
- const keys = Object.keys(errors);
742
- for (const key of keys) {
743
- if (typeof errors[key] === 'string')
744
- return errors[key];
745
- return firstString(errors[key]);
746
- }
747
- return '';
748
- }
749
- const validatePipe = (opts) => {
750
- const pipe = (_value, metas, level) => __awaiter(void 0, void 0, void 0, function* () {
751
- const { restoreCtx } = useEventContext();
752
- const valido = getMoostValido();
753
- let meta = {};
754
- if (level === 'PARAM') {
755
- meta = metas.paramMeta || {};
756
- }
757
- else if (level === 'PROP') {
758
- meta = metas.propMeta || {};
759
- }
760
- else if (level === 'METHOD') {
761
- meta = metas.methodMeta || {};
762
- }
763
- else if (level === 'CLASS') {
764
- meta = metas.classMeta || {};
765
- }
766
- const result = yield valido.validateParam(_value, meta, metas.key, undefined, metas.instance, undefined, 0, 0, (opts === null || opts === void 0 ? void 0 : opts.errorLimit) || DEFAULT_ERROR_LIMIT, restoreCtx);
767
- if (result !== true) {
768
- const message = typeof result === 'string' ? result : firstString(result);
769
- if (opts === null || opts === void 0 ? void 0 : opts.errorCb) {
770
- opts.errorCb(message, result);
771
- }
772
- else {
773
- throw new Error('Validation error: ' + message);
774
- }
775
- }
776
- return _value;
777
- });
778
- pipe.priority = TPipePriority.VALIDATE;
779
- return pipe;
780
- };
781
-
782
630
  /**
783
631
  * ### Define Interceptor Function
784
632
  *
@@ -829,20 +677,8 @@ function definePipeFn(fn, priority = TPipePriority.TRANSFORM) {
829
677
  }
830
678
 
831
679
  const resolvePipe = definePipeFn((_value, metas, level) => {
832
- var _a, _b, _c, _d;
833
- let resolver;
834
- if (level === 'PARAM') {
835
- resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
836
- }
837
- else if (level === 'PROP') {
838
- resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
839
- }
840
- else if (level === 'METHOD') {
841
- resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
842
- }
843
- else if (level === 'CLASS') {
844
- resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
845
- }
680
+ var _a;
681
+ const resolver = (_a = metas.targetMeta) === null || _a === void 0 ? void 0 : _a.resolver;
846
682
  if (resolver) {
847
683
  return resolver(metas, level);
848
684
  }
@@ -923,7 +759,8 @@ class Moost {
923
759
  this.pipes = [...sharedPipes];
924
760
  this.interceptors = [];
925
761
  this.adapters = [];
926
- this.provide = createProvideRegistry([Infact, getMoostInfact], [Mate, getMoostMate], [Valido, getMoostValido]);
762
+ this.controllersOverview = [];
763
+ this.provide = createProvideRegistry([Infact, getMoostInfact], [Mate, getMoostMate]);
927
764
  this.unregisteredControllers = [];
928
765
  this.logger = (options === null || options === void 0 ? void 0 : options.logger) || getDefaultLogger('moost');
929
766
  getMoostInfact().setLogger(this.getLogger('infact'));
@@ -951,13 +788,16 @@ class Moost {
951
788
  this.adapters.push(a);
952
789
  return a;
953
790
  }
791
+ getControllersOverview() {
792
+ return this.controllersOverview;
793
+ }
954
794
  /**
955
795
  * ### init
956
796
  * Ititializes adapter. Must be called after adapters are attached.
957
797
  */
958
798
  init() {
959
799
  return __awaiter(this, void 0, void 0, function* () {
960
- this.setProvideRegistry(createProvideRegistry([Moost, () => this]));
800
+ this.setProvideRegistry(createProvideRegistry([Moost, () => this], [ProstoLogger, () => this.logger], ['MOOST_LOGGER', () => this.logger]));
961
801
  for (const a of this.adapters) {
962
802
  const constructor = getConstructor(a);
963
803
  if (constructor) {
@@ -985,8 +825,14 @@ class Moost {
985
825
  const meta = getMoostMate();
986
826
  const thisMeta = meta.read(this);
987
827
  const provide = Object.assign(Object.assign({}, ((thisMeta === null || thisMeta === void 0 ? void 0 : thisMeta.provide) || {})), this.provide);
988
- for (const controller of this.unregisteredControllers) {
989
- yield this.bindController(controller, provide, ((_a = this.options) === null || _a === void 0 ? void 0 : _a.globalPrefix) || '');
828
+ for (const _controller of this.unregisteredControllers) {
829
+ let newPrefix = undefined;
830
+ let controller = _controller;
831
+ if (Array.isArray(_controller) && typeof _controller[0] === 'string') {
832
+ newPrefix = _controller[0];
833
+ controller = _controller[1];
834
+ }
835
+ yield this.bindController(controller, provide, ((_a = this.options) === null || _a === void 0 ? void 0 : _a.globalPrefix) || '', newPrefix);
990
836
  }
991
837
  this.unregisteredControllers = [];
992
838
  });
@@ -1025,7 +871,7 @@ class Moost {
1025
871
  const classConstructor = isConstructor(controller)
1026
872
  ? controller
1027
873
  : getConstructor(controller);
1028
- yield bindControllerMethods({
874
+ this.controllersOverview.push(yield bindControllerMethods({
1029
875
  getInstance,
1030
876
  classConstructor,
1031
877
  adapters: this.adapters,
@@ -1035,7 +881,7 @@ class Moost {
1035
881
  pipes,
1036
882
  provide: (classMeta === null || classMeta === void 0 ? void 0 : classMeta.provide) || {},
1037
883
  logger: this.logger,
1038
- });
884
+ }));
1039
885
  if (classMeta && classMeta.importController) {
1040
886
  const prefix = typeof replaceOwnPrefix === 'string'
1041
887
  ? replaceOwnPrefix
@@ -1281,4 +1127,4 @@ function defineMoostEventHandler(options) {
1281
1127
  });
1282
1128
  }
1283
1129
 
1284
- export { Circular, Const, ConstFactory, Controller, Description, Dto, Id, ImportController, Inherit, Inject, InjectEventLogger, Injectable, Intercept, InterceptorHandler, IsArray, IsBoolean, IsNumber, IsString, IsTypeOf, Label, Moost, Nullable, Optional, Param, Params, Provide, Required, Resolve, TInterceptorPriority, TPipePriority, Validate, Value, defineInterceptorFn, defineMoostEventHandler, definePipeFn, genericTypesCastPipe, getMoostInfact, getMoostMate, getNewMoostInfact, registerEventScope, resolvePipe, setControllerContext, useControllerContext, validatePipe };
1130
+ export { Circular, Const, ConstFactory, Controller, Description, Id, ImportController, Inherit, Inject, InjectEventLogger, Injectable, Intercept, InterceptorHandler, Label, Moost, Optional, Param, Params, Provide, Required, Resolve, TInterceptorPriority, TPipePriority, Value, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getMoostInfact, getMoostMate, getNewMoostInfact, registerEventScope, resolvePipe, setControllerContext, useControllerContext };
package/package.json CHANGED
@@ -1,10 +1,18 @@
1
1
  {
2
2
  "name": "moost",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
4
4
  "description": "moost",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
8
16
  "files": [
9
17
  "dist"
10
18
  ],
@@ -22,12 +30,11 @@
22
30
  "prostojs"
23
31
  ],
24
32
  "dependencies": {
25
- "@prostojs/infact": "^0.1.11",
26
- "@prostojs/mate": "^0.1.14",
33
+ "@prostojs/infact": "^0.1.13",
34
+ "@prostojs/mate": "^0.2.1",
27
35
  "@prostojs/logger": "^0.3.4",
28
- "@prostojs/valido": "^0.0.2",
29
- "@wooksjs/event-core": "^0.3.3",
30
- "wooks": "^0.3.3"
36
+ "@wooksjs/event-core": "^0.3.11",
37
+ "wooks": "^0.3.11"
31
38
  },
32
39
  "author": "Artem Maltsev",
33
40
  "license": "MIT",