moost 0.0.1 → 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 -158
  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 -923
  8. package/dist/moost.esm-bundler.js +0 -870
  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 -46
  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,30 +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
- import { WooksHttp } from '@wooksjs/event-http';
14
-
15
- export declare const All: (path?: string) => MethodDecorator;
16
-
17
- /**
18
- * Parse Authorisation Header
19
- * @decorator
20
- * @param name - define what to take from the Auth header
21
- * @paramType string
22
- */
23
- export declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator;
24
-
25
- /**
26
- * Get Parsed Request Body
27
- * @decorator
28
- * @paramType object | string | unknown
29
- */
30
- declare function Body_2(): ParameterDecorator;
31
- export { Body_2 as Body }
32
11
 
33
12
  export declare function Circular<T = unknown>(resolver: () => TClassConstructor<T>): ParameterDecorator;
34
13
 
@@ -48,49 +27,13 @@ export declare function Const(value: unknown, label?: string): ParameterDecorato
48
27
  */
49
28
  export declare function Controller(prefix?: string): ClassDecorator;
50
29
 
51
- /**
52
- * Get Request Cookie Value
53
- * @decorator
54
- * @param name - cookie name
55
- * @paramType string
56
- */
57
- export declare function Cookie(name: string): ParameterDecorator;
58
-
59
- /**
60
- * Hook to the Response Cookie
61
- * @decorator
62
- * @param name - header name
63
- * @paramType TCookieHook
64
- */
65
- export declare const CookieHook: (name: string) => ParameterDecorator;
66
-
67
- export declare const Delete: (path?: string) => MethodDecorator;
68
-
69
30
  export declare function Dto(dtoOptions?: TValidoDtoOptions): ClassDecorator;
70
31
 
71
32
  export declare const genericTypesCastPipe: (strict?: boolean) => TPipeFn;
72
33
 
73
- export declare const Get: (path?: string) => MethodDecorator;
74
-
75
34
  export declare function getMoostMate(): Mate<TMoostMetadata>;
76
35
 
77
- /**
78
- * Get Request Header Value
79
- * @decorator
80
- * @param name - header name
81
- * @paramType string
82
- */
83
- export declare function Header(name: string): ParameterDecorator;
84
-
85
- /**
86
- * Hook to the Response Header
87
- * @decorator
88
- * @param name - header name
89
- * @paramType THeaderHook
90
- */
91
- export declare const HeaderHook: (name: string) => ParameterDecorator;
92
-
93
- 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;
94
37
 
95
38
  /**
96
39
  * Set Class as a Controller
@@ -114,8 +57,8 @@ export declare function Inject(type: string | TClassConstructor): ParameterDecor
114
57
  /**
115
58
  * Mark the Class as Injectable to enable it to be used in dependency injection
116
59
  * @decorator
117
- * @param scope - Scope for injection ("FOR_REQUEST" | "SINGLETON" | true)
118
- * 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
119
62
  * SINGLETON | true - will create a new instance only once
120
63
  * @param label - field label
121
64
  */
@@ -123,21 +66,19 @@ export declare function Injectable(scope?: true | TInjectableScope): ClassDecora
123
66
 
124
67
  export declare function Intercept(handler: TCallableClassFunction<TInterceptorFn>, priority?: TInterceptorPriority): ClassDecorator & MethodDecorator;
125
68
 
126
- /**
127
- * Get Request IP Address
128
- * @decorator
129
- * @paramType string
130
- */
131
- export declare function Ip(opts?: {
132
- trustProxy: boolean;
133
- }): ParameterDecorator;
134
-
135
- /**
136
- * Get Request IP Address list
137
- * @decorator
138
- * @paramType string[]
139
- */
140
- 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
+ }
141
82
 
142
83
  export declare function IsArray<T = unknown>(opts?: TValidateArrayOptions<T>): PropertyDecorator & ParameterDecorator;
143
84
 
