@bitakit/core 0.2.7 → 0.2.9
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/AGENTS.md +55 -0
- package/README.md +22 -0
- package/dist/actions/action-list.d.ts +3 -2
- package/dist/actions/action-list.js +5 -0
- package/dist/actions/dependencies.js +4 -1
- package/dist/actions/execution.js +1 -0
- package/dist/actions/types.d.ts +7 -2
- package/dist/app/access.js +3 -2
- package/dist/app/action-access.js +2 -0
- package/dist/config-service.js +11 -3
- package/dist/configuration.js +5 -3
- package/dist/core.d.ts +6 -3
- package/dist/core.js +3 -1
- package/dist/definitions.d.ts +18 -0
- package/dist/discovered.d.ts +6 -0
- package/dist/discovered.js +6 -5
- package/dist/events/service.d.ts +2 -0
- package/dist/events/service.js +44 -9
- package/dist/events/types.d.ts +10 -6
- package/dist/inspection/inventory.d.ts +21 -2
- package/dist/inspection/inventory.js +30 -0
- package/dist/inspection/plugin-origin.d.ts +60 -0
- package/dist/inspection/plugin-origin.js +128 -0
- package/dist/interceptors/define.d.ts +6 -1
- package/dist/interceptors/define.js +7 -3
- package/dist/interceptors/service-observers.d.ts +1 -1
- package/dist/interceptors/service-observers.js +9 -2
- package/dist/lifecycle/controller.js +8 -7
- package/dist/lifecycle/reconcile.d.ts +6 -0
- package/dist/lifecycle/reconcile.js +3 -2
- package/dist/metadata.d.ts +26 -1
- package/dist/metadata.js +92 -10
- package/dist/name-resolution.d.ts +11 -0
- package/dist/name-resolution.js +24 -0
- package/dist/names.d.ts +4 -0
- package/dist/runtime.d.ts +10 -2
- package/dist/runtime.js +70 -14
- package/dist/service-key.js +7 -1
- package/dist/service-names.js +6 -5
- package/dist/settings/access.js +5 -3
- package/dist/settings/define.d.ts +2 -1
- package/dist/settings/store.js +3 -2
- package/dist/slots/define.d.ts +2 -1
- package/dist/slots/runtime.js +4 -2
- package/dist/slots/select.js +4 -1
- package/dist/slots/types.d.ts +12 -10
- package/package.json +4 -3
- package/testing/index.mjs +2 -9
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginMetadata } from '../definitions.js';
|
|
2
2
|
import type { LifecyclePhase, LifecycleSnapshot } from '../lifecycle/state.js';
|
|
3
3
|
import type { BitaKitRuntime } from '../runtime.js';
|
|
4
|
+
import { type PluginOrigin, type PackageIdentity, type PluginMembership } from './plugin-origin.js';
|
|
4
5
|
export type InventoryKind = 'service' | 'action' | 'event' | 'page' | 'setting' | 'slot' | 'widget' | 'provider' | 'config' | 'interceptor';
|
|
5
6
|
export type InventoryDeclaration = Readonly<{
|
|
6
7
|
kind: InventoryKind;
|
|
@@ -8,15 +9,17 @@ export type InventoryDeclaration = Readonly<{
|
|
|
8
9
|
source: string | null;
|
|
9
10
|
resolution: 'resolved' | 'file';
|
|
10
11
|
}>;
|
|
11
|
-
export type InventoryMetadata = Readonly<Pick<PluginMetadata, 'name' | 'description' | 'version' | 'license' | 'homepage' | 'tags' | 'coverImage'> & {
|
|
12
|
+
export type InventoryMetadata = Readonly<Pick<PluginMetadata, 'name' | 'title' | 'description' | 'version' | 'license' | 'homepage' | 'tags' | 'keywords' | 'repository' | 'coverImage'> & {
|
|
12
13
|
author?: string;
|
|
13
14
|
support?: string;
|
|
14
15
|
}>;
|
|
15
16
|
export type InventoryPlugin = Readonly<{
|
|
16
|
-
/**
|
|
17
|
+
/** Inventory key within this installation; physical package keys may change with hoisting. */
|
|
17
18
|
id: string;
|
|
18
19
|
pluginId: string | null;
|
|
19
20
|
enabled: boolean | null;
|
|
21
|
+
/** Static activation selection, separate from runtime enablement; null means not applicable. */
|
|
22
|
+
selected?: boolean | null;
|
|
20
23
|
source: Readonly<{
|
|
21
24
|
kind: 'runtime' | 'file' | 'package';
|
|
22
25
|
path: string | null;
|
|
@@ -24,6 +27,14 @@ export type InventoryPlugin = Readonly<{
|
|
|
24
27
|
metadata: InventoryMetadata;
|
|
25
28
|
dependencies: readonly string[] | null;
|
|
26
29
|
declarations: readonly InventoryDeclaration[] | null;
|
|
30
|
+
/** Additive host evidence; older inventory producers may omit these fields. */
|
|
31
|
+
origin?: PluginOrigin;
|
|
32
|
+
application?: boolean;
|
|
33
|
+
parent?: string | null;
|
|
34
|
+
package?: PackageIdentity | null;
|
|
35
|
+
declaredMembership?: readonly string[] | null;
|
|
36
|
+
membership?: PluginMembership;
|
|
37
|
+
metadataWarnings?: readonly string[];
|
|
27
38
|
}>;
|
|
28
39
|
export type InventoryLive = Readonly<{
|
|
29
40
|
revision: number;
|
|
@@ -64,6 +75,10 @@ export type RuntimeInventory = Readonly<{
|
|
|
64
75
|
static: Readonly<{
|
|
65
76
|
plugins: readonly InventoryPlugin[];
|
|
66
77
|
}>;
|
|
78
|
+
/** Optional passive-tooling diagnostics, without executing package code. */
|
|
79
|
+
diagnostics?: Readonly<{
|
|
80
|
+
identityConflicts: readonly string[];
|
|
81
|
+
}>;
|
|
67
82
|
/** Null means there is no running process to inspect, never an empty/healthy runtime. */
|
|
68
83
|
live: InventoryLive | null;
|
|
69
84
|
}>;
|
|
@@ -79,6 +94,10 @@ export declare function observeRuntimeInventory(runtime: BitaKitRuntime): {
|
|
|
79
94
|
static: Readonly<{
|
|
80
95
|
plugins: readonly InventoryPlugin[];
|
|
81
96
|
}>;
|
|
97
|
+
/** Optional passive-tooling diagnostics, without executing package code. */
|
|
98
|
+
diagnostics?: Readonly<{
|
|
99
|
+
identityConflicts: readonly string[];
|
|
100
|
+
}>;
|
|
82
101
|
/** Null means there is no running process to inspect, never an empty/healthy runtime. */
|
|
83
102
|
live: InventoryLive | null;
|
|
84
103
|
}>;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { projectPluginMetadata } from '../metadata.js';
|
|
1
2
|
import { contributionSource } from '../contribution-origin.js';
|
|
3
|
+
import { pluginOrigin, pluginMembership, } from './plugin-origin.js';
|
|
2
4
|
/** Public declaration metadata only; no icons, functions, defaults, credentials or arbitrary fields. */
|
|
3
5
|
export function inventoryMetadata(metadata = {}) {
|
|
6
|
+
metadata = projectPluginMetadata(metadata).metadata;
|
|
4
7
|
const result = {};
|
|
5
8
|
for (const key of [
|
|
6
9
|
'name',
|
|
10
|
+
'title',
|
|
7
11
|
'description',
|
|
8
12
|
'version',
|
|
9
13
|
'license',
|
|
@@ -20,6 +24,13 @@ export function inventoryMetadata(metadata = {}) {
|
|
|
20
24
|
result.support = support;
|
|
21
25
|
if (metadata.tags)
|
|
22
26
|
result.tags = Object.freeze([...metadata.tags]);
|
|
27
|
+
if (metadata.keywords)
|
|
28
|
+
result.keywords = Object.freeze([...metadata.keywords]);
|
|
29
|
+
if (metadata.repository)
|
|
30
|
+
result.repository =
|
|
31
|
+
typeof metadata.repository === 'string'
|
|
32
|
+
? metadata.repository
|
|
33
|
+
: Object.freeze({ ...metadata.repository });
|
|
23
34
|
return Object.freeze(result);
|
|
24
35
|
}
|
|
25
36
|
/** Both static tooling and runtime readers produce this versioned, serializable envelope. */
|
|
@@ -38,10 +49,28 @@ export function inspectRuntime(runtime) {
|
|
|
38
49
|
resolution: 'resolved',
|
|
39
50
|
});
|
|
40
51
|
const lifecycle = runtime.lifecycle.get();
|
|
52
|
+
const provenance = (id, parent) => {
|
|
53
|
+
const application = id === (runtime.config.appId ?? 'app');
|
|
54
|
+
const source = pluginOrigin(runtime.config.plugins?.find((plugin) => plugin.id === id));
|
|
55
|
+
return {
|
|
56
|
+
application,
|
|
57
|
+
origin: source?.kind ?? (application ? 'local' : 'unknown'),
|
|
58
|
+
...(source?.metadataWarnings?.length ? { metadataWarnings: source.metadataWarnings } : {}),
|
|
59
|
+
parent: parent ?? null,
|
|
60
|
+
package: source?.package ?? null,
|
|
61
|
+
declaredMembership: source?.memberOf ?? null,
|
|
62
|
+
membership: pluginMembership(source, {
|
|
63
|
+
application,
|
|
64
|
+
bundle: runtime.config.bundle,
|
|
65
|
+
knownBundles: runtime.config.knownBundles,
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
41
69
|
return createInventory([
|
|
42
70
|
...runtime.modules.map((module) => Object.freeze({
|
|
43
71
|
id: module.id,
|
|
44
72
|
pluginId: module.id,
|
|
73
|
+
...provenance(module.id, module.parent),
|
|
45
74
|
enabled: true,
|
|
46
75
|
source: Object.freeze({ kind: 'runtime', path: null }),
|
|
47
76
|
metadata: inventoryMetadata(module.metadata),
|
|
@@ -66,6 +95,7 @@ export function inspectRuntime(runtime) {
|
|
|
66
95
|
.map((plugin) => Object.freeze({
|
|
67
96
|
id: plugin.id,
|
|
68
97
|
pluginId: plugin.id,
|
|
98
|
+
...provenance(plugin.id, plugin.parent),
|
|
69
99
|
enabled: false,
|
|
70
100
|
source: Object.freeze({ kind: 'runtime', path: null }),
|
|
71
101
|
metadata: inventoryMetadata(plugin.metadata),
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PluginMetadataSources } from '../metadata.js';
|
|
2
|
+
import type { Plugin } from '../definitions.js';
|
|
3
|
+
export type PluginOrigin = 'local' | 'included' | 'package' | 'unknown';
|
|
4
|
+
export type PackageIdentity = Readonly<{
|
|
5
|
+
/** Complete lowercase name, including its npm scope. Never a runtime plugin ID. */
|
|
6
|
+
name: string;
|
|
7
|
+
version: string | null;
|
|
8
|
+
}>;
|
|
9
|
+
export type PluginOriginRecord = Readonly<{
|
|
10
|
+
kind: Exclude<PluginOrigin, 'unknown'>;
|
|
11
|
+
package?: PackageIdentity | null;
|
|
12
|
+
/** Authored membership; discovery validates it. ['*'] explicitly means general purpose. */
|
|
13
|
+
memberOf?: readonly string[] | null;
|
|
14
|
+
/** Authoritative ID of this single definition, never a prediction from its npm name. */
|
|
15
|
+
pluginId?: string | null;
|
|
16
|
+
/** Sanitized, statically available package sources; never executable UI metadata. */
|
|
17
|
+
metadata?: PluginMetadataSources;
|
|
18
|
+
/** Manifest path used by the host's static diagnostics, when known. */
|
|
19
|
+
metadataLocation?: string;
|
|
20
|
+
metadataWarnings?: readonly string[];
|
|
21
|
+
}>;
|
|
22
|
+
export type PluginBundle = Readonly<{
|
|
23
|
+
id: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
}>;
|
|
26
|
+
export type PluginMembership = Readonly<{
|
|
27
|
+
state: 'derived' | 'declared' | 'general' | 'unspecified';
|
|
28
|
+
bundles: readonly Readonly<{
|
|
29
|
+
id: string;
|
|
30
|
+
resolved: boolean;
|
|
31
|
+
label?: string;
|
|
32
|
+
}>[];
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Binds host-recorded provenance to a fresh definition without changing execution behavior.
|
|
36
|
+
* This is an attribution API for trusted hosts, not a sandbox or an authorization boundary.
|
|
37
|
+
*/
|
|
38
|
+
export declare function withPluginOrigin<T extends Plugin>(plugin: T, record: PluginOriginRecord): T;
|
|
39
|
+
/** Reads host evidence for this definition only; never guesses from an ID or metadata. */
|
|
40
|
+
export declare function pluginOrigin(plugin: Plugin | undefined): PluginOriginRecord | undefined;
|
|
41
|
+
/** Internal composition transforms retain the host's evidence; replacement plugins do not. */
|
|
42
|
+
export declare function preservePluginOrigin<T extends Plugin>(from: Plugin, to: T): T;
|
|
43
|
+
/** Pure grouping projection. Membership never changes dependencies, ownership or enablement. */
|
|
44
|
+
export declare function pluginMembership(origin: PluginOriginRecord | undefined, context?: {
|
|
45
|
+
application?: boolean;
|
|
46
|
+
bundle?: string;
|
|
47
|
+
knownBundles?: readonly PluginBundle[];
|
|
48
|
+
}): PluginMembership;
|
|
49
|
+
export type PluginGroup<T> = Readonly<{
|
|
50
|
+
key: string;
|
|
51
|
+
kind: 'application' | 'bundle' | 'unresolved' | 'general' | 'unspecified';
|
|
52
|
+
label?: string;
|
|
53
|
+
bundleId?: string;
|
|
54
|
+
entries: readonly T[];
|
|
55
|
+
}>;
|
|
56
|
+
/** Groups distinct records; callers keep one shared instance/toggle for repeated appearances. */
|
|
57
|
+
export declare function groupPlugins<T extends {
|
|
58
|
+
id: string;
|
|
59
|
+
membership: PluginMembership;
|
|
60
|
+
}>(plugins: readonly T[], bundle?: string): readonly PluginGroup<T>[];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { projectPluginMetadata, projectPluginMetadataSources, } from '../metadata.js';
|
|
2
|
+
// Host evidence follows the actual definition, never its ID or an array position. Definitions
|
|
3
|
+
// supplied later without a binding remain unknown, even if they replace the same runtime ID.
|
|
4
|
+
const origins = new WeakMap();
|
|
5
|
+
/**
|
|
6
|
+
* Binds host-recorded provenance to a fresh definition without changing execution behavior.
|
|
7
|
+
* This is an attribution API for trusted hosts, not a sandbox or an authorization boundary.
|
|
8
|
+
*/
|
|
9
|
+
export function withPluginOrigin(plugin, record) {
|
|
10
|
+
if (record.pluginId != null && record.pluginId !== plugin.id)
|
|
11
|
+
throw new Error(`Package "${record.package?.name ?? 'unknown'}" declares plugin ID "${record.pluginId}" but loaded "${plugin.id}".`);
|
|
12
|
+
const packageLocation = record.metadataLocation ?? `package "${record.package?.name ?? 'unknown'}" manifest`;
|
|
13
|
+
const declared = { value: plugin.metadata, location: `plugin "${plugin.id}" metadata` };
|
|
14
|
+
const canonical = { value: record.metadata?.canonical, location: packageLocation };
|
|
15
|
+
const projected = record.metadata
|
|
16
|
+
? projectPluginMetadataSources([
|
|
17
|
+
...(record.kind === 'included' ? [declared, canonical] : [canonical, declared]),
|
|
18
|
+
{ value: record.metadata.legacy, location: `${packageLocation} legacy fields` },
|
|
19
|
+
], { packageName: record.package?.name })
|
|
20
|
+
: undefined;
|
|
21
|
+
const warnings = [
|
|
22
|
+
...new Set([
|
|
23
|
+
...(origins.get(plugin)?.metadataWarnings ?? []),
|
|
24
|
+
...(record.metadataWarnings ?? []),
|
|
25
|
+
...(projected?.warnings ?? []),
|
|
26
|
+
]),
|
|
27
|
+
];
|
|
28
|
+
const definition = {
|
|
29
|
+
...plugin,
|
|
30
|
+
...(projected ? { metadata: { ...plugin.metadata, ...projected.metadata } } : {}),
|
|
31
|
+
};
|
|
32
|
+
origins.set(definition, Object.freeze({
|
|
33
|
+
kind: record.kind,
|
|
34
|
+
...(record.metadata
|
|
35
|
+
? {
|
|
36
|
+
metadata: Object.freeze({
|
|
37
|
+
canonical: Object.freeze(projectPluginMetadata(record.metadata.canonical).metadata),
|
|
38
|
+
legacy: Object.freeze(projectPluginMetadata(record.metadata.legacy).metadata),
|
|
39
|
+
}),
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
...(record.metadataLocation ? { metadataLocation: record.metadataLocation } : {}),
|
|
43
|
+
...(warnings.length ? { metadataWarnings: Object.freeze(warnings) } : {}),
|
|
44
|
+
...(record.pluginId == null ? {} : { pluginId: record.pluginId }),
|
|
45
|
+
package: record.package
|
|
46
|
+
? Object.freeze({
|
|
47
|
+
name: record.package.name.toLowerCase(),
|
|
48
|
+
version: record.package.version,
|
|
49
|
+
})
|
|
50
|
+
: null,
|
|
51
|
+
memberOf: record.memberOf ? Object.freeze([...record.memberOf]) : null,
|
|
52
|
+
}));
|
|
53
|
+
return definition;
|
|
54
|
+
}
|
|
55
|
+
/** Reads host evidence for this definition only; never guesses from an ID or metadata. */
|
|
56
|
+
export function pluginOrigin(plugin) {
|
|
57
|
+
return plugin && origins.get(plugin);
|
|
58
|
+
}
|
|
59
|
+
/** Internal composition transforms retain the host's evidence; replacement plugins do not. */
|
|
60
|
+
export function preservePluginOrigin(from, to) {
|
|
61
|
+
const record = origins.get(from);
|
|
62
|
+
if (record)
|
|
63
|
+
origins.set(to, record);
|
|
64
|
+
return to;
|
|
65
|
+
}
|
|
66
|
+
/** Pure grouping projection. Membership never changes dependencies, ownership or enablement. */
|
|
67
|
+
export function pluginMembership(origin, context = {}) {
|
|
68
|
+
const current = context.bundle?.toLowerCase();
|
|
69
|
+
const known = new Map((context.knownBundles ?? []).map((item) => [item.id.toLowerCase(), item]));
|
|
70
|
+
if (current && !known.has(current))
|
|
71
|
+
known.set(current, { id: current });
|
|
72
|
+
const project = (state, ids) => Object.freeze({
|
|
73
|
+
state,
|
|
74
|
+
bundles: Object.freeze([...new Set(ids.map((id) => id.toLowerCase()))].sort().map((id) => Object.freeze({
|
|
75
|
+
id,
|
|
76
|
+
resolved: known.has(id),
|
|
77
|
+
...(known.get(id)?.label ? { label: known.get(id).label } : {}),
|
|
78
|
+
}))),
|
|
79
|
+
});
|
|
80
|
+
if (context.application || origin?.kind === 'local')
|
|
81
|
+
return project('derived', current ? [current] : []);
|
|
82
|
+
if (!origin)
|
|
83
|
+
return project('unspecified', []);
|
|
84
|
+
const declaration = origin.memberOf;
|
|
85
|
+
if (!Array.isArray(declaration) ||
|
|
86
|
+
!declaration.length ||
|
|
87
|
+
declaration.some((id) => typeof id !== 'string' || !id))
|
|
88
|
+
return project('unspecified', []);
|
|
89
|
+
if (declaration.includes('*'))
|
|
90
|
+
return project(declaration.length === 1 ? 'general' : 'unspecified', []);
|
|
91
|
+
return project('declared', declaration);
|
|
92
|
+
}
|
|
93
|
+
/** Groups distinct records; callers keep one shared instance/toggle for repeated appearances. */
|
|
94
|
+
export function groupPlugins(plugins, bundle) {
|
|
95
|
+
const current = bundle?.toLowerCase();
|
|
96
|
+
const groups = new Map();
|
|
97
|
+
const add = (key, kind, plugin, details = {}) => {
|
|
98
|
+
if (!groups.has(key))
|
|
99
|
+
groups.set(key, { key, kind, ...details, entries: [] });
|
|
100
|
+
const group = groups.get(key);
|
|
101
|
+
if (!group.entries.some((entry) => entry.id === plugin.id))
|
|
102
|
+
group.entries.push(plugin);
|
|
103
|
+
};
|
|
104
|
+
for (const plugin of plugins) {
|
|
105
|
+
const membership = plugin.membership;
|
|
106
|
+
if (membership.state === 'derived')
|
|
107
|
+
add('application', 'application', plugin);
|
|
108
|
+
else if (membership.state === 'general' || membership.state === 'unspecified')
|
|
109
|
+
add(membership.state, membership.state, plugin);
|
|
110
|
+
else
|
|
111
|
+
for (const entry of membership.bundles) {
|
|
112
|
+
if (entry.id === current)
|
|
113
|
+
add('application', 'application', plugin);
|
|
114
|
+
else
|
|
115
|
+
add(`bundle:${entry.id}`, entry.resolved ? 'bundle' : 'unresolved', plugin, {
|
|
116
|
+
bundleId: entry.id,
|
|
117
|
+
label: entry.label,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const rank = { application: 0, bundle: 1, unresolved: 2, general: 3, unspecified: 4 };
|
|
122
|
+
const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
123
|
+
return Object.freeze([...groups.values()]
|
|
124
|
+
.sort((a, b) => rank[a.kind] - rank[b.kind] ||
|
|
125
|
+
compare(a.label ?? a.bundleId ?? a.key, b.label ?? b.bundleId ?? b.key) ||
|
|
126
|
+
compare(a.key, b.key))
|
|
127
|
+
.map((group) => Object.freeze({ ...group, entries: Object.freeze(group.entries) })));
|
|
128
|
+
}
|
|
@@ -38,6 +38,9 @@ export type ServiceCall<Name extends string = string, Key extends string = strin
|
|
|
38
38
|
/** The called service's ID; a glob or alias target still reports the actual ID. */
|
|
39
39
|
readonly service: string;
|
|
40
40
|
readonly method: Key;
|
|
41
|
+
/** Supplied by runtime observers; optional to preserve manually constructed legacy calls. */
|
|
42
|
+
readonly callId?: number;
|
|
43
|
+
readonly startedAt?: number;
|
|
41
44
|
readonly args: Readonly<Parameters<MethodOf<Name, Key>>>;
|
|
42
45
|
};
|
|
43
46
|
/**
|
|
@@ -59,9 +62,11 @@ export type ServiceInterceptorSpec<Name extends string = string, Key extends str
|
|
|
59
62
|
order?: number;
|
|
60
63
|
before?(call: ServiceCall<Name, Key> & ServiceHookContext): void;
|
|
61
64
|
after?(call: ServiceCall<Name, Key> & ServiceHookContext & {
|
|
65
|
+
readonly durationMs?: number;
|
|
62
66
|
readonly result: Awaited<ReturnType<MethodOf<Name, Key>>>;
|
|
63
67
|
}): void;
|
|
64
68
|
onError?(call: ServiceCall<Name, Key> & ServiceHookContext & {
|
|
69
|
+
readonly durationMs?: number;
|
|
65
70
|
readonly error: unknown;
|
|
66
71
|
}): void;
|
|
67
72
|
};
|
|
@@ -81,5 +86,5 @@ export declare function isServiceInterceptor(spec: object): spec is ServiceInter
|
|
|
81
86
|
kind: 'interceptor';
|
|
82
87
|
};
|
|
83
88
|
/** Glob matching for action IDs and service names: exact, `prefix.*`, or `*`. */
|
|
84
|
-
export declare function matchesTarget(target: InterceptorTarget, id: string): boolean;
|
|
89
|
+
export declare function matchesTarget(target: InterceptorTarget, id: string, names?: readonly string[]): boolean;
|
|
85
90
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from '../name-resolution.js';
|
|
1
2
|
export function defineInterceptor(spec) {
|
|
2
3
|
if (!spec || typeof spec !== 'object')
|
|
3
4
|
throw new Error('defineInterceptor expects an object.');
|
|
@@ -13,11 +14,14 @@ export function isServiceInterceptor(spec) {
|
|
|
13
14
|
return 'service' in spec && spec.service !== undefined;
|
|
14
15
|
}
|
|
15
16
|
/** Glob matching for action IDs and service names: exact, `prefix.*`, or `*`. */
|
|
16
|
-
export function matchesTarget(target, id) {
|
|
17
|
+
export function matchesTarget(target, id, names = [id]) {
|
|
17
18
|
const patterns = typeof target === 'string' ? [target] : target;
|
|
18
19
|
return patterns.some((pattern) => pattern === '*'
|
|
19
20
|
? true
|
|
20
21
|
: pattern.endsWith('.*')
|
|
21
|
-
? id.startsWith(pattern.slice(0, -
|
|
22
|
-
|
|
22
|
+
? id.startsWith(`${resolveName(pattern.slice(0, -2), names.flatMap((name) => name
|
|
23
|
+
.split('.')
|
|
24
|
+
.slice(0, -1)
|
|
25
|
+
.map((_, index, parts) => parts.slice(0, index + 1).join('.'))))}.`)
|
|
26
|
+
: resolveName(pattern, names) === id);
|
|
23
27
|
}
|
|
@@ -4,4 +4,4 @@ import { type InterceptorSpec } from './define.js';
|
|
|
4
4
|
* container consumers receive the same wrapper; frozen instances are supported. `services`
|
|
5
5
|
* is read when a call happens, because the service tree exists only after the container does.
|
|
6
6
|
*/
|
|
7
|
-
export declare function serviceObserver(interceptors: readonly InterceptorSpec[], namesOf: (id: string) => readonly string[], services: () => unknown): (id: string, instance: any, active: () => boolean) => any;
|
|
7
|
+
export declare function serviceObserver(interceptors: readonly InterceptorSpec[], namesOf: (id: string) => readonly string[], services: () => unknown, allNames?: () => readonly string[]): (id: string, instance: any, active: () => boolean) => any;
|
|
@@ -15,7 +15,8 @@ function notify(callback, event) {
|
|
|
15
15
|
* container consumers receive the same wrapper; frozen instances are supported. `services`
|
|
16
16
|
* is read when a call happens, because the service tree exists only after the container does.
|
|
17
17
|
*/
|
|
18
|
-
export function serviceObserver(interceptors, namesOf, services) {
|
|
18
|
+
export function serviceObserver(interceptors, namesOf, services, allNames) {
|
|
19
|
+
let nextCallId = 0;
|
|
19
20
|
const entries = interceptors
|
|
20
21
|
.filter(isServiceInterceptor)
|
|
21
22
|
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
@@ -23,7 +24,7 @@ export function serviceObserver(interceptors, namesOf, services) {
|
|
|
23
24
|
if (!instance || (typeof instance !== 'object' && typeof instance !== 'function'))
|
|
24
25
|
return instance;
|
|
25
26
|
const names = [id, ...namesOf(id)];
|
|
26
|
-
const selected = entries.filter((entry) => names.some((name) => matchesTarget(entry.service, name)));
|
|
27
|
+
const selected = entries.filter((entry) => names.some((name) => matchesTarget(entry.service, name, allNames?.() ?? names)));
|
|
27
28
|
if (!selected.length)
|
|
28
29
|
return instance;
|
|
29
30
|
const cache = new Map();
|
|
@@ -51,12 +52,18 @@ export function serviceObserver(interceptors, namesOf, services) {
|
|
|
51
52
|
// A function Proxy keeps the method's own properties (for example `translate.has`);
|
|
52
53
|
// only the call itself is observed.
|
|
53
54
|
const call = (...args) => {
|
|
55
|
+
const callId = ++nextCallId;
|
|
56
|
+
const startedAt = Date.now();
|
|
57
|
+
const start = performance.now();
|
|
54
58
|
const emit = (phase, extra = {}) => {
|
|
55
59
|
if (!active())
|
|
56
60
|
return;
|
|
57
61
|
for (const entry of observers)
|
|
58
62
|
notify(entry[phase], {
|
|
59
63
|
service: id,
|
|
64
|
+
callId,
|
|
65
|
+
startedAt,
|
|
66
|
+
...(phase === 'before' ? {} : { durationMs: performance.now() - start }),
|
|
60
67
|
method: key,
|
|
61
68
|
args: Object.freeze([...args]),
|
|
62
69
|
services: services(),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from '../name-resolution.js';
|
|
1
2
|
import { createActionList } from '../actions/core.js';
|
|
2
3
|
import { BitaKitRuntime } from '../runtime.js';
|
|
3
4
|
import { isBitaKitStartupError } from '../startup-error.js';
|
|
@@ -30,19 +31,19 @@ export function failedPluginClosure(plugins, failures) {
|
|
|
30
31
|
.flatMap((plugin) => plugin.ui?.providers?.map((provider) => provider.id) ?? []));
|
|
31
32
|
for (const plugin of plugins) {
|
|
32
33
|
const requirements = [
|
|
33
|
-
...(plugin.dependencies ?? []).map((id) => off.has(id)),
|
|
34
|
+
...(plugin.dependencies ?? []).map((id) => off.has(resolveName(id, plugins.map((plugin) => plugin.id)))),
|
|
34
35
|
...Object.values(plugin.services ?? {})
|
|
35
36
|
.flatMap((value) => value.requires ?? [])
|
|
36
|
-
.map((name) => unavailable.has(name)),
|
|
37
|
+
.map((name) => unavailable.has(resolveName(name, plugins.flatMap(pluginServiceNames)))),
|
|
37
38
|
...Object.values(plugin.actions ?? {})
|
|
38
39
|
.flatMap((value) => value.requires ?? [])
|
|
39
|
-
.map((name) => unavailable.has(name)),
|
|
40
|
+
.map((name) => unavailable.has(resolveName(name, plugins.flatMap(pluginServiceNames)))),
|
|
40
41
|
...(plugin.interceptors ?? [])
|
|
41
42
|
.flatMap((value) => value.requires ?? [])
|
|
42
|
-
.map((name) => unavailable.has(name)),
|
|
43
|
+
.map((name) => unavailable.has(resolveName(name, plugins.flatMap(pluginServiceNames)))),
|
|
43
44
|
...(plugin.ui?.providers ?? [])
|
|
44
45
|
.flatMap((value) => value.requires ?? [])
|
|
45
|
-
.map((name) => unavailableProviders.has(name)),
|
|
46
|
+
.map((name) => unavailableProviders.has(resolveName(name, plugins.flatMap((plugin) => plugin.ui?.providers?.map((provider) => provider.id) ?? [])))),
|
|
46
47
|
];
|
|
47
48
|
if (!off.has(plugin.id) && requirements.some(Boolean)) {
|
|
48
49
|
off.add(plugin.id);
|
|
@@ -99,7 +100,7 @@ export class RuntimeController {
|
|
|
99
100
|
const failure = failed.get(id);
|
|
100
101
|
const phase = failure
|
|
101
102
|
? 'failed'
|
|
102
|
-
: this.off.has(id)
|
|
103
|
+
: this.off.has(resolveName(id, (this.config.plugins ?? []).map((plugin) => plugin.id)))
|
|
103
104
|
? 'blocked'
|
|
104
105
|
: (states.get(id)?.phase ?? 'idle');
|
|
105
106
|
const previous = this.store.get().plugins.find((entry) => entry.id === id);
|
|
@@ -148,7 +149,7 @@ export class RuntimeController {
|
|
|
148
149
|
...this.config,
|
|
149
150
|
plugins: active,
|
|
150
151
|
configOverrides: this.config.configOverrides &&
|
|
151
|
-
Object.fromEntries(Object.entries(this.config.configOverrides).filter(([id]) => !this.off.has(id))),
|
|
152
|
+
Object.fromEntries(Object.entries(this.config.configOverrides).filter(([id]) => !this.off.has(resolveName(id, (this.config.plugins ?? []).map((plugin) => plugin.id))))),
|
|
152
153
|
ui: this.config.ui && {
|
|
153
154
|
...this.config.ui,
|
|
154
155
|
providers: this.config.ui.providers?.filter((provider) => !removedProviders.has(provider)),
|
|
@@ -25,6 +25,12 @@ export type PluginToggleRequest = PluginChangeOptions & (Readonly<{
|
|
|
25
25
|
id: string;
|
|
26
26
|
dependents: 'stop' | 'refuse';
|
|
27
27
|
}>);
|
|
28
|
+
/** Complete owned cohort replacement. External dependents must be updated separately. */
|
|
29
|
+
export type PluginReplacementRequest = PluginChangeOptions & Readonly<{
|
|
30
|
+
operation: 'replace';
|
|
31
|
+
ids: readonly string[];
|
|
32
|
+
plugins: readonly Plugin[];
|
|
33
|
+
}>;
|
|
28
34
|
export type PluginChangeReason = 'busy' | 'cleanup-failed' | 'stale' | 'protected' | 'dependents' | 'owner-disabled' | 'composition' | 'invalid' | 'pending-settings';
|
|
29
35
|
/** Read-only planning result. It grants no authority to execute a stale operation. */
|
|
30
36
|
export type PluginChangePreview = Readonly<{
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from '../name-resolution.js';
|
|
1
2
|
/** Lifecycle edges include required service aliases, not just explicit plugin dependencies. */
|
|
2
3
|
export function pluginDependencies(modules) {
|
|
3
4
|
const owners = new Map();
|
|
@@ -9,10 +10,10 @@ export function pluginDependencies(modules) {
|
|
|
9
10
|
return new Map(modules.map((module) => [
|
|
10
11
|
module.id,
|
|
11
12
|
new Set([
|
|
12
|
-
...(module.dependencies ?? []),
|
|
13
|
+
...(module.dependencies ?? []).map((id) => resolveName(id, modules.map((entry) => entry.id))),
|
|
13
14
|
...[...module.services, ...module.actions, ...(module.interceptors ?? [])]
|
|
14
15
|
.flatMap((value) => value.requires ?? [])
|
|
15
|
-
.map((name) => owners.get(name))
|
|
16
|
+
.map((name) => owners.get(resolveName(name, owners.keys())))
|
|
16
17
|
.filter((id) => !!id && id !== module.id),
|
|
17
18
|
]),
|
|
18
19
|
]));
|
package/dist/metadata.d.ts
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
import type { PluginMetadata } from './definitions.js';
|
|
2
|
-
|
|
2
|
+
export type PluginMetadataSources = Readonly<{
|
|
3
|
+
canonical?: PluginMetadata;
|
|
4
|
+
legacy?: PluginMetadata;
|
|
5
|
+
}>;
|
|
6
|
+
/** Shared display fallback; callers apply translations and explicit section labels first. */
|
|
7
|
+
export declare function pluginDisplayTitle(metadata: Pick<PluginMetadata, 'title' | 'name'> | undefined, fallback: string): string;
|
|
8
|
+
export declare function pluginDisplayTitle(metadata: Pick<PluginMetadata, 'title' | 'name'> | undefined): string | undefined;
|
|
9
|
+
/** One pure projection for build, discovery and runtime. Invalid optional values fall back per
|
|
10
|
+
* field; executable icons and arbitrary package fields never enter the serializable result. */
|
|
11
|
+
export declare function projectPluginMetadata(canonical?: unknown, ...legacy: unknown[]): {
|
|
12
|
+
metadata: PluginMetadata;
|
|
13
|
+
warnings: string[];
|
|
14
|
+
};
|
|
15
|
+
/** Projects ordered sources with truthful diagnostic labels. The first valid field wins. */
|
|
16
|
+
export declare function projectPluginMetadataSources(sources: readonly {
|
|
17
|
+
value: unknown;
|
|
18
|
+
location: string;
|
|
19
|
+
}[], { packageName }?: {
|
|
20
|
+
packageName?: string;
|
|
21
|
+
}): {
|
|
22
|
+
metadata: PluginMetadata;
|
|
23
|
+
warnings: string[];
|
|
24
|
+
};
|
|
25
|
+
/** Standard npm data plus the existing bitakit block; npm name stays package identity. */
|
|
26
|
+
export declare function packageMetadataSources(source: Record<string, unknown>): PluginMetadataSources;
|
|
27
|
+
/** Compatibility helper: copies supported public fields, without arbitrary manifest data. */
|
|
3
28
|
export declare function pluginMetadata(source: PluginMetadata): PluginMetadata;
|
package/dist/metadata.js
CHANGED
|
@@ -1,13 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// Optional descriptive shapes only. Loading policy, npm identity, URLs, licensing and
|
|
3
|
+
// compatibility have their own owners; metadata does not invent additional admission rules.
|
|
4
|
+
const fields = {
|
|
5
|
+
name: z.string(),
|
|
6
|
+
title: z.string(),
|
|
7
|
+
version: z.string(),
|
|
8
|
+
description: z.string(),
|
|
9
|
+
author: z.union([
|
|
10
|
+
z.string(),
|
|
11
|
+
z.object({ name: z.string(), email: z.string().optional(), url: z.string().optional() }),
|
|
12
|
+
]),
|
|
13
|
+
homepage: z.string(),
|
|
14
|
+
bugs: z.union([
|
|
15
|
+
z.string(),
|
|
16
|
+
z.object({ url: z.string().optional(), email: z.string().optional() }),
|
|
17
|
+
]),
|
|
18
|
+
license: z.string(),
|
|
19
|
+
coverImage: z.string(),
|
|
20
|
+
tags: z.array(z.string()),
|
|
21
|
+
keywords: z.array(z.string()),
|
|
22
|
+
repository: z.union([
|
|
23
|
+
z.string(),
|
|
24
|
+
z.object({ type: z.string().optional(), url: z.string(), directory: z.string().optional() }),
|
|
25
|
+
]),
|
|
26
|
+
};
|
|
27
|
+
export function pluginDisplayTitle(metadata, fallback) {
|
|
28
|
+
return metadata?.title ?? metadata?.name ?? fallback;
|
|
29
|
+
}
|
|
30
|
+
/** One pure projection for build, discovery and runtime. Invalid optional values fall back per
|
|
31
|
+
* field; executable icons and arbitrary package fields never enter the serializable result. */
|
|
32
|
+
export function projectPluginMetadata(canonical = {}, ...legacy) {
|
|
33
|
+
return projectPluginMetadataSources([
|
|
34
|
+
{ value: canonical, location: 'canonical metadata' },
|
|
35
|
+
...legacy.map((value) => ({ value, location: 'legacy metadata' })),
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
/** Projects ordered sources with truthful diagnostic labels. The first valid field wins. */
|
|
39
|
+
export function projectPluginMetadataSources(sources, { packageName } = {}) {
|
|
40
|
+
const metadata = {};
|
|
41
|
+
const warnings = [];
|
|
42
|
+
const owners = new Map();
|
|
43
|
+
for (const key of Object.keys(fields)) {
|
|
44
|
+
for (const [index, { value: source, location }] of sources.entries()) {
|
|
45
|
+
if (!source || typeof source !== 'object')
|
|
46
|
+
continue;
|
|
47
|
+
const value = source[key];
|
|
48
|
+
if (value === undefined)
|
|
49
|
+
continue;
|
|
50
|
+
const parsed = fields[key].safeParse(value);
|
|
51
|
+
if (!parsed.success) {
|
|
52
|
+
warnings.push(`Invalid optional metadata.${key} in ${location}; using the next available source.`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const owner = owners.get(key);
|
|
56
|
+
if (owner === undefined) {
|
|
57
|
+
Object.assign(metadata, { [key]: parsed.data });
|
|
58
|
+
owners.set(key, index);
|
|
59
|
+
}
|
|
60
|
+
else if (JSON.stringify(metadata[key]) !== JSON.stringify(parsed.data)) {
|
|
61
|
+
warnings.push(`Conflicting metadata.${key}: ${sources[owner].location} takes precedence over ${location}.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const titleOwner = owners.get('title');
|
|
66
|
+
const nameOwner = owners.get('name');
|
|
67
|
+
if (titleOwner !== undefined &&
|
|
68
|
+
nameOwner !== undefined &&
|
|
69
|
+
titleOwner !== nameOwner &&
|
|
70
|
+
!(packageName && metadata.name?.toLowerCase() === packageName.toLowerCase()) &&
|
|
71
|
+
metadata.title !== metadata.name)
|
|
72
|
+
warnings.push(`Conflicting display title: metadata.title in ${sources[titleOwner].location} takes precedence over metadata.name in ${sources[nameOwner].location}.`);
|
|
73
|
+
return { metadata, warnings: [...new Set(warnings)] };
|
|
74
|
+
}
|
|
75
|
+
/** Standard npm data plus the existing bitakit block; npm name stays package identity. */
|
|
76
|
+
export function packageMetadataSources(source) {
|
|
77
|
+
const block = source.bitakit ?? source.foundation;
|
|
78
|
+
const bitakit = block && typeof block === 'object' ? block : {};
|
|
79
|
+
const canonical = {};
|
|
80
|
+
for (const key of Object.keys(fields)) {
|
|
81
|
+
if (key === 'name')
|
|
82
|
+
continue;
|
|
83
|
+
const value = ['title', 'tags', 'coverImage'].includes(key) ? bitakit[key] : source[key];
|
|
84
|
+
if (value !== undefined)
|
|
85
|
+
canonical[key] = value;
|
|
86
|
+
}
|
|
4
87
|
return {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
...(description === undefined ? {} : { description }),
|
|
8
|
-
...(author === undefined ? {} : { author }),
|
|
9
|
-
...(homepage === undefined ? {} : { homepage }),
|
|
10
|
-
...(bugs === undefined ? {} : { bugs }),
|
|
11
|
-
...(license === undefined ? {} : { license }),
|
|
88
|
+
canonical,
|
|
89
|
+
legacy: { tags: source.tags, coverImage: source.coverImage },
|
|
12
90
|
};
|
|
13
91
|
}
|
|
92
|
+
/** Compatibility helper: copies supported public fields, without arbitrary manifest data. */
|
|
93
|
+
export function pluginMetadata(source) {
|
|
94
|
+
return projectPluginMetadata(source).metadata;
|
|
95
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Exact spellings remain authoritative; a folded reference must identify exactly one name. */
|
|
2
|
+
export declare function resolveName(name: string, candidates: Iterable<string>): string;
|
|
3
|
+
/** Resolves keys without renaming stored entries or collapsing existing case-only definitions. */
|
|
4
|
+
export declare function namedRecord<T extends object>(record: T): T;
|
|
5
|
+
/** Exact map keys take precedence, including when two existing keys differ only in case. */
|
|
6
|
+
type FoldedKey<Keys extends string, Name extends string> = Keys extends unknown ? Lowercase<Keys> extends Lowercase<Name> ? Keys : never : never;
|
|
7
|
+
export type NameKey<Map, Name extends string> = string extends Name ? never : Name extends keyof Map ? Name : FoldedKey<Extract<keyof Map, string>, Name>;
|
|
8
|
+
export type NamedValue<Map, Name extends string, Fallback = unknown> = [
|
|
9
|
+
NameKey<Map, Name>
|
|
10
|
+
] extends [never] ? Fallback : Map[NameKey<Map, Name>];
|
|
11
|
+
export {};
|