@open-pioneer/runtime 4.4.0-dev.20260121102820 → 4.5.0-dev-roving-menu.20260128080955
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/CHANGELOG.md +12 -4
- package/CustomElement.js +2 -1
- package/CustomElement.js.map +1 -1
- package/_virtual/source-info.js +16 -0
- package/_virtual/source-info.js.map +1 -0
- package/app/AppInstance.js +2 -1
- package/app/AppInstance.js.map +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js +2 -1
- package/builtin-services/ApplicationLifecycleEventService.js.map +1 -1
- package/builtin-services/NumberParserServiceImpl.js +2 -1
- package/builtin-services/NumberParserServiceImpl.js.map +1 -1
- package/i18n/AppIntl.js +2 -1
- package/i18n/AppIntl.js.map +1 -1
- package/i18n/pick.js +2 -1
- package/i18n/pick.js.map +1 -1
- package/package.json +4 -4
- package/service-layer/ServiceLayer.d.ts +1 -1
- package/service-layer/ServiceLayer.js +4 -3
- package/service-layer/ServiceLayer.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# @open-pioneer/runtime
|
|
2
2
|
|
|
3
|
-
## 4.
|
|
3
|
+
## 4.5.0-dev-roving-menu.20260128080955
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @open-pioneer/base-theme@4.5.0-dev-roving-menu.20260128080955
|
|
8
|
+
- @open-pioneer/core@4.5.0-dev-roving-menu.20260128080955
|
|
9
|
+
- @open-pioneer/reactivity@4.5.0-dev-roving-menu.20260128080955
|
|
10
|
+
|
|
11
|
+
## 4.4.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
6
14
|
|
|
@@ -16,9 +24,9 @@
|
|
|
16
24
|
- Updated dependencies [f9aaf46]
|
|
17
25
|
- Updated dependencies [b28d6bc]
|
|
18
26
|
- Updated dependencies [554d58e]
|
|
19
|
-
- @open-pioneer/base-theme@4.4.0
|
|
20
|
-
- @open-pioneer/core@4.4.0
|
|
21
|
-
- @open-pioneer/reactivity@4.4.0
|
|
27
|
+
- @open-pioneer/base-theme@4.4.0
|
|
28
|
+
- @open-pioneer/core@4.4.0
|
|
29
|
+
- @open-pioneer/reactivity@4.4.0
|
|
22
30
|
|
|
23
31
|
## 4.3.0
|
|
24
32
|
|
package/CustomElement.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
+
import { sourceId } from './_virtual/source-info.js';
|
|
2
3
|
import { AppInstance } from './app/AppInstance.js';
|
|
3
4
|
import { ErrorId } from './errors.js';
|
|
4
5
|
|
|
5
|
-
const LOG = createLogger(
|
|
6
|
+
const LOG = createLogger(sourceId);
|
|
6
7
|
function createCustomElement(options) {
|
|
7
8
|
class PioneerApplication extends HTMLElement {
|
|
8
9
|
#shadowRoot;
|
package/CustomElement.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomElement.js","sources":["CustomElement.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ComponentType } from \"react\";\nimport { ApiMethods, type ApiExtension } from \"./api\";\nimport { AppInstance } from \"./app\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata } from \"./metadata\";\n\nconst LOG = createLogger(\"runtime:CustomElement\");\n\n/**\n * Options for the {@link createCustomElement} function.\n */\nexport interface CustomElementOptions {\n /**\n * Rendered UI component.\n */\n component?: ComponentType<Record<string, string>>;\n\n /**\n * Application metadata (packages, services etc.).\n * This is usually autogenerated by importing the virtual `\"open-pioneer:app\"` module.\n */\n appMetadata?: ApplicationMetadata;\n\n /**\n * Application defined configuration.\n *\n * This option can be used to override default properties of the application's packages.\n *\n * All instances of the web component will share this static configuration.\n */\n config?: ApplicationConfig;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n\n /**\n * Advanced configuration that alters the behavior of the custom element.\n */\n advanced?: AdvancedCustomElementOptions;\n\n /**\n * Function to provide additional application defined configuration parameters.\n *\n * Compared to {@link config}, this function receives a context object\n * that allows the developer to provide dynamic properties on a per-application instance basis.\n *\n * Parameters returned by this function take precedence over the ones defined by {@link config}.\n */\n resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;\n}\n\n/**\n * A context object that is passed to the `resolveProperties` function.\n */\nexport interface ConfigContext {\n /**\n * The application's host element.\n */\n hostElement: HTMLElement;\n\n /**\n * Defined when the application forcefully restarts with new options.\n */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\n}\n\n/**\n * Application overrides are defined when the is explicitly being restarted with new options.\n *\n * Options set through overrides cannot be overwritten by the `resolveConfig` hook.\n */\nexport interface ApplicationOverrides {\n /**\n * The new application locale.\n */\n locale?: string;\n}\n\n/**\n * Runtime application configuration.\n */\nexport interface ApplicationConfig {\n /**\n * Set this value to a locale string (e.g. \"en\") to for the application's locale.\n * The default behavior is to choose an appropriate locale for the current user based\n * on the browser's settings.\n *\n * The locale must be supported by the application.\n */\n locale?: string | undefined;\n\n /**\n * Properties specified here will override default properties of the application's packages.\n */\n properties?: ApplicationProperties | undefined;\n}\n\n/**\n * Allows the application to override default properties in all packages.\n *\n * Properties are typed when the package contains type definitions for them.\n */\nexport interface ApplicationProperties {\n /**\n * Key: the name of the package.\n * Value: A record of configuration properties (key/value pairs).\n *\n * Properties will override default property values in the package.\n */\n [packageName: string]: Record<string, unknown>;\n}\n\n/**\n * The interface implemented by web components produced via {@link createCustomElement}.\n */\nexport interface ApplicationElement extends HTMLElement {\n /**\n * Resolves to the element's API when the application has started.\n *\n * The API exposed by an application can be defined by implementing an {@link ApiExtension}.\n * For more details, open the documentation of the `@open-pioneer/integration` package.\n */\n when(): Promise<ApiMethods>;\n}\n\n/**\n * Advanced configuration that alters the behavior of the custom element.\n *\n * See {@link createCustomElement}.\n */\nexport interface AdvancedCustomElementOptions {\n /**\n * Enables or disables the [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot) inside the application's web component.\n *\n * Default: `true`.\n *\n * By default, trails applications use a shadow root to avoid conflicts (e.g. styles) with other parts of the site where the application may be embedded.\n *\n * Applications that use the entire browser viewport may not need this feature, since there may be no \"other\" parts that may conflict with the app.\n * In this case, you can disable the shadow root by setting this property to `false`.\n * In general, UI components used by the app (e.g. from Chakra UI) should work just as well when disabling the shadow root.\n * If you notice any problems, please file an issue.\n *\n * If you are developing UI components that are meant to be used in other applications, you should always use a shadow root to\n * ensure that your components work in that setting.\n */\n enableShadowRoot?: boolean;\n}\n\n/**\n * The class returned by a call to {@link createCustomElement}.\n */\nexport interface ApplicationElementConstructor {\n new (): ApplicationElement;\n}\n\n/**\n * Creates a new custom element class (web component) that can be registered within a DOM.\n *\n * @example\n * ```ts\n * import * as appMetadata from \"open-pioneer:app\";\n *\n * const CustomElementClazz = createCustomElement({\n * component: <div>Hello World!</div>,\n * appMetadata\n * });\n * customElements.define(\"sample-element\", CustomElementClazz);\n * ```\n */\nexport function createCustomElement(options: CustomElementOptions): ApplicationElementConstructor {\n class PioneerApplication extends HTMLElement implements ApplicationElement {\n #shadowRoot: ShadowRoot | undefined;\n #instance: AppInstance | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #deferredRestart: any; // A Timer\n\n static get observedAttributes(): string[] {\n return [];\n }\n\n constructor() {\n super();\n\n const enableShadowRoot = options.advanced?.enableShadowRoot ?? true;\n if (enableShadowRoot) {\n this.#shadowRoot = this.attachShadow({\n mode: \"open\"\n });\n } else {\n LOG.debug(\"Creating component instance without shadow root\");\n }\n\n if (import.meta.env.DEV) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).$inspectElementState = () => this.#instance;\n }\n }\n\n connectedCallback() {\n LOG.debug(\"Launching application\");\n\n if (this.#instance) {\n this.#instance.destroy();\n }\n\n this.#instance = this.#createApplicationInstance();\n this.#instance.start();\n }\n\n disconnectedCallback() {\n LOG.debug(\"Shutting down application\");\n\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#instance?.destroy();\n this.#instance = undefined;\n\n LOG.debug(\"Application destroyed\");\n }\n\n when() {\n if (!this.#instance) {\n return Promise.reject(\n new Error(\n ErrorId.NOT_MOUNTED,\n \"Cannot use the application's API because the HTML element has not yet been mounted into the DOM.\"\n )\n );\n }\n\n return this.#instance.whenAPI();\n }\n\n #triggerReload(overrides?: ApplicationOverrides) {\n // Defer the restart operation a tiny bit so calling code does not get surprised by the application's destruction.\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#deferredRestart = setTimeout(() => {\n if (!this.#instance) {\n // disconnectedCallback was called in the meantime\n return;\n }\n\n LOG.debug(\"Restarting application with new options\", overrides);\n this.#instance.destroy();\n this.#instance = this.#createApplicationInstance(overrides);\n this.#instance.start();\n }, 1);\n }\n\n #createApplicationInstance(overrides?: ApplicationOverrides) {\n return new AppInstance({\n rootNode: this.#shadowRoot ?? document,\n hostElement: this,\n elementOptions: options,\n overrides: overrides,\n restart: this.#triggerReload.bind(this)\n });\n }\n }\n return PioneerApplication;\n}\n"],"names":[],"mappings":";;;;AAUA,MAAM,GAAA,GAAM,aAAa,uBAAuB,CAAA;AA6KzC,SAAS,oBAAoB,OAAA,EAA8D;AAAA,EAC9F,MAAM,2BAA2B,WAAA,CAA0C;AAAA,IACvE,WAAA;AAAA,IACA,SAAA;AAAA;AAAA,IAGA,gBAAA;AAAA;AAAA,IAEA,WAAW,kBAAA,GAA+B;AACtC,MAAA,OAAO,EAAC;AAAA,IACZ;AAAA,IAEA,WAAA,GAAc;AACV,MAAA,KAAA,EAAM;AAEN,MAAA,MAAM,gBAAA,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AQ;AAAA,IAClC;AAAA,IAEA,eAAe,SAAA,EAAkC;AAE7C,MAAA,IAAI,KAAK,gBAAA,EAAkB;AACvB,QAAA,YAAA,CAAa,KAAK,gBAAgB,CAAA;AAAA,MACtC;AACA,MAAA,IAAA,CAAK,gBAAA,GAAmB,WAAW,MAAM;AACrC,QAAA,IAAI,CAAC,KAAK,SAAA,EAAW;AAEjB,UAAA;AAAA,QACJ;AAEA,QAAA,GAAA,CAAI,KAAA,CAAM,2CAA2C,SAAS,CAAA;AAC9D,QAAA,IAAA,CAAK,UAAU,OAAA,EAAQ;AACvB,QAAA,IAAA,CAAK,SAAA,GAAY,IAAA,CAAK,0BAAA,CAA2B,SAAS,CAAA;AAC1D,QAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AAAA,MACzB,GAAG,CAAC,CAAA;AAAA,IACR;AAAA,IAEA,2BAA2B,SAAA,EAAkC;AACzD,MAAA,OAAO,IAAI,WAAA,CAAY;AAAA,QACnB,QAAA,EAAU,KAAK,WAAA,IAAe,QAAA;AAAA,QAC9B,WAAA,EAAa,IAAA;AAAA,QACb,cAAA,EAAgB,OAAA;AAAA,QAChB,SAAA;AAAA,QACA,OAAA,EAAS,IAAA,CAAK,cAAA,CAAe,IAAA,CAAK,IAAI;AAAA,OACzC,CAAA;AAAA,IACL;AAAA;AAEJ,EAAA,OAAO,kBAAA;AACX;;;;"}
|
|
1
|
+
{"version":3,"file":"CustomElement.js","sources":["CustomElement.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ComponentType } from \"react\";\nimport { ApiMethods, type ApiExtension } from \"./api\";\nimport { AppInstance } from \"./app\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata } from \"./metadata\";\n\nconst LOG = createLogger(sourceId);\n\n/**\n * Options for the {@link createCustomElement} function.\n */\nexport interface CustomElementOptions {\n /**\n * Rendered UI component.\n */\n component?: ComponentType<Record<string, string>>;\n\n /**\n * Application metadata (packages, services etc.).\n * This is usually autogenerated by importing the virtual `\"open-pioneer:app\"` module.\n */\n appMetadata?: ApplicationMetadata;\n\n /**\n * Application defined configuration.\n *\n * This option can be used to override default properties of the application's packages.\n *\n * All instances of the web component will share this static configuration.\n */\n config?: ApplicationConfig;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n\n /**\n * Advanced configuration that alters the behavior of the custom element.\n */\n advanced?: AdvancedCustomElementOptions;\n\n /**\n * Function to provide additional application defined configuration parameters.\n *\n * Compared to {@link config}, this function receives a context object\n * that allows the developer to provide dynamic properties on a per-application instance basis.\n *\n * Parameters returned by this function take precedence over the ones defined by {@link config}.\n */\n resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;\n}\n\n/**\n * A context object that is passed to the `resolveProperties` function.\n */\nexport interface ConfigContext {\n /**\n * The application's host element.\n */\n hostElement: HTMLElement;\n\n /**\n * Defined when the application forcefully restarts with new options.\n */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\n}\n\n/**\n * Application overrides are defined when the is explicitly being restarted with new options.\n *\n * Options set through overrides cannot be overwritten by the `resolveConfig` hook.\n */\nexport interface ApplicationOverrides {\n /**\n * The new application locale.\n */\n locale?: string;\n}\n\n/**\n * Runtime application configuration.\n */\nexport interface ApplicationConfig {\n /**\n * Set this value to a locale string (e.g. \"en\") to for the application's locale.\n * The default behavior is to choose an appropriate locale for the current user based\n * on the browser's settings.\n *\n * The locale must be supported by the application.\n */\n locale?: string | undefined;\n\n /**\n * Properties specified here will override default properties of the application's packages.\n */\n properties?: ApplicationProperties | undefined;\n}\n\n/**\n * Allows the application to override default properties in all packages.\n *\n * Properties are typed when the package contains type definitions for them.\n */\nexport interface ApplicationProperties {\n /**\n * Key: the name of the package.\n * Value: A record of configuration properties (key/value pairs).\n *\n * Properties will override default property values in the package.\n */\n [packageName: string]: Record<string, unknown>;\n}\n\n/**\n * The interface implemented by web components produced via {@link createCustomElement}.\n */\nexport interface ApplicationElement extends HTMLElement {\n /**\n * Resolves to the element's API when the application has started.\n *\n * The API exposed by an application can be defined by implementing an {@link ApiExtension}.\n * For more details, open the documentation of the `@open-pioneer/integration` package.\n */\n when(): Promise<ApiMethods>;\n}\n\n/**\n * Advanced configuration that alters the behavior of the custom element.\n *\n * See {@link createCustomElement}.\n */\nexport interface AdvancedCustomElementOptions {\n /**\n * Enables or disables the [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot) inside the application's web component.\n *\n * Default: `true`.\n *\n * By default, trails applications use a shadow root to avoid conflicts (e.g. styles) with other parts of the site where the application may be embedded.\n *\n * Applications that use the entire browser viewport may not need this feature, since there may be no \"other\" parts that may conflict with the app.\n * In this case, you can disable the shadow root by setting this property to `false`.\n * In general, UI components used by the app (e.g. from Chakra UI) should work just as well when disabling the shadow root.\n * If you notice any problems, please file an issue.\n *\n * If you are developing UI components that are meant to be used in other applications, you should always use a shadow root to\n * ensure that your components work in that setting.\n */\n enableShadowRoot?: boolean;\n}\n\n/**\n * The class returned by a call to {@link createCustomElement}.\n */\nexport interface ApplicationElementConstructor {\n new (): ApplicationElement;\n}\n\n/**\n * Creates a new custom element class (web component) that can be registered within a DOM.\n *\n * @example\n * ```ts\n * import * as appMetadata from \"open-pioneer:app\";\n *\n * const CustomElementClazz = createCustomElement({\n * component: <div>Hello World!</div>,\n * appMetadata\n * });\n * customElements.define(\"sample-element\", CustomElementClazz);\n * ```\n */\nexport function createCustomElement(options: CustomElementOptions): ApplicationElementConstructor {\n class PioneerApplication extends HTMLElement implements ApplicationElement {\n #shadowRoot: ShadowRoot | undefined;\n #instance: AppInstance | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #deferredRestart: any; // A Timer\n\n static get observedAttributes(): string[] {\n return [];\n }\n\n constructor() {\n super();\n\n const enableShadowRoot = options.advanced?.enableShadowRoot ?? true;\n if (enableShadowRoot) {\n this.#shadowRoot = this.attachShadow({\n mode: \"open\"\n });\n } else {\n LOG.debug(\"Creating component instance without shadow root\");\n }\n\n if (import.meta.env.DEV) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).$inspectElementState = () => this.#instance;\n }\n }\n\n connectedCallback() {\n LOG.debug(\"Launching application\");\n\n if (this.#instance) {\n this.#instance.destroy();\n }\n\n this.#instance = this.#createApplicationInstance();\n this.#instance.start();\n }\n\n disconnectedCallback() {\n LOG.debug(\"Shutting down application\");\n\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#instance?.destroy();\n this.#instance = undefined;\n\n LOG.debug(\"Application destroyed\");\n }\n\n when() {\n if (!this.#instance) {\n return Promise.reject(\n new Error(\n ErrorId.NOT_MOUNTED,\n \"Cannot use the application's API because the HTML element has not yet been mounted into the DOM.\"\n )\n );\n }\n\n return this.#instance.whenAPI();\n }\n\n #triggerReload(overrides?: ApplicationOverrides) {\n // Defer the restart operation a tiny bit so calling code does not get surprised by the application's destruction.\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#deferredRestart = setTimeout(() => {\n if (!this.#instance) {\n // disconnectedCallback was called in the meantime\n return;\n }\n\n LOG.debug(\"Restarting application with new options\", overrides);\n this.#instance.destroy();\n this.#instance = this.#createApplicationInstance(overrides);\n this.#instance.start();\n }, 1);\n }\n\n #createApplicationInstance(overrides?: ApplicationOverrides) {\n return new AppInstance({\n rootNode: this.#shadowRoot ?? document,\n hostElement: this,\n elementOptions: options,\n overrides: overrides,\n restart: this.#triggerReload.bind(this)\n });\n }\n }\n return PioneerApplication;\n}\n"],"names":[],"mappings":";;;;;AAWA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AA6K1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const sourceId$5 = "@open-pioneer/runtime/app/AppInstance";
|
|
4
|
+
|
|
5
|
+
const sourceId$4 = "@open-pioneer/runtime/i18n/AppIntl";
|
|
6
|
+
|
|
7
|
+
const sourceId$3 = "@open-pioneer/runtime/i18n/pick";
|
|
8
|
+
|
|
9
|
+
const sourceId$2 = "@open-pioneer/runtime/builtin-services/ApplicationLifecycleEventService";
|
|
10
|
+
|
|
11
|
+
const sourceId$1 = "@open-pioneer/runtime/builtin-services/NumberParserServiceImpl";
|
|
12
|
+
|
|
13
|
+
const sourceId = "@open-pioneer/runtime/service-layer/ServiceLayer";
|
|
14
|
+
|
|
15
|
+
export { sourceId$6 as sourceId, sourceId$5 as sourceId$1, sourceId$2, sourceId$1 as sourceId$3, sourceId$4, sourceId$3 as sourceId$5, sourceId as sourceId$6 };
|
|
16
|
+
//# sourceMappingURL=source-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-info.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
package/app/AppInstance.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { reactive, effect } from '@conterra/reactivity-core';
|
|
2
2
|
import { createLogger, Error, createAbortError, destroyResource, createManualPromise, throwAbortError } from '@open-pioneer/core';
|
|
3
|
+
import { sourceId$1 as sourceId } from '../_virtual/source-info.js';
|
|
3
4
|
import { createElement } from 'react';
|
|
4
5
|
import { createBuiltinPackage, RUNTIME_API_SERVICE, RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE, RUNTIME_AUTO_START } from '../builtin-services/index.js';
|
|
5
6
|
import { isShadowRoot, createAppRoot } from '../dom/index.js';
|
|
@@ -14,7 +15,7 @@ import { ServiceLayer } from '../service-layer/ServiceLayer.js';
|
|
|
14
15
|
import { gatherConfig } from './gatherConfig.js';
|
|
15
16
|
import { logError } from './logErrors.js';
|
|
16
17
|
|
|
17
|
-
const LOG = createLogger(
|
|
18
|
+
const LOG = createLogger(sourceId);
|
|
18
19
|
class AppInstance {
|
|
19
20
|
options;
|
|
20
21
|
// Public API
|
package/app/AppInstance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppInstance.js","sources":["AppInstance.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { effect, reactive, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventService } from \"../builtin-services/ApplicationLifecycleEventService\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, I18nConfig, initI18n } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(\"runtime:AppInstance\");\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\n\n /** Trails options for the application. */\n elementOptions: CustomElementOptions;\n\n /** These have higher priority than the options in `elementOptions`. */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * A callback to restart the application with new options.\n * Currently only used for reloading with a certain locale.\n */\n restart: (overrides?: ApplicationOverrides) => void;\n}\n\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n private options: AppOptions;\n\n // Public API\n private apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n private api: ApiMethods | undefined; // Present once started\n\n private state: AppState = \"not-started\";\n private rootNode: RootNode;\n private container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n private appRoot: HTMLDivElement | undefined; // .pioneer-root\n private config: ApplicationConfig | undefined;\n private serviceLayer: ServiceLayer | undefined;\n private lifecycleEvents: ApplicationLifecycleEventService | undefined;\n private reactIntegration: ReactIntegration | undefined;\n\n private stylesWatch: Resource | undefined;\n\n constructor(options: AppOptions) {\n this.options = options;\n this.container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;\n this.rootNode = options.rootNode;\n }\n\n start() {\n if (this.state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.state}'`);\n }\n\n this.state = \"starting\";\n this.startImpl().catch((e) => {\n if (this.state === \"destroyed\") return;\n\n logError(e);\n this.reset();\n this.state = \"error\";\n this.showErrorScreen(e);\n });\n }\n\n destroy() {\n if (this.state === \"destroyed\") {\n return;\n }\n\n // Only call event listener when 'started' was also signalled.\n if (this.state === \"started\") {\n try {\n this.triggerApplicationLifecycleEvent(\"before-stop\");\n } catch (e) {\n void e; // Ignored\n }\n }\n this.state = \"destroyed\";\n this.reset();\n }\n\n private reset() {\n this.apiPromise?.reject(createAbortError());\n this.reactIntegration = destroyResource(this.reactIntegration);\n this.container.replaceChildren();\n this.appRoot = undefined;\n this.lifecycleEvents = undefined;\n this.serviceLayer = destroyResource(this.serviceLayer);\n this.stylesWatch = destroyResource(this.stylesWatch);\n }\n\n whenAPI(): Promise<ApiMethods> {\n if (this.api) {\n return Promise.resolve(this.api);\n }\n\n const apiPromise = (this.apiPromise ??= createManualPromise());\n return apiPromise.promise;\n }\n\n private async startImpl() {\n const { hostElement, elementOptions, overrides } = this.options;\n const root = this.rootNode;\n\n // Resolve custom application config\n const config = (this.config = await gatherConfig(hostElement, elementOptions, overrides));\n this.checkAbort();\n LOG.debug(\"Application config is\", config);\n\n // Decide on locale and load i18n messages (if any).\n const i18n = await initI18n(elementOptions.appMetadata, config.locale);\n this.checkAbort();\n\n // Setup application root node in the shadow dom\n const appRoot = (this.appRoot = createAppRoot(i18n.locale));\n this.container.appendChild(appRoot);\n\n const styles = this.initStylesSignal();\n\n // Launch the service layer\n const { serviceLayer, packages } = this.initServiceLayer({\n container: appRoot,\n properties: config.properties,\n i18n\n });\n this.lifecycleEvents = getInternalService<ApplicationLifecycleEventService>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n\n await this.initAPI(serviceLayer);\n this.checkAbort();\n\n // Launch react\n this.reactIntegration = ReactIntegration.createForApp({\n rootNode: root,\n hostNode: hostElement,\n appRoot: appRoot,\n serviceLayer,\n packages,\n locale: i18n.locale,\n config: elementOptions.chakraSystemConfig,\n styles\n });\n const component = this.options.elementOptions.component ?? EmptyComponent;\n this.reactIntegration.render(createElement(component));\n this.state = \"started\";\n\n this.triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n /**\n * Returns a signal that contains the application's styles.\n * During development, the signal is updated when the user edits .css files.\n * In production, the signal is static.\n */\n private initStylesSignal(): ReadonlyReactive<string> {\n const stylesBox = this.options.elementOptions.appMetadata?.styles;\n if (!stylesBox) {\n return reactive(\"\");\n }\n\n const signal = reactive(stylesBox.value);\n if (import.meta.hot) {\n this.stylesWatch = effect(\n () => {\n signal.value = stylesBox.value;\n LOG.debug(\"Application styles changed\");\n },\n { dispatch: \"sync\" }\n );\n }\n return signal;\n }\n\n private initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n }) {\n const { hostElement, rootNode: shadowRoot, elementOptions, restart } = this.options;\n const { container, properties, i18n } = config;\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n rootNode: shadowRoot,\n container: container,\n locale: i18n.locale,\n supportedLocales: i18n.supportedMessageLocales,\n changeLocale(locale) {\n const supported = i18n.supportedMessageLocales;\n if (locale != null && !i18n.supportsLocale(locale)) {\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${locale}' (supported locales: ${supported.join(\n \", \"\n )}).`\n );\n }\n restart({ locale });\n }\n });\n const { serviceLayer, packages } = createServiceLayer({\n packageMetadata,\n builtinPackage,\n properties,\n i18n\n });\n this.serviceLayer = serviceLayer;\n\n if (LOG.isDebug()) {\n LOG.debug(\"Launching service layer with packages\", Object.fromEntries(packages));\n }\n serviceLayer.start();\n return { serviceLayer, packages };\n }\n\n private async initAPI(serviceLayer: ServiceLayer) {\n const apiService = getInternalService<ApiService>(serviceLayer, RUNTIME_API_SERVICE);\n try {\n const api = (this.api = await apiService.getApi());\n LOG.debug(\"Application API initialized to\", api);\n this.apiPromise?.resolve(api);\n } catch (e) {\n throw new Error(ErrorId.INTERNAL, \"Failed to gather the application's API methods.\", {\n cause: e\n });\n }\n }\n\n private triggerApplicationLifecycleEvent(event: \"after-start\" | \"before-stop\") {\n this.lifecycleEvents?.emitLifecycleEvent(event);\n }\n\n private checkAbort() {\n if (this.state === \"destroyed\") {\n throwAbortError();\n }\n }\n\n private showErrorScreen(error: globalThis.Error) {\n const userLocales = getBrowserLocales();\n const i18nConfig = new I18nConfig(Object.keys(MESSAGES_BY_LOCALE));\n const { locale, messageLocale } = i18nConfig.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale, messages);\n\n const appRoot = (this.appRoot = createAppRoot(locale));\n appRoot.classList.add(\"pioneer-root-error-screen\");\n this.container.appendChild(appRoot);\n\n const styles = this.initStylesSignal();\n\n this.reactIntegration = ReactIntegration.createForErrorScreen({\n rootNode: this.rootNode,\n hostNode: this.options.hostElement,\n appRoot: appRoot,\n locale: locale,\n config: this.options.elementOptions.chakraSystemConfig,\n styles\n });\n this.reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppIntl;\n}) {\n const { packageMetadata, properties, builtinPackage, i18n } = config;\n\n let packages: PackageRepr[];\n try {\n packages = createPackages(packageMetadata ?? {}, i18n, properties);\n } catch (e) {\n throw new Error(ErrorId.INVALID_METADATA, \"Failed to parse package metadata.\", {\n cause: e\n });\n }\n\n // Add builtin services defined within this package.\n {\n const index = packages.findIndex((pkg) => pkg.name === builtinPackage.name);\n if (index >= 0) {\n packages.splice(index, 1);\n }\n packages.push(builtinPackage);\n }\n\n // Automatically required references (-> forces services to start)\n const forcedReferences: ReferenceSpec[] = [\n {\n interfaceName: RUNTIME_API_SERVICE\n },\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n },\n {\n interfaceName: RUNTIME_AUTO_START,\n all: true\n }\n ];\n const serviceLayer = new ServiceLayer(packages, forcedReferences);\n return {\n packages: new Map(packages.map((pkg) => [pkg.name, pkg])),\n serviceLayer: serviceLayer\n };\n}\n\nfunction getInternalService<T = unknown>(serviceLayer: ServiceLayer, interfaceName: string) {\n const result = serviceLayer.getService(\n \"@open-pioneer/runtime\",\n {\n interfaceName\n },\n { ignoreDeclarationCheck: true }\n );\n if (result.type !== \"found\") {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find instance of '${interfaceName}' (result type '${result.type}').` +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C,GAAA,CAAI,IAAA,EAAM,GAAG,CAAC,CAAC,CAAA;AAAA,IACxD;AAAA,GACJ;AACJ;AAEA,SAAS,kBAAA,CAAgC,cAA4B,aAAA,EAAuB;AACxF,EAAA,MAAM,SAAS,YAAA,CAAa,UAAA;AAAA,IACxB,uBAAA;AAAA,IACA;AAAA,MACI;AAAA,KACJ;AAAA,IACA,EAAE,wBAAwB,IAAA;AAAK,GACnC;AACA,EAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,aAAa,CAAA,gBAAA,EAAmB,MAAA,CAAO,IAAI,CAAA,gEAAA;AAAA,KAE9E;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA,CAAO,MAAM,kBAAA,EAAmB;AAC3C;;;;"}
|
|
1
|
+
{"version":3,"file":"AppInstance.js","sources":["AppInstance.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { effect, reactive, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventService } from \"../builtin-services/ApplicationLifecycleEventService\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, I18nConfig, initI18n } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\n\n /** Trails options for the application. */\n elementOptions: CustomElementOptions;\n\n /** These have higher priority than the options in `elementOptions`. */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * A callback to restart the application with new options.\n * Currently only used for reloading with a certain locale.\n */\n restart: (overrides?: ApplicationOverrides) => void;\n}\n\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n private options: AppOptions;\n\n // Public API\n private apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n private api: ApiMethods | undefined; // Present once started\n\n private state: AppState = \"not-started\";\n private rootNode: RootNode;\n private container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n private appRoot: HTMLDivElement | undefined; // .pioneer-root\n private config: ApplicationConfig | undefined;\n private serviceLayer: ServiceLayer | undefined;\n private lifecycleEvents: ApplicationLifecycleEventService | undefined;\n private reactIntegration: ReactIntegration | undefined;\n\n private stylesWatch: Resource | undefined;\n\n constructor(options: AppOptions) {\n this.options = options;\n this.container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;\n this.rootNode = options.rootNode;\n }\n\n start() {\n if (this.state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.state}'`);\n }\n\n this.state = \"starting\";\n this.startImpl().catch((e) => {\n if (this.state === \"destroyed\") return;\n\n logError(e);\n this.reset();\n this.state = \"error\";\n this.showErrorScreen(e);\n });\n }\n\n destroy() {\n if (this.state === \"destroyed\") {\n return;\n }\n\n // Only call event listener when 'started' was also signalled.\n if (this.state === \"started\") {\n try {\n this.triggerApplicationLifecycleEvent(\"before-stop\");\n } catch (e) {\n void e; // Ignored\n }\n }\n this.state = \"destroyed\";\n this.reset();\n }\n\n private reset() {\n this.apiPromise?.reject(createAbortError());\n this.reactIntegration = destroyResource(this.reactIntegration);\n this.container.replaceChildren();\n this.appRoot = undefined;\n this.lifecycleEvents = undefined;\n this.serviceLayer = destroyResource(this.serviceLayer);\n this.stylesWatch = destroyResource(this.stylesWatch);\n }\n\n whenAPI(): Promise<ApiMethods> {\n if (this.api) {\n return Promise.resolve(this.api);\n }\n\n const apiPromise = (this.apiPromise ??= createManualPromise());\n return apiPromise.promise;\n }\n\n private async startImpl() {\n const { hostElement, elementOptions, overrides } = this.options;\n const root = this.rootNode;\n\n // Resolve custom application config\n const config = (this.config = await gatherConfig(hostElement, elementOptions, overrides));\n this.checkAbort();\n LOG.debug(\"Application config is\", config);\n\n // Decide on locale and load i18n messages (if any).\n const i18n = await initI18n(elementOptions.appMetadata, config.locale);\n this.checkAbort();\n\n // Setup application root node in the shadow dom\n const appRoot = (this.appRoot = createAppRoot(i18n.locale));\n this.container.appendChild(appRoot);\n\n const styles = this.initStylesSignal();\n\n // Launch the service layer\n const { serviceLayer, packages } = this.initServiceLayer({\n container: appRoot,\n properties: config.properties,\n i18n\n });\n this.lifecycleEvents = getInternalService<ApplicationLifecycleEventService>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n\n await this.initAPI(serviceLayer);\n this.checkAbort();\n\n // Launch react\n this.reactIntegration = ReactIntegration.createForApp({\n rootNode: root,\n hostNode: hostElement,\n appRoot: appRoot,\n serviceLayer,\n packages,\n locale: i18n.locale,\n config: elementOptions.chakraSystemConfig,\n styles\n });\n const component = this.options.elementOptions.component ?? EmptyComponent;\n this.reactIntegration.render(createElement(component));\n this.state = \"started\";\n\n this.triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n /**\n * Returns a signal that contains the application's styles.\n * During development, the signal is updated when the user edits .css files.\n * In production, the signal is static.\n */\n private initStylesSignal(): ReadonlyReactive<string> {\n const stylesBox = this.options.elementOptions.appMetadata?.styles;\n if (!stylesBox) {\n return reactive(\"\");\n }\n\n const signal = reactive(stylesBox.value);\n if (import.meta.hot) {\n this.stylesWatch = effect(\n () => {\n signal.value = stylesBox.value;\n LOG.debug(\"Application styles changed\");\n },\n { dispatch: \"sync\" }\n );\n }\n return signal;\n }\n\n private initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n }) {\n const { hostElement, rootNode: shadowRoot, elementOptions, restart } = this.options;\n const { container, properties, i18n } = config;\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n rootNode: shadowRoot,\n container: container,\n locale: i18n.locale,\n supportedLocales: i18n.supportedMessageLocales,\n changeLocale(locale) {\n const supported = i18n.supportedMessageLocales;\n if (locale != null && !i18n.supportsLocale(locale)) {\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${locale}' (supported locales: ${supported.join(\n \", \"\n )}).`\n );\n }\n restart({ locale });\n }\n });\n const { serviceLayer, packages } = createServiceLayer({\n packageMetadata,\n builtinPackage,\n properties,\n i18n\n });\n this.serviceLayer = serviceLayer;\n\n if (LOG.isDebug()) {\n LOG.debug(\"Launching service layer with packages\", Object.fromEntries(packages));\n }\n serviceLayer.start();\n return { serviceLayer, packages };\n }\n\n private async initAPI(serviceLayer: ServiceLayer) {\n const apiService = getInternalService<ApiService>(serviceLayer, RUNTIME_API_SERVICE);\n try {\n const api = (this.api = await apiService.getApi());\n LOG.debug(\"Application API initialized to\", api);\n this.apiPromise?.resolve(api);\n } catch (e) {\n throw new Error(ErrorId.INTERNAL, \"Failed to gather the application's API methods.\", {\n cause: e\n });\n }\n }\n\n private triggerApplicationLifecycleEvent(event: \"after-start\" | \"before-stop\") {\n this.lifecycleEvents?.emitLifecycleEvent(event);\n }\n\n private checkAbort() {\n if (this.state === \"destroyed\") {\n throwAbortError();\n }\n }\n\n private showErrorScreen(error: globalThis.Error) {\n const userLocales = getBrowserLocales();\n const i18nConfig = new I18nConfig(Object.keys(MESSAGES_BY_LOCALE));\n const { locale, messageLocale } = i18nConfig.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale, messages);\n\n const appRoot = (this.appRoot = createAppRoot(locale));\n appRoot.classList.add(\"pioneer-root-error-screen\");\n this.container.appendChild(appRoot);\n\n const styles = this.initStylesSignal();\n\n this.reactIntegration = ReactIntegration.createForErrorScreen({\n rootNode: this.rootNode,\n hostNode: this.options.hostElement,\n appRoot: appRoot,\n locale: locale,\n config: this.options.elementOptions.chakraSystemConfig,\n styles\n });\n this.reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppIntl;\n}) {\n const { packageMetadata, properties, builtinPackage, i18n } = config;\n\n let packages: PackageRepr[];\n try {\n packages = createPackages(packageMetadata ?? {}, i18n, properties);\n } catch (e) {\n throw new Error(ErrorId.INVALID_METADATA, \"Failed to parse package metadata.\", {\n cause: e\n });\n }\n\n // Add builtin services defined within this package.\n {\n const index = packages.findIndex((pkg) => pkg.name === builtinPackage.name);\n if (index >= 0) {\n packages.splice(index, 1);\n }\n packages.push(builtinPackage);\n }\n\n // Automatically required references (-> forces services to start)\n const forcedReferences: ReferenceSpec[] = [\n {\n interfaceName: RUNTIME_API_SERVICE\n },\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n },\n {\n interfaceName: RUNTIME_AUTO_START,\n all: true\n }\n ];\n const serviceLayer = new ServiceLayer(packages, forcedReferences);\n return {\n packages: new Map(packages.map((pkg) => [pkg.name, pkg])),\n serviceLayer: serviceLayer\n };\n}\n\nfunction getInternalService<T = unknown>(serviceLayer: ServiceLayer, interfaceName: string) {\n const result = serviceLayer.getService(\n \"@open-pioneer/runtime\",\n {\n interfaceName\n },\n { ignoreDeclarationCheck: true }\n );\n if (result.type !== \"found\") {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find instance of '${interfaceName}' (result type '${result.type}').` +\n ` This is a builtin service that must be present exactly once.`\n );\n }\n\n return result.value.getInstanceOrThrow() as T;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAyCA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAwB1B,MAAM,WAAA,CAAY;AAAA,EACb,OAAA;AAAA;AAAA,EAGA,UAAA;AAAA;AAAA,EACA,GAAA;AAAA;AAAA,EAEA,KAAA,GAAkB,aAAA;AAAA,EAClB,QAAA;AAAA,EACA,SAAA;AAAA;AAAA,EACA,OAAA;AAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,eAAA;AAAA,EACA,gBAAA;AAAA,EAEA,WAAA;AAAA,EAER,YAAY,OAAA,EAAqB;AAC7B,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,YAAY,YAAA,CAAa,OAAA,CAAQ,QAAQ,CAAA,GAAI,OAAA,CAAQ,WAAW,OAAA,CAAQ,WAAA;AAC7E,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AAAA,EAC5B;AAAA,EAEA,KAAA,GAAQ;AACJ,IAAA,IAAI,IAAA,CAAK,UAAU,aAAA,EAAe;AAC9B,MAAA,MAAM,IAAI,K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C,CAAA;AAAA,IAC5B;AACA,IAAA,QAAA,CAAS,KAAK,cAAc,CAAA;AAAA,EAChC;AAGA,EAAA,MAAM,gBAAA,GAAoC;AAAA,IACtC;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe,kBAAA;AAAA,MACf,GAAA,EAAK;AAAA;AACT,GACJ;AACA,EAAA,MAAM,YAAA,GAAe,IAAI,YAAA,CAAa,QAAA,EAAU,gBAAgB,CAAA;AAChE,EAAA,OAAO;AAAA,IACH,QAAA,EAAU,IAAI,GAAA,CAAI,QAAA,CAAS,GAAA,CAAI,CAAC,GAAA,KAAQ,CAAC,GAAA,CAAI,IAAA,EAAM,GAAG,CAAC,CAAC,CAAA;AAAA,IACxD;AAAA,GACJ;AACJ;AAEA,SAAS,kBAAA,CAAgC,cAA4B,aAAA,EAAuB;AACxF,EAAA,MAAM,SAAS,YAAA,CAAa,UAAA;AAAA,IACxB,uBAAA;AAAA,IACA;AAAA,MACI;AAAA,KACJ;AAAA,IACA,EAAE,wBAAwB,IAAA;AAAK,GACnC;AACA,EAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,aAAa,CAAA,gBAAA,EAAmB,MAAA,CAAO,IAAI,CAAA,gEAAA;AAAA,KAE9E;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA,CAAO,MAAM,kBAAA,EAAmB;AAC3C;;;;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
+
import { sourceId$2 as sourceId } from '../_virtual/source-info.js';
|
|
2
3
|
import { ErrorId } from '../errors.js';
|
|
3
4
|
|
|
4
|
-
const LOG = createLogger(
|
|
5
|
+
const LOG = createLogger(sourceId);
|
|
5
6
|
class ApplicationLifecycleEventService {
|
|
6
7
|
#listeners;
|
|
7
8
|
constructor(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApplicationLifecycleEventService.js","sources":["ApplicationLifecycleEventService.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger } from \"@open-pioneer/core\";\nimport {
|
|
1
|
+
{"version":3,"file":"ApplicationLifecycleEventService.js","sources":["ApplicationLifecycleEventService.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ServiceOptions } from \"../Service\";\nimport { ApplicationLifecycleListener } from \"../api\";\nimport { ErrorId } from \"../errors\";\n\nconst LOG = createLogger(sourceId);\n\ninterface References {\n listeners: ApplicationLifecycleListener[];\n}\n\nexport class ApplicationLifecycleEventService {\n #listeners: [serviceId: string, listener: ApplicationLifecycleListener][];\n\n constructor(options: ServiceOptions<References>) {\n const listeners = options.references.listeners;\n const listenersMeta = options.referencesMeta.listeners;\n this.#listeners = listeners.map((listener, index) => [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n listenersMeta[index]!.serviceId,\n listener\n ]);\n }\n\n /** @internal */\n emitLifecycleEvent(event: \"after-start\" | \"before-stop\"): void {\n const methodName = (() => {\n switch (event) {\n case \"after-start\":\n return \"afterApplicationStart\";\n case \"before-stop\":\n return \"beforeApplicationStop\";\n default:\n throw new Error(ErrorId.INTERNAL, `Invalid event '${event}'`);\n }\n })();\n for (const [serviceId, listener] of this.#listeners) {\n try {\n listener[methodName]?.();\n } catch (e) {\n LOG.error(`Unexpected error from application lifecycle listener ${serviceId}`, e);\n }\n }\n }\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAM1B,MAAM,gCAAA,CAAiC;AAAA,EAC1C,UAAA;AAAA,EAEA,YAAY,OAAA,EAAqC;AAC7C,IAAA,MAAM,SAAA,GAAY,QAAQ,UAAA,CAAW,SAAA;AACrC,IAAA,MAAM,aAAA,GAAgB,QAAQ,cAAA,CAAe,SAAA;AAC7C,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA,CAAU,GAAA,CAAI,CAAC,UAAU,KAAA,KAAU;AAAA;AAAA,MAEjD,aAAA,CAAc,KAAK,CAAA,CAAG,SAAA;AAAA,MACtB;AAAA,KACH,CAAA;AAAA,EACL;AAAA;AAAA,EAGA,mBAAmB,KAAA,EAA4C;AAC3D,IAAA,MAAM,cAAc,MAAM;AACtB,MAAA,QAAQ,KAAA;AAAO,QACX,KAAK,aAAA;AACD,UAAA,OAAO,uBAAA;AAAA,QACX,KAAK,aAAA;AACD,UAAA,OAAO,uBAAA;AAAA,QACX;AACI,UAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,EAAU,CAAA,eAAA,EAAkB,KAAK,CAAA,CAAA,CAAG,CAAA;AAAA;AACpE,IACJ,CAAA,GAAG;AACH,IAAA,KAAA,MAAW,CAAC,SAAA,EAAW,QAAQ,CAAA,IAAK,KAAK,UAAA,EAAY;AACjD,MAAA,IAAI;AACA,QAAA,QAAA,CAAS,UAAU,CAAA,IAAI;AAAA,MAC3B,SAAS,CAAA,EAAG;AACR,QAAA,GAAA,CAAI,KAAA,CAAM,CAAA,qDAAA,EAAwD,SAAS,CAAA,CAAA,EAAI,CAAC,CAAA;AAAA,MACpF;AAAA,IACJ;AAAA,EACJ;AACJ;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createLogger, NumberParser } from '@open-pioneer/core';
|
|
2
|
+
import { sourceId$3 as sourceId } from '../_virtual/source-info.js';
|
|
2
3
|
|
|
3
|
-
const LOG = createLogger(
|
|
4
|
+
const LOG = createLogger(sourceId);
|
|
4
5
|
class NumberParserServiceImpl {
|
|
5
6
|
numberParser;
|
|
6
7
|
constructor(serviceOptions, locale) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberParserServiceImpl.js","sources":["NumberParserServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"NumberParserServiceImpl.js","sources":["NumberParserServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, NumberParser } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { NumberParserService } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\nexport class NumberParserServiceImpl implements NumberParserService {\n private numberParser: NumberParser;\n\n constructor(serviceOptions: ServiceOptions, locale: string) {\n try {\n this.numberParser = new NumberParser(locale);\n } catch (e) {\n LOG.warn(\n \"Failed to create NumberParserImpl with locale. Retrying with default 'en-US' locale.\",\n e\n );\n this.numberParser = new NumberParser(\"en-US\");\n }\n }\n\n parseNumber(numberString: string): number {\n return this.numberParser.parse(numberString);\n }\n}\n"],"names":[],"mappings":";;;AAOA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAE1B,MAAM,uBAAA,CAAuD;AAAA,EACxD,YAAA;AAAA,EAER,WAAA,CAAY,gBAAgC,MAAA,EAAgB;AACxD,IAAA,IAAI;AACA,MAAA,IAAA,CAAK,YAAA,GAAe,IAAI,YAAA,CAAa,MAAM,CAAA;AAAA,IAC/C,SAAS,CAAA,EAAG;AACR,MAAA,GAAA,CAAI,IAAA;AAAA,QACA,sFAAA;AAAA,QACA;AAAA,OACJ;AACA,MAAA,IAAA,CAAK,YAAA,GAAe,IAAI,YAAA,CAAa,OAAO,CAAA;AAAA,IAChD;AAAA,EACJ;AAAA,EAEA,YAAY,YAAA,EAA8B;AACtC,IAAA,OAAO,IAAA,CAAK,YAAA,CAAa,KAAA,CAAM,YAAY,CAAA;AAAA,EAC/C;AACJ;;;;"}
|
package/i18n/AppIntl.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
+
import { sourceId$4 as sourceId } from '../_virtual/source-info.js';
|
|
2
3
|
import { ErrorId } from '../errors.js';
|
|
3
4
|
import { createPackageIntl } from './PackageIntl.js';
|
|
4
5
|
import { getBrowserLocales, I18nConfig } from './pick.js';
|
|
5
6
|
|
|
6
|
-
const LOG = createLogger(
|
|
7
|
+
const LOG = createLogger(sourceId);
|
|
7
8
|
async function initI18n(appMetadata, forcedLocale) {
|
|
8
9
|
const messageLocales = appMetadata?.locales ?? [];
|
|
9
10
|
const userLocales = getBrowserLocales();
|
package/i18n/AppIntl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppIntl.js","sources":["AppIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { ApplicationMetadata } from \"../metadata\";\nimport { createPackageIntl, PackageIntl } from \"./PackageIntl\";\nimport { getBrowserLocales, I18nConfig } from \"./pick\";\nconst LOG = createLogger(
|
|
1
|
+
{"version":3,"file":"AppIntl.js","sources":["AppIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ErrorId } from \"../errors\";\nimport { ApplicationMetadata } from \"../metadata\";\nimport { createPackageIntl, PackageIntl } from \"./PackageIntl\";\nimport { getBrowserLocales, I18nConfig } from \"./pick\";\nconst LOG = createLogger(sourceId);\n\n/**\n * Represents i18n info for the entire application.\n * Currently not exposed to user code.\n */\nexport interface AppIntl {\n /** Chosen locale */\n readonly locale: string;\n\n /** Supported locales from app metadata. */\n readonly supportedMessageLocales: string[];\n\n /** True if the locale can be used in this application (i.e. if there are any messages). */\n supportsLocale(locale: string): boolean;\n\n /** Given the package name, constructs a package i18n instance. */\n createPackageI18n(packageName: string): PackageIntl;\n}\n\n/**\n * Initializes the application's locale and fetches the appropriate i18n messages.\n */\nexport async function initI18n(\n appMetadata: ApplicationMetadata | undefined,\n forcedLocale: string | undefined\n): Promise<AppIntl> {\n const messageLocales = appMetadata?.locales ?? [];\n const userLocales = getBrowserLocales();\n if (LOG.isDebug()) {\n LOG.debug(\n `Attempting to pick locale for user (locales: ${userLocales.join(\n \", \"\n )}) from app (supported locales: ${messageLocales.join(\n \", \"\n )}) [forcedLocale=${forcedLocale}].`\n );\n }\n\n const i18nConfig = new I18nConfig(messageLocales);\n const { locale, messageLocale } = i18nConfig.pickSupportedLocale(forcedLocale, userLocales);\n\n if (LOG.isDebug()) {\n LOG.debug(`Using locale '${locale}' with messages from locale '${messageLocale}'.`);\n }\n\n let messages: Record<string, Record<string, string>>;\n if (messageLocales.includes(messageLocale)) {\n try {\n messages = (await appMetadata?.loadMessages?.(messageLocale)) ?? {};\n } catch (e) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to load messages for locale '${messageLocale}'.`,\n {\n cause: e\n }\n );\n }\n }\n return {\n locale,\n supportedMessageLocales: messageLocales,\n supportsLocale(locale) {\n return i18nConfig.supportsLocale(locale);\n },\n createPackageI18n(packageName) {\n const packageMessage = messages?.[packageName] ?? {};\n return createPackageIntl(locale, packageMessage);\n }\n };\n}\n"],"names":["locale"],"mappings":";;;;;;AAQA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAuBjC,eAAsB,QAAA,CAClB,aACA,YAAA,EACgB;AAChB,E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3B,MAAA,MAAM,cAAA,GAAiB,QAAA,GAAW,WAAW,CAAA,IAAK,EAAC;AACnD,MAAA,OAAO,iBAAA,CAAkB,QAAQ,cAAc,CAAA;AAAA,IACnD;AAAA,GACJ;AACJ;;;;"}
|
package/i18n/pick.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
+
import { sourceId$5 as sourceId } from '../_virtual/source-info.js';
|
|
2
3
|
import { ErrorId } from '../errors.js';
|
|
3
4
|
|
|
4
|
-
const LOG = createLogger(
|
|
5
|
+
const LOG = createLogger(sourceId);
|
|
5
6
|
class I18nConfig {
|
|
6
7
|
appLocales;
|
|
7
8
|
/**
|
package/i18n/pick.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick.js","sources":["pick.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nconst LOG = createLogger(
|
|
1
|
+
{"version":3,"file":"pick.js","sources":["pick.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ErrorId } from \"../errors\";\nconst LOG = createLogger(sourceId);\n\nexport interface LocalePickResult {\n /**\n * The actual locale (e.g. en-US) for number and date formatting etc.\n */\n locale: string;\n\n /**\n * The locale identifier to load messages for. E.g. \"en\".\n */\n messageLocale: string;\n}\n\n/**\n * Picks a locale for the app.\n */\nexport class I18nConfig {\n private appLocales: string[];\n\n /**\n * @param appLocales Locales the app has i18n messages for (e.g. \"en\", \"de\")\n */\n constructor(appLocales: string[]) {\n this.appLocales = appLocales;\n }\n\n /**\n * @param forcedLocale Optional forced locale (must be satisfied)\n * @param userLocales Locales requested by the user's browser\n */\n pickSupportedLocale(forcedLocale: string | undefined, userLocales: string[]): LocalePickResult {\n const { appLocales } = this;\n // Attempt to satisfy forced locale\n if (forcedLocale) {\n const result = this.pickImpl([forcedLocale]);\n if (!result) {\n const localesList = appLocales.join(\", \");\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Locale '${forcedLocale}' cannot be forced because it is not supported by the application.` +\n ` Supported locales are ${localesList}.`\n );\n }\n if (result.locale !== result.messageLocale) {\n LOG.warn(\n `Non-exact match for forced locale '${forcedLocale}': using messages from '${result.messageLocale}'.`\n );\n }\n return result;\n }\n\n // Match preferred locale\n const supportedLocale = this.pickImpl(userLocales);\n if (supportedLocale) {\n return supportedLocale;\n }\n\n // Fallback: Most preferred locale (for dates etc.), but some of our messages\n return {\n locale: userLocales[0] ?? \"en\",\n messageLocale: appLocales[0] ?? \"en\"\n };\n }\n\n supportsLocale(locale: string): boolean {\n return this.pickImpl([locale]) != null;\n }\n\n private pickImpl(requestedLocales: string[]) {\n const appLocales = this.appLocales;\n for (const requestedLocale of requestedLocales) {\n // try exact match\n if (appLocales.includes(requestedLocale)) {\n return { messageLocale: requestedLocale, locale: requestedLocale };\n }\n\n // try plain language tag (e.g. \"en\") as fallback\n const plainLanguage = requestedLocale.match(/^([a-z]+)/i)?.[1];\n if (plainLanguage && appLocales.includes(plainLanguage)) {\n return { messageLocale: plainLanguage, locale: requestedLocale };\n }\n }\n return undefined;\n }\n}\n\n/**\n * Returns locales supported by the browser, in order of preference (preferred first).\n *\n * See also https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages\n */\nexport function getBrowserLocales(): string[] {\n if (window.navigator.languages && window.navigator.languages.length) {\n return Array.from(window.navigator.languages);\n }\n return [window.navigator.language];\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAiB1B,MAAM,UAAA,CAAW;AAAA,EACZ,UAAA;AAAA;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tC;AAAA,EAEQ,SAAS,gBAAA,EAA4B;AACzC,IAAA,MAAM,aAAa,IAAA,CAAK,UAAA;AACxB,IAAA,KAAA,MAAW,mBAAmB,gBAAA,EAAkB;AAE5C,MAAA,IAAI,UAAA,CAAW,QAAA,CAAS,eAAe,CAAA,EAAG;AACtC,QAAA,OAAO,EAAE,aAAA,EAAe,eAAA,EAAiB,MAAA,EAAQ,eAAA,EAAgB;AAAA,MACrE;AAGA,MAAA,MAAM,aAAA,GAAgB,eAAA,CAAgB,KAAA,CAAM,YAAY,IAAI,CAAC,CAAA;AAC7D,MAAA,IAAI,aAAA,IAAiB,UAAA,CAAW,QAAA,CAAS,aAAa,CAAA,EAAG;AACrD,QAAA,OAAO,EAAE,aAAA,EAAe,aAAA,EAAe,MAAA,EAAQ,eAAA,EAAgB;AAAA,MACnE;AAAA,IACJ;AACA,IAAA,OAAO,MAAA;AAAA,EACX;AACJ;AAOO,SAAS,iBAAA,GAA8B;AAC1C,EAAA,IAAI,OAAO,SAAA,CAAU,SAAA,IAAa,MAAA,CAAO,SAAA,CAAU,UAAU,MAAA,EAAQ;AACjE,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,SAAA,CAAU,SAAS,CAAA;AAAA,EAChD;AACA,EAAA,OAAO,CAAC,MAAA,CAAO,SAAA,CAAU,QAAQ,CAAA;AACrC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/runtime",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.5.0-dev-roving-menu.20260128080955",
|
|
5
5
|
"description": "Implements the runtime environment for Open Pioneer Trails apps.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"@emotion/react": "^11.14.0",
|
|
22
22
|
"react": "^19.2.3",
|
|
23
23
|
"react-dom": "^19.2.3",
|
|
24
|
-
"@open-pioneer/core": "4.
|
|
25
|
-
"@open-pioneer/
|
|
26
|
-
"@open-pioneer/
|
|
24
|
+
"@open-pioneer/core": "4.5.0-dev-roving-menu.20260128080955",
|
|
25
|
+
"@open-pioneer/base-theme": "4.5.0-dev-roving-menu.20260128080955",
|
|
26
|
+
"@open-pioneer/reactivity": "4.5.0-dev-roving-menu.20260128080955"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
"./package.json": "./package.json",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { InterfaceSpec, ReferenceSpec } from "./InterfaceSpec";
|
|
1
2
|
import { PackageRepr } from "./PackageRepr";
|
|
2
3
|
import { ServiceLookupResult, ServicesLookupResult } from "./ServiceLookup";
|
|
3
|
-
import { InterfaceSpec, ReferenceSpec } from "./InterfaceSpec";
|
|
4
4
|
export type DynamicLookupResult = ServiceLookupResult | UndeclaredDependency;
|
|
5
5
|
/**
|
|
6
6
|
* Returned when a dependency is not declared in the package's metadata.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
+
import { sourceId$6 as sourceId } from '../_virtual/source-info.js';
|
|
3
|
+
import { RUNTIME_PACKAGE_NAME } from '../builtin-services/index.js';
|
|
2
4
|
import { ErrorId } from '../errors.js';
|
|
3
|
-
import { verifyDependencies } from './verifyDependencies.js';
|
|
4
5
|
import { isSingleImplementationSpec, renderInterfaceSpec, isAllImplementationsSpec } from './InterfaceSpec.js';
|
|
5
|
-
import {
|
|
6
|
+
import { verifyDependencies } from './verifyDependencies.js';
|
|
6
7
|
|
|
7
|
-
const LOG = createLogger(
|
|
8
|
+
const LOG = createLogger(sourceId);
|
|
8
9
|
const UNDECLARED_DEPENDENCY = { type: "undeclared" };
|
|
9
10
|
const UNKNOWN_PACKAGE = { type: "unknown-package" };
|
|
10
11
|
class ServiceLayer {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceLayer.js","sources":["ServiceLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ServiceRepr } from \"./ServiceRepr\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport {\n ComputedServiceDependencies,\n FrameworkDependency,\n UIDependency,\n verifyDependencies\n} from \"./verifyDependencies\";\nimport { PackageRepr } from \"./PackageRepr\";\nimport { ReadonlyServiceLookup, ServiceLookupResult, ServicesLookupResult } from \"./ServiceLookup\";\nimport {\n InterfaceSpec,\n isAllImplementationsSpec,\n isSingleImplementationSpec,\n ReferenceSpec,\n renderInterfaceSpec\n} from \"./InterfaceSpec\";\nimport { ReferenceMeta } from \"../Service\";\nimport { RUNTIME_PACKAGE_NAME } from \"../builtin-services\";\n\nconst LOG = createLogger(\"runtime:ServiceLayer\");\n\nexport type DynamicLookupResult = ServiceLookupResult | UndeclaredDependency;\n\n/**\n * Returned when a dependency is not declared in the package's metadata.\n */\nexport interface UndeclaredDependency {\n type: \"undeclared\";\n}\n\n/**\n * Returned when a package is not found in the application's metadata.\n */\nexport interface UnknownPackage {\n type: \"unknown-package\";\n}\n\nconst UNDECLARED_DEPENDENCY = { type: \"undeclared\" } satisfies UndeclaredDependency;\nconst UNKNOWN_PACKAGE = { type: \"unknown-package\" } satisfies UnknownPackage;\n\ninterface DependencyDeclarations {\n all: boolean;\n unqualified: boolean;\n qualifiers: Set<string>;\n}\n\nexport class ServiceLayer {\n // All services in the application.\n private allServices: ServiceRepr[];\n\n // Set of required services. These services and their dependencies will be started.\n private requiredServices: Set<ServiceRepr>;\n\n private serviceLookup: ReadonlyServiceLookup;\n\n // Service id --> Service dependencies\n private serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n // Package name --> Interface name --> Declarations\n private declaredDependencies;\n private state: \"not-started\" | \"started\" | \"destroyed\" = \"not-started\";\n\n /**\n * Constructs a new service layer instance.\n * Requires the application's set of packages (from which services are taken)\n * and an optional set of forced references (interfaces whose implementing services will be started unconditionally).\n *\n * In its current form, the service layer will start only forced references and references needed by the UI (and their dependencies).\n */\n constructor(packages: readonly PackageRepr[], forcedReferences: ReferenceSpec[] = []) {\n const allServices = packages.map((pkg) => pkg.services).flat();\n const uiDependencies = packages\n .map((pkg) =>\n pkg.uiReferences.map<UIDependency>((dep) => {\n return {\n type: \"ui\",\n packageName: pkg.name,\n ...dep\n };\n })\n )\n .flat();\n const requiredReferences = [\n ...forcedReferences.map<FrameworkDependency>((r) => ({\n type: \"framework\",\n ...r\n })),\n ...uiDependencies\n ];\n const { serviceLookup, serviceDependencies } = verifyDependencies({\n services: allServices,\n requiredReferences: requiredReferences\n });\n\n this.allServices = allServices;\n this.requiredServices = getRequiredServices(requiredReferences, serviceLookup);\n this.serviceLookup = serviceLookup;\n this.serviceDependencies = serviceDependencies;\n this.declaredDependencies = buildDependencyIndex(packages);\n }\n\n destroy() {\n for (const service of this.requiredServices) {\n this.destroyService(service);\n }\n this.state = \"destroyed\";\n }\n\n start() {\n if (this.state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer was already started.\");\n }\n\n for (const service of this.requiredServices) {\n this.createService(service);\n }\n this.state = \"started\";\n\n // Give warnings for unneeded services during development.\n if (import.meta.env.DEV) {\n const unneededServices = this.allServices\n .filter(\n (service) =>\n service.packageName !== RUNTIME_PACKAGE_NAME &&\n service.state === \"not-constructed\"\n )\n .map((service) => `'${service.id}'`);\n if (unneededServices.length) {\n const services = unneededServices.join(\", \");\n LOG.warn(\n `The following services are contained in the application but were not started: ${services}.`\n );\n }\n }\n }\n\n /**\n * Returns a service implementing the given interface.\n * Checks that the given package actually declared a dependency on that interface\n * to enforce coding guidelines.\n *\n * @param packageName the name of the package requesting the import\n * @param spec the interface specifier\n * @param options advanced options to customize lookup\n * @throws if the service layer is not in 'started' state or if no service implements the interface.\n */\n getService(\n packageName: string,\n spec: InterfaceSpec,\n options?: { ignoreDeclarationCheck?: boolean }\n ): ServiceLookupResult | UndeclaredDependency | UnknownPackage {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n if (!options?.ignoreDeclarationCheck) {\n const checkError = this.checkDependency(packageName, spec);\n if (checkError) {\n return checkError;\n }\n }\n\n return this.serviceLookup.lookupOne(spec);\n }\n\n /**\n * Returns all services implementing the given interface.\n * Requires that the dependency on all implementations has been declared in the package.\n *\n * @param packageName the name of the package requesting the import\n * @param interfaceName the interface name\n *\n * @throws if the service layer is not in 'started'.\n */\n getServices(\n packageName: string,\n interfaceName: string\n ): ServicesLookupResult | UndeclaredDependency | UnknownPackage {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n const checkError = this.checkDependency(packageName, { interfaceName, all: true });\n if (checkError) {\n return checkError;\n }\n return this.serviceLookup.lookupAll(interfaceName);\n }\n\n /**\n * Initializes the given service and its dependencies.\n * Dependencies are initialized before the service that requires them.\n */\n private createService(service: ServiceRepr) {\n if (service.state === \"constructed\") {\n const instance = service.getInstanceOrThrow();\n service.addRef();\n return instance;\n }\n if (service.state === \"constructing\") {\n throw new Error(ErrorId.INTERNAL, \"Cycle during service construction.\");\n }\n if (service.state !== \"not-constructed\") {\n throw new Error(ErrorId.INTERNAL, \"Invalid service state.\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const references: Record<string, any> = {};\n const referencesMeta: Record<string, ReferenceMeta | ReferenceMeta[]> = {};\n\n // Sets state to 'constructing' to detect cycles\n service.beforeCreate();\n\n // Initialize dependencies recursively before creating the current service.\n for (const [referenceName, serviceDeps] of Object.entries(this.getServiceDeps(service))) {\n const [referenceValue, referenceMeta] = this.getReference(serviceDeps);\n references[referenceName] = referenceValue;\n referencesMeta[referenceName] = referenceMeta;\n }\n\n // Sets state to 'constructed' to finish the state transition, useCount is 1.\n LOG.debug(`Creating service '${service.id}'.`);\n return service.create({ references, referencesMeta });\n }\n\n /**\n * Destroys the given service and its dependencies.\n * The dependencies are destroyed after the service.\n */\n private destroyService(service: ServiceRepr) {\n if (service.state === \"destroyed\") {\n return;\n }\n\n // Destroy the service before its dependencies (reverse order\n // compared to construction).\n if (service.removeRef() <= 0) {\n LOG.debug(`Destroying service '${service.id}'`);\n service.destroy();\n }\n\n for (const serviceDeps of Object.values(this.getServiceDeps(service))) {\n if (Array.isArray(serviceDeps)) {\n for (const dep of serviceDeps) {\n this.destroyService(dep);\n }\n } else {\n this.destroyService(serviceDeps);\n }\n }\n }\n\n /** Undefined -> everything is okay */\n private checkDependency(\n packageName: string,\n spec: ReferenceSpec\n ): UnknownPackage | UndeclaredDependency | undefined {\n const packageEntry = this.declaredDependencies.get(packageName);\n if (!packageEntry) {\n return UNKNOWN_PACKAGE;\n }\n\n const interfaceEntry = packageEntry.get(spec.interfaceName);\n if (!interfaceEntry) {\n return UNDECLARED_DEPENDENCY;\n }\n\n if (isSingleImplementationSpec(spec)) {\n if (spec.qualifier == null) {\n return interfaceEntry.unqualified ? undefined : UNDECLARED_DEPENDENCY;\n }\n return interfaceEntry.qualifiers.has(spec.qualifier)\n ? undefined\n : UNDECLARED_DEPENDENCY;\n } else {\n return interfaceEntry.all ? undefined : UNDECLARED_DEPENDENCY;\n }\n }\n\n private getReference(ref: ServiceRepr): [unknown, ReferenceMeta];\n private getReference(ref: ServiceRepr[]): [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]] {\n if (Array.isArray(ref)) {\n const referenceValues: unknown[] = [];\n const referenceMeta: ReferenceMeta[] = [];\n for (const d of ref) {\n const [value, meta] = this.getReference(d);\n referenceValues.push(value);\n referenceMeta.push(meta);\n }\n return [referenceValues, referenceMeta];\n }\n\n const referenceValue = this.createService(ref);\n const referenceMeta: ReferenceMeta = {\n serviceId: ref.id\n };\n return [referenceValue, referenceMeta];\n }\n\n private getServiceDeps(service: ServiceRepr) {\n const dependencies = this.serviceDependencies.get(service.id);\n if (!dependencies) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find precomputed service dependencies for '${service.id}'.`\n );\n }\n return dependencies;\n }\n}\n\nfunction getRequiredServices(\n requiredReferences: readonly ReferenceSpec[],\n serviceLookup: ReadonlyServiceLookup\n): Set<ServiceRepr> {\n const requiredServices = new Set<ServiceRepr>();\n for (const referenceSpec of requiredReferences) {\n const result = serviceLookup.lookup(referenceSpec);\n if (result.type !== \"found\") {\n // Should be caught by verifier\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find required reference to ${renderInterfaceSpec(referenceSpec)}.`\n );\n }\n if (Array.isArray(result.value)) {\n for (const service of result.value) {\n requiredServices.add(service);\n }\n } else {\n requiredServices.add(result.value);\n }\n }\n return requiredServices;\n}\n\nfunction buildDependencyIndex(packages: readonly PackageRepr[]) {\n // Register declared UI dependencies.\n // This is needed as a lookup structure to that dynamic service lookups\n // can be validated at runtime.\n const index = new Map<string, Map<string, DependencyDeclarations>>();\n for (const pkg of packages) {\n const packageName = pkg.name;\n const packageEntry = new Map<string, DependencyDeclarations>();\n for (const uiReference of pkg.uiReferences) {\n let interfaceEntry = packageEntry.get(uiReference.interfaceName);\n if (!interfaceEntry) {\n interfaceEntry = {\n all: false,\n unqualified: false,\n qualifiers: new Set<string>()\n };\n packageEntry.set(uiReference.interfaceName, interfaceEntry);\n }\n\n if (isAllImplementationsSpec(uiReference)) {\n interfaceEntry.all = true;\n } else if (isSingleImplementationSpec(uiReference)) {\n if (uiReference.qualifier == null) {\n interfaceEntry.unqualified = true;\n } else {\n interfaceEntry.qualifiers.add(uiReference.qualifier);\n }\n } else {\n throw new Error(ErrorId.INTERNAL, `Unexpected implementation spec.`);\n }\n }\n index.set(packageName, packageEntry);\n }\n return index;\n}\n"],"names":["referenceMeta"],"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e,UAAA,CAAW,GAAA,CAAI,WAAA,CAAY,SAAS,CAAA;AAAA,QACvD;AAAA,MACJ,CAAA,MAAO;AACH,QAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,EAAU,CAAA,+BAAA,CAAiC,CAAA;AAAA,MACvE;AAAA,IACJ;AACA,IAAA,KAAA,CAAM,GAAA,CAAI,aAAa,YAAY,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,KAAA;AACX;;;;"}
|
|
1
|
+
{"version":3,"file":"ServiceLayer.js","sources":["ServiceLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ReferenceMeta } from \"../Service\";\nimport { RUNTIME_PACKAGE_NAME } from \"../builtin-services\";\nimport { ErrorId } from \"../errors\";\nimport {\n InterfaceSpec,\n isAllImplementationsSpec,\n isSingleImplementationSpec,\n ReferenceSpec,\n renderInterfaceSpec\n} from \"./InterfaceSpec\";\nimport { PackageRepr } from \"./PackageRepr\";\nimport { ReadonlyServiceLookup, ServiceLookupResult, ServicesLookupResult } from \"./ServiceLookup\";\nimport { ServiceRepr } from \"./ServiceRepr\";\nimport {\n ComputedServiceDependencies,\n FrameworkDependency,\n UIDependency,\n verifyDependencies\n} from \"./verifyDependencies\";\n\nconst LOG = createLogger(sourceId);\n\nexport type DynamicLookupResult = ServiceLookupResult | UndeclaredDependency;\n\n/**\n * Returned when a dependency is not declared in the package's metadata.\n */\nexport interface UndeclaredDependency {\n type: \"undeclared\";\n}\n\n/**\n * Returned when a package is not found in the application's metadata.\n */\nexport interface UnknownPackage {\n type: \"unknown-package\";\n}\n\nconst UNDECLARED_DEPENDENCY = { type: \"undeclared\" } satisfies UndeclaredDependency;\nconst UNKNOWN_PACKAGE = { type: \"unknown-package\" } satisfies UnknownPackage;\n\ninterface DependencyDeclarations {\n all: boolean;\n unqualified: boolean;\n qualifiers: Set<string>;\n}\n\nexport class ServiceLayer {\n // All services in the application.\n private allServices: ServiceRepr[];\n\n // Set of required services. These services and their dependencies will be started.\n private requiredServices: Set<ServiceRepr>;\n\n private serviceLookup: ReadonlyServiceLookup;\n\n // Service id --> Service dependencies\n private serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n // Package name --> Interface name --> Declarations\n private declaredDependencies;\n private state: \"not-started\" | \"started\" | \"destroyed\" = \"not-started\";\n\n /**\n * Constructs a new service layer instance.\n * Requires the application's set of packages (from which services are taken)\n * and an optional set of forced references (interfaces whose implementing services will be started unconditionally).\n *\n * In its current form, the service layer will start only forced references and references needed by the UI (and their dependencies).\n */\n constructor(packages: readonly PackageRepr[], forcedReferences: ReferenceSpec[] = []) {\n const allServices = packages.map((pkg) => pkg.services).flat();\n const uiDependencies = packages\n .map((pkg) =>\n pkg.uiReferences.map<UIDependency>((dep) => {\n return {\n type: \"ui\",\n packageName: pkg.name,\n ...dep\n };\n })\n )\n .flat();\n const requiredReferences = [\n ...forcedReferences.map<FrameworkDependency>((r) => ({\n type: \"framework\",\n ...r\n })),\n ...uiDependencies\n ];\n const { serviceLookup, serviceDependencies } = verifyDependencies({\n services: allServices,\n requiredReferences: requiredReferences\n });\n\n this.allServices = allServices;\n this.requiredServices = getRequiredServices(requiredReferences, serviceLookup);\n this.serviceLookup = serviceLookup;\n this.serviceDependencies = serviceDependencies;\n this.declaredDependencies = buildDependencyIndex(packages);\n }\n\n destroy() {\n for (const service of this.requiredServices) {\n this.destroyService(service);\n }\n this.state = \"destroyed\";\n }\n\n start() {\n if (this.state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer was already started.\");\n }\n\n for (const service of this.requiredServices) {\n this.createService(service);\n }\n this.state = \"started\";\n\n // Give warnings for unneeded services during development.\n if (import.meta.env.DEV) {\n const unneededServices = this.allServices\n .filter(\n (service) =>\n service.packageName !== RUNTIME_PACKAGE_NAME &&\n service.state === \"not-constructed\"\n )\n .map((service) => `'${service.id}'`);\n if (unneededServices.length) {\n const services = unneededServices.join(\", \");\n LOG.warn(\n `The following services are contained in the application but were not started: ${services}.`\n );\n }\n }\n }\n\n /**\n * Returns a service implementing the given interface.\n * Checks that the given package actually declared a dependency on that interface\n * to enforce coding guidelines.\n *\n * @param packageName the name of the package requesting the import\n * @param spec the interface specifier\n * @param options advanced options to customize lookup\n * @throws if the service layer is not in 'started' state or if no service implements the interface.\n */\n getService(\n packageName: string,\n spec: InterfaceSpec,\n options?: { ignoreDeclarationCheck?: boolean }\n ): ServiceLookupResult | UndeclaredDependency | UnknownPackage {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n if (!options?.ignoreDeclarationCheck) {\n const checkError = this.checkDependency(packageName, spec);\n if (checkError) {\n return checkError;\n }\n }\n\n return this.serviceLookup.lookupOne(spec);\n }\n\n /**\n * Returns all services implementing the given interface.\n * Requires that the dependency on all implementations has been declared in the package.\n *\n * @param packageName the name of the package requesting the import\n * @param interfaceName the interface name\n *\n * @throws if the service layer is not in 'started'.\n */\n getServices(\n packageName: string,\n interfaceName: string\n ): ServicesLookupResult | UndeclaredDependency | UnknownPackage {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n const checkError = this.checkDependency(packageName, { interfaceName, all: true });\n if (checkError) {\n return checkError;\n }\n return this.serviceLookup.lookupAll(interfaceName);\n }\n\n /**\n * Initializes the given service and its dependencies.\n * Dependencies are initialized before the service that requires them.\n */\n private createService(service: ServiceRepr) {\n if (service.state === \"constructed\") {\n const instance = service.getInstanceOrThrow();\n service.addRef();\n return instance;\n }\n if (service.state === \"constructing\") {\n throw new Error(ErrorId.INTERNAL, \"Cycle during service construction.\");\n }\n if (service.state !== \"not-constructed\") {\n throw new Error(ErrorId.INTERNAL, \"Invalid service state.\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const references: Record<string, any> = {};\n const referencesMeta: Record<string, ReferenceMeta | ReferenceMeta[]> = {};\n\n // Sets state to 'constructing' to detect cycles\n service.beforeCreate();\n\n // Initialize dependencies recursively before creating the current service.\n for (const [referenceName, serviceDeps] of Object.entries(this.getServiceDeps(service))) {\n const [referenceValue, referenceMeta] = this.getReference(serviceDeps);\n references[referenceName] = referenceValue;\n referencesMeta[referenceName] = referenceMeta;\n }\n\n // Sets state to 'constructed' to finish the state transition, useCount is 1.\n LOG.debug(`Creating service '${service.id}'.`);\n return service.create({ references, referencesMeta });\n }\n\n /**\n * Destroys the given service and its dependencies.\n * The dependencies are destroyed after the service.\n */\n private destroyService(service: ServiceRepr) {\n if (service.state === \"destroyed\") {\n return;\n }\n\n // Destroy the service before its dependencies (reverse order\n // compared to construction).\n if (service.removeRef() <= 0) {\n LOG.debug(`Destroying service '${service.id}'`);\n service.destroy();\n }\n\n for (const serviceDeps of Object.values(this.getServiceDeps(service))) {\n if (Array.isArray(serviceDeps)) {\n for (const dep of serviceDeps) {\n this.destroyService(dep);\n }\n } else {\n this.destroyService(serviceDeps);\n }\n }\n }\n\n /** Undefined -> everything is okay */\n private checkDependency(\n packageName: string,\n spec: ReferenceSpec\n ): UnknownPackage | UndeclaredDependency | undefined {\n const packageEntry = this.declaredDependencies.get(packageName);\n if (!packageEntry) {\n return UNKNOWN_PACKAGE;\n }\n\n const interfaceEntry = packageEntry.get(spec.interfaceName);\n if (!interfaceEntry) {\n return UNDECLARED_DEPENDENCY;\n }\n\n if (isSingleImplementationSpec(spec)) {\n if (spec.qualifier == null) {\n return interfaceEntry.unqualified ? undefined : UNDECLARED_DEPENDENCY;\n }\n return interfaceEntry.qualifiers.has(spec.qualifier)\n ? undefined\n : UNDECLARED_DEPENDENCY;\n } else {\n return interfaceEntry.all ? undefined : UNDECLARED_DEPENDENCY;\n }\n }\n\n private getReference(ref: ServiceRepr): [unknown, ReferenceMeta];\n private getReference(ref: ServiceRepr[]): [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]] {\n if (Array.isArray(ref)) {\n const referenceValues: unknown[] = [];\n const referenceMeta: ReferenceMeta[] = [];\n for (const d of ref) {\n const [value, meta] = this.getReference(d);\n referenceValues.push(value);\n referenceMeta.push(meta);\n }\n return [referenceValues, referenceMeta];\n }\n\n const referenceValue = this.createService(ref);\n const referenceMeta: ReferenceMeta = {\n serviceId: ref.id\n };\n return [referenceValue, referenceMeta];\n }\n\n private getServiceDeps(service: ServiceRepr) {\n const dependencies = this.serviceDependencies.get(service.id);\n if (!dependencies) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find precomputed service dependencies for '${service.id}'.`\n );\n }\n return dependencies;\n }\n}\n\nfunction getRequiredServices(\n requiredReferences: readonly ReferenceSpec[],\n serviceLookup: ReadonlyServiceLookup\n): Set<ServiceRepr> {\n const requiredServices = new Set<ServiceRepr>();\n for (const referenceSpec of requiredReferences) {\n const result = serviceLookup.lookup(referenceSpec);\n if (result.type !== \"found\") {\n // Should be caught by verifier\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find required reference to ${renderInterfaceSpec(referenceSpec)}.`\n );\n }\n if (Array.isArray(result.value)) {\n for (const service of result.value) {\n requiredServices.add(service);\n }\n } else {\n requiredServices.add(result.value);\n }\n }\n return requiredServices;\n}\n\nfunction buildDependencyIndex(packages: readonly PackageRepr[]) {\n // Register declared UI dependencies.\n // This is needed as a lookup structure to that dynamic service lookups\n // can be validated at runtime.\n const index = new Map<string, Map<string, DependencyDeclarations>>();\n for (const pkg of packages) {\n const packageName = pkg.name;\n const packageEntry = new Map<string, DependencyDeclarations>();\n for (const uiReference of pkg.uiReferences) {\n let interfaceEntry = packageEntry.get(uiReference.interfaceName);\n if (!interfaceEntry) {\n interfaceEntry = {\n all: false,\n unqualified: false,\n qualifiers: new Set<string>()\n };\n packageEntry.set(uiReference.interfaceName, interfaceEntry);\n }\n\n if (isAllImplementationsSpec(uiReference)) {\n interfaceEntry.all = true;\n } else if (isSingleImplementationSpec(uiReference)) {\n if (uiReference.qualifier == null) {\n interfaceEntry.unqualified = true;\n } else {\n interfaceEntry.qualifiers.add(uiReference.qualifier);\n }\n } else {\n throw new Error(ErrorId.INTERNAL, `Unexpected implementation spec.`);\n }\n }\n index.set(packageName, packageEntry);\n }\n return index;\n}\n"],"names":["referenceMeta"],"mappings":";;;;;;;AAwBA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAkBjC,MAAM,qBAAA,GAAwB,EAAE,IAAA,EAAM,YAAA,EAAa;AACnD,MAAM,eAAA,GAAkB,EAAE,IAAA,EAAM,iBAAA,EAAkB;AAQ3C,MAAM,YAAA,CAAa;AAAA;AAAA,EAEd,WAAA;AAAA;AAAA,EAGA,gBAAA;AAAA,EAEA,aAAA;AAAA;AAAA,EAGA,mBAAA;AAAA;AAAA,EAGA,oBAAA;AAAA,EACA,KAAA,GAAiD,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASzD,WAAA,CAAY,QAAA,EAAkC,gBAAA,GAAoC,EAAC,EAAG;AAClF,IAAA,MAAM,WAAA,GAAc,SAAS,GAAA,CAAI,CAAC,QAAQ,GAAA,CAAI,QAAQ,EAAE,IAAA,EAAK;AAC7D,IAAA,MAAM,iBAAiB,QAAA,CAClB,GAAA;AAAA,MAAI,CAAC,GAAA,KACF,GAAA,CAAI,YAAA,CAAa,GAAA,CAAkB,CAAC,GAAA,KAAQ;AACxC,QAAA,OAAO;AAAA,UACH,IAAA,EAAM,IAAA;AAAA,UACN,aAAa,GAAA,CAAI,IAAA;AAAA,UACjB,GAAG;AAAA,SACP;AAAA,MACJ,CAAC;AAAA,MAEJ,IAAA,EAAK;AACV,IAAA,MAAM,kBAAA,GAAqB;AAAA,MACvB,GAAG,gBA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