moost 0.2.10 → 0.2.11

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
@@ -220,48 +220,6 @@ function runPipes(pipes, initialValue, metas, level, restoreCtx) {
220
220
  });
221
221
  }
222
222
 
223
- exports.TPipePriority = void 0;
224
- (function (TPipePriority) {
225
- TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
226
- TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
227
- TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
228
- TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
229
- TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
230
- TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
231
- TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
232
- TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
233
- TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
234
- })(exports.TPipePriority || (exports.TPipePriority = {}));
235
-
236
- const resolvePipe = (_value, metas, level) => {
237
- var _a, _b, _c, _d;
238
- let resolver;
239
- if (level === 'PARAM') {
240
- resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
241
- }
242
- else if (level === 'PROP') {
243
- resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
244
- }
245
- else if (level === 'METHOD') {
246
- resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
247
- }
248
- else if (level === 'CLASS') {
249
- resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
250
- }
251
- if (resolver) {
252
- return resolver(metas, level);
253
- }
254
- return undefined;
255
- };
256
- resolvePipe.priority = exports.TPipePriority.RESOLVE;
257
-
258
- const sharedPipes = [
259
- {
260
- handler: resolvePipe,
261
- priority: exports.TPipePriority.RESOLVE,
262
- },
263
- ];
264
-
265
223
  const sharedMoostInfact = getNewMoostInfact();
266
224
  function getMoostInfact() {
267
225
  return sharedMoostInfact;
@@ -280,18 +238,18 @@ function getNewMoostInfact() {
280
238
  };
281
239
  return infactMeta;
282
240
  },
