@qilin-agent/kylin 0.0.0-stage → 4.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/LICENSE +21 -0
- package/README.md +104 -2
- package/bin.js +16 -0
- package/lib/index.js +1829 -0
- package/lib/types/context.d.ts +101 -0
- package/lib/types/context.d.ts.map +1 -0
- package/lib/types/events.d.ts +240 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/fiber.d.ts +202 -0
- package/lib/types/fiber.d.ts.map +1 -0
- package/lib/types/index.d.ts +17 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/logger.d.ts +105 -0
- package/lib/types/logger.d.ts.map +1 -0
- package/lib/types/reflect.d.ts +186 -0
- package/lib/types/reflect.d.ts.map +1 -0
- package/lib/types/registry.d.ts +201 -0
- package/lib/types/registry.d.ts.map +1 -0
- package/lib/types/service.d.ts +55 -0
- package/lib/types/service.d.ts.map +1 -0
- package/lib/types/utils.d.ts +62 -0
- package/lib/types/utils.d.ts.map +1 -0
- package/package.json +53 -3
- package/src/context.ts +146 -0
- package/src/events.ts +352 -0
- package/src/fiber.ts +754 -0
- package/src/index.ts +16 -0
- package/src/logger.ts +271 -0
- package/src/reflect.ts +418 -0
- package/src/registry.ts +337 -0
- package/src/service.ts +115 -0
- package/src/utils.ts +287 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Shigma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cordis
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cordis is a TypeScript plugin framework for applications that need explicit
|
|
4
|
+
dependency injection, scoped services, lifecycle-managed cleanup, and optional
|
|
5
|
+
configuration-driven loading. The core package is published as `cordis`; the
|
|
6
|
+
official packages in this repository add a loader, config-file includes, HMR,
|
|
7
|
+
console logging, timers, and project scaffolding.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
yarn add cordis
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Cordis is ESM-first. The repository is tested on current Node releases, and the
|
|
16
|
+
scaffolder requires Node 22 or newer.
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { Context, Service } from 'cordis'
|
|
22
|
+
|
|
23
|
+
declare module 'cordis' {
|
|
24
|
+
interface Context {
|
|
25
|
+
counter: Counter
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface Events {
|
|
29
|
+
'app/ready'(message: string): void
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class Counter extends Service {
|
|
34
|
+
value = 0
|
|
35
|
+
|
|
36
|
+
constructor(ctx: Context) {
|
|
37
|
+
super(ctx, 'counter')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
next() {
|
|
41
|
+
return ++this.value
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const greeter = Object.assign((ctx: Context) => {
|
|
46
|
+
ctx.on('app/ready', (message) => {
|
|
47
|
+
ctx.logger.info('%s #%d', message, ctx.counter.next())
|
|
48
|
+
})
|
|
49
|
+
}, {
|
|
50
|
+
inject: ['counter'],
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const root = new Context()
|
|
54
|
+
await root.plugin(Counter)
|
|
55
|
+
await root.plugin(greeter)
|
|
56
|
+
|
|
57
|
+
root.emit('app/ready', 'started')
|
|
58
|
+
await root.fiber.dispose()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The important pieces are:
|
|
62
|
+
|
|
63
|
+
- `new Context()` creates the root dependency container.
|
|
64
|
+
- `ctx.plugin()` starts a plugin and returns a `Fiber`.
|
|
65
|
+
- `inject` tells Cordis which services must exist before the plugin runs.
|
|
66
|
+
- Effects, event listeners, and services are removed when their owning fiber is
|
|
67
|
+
disposed.
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
|
|
71
|
+
- [Tutorial: build a plugin](../../docs/tutorials/build-a-plugin.md)
|
|
72
|
+
- [Guide: plugin lifecycle](../../docs/guides/plugin-lifecycle.md)
|
|
73
|
+
- [Guide: loader configuration](../../docs/guides/loader-config.md)
|
|
74
|
+
- [API reference](../../docs/api/core.md)
|
|
75
|
+
|
|
76
|
+
## Packages
|
|
77
|
+
|
|
78
|
+
| Package | Purpose |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `cordis` | Core context, plugin registry, fiber lifecycle, events, services, and logger. |
|
|
81
|
+
| `create-cordis` | Interactive project scaffolder. |
|
|
82
|
+
| `@cordisjs/plugin-loader` | Runtime plugin tree and loader service. |
|
|
83
|
+
| `@cordisjs/plugin-include` | YAML/JSON config-file include support for the loader. |
|
|
84
|
+
| `@cordisjs/plugin-group` | Nested plugin groups for loader configs. |
|
|
85
|
+
| `@cordisjs/plugin-hmr` | Hot module replacement for loader-managed plugins. |
|
|
86
|
+
| `@cordisjs/plugin-logger-console` | Console exporter for the built-in logger. |
|
|
87
|
+
| `@cordisjs/plugin-timer` | Disposal-aware timeout, interval, throttle, and debounce helpers. |
|
|
88
|
+
| `@cordisjs/utils` | Shared utilities used by Cordis packages. |
|
|
89
|
+
|
|
90
|
+
## Development
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
yarn install
|
|
94
|
+
yarn build
|
|
95
|
+
yarn test
|
|
96
|
+
yarn lint
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The monorepo uses Yakumo to build and test all packages. Most examples in the
|
|
100
|
+
docs use public APIs from `cordis`; loader examples additionally use
|
|
101
|
+
`@cordisjs/plugin-loader` and `@cordisjs/plugin-include`.
|
|
102
|
+
|
|
103
|
+
## Volatile configuration
|
|
104
|
+
|
|
105
|
+
Schemas may return `Volatile<T>` references, whose values are read through `.get()`. Cordis exports the consumer types; Loader commits volatile-only changes into the running references without restarting and notifies the owning fiber through `loader/volatile-update`. Direct `fiber.update()` retains its existing update waterfall and default restart.
|
package/bin.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Context } from '@qilin-agent/kylin'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
import Loader from '@qilin-agent/kylin-plugin-loader'
|
|
6
|
+
|
|
7
|
+
const ctx = new Context()
|
|
8
|
+
ctx.baseUrl = pathToFileURL(process.cwd()).href + '/'
|
|
9
|
+
|
|
10
|
+
await ctx.plugin(Loader)
|
|
11
|
+
await ctx.loader.create({
|
|
12
|
+
name: '@qilin-agent/kylin-plugin-include',
|
|
13
|
+
config: {
|
|
14
|
+
path: './cordis.yml',
|
|
15
|
+
},
|
|
16
|
+
})
|