@kotori-bot/core 1.5.1 → 1.6.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.
Files changed (79) hide show
  1. package/README.md +10 -4
  2. package/lib/app/config.d.ts +32 -0
  3. package/lib/app/config.js +65 -0
  4. package/lib/app/core.d.ts +138 -0
  5. package/lib/{components → app}/core.js +24 -10
  6. package/lib/app/index.d.ts +1 -0
  7. package/lib/{service → app}/index.js +7 -13
  8. package/lib/{components → app}/message.d.ts +11 -10
  9. package/lib/app/message.js +253 -0
  10. package/lib/components/adapter.d.ts +122 -0
  11. package/lib/components/adapter.js +75 -0
  12. package/lib/components/api.d.ts +417 -0
  13. package/lib/components/api.js +546 -0
  14. package/lib/components/cache.d.ts +37 -0
  15. package/lib/{service → components}/cache.js +27 -6
  16. package/lib/components/command.d.ts +153 -0
  17. package/lib/{utils → components}/command.js +154 -48
  18. package/lib/components/elements.d.ts +144 -0
  19. package/lib/components/elements.js +179 -0
  20. package/lib/components/filter.d.ts +22 -0
  21. package/lib/components/filter.js +130 -0
  22. package/lib/components/index.d.ts +8 -2
  23. package/lib/components/index.js +19 -7
  24. package/lib/components/messages.d.ts +186 -0
  25. package/lib/components/messages.js +218 -0
  26. package/lib/components/session.d.ts +177 -0
  27. package/lib/components/session.js +275 -0
  28. package/lib/decorators/index.d.ts +7 -0
  29. package/lib/{components/config.js → decorators/index.js} +23 -39
  30. package/lib/decorators/plugin.d.ts +7 -0
  31. package/lib/{utils/commandError.js → decorators/plugin.js} +16 -16
  32. package/lib/decorators/utils.d.ts +59 -0
  33. package/lib/decorators/utils.js +189 -0
  34. package/lib/global/constants.d.ts +1 -8
  35. package/lib/global/constants.js +6 -25
  36. package/lib/global/index.js +3 -3
  37. package/lib/global/symbols.d.ts +13 -8
  38. package/lib/global/symbols.js +18 -12
  39. package/lib/index.d.ts +4 -4
  40. package/lib/index.js +10 -11
  41. package/lib/types/adapter.d.ts +1 -1
  42. package/lib/types/adapter.js +3 -3
  43. package/lib/types/api.d.ts +72 -0
  44. package/lib/{utils/jsxFactory.js → types/api.js} +5 -5
  45. package/lib/types/command.d.ts +78 -0
  46. package/lib/types/command.js +50 -0
  47. package/lib/types/config.d.ts +4 -6
  48. package/lib/types/config.js +3 -3
  49. package/lib/types/filter.d.ts +51 -0
  50. package/lib/types/filter.js +87 -0
  51. package/lib/types/index.d.ts +4 -0
  52. package/lib/types/index.js +12 -4
  53. package/lib/types/message.d.ts +128 -193
  54. package/lib/types/message.js +12 -31
  55. package/lib/types/session.d.ts +349 -0
  56. package/lib/types/session.js +27 -0
  57. package/lib/utils/container.d.ts +6 -6
  58. package/lib/utils/container.js +12 -16
  59. package/lib/utils/error.d.ts +46 -22
  60. package/lib/utils/error.js +38 -21
  61. package/lib/utils/factory.d.ts +10 -16
  62. package/lib/utils/factory.js +41 -101
  63. package/lib/utils/internal.d.ts +46 -0
  64. package/lib/utils/internal.js +102 -0
  65. package/package.json +10 -7
  66. package/lib/components/config.d.ts +0 -16
  67. package/lib/components/core.d.ts +0 -34
  68. package/lib/components/message.js +0 -195
  69. package/lib/service/adapter.d.ts +0 -41
  70. package/lib/service/adapter.js +0 -131
  71. package/lib/service/api.d.ts +0 -32
  72. package/lib/service/api.js +0 -80
  73. package/lib/service/cache.d.ts +0 -13
  74. package/lib/service/elements.d.ts +0 -12
  75. package/lib/service/elements.js +0 -73
  76. package/lib/service/index.d.ts +0 -4
  77. package/lib/utils/command.d.ts +0 -51
  78. package/lib/utils/commandError.d.ts +0 -7
  79. package/lib/utils/jsxFactory.d.ts +0 -6
