monsqlize 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +461 -458
- package/README.md +7 -2
- package/changelogs/README.md +141 -138
- package/changelogs/v2.0.0.md +164 -164
- package/changelogs/v2.0.1.md +39 -0
- package/changelogs/v2.0.2.md +22 -0
- package/dist/cjs/index.cjs +329 -141
- package/dist/esm/index.mjs +329 -141
- package/dist/types/base.d.ts +81 -81
- package/dist/types/collection.d.ts +973 -973
- package/dist/types/expression.d.ts +115 -115
- package/dist/types/index.d.ts +23 -23
- package/dist/types/model.d.ts +489 -485
- package/dist/types/mongodb.d.ts +49 -49
- package/dist/types/monsqlize.d.ts +429 -429
- package/dist/types/pool.d.ts +84 -84
- package/dist/types/runtime.d.ts +315 -315
- package/dist/types/saga.d.ts +121 -121
- package/dist/types/slow-query-log.d.ts +126 -126
- package/dist/types/sync.d.ts +103 -103
- package/package.json +101 -99
package/README.md
CHANGED
|
@@ -423,7 +423,7 @@ const user = await users.findOne({ email });
|
|
|
423
423
|
const list = await users.find({ status: 'active' }).toArray();
|
|
424
424
|
```
|
|
425
425
|
|
|
426
|
-
The current v2.0.
|
|
426
|
+
The current v2.0.1 release has been validated against the workspace consumers `chat`, `payment`, `user`, `admin`, `search`, `vext`, and `permission-core` without requiring business-source changes in those projects.
|
|
427
427
|
|
|
428
428
|
## Compatibility
|
|
429
429
|
|
|
@@ -490,7 +490,7 @@ npm run test:real-env:private
|
|
|
490
490
|
|
|
491
491
|
## Release Status
|
|
492
492
|
|
|
493
|
-
The current release
|
|
493
|
+
The current published release is `v2.0.1`.
|
|
494
494
|
|
|
495
495
|
Key release-readiness points:
|
|
496
496
|
|
|
@@ -503,6 +503,11 @@ Key release-readiness points:
|
|
|
503
503
|
|
|
504
504
|
## Roadmap
|
|
505
505
|
|
|
506
|
+
### v2.0.1
|
|
507
|
+
|
|
508
|
+
- v1 smooth-upgrade compatibility patch for Model actual collection names, scoped pools/databases, automatic-index dedupe, and cache/pool option aliases.
|
|
509
|
+
- Documentation and public types aligned with the current runtime behavior.
|
|
510
|
+
|
|
506
511
|
### v2.0.0
|
|
507
512
|
|
|
508
513
|
- TypeScript-native runtime and declarations.
|
package/changelogs/README.md
CHANGED
|
@@ -1,160 +1,163 @@
|
|
|
1
|
-
# Changelogs 目录说明
|
|
2
|
-
|
|
3
|
-
本目录存放 monSQLize 各版本的详细变更文档。
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 📁 目录结构
|
|
8
|
-
|
|
9
|
-
```
|
|
1
|
+
# Changelogs 目录说明
|
|
2
|
+
|
|
3
|
+
本目录存放 monSQLize 各版本的详细变更文档。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📁 目录结构
|
|
8
|
+
|
|
9
|
+
```
|
|
10
10
|
changelogs/
|
|
11
11
|
├── README.md # 本说明文档
|
|
12
12
|
├── TEMPLATE.md # 变更文档模板
|
|
13
|
+
├── v2.0.1.md # v2.0.1 详细变更
|
|
13
14
|
├── v2.0.0.md # v2.0.0 详细变更
|
|
14
15
|
└── 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
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 📝 文档格式
|
|
21
|
+
|
|
22
|
+
每个版本的详细变更文档包含以下章节:
|
|
23
|
+
|
|
24
|
+
### 必需章节
|
|
25
|
+
|
|
26
|
+
1. **版本信息** - 版本号、日期、类型、风险级别、兼容性
|
|
27
|
+
2. **变更摘要** - 一句话总结变更核心内容
|
|
28
|
+
3. **背景说明** - 为什么需要这次变更
|
|
29
|
+
4. **变更内容** - 改了什么
|
|
30
|
+
5. **影响范围** - 影响哪些文件和功能
|
|
31
|
+
6. **详细变更清单** - Added/Changed/Fixed 等分类列表
|
|
32
|
+
7. **验证方法** - 如何验证变更
|
|
33
|
+
|
|
34
|
+
### 可选章节
|
|
35
|
+
|
|
36
|
+
- **迁移指南** - 如何升级/降级(如有破坏性变更)
|
|
37
|
+
- **相关资源** - 文档/示例/测试链接
|
|
38
|
+
- **设计决策** - 为什么这样设计
|
|
39
|
+
- **未来改进** - 计划的后续改进
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🔍 快速查找
|
|
44
|
+
|
|
45
|
+
### 按版本类型
|
|
46
|
+
|
|
47
|
+
- **正式发布**: v2.0.1, v2.0.0, v1.0.0
|
|
47
48
|
- **功能版本**: v1.x
|
|
48
49
|
- **修复版本**: v1.x.y
|
|
49
|
-
|
|
50
|
-
### 按功能领域
|
|
51
|
-
|
|
52
|
-
- **TypeScript 重构与 v1 平滑升级**: v2.0.0
|
|
50
|
+
|
|
51
|
+
### 按功能领域
|
|
52
|
+
|
|
53
|
+
- **TypeScript 重构与 v1 平滑升级**: v2.0.1, v2.0.0
|
|
53
54
|
- **实时监听 / 管理功能 / 核心功能**: v1.x 历史版本
|
|
54
|
-
|
|
55
|
-
### 按风险级别
|
|
56
|
-
|
|
55
|
+
|
|
56
|
+
### 按风险级别
|
|
57
|
+
|
|
57
58
|
- **P0 (Critical)**: v2.0.0
|
|
59
|
+
- **Patch**: v2.0.1
|
|
58
60
|
- **P1 (High)**: v1.x 破坏性或高风险历史版本
|
|
59
61
|
- **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
|
-
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## ✍️ 如何创建新的变更文档
|
|
66
|
+
|
|
67
|
+
### 步骤1: 复制模板
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
cp TEMPLATE.md v{版本号}.md
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 步骤2: 填写内容
|
|
74
|
+
|
|
75
|
+
根据模板章节填写变更信息:
|
|
76
|
+
- 版本信息
|
|
77
|
+
- 变更摘要
|
|
78
|
+
- 背景说明
|
|
79
|
+
- 变更内容
|
|
80
|
+
- 影响范围
|
|
81
|
+
- 详细变更清单
|
|
82
|
+
- 验证方法
|
|
83
|
+
|
|
84
|
+
### 步骤3: 更新主 CHANGELOG
|
|
85
|
+
|
|
84
86
|
在项目根目录的 `CHANGELOG.md` 中:
|
|
85
87
|
- 在"版本概览"表格最上方添加新行
|
|
86
88
|
- 格式:版本列和详情列指向当前发布版本的 `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
|
-
|
|
89
|
+
|
|
90
|
+
### 步骤4: 提交变更
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
git add CHANGELOG.md changelogs/v{版本号}.md
|
|
94
|
+
git commit -m "docs: 发布 v{版本号}"
|
|
95
|
+
git tag v{版本号}
|
|
96
|
+
git push origin main --tags
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 📚 模板说明
|
|
102
|
+
|
|
103
|
+
### TEMPLATE.md
|
|
104
|
+
|
|
105
|
+
`TEMPLATE.md` 是创建新版本文档的标准模板,包含:
|
|
106
|
+
|
|
107
|
+
- 完整的章节结构
|
|
108
|
+
- 占位符和示例
|
|
109
|
+
- 注释说明
|
|
110
|
+
- Markdown 格式规范
|
|
111
|
+
|
|
112
|
+
使用时请:
|
|
113
|
+
1. 复制模板文件
|
|
114
|
+
2. 重命名为对应版本号
|
|
115
|
+
3. 替换所有占位符
|
|
116
|
+
4. 删除不需要的可选章节
|
|
117
|
+
5. 补充完整的变更信息
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 📊 版本命名规范
|
|
122
|
+
|
|
123
|
+
遵循[语义化版本](https://semver.org/lang/zh-CN/):
|
|
124
|
+
|
|
125
|
+
### 格式: vMAJOR.MINOR.PATCH
|
|
126
|
+
|
|
127
|
+
- **MAJOR** - 不兼容的 API 变更
|
|
128
|
+
- **MINOR** - 向后兼容的新增功能
|
|
129
|
+
- **PATCH** - 向后兼容的问题修复
|
|
130
|
+
|
|
131
|
+
### 示例
|
|
132
|
+
|
|
133
|
+
- `v1.0.0` - 正式发布
|
|
134
|
+
- `v1.1.0` - 新增功能
|
|
135
|
+
- `v1.1.1` - Bug 修复
|
|
136
|
+
- `v2.0.0` - 破坏性变更
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 🔗 相关资源
|
|
141
|
+
|
|
140
142
|
- **主 CHANGELOG**: [../CHANGELOG.md](../CHANGELOG.md)
|
|
141
143
|
- **项目文档**: [GitHub docs](https://github.com/vextjs/monSQLize/tree/main/docs)
|
|
142
144
|
- **使用示例**: [GitHub examples](https://github.com/vextjs/monSQLize/tree/main/examples)
|
|
143
145
|
- **测试用例**: [GitHub test](https://github.com/vextjs/monSQLize/tree/main/test)
|
|
144
|
-
- **语义化版本**: https://semver.org/lang/zh-CN/
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
148
|
-
## 📋 变更文档清单
|
|
149
|
-
|
|
146
|
+
- **语义化版本**: https://semver.org/lang/zh-CN/
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 📋 变更文档清单
|
|
151
|
+
|
|
150
152
|
| 版本 | 文件 | 状态 | 发布日期 |
|
|
151
153
|
|------|------|------|---------|
|
|
152
|
-
| v2.0.
|
|
154
|
+
| v2.0.1 | v2.0.1.md | ✅ 已发布 | 2026-06-03 |
|
|
155
|
+
| v2.0.0 | v2.0.0.md | ✅ 已发布 | 2026-06-01 |
|
|
153
156
|
| v1.x | 仓库历史归档 | ✅ 已发布 | 2025-12-03 起 |
|
|
154
|
-
|
|
155
|
-
---
|
|
156
|
-
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
157
160
|
**目录版本**: 2.0
|
|
158
|
-
**最后更新**: 2026-06-
|
|
159
|
-
**维护者**: monSQLize Team
|
|
160
|
-
|
|
161
|
+
**最后更新**: 2026-06-03
|
|
162
|
+
**维护者**: monSQLize Team
|
|
163
|
+
|
package/changelogs/v2.0.0.md
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
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
|
-
|
|
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
20
|
## Compatibility Notes and Breaking Changes
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
### B1 — `SagaResult` shape documents v1/v2 aliases
|
|
23
23
|
|
|
24
24
|
`SagaResult` now exposes the runtime fields and the restored v1/v2 alias fields:
|
|
@@ -44,142 +44,142 @@ v2.0.0 is a full **TypeScript rewrite** of monSQLize. The public API is preserve
|
|
|
44
44
|
### B2 — `TransactionInfo.status` keeps the v1 `'started'` value
|
|
45
45
|
|
|
46
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 | ✅ |
|
|
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
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
|
-
|
|
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
183
|
### Type Declarations
|
|
184
184
|
- **`FindAndCountResult`**: includes `documents?: TSchema[]` optional backward-compat alias
|
|
185
185
|
- **`SagaResult`**: includes `completedStepNames?: string[]` (ordered step names, v1 compat) and `errorCause?: unknown`
|
|
@@ -210,13 +210,13 @@ All public API surface now carries complete English JSDoc:
|
|
|
210
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
211
|
|
|
212
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.
|
|
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.
|