monsqlize 1.3.0 → 2.0.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 (172) hide show
  1. package/CHANGELOG.md +56 -60
  2. package/LICENSE +201 -21
  3. package/README.md +537 -1828
  4. package/changelogs/README.md +160 -0
  5. package/changelogs/v2.0.0.md +222 -0
  6. package/dist/cjs/index.cjs +10600 -0
  7. package/dist/cjs/mongodb/common/transaction-aware.cjs +10 -0
  8. package/dist/cjs/transaction/CacheLockManager.cjs +100 -0
  9. package/dist/cjs/transaction/Transaction.cjs +158 -0
  10. package/dist/cjs/transaction/TransactionManager.cjs +298 -0
  11. package/dist/esm/index.mjs +10650 -0
  12. package/dist/types/base.d.ts +81 -0
  13. package/dist/types/collection.d.ts +1031 -0
  14. package/dist/types/expression.d.ts +115 -0
  15. package/dist/types/index.d.ts +23 -0
  16. package/dist/types/lock.d.ts +74 -0
  17. package/dist/types/model.d.ts +526 -0
  18. package/dist/types/mongodb.d.ts +49 -0
  19. package/dist/types/monsqlize.d.ts +491 -0
  20. package/dist/types/pool.d.ts +84 -0
  21. package/dist/types/runtime.d.ts +362 -0
  22. package/dist/types/saga.d.ts +143 -0
  23. package/dist/types/slow-query-log.d.ts +126 -0
  24. package/dist/types/sync.d.ts +103 -0
  25. package/dist/types/transaction.d.ts +132 -0
  26. package/package.json +67 -69
  27. package/index.d.ts +0 -206
  28. package/index.mjs +0 -52
  29. package/lib/cache-invalidation.js +0 -279
  30. package/lib/cache.js +0 -530
  31. package/lib/common/cursor.js +0 -59
  32. package/lib/common/docs-urls.js +0 -73
  33. package/lib/common/index-options.js +0 -223
  34. package/lib/common/log.js +0 -61
  35. package/lib/common/namespace.js +0 -22
  36. package/lib/common/normalize.js +0 -34
  37. package/lib/common/page-result.js +0 -43
  38. package/lib/common/runner.js +0 -57
  39. package/lib/common/server-features.js +0 -232
  40. package/lib/common/shape-builders.js +0 -27
  41. package/lib/common/validation.js +0 -113
  42. package/lib/connect.js +0 -99
  43. package/lib/constants.js +0 -55
  44. package/lib/count-queue.js +0 -188
  45. package/lib/distributed-cache-invalidator.js +0 -260
  46. package/lib/errors.js +0 -168
  47. package/lib/expression/cache/ExpressionCache.js +0 -114
  48. package/lib/expression/compiler/ExpressionCompiler.js +0 -1090
  49. package/lib/expression/compiler/ExpressionCompilerExtensions.js +0 -531
  50. package/lib/expression/detector.js +0 -84
  51. package/lib/expression/factory.js +0 -29
  52. package/lib/expression/index.js +0 -19
  53. package/lib/function-cache.js +0 -533
  54. package/lib/index.js +0 -1251
  55. package/lib/infrastructure/ConnectionPoolManager.js +0 -464
  56. package/lib/infrastructure/HealthChecker.js +0 -281
  57. package/lib/infrastructure/PoolConfig.js +0 -199
  58. package/lib/infrastructure/PoolSelector.js +0 -225
  59. package/lib/infrastructure/PoolStats.js +0 -244
  60. package/lib/infrastructure/ssh-tunnel-ssh2.js +0 -212
  61. package/lib/infrastructure/ssh-tunnel.js +0 -41
  62. package/lib/infrastructure/uri-parser.js +0 -36
  63. package/lib/lock/Lock.js +0 -67
  64. package/lib/lock/errors.js +0 -28
  65. package/lib/lock/index.js +0 -13
  66. package/lib/logger.js +0 -225
  67. package/lib/model/examples/test.js +0 -311
  68. package/lib/model/features/defaults.js +0 -161
  69. package/lib/model/features/populate.js +0 -568
  70. package/lib/model/features/relations.js +0 -120
  71. package/lib/model/features/soft-delete.js +0 -349
  72. package/lib/model/features/version.js +0 -157
  73. package/lib/model/features/virtuals.js +0 -219
  74. package/lib/model/index.js +0 -1265
  75. package/lib/mongodb/common/accessor-helpers.js +0 -59
  76. package/lib/mongodb/common/agg-pipeline.js +0 -36
  77. package/lib/mongodb/common/aggregation-validator.js +0 -127
  78. package/lib/mongodb/common/iid.js +0 -28
  79. package/lib/mongodb/common/lexicographic-expr.js +0 -53
  80. package/lib/mongodb/common/shape.js +0 -32
  81. package/lib/mongodb/common/sort.js +0 -39
  82. package/lib/mongodb/common/transaction-aware.js +0 -25
  83. package/lib/mongodb/connect.js +0 -234
  84. package/lib/mongodb/index.js +0 -639
  85. package/lib/mongodb/management/admin-ops.js +0 -200
  86. package/lib/mongodb/management/bookmark-ops.js +0 -167
  87. package/lib/mongodb/management/cache-ops.js +0 -50
  88. package/lib/mongodb/management/collection-ops.js +0 -387
  89. package/lib/mongodb/management/database-ops.js +0 -202
  90. package/lib/mongodb/management/index-ops.js +0 -475
  91. package/lib/mongodb/management/index.js +0 -17
  92. package/lib/mongodb/management/namespace.js +0 -31
  93. package/lib/mongodb/management/validation-ops.js +0 -268
  94. package/lib/mongodb/queries/aggregate.js +0 -172
  95. package/lib/mongodb/queries/chain.js +0 -631
  96. package/lib/mongodb/queries/count.js +0 -99
  97. package/lib/mongodb/queries/distinct.js +0 -78
  98. package/lib/mongodb/queries/find-and-count.js +0 -193
  99. package/lib/mongodb/queries/find-by-ids.js +0 -236
  100. package/lib/mongodb/queries/find-one-by-id.js +0 -171
  101. package/lib/mongodb/queries/find-one.js +0 -71
  102. package/lib/mongodb/queries/find-page.js +0 -618
  103. package/lib/mongodb/queries/find.js +0 -171
  104. package/lib/mongodb/queries/index.js +0 -51
  105. package/lib/mongodb/queries/watch.js +0 -538
  106. package/lib/mongodb/writes/common/batch-retry.js +0 -65
  107. package/lib/mongodb/writes/delete-batch.js +0 -323
  108. package/lib/mongodb/writes/delete-many.js +0 -181
  109. package/lib/mongodb/writes/delete-one.js +0 -173
  110. package/lib/mongodb/writes/find-one-and-delete.js +0 -203
  111. package/lib/mongodb/writes/find-one-and-replace.js +0 -239
  112. package/lib/mongodb/writes/find-one-and-update.js +0 -240
  113. package/lib/mongodb/writes/increment-one.js +0 -259
  114. package/lib/mongodb/writes/index.js +0 -46
  115. package/lib/mongodb/writes/insert-batch.js +0 -508
  116. package/lib/mongodb/writes/insert-many.js +0 -223
  117. package/lib/mongodb/writes/insert-one.js +0 -169
  118. package/lib/mongodb/writes/replace-one.js +0 -226
  119. package/lib/mongodb/writes/result-handler.js +0 -237
  120. package/lib/mongodb/writes/update-batch.js +0 -416
  121. package/lib/mongodb/writes/update-many.js +0 -275
  122. package/lib/mongodb/writes/update-one.js +0 -273
  123. package/lib/mongodb/writes/upsert-one.js +0 -203
  124. package/lib/multi-level-cache.js +0 -244
  125. package/lib/operators.js +0 -330
  126. package/lib/redis-cache-adapter.js +0 -267
  127. package/lib/saga/SagaContext.js +0 -67
  128. package/lib/saga/SagaDefinition.js +0 -32
  129. package/lib/saga/SagaExecutor.js +0 -201
  130. package/lib/saga/SagaOrchestrator.js +0 -186
  131. package/lib/saga/index.js +0 -11
  132. package/lib/slow-query-log/base-storage.js +0 -70
  133. package/lib/slow-query-log/batch-queue.js +0 -97
  134. package/lib/slow-query-log/config-manager.js +0 -196
  135. package/lib/slow-query-log/index.js +0 -238
  136. package/lib/slow-query-log/mongodb-storage.js +0 -324
  137. package/lib/slow-query-log/query-hash.js +0 -39
  138. package/lib/sync/ChangeStreamSyncManager.js +0 -405
  139. package/lib/sync/ResumeTokenStore.js +0 -192
  140. package/lib/sync/SyncConfig.js +0 -127
  141. package/lib/sync/SyncTarget.js +0 -240
  142. package/lib/sync/index.js +0 -20
  143. package/lib/transaction/CacheLockManager.js +0 -162
  144. package/lib/transaction/DistributedCacheLockManager.js +0 -475
  145. package/lib/transaction/Transaction.js +0 -315
  146. package/lib/transaction/TransactionManager.js +0 -267
  147. package/lib/transaction/index.js +0 -11
  148. package/lib/utils/objectid-converter.js +0 -632
  149. package/types/README.md +0 -122
  150. package/types/base.ts +0 -94
  151. package/types/batch.ts +0 -187
  152. package/types/cache.ts +0 -71
  153. package/types/chain.ts +0 -254
  154. package/types/collection.ts +0 -357
  155. package/types/expression.ts +0 -109
  156. package/types/function-cache.d.ts +0 -135
  157. package/types/lock.ts +0 -95
  158. package/types/model/definition.ts +0 -152
  159. package/types/model/index.ts +0 -10
  160. package/types/model/instance.ts +0 -121
  161. package/types/model/relations.ts +0 -121
  162. package/types/model/virtuals.ts +0 -32
  163. package/types/monsqlize.ts +0 -245
  164. package/types/options.ts +0 -192
  165. package/types/pagination.ts +0 -154
  166. package/types/pool.ts +0 -125
  167. package/types/query.ts +0 -71
  168. package/types/saga.ts +0 -125
  169. package/types/stream.ts +0 -64
  170. package/types/sync.ts +0 -79
  171. package/types/transaction.ts +0 -79
  172. package/types/write.ts +0 -77
