@bitakit/core 0.1.1 → 0.2.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 (158) hide show
  1. package/README.md +47 -161
  2. package/assets/bitakit-logo-dark.svg +11 -0
  3. package/assets/bitakit-logo.svg +11 -0
  4. package/discovery/index.d.ts +1 -41
  5. package/discovery/index.mjs +1 -4
  6. package/dist/actions/action-list.d.ts +4 -0
  7. package/dist/actions/action-list.js +58 -16
  8. package/dist/actions/action.d.ts +2 -0
  9. package/dist/actions/action.js +4 -0
  10. package/dist/actions/brand.d.ts +21 -0
  11. package/dist/actions/brand.js +36 -0
  12. package/dist/actions/core.d.ts +4 -3
  13. package/dist/actions/core.js +4 -2
  14. package/dist/actions/execution.d.ts +2 -2
  15. package/dist/actions/execution.js +61 -9
  16. package/dist/actions/feedback.d.ts +2 -0
  17. package/dist/actions/feedback.js +8 -0
  18. package/dist/actions/groups.js +5 -1
  19. package/dist/actions/instance-bindings.js +3 -2
  20. package/dist/actions/interceptors.d.ts +9 -3
  21. package/dist/actions/interceptors.js +31 -3
  22. package/dist/actions/navigation.d.ts +2 -1
  23. package/dist/actions/navigation.js +10 -5
  24. package/dist/actions/reference.js +10 -5
  25. package/dist/actions/types.d.ts +9 -1
  26. package/dist/app/access.d.ts +4 -4
  27. package/dist/app/access.js +33 -71
  28. package/dist/app/action-access.d.ts +2 -2
  29. package/dist/app/action-access.js +6 -4
  30. package/dist/app/service-error.d.ts +2 -2
  31. package/dist/app/service-error.js +10 -6
  32. package/dist/app/types.d.ts +76 -33
  33. package/dist/config-service.d.ts +30 -6
  34. package/dist/config-service.js +25 -9
  35. package/dist/configuration.d.ts +6 -3
  36. package/dist/configuration.js +8 -6
  37. package/dist/contracts.d.ts +4 -2
  38. package/dist/contracts.js +3 -3
  39. package/dist/contribution-origin.d.ts +4 -1
  40. package/dist/contribution-origin.js +14 -1
  41. package/dist/contributions/action.d.ts +26 -0
  42. package/dist/contributions/action.js +171 -0
  43. package/dist/contributions/host.d.ts +14 -11
  44. package/dist/contributions/index.d.ts +1 -26
  45. package/dist/contributions/index.js +1 -18
  46. package/dist/conventions.d.ts +8 -4
  47. package/dist/conventions.js +12 -31
  48. package/dist/core.d.ts +41 -18
  49. package/dist/core.js +25 -13
  50. package/dist/definitions.d.ts +272 -306
  51. package/dist/definitions.js +28 -56
  52. package/dist/destinations.d.ts +25 -0
  53. package/dist/destinations.js +21 -0
  54. package/dist/discovered.d.ts +52 -21
  55. package/dist/discovered.js +89 -35
  56. package/dist/events/define.d.ts +43 -0
  57. package/dist/events/define.js +17 -0
  58. package/dist/events/service.d.ts +35 -8
  59. package/dist/events/service.js +184 -42
  60. package/dist/events/types.d.ts +29 -9
  61. package/dist/inspection/inventory.d.ts +86 -0
  62. package/dist/inspection/inventory.js +132 -0
  63. package/dist/interceptors/define.d.ts +76 -0
  64. package/dist/interceptors/define.js +23 -0
  65. package/dist/interceptors/service-observers.d.ts +6 -3
  66. package/dist/interceptors/service-observers.js +13 -10
  67. package/dist/lifecycle/cleanup.d.ts +5 -0
  68. package/dist/lifecycle/cleanup.js +41 -0
  69. package/dist/lifecycle/controller.d.ts +82 -0
  70. package/dist/lifecycle/controller.js +276 -0
  71. package/dist/lifecycle/reconcile.d.ts +19 -0
  72. package/dist/lifecycle/reconcile.js +68 -0
  73. package/dist/lifecycle/state.d.ts +53 -0
  74. package/dist/lifecycle/state.js +86 -0
  75. package/dist/names.d.ts +10 -0
  76. package/dist/names.js +1 -0
  77. package/dist/pages.d.ts +39 -6
  78. package/dist/pages.js +93 -11
  79. package/dist/presentation.d.ts +9 -0
  80. package/dist/runtime.d.ts +166 -28
  81. package/dist/runtime.js +1485 -248
  82. package/dist/schema.d.ts +13 -0
  83. package/dist/schema.js +38 -0
  84. package/dist/scope.d.ts +59 -4
  85. package/dist/scope.js +133 -11
  86. package/dist/service-key.d.ts +33 -14
  87. package/dist/service-key.js +21 -5
  88. package/dist/service-names.d.ts +39 -0
  89. package/dist/service-names.js +175 -0
  90. package/dist/services.d.ts +24 -5
  91. package/dist/services.js +230 -37
  92. package/dist/settings/access.d.ts +19 -0
  93. package/dist/settings/access.js +78 -0
  94. package/dist/settings/define.d.ts +97 -0
  95. package/dist/settings/define.js +83 -0
  96. package/dist/settings/storage.d.ts +45 -0
  97. package/dist/settings/storage.js +102 -0
  98. package/dist/settings/store.d.ts +74 -0
  99. package/dist/settings/store.js +345 -0
  100. package/dist/slots/action-placement.d.ts +47 -0
  101. package/dist/slots/action-placement.js +1 -0
  102. package/dist/slots/define.d.ts +52 -0
  103. package/dist/slots/define.js +12 -0
  104. package/dist/slots/normalize.d.ts +7 -0
  105. package/dist/slots/normalize.js +36 -0
  106. package/dist/slots/runtime.d.ts +43 -0
  107. package/dist/slots/runtime.js +348 -0
  108. package/dist/slots/types.d.ts +113 -0
  109. package/dist/slots/types.js +1 -0
  110. package/dist/startup-error.d.ts +21 -0
  111. package/dist/startup-error.js +29 -0
  112. package/dist/store.d.ts +24 -0
  113. package/dist/store.js +40 -0
  114. package/dist/translation.d.ts +9 -4
  115. package/dist/translation.js +2 -3
  116. package/examples/todos/actions/create.mjs +1 -3
  117. package/examples/todos/actions/delete.mjs +3 -10
  118. package/examples/todos/actions/list.mjs +1 -3
  119. package/examples/todos/events.mjs +5 -0
  120. package/examples/todos/plugin.mjs +4 -2
  121. package/examples/todos/services/tasks.mjs +14 -20
  122. package/examples/todos.mjs +8 -7
  123. package/package.json +37 -9
  124. package/testing/index.d.ts +59 -0
  125. package/testing/index.mjs +150 -0
  126. package/discovery/entries.mjs +0 -124
  127. package/discovery/generate.mjs +0 -321
  128. package/discovery/host.mjs +0 -12
  129. package/discovery/modules.mjs +0 -13
  130. package/discovery/packages.mjs +0 -57
  131. package/discovery/watch.mjs +0 -23
  132. package/dist/app/service-aliases.d.ts +0 -4
  133. package/dist/app/service-aliases.js +0 -14
  134. package/dist/contributions/command.d.ts +0 -8
  135. package/dist/contributions/command.js +0 -59
  136. package/dist/contributions/dialog.d.ts +0 -8
  137. package/dist/contributions/dialog.js +0 -18
  138. package/dist/contributions/form.d.ts +0 -10
  139. package/dist/contributions/form.js +0 -67
  140. package/dist/contributions/native.d.ts +0 -11
  141. package/dist/contributions/native.js +0 -87
  142. package/dist/contributions/shared.d.ts +0 -19
  143. package/dist/contributions/shared.js +0 -48
  144. package/dist/contributions/stateful-action.d.ts +0 -29
  145. package/dist/contributions/stateful-action.js +0 -33
  146. package/dist/events/action-setup.d.ts +0 -19
  147. package/dist/events/action-setup.js +0 -24
  148. package/dist/interceptors/service.d.ts +0 -37
  149. package/dist/interceptors/service.js +0 -7
  150. package/dist/replacements.d.ts +0 -22
  151. package/dist/replacements.js +0 -54
  152. package/dist/validation.d.ts +0 -2
  153. package/dist/validation.js +0 -16
  154. package/docs/auth.md +0 -106
  155. package/docs/events.md +0 -157
  156. package/docs/file-contributions.md +0 -174
  157. package/docs/reference.md +0 -404
  158. package/docs/todo-tutorial.md +0 -88
