@nattyjs/core 0.0.1-beta.2 → 0.0.1-beta.21

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
@@ -60,10 +60,13 @@ const nattyContainer = new class {
60
60
  this.container = /* @__PURE__ */ new Map();
61
61
  this.containerState = /* @__PURE__ */ new Map();
62
62
  }
63
- setup(config, routes, types) {
63
+ get types() {
64
+ return common.commonContainer.types;
65
+ }
66
+ setup(config, routes, resolver) {
64
67
  this.config = config;
65
68
  this.routes = routes;
66
- this.types = types;
69
+ this.resolver = resolver;
67
70
  }
68
71
  getTypes() {
69
72
  return StaticContainer.types;
@@ -116,13 +119,12 @@ const nattyContainer = new class {
116
119
  function init(config, appConfig) {
117
120
  common.commonContainer.setupConfig(config);
118
121
  common.commonContainer.setEnvTsDefinition(appConfig.envTsDefinition);
119
- nattyContainer.setup(config, appConfig.routes, appConfig.types);
120
- initializeModule(config);
121
- return appConfig.routes;
122
+ nattyContainer.setup(config, appConfig.routes, appConfig.resolver);
123
+ return initializeModule(config);
122
124
  }
123
125
  function initializeModule(config) {
124
126
  if (config.app) {
125
- config.app.init(config);
127
+ return config.app.init(config);
126
128
  }
127
129
  }
128
130
 
@@ -525,12 +527,14 @@ class ParameterTypeConverter extends BaseResponse {
525
527
  } else {
526
528
  if (this.isArrayType(property.type) && Array.isArray(value)) {
527
529
  let arrayValue = body[property.name] = [];
528
- let arrayInvalidProps = invalidProps[property.name] = [];
529
530
  for (const item of value) {
530
531
  const sanitizeValue = this.sanitizer[property.type.toLowerCase()] ? this.sanitizer[property.type.toLowerCase()](item) : item;
531
- if (sanitizeValue === INVALID_VALUE)
532
+ if (sanitizeValue === INVALID_VALUE) {
533
+ let arrayInvalidProps = invalidProps[property.name];
534
+ if (!arrayInvalidProps)
535
+ arrayInvalidProps = invalidProps[property.name] = [];
532
536
  arrayInvalidProps.push(property);
533
- else
537
+ } else
534
538
  arrayValue.push(sanitizeValue);
535
539
  }
536
540
  } else
@@ -558,7 +562,7 @@ class ParameterTypeConverter extends BaseResponse {
558
562
  }
559
563
  convertToInstance(entityName, data) {
560
564
  const typesInfo = this.types[entityName];
561
- const target = this.getClassTarget(typesInfo.path) || entityContainer.getTarget(entityName);
565
+ const target = this.getClassTarget(typesInfo.path, entityName) || entityContainer.getTarget(entityName);
562
566
  let instance = null;
563
567
  if (target) {
564
568
  instance = new target();
@@ -567,11 +571,10 @@ class ParameterTypeConverter extends BaseResponse {
567
571
  instance = data;
568
572
  return instance;
569
573
  }
570
- getClassTarget(resolver) {
571
- if (resolver) {
572
- const classInfo = resolver();
573
- const name = Object.keys(classInfo)[0];
574
- return classInfo[name];
574
+ getClassTarget(path, entityName) {
575
+ if (path) {
576
+ const classInfo = nattyContainer.resolver(path);
577
+ return classInfo[entityName];
575
578
  }
576
579
  return void 0;
577
580
  }
@@ -1232,10 +1235,28 @@ function authenticationOnly() {
1232
1235
  };
1233
1236
  }
1234
1237
 
1238
+ function setEnvInfo(envTsDefinition, envValueInfo) {
1239
+ if (envTsDefinition && envValueInfo) {
1240
+ common.commonContainer.setEnvTsDefinition(envTsDefinition);
1241
+ Object.keys(envValueInfo).forEach((key) => process.env[key] = envValueInfo[key]);
1242
+ }
1243
+ }
1244
+
1245
+ function authorize(permission) {
1246
+ return function(target, propertyKey, descriptor) {
1247
+ base({
1248
+ target,
1249
+ propertyKey,
1250
+ descriptor
1251
+ }, DecoratorType.authorize, permission);
1252
+ };
1253
+ }
1254
+
1235
1255
  exports.$request = $request;
1236
1256
  exports.AbstractModelState = AbstractModelState;
1237
1257
  exports.BadRequestResult = BadRequestResult;
1238
1258
  exports.BaseController = BaseController;
1259
+ exports.CreateProblemDetail = CreateProblemDetail;
1239
1260
  exports.CreatedResult = CreatedResult;
1240
1261
  exports.Delete = Delete;
1241
1262
  exports.ForbiddenAccessException = ForbiddenAccessException;
@@ -1246,6 +1267,7 @@ exports.HttpException = HttpException;
1246
1267
  exports.HttpHandler = HttpHandler;
1247
1268
  exports.HttpNotFoundException = HttpNotFoundException;
1248
1269
  exports.HttpResponse = HttpResponse;
1270
+ exports.HttpStatusCode = HttpStatusCode;
1249
1271
  exports.ModelBindingContext = ModelBindingContext;
1250
1272
  exports.NoContentResult = NoContentResult;
1251
1273
  exports.NotFoundResult = NotFoundResult;
@@ -1254,6 +1276,7 @@ exports.RunOn = RunOn;
1254
1276
  exports.UnauthorizedAccessException = UnauthorizedAccessException;
1255
1277
  exports.anonymous = anonymous;
1256
1278
  exports.authenticationOnly = authenticationOnly;
1279
+ exports.authorize = authorize;
1257
1280
  exports.badRequest = badRequest;
1258
1281
  exports.created = created;
1259
1282
  exports.defineNattyConfig = defineNattyConfig;
@@ -1270,4 +1293,5 @@ exports.post = post;
1270
1293
  exports.put = put;
1271
1294
  exports.registerDecorator = registerDecorator;
1272
1295
  exports.route = route;
1296
+ exports.setEnvInfo = setEnvInfo;
1273
1297
  exports.useFilter = useFilter;
package/dist/index.d.ts CHANGED
@@ -59,6 +59,64 @@ declare function put(path: string): (target: any, propertyKey?: string, descript
59
59
 
60
60
  declare function Delete(): (target: any, propertyKey?: string, descriptor?: any) => void;
61
61
 
62
+ interface RouteConfig {
63
+ controller: Function;
64
+ parameters: Array<{
65
+ name: string;
66
+ type: string;
67
+ }>;
68
+ get: {
69
+ [key: string]: {
70
+ name: string;
71
+ parameters: Array<{
72
+ name: string;
73
+ type: string;
74
+ }>;
75
+ returnType: string;
76
+ };
77
+ };
78
+ post: {
79
+ [key: string]: {
80
+ name: string;
81
+ parameters: Array<{
82
+ name: string;
83
+ type: string;
84
+ }>;
85
+ returnType: string;
86
+ };
87
+ };
88
+ put: {
89
+ [key: string]: {
90
+ name: string;
91
+ parameters: Array<{
92
+ name: string;
93
+ type: string;
94
+ }>;
95
+ returnType: string;
96
+ };
97
+ };
98
+ delete: {
99
+ [key: string]: {
100
+ name: string;
101
+ parameters: Array<{
102
+ name: string;
103
+ type: string;
104
+ }>;
105
+ returnType: string;
106
+ };
107
+ };
108
+ }
109
+
110
+ declare function init(config: NattyConfig, appConfig: {
111
+ routes: {
112
+ [key: string]: RouteConfig;
113
+ };
114
+ envTsDefinition: {
115
+ [key: string]: string;
116
+ };
117
+ resolver: (path: string) => {};
118
+ }): any;
119
+
62
120
  interface DecoratorInfo {
63
121
  httpMethod: string;
64
122
  route: string;
@@ -190,66 +248,6 @@ interface IHttpResult {
190
248
  getResponse(): HttpResponseInit;
191
249
  }
192
250
 
193
- interface RouteConfig {
194
- controller: Function;
195
- parameters: Array<{
196
- name: string;
197
- type: string;
198
- }>;
199
- get: {
200
- [key: string]: {
201
- name: string;
202
- parameters: Array<{
203
- name: string;
204
- type: string;
205
- }>;
206
- returnType: string;
207
- };
208
- };
209
- post: {
210
- [key: string]: {
211
- name: string;
212
- parameters: Array<{
213
- name: string;
214
- type: string;
215
- }>;
216
- returnType: string;
217
- };
218
- };
219
- put: {
220
- [key: string]: {
221
- name: string;
222
- parameters: Array<{
223
- name: string;
224
- type: string;
225
- }>;
226
- returnType: string;
227
- };
228
- };
229
- delete: {
230
- [key: string]: {
231
- name: string;
232
- parameters: Array<{
233
- name: string;
234
- type: string;
235
- }>;
236
- returnType: string;
237
- };
238
- };
239
- }
240
-
241
- declare function init(config: NattyConfig, appConfig: {
242
- routes: {
243
- [key: string]: RouteConfig;
244
- };
245
- envTsDefinition: {
246
- [key: string]: string;
247
- };
248
- types?: TypesInfo;
249
- }): {
250
- [key: string]: RouteConfig;
251
- };
252
-
253
251
  declare class HttpRequest {
254
252
  private httpRequest;
255
253
  constructor(http: HttpRequestInit);
@@ -465,4 +463,27 @@ declare function anonymous(): (target: any, propertyKey?: string, descriptor?: a
465
463
 
466
464
  declare function authenticationOnly(): (target: any, propertyKey?: string, descriptor?: any) => void;
467
465
 
468
- export { $request, AbstractModelState, BadRequestResult, BaseController, BuildOptions, ClassTypeInfo, CreatedResult, Delete, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpModule, HttpNotFoundException, HttpResponse, MethodInfo$1 as MethodInfo, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, ParameterInfo, RunOn, TypeInfo$1 as TypeInfo, UnauthorizedAccessException, anonymous, authenticationOnly, badRequest, created, defineNattyConfig, entityContainer, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, useFilter };
466
+ declare function setEnvInfo(envTsDefinition: {
467
+ [key: string]: string;
468
+ }, envValueInfo: {
469
+ [key: string]: any;
470
+ }): void;
471
+
472
+ declare enum HttpStatusCode {
473
+ success = 200,
474
+ created = 201,
475
+ noContent = 204,
476
+ notFound = 404,
477
+ unAuthorized = 401,
478
+ forbiddenAccess = 403,
479
+ badRequest = 400,
480
+ serverError = 500
481
+ }
482
+
483
+ declare function authorize(permission: {
484
+ [key: string]: any;
485
+ }): (target: any, propertyKey?: string, descriptor?: any) => void;
486
+
487
+ declare function CreateProblemDetail(modelName: string, detail: any): ProblemDetail;
488
+
489
+ export { $request, AbstractModelState, BadRequestResult, BaseController, BuildOptions, ClassTypeInfo, CreateProblemDetail, CreatedResult, Delete, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpModule, HttpNotFoundException, HttpResponse, HttpStatusCode, MethodInfo$1 as MethodInfo, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, ParameterInfo, RunOn, TypeInfo$1 as TypeInfo, UnauthorizedAccessException, anonymous, authenticationOnly, authorize, badRequest, created, defineNattyConfig, entityContainer, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, setEnvInfo, useFilter };
package/dist/index.mjs CHANGED
@@ -58,10 +58,13 @@ const nattyContainer = new class {
58
58
  this.container = /* @__PURE__ */ new Map();
59
59
  this.containerState = /* @__PURE__ */ new Map();
60
60
  }
61
- setup(config, routes, types) {
61
+ get types() {
62
+ return commonContainer.types;
63
+ }
64
+ setup(config, routes, resolver) {
62
65
  this.config = config;
63
66
  this.routes = routes;
64
- this.types = types;
67
+ this.resolver = resolver;
65
68
  }
66
69
  getTypes() {
67
70
  return StaticContainer.types;
@@ -114,13 +117,12 @@ const nattyContainer = new class {
114
117
  function init(config, appConfig) {
115
118
  commonContainer.setupConfig(config);
116
119
  commonContainer.setEnvTsDefinition(appConfig.envTsDefinition);
117
- nattyContainer.setup(config, appConfig.routes, appConfig.types);
118
- initializeModule(config);
119
- return appConfig.routes;
120
+ nattyContainer.setup(config, appConfig.routes, appConfig.resolver);
121
+ return initializeModule(config);
120
122
  }
121
123
  function initializeModule(config) {
122
124
  if (config.app) {
123
- config.app.init(config);
125
+ return config.app.init(config);
124
126
  }
125
127
  }
126
128
 
@@ -523,12 +525,14 @@ class ParameterTypeConverter extends BaseResponse {
523
525
  } else {
524
526
  if (this.isArrayType(property.type) && Array.isArray(value)) {
525
527
  let arrayValue = body[property.name] = [];
526
- let arrayInvalidProps = invalidProps[property.name] = [];
527
528
  for (const item of value) {
528
529
  const sanitizeValue = this.sanitizer[property.type.toLowerCase()] ? this.sanitizer[property.type.toLowerCase()](item) : item;
529
- if (sanitizeValue === INVALID_VALUE)
530
+ if (sanitizeValue === INVALID_VALUE) {
531
+ let arrayInvalidProps = invalidProps[property.name];
532
+ if (!arrayInvalidProps)
533
+ arrayInvalidProps = invalidProps[property.name] = [];
530
534
  arrayInvalidProps.push(property);
531
- else
535
+ } else
532
536
  arrayValue.push(sanitizeValue);
533
537
  }
534
538
  } else
@@ -556,7 +560,7 @@ class ParameterTypeConverter extends BaseResponse {
556
560
  }
557
561
  convertToInstance(entityName, data) {
558
562
  const typesInfo = this.types[entityName];
559
- const target = this.getClassTarget(typesInfo.path) || entityContainer.getTarget(entityName);
563
+ const target = this.getClassTarget(typesInfo.path, entityName) || entityContainer.getTarget(entityName);
560
564
  let instance = null;
561
565
  if (target) {
562
566
  instance = new target();
@@ -565,11 +569,10 @@ class ParameterTypeConverter extends BaseResponse {
565
569
  instance = data;
566
570
  return instance;
567
571
  }
568
- getClassTarget(resolver) {
569
- if (resolver) {
570
- const classInfo = resolver();
571
- const name = Object.keys(classInfo)[0];
572
- return classInfo[name];
572
+ getClassTarget(path, entityName) {
573
+ if (path) {
574
+ const classInfo = nattyContainer.resolver(path);
575
+ return classInfo[entityName];
573
576
  }
574
577
  return void 0;
575
578
  }
@@ -1230,4 +1233,21 @@ function authenticationOnly() {
1230
1233
  };
1231
1234
  }
1232
1235
 
1233
- export { $request, AbstractModelState, BadRequestResult, BaseController, CreatedResult, Delete, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpNotFoundException, HttpResponse, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, RunOn, UnauthorizedAccessException, anonymous, authenticationOnly, badRequest, created, defineNattyConfig, entityContainer, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, useFilter };
1236
+ function setEnvInfo(envTsDefinition, envValueInfo) {
1237
+ if (envTsDefinition && envValueInfo) {
1238
+ commonContainer.setEnvTsDefinition(envTsDefinition);
1239
+ Object.keys(envValueInfo).forEach((key) => process.env[key] = envValueInfo[key]);
1240
+ }
1241
+ }
1242
+
1243
+ function authorize(permission) {
1244
+ return function(target, propertyKey, descriptor) {
1245
+ base({
1246
+ target,
1247
+ propertyKey,
1248
+ descriptor
1249
+ }, DecoratorType.authorize, permission);
1250
+ };
1251
+ }
1252
+
1253
+ export { $request, AbstractModelState, BadRequestResult, BaseController, CreateProblemDetail, CreatedResult, Delete, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpNotFoundException, HttpResponse, HttpStatusCode, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, RunOn, UnauthorizedAccessException, anonymous, authenticationOnly, authorize, badRequest, created, defineNattyConfig, entityContainer, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, setEnvInfo, useFilter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/core",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.21",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "ajayojha",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "tsyringe": "^4.7.0",
19
19
  "path-to-regexp": "6.2.1",
20
- "@nattyjs/common": "0.0.1-beta.2"
20
+ "@nattyjs/common": "0.0.1-beta.21"
21
21
  },
22
22
  "devDependencies": {
23
23
  "unbuild": "1.2.1"