@@ -1,200 +0,0 @@
1
- /**
2
- * 运维监控方法工厂函数
3
- * 提供数据库和服务器级别的监控方法
4
- * @module mongodb/management/admin-ops
5
- */
6
-
7
- const { createValidationError } = require('../../errors');
8
-
9
- /**
10
- * 创建运维监控方法
11
- * @param {Object} context - 上下文对象
12
- * @param {Object} context.adapter - MongoDB 适配器
13
- * @param {Object} context.logger - 日志记录器
14
- * @returns {Object} 运维监控方法集合
15
- */
16
- function createAdminOps(context) {
17
- const { adapter, logger } = context;
18
-
19
- return {
20
- /**
21
- * 检测数据库连接是否正常
22
- * @returns {Promise<boolean>} 连接正常返回 true,否则返回 false
23
- * @example
24
- * const isAlive = await db.ping();
25
- * console.log('Database is alive:', isAlive);
26
- */
27
- async ping() {
28
- try {
29
- await adapter.db.admin().ping();
30
- return true;
31
- } catch (error) {
32
- logger.error('Ping failed', { error: error.message });
33
- return false;
34
- }
35
- },
36
-
37
- /**
38
- * 获取 MongoDB 版本信息
39
- * @returns {Promise<Object>} 版本信息对象
40
- * @property {string} version - 版本号(如 "6.0.3")
41
- * @property {Array<number>} versionArray - 版本号数组(如 [6, 0, 3])
42
- * @property {string} gitVersion - Git 版本哈希
43
- * @property {Object} [bits] - 系统位数(32 或 64)
44
- * @property {boolean} [debug] - 是否为 Debug 版本
45
- * @example
46
- * const info = await db.buildInfo();
47
- * console.log('MongoDB version:', info.version);
48
- * console.log('Git version:', info.gitVersion);
49
- */
50
- async buildInfo() {
51
- try {
52
- const admin = adapter.db.admin();
53
- const info = await admin.buildInfo();
54
-
55
- // 返回精简的版本信息
56
- return {
57
- version: info.version,
58
- versionArray: info.versionArray,
59
- gitVersion: info.gitVersion,
60
- bits: info.bits,
61
- debug: info.debug,
62
- maxBsonObjectSize: info.maxBsonObjectSize
63
- };
64
- } catch (error) {
65
- logger.error('buildInfo failed', { error: error.message });
66
- throw createValidationError(
67
- `Failed to get build info: ${error.message}`,
68
- { code: 'BUILD_INFO_ERROR' }
69
- );
70
- }
71
- },
72
-
73
- /**
74
- * 获取服务器状态信息
75
- * @param {Object} [options] - 选项
76
- * @param {boolean} [options.scale=1] - 缩放因子(1=字节, 1024=KB, 1048576=MB)
77
- * @returns {Promise<Object>} 服务器状态对象
78
- * @property {Object} connections - 连接信息
79
- * @property {number} connections.current - 当前连接数
80
- * @property {number} connections.available - 可用连接数
81
- * @property {number} connections.totalCreated - 总创建连接数
82
- * @property {Object} mem - 内存使用信息
83
- * @property {number} mem.resident - 常驻内存(MB)
84
- * @property {number} mem.virtual - 虚拟内存(MB)
85
- * @property {Object} opcounters - 操作计数器
86
- * @property {number} opcounters.insert - 插入操作数
87
- * @property {number} opcounters.query - 查询操作数
88
- * @property {number} opcounters.update - 更新操作数
89
- * @property {number} opcounters.delete - 删除操作数
90
- * @property {Object} network - 网络统计
91
- * @property {number} uptime - 运行时间(秒)
92
- * @example
93
- * const status = await db.serverStatus();
94
- * console.log('Current connections:', status.connections.current);
95
- * console.log('Memory usage:', status.mem.resident, 'MB');
96
- * console.log('Insert operations:', status.opcounters.insert);
97
- */
98
- async serverStatus(options = {}) {
99
- try {
100
- const admin = adapter.db.admin();
101
- const scale = options.scale || 1;
102
-
103
- const status = await admin.serverStatus({ scale });
104
-
105
- // 返回关键的状态信息
106
- return {
107
- connections: {
108
- current: status.connections?.current,
109
- available: status.connections?.available,
110
- totalCreated: status.connections?.totalCreated
111
- },
112
- mem: {
113
- resident: status.mem?.resident,
114
- virtual: status.mem?.virtual,
115
- mapped: status.mem?.mapped
116
- },
117
- opcounters: {
118
- insert: status.opcounters?.insert,
119
- query: status.opcounters?.query,
120
- update: status.opcounters?.update,
121
- delete: status.opcounters?.delete,
122
- getmore: status.opcounters?.getmore,
123
- command: status.opcounters?.command
124
- },
125
- network: {
126
- bytesIn: status.network?.bytesIn,
127
- bytesOut: status.network?.bytesOut,
128
- numRequests: status.network?.numRequests
129
- },
130
- uptime: status.uptime,
131
- localTime: status.localTime,
132
- version: status.version,
133
- process: status.process
134
- };
135
- } catch (error) {
136
- logger.error('serverStatus failed', { error: error.message });
137
- throw createValidationError(
138
- `Failed to get server status: ${error.message}`,
139
- { code: 'SERVER_STATUS_ERROR' }
140
- );
141
- }
142
- },
143
-
144
- /**
145
- * 获取数据库统计信息
146
- * @param {Object} [options] - 选项
147
- * @param {number} [options.scale=1] - 缩放因子(1=字节, 1024=KB, 1048576=MB)
148
- * @returns {Promise<Object>} 数据库统计对象
149
- * @property {string} db - 数据库名称
150
- * @property {number} collections - 集合数量
151
- * @property {number} views - 视图数量
152
- * @property {number} objects - 文档总数
153
- * @property {number} avgObjSize - 平均文档大小
154
- * @property {number} dataSize - 数据大小
155
- * @property {number} storageSize - 存储大小
156
- * @property {number} indexes - 索引数量
157
- * @property {number} indexSize - 索引大小
158
- * @example
159
- * const stats = await db.stats();
160
- * console.log('Collections:', stats.collections);
161
- * console.log('Total documents:', stats.objects);
162
- * console.log('Data size:', stats.dataSize, 'bytes');
163
- * console.log('Index size:', stats.indexSize, 'bytes');
164
- *
165
- * // 使用 MB 为单位
166
- * const statsMB = await db.stats({ scale: 1048576 });
167
- * console.log('Data size:', statsMB.dataSize, 'MB');
168
- */
169
- async stats(options = {}) {
170
- try {
171
- const scale = options.scale || 1;
172
- const stats = await adapter.db.stats({ scale });
173
-
174
- return {
175
- db: stats.db,
176
- collections: stats.collections,
177
- views: stats.views,
178
- objects: stats.objects,
179
- avgObjSize: stats.avgObjSize,
180
- dataSize: stats.dataSize,
181
- storageSize: stats.storageSize,
182
- indexes: stats.indexes,
183
- indexSize: stats.indexSize,
184
- totalSize: stats.totalSize,
185
- scaleFactor: stats.scaleFactor
186
- };
187
- } catch (error) {
188
- logger.error('Database stats failed', { error: error.message });
189
- throw createValidationError(
190
- `Failed to get database stats: ${error.message}`,
191
- { code: 'DATABASE_STATS_ERROR' }
192
- );
193
- }
194
- }
195
- };
196
- }
197
-
198
- module.exports = { createAdminOps };
199
-
200
-
@@ -1,167 +0,0 @@
1
- /**
2
- * Bookmark 管理模块
3
- * @description 提供书签缓存的预热、列表和清除功能
4
- */
5
-
6
- const { ensureStableSort } = require('../common/sort');
7
- const { normalizeSort } = require('../../common/normalize');
8
- const { bookmarkKey, buildKeyDimsAuto } = require('../queries/find-page');
9
-
10
- /**
11
- * 创建 Bookmark 管理操作
12
- * @param {Object} context - 上下文对象
13
- * @returns {Object} 包含 prewarmBookmarks, listBookmarks, clearBookmarks 方法
14
- */
15
- function createBookmarkOps(context) {
16
- const { getCache, instanceId, type, effectiveDbName, collection, logger, getCollectionMethods } = context;
17
-
18
- // 构建命名空间字符串
19
- const ns = `${instanceId}:${type}:${effectiveDbName}:${collection.collectionName}`;
20
-
21
- return {
22
- /**
23
- * 预热书签(缓存指定页面)
24
- * @param {Object} keyDims - 查询维度
25
- * @param {number[]} pages - 要预热的页码数组
26
- * @returns {Promise<Object>} 预热结果统计
27
- */
28
- prewarmBookmarks: async (keyDims = {}, pages = []) => {
29
- const cache = getCache(); // 动态获取 cache
30
- if (!cache) {
31
- const err = new Error('CACHE_UNAVAILABLE: Cache is required for bookmark operations');
32
- err.code = 'CACHE_UNAVAILABLE';
33
- throw err;
34
- }
35
-
36
- if (!Array.isArray(pages) || pages.length === 0) {
37
- const err = new Error('INVALID_PAGES: pages must be a non-empty array');
38
- err.code = 'INVALID_PAGES';
39
- throw err;
40
- }
41
-
42
- const accessor = getCollectionMethods();
43
- const results = { warmed: 0, failed: 0, keys: [] };
44
-
45
- for (const page of pages) {
46
- if (!Number.isInteger(page) || page < 1) {
47
- results.failed++;
48
- try {
49
- logger?.warn?.(`跳过无效页码: ${page}`);
50
- } catch (_) { /* ignore */ }
51
- continue;
52
- }
53
-
54
- try {
55
- // 使用 jump.step=1 确保 bookmark 被缓存
56
- const result = await accessor.findPage({
57
- ...keyDims,
58
- page,
59
- totals: false,
60
- jump: { step: 1 }
61
- });
62
-
63
- // 检查是否返回了数据
64
- if (result.items && result.items.length > 0) {
65
- results.warmed++;
66
- } else {
67
- results.failed++;
68
- try {
69
- logger?.warn?.(`页面 ${page} 无数据(可能超出范围)`);
70
- } catch (_) { /* ignore */ }
71
- }
72
- } catch (error) {
73
- results.failed++;
74
- try {
75
- logger?.error?.(`预热页面 ${page} 失败:`, error);
76
- } catch (_) { /* ignore */ }
77
- }
78
- }
79
-
80
- results.keys = await cache.keys(`${ns}:bm:*`);
81
- return results;
82
- },
83
-
84
- /**
85
- * 列出所有书签
86
- * @param {Object} [keyDims] - 可选的查询维度过滤
87
- * @returns {Promise<Object>} 书签列表
88
- */
89
- listBookmarks: async (keyDims) => {
90
- const cache = getCache(); // 动态获取 cache
91
- if (!cache) {
92
- const err = new Error('CACHE_UNAVAILABLE: Cache is required for bookmark operations');
93
- err.code = 'CACHE_UNAVAILABLE';
94
- throw err;
95
- }
96
-
97
- let pattern;
98
- if (keyDims) {
99
- // 确保 sort 与 findPage 内部处理一致
100
- const stableSort = ensureStableSort(normalizeSort(keyDims.sort) || { _id: 1 });
101
- const normalizedKeyDims = buildKeyDimsAuto({
102
- db: effectiveDbName,
103
- coll: collection.collectionName,
104
- sort: stableSort,
105
- limit: keyDims.limit,
106
- query: keyDims.query,
107
- pipeline: keyDims.pipeline
108
- });
109
- const baseKey = bookmarkKey(ns, normalizedKeyDims);
110
- pattern = `${baseKey}:*`;
111
- } else {
112
- pattern = `${ns}:bm:*`;
113
- }
114
-
115
- const keys = await cache.keys(pattern);
116
- const pages = keys
117
- .map((key) => {
118
- const match = key.match(/:(\d+)$/);
119
- return match ? parseInt(match[1], 10) : null;
120
- })
121
- .filter((page) => page !== null)
122
- .sort((a, b) => a - b);
123
-
124
- return { count: pages.length, pages, keys };
125
- },
126
-
127
- /**
128
- * 清除书签
129
- * @param {Object} [keyDims] - 可选的查询维度过滤
130
- * @returns {Promise<Object>} 清除结果统计
131
- */
132
- clearBookmarks: async (keyDims) => {
133
- const cache = getCache(); // 动态获取 cache
134
- if (!cache) {
135
- const err = new Error('CACHE_UNAVAILABLE: Cache is required for bookmark operations');
136
- err.code = 'CACHE_UNAVAILABLE';
137
- throw err;
138
- }
139
-
140
- let pattern;
141
- if (keyDims) {
142
- // 确保 sort 与 findPage 内部处理一致
143
- const stableSort = ensureStableSort(normalizeSort(keyDims.sort) || { _id: 1 });
144
- const normalizedKeyDims = buildKeyDimsAuto({
145
- db: effectiveDbName,
146
- coll: collection.collectionName,
147
- sort: stableSort,
148
- limit: keyDims.limit,
149
- query: keyDims.query,
150
- pipeline: keyDims.pipeline
151
- });
152
- const baseKey = bookmarkKey(ns, normalizedKeyDims);
153
- pattern = `${baseKey}:*`;
154
- } else {
155
- pattern = `${ns}:bm:*`;
156
- }
157
-
158
- const keysBefore = await cache.keys(pattern);
159
- const cleared = await cache.delPattern(pattern);
160
-
161
- return { cleared, pattern, keysBefore: keysBefore.length };
162
- }
163
- };
164
- }
165
-
166
- module.exports = createBookmarkOps;
167
-
@@ -1,50 +0,0 @@
1
- /**
2
- * cache-ops 缓存管理模块
3
- * @description 提供缓存失效和管理功能
4
- */
5
-
6
- const CacheFactory = require('../../cache');
7
-
8
- /**
9
- * 创建缓存管理操作
10
- * @param {Object} context - 上下文对象
11
- * @returns {Object} 包含 invalidate 方法的对象
12
- */
13
- function createCacheOps(context) {
14
- const { cache, instanceId, effectiveDbName, collection, logger } = context;
15
-
16
- return {
17
- /**
18
- * 失效缓存
19
- * @description 使指定集合的查询缓存失效(通过模式匹配删除)
20
- * @param {('find'|'findOne'|'count'|'findPage')} [op] - 可选:指定仅失效某操作
21
- * @returns {Promise<number>} 删除的键数量
22
- */
23
- invalidate: async (op) => {
24
- const ns = {
25
- iid: instanceId,
26
- type: context.type,
27
- db: effectiveDbName,
28
- collection: collection.collectionName,
29
- };
30
- const pattern = CacheFactory.buildNamespaceOpPattern(ns, op);
31
- try {
32
- const deleted = await cache.delPattern(pattern);
33
- try {
34
- logger?.info?.('🗑️ Cache invalidated', { ns, op, deleted });
35
- } catch (_) { /* ignore logging error */
36
- }
37
- return deleted;
38
- } catch (_) {
39
- try {
40
- logger?.warn?.('🗑️ Cache invalidation failed', { ns, op });
41
- } catch (_) {
42
- }
43
- return 0;
44
- }
45
- }
46
- };
47
- }
48
-
49
- module.exports = createCacheOps;
50
-