@@ -0,0 +1,86 @@
1
+ import { createStore } from '../store.js';
2
+ /** Observer failures are diagnostics, including callbacks that return rejected promises. */
3
+ export function notifyLifecycleObserver(call, report) {
4
+ const failed = (error) => {
5
+ try {
6
+ report(error);
7
+ }
8
+ catch {
9
+ /* reporting only */
10
+ }
11
+ };
12
+ try {
13
+ const result = call();
14
+ if (result && typeof result.then === 'function')
15
+ void Promise.resolve(result).catch(failed);
16
+ }
17
+ catch (error) {
18
+ failed(error);
19
+ }
20
+ }
21
+ /** Status only; actual services and registrations remain owned by the existing runtime. */
22
+ export function createLifecycleState(pluginIds, services, publish, report) {
23
+ const entry = (id, plugin) => Object.freeze({ id, plugin, enabled: true, phase: 'idle', since: Date.now() });
24
+ const store = createStore(Object.freeze({
25
+ generation: 0,
26
+ phase: 'idle',
27
+ cleanup: 'none',
28
+ operation: null,
29
+ plugins: Object.freeze(pluginIds.map((id) => entry(id, id))),
30
+ services: Object.freeze(services.map(({ id, plugin }) => entry(id, plugin))),
31
+ }));
32
+ const call = (listener, value) => notifyLifecycleObserver(() => listener(value), report);
33
+ const subscribe = (listener) => store.subscribe((value) => call(listener, value));
34
+ const state = Object.freeze({
35
+ get: store.get,
36
+ subscribe,
37
+ watch(listener) {
38
+ const off = subscribe(listener);
39
+ call(listener, store.get());
40
+ return off;
41
+ },
42
+ });
43
+ return {
44
+ state,
45
+ update(patch) {
46
+ const current = store.get();
47
+ const nextEntries = (entries, previous) => Object.freeze(entries.map((item) => {
48
+ const before = previous.find((entry) => entry.id === item.id);
49
+ return before?.phase === item.phase
50
+ ? item
51
+ : Object.freeze({ ...item, since: Date.now() });
52
+ }));
53
+ const next = Object.freeze({
54
+ ...current,
55
+ ...patch,
56
+ ...(patch.plugins ? { plugins: nextEntries(patch.plugins, current.plugins) } : {}),
57
+ ...(patch.services ? { services: nextEntries(patch.services, current.services) } : {}),
58
+ ...(patch.phase && !['starting', 'stopping'].includes(patch.phase)
59
+ ? { operation: null }
60
+ : {}),
61
+ });
62
+ store.set(next);
63
+ // A listener may request another transition; do not emit an obsolete snapshot afterward.
64
+ if (store.get() === next)
65
+ call(publish, next);
66
+ },
67
+ service(id, phase, failure) {
68
+ const current = store.get();
69
+ const entries = current.services.map((item) => item.id === id
70
+ ? Object.freeze({ ...item, phase, failure: failure && Object.freeze({ ...failure }) })
71
+ : item);
72
+ this.update({ services: Object.freeze(entries) });
73
+ },
74
+ plugin(id, phase, failure) {
75
+ this.update({
76
+ plugins: Object.freeze(store.get().plugins.map((item) => item.id === id
77
+ ? Object.freeze({
78
+ ...item,
79
+ phase,
80
+ failure: failure && Object.freeze({ ...failure }),
81
+ })
82
+ : item)),
83
+ });
84
+ },
85
+ };
86
+ }
@@ -0,0 +1,10 @@
1
+ import type { ActionMapOptions } from './actions/types.js';
2
+ /**
3
+ * A name that discovery generates: an Action ID, event, slot, setting or service name.
4
+ * Known names autocomplete. Unknown strings stay allowed until the generated `strict` switch
5
+ * (`ActionMapOptions { strict: true }`, on by default in generated apps) turns typos into type
6
+ * errors. Packages compiled without generated maps keep the loose form.
7
+ */
8
+ export type GeneratedName<Known extends string> = ActionMapOptions extends {
9
+ strict: true;
10
+ } ? Known : Known | (string & {});
package/dist/names.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/pages.d.ts CHANGED
@@ -1,8 +1,41 @@
1
- import type { Plugin } from './definitions.js';
1
+ import type { PluginPageDefinition, PluginView, ProviderDefinition, PluginSettingsPage } from './definitions.js';
2
+ import type { PresentationType } from './presentation.js';
2
3
  /** Exact, canonical paths only. Routers remain responsible for dynamic parameters. */
