@nattyjs/common 0.0.1-beta.1 → 0.0.1-beta.11
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 +100 -9
- package/dist/index.d.ts +68 -4
- package/dist/index.mjs +98 -10
- 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,7 @@ const commonContainer = new class {
|
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
};
|
|
38
|
-
this.nattyConfig = { ...{ api: { rootPath: "api" }, modelBinding, globalConfig: {} }, ...config };
|
|
51
|
+
this.nattyConfig = { ...{ api: { rootPath: "api" }, autoGeneratePort: true, modelBinding, globalConfig: {} }, ...config };
|
|
39
52
|
}
|
|
40
53
|
setupBuildOptions(options) {
|
|
41
54
|
this.buildOptions = options;
|
|
@@ -43,6 +56,9 @@ const commonContainer = new class {
|
|
|
43
56
|
setEnvTsDefinition(tsDefinition) {
|
|
44
57
|
this.envTsDefinition = tsDefinition;
|
|
45
58
|
}
|
|
59
|
+
setEnvValueInfo(valueInfo) {
|
|
60
|
+
this.envValueInfo = valueInfo;
|
|
61
|
+
}
|
|
46
62
|
setMetadata(key, value, propName) {
|
|
47
63
|
this.metadataConfig[propName].set(key, value);
|
|
48
64
|
}
|
|
@@ -186,6 +202,7 @@ function tsDefinition(value) {
|
|
|
186
202
|
|
|
187
203
|
function getEnvTsDefinition(parsed) {
|
|
188
204
|
let serverTypedDefinition = {};
|
|
205
|
+
let envVariableValueInfo = {};
|
|
189
206
|
if (parsed) {
|
|
190
207
|
const keys = Object.keys(parsed);
|
|
191
208
|
if (keys.length > 0) {
|
|
@@ -193,10 +210,11 @@ function getEnvTsDefinition(parsed) {
|
|
|
193
210
|
let keyName = key;
|
|
194
211
|
const { definition, transformValue } = tsDefinition(parsed[key]);
|
|
195
212
|
serverTypedDefinition[keyName] = definition;
|
|
213
|
+
envVariableValueInfo[keyName] = parsed[keyName];
|
|
196
214
|
});
|
|
197
215
|
}
|
|
198
216
|
}
|
|
199
|
-
return serverTypedDefinition;
|
|
217
|
+
return { parsedEnvTsDefinition: serverTypedDefinition, envVariableValueInfo };
|
|
200
218
|
}
|
|
201
219
|
|
|
202
220
|
function createPath(pathToCreate) {
|
|
@@ -220,18 +238,29 @@ function getPath(pathCollection, isIncludeRoot = true, isCreateFolder = false) {
|
|
|
220
238
|
return currentPath;
|
|
221
239
|
}
|
|
222
240
|
|
|
241
|
+
function resolvePath(path$1) {
|
|
242
|
+
return path.resolve(commonContainer.buildOptions.rootDir, path$1);
|
|
243
|
+
}
|
|
244
|
+
|
|
223
245
|
async function readEnv() {
|
|
224
|
-
|
|
246
|
+
const envConfig = commonContainer.nattyCliConfig.env;
|
|
247
|
+
let filePath = envConfig?.dictionary ? void 0 : getPath([ENVIRONMENTS, commonContainer.buildOptions.mode && commonContainer.buildOptions.mode !== "dev" ? `.env.${commonContainer.buildOptions.mode}` : `.env`]);
|
|
248
|
+
if (envConfig && envConfig.path)
|
|
249
|
+
filePath = resolvePath(envConfig.path);
|
|
225
250
|
let parsedEnvTsDefinition = {};
|
|
226
|
-
|
|
251
|
+
let parsedEnv = commonContainer.nattyCliConfig.env?.dictionary;
|
|
252
|
+
if (!parsedEnv && filePath && fs.existsSync(filePath)) {
|
|
227
253
|
const { parsed, error } = dotenv__namespace.config({
|
|
228
254
|
debug: !!process.env.DEBUG || void 0,
|
|
229
255
|
path: filePath
|
|
230
256
|
});
|
|
231
|
-
|
|
232
|
-
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
233
|
-
dotenvExpand__namespace.expand({ parsed });
|
|
257
|
+
parsedEnv = parsed;
|
|
234
258
|
}
|
|
259
|
+
const info = getEnvTsDefinition(parsedEnv);
|
|
260
|
+
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
261
|
+
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
262
|
+
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
263
|
+
dotenvExpand__namespace.expand({ parsed: parsedEnv });
|
|
235
264
|
return parsedEnvTsDefinition;
|
|
236
265
|
}
|
|
237
266
|
|
|
@@ -279,10 +308,10 @@ function readEnvKey(key) {
|
|
|
279
308
|
}
|
|
280
309
|
|
|
281
310
|
class UserIdentity {
|
|
282
|
-
constructor(isAuthenticate, id,
|
|
311
|
+
constructor(isAuthenticate, id, claims) {
|
|
283
312
|
this.isAuthenticate = isAuthenticate;
|
|
284
313
|
this.id = id;
|
|
285
|
-
this.
|
|
314
|
+
this.claims = claims;
|
|
286
315
|
}
|
|
287
316
|
}
|
|
288
317
|
|
|
@@ -559,7 +588,66 @@ class List {
|
|
|
559
588
|
}
|
|
560
589
|
}
|
|
561
590
|
|
|
591
|
+
var FrameworkType = /* @__PURE__ */ ((FrameworkType2) => {
|
|
592
|
+
FrameworkType2[FrameworkType2["Express"] = 0] = "Express";
|
|
593
|
+
FrameworkType2[FrameworkType2["Fastify"] = 1] = "Fastify";
|
|
594
|
+
FrameworkType2[FrameworkType2["AzureFunction"] = 2] = "AzureFunction";
|
|
595
|
+
FrameworkType2[FrameworkType2["Firebase"] = 3] = "Firebase";
|
|
596
|
+
FrameworkType2[FrameworkType2["Lambda"] = 4] = "Lambda";
|
|
597
|
+
return FrameworkType2;
|
|
598
|
+
})(FrameworkType || {});
|
|
599
|
+
|
|
600
|
+
function registerType(type) {
|
|
601
|
+
commonContainer.registerType(type);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
class AbstractRunner {
|
|
605
|
+
async exec(command, args, cwd = process.cwd()) {
|
|
606
|
+
const options = {
|
|
607
|
+
cwd,
|
|
608
|
+
stdio: "pipe",
|
|
609
|
+
shell: true
|
|
610
|
+
};
|
|
611
|
+
return new Promise((resolve, reject) => {
|
|
612
|
+
const child = child_process.spawn(
|
|
613
|
+
`${command}`,
|
|
614
|
+
[...args],
|
|
615
|
+
options
|
|
616
|
+
);
|
|
617
|
+
child.stdout.on(
|
|
618
|
+
"data",
|
|
619
|
+
(data) => {
|
|
620
|
+
const writeData = data.toString().replace(/\r\n|\n/, "");
|
|
621
|
+
if (writeData.indexOf("[NATTYJS]") > -1) {
|
|
622
|
+
console.log(writeData);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
);
|
|
626
|
+
child.on("close", (code) => {
|
|
627
|
+
if (code === 0) {
|
|
628
|
+
resolve(null);
|
|
629
|
+
} else {
|
|
630
|
+
console.error(
|
|
631
|
+
`${command} ${args}`
|
|
632
|
+
);
|
|
633
|
+
reject();
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
async function getPort() {
|
|
641
|
+
const portNumber = commonContainer.nattyConfig?.port || 3200;
|
|
642
|
+
if (portNumber)
|
|
643
|
+
return portNumber;
|
|
644
|
+
const port = await getPortPlease.getPort({ ports: [portNumber, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)] });
|
|
645
|
+
commonContainer.nattyConfig.port = port;
|
|
646
|
+
return port;
|
|
647
|
+
}
|
|
648
|
+
|
|
562
649
|
exports.ALLOW_METHODS = ALLOW_METHODS;
|
|
650
|
+
exports.AbstractRunner = AbstractRunner;
|
|
563
651
|
exports.ActionFilter = ActionFilter;
|
|
564
652
|
exports.AuthenticationFilter = AuthenticationFilter;
|
|
565
653
|
exports.AuthorizationFilter = AuthorizationFilter;
|
|
@@ -571,6 +659,7 @@ exports.DEFAULT_CHILD_PATH = DEFAULT_CHILD_PATH;
|
|
|
571
659
|
exports.DELETE = DELETE;
|
|
572
660
|
exports.ENVIRONMENTS = ENVIRONMENTS;
|
|
573
661
|
exports.ExceptionFilter = ExceptionFilter;
|
|
662
|
+
exports.FrameworkType = FrameworkType;
|
|
574
663
|
exports.GET = GET;
|
|
575
664
|
exports.HTTP_METHOD_ROUTES = HTTP_METHOD_ROUTES;
|
|
576
665
|
exports.IGNORE_METHODS = IGNORE_METHODS;
|
|
@@ -589,10 +678,12 @@ exports.commonContainer = commonContainer;
|
|
|
589
678
|
exports.createPath = createPath;
|
|
590
679
|
exports.createTestServer = createTestServer;
|
|
591
680
|
exports.getPath = getPath;
|
|
681
|
+
exports.getPort = getPort;
|
|
592
682
|
exports.isConstructor = isConstructor;
|
|
593
683
|
exports.isEqual = isEqual;
|
|
594
684
|
exports.isFunction = isFunction;
|
|
595
685
|
exports.isObject = isObject;
|
|
596
686
|
exports.readEnv = readEnv;
|
|
597
687
|
exports.readEnvKey = readEnvKey;
|
|
688
|
+
exports.registerType = registerType;
|
|
598
689
|
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 {
|
|
@@ -53,6 +53,14 @@ interface GlobalConfig {
|
|
|
53
53
|
onException?: ClassType<ExceptionFilter>;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
interface CorsConfig {
|
|
57
|
+
origin: string[];
|
|
58
|
+
methods: string;
|
|
59
|
+
preflightContinue: boolean;
|
|
60
|
+
optionsSuccessStatus: number;
|
|
61
|
+
credentials: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
interface NattyConfig {
|
|
57
65
|
app: any;
|
|
58
66
|
testModule?: NattyTestModule;
|
|
@@ -61,22 +69,62 @@ interface NattyConfig {
|
|
|
61
69
|
};
|
|
62
70
|
modelBinding?: ModelBinding;
|
|
63
71
|
global?: GlobalConfig;
|
|
72
|
+
autoGeneratePort?: boolean;
|
|
73
|
+
port?: number;
|
|
74
|
+
cors?: CorsConfig;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare abstract class AbstractRunner {
|
|
78
|
+
abstract run(): void;
|
|
79
|
+
protected exec(command: string, args: any[], cwd?: string): Promise<null | string>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface EnvConfig {
|
|
83
|
+
path: string;
|
|
84
|
+
dictionary: {
|
|
85
|
+
[key: string]: any;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface PackageJsonConfig {
|
|
90
|
+
addExports: string[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface LibraryConfig {
|
|
94
|
+
packageJson: PackageJsonConfig;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface NattyCliConfig {
|
|
98
|
+
library?: Partial<LibraryConfig>;
|
|
99
|
+
env?: Partial<EnvConfig>;
|
|
100
|
+
runner?: ClassType<AbstractRunner>;
|
|
101
|
+
port?: number;
|
|
64
102
|
}
|
|
65
103
|
|
|
66
104
|
declare const commonContainer: {
|
|
67
105
|
setupConfig(config?: NattyConfig): void;
|
|
106
|
+
setupCliConfig(config: NattyCliConfig): void;
|
|
68
107
|
setupBuildOptions(options: BuildOptions): any;
|
|
69
108
|
get nattyConfig(): NattyConfig;
|
|
109
|
+
get nattyCliConfig(): NattyCliConfig;
|
|
70
110
|
get buildOptions(): BuildOptions;
|
|
71
111
|
get envTsDefinition(): {
|
|
72
112
|
[key: string]: string;
|
|
73
113
|
};
|
|
114
|
+
get envValueInfo(): {
|
|
115
|
+
[key: string]: string;
|
|
116
|
+
};
|
|
74
117
|
setEnvTsDefinition(tsDefinition: {
|
|
75
118
|
[key: string]: string;
|
|
76
119
|
}): void;
|
|
120
|
+
setEnvValueInfo(envValueInfo: {
|
|
121
|
+
[key: string]: string;
|
|
122
|
+
}): void;
|
|
77
123
|
setMetadata(key: string, value: any, propName: string): void;
|
|
78
124
|
getMetadataValue(key: string, propName: string): any;
|
|
79
125
|
get globalConfig(): GlobalConfig;
|
|
126
|
+
registerType(type: TypesInfo): void;
|
|
127
|
+
types: TypesInfo;
|
|
80
128
|
};
|
|
81
129
|
|
|
82
130
|
declare const typeContainer: {
|
|
@@ -200,4 +248,20 @@ declare class List<T> {
|
|
|
200
248
|
declare function isObject(value: any): boolean;
|
|
201
249
|
declare function isEqual(first: any, second: any): boolean;
|
|
202
250
|
|
|
203
|
-
|
|
251
|
+
declare enum FrameworkType {
|
|
252
|
+
Express = 0,
|
|
253
|
+
Fastify = 1,
|
|
254
|
+
AzureFunction = 2,
|
|
255
|
+
Firebase = 3,
|
|
256
|
+
Lambda = 4
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
interface NattyAppConfig extends NattyConfig {
|
|
260
|
+
framework: FrameworkType;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
declare function registerType(type: TypesInfo): void;
|
|
264
|
+
|
|
265
|
+
declare function getPort(): Promise<number>;
|
|
266
|
+
|
|
267
|
+
export { ALLOW_METHODS, AbstractRunner, 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, 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,7 @@ const commonContainer = new class {
|
|
|
17
31
|
}
|
|
18
32
|
}
|
|
19
33
|
};
|
|
20
|
-
this.nattyConfig = { ...{ api: { rootPath: "api" }, modelBinding, globalConfig: {} }, ...config };
|
|
34
|
+
this.nattyConfig = { ...{ api: { rootPath: "api" }, autoGeneratePort: true, modelBinding, globalConfig: {} }, ...config };
|
|
21
35
|
}
|
|
22
36
|
setupBuildOptions(options) {
|
|
23
37
|
this.buildOptions = options;
|
|
@@ -25,6 +39,9 @@ const commonContainer = new class {
|
|
|
25
39
|
setEnvTsDefinition(tsDefinition) {
|
|
26
40
|
this.envTsDefinition = tsDefinition;
|
|
27
41
|
}
|
|
42
|
+
setEnvValueInfo(valueInfo) {
|
|
43
|
+
this.envValueInfo = valueInfo;
|
|
44
|
+
}
|
|
28
45
|
setMetadata(key, value, propName) {
|
|
29
46
|
this.metadataConfig[propName].set(key, value);
|
|
30
47
|
}
|
|
@@ -168,6 +185,7 @@ function tsDefinition(value) {
|
|
|
168
185
|
|
|
169
186
|
function getEnvTsDefinition(parsed) {
|
|
170
187
|
let serverTypedDefinition = {};
|
|
188
|
+
let envVariableValueInfo = {};
|
|
171
189
|
if (parsed) {
|
|
172
190
|
const keys = Object.keys(parsed);
|
|
173
191
|
if (keys.length > 0) {
|
|
@@ -175,10 +193,11 @@ function getEnvTsDefinition(parsed) {
|
|
|
175
193
|
let keyName = key;
|
|
176
194
|
const { definition, transformValue } = tsDefinition(parsed[key]);
|
|
177
195
|
serverTypedDefinition[keyName] = definition;
|
|
196
|
+
envVariableValueInfo[keyName] = parsed[keyName];
|
|
178
197
|
});
|
|
179
198
|
}
|
|
180
199
|
}
|
|
181
|
-
return serverTypedDefinition;
|
|
200
|
+
return { parsedEnvTsDefinition: serverTypedDefinition, envVariableValueInfo };
|
|
182
201
|
}
|
|
183
202
|
|
|
184
203
|
function createPath(pathToCreate) {
|
|
@@ -202,18 +221,29 @@ function getPath(pathCollection, isIncludeRoot = true, isCreateFolder = false) {
|
|
|
202
221
|
return currentPath;
|
|
203
222
|
}
|
|
204
223
|
|
|
224
|
+
function resolvePath(path) {
|
|
225
|
+
return resolve(commonContainer.buildOptions.rootDir, path);
|
|
226
|
+
}
|
|
227
|
+
|
|
205
228
|
async function readEnv() {
|
|
206
|
-
|
|
229
|
+
const envConfig = commonContainer.nattyCliConfig.env;
|
|
230
|
+
let filePath = envConfig?.dictionary ? void 0 : getPath([ENVIRONMENTS, commonContainer.buildOptions.mode && commonContainer.buildOptions.mode !== "dev" ? `.env.${commonContainer.buildOptions.mode}` : `.env`]);
|
|
231
|
+
if (envConfig && envConfig.path)
|
|
232
|
+
filePath = resolvePath(envConfig.path);
|
|
207
233
|
let parsedEnvTsDefinition = {};
|
|
208
|
-
|
|
234
|
+
let parsedEnv = commonContainer.nattyCliConfig.env?.dictionary;
|
|
235
|
+
if (!parsedEnv && filePath && existsSync(filePath)) {
|
|
209
236
|
const { parsed, error } = dotenv.config({
|
|
210
237
|
debug: !!process.env.DEBUG || void 0,
|
|
211
238
|
path: filePath
|
|
212
239
|
});
|
|
213
|
-
|
|
214
|
-
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
215
|
-
dotenvExpand.expand({ parsed });
|
|
240
|
+
parsedEnv = parsed;
|
|
216
241
|
}
|
|
242
|
+
const info = getEnvTsDefinition(parsedEnv);
|
|
243
|
+
parsedEnvTsDefinition = info.parsedEnvTsDefinition;
|
|
244
|
+
commonContainer.setEnvTsDefinition(parsedEnvTsDefinition);
|
|
245
|
+
commonContainer.setEnvValueInfo(info.envVariableValueInfo);
|
|
246
|
+
dotenvExpand.expand({ parsed: parsedEnv });
|
|
217
247
|
return parsedEnvTsDefinition;
|
|
218
248
|
}
|
|
219
249
|
|
|
@@ -261,10 +291,10 @@ function readEnvKey(key) {
|
|
|
261
291
|
}
|
|
262
292
|
|
|
263
293
|
class UserIdentity {
|
|
264
|
-
constructor(isAuthenticate, id,
|
|
294
|
+
constructor(isAuthenticate, id, claims) {
|
|
265
295
|
this.isAuthenticate = isAuthenticate;
|
|
266
296
|
this.id = id;
|
|
267
|
-
this.
|
|
297
|
+
this.claims = claims;
|
|
268
298
|
}
|
|
269
299
|
}
|
|
270
300
|
|
|
@@ -541,4 +571,62 @@ class List {
|
|
|
541
571
|
}
|
|
542
572
|
}
|
|
543
573
|
|
|
544
|
-
|
|
574
|
+
var FrameworkType = /* @__PURE__ */ ((FrameworkType2) => {
|
|
575
|
+
FrameworkType2[FrameworkType2["Express"] = 0] = "Express";
|
|
576
|
+
FrameworkType2[FrameworkType2["Fastify"] = 1] = "Fastify";
|
|
577
|
+
FrameworkType2[FrameworkType2["AzureFunction"] = 2] = "AzureFunction";
|
|
578
|
+
FrameworkType2[FrameworkType2["Firebase"] = 3] = "Firebase";
|
|
579
|
+
FrameworkType2[FrameworkType2["Lambda"] = 4] = "Lambda";
|
|
580
|
+
return FrameworkType2;
|
|
581
|
+
})(FrameworkType || {});
|
|
582
|
+
|
|
583
|
+
function registerType(type) {
|
|
584
|
+
commonContainer.registerType(type);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
class AbstractRunner {
|
|
588
|
+
async exec(command, args, cwd = process.cwd()) {
|
|
589
|
+
const options = {
|
|
590
|
+
cwd,
|
|
591
|
+
stdio: "pipe",
|
|
592
|
+
shell: true
|
|
593
|
+
};
|
|
594
|
+
return new Promise((resolve, reject) => {
|
|
595
|
+
const child = spawn(
|
|
596
|
+
`${command}`,
|
|
597
|
+
[...args],
|
|
598
|
+
options
|
|
599
|
+
);
|
|
600
|
+
child.stdout.on(
|
|
601
|
+
"data",
|
|
602
|
+
(data) => {
|
|
603
|
+
const writeData = data.toString().replace(/\r\n|\n/, "");
|
|
604
|
+
if (writeData.indexOf("[NATTYJS]") > -1) {
|
|
605
|
+
console.log(writeData);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
child.on("close", (code) => {
|
|
610
|
+
if (code === 0) {
|
|
611
|
+
resolve(null);
|
|
612
|
+
} else {
|
|
613
|
+
console.error(
|
|
614
|
+
`${command} ${args}`
|
|
615
|
+
);
|
|
616
|
+
reject();
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
async function getPort() {
|
|
624
|
+
const portNumber = commonContainer.nattyConfig?.port || 3200;
|
|
625
|
+
if (portNumber)
|
|
626
|
+
return portNumber;
|
|
627
|
+
const port = await getPort$1({ ports: [portNumber, ...Array(50).fill(3001).map((fillValue, index) => fillValue + index)] });
|
|
628
|
+
commonContainer.nattyConfig.port = port;
|
|
629
|
+
return port;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export { ALLOW_METHODS, AbstractRunner, 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, 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.11",
|
|
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.11",
|
|
25
|
+
"unbuild": "1.2.1"
|
|
22
26
|
}
|
|
23
27
|
}
|