moost 0.0.1-beta.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +14 -8
  2. package/dist/index.cjs +2093 -0
  3. package/dist/{moost.d.ts → index.d.ts} +43 -156
  4. package/dist/index.mjs +2063 -0
  5. package/package.json +13 -69
  6. package/LICENSE +0 -21
  7. package/dist/moost.cjs.prod.js +0 -922
  8. package/dist/moost.esm-bundler.js +0 -869
  9. package/dist/src/binding/bind-controller.d.ts +0 -13
  10. package/dist/src/binding/bind-controller.d.ts.map +0 -1
  11. package/dist/src/binding/bind-handler.d.ts +0 -18
  12. package/dist/src/binding/bind-handler.d.ts.map +0 -1
  13. package/dist/src/binding/index.d.ts +0 -3
  14. package/dist/src/binding/index.d.ts.map +0 -1
  15. package/dist/src/binding/tests/binding.spec.d.ts +0 -2
  16. package/dist/src/binding/tests/binding.spec.d.ts.map +0 -1
  17. package/dist/src/binding/utils.d.ts +0 -3
  18. package/dist/src/binding/utils.d.ts.map +0 -1
  19. package/dist/src/class-function/class-function.d.ts +0 -4
  20. package/dist/src/class-function/class-function.d.ts.map +0 -1
  21. package/dist/src/class-function/index.d.ts +0 -2
  22. package/dist/src/class-function/index.d.ts.map +0 -1
  23. package/dist/src/class-function/types.d.ts +0 -9
  24. package/dist/src/class-function/types.d.ts.map +0 -1
  25. package/dist/src/composables/controller-meta.d.ts +0 -13
  26. package/dist/src/composables/controller-meta.d.ts.map +0 -1
  27. package/dist/src/composables/index.d.ts +0 -2
  28. package/dist/src/composables/index.d.ts.map +0 -1
  29. package/dist/src/decorators/circular.decorator.d.ts +0 -3
  30. package/dist/src/decorators/circular.decorator.d.ts.map +0 -1
  31. package/dist/src/decorators/common.decorator.d.ts +0 -4
  32. package/dist/src/decorators/common.decorator.d.ts.map +0 -1
  33. package/dist/src/decorators/controller.decorator.d.ts +0 -24
  34. package/dist/src/decorators/controller.decorator.d.ts.map +0 -1
  35. package/dist/src/decorators/http-method.decorator.d.ts +0 -8
  36. package/dist/src/decorators/http-method.decorator.d.ts.map +0 -1
  37. package/dist/src/decorators/index.d.ts +0 -10
  38. package/dist/src/decorators/index.d.ts.map +0 -1
  39. package/dist/src/decorators/injectable.decorator.d.ts +0 -12
  40. package/dist/src/decorators/injectable.decorator.d.ts.map +0 -1
  41. package/dist/src/decorators/intercept.decorator.d.ts +0 -20
  42. package/dist/src/decorators/intercept.decorator.d.ts.map +0 -1
  43. package/dist/src/decorators/pipe.decorator.d.ts +0 -3
  44. package/dist/src/decorators/pipe.decorator.d.ts.map +0 -1
  45. package/dist/src/decorators/provide.decorator.d.ts +0 -5
  46. package/dist/src/decorators/provide.decorator.d.ts.map +0 -1
  47. package/dist/src/decorators/resolve.decorator.d.ts +0 -137
  48. package/dist/src/decorators/resolve.decorator.d.ts.map +0 -1
  49. package/dist/src/decorators/tests/circular.artifacts.d.ts +0 -7
  50. package/dist/src/decorators/tests/circular.artifacts.d.ts.map +0 -1
  51. package/dist/src/decorators/tests/circular.spec.d.ts +0 -2
  52. package/dist/src/decorators/tests/circular.spec.d.ts.map +0 -1
  53. package/dist/src/decorators/tests/common.artifacts.d.ts +0 -4
  54. package/dist/src/decorators/tests/common.artifacts.d.ts.map +0 -1
  55. package/dist/src/decorators/tests/common.spec.d.ts +0 -2
  56. package/dist/src/decorators/tests/common.spec.d.ts.map +0 -1
  57. package/dist/src/decorators/tests/controller.spec.d.ts +0 -2
  58. package/dist/src/decorators/tests/controller.spec.d.ts.map +0 -1
  59. package/dist/src/decorators/tests/http-method.artifacts.d.ts +0 -12
  60. package/dist/src/decorators/tests/http-method.artifacts.d.ts.map +0 -1
  61. package/dist/src/decorators/tests/http-method.spec.d.ts +0 -2
  62. package/dist/src/decorators/tests/http-method.spec.d.ts.map +0 -1
  63. package/dist/src/decorators/tests/injectable.spec.d.ts +0 -2
  64. package/dist/src/decorators/tests/injectable.spec.d.ts.map +0 -1
  65. package/dist/src/decorators/tests/intercept.spec.d.ts +0 -2
  66. package/dist/src/decorators/tests/intercept.spec.d.ts.map +0 -1
  67. package/dist/src/decorators/tests/pipe.artifacts.d.ts +0 -4
  68. package/dist/src/decorators/tests/pipe.artifacts.d.ts.map +0 -1
  69. package/dist/src/decorators/tests/pipe.spec.d.ts +0 -2
  70. package/dist/src/decorators/tests/pipe.spec.d.ts.map +0 -1
  71. package/dist/src/decorators/tests/provide.artifacts.d.ts +0 -9
  72. package/dist/src/decorators/tests/provide.artifacts.d.ts.map +0 -1
  73. package/dist/src/decorators/tests/provide.spec.d.ts +0 -2
  74. package/dist/src/decorators/tests/provide.spec.d.ts.map +0 -1
  75. package/dist/src/decorators/tests/resolve.artifacts.d.ts +0 -4
  76. package/dist/src/decorators/tests/resolve.artifacts.d.ts.map +0 -1
  77. package/dist/src/decorators/tests/resolve.spec.d.ts +0 -2
  78. package/dist/src/decorators/tests/resolve.spec.d.ts.map +0 -1
  79. package/dist/src/decorators/tests/validate.artifacts.d.ts +0 -21
  80. package/dist/src/decorators/tests/validate.artifacts.d.ts.map +0 -1
  81. package/dist/src/decorators/tests/validate.spec.d.ts +0 -2
  82. package/dist/src/decorators/tests/validate.spec.d.ts.map +0 -1
  83. package/dist/src/decorators/validate.decorator.d.ts +0 -10
  84. package/dist/src/decorators/validate.decorator.d.ts.map +0 -1
  85. package/dist/src/index.d.ts +0 -7
  86. package/dist/src/index.d.ts.map +0 -1
  87. package/dist/src/metadata/index.d.ts +0 -2
  88. package/dist/src/metadata/index.d.ts.map +0 -1
  89. package/dist/src/metadata/infact.d.ts +0 -7
  90. package/dist/src/metadata/infact.d.ts.map +0 -1
  91. package/dist/src/metadata/moost-metadata.d.ts +0 -62
  92. package/dist/src/metadata/moost-metadata.d.ts.map +0 -1
  93. package/dist/src/metadata/valido.d.ts +0 -3
  94. package/dist/src/metadata/valido.d.ts.map +0 -1
  95. package/dist/src/moost.d.ts +0 -44
  96. package/dist/src/moost.d.ts.map +0 -1
  97. package/dist/src/moost.spec.d.ts +0 -2
  98. package/dist/src/moost.spec.d.ts.map +0 -1
  99. package/dist/src/pipes/generic-types-cast.pipe.d.ts +0 -3
  100. package/dist/src/pipes/generic-types-cast.pipe.d.ts.map +0 -1
  101. package/dist/src/pipes/index.d.ts +0 -5
  102. package/dist/src/pipes/index.d.ts.map +0 -1
  103. package/dist/src/pipes/resolve.pipe.d.ts +0 -3
  104. package/dist/src/pipes/resolve.pipe.d.ts.map +0 -1
  105. package/dist/src/pipes/run-pipes.d.ts +0 -5
  106. package/dist/src/pipes/run-pipes.d.ts.map +0 -1
  107. package/dist/src/pipes/shared-pipes.d.ts +0 -3
  108. package/dist/src/pipes/shared-pipes.d.ts.map +0 -1
  109. package/dist/src/pipes/types.d.ts +0 -21
  110. package/dist/src/pipes/types.d.ts.map +0 -1
  111. package/dist/src/pipes/validate.pipe.d.ts +0 -7
  112. package/dist/src/pipes/validate.pipe.d.ts.map +0 -1
  113. package/dist/src/pipes/validation.spec.d.ts +0 -2
  114. package/dist/src/pipes/validation.spec.d.ts.map +0 -1
  115. package/dist/src/tests/e2e.artifacts.d.ts +0 -17
  116. package/dist/src/tests/e2e.artifacts.d.ts.map +0 -1
  117. package/dist/src/tests/e2e.spec.d.ts +0 -2
  118. package/dist/src/tests/e2e.spec.d.ts.map +0 -1
  119. package/dist/src/tests/request.artifacts.d.ts +0 -10
  120. package/dist/src/tests/request.artifacts.d.ts.map +0 -1
  121. package/dist/src/types.d.ts +0 -8
  122. package/dist/src/types.d.ts.map +0 -1
  123. package/dist/src/utils/banner.d.ts +0 -2
  124. package/dist/src/utils/banner.d.ts.map +0 -1
  125. package/dist/src/utils/log.d.ts +0 -5
  126. package/dist/src/utils/log.d.ts.map +0 -1
  127. package/dist/src/utils/panic.d.ts +0 -2
  128. package/dist/src/utils/panic.d.ts.map +0 -1
  129. package/index.js +0 -2