3
- export declare function validatePluginPages(plugins: readonly Plugin[]): void;
4
- export declare function findPluginPage(plugins: readonly Plugin[], pathname: string): {
4
+ export declare function validatePluginPages(plugins: readonly {
5
+ id: string;
6
+ pages?: readonly PluginPageDefinition[];
7
+ }[], layouts?: ReadonlySet<string>): void;
8
+ /**
9
+ * The registered page for a pathname, with its parameters and the ID of the module that owns
10
+ * it. Exact paths win over parameterized ones.
11
+ */
12
+ export declare function findPluginPage(plugins: readonly {
13
+ id: string;
14
+ pages?: readonly PluginPageDefinition[];
15
+ }[], pathname: string): (PluginPageDefinition & {
16
+ plugin: string;
5
17
  key: string;
6
- path: string;
7
- component: import("./presentation.js").PresentationType<"component">;
8
- } | undefined;
18
+ params: Record<string, string>;
19
+ }) | undefined;
20
+ type Exported<T> = {
21
+ default: T;
22
+ layout?: string;
23
+ order?: number;
24
+ key?: string;
25
+ when?: PluginView['when'];
26
+ boundary?: PresentationType<'component'>;
27
+ availability?: import('./slots/types.js').SlotAvailability;
28
+ requires?: readonly string[];
29
+ id?: string;
30
+ };
31
+ /** A page from `ui/pages/<path>.tsx`: the default export is the component; the path comes from the file. */
32
+ export declare function pluginPage(module: Exported<unknown>, path: string): PluginPageDefinition;
33
+ /** A slot view from `ui/slots/<slot>.tsx`. */
34
+ export declare function pluginSlot(module: Exported<unknown>, slot: string, source?: string): PluginView;
35
+ /** A layout from `src/layouts/<name>.tsx`: the default export wraps pages that name it. */
36
+ export declare function pluginLayout(module: Exported<unknown>): PresentationType<'component'>;
37
+ /** The settings page from `ui/settings/page.tsx`; it replaces the generated page of the plugin. */
38
+ export declare function pluginSettingsPage(module: Exported<unknown>): PluginSettingsPage;
39
+ /** A React provider from `ui/providers/<name>.tsx`. */
40
+ export declare function pluginProvider(module: Exported<unknown>, id: string): ProviderDefinition;
41
+ export {};
package/dist/pages.js CHANGED
@@ -1,22 +1,104 @@
1
+ import { setContributionSource } from './contribution-origin.js';
2
+ import { BitaKitStartupError } from './startup-error.js';
1
3
  /** Exact, canonical paths only. Routers remain responsible for dynamic parameters. */
