@deepseek-ai/cordis-plugin-loader 1.0.3 → 1.0.5
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 +4 -0
- package/lib/index.js +149 -231
- package/lib/types/config/diff.d.ts +13 -0
- package/lib/types/config/diff.d.ts.map +1 -0
- package/lib/types/config/entry.d.ts +6 -5
- package/lib/types/config/entry.d.ts.map +1 -1
- package/lib/types/config/group.d.ts +3 -3
- package/lib/types/config/group.d.ts.map +1 -1
- package/lib/types/config/tree.d.ts +2 -5
- package/lib/types/config/tree.d.ts.map +1 -1
- package/lib/types/config/utils.d.ts +1 -1
- package/lib/types/config/utils.d.ts.map +1 -1
- package/lib/types/index.d.ts +13 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/config/diff.ts +45 -0
- package/src/config/entry.ts +84 -151
- package/src/config/group.ts +21 -60
- package/src/config/isolate.ts +2 -2
- package/src/config/tree.ts +10 -43
- package/src/config/utils.ts +1 -1
- package/src/index.ts +17 -8
package/src/config/tree.ts
CHANGED
|
@@ -39,27 +39,12 @@ export abstract class EntryTree {
|
|
|
39
39
|
.filter(isNonNullable)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* Wait until this tree has no active import or lifecycle tasks.
|
|
44
|
-
* @throws a settled fiber failure, or an aggregate when several fibers failed.
|
|
45
|
-
*/
|
|
42
|
+
/** Wait until this tree has no pending import or lifecycle tasks. */
|
|
46
43
|
async await() {
|
|
47
44
|
while (true) {
|
|
48
45
|
const tasks = this.getTasks()
|
|
49
|
-
if (tasks.length)
|
|
50
|
-
|
|
51
|
-
continue
|
|
52
|
-
}
|
|
53
|
-
const outcomes = await Promise.allSettled(
|
|
54
|
-
[...this.entries()].map(entry => entry._await()),
|
|
55
|
-
)
|
|
56
|
-
const failures = outcomes
|
|
57
|
-
.filter((outcome): outcome is PromiseRejectedResult => outcome.status === 'rejected')
|
|
58
|
-
.map(outcome => outcome.reason)
|
|
59
|
-
if (failures.length === 1) throw failures[0]
|
|
60
|
-
if (failures.length > 1) throw new AggregateError(failures, 'loader fibers failed')
|
|
61
|
-
this.ctx.reflect.notify(['loader'])
|
|
62
|
-
if (!this.getTasks().length) return
|
|
46
|
+
if (!tasks.length) return
|
|
47
|
+
await Promise.allSettled(tasks)
|
|
63
48
|
}
|
|
64
49
|
}
|
|
65
50
|
|
|
@@ -96,17 +81,15 @@ export abstract class EntryTree {
|
|
|
96
81
|
/** Create an entry in the root group or a nested group. */
|
|
97
82
|
async create(options: Omit<EntryOptions, 'id'>, parent: string | null = null, position = Infinity) {
|
|
98
83
|
const group = this.resolveGroup(parent)
|
|
99
|
-
|
|
100
|
-
const entry = this.resolve(id)
|
|
101
|
-
group.data.splice(position, 0, entry.options)
|
|
84
|
+
group.data.splice(position, 0, options as EntryOptions)
|
|
102
85
|
group.tree.write()
|
|
103
|
-
return
|
|
86
|
+
return group.create(options)
|
|
104
87
|
}
|
|
105
88
|
|
|
106
89
|
/** Stop and remove an entry from its parent group. */
|
|
107
|
-
|
|
90
|
+
remove(id: string) {
|
|
108
91
|
const entry = this.resolve(id)
|
|
109
|
-
|
|
92
|
+
entry.parent.remove(id)
|
|
110
93
|
entry.parent.tree.write()
|
|
111
94
|
}
|
|
112
95
|
|
|
@@ -114,31 +97,15 @@ export abstract class EntryTree {
|
|
|
114
97
|
async update(id: string, options: Omit<EntryOptions, 'id' | 'name'>, parent?: string | null, position?: number) {
|
|
115
98
|
const entry = this.resolve(id)
|
|
116
99
|
const source = entry.parent
|
|
117
|
-
const sourceIndex = source.data.indexOf(entry.options)
|
|
118
|
-
let target = source
|
|
119
100
|
if (parent !== undefined) {
|
|
120
|
-
target = this.resolveGroup(parent)
|
|
101
|
+
const target = this.resolveGroup(parent)
|
|
121
102
|
source.unlink(entry.options)
|
|
122
103
|
target.data.splice(position ?? Infinity, 0, entry.options)
|
|
104
|
+
target.tree.write()
|
|
123
105
|
entry.parent = target
|
|
124
106
|
}
|
|
125
|
-
try {
|
|
126
|
-
await entry.update(options, false, true)
|
|
127
|
-
} catch (error) {
|
|
128
|
-
if (parent !== undefined) {
|
|
129
|
-
target.unlink(entry.options)
|
|
130
|
-
source.data.splice(sourceIndex < 0 ? source.data.length : sourceIndex, 0, entry.options)
|
|
131
|
-
entry.parent = source
|
|
132
|
-
try {
|
|
133
|
-
await entry.update({}, false, true)
|
|
134
|
-
} catch (rollbackError) {
|
|
135
|
-
throw new AggregateError([error, rollbackError], `failed to roll back loader entry move ${id}`)
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
throw error
|
|
139
|
-
}
|
|
140
107
|
source.tree.write()
|
|
141
|
-
|
|
108
|
+
return entry.update(options, false, true)
|
|
142
109
|
}
|
|
143
110
|
|
|
144
111
|
/** Import a plugin module from a specifier or `cordis:` builtin. */
|
package/src/config/utils.ts
CHANGED
|
@@ -8,7 +8,7 @@ export const evaluate = new Function('ctx', 'expr', `
|
|
|
8
8
|
}
|
|
9
9
|
`) as ((ctx: object, expr: string) => any)
|
|
10
10
|
|
|
11
|
-
/** Recursively replace YAML
|
|
11
|
+
/** Recursively replace YAML `!!js` expression nodes with evaluated values. */
|
|
12
12
|
export function interpolate(ctx: object, value: any) {
|
|
13
13
|
if (isJsExpr(value)) {
|
|
14
14
|
return evaluate(ctx, value.__jsExpr)
|
package/src/index.ts
CHANGED
|
@@ -26,7 +26,19 @@ declare module '@deepseek-ai/cordis' {
|
|
|
26
26
|
'loader/config-update'(): void
|
|
27
27
|
'loader/entry-init'(entry: Entry): void
|
|
28
28
|
'loader/partial-dispose'(entry: Entry, legacy: Partial<EntryOptions>, active: boolean): void
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Volatile config values were committed into the running fiber without a remount; dispatched to the owning fiber only.
|
|
31
|
+
* @param paths - changed config paths as key arrays; every value is committed before dispatch.
|
|
32
|
+
* @mode emit
|
|
33
|
+
*/
|
|
34
|
+
'loader/volatile-update'(paths: readonly (readonly string[])[]): void
|
|
35
|
+
/**
|
|
36
|
+
* Refresh entry context before applying config.
|
|
37
|
+
* @param entry - entry containing the new raw config and optional current fiber.
|
|
38
|
+
* @param next - continue context refresh and Loader's config update.
|
|
39
|
+
* @mode waterfall
|
|
40
|
+
*/
|
|
41
|
+
'loader/patch-context'(entry: Entry, next: () => void): void
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
interface Context {
|
|
@@ -100,12 +112,12 @@ export class Loader extends EntryTree {
|
|
|
100
112
|
return interpolate(this.ctx, config)
|
|
101
113
|
}, { global: true })
|
|
102
114
|
|
|
103
|
-
ctx.on('internal/update',
|
|
115
|
+
ctx.on('internal/update', function (config, noSave, next) {
|
|
104
116
|
if (!this.entry || noSave || this.parent.fiber?.entry === this.entry) return next()
|
|
105
|
-
await next()
|
|
106
117
|
const unparse = this.runtime?.Config?.['simplify']
|
|
107
|
-
this.entry.options.config = unparse ? unparse(config) : config
|
|
118
|
+
this.entry.options.config = unparse ? unparse.call(this.runtime!.Config, config) : config
|
|
108
119
|
this.entry.parent.tree.write()
|
|
120
|
+
return next()
|
|
109
121
|
}, { global: true, prepend: true })
|
|
110
122
|
|
|
111
123
|
ctx.on('internal/update', function (config, _, next) {
|
|
@@ -143,12 +155,9 @@ export class Loader extends EntryTree {
|
|
|
143
155
|
const treeOwner = fiber.entry.parent.tree.ctx.fiber
|
|
144
156
|
if (!treeOwner.uid || treeOwner.state === FiberState.UNLOADING) return
|
|
145
157
|
|
|
146
|
-
// case 6: Loader is replacing or removing this exact fiber
|
|
147
|
-
if (fiber.entry._disposing) return
|
|
148
|
-
|
|
149
158
|
this.showLog(fiber.entry, 'unload')
|
|
150
159
|
|
|
151
|
-
// case
|
|
160
|
+
// case 6: fiber is disposed by loader behavior
|
|
152
161
|
// such as inject checker, config file update, ancestor group disable
|
|
153
162
|
if (fiber.entry.disabled) return
|
|
154
163
|
|