moost 0.0.1-beta.0 → 0.0.1-beta.2

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 prostojs
3
+ Copyright (c) 2022 prostojs
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -11,6 +11,20 @@
11
11
 
12
12
  Moost is a Metadata driven Web App Framework inspired by [nestjs](https://nestjs.com/) and powered by [wooks](https://github.com/prostojs/wooks).
13
13
 
14
+ The main ideas behind Moost are:
15
+ 1. Use the power of TS decorators to describe your app
16
+ 2. Use the power of [wooks](https://github.com/prostojs/wooks) to process http requests
17
+ 3. Make it easier to control dependency injections
18
+ 4. Use as less external dependencies as possible
19
+
20
+ What's the difference to [nestjs](https://nestjs.com/)?
21
+ 1. It does not use additional `modules` abstraction
22
+ 2. It utilizes reusable dependency injection framework [@prostojs/infact](https://github.com/prostojs/infact)
23
+ 3. It uses metadata layer powered by [@prostojs/mate](https://github.com/prostojs/mate)
24
+ 4. It supports DTOs and validations powered by [@prostojs/valido](https://github.com/prostojs/valido)
25
+ 5. It does not use express or fastify
26
+ 6. Currently it does not support any of additional techniques (like ORMs, Queues etc.)
27
+
14
28
  ## Quick Start
15
29
 
16
30
  ```ts
@@ -311,6 +311,27 @@ function Resolve(resolver, label) {
311
311
  getMoostMate().decorate('resolver', resolver)(target, key, index);
312
312
  };
313
313
  }
314
+ const StatusHook = Resolve(() => wooks.useStatus(), 'status');
315
+ const HeaderHook = (name) => Resolve(() => wooks.useRespHeader(name), name);
316
+ const CookieHook = (name) => Resolve(() => wooks.useRespCookie(name), name);
317
+ function Authorization(name) {
318
+ return Resolve(() => {
319
+ var _a, _b;
320
+ const auth = wooks.useAuthorization();
321
+ switch (name) {
322
+ case 'username':
323
+ return auth.isBasic() ? (_a = auth.basicCredentials()) === null || _a === void 0 ? void 0 : _a.username : undefined;
324
+ case 'password':
325
+ return auth.isBasic() ? (_b = auth.basicCredentials()) === null || _b === void 0 ? void 0 : _b.password : undefined;
326
+ case 'bearer':
327
+ return auth.isBearer() ? auth.authorization : undefined;
328
+ case 'raw':
329
+ return auth.authRawCredentials();
330
+ case 'type':
331
+ return auth.authType();
332
+ }
333
+ }, 'authorization');
334
+ }
314
335
  function Header(name) {
315
336
  return Resolve(() => {
316
337
  const headers = wooks.useHeaders();
@@ -378,8 +399,18 @@ function fillLabel(target, key, index, name) {
378
399
  }
379
400
  }
380
401
 
402
+ function Injectable(scope = true) {
403
+ return getMoostMate().decorate('injectable', scope);
404
+ }
405
+ const insureInjectable = getMoostMate().decorate((meta) => {
406
+ if (!meta.injectable)
407
+ meta.injectable = true;
408
+ return meta;
409
+ });
410
+
381
411
  function Controller(prefix) {
382
- return getMoostMate().decorate('controller', { prefix: prefix || '' });
412
+ const mate = getMoostMate();
413
+ return mate.apply(insureInjectable, mate.decorate('controller', { prefix: prefix || '' }));
383
414
  }
384
415
  function ImportController(prefix, controller, provide) {
385
416
  return getMoostMate().decorate('importController', {
@@ -389,10 +420,6 @@ function ImportController(prefix, controller, provide) {
389
420
  }, true);
390
421
  }
391
422
 
392
- function Injectable(scope = true) {
393
- return getMoostMate().decorate('injectable', scope);
394
- }
395
-
396
423
  function Circular(resolver) {
397
424
  return getMoostMate().decorate('circular', resolver);
398
425
  }
@@ -695,15 +722,18 @@ const validatePipe = (opts) => {
695
722
  };
696
723
 
697
724
  exports.All = All;
725
+ exports.Authorization = Authorization;
698
726
  exports.Body = Body;
699
727
  exports.Circular = Circular;
700
728
  exports.Const = Const;
701
729
  exports.Controller = Controller;
702
730
  exports.Cookie = Cookie;
731
+ exports.CookieHook = CookieHook;
703
732
  exports.Delete = Delete;
704
733
  exports.Dto = Dto;
705
734
  exports.Get = Get;
706
735
  exports.Header = Header;
736
+ exports.HeaderHook = HeaderHook;
707
737
  exports.HttpMethod = HttpMethod;
708
738
  exports.ImportController = ImportController;
709
739
  exports.Inject = Inject;
@@ -733,6 +763,7 @@ exports.ReqId = ReqId;
733
763
  exports.Required = Required;
734
764
  exports.Res = Res;
735
765
  exports.Resolve = Resolve;
766
+ exports.StatusHook = StatusHook;
736
767
  exports.Url = Url;
737
768
  exports.Validate = Validate;
738
769
  exports.genericTypesCastPipe = genericTypesCastPipe;
package/dist/moost.d.ts CHANGED
@@ -13,6 +13,8 @@ import { Wooks } from 'wooks';
13
13
 
14
14
  export declare const All: (path?: string) => MethodDecorator;
15
15
 
16
+ export declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator;
17
+
16
18
  export declare function Body(): ParameterDecorator;
17
19
 
18
20
  export declare function Circular<T = unknown>(resolver: () => TClassConstructor<T>): ParameterDecorator;
@@ -23,6 +25,8 @@ export declare function Controller(prefix?: string): ClassDecorator;
23
25
 
24
26
  export declare function Cookie(name: string): ParameterDecorator;
25
27
 
28
+ export declare const CookieHook: (name: string) => ParameterDecorator;
29
+
26
30
  export declare const Delete: (path?: string) => MethodDecorator;
27
31
 
28
32
  export declare function Dto(dtoOptions?: TValidoDtoOptions): ClassDecorator;
@@ -35,6 +39,8 @@ export declare function getMoostMate(): Mate<TMoostMetadata>;
35
39
 
36
40
  export declare function Header(name: string): ParameterDecorator;
37
41
 
42
+ export declare const HeaderHook: (name: string) => ParameterDecorator;
43
+
38
44
  export declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', path?: string): MethodDecorator;
39
45
 
40
46
  export declare function ImportController(controller: TFunction | TObject, provide?: TProvideRegistry): ClassDecorator;
@@ -123,6 +129,8 @@ export declare function Resolve(resolver: () => unknown, label?: string): Parame
123
129
 
124
130
  export declare const resolvePipe: TPipeFn;
125
131
 
132
+ export declare const StatusHook: ParameterDecorator;
133
+
126
134
  declare type TAny = any;
127
135
 
128
136
  declare type TAnyFn = {
@@ -1,4 +1,4 @@
1
- import { useCurrentWooksContext, useRequest, useHeaders, useCookies, useRouteParams, useSearchParams, useResponse, useBody, Wooks, WooksError } from 'wooks';
1
+ import { useCurrentWooksContext, useRequest, useStatus, useRespHeader, useRespCookie, useAuthorization, useHeaders, useCookies, useRouteParams, useSearchParams, useResponse, useBody, Wooks, WooksError } from 'wooks';
2
2
  import { Mate, getConstructor, isConstructor } from '@prostojs/mate';
3
3
  import { Infact, createProvideRegistry } from '@prostojs/infact';
4
4
  import { validoIsTypeOf, validoIsString, validoIsNumber, validoIsBoolean, Valido } from '@prostojs/valido';
@@ -307,6 +307,27 @@ function Resolve(resolver, label) {
307
307
  getMoostMate().decorate('resolver', resolver)(target, key, index);
308
308
  };
309
309
  }
310
+ const StatusHook = Resolve(() => useStatus(), 'status');
311
+ const HeaderHook = (name) => Resolve(() => useRespHeader(name), name);
312
+ const CookieHook = (name) => Resolve(() => useRespCookie(name), name);
313
+ function Authorization(name) {
314
+ return Resolve(() => {
315
+ var _a, _b;
316
+ const auth = useAuthorization();
317
+ switch (name) {
318
+ case 'username':
319
+ return auth.isBasic() ? (_a = auth.basicCredentials()) === null || _a === void 0 ? void 0 : _a.username : undefined;
320
+ case 'password':
321
+ return auth.isBasic() ? (_b = auth.basicCredentials()) === null || _b === void 0 ? void 0 : _b.password : undefined;
322
+ case 'bearer':
323
+ return auth.isBearer() ? auth.authorization : undefined;
324
+ case 'raw':
325
+ return auth.authRawCredentials();
326
+ case 'type':
327
+ return auth.authType();
328
+ }
329
+ }, 'authorization');
330
+ }
310
331
  function Header(name) {
311
332
  return Resolve(() => {
312
333
  const headers = useHeaders();
@@ -374,8 +395,18 @@ function fillLabel(target, key, index, name) {
374
395
  }
375
396
  }
376
397
 
398
+ function Injectable(scope = true) {
399
+ return getMoostMate().decorate('injectable', scope);
400
+ }
401
+ const insureInjectable = getMoostMate().decorate((meta) => {
402
+ if (!meta.injectable)
403
+ meta.injectable = true;
404
+ return meta;
405
+ });
406
+
377
407
  function Controller(prefix) {
378
- return getMoostMate().decorate('controller', { prefix: prefix || '' });
408
+ const mate = getMoostMate();
409
+ return mate.apply(insureInjectable, mate.decorate('controller', { prefix: prefix || '' }));
379
410
  }
380
411
  function ImportController(prefix, controller, provide) {
381
412
  return getMoostMate().decorate('importController', {
@@ -385,10 +416,6 @@ function ImportController(prefix, controller, provide) {
385
416
  }, true);
386
417
  }
387
418
 
388
- function Injectable(scope = true) {
389
- return getMoostMate().decorate('injectable', scope);
390
- }
391
-
392
419
  function Circular(resolver) {
393
420
  return getMoostMate().decorate('circular', resolver);
394
421
  }
@@ -690,4 +717,4 @@ const validatePipe = (opts) => {
690
717
  return pipe;
691
718
  };
692
719
 
693
- export { All, Body, Circular, Const, Controller, Cookie, Delete, Dto, Get, Header, HttpMethod, ImportController, Inject, Injectable, Intercept, Ip, IpList, IsArray, IsBoolean, IsNumber, IsString, IsTypeOf, Label, Method, Moost, Optional, Param, Params, Patch, Post, Provide, Put, Query, RawBody, Req, ReqId, Required, Res, Resolve, TInterceptorPriority, TPipePriority, Url, Validate, genericTypesCastPipe, getMoostMate, resolvePipe, useControllerMeta, validatePipe };
720
+ export { All, Authorization, Body, Circular, Const, Controller, Cookie, CookieHook, Delete, Dto, Get, Header, HeaderHook, HttpMethod, ImportController, Inject, Injectable, Intercept, Ip, IpList, IsArray, IsBoolean, IsNumber, IsString, IsTypeOf, Label, Method, Moost, Optional, Param, Params, Patch, Post, Provide, Put, Query, RawBody, Req, ReqId, Required, Res, Resolve, StatusHook, TInterceptorPriority, TPipePriority, Url, Validate, genericTypesCastPipe, getMoostMate, resolvePipe, useControllerMeta, validatePipe };
@@ -1 +1 @@
1
- {"version":3,"file":"controller.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/controller.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAE7C,wBAAgB,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CAE1D;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAA;AAE7G,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAA"}
1
+ {"version":3,"file":"controller.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/controller.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAG7C,wBAAgB,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CAG1D;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAA;AAE7G,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAA"}
@@ -1,7 +1,7 @@
1
1
  export * from './http-method.decorator';
2
2
  export * from './resolve.decorator';
3
3
  export * from './controller.decorator';
4
- export * from './injectable.decorator';
4
+ export { Injectable } from './injectable.decorator';
5
5
  export * from './circular.decorator';
6
6
  export * from './intercept.decorator';
7
7
  export * from './provide.decorator';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA"}
@@ -1,3 +1,4 @@
1
1
  import { TInjectableScope } from '../metadata/moost-metadata';
2
2
  export declare function Injectable(scope?: true | TInjectableScope): ClassDecorator;
3
+ export declare const insureInjectable: MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
3
4
  //# sourceMappingURL=injectable.decorator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE3E,wBAAgB,UAAU,CAAC,KAAK,GAAE,IAAI,GAAG,gBAAuB,GAAG,cAAc,CAEhF"}
1
+ {"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE3E,wBAAgB,UAAU,CAAC,KAAK,GAAE,IAAI,GAAG,gBAAuB,GAAG,cAAc,CAEhF;AAED,eAAO,MAAM,gBAAgB,2EAG3B,CAAA"}
@@ -1,4 +1,8 @@
1
1
  export declare function Resolve(resolver: () => unknown, label?: string): ParameterDecorator;
2
+ export declare const StatusHook: ParameterDecorator;
3
+ export declare const HeaderHook: (name: string) => ParameterDecorator;
4
+ export declare const CookieHook: (name: string) => ParameterDecorator;
5
+ export declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator;
2
6
  export declare function Header(name: string): ParameterDecorator;
3
7
  export declare function Cookie(name: string): ParameterDecorator;
4
8
  export declare function Param(name: string): ParameterDecorator;
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/resolve.decorator.ts"],"names":[],"mappings":"AAKA,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAKnF;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,sBAKlC;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,sBAElC;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,sBAEjC;AAED,wBAAgB,MAAM,uBAErB;AAED,wBAAgB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAYvD;AAED,wBAAgB,GAAG,uBAElB;AAED,wBAAgB,MAAM,uBAErB;AAED,wBAAgB,GAAG,uBAElB;AAED,wBAAgB,KAAK,uBAEpB;AAED,wBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,sBAEhD;AAED,wBAAgB,MAAM,uBAErB;AAED,wBAAgB,GAAG,CAAC,OAAO,CAAC,EAAE;IAAE,WAAW,EAAE,OAAO,CAAA;CAAE,sBAErD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,sBAEnD;AAED,wBAAgB,IAAI,uBAEnB;AAED,wBAAgB,OAAO,uBAEtB"}
1
+ {"version":3,"file":"resolve.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/resolve.decorator.ts"],"names":[],"mappings":"AAKA,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAKnF;AAED,eAAO,MAAM,UAAU,oBAAuC,CAAA;AAC9D,eAAO,MAAM,UAAU,SAAU,MAAM,uBAA6C,CAAA;AACpF,eAAO,MAAM,UAAU,SAAU,MAAM,uBAA6C,CAAA;AAEpF,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,sBAgBtF;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,sBAKlC;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,sBAElC;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,sBAEjC;AAED,wBAAgB,MAAM,uBAErB;AAED,wBAAgB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAYvD;AAED,wBAAgB,GAAG,uBAElB;AAED,wBAAgB,MAAM,uBAErB;AAED,wBAAgB,GAAG,uBAElB;AAED,wBAAgB,KAAK,uBAEpB;AAED,wBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,sBAEhD;AAED,wBAAgB,MAAM,uBAErB;AAED,wBAAgB,GAAG,CAAC,OAAO,CAAC,EAAE;IAAE,WAAW,EAAE,OAAO,CAAA;CAAE,sBAErD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,sBAEnD;AAED,wBAAgB,IAAI,uBAEnB;AAED,wBAAgB,OAAO,uBAEtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moost",
3
- "version": "0.0.1-beta.0",
3
+ "version": "0.0.1-beta.2",
4
4
  "description": "Metadata driven Web App Framework",
5
5
  "main": "index.js",
6
6
  "module": "dist/moost.esm-bundler.js",
@@ -44,7 +44,7 @@
44
44
  "@prostojs/infact": "^0.0.12",
45
45
  "@prostojs/mate": "^0.1.10",
46
46
  "@prostojs/valido": "^0.0.2",
47
- "wooks": "^0.0.1-beta.1"
47
+ "wooks": "^0.0.1-beta.3"
48
48
  },
49
49
  "gitHooks": {
50
50
  "commit-msg": "node scripts/verifyCommit.js"