@bitakit/core 0.2.8 → 0.3.0

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.
Files changed (40) hide show
  1. package/AGENTS.md +42 -0
  2. package/dist/actions/action-list.d.ts +3 -2
  3. package/dist/actions/action-list.js +5 -0
  4. package/dist/actions/dependencies.js +4 -1
  5. package/dist/actions/execution.js +1 -0
  6. package/dist/actions/types.d.ts +7 -2
  7. package/dist/app/access.js +3 -2
  8. package/dist/app/action-access.js +2 -0
  9. package/dist/config-service.js +11 -3
  10. package/dist/configuration.js +3 -2
  11. package/dist/core.d.ts +4 -1
  12. package/dist/core.js +2 -0
  13. package/dist/definitions.d.ts +10 -0
  14. package/dist/discovered.d.ts +11 -0
  15. package/dist/discovered.js +29 -5
  16. package/dist/events/service.d.ts +2 -0
  17. package/dist/events/service.js +44 -9
  18. package/dist/events/types.d.ts +10 -6
  19. package/dist/interceptors/define.d.ts +6 -1
  20. package/dist/interceptors/define.js +7 -3
  21. package/dist/interceptors/service-observers.d.ts +1 -1
  22. package/dist/interceptors/service-observers.js +9 -2
  23. package/dist/lifecycle/controller.js +8 -7
  24. package/dist/lifecycle/reconcile.js +3 -2
  25. package/dist/name-resolution.d.ts +11 -0
  26. package/dist/name-resolution.js +24 -0
  27. package/dist/names.d.ts +4 -0
  28. package/dist/permissions.d.ts +103 -0
  29. package/dist/permissions.js +172 -0
  30. package/dist/runtime.js +68 -8
  31. package/dist/service-key.js +7 -1
  32. package/dist/service-names.js +6 -5
  33. package/dist/settings/access.js +5 -3
  34. package/dist/settings/define.d.ts +2 -1
  35. package/dist/settings/store.js +3 -2
  36. package/dist/slots/define.d.ts +2 -1
  37. package/dist/slots/runtime.js +4 -2
  38. package/dist/slots/select.js +4 -1
  39. package/dist/slots/types.d.ts +12 -10
  40. package/package.json +3 -3
@@ -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 segment of key.split('.')) {
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];
@@ -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,
@@ -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> = Key extends keyof SettingsMap ? SettingsMap[Key] : unknown;
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> ? {
@@ -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}.`);
@@ -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;
@@ -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')
@@ -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 matches = candidates.filter((item) => candidateNames(item).includes(options.choice));
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 };
@@ -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[Name] extends {
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[Name] extends {
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[Name] extends {
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[Name] extends {
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: SlotName, listener: (state: SlotSnapshot) => void): () => void;
103
- watch(name: SlotName, listener: (state: SlotSnapshot) => void): () => void;
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 SlotName>(contribution: {
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.8",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -42,7 +42,7 @@
42
42
  "zustand": "^5.0.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@bitakit/discovery": "^0.2.5",
45
+ "@bitakit/discovery": "^0.3.0",
46
46
  "jiti": "^2.7.0"
47
47
  },
48
48
  "peerDependenciesMeta": {
@@ -54,7 +54,7 @@
54
54
  }
55
55
  },
56
56
  "devDependencies": {
57
- "@bitakit/discovery": "^0.2.5",
57
+ "@bitakit/discovery": "^0.3.0",
58
58
  "jiti": "^2.7.0",
59
59
  "typescript": "^5.9.3"
60
60
  },