@bitakit/core 0.1.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +382 -0
  3. package/discovery/entries.mjs +124 -0
  4. package/discovery/generate.mjs +327 -0
  5. package/discovery/host.mjs +12 -0
  6. package/discovery/index.d.ts +41 -0
  7. package/discovery/index.mjs +4 -0
  8. package/discovery/modules.mjs +13 -0
  9. package/discovery/packages.mjs +57 -0
  10. package/discovery/watch.mjs +23 -0
  11. package/dist/actions/action-list.d.ts +69 -0
  12. package/dist/actions/action-list.js +247 -0
  13. package/dist/actions/action.d.ts +96 -0
  14. package/dist/actions/action.js +145 -0
  15. package/dist/actions/base/url-action.d.ts +8 -0
  16. package/dist/actions/base/url-action.js +15 -0
  17. package/dist/actions/core.d.ts +14 -0
  18. package/dist/actions/core.js +8 -0
  19. package/dist/actions/dependencies.d.ts +8 -0
  20. package/dist/actions/dependencies.js +34 -0
  21. package/dist/actions/execution.d.ts +4 -0
  22. package/dist/actions/execution.js +64 -0
  23. package/dist/actions/feedback.d.ts +17 -0
  24. package/dist/actions/feedback.js +21 -0
  25. package/dist/actions/groups.d.ts +13 -0
  26. package/dist/actions/groups.js +21 -0
  27. package/dist/actions/instance-bindings.d.ts +16 -0
  28. package/dist/actions/instance-bindings.js +93 -0
  29. package/dist/actions/interceptors.d.ts +24 -0
  30. package/dist/actions/interceptors.js +42 -0
  31. package/dist/actions/navigation.d.ts +12 -0
  32. package/dist/actions/navigation.js +42 -0
  33. package/dist/actions/reference.d.ts +17 -0
  34. package/dist/actions/reference.js +39 -0
  35. package/dist/actions/state.d.ts +11 -0
  36. package/dist/actions/state.js +8 -0
  37. package/dist/actions/types.d.ts +99 -0
  38. package/dist/actions/types.js +1 -0
  39. package/dist/app/access.d.ts +4 -0
  40. package/dist/app/access.js +85 -0
  41. package/dist/app/action-access.d.ts +4 -0
  42. package/dist/app/action-access.js +20 -0
  43. package/dist/app/service-error.d.ts +8 -0
  44. package/dist/app/service-error.js +19 -0
  45. package/dist/app/types.d.ts +47 -0
  46. package/dist/app/types.js +1 -0
  47. package/dist/config-service.d.ts +49 -0
  48. package/dist/config-service.js +83 -0
  49. package/dist/configuration.d.ts +4 -0
  50. package/dist/configuration.js +42 -0
  51. package/dist/confirmation.d.ts +14 -0
  52. package/dist/confirmation.js +26 -0
  53. package/dist/contracts.d.ts +27 -0
  54. package/dist/contracts.js +3 -0
  55. package/dist/contribution-origin.d.ts +3 -0
  56. package/dist/contribution-origin.js +13 -0
  57. package/dist/contributions/command.d.ts +8 -0
  58. package/dist/contributions/command.js +50 -0
  59. package/dist/contributions/dialog.d.ts +8 -0
  60. package/dist/contributions/dialog.js +18 -0
  61. package/dist/contributions/form.d.ts +10 -0
  62. package/dist/contributions/form.js +67 -0
  63. package/dist/contributions/host.d.ts +40 -0
  64. package/dist/contributions/host.js +1 -0
  65. package/dist/contributions/index.d.ts +26 -0
  66. package/dist/contributions/index.js +18 -0
  67. package/dist/contributions/native.d.ts +11 -0
  68. package/dist/contributions/native.js +87 -0
  69. package/dist/contributions/shared.d.ts +19 -0
  70. package/dist/contributions/shared.js +48 -0
  71. package/dist/contributions/stateful-action.d.ts +29 -0
  72. package/dist/contributions/stateful-action.js +33 -0
  73. package/dist/conventions.d.ts +4 -0
  74. package/dist/conventions.js +38 -0
  75. package/dist/core.d.ts +21 -0
  76. package/dist/core.js +18 -0
  77. package/dist/definitions.d.ts +356 -0
  78. package/dist/definitions.js +60 -0
  79. package/dist/discovered.d.ts +49 -0
  80. package/dist/discovered.js +120 -0
  81. package/dist/interceptors/service-observers.d.ts +3 -0
  82. package/dist/interceptors/service-observers.js +80 -0
  83. package/dist/interceptors/service.d.ts +37 -0
  84. package/dist/interceptors/service.js +7 -0
  85. package/dist/messages.d.ts +9 -0
  86. package/dist/messages.js +21 -0
  87. package/dist/metadata.d.ts +3 -0
  88. package/dist/metadata.js +13 -0
  89. package/dist/pages.d.ts +8 -0
  90. package/dist/pages.js +22 -0
  91. package/dist/presentation.d.ts +4 -0
  92. package/dist/presentation.js +1 -0
  93. package/dist/replacements.d.ts +22 -0
  94. package/dist/replacements.js +54 -0
  95. package/dist/runtime.d.ts +88 -0
  96. package/dist/runtime.js +445 -0
  97. package/dist/scope.d.ts +34 -0
  98. package/dist/scope.js +78 -0
  99. package/dist/service-key.d.ts +13 -0
  100. package/dist/service-key.js +14 -0
  101. package/dist/services.d.ts +6 -0
  102. package/dist/services.js +53 -0
  103. package/dist/translation.d.ts +13 -0
  104. package/dist/translation.js +43 -0
  105. package/dist/validation.d.ts +2 -0
  106. package/dist/validation.js +16 -0
  107. package/docs/file-contributions.md +161 -0
  108. package/package.json +48 -0
