@deepseek-ai/cordis-plugin-loader 1.0.7-alpha.1 → 1.0.7-alpha.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/README.md +8 -0
- package/lib/index.js +134 -57
- package/lib/types/config/entry.d.ts +1 -1
- package/lib/types/config/entry.d.ts.map +1 -1
- package/lib/types/config/group.d.ts.map +1 -1
- package/lib/types/config/isolate.d.ts.map +1 -1
- package/lib/types/config/tree.d.ts +31 -2
- package/lib/types/config/tree.d.ts.map +1 -1
- package/lib/types/index.d.ts +7 -7
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/config/entry.ts +15 -15
- package/src/config/group.ts +4 -5
- package/src/config/isolate.ts +10 -7
- package/src/config/tree.ts +77 -8
- package/src/index.ts +39 -31
package/README.md
CHANGED
|
@@ -61,3 +61,11 @@ Node module internals are classified by their available APIs, including the v1 A
|
|
|
61
61
|
## Volatile configuration
|
|
62
62
|
|
|
63
63
|
`Entry.update` compares raw entry options strictly; when only `config` changed on an active fiber in an unchanged context, the pure `equalExceptVolatile` function in `config/diff.ts` compares the raw configs using Schemastery metadata. It ignores volatile fields at fixed object paths without executing expressions, validators or `internal/config` hooks. Object nodes use their declared defaults for null or absent values, including objects without volatile fields; equivalent defaults skip updates. Other ordinary values, parent expressions and unknown fields retain raw comparison. Recursive schema backedges use raw comparison. Entry passes the actual plugin schema; a non-Schemastery schema compares raw. Context changes, other option changes and pending fibers use ordinary updates. A volatile-only change retains the raw Fiber config for later activation, then `_commitVolatile` parses it through the fiber's `internal/config` hook and schema, commits the new values into the running references when every ordinary effective value still matches, and emits `loader/volatile-update` to the owning fiber with the changed paths. A changed ordinary effective value uses the ordinary remount with a debug log naming the entry; because strict comparison treats class instances other than URL, Date and RegExp by identity, an ordinary field whose transform builds a fresh instance on every parse always takes that remount. An invalid candidate is logged and leaves the running references unchanged. A throwing `loader/volatile-update` listener is logged and does not fail the update; the values are already committed. Group/Include retain child dispatch, and programmatic Fiber updates preserve saving and `noSave`; `simplify` is called with its schema receiver so saved config contains plain values.
|
|
64
|
+
|
|
65
|
+
## Update completion
|
|
66
|
+
|
|
67
|
+
Entry updates await `loader/patch-context`, the Fiber update waterfall and disabled-entry disposal. Combined context/config changes refresh required bindings before restarting. Group and Include updates expose completion of their child updates; file persistence completes through Include’s `flush()`.
|
|
68
|
+
|
|
69
|
+
## Tree mutation reports
|
|
70
|
+
|
|
71
|
+
`EntryTree.commit(change)` receives each mutation made through `EntryTree` methods synchronously after options and group membership change; file-driven `EntryGroup` reconciliation does not report. A missing `legacy` means creation; missing `options` means removal. Updates carry both, with `from` naming the previous group after a move within the tree; a move into another tree transfers the registrations of the entry and its group members, reports a removal to the source tree and a creation to the destination tree, and is rejected when the destination tree already holds the id. Explicit Fiber saves report their simplified configuration. File-driven reconciliation, parent teardown and Loader removal do not produce spurious self-disable reports. In-memory trees implement a no-op; Include journals the reports and reconciles them with file edits. Explicit entry ids may contain `:`; `resolve()` cannot address such entries by nested path, because `:` separates nested tree paths.
|
package/lib/index.js
CHANGED
|
@@ -73,10 +73,10 @@ var EntryGroup = class {
|
|
|
73
73
|
}
|
|
74
74
|
remove(id, isDispose = false) {
|
|
75
75
|
const entry = this.tree.store[id];
|
|
76
|
-
if (!entry) return;
|
|
76
|
+
if (!entry || entry.parent !== this) return;
|
|
77
|
+
delete this.tree.store[id];
|
|
77
78
|
entry.fiber?.dispose();
|
|
78
79
|
if (!isDispose) this.unlink(entry.options);
|
|
79
|
-
delete this.tree.store[id];
|
|
80
80
|
this.context.emit("loader/partial-dispose", entry, entry.options, false);
|
|
81
81
|
}
|
|
82
82
|
async update(config) {
|
|
@@ -109,9 +109,7 @@ var Group = class extends EntryGroup {
|
|
|
109
109
|
super(ctx, ctx.fiber.entry.parent.tree);
|
|
110
110
|
this.ctx = ctx;
|
|
111
111
|
this.config = config;
|
|
112
|
-
ctx.on("internal/update", (config) =>
|
|
113
|
-
this.update(config);
|
|
114
|
-
});
|
|
112
|
+
ctx.on("internal/update", (config) => this.update(config));
|
|
115
113
|
}
|
|
116
114
|
async *[Service.init]() {
|
|
117
115
|
yield () => this.stop();
|
|
@@ -187,6 +185,18 @@ var __rewriteRelativeImportExtension = function(path, preserveJsx) {
|
|
|
187
185
|
});
|
|
188
186
|
return path;
|
|
189
187
|
};
|
|
188
|
+
/** The entry and the same-tree members of its group, recursively. */
|
|
189
|
+
function members(entry) {
|
|
190
|
+
const { tree } = entry.parent;
|
|
191
|
+
const result = [entry];
|
|
192
|
+
const group = entry.subgroup;
|
|
193
|
+
if (group?.tree !== tree) return result;
|
|
194
|
+
for (const options of group.data) {
|
|
195
|
+
const member = tree.store[options.id];
|
|
196
|
+
if (member?.parent === group) result.push(...members(member));
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
190
200
|
/** Mutable tree of loader entries. Persistence is supplied by subclasses. */
|
|
191
201
|
var EntryTree = class EntryTree {
|
|
192
202
|
static sep = ":";
|
|
@@ -223,6 +233,13 @@ var EntryTree = class EntryTree {
|
|
|
223
233
|
await Promise.allSettled(tasks);
|
|
224
234
|
}
|
|
225
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Assign a random tree-local id when `options.id` is absent. Explicit ids
|
|
238
|
+
* may contain `EntryTree.sep`; `resolve()` and `resolveGroup()` cannot
|
|
239
|
+
* address such entries by nested path.
|
|
240
|
+
* @param options - Entry options; a generated id is written to `options.id`.
|
|
241
|
+
* @returns The existing or generated id.
|
|
242
|
+
*/
|
|
226
243
|
ensureId(options) {
|
|
227
244
|
if (!options.id) do
|
|
228
245
|
options.id = Math.random().toString(16).slice(2, 10);
|
|
@@ -251,29 +268,71 @@ var EntryTree = class EntryTree {
|
|
|
251
268
|
/** Create an entry in the root group or a nested group. */
|
|
252
269
|
async create(options, parent = null, position = Infinity) {
|
|
253
270
|
const group = this.resolveGroup(parent);
|
|
271
|
+
const id = group.tree.ensureId(options);
|
|
254
272
|
group.data.splice(position, 0, options);
|
|
255
|
-
group.tree.
|
|
273
|
+
group.tree.commit({
|
|
274
|
+
id,
|
|
275
|
+
group,
|
|
276
|
+
options
|
|
277
|
+
});
|
|
256
278
|
return group.create(options);
|
|
257
279
|
}
|
|
258
280
|
/** Stop and remove an entry from its parent group. */
|
|
259
281
|
remove(id) {
|
|
260
282
|
const entry = this.resolve(id);
|
|
261
|
-
entry.parent
|
|
262
|
-
entry.
|
|
283
|
+
const group = entry.parent;
|
|
284
|
+
const legacy = entry.options;
|
|
285
|
+
group.remove(legacy.id);
|
|
286
|
+
group.tree.commit({
|
|
287
|
+
id: legacy.id,
|
|
288
|
+
group,
|
|
289
|
+
legacy
|
|
290
|
+
});
|
|
263
291
|
}
|
|
264
292
|
/** Update an entry and optionally move it to another group. */
|
|
265
293
|
async update(id, options, parent, position) {
|
|
266
294
|
const entry = this.resolve(id);
|
|
267
295
|
const source = entry.parent;
|
|
296
|
+
const legacy = { ...entry.options };
|
|
268
297
|
if (parent !== void 0) {
|
|
269
298
|
const target = this.resolveGroup(parent);
|
|
299
|
+
const moved = target.tree === source.tree ? [] : members(entry);
|
|
300
|
+
for (const member of moved) {
|
|
301
|
+
const { id } = member.options;
|
|
302
|
+
if (target.tree.store[id]) throw new Error(`entry ${id} already exists in the target tree`);
|
|
303
|
+
}
|
|
270
304
|
source.unlink(entry.options);
|
|
271
305
|
target.data.splice(position ?? Infinity, 0, entry.options);
|
|
272
|
-
target.tree.write();
|
|
273
306
|
entry.parent = target;
|
|
307
|
+
for (const member of moved) {
|
|
308
|
+
delete source.tree.store[member.options.id];
|
|
309
|
+
target.tree.store[member.options.id] = member;
|
|
310
|
+
if (member.subgroup?.tree === source.tree) member.subgroup.tree = target.tree;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const task = entry.update(options, false, true);
|
|
314
|
+
if (entry.parent.tree !== source.tree) {
|
|
315
|
+
source.tree.commit({
|
|
316
|
+
id: legacy.id,
|
|
317
|
+
group: source,
|
|
318
|
+
legacy
|
|
319
|
+
});
|
|
320
|
+
entry.parent.tree.commit({
|
|
321
|
+
id: legacy.id,
|
|
322
|
+
group: entry.parent,
|
|
323
|
+
options: entry.options
|
|
324
|
+
});
|
|
325
|
+
} else {
|
|
326
|
+
const from = entry.parent === source ? void 0 : source;
|
|
327
|
+
entry.parent.tree.commit({
|
|
328
|
+
id: legacy.id,
|
|
329
|
+
group: entry.parent,
|
|
330
|
+
from,
|
|
331
|
+
options: entry.options,
|
|
332
|
+
legacy
|
|
333
|
+
});
|
|
274
334
|
}
|
|
275
|
-
|
|
276
|
-
return entry.update(options, false, true);
|
|
335
|
+
return task;
|
|
277
336
|
}
|
|
278
337
|
/** Import a plugin module from a specifier or `cordis:` builtin. */
|
|
279
338
|
import(name, getOuterStack) {
|
|
@@ -405,7 +464,7 @@ var Entry = class Entry {
|
|
|
405
464
|
if (this.options.group) return false;
|
|
406
465
|
let entry = this;
|
|
407
466
|
do {
|
|
408
|
-
if (this.
|
|
467
|
+
if (this._resolveDisabled(entry.options)) return true;
|
|
409
468
|
entry = entry.parent.ctx.fiber.entry;
|
|
410
469
|
} while (entry);
|
|
411
470
|
return false;
|
|
@@ -414,16 +473,20 @@ var Entry = class Entry {
|
|
|
414
473
|
* Effective disabled state: a `!!js` expression evaluates against the loader
|
|
415
474
|
* context. The raw node stays in the options, so write-back keeps the form.
|
|
416
475
|
*/
|
|
417
|
-
|
|
476
|
+
_resolveDisabled(options) {
|
|
418
477
|
return isJsExpr(options.disabled) ? Boolean(this.evaluate(options.disabled.__jsExpr)) : Boolean(options.disabled);
|
|
419
478
|
}
|
|
420
479
|
evaluate(expr) {
|
|
421
480
|
return evaluate(this.ctx, expr);
|
|
422
481
|
}
|
|
423
|
-
_patchContext(diff) {
|
|
424
|
-
this.context.waterfall("loader/patch-context", this, () => {
|
|
482
|
+
async _patchContext(diff) {
|
|
483
|
+
await this.context.waterfall("loader/patch-context", this, async () => {
|
|
425
484
|
Object.setPrototypeOf(this.ctx, this.parent.ctx);
|
|
426
|
-
if (this.fiber?.uid && (diff.includes("config") || this.options.group))
|
|
485
|
+
if (this.fiber?.uid && (diff.includes("config") || this.options.group)) {
|
|
486
|
+
const fiber = this.fiber.ctx.fiber;
|
|
487
|
+
for (const name of Object.keys(fiber.inject)) fiber._checkImpl(name);
|
|
488
|
+
await fiber.update(this.options.config, true);
|
|
489
|
+
}
|
|
427
490
|
});
|
|
428
491
|
}
|
|
429
492
|
async refresh() {
|
|
@@ -439,7 +502,7 @@ var Entry = class Entry {
|
|
|
439
502
|
else this.options[key] = value;
|
|
440
503
|
sortKeys(this.options);
|
|
441
504
|
if (this.disabled) {
|
|
442
|
-
this.fiber?.dispose();
|
|
505
|
+
await this.fiber?.dispose();
|
|
443
506
|
return;
|
|
444
507
|
}
|
|
445
508
|
if (this.fiber?.uid) {
|
|
@@ -452,7 +515,7 @@ var Entry = class Entry {
|
|
|
452
515
|
const pending = volatileOnly && this._commitVolatile() ? [] : changes;
|
|
453
516
|
if (!pending.length && !force) return;
|
|
454
517
|
this.context.emit("loader/partial-dispose", this, legacy, true);
|
|
455
|
-
this._patchContext(pending);
|
|
518
|
+
await this._patchContext(pending);
|
|
456
519
|
} else await this.init();
|
|
457
520
|
}
|
|
458
521
|
/**
|
|
@@ -461,7 +524,7 @@ var Entry = class Entry {
|
|
|
461
524
|
* @returns `false` when an ordinary effective value changed, so the caller applies the ordinary update lifecycle.
|
|
462
525
|
*/
|
|
463
526
|
_commitVolatile() {
|
|
464
|
-
const fiber = this.fiber;
|
|
527
|
+
const fiber = this.fiber.ctx.fiber;
|
|
465
528
|
const refs = volatileEntries(fiber.effectiveConfig);
|
|
466
529
|
if (!refs.length) return true;
|
|
467
530
|
const raw = this.options.config;
|
|
@@ -509,11 +572,10 @@ var Entry = class Entry {
|
|
|
509
572
|
} finally {
|
|
510
573
|
this._initTask = void 0;
|
|
511
574
|
}
|
|
512
|
-
|
|
575
|
+
this.fiber?.await().catch(() => {}).finally(() => {
|
|
513
576
|
if (this.loader.getTasks().length) return;
|
|
514
577
|
this.ctx.reflect.notify(["loader"]);
|
|
515
|
-
};
|
|
516
|
-
this.fiber?.await().then(notify, notify);
|
|
578
|
+
});
|
|
517
579
|
}
|
|
518
580
|
async _init() {
|
|
519
581
|
let moduleNamespace;
|
|
@@ -522,13 +584,11 @@ var Entry = class Entry {
|
|
|
522
584
|
} catch (error) {
|
|
523
585
|
this.ctx.logger.error(error);
|
|
524
586
|
return;
|
|
525
|
-
} finally {
|
|
526
|
-
this._initTask = void 0;
|
|
527
587
|
}
|
|
528
588
|
const plugin = this.loader.unwrapExports(moduleNamespace);
|
|
529
|
-
this._patchContext([]);
|
|
589
|
+
await this._patchContext([]);
|
|
530
590
|
this.loader.showLog(this, "apply");
|
|
531
|
-
this.fiber = this.ctx.registry.plugin(plugin, this.options.config, this.getOuterStack)
|
|
591
|
+
this.fiber = this.ctx.registry.plugin(plugin, this.options.config, this.getOuterStack);
|
|
532
592
|
this.moduleNamespace = moduleNamespace;
|
|
533
593
|
}
|
|
534
594
|
};
|
|
@@ -591,7 +651,7 @@ function isolate(ctx) {
|
|
|
591
651
|
entry.ctx[Context.intercept] = Object.create(entry.ctx[Context.intercept]);
|
|
592
652
|
entry.ctx[Context.isolate] = Object.create(entry.ctx[Context.isolate]);
|
|
593
653
|
});
|
|
594
|
-
ctx.on("loader/patch-context", (entry, next) => {
|
|
654
|
+
ctx.on("loader/patch-context", async (entry, next) => {
|
|
595
655
|
const newMap = Object.create(entry.parent.ctx[Context.isolate]);
|
|
596
656
|
for (const name of Object.keys(entry.options.isolate ?? {})) newMap[name] = access(entry, name, true);
|
|
597
657
|
const diff = Object.create(null);
|
|
@@ -606,7 +666,8 @@ function isolate(ctx) {
|
|
|
606
666
|
for (const symbol of [oldMap[name], newMap[name]]) {
|
|
607
667
|
const impl = symbol && entry.ctx.reflect.store[symbol];
|
|
608
668
|
if (!impl) continue;
|
|
609
|
-
|
|
669
|
+
const fiber = impl.ctx.fiber;
|
|
670
|
+
if (!fiber) {
|
|
610
671
|
entry.ctx.logger.warn(/* @__PURE__ */ new Error(`expected service ${name} to be implemented`));
|
|
611
672
|
continue;
|
|
612
673
|
}
|
|
@@ -614,19 +675,23 @@ function isolate(ctx) {
|
|
|
614
675
|
oldMap[name],
|
|
615
676
|
newMap[name],
|
|
616
677
|
entry.ctx[delim],
|
|
617
|
-
|
|
678
|
+
fiber.ctx[delim]
|
|
618
679
|
];
|
|
619
|
-
if (entry.ctx[delim] !==
|
|
680
|
+
if (entry.ctx[delim] !== fiber.ctx[delim]) break;
|
|
620
681
|
}
|
|
621
682
|
}
|
|
622
683
|
Object.setPrototypeOf(entry.ctx[Context.isolate], entry.parent.ctx[Context.isolate]);
|
|
623
684
|
Object.setPrototypeOf(entry.ctx[Context.intercept], entry.parent.ctx[Context.intercept]);
|
|
624
685
|
swap(entry.ctx[Context.isolate], newMap);
|
|
625
686
|
swap(entry.ctx[Context.intercept], entry.options.intercept);
|
|
626
|
-
next();
|
|
627
|
-
for (const [symbol1, symbol2, flag1, flag2] of Object.values(diff))
|
|
628
|
-
|
|
629
|
-
|
|
687
|
+
await next();
|
|
688
|
+
for (const [symbol1, symbol2, flag1, flag2] of Object.values(diff)) {
|
|
689
|
+
const impl = entry.ctx.reflect.store[symbol1];
|
|
690
|
+
if (flag1 === flag2 && impl && !entry.ctx.reflect.store[symbol2]) {
|
|
691
|
+
entry.ctx.reflect.store[symbol2] = impl;
|
|
692
|
+
delete entry.ctx.reflect.store[symbol1];
|
|
693
|
+
impl.isolate = symbol2;
|
|
694
|
+
}
|
|
630
695
|
}
|
|
631
696
|
ctx.reflect.notify(Object.keys(diff), (ctx, name) => {
|
|
632
697
|
const [symbol1, symbol2, flag1, flag2] = diff[name];
|
|
@@ -653,7 +718,7 @@ function isolate(ctx) {
|
|
|
653
718
|
/**
|
|
654
719
|
* Service that owns a loader entry tree and imports configured plugins.
|
|
655
720
|
*
|
|
656
|
-
* Subclasses provide persistence by implementing `
|
|
721
|
+
* Subclasses provide persistence by implementing `commit(change)` on `EntryTree`.
|
|
657
722
|
*/
|
|
658
723
|
var Loader = class extends EntryTree {
|
|
659
724
|
config;
|
|
@@ -672,23 +737,27 @@ var Loader = class extends EntryTree {
|
|
|
672
737
|
noShadow: true
|
|
673
738
|
});
|
|
674
739
|
ctx.reflect.provide("loader", this, this[Service.check]);
|
|
675
|
-
ctx.on("internal/config",
|
|
740
|
+
ctx.on("internal/config", (fiber, next) => {
|
|
676
741
|
const config = next();
|
|
677
|
-
if (!
|
|
678
|
-
if (
|
|
679
|
-
return interpolate(
|
|
680
|
-
}, { global: true });
|
|
681
|
-
ctx.on("internal/update", function(config, noSave, next) {
|
|
682
|
-
if (!this.entry || noSave || this.parent.fiber?.entry === this.entry) return next();
|
|
683
|
-
const unparse = this.runtime?.Config?.["simplify"];
|
|
684
|
-
this.entry.options.config = unparse ? unparse.call(this.runtime.Config, config) : config;
|
|
685
|
-
this.entry.parent.tree.write();
|
|
686
|
-
return next();
|
|
687
|
-
}, {
|
|
688
|
-
global: true,
|
|
689
|
-
prepend: true
|
|
742
|
+
if (!fiber.entry || fiber.parent.fiber?.entry === fiber.entry) return config;
|
|
743
|
+
if (fiber.runtime?.callback[EntryGroup.key]) return config;
|
|
744
|
+
return interpolate(fiber.ctx, config);
|
|
690
745
|
});
|
|
691
|
-
ctx.on("internal/
|
|
746
|
+
ctx.on("internal/commit", (fiber, config) => {
|
|
747
|
+
if (!fiber.entry || fiber.parent.fiber?.entry === fiber.entry) return;
|
|
748
|
+
const schema = fiber.runtime?.Config;
|
|
749
|
+
const unparse = schema?.["simplify"];
|
|
750
|
+
const { entry } = fiber;
|
|
751
|
+
const legacy = { ...entry.options };
|
|
752
|
+
entry.options.config = unparse ? unparse.call(schema, config) : config;
|
|
753
|
+
entry.parent.tree.commit({
|
|
754
|
+
id: entry.options.id,
|
|
755
|
+
group: entry.parent,
|
|
756
|
+
options: entry.options,
|
|
757
|
+
legacy
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
ctx.on("internal/update", function(config, next) {
|
|
692
761
|
if (!this.entry || this.parent.fiber?.entry === this.entry) return next();
|
|
693
762
|
self.showLog(this.entry, "reload");
|
|
694
763
|
return next();
|
|
@@ -702,16 +771,24 @@ var Loader = class extends EntryTree {
|
|
|
702
771
|
if (!fiber.entry) return;
|
|
703
772
|
if (fiber.parent.fiber?.entry === fiber.entry) return;
|
|
704
773
|
if (!ctx.registry.has(fiber.runtime.callback)) return;
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
this.showLog(
|
|
708
|
-
if (fiber.
|
|
709
|
-
|
|
710
|
-
|
|
774
|
+
if (!fiber.entry.parent.tree.ctx.fiber.uid) return;
|
|
775
|
+
const { entry } = fiber;
|
|
776
|
+
this.showLog(entry, "unload");
|
|
777
|
+
if (fiber.parent.fiber.state === 5) return;
|
|
778
|
+
if (entry.parent.tree.store[entry.options.id] !== entry) return;
|
|
779
|
+
if (entry.disabled) return;
|
|
780
|
+
const legacy = { ...entry.options };
|
|
781
|
+
entry.options.disabled = true;
|
|
782
|
+
entry.parent.tree.commit({
|
|
783
|
+
id: entry.options.id,
|
|
784
|
+
group: entry.parent,
|
|
785
|
+
options: entry.options,
|
|
786
|
+
legacy
|
|
787
|
+
});
|
|
711
788
|
});
|
|
712
789
|
ctx.plugin(isolate);
|
|
713
790
|
}
|
|
714
|
-
|
|
791
|
+
commit(_change) {}
|
|
715
792
|
[Service.check]() {
|
|
716
793
|
if (Service.prototype[Service.resolveConfig].call(this).await && this.getTasks().length) return false;
|
|
717
794
|
return true;
|
|
@@ -39,7 +39,7 @@ export declare class Entry {
|
|
|
39
39
|
* Effective disabled state: a `!!js` expression evaluates against the loader
|
|
40
40
|
* context. The raw node stays in the options, so write-back keeps the form.
|
|
41
41
|
*/
|
|
42
|
-
private
|
|
42
|
+
private _resolveDisabled;
|
|
43
43
|
evaluate(expr: string): any;
|
|
44
44
|
private _patchContext;
|
|
45
45
|
refresh(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|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C,gBAAgB;IAMxB,QAAQ,CAAC,IAAI,EAAE,MAAM;YAIP,aAAa;IAarB,OAAO;IAMb,iFAAiF;IAC3E,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,MAAM,UAAQ,EAAE,KAAK,UAAQ;IAyC1E;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAmCvB,aAAa,iBAQZ;IAED,2EAA2E;IACrE,IAAI;YAYI,KAAK;CAcpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../../src/config/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,wDAAwD;AACxD,qBAAa,UAAU;IAKF,GAAG,EAAE,OAAO;IAAS,IAAI,EAAE,SAAS;IAJvD,MAAM,CAAC,QAAQ,CAAC,GAAG,gBAA6B;IAEzC,IAAI,EAAE,YAAY,EAAE,CAAK;gBAEb,GAAG,EAAE,OAAO,EAAS,IAAI,EAAE,SAAS;IAKvD,IAAI,OAAO,IAAI,OAAO,CAErB;IAEK,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC;IAW9C,MAAM,CAAC,OAAO,EAAE,YAAY;IAM5B,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,UAAQ;
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../../src/config/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,wDAAwD;AACxD,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CAAsB;IAEnD,QAAQ,KAAK,MAAM,IAAI,MAAM,CAAA;IAE7B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAQ;IAQlC,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,IAAI,IAAI,WAEP;CACF;AAED,mCAAmC;AACnC,qBAAa,UAAW,SAAQ,KAAK;IACvB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,KAAK;IAIhC,IAAI,MAAM,WAET;CACF;AAED,uEAAuE;AACvE,qBAAa,WAAY,SAAQ,KAAK;IACjB,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;IAIhC,IAAI,MAAM,WAET;CACF;AAED,+EAA+E;AAC/E,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,GAAG,EAAE,OAAO,QAyG3C"}
|
|
@@ -2,6 +2,28 @@ import { Context } from '@deepseek-ai/cordis';
|
|
|
2
2
|
import { type Dict } from '@deepseek-ai/cosmokit';
|
|
3
3
|
import { Entry, type EntryOptions } from './entry.ts';
|
|
4
4
|
import { EntryGroup } from './group.ts';
|
|
5
|
+
/**
|
|
6
|
+
* One tree-side mutation, reported to `EntryTree.commit()` synchronously after
|
|
7
|
+
* it has been applied to `entry.options` / `group.data`.
|
|
8
|
+
*
|
|
9
|
+
* - `options` absent: the entry was removed from `group`.
|
|
10
|
+
* - `legacy` absent: the entry was created in `group`.
|
|
11
|
+
* - both present: the entry was updated and now lives in `group`; `from` is
|
|
12
|
+
* the group it left if the update moved it within the same tree. A move to
|
|
13
|
+
* another tree reports a removal to the source tree and a creation to the
|
|
14
|
+
* destination tree.
|
|
15
|
+
*
|
|
16
|
+
* `id` is local to the receiving tree; `Entry.id` prefixes it with the parent
|
|
17
|
+
* tree's path. Only `EntryTree` mutation methods and explicit Fiber saves
|
|
18
|
+
* report changes; file-driven `EntryGroup` reconciliation does not.
|
|
19
|
+
*/
|
|
20
|
+
export interface EntryChange {
|
|
21
|
+
id: string;
|
|
22
|
+
group: EntryGroup;
|
|
23
|
+
from?: EntryGroup;
|
|
24
|
+
options?: EntryOptions;
|
|
25
|
+
legacy?: EntryOptions;
|
|
26
|
+
}
|
|
5
27
|
/** Mutable tree of loader entries. Persistence is supplied by subclasses. */
|
|
6
28
|
export declare abstract class EntryTree {
|
|
7
29
|
static readonly sep = ":";
|
|
@@ -17,6 +39,13 @@ export declare abstract class EntryTree {
|
|
|
17
39
|
getTasks(): Promise<void>[];
|
|
18
40
|
/** Wait until this tree has no pending import or lifecycle tasks. */
|
|
19
41
|
await(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Assign a random tree-local id when `options.id` is absent. Explicit ids
|
|
44
|
+
* may contain `EntryTree.sep`; `resolve()` and `resolveGroup()` cannot
|
|
45
|
+
* address such entries by nested path.
|
|
46
|
+
* @param options - Entry options; a generated id is written to `options.id`.
|
|
47
|
+
* @returns The existing or generated id.
|
|
48
|
+
*/
|
|
20
49
|
ensureId(options: Partial<EntryOptions>): string;
|
|
21
50
|
/** Resolve an entry by id, including nested ids separated by `EntryTree.sep`. */
|
|
22
51
|
resolve(id: string): Entry;
|
|
@@ -29,7 +58,7 @@ export declare abstract class EntryTree {
|
|
|
29
58
|
update(id: string, options: Omit<EntryOptions, 'id' | 'name'>, parent?: string | null, position?: number): Promise<void>;
|
|
30
59
|
/** Import a plugin module from a specifier or `cordis:` builtin. */
|
|
31
60
|
import(name: string, getOuterStack?: () => string[]): any;
|
|
32
|
-
/**
|
|
33
|
-
abstract
|
|
61
|
+
/** Report an applied mutation synchronously. In-memory trees may use a no-op. */
|
|
62
|
+
abstract commit(change: EntryChange): void;
|
|
34
63
|
}
|
|
35
64
|
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../src/config/tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAiB,KAAK,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,EAAE;IAqBnD,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;CAC3C"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Context, Service
|
|
2
|
-
import { type Dict } from '@deepseek-ai/cosmokit';
|
|
1
|
+
import { Context, Service } from '@deepseek-ai/cordis';
|
|
2
|
+
import { type Awaitable, type Dict } from '@deepseek-ai/cosmokit';
|
|
3
3
|
import { ModuleLoader } from './internal.ts';
|
|
4
4
|
import { Entry, type EntryOptions } from './config/entry.ts';
|
|
5
|
-
import { EntryTree } from './config/tree.ts';
|
|
5
|
+
import { EntryTree, type EntryChange } from './config/tree.ts';
|
|
6
6
|
/** Re-export entry node APIs. */
|
|
7
7
|
export * from './config/entry.ts';
|
|
8
8
|
/** Re-export nested entry group APIs. */
|
|
@@ -33,7 +33,7 @@ declare module '@deepseek-ai/cordis' {
|
|
|
33
33
|
* @param next - continue context refresh and Loader's config update.
|
|
34
34
|
* @mode waterfall
|
|
35
35
|
*/
|
|
36
|
-
'loader/patch-context'(entry: Entry, next: () => void): void
|
|
36
|
+
'loader/patch-context'(entry: Entry, next: () => Awaitable<void>): Awaitable<void>;
|
|
37
37
|
}
|
|
38
38
|
interface Context {
|
|
39
39
|
loader: Loader;
|
|
@@ -61,7 +61,7 @@ export declare namespace Loader {
|
|
|
61
61
|
/**
|
|
62
62
|
* Service that owns a loader entry tree and imports configured plugins.
|
|
63
63
|
*
|
|
64
|
-
* Subclasses provide persistence by implementing `
|
|
64
|
+
* Subclasses provide persistence by implementing `commit(change)` on `EntryTree`.
|
|
65
65
|
*/
|
|
66
66
|
export declare class Loader extends EntryTree {
|
|
67
67
|
config: Loader.Config;
|
|
@@ -71,11 +71,11 @@ export declare class Loader extends EntryTree {
|
|
|
71
71
|
internal: ModuleLoader | undefined;
|
|
72
72
|
builtins: Dict<any>;
|
|
73
73
|
constructor(ctx: Context, config?: Loader.Config);
|
|
74
|
-
|
|
74
|
+
commit(_change: EntryChange): void;
|
|
75
75
|
[Service.check](): boolean;
|
|
76
76
|
showLog(entry: Entry, type: string): void;
|
|
77
77
|
/** Return the loader entry id that owns `fiber`, if any. */
|
|
78
|
-
locate(fiber?: Fiber): string | undefined;
|
|
78
|
+
locate(fiber?: import("@deepseek-ai/cordis").Fiber): string | undefined;
|
|
79
79
|
/** Hook for hosts that can restart the process on full-reload requests. */
|
|
80
80
|
exit(): void;
|
|
81
81
|
/** Normalize ESM/CJS/default export shapes before applying a plugin. */
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAA8B,KAAK,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAG5D,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9D,iCAAiC;AACjC,cAAc,mBAAmB,CAAA;AACjC,yCAAyC;AACzC,cAAc,mBAAmB,CAAA;AACjC,2CAA2C;AAC3C,cAAc,qBAAqB,CAAA;AACnC,6CAA6C;AAC7C,cAAc,kBAAkB,CAAA;AAChC,kDAAkD;AAClD,cAAc,mBAAmB,CAAA;AACjC,iEAAiE;AACjE,cAAc,eAAe,CAAA;AAE7B,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,MAAM;QACd,MAAM,CAAC,MA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AAM,CAAC,MAAW;IA0F3D,MAAM,CAAC,OAAO,EAAE,WAAW;IAI3B,CAAC,OAAO,CAAC,KAAK,CAAC;IAMf,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM;IAKlC,4DAA4D;IAC5D,MAAM,CAAC,KAAK,sCAAiB;IAS7B,2EAA2E;IAC3E,IAAI;IAGJ,wEAAwE;IACxE,aAAa,CAAC,OAAO,EAAE,GAAG;CAQ3B;AAED,eAAe,MAAM,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/cordis-plugin-loader",
|
|
3
3
|
"description": "Plugin loader for cordis",
|
|
4
|
-
"version": "1.0.7-alpha.
|
|
4
|
+
"version": "1.0.7-alpha.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"author": "Shigma <shigma10826@gmail.com>",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@deepseek-ai/cordis": "~4.0.6-alpha.
|
|
33
|
+
"@deepseek-ai/cordis": "~4.0.6-alpha.2",
|
|
34
34
|
"node-addon-require-builtin": "^0.1.9"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@deepseek-ai/cosmokit": "~1.8.7-alpha.
|
|
43
|
-
"@deepseek-ai/schemastery": "~3.18.6-alpha.
|
|
42
|
+
"@deepseek-ai/cosmokit": "~1.8.7-alpha.2",
|
|
43
|
+
"@deepseek-ai/schemastery": "~3.18.6-alpha.2"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/config/entry.ts
CHANGED
|
@@ -78,7 +78,7 @@ export class Entry {
|
|
|
78
78
|
if (this.options.group) return false
|
|
79
79
|
let entry: Entry | undefined = this
|
|
80
80
|
do {
|
|
81
|
-
if (this.
|
|
81
|
+
if (this._resolveDisabled(entry.options)) return true
|
|
82
82
|
entry = entry.parent.ctx.fiber.entry
|
|
83
83
|
} while (entry)
|
|
84
84
|
return false
|
|
@@ -88,7 +88,7 @@ export class Entry {
|
|
|
88
88
|
* Effective disabled state: a `!!js` expression evaluates against the loader
|
|
89
89
|
* context. The raw node stays in the options, so write-back keeps the form.
|
|
90
90
|
*/
|
|
91
|
-
private
|
|
91
|
+
private _resolveDisabled(options: EntryOptions): boolean {
|
|
92
92
|
return isJsExpr(options.disabled)
|
|
93
93
|
? Boolean(this.evaluate(options.disabled.__jsExpr))
|
|
94
94
|
: Boolean(options.disabled)
|
|
@@ -98,12 +98,15 @@ export class Entry {
|
|
|
98
98
|
return evaluate(this.ctx, expr)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
private _patchContext(diff: string[]) {
|
|
102
|
-
this.context.waterfall('loader/patch-context', this, () => {
|
|
101
|
+
private async _patchContext(diff: string[]) {
|
|
102
|
+
await this.context.waterfall('loader/patch-context', this, async () => {
|
|
103
103
|
Object.setPrototypeOf(this.ctx, this.parent.ctx)
|
|
104
104
|
|
|
105
105
|
if (this.fiber?.uid && (diff.includes('config') || this.options.group)) {
|
|
106
|
-
|
|
106
|
+
// A simultaneous context/config edit must restart against the new dependencies.
|
|
107
|
+
const fiber = this.fiber.ctx.fiber
|
|
108
|
+
for (const name of Object.keys(fiber.inject)) fiber._checkImpl(name)
|
|
109
|
+
await fiber.update(this.options.config, true)
|
|
107
110
|
}
|
|
108
111
|
})
|
|
109
112
|
}
|
|
@@ -134,7 +137,7 @@ export class Entry {
|
|
|
134
137
|
|
|
135
138
|
// step 2: execute
|
|
136
139
|
if (this.disabled) {
|
|
137
|
-
this.fiber?.dispose()
|
|
140
|
+
await this.fiber?.dispose()
|
|
138
141
|
return
|
|
139
142
|
}
|
|
140
143
|
|
|
@@ -150,7 +153,7 @@ export class Entry {
|
|
|
150
153
|
const pending = volatileOnly && this._commitVolatile() ? [] : changes
|
|
151
154
|
if (!pending.length && !force) return
|
|
152
155
|
this.context.emit('loader/partial-dispose', this, legacy, true)
|
|
153
|
-
this._patchContext(pending)
|
|
156
|
+
await this._patchContext(pending)
|
|
154
157
|
} else {
|
|
155
158
|
await this.init()
|
|
156
159
|
}
|
|
@@ -162,7 +165,7 @@ export class Entry {
|
|
|
162
165
|
* @returns `false` when an ordinary effective value changed, so the caller applies the ordinary update lifecycle.
|
|
163
166
|
*/
|
|
164
167
|
private _commitVolatile(): boolean {
|
|
165
|
-
const fiber = this.fiber
|
|
168
|
+
const fiber = this.fiber!.ctx.fiber
|
|
166
169
|
const refs = volatileEntries(fiber.effectiveConfig)
|
|
167
170
|
if (!refs.length) return true
|
|
168
171
|
const raw = this.options.config
|
|
@@ -213,11 +216,10 @@ export class Entry {
|
|
|
213
216
|
} finally {
|
|
214
217
|
this._initTask = undefined
|
|
215
218
|
}
|
|
216
|
-
|
|
219
|
+
this.fiber?.await().catch(() => {}).finally(() => {
|
|
217
220
|
if (this.loader.getTasks().length) return
|
|
218
221
|
this.ctx.reflect.notify(['loader'])
|
|
219
|
-
}
|
|
220
|
-
this.fiber?.await().then(notify, notify)
|
|
222
|
+
})
|
|
221
223
|
}
|
|
222
224
|
|
|
223
225
|
private async _init() {
|
|
@@ -227,13 +229,11 @@ export class Entry {
|
|
|
227
229
|
} catch (error) {
|
|
228
230
|
this.ctx.logger.error(error)
|
|
229
231
|
return
|
|
230
|
-
} finally {
|
|
231
|
-
this._initTask = undefined
|
|
232
232
|
}
|
|
233
233
|
const plugin = this.loader.unwrapExports(moduleNamespace)
|
|
234
|
-
this._patchContext([])
|
|
234
|
+
await this._patchContext([])
|
|
235
235
|
this.loader.showLog(this, 'apply')
|
|
236
|
-
this.fiber = this.ctx.registry.plugin(plugin, this.options.config, this.getOuterStack)
|
|
236
|
+
this.fiber = this.ctx.registry.plugin(plugin, this.options.config, this.getOuterStack)
|
|
237
237
|
this.moduleNamespace = moduleNamespace
|
|
238
238
|
}
|
|
239
239
|
}
|
package/src/config/group.ts
CHANGED
|
@@ -36,12 +36,13 @@ export class EntryGroup {
|
|
|
36
36
|
|
|
37
37
|
remove(id: string, isDispose = false) {
|
|
38
38
|
const entry = this.tree.store[id]
|
|
39
|
-
if (!entry) return
|
|
39
|
+
if (!entry || entry.parent !== this) return
|
|
40
|
+
// Unregister before disposal so Loader can distinguish removal from self-disposal.
|
|
41
|
+
delete this.tree.store[id]
|
|
40
42
|
entry.fiber?.dispose()
|
|
41
43
|
if (!isDispose) {
|
|
42
44
|
this.unlink(entry.options)
|
|
43
45
|
}
|
|
44
|
-
delete this.tree.store[id]
|
|
45
46
|
this.context.emit('loader/partial-dispose', entry, entry.options, false)
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -78,9 +79,7 @@ export class Group extends EntryGroup {
|
|
|
78
79
|
|
|
79
80
|
constructor(public ctx: Context, public config: EntryOptions[]) {
|
|
80
81
|
super(ctx, ctx.fiber.entry!.parent.tree)
|
|
81
|
-
ctx.on('internal/update',
|
|
82
|
-
this.update(config)
|
|
83
|
-
})
|
|
82
|
+
ctx.on('internal/update', config => this.update(config))
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
async* [Service.init]() {
|
package/src/config/isolate.ts
CHANGED
|
@@ -93,7 +93,7 @@ export default function isolate(ctx: Context) {
|
|
|
93
93
|
entry.ctx[Context.isolate] = Object.create(entry.ctx[Context.isolate])
|
|
94
94
|
})
|
|
95
95
|
|
|
96
|
-
ctx.on('loader/patch-context', (entry, next) => {
|
|
96
|
+
ctx.on('loader/patch-context', async (entry, next) => {
|
|
97
97
|
// step 1: generate new isolate map
|
|
98
98
|
const newMap: Dict<symbol> = Object.create(entry.parent.ctx[Context.isolate])
|
|
99
99
|
for (const name of Object.keys(entry.options.isolate ?? {})) {
|
|
@@ -110,12 +110,13 @@ export default function isolate(ctx: Context) {
|
|
|
110
110
|
for (const symbol of [oldMap[name], newMap[name]]) {
|
|
111
111
|
const impl = symbol && entry.ctx.reflect.store[symbol]
|
|
112
112
|
if (!impl) continue
|
|
113
|
-
|
|
113
|
+
const fiber = impl.ctx.fiber
|
|
114
|
+
if (!fiber) {
|
|
114
115
|
entry.ctx.logger.warn(new Error(`expected service ${name} to be implemented`))
|
|
115
116
|
continue
|
|
116
117
|
}
|
|
117
|
-
diff[name] = [oldMap[name], newMap[name], entry.ctx[delim],
|
|
118
|
-
if (entry.ctx[delim] !==
|
|
118
|
+
diff[name] = [oldMap[name], newMap[name], entry.ctx[delim], fiber.ctx[delim]]
|
|
119
|
+
if (entry.ctx[delim] !== fiber.ctx[delim]) break
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
|
|
@@ -126,13 +127,15 @@ export default function isolate(ctx: Context) {
|
|
|
126
127
|
swap(entry.ctx[Context.intercept], entry.options.intercept)
|
|
127
128
|
|
|
128
129
|
// step 4: reload fiber
|
|
129
|
-
next()
|
|
130
|
+
await next()
|
|
130
131
|
|
|
131
132
|
// step 5: replace service impl
|
|
132
133
|
for (const [symbol1, symbol2, flag1, flag2] of Object.values(diff)) {
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
const impl = entry.ctx.reflect.store[symbol1]
|
|
135
|
+
if (flag1 === flag2 && impl && !entry.ctx.reflect.store[symbol2]) {
|
|
136
|
+
entry.ctx.reflect.store[symbol2] = impl
|
|
135
137
|
delete entry.ctx.reflect.store[symbol1]
|
|
138
|
+
impl.isolate = symbol2
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
|
package/src/config/tree.ts
CHANGED
|
@@ -4,6 +4,42 @@ import { Entry, type EntryOptions } from './entry.ts'
|
|
|
4
4
|
import { EntryGroup } from './group.ts'
|
|
5
5
|
import { createResolve } from '../resolve.ts'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* One tree-side mutation, reported to `EntryTree.commit()` synchronously after
|
|
9
|
+
* it has been applied to `entry.options` / `group.data`.
|
|
10
|
+
*
|
|
11
|
+
* - `options` absent: the entry was removed from `group`.
|
|
12
|
+
* - `legacy` absent: the entry was created in `group`.
|
|
13
|
+
* - both present: the entry was updated and now lives in `group`; `from` is
|
|
14
|
+
* the group it left if the update moved it within the same tree. A move to
|
|
15
|
+
* another tree reports a removal to the source tree and a creation to the
|
|
16
|
+
* destination tree.
|
|
17
|
+
*
|
|
18
|
+
* `id` is local to the receiving tree; `Entry.id` prefixes it with the parent
|
|
19
|
+
* tree's path. Only `EntryTree` mutation methods and explicit Fiber saves
|
|
20
|
+
* report changes; file-driven `EntryGroup` reconciliation does not.
|
|
21
|
+
*/
|
|
22
|
+
export interface EntryChange {
|
|
23
|
+
id: string
|
|
24
|
+
group: EntryGroup
|
|
25
|
+
from?: EntryGroup
|
|
26
|
+
options?: EntryOptions
|
|
27
|
+
legacy?: EntryOptions
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The entry and the same-tree members of its group, recursively. */
|
|
31
|
+
function members(entry: Entry): Entry[] {
|
|
32
|
+
const { tree } = entry.parent
|
|
33
|
+
const result = [entry]
|
|
34
|
+
const group = entry.subgroup
|
|
35
|
+
if (group?.tree !== tree) return result
|
|
36
|
+
for (const options of group.data) {
|
|
37
|
+
const member = tree.store[options.id]
|
|
38
|
+
if (member?.parent === group) result.push(...members(member))
|
|
39
|
+
}
|
|
40
|
+
return result
|
|
41
|
+
}
|
|
42
|
+
|
|
7
43
|
/** Mutable tree of loader entries. Persistence is supplied by subclasses. */
|
|
8
44
|
export abstract class EntryTree {
|
|
9
45
|
static readonly sep = ':'
|
|
@@ -49,6 +85,13 @@ export abstract class EntryTree {
|
|
|
49
85
|
}
|
|
50
86
|
}
|
|
51
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Assign a random tree-local id when `options.id` is absent. Explicit ids
|
|
90
|
+
* may contain `EntryTree.sep`; `resolve()` and `resolveGroup()` cannot
|
|
91
|
+
* address such entries by nested path.
|
|
92
|
+
* @param options - Entry options; a generated id is written to `options.id`.
|
|
93
|
+
* @returns The existing or generated id.
|
|
94
|
+
*/
|
|
52
95
|
ensureId(options: Partial<EntryOptions>) {
|
|
53
96
|
if (!options.id) {
|
|
54
97
|
do {
|
|
@@ -82,31 +125,57 @@ export abstract class EntryTree {
|
|
|
82
125
|
/** Create an entry in the root group or a nested group. */
|
|
83
126
|
async create(options: Omit<EntryOptions, 'id'>, parent: string | null = null, position = Infinity) {
|
|
84
127
|
const group = this.resolveGroup(parent)
|
|
128
|
+
const id = group.tree.ensureId(options)
|
|
85
129
|
group.data.splice(position, 0, options as EntryOptions)
|
|
86
|
-
group.tree.
|
|
130
|
+
group.tree.commit({ id, group, options: options as EntryOptions })
|
|
87
131
|
return group.create(options)
|
|
88
132
|
}
|
|
89
133
|
|
|
90
134
|
/** Stop and remove an entry from its parent group. */
|
|
91
135
|
remove(id: string) {
|
|
92
136
|
const entry = this.resolve(id)
|
|
93
|
-
entry.parent
|
|
94
|
-
entry.
|
|
137
|
+
const group = entry.parent
|
|
138
|
+
const legacy = entry.options
|
|
139
|
+
group.remove(legacy.id)
|
|
140
|
+
group.tree.commit({ id: legacy.id, group, legacy })
|
|
95
141
|
}
|
|
96
142
|
|
|
97
143
|
/** Update an entry and optionally move it to another group. */
|
|
98
144
|
async update(id: string, options: Omit<EntryOptions, 'id' | 'name'>, parent?: string | null, position?: number) {
|
|
99
145
|
const entry = this.resolve(id)
|
|
100
146
|
const source = entry.parent
|
|
147
|
+
const legacy = { ...entry.options }
|
|
101
148
|
if (parent !== undefined) {
|
|
102
149
|
const target = this.resolveGroup(parent)
|
|
150
|
+
const moved = target.tree === source.tree ? [] : members(entry)
|
|
151
|
+
for (const member of moved) {
|
|
152
|
+
const { id } = member.options
|
|
153
|
+
if (target.tree.store[id]) throw new Error(`entry ${id} already exists in the target tree`)
|
|
154
|
+
}
|
|
103
155
|
source.unlink(entry.options)
|
|
104
156
|
target.data.splice(position ?? Infinity, 0, entry.options)
|
|
105
|
-
target.tree.write()
|
|
106
157
|
entry.parent = target
|
|
158
|
+
// The target tree owns the moved entries from now on, so that it adopts
|
|
159
|
+
// them instead of creating new ones when it reconciles its source.
|
|
160
|
+
for (const member of moved) {
|
|
161
|
+
delete source.tree.store[member.options.id]
|
|
162
|
+
target.tree.store[member.options.id] = member
|
|
163
|
+
if (member.subgroup?.tree === source.tree) member.subgroup.tree = target.tree
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// `Entry.update` assigns the new options before its first `await`, so the
|
|
167
|
+
// change is fully visible to `commit()` once the call returns.
|
|
168
|
+
const task = entry.update(options, false, true)
|
|
169
|
+
if (entry.parent.tree !== source.tree) {
|
|
170
|
+
// a move across trees removes the entry from the source tree and
|
|
171
|
+
// creates it in the target tree
|
|
172
|
+
source.tree.commit({ id: legacy.id, group: source, legacy })
|
|
173
|
+
entry.parent.tree.commit({ id: legacy.id, group: entry.parent, options: entry.options })
|
|
174
|
+
} else {
|
|
175
|
+
const from = entry.parent === source ? undefined : source
|
|
176
|
+
entry.parent.tree.commit({ id: legacy.id, group: entry.parent, from, options: entry.options, legacy })
|
|
107
177
|
}
|
|
108
|
-
|
|
109
|
-
return entry.update(options, false, true)
|
|
178
|
+
return task
|
|
110
179
|
}
|
|
111
180
|
|
|
112
181
|
/** Import a plugin module from a specifier or `cordis:` builtin. */
|
|
@@ -131,6 +200,6 @@ export abstract class EntryTree {
|
|
|
131
200
|
}, getOuterStack)
|
|
132
201
|
}
|
|
133
202
|
|
|
134
|
-
/**
|
|
135
|
-
abstract
|
|
203
|
+
/** Report an applied mutation synchronously. In-memory trees may use a no-op. */
|
|
204
|
+
abstract commit(change: EntryChange): void
|
|
136
205
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Context, FiberState, Inject, Service
|
|
2
|
-
import { defineProperty, isNullable, type Dict } from '@deepseek-ai/cosmokit'
|
|
1
|
+
import { Context, FiberState, Inject, Service } from '@deepseek-ai/cordis'
|
|
2
|
+
import { defineProperty, isNullable, type Awaitable, type Dict } from '@deepseek-ai/cosmokit'
|
|
3
3
|
import { ModuleLoader } from './internal.ts'
|
|
4
4
|
import { Entry, type EntryOptions } from './config/entry.ts'
|
|
5
5
|
import { EntryGroup } from './config/group.ts'
|
|
6
6
|
import isolate from './config/isolate.ts'
|
|
7
|
-
import { EntryTree } from './config/tree.ts'
|
|
7
|
+
import { EntryTree, type EntryChange } from './config/tree.ts'
|
|
8
8
|
import { interpolate } from './config/utils.ts'
|
|
9
9
|
|
|
10
10
|
/** Re-export entry node APIs. */
|
|
@@ -38,7 +38,7 @@ declare module '@deepseek-ai/cordis' {
|
|
|
38
38
|
* @param next - continue context refresh and Loader's config update.
|
|
39
39
|
* @mode waterfall
|
|
40
40
|
*/
|
|
41
|
-
'loader/patch-context'(entry: Entry, next: () => void): void
|
|
41
|
+
'loader/patch-context'(entry: Entry, next: () => Awaitable<void>): Awaitable<void>
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
interface Context {
|
|
@@ -72,7 +72,7 @@ export namespace Loader {
|
|
|
72
72
|
/**
|
|
73
73
|
* Service that owns a loader entry tree and imports configured plugins.
|
|
74
74
|
*
|
|
75
|
-
* Subclasses provide persistence by implementing `
|
|
75
|
+
* Subclasses provide persistence by implementing `commit(change)` on `EntryTree`.
|
|
76
76
|
*/
|
|
77
77
|
export class Loader extends EntryTree {
|
|
78
78
|
declare [Service.config]: Loader.Intercept
|
|
@@ -101,26 +101,25 @@ export class Loader extends EntryTree {
|
|
|
101
101
|
|
|
102
102
|
ctx.reflect.provide('loader', this, this[Service.check])
|
|
103
103
|
|
|
104
|
-
ctx.on('internal/config',
|
|
104
|
+
ctx.on('internal/config', (fiber, next) => {
|
|
105
105
|
const config = next()
|
|
106
|
-
if (!
|
|
107
|
-
// Tree carriers
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (plugin?.[EntryGroup.key]) return config
|
|
112
|
-
return interpolate(this.ctx, config)
|
|
113
|
-
}, { global: true })
|
|
106
|
+
if (!fiber.entry || fiber.parent.fiber?.entry === fiber.entry) return config
|
|
107
|
+
// Tree carriers preserve the expressions owned by their child entries.
|
|
108
|
+
if (fiber.runtime?.callback[EntryGroup.key]) return config
|
|
109
|
+
return interpolate(fiber.ctx, config)
|
|
110
|
+
})
|
|
114
111
|
|
|
115
|
-
ctx.on('internal/
|
|
116
|
-
if (!
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
112
|
+
ctx.on('internal/commit', (fiber, config) => {
|
|
113
|
+
if (!fiber.entry || fiber.parent.fiber?.entry === fiber.entry) return
|
|
114
|
+
const schema = fiber.runtime?.Config
|
|
115
|
+
const unparse = schema?.['simplify']
|
|
116
|
+
const { entry } = fiber
|
|
117
|
+
const legacy = { ...entry.options }
|
|
118
|
+
entry.options.config = unparse ? unparse.call(schema, config) : config
|
|
119
|
+
entry.parent.tree.commit({ id: entry.options.id, group: entry.parent, options: entry.options, legacy })
|
|
120
|
+
})
|
|
122
121
|
|
|
123
|
-
ctx.on('internal/update', function (config,
|
|
122
|
+
ctx.on('internal/update', function (config, next) {
|
|
124
123
|
if (!this.entry || this.parent.fiber?.entry === this.entry) return next()
|
|
125
124
|
self.showLog(this.entry, 'reload')
|
|
126
125
|
return next()
|
|
@@ -152,24 +151,33 @@ export class Loader extends EntryTree {
|
|
|
152
151
|
if (!ctx.registry.has(fiber.runtime!.callback)) return
|
|
153
152
|
|
|
154
153
|
// case 5: the entry's tree is being disposed
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
if (!fiber.entry.parent.tree.ctx.fiber.uid) return
|
|
155
|
+
|
|
156
|
+
const { entry } = fiber
|
|
157
|
+
this.showLog(entry, 'unload')
|
|
158
|
+
|
|
159
|
+
// case 6: the entry's parent is being unloaded, which takes the entry with it
|
|
160
|
+
// (the parent may still be registered, e.g. when it has lost a dependency)
|
|
161
|
+
if (fiber.parent.fiber.state === FiberState.UNLOADING) return
|
|
157
162
|
|
|
158
|
-
|
|
163
|
+
// case 7: the entry is being removed by the loader (`EntryGroup.remove`
|
|
164
|
+
// unregisters it before disposing the fiber)
|
|
165
|
+
if (entry.parent.tree.store[entry.options.id] !== entry) return
|
|
159
166
|
|
|
160
|
-
// case
|
|
167
|
+
// case 8: fiber is disposed by loader behavior
|
|
161
168
|
// such as inject checker, config file update, ancestor group disable
|
|
162
|
-
if (
|
|
169
|
+
if (entry.disabled) return
|
|
163
170
|
|
|
164
|
-
|
|
165
|
-
|
|
171
|
+
const legacy = { ...entry.options }
|
|
172
|
+
entry.options.disabled = true
|
|
173
|
+
entry.parent.tree.commit({ id: entry.options.id, group: entry.parent, options: entry.options, legacy })
|
|
166
174
|
})
|
|
167
175
|
|
|
168
176
|
ctx.plugin(isolate)
|
|
169
177
|
}
|
|
170
178
|
|
|
171
|
-
|
|
172
|
-
// Loader's root tree is in-memory;
|
|
179
|
+
commit(_change: EntryChange) {
|
|
180
|
+
// Loader's root tree is in-memory; commits are no-ops.
|
|
173
181
|
}
|
|
174
182
|
|
|
175
183
|
[Service.check]() {
|