2
- export function validatePluginPages(plugins) {
3
- const paths = new Set();
4
+ export function validatePluginPages(plugins, layouts = new Set()) {
5
+ const owners = new Map();
4
6
  for (const plugin of plugins) {
5
7
  for (const page of plugin.pages ?? []) {
6
- if (!/^\/(?:[a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9_-]+)*)?$/.test(page.path))
7
- throw new Error(`Invalid plugin page path "${page.path}" in "${plugin.id}".`);
8
- if (paths.has(page.path))
9
- throw new Error(`Duplicate plugin page path "${page.path}".`);
10
- paths.add(page.path);
8
+ if (page.layout &&
9
+ page.layout !== 'app' &&
10
+ page.layout !== 'blank' &&
11
+ !layouts.has(page.layout))
12
+ throw new BitaKitStartupError(`Page ${page.path} of plugin "${plugin.id}" names layout "${page.layout}", but src/layouts/${page.layout}.tsx does not exist.${layouts.size ? ` Known layouts: ${[...layouts].join(', ')}.` : ''} Use "app", "blank" or an existing layout.`, plugin.id);
13
+ if (!/^\/(?:(?:[a-zA-Z0-9_-]+|\[[a-zA-Z0-9_-]+\])(?:\/(?:[a-zA-Z0-9_-]+|\[[a-zA-Z0-9_-]+\]))*)?$/.test(page.path))
14
+ throw new BitaKitStartupError(`Invalid plugin page path "${page.path}" in plugin "${plugin.id}". Use a root-relative path such as /todos.`, plugin.id);
15
+ const owner = owners.get(page.path);
16
+ if (owner)
17
+ throw new BitaKitStartupError(`Plugins "${owner}" and "${plugin.id}" both define a page at ${page.path}.`, plugin.id);
18
+ owners.set(page.path, plugin.id);
11
19
  }
12
20
  }
13
21
  }
