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.
Files changed (213) hide show
  1. package/com/cacher.cjs +1 -1
  2. package/com/cacher.d.ts +4 -4
  3. package/com/cacher.mjs +1 -1
  4. package/com/database.cjs +0 -2
  5. package/com/database.d.ts +4 -4
  6. package/com/database.mjs +0 -2
  7. package/com/docker.d.ts +5 -5
  8. package/com/entrypoint.cjs +3 -1
  9. package/com/entrypoint.d.ts +2 -2
  10. package/com/entrypoint.mjs +3 -1
  11. package/com/logger.d.ts +1 -1
  12. package/com/monitor.d.ts +2 -2
  13. package/decorator/asst.d.ts +1 -1
  14. package/decorator/ctrl.cjs +3 -1
  15. package/decorator/ctrl.d.ts +4 -4
  16. package/decorator/ctrl.mjs +3 -1
  17. package/decorator/di.d.ts +3 -3
  18. package/decorator/dto.d.ts +3 -3
  19. package/decorator/orm.cjs +86 -88
  20. package/decorator/orm.d.ts +51 -75
  21. package/decorator/orm.mjs +44 -46
  22. package/helper.cjs +24 -18
  23. package/helper.d.ts +129 -3
  24. package/helper.mjs +6 -2
  25. package/lakutata.cjs +3 -1
  26. package/lakutata.d.ts +10 -10
  27. package/lakutata.mjs +3 -1
  28. package/orm.cjs +1075 -112
  29. package/orm.d.ts +6 -6
  30. package/orm.mjs +1015 -17
  31. package/package.json +1 -1
  32. package/provider/database.cjs +0 -2
  33. package/provider/database.d.ts +4 -4
  34. package/provider/database.mjs +0 -2
  35. package/provider/passwordHash.d.ts +1 -1
  36. package/src/components/Database.cjs +0 -2
  37. package/src/components/Database.mjs +0 -2
  38. package/src/components/cacher/Cacher.cjs +1 -1
  39. package/src/components/cacher/Cacher.mjs +1 -1
  40. package/src/components/cacher/adapters/CreateFileCacheAdapter.cjs +1 -1
  41. package/src/components/cacher/adapters/CreateFileCacheAdapter.mjs +1 -1
  42. package/src/components/cacher/adapters/CreateMemcacheCacheAdapter.cjs +2 -2
  43. package/src/components/cacher/adapters/CreateMemcacheCacheAdapter.mjs +2 -2
  44. package/src/components/cacher/adapters/CreateMongoCacheAdapter.cjs +2 -2
  45. package/src/components/cacher/adapters/CreateMongoCacheAdapter.mjs +2 -2
  46. package/src/components/cacher/adapters/CreateMysqlCacheAdapter.cjs +2 -2
  47. package/src/components/cacher/adapters/CreateMysqlCacheAdapter.mjs +2 -2
  48. package/src/components/cacher/adapters/CreatePostgresCacheAdapter.cjs +2 -2
  49. package/src/components/cacher/adapters/CreatePostgresCacheAdapter.mjs +2 -2
  50. package/src/components/cacher/adapters/CreateRedisCacheAdapter.cjs +2 -2
  51. package/src/components/cacher/adapters/CreateRedisCacheAdapter.mjs +2 -2
  52. package/src/components/cacher/adapters/CreateSqliteCacheAdapter.cjs +2 -2
  53. package/src/components/cacher/adapters/CreateSqliteCacheAdapter.mjs +2 -2
  54. package/src/components/entrypoint/Entrypoint.cjs +3 -1
  55. package/src/components/entrypoint/Entrypoint.mjs +3 -1
  56. package/src/decorators/ctrl/CLIAction.cjs +7 -5
  57. package/src/decorators/ctrl/CLIAction.mjs +3 -1
  58. package/src/decorators/ctrl/HTTPAction.cjs +8 -6
  59. package/src/decorators/ctrl/HTTPAction.mjs +3 -1
  60. package/src/decorators/ctrl/ServiceAction.cjs +3 -1
  61. package/src/decorators/ctrl/ServiceAction.mjs +7 -5
  62. package/src/decorators/ctrl/http/DELETE.cjs +3 -1
  63. package/src/decorators/ctrl/http/DELETE.mjs +3 -1
  64. package/src/decorators/ctrl/http/GET.cjs +3 -1
  65. package/src/decorators/ctrl/http/GET.mjs +3 -1
  66. package/src/decorators/ctrl/http/HEAD.cjs +3 -1
  67. package/src/decorators/ctrl/http/HEAD.mjs +3 -1
  68. package/src/decorators/ctrl/http/OPTIONS.cjs +3 -1
  69. package/src/decorators/ctrl/http/OPTIONS.mjs +3 -1
  70. package/src/decorators/ctrl/http/PATCH.cjs +3 -1
  71. package/src/decorators/ctrl/http/PATCH.mjs +3 -1
  72. package/src/decorators/ctrl/http/POST.cjs +3 -1
  73. package/src/decorators/ctrl/http/POST.mjs +3 -1
  74. package/src/decorators/ctrl/http/PUT.cjs +3 -1
  75. package/src/decorators/ctrl/http/PUT.mjs +3 -1
  76. package/src/decorators/orm/AfterInsert.cjs +27 -7
  77. package/src/decorators/orm/AfterInsert.mjs +28 -6
  78. package/src/decorators/orm/AfterLoad.cjs +27 -7
  79. package/src/decorators/orm/AfterLoad.mjs +28 -6
  80. package/src/decorators/orm/AfterRecover.cjs +27 -7
  81. package/src/decorators/orm/AfterRecover.mjs +28 -6
  82. package/src/decorators/orm/AfterRemove.cjs +27 -7
  83. package/src/decorators/orm/AfterRemove.mjs +28 -6
  84. package/src/decorators/orm/AfterSoftRemove.cjs +27 -7
  85. package/src/decorators/orm/AfterSoftRemove.mjs +28 -6
  86. package/src/decorators/orm/AfterUpdate.cjs +27 -7
  87. package/src/decorators/orm/AfterUpdate.mjs +28 -6
  88. package/src/decorators/orm/BeforeInsert.cjs +27 -7
  89. package/src/decorators/orm/BeforeInsert.mjs +28 -6
  90. package/src/decorators/orm/BeforeRecover.cjs +27 -7
  91. package/src/decorators/orm/BeforeRecover.mjs +28 -6
  92. package/src/decorators/orm/BeforeRemove.cjs +27 -7
  93. package/src/decorators/orm/BeforeRemove.mjs +28 -6
  94. package/src/decorators/orm/BeforeSoftRemove.cjs +27 -7
  95. package/src/decorators/orm/BeforeSoftRemove.mjs +28 -6
  96. package/src/decorators/orm/BeforeUpdate.cjs +27 -7
  97. package/src/decorators/orm/BeforeUpdate.mjs +28 -6
  98. package/src/decorators/orm/Check.cjs +30 -7
  99. package/src/decorators/orm/Check.mjs +31 -6
  100. package/src/decorators/orm/ChildEntity.cjs +30 -7
  101. package/src/decorators/orm/ChildEntity.mjs +31 -6
  102. package/src/decorators/orm/Column.cjs +62 -7
  103. package/src/decorators/orm/Column.mjs +63 -6
  104. package/src/decorators/orm/CreateDateColumn.cjs +26 -7
  105. package/src/decorators/orm/CreateDateColumn.mjs +27 -6
  106. package/src/decorators/orm/DeleteDateColumn.cjs +26 -7
  107. package/src/decorators/orm/DeleteDateColumn.mjs +27 -6
  108. package/src/decorators/orm/Entity.cjs +36 -7
  109. package/src/decorators/orm/Entity.mjs +37 -6
  110. package/src/decorators/orm/EventSubscriber.cjs +23 -7
  111. package/src/decorators/orm/EventSubscriber.mjs +24 -6
  112. package/src/decorators/orm/Exclusion.cjs +30 -7
  113. package/src/decorators/orm/Exclusion.mjs +31 -6
  114. package/src/decorators/orm/Generated.cjs +25 -7
  115. package/src/decorators/orm/Generated.mjs +26 -6
  116. package/src/decorators/orm/Index.cjs +42 -7
  117. package/src/decorators/orm/Index.mjs +43 -6
  118. package/src/decorators/orm/JoinColumn.cjs +30 -7
  119. package/src/decorators/orm/JoinColumn.mjs +31 -6
  120. package/src/decorators/orm/JoinTable.cjs +31 -7
  121. package/src/decorators/orm/JoinTable.mjs +32 -6
  122. package/src/decorators/orm/ManyToMany.cjs +43 -7
  123. package/src/decorators/orm/ManyToMany.mjs +44 -6
  124. package/src/decorators/orm/ManyToOne.cjs +43 -7
  125. package/src/decorators/orm/ManyToOne.mjs +44 -6
  126. package/src/decorators/orm/ObjectIdColumn.cjs +29 -7
  127. package/src/decorators/orm/ObjectIdColumn.mjs +30 -6
  128. package/src/decorators/orm/OneToMany.cjs +35 -7
  129. package/src/decorators/orm/OneToMany.mjs +36 -6
  130. package/src/decorators/orm/OneToOne.cjs +43 -7
  131. package/src/decorators/orm/OneToOne.mjs +44 -6
  132. package/src/decorators/orm/PrimaryColumn.cjs +50 -7
  133. package/src/decorators/orm/PrimaryColumn.mjs +51 -6
  134. package/src/decorators/orm/PrimaryGeneratedColumn.cjs +55 -7
  135. package/src/decorators/orm/PrimaryGeneratedColumn.mjs +56 -6
  136. package/src/decorators/orm/RelationId.cjs +27 -7
  137. package/src/decorators/orm/RelationId.mjs +28 -6
  138. package/src/decorators/orm/TableInheritance.cjs +27 -7
  139. package/src/decorators/orm/TableInheritance.mjs +28 -6
  140. package/src/decorators/orm/Tree.cjs +25 -7
  141. package/src/decorators/orm/Tree.mjs +26 -6
  142. package/src/decorators/orm/TreeChildren.cjs +32 -7
  143. package/src/decorators/orm/TreeChildren.mjs +33 -6
  144. package/src/decorators/orm/TreeLevelColumn.cjs +26 -7
  145. package/src/decorators/orm/TreeLevelColumn.mjs +27 -6
  146. package/src/decorators/orm/TreeParent.cjs +32 -7
  147. package/src/decorators/orm/TreeParent.mjs +33 -6
  148. package/src/decorators/orm/Unique.cjs +45 -7
  149. package/src/decorators/orm/Unique.mjs +46 -6
  150. package/src/decorators/orm/UpdateDateColumn.cjs +26 -7
  151. package/src/decorators/orm/UpdateDateColumn.mjs +27 -6
  152. package/src/decorators/orm/VersionColumn.cjs +26 -7
  153. package/src/decorators/orm/VersionColumn.mjs +27 -6
  154. package/src/decorators/orm/ViewColumn.cjs +26 -7
  155. package/src/decorators/orm/ViewColumn.mjs +27 -6
  156. package/src/decorators/orm/ViewEntity.cjs +35 -7
  157. package/src/decorators/orm/ViewEntity.mjs +36 -6
  158. package/src/decorators/orm/VirtualColumn.cjs +43 -7
  159. package/src/decorators/orm/VirtualColumn.mjs +44 -6
  160. package/src/lib/base/internal/ControllerEntrypoint.cjs +70 -610
  161. package/src/lib/base/internal/ControllerEntrypoint.mjs +87 -627
  162. package/src/lib/base/internal/StringifyPattern.cjs +1 -1
  163. package/src/lib/base/internal/StringifyPattern.mjs +1 -1
  164. package/src/lib/core/Application.cjs +3 -1
  165. package/src/lib/core/Application.mjs +3 -1
  166. package/src/lib/helpers/MD5.cjs +1 -1
  167. package/src/lib/helpers/MD5.mjs +1 -1
  168. package/src/lib/helpers/SHA1.cjs +1 -1
  169. package/src/lib/helpers/SHA1.mjs +1 -1
  170. package/src/lib/helpers/SHA256.cjs +1 -1
  171. package/src/lib/helpers/SHA256.mjs +1 -1
  172. package/src/lib/helpers/SortArray.cjs +1 -1
  173. package/src/lib/helpers/SortArray.mjs +1 -1
  174. package/src/lib/helpers/UUID.cjs +45 -0
  175. package/src/lib/helpers/UUID.mjs +39 -0
  176. package/src/providers/Database.cjs +0 -2
  177. package/src/providers/Database.mjs +0 -2
  178. package/vendor/Package.122.cjs +13223 -16706
  179. package/vendor/Package.122.mjs +13498 -16881
  180. package/vendor/Package.19.cjs +184 -195
  181. package/vendor/Package.19.mjs +176 -187
  182. package/vendor/Package.610.cjs +297 -113
  183. package/vendor/Package.610.mjs +285 -97
  184. package/vendor/Package.611.cjs +85 -103
  185. package/vendor/Package.611.mjs +80 -98
  186. package/vendor/Package.612.cjs +100 -121
  187. package/vendor/Package.612.mjs +97 -120
  188. package/vendor/Package.613.cjs +196 -0
  189. package/vendor/Package.613.mjs +180 -0
  190. package/vendor/Package.64.cjs +511 -134
  191. package/vendor/Package.64.mjs +491 -134
  192. package/vendor/Package.65.cjs +140 -4118
  193. package/vendor/Package.65.mjs +140 -4126
  194. package/vendor/Package.66.cjs +4142 -692
  195. package/vendor/Package.66.mjs +4151 -689
  196. package/vendor/Package.67.cjs +571 -535
  197. package/vendor/Package.67.mjs +586 -528
  198. package/vendor/Package.68.cjs +633 -96
  199. package/vendor/Package.68.mjs +619 -94
  200. package/vendor/Package.69.cjs +96 -294
  201. package/vendor/Package.69.mjs +95 -295
  202. package/vendor/TypeDef.internal.1.d.ts +1 -1
  203. package/vendor/TypeDef.internal.10.d.ts +1 -1
  204. package/vendor/TypeDef.internal.11.d.ts +2 -2
  205. package/vendor/TypeDef.internal.12.d.ts +2 -2
  206. package/vendor/TypeDef.internal.13.d.ts +6 -6
  207. package/vendor/TypeDef.internal.3.d.ts +3 -3
  208. package/vendor/TypeDef.internal.4.d.ts +181 -347
  209. package/vendor/TypeDef.internal.5.d.ts +2 -2
  210. package/vendor/TypeDef.internal.6.d.ts +2 -2
  211. package/vendor/TypeDef.internal.7.d.ts +1 -1
  212. package/vendor/TypeDef.internal.8.d.ts +1 -1
  213. package/vendor/TypeDef.internal.9.d.ts +1 -1
