@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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Exact spellings remain authoritative; a folded reference must identify exactly one name. */
|
|
2
|
+
export function resolveName(name, candidates) {
|
|
3
|
+
let match;
|
|
4
|
+
let ambiguous = false;
|
|
5
|
+
for (const candidate of candidates) {
|
|
6
|
+
if (candidate === name)
|
|
7
|
+
return name;
|
|
8
|
+
if (candidate.toLowerCase() !== name.toLowerCase())
|
|
9
|
+
continue;
|
|
10
|
+
if (match !== undefined && match !== candidate)
|
|
11
|
+
ambiguous = true;
|
|
12
|
+
match = candidate;
|
|
13
|
+
}
|
|
14
|
+
if (ambiguous)
|
|
15
|
+
throw new Error(`Ambiguous identifier "${name}". Use the exact registered spelling.`);
|
|
16
|
+
return match ?? name;
|
|
17
|
+
}
|
|
18
|
+
/** Resolves keys without renaming stored entries or collapsing existing case-only definitions. */
|
|
19
|
+
export function namedRecord(record) {
|
|
20
|
+
return new Proxy(record, {
|
|
21
|
+
get: (target, name, receiver) => Reflect.get(target, typeof name === 'string' ? resolveName(name, Object.keys(target)) : name, receiver),
|
|
22
|
+
has: (target, name) => Reflect.has(target, typeof name === 'string' ? resolveName(name, Object.keys(target)) : name),
|
|
23
|
+
});
|
|
24
|
+
}
|
package/dist/names.d.ts
CHANGED
|
@@ -8,3 +8,7 @@ import type { ActionMapOptions } from './actions/types.js';
|
|
|
8
8
|
export type GeneratedName<Known extends string> = ActionMapOptions extends {
|
|
9
9
|
strict: true;
|
|
10
10
|
} ? Known : Known | (string & {});
|
|
11
|
+
/** Checks a caller's string literal without enumerating exponentially many case permutations. */
|
|
12
|
+
export type CheckedName<Name extends string, Known extends string> = ActionMapOptions extends {
|
|
13
|
+
strict: true;
|
|
14
|
+
} ? Lowercase<Name> extends Lowercase<Known> ? Name : never : Name;
|
package/dist/runtime.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { type Feedback, type MessageValues } from './actions/feedback.js';
|
|
|
12
12
|
import { type ContributionHost, type DialogState, type FeedbackOutcome, type OpenableDefinition, type Override } from './contributions/index.js';
|
|
13
13
|
import type { Confirmation } from './confirmation.js';
|
|
14
14
|
import { type LifecycleState } from './lifecycle/state.js';
|
|
15
|
-
import { type PluginUpdateResult, type PluginDependentOptions, type PluginChangeOptions, type PluginToggleRequest, type PluginChangePreview } from './lifecycle/reconcile.js';
|
|
15
|
+
import { type PluginUpdateResult, type PluginDependentOptions, type PluginChangeOptions, type PluginToggleRequest, type PluginReplacementRequest, type PluginChangePreview } from './lifecycle/reconcile.js';
|
|
16
16
|
export type { DialogState } from './contributions/index.js';
|
|
17
17
|
/** A plugin after normalization: records resolved to arrays with IDs, `ui` merged with the legacy fields. */
|
|
18
18
|
export type NormalizedPlugin = Omit<Plugin, 'services' | 'actions' | 'slots'> & {
|
|
@@ -85,6 +85,14 @@ export declare class BitaKitRuntime implements ContributionHost {
|
|
|
85
85
|
affected: readonly string[];
|
|
86
86
|
reasons: readonly string[];
|
|
87
87
|
}>>;
|
|
88
|
+
/** Replace a complete cohort after candidate validation; refuses external dependents. */
|
|
89
|
+
replace: (ids: readonly string[], plugins: readonly Plugin[], options?: PluginChangeOptions) => Promise<Readonly<{
|
|
90
|
+
status: "applied" | "blocked" | "failed" | "restart-required";
|
|
91
|
+
revision: number;
|
|
92
|
+
changed: readonly string[];
|
|
93
|
+
affected: readonly string[];
|
|
94
|
+
reasons: readonly string[];
|
|
95
|
+
}>>;
|
|
88
96
|
enable: (id: string, options?: PluginChangeOptions) => Promise<Readonly<{
|
|
89
97
|
status: "applied" | "blocked" | "failed" | "restart-required";
|
|
90
98
|
revision: number;
|
|
@@ -100,7 +108,7 @@ export declare class BitaKitRuntime implements ContributionHost {
|
|
|
100
108
|
reasons: readonly string[];
|
|
101
109
|
}>>;
|
|
102
110
|
/** Preview uses the execution planner without stopping owners or changing retained intent. */
|
|
103
|
-
preview: (request: PluginToggleRequest) => PluginChangePreview;
|
|
111
|
+
preview: (request: PluginToggleRequest | PluginReplacementRequest) => PluginChangePreview;
|
|
104
112
|
}>;
|
|
105
113
|
private revision;
|
|
106
114
|
getRevision: () => number;
|
package/dist/runtime.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from './name-resolution.js';
|
|
1
2
|
import { EventService, createEventScope } from './events/service.js';
|
|
2
3
|
import { normalizeSlots, validateSlotDeclarations } from './slots/normalize.js';
|
|
3
4
|
import { SlotRuntime } from './slots/runtime.js';
|
|
@@ -97,7 +98,8 @@ function descendantsOf(installed, ids) {
|
|
|
97
98
|
const found = [];
|
|
98
99
|
for (let frontier = [...ids]; frontier.length;) {
|
|
99
100
|
const children = installed
|
|
100
|
-
.filter((plugin) => plugin.parent &&
|
|
101
|
+
.filter((plugin) => plugin.parent &&
|
|
102
|
+
frontier.includes(resolveName(plugin.parent, installed.map((entry) => entry.id))))
|
|
101
103
|
.map((plugin) => plugin.id)
|
|
102
104
|
.filter((id) => !found.includes(id) && !ids.includes(id));
|
|
103
105
|
found.push(...children);
|
|
@@ -106,6 +108,12 @@ function descendantsOf(installed, ids) {
|
|
|
106
108
|
return found;
|
|
107
109
|
}
|
|
108
110
|
function orderPlugins(plugins, appId) {
|
|
111
|
+
const names = plugins.map((plugin) => plugin.id);
|
|
112
|
+
plugins = plugins.map((plugin) => ({
|
|
113
|
+
...plugin,
|
|
114
|
+
dependencies: plugin.dependencies?.map((id) => resolveName(id, names)),
|
|
115
|
+
parent: plugin.parent ? resolveName(plugin.parent, names) : undefined,
|
|
116
|
+
}));
|
|
109
117
|
const remaining = new Map();
|
|
110
118
|
for (const plugin of plugins) {
|
|
111
119
|
if (remaining.has(plugin.id))
|
|
@@ -199,10 +207,14 @@ export class BitaKitRuntime {
|
|
|
199
207
|
plugins = Object.freeze({
|
|
200
208
|
add: (plugins) => this.changePlugins('add', [...plugins]),
|
|
201
209
|
remove: (ids, options) => this.changePlugins('remove', [...ids], options),
|
|
210
|
+
/** Replace a complete cohort after candidate validation; refuses external dependents. */
|
|
211
|
+
replace: (ids, plugins, options) => this.changePlugins('replace', [...ids], options, [...plugins]),
|
|
202
212
|
enable: (id, options) => this.changePlugins('enable', [id], options),
|
|
203
213
|
disable: (id, options) => this.changePlugins('disable', [id], options),
|
|
204
214
|
/** Preview uses the execution planner without stopping owners or changing retained intent. */
|
|
205
|
-
preview: (request) =>
|
|
215
|
+
preview: (request) => request.operation === 'replace'
|
|
216
|
+
? this.planPluginChange('replace', request.ids, request, request.plugins).preview
|
|
217
|
+
: this.planPluginChange(request.operation, [request.id], request).preview,
|
|
206
218
|
});
|
|
207
219
|
revision = 0;
|
|
208
220
|
getRevision = () => this.revision;
|
|
@@ -219,7 +231,8 @@ export class BitaKitRuntime {
|
|
|
219
231
|
/** Initial startup has completed and shutdown has not begun. Updates use owner readiness. */
|
|
220
232
|
isReady = (plugin) => this.mounted &&
|
|
221
233
|
(plugin === undefined ||
|
|
222
|
-
this.lifecycle.get().plugins.some((entry) => entry.id ===
|
|
234
|
+
this.lifecycle.get().plugins.some((entry) => entry.id ===
|
|
235
|
+
resolveName(plugin, this.modules.map((module) => module.id)) && entry.phase === 'ready'));
|
|
223
236
|
subscribeReady = (listener) => {
|
|
224
237
|
this.readinessListeners.add(listener);
|
|
225
238
|
return () => {
|
|
@@ -533,7 +546,18 @@ export class BitaKitRuntime {
|
|
|
533
546
|
return translate;
|
|
534
547
|
}
|
|
535
548
|
override(id) {
|
|
536
|
-
|
|
549
|
+
const overrides = this.config.actionOverrides ?? {};
|
|
550
|
+
const keys = Object.keys(overrides);
|
|
551
|
+
const exact = keys.find((name) => name === id);
|
|
552
|
+
if (exact)
|
|
553
|
+
return overrides[exact];
|
|
554
|
+
const requested = keys.filter((name) => resolveName(name, [
|
|
555
|
+
...this.modules.flatMap((module) => module.actions.map((action) => action.id)),
|
|
556
|
+
...Object.keys(this.actions.getState().actions),
|
|
557
|
+
]) === id);
|
|
558
|
+
if (requested.length > 1)
|
|
559
|
+
throw new Error(`Duplicate action override for "${id}".`);
|
|
560
|
+
return requested.length ? overrides[requested[0]] : undefined;
|
|
537
561
|
}
|
|
538
562
|
dialog() {
|
|
539
563
|
return this.state;
|
|
@@ -686,7 +710,7 @@ export class BitaKitRuntime {
|
|
|
686
710
|
const interceptors = plugins.flatMap((plugin) => plugin.interceptors ?? []);
|
|
687
711
|
this.container = createServices(plugins.flatMap((plugin) => plugin.services), this.providedServices, (definition) => this.configuration.context(owners.get(definition) ??
|
|
688
712
|
this.modules.find((module) => module.services.includes(definition))?.id ??
|
|
689
|
-
this.appId), serviceObserver(interceptors, (id) => this.aliasesOf(id), () => this.view), this.events, {
|
|
713
|
+
this.appId), serviceObserver(interceptors, (id) => this.aliasesOf(id), () => this.view, () => this.names.names()), this.events, {
|
|
690
714
|
names: this.names,
|
|
691
715
|
appId: this.appId,
|
|
692
716
|
moduleOf: (definition) => owners.get(definition) ??
|
|
@@ -887,6 +911,9 @@ export class BitaKitRuntime {
|
|
|
887
911
|
module: plugin.id,
|
|
888
912
|
app: plugin.id === this.appId,
|
|
889
913
|
services: this.services,
|
|
914
|
+
config: this.configuration.context(plugin.id),
|
|
915
|
+
events: this.pluginEvents.get(plugin.id).events,
|
|
916
|
+
settings: this.settingsAccess,
|
|
890
917
|
});
|
|
891
918
|
if (cleanup)
|
|
892
919
|
this.scopes[index].own(cleanup);
|
|
@@ -923,7 +950,7 @@ export class BitaKitRuntime {
|
|
|
923
950
|
catch (error) {
|
|
924
951
|
throw this.attribute(error, module, 'Interceptor', requester.source);
|
|
925
952
|
}
|
|
926
|
-
const applies = (id) => matchesTarget(definition.action ?? '*', id) &&
|
|
953
|
+
const applies = (id) => matchesTarget(definition.action ?? '*', id, Object.keys(this.actions.getState().actions)) &&
|
|
927
954
|
(global || this.actionConfigs.get(id)?.module === module);
|
|
928
955
|
const context = (base) => ({
|
|
929
956
|
...base,
|
|
@@ -1091,8 +1118,8 @@ export class BitaKitRuntime {
|
|
|
1091
1118
|
this.actions.refresh();
|
|
1092
1119
|
}
|
|
1093
1120
|
/** Execute the same plan used by preview; there is no await between validation and exclusion. */
|
|
1094
|
-
changePlugins(operation, values, options) {
|
|
1095
|
-
const plan = this.planPluginChange(operation, values, options);
|
|
1121
|
+
changePlugins(operation, values, options, replacement = []) {
|
|
1122
|
+
const plan = this.planPluginChange(operation, values, options, replacement);
|
|
1096
1123
|
if (plan.apply)
|
|
1097
1124
|
return plan.apply();
|
|
1098
1125
|
const { status, revision, changed, affected, reasons } = plan.preview;
|
|
@@ -1105,7 +1132,7 @@ export class BitaKitRuntime {
|
|
|
1105
1132
|
});
|
|
1106
1133
|
}
|
|
1107
1134
|
/** Validate without starting services, invoking hooks or mutating retained lifecycle intent. */
|
|
1108
|
-
planPluginChange(operation, values, options) {
|
|
1135
|
+
planPluginChange(operation, values, options, replacement = []) {
|
|
1109
1136
|
let changed = [];
|
|
1110
1137
|
let affected = [];
|
|
1111
1138
|
let dependents = [];
|
|
@@ -1138,7 +1165,7 @@ export class BitaKitRuntime {
|
|
|
1138
1165
|
const disabled = new Set(this.disabledPlugins);
|
|
1139
1166
|
const ids = operation === 'add'
|
|
1140
1167
|
? values.map((plugin) => plugin.id)
|
|
1141
|
-
:
|
|
1168
|
+
: values.map((id) => resolveName(id, installed.map((plugin) => plugin.id)));
|
|
1142
1169
|
if (new Set(ids).size !== ids.length)
|
|
1143
1170
|
return result('blocked', ['Plugin IDs must be unique.']);
|
|
1144
1171
|
if (ids.includes(this.appId))
|
|
@@ -1155,6 +1182,19 @@ export class BitaKitRuntime {
|
|
|
1155
1182
|
}
|
|
1156
1183
|
// Ownership: a parent's descendants follow it, whatever the dependents policy says.
|
|
1157
1184
|
const owned = descendantsOf(installed, ids);
|
|
1185
|
+
if (operation === 'replace') {
|
|
1186
|
+
const incoming = replacement.map((plugin) => plugin.id);
|
|
1187
|
+
if (new Set(incoming).size !== incoming.length || incoming.includes(this.appId))
|
|
1188
|
+
return result('blocked', ['Replacement plugin IDs must be unique and exclude the app.']);
|
|
1189
|
+
if (owned.some((id) => !ids.includes(id)))
|
|
1190
|
+
return result('blocked', ['Replacement must include every owned descendant.']);
|
|
1191
|
+
for (const id of incoming)
|
|
1192
|
+
if (!ids.includes(id) && installed.some((plugin) => plugin.id === id))
|
|
1193
|
+
return result('blocked', [`Plugin "${id}" is owned outside the replacement cohort.`]);
|
|
1194
|
+
dependents = updateClosure(modules, ids).filter((id) => !ids.includes(id));
|
|
1195
|
+
if (dependents.length)
|
|
1196
|
+
return result('blocked', [`Enabled dependents: ${dependents.join(', ')}.`], 'dependents', dependents);
|
|
1197
|
+
}
|
|
1158
1198
|
const cascaded = new Map(this.disabledWithParent);
|
|
1159
1199
|
if (operation === 'remove')
|
|
1160
1200
|
ids.push(...owned);
|
|
@@ -1163,7 +1203,10 @@ export class BitaKitRuntime {
|
|
|
1163
1203
|
cascaded.set(parent, children.filter((child) => !ids.includes(child)));
|
|
1164
1204
|
if (operation === 'enable')
|
|
1165
1205
|
for (const id of [...ids]) {
|
|
1166
|
-
const
|
|
1206
|
+
const declaredParent = installed.find((plugin) => plugin.id === id)?.parent;
|
|
1207
|
+
const parent = declaredParent
|
|
1208
|
+
? resolveName(declaredParent, installed.map((plugin) => plugin.id))
|
|
1209
|
+
: undefined;
|
|
1167
1210
|
if (parent && disabled.has(parent) && !ids.includes(parent))
|
|
1168
1211
|
return result('blocked', [
|
|
1169
1212
|
`Plugin "${id}" belongs to "${parent}", which is disabled. Enable "${parent}" first.`,
|
|
@@ -1195,19 +1238,32 @@ export class BitaKitRuntime {
|
|
|
1195
1238
|
for (const id of ids)
|
|
1196
1239
|
disabled.delete(id);
|
|
1197
1240
|
}
|
|
1241
|
+
else if (operation === 'replace') {
|
|
1242
|
+
changed = [...new Set([...ids, ...replacement.map((plugin) => plugin.id)])];
|
|
1243
|
+
for (const id of ids) {
|
|
1244
|
+
disabled.delete(id);
|
|
1245
|
+
cascaded.delete(id);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1198
1248
|
else
|
|
1199
1249
|
installed.push(...values);
|
|
1200
1250
|
if (operation === 'remove')
|
|
1201
1251
|
for (const id of ids)
|
|
1202
1252
|
cascaded.delete(id);
|
|
1203
|
-
const nextInstalled = operation === '
|
|
1253
|
+
const nextInstalled = operation === 'replace'
|
|
1254
|
+
? [...installed.filter((plugin) => !ids.includes(plugin.id)), ...replacement]
|
|
1255
|
+
: operation === 'remove'
|
|
1256
|
+
? installed.filter((plugin) => !ids.includes(plugin.id))
|
|
1257
|
+
: installed;
|
|
1204
1258
|
for (const id of ids)
|
|
1205
1259
|
if (operation === 'remove')
|
|
1206
1260
|
disabled.delete(id);
|
|
1207
1261
|
if (operation === 'disable')
|
|
1208
1262
|
changed = changed.filter((id) => !this.disabledPlugins.has(id));
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1263
|
+
const preserved = options?.preserve?.map((id) => resolveName(id, installed.map((plugin) => plugin.id))) ?? [];
|
|
1264
|
+
const protectedOwners = changed.filter((id) => preserved.includes(id));
|
|
1265
|
+
if ((operation === 'disable' || operation === 'remove' || operation === 'replace') &&
|
|
1266
|
+
protectedOwners.length)
|
|
1211
1267
|
return result('blocked', ['The host requires these plugins to remain enabled.'], 'protected', protectedOwners);
|
|
1212
1268
|
if (!changed.length) {
|
|
1213
1269
|
const plan = result('ready', []);
|
package/dist/service-key.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from './name-resolution.js';
|
|
1
2
|
/**
|
|
2
3
|
* Low-level key creation; `defineContract(name).of<T>()` is the documented form. Pass both type
|
|
3
4
|
* arguments (`serviceKey<T, 'name'>('name')`) to keep the literal name.
|
|
@@ -18,7 +19,12 @@ export function defineContract(id) {
|
|
|
18
19
|
/** Reads a contract from a services object (tree or flat); throws a clear error when absent. */
|
|
19
20
|
export function getService(services, key) {
|
|
20
21
|
let current = services;
|
|
21
|
-
for (const
|
|
22
|
+
for (const requested of key.split('.')) {
|
|
23
|
+
const segment = current && typeof current === 'object'
|
|
24
|
+
? requested in current
|
|
25
|
+
? requested
|
|
26
|
+
: resolveName(requested, Object.getOwnPropertyNames(current))
|
|
27
|
+
: requested;
|
|
22
28
|
if (!current || typeof current !== 'object' || !(segment in current))
|
|
23
29
|
throw new Error(`Missing service "${key}".`);
|
|
24
30
|
current = current[segment];
|
package/dist/service-names.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from './name-resolution.js';
|
|
1
2
|
import { BitaKitStartupError } from './startup-error.js';
|
|
2
3
|
import { BitaKitServiceError } from './app/service-error.js';
|
|
3
4
|
/**
|
|
@@ -69,10 +70,10 @@ export class ServiceNames {
|
|
|
69
70
|
}
|
|
70
71
|
/** The container key that `name` refers to; unknown names are returned as-is. */
|
|
71
72
|
key(name) {
|
|
72
|
-
return this.ids.get(name) ?? name;
|
|
73
|
+
return this.ids.get(resolveName(name, this.ids.keys())) ?? name;
|
|
73
74
|
}
|
|
74
75
|
known(name) {
|
|
75
|
-
return this.ids.has(name);
|
|
76
|
+
return this.ids.has(resolveName(name, this.ids.keys()));
|
|
76
77
|
}
|
|
77
78
|
/** Every known name, IDs first. */
|
|
78
79
|
names() {
|
|
@@ -94,7 +95,7 @@ export class ServiceNames {
|
|
|
94
95
|
if (typeof name !== 'string' || name === 'then' || name === 'toJSON')
|
|
95
96
|
return undefined;
|
|
96
97
|
const path = prefix ? `${prefix}.${name}` : name;
|
|
97
|
-
const child = node.children.get(name);
|
|
98
|
+
const child = node.children.get(resolveName(name, node.children.keys()));
|
|
98
99
|
if (!child) {
|
|
99
100
|
throw new BitaKitServiceError(path, notReady?.() ? 'not-ready' : 'unregistered');
|
|
100
101
|
}
|
|
@@ -106,9 +107,9 @@ export class ServiceNames {
|
|
|
106
107
|
}
|
|
107
108
|
return project(child, path);
|
|
108
109
|
},
|
|
109
|
-
has: (_target, name) => typeof name === 'string' && node.children.has(name),
|
|
110
|
+
has: (_target, name) => typeof name === 'string' && node.children.has(resolveName(name, node.children.keys())),
|
|
110
111
|
ownKeys: () => [...node.children.keys()],
|
|
111
|
-
getOwnPropertyDescriptor: (_target, name) => typeof name === 'string' && node.children.has(name)
|
|
112
|
+
getOwnPropertyDescriptor: (_target, name) => typeof name === 'string' && node.children.has(resolveName(name, node.children.keys()))
|
|
112
113
|
? { enumerable: true, configurable: true, writable: false, value: proxy[name] }
|
|
113
114
|
: undefined,
|
|
114
115
|
set: () => false,
|
package/dist/settings/access.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from '../name-resolution.js';
|
|
1
2
|
const reserved = new Set(['then', 'toJSON', 'constructor', '__proto__']);
|
|
2
3
|
/** Validates declarations; namespace proxies follow the current store without copying values. */
|
|
3
4
|
export function createSettingsAccess(store) {
|
|
@@ -39,6 +40,7 @@ export function createSettingsAccess(store) {
|
|
|
39
40
|
get(_object, name) {
|
|
40
41
|
if (typeof name !== 'string' || reserved.has(name))
|
|
41
42
|
return undefined;
|
|
43
|
+
name = resolveName(name, keys());
|
|
42
44
|
const key = path ? `${path}.${name}` : name;
|
|
43
45
|
if (store.has(key)) {
|
|
44
46
|
const spec = store.definition(key).spec;
|
|
@@ -46,14 +48,14 @@ export function createSettingsAccess(store) {
|
|
|
46
48
|
handles.set(key, { spec, value: handle(store, key, spec) });
|
|
47
49
|
return handles.get(key).value;
|
|
48
50
|
}
|
|
49
|
-
if (keys().includes(name))
|
|
51
|
+
if (keys().includes(resolveName(name, keys())))
|
|
50
52
|
return project(key);
|
|
51
53
|
const owner = path ? `plugin "${path}"` : 'the app or a plugin';
|
|
52
54
|
throw new Error(`Unknown setting "${key}". Declare it in settings.ts of ${owner}.`);
|
|
53
55
|
},
|
|
54
|
-
has: (_object, name) => typeof name === 'string' && keys().includes(name),
|
|
56
|
+
has: (_object, name) => typeof name === 'string' && keys().includes(resolveName(name, keys())),
|
|
55
57
|
ownKeys: keys,
|
|
56
|
-
getOwnPropertyDescriptor: (_object, name) => typeof name === 'string' && keys().includes(name)
|
|
58
|
+
getOwnPropertyDescriptor: (_object, name) => typeof name === 'string' && keys().includes(resolveName(name, keys()))
|
|
57
59
|
? { enumerable: true, configurable: true }
|
|
58
60
|
: undefined,
|
|
59
61
|
set: () => false,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NamedValue } from '../name-resolution.js';
|
|
1
2
|
import type { InputSchema, SchemaOutput } from '../definitions.js';
|
|
2
3
|
import type { PresentationType } from '../presentation.js';
|
|
3
4
|
import type { GeneratedName } from '../names.js';
|
|
@@ -103,7 +104,7 @@ export interface SettingsMap {
|
|
|
103
104
|
}
|
|
104
105
|
/** A declared setting key; strict generated apps reject unknown keys. */
|
|
105
106
|
export type SettingKey = GeneratedName<Extract<keyof SettingsMap, string>>;
|
|
106
|
-
export type SettingValue<Key extends string> =
|
|
107
|
+
export type SettingValue<Key extends string> = NamedValue<SettingsMap, Key>;
|
|
107
108
|
type ValueOf<S> = S extends SettingSpec<infer T> ? T : never;
|
|
108
109
|
/** `SettingsMap` entries of one declaration under a plugin prefix (none for the app module). */
|
|
109
110
|
export type SettingsOf<D, Plugin extends string> = D extends SettingsDefinition<infer Specs> ? {
|
package/dist/settings/store.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from '../name-resolution.js';
|
|
1
2
|
import { parseSetting } from './define.js';
|
|
2
3
|
import { schemaErrorMessage } from '../schema.js';
|
|
3
4
|
const message = (error, fallback) => schemaErrorMessage(error, fallback);
|
|
@@ -67,7 +68,7 @@ export class SettingsStore {
|
|
|
67
68
|
return [...this.slots.values()].map((slot) => slot.entry);
|
|
68
69
|
}
|
|
69
70
|
has(key) {
|
|
70
|
-
return this.slots.has(key);
|
|
71
|
+
return this.slots.has(resolveName(key, this.slots.keys()));
|
|
71
72
|
}
|
|
72
73
|
definition(key) {
|
|
73
74
|
return this.slot(key).entry;
|
|
@@ -172,7 +173,7 @@ export class SettingsStore {
|
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
slot(key) {
|
|
175
|
-
const slot = this.slots.get(key);
|
|
176
|
+
const slot = this.slots.get(resolveName(key, this.slots.keys()));
|
|
176
177
|
if (!slot) {
|
|
177
178
|
const plugin = key.includes('.') ? `plugin "${key.slice(0, key.indexOf('.'))}"` : 'the app';
|
|
178
179
|
throw new Error(`Unknown setting "${key}". Declare it in settings.ts of ${plugin}.`);
|
package/dist/slots/define.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NamedValue } from '../name-resolution.js';
|
|
1
2
|
import type { InputSchema, SchemaOutput, EffectiveActionId } from '../definitions.js';
|
|
2
3
|
import type { SlotMap } from '../presentation.js';
|
|
3
4
|
/**
|
|
@@ -43,7 +44,7 @@ export declare function defineSlot<const T extends SlotOptions>(options: T): Rea
|
|
|
43
44
|
}>;
|
|
44
45
|
export declare function isSlotDefinition(value: unknown): value is SlotDefinition;
|
|
45
46
|
/** Accept a generated name or a definition directly (manual composition needs no augmentation). */
|
|
46
|
-
type DefinitionOf<T> = T extends keyof SlotMap ? SlotMap[T] : T;
|
|
47
|
+
type DefinitionOf<T> = T extends keyof SlotMap ? SlotMap[T] : T extends string ? NamedValue<SlotMap, T, T> : T;
|
|
47
48
|
export type SlotPayload<T> = DefinitionOf<T> extends {
|
|
48
49
|
payload: infer S;
|
|
49
50
|
} ? SchemaOutput<S> : undefined;
|
package/dist/slots/runtime.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveName } from '../name-resolution.js';
|
|
1
2
|
import { BitaKitStartupError } from '../startup-error.js';
|
|
2
3
|
import { createStore } from '../store.js';
|
|
3
4
|
import { validate } from '../schema.js';
|
|
@@ -45,7 +46,7 @@ export class SlotRuntime {
|
|
|
45
46
|
})),
|
|
46
47
|
});
|
|
47
48
|
this.reader = Object.freeze({
|
|
48
|
-
has: (name) => this.entries.has(name),
|
|
49
|
+
has: (name) => this.entries.has(resolveName(name, this.entries.keys())),
|
|
49
50
|
get: (name) => this.entry(name).store.get(),
|
|
50
51
|
subscribe: (name, listener) => this.listen(this.entry(name).store, listener),
|
|
51
52
|
watch: (name, listener) => this.listen(this.entry(name).store, listener, true),
|
|
@@ -54,7 +55,7 @@ export class SlotRuntime {
|
|
|
54
55
|
}
|
|
55
56
|
/** `source` names the contributing file when an unknown target comes from an attachment. */
|
|
56
57
|
entry(name, plugin = this.appId, source) {
|
|
57
|
-
const entry = this.entries.get(name);
|
|
58
|
+
const entry = this.entries.get(resolveName(name, this.entries.keys()));
|
|
58
59
|
if (!entry)
|
|
59
60
|
throw new SlotError('unknown-slot', name, plugin, 'no owning definition exists. Install and enable the plugin that declares it (in tests, pass that plugin to mountPlugin).', source, plugin === this.appId);
|
|
60
61
|
return entry;
|
|
@@ -135,6 +136,7 @@ export class SlotRuntime {
|
|
|
135
136
|
}
|
|
136
137
|
attach(scope, plugin, name, contribution, availability) {
|
|
137
138
|
const { definition } = this.entry(name, plugin, contributionSource(contribution));
|
|
139
|
+
name = definition.id;
|
|
138
140
|
const source = contributionSource(contribution) ?? contributionSource(definition);
|
|
139
141
|
const error = (code, message) => new SlotError(code, name, plugin, message, source, plugin === this.appId);
|
|
140
142
|
if (availability !== 'require' && availability !== 'wait')
|
package/dist/slots/select.js
CHANGED
|
@@ -12,7 +12,10 @@ export function candidateNames(item) {
|
|
|
12
12
|
*/
|
|
13
13
|
export function selectSingle(candidates, options) {
|
|
14
14
|
if (options.choice !== undefined) {
|
|
15
|
-
const
|
|
15
|
+
const exact = candidates.filter((item) => candidateNames(item).includes(options.choice));
|
|
16
|
+
const matches = exact.length
|
|
17
|
+
? exact
|
|
18
|
+
: candidates.filter((item) => candidateNames(item).some((name) => name.toLowerCase() === options.choice.toLowerCase()));
|
|
16
19
|
if (matches.length === 1)
|
|
17
20
|
return { selected: matches[0], candidates };
|
|
18
21
|
return { reason: matches.length ? 'ambiguous' : 'choice-unavailable', candidates };
|
package/dist/slots/types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { CheckedName } from '../names.js';
|
|
2
|
+
import type { NamedValue } from '../name-resolution.js';
|
|
1
3
|
import type { PresentationType, SlotMap, SlotName } from '../presentation.js';
|
|
2
4
|
import type { LifecycleFailure, LifecyclePhase } from '../lifecycle/state.js';
|
|
3
5
|
import type { SlotPayload, SlotData } from './define.js';
|
|
4
6
|
import type { ActionId } from '../actions/core.js';
|
|
5
7
|
export type SlotPredicate<Name extends string = string> = (context: {
|
|
6
|
-
payload: Name extends keyof SlotMap ? SlotPayload<Name> : any;
|
|
8
|
+
payload: Lowercase<Name> extends Lowercase<Extract<keyof SlotMap, string>> ? SlotPayload<Name> : any;
|
|
7
9
|
}) => boolean;
|
|
8
10
|
export type SlotAvailability = 'require' | 'wait';
|
|
9
11
|
export type SlotContent = {
|
|
@@ -24,14 +26,14 @@ export type SlotContent = {
|
|
|
24
26
|
component?: never;
|
|
25
27
|
data?: never;
|
|
26
28
|
};
|
|
27
|
-
type ContentFor<Name extends string> = Name extends keyof SlotMap ? SlotMap
|
|
29
|
+
type ContentFor<Name extends string> = Lowercase<Name> extends Lowercase<Extract<keyof SlotMap, string>> ? NamedValue<SlotMap, Name> extends {
|
|
28
30
|
accepts: 'data';
|
|
29
31
|
} ? {
|
|
30
32
|
data: SlotData<Name>;
|
|
31
33
|
component?: never;
|
|
32
34
|
actionId?: never;
|
|
33
35
|
input?: never;
|
|
34
|
-
} : SlotMap
|
|
36
|
+
} : NamedValue<SlotMap, Name> extends {
|
|
35
37
|
accepts: 'actions';
|
|
36
38
|
} ? {
|
|
37
39
|
actionId: ActionId;
|
|
@@ -40,7 +42,7 @@ type ContentFor<Name extends string> = Name extends keyof SlotMap ? SlotMap[Name
|
|
|
40
42
|
}) => unknown;
|
|
41
43
|
component?: never;
|
|
42
44
|
data?: never;
|
|
43
|
-
} : SlotMap
|
|
45
|
+
} : NamedValue<SlotMap, Name> extends {
|
|
44
46
|
accepts: 'component';
|
|
45
47
|
} ? {
|
|
46
48
|
component: PresentationType<'component'>;
|
|
@@ -54,7 +56,7 @@ export type SlotContribution<Name extends string = string> = ContentFor<Name> &
|
|
|
54
56
|
order?: number;
|
|
55
57
|
/** Pure per-outlet presentation filter; never changes shared attachment state. */
|
|
56
58
|
when?: SlotPredicate<Name>;
|
|
57
|
-
} & (Name extends keyof SlotMap ? SlotMap
|
|
59
|
+
} & (Lowercase<Name> extends Lowercase<Extract<keyof SlotMap, string>> ? NamedValue<SlotMap, Name> extends {
|
|
58
60
|
policy: 'keyed';
|
|
59
61
|
} ? {
|
|
60
62
|
key: string;
|
|
@@ -98,14 +100,14 @@ export type SlotAttachment = Readonly<{
|
|
|
98
100
|
}>;
|
|
99
101
|
export type SlotReader = Readonly<{
|
|
100
102
|
has(name: string): boolean;
|
|
101
|
-
get(name: SlotName): SlotSnapshot;
|
|
102
|
-
subscribe(name:
|
|
103
|
-
watch(name:
|
|
103
|
+
get<const Name extends string>(name: Name & CheckedName<Name, SlotName>): SlotSnapshot;
|
|
104
|
+
subscribe<const Name extends string>(name: Name & CheckedName<Name, SlotName>, listener: (state: SlotSnapshot) => void): () => void;
|
|
105
|
+
watch<const Name extends string>(name: Name & CheckedName<Name, SlotName>, listener: (state: SlotSnapshot) => void): () => void;
|
|
104
106
|
}>;
|
|
105
107
|
export type ScopedSlots = SlotReader & {
|
|
106
108
|
/** `scope.slots.attach({ slot: 'shell.toolbar', actionId: 'notes.open' })`; the slot is part of the contribution. */
|
|
107
|
-
attach<const Name extends
|
|
108
|
-
slot: Name
|
|
109
|
+
attach<const Name extends string>(contribution: {
|
|
110
|
+
slot: Name & CheckedName<Name, SlotName>;
|
|
109
111
|
} & SlotContribution<Name>, options?: {
|
|
110
112
|
availability?: SlotAvailability;
|
|
111
113
|
}): SlotAttachment;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitakit/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -38,10 +38,11 @@
|
|
|
38
38
|
"dev": "tsc -p tsconfig.json --watch"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"zod": "^4.6.7",
|
|
41
42
|
"zustand": "^5.0.0"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
|
-
"@bitakit/discovery": "^0.2.
|
|
45
|
+
"@bitakit/discovery": "^0.2.5",
|
|
45
46
|
"jiti": "^2.7.0"
|
|
46
47
|
},
|
|
47
48
|
"peerDependenciesMeta": {
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@bitakit/discovery": "^0.2.
|
|
57
|
+
"@bitakit/discovery": "^0.2.6",
|
|
57
58
|
"jiti": "^2.7.0",
|
|
58
59
|
"typescript": "^5.9.3"
|
|
59
60
|
},
|
package/testing/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { createJiti } from 'jiti';
|
|
5
|
-
import { describeModule } from '@bitakit/discovery';
|
|
5
|
+
import { describeModule, packagePluginId } from '@bitakit/discovery';
|
|
6
6
|
import {
|
|
7
7
|
createRuntime,
|
|
8
8
|
discoverActions,
|
|
@@ -23,14 +23,7 @@ async function packageId(directory) {
|
|
|
23
23
|
.then(JSON.parse)
|
|
24
24
|
.catch(() => undefined);
|
|
25
25
|
if (manifest)
|
|
26
|
-
return (
|
|
27
|
-
manifest.bitakit?.id ??
|
|
28
|
-
manifest.foundation?.id ??
|
|
29
|
-
(manifest.name ?? '')
|
|
30
|
-
.replace(/^@[^/]+\//, '')
|
|
31
|
-
.replace(/^bitakit-(plugin-)?/, '')
|
|
32
|
-
.replace(/-plugin$/, '')
|
|
33
|
-
);
|
|
26
|
+
return (manifest.bitakit ?? manifest.foundation)?.id ?? packagePluginId(manifest.name);
|
|
34
27
|
if (path.dirname(folder) === folder) return undefined;
|
|
35
28
|
}
|
|
36
29
|
}
|