283
- resolveParam(paramMeta, classMeta) {
284
- if (paramMeta.resolver) {
285
- return runPipes(sharedPipes, undefined, { paramMeta, classMeta: classMeta }, 'PARAM');
241
+ resolveParam({ paramMeta, classMeta, customData }) {
242
+ if (paramMeta && customData && customData.pipes) {
243
+ return runPipes(customData.pipes, undefined, { paramMeta, classMeta: classMeta }, 'PARAM');
286
244
  }
287
245
  },
288
246
  describeProp(classConstructor, key) {
289
247
  const meta = getMoostMate().read(classConstructor, key);
290
248
  return meta;
291
249
  },
292
- resolveProp(instance, key, initialValue, propMeta, classMeta) {
293
- if (propMeta.resolver) {
294
- return runPipes(sharedPipes, initialValue, { instance, key, propMeta, classMeta: classMeta }, 'PROP');
250
+ resolveProp({ instance, key, initialValue, propMeta, classMeta, customData }) {
251
+ if (propMeta && customData && customData.pipes) {
252
+ return runPipes(customData.pipes, initialValue, { instance, key, propMeta, classMeta: classMeta }, 'PROP');
295
253
  }
296
254
  },
297
255
  storeProvideRegByInstance: true,
@@ -329,7 +287,10 @@ function getCallableFn(targetInstance, fn, restoreCtx) {
329
287
  if (meta === null || meta === void 0 ? void 0 : meta.injectable) {
330
288
  const infact = getMoostInfact();
331
289
  infact.silent(meta.injectable === 'FOR_EVENT');
332
- const instance = yield infact.getForInstance(targetInstance, fn, [], () => { restoreCtx && restoreCtx(); });
290
+ const instance = yield infact.getForInstance(targetInstance, fn, {
291
+ syncContextFn: () => { restoreCtx && restoreCtx(); },
292
+ customData: { pipes: meta.pipes },
293
+ });
333
294
  infact.silent(false);
334
295
  return ((...args) => {
335
296
  return instance.handler(...args);
@@ -419,7 +380,7 @@ function bindControllerMethods(options) {
419
380
  continue;
420
381
  // preparing interceptors
421
382
  const interceptors = [...(opts.interceptors || []), ...(meta.interceptors || []), ...(methodMeta.interceptors || [])].sort((a, b) => a.priority - b.priority);
422
- const getIterceptorHandler = () => __awaiter(this, void 0, void 0, function* () {
383
+ const getIterceptorHandler = () => {
423
384
  const interceptorHandlers = [];
424
385
  for (const { handler } of interceptors) {
425
386
  const interceptorMeta = mate.read(handler);
@@ -435,10 +396,10 @@ function bindControllerMethods(options) {
435
396
  interceptorHandlers.push(handler);
436
397
  }
437
398
  }
438
- return new InterceptorHandler(interceptorHandlers);
439
- });
399
+ return Promise.resolve(new InterceptorHandler(interceptorHandlers));
400
+ };
440
401
  // preparing pipes
441
- const pipes = [...(opts.pipes || []), ...(meta.pipes || []), ...(methodMeta.pipes || [])];
402
+ const pipes = [...(opts.pipes || []), ...(methodMeta.pipes || [])];
442
403
  const argsPipes = [];
443
404
  for (const p of methodMeta.params || []) {
444
405
  argsPipes.push({
@@ -476,7 +437,7 @@ function bindControllerMethods(options) {
476
437
  handlers: methodMeta.handlers,
477
438
  getIterceptorHandler,
478
439
  resolveArgs,
479
- logHandler: opts.silent ? (_) => { } : (eventName) => log(`• ${eventName} ${'' + '' + ''}→ ${classConstructor.name}.${''}${method}${''}()`),
440
+ logHandler: opts.silent ? () => { } : (eventName) => log(`• ${eventName} ${'' + '' + ''}→ ${classConstructor.name}.${''}${method}${''}()`),
480
441
  });
481
442
  }
482
443
  }
@@ -664,6 +625,48 @@ function IsBoolean(...args) {
664
625
  return Validate(valido$1.validoIsBoolean(...args));
665
626
  }
666
627
 
628
+ exports.TPipePriority = void 0;
629
+ (function (TPipePriority) {
630
+ TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
631
+ TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
632
+ TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
633
+ TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
634
+ TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
635
+ TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
636
+ TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
637
+ TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
638
+ TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
639
+ })(exports.TPipePriority || (exports.TPipePriority = {}));
640
+
641
+ const resolvePipe = (_value, metas, level) => {
642
+ var _a, _b, _c, _d;
643
+ let resolver;
644
+ if (level === 'PARAM') {
645
+ resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
646
+ }
647
+ else if (level === 'PROP') {
648
+ resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
649
+ }
650
+ else if (level === 'METHOD') {
651
+ resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
652
+ }
653
+ else if (level === 'CLASS') {
654
+ resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
655
+ }
656
+ if (resolver) {
657
+ return resolver(metas, level);
658
+ }
659
+ return undefined;
660
+ };
661
+ resolvePipe.priority = exports.TPipePriority.RESOLVE;
662
+
663
+ const sharedPipes = [
664
+ {
665
+ handler: resolvePipe,
666
+ priority: exports.TPipePriority.RESOLVE,
667
+ },
668
+ ];
669
+
667
670
  const valido = new valido$1.Valido({
668
671
  getDtoMeta(value, _type) {
669
672
  let type = _type;
@@ -736,9 +739,11 @@ class Moost {
736
739
  const classMeta = meta.read(controller);
737
740
  const infact = getMoostInfact();
738
741
  const isControllerConsructor = mate.isConstructor(controller);
742
+ const pipes = [...this.pipes, ...((classMeta === null || classMeta === void 0 ? void 0 : classMeta.pipes) || [])].sort((a, b) => a.priority - b.priority);
739
743
  let instance;
744
+ const infactOpts = { provide, customData: { pipes } };
740
745
  if (isControllerConsructor && ((classMeta === null || classMeta === void 0 ? void 0 : classMeta.injectable) === 'SINGLETON' || (classMeta === null || classMeta === void 0 ? void 0 : classMeta.injectable) === true)) {
741
- instance = (yield infact.get(controller, provide));
746
+ instance = (yield infact.get(controller, infactOpts));
742
747
  }
743
748
  else if (!isControllerConsructor) {
744
749
  instance = controller;
@@ -748,7 +753,8 @@ class Moost {
748
753
  const getInstance = instance ? () => Promise.resolve(instance) : () => __awaiter(this, void 0, void 0, function* () {
749
754
  // if (!instance) {
750
755
  infact.silent();
751
- const instance = yield infact.get(controller, provide);
756
+ const { restoreCtx } = eventCore.useEventContext();
757
+ const instance = yield infact.get(controller, Object.assign(Object.assign({}, infactOpts), { syncContextFn: restoreCtx }));
752
758
  infact.silent(false);
753
759
  // }
754
760
  return instance;
@@ -762,7 +768,7 @@ class Moost {
762
768
  globalPrefix,
763
769
  replaceOwnPrefix,
764
770
  interceptors: [...this.interceptors],
765
- pipes: [...this.pipes],
771
+ pipes,
766
772
  provide: (classMeta === null || classMeta === void 0 ? void 0 : classMeta.provide) || {},
767
773
  });
768
774
  if (classMeta && classMeta.importController) {
@@ -915,17 +921,31 @@ function firstString(errors) {
915
921
  return '';
916
922
  }
917
923
  const validatePipe = (opts) => {
918
- const pipe = (_value, meta) => __awaiter(void 0, void 0, void 0, function* () {
919
- const { restoreCtx } = useHttpContext();
924
+ const pipe = (_value, metas, level) => __awaiter(void 0, void 0, void 0, function* () {
925
+ const { restoreCtx } = eventCore.useEventContext();
920
926
  const valido = getMoostValido();
921
- const result = yield valido.validateParam(_value, meta.paramMeta || {}, undefined, undefined, undefined, undefined, 0, 0, (opts === null || opts === void 0 ? void 0 : opts.errorLimit) || DEFAULT_ERROR_LIMIT, restoreCtx);
927
+ let meta = {};
928
+ if (level === 'PARAM') {
929
+ meta = metas.paramMeta || {};
930
+ }
931
+ else if (level === 'PROP') {
932
+ meta = metas.propMeta || {};
933
+ }
934
+ else if (level === 'METHOD') {
935
+ meta = metas.methodMeta || {};
936
+ }
937
+ else if (level === 'CLASS') {
938
+ meta = metas.classMeta || {};
939
+ }
940
+ const result = yield valido.validateParam(_value, meta, undefined, undefined, undefined, undefined, 0, 0, (opts === null || opts === void 0 ? void 0 : opts.errorLimit) || DEFAULT_ERROR_LIMIT, restoreCtx);
922
941
  if (result !== true) {
923
- throw new HttpError(400, {
924
- statusCode: 400,
925
- message: typeof result === 'string' ? result : firstString(result),
926
- error: 'Validation Error',
927
- details: result,
928
- });
942
+ const message = typeof result === 'string' ? result : firstString(result);
943
+ if (opts === null || opts === void 0 ? void 0 : opts.errorCb) {
944
+ opts.errorCb(message, result);
945
+ }
946
+ else {
947
+ throw new Error('Validation error: ' + message);
948
+ }
929
949
  }
930
950
  return _value;
931
951
  });
package/dist/index.d.ts CHANGED
@@ -32,11 +32,11 @@ export declare function Dto(dtoOptions?: TValidoDtoOptions): ClassDecorator;
32
32
 
33
33
  export declare const genericTypesCastPipe: (strict?: boolean) => TPipeFn;
34
34
 
35
- export declare function getMoostInfact(): Infact<TMoostMetadata, TMoostMetadata, TMoostParamsMetadata>;
35
+ export declare function getMoostInfact(): Infact<TMoostMetadata, TMoostMetadata, TMoostParamsMetadata, TCustom>;
36
36
 
37
37
  export declare function getMoostMate(): Mate<TMoostMetadata>;
38
38
 
39
- export declare function getNewMoostInfact(): Infact<TMoostMetadata, TMoostMetadata, TMoostParamsMetadata>;
39
+ export declare function getNewMoostInfact(): Infact<TMoostMetadata, TMoostMetadata, TMoostParamsMetadata, TCustom>;
40
40
 
41
41
  export declare function Id(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
42
42
 
@@ -188,6 +188,10 @@ declare interface TCommonMoostMeta {
188
188
  resolver?: (metas: TPipeMetas, level: TDecoratorLevel) => unknown;
189
189
  }
190
190
 
191
+ declare interface TCustom {
192
+ pipes?: TPipeData[];
193
+ }
194
+
191
195
  declare type TDecoratorLevel = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
192
196
 
193
197
  declare interface TEmpty {
@@ -327,6 +331,7 @@ export declare interface TValidateArrayOptions<T = unknown> {
327
331
 
328
332
  declare interface TValidatePipeOptions {
329
333
  errorLimit?: number;
334
+ errorCb?: (message: string, details: string | TObject) => unknown;
330
335
  }
331
336
 
332
337
  export declare function useControllerMeta<T extends TMoostMetadata = TMoostMetadata>(): {
package/dist/index.mjs CHANGED
@@ -218,48 +218,6 @@ function runPipes(pipes, initialValue, metas, level, restoreCtx) {
218
218
  });
219
219
  }
220
220
 
221
- var TPipePriority;
222
- (function (TPipePriority) {
223
- TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
224
- TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
225
- TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
226
- TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
227
- TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
228
- TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
229
- TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
230
- TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
231
- TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
232
- })(TPipePriority || (TPipePriority = {}));
233
-
234
- const resolvePipe = (_value, metas, level) => {
235
- var _a, _b, _c, _d;
236
- let resolver;
237
- if (level === 'PARAM') {
238
- resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
239
- }
240
- else if (level === 'PROP') {
241
- resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
242
- }
243
- else if (level === 'METHOD') {
244
- resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
245
- }
246
- else if (level === 'CLASS') {
247
- resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
248
- }
249
- if (resolver) {
250
- return resolver(metas, level);
251
- }
252
- return undefined;
253
- };
254
- resolvePipe.priority = TPipePriority.RESOLVE;
255
-
256
- const sharedPipes = [
257
- {
258
- handler: resolvePipe,
259
- priority: TPipePriority.RESOLVE,
260
- },
261
- ];
262
-
263
221
  const sharedMoostInfact = getNewMoostInfact();
264
222
  function getMoostInfact() {
265
223
  return sharedMoostInfact;
@@ -278,18 +236,18 @@ function getNewMoostInfact() {
278
236
  };
279
237
  return infactMeta;
280
238
  },
281
- resolveParam(paramMeta, classMeta) {
282
- if (paramMeta.resolver) {
283
- return runPipes(sharedPipes, undefined, { paramMeta, classMeta: classMeta }, 'PARAM');
239
+ resolveParam({ paramMeta, classMeta, customData }) {
240
+ if (paramMeta && customData && customData.pipes) {
241
+ return runPipes(customData.pipes, undefined, { paramMeta, classMeta: classMeta }, 'PARAM');
284
242
  }
285
243
  },
286
244
  describeProp(classConstructor, key) {
287
245
  const meta = getMoostMate().read(classConstructor, key);
288
246
  return meta;
289
247
  },
290
- resolveProp(instance, key, initialValue, propMeta, classMeta) {
291
- if (propMeta.resolver) {
292
- return runPipes(sharedPipes, initialValue, { instance, key, propMeta, classMeta: classMeta }, 'PROP');
248
+ resolveProp({ instance, key, initialValue, propMeta, classMeta, customData }) {
249
+ if (propMeta && customData && customData.pipes) {
250
+ return runPipes(customData.pipes, initialValue, { instance, key, propMeta, classMeta: classMeta }, 'PROP');
293
251
  }
294
252
  },
295
253
  storeProvideRegByInstance: true,
@@ -327,7 +285,10 @@ function getCallableFn(targetInstance, fn, restoreCtx) {
327
285
  if (meta === null || meta === void 0 ? void 0 : meta.injectable) {
328
286
  const infact = getMoostInfact();
329
287
  infact.silent(meta.injectable === 'FOR_EVENT');
330
- const instance = yield infact.getForInstance(targetInstance, fn, [], () => { restoreCtx && restoreCtx(); });
288
+ const instance = yield infact.getForInstance(targetInstance, fn, {
289
+ syncContextFn: () => { restoreCtx && restoreCtx(); },
290
+ customData: { pipes: meta.pipes },
291
+ });
331
292
  infact.silent(false);
332
293
  return ((...args) => {
333
294
  return instance.handler(...args);
@@ -417,7 +378,7 @@ function bindControllerMethods(options) {
417
378
  continue;
418
379
  // preparing interceptors
419
380
  const interceptors = [...(opts.interceptors || []), ...(meta.interceptors || []), ...(methodMeta.interceptors || [])].sort((a, b) => a.priority - b.priority);
420
- const getIterceptorHandler = () => __awaiter(this, void 0, void 0, function* () {
381
+ const getIterceptorHandler = () => {
421
382
  const interceptorHandlers = [];
422
383
  for (const { handler } of interceptors) {
423
384
  const interceptorMeta = mate.read(handler);
@@ -433,10 +394,10 @@ function bindControllerMethods(options) {
433
394
  interceptorHandlers.push(handler);
434
395
  }
435
396
  }
436
- return new InterceptorHandler(interceptorHandlers);
437
- });
397
+ return Promise.resolve(new InterceptorHandler(interceptorHandlers));
398
+ };
438
399
  // preparing pipes
439
- const pipes = [...(opts.pipes || []), ...(meta.pipes || []), ...(methodMeta.pipes || [])];
400
+ const pipes = [...(opts.pipes || []), ...(methodMeta.pipes || [])];
440
401
  const argsPipes = [];
441
402
  for (const p of methodMeta.params || []) {
442
403
  argsPipes.push({
@@ -474,7 +435,7 @@ function bindControllerMethods(options) {
474
435
  handlers: methodMeta.handlers,
475
436
  getIterceptorHandler,
476
437
  resolveArgs,
477
- logHandler: opts.silent ? (_) => { } : (eventName) => log(`• ${eventName} ${'' + '' + ''}→ ${classConstructor.name}.${''}${method}${''}()`),
438
+ logHandler: opts.silent ? () => { } : (eventName) => log(`• ${eventName} ${'' + '' + ''}→ ${classConstructor.name}.${''}${method}${''}()`),
478
439
  });
479
440
  }
480
441
  }
@@ -662,6 +623,48 @@ function IsBoolean(...args) {
662
623
  return Validate(validoIsBoolean(...args));
663
624
  }
664
625
 
626
+ var TPipePriority;
627
+ (function (TPipePriority) {
628
+ TPipePriority[TPipePriority["BEFORE_RESOLVE"] = 0] = "BEFORE_RESOLVE";
629
+ TPipePriority[TPipePriority["RESOLVE"] = 1] = "RESOLVE";
630
+ TPipePriority[TPipePriority["AFTER_RESOLVE"] = 2] = "AFTER_RESOLVE";
631
+ TPipePriority[TPipePriority["BEFORE_TRANSFORM"] = 3] = "BEFORE_TRANSFORM";
632
+ TPipePriority[TPipePriority["TRANSFORM"] = 4] = "TRANSFORM";
633
+ TPipePriority[TPipePriority["AFTER_TRANSFORM"] = 5] = "AFTER_TRANSFORM";
634
+ TPipePriority[TPipePriority["BEFORE_VALIDATE"] = 6] = "BEFORE_VALIDATE";
635
+ TPipePriority[TPipePriority["VALIDATE"] = 7] = "VALIDATE";
636
+ TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
637
+ })(TPipePriority || (TPipePriority = {}));
638
+
639
+ const resolvePipe = (_value, metas, level) => {
640
+ var _a, _b, _c, _d;
641
+ let resolver;
642
+ if (level === 'PARAM') {
643
+ resolver = (_a = metas.paramMeta) === null || _a === void 0 ? void 0 : _a.resolver;
644
+ }
645
+ else if (level === 'PROP') {
646
+ resolver = (_b = metas.propMeta) === null || _b === void 0 ? void 0 : _b.resolver;
647
+ }
648
+ else if (level === 'METHOD') {
649
+ resolver = (_c = metas.methodMeta) === null || _c === void 0 ? void 0 : _c.resolver;
650
+ }
651
+ else if (level === 'CLASS') {
652
+ resolver = (_d = metas.classMeta) === null || _d === void 0 ? void 0 : _d.resolver;
653
+ }
654
+ if (resolver) {
655
+ return resolver(metas, level);
656
+ }
657
+ return undefined;
658
+ };
659
+ resolvePipe.priority = TPipePriority.RESOLVE;
660
+
661
+ const sharedPipes = [
662
+ {
663
+ handler: resolvePipe,
664
+ priority: TPipePriority.RESOLVE,
665
+ },
666
+ ];
667
+
665
668
  const valido = new Valido({
666
669
  getDtoMeta(value, _type) {
667
670
  let type = _type;
@@ -734,9 +737,11 @@ class Moost {
734
737
  const classMeta = meta.read(controller);
735
738
  const infact = getMoostInfact();
736
739
  const isControllerConsructor = isConstructor(controller);
740
+ const pipes = [...this.pipes, ...((classMeta === null || classMeta === void 0 ? void 0 : classMeta.pipes) || [])].sort((a, b) => a.priority - b.priority);
737
741
  let instance;
742
+ const infactOpts = { provide, customData: { pipes } };
738
743
  if (isControllerConsructor && ((classMeta === null || classMeta === void 0 ? void 0 : classMeta.injectable) === 'SINGLETON' || (classMeta === null || classMeta === void 0 ? void 0 : classMeta.injectable) === true)) {
739
- instance = (yield infact.get(controller, provide));
744
+ instance = (yield infact.get(controller, infactOpts));
740
745
  }
741
746
  else if (!isControllerConsructor) {
742
747
  instance = controller;
@@ -746,7 +751,8 @@ class Moost {
746
751
  const getInstance = instance ? () => Promise.resolve(instance) : () => __awaiter(this, void 0, void 0, function* () {
747
752
  // if (!instance) {
748
753
  infact.silent();
749
- const instance = yield infact.get(controller, provide);
754
+ const { restoreCtx } = useEventContext();
755
+ const instance = yield infact.get(controller, Object.assign(Object.assign({}, infactOpts), { syncContextFn: restoreCtx }));
750
756
  infact.silent(false);
751
757
  // }
752
758
  return instance;
@@ -760,7 +766,7 @@ class Moost {
760
766
  globalPrefix,
761
767
  replaceOwnPrefix,
762
768
  interceptors: [...this.interceptors],
763
- pipes: [...this.pipes],
769
+ pipes,
764
770
  provide: (classMeta === null || classMeta === void 0 ? void 0 : classMeta.provide) || {},
765
771
  });
766
772
  if (classMeta && classMeta.importController) {
@@ -913,17 +919,31 @@ function firstString(errors) {
913
919
  return '';
914
920
  }
915
921
  const validatePipe = (opts) => {
916
- const pipe = (_value, meta) => __awaiter(void 0, void 0, void 0, function* () {
917
- const { restoreCtx } = useHttpContext();
922
+ const pipe = (_value, metas, level) => __awaiter(void 0, void 0, void 0, function* () {
923
+ const { restoreCtx } = useEventContext();
918
924
  const valido = getMoostValido();
919
- const result = yield valido.validateParam(_value, meta.paramMeta || {}, undefined, undefined, undefined, undefined, 0, 0, (opts === null || opts === void 0 ? void 0 : opts.errorLimit) || DEFAULT_ERROR_LIMIT, restoreCtx);
925
+ let meta = {};
926
+ if (level === 'PARAM') {
927
+ meta = metas.paramMeta || {};
928
+ }
929
+ else if (level === 'PROP') {
930
+ meta = metas.propMeta || {};
931
+ }
932
+ else if (level === 'METHOD') {
933
+ meta = metas.methodMeta || {};
934
+ }
935
+ else if (level === 'CLASS') {
936
+ meta = metas.classMeta || {};
937
+ }
938
+ const result = yield valido.validateParam(_value, meta, undefined, undefined, undefined, undefined, 0, 0, (opts === null || opts === void 0 ? void 0 : opts.errorLimit) || DEFAULT_ERROR_LIMIT, restoreCtx);
920
939
  if (result !== true) {
921
- throw new HttpError(400, {
922
- statusCode: 400,
923
- message: typeof result === 'string' ? result : firstString(result),
924
- error: 'Validation Error',
925
- details: result,
926
- });
940
+ const message = typeof result === 'string' ? result : firstString(result);
941
+ if (opts === null || opts === void 0 ? void 0 : opts.errorCb) {
942
+ opts.errorCb(message, result);
943
+ }
944
+ else {
945
+ throw new Error('Validation error: ' + message);
946
+ }
927
947
  }
928
948
  return _value;
929
949
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moost",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "moost",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -22,7 +22,7 @@
22
22
  "prostojs"
23
23
  ],
24
24
  "dependencies": {
25
- "@prostojs/infact": "^0.1.1",
25
+ "@prostojs/infact": "^0.1.3",
26
26
  "@prostojs/mate": "^0.1.12",
27
27
  "@prostojs/valido": "^0.0.2",
28
28
  "@wooksjs/event-core": "^0.2.6",