@rxap/nest-keyv-minio 11.0.0-dev.2 → 11.0.1-dev.0
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/CHANGELOG.md +16 -0
- package/TODO.md +88 -0
- package/package.json +3 -4
- package/src/generators/init/generator.js +25 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
## 11.0.1-dev.0 (2026-06-19)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- **release:** drop stale per-project release.version overrides
|
|
6
|
+
- **generators:** read package.json and node_modules from disk, not the virtual Tree
|
|
7
|
+
- **generators:** match package name with .some() in init devDependency coercion
|
|
8
|
+
|
|
9
|
+
### ❤️ Thank You
|
|
10
|
+
|
|
11
|
+
- Merzough Münker
|
|
12
|
+
|
|
1
13
|
# Change Log
|
|
2
14
|
|
|
3
15
|
All notable changes to this project will be documented in this file.
|
|
4
16
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
17
|
|
|
18
|
+
# [11.0.0](https://gitlab.com/rxap/packages/compare/@rxap/nest-keyv-minio@11.0.0-dev.2...@rxap/nest-keyv-minio@11.0.0) (2026-01-23)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @rxap/nest-keyv-minio
|
|
21
|
+
|
|
6
22
|
# [11.0.0-dev.2](https://gitlab.com/rxap/packages/compare/@rxap/nest-keyv-minio@11.0.0-dev.1...@rxap/nest-keyv-minio@11.0.0-dev.2) (2025-05-19)
|
|
7
23
|
|
|
8
24
|
### Bug Fixes
|
package/TODO.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# TODO: nest-keyv-minio Audit Findings & Improvements
|
|
2
|
+
|
|
3
|
+
This document lists the findings from the project audit of `nest-keyv-minio`. It includes critical logic bugs, architectural debt, testing gaps, and recommended fixes.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Critical Bugs 🚨
|
|
8
|
+
|
|
9
|
+
### A. Platform-Dependent S3 Keys (Medium Severity)
|
|
10
|
+
- **File:** `src/lib/keyv-minio.ts` (Lines 30, 47, 52)
|
|
11
|
+
- **Problem:**
|
|
12
|
+
```typescript
|
|
13
|
+
const filePath = join(this.options.pathPrefix ?? '', key + '.json');
|
|
14
|
+
```
|
|
15
|
+
The `join` function from the native Node `path` module is platform-dependent. On Windows systems, it uses backslashes (`\`) instead of forward slashes (`/`). S3 and MinIO expect forward slashes as directory separators. Using `path.join` causes malformed object keys on Windows development or server environments, breaking compatibility and cache prefix routing.
|
|
16
|
+
- **Recommended Fix:** Use `path/posix`'s `join`, or manual string concatenation:
|
|
17
|
+
```typescript
|
|
18
|
+
const prefix = this.options.pathPrefix ? `${this.options.pathPrefix}/` : '';
|
|
19
|
+
const filePath = `${prefix}${key}.json`;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### B. Swallowed Errors in `delete()` (Medium Severity)
|
|
23
|
+
- **File:** `src/lib/keyv-minio.ts` (Lines 51-61)
|
|
24
|
+
- **Problem:**
|
|
25
|
+
```typescript
|
|
26
|
+
try {
|
|
27
|
+
await this.client.removeObject(this.bucketName, filePath);
|
|
28
|
+
} catch (error: any) {
|
|
29
|
+
if (error.code === 'NoSuchKey') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
```
|
|
35
|
+
If `removeObject` fails due to critical network, credential, or permission errors, the catch block swallows the error entirely and returns `true` (indicating successful deletion). This can lead to silent cache failures where values are never deleted but the application believes they were.
|
|
36
|
+
- **Recommended Fix:** Propagate unexpected errors or return `false`:
|
|
37
|
+
```typescript
|
|
38
|
+
try {
|
|
39
|
+
await this.client.removeObject(this.bucketName, filePath);
|
|
40
|
+
return true;
|
|
41
|
+
} catch (error: any) {
|
|
42
|
+
if (error.code === 'NoSuchKey') {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Failed to delete key ${key}: ${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 2. Architectural Debt & Anti-patterns 🏛️
|
|
52
|
+
|
|
53
|
+
### A. Resource Exhaustion & Missing Batch Deletion in `clear()` (High Risk)
|
|
54
|
+
- **File:** `src/lib/keyv-minio.ts` (Lines 63-94)
|
|
55
|
+
- **Problem:**
|
|
56
|
+
The `clear()` method collects deletion promises for every object in the stream and executes them concurrently using `Promise.allSettled`:
|
|
57
|
+
```typescript
|
|
58
|
+
const deletePromises: Array<Promise<any>> = [];
|
|
59
|
+
stream.on('data', (obj) => {
|
|
60
|
+
deletePromises.push(this.client.removeObject(this.bucketName, obj.name));
|
|
61
|
+
});
|
|
62
|
+
stream.on('end', async () => {
|
|
63
|
+
await Promise.allSettled(deletePromises);
|
|
64
|
+
resolve();
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
For large buckets or prefixes containing thousands of files, this will attempt to fire thousands of concurrent HTTP requests. This leads to socket exhaustion, connection timeouts, heap out-of-memory crashes, or API rate-limiting.
|
|
68
|
+
Furthermore, because `Promise.allSettled` is resolved without checking the results, failures to delete items are silently ignored.
|
|
69
|
+
- **Recommended Fix:**
|
|
70
|
+
Use MinIO's native plural `removeObjects` method to delete objects in batches of up to 1000, which is highly optimized and S3-standard:
|
|
71
|
+
```typescript
|
|
72
|
+
// Collect object names in an array and use removeObjects in chunks of 1000
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 3. Test Coverage 🧪
|
|
78
|
+
|
|
79
|
+
- **Current Status:** **0% Test Coverage**.
|
|
80
|
+
- **Problem:**
|
|
81
|
+
The project contains setup for Jest (`jest.config.ts`, `tsconfig.spec.json`) but does not contain a single `.spec.ts` test file. Running `yarn nx run nest-keyv-minio:test` runs successfully but executes 0 tests.
|
|
82
|
+
- **Recommended Fix:**
|
|
83
|
+
Create a test suite (e.g. `src/lib/keyv-minio.spec.ts`) that mocks the MinIO `Client` and verifies:
|
|
84
|
+
1. `get()` retrieves and parses valid JSON.
|
|
85
|
+
2. `get()` handles `NoSuchKey` and returns `undefined`.
|
|
86
|
+
3. `set()` saves JSON wrapped with expiration.
|
|
87
|
+
4. `delete()` deletes keys and handles errors appropriately.
|
|
88
|
+
5. `clear()` lists and deletes files correctly.
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "11.0.
|
|
2
|
+
"version": "11.0.1-dev.0",
|
|
3
3
|
"name": "@rxap/nest-keyv-minio",
|
|
4
4
|
"description": "A NestJS cache module that utilizes MinIO as a storage adapter for Keyv. It provides a simple way to integrate MinIO with NestJS caching, allowing you to store cached data in a MinIO bucket. This package includes a Keyv adapter and a module options factory for easy configuration.\n",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"@nestjs/cache-manager": "^3.0.1",
|
|
12
12
|
"@nestjs/common": "^11.1.1",
|
|
13
|
-
"@rxap/nest-utilities": "^11.0.0
|
|
13
|
+
"@rxap/nest-utilities": "^11.0.0",
|
|
14
14
|
"joi": "^17.9.2",
|
|
15
15
|
"keyv": "^5.2.3",
|
|
16
16
|
"minio": "^8.0.1"
|
|
@@ -42,6 +42,5 @@
|
|
|
42
42
|
"directory": "packages/nest/keyv-minio"
|
|
43
43
|
},
|
|
44
44
|
"type": "commonjs",
|
|
45
|
-
"types": "./src/index.d.ts"
|
|
46
|
-
"gitHead": "0155bd71eef8e8c04737d05993133cb8bc79c47d"
|
|
45
|
+
"types": "./src/index.d.ts"
|
|
47
46
|
}
|
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initGenerator = initGenerator;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
async function initGenerator(tree, options) {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// The package's own package.json lives on disk next to the compiled generator
|
|
9
|
+
// (inside node_modules when installed), which the virtual Tree does not track.
|
|
10
|
+
// Read it directly from the physical filesystem.
|
|
11
|
+
const packageJsonFilePath = (0, path_1.join)(__dirname, '..', '..', '..', 'package.json');
|
|
12
|
+
if (!(0, fs_1.existsSync)(packageJsonFilePath)) {
|
|
9
13
|
console.error('package.json not found in: ' + packageJsonFilePath);
|
|
10
14
|
return;
|
|
11
15
|
}
|
|
12
|
-
const { peerDependencies, name: packageName } = JSON.parse(
|
|
16
|
+
const { peerDependencies, name: packageName } = JSON.parse((0, fs_1.readFileSync)(packageJsonFilePath, 'utf-8'));
|
|
13
17
|
console.log(`Coerce peer dependencies for package: ${packageName}`);
|
|
14
18
|
if (!peerDependencies || !Object.keys(peerDependencies).length) {
|
|
15
19
|
console.log('No peer dependencies found');
|
|
@@ -27,11 +31,12 @@ async function initGenerator(tree, options) {
|
|
|
27
31
|
isDevDependency = false;
|
|
28
32
|
tree.write('package.json', JSON.stringify(rootPackageJson, null, 2));
|
|
29
33
|
}
|
|
30
|
-
if (!isDevDependency &&
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (!isDevDependency &&
|
|
35
|
+
[
|
|
36
|
+
/^@rxap\/plugin/,
|
|
37
|
+
/^@rxap\/workspace/,
|
|
38
|
+
/@rxap\/schematic/,
|
|
39
|
+
].some((rx) => rx.test(packageName))) {
|
|
35
40
|
rootPackageJson.devDependencies ??= {};
|
|
36
41
|
rootPackageJson.devDependencies[packageName] =
|
|
37
42
|
rootPackageJson.dependencies[packageName];
|
|
@@ -57,35 +62,39 @@ async function initGenerator(tree, options) {
|
|
|
57
62
|
(0, devkit_1.installPackagesTask)(tree);
|
|
58
63
|
for (const peer of Object.keys(missingPeerDependencies)) {
|
|
59
64
|
console.log(`Peer dependency ${peer} added to package.json`);
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
// node_modules is physical and excluded from the virtual Tree, so resolve
|
|
66
|
+
// peer files from disk relative to the workspace root.
|
|
67
|
+
const peerPackageDir = (0, path_1.join)(tree.root, 'node_modules', ...peer.split('/'));
|
|
68
|
+
const peerPackageJsonFilePath = (0, path_1.join)(peerPackageDir, 'package.json');
|
|
69
|
+
if (!(0, fs_1.existsSync)(peerPackageJsonFilePath)) {
|
|
62
70
|
console.log(`Peer dependency ${peer} has no package.json`);
|
|
63
71
|
continue;
|
|
64
72
|
}
|
|
65
|
-
const { generators, schematics } = JSON.parse(
|
|
73
|
+
const { generators, schematics } = JSON.parse((0, fs_1.readFileSync)(peerPackageJsonFilePath, 'utf-8'));
|
|
66
74
|
if (!generators && !schematics) {
|
|
67
75
|
console.log(`Peer dependency ${peer} has no generators or schematics`);
|
|
68
76
|
continue;
|
|
69
77
|
}
|
|
70
78
|
const configFile = generators || schematics;
|
|
71
|
-
|
|
79
|
+
const configFilePath = (0, path_1.join)(peerPackageDir, configFile);
|
|
80
|
+
if (!(0, fs_1.existsSync)(configFilePath)) {
|
|
72
81
|
console.log(`Peer dependency ${peer} has no generators or schematics file`);
|
|
73
82
|
continue;
|
|
74
83
|
}
|
|
75
|
-
const config = JSON.parse(
|
|
84
|
+
const config = JSON.parse((0, fs_1.readFileSync)(configFilePath, 'utf-8'));
|
|
76
85
|
if (!config.generators?.init) {
|
|
77
86
|
console.log(`Peer dependency ${peer} has no init generator`);
|
|
78
87
|
continue;
|
|
79
88
|
}
|
|
80
89
|
const initGeneratorFilePath = config.generators.init.factory;
|
|
81
|
-
const fullInitGeneratorFilePath = (0, path_1.join)(
|
|
82
|
-
if (!
|
|
90
|
+
const fullInitGeneratorFilePath = (0, path_1.join)(peerPackageDir, initGeneratorFilePath) + '.js';
|
|
91
|
+
if (!(0, fs_1.existsSync)(fullInitGeneratorFilePath)) {
|
|
83
92
|
console.log(`Peer dependency ${peer} has no init generator file: ` +
|
|
84
93
|
fullInitGeneratorFilePath);
|
|
85
94
|
continue;
|
|
86
95
|
}
|
|
87
96
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
88
|
-
const initGenerator = require((0, path_1.join)(
|
|
97
|
+
const initGenerator = require((0, path_1.join)(peerPackageDir, initGeneratorFilePath))?.default;
|
|
89
98
|
if (typeof initGenerator !== 'function') {
|
|
90
99
|
console.log(`Peer dependency ${peer} has no init generator function`);
|
|
91
100
|
continue;
|