@nattyjs/common 0.0.1-beta.3 → 0.0.1-beta.30
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 +122 -10
- package/dist/index.d.ts +86 -5
- package/dist/index.mjs +119 -11
- package/package.json +8 -4
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,8 @@ const fs = require('fs');
|
|
|
4
4
|
const dotenv = require('dotenv');
|
|
5
5
|
const dotenvExpand = require('dotenv-expand');
|
|
6
6
|
const path = require('path');
|
|
7
|
+
const child_process = require('child_process');
|
|
8
|
+
const getPortPlease = require('get-port-please');
|
|
7
9
|
|
|
8
10
|
function _interopNamespaceCompat(e) {
|
|
9
11
|
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
@@ -25,6 +27,17 @@ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
|
25
27
|
const commonContainer = new class {
|
|
26
28
|
constructor() {
|
|
27
29
|
this.metadataConfig = { services: /* @__PURE__ */ new Map() };
|
|
30
|
+
this.types = {};
|
|
31
|
+
}
|
|
32
|
+
registerType(type) {
|
|
33
|
+
if (type) {
|
|
34
|
+
if (typeof type === "string")
|
|
35
|
+
type = JSON.parse(type);
|
|
36
|
+
this.types[type.name] = type;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
setupCliConfig(config) {
|
|
40
|
+
this.nattyCliConfig = config;
|
|
28
41
|
}
|
|
29
42
|
setupConfig(config) {
|
|
30
43
|
const modelBinding = {
|
|
@@ -35,7 +48,8 @@ const commonContainer = new class {
|
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
};
|
|
38
|
-
|
|
51
|
+
const secureConfig = { sensitiveProps: ["password", "mobileNo", "email"] };
|
|
52
|
+
this.nattyConfig = { ...{ api: { rootPath: "api" }, autoGeneratePort: true, modelBinding, globalConfig: {}, secure: secureConfig }, ...config };
|
|
39
53
|
}
|
|
40
54
|
setupBuildOptions(options) {
|
|
41
55
|
this.buildOptions = options;
|
|
@@ -225,20 +239,29 @@ function getPath(pathCollection, isIncludeRoot = true, isCreateFolder = false) {
|
|
|
225
239
|
return currentPath;
|
|
226
240
|
}
|
|
227
241
|
|
|
242
|
+
function resolvePath(path$1) {
|
|
243
|
+
return path.resolve(commonContainer.buildOptions.rootDir, path$1);
|
|
244
|
+
}
|
|
245
|
+
|
|
228
246
|
async function readEnv() {
|
|
229
|
-
|
|
247
|
+
const envConfig = commonContainer.nattyCliConfig.env;
|
|
248
|
+
let filePath = envConfig?.dictionary ? void 0 : getPath([ENVIRONMENTS, commonContainer.buildOptions.mode && commonContainer.buildOptions.mode !== "dev" ? `.env.${commonContainer.buildOptions.mode}` : `.env`]);
|
|
249
|
+
if (envConfig && envConfig.path)
|
|
250
|
+
filePath = resolvePath(envConfig.path);
|
|
230
251
|
let parsedEnvTsDefinition = {};
|
|
231
|
-
|
|
252
|
+
let parsedEnv = commonContainer.nattyCliConfig.env?.dictionary;
|
|
253
|
+
if (!parsedEnv && filePath && fs.existsSync(filePath)) {
|
|
232
254
|
const { parsed, error } = dotenv__namespace.config({
|
|
233
255
|
debug: !!process.env.DEBUG || void 0,
|
|
234
256
|
path: filePath
|
|
235
257
|
});
|
|
236
|
-
|
|
237
|
-
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
238
|
-
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
239
|
-
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
240
|
-
dotenvExpand__namespace.expand({ parsed });
|
|
258
|
+
parsedEnv = parsed;
|
|
241
259
|
}
|
|
260
|
+
const info = getEnvTsDefinition(parsedEnv);
|
|
261
|
+
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
262
|
+
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
263
|
+
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
264
|
+
dotenvExpand__namespace.expand({ parsed: parsedEnv });
|
|
242
265
|
return parsedEnvTsDefinition;
|
|
243
266
|
}
|
|
244
267
|
|
|
@@ -286,10 +309,10 @@ function readEnvKey(key) {
|
|
|
286
309
|
}
|
|
287
310
|
|
|
288
311
|
class UserIdentity {
|
|
289
|
-
constructor(isAuthenticate, id,
|
|
312
|
+
constructor(isAuthenticate, id, claims) {
|
|
290
313
|
this.isAuthenticate = isAuthenticate;
|
|
291
314
|
this.id = id;
|
|
292
|
-
this.
|
|
315
|
+
this.claims = claims;
|
|
293
316
|
}
|
|
294
317
|
}
|
|
295
318
|
|
|
@@ -566,18 +589,105 @@ class List {
|
|
|
566
589
|
}
|
|
567
590
|
}
|
|
568
591
|
|
|
592
|
+
var FrameworkType = /* @__PURE__ */ ((FrameworkType2) => {
|
|
593
|
+
FrameworkType2[FrameworkType2["Express"] = 0] = "Express";
|
|
594
|
+
FrameworkType2[FrameworkType2["Fastify"] = 1] = "Fastify";
|
|
595
|
+
FrameworkType2[FrameworkType2["AzureFunction"] = 2] = "AzureFunction";
|
|
596
|
+
FrameworkType2[FrameworkType2["Firebase"] = 3] = "Firebase";
|
|
597
|
+
FrameworkType2[FrameworkType2["Lambda"] = 4] = "Lambda";
|
|
598
|
+
return FrameworkType2;
|
|
599
|
+
})(FrameworkType || {});
|
|
600
|
+
|
|
601
|
+
function registerType(type) {
|
|
602
|
+
commonContainer.registerType(type);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
class AbstractRunner {
|
|
606
|
+
async exec(command, args, cwd = process.cwd()) {
|
|
607
|
+
const options = {
|
|
608
|
+
cwd,
|
|
609
|
+
stdio: "pipe",
|
|
610
|
+
shell: true
|
|
611
|
+
};
|
|
612
|
+
return new Promise((resolve, reject) => {
|
|
613
|
+
const child = child_process.spawn(
|
|
614
|
+
`${command}`,
|
|
615
|
+
[...args],
|
|
616
|
+
options
|
|
617
|
+
);
|
|
618
|
+
child.stdout.on(
|
|
619
|
+
"data",
|
|
620
|
+
(data) => {
|
|
621
|
+
const writeData = data.toString().replace(/\r\n|\n/, "");
|
|
622
|
+
if (writeData.indexOf("[NATTYJS]") > -1 || writeData.indexOf("[NATTYJS:LOGGER]") > -1) {
|
|
623
|
+
console.log(writeData);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
);
|
|
627
|
+
child.on("close", (code) => {
|
|
628
|
+
if (code === 0) {
|
|
629
|
+
resolve(null);
|
|
630
|
+
} else {
|
|
631
|
+
console.error(
|
|
632
|
+
`${command} ${args}`
|
|
633
|
+
);
|
|
634
|
+
reject();
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
async function getPort() {
|
|
642
|
+
const portNumber = commonContainer.nattyConfig?.port || 3200;
|
|
643
|
+
if (portNumber)
|
|
644
|
+
return portNumber;
|
|
645
|
+
const port = await getPortPlease.getPort({ ports: [portNumber, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)] });
|
|
646
|
+
commonContainer.nattyConfig.port = port;
|
|
647
|
+
return port;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const reset = "\x1B[0m";
|
|
651
|
+
const NATTY_LOGGER = `[NATTYJS:LOGGER] `;
|
|
652
|
+
const log = {
|
|
653
|
+
green: (text) => console.log("\x1B[32m" + NATTY_LOGGER + text + reset),
|
|
654
|
+
red: (text) => console.log("\x1B[31m" + NATTY_LOGGER + text + reset),
|
|
655
|
+
blue: (text) => console.log("\x1B[34m" + NATTY_LOGGER + text + reset),
|
|
656
|
+
yellow: (text) => console.log("\x1B[33m" + NATTY_LOGGER + text + reset)
|
|
657
|
+
};
|
|
658
|
+
class AbstractConsoleLogger {
|
|
659
|
+
log(message) {
|
|
660
|
+
log.yellow(message);
|
|
661
|
+
}
|
|
662
|
+
info(message) {
|
|
663
|
+
log.blue(message);
|
|
664
|
+
}
|
|
665
|
+
warn(message) {
|
|
666
|
+
log.yellow(message);
|
|
667
|
+
}
|
|
668
|
+
error(message) {
|
|
669
|
+
log.red(message);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
class ConsoleLogger extends AbstractConsoleLogger {
|
|
674
|
+
}
|
|
675
|
+
|
|
569
676
|
exports.ALLOW_METHODS = ALLOW_METHODS;
|
|
677
|
+
exports.AbstractRunner = AbstractRunner;
|
|
570
678
|
exports.ActionFilter = ActionFilter;
|
|
571
679
|
exports.AuthenticationFilter = AuthenticationFilter;
|
|
572
680
|
exports.AuthorizationFilter = AuthorizationFilter;
|
|
573
681
|
exports.BACK_SLASH_REGEX = BACK_SLASH_REGEX;
|
|
574
682
|
exports.BLANK = BLANK;
|
|
575
683
|
exports.CONTROLLER = CONTROLLER;
|
|
684
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
576
685
|
exports.DEFAULT_ACTIONS = DEFAULT_ACTIONS;
|
|
577
686
|
exports.DEFAULT_CHILD_PATH = DEFAULT_CHILD_PATH;
|
|
578
687
|
exports.DELETE = DELETE;
|
|
579
688
|
exports.ENVIRONMENTS = ENVIRONMENTS;
|
|
580
689
|
exports.ExceptionFilter = ExceptionFilter;
|
|
690
|
+
exports.FrameworkType = FrameworkType;
|
|
581
691
|
exports.GET = GET;
|
|
582
692
|
exports.HTTP_METHOD_ROUTES = HTTP_METHOD_ROUTES;
|
|
583
693
|
exports.IGNORE_METHODS = IGNORE_METHODS;
|
|
@@ -596,10 +706,12 @@ exports.commonContainer = commonContainer;
|
|
|
596
706
|
exports.createPath = createPath;
|
|
597
707
|
exports.createTestServer = createTestServer;
|
|
598
708
|
exports.getPath = getPath;
|
|
709
|
+
exports.getPort = getPort;
|
|
599
710
|
exports.isConstructor = isConstructor;
|
|
600
711
|
exports.isEqual = isEqual;
|
|
601
712
|
exports.isFunction = isFunction;
|
|
602
713
|
exports.isObject = isObject;
|
|
603
714
|
exports.readEnv = readEnv;
|
|
604
715
|
exports.readEnvKey = readEnvKey;
|
|
716
|
+
exports.registerType = registerType;
|
|
605
717
|
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, 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
|
-
|
|
11
|
-
constructor(isAuthenticate: boolean, id?: any,
|
|
10
|
+
claims?: T;
|
|
11
|
+
constructor(isAuthenticate: boolean, id?: any, claims?: T);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface IExecutionContext {
|
|
@@ -37,8 +37,12 @@ declare abstract class AuthenticationFilter {
|
|
|
37
37
|
onFailedResponse(): ProblemDetail;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
interface IAuthorizationContext extends IActionExecutingContext {
|
|
41
|
+
config: any;
|
|
42
|
+
}
|
|
43
|
+
|
|
40
44
|
declare abstract class AuthorizationFilter {
|
|
41
|
-
abstract onAuthorization(httpContext:
|
|
45
|
+
abstract onAuthorization(httpContext: IAuthorizationContext): Promise<boolean>;
|
|
42
46
|
onFailedAuthorization(): ProblemDetail;
|
|
43
47
|
}
|
|
44
48
|
|
|
@@ -53,6 +57,22 @@ interface GlobalConfig {
|
|
|
53
57
|
onException?: ClassType<ExceptionFilter>;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
interface CorsConfig {
|
|
61
|
+
origin: string[];
|
|
62
|
+
methods: string;
|
|
63
|
+
preflightContinue: boolean;
|
|
64
|
+
optionsSuccessStatus: number;
|
|
65
|
+
credentials: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface PayloadConfig {
|
|
69
|
+
limit?: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface SecureConfig {
|
|
73
|
+
sensitiveProps?: String[];
|
|
74
|
+
}
|
|
75
|
+
|
|
56
76
|
interface NattyConfig {
|
|
57
77
|
app: any;
|
|
58
78
|
testModule?: NattyTestModule;
|
|
@@ -62,12 +82,45 @@ interface NattyConfig {
|
|
|
62
82
|
modelBinding?: ModelBinding;
|
|
63
83
|
global?: GlobalConfig;
|
|
64
84
|
autoGeneratePort?: boolean;
|
|
85
|
+
port?: number;
|
|
86
|
+
cors?: CorsConfig;
|
|
87
|
+
payload?: PayloadConfig;
|
|
88
|
+
secure?: SecureConfig;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare abstract class AbstractRunner {
|
|
92
|
+
abstract run(): void;
|
|
93
|
+
protected exec(command: string, args: any[], cwd?: string): Promise<null | string>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface EnvConfig {
|
|
97
|
+
path: string;
|
|
98
|
+
dictionary: {
|
|
99
|
+
[key: string]: any;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface PackageJsonConfig {
|
|
104
|
+
addExports: string[];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface LibraryConfig {
|
|
108
|
+
packageJson: PackageJsonConfig;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface NattyCliConfig {
|
|
112
|
+
library?: Partial<LibraryConfig>;
|
|
113
|
+
env?: Partial<EnvConfig>;
|
|
114
|
+
runner?: ClassType<AbstractRunner>;
|
|
115
|
+
port?: number;
|
|
65
116
|
}
|
|
66
117
|
|
|
67
118
|
declare const commonContainer: {
|
|
68
119
|
setupConfig(config?: NattyConfig): void;
|
|
120
|
+
setupCliConfig(config: NattyCliConfig): void;
|
|
69
121
|
setupBuildOptions(options: BuildOptions): any;
|
|
70
122
|
get nattyConfig(): NattyConfig;
|
|
123
|
+
get nattyCliConfig(): NattyCliConfig;
|
|
71
124
|
get buildOptions(): BuildOptions;
|
|
72
125
|
get envTsDefinition(): {
|
|
73
126
|
[key: string]: string;
|
|
@@ -84,6 +137,8 @@ declare const commonContainer: {
|
|
|
84
137
|
setMetadata(key: string, value: any, propName: string): void;
|
|
85
138
|
getMetadataValue(key: string, propName: string): any;
|
|
86
139
|
get globalConfig(): GlobalConfig;
|
|
140
|
+
registerType(type: TypesInfo): void;
|
|
141
|
+
types: TypesInfo;
|
|
87
142
|
};
|
|
88
143
|
|
|
89
144
|
declare const typeContainer: {
|
|
@@ -207,4 +262,30 @@ declare class List<T> {
|
|
|
207
262
|
declare function isObject(value: any): boolean;
|
|
208
263
|
declare function isEqual(first: any, second: any): boolean;
|
|
209
264
|
|
|
210
|
-
|
|
265
|
+
declare enum FrameworkType {
|
|
266
|
+
Express = 0,
|
|
267
|
+
Fastify = 1,
|
|
268
|
+
AzureFunction = 2,
|
|
269
|
+
Firebase = 3,
|
|
270
|
+
Lambda = 4
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
interface NattyAppConfig extends NattyConfig {
|
|
274
|
+
framework: FrameworkType;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
declare function registerType(type: TypesInfo): void;
|
|
278
|
+
|
|
279
|
+
declare function getPort(): Promise<number>;
|
|
280
|
+
|
|
281
|
+
declare abstract class AbstractConsoleLogger {
|
|
282
|
+
log(message: any): void;
|
|
283
|
+
info(message: any): void;
|
|
284
|
+
warn(message: any): void;
|
|
285
|
+
error(message: any): void;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
declare class ConsoleLogger extends AbstractConsoleLogger {
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
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, commonContainer, createPath, createTestServer, getPath, getPort, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer };
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,24 @@ import { existsSync } from 'fs';
|
|
|
3
3
|
import * as dotenv from 'dotenv';
|
|
4
4
|
import * as dotenvExpand from 'dotenv-expand';
|
|
5
5
|
import * as path from 'path';
|
|
6
|
+
import { resolve } from 'path';
|
|
7
|
+
import { spawn } from 'child_process';
|
|
8
|
+
import { getPort as getPort$1 } from 'get-port-please';
|
|
6
9
|
|
|
7
10
|
const commonContainer = new class {
|
|
8
11
|
constructor() {
|
|
9
12
|
this.metadataConfig = { services: /* @__PURE__ */ new Map() };
|
|
13
|
+
this.types = {};
|
|
14
|
+
}
|
|
15
|
+
registerType(type) {
|
|
16
|
+
if (type) {
|
|
17
|
+
if (typeof type === "string")
|
|
18
|
+
type = JSON.parse(type);
|
|
19
|
+
this.types[type.name] = type;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
setupCliConfig(config) {
|
|
23
|
+
this.nattyCliConfig = config;
|
|
10
24
|
}
|
|
11
25
|
setupConfig(config) {
|
|
12
26
|
const modelBinding = {
|
|
@@ -17,7 +31,8 @@ const commonContainer = new class {
|
|
|
17
31
|
}
|
|
18
32
|
}
|
|
19
33
|
};
|
|
20
|
-
|
|
34
|
+
const secureConfig = { sensitiveProps: ["password", "mobileNo", "email"] };
|
|
35
|
+
this.nattyConfig = { ...{ api: { rootPath: "api" }, autoGeneratePort: true, modelBinding, globalConfig: {}, secure: secureConfig }, ...config };
|
|
21
36
|
}
|
|
22
37
|
setupBuildOptions(options) {
|
|
23
38
|
this.buildOptions = options;
|
|
@@ -207,20 +222,29 @@ function getPath(pathCollection, isIncludeRoot = true, isCreateFolder = false) {
|
|
|
207
222
|
return currentPath;
|
|
208
223
|
}
|
|
209
224
|
|
|
225
|
+
function resolvePath(path) {
|
|
226
|
+
return resolve(commonContainer.buildOptions.rootDir, path);
|
|
227
|
+
}
|
|
228
|
+
|
|
210
229
|
async function readEnv() {
|
|
211
|
-
|
|
230
|
+
const envConfig = commonContainer.nattyCliConfig.env;
|
|
231
|
+
let filePath = envConfig?.dictionary ? void 0 : getPath([ENVIRONMENTS, commonContainer.buildOptions.mode && commonContainer.buildOptions.mode !== "dev" ? `.env.${commonContainer.buildOptions.mode}` : `.env`]);
|
|
232
|
+
if (envConfig && envConfig.path)
|
|
233
|
+
filePath = resolvePath(envConfig.path);
|
|
212
234
|
let parsedEnvTsDefinition = {};
|
|
213
|
-
|
|
235
|
+
let parsedEnv = commonContainer.nattyCliConfig.env?.dictionary;
|
|
236
|
+
if (!parsedEnv && filePath && existsSync(filePath)) {
|
|
214
237
|
const { parsed, error } = dotenv.config({
|
|
215
238
|
debug: !!process.env.DEBUG || void 0,
|
|
216
239
|
path: filePath
|
|
217
240
|
});
|
|
218
|
-
|
|
219
|
-
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
220
|
-
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
221
|
-
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
222
|
-
dotenvExpand.expand({ parsed });
|
|
241
|
+
parsedEnv = parsed;
|
|
223
242
|
}
|
|
243
|
+
const info = getEnvTsDefinition(parsedEnv);
|
|
244
|
+
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
245
|
+
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
246
|
+
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
247
|
+
dotenvExpand.expand({ parsed: parsedEnv });
|
|
224
248
|
return parsedEnvTsDefinition;
|
|
225
249
|
}
|
|
226
250
|
|
|
@@ -268,10 +292,10 @@ function readEnvKey(key) {
|
|
|
268
292
|
}
|
|
269
293
|
|
|
270
294
|
class UserIdentity {
|
|
271
|
-
constructor(isAuthenticate, id,
|
|
295
|
+
constructor(isAuthenticate, id, claims) {
|
|
272
296
|
this.isAuthenticate = isAuthenticate;
|
|
273
297
|
this.id = id;
|
|
274
|
-
this.
|
|
298
|
+
this.claims = claims;
|
|
275
299
|
}
|
|
276
300
|
}
|
|
277
301
|
|
|
@@ -548,4 +572,88 @@ class List {
|
|
|
548
572
|
}
|
|
549
573
|
}
|
|
550
574
|
|
|
551
|
-
|
|
575
|
+
var FrameworkType = /* @__PURE__ */ ((FrameworkType2) => {
|
|
576
|
+
FrameworkType2[FrameworkType2["Express"] = 0] = "Express";
|
|
577
|
+
FrameworkType2[FrameworkType2["Fastify"] = 1] = "Fastify";
|
|
578
|
+
FrameworkType2[FrameworkType2["AzureFunction"] = 2] = "AzureFunction";
|
|
579
|
+
FrameworkType2[FrameworkType2["Firebase"] = 3] = "Firebase";
|
|
580
|
+
FrameworkType2[FrameworkType2["Lambda"] = 4] = "Lambda";
|
|
581
|
+
return FrameworkType2;
|
|
582
|
+
})(FrameworkType || {});
|
|
583
|
+
|
|
584
|
+
function registerType(type) {
|
|
585
|
+
commonContainer.registerType(type);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
class AbstractRunner {
|
|
589
|
+
async exec(command, args, cwd = process.cwd()) {
|
|
590
|
+
const options = {
|
|
591
|
+
cwd,
|
|
592
|
+
stdio: "pipe",
|
|
593
|
+
shell: true
|
|
594
|
+
};
|
|
595
|
+
return new Promise((resolve, reject) => {
|
|
596
|
+
const child = spawn(
|
|
597
|
+
`${command}`,
|
|
598
|
+
[...args],
|
|
599
|
+
options
|
|
600
|
+
);
|
|
601
|
+
child.stdout.on(
|
|
602
|
+
"data",
|
|
603
|
+
(data) => {
|
|
604
|
+
const writeData = data.toString().replace(/\r\n|\n/, "");
|
|
605
|
+
if (writeData.indexOf("[NATTYJS]") > -1 || writeData.indexOf("[NATTYJS:LOGGER]") > -1) {
|
|
606
|
+
console.log(writeData);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
child.on("close", (code) => {
|
|
611
|
+
if (code === 0) {
|
|
612
|
+
resolve(null);
|
|
613
|
+
} else {
|
|
614
|
+
console.error(
|
|
615
|
+
`${command} ${args}`
|
|
616
|
+
);
|
|
617
|
+
reject();
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
async function getPort() {
|
|
625
|
+
const portNumber = commonContainer.nattyConfig?.port || 3200;
|
|
626
|
+
if (portNumber)
|
|
627
|
+
return portNumber;
|
|
628
|
+
const port = await getPort$1({ ports: [portNumber, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)] });
|
|
629
|
+
commonContainer.nattyConfig.port = port;
|
|
630
|
+
return port;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const reset = "\x1B[0m";
|
|
634
|
+
const NATTY_LOGGER = `[NATTYJS:LOGGER] `;
|
|
635
|
+
const log = {
|
|
636
|
+
green: (text) => console.log("\x1B[32m" + NATTY_LOGGER + text + reset),
|
|
637
|
+
red: (text) => console.log("\x1B[31m" + NATTY_LOGGER + text + reset),
|
|
638
|
+
blue: (text) => console.log("\x1B[34m" + NATTY_LOGGER + text + reset),
|
|
639
|
+
yellow: (text) => console.log("\x1B[33m" + NATTY_LOGGER + text + reset)
|
|
640
|
+
};
|
|
641
|
+
class AbstractConsoleLogger {
|
|
642
|
+
log(message) {
|
|
643
|
+
log.yellow(message);
|
|
644
|
+
}
|
|
645
|
+
info(message) {
|
|
646
|
+
log.blue(message);
|
|
647
|
+
}
|
|
648
|
+
warn(message) {
|
|
649
|
+
log.yellow(message);
|
|
650
|
+
}
|
|
651
|
+
error(message) {
|
|
652
|
+
log.red(message);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
class ConsoleLogger extends AbstractConsoleLogger {
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
export { ALLOW_METHODS, AbstractRunner, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, ConsoleLogger, 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, getPort, 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.
|
|
3
|
+
"version": "0.0.1-beta.30",
|
|
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,14 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "unbuild"
|
|
16
16
|
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"dotenv": "16.3.1",
|
|
19
|
+
"dotenv-expand": "10.0.0",
|
|
20
|
+
"get-port-please": "3.1.1"
|
|
21
|
+
},
|
|
17
22
|
"devDependencies": {
|
|
18
23
|
"@types/node": "20.3.1",
|
|
19
|
-
"@nattyjs/types": "0.0.1-beta.
|
|
20
|
-
"unbuild": "1.2.1"
|
|
21
|
-
"dotenv-expand": "10.0.0"
|
|
24
|
+
"@nattyjs/types": "0.0.1-beta.30",
|
|
25
|
+
"unbuild": "1.2.1"
|
|
22
26
|
}
|
|
23
27
|
}
|