moost 0.2.8 → 0.2.10

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
@@ -203,17 +203,18 @@ const METADATA_WORKSPACE = 'moost';
203
203
  const moostMate = new mate.Mate(METADATA_WORKSPACE, {
204
204
  readType: true,
205
205
  readReturnType: true,
206
+ collectPropKeys: true,
206
207
  });
207
208
  function getMoostMate() {
208
209
  return moostMate;
209
210
  }
210
211
 
211
- function runPipes(pipes, meta, restoreCtx) {
212
+ function runPipes(pipes, initialValue, metas, level, restoreCtx) {
212
213
  return __awaiter(this, void 0, void 0, function* () {
213
- let v = undefined;
214
+ let v = initialValue;
214
215
  for (const pipe of pipes) {
215
216
  restoreCtx && restoreCtx();
216
- v = yield pipe.handler(v, meta);
217
+ v = yield pipe.handler(v, metas, level);
217
218
  }
218
219
  return v;
219
220
  });
@@ -232,9 +233,23 @@ exports.TPipePriority = void 0;
232
233
  TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
233
234
  })(exports.TPipePriority || (exports.TPipePriority = {}));
234
235
 
235
- const resolvePipe = (_value, meta) => {
236
- if (meta === null || meta === void 0 ? void 0 : meta.resolver) {
237
- return meta.resolver();
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);
238
253
  }
239
254
  return undefined;
240
255
  };
@@ -260,13 +275,23 @@ function getNewMoostInfact() {
260
275
  global: false,
261
276
  constructorParams: (meta === null || meta === void 0 ? void 0 : meta.params) || [],
262
277
  provide: meta === null || meta === void 0 ? void 0 : meta.provide,
278
+ properties: (meta === null || meta === void 0 ? void 0 : meta.properties) || [],
263
279
  scopeId: (meta === null || meta === void 0 ? void 0 : meta.injectable) === 'FOR_EVENT' ? eventCore.useEventId().getId() : undefined,
264
280
  };
265
281
  return infactMeta;
266
282
  },
267
- resolveParam(paramMeta) {
283
+ resolveParam(paramMeta, classMeta) {
268
284
  if (paramMeta.resolver) {
269
- return runPipes(sharedPipes, paramMeta);
285
+ return runPipes(sharedPipes, undefined, { paramMeta, classMeta: classMeta }, 'PARAM');
286
+ }
287
+ },
288
+ describeProp(classConstructor, key) {
289
+ const meta = getMoostMate().read(classConstructor, key);
290
+ return meta;
291
+ },
292
+ resolveProp(instance, key, initialValue, propMeta, classMeta) {
293
+ if (propMeta.resolver) {
294
+ return runPipes(sharedPipes, initialValue, { instance, key, propMeta, classMeta: classMeta }, 'PROP');
270
295
  }
271
296
  },
272
297
  storeProvideRegByInstance: true,
@@ -425,8 +450,12 @@ function bindControllerMethods(options) {
425
450
  const args = [];
426
451
  const { restoreCtx } = eventCore.useEventContext();
427
452
  for (let i = 0; i < argsPipes.length; i++) {
428
- const { pipes, meta } = argsPipes[i];
429
- args[i] = yield runPipes(pipes, meta, restoreCtx);
453
+ const { pipes, meta: paramMeta } = argsPipes[i];
454
+ args[i] = yield runPipes(pipes, undefined, {
455
+ classMeta: meta,
456
+ methodMeta,
457
+ paramMeta,
458
+ }, 'PARAM', restoreCtx);
430
459
  }
431
460
  return args;
432
461
  });
