Skip to content

Commit 6c00815

Browse files
committed
fix: preserve v1 smooth-upgrade compatibility
1 parent 52aa98a commit 6c00815

23 files changed

Lines changed: 584 additions & 78 deletions

‎.github/workflows/publish.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
version:
1010
description: "Version to publish. Must match package.json."
1111
required: true
12-
default: "2.0.0"
12+
default: "2.0.1"
1313

1414
concurrency:
1515
group: publish-${{ github.ref }}

‎CHANGELOG.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# CHANGELOG
22

3-
> Summary index — current release details are packaged in [changelogs/v2.0.0.md](./changelogs/v2.0.0.md); historical details live in the repository changelog archive.
4-
> **Last updated**: 2026-06-01
3+
> Summary index — current release details are packaged in [changelogs/v2.0.1.md](./changelogs/v2.0.1.md); historical details live in the repository changelog archive.
4+
> **Last updated**: 2026-06-03
55
66
---
77

88
## Version Overview
99

1010
| Version | Date | Summary | Details |
1111
|---------|------|---------|---------|
12+
| [v2.0.1](./changelogs/v2.0.1.md) | 2026-06-03 | Patch: model collection/pool compatibility, automatic-index task dedupe, runtime cache/pool v1 smooth-upgrade fixes, and current docs/types alignment | [View](./changelogs/v2.0.1.md) |
1213
| [v2.0.0](./changelogs/v2.0.0.md) | 2026-06-01 | 🎉 **v2.0.0 — TypeScript rewrite**: full TypeScript source, cache-hub integration, schema-dsl `^2.0.3` TS dependency, Apache-2.0 licensing, English README, MultiLevel cache support, v1 API compat preserved, optimized npm artifact boundary without default sourcemaps, JSDoc coverage complete, `getPoolStats/getPoolHealth` keyed by pool name, v1 compat fixes included, workspace smooth-upgrade bridge validated for downstream consumers | [View](./changelogs/v2.0.0.md) |
1314
| [v1.3.0](https://github.com/vextjs/monSQLize/blob/main/changelogs/v1.3.0.md) | 2026-04-27 | 🆕 **新功能**:链式池访问 API — `pool(name)` / `use(dbName)` / `scopedCollection()` / `scopedModel()` 四个公开方法,支持多连接池多数据库路由,connection 合并语义,TypeScript 类型签名完整覆盖 | [查看](https://github.com/vextjs/monSQLize/blob/main/changelogs/v1.3.0.md) |
1415
| [v1.2.3](https://github.com/vextjs/monSQLize/blob/main/changelogs/v1.2.3.md) | 2026-04-26 | 🐛 **Bug Fix**:`model()` 方法修复注册 key 直接作为 MongoDB 集合名的问题,优先读 `definition.collection > definition.name`,注册 key 仅作 fallback,向后兼容 | [查看](https://github.com/vextjs/monSQLize/blob/main/changelogs/v1.2.3.md) |
@@ -443,7 +444,8 @@ const result = await msq.collection('orders').insertOne(dataFromMongoose);
443444
changelogs/
444445
├── README.md # 变更文档说明
445446
├── TEMPLATE.md # 变更文档模板
446-
├── v2.0.0.md # 当前发布详细变更
447+
├── v2.0.1.md # 当前发布详细变更
448+
├── v2.0.0.md # v2 TypeScript 重写发布详细变更
447449
└── v1.x.y.md # 历史版本详细变更(仓库归档)
448450
```
449451

@@ -494,11 +496,11 @@ changelogs/
494496

495497
## 相关文档
496498

497-
- [changelogs/v2.0.0.md](./changelogs/v2.0.0.md) - 当前发布详细变更文档
499+
- [changelogs/v2.0.1.md](./changelogs/v2.0.1.md) - 当前发布详细变更文档
498500
- [README.md](./README.md) - 项目说明
499501
- [docs/](https://github.com/vextjs/monSQLize/blob/main/docs/index.md) - API 文档
500502

501503
---
502504

503-
**最后更新**: 2026-06-01
505+
**最后更新**: 2026-06-03
504506

‎README.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ const user = await users.findOne({ email });
423423
const list = await users.find({ status: 'active' }).toArray();
424424
```
425425

426-
The current v2.0.0 release candidate has been validated against the workspace consumers `chat`, `payment`, `user`, `admin`, `search`, `vext`, and `permission-core` without requiring business-source changes in those projects.
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.
427427

428428
## Compatibility
429429

@@ -490,7 +490,7 @@ npm run test:real-env:private
490490

491491
## Release Status
492492

493-
The current release candidate is `v2.0.0`.
493+
The current published release is `v2.0.1`.
494494

495495
Key release-readiness points:
496496

@@ -503,6 +503,11 @@ Key release-readiness points:
503503

504504
## Roadmap
505505

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+
506511
### v2.0.0
507512

508513
- TypeScript-native runtime and declarations.

‎changelogs/README.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
changelogs/
1111
├── README.md # 本说明文档
1212
├── TEMPLATE.md # 变更文档模板
13+
├── v2.0.1.md # v2.0.1 详细变更
1314
├── v2.0.0.md # v2.0.0 详细变更
1415
└── v1.x.y.md # 历史版本详细变更(仓库归档)
1516
```
@@ -43,18 +44,19 @@ changelogs/
4344

4445
### 按版本类型
4546

46-
- **正式发布**: v2.0.0, v1.0.0
47+
- **正式发布**: v2.0.1, v2.0.0, v1.0.0
4748
- **功能版本**: v1.x
4849
- **修复版本**: v1.x.y
4950

5051
### 按功能领域
5152

52-
- **TypeScript 重构与 v1 平滑升级**: v2.0.0
53+
- **TypeScript 重构与 v1 平滑升级**: v2.0.1, v2.0.0
5354
- **实时监听 / 管理功能 / 核心功能**: v1.x 历史版本
5455

5556
### 按风险级别
5657

5758
- **P0 (Critical)**: v2.0.0
59+
- **Patch**: v2.0.1
5860
- **P1 (High)**: v1.x 破坏性或高风险历史版本
5961
- **P2 (Low)**: v1.x 修复版本
6062

@@ -149,12 +151,13 @@ git push origin main --tags
149151

150152
| 版本 | 文件 | 状态 | 发布日期 |
151153
|------|------|------|---------|
152-
| v2.0.0 | v2.0.0.md | ✅ 待发布候选 | 2026-06-01 |
154+
| v2.0.1 | v2.0.1.md | ✅ 已发布 | 2026-06-03 |
155+
| v2.0.0 | v2.0.0.md | ✅ 已发布 | 2026-06-01 |
153156
| v1.x | 仓库历史归档 | ✅ 已发布 | 2025-12-03 起 |
154157

155158
---
156159

157160
**目录版本**: 2.0
158-
**最后更新**: 2026-06-01
161+
**最后更新**: 2026-06-03
159162
**维护者**: monSQLize Team
160163

‎changelogs/v2.0.1.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# v2.0.1 — 2026-06-03
2+
3+
## Overview
4+
5+
v2.0.1 is a compatibility and documentation patch for the v2 TypeScript line. It preserves the v2.0.0 public package shape while tightening v1 smooth-upgrade behavior and aligning the published documentation with the current runtime.
6+
7+
---
8+
9+
## Fixes
10+
11+
- **Model routing:** `definition.collection` is now used as the actual MongoDB collection name, with `definition.name` and the registered model name as fallbacks.
12+
- **Model pool scope:** Model connection metadata now routes through the configured pool and database when creating scoped collections.
13+
- **Model cache identity:** Model instance cache keys include pool, database, registered model name, and actual collection name to avoid cross-scope reuse.
14+
- **Populate compatibility:** `relations.from` resolves registered Model names to their actual MongoDB collection names, while still allowing direct collection names when no registered Model exists.
15+
- **Automatic indexes:** Model index creation is deduplicated per runtime / pool / database / collection / index fingerprint; pending and fulfilled tasks are reused, while failed tasks may retry.
16+
- **Cache compatibility:** Runtime cache option normalization preserves v1 aliases and millisecond TTL semantics.
17+
- **Pool compatibility:** Pool selector operation names accept v1-style string inputs.
18+
19+
---
20+
21+
## Documentation and Types
22+
23+
- Added `ModelDefinition.collection` and `ModelDefinition.name` to the public type surface.
24+
- Documented the actual automatic-index flow: `connect()` only registers models; `ModelInstance` creation schedules per-index `createIndex()` calls; no `listIndexes()` preflight is performed.
25+
- Updated the current release status, API index count, examples count, and advanced capability index entries.
26+
- Kept historical changelog archive links unchanged; current published package links remain clean.
27+
28+
---
29+
30+
## Validation
31+
32+
- `npm run build`
33+
- `npm run type-check`
34+
- `npm run lint`
35+
- `npm run test:runtime`
36+
- `npm run test:compatibility`
37+
- `npm run check:sizes:strict`
38+
- `npm run test:examples`
39+
- `npm pack --json --dry-run`

‎docs/api-index.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@
190190

191191
---
192192

193-
**文档总数**: 85个
194-
**最后更新**: 2025-01-06
193+
**文档总数**: 96个
194+
**最后更新**: 2026-06-03
195195
**新增**:
196196
- ✨ esm-support.md - ES Module (import) 支持
197197
- ✨ findOneAnd-return-value-unified.md - 返回值统一说明
198-

‎docs/capability-index.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@
6969
- slow-query-log:manager / queue / runtime façade
7070
- saga:orchestrator / runtime façade
7171

72-
当前 `docs/**` 先只提供能力索引,不在本轮把这三类能力全部展开成独立专题。
72+
当前仓库已提供这些能力的专题入口与可执行示例:
73+
74+
- sync:`docs/sync-backup.md`,示例 `examples/docs/sync.ts`、`examples/docs/sync-target-failure.ts`
75+
- slow-query-log:`docs/slow-query-log.md`,示例 `examples/docs/slow-query-log.ts`
76+
- saga:`docs/saga-transaction.md`、`docs/saga-advanced.md`,示例 `examples/docs/saga.ts`
77+
78+
后续扩展重点是继续补充运行时故障注入、真实部署拓扑与性能边界,而不是补缺基础入口。
7379

7480
## 5. 当前仓库内的推荐入口
7581

‎docs/examples.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
文档站中的每个核心 API,都应尽量对应到**当前仓库内可直接运行的示例**。
44

5-
> 当前官方示例总览见 [`../examples/README.md`](../examples/README.md),其中 `npm run test:examples` 会统一编译并执行当前 **44 个** TypeScript 示例。
5+
> 当前官方示例总览见 [`../examples/README.md`](../examples/README.md),其中 `npm run test:examples` 会统一编译并执行当前 **43 个** TypeScript 示例;`examples/helpers/bootstrap.ts` 是辅助模块,不单独执行。
66
77
## 运行方式
88

‎docs/model.md‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ if (user.checkPassword('secret123')) {
6565
**参数**:
6666
- `collectionName` - 集合名称
6767
- `definition` - Model 定义
68+
- `collection` - 实际 MongoDB 集合名;不填时依次回退到 `name` 与 `collectionName`
69+
- `name` - Model 自动加载文件中的兼容集合名;`collection` 优先级更高
6870
- `schema` (必需) - Schema 定义
6971
- `enums` - 枚举配置
7072
- `methods` - 自定义方法
@@ -76,6 +78,8 @@ if (user.checkPassword('secret123')) {
7678

7779
```javascript
7880
Model.define('users', {
81+
// 可选:把注册名与实际 MongoDB 集合名分开
82+
// collection: 'app_users',
7983
enums: {
8084
role: 'admin|user|guest'
8185
},
@@ -253,7 +257,11 @@ Model.define('users', newDefinition);
253257

254258
获取 Model 实例。
255259

256-
> **缓存行为**(v1.2.1+):同一 `collectionName` 多次调用 `msq.model()` 返回**同一 ModelInstance 实例**。索引仅在首次创建实例时触发一次 `createIndexes` 命令。
260+
> **缓存行为**(v1.2.1+):同一 runtime / pool / database / 注册名 / 实际集合名 / 定义版本下,多次调用 `msq.model()` 返回同一 `ModelInstance` 实例。
261+
> - 首次创建实例时会调度 Model 自动索引;每个索引实际调用一次 `createIndex()`,同一进程内 pending / fulfilled 的索引任务会去重
262+
> - `connect()` 只加载与注册 Model 定义,不会单独创建 `ModelInstance`,也不会单独触发索引创建
263+
> - 进程重启后内存任务表清空,首次使用对应 Model 时会再次发送 `createIndex()` ensure 命令;相同索引定义由 MongoDB 驱动/服务端按幂等语义处理
264+
> - 自动索引不会先调用 `listIndexes()` 预检;索引定义冲突时由 MongoDB 抛错
257265
> - `Model.redefine()` 或 `Model.undefine()` 后,下次调用 `msq.model()` 自动获取新定义的实例
258266
> - `Model._clear()` 后(v1.2.2 修复),所有已注册 Model 的缓存均自动失效,下次调用 `msq.model()` 重建实例
259267
> - `msq.close()` 后全部缓存清空
@@ -288,6 +296,32 @@ if (!result.valid) {
288296

289297
---
290298

299+
## 注册名与实际集合名
300+
301+
`Model.define(collectionName, definition)` 的第一个参数是注册名,也是调用 `msq.model(collectionName)` 时使用的名称。运行时访问 MongoDB 时会按以下顺序解析实际集合名:
302+
303+
1. `definition.collection`
304+
2. `definition.name`
305+
3. `Model.define()` 的 `collectionName`
306+
307+
```javascript
308+
Model.define('UserModel', {
309+
collection: 'users',
310+
schema: (dsl) => dsl({
311+
username: 'string!'
312+
})
313+
});
314+
315+
const User = msq.model('UserModel'); // 使用注册名获取 Model
316+
await User.insertOne({ username: 'alice' }); // 实际写入 MongoDB users 集合
317+
```
318+
319+
`definition.name` 主要兼容自动加载文件格式;在手动注册时优先使用 `collection` 表达实际集合名。Model 实例缓存键同时包含 pool、database、注册名和实际集合名,避免不同路由或不同实际集合复用同一个实例。
320+
321+
如果 `relations.from` 指向一个已注册 Model,populate 会使用该 Model 的实际集合名;如果没有同名 Model,则把 `from` 当作原始集合名使用。这样既兼容 v1 常见的“按 Model 名引用关系”,也保留直接写 MongoDB 集合名的方式。
322+
323+
---
324+
291325
## 数据源绑定(v1.2.2+)
292326

293327
通过 `Model.define()` 的 `connection` 字段,将 Model 绑定到指定连接池和/或数据库,实现多数据源路由。
@@ -831,6 +865,14 @@ indexes: [
831865
]
832866
```
833867

868+
自动索引只在 `ModelInstance` 创建时调度,不会在每次查询或每次请求时重复创建。同一进程内,monSQLize 会按 runtime / pool / database / collection / index 指纹记录索引任务:任务处于 pending 或 fulfilled 状态时会跳过重复调度;失败任务允许下次重新调度。
869+
870+
该流程不会先读取 `listIndexes()` 做数据库预检,而是直接调用 MongoDB `createIndex()`。因此:
871+
872+
- 相同索引定义通常会被 MongoDB 幂等处理
873+
- 索引选项冲突、同名冲突等问题会由 MongoDB 返回错误
874+
- 如果业务需要在手动索引管理前做差异化判断,可先调用 `listIndexes()` 再决定是否调用 `createIndex()` / `createIndexes()`
875+
834876
---
835877

836878
### 5. enums - 枚举配置

‎examples/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Runnable TypeScript examples for every major monSQLize API.
44
Each file uses an in-memory MongoDB server (`mongodb-memory-server`) — no real database needed.
55

6-
> 当前共 **44 个**可执行 TypeScript 示例,统一由 `npm run test:examples` 编译并执行。
6+
> 当前共 **43 个**可执行 TypeScript 示例,另有 `examples/helpers/bootstrap.ts` 作为示例辅助模块;可执行示例统一由 `npm run test:examples` 编译并执行。
77
88
## Prerequisites
99

0 commit comments

Comments
 (0)