@rxap/nest-keyv-minio 10.0.0-dev.1 → 10.0.0-dev.2
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 +4 -0
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/lib/keyv-minio-validation-schema.d.ts +3 -0
- package/src/lib/keyv-minio-validation-schema.js +15 -0
- package/src/lib/keyv-minio.d.ts +1 -0
- package/src/lib/keyv-minio.js +9 -5
- package/src/lib/minio-cache-module-options-factory.d.ts +1 -1
- package/src/lib/minio-cache-module-options-factory.js +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [10.0.0-dev.2](https://gitlab.com/rxap/packages/compare/@rxap/nest-keyv-minio@10.0.0-dev.1...@rxap/nest-keyv-minio@10.0.0-dev.2) (2025-02-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rxap/nest-keyv-minio
|
|
9
|
+
|
|
6
10
|
# 10.0.0-dev.1 (2025-02-18)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @rxap/nest-keyv-minio
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "10.0.0-dev.
|
|
2
|
+
"version": "10.0.0-dev.2",
|
|
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",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
},
|
|
43
43
|
"type": "commonjs",
|
|
44
44
|
"types": "./src/index.d.ts",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "2458ac1ebbc7651568802271fb9538c5220bfd41"
|
|
46
46
|
}
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
// region
|
|
5
|
+
tslib_1.__exportStar(require("./lib/keyv-minio-validation-schema"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./lib/keyv-minio"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./lib/minio-cache-module-options-factory"), exports);
|
|
7
8
|
// endregion
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keyvMinioValidationSchema = keyvMinioValidationSchema;
|
|
4
|
+
const Joi = require("joi");
|
|
5
|
+
function keyvMinioValidationSchema(environment) {
|
|
6
|
+
const schema = {};
|
|
7
|
+
schema['KEYV_MINIO_END_POINT'] = Joi.string().default('minio');
|
|
8
|
+
schema['KEYV_MINIO_PORT'] = Joi.number().default(9000);
|
|
9
|
+
schema['KEYV_MINIO_USE_SSL'] = Joi.boolean().default(false);
|
|
10
|
+
schema['KEYV_MINIO_ACCESS_KEY'] = Joi.string().default('minioadmin');
|
|
11
|
+
schema['KEYV_MINIO_SECRET_KEY'] = Joi.string().default('minioadmin');
|
|
12
|
+
schema['KEYV_MINIO_BUCKET_NAME'] = Joi.string().default('minioadmin');
|
|
13
|
+
schema['KEYV_MINIO_PATH_PREFIX'] = Joi.string().default(environment.app);
|
|
14
|
+
return schema;
|
|
15
|
+
}
|
package/src/lib/keyv-minio.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { KeyvStoreAdapter, StoredData } from 'keyv';
|
|
|
2
2
|
import { ClientOptions } from 'minio';
|
|
3
3
|
export interface KeyvMinioOptions extends ClientOptions {
|
|
4
4
|
bucketName: string;
|
|
5
|
+
pathPrefix?: string;
|
|
5
6
|
}
|
|
6
7
|
export declare class KeyvMinio implements KeyvStoreAdapter {
|
|
7
8
|
private readonly options;
|
package/src/lib/keyv-minio.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KeyvMinio = void 0;
|
|
4
4
|
const minio_1 = require("minio");
|
|
5
|
+
const path_1 = require("path");
|
|
5
6
|
class KeyvMinio {
|
|
6
7
|
constructor(options) {
|
|
7
8
|
this.options = options;
|
|
@@ -11,8 +12,9 @@ class KeyvMinio {
|
|
|
11
12
|
return this.options.bucketName;
|
|
12
13
|
}
|
|
13
14
|
async get(key) {
|
|
15
|
+
const filePath = (0, path_1.join)(this.options.pathPrefix ?? '', key + '.json');
|
|
14
16
|
try {
|
|
15
|
-
const dataStream = await this.client.getObject(this.bucketName,
|
|
17
|
+
const dataStream = await this.client.getObject(this.bucketName, filePath);
|
|
16
18
|
let data = '';
|
|
17
19
|
for await (const chunk of dataStream) {
|
|
18
20
|
data += chunk.toString();
|
|
@@ -23,15 +25,17 @@ class KeyvMinio {
|
|
|
23
25
|
if (error.code === 'NoSuchKey') {
|
|
24
26
|
return undefined;
|
|
25
27
|
}
|
|
26
|
-
throw new Error(`Error getting minio object in bucket ${this.bucketName} with key ${
|
|
28
|
+
throw new Error(`Error getting minio object in bucket ${this.bucketName} with key ${filePath}: (${error.code}) ${error.message}`);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
async set(key, value, ttl) {
|
|
30
|
-
|
|
32
|
+
const filePath = (0, path_1.join)(this.options.pathPrefix ?? '', key + '.json');
|
|
33
|
+
await this.client.putObject(this.bucketName, filePath, JSON.stringify({ value, expires: ttl ? Date.now() + ttl : null }), undefined);
|
|
31
34
|
}
|
|
32
35
|
async delete(key) {
|
|
36
|
+
const filePath = (0, path_1.join)(this.options.pathPrefix ?? '', key + '.json');
|
|
33
37
|
try {
|
|
34
|
-
await this.client.removeObject(this.bucketName,
|
|
38
|
+
await this.client.removeObject(this.bucketName, filePath);
|
|
35
39
|
}
|
|
36
40
|
catch (error) {
|
|
37
41
|
if (error.code === 'NoSuchKey') {
|
|
@@ -43,7 +47,7 @@ class KeyvMinio {
|
|
|
43
47
|
async clear() {
|
|
44
48
|
try {
|
|
45
49
|
// Use the listObjectsV2 method to get a list of objects in the bucket
|
|
46
|
-
const stream = this.client.listObjectsV2(this.bucketName, '', true);
|
|
50
|
+
const stream = this.client.listObjectsV2(this.bucketName, this.options.pathPrefix ?? '', true);
|
|
47
51
|
await new Promise((resolve, reject) => {
|
|
48
52
|
// Array to hold promises for object deletions
|
|
49
53
|
const deletePromises = [];
|
|
@@ -2,5 +2,5 @@ import { CacheOptions } from '@nestjs/cache-manager';
|
|
|
2
2
|
import { KeyvMinioOptions } from './keyv-minio';
|
|
3
3
|
import { CacheModuleOptionsLoader } from '@rxap/nest-utilities';
|
|
4
4
|
export declare class MinioCacheModuleOptionsFactory extends CacheModuleOptionsLoader<KeyvMinioOptions> {
|
|
5
|
-
createCacheOptions(): CacheOptions<KeyvMinioOptions>;
|
|
5
|
+
createCacheOptions(): Promise<CacheOptions<KeyvMinioOptions>> | CacheOptions<KeyvMinioOptions>;
|
|
6
6
|
}
|
|
@@ -49,12 +49,13 @@ let MinioCacheModuleOptionsFactory = class MinioCacheModuleOptionsFactory extend
|
|
|
49
49
|
createCacheOptions() {
|
|
50
50
|
return {
|
|
51
51
|
...super.createCacheOptions(),
|
|
52
|
-
endPoint: this.config.
|
|
53
|
-
port: this.config.get('
|
|
54
|
-
useSSL: this.config.get('
|
|
55
|
-
accessKey: this.config.
|
|
56
|
-
secretKey: this.config.
|
|
57
|
-
bucketName: this.config.get('
|
|
52
|
+
endPoint: this.config.get('KEYV_MINIO_END_POINT', 'minio'),
|
|
53
|
+
port: this.config.get('KEYV_MINIO_PORT', 9000),
|
|
54
|
+
useSSL: this.config.get('KEYV_MINIO_USE_SSL', false),
|
|
55
|
+
accessKey: this.config.get('KEYV_MINIO_ACCESS_KEY', 'minioadmin'),
|
|
56
|
+
secretKey: this.config.get('KEYV_MINIO_SECRET_KEY', 'minioadmin'),
|
|
57
|
+
bucketName: this.config.get('KEYV_MINIO_BUCKET_NAME', 'keyv'),
|
|
58
|
+
pathPrefix: this.config.get('KEYV_MINIO_PATH_PREFIX'),
|
|
58
59
|
store: (options) => new CacheStoreV6ToV5Adapter(new keyv_minio_1.KeyvMinio(options)),
|
|
59
60
|
};
|
|
60
61
|
}
|