ts-cache-mongoose 1.7.3 → 1.7.5
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/biome.json +20 -3
- package/dist/index.cjs +2 -6
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -6
- package/package.json +13 -13
- package/src/cache/Cache.ts +1 -4
- package/src/cache/engine/RedisCacheEngine.ts +1 -4
- package/src/extend/aggregate.ts +1 -0
- package/src/extend/query.ts +1 -0
- package/tests/cache-options.test.ts +1 -0
- package/tests/cache-redis.test.ts +2 -3
- package/tests/models/Story.ts +1 -1
- package/tests/models/User.ts +1 -1
- package/tests/mongo/server.ts +1 -2
package/biome.json
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.2.0/schema.json",
|
|
3
3
|
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
|
|
4
4
|
"files": {
|
|
5
5
|
"ignoreUnknown": false,
|
|
6
|
-
"
|
|
6
|
+
"includes": ["src/**/*.ts", "tests/**/*.ts"]
|
|
7
7
|
},
|
|
8
8
|
"formatter": { "enabled": true, "indentStyle": "space", "indentWidth": 2 },
|
|
9
|
-
"
|
|
9
|
+
"assist": {
|
|
10
|
+
"actions": {
|
|
11
|
+
"source": {
|
|
12
|
+
"organizeImports": {
|
|
13
|
+
"level": "on",
|
|
14
|
+
"options": {
|
|
15
|
+
"groups": [
|
|
16
|
+
"vitest",
|
|
17
|
+
":BLANK_LINE:",
|
|
18
|
+
":NODE:",
|
|
19
|
+
{ "type": false },
|
|
20
|
+
":BLANK_LINE:"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
10
27
|
"linter": {
|
|
11
28
|
"enabled": true,
|
|
12
29
|
"rules": {
|
package/dist/index.cjs
CHANGED
|
@@ -72,9 +72,7 @@ var _client;
|
|
|
72
72
|
class RedisCacheEngine {
|
|
73
73
|
constructor(options) {
|
|
74
74
|
__privateAdd$2(this, _client);
|
|
75
|
-
|
|
76
|
-
options.keyPrefix = "cache-mongoose:";
|
|
77
|
-
}
|
|
75
|
+
options.keyPrefix ??= "cache-mongoose:";
|
|
78
76
|
__privateSet$2(this, _client, new IORedis(options));
|
|
79
77
|
}
|
|
80
78
|
async get(key) {
|
|
@@ -131,9 +129,7 @@ class Cache {
|
|
|
131
129
|
if (cacheOptions.engine === "redis" && !cacheOptions.engineOptions) {
|
|
132
130
|
throw new Error(`Engine options are required for ${cacheOptions.engine} engine`);
|
|
133
131
|
}
|
|
134
|
-
|
|
135
|
-
cacheOptions.defaultTTL = "1 minute";
|
|
136
|
-
}
|
|
132
|
+
cacheOptions.defaultTTL ??= "1 minute";
|
|
137
133
|
__privateSet$1(this, _defaultTTL, typeof cacheOptions.defaultTTL === "string" ? ms(cacheOptions.defaultTTL) : cacheOptions.defaultTTL);
|
|
138
134
|
if (cacheOptions.engine === "redis" && cacheOptions.engineOptions) {
|
|
139
135
|
__privateSet$1(this, _engine, new RedisCacheEngine(cacheOptions.engineOptions));
|
package/dist/index.d.cts
CHANGED
|
@@ -48,4 +48,5 @@ declare class CacheMongoose {
|
|
|
48
48
|
close(): Promise<void>;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export {
|
|
51
|
+
export { CacheMongoose as default };
|
|
52
|
+
export type { CacheData, CacheEngine, CacheOptions, CacheTTL };
|
package/dist/index.d.mts
CHANGED
|
@@ -48,4 +48,5 @@ declare class CacheMongoose {
|
|
|
48
48
|
close(): Promise<void>;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export {
|
|
51
|
+
export { CacheMongoose as default };
|
|
52
|
+
export type { CacheData, CacheEngine, CacheOptions, CacheTTL };
|
package/dist/index.mjs
CHANGED
|
@@ -70,9 +70,7 @@ var _client;
|
|
|
70
70
|
class RedisCacheEngine {
|
|
71
71
|
constructor(options) {
|
|
72
72
|
__privateAdd$2(this, _client);
|
|
73
|
-
|
|
74
|
-
options.keyPrefix = "cache-mongoose:";
|
|
75
|
-
}
|
|
73
|
+
options.keyPrefix ??= "cache-mongoose:";
|
|
76
74
|
__privateSet$2(this, _client, new IORedis(options));
|
|
77
75
|
}
|
|
78
76
|
async get(key) {
|
|
@@ -129,9 +127,7 @@ class Cache {
|
|
|
129
127
|
if (cacheOptions.engine === "redis" && !cacheOptions.engineOptions) {
|
|
130
128
|
throw new Error(`Engine options are required for ${cacheOptions.engine} engine`);
|
|
131
129
|
}
|
|
132
|
-
|
|
133
|
-
cacheOptions.defaultTTL = "1 minute";
|
|
134
|
-
}
|
|
130
|
+
cacheOptions.defaultTTL ??= "1 minute";
|
|
135
131
|
__privateSet$1(this, _defaultTTL, typeof cacheOptions.defaultTTL === "string" ? ms(cacheOptions.defaultTTL) : cacheOptions.defaultTTL);
|
|
136
132
|
if (cacheOptions.engine === "redis" && cacheOptions.engineOptions) {
|
|
137
133
|
__privateSet$1(this, _engine, new RedisCacheEngine(cacheOptions.engineOptions));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-cache-mongoose",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"description": "Cache plugin for mongoose Queries and Aggregate (in-memory, redis)",
|
|
5
5
|
"author": "ilovepixelart",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,23 +73,23 @@
|
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@types/ms": "2.1.0",
|
|
75
75
|
"@types/semver": "7.7.0",
|
|
76
|
-
"ioredis": "5.
|
|
76
|
+
"ioredis": "5.7.0",
|
|
77
77
|
"ms": "2.1.3",
|
|
78
|
-
"semver": "7.7.
|
|
78
|
+
"semver": "7.7.2",
|
|
79
79
|
"sort-keys": "4.2.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@biomejs/biome": "
|
|
83
|
-
"@types/node": "
|
|
84
|
-
"@vitest/coverage-v8": "3.
|
|
85
|
-
"bson": "^6.10.
|
|
86
|
-
"mongodb-memory-server": "10.
|
|
87
|
-
"mongoose": "8.
|
|
82
|
+
"@biomejs/biome": "2.2.0",
|
|
83
|
+
"@types/node": "24.3.0",
|
|
84
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
85
|
+
"bson": "^6.10.4",
|
|
86
|
+
"mongodb-memory-server": "10.2.0",
|
|
87
|
+
"mongoose": "8.17.1",
|
|
88
88
|
"open-cli": "8.0.0",
|
|
89
|
-
"pkgroll": "2.
|
|
90
|
-
"simple-git-hooks": "2.
|
|
91
|
-
"typescript": "5.
|
|
92
|
-
"vitest": "3.
|
|
89
|
+
"pkgroll": "2.15.3",
|
|
90
|
+
"simple-git-hooks": "2.13.1",
|
|
91
|
+
"typescript": "5.9.2",
|
|
92
|
+
"vitest": "3.2.4"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"bson": ">=4.7.2 < 7",
|
package/src/cache/Cache.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import ms from 'ms'
|
|
2
|
-
|
|
3
2
|
import { MemoryCacheEngine } from './engine/MemoryCacheEngine'
|
|
4
3
|
import { RedisCacheEngine } from './engine/RedisCacheEngine'
|
|
5
4
|
|
|
@@ -20,9 +19,7 @@ export class Cache {
|
|
|
20
19
|
throw new Error(`Engine options are required for ${cacheOptions.engine} engine`)
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
cacheOptions.defaultTTL = '1 minute'
|
|
25
|
-
}
|
|
22
|
+
cacheOptions.defaultTTL ??= '1 minute'
|
|
26
23
|
|
|
27
24
|
this.#defaultTTL = typeof cacheOptions.defaultTTL === 'string' ? ms(cacheOptions.defaultTTL) : cacheOptions.defaultTTL
|
|
28
25
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EJSON } from 'bson'
|
|
2
2
|
import IORedis from 'ioredis'
|
|
3
3
|
import ms from 'ms'
|
|
4
|
-
|
|
5
4
|
import { convertToObject } from '../../version'
|
|
6
5
|
|
|
7
6
|
import type { Redis, RedisOptions } from 'ioredis'
|
|
@@ -11,9 +10,7 @@ export class RedisCacheEngine implements CacheEngine {
|
|
|
11
10
|
readonly #client: Redis
|
|
12
11
|
|
|
13
12
|
constructor(options: RedisOptions) {
|
|
14
|
-
|
|
15
|
-
options.keyPrefix = 'cache-mongoose:'
|
|
16
|
-
}
|
|
13
|
+
options.keyPrefix ??= 'cache-mongoose:'
|
|
17
14
|
this.#client = new IORedis(options)
|
|
18
15
|
}
|
|
19
16
|
|
package/src/extend/aggregate.ts
CHANGED
|
@@ -26,6 +26,7 @@ export function extendAggregate(mongoose: Mongoose, cache: Cache): void {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
mongoose.Aggregate.prototype.exec = async function (...args: []) {
|
|
29
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: to support node 16
|
|
29
30
|
if (!Object.prototype.hasOwnProperty.call(this, '_ttl')) {
|
|
30
31
|
return mongooseExec.apply(this, args)
|
|
31
32
|
}
|
package/src/extend/query.ts
CHANGED
|
@@ -40,6 +40,7 @@ export function extendQuery(mongoose: Mongoose, cache: Cache): void {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
mongoose.Query.prototype.exec = async function (...args: []) {
|
|
43
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: to support node 16
|
|
43
44
|
if (!Object.prototype.hasOwnProperty.call(this, '_ttl')) {
|
|
44
45
|
return mongooseExec.apply(this, args)
|
|
45
46
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
+
import { ObjectId } from 'bson'
|
|
3
4
|
import mongoose from 'mongoose'
|
|
4
5
|
import plugin from '../src/index'
|
|
5
|
-
import { server } from './mongo/server'
|
|
6
|
-
|
|
7
|
-
import { ObjectId } from 'bson'
|
|
8
6
|
import { StoryModel } from './models/Story'
|
|
9
7
|
import { UserModel } from './models/User'
|
|
8
|
+
import { server } from './mongo/server'
|
|
10
9
|
|
|
11
10
|
import type CacheMongoose from '../src/index'
|
|
12
11
|
|
package/tests/models/Story.ts
CHANGED
package/tests/models/User.ts
CHANGED
package/tests/mongo/server.ts
CHANGED