lakutata 2.0.65 → 2.0.67
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/com/cacher.cjs +1 -1
- package/com/cacher.d.ts +4 -4
- package/com/cacher.mjs +1 -1
- package/com/database.cjs +0 -2
- package/com/database.d.ts +4 -4
- package/com/database.mjs +0 -2
- package/com/docker.d.ts +5 -5
- package/com/entrypoint.cjs +3 -1
- package/com/entrypoint.d.ts +2 -2
- package/com/entrypoint.mjs +3 -1
- package/com/logger.d.ts +1 -1
- package/com/monitor.d.ts +2 -2
- package/decorator/asst.d.ts +1 -1
- package/decorator/ctrl.cjs +3 -1
- package/decorator/ctrl.d.ts +4 -4
- package/decorator/ctrl.mjs +3 -1
- package/decorator/di.d.ts +3 -3
- package/decorator/dto.d.ts +3 -3
- package/decorator/orm.cjs +86 -88
- package/decorator/orm.d.ts +51 -75
- package/decorator/orm.mjs +44 -46
- package/helper.cjs +24 -18
- package/helper.d.ts +129 -3
- package/helper.mjs +6 -2
- package/lakutata.cjs +3 -1
- package/lakutata.d.ts +10 -10
- package/lakutata.mjs +3 -1
- package/orm.cjs +1075 -112
- package/orm.d.ts +6 -6
- package/orm.mjs +1015 -17
- package/package.json +1 -1
- package/provider/database.cjs +0 -2
- package/provider/database.d.ts +4 -4
- package/provider/database.mjs +0 -2
- package/provider/passwordHash.d.ts +1 -1
- package/src/components/Database.cjs +0 -2
- package/src/components/Database.mjs +0 -2
- package/src/components/cacher/Cacher.cjs +1 -1
- package/src/components/cacher/Cacher.mjs +1 -1
- package/src/components/cacher/adapters/CreateFileCacheAdapter.cjs +1 -1
- package/src/components/cacher/adapters/CreateFileCacheAdapter.mjs +1 -1
- package/src/components/cacher/adapters/CreateMemcacheCacheAdapter.cjs +2 -2
- package/src/components/cacher/adapters/CreateMemcacheCacheAdapter.mjs +2 -2
- package/src/components/cacher/adapters/CreateMongoCacheAdapter.cjs +2 -2
- package/src/components/cacher/adapters/CreateMongoCacheAdapter.mjs +2 -2
- package/src/components/cacher/adapters/CreateMysqlCacheAdapter.cjs +2 -2
- package/src/components/cacher/adapters/CreateMysqlCacheAdapter.mjs +2 -2
- package/src/components/cacher/adapters/CreatePostgresCacheAdapter.cjs +2 -2
- package/src/components/cacher/adapters/CreatePostgresCacheAdapter.mjs +2 -2
- package/src/components/cacher/adapters/CreateRedisCacheAdapter.cjs +2 -2
- package/src/components/cacher/adapters/CreateRedisCacheAdapter.mjs +2 -2
- package/src/components/cacher/adapters/CreateSqliteCacheAdapter.cjs +2 -2
- package/src/components/cacher/adapters/CreateSqliteCacheAdapter.mjs +2 -2
- package/src/components/entrypoint/Entrypoint.cjs +3 -1
- package/src/components/entrypoint/Entrypoint.mjs +3 -1
- package/src/decorators/ctrl/CLIAction.cjs +7 -5
- package/src/decorators/ctrl/CLIAction.mjs +3 -1
- package/src/decorators/ctrl/HTTPAction.cjs +8 -6
- package/src/decorators/ctrl/HTTPAction.mjs +3 -1
- package/src/decorators/ctrl/ServiceAction.cjs +3 -1
- package/src/decorators/ctrl/ServiceAction.mjs +7 -5
- package/src/decorators/ctrl/http/DELETE.cjs +3 -1
- package/src/decorators/ctrl/http/DELETE.mjs +3 -1
- package/src/decorators/ctrl/http/GET.cjs +3 -1
- package/src/decorators/ctrl/http/GET.mjs +3 -1
- package/src/decorators/ctrl/http/HEAD.cjs +3 -1
- package/src/decorators/ctrl/http/HEAD.mjs +3 -1
- package/src/decorators/ctrl/http/OPTIONS.cjs +3 -1
- package/src/decorators/ctrl/http/OPTIONS.mjs +3 -1
- package/src/decorators/ctrl/http/PATCH.cjs +3 -1
- package/src/decorators/ctrl/http/PATCH.mjs +3 -1
- package/src/decorators/ctrl/http/POST.cjs +3 -1
- package/src/decorators/ctrl/http/POST.mjs +3 -1
- package/src/decorators/ctrl/http/PUT.cjs +3 -1
- package/src/decorators/ctrl/http/PUT.mjs +3 -1
- package/src/decorators/orm/AfterInsert.cjs +27 -7
- package/src/decorators/orm/AfterInsert.mjs +28 -6
- package/src/decorators/orm/AfterLoad.cjs +27 -7
- package/src/decorators/orm/AfterLoad.mjs +28 -6
- package/src/decorators/orm/AfterRecover.cjs +27 -7
- package/src/decorators/orm/AfterRecover.mjs +28 -6
- package/src/decorators/orm/AfterRemove.cjs +27 -7
- package/src/decorators/orm/AfterRemove.mjs +28 -6
- package/src/decorators/orm/AfterSoftRemove.cjs +27 -7
- package/src/decorators/orm/AfterSoftRemove.mjs +28 -6
- package/src/decorators/orm/AfterUpdate.cjs +27 -7
- package/src/decorators/orm/AfterUpdate.mjs +28 -6
- package/src/decorators/orm/BeforeInsert.cjs +27 -7
- package/src/decorators/orm/BeforeInsert.mjs +28 -6
- package/src/decorators/orm/BeforeRecover.cjs +27 -7
- package/src/decorators/orm/BeforeRecover.mjs +28 -6
- package/src/decorators/orm/BeforeRemove.cjs +27 -7
- package/src/decorators/orm/BeforeRemove.mjs +28 -6
- package/src/decorators/orm/BeforeSoftRemove.cjs +27 -7
- package/src/decorators/orm/BeforeSoftRemove.mjs +28 -6
- package/src/decorators/orm/BeforeUpdate.cjs +27 -7
- package/src/decorators/orm/BeforeUpdate.mjs +28 -6
- package/src/decorators/orm/Check.cjs +30 -7
- package/src/decorators/orm/Check.mjs +31 -6
- package/src/decorators/orm/ChildEntity.cjs +30 -7
- package/src/decorators/orm/ChildEntity.mjs +31 -6
- package/src/decorators/orm/Column.cjs +62 -7
- package/src/decorators/orm/Column.mjs +63 -6
- package/src/decorators/orm/CreateDateColumn.cjs +26 -7
- package/src/decorators/orm/CreateDateColumn.mjs +27 -6
- package/src/decorators/orm/DeleteDateColumn.cjs +26 -7
- package/src/decorators/orm/DeleteDateColumn.mjs +27 -6
- package/src/decorators/orm/Entity.cjs +36 -7
- package/src/decorators/orm/Entity.mjs +37 -6
- package/src/decorators/orm/EventSubscriber.cjs +23 -7
- package/src/decorators/orm/EventSubscriber.mjs +24 -6
- package/src/decorators/orm/Exclusion.cjs +30 -7
- package/src/decorators/orm/Exclusion.mjs +31 -6
- package/src/decorators/orm/Generated.cjs +25 -7
- package/src/decorators/orm/Generated.mjs +26 -6
- package/src/decorators/orm/Index.cjs +42 -7
- package/src/decorators/orm/Index.mjs +43 -6
- package/src/decorators/orm/JoinColumn.cjs +30 -7
- package/src/decorators/orm/JoinColumn.mjs +31 -6
- package/src/decorators/orm/JoinTable.cjs +31 -7
- package/src/decorators/orm/JoinTable.mjs +32 -6
- package/src/decorators/orm/ManyToMany.cjs +43 -7
- package/src/decorators/orm/ManyToMany.mjs +44 -6
- package/src/decorators/orm/ManyToOne.cjs +43 -7
- package/src/decorators/orm/ManyToOne.mjs +44 -6
- package/src/decorators/orm/ObjectIdColumn.cjs +29 -7
- package/src/decorators/orm/ObjectIdColumn.mjs +30 -6
- package/src/decorators/orm/OneToMany.cjs +35 -7
- package/src/decorators/orm/OneToMany.mjs +36 -6
- package/src/decorators/orm/OneToOne.cjs +43 -7
- package/src/decorators/orm/OneToOne.mjs +44 -6
- package/src/decorators/orm/PrimaryColumn.cjs +50 -7
- package/src/decorators/orm/PrimaryColumn.mjs +51 -6
- package/src/decorators/orm/PrimaryGeneratedColumn.cjs +55 -7
- package/src/decorators/orm/PrimaryGeneratedColumn.mjs +56 -6
- package/src/decorators/orm/RelationId.cjs +27 -7
- package/src/decorators/orm/RelationId.mjs +28 -6
- package/src/decorators/orm/TableInheritance.cjs +27 -7
- package/src/decorators/orm/TableInheritance.mjs +28 -6
- package/src/decorators/orm/Tree.cjs +25 -7
- package/src/decorators/orm/Tree.mjs +26 -6
- package/src/decorators/orm/TreeChildren.cjs +32 -7
- package/src/decorators/orm/TreeChildren.mjs +33 -6
- package/src/decorators/orm/TreeLevelColumn.cjs +26 -7
- package/src/decorators/orm/TreeLevelColumn.mjs +27 -6
- package/src/decorators/orm/TreeParent.cjs +32 -7
- package/src/decorators/orm/TreeParent.mjs +33 -6
- package/src/decorators/orm/Unique.cjs +45 -7
- package/src/decorators/orm/Unique.mjs +46 -6
- package/src/decorators/orm/UpdateDateColumn.cjs +26 -7
- package/src/decorators/orm/UpdateDateColumn.mjs +27 -6
- package/src/decorators/orm/VersionColumn.cjs +26 -7
- package/src/decorators/orm/VersionColumn.mjs +27 -6
- package/src/decorators/orm/ViewColumn.cjs +26 -7
- package/src/decorators/orm/ViewColumn.mjs +27 -6
- package/src/decorators/orm/ViewEntity.cjs +35 -7
- package/src/decorators/orm/ViewEntity.mjs +36 -6
- package/src/decorators/orm/VirtualColumn.cjs +43 -7
- package/src/decorators/orm/VirtualColumn.mjs +44 -6
- package/src/lib/base/internal/ControllerEntrypoint.cjs +70 -610
- package/src/lib/base/internal/ControllerEntrypoint.mjs +87 -627
- package/src/lib/base/internal/StringifyPattern.cjs +1 -1
- package/src/lib/base/internal/StringifyPattern.mjs +1 -1
- package/src/lib/core/Application.cjs +3 -1
- package/src/lib/core/Application.mjs +3 -1
- package/src/lib/helpers/MD5.cjs +1 -1
- package/src/lib/helpers/MD5.mjs +1 -1
- package/src/lib/helpers/SHA1.cjs +1 -1
- package/src/lib/helpers/SHA1.mjs +1 -1
- package/src/lib/helpers/SHA256.cjs +1 -1
- package/src/lib/helpers/SHA256.mjs +1 -1
- package/src/lib/helpers/SortArray.cjs +1 -1
- package/src/lib/helpers/SortArray.mjs +1 -1
- package/src/lib/helpers/UUID.cjs +45 -0
- package/src/lib/helpers/UUID.mjs +39 -0
- package/src/providers/Database.cjs +0 -2
- package/src/providers/Database.mjs +0 -2
- package/vendor/Package.122.cjs +13223 -16706
- package/vendor/Package.122.mjs +13498 -16881
- package/vendor/Package.19.cjs +184 -195
- package/vendor/Package.19.mjs +176 -187
- package/vendor/Package.610.cjs +297 -113
- package/vendor/Package.610.mjs +285 -97
- package/vendor/Package.611.cjs +85 -103
- package/vendor/Package.611.mjs +80 -98
- package/vendor/Package.612.cjs +100 -121
- package/vendor/Package.612.mjs +97 -120
- package/vendor/Package.613.cjs +196 -0
- package/vendor/Package.613.mjs +180 -0
- package/vendor/Package.64.cjs +511 -134
- package/vendor/Package.64.mjs +491 -134
- package/vendor/Package.65.cjs +140 -4118
- package/vendor/Package.65.mjs +140 -4126
- package/vendor/Package.66.cjs +4142 -692
- package/vendor/Package.66.mjs +4151 -689
- package/vendor/Package.67.cjs +571 -535
- package/vendor/Package.67.mjs +586 -528
- package/vendor/Package.68.cjs +633 -96
- package/vendor/Package.68.mjs +619 -94
- package/vendor/Package.69.cjs +96 -294
- package/vendor/Package.69.mjs +95 -295
- package/vendor/TypeDef.internal.1.d.ts +1 -1
- package/vendor/TypeDef.internal.10.d.ts +1 -1
- package/vendor/TypeDef.internal.11.d.ts +2 -2
- package/vendor/TypeDef.internal.12.d.ts +2 -2
- package/vendor/TypeDef.internal.13.d.ts +6 -6
- package/vendor/TypeDef.internal.3.d.ts +3 -3
- package/vendor/TypeDef.internal.4.d.ts +181 -347
- package/vendor/TypeDef.internal.5.d.ts +2 -2
- package/vendor/TypeDef.internal.6.d.ts +2 -2
- package/vendor/TypeDef.internal.7.d.ts +1 -1
- package/vendor/TypeDef.internal.8.d.ts +1 -1
- package/vendor/TypeDef.internal.9.d.ts +1 -1
package/vendor/Package.67.cjs
CHANGED
|
@@ -1,680 +1,716 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: "Module"
|
|
5
|
-
});
|
|
3
|
+
const e = require("buffer");
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
var t = s => {
|
|
6
|
+
if (s === void 0 || s === null) {
|
|
7
|
+
return "null";
|
|
8
|
+
}
|
|
9
|
+
if (typeof s === "string") {
|
|
10
|
+
return JSON.stringify(s.startsWith(":") ? ":" + s : s);
|
|
11
|
+
}
|
|
12
|
+
if (e.Buffer.isBuffer(s)) {
|
|
13
|
+
return JSON.stringify(":base64:" + s.toString("base64"));
|
|
14
|
+
}
|
|
15
|
+
if (s?.toJSON) {
|
|
16
|
+
s = s.toJSON();
|
|
17
|
+
}
|
|
18
|
+
if (typeof s === "object") {
|
|
19
|
+
let e = "";
|
|
20
|
+
const i = Array.isArray(s);
|
|
21
|
+
e = i ? "[" : "{";
|
|
22
|
+
let r = true;
|
|
23
|
+
for (const o in s) {
|
|
24
|
+
const a = typeof s[o] === "function" || !i && s[o] === void 0;
|
|
25
|
+
if (!Object.hasOwn(s, o) || a) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!r) {
|
|
29
|
+
e += ",";
|
|
30
|
+
}
|
|
31
|
+
r = false;
|
|
32
|
+
if (i) {
|
|
33
|
+
e += t(s[o]);
|
|
34
|
+
} else if (s[o] !== void 0) {
|
|
35
|
+
e += t(o) + ":" + t(s[o]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
e += i ? "]" : "}";
|
|
39
|
+
return e;
|
|
40
|
+
}
|
|
41
|
+
return JSON.stringify(s);
|
|
17
42
|
};
|
|
18
43
|
|
|
19
|
-
|
|
44
|
+
var s = t => JSON.parse(t, ((t, s) => {
|
|
45
|
+
if (typeof s === "string") {
|
|
46
|
+
if (s.startsWith(":base64:")) {
|
|
47
|
+
return e.Buffer.from(s.slice(8), "base64");
|
|
48
|
+
}
|
|
49
|
+
return s.startsWith(":") ? s.slice(1) : s;
|
|
50
|
+
}
|
|
51
|
+
return s;
|
|
52
|
+
}));
|
|
20
53
|
|
|
21
|
-
var
|
|
54
|
+
var i = class {
|
|
22
55
|
_eventListeners;
|
|
23
56
|
_maxListeners;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
}
|
|
28
|
-
once(e, t) {
|
|
29
|
-
let r = (...s) => {
|
|
30
|
-
this.off(e, r), t(...s);
|
|
31
|
-
};
|
|
32
|
-
return this.on(e, r), this;
|
|
33
|
-
}
|
|
34
|
-
listenerCount(e) {
|
|
35
|
-
if (!e) return this.getAllListeners().length;
|
|
36
|
-
let t = this._eventListeners.get(e);
|
|
37
|
-
return t ? t.length : 0;
|
|
38
|
-
}
|
|
39
|
-
eventNames() {
|
|
40
|
-
return [ ...this._eventListeners.keys() ];
|
|
41
|
-
}
|
|
42
|
-
rawListeners(e) {
|
|
43
|
-
return e ? this._eventListeners.get(e) ?? [] : this.getAllListeners();
|
|
44
|
-
}
|
|
45
|
-
prependListener(e, t) {
|
|
46
|
-
let r = this._eventListeners.get(e) ?? [];
|
|
47
|
-
return r.unshift(t), this._eventListeners.set(e, r), this;
|
|
48
|
-
}
|
|
49
|
-
prependOnceListener(e, t) {
|
|
50
|
-
let r = (...s) => {
|
|
51
|
-
this.off(e, r), t(...s);
|
|
52
|
-
};
|
|
53
|
-
return this.prependListener(e, r), this;
|
|
57
|
+
constructor() {
|
|
58
|
+
this._eventListeners = new Map;
|
|
59
|
+
this._maxListeners = 100;
|
|
54
60
|
}
|
|
55
61
|
maxListeners() {
|
|
56
62
|
return this._maxListeners;
|
|
57
63
|
}
|
|
58
64
|
addListener(e, t) {
|
|
59
|
-
|
|
65
|
+
this.on(e, t);
|
|
60
66
|
}
|
|
61
67
|
on(e, t) {
|
|
62
|
-
this._eventListeners.has(e)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
if (!this._eventListeners.has(e)) {
|
|
69
|
+
this._eventListeners.set(e, []);
|
|
70
|
+
}
|
|
71
|
+
const s = this._eventListeners.get(e);
|
|
72
|
+
if (s) {
|
|
73
|
+
if (s.length >= this._maxListeners) {
|
|
74
|
+
console.warn(`MaxListenersExceededWarning: Possible event memory leak detected. ${s.length + 1} ${e} listeners added. Use setMaxListeners() to increase limit.`);
|
|
75
|
+
}
|
|
76
|
+
s.push(t);
|
|
77
|
+
}
|
|
78
|
+
return this;
|
|
66
79
|
}
|
|
67
80
|
removeListener(e, t) {
|
|
68
|
-
|
|
81
|
+
this.off(e, t);
|
|
69
82
|
}
|
|
70
83
|
off(e, t) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
const s = this._eventListeners.get(e) ?? [];
|
|
85
|
+
const i = s.indexOf(t);
|
|
86
|
+
if (i !== -1) {
|
|
87
|
+
s.splice(i, 1);
|
|
88
|
+
}
|
|
89
|
+
if (s.length === 0) {
|
|
90
|
+
this._eventListeners.delete(e);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
once(e, t) {
|
|
94
|
+
const s = (...i) => {
|
|
95
|
+
t(...i);
|
|
96
|
+
this.off(e, s);
|
|
97
|
+
};
|
|
98
|
+
this.on(e, s);
|
|
74
99
|
}
|
|
75
100
|
emit(e, ...t) {
|
|
76
|
-
|
|
77
|
-
if (s && s.length > 0)
|
|
78
|
-
|
|
101
|
+
const s = this._eventListeners.get(e);
|
|
102
|
+
if (s && s.length > 0) {
|
|
103
|
+
for (const e of s) {
|
|
104
|
+
e(...t);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
79
107
|
}
|
|
80
108
|
listeners(e) {
|
|
81
109
|
return this._eventListeners.get(e) ?? [];
|
|
82
110
|
}
|
|
83
111
|
removeAllListeners(e) {
|
|
84
|
-
|
|
112
|
+
if (e) {
|
|
113
|
+
this._eventListeners.delete(e);
|
|
114
|
+
} else {
|
|
115
|
+
this._eventListeners.clear();
|
|
116
|
+
}
|
|
85
117
|
}
|
|
86
118
|
setMaxListeners(e) {
|
|
87
119
|
this._maxListeners = e;
|
|
88
|
-
for (let t of this._eventListeners.values()) t.length > e && t.splice(e);
|
|
89
|
-
}
|
|
90
|
-
getAllListeners() {
|
|
91
|
-
let e = new Array;
|
|
92
|
-
for (let t of this._eventListeners.values()) e = [ ...e, ...t ];
|
|
93
|
-
return e;
|
|
94
120
|
}
|
|
95
121
|
};
|
|
96
122
|
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
get hooks() {
|
|
106
|
-
return this._hooks;
|
|
107
|
-
}
|
|
108
|
-
get throwHookErrors() {
|
|
109
|
-
return this._throwHookErrors;
|
|
110
|
-
}
|
|
111
|
-
set throwHookErrors(e) {
|
|
112
|
-
this._throwHookErrors = e;
|
|
113
|
-
}
|
|
114
|
-
get logger() {
|
|
115
|
-
return this._logger;
|
|
116
|
-
}
|
|
117
|
-
set logger(e) {
|
|
118
|
-
this._logger = e;
|
|
119
|
-
}
|
|
120
|
-
onHook(e, t) {
|
|
121
|
-
let r = this._hooks.get(e);
|
|
122
|
-
r ? r.push(t) : this._hooks.set(e, [ t ]);
|
|
123
|
-
}
|
|
124
|
-
addHook(e, t) {
|
|
125
|
-
this.onHook(e, t);
|
|
123
|
+
var r = i;
|
|
124
|
+
|
|
125
|
+
var o = class extends r {
|
|
126
|
+
_hookHandlers;
|
|
127
|
+
constructor() {
|
|
128
|
+
super();
|
|
129
|
+
this._hookHandlers = new Map;
|
|
126
130
|
}
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
addHandler(e, t) {
|
|
132
|
+
const s = this._hookHandlers.get(e);
|
|
133
|
+
if (s) {
|
|
134
|
+
s.push(t);
|
|
135
|
+
} else {
|
|
136
|
+
this._hookHandlers.set(e, [ t ]);
|
|
137
|
+
}
|
|
129
138
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
removeHandler(e, t) {
|
|
140
|
+
const s = this._hookHandlers.get(e);
|
|
141
|
+
if (s) {
|
|
142
|
+
const e = s.indexOf(t);
|
|
143
|
+
if (e !== -1) {
|
|
144
|
+
s.splice(e, 1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
133
147
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
148
|
+
trigger(e, t) {
|
|
149
|
+
const s = this._hookHandlers.get(e);
|
|
150
|
+
if (s) {
|
|
151
|
+
for (const i of s) {
|
|
152
|
+
try {
|
|
153
|
+
i(t);
|
|
154
|
+
} catch (t) {
|
|
155
|
+
this.emit("error", new Error(`Error in hook handler for event "${e}": ${t.message}`));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
137
159
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this.onHook(e, r);
|
|
160
|
+
get handlers() {
|
|
161
|
+
return new Map(this._hookHandlers);
|
|
141
162
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
var a = o;
|
|
166
|
+
|
|
167
|
+
var n = class extends r {
|
|
168
|
+
enabled=true;
|
|
169
|
+
hits=0;
|
|
170
|
+
misses=0;
|
|
171
|
+
sets=0;
|
|
172
|
+
deletes=0;
|
|
173
|
+
errors=0;
|
|
174
|
+
constructor(e) {
|
|
175
|
+
super();
|
|
176
|
+
if (e !== void 0) {
|
|
177
|
+
this.enabled = e;
|
|
147
178
|
}
|
|
179
|
+
this.reset();
|
|
148
180
|
}
|
|
149
|
-
|
|
150
|
-
|
|
181
|
+
hit() {
|
|
182
|
+
if (this.enabled) {
|
|
183
|
+
this.hits++;
|
|
184
|
+
}
|
|
151
185
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
await s(...t);
|
|
156
|
-
} catch (t) {
|
|
157
|
-
let r = `${e}: ${t.message}`;
|
|
158
|
-
if (this.emit("error", new Error(r)), this._logger && this._logger.error(r), this._throwHookErrors) throw new Error(r);
|
|
186
|
+
miss() {
|
|
187
|
+
if (this.enabled) {
|
|
188
|
+
this.misses++;
|
|
159
189
|
}
|
|
160
190
|
}
|
|
161
|
-
|
|
162
|
-
|
|
191
|
+
set() {
|
|
192
|
+
if (this.enabled) {
|
|
193
|
+
this.sets++;
|
|
194
|
+
}
|
|
163
195
|
}
|
|
164
|
-
|
|
165
|
-
|
|
196
|
+
delete() {
|
|
197
|
+
if (this.enabled) {
|
|
198
|
+
this.deletes++;
|
|
199
|
+
}
|
|
166
200
|
}
|
|
167
|
-
|
|
168
|
-
this.
|
|
201
|
+
reset() {
|
|
202
|
+
this.hits = 0;
|
|
203
|
+
this.misses = 0;
|
|
204
|
+
this.sets = 0;
|
|
205
|
+
this.deletes = 0;
|
|
206
|
+
this.errors = 0;
|
|
169
207
|
}
|
|
170
208
|
};
|
|
171
209
|
|
|
172
|
-
var
|
|
173
|
-
|
|
210
|
+
var h = n;
|
|
211
|
+
|
|
212
|
+
var l = (e => {
|
|
213
|
+
e["PRE_SET"] = "preSet";
|
|
214
|
+
e["POST_SET"] = "postSet";
|
|
215
|
+
e["PRE_GET"] = "preGet";
|
|
216
|
+
e["POST_GET"] = "postGet";
|
|
217
|
+
e["PRE_GET_MANY"] = "preGetMany";
|
|
218
|
+
e["POST_GET_MANY"] = "postGetMany";
|
|
219
|
+
e["PRE_DELETE"] = "preDelete";
|
|
220
|
+
e["POST_DELETE"] = "postDelete";
|
|
174
221
|
return e;
|
|
175
|
-
})(
|
|
222
|
+
})(l || {});
|
|
176
223
|
|
|
177
|
-
var c =
|
|
178
|
-
const t = Math.min(2 ** e * 100, 2e3);
|
|
179
|
-
const r = (Math.random() - .5) * 100;
|
|
180
|
-
return t + r;
|
|
181
|
-
};
|
|
224
|
+
var c = [ "sqlite", "postgres", "mysql", "mongo", "redis", "valkey", "etcd" ];
|
|
182
225
|
|
|
183
|
-
var
|
|
184
|
-
|
|
226
|
+
var f = class extends r {
|
|
227
|
+
opts;
|
|
228
|
+
iterator;
|
|
229
|
+
hooks=new a;
|
|
230
|
+
stats=new h(false);
|
|
231
|
+
_ttl;
|
|
185
232
|
_namespace;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
_connectionTimeout;
|
|
193
|
-
constructor(t, r) {
|
|
233
|
+
_store=new Map;
|
|
234
|
+
_serialize=t;
|
|
235
|
+
_deserialize=s;
|
|
236
|
+
_compression;
|
|
237
|
+
_useKeyPrefix=true;
|
|
238
|
+
constructor(e, i) {
|
|
194
239
|
super();
|
|
195
|
-
|
|
196
|
-
|
|
240
|
+
i ??= {};
|
|
241
|
+
e ??= {};
|
|
242
|
+
this.opts = {
|
|
243
|
+
namespace: "keyv",
|
|
244
|
+
serialize: t,
|
|
245
|
+
deserialize: s,
|
|
246
|
+
emitErrors: true,
|
|
247
|
+
store: new Map,
|
|
248
|
+
...i
|
|
197
249
|
};
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
250
|
+
if (e && e.get) {
|
|
251
|
+
this.opts.store = e;
|
|
252
|
+
} else {
|
|
253
|
+
this.opts = {
|
|
254
|
+
...this.opts,
|
|
255
|
+
...e
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
this._store = this.opts.store ?? new Map;
|
|
259
|
+
this._compression = this.opts.compression;
|
|
260
|
+
this._serialize = this.opts.serialize;
|
|
261
|
+
this._deserialize = this.opts.deserialize;
|
|
262
|
+
if (this.opts.namespace) {
|
|
263
|
+
this._namespace = this.opts.namespace;
|
|
264
|
+
}
|
|
265
|
+
if (this._store) {
|
|
266
|
+
if (!this._isValidStorageAdapter(this._store)) {
|
|
267
|
+
throw new Error("Invalid storage adapter");
|
|
268
|
+
}
|
|
269
|
+
if (typeof this._store.on === "function") {
|
|
270
|
+
this._store.on("error", (e => this.emit("error", e)));
|
|
271
|
+
}
|
|
272
|
+
this._store.namespace = this._namespace;
|
|
273
|
+
if (typeof this._store[Symbol.iterator] === "function" && this._store instanceof Map) {
|
|
274
|
+
this.iterator = this.generateIterator(this._store);
|
|
275
|
+
} else if ("iterator" in this._store && this._store.opts && this._checkIterableAdapter()) {
|
|
276
|
+
this.iterator = this.generateIterator(this._store.iterator.bind(this._store));
|
|
208
277
|
}
|
|
209
278
|
}
|
|
210
|
-
this.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
279
|
+
if (this.opts.stats) {
|
|
280
|
+
this.stats.enabled = this.opts.stats;
|
|
281
|
+
}
|
|
282
|
+
if (this.opts.ttl) {
|
|
283
|
+
this._ttl = this.opts.ttl;
|
|
284
|
+
}
|
|
285
|
+
if (this.opts.useKeyPrefix !== void 0) {
|
|
286
|
+
this._useKeyPrefix = this.opts.useKeyPrefix;
|
|
287
|
+
}
|
|
215
288
|
}
|
|
216
|
-
|
|
217
|
-
this.
|
|
218
|
-
this.initClient();
|
|
289
|
+
get store() {
|
|
290
|
+
return this._store;
|
|
219
291
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
e
|
|
292
|
+
set store(e) {
|
|
293
|
+
if (this._isValidStorageAdapter(e)) {
|
|
294
|
+
this._store = e;
|
|
295
|
+
this.opts.store = e;
|
|
296
|
+
if (typeof e.on === "function") {
|
|
297
|
+
e.on("error", (e => this.emit("error", e)));
|
|
298
|
+
}
|
|
299
|
+
if (this._namespace) {
|
|
300
|
+
this._store.namespace = this._namespace;
|
|
226
301
|
}
|
|
302
|
+
if (typeof e[Symbol.iterator] === "function" && e instanceof Map) {
|
|
303
|
+
this.iterator = this.generateIterator(e);
|
|
304
|
+
} else if ("iterator" in e && e.opts && this._checkIterableAdapter()) {
|
|
305
|
+
this.iterator = this.generateIterator(e.iterator.bind(e));
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
throw new Error("Invalid storage adapter");
|
|
227
309
|
}
|
|
228
|
-
const t = {
|
|
229
|
-
namespace: this._namespace,
|
|
230
|
-
keyPrefixSeparator: this._keyPrefixSeparator,
|
|
231
|
-
clearBatchSize: this._clearBatchSize,
|
|
232
|
-
noNamespaceAffectsAll: this._noNamespaceAffectsAll,
|
|
233
|
-
useUnlink: this._useUnlink,
|
|
234
|
-
throwOnConnectError: this._throwOnConnectError,
|
|
235
|
-
throwErrors: this._throwErrors,
|
|
236
|
-
connectionTimeout: this._connectionTimeout,
|
|
237
|
-
dialect: "redis",
|
|
238
|
-
url: e
|
|
239
|
-
};
|
|
240
|
-
return t;
|
|
241
310
|
}
|
|
242
|
-
|
|
243
|
-
this.
|
|
311
|
+
get compression() {
|
|
312
|
+
return this._compression;
|
|
313
|
+
}
|
|
314
|
+
set compression(e) {
|
|
315
|
+
this._compression = e;
|
|
244
316
|
}
|
|
245
317
|
get namespace() {
|
|
246
318
|
return this._namespace;
|
|
247
319
|
}
|
|
248
320
|
set namespace(e) {
|
|
249
321
|
this._namespace = e;
|
|
322
|
+
this.opts.namespace = e;
|
|
323
|
+
this._store.namespace = e;
|
|
324
|
+
if (this.opts.store) {
|
|
325
|
+
this.opts.store.namespace = e;
|
|
326
|
+
}
|
|
250
327
|
}
|
|
251
|
-
get
|
|
252
|
-
return this.
|
|
328
|
+
get ttl() {
|
|
329
|
+
return this._ttl;
|
|
253
330
|
}
|
|
254
|
-
set
|
|
255
|
-
this.
|
|
331
|
+
set ttl(e) {
|
|
332
|
+
this.opts.ttl = e;
|
|
333
|
+
this._ttl = e;
|
|
256
334
|
}
|
|
257
|
-
get
|
|
258
|
-
return this.
|
|
335
|
+
get serialize() {
|
|
336
|
+
return this._serialize;
|
|
259
337
|
}
|
|
260
|
-
set
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
} else {
|
|
264
|
-
this.emit("error", "clearBatchSize must be greater than 0");
|
|
265
|
-
}
|
|
338
|
+
set serialize(e) {
|
|
339
|
+
this.opts.serialize = e;
|
|
340
|
+
this._serialize = e;
|
|
266
341
|
}
|
|
267
|
-
get
|
|
268
|
-
return this.
|
|
342
|
+
get deserialize() {
|
|
343
|
+
return this._deserialize;
|
|
269
344
|
}
|
|
270
|
-
set
|
|
271
|
-
this.
|
|
345
|
+
set deserialize(e) {
|
|
346
|
+
this.opts.deserialize = e;
|
|
347
|
+
this._deserialize = e;
|
|
272
348
|
}
|
|
273
|
-
get
|
|
274
|
-
return this.
|
|
349
|
+
get useKeyPrefix() {
|
|
350
|
+
return this._useKeyPrefix;
|
|
275
351
|
}
|
|
276
|
-
set
|
|
277
|
-
this.
|
|
352
|
+
set useKeyPrefix(e) {
|
|
353
|
+
this._useKeyPrefix = e;
|
|
354
|
+
this.opts.useKeyPrefix = e;
|
|
278
355
|
}
|
|
279
|
-
|
|
280
|
-
|
|
356
|
+
generateIterator(e) {
|
|
357
|
+
const t = async function*() {
|
|
358
|
+
for await (const [t, s] of typeof e === "function" ? e(this._store.namespace) : e) {
|
|
359
|
+
const e = await this.deserializeData(s);
|
|
360
|
+
if (this._useKeyPrefix && this._store.namespace && !t.includes(this._store.namespace)) {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (typeof e.expires === "number" && Date.now() > e.expires) {
|
|
364
|
+
this.delete(t);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
yield [ this._getKeyUnprefix(t), e.value ];
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
return t.bind(this);
|
|
281
371
|
}
|
|
282
|
-
|
|
283
|
-
this.
|
|
372
|
+
_checkIterableAdapter() {
|
|
373
|
+
return c.includes(this._store.opts.dialect) || c.some((e => this._store.opts.url.includes(e)));
|
|
284
374
|
}
|
|
285
|
-
|
|
286
|
-
|
|
375
|
+
_getKeyPrefix(e) {
|
|
376
|
+
if (!this._useKeyPrefix) {
|
|
377
|
+
return e;
|
|
378
|
+
}
|
|
379
|
+
if (!this._namespace) {
|
|
380
|
+
return e;
|
|
381
|
+
}
|
|
382
|
+
return `${this._namespace}:${e}`;
|
|
287
383
|
}
|
|
288
|
-
|
|
289
|
-
this.
|
|
384
|
+
_getKeyPrefixArray(e) {
|
|
385
|
+
if (!this._useKeyPrefix) {
|
|
386
|
+
return e;
|
|
387
|
+
}
|
|
388
|
+
if (!this._namespace) {
|
|
389
|
+
return e;
|
|
390
|
+
}
|
|
391
|
+
return e.map((e => `${this._namespace}:${e}`));
|
|
290
392
|
}
|
|
291
|
-
|
|
292
|
-
|
|
393
|
+
_getKeyUnprefix(e) {
|
|
394
|
+
if (!this._useKeyPrefix) {
|
|
395
|
+
return e;
|
|
396
|
+
}
|
|
397
|
+
return e.split(":").splice(1).join(":");
|
|
293
398
|
}
|
|
294
|
-
|
|
295
|
-
|
|
399
|
+
_isValidStorageAdapter(e) {
|
|
400
|
+
return e instanceof Map || typeof e.get === "function" && typeof e.set === "function" && typeof e.delete === "function" && typeof e.clear === "function";
|
|
296
401
|
}
|
|
297
|
-
async
|
|
298
|
-
|
|
299
|
-
|
|
402
|
+
async get(e, t) {
|
|
403
|
+
const {store: s} = this.opts;
|
|
404
|
+
const i = Array.isArray(e);
|
|
405
|
+
const r = i ? this._getKeyPrefixArray(e) : this._getKeyPrefix(e);
|
|
406
|
+
const o = e => typeof e.expires === "number" && Date.now() > e.expires;
|
|
407
|
+
if (i) {
|
|
408
|
+
if (t?.raw === true) {
|
|
409
|
+
return this.getMany(e, {
|
|
410
|
+
raw: true
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
return this.getMany(e, {
|
|
414
|
+
raw: false
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
this.hooks.trigger("preGet", {
|
|
418
|
+
key: r
|
|
419
|
+
});
|
|
420
|
+
const a = await s.get(r);
|
|
421
|
+
const n = typeof a === "string" || this.opts.compression ? await this.deserializeData(a) : a;
|
|
422
|
+
if (n === void 0 || n === null) {
|
|
423
|
+
this.stats.miss();
|
|
424
|
+
return void 0;
|
|
300
425
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
426
|
+
if (o(n)) {
|
|
427
|
+
await this.delete(e);
|
|
428
|
+
this.stats.miss();
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
this.hooks.trigger("postGet", {
|
|
432
|
+
key: r,
|
|
433
|
+
value: n
|
|
434
|
+
});
|
|
435
|
+
this.stats.hit();
|
|
436
|
+
return t?.raw ? n : n.value;
|
|
437
|
+
}
|
|
438
|
+
async getMany(e, t) {
|
|
439
|
+
const {store: s} = this.opts;
|
|
440
|
+
const i = this._getKeyPrefixArray(e);
|
|
441
|
+
const r = e => typeof e.expires === "number" && Date.now() > e.expires;
|
|
442
|
+
this.hooks.trigger("preGetMany", {
|
|
443
|
+
keys: i
|
|
444
|
+
});
|
|
445
|
+
if (s.getMany === void 0) {
|
|
446
|
+
const e = i.map((async e => {
|
|
447
|
+
const i = await s.get(e);
|
|
448
|
+
const o = typeof i === "string" || this.opts.compression ? await this.deserializeData(i) : i;
|
|
449
|
+
if (o === void 0 || o === null) {
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
if (r(o)) {
|
|
453
|
+
await this.delete(e);
|
|
454
|
+
return void 0;
|
|
455
|
+
}
|
|
456
|
+
return t?.raw ? o : o.value;
|
|
457
|
+
}));
|
|
458
|
+
const o = await Promise.allSettled(e);
|
|
459
|
+
const a = o.map((e => e.value));
|
|
460
|
+
this.hooks.trigger("postGetMany", a);
|
|
461
|
+
if (a.length > 0) {
|
|
462
|
+
this.stats.hit();
|
|
306
463
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
464
|
+
return a;
|
|
465
|
+
}
|
|
466
|
+
const o = await s.getMany(i);
|
|
467
|
+
const a = [];
|
|
468
|
+
for (const s in o) {
|
|
469
|
+
let i = o[s];
|
|
470
|
+
if (typeof i === "string") {
|
|
471
|
+
i = await this.deserializeData(i);
|
|
311
472
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return this._client;
|
|
316
|
-
}
|
|
317
|
-
async set(e, t, r) {
|
|
318
|
-
const s = await this.getClient();
|
|
319
|
-
try {
|
|
320
|
-
e = this.createKeyPrefix(e, this._namespace);
|
|
321
|
-
if (r) {
|
|
322
|
-
await s.set(e, t, {
|
|
323
|
-
PX: r
|
|
324
|
-
});
|
|
325
|
-
} else {
|
|
326
|
-
await s.set(e, t);
|
|
473
|
+
if (i === void 0 || i === null) {
|
|
474
|
+
a.push(void 0);
|
|
475
|
+
continue;
|
|
327
476
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
477
|
+
if (r(i)) {
|
|
478
|
+
await this.delete(e[s]);
|
|
479
|
+
a.push(void 0);
|
|
480
|
+
continue;
|
|
332
481
|
}
|
|
482
|
+
const n = t?.raw ? i : i.value;
|
|
483
|
+
a.push(n);
|
|
484
|
+
}
|
|
485
|
+
this.hooks.trigger("postGetMany", a);
|
|
486
|
+
if (a.length > 0) {
|
|
487
|
+
this.stats.hit();
|
|
333
488
|
}
|
|
489
|
+
return a;
|
|
334
490
|
}
|
|
335
|
-
async
|
|
336
|
-
const
|
|
491
|
+
async set(e, t, s) {
|
|
492
|
+
const i = {
|
|
493
|
+
key: e,
|
|
494
|
+
value: t,
|
|
495
|
+
ttl: s
|
|
496
|
+
};
|
|
497
|
+
this.hooks.trigger("preSet", i);
|
|
498
|
+
const r = this._getKeyPrefix(i.key);
|
|
499
|
+
i.ttl ??= this._ttl;
|
|
500
|
+
if (i.ttl === 0) {
|
|
501
|
+
i.ttl = void 0;
|
|
502
|
+
}
|
|
503
|
+
const {store: o} = this.opts;
|
|
504
|
+
const a = typeof i.ttl === "number" ? Date.now() + i.ttl : void 0;
|
|
505
|
+
if (typeof i.value === "symbol") {
|
|
506
|
+
this.emit("error", "symbol cannot be serialized");
|
|
507
|
+
throw new Error("symbol cannot be serialized");
|
|
508
|
+
}
|
|
509
|
+
const n = {
|
|
510
|
+
value: i.value,
|
|
511
|
+
expires: a
|
|
512
|
+
};
|
|
513
|
+
const h = await this.serializeData(n);
|
|
514
|
+
let l = true;
|
|
337
515
|
try {
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (i) {
|
|
342
|
-
r.set(e, s, {
|
|
343
|
-
PX: i
|
|
344
|
-
});
|
|
345
|
-
} else {
|
|
346
|
-
r.set(e, s);
|
|
347
|
-
}
|
|
516
|
+
const e = await o.set(r, h, i.ttl);
|
|
517
|
+
if (typeof e === "boolean") {
|
|
518
|
+
l = e;
|
|
348
519
|
}
|
|
349
|
-
await r.exec();
|
|
350
520
|
} catch (e) {
|
|
521
|
+
l = false;
|
|
351
522
|
this.emit("error", e);
|
|
352
|
-
if (this._throwErrors) {
|
|
353
|
-
throw e;
|
|
354
|
-
}
|
|
355
523
|
}
|
|
524
|
+
this.hooks.trigger("postSet", {
|
|
525
|
+
key: r,
|
|
526
|
+
value: h,
|
|
527
|
+
ttl: s
|
|
528
|
+
});
|
|
529
|
+
this.stats.set();
|
|
530
|
+
return l;
|
|
356
531
|
}
|
|
357
|
-
async
|
|
358
|
-
|
|
532
|
+
async setMany(e) {
|
|
533
|
+
let t = [];
|
|
359
534
|
try {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
535
|
+
if (this._store.setMany !== void 0) {
|
|
536
|
+
const s = await Promise.all(e.map((async ({key: e, value: t, ttl: s}) => {
|
|
537
|
+
s ??= this._ttl;
|
|
538
|
+
if (s === 0) {
|
|
539
|
+
s = void 0;
|
|
540
|
+
}
|
|
541
|
+
const i = typeof s === "number" ? Date.now() + s : void 0;
|
|
542
|
+
if (typeof t === "symbol") {
|
|
543
|
+
this.emit("error", "symbol cannot be serialized");
|
|
544
|
+
throw new Error("symbol cannot be serialized");
|
|
545
|
+
}
|
|
546
|
+
const r = {
|
|
547
|
+
value: t,
|
|
548
|
+
expires: i
|
|
549
|
+
};
|
|
550
|
+
const o = await this.serializeData(r);
|
|
551
|
+
return {
|
|
552
|
+
key: e,
|
|
553
|
+
value: o,
|
|
554
|
+
ttl: s
|
|
555
|
+
};
|
|
556
|
+
})));
|
|
557
|
+
t = await this._store.setMany(s);
|
|
367
558
|
}
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
async hasMany(e) {
|
|
372
|
-
const t = await this.getClient();
|
|
373
|
-
try {
|
|
374
|
-
const r = t.multi();
|
|
559
|
+
const s = [];
|
|
375
560
|
for (const t of e) {
|
|
376
|
-
|
|
377
|
-
r.exists(e);
|
|
378
|
-
}
|
|
379
|
-
const s = await r.exec();
|
|
380
|
-
return s.map((e => e === 1));
|
|
381
|
-
} catch (t) {
|
|
382
|
-
this.emit("error", t);
|
|
383
|
-
if (this._throwErrors) {
|
|
384
|
-
throw t;
|
|
561
|
+
s.push(this.set(t.key, t.value, t.ttl));
|
|
385
562
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
563
|
+
const i = await Promise.allSettled(s);
|
|
564
|
+
t = i.map((e => e.value));
|
|
565
|
+
} catch (s) {
|
|
566
|
+
this.emit("error", s);
|
|
567
|
+
t = e.map((() => false));
|
|
389
568
|
}
|
|
569
|
+
return t;
|
|
390
570
|
}
|
|
391
|
-
async
|
|
392
|
-
const t =
|
|
571
|
+
async delete(e) {
|
|
572
|
+
const {store: t} = this.opts;
|
|
573
|
+
if (Array.isArray(e)) {
|
|
574
|
+
return this.deleteMany(e);
|
|
575
|
+
}
|
|
576
|
+
const s = this._getKeyPrefix(e);
|
|
577
|
+
this.hooks.trigger("preDelete", {
|
|
578
|
+
key: s
|
|
579
|
+
});
|
|
580
|
+
let i = true;
|
|
393
581
|
try {
|
|
394
|
-
e =
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return void 0;
|
|
582
|
+
const e = await t.delete(s);
|
|
583
|
+
if (typeof e === "boolean") {
|
|
584
|
+
i = e;
|
|
398
585
|
}
|
|
399
|
-
return r;
|
|
400
586
|
} catch (e) {
|
|
587
|
+
i = false;
|
|
401
588
|
this.emit("error", e);
|
|
402
|
-
if (this._throwErrors) {
|
|
403
|
-
throw e;
|
|
404
|
-
}
|
|
405
|
-
return void 0;
|
|
406
589
|
}
|
|
590
|
+
this.hooks.trigger("postDelete", {
|
|
591
|
+
key: s,
|
|
592
|
+
value: i
|
|
593
|
+
});
|
|
594
|
+
this.stats.delete();
|
|
595
|
+
return i;
|
|
407
596
|
}
|
|
408
|
-
async
|
|
409
|
-
if (e.length === 0) {
|
|
410
|
-
return [];
|
|
411
|
-
}
|
|
412
|
-
e = e.map((e => this.createKeyPrefix(e, this._namespace)));
|
|
597
|
+
async deleteMany(e) {
|
|
413
598
|
try {
|
|
414
|
-
const t =
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
599
|
+
const {store: t} = this.opts;
|
|
600
|
+
const s = this._getKeyPrefixArray(e);
|
|
601
|
+
this.hooks.trigger("preDelete", {
|
|
602
|
+
key: s
|
|
603
|
+
});
|
|
604
|
+
if (t.deleteMany !== void 0) {
|
|
605
|
+
return await t.deleteMany(s);
|
|
420
606
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
e = this.createKeyPrefix(e, this._namespace);
|
|
430
|
-
let r = 0;
|
|
431
|
-
r = await (this._useUnlink ? t.unlink(e) : t.del(e));
|
|
432
|
-
return r > 0;
|
|
607
|
+
const i = s.map((async e => t.delete(e)));
|
|
608
|
+
const r = await Promise.allSettled(i);
|
|
609
|
+
const o = r.every((e => e.value === true));
|
|
610
|
+
this.hooks.trigger("postDelete", {
|
|
611
|
+
key: s,
|
|
612
|
+
value: o
|
|
613
|
+
});
|
|
614
|
+
return o;
|
|
433
615
|
} catch (e) {
|
|
434
616
|
this.emit("error", e);
|
|
435
|
-
if (this._throwErrors) {
|
|
436
|
-
throw e;
|
|
437
|
-
}
|
|
438
617
|
return false;
|
|
439
618
|
}
|
|
440
619
|
}
|
|
441
|
-
async
|
|
442
|
-
|
|
443
|
-
const
|
|
620
|
+
async clear() {
|
|
621
|
+
this.emit("clear");
|
|
622
|
+
const {store: e} = this.opts;
|
|
444
623
|
try {
|
|
445
|
-
|
|
446
|
-
for (const t of e) {
|
|
447
|
-
const e = this.createKeyPrefix(t, this._namespace);
|
|
448
|
-
if (this._useUnlink) {
|
|
449
|
-
s.unlink(e);
|
|
450
|
-
} else {
|
|
451
|
-
s.del(e);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
const i = await s.exec();
|
|
455
|
-
for (const e of i) {
|
|
456
|
-
if (typeof e === "number" && e > 0) {
|
|
457
|
-
t = true;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
624
|
+
await e.clear();
|
|
460
625
|
} catch (e) {
|
|
461
626
|
this.emit("error", e);
|
|
462
|
-
if (this._throwErrors) {
|
|
463
|
-
throw e;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
return t;
|
|
467
|
-
}
|
|
468
|
-
async disconnect(e) {
|
|
469
|
-
if (this._client.isOpen) {
|
|
470
|
-
await (e ? this._client.disconnect() : this._client.quit());
|
|
471
627
|
}
|
|
472
628
|
}
|
|
473
|
-
|
|
474
|
-
if (
|
|
475
|
-
return
|
|
629
|
+
async has(e) {
|
|
630
|
+
if (Array.isArray(e)) {
|
|
631
|
+
return this.hasMany(e);
|
|
476
632
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
return e.replace(`${t}${this._keyPrefixSeparator}`, "");
|
|
633
|
+
const t = this._getKeyPrefix(e);
|
|
634
|
+
const {store: s} = this.opts;
|
|
635
|
+
if (s.has !== void 0 && !(s instanceof Map)) {
|
|
636
|
+
return s.has(t);
|
|
482
637
|
}
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
isCluster() {
|
|
486
|
-
return this.isClientCluster(this._client);
|
|
487
|
-
}
|
|
488
|
-
async getMasterNodes() {
|
|
489
|
-
if (this.isCluster()) {
|
|
490
|
-
const e = await this.getClient();
|
|
491
|
-
return Promise.all(e.masters.map((async t => e.nodeClient(t))));
|
|
492
|
-
}
|
|
493
|
-
return [ await this.getClient() ];
|
|
494
|
-
}
|
|
495
|
-
async* iterator(e) {
|
|
496
|
-
const t = await this.getMasterNodes();
|
|
497
|
-
for (const r of t) {
|
|
498
|
-
const t = e ? `${e}${this._keyPrefixSeparator}*` : "*";
|
|
499
|
-
let s = "0";
|
|
500
|
-
do {
|
|
501
|
-
const i = await r.scan(Number.parseInt(s, 10), {
|
|
502
|
-
MATCH: t,
|
|
503
|
-
TYPE: "string"
|
|
504
|
-
});
|
|
505
|
-
s = i.cursor.toString();
|
|
506
|
-
let {keys: n} = i;
|
|
507
|
-
if (!e && !this._noNamespaceAffectsAll) {
|
|
508
|
-
n = n.filter((e => !e.includes(this._keyPrefixSeparator)));
|
|
509
|
-
}
|
|
510
|
-
if (n.length > 0) {
|
|
511
|
-
const t = await this.mget(n);
|
|
512
|
-
for (const r of n.keys()) {
|
|
513
|
-
const s = this.getKeyWithoutPrefix(n[r], e);
|
|
514
|
-
const i = t[r];
|
|
515
|
-
yield [ s, i ];
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
} while (s !== "0");
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
async clear() {
|
|
638
|
+
let i;
|
|
522
639
|
try {
|
|
523
|
-
|
|
524
|
-
await Promise.all(e.map((async e => {
|
|
525
|
-
if (!this._namespace && this._noNamespaceAffectsAll) {
|
|
526
|
-
await e.flushDb();
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
let t = "0";
|
|
530
|
-
const r = this._clearBatchSize;
|
|
531
|
-
const s = this._namespace ? `${this._namespace}${this._keyPrefixSeparator}*` : "*";
|
|
532
|
-
const i = [];
|
|
533
|
-
do {
|
|
534
|
-
const n = await e.scan(Number.parseInt(t, 10), {
|
|
535
|
-
MATCH: s,
|
|
536
|
-
COUNT: r,
|
|
537
|
-
TYPE: "string"
|
|
538
|
-
});
|
|
539
|
-
t = n.cursor.toString();
|
|
540
|
-
let {keys: o} = n;
|
|
541
|
-
if (o.length === 0) {
|
|
542
|
-
continue;
|
|
543
|
-
}
|
|
544
|
-
if (!this._namespace) {
|
|
545
|
-
o = o.filter((e => !e.includes(this._keyPrefixSeparator)));
|
|
546
|
-
}
|
|
547
|
-
i.push(this.clearWithClusterSupport(o));
|
|
548
|
-
} while (t !== "0");
|
|
549
|
-
await Promise.all(i);
|
|
550
|
-
})));
|
|
640
|
+
i = await s.get(t);
|
|
551
641
|
} catch (e) {
|
|
552
642
|
this.emit("error", e);
|
|
553
643
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
for (const [e, s] of i.entries()) {
|
|
562
|
-
r.set(t[e], s ?? void 0);
|
|
644
|
+
if (i) {
|
|
645
|
+
const e = await this.deserializeData(i);
|
|
646
|
+
if (e) {
|
|
647
|
+
if (e.expires === void 0 || e.expires === null) {
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
return e.expires > Date.now();
|
|
563
651
|
}
|
|
564
|
-
})));
|
|
565
|
-
return e.map((e => r.get(e)));
|
|
566
|
-
}
|
|
567
|
-
async clearWithClusterSupport(e) {
|
|
568
|
-
if (e.length > 0) {
|
|
569
|
-
const t = this.getSlotMap(e);
|
|
570
|
-
await Promise.all(Array.from(t.entries(), (async ([e, t]) => {
|
|
571
|
-
const r = await this.getSlotMaster(e);
|
|
572
|
-
return this._useUnlink ? r.unlink(t) : r.del(t);
|
|
573
|
-
})));
|
|
574
652
|
}
|
|
653
|
+
return false;
|
|
575
654
|
}
|
|
576
|
-
async
|
|
577
|
-
const t =
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
return r.nodeClient(s);
|
|
655
|
+
async hasMany(e) {
|
|
656
|
+
const t = this._getKeyPrefixArray(e);
|
|
657
|
+
const {store: s} = this.opts;
|
|
658
|
+
if (s.hasMany !== void 0) {
|
|
659
|
+
return s.hasMany(t);
|
|
582
660
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
const t = new Map;
|
|
587
|
-
if (this.isCluster()) {
|
|
588
|
-
for (const r of e) {
|
|
589
|
-
const e = i.default(r);
|
|
590
|
-
const s = t.get(e) ?? [];
|
|
591
|
-
s.push(r);
|
|
592
|
-
t.set(e, s);
|
|
593
|
-
}
|
|
594
|
-
} else {
|
|
595
|
-
t.set(0, e);
|
|
661
|
+
const i = [];
|
|
662
|
+
for (const e of t) {
|
|
663
|
+
i.push(await this.has(e));
|
|
596
664
|
}
|
|
597
|
-
return
|
|
665
|
+
return i;
|
|
598
666
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
667
|
+
async disconnect() {
|
|
668
|
+
const {store: e} = this.opts;
|
|
669
|
+
this.emit("disconnect");
|
|
670
|
+
if (typeof e.disconnect === "function") {
|
|
671
|
+
return e.disconnect();
|
|
602
672
|
}
|
|
603
|
-
return false;
|
|
604
673
|
}
|
|
605
|
-
|
|
606
|
-
if (!
|
|
674
|
+
emit(e, ...t) {
|
|
675
|
+
if (e === "error" && !this.opts.emitErrors) {
|
|
607
676
|
return;
|
|
608
677
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
if (
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
if (e.clearBatchSize !== void 0 && e.clearBatchSize > 0) {
|
|
616
|
-
this._clearBatchSize = e.clearBatchSize;
|
|
617
|
-
}
|
|
618
|
-
if (e.useUnlink !== void 0) {
|
|
619
|
-
this._useUnlink = e.useUnlink;
|
|
678
|
+
super.emit(e, ...t);
|
|
679
|
+
}
|
|
680
|
+
async serializeData(e) {
|
|
681
|
+
if (!this._serialize) {
|
|
682
|
+
return e;
|
|
620
683
|
}
|
|
621
|
-
if (
|
|
622
|
-
this.
|
|
684
|
+
if (this._compression?.compress) {
|
|
685
|
+
return this._serialize({
|
|
686
|
+
value: await this._compression.compress(e.value),
|
|
687
|
+
expires: e.expires
|
|
688
|
+
});
|
|
623
689
|
}
|
|
624
|
-
|
|
625
|
-
|
|
690
|
+
return this._serialize(e);
|
|
691
|
+
}
|
|
692
|
+
async deserializeData(e) {
|
|
693
|
+
if (!this._deserialize) {
|
|
694
|
+
return e;
|
|
626
695
|
}
|
|
627
|
-
if (
|
|
628
|
-
|
|
696
|
+
if (this._compression?.decompress && typeof e === "string") {
|
|
697
|
+
const t = await this._deserialize(e);
|
|
698
|
+
return {
|
|
699
|
+
value: await this._compression.decompress(t?.value),
|
|
700
|
+
expires: t?.expires
|
|
701
|
+
};
|
|
629
702
|
}
|
|
630
|
-
if (e
|
|
631
|
-
this.
|
|
703
|
+
if (typeof e === "string") {
|
|
704
|
+
return this._deserialize(e);
|
|
632
705
|
}
|
|
633
|
-
|
|
634
|
-
initClient() {
|
|
635
|
-
this._client.on("connect", (() => {
|
|
636
|
-
this.emit("connect", this._client);
|
|
637
|
-
}));
|
|
638
|
-
this._client.on("disconnect", (() => {
|
|
639
|
-
this.emit("disconnect", this._client);
|
|
640
|
-
}));
|
|
641
|
-
this._client.on("reconnecting", (e => {
|
|
642
|
-
this.emit("reconnecting", e);
|
|
643
|
-
}));
|
|
644
|
-
}
|
|
645
|
-
async createTimeoutPromise(e) {
|
|
646
|
-
return new Promise(((t, r) => setTimeout((() => {
|
|
647
|
-
r(new Error(`Redis timed out after ${e}ms`));
|
|
648
|
-
}), e)));
|
|
706
|
+
return void 0;
|
|
649
707
|
}
|
|
650
708
|
};
|
|
651
709
|
|
|
652
|
-
|
|
653
|
-
e ??= "redis://localhost:6379";
|
|
654
|
-
const s = new h(e, r);
|
|
655
|
-
const i = new t.Keyv(s, {
|
|
656
|
-
namespace: r?.namespace,
|
|
657
|
-
useKeyPrefix: false
|
|
658
|
-
});
|
|
659
|
-
return i;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
Object.defineProperty(exports, "createClient", {
|
|
663
|
-
enumerable: true,
|
|
664
|
-
get: () => e.createClient
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
Object.defineProperty(exports, "createCluster", {
|
|
668
|
-
enumerable: true,
|
|
669
|
-
get: () => e.createCluster
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
exports.Keyv = t.Keyv;
|
|
673
|
-
|
|
674
|
-
exports.RedisErrorMessages = a;
|
|
710
|
+
var p = f;
|
|
675
711
|
|
|
676
|
-
exports.
|
|
712
|
+
exports.Keyv = f;
|
|
677
713
|
|
|
678
|
-
exports.
|
|
714
|
+
exports.defaultDeserialize = s;
|
|
679
715
|
|
|
680
|
-
exports.
|
|
716
|
+
exports.index_default = p;
|