@@ -487,8 +516,9 @@ function Required() {
487
516
  */
488
517
  function Resolve(resolver, label) {
489
518
  return (target, key, index) => {
490
- fillLabel(target, key, index, label);
491
- getMoostMate().decorate('resolver', resolver)(target, key, index);
519
+ const i = typeof index === 'number' ? index : undefined;
520
+ fillLabel(target, key, i, label);
521
+ getMoostMate().decorate('resolver', resolver)(target, key, i);
492
522
  };
493
523
  }
494
524
  /**
@@ -521,8 +551,15 @@ function Const(value, label) {
521
551
  function fillLabel(target, key, index, name) {
522
552
  if (name) {
523
553
  const meta = getMoostMate().read(target, key);
524
- if (!(meta === null || meta === void 0 ? void 0 : meta.params) || !(meta === null || meta === void 0 ? void 0 : meta.params[index]) || !(meta === null || meta === void 0 ? void 0 : meta.params[index].label)) {
525
- Label(name)(target, key, index);
554
+ if (typeof index === 'number') {
555
+ if (!(meta === null || meta === void 0 ? void 0 : meta.params) || !(meta === null || meta === void 0 ? void 0 : meta.params[index]) || !(meta === null || meta === void 0 ? void 0 : meta.params[index].label)) {
556
+ Label(name)(target, key, index);
557
+ }
558
+ }
559
+ else {
560
+ if (!(meta === null || meta === void 0 ? void 0 : meta.label)) {
561
+ Label(name)(target, key);
562
+ }
526
563
  }
527
564
  }
528
565
  }
@@ -809,7 +846,7 @@ function useMoostStore() {
809
846
  }
810
847
 
811
848
  const genericTypesCastPipe = (strict) => {
812
- const handler = (value, meta) => {
849
+ const handler = (value, { paramMeta: meta }) => {
813
850
  if (meta === null || meta === void 0 ? void 0 : meta.type) {
814
851
  if ((value === undefined || value === null || (meta.type !== String && value === '')) && meta.optional) {
815
852
  return undefined;
@@ -881,7 +918,7 @@ const validatePipe = (opts) => {
881
918
  const pipe = (_value, meta) => __awaiter(void 0, void 0, void 0, function* () {
882
919
  const { restoreCtx } = useHttpContext();
883
920
  const valido = getMoostValido();
884
- 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);
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);
885
922
  if (result !== true) {
886
923
  throw new HttpError(400, {
887
924
  statusCode: 400,
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { Infact } from '@prostojs/infact';
2
2
  import { Mate } from '@prostojs/mate';
3
- import { TInfactClassMeta } from '@prostojs/infact';
4
- import { TInfactConstructorParamMeta } from '@prostojs/infact';
5
3
  import { TProstoMetadata } from '@prostojs/mate';
6
4
  import { TProstoParamsMetadata } from '@prostojs/mate';
7
5
  import { TProvideFn } from '@prostojs/infact';
@@ -21,7 +19,7 @@ export declare function Circular<T = unknown>(resolver: () => TClassConstructor<
21
19
  * @param label - label of the field
22
20
  * @paramType unknown
23
21
  */
24
- export declare function Const(value: unknown, label?: string): ParameterDecorator;
22
+ export declare function Const(value: unknown, label?: string): ParameterDecorator & PropertyDecorator;
25
23
 
26
24
  /**
27
25
  * Set Class as a Controller
@@ -34,11 +32,11 @@ export declare function Dto(dtoOptions?: TValidoDtoOptions): ClassDecorator;
34
32
 
35
33
  export declare const genericTypesCastPipe: (strict?: boolean) => TPipeFn;
36
34
 
37
- export declare function getMoostInfact(): Infact<TInfactMoostMeta>;
35
+ export declare function getMoostInfact(): Infact<TMoostMetadata, TMoostMetadata, TMoostParamsMetadata>;
38
36
 
39
37
  export declare function getMoostMate(): Mate<TMoostMetadata>;
40
38
 
41
- export declare function getNewMoostInfact(): Infact<TInfactMoostMeta>;
39
+ export declare function getNewMoostInfact(): Infact<TMoostMetadata, TMoostMetadata, TMoostParamsMetadata>;
42
40
 
43
41
  export declare function Id(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
44
42
 
@@ -135,14 +133,14 @@ export declare function Optional(): MethodDecorator & ClassDecorator & Parameter
135
133
  * @param name - param name
136
134
  * @paramType string
137
135
  */
138
- export declare function Param(name: string): ParameterDecorator;
136
+ export declare function Param(name: string): ParameterDecorator & PropertyDecorator;
139
137
 
140
138
  /**
141
139
  * Get Parsed Params from url parh
142
140
  * @decorator
143
141
  * @paramType object
144
142
  */
145
- export declare function Params(): ParameterDecorator;
143
+ export declare function Params(): ParameterDecorator & PropertyDecorator;
146
144
 
147
145
  export declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator;
148
146
 
@@ -156,7 +154,7 @@ export { Required_2 as Required }
156
154
  * @param label - field label
157
155
  * @paramType unknown
158
156
  */
159
- export declare function Resolve(resolver: () => unknown, label?: string): ParameterDecorator;
157
+ export declare function Resolve<T extends TObject = TEmpty>(resolver: (metas: TPipeMetas<T>, level: TDecoratorLevel) => unknown, label?: string): ParameterDecorator & PropertyDecorator;
160
158
 
161
159
  export declare const resolvePipe: TPipeFn;
162
160
 
@@ -187,11 +185,15 @@ declare interface TCommonMetaFields {
187
185
 
188
186
  declare interface TCommonMoostMeta {
189
187
  pipes?: TPipeData[];
188
+ resolver?: (metas: TPipeMetas, level: TDecoratorLevel) => unknown;
190
189
  }
191
190
 
192
- declare type TFunction = Function;
191
+ declare type TDecoratorLevel = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
192
+
193
+ declare interface TEmpty {
194
+ }
193
195
 
194
- declare type TInfactMoostMeta = TInfactClassMeta<TMoostParamsMetadata & TInfactConstructorParamMeta>;
196
+ declare type TFunction = Function;
195
197
 
196
198
  export declare type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
197
199
 
@@ -256,6 +258,7 @@ export declare interface TMoostMetadata extends TProstoAndCommonMetadata {
256
258
  typeResolver?: TClassConstructor | (() => TClassConstructor | TObject | Promise<TClassConstructor | TObject>);
257
259
  provide?: TProvideRegistry;
258
260
  }[];
261
+ properties?: (string | symbol)[];
259
262
  injectable?: true | TInjectableScope;
260
263
  interceptors?: TInterceptorData[];
261
264
  handlers?: TMoostHandler<TAny>[];
@@ -274,7 +277,6 @@ export declare interface TMoostParamsMetadata extends TProstoParamsAndCommonMeta
274
277
  validators?: TValidoFn[];
275
278
  validatorsOfItem?: TValidoFn[];
276
279
  arrayType?: true | TValidateArrayOptions;
277
- resolver?: TFunction;
278
280
  circular?: () => TAny;
279
281
  inject?: string | symbol;
280
282
  }
@@ -286,11 +288,20 @@ export declare interface TPipeData {
286
288
  priority: TPipePriority;
287
289
  }
288
290
 
289
- export declare type TPipeFn<T extends TMoostParamsMetadata = TMoostParamsMetadata> = {
290
- (value: unknown, meta: T): unknown | Promise<unknown>;
291
+ export declare type TPipeFn<T extends TObject = TEmpty> = {
292
+ (value: unknown, metas: TPipeMetas<T>, level: TDecoratorLevel): unknown | Promise<unknown>;
291
293
  priority?: TPipePriority;
292
294
  };
293
295
 
296
+ export declare interface TPipeMetas<T extends TObject = TEmpty> {
297
+ classMeta?: TMoostMetadata & T;
298
+ methodMeta?: TMoostMetadata & T;
299
+ propMeta?: TMoostMetadata & T;
300
+ paramMeta?: TMoostParamsMetadata & T;
301
+ instance?: TObject;
302
+ key?: string | symbol;
303
+ }
304
+
294
305
  export declare enum TPipePriority {
295
306
  BEFORE_RESOLVE = 0,
296
307
  RESOLVE = 1,
package/dist/index.mjs CHANGED
@@ -201,17 +201,18 @@ const METADATA_WORKSPACE = 'moost';
201
201
  const moostMate = new Mate(METADATA_WORKSPACE, {
202
202
  readType: true,
203
203
  readReturnType: true,
204
+ collectPropKeys: true,
204
205
  });
205
206
  function getMoostMate() {
206
207
  return moostMate;
207
208
  }
208
209
 
209
- function runPipes(pipes, meta, restoreCtx) {
210
+ function runPipes(pipes, initialValue, metas, level, restoreCtx) {
210
211
  return __awaiter(this, void 0, void 0, function* () {
211
- let v = undefined;
212
+ let v = initialValue;
212
213
  for (const pipe of pipes) {
213
214
  restoreCtx && restoreCtx();
214
- v = yield pipe.handler(v, meta);
215
+ v = yield pipe.handler(v, metas, level);
215
216
  }
216
217
  return v;
217
218
  });
@@ -230,9 +231,23 @@ var TPipePriority;
230
231
  TPipePriority[TPipePriority["AFTER_VALIDATE"] = 8] = "AFTER_VALIDATE";
231
232
  })(TPipePriority || (TPipePriority = {}));
232
233
 
233
- const resolvePipe = (_value, meta) => {
234
- if (meta === null || meta === void 0 ? void 0 : meta.resolver) {
235
- return meta.resolver();
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);
236
251
  }
237
252
  return undefined;
238
253
  };
@@ -258,13 +273,23 @@ function getNewMoostInfact() {
258
273
  global: false,
259
274
  constructorParams: (meta === null || meta === void 0 ? void 0 : meta.params) || [],
260
275
  provide: meta === null || meta === void 0 ? void 0 : meta.provide,
276
+ properties: (meta === null || meta === void 0 ? void 0 : meta.properties) || [],
261
277
  scopeId: (meta === null || meta === void 0 ? void 0 : meta.injectable) === 'FOR_EVENT' ? useEventId().getId() : undefined,
262
278
  };
263
279
  return infactMeta;
264
280
  },
265
- resolveParam(paramMeta) {
281
+ resolveParam(paramMeta, classMeta) {
266
282
  if (paramMeta.resolver) {
267
- return runPipes(sharedPipes, paramMeta);
283
+ return runPipes(sharedPipes, undefined, { paramMeta, classMeta: classMeta }, 'PARAM');
284
+ }
285
+ },
286
+ describeProp(classConstructor, key) {
287
+ const meta = getMoostMate().read(classConstructor, key);
288
+ return meta;
289
+ },
290
+ resolveProp(instance, key, initialValue, propMeta, classMeta) {
291
+ if (propMeta.resolver) {
292
+ return runPipes(sharedPipes, initialValue, { instance, key, propMeta, classMeta: classMeta }, 'PROP');
268
293
  }
269
294
  },
270
295
  storeProvideRegByInstance: true,
@@ -423,8 +448,12 @@ function bindControllerMethods(options) {
423
448
  const args = [];
424
449
  const { restoreCtx } = useEventContext();
425
450
  for (let i = 0; i < argsPipes.length; i++) {
426
- const { pipes, meta } = argsPipes[i];
427
- args[i] = yield runPipes(pipes, meta, restoreCtx);
451
+ const { pipes, meta: paramMeta } = argsPipes[i];
452
+ args[i] = yield runPipes(pipes, undefined, {
453
+ classMeta: meta,
454
+ methodMeta,
455
+ paramMeta,
456
+ }, 'PARAM', restoreCtx);
428
457
  }
429
458
  return args;
430
459
  });
@@ -485,8 +514,9 @@ function Required() {
485
514
  */
486
515
  function Resolve(resolver, label) {
487
516
  return (target, key, index) => {
488
- fillLabel(target, key, index, label);
489
- getMoostMate().decorate('resolver', resolver)(target, key, index);
517
+ const i = typeof index === 'number' ? index : undefined;
518
+ fillLabel(target, key, i, label);
519
+ getMoostMate().decorate('resolver', resolver)(target, key, i);
490
520
  };
491
521
  }
492
522
  /**
@@ -519,8 +549,15 @@ function Const(value, label) {
519
549
  function fillLabel(target, key, index, name) {
520
550
  if (name) {
521
551
  const meta = getMoostMate().read(target, key);
522
- if (!(meta === null || meta === void 0 ? void 0 : meta.params) || !(meta === null || meta === void 0 ? void 0 : meta.params[index]) || !(meta === null || meta === void 0 ? void 0 : meta.params[index].label)) {
523
- Label(name)(target, key, index);
552
+ if (typeof index === 'number') {
553
+ if (!(meta === null || meta === void 0 ? void 0 : meta.params) || !(meta === null || meta === void 0 ? void 0 : meta.params[index]) || !(meta === null || meta === void 0 ? void 0 : meta.params[index].label)) {
554
+ Label(name)(target, key, index);
555
+ }
556
+ }
557
+ else {
558
+ if (!(meta === null || meta === void 0 ? void 0 : meta.label)) {
559
+ Label(name)(target, key);
560
+ }
524
561
  }
525
562
  }
526
563
  }
@@ -807,7 +844,7 @@ function useMoostStore() {
807
844
  }
808
845
 
809
846
  const genericTypesCastPipe = (strict) => {
810
- const handler = (value, meta) => {
847
+ const handler = (value, { paramMeta: meta }) => {
811
848
  if (meta === null || meta === void 0 ? void 0 : meta.type) {
812
849
  if ((value === undefined || value === null || (meta.type !== String && value === '')) && meta.optional) {
813
850
  return undefined;
@@ -879,7 +916,7 @@ const validatePipe = (opts) => {
879
916
  const pipe = (_value, meta) => __awaiter(void 0, void 0, void 0, function* () {
880
917
  const { restoreCtx } = useHttpContext();
881
918
  const valido = getMoostValido();
882
- 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);
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);
883
920
  if (result !== true) {
884
921
  throw new HttpError(400, {
885
922
  statusCode: 400,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moost",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "moost",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -22,11 +22,11 @@
22
22
  "prostojs"
23
23
  ],
24
24
  "dependencies": {
25
- "@prostojs/infact": "^0.0.13",
26
- "@prostojs/mate": "^0.1.10",
25
+ "@prostojs/infact": "^0.1.1",
26
+ "@prostojs/mate": "^0.1.12",
27
27
  "@prostojs/valido": "^0.0.2",
28
- "@wooksjs/event-core": "^0.2.5",
29
- "wooks": "^0.2.5"
28
+ "@wooksjs/event-core": "^0.2.6",
29
+ "wooks": "^0.2.6"
30
30
  },
31
31
  "author": "Artem Maltsev",
32
32
  "license": "MIT",