dougong 0.0.2 → 0.0.3
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/README.md +100 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,16 +1,111 @@
|
|
|
1
1
|
# dougong
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[简体中文](#简体中文) · [English](#english)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 简体中文
|
|
8
|
+
|
|
9
|
+
**能力组合与结构化生命周期内核**,纯 JavaScript/TypeScript。
|
|
10
|
+
|
|
11
|
+
这是门面包,聚合 [`@dougongjs/core`](https://www.npmjs.com/package/@dougongjs/core)、[`@dougongjs/reactive`](https://www.npmjs.com/package/@dougongjs/reactive) 与 [`@dougongjs/platform`](https://www.npmjs.com/package/@dougongjs/platform)。它只做 re-export,不包含任何逻辑——架构门禁会强制这一点。
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install dougong
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createApp, definePlugin, service } from "dougong"
|
|
19
|
+
|
|
20
|
+
const CLOCK = service<Clock>("app/clock")
|
|
21
|
+
|
|
22
|
+
const clock = definePlugin({
|
|
23
|
+
name: "app.clock",
|
|
24
|
+
provides: { clock: CLOCK },
|
|
25
|
+
setup: () => ({ clock: { now: () => new Date() } }),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const greeter = definePlugin({
|
|
29
|
+
name: "app.greeter",
|
|
30
|
+
requires: { clock: CLOCK }, // 依赖写在这里
|
|
31
|
+
setup(ctx) {
|
|
32
|
+
console.log(ctx.clock.now()) // 只能读声明过的依赖,否则编译错误
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const app = createApp({ name: "hello" })
|
|
37
|
+
app.install(greeter) // 安装顺序不决定启动顺序
|
|
38
|
+
app.install(clock)
|
|
39
|
+
await app.start() // 从声明推导拓扑,同层并发启动
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
六个原子:**Service**(稳定的一对一能力)、**Extension**(开放贡献集合)、**Event**(瞬时事实)、**Lifetime**(结构化所有权)、**Plugin**、**Application**。
|
|
43
|
+
|
|
44
|
+
三条核心保证:依赖与所有权**显式**写在声明里;每个语义只有**一条**正式路径;事务只暴露**已提交**状态。
|
|
45
|
+
|
|
46
|
+
### 环境要求
|
|
47
|
+
|
|
48
|
+
Node.js ≥ 22 或等价的 ES2024 宿主。TypeScript 消费者需要:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
"lib": ["ES2024", "DOM", "DOM.Iterable", "ESNext.Disposable"]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## English
|
|
57
|
+
|
|
58
|
+
A **capability composition and structured lifetime kernel** in pure JavaScript/TypeScript.
|
|
59
|
+
|
|
60
|
+
This is the facade package aggregating [`@dougongjs/core`](https://www.npmjs.com/package/@dougongjs/core), [`@dougongjs/reactive`](https://www.npmjs.com/package/@dougongjs/reactive) and [`@dougongjs/platform`](https://www.npmjs.com/package/@dougongjs/platform). It only re-exports and contains no logic — an architecture gate enforces that.
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
npm install dougong
|
|
64
|
+
```
|
|
6
65
|
|
|
7
66
|
```ts
|
|
8
67
|
import { createApp, definePlugin, service } from "dougong"
|
|
68
|
+
|
|
69
|
+
const CLOCK = service<Clock>("app/clock")
|
|
70
|
+
|
|
71
|
+
const clock = definePlugin({
|
|
72
|
+
name: "app.clock",
|
|
73
|
+
provides: { clock: CLOCK },
|
|
74
|
+
setup: () => ({ clock: { now: () => new Date() } }),
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const greeter = definePlugin({
|
|
78
|
+
name: "app.greeter",
|
|
79
|
+
requires: { clock: CLOCK }, // the dependency lives here
|
|
80
|
+
setup(ctx) {
|
|
81
|
+
console.log(ctx.clock.now()) // only declared dependencies exist, or it fails to compile
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const app = createApp({ name: "hello" })
|
|
86
|
+
app.install(greeter) // install order does not decide start order
|
|
87
|
+
app.install(clock)
|
|
88
|
+
await app.start() // topology derived from declarations, layers start concurrently
|
|
9
89
|
```
|
|
10
90
|
|
|
11
|
-
-
|
|
12
|
-
|
|
91
|
+
Six atoms: **Service** (a stable one-to-one capability), **Extension** (an open contribution set), **Event** (a transient fact), **Lifetime** (structured ownership), **Plugin**, **Application**.
|
|
92
|
+
|
|
93
|
+
Three core guarantees: dependencies and ownership are written **explicitly** in declarations; every semantic has exactly **one** canonical path; transactions expose only **committed** state.
|
|
94
|
+
|
|
95
|
+
### Requirements
|
|
96
|
+
|
|
97
|
+
Node.js ≥ 22 or an equivalent ES2024 host. TypeScript consumers need:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
"lib": ["ES2024", "DOM", "DOM.Iterable", "ESNext.Disposable"]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
- 文档站 / Documentation: https://tangerg.github.io/dougong/
|
|
106
|
+
- 仓库 / Repository: https://github.com/Tangerg/dougong
|
|
13
107
|
|
|
14
|
-
> 早期开发阶段(0.0.x
|
|
108
|
+
> 早期开发阶段(0.0.x),当前不承诺向后兼容。
|
|
109
|
+
> Early development (0.0.x); no backward-compatibility promises yet.
|
|
15
110
|
|
|
16
111
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dougong",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dougongjs/core": "0.0.
|
|
22
|
-
"@dougongjs/
|
|
23
|
-
"@dougongjs/
|
|
21
|
+
"@dougongjs/core": "0.0.3",
|
|
22
|
+
"@dougongjs/reactive": "0.0.3",
|
|
23
|
+
"@dougongjs/platform": "0.0.3"
|
|
24
24
|
},
|
|
25
25
|
"description": "Capability composition and structured lifetime kernel, plus its plugin distribution layer.",
|
|
26
26
|
"license": "MIT",
|