22
+ /** Matches one registered path against a pathname; `[id]` segments capture parameters. */
23
+ function matchPath(pattern, pathname) {
24
+ const expected = pattern.split('/').filter(Boolean);
25
+ const actual = pathname.split('/').filter(Boolean);
26
+ if (expected.length !== actual.length)
27
+ return undefined;
28
+ const params = {};
29
+ for (const [index, segment] of expected.entries()) {
30
+ const match = /^\[(.+)\]$/.exec(segment);
31
+ if (match)
32
+ params[match[1]] = decodeURIComponent(actual[index]);
33
+ else if (segment !== actual[index])
34
+ return undefined;
35
+ }
36
+ return params;
37
+ }
38
+ /**
39
+ * The registered page for a pathname, with its parameters and the ID of the module that owns
40
+ * it. Exact paths win over parameterized ones.
41
+ */
14
42
  export function findPluginPage(plugins, pathname) {
15
43
  const path = pathname.length > 1 ? pathname.replace(/\/$/, '') : pathname;
44
+ let fallback;
16
45
  for (const plugin of plugins) {
17
- const page = plugin.pages?.find((entry) => entry.path === path);
18
- if (page)
19
- return { ...page, key: `${plugin.id}:${page.path}` };
46
+ for (const page of plugin.pages ?? []) {
47
+ if (page.path === path)
48
+ return { ...page, plugin: plugin.id, key: `${plugin.id}:${page.path}`, params: {} };
49
+ if (!fallback && page.path.includes('[')) {
50
+ const params = matchPath(page.path, path);
51
+ if (params)
52
+ fallback = { ...page, plugin: plugin.id, key: `${plugin.id}:${page.path}`, params };
53
+ }
54
+ }
20
55
  }
21
- return undefined;
56
+ return fallback;
57
+ }
58
+ /** A page from `ui/pages/<path>.tsx`: the default export is the component; the path comes from the file. */
59
+ export function pluginPage(module, path) {
60
+ const value = module.default;
61
+ if (value && typeof value === 'object' && 'component' in value)
62
+ return value;
63
+ return { path, component: value, layout: module.layout };
64
+ }
65
+ /** A slot view from `ui/slots/<slot>.tsx`. */
66
+ export function pluginSlot(module, slot, source) {
67
+ const value = module.default;
68
+ const view = value && typeof value === 'object' && 'component' in value
69
+ ? { ...value, slot: value.slot ?? slot }
70
+ : {
71
+ slot,
72
+ component: value,
73
+ order: module.order,
74
+ ...(module.id === undefined ? {} : { id: module.id }),
75
+ ...(module.key === undefined ? {} : { key: module.key }),
76
+ ...(module.availability === undefined ? {} : { availability: module.availability }),
77
+ ...(module.when === undefined ? {} : { when: module.when }),
78
+ };
79
+ if (source)
80
+ setContributionSource(view, source);
81
+ return view;
82
+ }
83
+ /** A layout from `src/layouts/<name>.tsx`: the default export wraps pages that name it. */
84
+ export function pluginLayout(module) {
85
+ return module.default;
86
+ }
87
+ /** The settings page from `ui/settings/page.tsx`; it replaces the generated page of the plugin. */
88
+ export function pluginSettingsPage(module) {
89
+ const value = module.default;
90
+ if (value && typeof value === 'object' && ('component' in value || 'pages' in value))
91
+ return value;
92
+ return { component: value, boundary: module.boundary };
93
+ }
94
+ /** A React provider from `ui/providers/<name>.tsx`. */
95
+ export function pluginProvider(module, id) {
96
+ const value = module.default;
97
+ if (value && typeof value === 'object' && 'component' in value)
98
+ return value;
99
+ return {
100
+ id: module.id ?? id,
101
+ component: value,
102
+ requires: module.requires,
103
+ };
22
104
  }
@@ -1,4 +1,13 @@
1
+ import type { GeneratedName } from './names.js';
1
2
  /** Optional host presentation types. Core stores these values without rendering them. */
2
3
  export interface PresentationTypes {
3
4
  }
4
5
  export type PresentationType<Key extends string> = Key extends keyof PresentationTypes ? PresentationTypes[Key] : unknown;
6
+ /** Owned slot definitions, generated from `slots/`; augmentable for manual composition. */
7
+ export interface SlotMap {
8
+ }
9
+ /** Transitional name hints only. They neither declare a contract nor activate a slot. */
10
+ export interface LegacySlotMap {
11
+ }
12
+ /** A declared slot or legacy outlet name; strict generated apps reject unknown names. */
13
+ export type SlotName = GeneratedName<Extract<keyof SlotMap | keyof LegacySlotMap, string>>;
package/dist/runtime.d.ts CHANGED
@@ -1,28 +1,120 @@
1
1
  import { EventService } from './events/service.js';