@@ -5,29 +5,9 @@ import { TProvideFn } from '@prostojs/infact';
5
5
  import { TProvideRegistry } from '@prostojs/infact';
6
6
  import { TValidoDtoOptions } from '@prostojs/valido';
7
7
  import { TValidoFn } from '@prostojs/valido';
8
- import { TWooksOptions } from 'wooks';
9
8
  import { validoIsBoolean } from '@prostojs/valido';
10
9
  import { validoIsNumber } from '@prostojs/valido';
11
10
  import { validoIsString } from '@prostojs/valido';
12
- import { Wooks } from 'wooks';
13
-
14
- export declare const All: (path?: string) => MethodDecorator;
15
-
16
- /**
17
- * Parse Authorisation Header
18
- * @decorator
19
- * @param name - define what to take from the Auth header
20
- * @paramType string
21
- */
22
- export declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator;
23
-
24
- /**
25
- * Get Parsed Request Body
26
- * @decorator
27
- * @paramType object | string | unknown
28
- */
29
- declare function Body_2(): ParameterDecorator;
30
- export { Body_2 as Body }
31
11
 
32
12
  export declare function Circular<T = unknown>(resolver: () => TClassConstructor<T>): ParameterDecorator;
33
13
 
@@ -47,49 +27,13 @@ export declare function Const(value: unknown, label?: string): ParameterDecorato
47
27
  */