@@ -151,29 +92,16 @@ export declare function IsTypeOf(type: 'string' | 'object' | 'number' | 'boolean
151
92
 
152
93
  export declare function Label(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
153
94
 
154
- /**
155
- * Get Requested HTTP Method
156
- * @decorator
157
- * @paramType string
158
- */
159
- export declare function Method(): ParameterDecorator;
160
-
161
95
  export declare class Moost {
162
96
  protected options?: TMoostOptions | undefined;
163
97
  pipes: TPipeData[];
164
98
  interceptors: TInterceptorData[];
99
+ adapters: TMoostAdapter<TAny>[];
165
100
  provide: TProvideRegistry;
166
101
  constructor(options?: TMoostOptions | undefined);
167
- protected wooksApp?: Wooks;
168
- protected wooksHttp?: WooksHttp;
102
+ adapter<T extends object, A extends TMoostAdapter<T>>(a: A): A;
169
103
  protected unregisteredControllers: (TObject | TFunction)[];
170
- listen(): Promise<Wooks>;
171
- listen(port: number): Promise<Wooks>;
172
- listen(port: number, cb: () => void): Promise<Wooks>;
173
- listen(port: number, hostname: string): Promise<Wooks>;
174
- listen(port: number, hostname: string, cb: () => void): Promise<Wooks>;
175
- close(): Promise<unknown> | undefined;
176
- private init;
104
+ init(): Promise<void>;
177
105
  protected bindControllers(): Promise<void>;
178
106
  protected bindController(controller: TFunction | TObject, provide: TProvideRegistry, globalPrefix: string, replaceOwnPrefix?: string): Promise<void>;
179
107
  applyGlobalPipes(...items: (TPipeFn | TPipeData)[]): this;
@@ -209,56 +137,11 @@ export declare function Param(name: string): ParameterDecorator;
209
137
  */
210
138
  export declare function Params(): ParameterDecorator;
211
139
 
212
- export declare const Patch: (path?: string) => MethodDecorator;
213
-
214
- export declare const Post: (path?: string) => MethodDecorator;
215
-
216
140
  export declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator;
217
141
 
218
- export declare const Put: (path?: string) => MethodDecorator;
219
-
220
- /**
221
- * Get Query Item value or the whole parsed Query as an object
222
- * @decorator
223
- * @param name - query item name (optional)
224
- * @paramType string | object
225
- */
226
- export declare function Query(name?: string): ParameterDecorator;
227
-
228
- /**
229
- * Get Raw Request Body Buffer
230
- * @decorator
231
- * @paramType Promise<Buffer>
232
- */
233
- export declare function RawBody(): ParameterDecorator;
234
-
235
- /**
236
- * Get Raw Request Instance
237
- * @decorator
238
- * @paramType IncomingMessage
239
- */
240
- export declare function Req(): ParameterDecorator;
241
-
242
- /**
243
- * Get Request Unique Identificator (UUID)
244
- * @decorator
245
- * @paramType string
246
- */
247
- export declare function ReqId(): ParameterDecorator;
248
-
249
142
  declare function Required_2(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
250
143
  export { Required_2 as Required }
251
144
 
252
- /**
253
- * Get Raw Response Object
254
- * @decorator
255
- * @param options - passthrough options
256
- * @paramType string
257
- */
258
- export declare function Res(options?: {
259
- passthrough: boolean;
260
- }): ParameterDecorator;
261
-
262
145
  /**
263
146
  * Hook to the Response Status
264
147
  * @decorator
@@ -270,13 +153,6 @@ export declare function Resolve(resolver: () => unknown, label?: string): Parame
270
153
 
271
154
  export declare const resolvePipe: TPipeFn;
272
155
 
273
- /**
274
- * Hook to the Response Status
275
- * @decorator
276
- * @paramType TStatusHook
277
- */
278
- export declare const StatusHook: ParameterDecorator;
279
-
280
156
  declare type TAny = any;
281
157
 
282
158
  declare type TAnyFn = {
@@ -296,6 +172,7 @@ declare interface TClassFunctionConstructor<T extends TAnyFn = TAnyFn> {
296
172
  }
297
173
 
298
174
  declare interface TCommonMetaFields {
175
+ id?: string;
299
176
  label?: string;
300
177
  optional?: boolean;
301
178
  required?: boolean;
@@ -307,7 +184,7 @@ declare interface TCommonMoostMeta {
307
184
 
308
185
  declare type TFunction = Function;
309
186
 
310
- export declare type TInjectableScope = 'FOR_REQUEST' | 'SINGLETON';
187
+ export declare type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
311
188
 
312
189
  export declare type TInterceptorAfter = (response: TAny, reply: (response: TAny) => void) => void | Promise<void>;
313
190
 
@@ -335,6 +212,27 @@ export declare enum TInterceptorPriority {
335
212
  AFTER_ALL = 6
336
213
  }
337
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
+
338
236
  export declare interface TMoostMetadata extends TProstoAndCommonMetadata {
339
237
  inherit?: boolean;
340
238
  dto?: TValidoDtoOptions;
@@ -349,10 +247,7 @@ export declare interface TMoostMetadata extends TProstoAndCommonMetadata {
349
247
  }[];
350
248
  injectable?: true | TInjectableScope;
351
249
  interceptors?: TInterceptorData[];
352
- httpHandler?: {
353
- method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
354
- path: string;
355
- }[];
250
+ handlers?: TMoostHandler<TAny>[];
356
251
  validators?: TValidoFn[];
357
252
  validatorsOfItem?: TValidoFn[];
358
253
  arrayType?: true | TValidateArrayOptions;
@@ -361,9 +256,6 @@ export declare interface TMoostMetadata extends TProstoAndCommonMetadata {
361
256
 
362
257
  export declare interface TMoostOptions {
363
258
  globalPrefix?: string;
364
- port?: number | string;
365
- hostname?: string;
366
- wooksOptions?: TWooksOptions;
367
259
  }
368
260
 
369
261
  export declare interface TMoostParamsMetadata extends TProstoParamsAndCommonMetadata {
@@ -414,13 +306,6 @@ declare interface TValidatePipeOptions {
414
306
  errorLimit?: number;
415
307
  }
416
308
 
417
- /**
418
- * Get Requested URL
419
- * @decorator
420
- * @paramType string
421
- */
422
- export declare function Url(): ParameterDecorator;
423
-
424
309
  export declare function useControllerMeta<T extends TMoostMetadata = TMoostMetadata>(): {
425
310
  getClassMeta: () => T | undefined;
426
311
  getMethodMeta: () => T | undefined;