@nattyjs/common 0.0.1-beta.0 → 0.0.1-beta.10

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
@@ -25,6 +25,14 @@ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
25
25
  const commonContainer = new class {
26
26
  constructor() {
27
27
  this.metadataConfig = { services: /* @__PURE__ */ new Map() };
28
+ this.types = {};
29
+ }
30
+ registerType(type) {
31
+ for (const key of Object.keys(type))
32
+ this.types[key] = type[key];
33
+ }
34
+ setupCliConfig(config) {
35
+ this.nattyCliConfig = config;
28
36
  }
29
37
  setupConfig(config) {
30
38
  const modelBinding = {
@@ -35,7 +43,7 @@ const commonContainer = new class {
35
43
  }
36
44
  }
37
45
  };
38
- this.nattyConfig = { ...{ api: { rootPath: "api" }, modelBinding, globalConfig: {} }, ...config };
46
+ this.nattyConfig = { ...{ api: { rootPath: "api" }, autoGeneratePort: true, modelBinding, globalConfig: {} }, ...config };
39
47
  }
40
48
  setupBuildOptions(options) {
41
49
  this.buildOptions = options;
@@ -43,6 +51,9 @@ const commonContainer = new class {
43
51
  setEnvTsDefinition(tsDefinition) {
44
52
  this.envTsDefinition = tsDefinition;
45
53
  }
54
+ setEnvValueInfo(valueInfo) {
55
+ this.envValueInfo = valueInfo;
56
+ }
46
57
  setMetadata(key, value, propName) {
47
58
  this.metadataConfig[propName].set(key, value);
48
59
  }
@@ -186,6 +197,7 @@ function tsDefinition(value) {
186
197
 
187
198
  function getEnvTsDefinition(parsed) {
188
199
  let serverTypedDefinition = {};
200
+ let envVariableValueInfo = {};
189
201
  if (parsed) {
190
202
  const keys = Object.keys(parsed);
191
203
  if (keys.length > 0) {
@@ -193,10 +205,11 @@ function getEnvTsDefinition(parsed) {
193
205
  let keyName = key;
194
206
  const { definition, transformValue } = tsDefinition(parsed[key]);
195
207
  serverTypedDefinition[keyName] = definition;
208
+ envVariableValueInfo[keyName] = parsed[keyName];
196
209
  });
197
210
  }
198
211
  }
199
- return serverTypedDefinition;
212
+ return { parsedEnvTsDefinition: serverTypedDefinition, envVariableValueInfo };
200
213
  }
201
214
 
202
215
  function createPath(pathToCreate) {
@@ -228,8 +241,10 @@ async function readEnv() {
228
241
  debug: !!process.env.DEBUG || void 0,
229
242
  path: filePath
230
243
  });
231
- parsedEnvTsDefinition = getEnvTsDefinition(parsed);
244
+ const info = getEnvTsDefinition(parsed);
245
+ parsedEnvTsDefinition = info.parsedEnvTsDefinition;
232
246
  commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
247
+ commonContainer.setEnvValueInfo(info.envVariableValueInfo);
233
248
  dotenvExpand__namespace.expand({ parsed });
234
249
  }
235
250
  return parsedEnvTsDefinition;
@@ -279,10 +294,10 @@ function readEnvKey(key) {
279
294
  }
280
295
 
281
296
  class UserIdentity {
282
- constructor(isAuthenticate, id, claim) {
297
+ constructor(isAuthenticate, id, claims) {
283
298
  this.isAuthenticate = isAuthenticate;
284
299
  this.id = id;
285
- this.claim = claim;
300
+ this.claims = claims;
286
301
  }
287
302
  }
288
303
 
@@ -559,6 +574,19 @@ class List {
559
574
  }
560
575
  }
561
576
 
577
+ var FrameworkType = /* @__PURE__ */ ((FrameworkType2) => {
578
+ FrameworkType2[FrameworkType2["Express"] = 0] = "Express";
579
+ FrameworkType2[FrameworkType2["Fastify"] = 1] = "Fastify";
580
+ FrameworkType2[FrameworkType2["AzureFunction"] = 2] = "AzureFunction";
581
+ FrameworkType2[FrameworkType2["Firebase"] = 3] = "Firebase";
582
+ FrameworkType2[FrameworkType2["Lambda"] = 4] = "Lambda";
583
+ return FrameworkType2;
584
+ })(FrameworkType || {});
585
+
586
+ function registerType(type) {
587
+ commonContainer.registerType(type);
588
+ }
589
+
562
590
  exports.ALLOW_METHODS = ALLOW_METHODS;
563
591
  exports.ActionFilter = ActionFilter;
564
592
  exports.AuthenticationFilter = AuthenticationFilter;
@@ -571,6 +599,7 @@ exports.DEFAULT_CHILD_PATH = DEFAULT_CHILD_PATH;
571
599
  exports.DELETE = DELETE;
572
600
  exports.ENVIRONMENTS = ENVIRONMENTS;
573
601
  exports.ExceptionFilter = ExceptionFilter;
602
+ exports.FrameworkType = FrameworkType;
574
603
  exports.GET = GET;
575
604
  exports.HTTP_METHOD_ROUTES = HTTP_METHOD_ROUTES;
576
605
  exports.IGNORE_METHODS = IGNORE_METHODS;
@@ -595,4 +624,5 @@ exports.isFunction = isFunction;
595
624
  exports.isObject = isObject;
596
625
  exports.readEnv = readEnv;
597
626
  exports.readEnvKey = readEnvKey;
627
+ exports.registerType = registerType;
598
628
  exports.typeContainer = typeContainer;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RequestRouteInfo, IHttpResult, IModelBindingContext, ProblemDetail, IExceptionContext, HttpResponseInit, NattyTestModule, ModelBinding, BuildOptions, ClassTypeInfo } from '@nattyjs/types';
