@nest-omni/core 1.0.33 → 1.0.34
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/cli.js +23 -25
- package/decorators/field.decorators.d.ts +2 -1
- package/decorators/field.decorators.js +11 -5
- package/decorators/validator.decorators.d.ts +1 -0
- package/decorators/validator.decorators.js +21 -1
- package/package.json +4 -1
- package/shared/serviceRegistryModule.js +2 -1
- package/shared/services/api-config.service.js +7 -5
- package/tsconfig.tsbuildinfo +1 -1
package/cli.js
CHANGED
|
@@ -4,30 +4,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const program = require("commander");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
7
|
+
const hygen_1 = require("hygen");
|
|
8
|
+
const logger_1 = require("hygen/dist/logger");
|
|
9
|
+
const process = require("node:process");
|
|
10
|
+
const _hygen_1 = require(".hygen");
|
|
7
11
|
program.version('0.1.0').option('-v, --verbose', 'output extra information');
|
|
8
12
|
program
|
|
9
|
-
.command('
|
|
13
|
+
.command('create <project>')
|
|
10
14
|
.description('initialize a new project')
|
|
11
|
-
.action((
|
|
12
|
-
console.log(`Initializing project ${
|
|
15
|
+
.action((project) => {
|
|
16
|
+
console.log(`Initializing project ${project}`);
|
|
13
17
|
});
|
|
14
18
|
program
|
|
15
|
-
.command('i18n
|
|
16
|
-
.description('add i18n support to the project')
|
|
17
|
-
.action((
|
|
18
|
-
|
|
19
|
+
.command('i18n')
|
|
20
|
+
.description('add class-validator i18n support to the project')
|
|
21
|
+
.action(() => {
|
|
22
|
+
copyRecursiveSync(path.join(__dirname, 'i18n'), './i18n');
|
|
19
23
|
});
|
|
20
24
|
program
|
|
21
|
-
.command('crud
|
|
22
|
-
.description('generate CRUD operations for
|
|
23
|
-
.action((
|
|
24
|
-
console.log(`Generating CRUD operations for
|
|
25
|
+
.command('crud')
|
|
26
|
+
.description('generate CRUD operations for a module')
|
|
27
|
+
.action(() => {
|
|
28
|
+
console.log(`Generating CRUD operations for module`);
|
|
29
|
+
(0, hygen_1.runner)(['new', 'crud'], {
|
|
30
|
+
templates: _hygen_1.templates,
|
|
31
|
+
helpers: _hygen_1.helpers,
|
|
32
|
+
cwd: process.cwd(),
|
|
33
|
+
logger: new logger_1.default(console.log.bind(console)),
|
|
34
|
+
debug: !!process.env.DEBUG,
|
|
35
|
+
});
|
|
25
36
|
});
|
|
26
37
|
program.parse(process.argv);
|
|
27
38
|
function copyRecursiveSync(src, dest) {
|
|
28
39
|
const exists = fs.existsSync(src);
|
|
29
40
|
const stats = exists && fs.statSync(src);
|
|
30
41
|
const isDirectory = exists && stats.isDirectory();
|
|
42
|
+
console.log(`Copied ${src} to ${dest}`);
|
|
31
43
|
if (isDirectory) {
|
|
32
44
|
fs.mkdirSync(dest, { recursive: true });
|
|
33
45
|
fs.readdirSync(src).forEach((childItemName) => {
|
|
@@ -38,17 +50,3 @@ function copyRecursiveSync(src, dest) {
|
|
|
38
50
|
fs.copyFileSync(src, dest);
|
|
39
51
|
}
|
|
40
52
|
}
|
|
41
|
-
const directoriesToCopy = [
|
|
42
|
-
{ src: './node_modules/@nest-omni/core/i18n', dest: './i18n' },
|
|
43
|
-
{ src: './node_modules/@nest-omni/core/.hygen', dest: './.hygen' },
|
|
44
|
-
{ src: './node_modules/@nest-omni/core/.hygen.js', dest: './.hygen.js' },
|
|
45
|
-
];
|
|
46
|
-
directoriesToCopy.forEach(({ src, dest }) => {
|
|
47
|
-
try {
|
|
48
|
-
copyRecursiveSync(src, dest);
|
|
49
|
-
console.log(`Copied ${src} to ${dest}`);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
console.error(`Error copying ${src} to ${dest}:`, error);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
@@ -32,6 +32,7 @@ interface IIPFieldOptions {
|
|
|
32
32
|
}
|
|
33
33
|
interface IURLFieldOptions {
|
|
34
34
|
urlOptions?: ValidatorJS.IsURLOptions;
|
|
35
|
+
simpleUrl?: boolean;
|
|
35
36
|
}
|
|
36
37
|
interface IFQDNFieldOptions extends ValidatorJS.IsFQDNOptions {
|
|
37
38
|
}
|
|
@@ -62,7 +63,7 @@ export declare function PhoneFieldOptional(options?: Omit<ApiPropertyOptions, 't
|
|
|
62
63
|
export declare function UUIDField(options?: Omit<ApiPropertyOptions, 'type' | 'format' | 'isArray'> & IFieldOptions): PropertyDecorator;
|
|
63
64
|
export declare function UUIDFieldOptional(options?: Omit<ApiPropertyOptions, 'type' | 'required' | 'isArray'> & IFieldOptions): PropertyDecorator;
|
|
64
65
|
export declare function URLField(options?: Omit<ApiPropertyOptions, 'type'> & IURLFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
65
|
-
export declare function URLFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions): PropertyDecorator;
|
|
66
|
+
export declare function URLFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IURLFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
66
67
|
export declare function FQDNField(options?: Omit<ApiPropertyOptions, 'type'> & IFQDNFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
67
68
|
export declare function FQDNFieldOptional(options?: Omit<ApiPropertyOptions, 'type'> & IFQDNFieldOptions & IStringFieldOptions): PropertyDecorator;
|
|
68
69
|
export declare function DateField(options?: Omit<ApiPropertyOptions, 'type'> & IDateFieldOptions): PropertyDecorator;
|
|
@@ -326,13 +326,19 @@ function UUIDFieldOptional(options = {}) {
|
|
|
326
326
|
}
|
|
327
327
|
exports.UUIDFieldOptional = UUIDFieldOptional;
|
|
328
328
|
function URLField(options = {}) {
|
|
329
|
-
const decorators = [
|
|
330
|
-
|
|
329
|
+
const decorators = [StringField(Object.assign({}, options))];
|
|
330
|
+
if (options.simpleUrl) {
|
|
331
|
+
decorators.push((0, validator_decorators_1.IsHttpUrl)({
|
|
331
332
|
each: options.each,
|
|
332
333
|
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_URL'),
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
|
|
334
|
+
}));
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
decorators.push((0, class_validator_1.IsUrl)(options.urlOptions, {
|
|
338
|
+
each: options.each,
|
|
339
|
+
message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_URL'),
|
|
340
|
+
}));
|
|
341
|
+
}
|
|
336
342
|
if (options.nullable) {
|
|
337
343
|
decorators.push((0, validator_decorators_1.IsNullable)({ each: options.each }));
|
|
338
344
|
}
|
|
@@ -8,3 +8,4 @@ export declare function IsTmpKey(validationOptions?: ValidationOptions): Propert
|
|
|
8
8
|
export declare function IsUndefinable(options?: ValidationOptions): PropertyDecorator;
|
|
9
9
|
export declare function IsEmptyable(options?: ValidationOptions): PropertyDecorator;
|
|
10
10
|
export declare function IsNullable(options?: ValidationOptions): PropertyDecorator;
|
|
11
|
+
export declare function IsHttpUrl(validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IsNullable = exports.IsEmptyable = exports.IsUndefinable = exports.IsTmpKey = exports.IsPhoneNumber = exports.IsPassword = void 0;
|
|
3
|
+
exports.IsHttpUrl = exports.IsNullable = exports.IsEmptyable = exports.IsUndefinable = exports.IsTmpKey = exports.IsPhoneNumber = exports.IsPassword = void 0;
|
|
4
4
|
const class_validator_1 = require("class-validator");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
6
|
function IsPassword(validationOptions) {
|
|
@@ -57,3 +57,23 @@ function IsNullable(options) {
|
|
|
57
57
|
return (0, class_validator_1.ValidateIf)((obj, value) => value !== null, options);
|
|
58
58
|
}
|
|
59
59
|
exports.IsNullable = IsNullable;
|
|
60
|
+
function IsHttpUrl(validationOptions) {
|
|
61
|
+
return function (object, propertyName) {
|
|
62
|
+
(0, class_validator_1.registerDecorator)({
|
|
63
|
+
name: 'isHttpUrl',
|
|
64
|
+
target: object.constructor,
|
|
65
|
+
propertyName: propertyName,
|
|
66
|
+
options: validationOptions,
|
|
67
|
+
validator: {
|
|
68
|
+
validate(value) {
|
|
69
|
+
const httpUrlPattern = /^(https?:\/\/)/i;
|
|
70
|
+
return typeof value === 'string' && httpUrlPattern.test(value);
|
|
71
|
+
},
|
|
72
|
+
defaultMessage() {
|
|
73
|
+
return 'URL must start with http:// or https://';
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
exports.IsHttpUrl = IsHttpUrl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-omni/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -64,5 +64,8 @@
|
|
|
64
64
|
"typeorm": "^0.3.17",
|
|
65
65
|
"typeorm-transactional": "~0.4.1",
|
|
66
66
|
"uuid": "^9.0.1"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"hygen": "^6.2.11"
|
|
67
70
|
}
|
|
68
71
|
}
|
|
@@ -43,11 +43,12 @@ function findValidRootPath() {
|
|
|
43
43
|
const envFile = `${process.env.NODE_ENV || ''}.env`;
|
|
44
44
|
for (const rootPath of possibleRootPaths) {
|
|
45
45
|
const envFilePath = path.join(rootPath, 'config', envFile);
|
|
46
|
+
console.log('Checking for env file:', envFilePath);
|
|
46
47
|
if ((0, fs_1.existsSync)(envFilePath)) {
|
|
47
48
|
return { rootPath, envFilePath };
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
throw new Error(
|
|
51
|
+
throw new Error(`No valid .env file: ${envFilePath}`);
|
|
51
52
|
}
|
|
52
53
|
const { envFilePath, rootPath } = findValidRootPath();
|
|
53
54
|
services_1.ApiConfigService.rootPath = rootPath;
|
|
@@ -58,7 +58,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
58
58
|
return Number(value);
|
|
59
59
|
}
|
|
60
60
|
catch (_a) {
|
|
61
|
-
throw new Error(key
|
|
61
|
+
throw new Error(`key:${key}, value:${value} - is not a number`);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
getBoolean(key) {
|
|
@@ -73,7 +73,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
73
73
|
if (!(0, lodash_1.isNil)(defaultValue)) {
|
|
74
74
|
return defaultValue;
|
|
75
75
|
}
|
|
76
|
-
throw new Error(value
|
|
76
|
+
throw new Error(`value:${value} - is not a boolean`);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
getString(key) {
|
|
@@ -261,12 +261,14 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
261
261
|
}
|
|
262
262
|
return 'error';
|
|
263
263
|
},
|
|
264
|
-
|
|
264
|
+
wrapSerializers: true,
|
|
265
|
+
customProps: (req, res) => {
|
|
265
266
|
return {
|
|
266
267
|
env: this.nodeEnv,
|
|
267
268
|
appName: this.getString('NAME'),
|
|
268
269
|
user: req === null || req === void 0 ? void 0 : req.user,
|
|
269
|
-
body: req === null || req === void 0 ? void 0 : req.body,
|
|
270
|
+
'req.body': req === null || req === void 0 ? void 0 : req.body,
|
|
271
|
+
'res.body': res === null || res === void 0 ? void 0 : res.body,
|
|
270
272
|
};
|
|
271
273
|
},
|
|
272
274
|
redact: {
|
|
@@ -288,7 +290,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
288
290
|
get(key) {
|
|
289
291
|
const value = this.configService.get(key);
|
|
290
292
|
if ((0, lodash_1.isNil)(value)) {
|
|
291
|
-
throw new Error(key
|
|
293
|
+
throw new Error(`key:'${key}' - environment does not set`);
|
|
292
294
|
}
|
|
293
295
|
return value;
|
|
294
296
|
}
|