@nattyjs/common 0.0.1-beta.63 → 0.0.1-beta.65

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
@@ -48,11 +48,19 @@ const commonContainer = new class {
48
48
  }
49
49
  }
50
50
  };
51
- const secureConfig = { sensitiveProps: ["password", "mobileNo", "email"] };
51
+ const secureConfig = {};
52
52
  this.nattyConfig = { ...{ api: { rootPath: "api" }, ...{ static: { enabled: true } }, autoGeneratePort: true, modelBinding, globalConfig: {}, secure: secureConfig }, ...config };
53
53
  }
54
54
  setupBuildOptions(options) {
55
- this.buildOptions = options;
55
+ this.buildOptions = {
56
+ commandName: options.commandName || "dev",
57
+ mode: options.mode || "dev",
58
+ port: options.port ?? 0,
59
+ rootDir: options.rootDir || process.cwd(),
60
+ outDir: options.outDir || "dist",
61
+ startupFilePath: options.startupFilePath || "dist/index.js",
62
+ clearScreen: options.clearScreen ?? false
63
+ };
56
64
  }
57
65
  setEnvTsDefinition(tsDefinition) {
58
66
  this.envTsDefinition = tsDefinition;
@@ -66,6 +74,9 @@ const commonContainer = new class {
66
74
  getMetadataValue(key, propName) {
67
75
  return this.metadataConfig[propName].get(key);
68
76
  }
77
+ deleteMetadataValue(key, propName) {
78
+ this.metadataConfig[propName].delete(key);
79
+ }
69
80
  get globalConfig() {
70
81
  return this.nattyConfig.global || {};
71
82
  }
@@ -132,6 +143,8 @@ const typeContainer = new class {
132
143
  const routes = {};
133
144
  for (const key of this.controllerInfo.keys()) {
134
145
  const classInfo = this.controllerInfo.get(key);
146
+ if (!classInfo?.filePath)
147
+ continue;
135
148
  let templateInfo = {
136
149
  path: `.${classInfo.filePath.replace(TS_EXTENSION, BLANK).replace(BACK_SLASH_REGEX, RIGHT_SLASH)}`,
137
150
  route: this.getControllerRouteName(classInfo),
@@ -252,12 +265,12 @@ function resolvePath(path$1) {
252
265
  }
253
266
 
254
267
  async function readEnv() {
255
- const envConfig = commonContainer.nattyCliConfig.env;
268
+ const envConfig = commonContainer.nattyCliConfig?.env;
256
269
  let filePath = envConfig?.dictionary ? void 0 : getPath([ENVIRONMENTS, commonContainer.buildOptions.mode && commonContainer.buildOptions.mode !== "dev" ? `.env.${commonContainer.buildOptions.mode}` : `.env`]);
257
270
  if (envConfig && envConfig.path)
258
271
  filePath = resolvePath(envConfig.path);
259
272
  let parsedEnvTsDefinition = {};
260
- let parsedEnv = commonContainer.nattyCliConfig.env?.dictionary;
273
+ let parsedEnv = envConfig?.dictionary;
261
274
  if (!parsedEnv && filePath && fs.existsSync(filePath)) {
262
275
  const { parsed, error } = dotenv__namespace.config({
263
276
  debug: !!process.env.DEBUG || void 0,
@@ -656,10 +669,11 @@ class AbstractRunner {
656
669
  }
657
670
 
658
671
  async function getPort() {
659
- const portNumber = commonContainer.nattyConfig?.port || 3200;
660
- if (portNumber)
661
- return portNumber;
662
- const port = await getPortPlease.getPort({ ports: [portNumber, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)] });
672
+ const configuredPort = commonContainer.nattyConfig?.port;
673
+ if (configuredPort)
674
+ return configuredPort;
675
+ const preferredPorts = [3200, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)];
676
+ const port = await getPortPlease.getPort({ ports: preferredPorts });
663
677
  commonContainer.nattyConfig.port = port;
664
678
  return port;
665
679
  }
package/dist/index.d.ts CHANGED
@@ -48,7 +48,7 @@ interface IAuthorizationContext extends IActionExecutingContext {
48
48
  }
49
49
 
50
50
  declare abstract class AuthorizationFilter {
51
- abstract onAuthorization(httpContext: IAuthorizationContext): Promise<boolean>;
51
+ abstract onAuthorization(httpContext: IAuthorizationContext, permissionRequirement: any): Promise<boolean>;
52
52
  onFailedAuthorization(): ProblemDetail;
53
53
  }
54
54
 
@@ -77,6 +77,7 @@ interface PayloadConfig {
77
77
 
78
78
  interface SecureConfig {
79
79
  sensitiveProps?: String[];
80
+ denyByDefault?: boolean;
80
81
  }
81
82
 
82
83
  interface PreInitEventConfig {
@@ -122,6 +123,12 @@ declare abstract class AbstractRunner {
122
123
  protected exec(command: string, args: any[], cwd?: string): Promise<null | string>;
123
124
  }
124
125
 
126
+ interface DiTransformConfig {
127
+ decoratorName?: string;
128
+ markerName?: string;
129
+ stripPathPrefixes?: string[];
130
+ }
131
+
125
132
  interface EnvConfig {
126
133
  path: string;
127
134
  dictionary: {
@@ -140,6 +147,7 @@ interface LibraryConfig {
140
147
  interface NattyCliConfig {
141
148
  library?: Partial<LibraryConfig>;
142
149
  env?: Partial<EnvConfig>;
150
+ di?: DiTransformConfig;
143
151
  runner?: ClassType<AbstractRunner>;
144
152
  port?: number;
145
153
  openapi?: GenerateOpenApiOptions;
@@ -151,7 +159,7 @@ interface NattyCliConfig {
151
159
  declare const commonContainer: {
152
160
  setupConfig(config?: NattyConfig): void;
153
161
  setupCliConfig(config: NattyCliConfig): void;
154
- setupBuildOptions(options: BuildOptions): any;
162
+ setupBuildOptions(options: Partial<BuildOptions>): void;
155
163
  get nattyConfig(): NattyConfig;
156
164
  get nattyCliConfig(): NattyCliConfig;
157
165
  get buildOptions(): BuildOptions;
@@ -169,6 +177,7 @@ declare const commonContainer: {
169
177
  }): void;
170
178
  setMetadata(key: string, value: any, propName: string): void;
171
179
  getMetadataValue(key: string, propName: string): any;
180
+ deleteMetadataValue(key: string, propName: string): void;
172
181
  get globalConfig(): GlobalConfig;
173
182
  registerType(type: TypesInfo): void;
174
183
  types: TypesInfo;
@@ -323,8 +332,6 @@ declare abstract class AbstractConsoleLogger {
323
332
  declare class ConsoleLogger extends AbstractConsoleLogger {
324
333
  }
325
334
 
326
- declare function typed(): <T extends {
327
- new (...args: any[]): {};
328
- }>(OriginalClass: T) => T;
335
+ declare function typed(): <T extends new (...args: any[]) => {}>(OriginalClass: T) => T;
329
336
 
330
- export { ALLOW_METHODS, AbstractRunner, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, Claim, ClassType, ConsoleLogger, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, FrameworkType, GET, GlobalConfig, HTTP_METHOD_ROUTES, IActionExecutedContext, IActionExecutingContext, IAuthorizationContext, IExecutionContext, IGNORE_METHODS, List, MetaConfigProps, Middleware, NattyAppConfig, NattyCliConfig, NattyConfig, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, WebScheduleConfig, commonContainer, createPath, createTestServer, getPath, getPort, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer, typed };
337
+ export { ALLOW_METHODS, AbstractRunner, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, Claim, ClassType, ConsoleLogger, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, DiTransformConfig, ENVIRONMENTS, ExceptionFilter, FrameworkType, GET, GlobalConfig, HTTP_METHOD_ROUTES, IActionExecutedContext, IActionExecutingContext, IAuthorizationContext, IExecutionContext, IGNORE_METHODS, List, MetaConfigProps, Middleware, NattyAppConfig, NattyCliConfig, NattyConfig, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, WebScheduleConfig, commonContainer, createPath, createTestServer, getPath, getPort, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer, typed };
package/dist/index.mjs CHANGED
@@ -31,11 +31,19 @@ const commonContainer = new class {
31
31
  }
32
32
  }
33
33
  };
34
- const secureConfig = { sensitiveProps: ["password", "mobileNo", "email"] };
34
+ const secureConfig = {};
35
35
  this.nattyConfig = { ...{ api: { rootPath: "api" }, ...{ static: { enabled: true } }, autoGeneratePort: true, modelBinding, globalConfig: {}, secure: secureConfig }, ...config };
36
36
  }
37
37
  setupBuildOptions(options) {
38
- this.buildOptions = options;
38
+ this.buildOptions = {
39
+ commandName: options.commandName || "dev",
40
+ mode: options.mode || "dev",
41
+ port: options.port ?? 0,
42
+ rootDir: options.rootDir || process.cwd(),
43
+ outDir: options.outDir || "dist",
44
+ startupFilePath: options.startupFilePath || "dist/index.js",
45
+ clearScreen: options.clearScreen ?? false
46
+ };
39
47
  }
40
48
  setEnvTsDefinition(tsDefinition) {
41
49
  this.envTsDefinition = tsDefinition;
@@ -49,6 +57,9 @@ const commonContainer = new class {
49
57
  getMetadataValue(key, propName) {
50
58
  return this.metadataConfig[propName].get(key);
51
59
  }
60
+ deleteMetadataValue(key, propName) {
61
+ this.metadataConfig[propName].delete(key);
62
+ }
52
63
  get globalConfig() {
53
64
  return this.nattyConfig.global || {};
54
65
  }
@@ -115,6 +126,8 @@ const typeContainer = new class {
115
126
  const routes = {};
116
127
  for (const key of this.controllerInfo.keys()) {
117
128
  const classInfo = this.controllerInfo.get(key);
129
+ if (!classInfo?.filePath)
130
+ continue;
118
131
  let templateInfo = {
119
132
  path: `.${classInfo.filePath.replace(TS_EXTENSION, BLANK).replace(BACK_SLASH_REGEX, RIGHT_SLASH)}`,
120
133
  route: this.getControllerRouteName(classInfo),
@@ -235,12 +248,12 @@ function resolvePath(path) {
235
248
  }
236
249
 
237
250
  async function readEnv() {
238
- const envConfig = commonContainer.nattyCliConfig.env;
251
+ const envConfig = commonContainer.nattyCliConfig?.env;
239
252
  let filePath = envConfig?.dictionary ? void 0 : getPath([ENVIRONMENTS, commonContainer.buildOptions.mode && commonContainer.buildOptions.mode !== "dev" ? `.env.${commonContainer.buildOptions.mode}` : `.env`]);
240
253
  if (envConfig && envConfig.path)
241
254
  filePath = resolvePath(envConfig.path);
242
255
  let parsedEnvTsDefinition = {};
243
- let parsedEnv = commonContainer.nattyCliConfig.env?.dictionary;
256
+ let parsedEnv = envConfig?.dictionary;
244
257
  if (!parsedEnv && filePath && existsSync(filePath)) {
245
258
  const { parsed, error } = dotenv.config({
246
259
  debug: !!process.env.DEBUG || void 0,
@@ -639,10 +652,11 @@ class AbstractRunner {
639
652
  }
640
653
 
641
654
  async function getPort() {
642
- const portNumber = commonContainer.nattyConfig?.port || 3200;
643
- if (portNumber)
644
- return portNumber;
645
- const port = await getPort$1({ ports: [portNumber, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)] });
655
+ const configuredPort = commonContainer.nattyConfig?.port;
656
+ if (configuredPort)
657
+ return configuredPort;
658
+ const preferredPorts = [3200, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)];
659
+ const port = await getPort$1({ ports: preferredPorts });
646
660
  commonContainer.nattyConfig.port = port;
647
661
  return port;
648
662
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/common",
3
- "version": "0.0.1-beta.63",
3
+ "version": "0.0.1-beta.65",
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>",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "20.3.1",
24
- "@nattyjs/types": "0.0.1-beta.63",
24
+ "@nattyjs/types": "0.0.1-beta.65",
25
25
  "unbuild": "1.2.1"
26
26
  }
27
27
  }