48
28
  export declare function Controller(prefix?: string): ClassDecorator;
49
29
 
50
- /**
51
- * Get Request Cookie Value
52
- * @decorator
53
- * @param name - cookie name
54
- * @paramType string
55
- */
56
- export declare function Cookie(name: string): ParameterDecorator;
57
-
58
- /**
59
- * Hook to the Response Cookie
60
- * @decorator
61
- * @param name - header name
62
- * @paramType TCookieHook
63
- */
64
- export declare const CookieHook: (name: string) => ParameterDecorator;
65
-
66
- export declare const Delete: (path?: string) => MethodDecorator;
67
-
68
30
  export declare function Dto(dtoOptions?: TValidoDtoOptions): ClassDecorator;
69
31
 
70
32
  export declare const genericTypesCastPipe: (strict?: boolean) => TPipeFn;
71
33
 
72
- export declare const Get: (path?: string) => MethodDecorator;
73
-
74
34
  export declare function getMoostMate(): Mate<TMoostMetadata>;
75
35
 
76
- /**
77
- * Get Request Header Value
78
- * @decorator
79
- * @param name - header name
80
- * @paramType string
81
- */
82
- export declare function Header(name: string): ParameterDecorator;
83
-
84
- /**
85
- * Hook to the Response Header
86
- * @decorator
87
- * @param name - header name
88
- * @paramType THeaderHook
89
- */
90
- export declare const HeaderHook: (name: string) => ParameterDecorator;
91
-
92
- export declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', path?: string): MethodDecorator;
36
+ export declare function Id(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
93
37
 
94
38
  /**
95
39
  * Set Class as a Controller
@@ -113,8 +57,8 @@ export declare function Inject(type: string | TClassConstructor): ParameterDecor
113
57
  /**
114
58
  * Mark the Class as Injectable to enable it to be used in dependency injection
115
59
  * @decorator
116
- * @param scope - Scope for injection ("FOR_REQUEST" | "SINGLETON" | true)
117
- * FOR_REQUEST - will create a new instance for each incoming request
60
+ * @param scope - Scope for injection ("FOR_EVENT" | "SINGLETON" | true)
61
+ * FOR_EVENT - will create a new instance for each incoming request
118
62
  * SINGLETON | true - will create a new instance only once
119
63
  * @param label - field label
120
64
  */
@@ -122,21 +66,19 @@ export declare function Injectable(scope?: true | TInjectableScope): ClassDecora
122
66
 
123
67
  export declare function Intercept(handler: TCallableClassFunction<TInterceptorFn>, priority?: TInterceptorPriority): ClassDecorator & MethodDecorator;
124
68
 
125
- /**
126
- * Get Request IP Address
127
- * @decorator
128
- * @paramType string
129
- */
130
- export declare function Ip(opts?: {
131
- trustProxy: boolean;
132
- }): ParameterDecorator;
133
-
134
- /**
135
- * Get Request IP Address list
136
- * @decorator
137
- * @paramType string[]
138
- */
139
- export declare function IpList(): ParameterDecorator;
69
+ export declare class InterceptorHandler {
70
+ protected handlers: TInterceptorFn[];
71
+ constructor(handlers: TInterceptorFn[]);
72
+ protected before: TInterceptorBefore[];
73
+ protected after: TInterceptorAfter[];
74
+ protected onError: TInterceptorOnError[];
75
+ response?: unknown;
76
+ responseOverwritten: boolean;
77
+ replyFn(reply: unknown): void;
78
+ init(): Promise<void>;
79
+ fireBefore(response: unknown): Promise<unknown>;
80
+ fireAfter(response: unknown): Promise<unknown>;
81
+ }
140
82
 
141
83
  export declare function IsArray<T = unknown>(opts?: TValidateArrayOptions<T>): PropertyDecorator & ParameterDecorator;
142
84
 
@@ -150,28 +92,16 @@ export declare function IsTypeOf(type: 'string' | 'object' | 'number' | 'boolean
150
92
 
151
93
  export declare function Label(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
152
94
 
153
- /**
154
- * Get Requested HTTP Method
155
- * @decorator
156
- * @paramType string
157
- */
158
- export declare function Method(): ParameterDecorator;
159
-
160
95
  export declare class Moost {
161
96
  protected options?: TMoostOptions | undefined;
162
97
  pipes: TPipeData[];
163
98
  interceptors: TInterceptorData[];
99
+ adapters: TMoostAdapter<TAny>[];
164
100
  provide: TProvideRegistry;
165
101
  constructor(options?: TMoostOptions | undefined);
166
- protected wooksApp?: Wooks;
102
+ adapter<T extends object, A extends TMoostAdapter<T>>(a: A): A;
167
103
  protected unregisteredControllers: (TObject | TFunction)[];
168
- listen(): Promise<Wooks>;
169
- listen(port: number): Promise<Wooks>;
170
- listen(port: number, cb: () => void): Promise<Wooks>;
171
- listen(port: number, hostname: string): Promise<Wooks>;
172
- listen(port: number, hostname: string, cb: () => void): Promise<Wooks>;
173
- close(): Promise<unknown> | undefined;
174
- private init;
104
+ init(): Promise<void>;
175
105
  protected bindControllers(): Promise<void>;
176
106
  protected bindController(controller: TFunction | TObject, provide: TProvideRegistry, globalPrefix: string, replaceOwnPrefix?: string): Promise<void>;
177
107
  applyGlobalPipes(...items: (TPipeFn | TPipeData)[]): this;
@@ -207,56 +137,11 @@ export declare function Param(name: string): ParameterDecorator;
207
137
  */
208
138
  export declare function Params(): ParameterDecorator;
209
139
 
210
- export declare const Patch: (path?: string) => MethodDecorator;
211
-
212
- export declare const Post: (path?: string) => MethodDecorator;
213
-
214
140
  export declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator;
215
141
 
216
- export declare const Put: (path?: string) => MethodDecorator;
217
-
218
- /**
219
- * Get Query Item value or the whole parsed Query as an object
220
- * @decorator
221
- * @param name - query item name (optional)
222
- * @paramType string | object
223
- */
224
- export declare function Query(name?: string): ParameterDecorator;
225
-
226
- /**
227
- * Get Raw Request Body Buffer
228
- * @decorator
229
- * @paramType Promise<Buffer>
230
- */
231
- export declare function RawBody(): ParameterDecorator;
232
-
233
- /**
234
- * Get Raw Request Instance
235
- * @decorator
236
- * @paramType IncomingMessage
237
- */
238
- export declare function Req(): ParameterDecorator;
239
-
240
- /**
241
- * Get Request Unique Identificator (UUID)
242
- * @decorator
243
- * @paramType string
244
- */
245
- export declare function ReqId(): ParameterDecorator;
246
-
247
142
  declare function Required_2(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
248
143
  export { Required_2 as Required }
249
144
 
250
- /**
251
- * Get Raw Response Object
252
- * @decorator
253
- * @param options - passthrough options
254
- * @paramType string
255
- */
256
- export declare function Res(options?: {
257
- passthrough: boolean;
258
- }): ParameterDecorator;
259
-
260
145
  /**
261
146
  * Hook to the Response Status
262
147
  * @decorator
@@ -268,13 +153,6 @@ export declare function Resolve(resolver: () => unknown, label?: string): Parame
268
153
 
269
154
  export declare const resolvePipe: TPipeFn;
270
155
 
271
- /**
272
- * Hook to the Response Status
273
- * @decorator
274
- * @paramType TStatusHook
275
- */
276
- export declare const StatusHook: ParameterDecorator;
277
-
278
156
  declare type TAny = any;
279
157
 
280
158
  declare type TAnyFn = {
@@ -294,6 +172,7 @@ declare interface TClassFunctionConstructor<T extends TAnyFn = TAnyFn> {
294
172
  }
295
173
 
296
174
  declare interface TCommonMetaFields {
175
+ id?: string;
297
176
  label?: string;
298
177
  optional?: boolean;
299
178
  required?: boolean;
@@ -305,7 +184,7 @@ declare interface TCommonMoostMeta {
305
184
 
306
185
  declare type TFunction = Function;
307
186
 
308
- export declare type TInjectableScope = 'FOR_REQUEST' | 'SINGLETON';
187
+ export declare type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
309
188
 
310
189
  export declare type TInterceptorAfter = (response: TAny, reply: (response: TAny) => void) => void | Promise<void>;
311
190
 
@@ -333,6 +212,27 @@ export declare enum TInterceptorPriority {
333
212
  AFTER_ALL = 6
334
213
  }
335
214
 
215
+ export declare interface TMoostAdapter<H extends object> {
216
+ bindHandler<T extends TObject = TObject>(options: TMoostAdapterOptions<H, T>): void | Promise<void>;
217
+ onInit?: () => void | Promise<void>;
218
+ }
219
+
220
+ export declare interface TMoostAdapterOptions<H extends object, T extends object> {
221
+ prefix: string;
222
+ fakeInstance: T;
223
+ getInstance: () => Promise<T>;
224
+ method: keyof T;
225
+ handlers: TMoostHandler<H>[];
226
+ getIterceptorHandler: () => Promise<InterceptorHandler>;
227
+ registerEventScope: (scopeId: string) => () => void;
228
+ resolveArgs: () => Promise<unknown[]>;
229
+ logHandler: (eventName: string) => void;
230
+ }
231
+
232
+ export declare type TMoostHandler<T extends object> = T & {
233
+ type: string;
234
+ };
235
+
336
236
  export declare interface TMoostMetadata extends TProstoAndCommonMetadata {
337
237
  inherit?: boolean;
338
238
  dto?: TValidoDtoOptions;
@@ -347,10 +247,7 @@ export declare interface TMoostMetadata extends TProstoAndCommonMetadata {
347
247
  }[];
348
248
  injectable?: true | TInjectableScope;
349
249
  interceptors?: TInterceptorData[];
350
- httpHandler?: {
351
- method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
352
- path: string;
353
- }[];
250
+ handlers?: TMoostHandler<TAny>[];
354
251
  validators?: TValidoFn[];
355
252
  validatorsOfItem?: TValidoFn[];
356
253
  arrayType?: true | TValidateArrayOptions;
@@ -359,9 +256,6 @@ export declare interface TMoostMetadata extends TProstoAndCommonMetadata {
359
256
 
360
257
  export declare interface TMoostOptions {
361
258
  globalPrefix?: string;
362
- port?: number | string;
363
- hostname?: string;
364
- wooksOptions?: TWooksOptions;
365
259
  }
366
260
 
367
261
  export declare interface TMoostParamsMetadata extends TProstoParamsAndCommonMetadata {
@@ -412,13 +306,6 @@ declare interface TValidatePipeOptions {
412
306
  errorLimit?: number;
413
307
  }
414
308
 
415
- /**
416
- * Get Requested URL
417
- * @decorator
418
- * @paramType string
419
- */
420
- export declare function Url(): ParameterDecorator;
421
-
422
309
  export declare function useControllerMeta<T extends TMoostMetadata = TMoostMetadata>(): {
423
310
  getClassMeta: () => T | undefined;
424
311
  getMethodMeta: () => T | undefined;