2
+ import type { OwnedSlotDefinition } from './slots/define.js';
3
+ import type { SlotReader } from './slots/types.js';
2
4
  import { ConfigService } from './config-service.js';
3
- import { ActionGroup, type ActionList } from '@bitakit/core/actions';
4
- import type { ContributionMap, ResolvedContribution, ResolvedForm, Field, FoundationConfig, Plugin, Services, Translator } from './definitions.js';
5
- import type { FoundationApp } from './app/types.js';
5
+ import { type Destination } from './destinations.js';
6
+ import { ActionGroup, type ActionList, type ActionSnapshot } from '@bitakit/core/actions';
7
+ import type { ContributionMap, ResolvedContribution, BitaKitRuntimeConfig, Plugin, PluginPageDefinition, PluginView, ProviderDefinition, ServiceDefinition, Services, Translator } from './definitions.js';
8
+ import { SettingsStore } from './settings/store.js';
9
+ import { type SettingsAccess } from './settings/access.js';
10
+ import type { BitaKitApp } from './app/types.js';
6
11
  import { type Feedback, type MessageValues } from './actions/feedback.js';
7
12
  import { type ContributionHost, type DialogState, type FeedbackOutcome, type OpenableDefinition, type Override } from './contributions/index.js';
13
+ import type { Confirmation } from './confirmation.js';
14
+ import { type LifecycleState } from './lifecycle/state.js';
15
+ import { type PluginUpdateResult, type PluginDependentOptions } from './lifecycle/reconcile.js';
8
16
  export type { DialogState } from './contributions/index.js';
17
+ /** A plugin after normalization: records resolved to arrays with IDs, `ui` merged with the legacy fields. */
18
+ export type NormalizedPlugin = Omit<Plugin, 'services' | 'actions' | 'slots'> & {
19
+ readonly id: string;
20
+ readonly services: readonly (ServiceDefinition<any> & {
21
+ id: string;
22
+ })[];
23
+ readonly actions: readonly ResolvedContribution[];
24
+ readonly slots: readonly OwnedSlotDefinition[];
25
+ readonly pages: readonly PluginPageDefinition[];
26
+ readonly views: readonly PluginView[];
27
+ readonly providers: readonly ProviderDefinition[];
28
+ };
9
29
  /**
10
- * Mounts plugins into the host's ActionList. Each contribution kind is normalized by an adapter
11
- * in `./contributions`; the runtime owns services, translation, dialogs, ordering and cleanup.
30
+ * Mounts plugins into the host's ActionList. The runtime owns services, events, translation,
31
+ * dialogs, confirmation, ordering and cleanup; every contribution goes through one adapter.
12
32
  */
