moost 0.0.1-beta.0 → 0.0.1-beta.1

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,24 @@ function Resolve(resolver, label) {
311
311
  getMoostMate().decorate('resolver', resolver)(target, key, index);
312
312
  };
313
313
  }
314
+ function Authorization(name) {
315
+ return Resolve(() => {
316
+ var _a, _b;
317
+ const auth = wooks.useAuthorization();
318
+ switch (name) {
319
+ case 'username':
320
+ return auth.isBasic() ? (_a = auth.basicCredentials()) === null || _a === void 0 ? void 0 : _a.username : undefined;
321
+ case 'password':
322
+ return auth.isBasic() ? (_b = auth.basicCredentials()) === null || _b === void 0 ? void 0 : _b.password : undefined;
323
+ case 'bearer':
324
+ return auth.isBearer() ? auth.authorization : undefined;
325
+ case 'raw':
326
+ return auth.authRawCredentials();
327
+ case 'type':
328
+ return auth.authType();
329
+ }
330
+ }, 'authorization');
331
+ }
314
332
  function Header(name) {
315
333
  return Resolve(() => {
316
334
  const headers = wooks.useHeaders();
@@ -378,8 +396,18 @@ function fillLabel(target, key, index, name) {
378
396
  }
379
397
  }
380
398
 
399
+ function Injectable(scope = true) {
400
+ return getMoostMate().decorate('injectable', scope);
401
+ }
402
+ const insureInjectable = getMoostMate().decorate((meta) => {
403
+ if (!meta.injectable)
404
+ meta.injectable = true;
405
+ return meta;
406
+ });
407
+
381
408
  function Controller(prefix) {
382
- return getMoostMate().decorate('controller', { prefix: prefix || '' });
409
+ const mate = getMoostMate();
410
+ return mate.apply(insureInjectable, mate.decorate('controller', { prefix: prefix || '' }));
383
411
  }
384
412
  function ImportController(prefix, controller, provide) {
385
413
  return getMoostMate().decorate('importController', {
@@ -389,10 +417,6 @@ function ImportController(prefix, controller, provide) {
389
417
  }, true);
390
418
  }
391
419
 
392
- function Injectable(scope = true) {
393
- return getMoostMate().decorate('injectable', scope);
394
- }
395
-
396
420
  function Circular(resolver) {
397
421
  return getMoostMate().decorate('circular', resolver);
398
422
  }
@@ -695,6 +719,7 @@ const validatePipe = (opts) => {
695
719
  };
696
720
 
697
721
  exports.All = All;
722
+ exports.Authorization = Authorization;
698
723
  exports.Body = Body;
699
724
  exports.Circular = Circular;
700
725
  exports.Const = Const;
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;
@@ -1,4 +1,4 @@
1
- import { useCurrentWooksContext, useRequest, useHeaders, useCookies, useRouteParams, useSearchParams, useResponse, useBody, Wooks, WooksError } from 'wooks';
1
+ import { useCurrentWooksContext, useRequest, 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,24 @@ function Resolve(resolver, label) {
307
307
  getMoostMate().decorate('resolver', resolver)(target, key, index);
308
308
  };
309
309
  }
310
+ function Authorization(name) {
311
+ return Resolve(() => {
312
+ var _a, _b;
313
+ const auth = useAuthorization();
314
+ switch (name) {
315
+ case 'username':
316
+ return auth.isBasic() ? (_a = auth.basicCredentials()) === null || _a === void 0 ? void 0 : _a.username : undefined;
317
+ case 'password':
318
+ return auth.isBasic() ? (_b = auth.basicCredentials()) === null || _b === void 0 ? void 0 : _b.password : undefined;
319
+ case 'bearer':
320
+ return auth.isBearer() ? auth.authorization : undefined;
321
+ case 'raw':
322
+ return auth.authRawCredentials();
323
+ case 'type':
324
+ return auth.authType();
325
+ }
326
+ }, 'authorization');
327
+ }
310
328
  function Header(name) {
311
329
  return Resolve(() => {
312
330
  const headers = useHeaders();
@@ -374,8 +392,18 @@ function fillLabel(target, key, index, name) {
374
392
  }
375
393
  }
376
394
 
395
+ function Injectable(scope = true) {
396
+ return getMoostMate().decorate('injectable', scope);
397
+ }
398
+ const insureInjectable = getMoostMate().decorate((meta) => {
399
+ if (!meta.injectable)
400
+ meta.injectable = true;
401
+ return meta;
402
+ });
403
+
377
404
  function Controller(prefix) {
378
- return getMoostMate().decorate('controller', { prefix: prefix || '' });
405
+ const mate = getMoostMate();
406
+ return mate.apply(insureInjectable, mate.decorate('controller', { prefix: prefix || '' }));
379
407
  }
380
408
  function ImportController(prefix, controller, provide) {
381
409
  return getMoostMate().decorate('importController', {
@@ -385,10 +413,6 @@ function ImportController(prefix, controller, provide) {
385
413
  }, true);
386
414
  }
387
415
 
388
- function Injectable(scope = true) {
389
- return getMoostMate().decorate('injectable', scope);
390
- }
391
-
392
416
  function Circular(resolver) {
393
417
  return getMoostMate().decorate('circular', resolver);
394
418
  }
@@ -690,4 +714,4 @@ const validatePipe = (opts) => {
690
714
  return pipe;
691
715
  };
692
716
 
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 };
717
+ export { All, Authorization, 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 };
@@ -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,5 @@
1
1
  export declare function Resolve(resolver: () => unknown, label?: string): ParameterDecorator;
2
+ export declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator;
2
3
  export declare function Header(name: string): ParameterDecorator;
3
4
  export declare function Cookie(name: string): ParameterDecorator;
4
5
  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,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.1",
4
4
  "description": "Metadata driven Web App Framework",
5
5
  "main": "index.js",
6
6
  "module": "dist/moost.esm-bundler.js",