@@ -0,0 +1,546 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/core
4
+ * @Version 1.6.0-rc.1
5
+ * @Author Arimura Sena <me@hotaru.icu>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/8/9 17:33:05
10
+ */
11
+
12
+ "use strict";
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var api_exports = {};
31
+ __export(api_exports, {
32
+ Api: () => Api,
33
+ default: () => api_default
34
+ });
35
+ module.exports = __toCommonJS(api_exports);
36
+ var import_tools = require("@kotori-bot/tools");
37
+ class Api {
38
+ /**
39
+ * Get supported actions for current api implementation.
40
+ *
41
+ * @returns Supported actions
42
+ */
43
+ getSupportedActions() {
44
+ return Object.getOwnPropertyNames(Api.prototype).filter(
45
+ (key) => typeof key === "string" && !["getSupportedActions", "adapter", "constructor"].includes(key) && this[key] instanceof Function && this[key] !== Api.prototype[key]
46
+ );
47
+ }
48
+ /**
49
+ * Current api's bot instance.
50
+ *
51
+ * @readonly
52
+ */
53
+ // biome-ignore lint:
54
+ adapter;
55
+ /**
56
+ * Api class constructor.
57
+ *
58
+ * @param adapter - Current api's bot instance
59
+ */
60
+ // biome-ignore lint:
61
+ constructor(adapter) {
62
+ this.adapter = adapter;
63
+ }
64
+ /**
65
+ * Send a private message.
66
+ *
67
+ * @param message - Message content to send
68
+ * @param userId - Target user id
69
+ * @param meta - Extra meta data, optional
70
+ * @returns Message id and send time
71
+ *
72
+ * @async
73
+ */
74
+ async sendPrivateMsg(message, userId, meta = {}) {
75
+ (0, import_tools.none)(this, message, userId, meta);
76
+ return { messageId: "", time: 0 };
77
+ }
78
+ /**
79
+ * Send a group message.
80
+ *
81
+ * @param message - Message content to send
82
+ * @param groupId - Target group id
83
+ * @param meta - Extra meta data, optional
84
+ * @returns Message id and send time
85
+ *
86
+ * @async
87
+ */
88
+ async sendGroupMsg(message, groupId, meta = {}) {
89
+ (0, import_tools.none)(this, message, groupId, meta, meta);
90
+ return { messageId: "", time: 0 };
91
+ }
92
+ /**
93
+ * Send a channel message.
94
+ *
95
+ * @param message - Message content to send
96
+ * @param guildId - Target guild id
97
+ * @param channelId - Target channel id
98
+ * @param meta - Extra meta data, optional
99
+ * @returns Message id and send time
100
+ *
101
+ * @async
102
+ */
103
+ async sendChannelMsg(message, guildId, channelId, meta = {}) {
104
+ (0, import_tools.none)(this, message, guildId, channelId, meta);
105
+ return { messageId: "", time: 0 };
106
+ }
107
+ /**
108
+ * Delete a message.
109
+ *
110
+ * Required target message that is sent by self or bot had manger permission.
111
+ *
112
+ * @param messageId - Target message id
113
+ * @param meta - Extra meta data, optional
114
+ *
115
+ * @async
116
+ */
117
+ deleteMsg(messageId, meta = {}) {
118
+ (0, import_tools.none)(this, messageId, meta);
119
+ }
120
+ /**
121
+ * Get information about the bot itself.
122
+ *
123
+ * @returns Self info
124
+ *
125
+ * @async
126
+ */
127
+ async getSelfInfo(meta = {}) {
128
+ (0, import_tools.none)(this, meta);
129
+ return { userId: "", username: "", userDisplayname: "" };
130
+ }
131
+ /**
132
+ * Get user information.
133
+ *
134
+ * @param userId - Target user id, can be the friend or the stronger
135
+ * @param meta - Extra meta data, optional
136
+ * @returns User info
137
+ *
138
+ * @async
139
+ */
140
+ async getUserInfo(userId, meta = {}) {
141
+ (0, import_tools.none)(this, userId, meta);
142
+ return { userId: "", username: "", userDisplayname: "", userRemark: "" };
143
+ }
144
+ /**
145
+ * Get friend list.
146
+ *
147
+ * @param meta - Extra meta data, optional
148
+ * @returns Friend list information
149
+ *
150
+ * @async
151
+ */
152
+ async getFriendList(meta = {}) {
153
+ (0, import_tools.none)(this, meta);
154
+ return [];
155
+ }
156
+ /**
157
+ * Get group information.
158
+ *
159
+ * @param groupId - Target group id
160
+ * @param meta - Extra meta data, optional
161
+ * @returns Group info
162
+ *
163
+ * @async
164
+ */
165
+ async getGroupInfo(groupId, meta = {}) {
166
+ (0, import_tools.none)(this, groupId, meta);
167
+ return { groupId: "", groupName: "" };
168
+ }
169
+ /**
170
+ * Get group list.
171
+ *
172
+ * @param meta - Extra meta data, optional
173
+ * @returns Group list information
174
+ *
175
+ * @async
176
+ */
177
+ async getGroupList(meta = {}) {
178
+ (0, import_tools.none)(this, meta);
179
+ return [];
180
+ }
181
+ /**
182
+ * Get group member information.
183
+ *
184
+ * @param groupId - Target group id
185
+ * @param userId - Target user id
186
+ * @param meta - Extra meta data, optional
187
+ * @returns Group member info
188
+ *
189
+ * @async
190
+ */
191
+ async getGroupMemberInfo(groupId, userId, meta = {}) {
192
+ (0, import_tools.none)(this, groupId, userId, meta);
193
+ return { userId: "", username: "", userDisplayname: "" };
194
+ }
195
+ /**
196
+ * Get group member list.
197
+ *
198
+ * @param groupId - Target group id
199
+ * @param meta - Extra meta data, optional
200
+ * @returns Group member list information
201
+ *
202
+ * @async
203
+ */
204
+ async getGroupMemberList(groupId, meta = {}) {
205
+ (0, import_tools.none)(this, groupId, meta);
206
+ return [];
207
+ }
208
+ /**
209
+ * Set group information.
210
+ *
211
+ * @param groupId - Target group id
212
+ * @param groupName - Group name
213
+ * @param meta - Extra meta data, optional
214
+ */
215
+ setGroupName(groupId, groupName, meta = {}) {
216
+ (0, import_tools.none)(this, groupId, groupName, meta);
217
+ }
218
+ /**
219
+ * Leave a group, if bot is owner so it will be destroy the group.
220
+ *
221
+ * @param groupId - Target group id
222
+ * @param meta - Extra meta data, optional
223
+ */
224
+ leaveGroup(groupId, meta = {}) {
225
+ (0, import_tools.none)(this, groupId, meta);
226
+ }
227
+ /**
228
+ * Get guild information.
229
+ *
230
+ * @param guildId - Target guild id
231
+ * @param meta - Extra meta data, optional
232
+ * @returns Guild info
233
+ *
234
+ * @async
235
+ */
236
+ async getGuildInfo(guildId, meta = {}) {
237
+ (0, import_tools.none)(this, guildId, meta);
238
+ return { guildId: "", guildName: "" };
239
+ }
240
+ /**
241
+ * Get guild list.
242
+ *
243
+ * @param meta - Extra meta data, optional
244
+ * @returns Guild list information
245
+ *
246
+ * @async
247
+ */
248
+ async getGuildList(meta = {}) {
249
+ (0, import_tools.none)(this, meta);
250
+ return [];
251
+ }
252
+ /**
253
+ * Set guild information.
254
+ *
255
+ * @param guildId - Target guild id
256
+ * @param guildName - Guild name
257
+ * @param meta - Extra meta data, optional
258
+ */
259
+ setGuildName(guildId, guildName, meta = {}) {
260
+ (0, import_tools.none)(this, guildId, guildName, meta);
261
+ }
262
+ /**
263
+ * Get guild member information.
264
+ *
265
+ * @param guildId - Target guild id
266
+ * @param channelId - Target channel id
267
+ * @param userId - Target user id
268
+ * @param meta - Extra meta data, optional
269
+ * @returns Guild member info
270
+ *
271
+ * @async
272
+ */
273
+ async getGuildMemberInfo(guildId, userId, meta = {}) {
274
+ (0, import_tools.none)(this, guildId, userId, meta);
275
+ return { userId: "", username: "", userDisplayname: "", userRemark: "" };
276
+ }
277
+ /**
278
+ * Get guild member list.
279
+ *
280
+ * @param guildId - Target guild id
281
+ * @param channelId - Target channel id
282
+ * @param meta - Extra meta data, optional
283
+ * @returns Guild member list information
284
+ *
285
+ * @async
286
+ */
287
+ async getGuildMemberList(guildId, meta = {}) {
288
+ (0, import_tools.none)(this, guildId, meta);
289
+ return [];
290
+ }
291
+ /**
292
+ * Leave a guild.
293
+ *
294
+ * @param guildId - Target guild id
295
+ * @param meta - Extra meta data, optional
296
+ */
297
+ leaveGuild(guildId, meta = {}) {
298
+ (0, import_tools.none)(this, guildId, meta);
299
+ }
300
+ /**
301
+ * Get channel information.
302
+ *
303
+ * @param guildId - Target guild id
304
+ * @param channelId - Target channel id
305
+ * @param meta - Extra meta data, optional
306
+ * @returns Channel info
307
+ *
308
+ * @async
309
+ */
310
+ async getChannelInfo(guildId, channelId, meta = {}) {
311
+ (0, import_tools.none)(this, guildId, channelId, meta);
312
+ return { channelId: "", channelName: "" };
313
+ }
314
+ /**
315
+ * Get channel list.
316
+ *
317
+ * @param guildId - Target guild id
318
+ * @param joinedOnly - Whether to get joined channels only, default is false
319
+ * @param meta - Extra meta data, optional
320
+ * @returns Channel list information
321
+ *
322
+ * @async
323
+ */
324
+ async getChannelList(guildId, joinedOnly = false, meta = {}) {
325
+ (0, import_tools.none)(this, guildId, joinedOnly, meta);
326
+ return [];
327
+ }
328
+ /**
329
+ * Set channel information.
330
+ *
331
+ * @param guildId - Target guild id
332
+ * @param channelId - Target channel id
333
+ * @param channelName - Channel name
334
+ * @param meta - Extra meta data, optional
335
+ */
336
+ setChannelName(guildId, channelId, channelName, meta = {}) {
337
+ (0, import_tools.none)(this, guildId, channelId, channelName, meta);
338
+ }
339
+ /**
340
+ * Get channel member information.
341
+ *
342
+ * @param guildId - Target guild id
343
+ * @param channelId - Target channel id
344
+ * @param userId - Target user id
345
+ * @param meta - Extra meta data, optional
346
+ * @returns Channel member info
347
+ *
348
+ * @async
349
+ */
350
+ async getChannelMemberInfo(guildId, channelId, userId, meta = {}) {
351
+ (0, import_tools.none)(this, guildId, channelId, userId, meta);
352
+ return { userId: "", username: "", userDisplayname: "", userRemark: "" };
353
+ }
354
+ /**
355
+ * Get channel member list.
356
+ *
357
+ * @param guildId - Target guild id
358
+ * @param channelId - Target channel id
359
+ * @param meta - Extra meta data, optional
360
+ * @returns Channel member list information
361
+ *
362
+ * @async
363
+ */
364
+ async getChannelMemberList(guildId, channelId, meta = {}) {
365
+ (0, import_tools.none)(this, guildId, channelId, meta);
366
+ return [];
367
+ }
368
+ /**
369
+ * Leave a channel.
370
+ *
371
+ * @param guildId - Target guild id
372
+ * @param channelId - Target channel id
373
+ * @param meta - Extra meta data, optional
374
+ */
375
+ leaveChannel(guildId, channelId, meta = {}) {
376
+ (0, import_tools.none)(this, guildId, channelId, meta);
377
+ }
378
+ /**
379
+ * Upload file from url.
380
+ *
381
+ * @param name - File name
382
+ * @param url - File url
383
+ * @param headers - File download url headers, optional
384
+ * @param meta - Extra meta data, optional
385
+ * @returns File id
386
+ *
387
+ * @async
388
+ */
389
+ async uploadFileUrl(name, url, headers = {}, meta = {}) {
390
+ (0, import_tools.none)(this, name, url, headers, meta);
391
+ return { filedId: "" };
392
+ }
393
+ /**
394
+ * Upload file from path.
395
+ *
396
+ * @param name - File name
397
+ * @param path - File path
398
+ * @param meta - Extra meta data, optional
399
+ * @returns File id
400
+ *
401
+ * @async
402
+ */
403
+ async uploadFilePath(name, path, meta = {}) {
404
+ (0, import_tools.none)(this, name, path, meta);
405
+ return { filedId: "" };
406
+ }
407
+ /**
408
+ * Upload file from data.
409
+ *
410
+ * @param name - File name
411
+ * @param data - File data
412
+ * @param meta - Extra meta data, optional
413
+ * @returns File id
414
+ *
415
+ * @async
416
+ */
417
+ async uploadFileData(name, data, meta = {}) {
418
+ (0, import_tools.none)(this, name, data, meta);
419
+ return { filedId: "" };
420
+ }
421
+ /**
422
+ * Get file url.
423
+ *
424
+ * @param filedId - File id
425
+ * @param meta - Extra meta data, optional
426
+ * @returns File url data
427
+ *
428
+ * @async
429
+ */
430
+ async getFileUrl(filedId, meta = {}) {
431
+ (0, import_tools.none)(this, filedId, meta);
432
+ return { name: "", sha256: "", url: "", headers: {} };
433
+ }
434
+ /**
435
+ * Get file path.
436
+ *
437
+ * @param filedId - File id
438
+ * @param meta - Extra meta data, optional
439
+ * @returns File path data
440
+ *
441
+ * @async
442
+ */
443
+ async getFilePath(filedId, meta = {}) {
444
+ (0, import_tools.none)(this, filedId, meta);
445
+ return { name: "", sha256: "", path: "" };
446
+ }
447
+ /**
448
+ * Get file data.
449
+ *
450
+ * @param filedId - File id
451
+ * @param meta - Extra meta data, optional
452
+ * @returns File data
453
+ *
454
+ * @async
455
+ */
456
+ async getFileData(filedId, meta = {}) {
457
+ (0, import_tools.none)(this, filedId, meta);
458
+ return { name: "", sha256: "", data: Buffer.from("") };
459
+ }
460
+ /**
461
+ * Set group avatar.
462
+ *
463
+ * @param groupId - Target group id
464
+ * @param groupName - Group name
465
+ * @param meta - Extra meta data, optional
466
+ *
467
+ * @experimental
468
+ */
469
+ setGroupAvatar(groupId, image, meta = {}) {
470
+ (0, import_tools.none)(this, groupId, image, meta);
471
+ }
472
+ /**
473
+ * Set group admin.
474
+ *
475
+ * @param groupId - Target group id
476
+ * @param groupName - Group name
477
+ * @param meta - Extra meta data, optional
478
+ *
479
+ * @experimental
480
+ */
481
+ setGroupAdmin(groupId, userId, enable, meta = {}) {
482
+ (0, import_tools.none)(this, groupId, userId, enable, meta);
483
+ }
484
+ /**
485
+ * Set group card.
486
+ *
487
+ * @param groupId - Target group id
488
+ * @param groupName - Group name
489
+ * @param meta - Extra meta data, optional
490
+ *
491
+ * @experimental
492
+ */
493
+ setGroupCard(groupId, userId, card, meta = {}) {
494
+ (0, import_tools.none)(this, groupId, userId, card, meta);
495
+ }
496
+ /**
497
+ * Set group members ban or unban.
498
+ *
499
+ * @param groupId - Target group id
500
+ * @param groupName - Group name
501
+ * @param meta - Extra meta data, optional
502
+ *
503
+ * @experimental
504
+ */
505
+ setGroupBan(groupId, userId, time, meta = {}) {
506
+ (0, import_tools.none)(this, groupId, userId, time, meta);
507
+ }
508
+ /**
509
+ * Set group new notice.
510
+ *
511
+ * @param groupId - Target group id
512
+ * @param groupName - Group name
513
+ * @param meta - Extra meta data, optional
514
+ *
515
+ * @experimental
516
+ */
517
+ sendGroupNotice(groupId, content, image, meta = {}) {
518
+ (0, import_tools.none)(this, groupId, content, image, meta);
519
+ }
520
+ /**
521
+ * Set group whole ban
522
+ *
523
+ * @param groupId - Target group id
524
+ * @param enable - Whether to ban
525
+ */
526
+ setGroupWholeBan(groupId, enable = true) {
527
+ this.adapter.send("set_group_whole_ban", { group_id: Number(groupId), enable });
528
+ }
529
+ /**
530
+ * Set group members kicked.
531
+ *
532
+ * @param groupId - Target group id
533
+ * @param groupName - Group name
534
+ * @param meta - Extra meta data, optional
535
+ *
536
+ * @experimental
537
+ */
538
+ setGroupKick(groupId, userId, meta = {}) {
539
+ (0, import_tools.none)(this, groupId, userId, meta);
540
+ }
541
+ }
542
+ var api_default = Api;
543
+ // Annotate the CommonJS export names for ESM import in node:
544
+ 0 && (module.exports = {
545
+ Api
546
+ });
@@ -0,0 +1,37 @@
1
+ import { Service } from 'fluoro';
2
+ type CacheKey = string | symbol | number;
3
+ type CacheValue = string | number | object;
4
+ type Container = Map<CacheKey, CacheValue>;
5
+ /**
6
+ * Cache service
7
+ *
8
+ * @class
9
+ * @extends Service
10
+ */
11
+ export declare class Cache extends Service {
12
+ private cache?;
13
+ constructor(ctx: ConstructorParameters<typeof Service>[0]);
14
+ start(): void;
15
+ stop(): void;
16
+ /**
17
+ * Get the container of current content instance.
18
+ *
19
+ * @returns THe container
20
+ */
21
+ getContainer(): Container;
22
+ /**
23
+ * Get the value from current the container.
24
+ *
25
+ * @param prop The property name
26
+ * @returns The value
27
+ */
28
+ get<T = CacheValue>(prop: CacheKey): T;
29
+ /**
30
+ * Set the value to current the container.
31
+ *
32
+ * @param prop The property name
33
+ * @param value The value
34
+ */
35
+ set(prop: CacheKey, value: CacheValue): void;
36
+ }
37
+ export default Cache;
@@ -1,12 +1,12 @@
1
1
 