13
- export declare class FoundationRuntime implements ContributionHost {
33
+ export declare class BitaKitRuntime implements ContributionHost {
14
34
  readonly actions: ActionList;
15
- readonly config: FoundationConfig;
16
35
  private providedServices;
17
- readonly app: FoundationApp;
36
+ readonly app: BitaKitApp;
18
37
  readonly events: EventService;
19
38
  readonly configuration: ConfigService;
20
- readonly modules: readonly Plugin[];
39
+ private currentModules;
40
+ get modules(): readonly NormalizedPlugin[];
41
+ private currentConfig;
42
+ get config(): BitaKitRuntimeConfig;
43
+ readonly groups: Map<string, ActionGroup>;
44
+ /** The owner of setting values; `useSetting` and the `settings` contexts read from it. */
45
+ readonly settings: SettingsStore;
46
+ /** Typed handles under plugin namespaces, the `settings` every context receives. */
47
+ readonly settingsAccess: SettingsAccess;
48
+ private defaultStorage?;
49
+ private readonly appId;
50
+ private order;
51
+ private readonly names;
21
52
  private readonly actionConfigs;
22
- private ready;
53
+ private mounted;
54
+ private mounting;
55
+ private tearingDown;
56
+ readonly lifecycle: LifecycleState;
57
+ readonly slots: SlotReader;
58
+ private slotRuntime;
59
+ private lifecycleState;
60
+ private generation;
61
+ private stopCompletion?;
62
+ private mountStop?;
63
+ private startWork?;
64
+ private startPending;
65
+ private setupComplete;
66
+ private activeRuns;
67
+ private updating?;
68
+ private updateController?;
69
+ private disabledPlugins;
70
+ /** Descendants a parent's disable switched off, so enabling the parent restores exactly them. */
71
+ private disabledWithParent;
72
+ /** Host-only structural changes; no package loading or persistence is performed by Core. */
73
+ readonly plugins: Readonly<{
74
+ add: (plugins: readonly Plugin[]) => Promise<Readonly<{
75
+ status: "applied" | "blocked" | "failed" | "restart-required";
76
+ revision: number;
77
+ changed: readonly string[];
78
+ affected: readonly string[];
79
+ reasons: readonly string[];
80
+ }>>;
81
+ remove: (ids: readonly string[], options: PluginDependentOptions) => Promise<Readonly<{
82
+ status: "applied" | "blocked" | "failed" | "restart-required";
83
+ revision: number;
84
+ changed: readonly string[];
85
+ affected: readonly string[];
86
+ reasons: readonly string[];
87
+ }>>;
88
+ enable: (id: string) => Promise<Readonly<{
89
+ status: "applied" | "blocked" | "failed" | "restart-required";
90
+ revision: number;
91
+ changed: readonly string[];
92
+ affected: readonly string[];
93
+ reasons: readonly string[];
94
+ }>>;
95
+ disable: (id: string, options: PluginDependentOptions) => Promise<Readonly<{
96
+ status: "applied" | "blocked" | "failed" | "restart-required";
97
+ revision: number;
98
+ changed: readonly string[];
99
+ affected: readonly string[];
100
+ reasons: readonly string[];
101
+ }>>;
102
+ }>;
103
+ private revision;
104
+ getRevision: () => number;
105
+ private observations;
106
+ private pluginEvents;
107
+ /** Settles after the current shutdown; a rejection means cleanup did not complete successfully. */
108
+ get stopped(): Promise<void>;
109
+ stop: () => Promise<void>;
23
110
  private readinessListeners;
24
- isReady: () => boolean;
111
+ private readyDeferred;
112
+ private startController?;
113
+ /** Initial startup has completed and shutdown has not begun. Updates use owner readiness. */
114
+ isReady: (plugin?: string) => boolean;
25
115
  subscribeReady: (listener: () => void) => () => void;
116
+ /** Resolves when every service's `onStart` has completed; rejects with the attributed startup error. */
117
+ get ready(): Promise<void>;
26
118
  private setReady;
27
119
  private listeners;
28
120
  private state;
@@ -30,30 +122,46 @@ export declare class FoundationRuntime implements ContributionHost {
30
122
  private scopes;
31
123
  private extensionCleanups;
32
124
  private container?;
125
+ private view?;
33
126
  private translate;
34
127
  private translationRevision;
35
128
  private translationListeners;
36
129
  getTranslationRevision: () => number;
37
130
  subscribeTranslations: (listener: () => void) => () => void;
38
131
  private notifier?;
39
- private formFeedback;
40
- readonly groups: Map<string, ActionGroup>;
41
- constructor(actions: ActionList, config: FoundationConfig, providedServices?: Partial<Services>);
42
- private get appId();
43
- private order?;
44
- /** Modules in install order: dependencies first, the application module included. */
45
- private moduleOrder;
132
+ private confirmHandler?;
133
+ private confirmWarned;
134
+ constructor(actions: ActionList, config: BitaKitRuntimeConfig, providedServices?: Readonly<Record<string, unknown>>);
135
+ private serviceEntries;
136
+ private settingEntries;
137
+ /** The `settings.storage` contract when a service provides it, otherwise browser storage. */
138
+ private storage;
46
139
  /**
47
- * Declarative contributions of one kind in install order. Pure and available before mount, so
48
- * UI integrations can derive an initial render snapshot equivalent to the mounted state.
140
+ * Loads settings for the identity the `auth` contract reports. Runs after setup and whenever
141
+ * an observed service changes, so no extra subscription is needed; without authentication the
142
+ * anonymous device identity applies. Never blocks readiness.
49
143
  */
144
+ private syncIdentity;
145
+ /** Every name (ID and aliases) that resolves to a container key. */
146
+ private aliasesOf;
147
+ /** Declarative contributions of one kind in install order; available before mount. */
50
148
  contributionsOf<K extends string>(kind: K): readonly {
51
149
  module: string;
52
150
  app: boolean;
53
151
  values: readonly (K extends keyof ContributionMap ? ContributionMap[K] : unknown)[];
54
152
  }[];
153
+ /** What a URL Action leads to and which plugin owns it, from existing registrations. */
154
+ destinationOf(action: Pick<ActionSnapshot, 'id' | 'href' | 'metadata'>): Destination | undefined;
155
+ actionOwner(id: string): string | undefined;
156
+ private ownerOf;
157
+ /** One group per ID; the first title given for an ID is kept. */
55
158
  getGroup: (entry: string | ActionGroup) => ActionGroup<unknown>;
159
+ /** The live service tree every contribution sees. */
56
160
  get services(): Services;
161
+ servicesIfMounted(): Services | undefined;
162
+ hasService(name: string): boolean;
163
+ /** UI availability; raw service access remains available to dependent cleanup hooks. */
164
+ isServiceReady(name: string): boolean;
57
165
  getSnapshot: () => DialogState | null;
58
166
  getServerSnapshot: () => null;
59
167
  subscribe: (listener: () => void) => () => void;
@@ -62,29 +170,59 @@ export declare class FoundationRuntime implements ContributionHost {
62
170
  text(key: string | undefined, fallback: string, values?: MessageValues): string;
63
171
  title(definition: ResolvedContribution): string;
64
172
  description(definition: ResolvedContribution): string | undefined;
65
- fieldLabel(definition: ResolvedForm, name: string, field: Field): string;
173
+ tooltip(definition: ResolvedContribution): string | undefined;
66
174
  /** Installs one presentation sink; disposing an older owner cannot clear its replacement. */
67
175
  setNotifier(notify: (message: string, kind: 'success' | 'failure') => unknown): () => void;
68
- /** Presentation failures, including rejected promises, never change the Action outcome. */
69
176
  notify(message: string | false, kind?: 'success' | 'failure'): void;
177
+ /** Installs the host's confirmation dialog for actions with `confirm`. */
178
+ setConfirm(handler: (request: Confirmation) => Promise<boolean> | boolean): () => void;
179
+ confirm(request: Confirmation): Promise<boolean>;
70
180
  translator(): Translator;
71
181
  override(id: string): Override;
72
182
  dialog(): DialogState | null;
73
183
  openDialog(definition: OpenableDefinition, input: unknown): void;
74
- rememberFormFeedback(state: DialogState, outcome: FeedbackOutcome): void;
75
- feedback<C>(definition: ResolvedContribution, kind: 'success' | 'failure', option: Feedback<C>, context: C): FeedbackOutcome;
76
- /** Public submission path; the internal submit registration owns validation and pending guards. */
77
- submitForm(definition: ResolvedForm, values: Record<string, string>): Promise<void>;
184
+ /**
185
+ * Resolves a feedback option. Without one, the `<id>.success` / `<id>.failure` catalog keys
186
+ * apply; a failure without any message shows the error in development and a generic text
187
+ * in production. Feedback callbacks can never turn a success into a failure.
188
+ */
189
+ feedback<C>(definition: ResolvedContribution, kind: 'success' | 'failure', option: Feedback<C> | undefined, context: C & {
190
+ error?: unknown;
191
+ }): FeedbackOutcome;
78
192
  setTranslations(translate: Translator): void;
79
193
  close: () => void;
80
- mount(): () => void;
194
+ private reportLifecycleError;
195
+ private servicePhase;
196
+ private refreshPluginReadiness;
197
+ mount(): () => Promise<void>;
198
+ private start;
199
+ private startFailed;
81
200
  /** Routes each contribution kind to the one module that installs it; cleanup stays with the contributor. */
82
201
  private installContributions;
83
202
  private connectTranslation;
84
203
  private installInterceptors;
204
+ /** Resolves required names to container keys; a missing one is attributed to `module`. */
85
205
  private requireServices;
86
- /** One path for every kind: adapt, check dependencies, register, remember for re-translation. */
206
+ private attribute;
207
+ /** One path for every action: adapt, check dependencies, register, remember for re-translation. */
87
208
  private install;
209
+ /** Reconcile subscriptions over the existing container; never mirror service state. */
88
210
  private observe;
211
+ /** Plan structural changes before touching scopes; use the existing update exclusion and executor. */
212
+ private changePlugins;
213
+ /** Explicit host update of already-loaded immutable plugin definitions; never installs code. */
214
+ reconcilePlugins(next: readonly Plugin[]): Promise<PluginUpdateResult>;
215
+ private stopPlugins;
216
+ private applyPluginUpdate;
89
217
  private unmount;
218
+ private teardown;
90
219
  }
220
+ /**
221
+ * Creates the runtime for one composition; `runtime.mount()` starts it and returns the stop
222
+ * function. Core creates the ActionList unless you pass one. `services` supplies host-owned
223
+ * services, such as authentication, under their contract names.
224
+ */
225
+ export declare function createRuntime(config: BitaKitRuntimeConfig, options?: {
226
+ actions?: ActionList;
227
+ services?: Readonly<Record<string, unknown>>;
228
+ }): BitaKitRuntime;