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

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
 
@@ -558,7 +560,7 @@ class ParameterTypeConverter extends BaseResponse {
558
560
  }
559
561
  convertToInstance(entityName, data) {
560
562
  const typesInfo = this.types[entityName];
561
- const target = this.getClassTarget(typesInfo.path) || entityContainer.getTarget(entityName);
563
+ const target = this.getClassTarget(typesInfo.path, entityName) || entityContainer.getTarget(entityName);
562
564
  let instance = null;
563
565
  if (target) {
564
566
  instance = new target();
@@ -567,11 +569,10 @@ class ParameterTypeConverter extends BaseResponse {
567
569
  instance = data;
568
570
  return instance;
569
571
  }
570
- getClassTarget(resolver) {
571
- if (resolver) {
572
- const classInfo = resolver();
573
- const name = Object.keys(classInfo)[0];
574
- return classInfo[name];
572
+ getClassTarget(path, entityName) {
573
+ if (path) {
574
+ const classInfo = nattyContainer.resolver(path);
575
+ return classInfo[entityName];
575
576
  }
576
577
  return void 0;
577
578
  }
@@ -1232,10 +1233,28 @@ function authenticationOnly() {
1232
1233
  };
1233
1234
  }
1234
1235
 
1236
+ function setEnvInfo(envTsDefinition, envValueInfo) {
1237
+ if (envTsDefinition && envValueInfo) {
1238
+ common.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
+
1235
1253
  exports.$request = $request;
1236
1254
  exports.AbstractModelState = AbstractModelState;
1237
1255
  exports.BadRequestResult = BadRequestResult;
1238
1256
  exports.BaseController = BaseController;
1257
+ exports.CreateProblemDetail = CreateProblemDetail;
1239
1258
  exports.CreatedResult = CreatedResult;
1240
1259
  exports.Delete = Delete;
1241
1260
  exports.ForbiddenAccessException = ForbiddenAccessException;
@@ -1246,6 +1265,7 @@ exports.HttpException = HttpException;
1246
1265
  exports.HttpHandler = HttpHandler;
1247
1266
  exports.HttpNotFoundException = HttpNotFoundException;
1248
1267
  exports.HttpResponse = HttpResponse;
1268
+ exports.HttpStatusCode = HttpStatusCode;
1249
1269
  exports.ModelBindingContext = ModelBindingContext;
1250
1270
  exports.NoContentResult = NoContentResult;
1251
1271
  exports.NotFoundResult = NotFoundResult;
@@ -1254,6 +1274,7 @@ exports.RunOn = RunOn;
1254
1274
  exports.UnauthorizedAccessException = UnauthorizedAccessException;
1255
1275
  exports.anonymous = anonymous;
1256
1276
  exports.authenticationOnly = authenticationOnly;
1277
+ exports.authorize = authorize;
1257
1278
  exports.badRequest = badRequest;
1258
1279
  exports.created = created;
1259
1280
  exports.defineNattyConfig = defineNattyConfig;
@@ -1270,4 +1291,5 @@ exports.post = post;
1270
1291
  exports.put = put;
1271
1292
  exports.registerDecorator = registerDecorator;
1272
1293
  exports.route = route;
1294
+ exports.setEnvInfo = setEnvInfo;
1273
1295
  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
 
@@ -556,7 +558,7 @@ class ParameterTypeConverter extends BaseResponse {
556
558
  }
557
559
  convertToInstance(entityName, data) {
558
560
  const typesInfo = this.types[entityName];
559
- const target = this.getClassTarget(typesInfo.path) || entityContainer.getTarget(entityName);
561
+ const target = this.getClassTarget(typesInfo.path, entityName) || entityContainer.getTarget(entityName);
560
562
  let instance = null;
561
563
  if (target) {
562
564
  instance = new target();
@@ -565,11 +567,10 @@ class ParameterTypeConverter extends BaseResponse {
565
567
  instance = data;
566
568
  return instance;
567
569
  }
568
- getClassTarget(resolver) {
569
- if (resolver) {
570
- const classInfo = resolver();
571
- const name = Object.keys(classInfo)[0];
572
- return classInfo[name];
570
+ getClassTarget(path, entityName) {
571
+ if (path) {
572
+ const classInfo = nattyContainer.resolver(path);
573
+ return classInfo[entityName];
573
574
  }
574
575
  return void 0;
575
576
  }
@@ -1230,4 +1231,21 @@ function authenticationOnly() {
1230
1231
  };
1231
1232
  }
1232
1233
 
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 };
1234
+ function setEnvInfo(envTsDefinition, envValueInfo) {
1235
+ if (envTsDefinition && envValueInfo) {
1236
+ commonContainer.setEnvTsDefinition(envTsDefinition);
1237
+ Object.keys(envValueInfo).forEach((key) => process.env[key] = envValueInfo[key]);
1238
+ }
1239
+ }
1240
+
1241
+ function authorize(permission) {
1242
+ return function(target, propertyKey, descriptor) {
1243
+ base({
1244
+ target,
1245
+ propertyKey,
1246
+ descriptor
1247
+ }, DecoratorType.authorize, permission);
1248
+ };
1249
+ }
1250
+
1251
+ 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.20",
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.20"
21
21
  },
22
22
  "devDependencies": {
23
23
  "unbuild": "1.2.1"