@maioradv/nestjs-core 2.0.4 → 2.0.6

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
- ```
2
- # build
3
- $ yarn build
4
-
5
- # publish
6
- $ npm publish --access public
7
-
1
+ ```
2
+ # build
3
+ $ yarn build
4
+
5
+ # publish
6
+ $ npm publish --access public
7
+
8
8
  ```
@@ -1,2 +1,3 @@
1
1
  export * from './standard-clauses.decorator';
2
2
  export * from './model';
3
+ export * from './special-clauses.decorator';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./standard-clauses.decorator"), exports);
18
18
  __exportStar(require("./model"), exports);
19
+ __exportStar(require("./special-clauses.decorator"), exports);
@@ -0,0 +1,5 @@
1
+ export declare class MetafieldClauseDto {
2
+ key: string;
3
+ value: string;
4
+ }
5
+ export declare const IsMetafieldClause: () => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.IsMetafieldClause = exports.MetafieldClauseDto = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const swagger_1 = require("@nestjs/swagger");
15
+ const class_transformer_1 = require("class-transformer");
16
+ const class_validator_1 = require("class-validator");
17
+ class MetafieldClauseDto {
18
+ }
19
+ exports.MetafieldClauseDto = MetafieldClauseDto;
20
+ __decorate([
21
+ (0, class_validator_1.IsString)(),
22
+ (0, class_validator_1.IsNotEmpty)(),
23
+ __metadata("design:type", String)
24
+ ], MetafieldClauseDto.prototype, "key", void 0);
25
+ __decorate([
26
+ (0, class_validator_1.IsString)(),
27
+ (0, class_validator_1.IsNotEmpty)(),
28
+ __metadata("design:type", String)
29
+ ], MetafieldClauseDto.prototype, "value", void 0);
30
+ const IsMetafieldClause = () => {
31
+ return (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({
32
+ description: 'A key:value couple or a comma-separated list of couples. Format: key1:value1,key2:value2'
33
+ }), (0, class_transformer_1.Transform)(({ value }) => value.split(',').map(pair => {
34
+ const [key, value] = pair.split(':');
35
+ return { key: key.trim(), value: value.trim() };
36
+ })), (0, class_validator_1.IsOptional)(), (0, class_validator_1.IsArray)(), (0, class_validator_1.ValidateNested)({ each: true }), (0, class_transformer_1.Type)(() => MetafieldClauseDto));
37
+ };
38
+ exports.IsMetafieldClause = IsMetafieldClause;
@@ -14,7 +14,9 @@ export type ResourceGuardOptions = {
14
14
  shutdownFn?: () => Promise<void>;
15
15
  /** Optional NestJS LoggerService to use for logging. */
16
16
  logger?: LoggerService;
17
- /** Optional peak logging options: log when CPU/memory exceed thresholds for a sustained period. Default sustain: 3000ms */
17
+ /** If true, logs each check with CPU/memory usage. Default: false */
18
+ debug?: boolean;
19
+ /** Optional peak logging options: log when CPU/memory exceed thresholds for a sustained period. Default sustain: 5000ms */
18
20
  logPeaks?: {
19
21
  cpuThreshold?: number;
20
22
  memoryThresholdMb?: number;
@@ -14,7 +14,7 @@ class ResourceGuard {
14
14
  this.opts.sustainForMs ??= 10000;
15
15
  this.opts.hardKillAfterMs ??= 5000;
16
16
  if (this.opts.logPeaks) {
17
- this.opts.logPeaks.sustainMs ??= 3000;
17
+ this.opts.logPeaks.sustainMs ??= 5000;
18
18
  }
19
19
  }
20
20
  /** Start monitoring CPU and memory */
@@ -47,6 +47,15 @@ class ResourceGuard {
47
47
  if (this.opts.memoryLimitMb && currentMemMb > this.opts.memoryLimitMb)
48
48
  over = true;
49
49
  }
50
+ if (this.opts.debug) {
51
+ const cpuMsg = this.opts.cpuLimit ? `CPU: ${currentCpuPercent?.toFixed(1)}%;` : '';
52
+ const memMsg = this.opts.memoryLimitMb ? `MEM: ${currentMemMb?.toFixed(0)}MB;` : '';
53
+ const msg = `${cpuMsg}${memMsg}`;
54
+ if (this.opts.logger)
55
+ this.opts.logger.debug(`${msg}`);
56
+ else
57
+ console.debug(`${msg}`);
58
+ }
50
59
  this.lastTime = nowTime;
51
60
  if (over) {
52
61
  if (!this.overSince)
package/package.json CHANGED
@@ -1,78 +1,78 @@
1
- {
2
- "name": "@maioradv/nestjs-core",
3
- "version": "2.0.4",
4
- "description": "NestJS helpers by MaiorADV",
5
- "repository": "https://github.com/maioradv/nestjs-core.git",
6
- "author": "Maior ADV Srl",
7
- "license": "MIT",
8
- "private": false,
9
- "main": "dist/index.js",
10
- "types": "dist/index.d.ts",
11
- "files": [
12
- "/dist"
13
- ],
14
- "scripts": {
15
- "example": "ts-node example/test.ts",
16
- "build": "tsc",
17
- "publish:npm": "npm publish --access public"
18
- },
19
- "dependencies": {
20
- "@aws-sdk/client-s3": "^3.899.0",
21
- "@maioradv/accounts-lib": "^1.3.3",
22
- "@nestjs/cache-manager": "^3.0.1",
23
- "@nestjs/common": "^11.1.6",
24
- "@nestjs/config": "^4.0.2",
25
- "@nestjs/graphql": "^13.2.0",
26
- "@nestjs/platform-express": "^11.1.6",
27
- "@nestjs/swagger": "^11.2.0",
28
- "@nestjs/throttler": "^6.4.0",
29
- "@sentry/nestjs": "^10.17.0",
30
- "bcrypt": "^6.0.0",
31
- "class-transformer": "^0.5.1",
32
- "class-validator": "^0.14.2",
33
- "file-type": "^21.0.0",
34
- "handlebars": "^4.7.8",
35
- "image-size": "^2.0.2",
36
- "nest-winston": "^1.10.2",
37
- "nodemailer": "^7.0.6",
38
- "request-ip": "^3.3.0",
39
- "sharp": "^0.34.4",
40
- "winston": "^3.18.3",
41
- "winston-daily-rotate-file": "^5.0.0"
42
- },
43
- "devDependencies": {
44
- "@types/multer": "^2.0.0",
45
- "@types/node": "^24.6.1",
46
- "@types/nodemailer": "^7.0.2",
47
- "@types/request-ip": "^0.0.41",
48
- "ts-node": "^10.9.2",
49
- "typescript": "^5.9.3"
50
- },
51
- "peerDependencies": {
52
- "@aws-sdk/client-s3": "^3.899.0",
53
- "@maioradv/accounts-lib": "^1.3.3",
54
- "@nestjs/cache-manager": "^3.0.1",
55
- "@nestjs/common": "^11.1.6",
56
- "@nestjs/config": "^4.0.2",
57
- "@nestjs/graphql": "^13.2.0",
58
- "@nestjs/platform-express": "^11.1.6",
59
- "@nestjs/swagger": "^11.2.0",
60
- "@nestjs/throttler": "^6.4.0",
61
- "@sentry/nestjs": "^10.17.0",
62
- "bcrypt": "^6.0.0",
63
- "class-transformer": "^0.5.1",
64
- "class-validator": "^0.14.2",
65
- "file-type": "^21.0.0",
66
- "handlebars": "^4.7.8",
67
- "image-size": "^2.0.2",
68
- "nest-winston": "^1.10.2",
69
- "nodemailer": "^7.0.6",
70
- "sharp": "^0.34.4",
71
- "winston": "^3.18.3",
72
- "winston-daily-rotate-file": "^5.0.0"
73
- },
74
- "keywords": [
75
- "typescript",
76
- "nestjs"
77
- ]
78
- }
1
+ {
2
+ "name": "@maioradv/nestjs-core",
3
+ "version": "2.0.6",
4
+ "description": "NestJS helpers by MaiorADV",
5
+ "repository": "https://github.com/maioradv/nestjs-core.git",
6
+ "author": "Maior ADV Srl",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "files": [
12
+ "/dist"
13
+ ],
14
+ "scripts": {
15
+ "example": "ts-node example/test.ts",
16
+ "build": "tsc",
17
+ "publish:npm": "npm publish --access public"
18
+ },
19
+ "dependencies": {
20
+ "@aws-sdk/client-s3": "^3.899.0",
21
+ "@maioradv/accounts-lib": "^1.3.3",
22
+ "@nestjs/cache-manager": "^3.0.1",
23
+ "@nestjs/common": "^11.1.6",
24
+ "@nestjs/config": "^4.0.2",
25
+ "@nestjs/graphql": "^13.2.0",
26
+ "@nestjs/platform-express": "^11.1.6",
27
+ "@nestjs/swagger": "^11.2.0",
28
+ "@nestjs/throttler": "^6.4.0",
29
+ "@sentry/nestjs": "^10.17.0",
30
+ "bcrypt": "^6.0.0",
31
+ "class-transformer": "^0.5.1",
32
+ "class-validator": "^0.14.2",
33
+ "file-type": "^21.0.0",
34
+ "handlebars": "^4.7.8",
35
+ "image-size": "^2.0.2",
36
+ "nest-winston": "^1.10.2",
37
+ "nodemailer": "^7.0.6",
38
+ "request-ip": "^3.3.0",
39
+ "sharp": "^0.34.4",
40
+ "winston": "^3.18.3",
41
+ "winston-daily-rotate-file": "^5.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/multer": "^2.0.0",
45
+ "@types/node": "^24.6.1",
46
+ "@types/nodemailer": "^7.0.2",
47
+ "@types/request-ip": "^0.0.41",
48
+ "ts-node": "^10.9.2",
49
+ "typescript": "^5.9.3"
50
+ },
51
+ "peerDependencies": {
52
+ "@aws-sdk/client-s3": "^3.899.0",
53
+ "@maioradv/accounts-lib": "^1.3.3",
54
+ "@nestjs/cache-manager": "^3.0.1",
55
+ "@nestjs/common": "^11.1.6",
56
+ "@nestjs/config": "^4.0.2",
57
+ "@nestjs/graphql": "^13.2.0",
58
+ "@nestjs/platform-express": "^11.1.6",
59
+ "@nestjs/swagger": "^11.2.0",
60
+ "@nestjs/throttler": "^6.4.0",
61
+ "@sentry/nestjs": "^10.17.0",
62
+ "bcrypt": "^6.0.0",
63
+ "class-transformer": "^0.5.1",
64
+ "class-validator": "^0.14.2",
65
+ "file-type": "^21.0.0",
66
+ "handlebars": "^4.7.8",
67
+ "image-size": "^2.0.2",
68
+ "nest-winston": "^1.10.2",
69
+ "nodemailer": "^7.0.6",
70
+ "sharp": "^0.34.4",
71
+ "winston": "^3.18.3",
72
+ "winston-daily-rotate-file": "^5.0.0"
73
+ },
74
+ "keywords": [
75
+ "typescript",
76
+ "nestjs"
77
+ ]
78
+ }
File without changes
@@ -1,13 +0,0 @@
1
- /*import * as Sentry from "@sentry/nestjs"
2
- import { nodeProfilingIntegration } from "@sentry/profiling-node";
3
-
4
- Sentry.init({
5
- dsn: process.env.SENTRY_DSN,
6
- serverName: process.env.SENTRY_SERVER_NAME,
7
- sendDefaultPii: true,
8
- integrations: [
9
- nodeProfilingIntegration(),
10
- ],
11
- tracesSampleRate: 1.0,
12
- profilesSampleRate: 1.0,
13
- });*/
@@ -1 +0,0 @@
1
- export {};
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- const Sentry = __importStar(require("@sentry/nestjs"));
37
- const profiling_node_1 = require("@sentry/profiling-node");
38
- Sentry.init({
39
- dsn: process.env.SENTRY_DSN,
40
- serverName: process.env.SENTRY_SERVER_NAME,
41
- sendDefaultPii: true,
42
- integrations: [
43
- (0, profiling_node_1.nodeProfilingIntegration)(),
44
- ],
45
- tracesSampleRate: 1.0,
46
- profilesSampleRate: 1.0,
47
- });
@@ -1,15 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node" />
5
- import { Stats } from 'fs';
6
- import internal from 'stream';
7
- export declare class StorageHelper {
8
- rootPath: string;
9
- read(path: string): Promise<Buffer>;
10
- write(path: string, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | internal.Stream): Promise<void>;
11
- append(path: string, data: string | Uint8Array): Promise<void>;
12
- delete(path: string): Promise<void>;
13
- stat(path: string): Promise<Stats>;
14
- private safeDirectory;
15
- }
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StorageHelper = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const os_1 = require("os");
7
- const path_helper_1 = require("./path.helper");
8
- class StorageHelper {
9
- constructor() {
10
- this.rootPath = (0, path_helper_1.joinFromRoot)('public');
11
- }
12
- async read(path) {
13
- const realPath = (0, path_1.join)(this.rootPath, path);
14
- return await fs_1.promises.readFile(realPath, {});
15
- }
16
- async write(path, data) {
17
- const realPath = (0, path_1.join)(this.rootPath, path);
18
- await this.safeDirectory(realPath);
19
- return await fs_1.promises.writeFile(realPath, data, 'utf8');
20
- }
21
- async append(path, data) {
22
- const realPath = (0, path_1.join)(this.rootPath, path);
23
- await this.safeDirectory(realPath);
24
- return await fs_1.promises.appendFile(realPath, data + os_1.EOL);
25
- }
26
- async delete(path) {
27
- const realPath = (0, path_1.join)(this.rootPath, path);
28
- try {
29
- return await fs_1.promises.unlink(realPath);
30
- }
31
- catch (e) { }
32
- }
33
- async stat(path) {
34
- const realPath = (0, path_1.join)(this.rootPath, path);
35
- return fs_1.promises.stat(realPath);
36
- }
37
- async safeDirectory(path) {
38
- const dirPath = (0, path_1.dirname)(path);
39
- try {
40
- await fs_1.promises.stat(dirPath);
41
- }
42
- catch (e) {
43
- await fs_1.promises.mkdir(dirPath, { recursive: true });
44
- }
45
- }
46
- }
47
- exports.StorageHelper = StorageHelper;