1
+ import { RequestRouteInfo, IHttpResult, IModelBindingContext, ProblemDetail, IExceptionContext, HttpResponseInit, NattyTestModule, ModelBinding, NattyCliConfig, BuildOptions, TypesInfo, ClassTypeInfo } from '@nattyjs/types';
2
2
 
3
3
  interface ClassType<T> extends Function {
4
4
  new (...args: any[]): T;
@@ -7,8 +7,8 @@ interface ClassType<T> extends Function {
7
7
  declare class UserIdentity<T> {
8
8
  isAuthenticate: boolean;
9
9
  id?: any;
10
- claim?: T;
11
- constructor(isAuthenticate: boolean, id?: any, claim?: T);
10
+ claims?: T;
11
+ constructor(isAuthenticate: boolean, id?: any, claims?: T);
12
12
  }
13
13
 
14
14
  interface IExecutionContext {
@@ -61,22 +61,32 @@ interface NattyConfig {
61
61
  };
62
62
  modelBinding?: ModelBinding;
63
63
  global?: GlobalConfig;
64
+ autoGeneratePort?: boolean;
64
65
  }
65
66
 
66
67
  declare const commonContainer: {
67
68
  setupConfig(config?: NattyConfig): void;
69
+ setupCliConfig(config: NattyCliConfig): void;
68
70
  setupBuildOptions(options: BuildOptions): any;
69
71
  get nattyConfig(): NattyConfig;
72
+ get nattyCliConfig(): NattyCliConfig;
70
73
  get buildOptions(): BuildOptions;
71
74
  get envTsDefinition(): {
72
75
  [key: string]: string;
73
76
  };
77
+ get envValueInfo(): {
78
+ [key: string]: string;
79
+ };
74
80
  setEnvTsDefinition(tsDefinition: {
75
81
  [key: string]: string;
76
82
  }): void;
83
+ setEnvValueInfo(envValueInfo: {
84
+ [key: string]: string;
85
+ }): void;
77
86
  setMetadata(key: string, value: any, propName: string): void;
78
87
  getMetadataValue(key: string, propName: string): any;
79
88
  get globalConfig(): GlobalConfig;
89
+ registerType(type: TypesInfo): void;
80
90
  };
81
91
 
82
92
  declare const typeContainer: {
@@ -200,4 +210,18 @@ declare class List<T> {
200
210
  declare function isObject(value: any): boolean;
201
211
  declare function isEqual(first: any, second: any): boolean;
202
212
 
203
- export { ALLOW_METHODS, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, Claim, ClassType, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, GET, GlobalConfig, HTTP_METHOD_ROUTES, IActionExecutedContext, IActionExecutingContext, IExecutionContext, IGNORE_METHODS, List, MetaConfigProps, Middleware, NattyConfig, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, commonContainer, createPath, createTestServer, getPath, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, typeContainer };
213
+ declare enum FrameworkType {
214
+ Express = 0,
215
+ Fastify = 1,
216
+ AzureFunction = 2,
217
+ Firebase = 3,
218
+ Lambda = 4
219
+ }
220
+
221
+ interface NattyAppConfig extends NattyConfig {
222
+ framework: FrameworkType;
223
+ }
224
+
225
+ declare function registerType(type: TypesInfo): void;
226
+
227
+ export { ALLOW_METHODS, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, Claim, ClassType, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, FrameworkType, GET, GlobalConfig, HTTP_METHOD_ROUTES, IActionExecutedContext, IActionExecutingContext, IExecutionContext, IGNORE_METHODS, List, MetaConfigProps, Middleware, NattyAppConfig, NattyConfig, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, commonContainer, createPath, createTestServer, getPath, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer };
package/dist/index.mjs CHANGED
@@ -7,6 +7,14 @@ import * as path from 'path';
7
7
  const commonContainer = new class {
8
8
  constructor() {
9
9
  this.metadataConfig = { services: /* @__PURE__ */ new Map() };
10
+ this.types = {};
11
+ }
12
+ registerType(type) {
13
+ for (const key of Object.keys(type))
14
+ this.types[key] = type[key];
15
+ }
16
+ setupCliConfig(config) {
17
+ this.nattyCliConfig = config;
10
18
  }
11
19
  setupConfig(config) {
12
20
  const modelBinding = {
@@ -17,7 +25,7 @@ const commonContainer = new class {
17
25
  }
18
26
  }
19
27
  };
20
- this.nattyConfig = { ...{ api: { rootPath: "api" }, modelBinding, globalConfig: {} }, ...config };
28
+ this.nattyConfig = { ...{ api: { rootPath: "api" }, autoGeneratePort: true, modelBinding, globalConfig: {} }, ...config };
21
29
  }
22
30
  setupBuildOptions(options) {
23
31
  this.buildOptions = options;
@@ -25,6 +33,9 @@ const commonContainer = new class {
25
33
  setEnvTsDefinition(tsDefinition) {
26
34
  this.envTsDefinition = tsDefinition;
27
35
  }
36
+ setEnvValueInfo(valueInfo) {
37
+ this.envValueInfo = valueInfo;
38
+ }
28
39
  setMetadata(key, value, propName) {
29
40
  this.metadataConfig[propName].set(key, value);
30
41
  }
@@ -168,6 +179,7 @@ function tsDefinition(value) {
168
179
 
169
180
  function getEnvTsDefinition(parsed) {
170
181
  let serverTypedDefinition = {};
182
+ let envVariableValueInfo = {};
171
183
  if (parsed) {
172
184
  const keys = Object.keys(parsed);
173
185
  if (keys.length > 0) {
@@ -175,10 +187,11 @@ function getEnvTsDefinition(parsed) {
175
187
  let keyName = key;
176
188
  const { definition, transformValue } = tsDefinition(parsed[key]);
177
189
  serverTypedDefinition[keyName] = definition;
190
+ envVariableValueInfo[keyName] = parsed[keyName];
178
191
  });
179
192
  }
180
193
  }
181
- return serverTypedDefinition;
194
+ return { parsedEnvTsDefinition: serverTypedDefinition, envVariableValueInfo };
182
195
  }
183
196
 
184
197
  function createPath(pathToCreate) {
@@ -210,8 +223,10 @@ async function readEnv() {
210
223
  debug: !!process.env.DEBUG || void 0,
211
224
  path: filePath
212
225
  });
213
- parsedEnvTsDefinition = getEnvTsDefinition(parsed);
226
+ const info = getEnvTsDefinition(parsed);
227
+ parsedEnvTsDefinition = info.parsedEnvTsDefinition;
214
228
  commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
229
+ commonContainer.setEnvValueInfo(info.envVariableValueInfo);
215
230
  dotenvExpand.expand({ parsed });
216
231
  }
217
232
  return parsedEnvTsDefinition;
@@ -261,10 +276,10 @@ function readEnvKey(key) {
261
276
  }
262
277
 
263
278
  class UserIdentity {
264
- constructor(isAuthenticate, id, claim) {
279
+ constructor(isAuthenticate, id, claims) {
265
280
  this.isAuthenticate = isAuthenticate;
266
281
  this.id = id;
267
- this.claim = claim;
282
+ this.claims = claims;
268
283
  }
269
284
  }
270
285
 
@@ -541,4 +556,17 @@ class List {
541
556
  }
542
557
  }
543
558
 
544
- export { ALLOW_METHODS, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, GET, HTTP_METHOD_ROUTES, IGNORE_METHODS, List, MetaConfigProps, Middleware, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, commonContainer, createPath, createTestServer, getPath, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, typeContainer };
559
+ var FrameworkType = /* @__PURE__ */ ((FrameworkType2) => {
560
+ FrameworkType2[FrameworkType2["Express"] = 0] = "Express";
561
+ FrameworkType2[FrameworkType2["Fastify"] = 1] = "Fastify";
562
+ FrameworkType2[FrameworkType2["AzureFunction"] = 2] = "AzureFunction";
563
+ FrameworkType2[FrameworkType2["Firebase"] = 3] = "Firebase";
564
+ FrameworkType2[FrameworkType2["Lambda"] = 4] = "Lambda";
565
+ return FrameworkType2;
566
+ })(FrameworkType || {});
567
+
568
+ function registerType(type) {
569
+ commonContainer.registerType(type);
570
+ }
571
+
572
+ export { ALLOW_METHODS, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, FrameworkType, GET, HTTP_METHOD_ROUTES, IGNORE_METHODS, List, MetaConfigProps, Middleware, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, commonContainer, createPath, createTestServer, getPath, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/common",
3
- "version": "0.0.1-beta.0",
3
+ "version": "0.0.1-beta.10",
4
4
  "description": "Now I’m the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin’ letters to relatives / Embellishin’ my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
5
5
  "keywords": [],
6
6
  "author": "ajayojha <ojhaajay@outlook.com>",
@@ -14,10 +14,13 @@
14
14
  "scripts": {
15
15
  "build": "unbuild"
16
16
  },
17
+ "dependencies": {
18
+ "dotenv": "16.3.1",
19
+ "dotenv-expand": "10.0.0"
20
+ },
17
21
  "devDependencies": {
18
22
  "@types/node": "20.3.1",
19
- "@nattyjs/types": "0.0.1-beta.0",
20
- "unbuild": "1.2.1",
21
- "dotenv-expand": "10.0.0"
23
+ "@nattyjs/types": "0.0.1-beta.10",
24
+ "unbuild": "1.2.1"
22
25
  }
23
26
  }