2
2
  /**
3
3
  * @Package @kotori-bot/core
4
- * @Version 1.5.0
5
- * @Author Hotaru <biyuehuya@gmail.com>
4
+ * @Version 1.6.0-rc.1
5
+ * @Author Arimura Sena <me@hotaru.icu>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 11:22:22
9
+ * @Date 2024/8/9 17:33:05
10
10
  */
11
11
 
12
12
  "use strict";
@@ -34,8 +34,9 @@ __export(cache_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(cache_exports);
36
36
  var import_fluoro = require("fluoro");
37
+ var import_error = require("../utils/error");
37
38
  class Cache extends import_fluoro.Service {
38
- cache;
39
+ cache = /* @__PURE__ */ new Map();
39
40
  constructor(ctx) {
40
41
  super(ctx, {}, "cache");
41
42
  }
@@ -44,18 +45,38 @@ class Cache extends import_fluoro.Service {
44
45
  this.cache = /* @__PURE__ */ new Map();
45
46
  }
46
47
  stop() {
47
- this.cache?.forEach((el) => el.clear());
48
- this.cache?.clear();
48
+ if (this.cache) {
49
+ for (const el of this.cache.values()) el.clear();
50
+ this.cache.clear();
51
+ }
49
52
  delete this.cache;
50
53
  }
54
+ /**
55
+ * Get the container of current content instance.
56
+ *
57
+ * @returns THe container
58
+ */
51
59
  getContainer() {
60
+ if (!this.cache) throw new import_error.KotoriError("Cache service is not started.", "cache");
52
61
  const key = this.ctx.identity ?? "root";
53
62
  if (!this.cache.has(key)) this.cache.set(key, /* @__PURE__ */ new Map());
54
63
  return this.cache.get(key);
55
64
  }
65
+ /**
66
+ * Get the value from current the container.
67
+ *
68
+ * @param prop The property name
69
+ * @returns The value
70
+ */
56
71
  get(prop) {
57
72
  return this.getContainer().get(prop);
58
73
  }
74
+ /**
75
+ * Set the value to current the container.
76
+ *
77
+ * @param prop The property name
78
+ * @param value The value
79
+ */
59
80
  set(prop, value) {
60
81
  this.getContainer().set(prop, value);
61
82
  }