@@ -4,154 +4,338 @@ Object.defineProperty(exports, Symbol.toStringTag, {
4
4
  value: "Module"
5
5
  });
6
6
 
7
- const t = require("events");
7
+ const e = require("events");
8
8
 
9
- const e = require("util");
9
+ const t = require("buffer");
10
10
 
11
- const s = require("./Package.66.cjs");
11
+ const n = require("mongodb");
12
12
 
13
- const i = require("sqlite3");
14
-
15
- require("buffer");
16
-
17
- const a = t => t && t.__esModule ? t : {
18
- default: t
13
+ const s = e => e && e.__esModule ? e : {
14
+ default: e
19
15
  };
20
16
 
21
- const n = a(t);
17
+ const o = s(e);
22
18
 
23
- const r = a(i);
19
+ var a = new Set([ "url", "collection", "namespace", "serialize", "deserialize", "uri", "useGridFS", "dialect", "db" ]);
24
20
 
25
- var o = t => String(t).search(/^[a-zA-Z]+$/) < 0 ? "_" + t : t;
26
-
27
- var c = class extends n.default {
28
- ttlSupport;
21
+ var i = class extends o.default {
22
+ ttlSupport=false;
29
23
  opts;
24
+ connect;
30
25
  namespace;
31
- close;
32
- query;
33
- constructor(t) {
26
+ constructor(e, t) {
34
27
  super();
35
- this.ttlSupport = false;
36
- let s = {
37
- dialect: "sqlite",
38
- uri: "sqlite://:memory:"
39
- };
40
- if (typeof t === "string") {
41
- s.uri = t;
42
- } else {
43
- s = {
44
- ...s,
45
- ...t
28
+ e ??= {};
29
+ if (typeof e === "string") {
30
+ e = {
31
+ url: e
46
32
  };
47
33
  }
48
- s.db = s.uri.replace(/^sqlite:\/\//, "");
49
- s.connect = async () => new Promise(((t, e) => {
50
- const i = new r.default.Database(s.db, (a => {
51
- if (a) {
52
- e(a);
34
+ if (e.uri) {
35
+ e = {
36
+ url: e.uri,
37
+ ...e
38
+ };
39
+ }
40
+ this.opts = {
41
+ url: "mongodb://127.0.0.1:27017",
42
+ collection: "keyv",
43
+ ...e,
44
+ ...t
45
+ };
46
+ delete this.opts.emitErrors;
47
+ const s = Object.fromEntries(Object.entries(this.opts).filter((([e]) => !a.has(e))));
48
+ this.opts = Object.fromEntries(Object.entries(this.opts).filter((([e]) => a.has(e))));
49
+ this.connect = new Promise((async (e, t) => {
50
+ try {
51
+ let t = "";
52
+ if (this.opts.url) {
53
+ t = this.opts.url;
54
+ }
55
+ const o = new n.MongoClient(t, s);
56
+ await o.connect();
57
+ const a = o.db(this.opts.db);
58
+ if (this.opts.useGridFS) {
59
+ const t = new n.GridFSBucket(a, {
60
+ readPreference: this.opts.readPreference,
61
+ bucketName: this.opts.collection
62
+ });
63
+ const s = a.collection(`${this.opts.collection}.files`);
64
+ await s.createIndex({
65
+ uploadDate: -1
66
+ });
67
+ await s.createIndex({
68
+ "metadata.expiresAt": 1
69
+ });
70
+ await s.createIndex({
71
+ "metadata.lastAccessed": 1
72
+ });
73
+ await s.createIndex({
74
+ "metadata.filename": 1
75
+ });
76
+ e({
77
+ bucket: t,
78
+ store: s,
79
+ db: a,
80
+ mongoClient: o
81
+ });
53
82
  } else {
54
- if (s.busyTimeout) {
55
- i.configure("busyTimeout", s.busyTimeout);
83
+ let t = "keyv";
84
+ if (this.opts.collection) {
85
+ t = this.opts.collection;
56
86
  }
57
- t(i);
87
+ const n = a.collection(t);
88
+ await n.createIndex({
89
+ key: 1
90
+ }, {
91
+ unique: true,
92
+ background: true
93
+ });
94
+ await n.createIndex({
95
+ expiresAt: 1
96
+ }, {
97
+ expireAfterSeconds: 0,
98
+ background: true
99
+ });
100
+ e({
101
+ store: n,
102
+ mongoClient: o
103
+ });
58
104
  }
59
- }));
60
- })).then((t => ({
61
- query: e.promisify(t.all).bind(t),
62
- close: e.promisify(t.close).bind(t)
63
- })));
64
- this.opts = {
65
- table: "keyv",
66
- keySize: 255,
67
- ...s
68
- };
69
- this.opts.table = o(this.opts.table);
70
- const i = `CREATE TABLE IF NOT EXISTS ${this.opts.table}(key VARCHAR(${Number(this.opts.keySize)}) PRIMARY KEY, value TEXT )`;
71
- const a = this.opts.connect().then((async t => t.query(i).then((() => t)))).catch((t => this.emit("error", t)));
72
- this.query = async (t, ...e) => a.then((async s => s.query(t, ...e)));
73
- this.close = async () => a.then((t => t.close()));
105
+ } catch (e) {
106
+ this.emit("error", e);
107
+ }
108
+ }));
74
109
  }
75
- async get(t) {
76
- const e = `SELECT * FROM ${this.opts.table} WHERE key = ?`;
77
- const s = await this.query(e, t);
78
- const i = s[0];
79
- if (i === void 0) {
110
+ async get(e) {
111
+ const n = await this.connect;
112
+ if (this.opts.useGridFS) {
113
+ await n.store.updateOne({
114
+ filename: e
115
+ }, {
116
+ $set: {
117
+ "metadata.lastAccessed": new Date
118
+ }
119
+ });
120
+ const s = n.bucket.openDownloadStreamByName(e);
121
+ return new Promise((e => {
122
+ const n = [];
123
+ s.on("error", (() => {
124
+ e(void 0);
125
+ }));
126
+ s.on("end", (() => {
127
+ const s = t.Buffer.concat(n).toString("utf8");
128
+ e(s);
129
+ }));
130
+ s.on("data", (e => {
131
+ n.push(e);
132
+ }));
133
+ }));
134
+ }
135
+ const s = await n.store.findOne({
136
+ key: {
137
+ $eq: e
138
+ }
139
+ });
140
+ if (!s) {
80
141
  return void 0;
81
142
  }
82
- return i.value;
143
+ return s.value;
83
144
  }
84
- async getMany(t) {
85
- const e = `SELECT * FROM ${this.opts.table} WHERE key IN (SELECT value FROM json_each(?))`;
86
- const s = await this.query(e, JSON.stringify(t));
87
- return t.map((t => {
88
- const e = s.find((e => e.key === t));
89
- return e ? e.value : void 0;
90
- }));
145
+ async getMany(e) {
146
+ if (this.opts.useGridFS) {
147
+ const t = [];
148
+ for (const n of e) {
149
+ t.push(this.get(n));
150
+ }
151
+ const n = await Promise.allSettled(t);
152
+ const s = [];
153
+ for (const e of n) {
154
+ s.push(e.value);
155
+ }
156
+ return s;
157
+ }
158
+ const t = await this.connect;
159
+ const n = await t.store.s.db.collection(this.opts.collection).find({
160
+ key: {
161
+ $in: e
162
+ }
163
+ }).project({
164
+ _id: 0,
165
+ value: 1,
166
+ key: 1
167
+ }).toArray();
168
+ const s = [ ...e ];
169
+ let o = 0;
170
+ for (const t of e) {
171
+ const e = n.findIndex((e => e.key === t));
172
+ s[o] = e > -1 ? n[e].value : void 0;
173
+ o++;
174
+ }
175
+ return s;
91
176
  }
92
- async set(t, e) {
93
- const s = `INSERT INTO ${this.opts.table} (key, value)\n\t\t\tVALUES(?, ?) \n\t\t\tON CONFLICT(key) \n\t\t\tDO UPDATE SET value=excluded.value;`;
94
- return this.query(s, t, e);
177
+ async set(e, t, n) {
178
+ const s = typeof n === "number" ? new Date(Date.now() + n) : null;
179
+ if (this.opts.useGridFS) {
180
+ const n = await this.connect;
181
+ const o = n.bucket.openUploadStream(e, {
182
+ metadata: {
183
+ expiresAt: s,
184
+ lastAccessed: new Date
185
+ }
186
+ });
187
+ return new Promise((e => {
188
+ o.on("finish", (() => {
189
+ e(o);
190
+ }));
191
+ o.end(t);
192
+ }));
193
+ }
194
+ const o = await this.connect;
195
+ await o.store.updateOne({
196
+ key: {
197
+ $eq: e
198
+ }
199
+ }, {
200
+ $set: {
201
+ key: e,
202
+ value: t,
203
+ expiresAt: s
204
+ }
205
+ }, {
206
+ upsert: true
207
+ });
95
208
  }
96
- async delete(t) {
97
- const e = `SELECT * FROM ${this.opts.table} WHERE key = ?`;
98
- const s = `DELETE FROM ${this.opts.table} WHERE key = ?`;
99
- const i = await this.query(e, t);
100
- const a = i[0];
101
- if (a === void 0) {
209
+ async delete(e) {
210
+ if (typeof e !== "string") {
102
211
  return false;
103
212
  }
104
- await this.query(s, t);
105
- return true;
213
+ const t = await this.connect;
214
+ if (this.opts.useGridFS) {
215
+ try {
216
+ const s = t.db;
217
+ const o = new n.GridFSBucket(s, {
218
+ bucketName: this.opts.collection
219
+ });
220
+ const a = await o.find({
221
+ filename: e
222
+ }).toArray();
223
+ await t.bucket.delete(a[0]._id);
224
+ return true;
225
+ } catch {
226
+ return false;
227
+ }
228
+ }
229
+ const s = await t.store.deleteOne({
230
+ key: {
231
+ $eq: e
232
+ }
233
+ });
234
+ return s.deletedCount > 0;
106
235
  }
107
- async deleteMany(t) {
108
- const e = `DELETE FROM ${this.opts.table} WHERE key IN (SELECT value FROM json_each(?))`;
109
- const s = await this.getMany(t);
110
- if (s.every((t => t === void 0))) {
111
- return false;
236
+ async deleteMany(e) {
237
+ const t = await this.connect;
238
+ if (this.opts.useGridFS) {
239
+ const s = t.db;
240
+ const o = new n.GridFSBucket(s, {
241
+ bucketName: this.opts.collection
242
+ });
243
+ const a = await o.find({
244
+ filename: {
245
+ $in: e
246
+ }
247
+ }).toArray();
248
+ if (a.length === 0) {
249
+ return false;
250
+ }
251
+ await Promise.all(a.map((async e => t.bucket.delete(e._id))));
252
+ return true;
112
253
  }
113
- await this.query(e, JSON.stringify(t));
114
- return true;
254
+ const s = await t.store.deleteMany({
255
+ key: {
256
+ $in: e
257
+ }
258
+ });
259
+ return s.deletedCount > 0;
115
260
  }
116
261
  async clear() {
117
- const t = `DELETE FROM ${this.opts.table} WHERE key LIKE ?`;
118
- await this.query(t, this.namespace ? `${this.namespace}:%` : "%");
119
- }
120
- async* iterator(t) {
121
- const e = Number.parseInt(this.opts.iterationLimit, 10) || 10;
122
- async function* s(i, a, n) {
123
- const r = `SELECT * FROM ${a.table} WHERE key LIKE ? LIMIT ? OFFSET ?`;
124
- const o = await n(r, [ `${t ? t + ":" : ""}%`, e, i ]);
125
- const c = [ ...o ];
126
- if (c.length === 0) {
127
- return;
262
+ const e = await this.connect;
263
+ if (this.opts.useGridFS) {
264
+ try {
265
+ await e.bucket.drop();
266
+ } catch (e) {
267
+ if (!(e instanceof n.MongoServerError && e.code === 26)) {
268
+ throw e;
269
+ }
128
270
  }
129
- for (const t of c) {
130
- i += 1;
131
- yield [ t.key, t.value ];
271
+ }
272
+ await e.store.deleteMany({
273
+ key: {
274
+ $regex: this.namespace ? `^${this.namespace}:*` : ""
132
275
  }
133
- yield* s(i, a, n);
276
+ });
277
+ }
278
+ async clearExpired() {
279
+ if (!this.opts.useGridFS) {
280
+ return false;
134
281
  }
135
- yield* s(0, this.opts, this.query);
282
+ return this.connect.then((async e => {
283
+ const t = e.db;
284
+ const s = new n.GridFSBucket(t, {
285
+ bucketName: this.opts.collection
286
+ });
287
+ return s.find({
288
+ "metadata.expiresAt": {
289
+ $lte: new Date(Date.now())
290
+ }
291
+ }).toArray().then((async t => Promise.all(t.map((async t => e.bucket.delete(t._id)))).then((() => true))));
292
+ }));
293
+ }
294
+ async clearUnusedFor(e) {
295
+ if (!this.opts.useGridFS) {
296
+ return false;
297
+ }
298
+ const t = await this.connect;
299
+ const s = t.db;
300
+ const o = new n.GridFSBucket(s, {
301
+ bucketName: this.opts.collection
302
+ });
303
+ const a = await o.find({
304
+ "metadata.lastAccessed": {
305
+ $lte: new Date(Date.now() - e * 1e3)
306
+ }
307
+ }).toArray();
308
+ await Promise.all(a.map((async e => t.bucket.delete(e._id))));
309
+ return true;
310
+ }
311
+ async* iterator(e) {
312
+ const t = await this.connect;
313
+ const n = new RegExp(`^${e ? e + ":" : ".*"}`);
314
+ const s = this.opts.useGridFS ? t.store.find({
315
+ filename: n
316
+ }).map((async e => [ e.filename, await this.get(e.filename) ])) : t.store.find({
317
+ key: n
318
+ }).map((e => [ e.key, e.value ]));
319
+ yield* s;
136
320
  }
137
- async has(t) {
138
- const e = `SELECT EXISTS ( SELECT * FROM ${this.opts.table} WHERE key = ? )`;
139
- const s = await this.query(e, t);
140
- return Object.values(s[0])[0] === 1;
321
+ async has(e) {
322
+ const t = await this.connect;
323
+ const n = {
324
+ [this.opts.useGridFS ? "filename" : "key"]: {
325
+ $eq: e
326
+ }
327
+ };
328
+ const s = await t.store.count(n);
329
+ return s !== 0;
141
330
  }
142
331
  async disconnect() {
143
- await this.close();
332
+ const e = await this.connect;
333
+ await e.mongoClient.close();
144
334
  }
145
335
  };
146
336
 
147
- var u = t => new s.index_default({
148
- store: new c(t)
149
- });
150
-
151
- var l = c;
152
-
153
- exports.KeyvSqlite = c;
337
+ var c = i;
154
338
 
155
- exports.createKeyv = u;
339
+ exports.KeyvMongo = i;
156
340
 
157
- exports.default = l;
341
+ exports.default = c;