@@ -0,0 +1,47 @@
1
+ import type { ActionReference, KnownActionId } from '../actions/core.js';
2
+ import type { ConfigMap } from '../config-service.js';
3
+ import type { Plugin } from '../definitions.js';
4
+ import type { ServiceKey } from '../service-key.js';
5
+ /** Published contracts are exposed inside app.services. */
6
+ export type PublicServiceKeys = Readonly<Record<string, ServiceKey<any>>>;
7
+ /** Extended by app discovery; package installation alone does not declare availability. */
8
+ export interface PublicServiceMap {
9
+ }
10
+ /** Optional packages contribute their own typed facades without Core depending on them. */
11
+ export interface AppExtensionMap {
12
+ }
13
+ type Published<P> = P extends {
14
+ publicServices: infer Keys extends PublicServiceKeys;
15
+ } ? {
16
+ readonly [K in keyof Keys]: Keys[K] extends ServiceKey<infer T> ? T : never;
17
+ } : {};
18
+ type Intersection<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
19
+ export type PublicServicesOf<Plugins extends readonly Plugin[]> = [Plugins[number]] extends [never] ? {} : Intersection<Published<Plugins[number]>>;
20
+ /** Service reads resolve the current runtime container; they never copy or own service state. */
21
+ type AtPath<Path extends string, Value> = Path extends `${infer Head}.${infer Tail}` ? {
22
+ readonly [K in Head]: AtPath<Tail, Value>;
23
+ } : {
24
+ readonly [K in Path]: Value;
25
+ };
26
+ /** The same dotted names drive generated completion and runtime namespaces. */
27
+ export type Namespace<Entries extends object> = keyof Entries extends never ? {} : Intersection<{
28
+ [K in keyof Entries & string]: AtPath<K, Entries[K]>;
29
+ }[keyof Entries & string]>;
30
+ type Immutable<T> = T extends object ? {
31
+ readonly [K in keyof T]: Immutable<T[K]>;
32
+ } : T;
33
+ export type FoundationActions = Namespace<{
34
+ [K in KnownActionId]: ActionReference<K>;
35
+ }>;
36
+ export interface FoundationApp<Public extends object = PublicServiceMap> extends AppExtensionMap {
37
+ readonly actions: FoundationActions;
38
+ readonly config: Namespace<Immutable<ConfigMap>>;
39
+ readonly services: Namespace<Public>;
40
+ readonly ready: boolean;
41
+ readonly optional: {
42
+ readonly services: Namespace<{
43
+ [K in keyof Public]: Public[K] | undefined;
44
+ }>;
45
+ };
46
+ }
47
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ /** Immutable configuration. User preferences continue to belong to AppPreferences. */
2
+ export interface ConfigMap {
3
+ }
4
+ export type ConfigValues = Readonly<Record<string, unknown>>;
5
+ declare const configDefinition: unique symbol;
6
+ export type ConfigSchema<T> = {
7
+ parse(input: unknown): T;
8
+ };
9
+ export type ConfigDefinition<T = ConfigValues> = {
10
+ readonly [configDefinition]: true;
11
+ readonly defaults?: Partial<T>;
12
+ readonly schema?: ConfigSchema<T>;
13
+ };
14
+ export declare function defineConfig<T extends ConfigValues>(value: {
15
+ defaults: T;
16
+ }): ConfigDefinition<T>;
17
+ export declare function defineConfig<T>(value: {
18
+ schema: ConfigSchema<T>;
19
+ defaults?: Partial<T>;
20
+ }): ConfigDefinition<T>;
21
+ export declare function defineConfig<T extends ConfigValues>(value: T): T;
22
+ export declare function isConfigDefinition(value: unknown): value is ConfigDefinition;
23
+ export declare function isConfigObject(value: unknown): value is Record<string, unknown>;
24
+ export type ConfigPath = string | readonly string[];
25
+ export type ConfigAt<T, P extends string> = P extends keyof T ? T[P] : P extends `${infer Head}.${infer Tail}` ? Head extends keyof T ? ConfigAt<T[Head], Tail> : unknown : unknown;
26
+ export declare class ConfigScope<T = ConfigValues> {
27
+ private readonly value;
28
+ constructor(value: T);
29
+ get<P extends string>(path: P): ConfigAt<T, P>;
30
+ get<V>(path: ConfigPath, fallback: V): V;
31
+ get(path: readonly string[]): unknown;
32
+ scope<U = ConfigValues>(path: ConfigPath): ConfigScope<U>;
33
+ snapshot(): T;
34
+ }
35
+ export type ConfigContext = {
36
+ plugin: ConfigScope;
37
+ action: ConfigScope;
38
+ };
39
+ export declare class ConfigService {
40
+ private readonly modules;
41
+ constructor(modules: readonly {
42
+ id: string;
43
+ config?: ConfigValues | ConfigDefinition;
44
+ }[], overrides?: Readonly<Record<string, ConfigValues>>);
45
+ plugin<K extends keyof ConfigMap & string>(id: K): ConfigScope<ConfigMap[K]>;
46
+ plugin<T = ConfigValues>(id: string): ConfigScope<T>;
47
+ context(id: string, actionPath?: readonly string[]): ConfigContext;
48
+ }
49
+ export {};
@@ -0,0 +1,83 @@
1
+ const configDefinition = Symbol('foundation.config');
2
+ export function defineConfig(value) {
3
+ return 'defaults' in value || (value.schema && typeof value.schema.parse === 'function')
4
+ ? { ...value, [configDefinition]: true }
5
+ : value;
6
+ }
7
+ export function isConfigDefinition(value) {
8
+ return !!value && typeof value === 'object' && configDefinition in value;
9
+ }
10
+ export function isConfigObject(value) {
11
+ return (!!value &&
12
+ typeof value === 'object' &&
13
+ !Array.isArray(value) &&
14
+ (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null));
15
+ }
16
+ function immutable(value) {
17
+ if (Array.isArray(value))
18
+ return Object.freeze(value.map(immutable));
19
+ if (isConfigObject(value))
20
+ return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, immutable(item)])));
21
+ if ((value !== null && typeof value === 'object') || typeof value === 'function')
22
+ throw new TypeError('Config snapshots require plain objects, arrays and primitive values.');
23
+ return value;
24
+ }
25
+ function resolve(defaults, override) {
26
+ if (isConfigDefinition(defaults))
27
+ return immutable(defaults.schema
28
+ ? defaults.schema.parse(resolve(defaults.defaults ?? {}, override))
29
+ : resolve(defaults.defaults ?? {}, override));
30
+ if (isConfigObject(defaults) && (override === undefined || isConfigObject(override))) {
31
+ const extra = (override ?? {});
32
+ return Object.freeze(Object.fromEntries([...new Set([...Object.keys(defaults), ...Object.keys(extra)])].map((key) => [
33
+ key,
34
+ resolve(defaults[key], extra[key]),
35
+ ])));
36
+ }
37
+ return immutable(override === undefined ? defaults : override);
38
+ }
39
+ export class ConfigScope {
40
+ value;
41
+ constructor(value) {
42
+ this.value = value;
43
+ }
44
+ get(path, fallback) {
45
+ const segments = typeof path === 'string' ? path.split('.') : path;
46
+ let value = this.value;
47
+ for (const key of segments) {
48
+ if (!value || typeof value !== 'object' || !Object.hasOwn(value, key))
49
+ return fallback;
50
+ value = value[key];
51
+ }
52
+ return value === undefined ? fallback : value;
53
+ }
54
+ scope(path) {
55
+ return new ConfigScope((this.get(typeof path === 'string' ? path.split('.') : path) ?? {}));
56
+ }
57
+ snapshot() {
58
+ return this.value;
59
+ }
60
+ }
61
+ export class ConfigService {
62
+ modules = new Map();
63
+ constructor(modules, overrides = {}) {
64
+ for (const module of modules) {
65
+ if (this.modules.has(module.id))
66
+ throw new Error(`Duplicate config module "${module.id}".`);
67
+ this.modules.set(module.id, new ConfigScope(resolve(module.config ?? {}, overrides[module.id])));
68
+ }
69
+ for (const id of Object.keys(overrides))
70
+ if (!this.modules.has(id))
71
+ throw new Error(`Unknown config module "${id}".`);
72
+ }
73
+ plugin(id) {
74
+ const scope = this.modules.get(id);
75
+ if (!scope)
76
+ throw new Error(`Unknown config module "${id}".`);
77
+ return scope;
78
+ }
79
+ context(id, actionPath = []) {
80
+ const plugin = this.plugin(id);
81
+ return { plugin, action: plugin.scope(['actions', ...actionPath]) };
82
+ }
83
+ }
@@ -0,0 +1,4 @@
1
+ import type { FoundationConfig } from './definitions.js';
2
+ export type FoundationOverrides = Pick<FoundationConfig, 'actions' | 'plugins' | 'interceptors' | 'providers'>;
3
+ /** Undefined inherits. An explicit list replaces that domain, including an empty list. */
4
+ export declare function resolveFoundationConfig(discovered: FoundationConfig, overrides?: FoundationOverrides): FoundationConfig;
@@ -0,0 +1,42 @@
1
+ /** Undefined inherits. An explicit list replaces that domain, including an empty list. */
2
+ export function resolveFoundationConfig(discovered, overrides = {}) {
3
+ const selectedPlugins = overrides.plugins ?? discovered.plugins ?? [];
4
+ const config = {
5
+ ...discovered,
6
+ plugins: overrides.actions === undefined && overrides.interceptors === undefined
7
+ ? selectedPlugins
8
+ : selectedPlugins.map((plugin) => ({
9
+ ...plugin,
10
+ ...(overrides.actions === undefined ? {} : { actions: [] }),
11
+ ...(overrides.interceptors === undefined ? {} : { interceptors: [] }),
12
+ })),
13
+ actions: overrides.actions ?? discovered.actions ?? [],
14
+ interceptors: overrides.interceptors ?? discovered.interceptors ?? [],
15
+ providers: overrides.providers ?? discovered.providers ?? [],
16
+ };
17
+ const removed = new Set((discovered.plugins ?? [])
18
+ .filter((plugin) => !selectedPlugins.some((selected) => selected.id === plugin.id))
19
+ .map((plugin) => plugin.id));
20
+ if (config.configOverrides)
21
+ config.configOverrides = Object.fromEntries(Object.entries(config.configOverrides).filter(([id]) => !removed.has(id)));
22
+ const pluginIds = new Set();
23
+ for (const plugin of config.plugins ?? []) {
24
+ if (!plugin.id || pluginIds.has(plugin.id))
25
+ throw new Error(`Invalid or duplicate plugin "${plugin.id}".`);
26
+ pluginIds.add(plugin.id);
27
+ }
28
+ const pluginProviders = (config.plugins ?? []).flatMap((plugin) => plugin.providers ?? []);
29
+ if (overrides.providers === undefined && pluginProviders.length)
30
+ config.providers = [...pluginProviders, ...config.providers];
31
+ const seen = new Set();
32
+ for (const provider of config.providers) {
33
+ if (!provider.id || seen.has(provider.id))
34
+ throw new Error(`Invalid or duplicate provider "${provider.id}".`);
35
+ for (const id of provider.requires ?? []) {
36
+ if (!seen.has(id))
37
+ throw new Error(`Provider "${provider.id}" requires "${id}" before it.`);
38
+ }
39
+ seen.add(provider.id);
40
+ }
41
+ return config;
42
+ }
@@ -0,0 +1,14 @@
1
+ export type Confirmation = {
2
+ title: string;
3
+ description: string;
4
+ destructive?: boolean;
5
+ };
6
+ /** Owns a single pending decision; creating it has no side effects. */
7
+ export declare class ConfirmationController {
8
+ private display;
9
+ private resolve?;
10
+ constructor(display: (request: Confirmation | null) => void);
11
+ confirm: (request: Confirmation) => Promise<boolean>;
12
+ answer: (accepted: boolean) => void;
13
+ dispose: () => void;
14
+ }
@@ -0,0 +1,26 @@
1
+ /** Owns a single pending decision; creating it has no side effects. */
2
+ export class ConfirmationController {
3
+ display;
4
+ resolve;
5
+ constructor(display) {
6
+ this.display = display;
7
+ }
8
+ confirm = (request) => new Promise((resolve) => {
9
+ if (this.resolve) {
10
+ resolve(false);
11
+ return;
12
+ }
13
+ this.resolve = resolve;
14
+ this.display(request);
15
+ });
16
+ answer = (accepted) => {
17
+ const resolve = this.resolve;
18
+ this.resolve = undefined;
19
+ this.display(null);
20
+ resolve?.(accepted);
21
+ };
22
+ dispose = () => {
23
+ this.resolve?.(false);
24
+ this.resolve = undefined;
25
+ };
26
+ }
@@ -0,0 +1,27 @@
1
+ import type { Translator } from './definitions.js';
2
+ export type AuthSnapshot = {
3
+ user: {
4
+ id: string;
5
+ name?: string;
6
+ email?: string;
7
+ } | null;
8
+ pending: boolean;
9
+ error: unknown;
10
+ };
11
+ export interface AuthService {
12
+ getSnapshot(): AuthSnapshot;
13
+ subscribe(listener: () => void): () => void;
14
+ signOut(): Promise<void>;
15
+ }
16
+ /** Nested, read-only message data supplied by the translation provider. */
17
+ export type TranslationCatalog = {
18
+ readonly [key: string]: string | TranslationCatalog;
19
+ };
20
+ export interface TranslationService {
21
+ translate: Translator;
22
+ /** Current raw message group; undefined when unavailable. No vendor-specific types. */
23
+ getCatalog?(namespace?: string): TranslationCatalog | undefined;
24
+ subscribe(listener: () => void): () => void;
25
+ }
26
+ export declare const authService: import("./service-key.js").ServiceKey<AuthService>;
27
+ export declare const translationService: import("./service-key.js").ServiceKey<TranslationService>;
@@ -0,0 +1,3 @@
1
+ import { serviceKey } from './service-key.js';
2
+ export const authService = serviceKey('auth');
3
+ export const translationService = serviceKey('i18n');
@@ -0,0 +1,3 @@
1
+ export declare function contributionPath(entry: object): readonly string[] | undefined;
2
+ export declare function preserveContributionPath(from: object, to: object): object;
3
+ export declare function setContributionPath(entry: object, path: readonly string[]): void;
@@ -0,0 +1,13 @@
1
+ const origins = new WeakMap();
2
+ export function contributionPath(entry) {
3
+ return origins.get(entry);
4
+ }
5
+ export function preserveContributionPath(from, to) {
6
+ const path = origins.get(from);
7
+ if (path)
8
+ origins.set(to, path);
9
+ return to;
10
+ }
11
+ export function setContributionPath(entry, path) {
12
+ origins.set(entry, path);
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { ConfigContext } from '../config-service.js';
2
+ import type { PlainDefinition } from '../definitions.js';
3
+ import type { ContributionHost } from './host.js';
4
+ import type { Adapted } from './index.js';
5
+ /** Plain commands: contextual presentation from services, explicit outcome feedback around execution. */
6
+ export declare function adaptCommand(resolved: PlainDefinition<any, any> & {
7
+ id: string;
8
+ }, host: ContributionHost, config: ConfigContext): Adapted;
@@ -0,0 +1,50 @@
1
+ import { ActionFailure } from '../actions/feedback.js';
2
+ import { applyOverride, cap, groupsOf, texts } from './shared.js';
3
+ /** Plain commands: contextual presentation from services, explicit outcome feedback around execution. */
4
+ export function adaptCommand(resolved, host, config) {
5
+ const { definition, override } = applyOverride(resolved, host);
6
+ const services = host.services;
7
+ const execute = definition.execute;
8
+ return {
9
+ definition,
10
+ requires: definition.requires ?? [],
11
+ watch: definition.watch ?? [],
12
+ registrations: [
13
+ {
14
+ id: definition.id,
15
+ placement: {},
16
+ definition: {
17
+ ...definition,
18
+ ...texts(host, definition),
19
+ groups: groupsOf(host, definition),
20
+ resolve: (input) => cap(definition.resolve?.(input, { services, config }) ?? {}, override),
21
+ execute: execute
22
+ ? async (context) => {
23
+ let result;
24
+ try {
25
+ result = await execute({ ...context, services, config, app: host.app });
26
+ }
27
+ catch (error) {
28
+ const feedback = context.get()
29
+ ? host.feedback(definition, 'failure', definition.failure, {
30
+ error,
31
+ input: context.input,
32
+ services,
33
+ }).message
34
+ : false;
35
+ throw new ActionFailure(feedback, error);
36
+ }
37
+ if (context.get())
38
+ host.notify(host.feedback(definition, 'success', definition.success, {
39
+ result,
40
+ input: context.input,
41
+ services,
42
+ }).message);
43
+ return result;
44
+ }
45
+ : undefined,
46
+ },
47
+ },
48
+ ],
49
+ };
50
+ }
@@ -0,0 +1,8 @@
1
+ import type { ConfigContext } from '../config-service.js';
2
+ import type { DialogDefinition } from '../definitions.js';
3
+ import type { ContributionHost } from './host.js';
4
+ import type { Adapted } from './index.js';
5
+ /** Custom dialogs: the opener carries contextual guards; the body renders inside the dialog host. */
6
+ export declare function adaptDialog(resolved: DialogDefinition<any> & {
7
+ id: string;
8
+ }, host: ContributionHost, config: ConfigContext): Adapted;
@@ -0,0 +1,18 @@
1
+ import { applyOverride, cap, opener } from './shared.js';
2
+ /** Custom dialogs: the opener carries contextual guards; the body renders inside the dialog host. */
3
+ export function adaptDialog(resolved, host, config) {
4
+ const { definition, override } = applyOverride(resolved, host);
5
+ const services = host.services;
6
+ return {
7
+ definition,
8
+ requires: definition.requires ?? [],
9
+ watch: definition.watch ?? [],
10
+ registrations: [
11
+ {
12
+ id: definition.id,
13
+ placement: {},
14
+ definition: opener(host, definition, (input) => cap(definition.resolve?.(input, { services, config }) ?? {}, override)),
15
+ },
16
+ ],
17
+ };
18
+ }
@@ -0,0 +1,10 @@
1
+ import type { ConfigContext } from '../config-service.js';
2
+ import type { ResolvedForm } from '../definitions.js';
3
+ import type { ContributionHost } from './host.js';
4
+ import type { Adapted } from './index.js';
5
+ /**
6
+ * Forms register the public opener plus an internal `<id>.submit` registration. Submission runs
7
+ * through the same executor so interceptors, pending state and execution events apply, but it is
8
+ * excluded from enumeration: `runtime.submitForm` is the supported programmatic path.
9
+ */
10
+ export declare function adaptForm(resolved: ResolvedForm, host: ContributionHost, config: ConfigContext): Adapted;
@@ -0,0 +1,67 @@
1
+ import { ActionFailure } from '../actions/feedback.js';
2
+ import { validateFields } from '../validation.js';
3
+ import { applyOverride, cap, opener, texts } from './shared.js';
4
+ /**
5
+ * Forms register the public opener plus an internal `<id>.submit` registration. Submission runs
6
+ * through the same executor so interceptors, pending state and execution events apply, but it is
7
+ * excluded from enumeration: `runtime.submitForm` is the supported programmatic path.
8
+ */
9
+ export function adaptForm(resolved, host, config) {
10
+ const { definition, override } = applyOverride(resolved, host);
11
+ const services = host.services;
12
+ const shared = texts(host, definition);
13
+ const submit = {
14
+ id: `${definition.id}.submit`,
15
+ title: shared.title,
16
+ description: shared.description,
17
+ internal: true,
18
+ resolve: () => {
19
+ const state = host.dialog();
20
+ return {
21
+ enabled: state?.definition === definition &&
22
+ !!host.actions.resolve(definition.id, state?.input)?.enabled,
23
+ visible: !!host.actions.get(definition.id)?.visible,
24
+ };
25
+ },
26
+ execute: async (context) => {
27
+ const state = host.dialog();
28
+ const input = validateFields(definition.fields, context.input);
29
+ let result;
30
+ try {
31
+ result = await definition.submit(input, { services, config, input: state?.input });
32
+ }
33
+ catch (error) {
34
+ const feedback = context.get() && host.dialog() === state
35
+ ? host.feedback(definition, 'failure', definition.failure, { error, input, services })
36
+ .message
37
+ : false;
38
+ throw new ActionFailure(feedback, error);
39
+ }
40
+ if (state && context.get() && host.dialog() === state) {
41
+ const feedback = host.feedback(definition, 'success', definition.success, {
42
+ result,
43
+ input,
44
+ services,
45
+ });
46
+ host.rememberFormFeedback(state, {
47
+ ...feedback,
48
+ closeDialog: definition.closeOnSuccess ?? feedback.closeDialog,
49
+ });
50
+ }
51
+ return result;
52
+ },
53
+ };
54
+ return {
55
+ definition,
56
+ requires: definition.requires ?? [],
57
+ watch: [],
58
+ registrations: [
59
+ {
60
+ id: definition.id,
61
+ placement: {},
62
+ definition: opener(host, definition, () => cap({}, override)),
63
+ },
64
+ { id: submit.id, placement: {}, definition: submit },
65
+ ],
66
+ };
67
+ }
@@ -0,0 +1,40 @@
1
+ import type { ActionGroup, ActionList } from '@bitakit/core/actions';
2
+ import type { Feedback, MessageValues } from '../actions/feedback.js';
3
+ import type { ResolvedContribution, Services, Translator } from '../definitions.js';
4
+ import type { FoundationApp } from '../app/types.js';
5
+ export type FeedbackOutcome = {
6
+ message: string | false;
7
+ closeDialog: boolean;
8
+ };
9
+ export type Override = Readonly<{
10
+ enabled?: boolean;
11
+ visible?: boolean;
12
+ }> | undefined;
13
+ /** Contributions that open the shared dialog host. */
14
+ export type OpenableDefinition = Exclude<ResolvedContribution, {
15
+ kind: 'action' | 'native';
16
+ }>;
17
+ export type DialogState = {
18
+ definition: OpenableDefinition;
19
+ input: unknown;
20
+ token: symbol;
21
+ };
22
+ /** Runtime capabilities available to contribution adapters. Registration ownership stays with the runtime. */
23
+ export interface ContributionHost {
24
+ readonly app: FoundationApp;
25
+ readonly actions: ActionList;
26
+ readonly services: Services;
27
+ /** A translator bound to the current locale, with `has` always answering. */
28
+ translator(): Translator;
29
+ title(definition: ResolvedContribution): string;
30
+ description(definition: ResolvedContribution): string | undefined;
31
+ text(key: string | undefined, fallback: string, values?: MessageValues): string;
32
+ feedback<C>(definition: ResolvedContribution, kind: 'success' | 'failure', option: Feedback<C>, context: C): FeedbackOutcome;
33
+ /** Presentation only; a failing notifier never changes the business outcome. */
34
+ notify(message: string | false): void;
35
+ getGroup(entry: string | ActionGroup): ActionGroup;
36
+ override(id: string): Override;
37
+ dialog(): DialogState | null;
38
+ openDialog(definition: OpenableDefinition, input: unknown): void;
39
+ rememberFormFeedback(state: DialogState, outcome: FeedbackOutcome): void;
40
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { ConfigContext } from '../config-service.js';
2
+ import type { Action, ActionDefinition, RegistrationOptions } from '@bitakit/core/actions';
3
+ import type { Contribution, ResolvedContribution } from '../definitions.js';
4
+ import type { ContributionHost } from './host.js';
5
+ export type { ContributionHost, DialogState, FeedbackOutcome, OpenableDefinition, Override, } from './host.js';
6
+ /** A ready-to-register entry: either a class instance (added with bindings) or a plain definition. */
7
+ export type Registration = {
8
+ id: string;
9
+ placement: RegistrationOptions;
10
+ } & ({
11
+ instance: Action<any, any>;
12
+ definition?: undefined;
13
+ } | {
14
+ definition: ActionDefinition;
15
+ instance?: undefined;
16
+ });
17
+ /** The normalized shape every contribution kind reduces to. */
18
+ export type Adapted = {
19
+ /** Final definition after conventions and overrides; the runtime re-translates from it. */
20
+ definition: ResolvedContribution;
21
+ requires: readonly string[];
22
+ /** Observable services whose changes refresh the shared list. */
23
+ watch: readonly string[];
24
+ registrations: readonly Registration[];
25
+ };
26
+ export declare function adaptContribution(contribution: Contribution, host: ContributionHost, config: ConfigContext): Adapted;
@@ -0,0 +1,18 @@
1
+ import { resolveContribution } from '../conventions.js';
2
+ import { adaptCommand } from './command.js';
3
+ import { adaptDialog } from './dialog.js';
4
+ import { adaptForm } from './form.js';
5
+ import { adaptNative } from './native.js';
6
+ export function adaptContribution(contribution, host, config) {
7
+ const resolved = resolveContribution(contribution);
8
+ switch (resolved.kind) {
9
+ case 'native':
10
+ return adaptNative(resolved, host, config);
11
+ case 'action':
12
+ return adaptCommand(resolved, host, config);
13
+ case 'dialog':
14
+ return adaptDialog(resolved, host, config);
15
+ case 'form':
16
+ return adaptForm(resolved, host, config);
17
+ }
18
+ }
@@ -0,0 +1,11 @@
1
+ import type { ConfigContext } from '../config-service.js';
2
+ import type { NativeDefinition } from '../definitions.js';
3
+ import type { ContributionHost } from './host.js';
4
+ import type { Adapted } from './index.js';
5
+ /**
6
+ * Class and function exports: one fresh instance per runtime. Metadata declared on the instance
7
+ * wins; translation, overrides and opt-in feedback are applied to that instance.
8
+ */
9
+ export declare function adaptNative(resolved: NativeDefinition & {
10
+ id: string;
11
+ }, host: ContributionHost, config: ConfigContext): Adapted;