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
@@ -0,0 +1,160 @@
1
+ # Changelogs 目录说明
2
+
3
+ 本目录存放 monSQLize 各版本的详细变更文档。
4
+
5
+ ---
6
+
7
+ ## 📁 目录结构
8
+
9
+ ```
10
+ changelogs/
11
+ ├── README.md # 本说明文档
12
+ ├── TEMPLATE.md # 变更文档模板
13
+ ├── v2.0.0.md # v2.0.0 详细变更
14
+ └── v1.x.y.md # 历史版本详细变更(仓库归档)
15
+ ```
16
+
17
+ ---
18
+
19
+ ## 📝 文档格式
20
+
21
+ 每个版本的详细变更文档包含以下章节:
22
+
23
+ ### 必需章节
24
+
25
+ 1. **版本信息** - 版本号、日期、类型、风险级别、兼容性
26
+ 2. **变更摘要** - 一句话总结变更核心内容
27
+ 3. **背景说明** - 为什么需要这次变更
28
+ 4. **变更内容** - 改了什么
29
+ 5. **影响范围** - 影响哪些文件和功能
30
+ 6. **详细变更清单** - Added/Changed/Fixed 等分类列表
31
+ 7. **验证方法** - 如何验证变更
32
+
33
+ ### 可选章节
34
+
35
+ - **迁移指南** - 如何升级/降级(如有破坏性变更)
36
+ - **相关资源** - 文档/示例/测试链接
37
+ - **设计决策** - 为什么这样设计
38
+ - **未来改进** - 计划的后续改进
39
+
40
+ ---
41
+
42
+ ## 🔍 快速查找
43
+
44
+ ### 按版本类型
45
+
46
+ - **正式发布**: v2.0.0, v1.0.0
47
+ - **功能版本**: v1.x
48
+ - **修复版本**: v1.x.y
49
+
50
+ ### 按功能领域
51
+
52
+ - **TypeScript 重构与 v1 平滑升级**: v2.0.0
53
+ - **实时监听 / 管理功能 / 核心功能**: v1.x 历史版本
54
+
55
+ ### 按风险级别
56
+
57
+ - **P0 (Critical)**: v2.0.0
58
+ - **P1 (High)**: v1.x 破坏性或高风险历史版本
59
+ - **P2 (Low)**: v1.x 修复版本
60
+
61
+ ---
62
+
63
+ ## ✍️ 如何创建新的变更文档
64
+
65
+ ### 步骤1: 复制模板
66
+
67
+ ```bash
68
+ cp TEMPLATE.md v{版本号}.md
69
+ ```
70
+
71
+ ### 步骤2: 填写内容
72
+
73
+ 根据模板章节填写变更信息:
74
+ - 版本信息
75
+ - 变更摘要
76
+ - 背景说明
77
+ - 变更内容
78
+ - 影响范围
79
+ - 详细变更清单
80
+ - 验证方法
81
+
82
+ ### 步骤3: 更新主 CHANGELOG
83
+
84
+ 在项目根目录的 `CHANGELOG.md` 中:
85
+ - 在"版本概览"表格最上方添加新行
86
+ - 格式:版本列和详情列指向当前发布版本的 `changelogs/v{版本号}.md`
87
+
88
+ ### 步骤4: 提交变更
89
+
90
+ ```bash
91
+ git add CHANGELOG.md changelogs/v{版本号}.md
92
+ git commit -m "docs: 发布 v{版本号}"
93
+ git tag v{版本号}
94
+ git push origin main --tags
95
+ ```
96
+
97
+ ---
98
+
99
+ ## 📚 模板说明
100
+
101
+ ### TEMPLATE.md
102
+
103
+ `TEMPLATE.md` 是创建新版本文档的标准模板,包含:
104
+
105
+ - 完整的章节结构
106
+ - 占位符和示例
107
+ - 注释说明
108
+ - Markdown 格式规范
109
+
110
+ 使用时请:
111
+ 1. 复制模板文件
112
+ 2. 重命名为对应版本号
113
+ 3. 替换所有占位符
114
+ 4. 删除不需要的可选章节
115
+ 5. 补充完整的变更信息
116
+
117
+ ---
118
+
119
+ ## 📊 版本命名规范
120
+
121
+ 遵循[语义化版本](https://semver.org/lang/zh-CN/):
122
+
123
+ ### 格式: vMAJOR.MINOR.PATCH
124
+
125
+ - **MAJOR** - 不兼容的 API 变更
126
+ - **MINOR** - 向后兼容的新增功能
127
+ - **PATCH** - 向后兼容的问题修复
128
+
129
+ ### 示例
130
+
131
+ - `v1.0.0` - 正式发布
132
+ - `v1.1.0` - 新增功能
133
+ - `v1.1.1` - Bug 修复
134
+ - `v2.0.0` - 破坏性变更
135
+
136
+ ---
137
+
138
+ ## 🔗 相关资源
139
+
140
+ - **主 CHANGELOG**: [../CHANGELOG.md](../CHANGELOG.md)
141
+ - **项目文档**: [GitHub docs](https://github.com/vextjs/monSQLize/tree/main/docs)
142
+ - **使用示例**: [GitHub examples](https://github.com/vextjs/monSQLize/tree/main/examples)
143
+ - **测试用例**: [GitHub test](https://github.com/vextjs/monSQLize/tree/main/test)
144
+ - **语义化版本**: https://semver.org/lang/zh-CN/
145
+
146
+ ---
147
+
148
+ ## 📋 变更文档清单
149
+
150
+ | 版本 | 文件 | 状态 | 发布日期 |
151
+ |------|------|------|---------|
152
+ | v2.0.0 | v2.0.0.md | ✅ 待发布候选 | 2026-06-01 |
153
+ | v1.x | 仓库历史归档 | ✅ 已发布 | 2025-12-03 起 |
154
+
155
+ ---
156
+
157
+ **目录版本**: 2.0
158
+ **最后更新**: 2026-06-01
159
+ **维护者**: monSQLize Team
160
+
@@ -0,0 +1,222 @@
1
+ # v2.0.0 — 2026-06-01
2
+
3
+ ## Overview
4
+
5
+ v2.0.0 is a full **TypeScript rewrite** of monSQLize. The public API is preserved — existing v1 code requires only minor configuration adjustments to run on v2.
6
+
7
+ ---
8
+
9
+ ## Architecture
10
+
11
+ | Layer | Change |
12
+ |---|---|
13
+ | Source language | JavaScript → TypeScript (strict mode) |
14
+ | Cache engine | Internal implementation → [`cache-hub`](https://github.com/vextjs/cache-hub) |
15
+ | Internal structure | Flat modules → capability layers + adapter bridge |
16
+ | Type declarations | Hand-maintained `.d.ts` → generated from source (single source of truth) |
17
+
18
+ ---
19
+
20
+ ## Compatibility Notes and Breaking Changes
21
+
22
+ ### B1 — `SagaResult` shape documents v1/v2 aliases
23
+
24
+ `SagaResult` now exposes the runtime fields and the restored v1/v2 alias fields:
25
+
26
+ ```ts
27
+ {
28
+ executionId: string; // primary v1 field
29
+ sagaId?: string; // v2 alias, optional for v1 fixtures
30
+ sagaName?: string;
31
+ success: boolean;
32
+ result?: unknown;
33
+ error?: Error;
34
+ errorMessage?: string;
35
+ completedSteps: string[];
36
+ completedStepCount?: number;
37
+ completedStepNames?: string[];
38
+ compensatedSteps: string[];
39
+ duration: number;
40
+ compensation?: { success: boolean; results: [...] };
41
+ }
42
+ ```
43
+
44
+ ### B2 — `TransactionInfo.status` keeps the v1 `'started'` value
45
+
46
+ The internal transaction state still uses `'active'`, but `Transaction#getInfo().status` maps it back to `'started'` for v1 callers. Public values are `'pending' | 'started' | 'committed' | 'aborted'`.
47
+
48
+ ### B3 — `getPoolStats()` / `getPoolHealth()` return `Record<string, T>`
49
+
50
+ ```ts
51
+ // v1 — array
52
+ getPoolStats(): PoolStats[]
53
+ getPoolHealth(): PoolHealthStatus[]
54
+
55
+ // v2 — keyed by pool name
56
+ getPoolStats(): Record<string, PoolStats>
57
+ getPoolHealth(): Record<string, PoolHealthStatus>
58
+ ```
59
+
60
+ ### B4 — `PoolStats` shape extended
61
+
62
+ `PoolStats` now includes `connections`, `available`, `waiting`, and `status` fields that were absent in v1 type declarations (but present in the runtime).
63
+
64
+ ### B5 — `getCache()` returns `CacheLike`
65
+
66
+ ```ts
67
+ // v1
68
+ getCache(): MemoryCache
69
+
70
+ // v2
71
+ getCache(): CacheLike // MemoryCache | MultiLevelCache | custom adapter
72
+ ```
73
+
74
+ This is a widening: `MemoryCache` is still the default; the return type is broader to accommodate the two new cache modes.
75
+
76
+ ---
77
+
78
+ ## New Features
79
+
80
+ ### MultiLevel cache via `cache` option
81
+
82
+ ```ts
83
+ const msq = new MonSQLize({
84
+ type: 'mongodb',
85
+ cache: {
86
+ multiLevel: true,
87
+ local: { maxEntries: 5000 },
88
+ remote: MonSQLize.createRedisCacheAdapter('redis://localhost:6379'),
89
+ policy: { writePolicy: 'local-first-async-remote', backfillLocalOnRemoteHit: true },
90
+ },
91
+ });
92
+ ```
93
+
94
+ ### SSH tunnel support
95
+
96
+ Connect to MongoDB through a bastion host with no code changes required:
97
+
98
+ ```ts
99
+ const msq = new MonSQLize({
100
+ type: 'mongodb',
101
+ config: {
102
+ uri: 'mongodb://mongo.internal:27017/mydb',
103
+ ssh: {
104
+ host: 'bastion.example.com',
105
+ username: 'deploy',
106
+ privateKeyPath: '~/.ssh/id_rsa',
107
+ },
108
+ },
109
+ });
110
+ ```
111
+
112
+ Requires the optional `ssh2` package: `npm install ssh2`.
113
+
114
+ ### Custom `CacheLike` pass-through (v1 compat)
115
+
116
+ Passing a custom `CacheLike` instance (e.g. a Redis adapter) directly as `cache` is now supported:
117
+
118
+ ```ts
119
+ const msq = new MonSQLize({
120
+ type: 'mongodb',
121
+ cache: MonSQLize.createRedisCacheAdapter('redis://localhost:6379'),
122
+ });
123
+ ```
124
+
125
+ In v1 this silently fell back to a default `MemoryCache`. In v2 it is used directly.
126
+
127
+ ### `HealthView.driver` field
128
+
129
+ `health()` now returns `driver: { connected: boolean }` alongside the existing fields.
130
+
131
+ ### `ModelInstance` soft-delete and batch methods
132
+
133
+ `findOneOnlyDeleted`, `countWithDeleted`, `countOnlyDeleted`, `insertBatch`, `updateBatch` are now declared in the public type surface (they existed at runtime in v1 but were not typed).
134
+
135
+ ---
136
+
137
+ ## v1 Compatibility Map
138
+
139
+ | v1 option | v2 equivalent | Status |
140
+ |---|---|---|
141
+ | `cache.maxSize` | `cache.maxEntries` | ✅ auto-mapped |
142
+ | `cache.ttl` | `cache.defaultTtl` | ✅ auto-mapped |
143
+ | `cache.autoInvalidate` | `cacheAutoInvalidate` (top-level) | ✅ both accepted |
144
+ | `cache: CacheLike` | `cache: CacheLike` | ✅ pass-through |
145
+ | `cache: MultiLevelCacheOptions` | `cache: { multiLevel: true, ... }` | ✅ fully supported |
146
+ | `options.database` | `options.databaseName` | ✅ alias preserved |
147
+ | `SagaResult.sagaId` | `SagaResult.sagaId` + `executionId` alias | ✅ |
148
+ | `ctx.sagaId` in Saga steps | `ctx.executionId` + `ctx.sagaId` alias | ✅ alias preserved |
149
+
150
+ ---
151
+
152
+ ## JSDoc Coverage
153
+
154
+ All public API surface now carries complete English JSDoc:
155
+
156
+ - `types/collection.d.ts` — 49 Collection / DbAccessor / AdminAccessor methods
157
+ - `types/model.d.ts` — 44 ModelInstance methods
158
+ - `types/monsqlize.d.ts` — 43 MonSQLize interface methods
159
+ - `types/lock.d.ts` — Lock / LockManager
160
+ - `types/saga.d.ts` — SagaOrchestrator / SagaContext / SagaStep
161
+ - `types/transaction.d.ts` — Transaction / TransactionManager / CacheLockManager
162
+ - `types/runtime.d.ts` — MemoryCache / MultiLevelCache / FunctionCache
163
+
164
+ ---
165
+
166
+ ## v1 Compatibility Fixes (included in this release)
167
+
168
+ ### API / Runtime
169
+ - **`findAndCount`**: return value includes `documents` as a backward-compat alias for `data` (`{ data, total, documents }`)
170
+ - **`findOneById` / `findByIds`**: `options.cache` now restores v1-style read-through TTL caching.
171
+ - **Runtime query defaults**: built-in defaults now match v1 (`maxTimeMS=2000`, `findLimit=10`, `slowQueryMs=500`, `findPageMaxLimit=500`).
172
+ - **`LockManager` TTL**: explicit lock TTL values are no longer silently capped by `maxDuration`.
173
+ - **`withCache(fn)`**: default behavior now matches v1 (`ttl=60000`, `namespace='fn'`, `enableStats=true`).
174
+ - **`adaptLegacyCacheLike`**: exported as both a named import and `MonSQLize.adaptLegacyCacheLike`
175
+ - **`MultiLevelCache`**: exported as both a named import and `MonSQLize.MultiLevelCache`
176
+ - **Error messages**: `createValidationError` default message `参数校验失败`; `createCursorError` default `游标无效`
177
+ - **`FunctionCache.defaultTTL`**: v1 option `defaultTTL` now accepted as an alias for `ttl`; v1 code using `new FunctionCache(db, { defaultTTL: 60000 })` works without changes
178
+ - **Read query meta wrapper**: `find` / `findOne` / `count` / `aggregate` / `distinct` now restore the v1 `{ data, meta }` result shape when `options.meta` is enabled.
179
+ - **`FunctionCache` defaults and stats**: `new FunctionCache()` is supported, the default namespace is restored to `action`, and stats include `totalTime` / `avgTime`.
180
+ - **Batch writes**: `insertBatch` / `deleteBatch` retry defaults are restored to `3` attempts and `1000ms`; `updateBatch` now supports `onError='retry'`, `retryAttempts`, `retryDelay`, and `onRetry`.
181
+ - **Model hooks**: flat hooks support `beforeInsert` / `afterInsert` aliases and now cover bulk/upsert/findOneAnd* write paths.
182
+
183
+ ### Type Declarations
184
+ - **`FindAndCountResult`**: includes `documents?: TSchema[]` optional backward-compat alias
185
+ - **`SagaResult`**: includes `completedStepNames?: string[]` (ordered step names, v1 compat) and `errorCause?: unknown`
186
+ - **`CachedFunction`**: exposes `getCacheStats()` as a v1 shim over `stats()`
187
+ - **Query meta overloads**: public collection types now expose `ResultWithMeta<T>` overloads for meta-enabled read APIs.
188
+ - **Collection management methods**: public collection types now declare `stats`, `renameCollection`, `collMod`, `convertToCapped`, validator setters, and `getValidator`.
189
+ - **`ModelInstance` helpers**: public model types now declare `getRelations()` and `getEnums()`.
190
+ - **`Model hooks`**: `beforeInsert` / `afterInsert` are declared as flat hook aliases.
191
+ - **Batch options**: public batch option types now expose retry and progress options consistently.
192
+ - **Workspace smooth-upgrade bridge**: legacy-wide `Model` / `Collection` public contracts accept v1 consumer fixture shapes without source changes, including object schema definitions, `validate:true` operation overrides, `validate()` response data, array-form `populate()`, document-level `populate()`, Transaction stats, Saga metadata/return contracts, FunctionCache registration, Mongo connection aliases, package metadata exports, sync transform overloads, top-level `FindPageOptions.comment`, and optional v2-only counter aliases.
193
+ - **Root and static export parity**: ESM named exports and default `MonSQLize` statics are aligned with the CJS surface, including advanced capabilities and package metadata.
194
+ - **Remaining v1 operation contracts**: `MonSQLize#scopedCollection()` pool scoping, `ConnectionPoolManager#selectPool()` string operations, chainable `ModelDocument#populate()`, synchronous `listSagas()`, and required `SagaResult.compensatedSteps` are restored for v1-compatible consumers.
195
+ - **Collection `find()` overload**: the v1 three-argument `find(query, projection, options)` form is restored at runtime and in public types.
196
+ - **Redis adapter errors**: legacy invalid-argument and missing-`ioredis` messages are preserved while keeping structured monSQLize error codes.
197
+
198
+ ### Workspace Upgrade Validation
199
+ - Verified zero-business-code upgrade paths for workspace consumers `chat`, `payment`, `user`, `admin`, `search`, `vext`, and `permission-core` by overlaying only the local monSQLize package candidate and running each service's TypeScript/test gate.
200
+ - Additional workspace declarations were classified in `requirements/平滑升级支持/06-工作区依赖覆盖矩阵.md`; historical/spec assets and credential-bearing scripts are static-only exclusions from the default release gate until they are sanitized.
201
+
202
+ ### Internal
203
+ - `src/entry/runtime-core.ts` reduced from 852 to 769 lines; cache normalizer extracted to `runtime-cache-normalizer.ts`
204
+ - `node --test --test-concurrency=1` applied to all integration test scripts to prevent parallel mongod startup hangs on Windows
205
+ - `withCache()` performance validation ledgers now align with the current benchmark source and document that v1 transaction benchmarks are not directly comparable to the v2 function-cache hot-path baseline.
206
+ - The transaction/cache-lock unit test was stabilized, and release preflight now runs the default `npm test` gate before pack dry-run.
207
+ - Runtime dependency `schema-dsl` now follows npm `latest` TypeScript line `^2.0.3`; deprecated mistake releases in the `2.3.x` range are explicitly excluded from the upgrade target.
208
+ - Project licensing is now Apache-2.0, and the package README is published in English for npm and GitHub users.
209
+ - npm package artifacts are limited to runtime CJS / ESM bundles, public `.d.ts` declarations, and release documentation. Source maps are disabled by default and excluded from the package boundary even when generated locally.
210
+ - GitHub Actions publish flow now runs `release:preflight` once before `npm publish --ignore-scripts`, avoiding duplicate `prepublishOnly` lifecycle execution inside the final publish step while preserving raw `npm publish` safeguards.
211
+
212
+ ---
213
+
214
+ ## Migration Notes
215
+
216
+ Most v1 applications will **run without modification**. The steps below apply only if you hit one of the breaking changes.
217
+
218
+ 1. **`getPoolStats()` / `getPoolHealth()`** — if you iterate the result as an array, switch to `Object.values(msq.getPoolStats())`.
219
+ 2. **`Saga context`** — replace `ctx.sagaId` with `ctx.executionId` inside step handlers.
220
+ 3. **`getCache()` narrowing** — if you assigned the result to a `MemoryCache` typed variable, widen the type to `CacheLike`.
221
+ 4. **`cache.maxSize`** — still works transparently; rename to `maxEntries` at your convenience.
222
+ 5. **`slow-query-log queryHash`** — v2 now normalizes the hash from stable identity fields (`database|db`、`collection|coll`、`operation|op`、`queryShape|query`) and stores a 16-character digest. Historical slow-query-log records remain readable, but new and old aggregation keys are not guaranteed to stay continuous. This release does **not** include an automatic migration script; if your downstream analytics depend on historical key continuity, migrate those records explicitly before or during rollout.