@open-pioneer/runtime 1.0.2 → 2.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,86 @@
1
1
  # @open-pioneer/runtime
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - ce9e060: Remove support for closed shadow roots.
8
+ Shadow roots used by trails applications are now always `"open"`.
9
+ See #19.
10
+ - 6f954e3: **Breaking Change**: change how services integrate into TypeScript (fixes #22).
11
+ The old TypeScript integration had unexpected edge cases, see the linked issue.
12
+
13
+ NOTE: The changes below have no impact on runtime behavior, but they may trigger TypeScript errors in your code.
14
+
15
+ - To register a service's type with TypeScript, one previously used a block such as this:
16
+
17
+ ```ts
18
+ // OLD! Can be removed
19
+ import "@open-pioneer/runtime";
20
+ declare module "@open-pioneer/runtime" {
21
+ interface ServiceRegistry {
22
+ "http.HttpService": HttpService;
23
+ }
24
+ }
25
+ ```
26
+
27
+ The new method requires the developer to change the service's declaration.
28
+ Simply add `extends DeclaredService<"SERVICE_ID">` to your service interface, where `SERVICE_ID` should match the service's interface name (`"provides"` in `build.config.mjs`).
29
+
30
+ ```diff
31
+ + import { DeclaredService } from "@open-pioneer/runtime";
32
+
33
+ - export interface HttpService {
34
+ + export interface HttpService extends DeclaredService<"http.HttpService"> {
35
+
36
+ - import "@open-pioneer/runtime";
37
+ - declare module "@open-pioneer/runtime" {
38
+ - interface ServiceRegistry {
39
+ - "http.HttpService": HttpService;
40
+ - }
41
+ - }
42
+ ```
43
+
44
+ - To use a service from React code (i.e. `useService` and `useServices`), you must now use the explicit service type in the hook's generic parameter list. Otherwise the hook will simply return `unknown`:
45
+
46
+ ```diff
47
+ + import { HttpService } from "@open-pioneer/http";
48
+ - const httpService = useService("http.HttpService");
49
+ + const httpService = useService<HttpService>("http.HttpService");
50
+ ```
51
+
52
+ This change was necessary to fix an issue where the global registration of the service interface (and its association with the string constant) was not available.
53
+
54
+ The system will still check that the provided string matches the string constant used in the service's declaration (`DeclaredService<...>`), so type safety is preserved.
55
+
56
+ - The types `InterfaceName` and `ServiceType<I>` have been removed. Use explicit service interfaces instead.
57
+ - The interfaces `ServiceRegistry` and `PropertiesRegistry` have been removed as global registration is no longer possible.
58
+ - The type `RawApplicationProperties` has been removed. Use `ApplicationProperties` instead.
59
+
60
+ ### Patch Changes
61
+
62
+ - f5c0e31: Bump @formatjs/intl version
63
+ - Updated dependencies [f5c0e31]
64
+ - Updated dependencies [6f954e3]
65
+ - @open-pioneer/chakra-integration@1.1.1
66
+ - @open-pioneer/base-theme@0.2.0
67
+ - @open-pioneer/runtime-react-support@1.0.0
68
+
69
+ ## 1.1.0
70
+
71
+ ### Minor Changes
72
+
73
+ - 6632892: Implement support for custom chakra themes via the `theme` parameter in `createCustomElement()`.
74
+ `theme` from `@open-pioneer/base-theme` is used as default when no other theme is configured.
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [6632892]
79
+ - Updated dependencies [6632892]
80
+ - @open-pioneer/base-theme@0.1.0
81
+ - @open-pioneer/chakra-integration@1.1.0
82
+ - @open-pioneer/runtime-react-support@1.0.0
83
+
3
84
  ## 1.0.2
4
85
 
5
86
  ### Patch Changes
@@ -1,7 +1,6 @@
1
1
  import { ComponentType } from "react";
2
2
  import { ApplicationMetadata } from "./metadata";
3
3
  import { ApiMethods } from "./api";
4
- import { PropertiesRegistry } from "./PropertiesRegistry";
5
4
  /**
6
5
  * Options for the {@link createCustomElement} function.
7
6
  */
@@ -33,10 +32,9 @@ export interface CustomElementOptions {
33
32
  */
34
33
  resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;
35
34
  /**
36
- * Whether the shadow root element is accessible from the outside.
37
- * Defaults to `false` in production mode and `true` during development to make testing easier.
35
+ * Chakra theming object.
38
36
  */
39
- openShadowRoot?: boolean;
37
+ theme?: Record<string, unknown>;
40
38
  }
41
39
  /**
42
40
  * A context object that is passed to the `resolveProperties` function.
@@ -66,8 +64,10 @@ export interface ApplicationConfig {
66
64
  }
67
65
  /**
68
66
  * Allows the application to override default properties in all packages.
67
+ *
68
+ * Properties are typed when the package contains type definitions for them.
69
69
  */
70
- export interface RawApplicationProperties {
70
+ export interface ApplicationProperties {
71
71
  /**
72
72
  * Key: the name of the package.
73
73
  * Value: A record of configuration properties (key/value pairs).
@@ -76,12 +76,6 @@ export interface RawApplicationProperties {
76
76
  */
77
77
  [packageName: string]: Record<string, unknown>;
78
78
  }
79
- /**
80
- * Allows the application to override default properties in all packages.
81
- *
82
- * Properties are typed when the package contains type definitions for them.
83
- */
84
- export type ApplicationProperties = RawApplicationProperties & Partial<PropertiesRegistry>;
85
79
  /**
86
80
  * The interface implemented by web components produced via {@link createCustomElement}.
87
81
  */
package/CustomElement.js CHANGED
@@ -16,9 +16,8 @@ function createCustomElement(options) {
16
16
  }
17
17
  constructor() {
18
18
  super();
19
- const mode = options.openShadowRoot ?? import.meta.env.DEV ? "open" : "closed";
20
19
  this.#shadowRoot = this.attachShadow({
21
- mode
20
+ mode: "open"
22
21
  });
23
22
  if (import.meta.env.DEV) {
24
23
  this.$inspectElementState = () => this.#state;
@@ -136,6 +135,7 @@ class ElementState {
136
135
  this.reactIntegration = new ReactIntegration({
137
136
  rootNode: container,
138
137
  container: shadowRoot,
138
+ theme: options.theme,
139
139
  serviceLayer,
140
140
  packages
141
141
  });
@@ -145,7 +145,7 @@ class ElementState {
145
145
  LOG.debug("Application started");
146
146
  }
147
147
  render() {
148
- this.reactIntegration?.render(this.options.component ?? emptyComponent, {});
148
+ this.reactIntegration?.render(this.options.component ?? emptyComponent);
149
149
  }
150
150
  initStyles() {
151
151
  const builtinStyles = ":host { all: initial; display: block; }";
@@ -1 +1 @@
1
- {"version":3,"file":"CustomElement.js","sources":["CustomElement.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { ComponentType } from \"react\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n isAbortError,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata, PackageMetadata } from \"./metadata\";\nimport { PackageRepr, createPackages } from \"./service-layer/PackageRepr\";\nimport { ServiceLayer } from \"./service-layer/ServiceLayer\";\nimport { getErrorChain } from \"@open-pioneer/core\";\nimport { ReactIntegration } from \"./react-integration/ReactIntegration\";\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 { ReferenceSpec } from \"./service-layer/InterfaceSpec\";\nimport { PropertiesRegistry } from \"./PropertiesRegistry\";\nimport { AppI18n, initI18n } from \"./i18n\";\nimport { ApplicationLifecycleEventService } from \"./builtin-services/ApplicationLifecycleEventService\";\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 * 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 * Whether the shadow root element is accessible from the outside.\n * Defaults to `false` in production mode and `true` during development to make testing easier.\n */\n openShadowRoot?: boolean;\n}\n\n/**\n * A context object that is passed to the `resolveProperties` function.\n */\nexport interface ConfigContext {\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\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 */\nexport interface RawApplicationProperties {\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 * 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 type ApplicationProperties = RawApplicationProperties & Partial<PropertiesRegistry>;\n\n/**\n * The interface implemented by web components produced via {@link createCustomElement}.\n */\nexport interface ApplicationElement extends HTMLElement {\n /** Resolves to the element's API when the application has started. */\n when(): Promise<ApiMethods>;\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;\n #state: ElementState | undefined;\n\n static get observedAttributes(): string[] {\n return [];\n }\n\n constructor() {\n super();\n\n const mode = options.openShadowRoot ?? import.meta.env.DEV ? \"open\" : \"closed\";\n this.#shadowRoot = this.attachShadow({\n mode: mode\n });\n\n if (import.meta.env.DEV) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).$inspectElementState = () => this.#state;\n }\n }\n\n connectedCallback() {\n LOG.debug(\"Launching application\");\n\n if (this.#state) {\n this.#state.destroy();\n }\n\n this.#state = new ElementState(this, this.#shadowRoot, options);\n this.#state.start();\n }\n\n disconnectedCallback() {\n LOG.debug(\"Shutting down application\");\n\n this.#state?.destroy();\n this.#state = undefined;\n\n LOG.debug(\"Application destroyed\");\n }\n\n when() {\n if (!this.#state) {\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.#state.whenAPI();\n }\n }\n return PioneerApplication;\n}\n\nclass ElementState {\n private hostElement: HTMLElement;\n private shadowRoot: ShadowRoot;\n private options: CustomElementOptions;\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 = \"not-started\" as \"not-started\" | \"starting\" | \"started\" | \"destroyed\";\n private locale: string | undefined;\n private container: HTMLDivElement | undefined;\n private config: ApplicationConfig | undefined;\n private serviceLayer: ServiceLayer | undefined;\n private lifecycleEvents: ApplicationLifecycleEventService | undefined;\n private reactIntegration: ReactIntegration | undefined;\n private stylesWatch: Resource | undefined;\n\n constructor(hostElement: HTMLElement, shadowRoot: ShadowRoot, options: CustomElementOptions) {\n this.hostElement = hostElement;\n this.shadowRoot = shadowRoot;\n this.options = options;\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 // TODO: Error splash?\n this.destroy();\n if (!isAbortError(e)) {\n logError(e);\n }\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.apiPromise?.reject(createAbortError());\n this.reactIntegration = destroyResource(this.reactIntegration);\n this.shadowRoot.replaceChildren();\n this.container = 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 { options, shadowRoot, hostElement } = this;\n\n // Resolve custom application config\n const config = (this.config = await gatherConfig(hostElement, options));\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(options.appMetadata, config.locale);\n this.checkAbort();\n\n // Setup application root node in the shadow dom\n const container = (this.container = createContainer(i18n.locale));\n const styles = this.initStyles();\n shadowRoot.replaceChildren(container, ...styles);\n\n // Launch the service layer\n const { serviceLayer, packages } = this.initServiceLayer({\n container,\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 = new ReactIntegration({\n rootNode: container,\n container: shadowRoot,\n serviceLayer,\n packages\n });\n this.render();\n this.state = \"started\";\n\n this.triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n private render() {\n this.reactIntegration?.render(this.options.component ?? emptyComponent, {});\n }\n\n private initStyles() {\n // Prevent inheritance of certain css values and normalize to display: block by default.\n // See https://open-wc.org/guides/knowledge/styling/styles-piercing-shadow-dom/\n const builtinStyles = \":host { all: initial; display: block; }\";\n const builtinStylesNode = document.createElement(\"style\");\n applyStyles(builtinStylesNode, { value: builtinStyles });\n\n const appStyles = this.options.appMetadata?.styles;\n const appStylesNode = document.createElement(\"style\");\n applyStyles(appStylesNode, appStyles);\n if (import.meta.hot) {\n this.stylesWatch = appStyles?.on?.(\"changed\", () => {\n LOG.debug(\"Application styles changed\");\n applyStyles(appStylesNode, appStyles);\n });\n }\n return [builtinStylesNode, appStylesNode];\n }\n\n private initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppI18n;\n }) {\n const options = this.options;\n const { container, properties, i18n } = config;\n const packageMetadata = options.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: this.hostElement,\n shadowRoot: this.shadowRoot,\n container: container,\n locale: i18n.locale,\n supportedLocales: i18n.supportedLocales\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\nfunction createContainer(locale: string) {\n // Setup application root node in the shadow dom\n const container = document.createElement(\"div\");\n container.classList.add(\"pioneer-root\");\n container.style.minHeight = \"100%\";\n container.style.height = \"100%\";\n if (locale) {\n container.lang = locale;\n }\n return container;\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppI18n;\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\n/**\n * Gathers application properties by reading them from the options object\n * and by (optionally) invoking the `resolveProperties` hook.\n */\nasync function gatherConfig(hostElement: HTMLElement, options: CustomElementOptions) {\n let configs: ApplicationConfig[];\n try {\n const staticConfig = options.config ?? {};\n const dynamicConfig =\n (await options.resolveConfig?.({\n getAttribute(name) {\n return hostElement.getAttribute(name) ?? undefined;\n }\n })) ?? {};\n\n configs = [staticConfig, dynamicConfig];\n } catch (e) {\n throw new Error(\n ErrorId.CONFIG_RESOLUTION_FAILED,\n \"Failed to resolve application properties.\",\n {\n cause: e\n }\n );\n }\n\n return mergeConfigs(configs);\n}\n\n/**\n * Merges application configurations into a single object.\n * Properties / config parameters at a later position overwrite properties from earlier ones.\n */\nfunction mergeConfigs(configs: ApplicationConfig[]): Required<ApplicationConfig> {\n // Merge simple values by assigning them in order\n const mergedConfig: Required<ApplicationConfig> = Object.assign(\n {\n locale: undefined,\n properties: {}\n } satisfies ApplicationConfig,\n ...configs\n );\n\n // Deep merge for application properties\n const mergedProperties: ApplicationProperties = (mergedConfig.properties = {});\n for (const config of configs) {\n for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {\n const mergedPackageProps = (mergedProperties[packageName] ??= {});\n Object.assign(mergedPackageProps, packageProperties);\n }\n }\n\n return mergedConfig;\n}\n\n// Applies application styles to the given style node.\n// Can be called multiple times in development mode to implement hot reloading.\nfunction applyStyles(styleNode: HTMLStyleElement, styles: { value: string } | undefined) {\n let cssValue = styles?.value ?? \"\";\n // Remove sourcemaps from inline css.\n // This currently does not work because a) the 'importer' (the index.html file) does not\n // match the actual path the source map would exist and b) vite refuses to generate it anyway, probably\n // because of our virtual modules.\n // TODO: both should be fixed once we can refer to actual `.css` files\n // and don't have to embed inline css anymore.\n cssValue = cssValue.replace(/\\/\\*# sourceMappingURL=.*$/, \"\");\n const cssNode = document.createTextNode(cssValue);\n styleNode.replaceChildren(cssNode);\n}\n\nfunction logError(e: unknown) {\n if (e instanceof Error) {\n const chain = getErrorChain(e).reverse();\n if (chain.length === 1) {\n console.error(e);\n return;\n }\n\n let n = 1;\n for (const error of chain) {\n console.error(`#${n}`, error);\n ++n;\n }\n } else {\n console.error(\"Unexpected error\", e);\n }\n}\n\nfunction emptyComponent() {\n return null;\n}\n"],"names":[],"mappings":";;;;;;;;AA+BA,MAAM,GAAA,GAAM,aAAa,uBAAuB,CAAA,CAAA;AAyHzC,SAAS,oBAAoB,OAA8D,EAAA;AAC9F,EAAA,MAAM,2BAA2B,WAA0C,CAAA;AAAA,IACvE,WAAA,CAAA;AAAA,IACA,MAAA,CAAA;AAAA,IAEA,WAAW,kBAA+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CAAA;AAOhC,EAAW,QAAA,GAAA,QAAA,CAAS,OAAQ,CAAA,4BAAA,EAA8B,EAAE,CAAA,CAAA;AAC5D,EAAM,MAAA,OAAA,GAAU,QAAS,CAAA,cAAA,CAAe,QAAQ,CAAA,CAAA;AAChD,EAAA,SAAA,CAAU,gBAAgB,OAAO,CAAA,CAAA;AACrC,CAAA;AAEA,SAAS,SAAS,CAAY,EAAA;AAC1B,EAAA,IAAI,aAAa,KAAO,EAAA;AACpB,IAAA,MAAM,KAAQ,GAAA,aAAA,CAAc,CAAC,CAAA,CAAE,OAAQ,EAAA,CAAA;AACvC,IAAI,IAAA,KAAA,CAAM,WAAW,CAAG,EAAA;AACpB,MAAA,OAAA,CAAQ,MAAM,CAAC,CAAA,CAAA;AACf,MAAA,OAAA;AAAA,KACJ;AAEA,IAAA,IAAI,CAAI,GAAA,CAAA,CAAA;AACR,IAAA,KAAA,MAAW,SAAS,KAAO,EAAA;AACvB,MAAQ,OAAA,CAAA,KAAA,CAAM,CAAI,CAAA,EAAA,CAAA,CAAA,CAAA,EAAK,KAAK,CAAA,CAAA;AAC5B,MAAE,EAAA,CAAA,CAAA;AAAA,KACN;AAAA,GACG,MAAA;AACH,IAAQ,OAAA,CAAA,KAAA,CAAM,oBAAoB,CAAC,CAAA,CAAA;AAAA,GACvC;AACJ,CAAA;AAEA,SAAS,cAAiB,GAAA;AACtB,EAAO,OAAA,IAAA,CAAA;AACX;;;;"}
1
+ {"version":3,"file":"CustomElement.js","sources":["CustomElement.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ComponentType } from \"react\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n isAbortError,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata, PackageMetadata } from \"./metadata\";\nimport { PackageRepr, createPackages } from \"./service-layer/PackageRepr\";\nimport { ServiceLayer } from \"./service-layer/ServiceLayer\";\nimport { getErrorChain } from \"@open-pioneer/core\";\nimport { ReactIntegration } from \"./react-integration/ReactIntegration\";\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 { ReferenceSpec } from \"./service-layer/InterfaceSpec\";\nimport { AppI18n, initI18n } from \"./i18n\";\nimport { ApplicationLifecycleEventService } from \"./builtin-services/ApplicationLifecycleEventService\";\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 * 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 * Chakra theming object.\n */\n theme?: Record<string, unknown>;\n}\n\n/**\n * A context object that is passed to the `resolveProperties` function.\n */\nexport interface ConfigContext {\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\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 /** Resolves to the element's API when the application has started. */\n when(): Promise<ApiMethods>;\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;\n #state: ElementState | undefined;\n\n static get observedAttributes(): string[] {\n return [];\n }\n\n constructor() {\n super();\n\n this.#shadowRoot = this.attachShadow({\n mode: \"open\"\n });\n\n if (import.meta.env.DEV) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).$inspectElementState = () => this.#state;\n }\n }\n\n connectedCallback() {\n LOG.debug(\"Launching application\");\n\n if (this.#state) {\n this.#state.destroy();\n }\n\n this.#state = new ElementState(this, this.#shadowRoot, options);\n this.#state.start();\n }\n\n disconnectedCallback() {\n LOG.debug(\"Shutting down application\");\n\n this.#state?.destroy();\n this.#state = undefined;\n\n LOG.debug(\"Application destroyed\");\n }\n\n when() {\n if (!this.#state) {\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.#state.whenAPI();\n }\n }\n return PioneerApplication;\n}\n\nclass ElementState {\n private hostElement: HTMLElement;\n private shadowRoot: ShadowRoot;\n private options: CustomElementOptions;\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 = \"not-started\" as \"not-started\" | \"starting\" | \"started\" | \"destroyed\";\n private locale: string | undefined;\n private container: HTMLDivElement | undefined;\n private config: ApplicationConfig | undefined;\n private serviceLayer: ServiceLayer | undefined;\n private lifecycleEvents: ApplicationLifecycleEventService | undefined;\n private reactIntegration: ReactIntegration | undefined;\n private stylesWatch: Resource | undefined;\n\n constructor(hostElement: HTMLElement, shadowRoot: ShadowRoot, options: CustomElementOptions) {\n this.hostElement = hostElement;\n this.shadowRoot = shadowRoot;\n this.options = options;\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 // TODO: Error splash?\n this.destroy();\n if (!isAbortError(e)) {\n logError(e);\n }\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.apiPromise?.reject(createAbortError());\n this.reactIntegration = destroyResource(this.reactIntegration);\n this.shadowRoot.replaceChildren();\n this.container = 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 { options, shadowRoot, hostElement } = this;\n\n // Resolve custom application config\n const config = (this.config = await gatherConfig(hostElement, options));\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(options.appMetadata, config.locale);\n this.checkAbort();\n\n // Setup application root node in the shadow dom\n const container = (this.container = createContainer(i18n.locale));\n const styles = this.initStyles();\n shadowRoot.replaceChildren(container, ...styles);\n\n // Launch the service layer\n const { serviceLayer, packages } = this.initServiceLayer({\n container,\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 = new ReactIntegration({\n rootNode: container,\n container: shadowRoot,\n theme: options.theme,\n serviceLayer,\n packages\n });\n this.render();\n this.state = \"started\";\n\n this.triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n private render() {\n this.reactIntegration?.render(this.options.component ?? emptyComponent);\n }\n\n private initStyles() {\n // Prevent inheritance of certain css values and normalize to display: block by default.\n // See https://open-wc.org/guides/knowledge/styling/styles-piercing-shadow-dom/\n const builtinStyles = \":host { all: initial; display: block; }\";\n const builtinStylesNode = document.createElement(\"style\");\n applyStyles(builtinStylesNode, { value: builtinStyles });\n\n const appStyles = this.options.appMetadata?.styles;\n const appStylesNode = document.createElement(\"style\");\n applyStyles(appStylesNode, appStyles);\n if (import.meta.hot) {\n this.stylesWatch = appStyles?.on?.(\"changed\", () => {\n LOG.debug(\"Application styles changed\");\n applyStyles(appStylesNode, appStyles);\n });\n }\n return [builtinStylesNode, appStylesNode];\n }\n\n private initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppI18n;\n }) {\n const options = this.options;\n const { container, properties, i18n } = config;\n const packageMetadata = options.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: this.hostElement,\n shadowRoot: this.shadowRoot,\n container: container,\n locale: i18n.locale,\n supportedLocales: i18n.supportedLocales\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\nfunction createContainer(locale: string) {\n // Setup application root node in the shadow dom\n const container = document.createElement(\"div\");\n container.classList.add(\"pioneer-root\");\n container.style.minHeight = \"100%\";\n container.style.height = \"100%\";\n if (locale) {\n container.lang = locale;\n }\n return container;\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppI18n;\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\n/**\n * Gathers application properties by reading them from the options object\n * and by (optionally) invoking the `resolveProperties` hook.\n */\nasync function gatherConfig(hostElement: HTMLElement, options: CustomElementOptions) {\n let configs: ApplicationConfig[];\n try {\n const staticConfig = options.config ?? {};\n const dynamicConfig =\n (await options.resolveConfig?.({\n getAttribute(name) {\n return hostElement.getAttribute(name) ?? undefined;\n }\n })) ?? {};\n\n configs = [staticConfig, dynamicConfig];\n } catch (e) {\n throw new Error(\n ErrorId.CONFIG_RESOLUTION_FAILED,\n \"Failed to resolve application properties.\",\n {\n cause: e\n }\n );\n }\n\n return mergeConfigs(configs);\n}\n\n/**\n * Merges application configurations into a single object.\n * Properties / config parameters at a later position overwrite properties from earlier ones.\n */\nfunction mergeConfigs(configs: ApplicationConfig[]): Required<ApplicationConfig> {\n // Merge simple values by assigning them in order\n const mergedConfig: Required<ApplicationConfig> = Object.assign(\n {\n locale: undefined,\n properties: {}\n } satisfies ApplicationConfig,\n ...configs\n );\n\n // Deep merge for application properties\n const mergedProperties: ApplicationProperties = (mergedConfig.properties = {});\n for (const config of configs) {\n for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {\n const mergedPackageProps = (mergedProperties[packageName] ??= {});\n Object.assign(mergedPackageProps, packageProperties);\n }\n }\n\n return mergedConfig;\n}\n\n// Applies application styles to the given style node.\n// Can be called multiple times in development mode to implement hot reloading.\nfunction applyStyles(styleNode: HTMLStyleElement, styles: { value: string } | undefined) {\n let cssValue = styles?.value ?? \"\";\n // Remove sourcemaps from inline css.\n // This currently does not work because a) the 'importer' (the index.html file) does not\n // match the actual path the source map would exist and b) vite refuses to generate it anyway, probably\n // because of our virtual modules.\n // TODO: both should be fixed once we can refer to actual `.css` files\n // and don't have to embed inline css anymore.\n cssValue = cssValue.replace(/\\/\\*# sourceMappingURL=.*$/, \"\");\n const cssNode = document.createTextNode(cssValue);\n styleNode.replaceChildren(cssNode);\n}\n\nfunction logError(e: unknown) {\n if (e instanceof Error) {\n const chain = getErrorChain(e).reverse();\n if (chain.length === 1) {\n console.error(e);\n return;\n }\n\n let n = 1;\n for (const error of chain) {\n console.error(`#${n}`, error);\n ++n;\n }\n } else {\n console.error(\"Unexpected error\", e);\n }\n}\n\nfunction emptyComponent() {\n return null;\n}\n"],"names":[],"mappings":";;;;;;;;AA8BA,MAAM,GAAA,GAAM,aAAa,uBAAuB,CAAA,CAAA;AAmHzC,SAAS,oBAAoB,OAA8D,EAAA;AAAA,EAC9F,MAAM,2BAA2B,WAA0C,CAAA;AAAA,IACvE,WAAA,CAAA;AAAA,IACA,MAAA,CAAA;AAAA,IAEA,WAAW,kBAA+B,GAAA;AACtC,MAAA,OAAO,EAAC,CAAA;AAAA,KACZ;AAAA,IAEA,WAAc,GAAA;AACV,MAAM,KAAA,EAAA,CAAA;AAEN,MAAK,IAAA,CAAA,WAAA,GAAc,KAAK,YAAa,CAAA;AAAA,QACjC,IAAM,EAAA,MAAA;AAAA,OACT,CAAA,CAAA;AAED,MAAI,IAAA,MAAA,CAAA,IAAA,CAAY,IAAI,GAAK,EAAA;AAErB,QAAC,IAAA,CAAa,oBAAuB,GAAA,MAAM,IAAK,CAAA,MAAA,CAAA;AAAA,OACpD;AAAA,KACJ;AAAA,IA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MAAA,OAAA,CAAQ,MAAM,CAAC,CAAA,CAAA;AACf,MAAA,OAAA;AAAA,KACJ;AAEA,IAAA,IAAI,CAAI,GAAA,CAAA,CAAA;AACR,IAAA,KAAA,MAAW,SAAS,KAAO,EAAA;AACvB,MAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA;AAC5B,MAAE,EAAA,CAAA,CAAA;AAAA,KACN;AAAA,GACG,MAAA;AACH,IAAQ,OAAA,CAAA,KAAA,CAAM,oBAAoB,CAAC,CAAA,CAAA;AAAA,GACvC;AACJ,CAAA;AAEA,SAAS,cAAiB,GAAA;AACtB,EAAO,OAAA,IAAA,CAAA;AACX;;;;"}
@@ -0,0 +1,52 @@
1
+ declare const INTERNAL_ASSOCIATED_SERVICE_METADATA: unique symbol;
2
+ declare const ERROR: unique symbol;
3
+ /**
4
+ * Base interface for services that are associated with a well known interface name.
5
+ *
6
+ * By using this base interface, you can ensure that users of your interface use the correct interface name.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // MyLogger should be referenced via "my-package.Logger"
11
+ * export interface MyLogger extends DeclaredService<"my-package.Logger"> {
12
+ * log(message: string): void;
13
+ * }
14
+ * ```
15
+ *
16
+ * > Note: TypeScript may list the `INTERNAL_ASSOCIATED_SERVICE_METADATA` property
17
+ * > when generating the implementation for an interface extending this type.
18
+ * > You can simply remove the offending line; it is not required (and not possible)
19
+ * > to implement that attribute - it only exists for the compiler.
20
+ */
21
+ export interface DeclaredService<InterfaceName extends string> {
22
+ /**
23
+ * Internal type-level service metadata.
24
+ *
25
+ * Note: there is no need to implement this symbol attribute.
26
+ * It is optional and only exists for the compiler, never at runtime.
27
+ *
28
+ * @internal
29
+ */
30
+ [INTERNAL_ASSOCIATED_SERVICE_METADATA]?: ServiceMetadata<InterfaceName>;
31
+ }
32
+ /**
33
+ * Given a type implementing {@link DeclaredService}, this type will produce the interface name associated with the service type.
34
+ */
35
+ export type AssociatedInterfaceName<T extends DeclaredService<string>> = T extends DeclaredService<infer InterfaceName> ? InterfaceName : never;
36
+ /**
37
+ * This helper type produces the expected `interfaceName` (a string parameter) for the given service type.
38
+ *
39
+ * 1. If `ServiceType` is `unknown`, it will produce `string` to allow arbitrary parameters.
40
+ * 2. If `ServiceType` implements {@link DeclaredService}, it will enforce the associated interface name.
41
+ * 3. Otherwise, a compile time error is generated.
42
+ */
43
+ export type InterfaceNameForServiceType<ServiceType> = unknown extends ServiceType ? string : ServiceType extends DeclaredService<string> ? AssociatedInterfaceName<ServiceType> : {
44
+ [ERROR]: "TypeScript integration was not set up properly for this service. Make sure the service's TypeScript interface extends 'DeclaredService'.";
45
+ };
46
+ /**
47
+ * @internal
48
+ */
49
+ interface ServiceMetadata<InterfaceName> {
50
+ interfaceName: InterfaceName;
51
+ }
52
+ export {};
package/README.md CHANGED
@@ -26,7 +26,7 @@ HTML sites or JavaScript code can now instantiate the application by creating a
26
26
 
27
27
  ```html
28
28
  <!-- some-site/index.html -->
29
- <!DOCTYPE html>
29
+ <!doctype html>
30
30
  <html>
31
31
  <body>
32
32
  <!-- Contains the app once the script has been loaded -->
@@ -38,4 +38,4 @@ HTML sites or JavaScript code can now instantiate the application by creating a
38
38
 
39
39
  ## License
40
40
 
41
- [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
41
+ Apache-2.0 (see `LICENSE` file)
package/api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { DeclaredService } from "./DeclaredService";
1
2
  export type ApiMethod = (...args: any[]) => any;
2
3
  /**
3
4
  * A record of exposed functions.
@@ -16,7 +17,7 @@ export interface ApiExtension {
16
17
  * A service provided by the system.
17
18
  * Used by the runtime to assemble the public facing API.
18
19
  */
19
- export interface ApiService {
20
+ export interface ApiService extends DeclaredService<"runtime.ApiService"> {
20
21
  /**
21
22
  * Called by the runtime to gather methods that should be available from the web component's API.
22
23
  */
@@ -25,7 +26,7 @@ export interface ApiService {
25
26
  /**
26
27
  * A service provided by the system, useful for accessing values that are global to the application.
27
28
  */
28
- export interface ApplicationContext {
29
+ export interface ApplicationContext extends DeclaredService<"runtime.ApplicationContext"> {
29
30
  /**
30
31
  * The web component's host element.
31
32
  * This dom node can be accessed by the host site.
@@ -60,7 +61,7 @@ export interface ApplicationContext {
60
61
  * **Experimental**. This interface is not affected by semver guarantees.
61
62
  * It may change (or be removed) in a future minor release.
62
63
  */
63
- export interface ApplicationLifecycleListener {
64
+ export interface ApplicationLifecycleListener extends DeclaredService<"runtime.ApplicationLifecycleListener"> {
64
65
  /**
65
66
  * Called after all services required by the application have been started.
66
67
  */
@@ -70,10 +71,3 @@ export interface ApplicationLifecycleListener {
70
71
  */
71
72
  beforeApplicationStop?(): void;
72
73
  }
73
- declare module "./ServiceRegistry" {
74
- interface ServiceRegistry {
75
- "runtime.ApiService": ApiService;
76
- "runtime.ApplicationContext": ApplicationContext;
77
- "runtime.ApplicationLifecycleListener": ApplicationLifecycleListener;
78
- }
79
- }
@@ -1 +1 @@
1
- {"version":3,"file":"ApiServiceImpl.js","sources":["ApiServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { ServiceOptions } from \"../Service\";\nimport { ApiExtension, ApiMethod, ApiMethods, ApiService } from \"../api\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\n\ninterface References {\n providers: ApiExtension[];\n}\n\nexport class ApiServiceImpl implements ApiService {\n private readonly providers: [serviceId: string, provider: ApiExtension][];\n\n constructor(options: ServiceOptions<References>) {\n const providers = options.references.providers;\n const meta = options.referencesMeta.providers;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.providers = providers.map((provider, index) => [meta[index]!.serviceId, provider]);\n }\n\n async getApi() {\n interface ProviderResult {\n serviceId: string;\n methods: ApiMethods;\n }\n\n const promises = this.providers.map(async ([serviceId, provider]) => {\n const methods = await provider.getApiMethods();\n const result: ProviderResult = {\n serviceId,\n methods\n };\n return result;\n });\n const providerMethods = await Promise.all(promises);\n\n interface MethodEntry {\n method: ApiMethod;\n serviceId: string;\n }\n\n const methodEntries = new Map<string, MethodEntry>();\n for (const { serviceId, methods } of providerMethods) {\n for (const [methodName, method] of Object.entries(methods)) {\n const existingEntry = methodEntries.get(methodName);\n if (existingEntry) {\n throw new Error(\n ErrorId.DUPLICATE_API_METHODS,\n `Cannot define API method '${methodName}' from '${serviceId}' (method is also defined by '${existingEntry.serviceId}').`\n );\n }\n\n methodEntries.set(methodName, {\n serviceId,\n method\n });\n }\n }\n\n const api: Record<string, ApiMethod> = {};\n for (const [methodName, entry] of methodEntries.entries()) {\n api[methodName] = entry.method;\n }\n return api;\n }\n}\n"],"names":[],"mappings":";;;AAWO,MAAM,cAAqC,CAAA;AAAA,EAC7B,SAAA,CAAA;AAAA,EAEjB,YAAY,OAAqC,EAAA;AAC7C,IAAM,MAAA,SAAA,GAAY,QAAQ,UAAW,CAAA,SAAA,CAAA;AACrC,IAAM,MAAA,IAAA,GAAO,QAAQ,cAAe,CAAA,SAAA,CAAA;AAEpC,IAAA,IAAA,CAAK,SAAY,GAAA,SAAA,CAAU,GAAI,CAAA,CAAC,QAAU,EAAA,KAAA,KAAU,CAAC,IAAA,CAAK,KAAK,CAAA,CAAG,SAAW,EAAA,QAAQ,CAAC,CAAA,CAAA;AAAA,GAC1F;AAAA,EAEA,MAAM,MAAS,GAAA;AAMX,IAAM,MAAA,QAAA,GAAW,KAAK,SAAU,CAAA,GAAA,CAAI,OAAO,CAAC,SAAA,EAAW,QAAQ,CAAM,KAAA;AACjE,MAAM,MAAA,OAAA,GAAU,MAAM,QAAA,CAAS,aAAc,EAAA,CAAA;AAC7C,MAAA,MAAM,MAAyB,GAAA;AAAA,QAC3B,SAAA;AAAA,QACA,OAAA;AAAA,OACJ,CAAA;AACA,MAAO,OAAA,MAAA,CAAA;AAAA,KACV,CAAA,CAAA;AACD,IAAA,MAAM,eAAkB,GAAA,MAAM,OAAQ,CAAA,GAAA,CAAI,QAAQ,CAAA,CAAA;AAOlD,IAAM,MAAA,aAAA,uBAAoB,GAAyB,EAAA,CAAA;AACnD,IAAA,KAAA,MAAW,EAAE,SAAA,EAAW,OAAQ,EAAA,IAAK,eAAiB,EAAA;AAClD,MAAA,KAAA,MAAW,CAAC,UAAY,EAAA,MAAM,KAAK,MAAO,CAAA,OAAA,CAAQ,OAAO,CAAG,EAAA;AACxD,QAAM,MAAA,aAAA,GAAgB,aAAc,CAAA,GAAA,CAAI,UAAU,CAAA,CAAA;AAClD,QAAA,IAAI,aAAe,EAAA;AACf,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAQ,CAAA,qBAAA;AAAA,YACR,CAAA,0BAAA,EAA6B,UAAqB,CAAA,QAAA,EAAA,SAAA,CAAA,8BAAA,EAA0C,aAAc,CAAA,SAAA,CAAA,GAAA,CAAA;AAAA,WAC9G,CAAA;AAAA,SACJ;AAEA,QAAA,aAAA,CAAc,IAAI,UAAY,EAAA;AAAA,UAC1B,SAAA;AAAA,UACA,MAAA;AAAA,SACH,CAAA,CAAA;AAAA,OACL;AAAA,KACJ;AAEA,IAAA,MAAM,MAAiC,EAAC,CAAA;AACxC,IAAA,KAAA,MAAW,CAAC,UAAY,EAAA,KAAK,CAAK,IAAA,aAAA,CAAc,SAAW,EAAA;AACvD,MAAI,GAAA,CAAA,UAAU,IAAI,KAAM,CAAA,MAAA,CAAA;AAAA,KAC5B;AACA,IAAO,OAAA,GAAA,CAAA;AAAA,GACX;AACJ;;;;"}
1
+ {"version":3,"file":"ApiServiceImpl.js","sources":["ApiServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ServiceOptions } from \"../Service\";\nimport { ApiExtension, ApiMethod, ApiMethods, ApiService } from \"../api\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\n\ninterface References {\n providers: ApiExtension[];\n}\n\nexport class ApiServiceImpl implements ApiService {\n private readonly providers: [serviceId: string, provider: ApiExtension][];\n\n constructor(options: ServiceOptions<References>) {\n const providers = options.references.providers;\n const meta = options.referencesMeta.providers;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.providers = providers.map((provider, index) => [meta[index]!.serviceId, provider]);\n }\n\n async getApi() {\n interface ProviderResult {\n serviceId: string;\n methods: ApiMethods;\n }\n\n const promises = this.providers.map(async ([serviceId, provider]) => {\n const methods = await provider.getApiMethods();\n const result: ProviderResult = {\n serviceId,\n methods\n };\n return result;\n });\n const providerMethods = await Promise.all(promises);\n\n interface MethodEntry {\n method: ApiMethod;\n serviceId: string;\n }\n\n const methodEntries = new Map<string, MethodEntry>();\n for (const { serviceId, methods } of providerMethods) {\n for (const [methodName, method] of Object.entries(methods)) {\n const existingEntry = methodEntries.get(methodName);\n if (existingEntry) {\n throw new Error(\n ErrorId.DUPLICATE_API_METHODS,\n `Cannot define API method '${methodName}' from '${serviceId}' (method is also defined by '${existingEntry.serviceId}').`\n );\n }\n\n methodEntries.set(methodName, {\n serviceId,\n method\n });\n }\n }\n\n const api: Record<string, ApiMethod> = {};\n for (const [methodName, entry] of methodEntries.entries()) {\n api[methodName] = entry.method;\n }\n return api;\n }\n}\n"],"names":[],"mappings":";;;AAWO,MAAM,cAAqC,CAAA;AAAA,EAC7B,SAAA,CAAA;AAAA,EAEjB,YAAY,OAAqC,EAAA;AAC7C,IAAM,MAAA,SAAA,GAAY,QAAQ,UAAW,CAAA,SAAA,CAAA;AACrC,IAAM,MAAA,IAAA,GAAO,QAAQ,cAAe,CAAA,SAAA,CAAA;AAEpC,IAAA,IAAA,CAAK,SAAY,GAAA,SAAA,CAAU,GAAI,CAAA,CAAC,QAAU,EAAA,KAAA,KAAU,CAAC,IAAA,CAAK,KAAK,CAAA,CAAG,SAAW,EAAA,QAAQ,CAAC,CAAA,CAAA;AAAA,GAC1F;AAAA,EAEA,MAAM,MAAS,GAAA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IAAO,OAAA,GAAA,CAAA;AAAA,GACX;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ApplicationContextImpl.js","sources":["ApplicationContextImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { ApplicationContext } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nexport interface ApplicationContextProperties {\n host: HTMLElement;\n shadowRoot: ShadowRoot;\n container: HTMLElement;\n locale: string;\n supportedLocales: string[];\n}\n\nexport class ApplicationContextImpl implements ApplicationContext {\n #host: HTMLElement;\n #shadowRoot: ShadowRoot;\n #container: HTMLElement;\n #locale: string;\n #supportedLocales: readonly string[];\n\n constructor(options: ServiceOptions, properties: ApplicationContextProperties) {\n this.#host = properties.host;\n this.#shadowRoot = properties.shadowRoot;\n this.#container = properties.container;\n this.#locale = properties.locale;\n this.#supportedLocales = Object.freeze(Array.from(properties.supportedLocales));\n }\n\n getHostElement(): HTMLElement {\n return this.#host;\n }\n\n getShadowRoot(): ShadowRoot {\n return this.#shadowRoot;\n }\n\n getApplicationContainer(): HTMLElement {\n return this.#container;\n }\n\n getLocale(): string {\n return this.#locale;\n }\n\n getSupportedLocales(): readonly string[] {\n return this.#supportedLocales;\n }\n}\n"],"names":[],"mappings":"AAaO,MAAM,sBAAqD,CAAA;AAAA,EAC9D,KAAA,CAAA;AAAA,EACA,WAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EACA,OAAA,CAAA;AAAA,EACA,iBAAA,CAAA;AAAA,EAEA,WAAA,CAAY,SAAyB,UAA0C,EAAA;AAC3E,IAAA,IAAA,CAAK,QAAQ,UAAW,CAAA,IAAA,CAAA;AACxB,IAAA,IAAA,CAAK,cAAc,UAAW,CAAA,UAAA,CAAA;AAC9B,IAAA,IAAA,CAAK,aAAa,UAAW,CAAA,SAAA,CAAA;AAC7B,IAAA,IAAA,CAAK,UAAU,UAAW,CAAA,MAAA,CAAA;AAC1B,IAAA,IAAA,CAAK,oBAAoB,MAAO,CAAA,MAAA,CAAO,MAAM,IAAK,CAAA,UAAA,CAAW,gBAAgB,CAAC,CAAA,CAAA;AAAA,GAClF;AAAA,EAEA,cAA8B,GAAA;AAC1B,IAAA,OAAO,IAAK,CAAA,KAAA,CAAA;AAAA,GAChB;AAAA,EAEA,aAA4B,GAAA;AACxB,IAAA,OAAO,IAAK,CAAA,WAAA,CAAA;AAAA,GAChB;AAAA,EAEA,uBAAuC,GAAA;AACnC,IAAA,OAAO,IAAK,CAAA,UAAA,CAAA;AAAA,GAChB;AAAA,EAEA,SAAoB,GAAA;AAChB,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GAChB;AAAA,EAEA,mBAAyC,GAAA;AACrC,IAAA,OAAO,IAAK,CAAA,iBAAA,CAAA;AAAA,GAChB;AACJ;;;;"}
1
+ {"version":3,"file":"ApplicationContextImpl.js","sources":["ApplicationContextImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ApplicationContext } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nexport interface ApplicationContextProperties {\n host: HTMLElement;\n shadowRoot: ShadowRoot;\n container: HTMLElement;\n locale: string;\n supportedLocales: string[];\n}\n\nexport class ApplicationContextImpl implements ApplicationContext {\n #host: HTMLElement;\n #shadowRoot: ShadowRoot;\n #container: HTMLElement;\n #locale: string;\n #supportedLocales: readonly string[];\n\n constructor(options: ServiceOptions, properties: ApplicationContextProperties) {\n this.#host = properties.host;\n this.#shadowRoot = properties.shadowRoot;\n this.#container = properties.container;\n this.#locale = properties.locale;\n this.#supportedLocales = Object.freeze(Array.from(properties.supportedLocales));\n }\n\n getHostElement(): HTMLElement {\n return this.#host;\n }\n\n getShadowRoot(): ShadowRoot {\n return this.#shadowRoot;\n }\n\n getApplicationContainer(): HTMLElement {\n return this.#container;\n }\n\n getLocale(): string {\n return this.#locale;\n }\n\n getSupportedLocales(): readonly string[] {\n return this.#supportedLocales;\n }\n}\n"],"names":[],"mappings":"AAaO,MAAM,sBAAqD,CAAA;AAAA,EAC9D,KAAA,CAAA;AAAA,EACA,WAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EACA,OAAA,CAAA;AAAA,EACA,iBAAA,CAAA;AAAA,EAEA,WAAA,CAAY,SAAyB,UAA0C,EAAA;AAC3E,IAAA,IAAA,CAAK,QAAQ,UAAW,CAAA,IAAA,CAAA;AACxB,IAAA,IAAA,CAAK,cAAc,UAAW,CAAA,UAAA,CAAA;AAC9B,IAAA,IAAA,CAAK,aAAa,UAAW,CAAA,SAAA,CAAA;AAC7B,IAAA,IAAA,CAAK,UAAU,UAAW,CAAA,MAAA,CAAA;AAC1B,IAAA,IAAA,CAAK,oBAAoB,MAAO,CAAA,MAAA,CAAO,MAAM,IAAK,CAAA,UAAA,CAAW,gBAAgB,CAAC,CAAA,CAAA;AAAA,GAClF;AAAA,EAEA,cAA8B,GAAA;AAC1B,IAAA,OAAO,IAAK,CAAA,KAAA,CAAA;AAAA,GAChB;AAAA,EAEA,aAA4B,GAAA;AACxB,IAAA,OAAO,IAAK,CAAA,WAAA,CAAA;AAAA,GAChB;AAAA,EAEA,uBAAuC,GAAA;AACnC,IAAA,OAAO,IAAK,CAAA,UAAA,CAAA;AAAA,GAChB;AAAA,EAEA,SAAoB,GAAA;AAChB,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GAChB;AAAA,EAEA,mBAAyC,GAAA;AACrC,IAAA,OAAO,IAAK,CAAA,iBAAA,CAAA;AAAA,GAChB;AACJ;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { ServiceOptions } from "../Service";
2
- import { ServiceType } from "../ServiceRegistry";
2
+ import { ApplicationLifecycleListener } from "../api";
3
3
  interface References {
4
- listeners: ServiceType<"runtime.ApplicationLifecycleListener">[];
4
+ listeners: ApplicationLifecycleListener[];
5
5
  }
6
6
  export declare class ApplicationLifecycleEventService {
7
7
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"ApplicationLifecycleEventService.js","sources":["ApplicationLifecycleEventService.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger } from \"@open-pioneer/core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ServiceOptions } from \"../Service\";\nimport { ServiceType } from \"../ServiceRegistry\";\nimport { ApplicationLifecycleListener } from \"../api\";\nimport { ErrorId } from \"../errors\";\n\nconst LOG = createLogger(\"runtime:ApplicationLifecycleEventService\");\n\ninterface References {\n listeners: ServiceType<\"runtime.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":";;;AAUA,MAAM,GAAA,GAAM,aAAa,0CAA0C,CAAA,CAAA;AAM5D,MAAM,gCAAiC,CAAA;AAAA,EAC1C,UAAA,CAAA;AAAA,EAEA,YAAY,OAAqC,EAAA;AAC7C,IAAM,MAAA,SAAA,GAAY,QAAQ,UAAW,CAAA,SAAA,CAAA;AACrC,IAAM,MAAA,aAAA,GAAgB,QAAQ,cAAe,CAAA,SAAA,CAAA;AAC7C,IAAA,IAAA,CAAK,UAAa,GAAA,SAAA,CAAU,GAAI,CAAA,CAAC,UAAU,KAAU,KAAA;AAAA;AAAA,MAEjD,aAAA,CAAc,KAAK,CAAG,CAAA,SAAA;AAAA,MACtB,QAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AAAA;AAAA,EAGA,mBAAmB,KAA4C,EAAA;AAC3D,IAAA,MAAM,cAAc,MAAM;AACtB,MAAA,QAAQ,KAAO;AAAA,QACX,KAAK,aAAA;AACD,UAAO,OAAA,uBAAA,CAAA;AAAA,QACX,KAAK,aAAA;AACD,UAAO,OAAA,uBAAA,CAAA;AAAA,QACX;AACI,UAAA,MAAM,IAAI,KAAA,CAAM,OAAQ,CAAA,QAAA,EAAU,kBAAkB,KAAQ,CAAA,CAAA,CAAA,CAAA,CAAA;AAAA,OACpE;AAAA,KACD,GAAA,CAAA;AACH,IAAA,KAAA,MAAW,CAAC,SAAA,EAAW,QAAQ,CAAA,IAAK,KAAK,UAAY,EAAA;AACjD,MAAI,IAAA;AACA,QAAA,QAAA,CAAS,UAAU,CAAI,IAAA,CAAA;AAAA,eAClB,CAAP,EAAA;AACE,QAAI,GAAA,CAAA,KAAA,CAAM,CAAwD,qDAAA,EAAA,SAAA,CAAA,CAAA,EAAa,CAAC,CAAA,CAAA;AAAA,OACpF;AAAA,KACJ;AAAA,GACJ;AACJ;;;;"}
1
+ {"version":3,"file":"ApplicationLifecycleEventService.js","sources":["ApplicationLifecycleEventService.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger } from \"@open-pioneer/core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ServiceOptions } from \"../Service\";\nimport { ApplicationLifecycleListener } from \"../api\";\nimport { ErrorId } from \"../errors\";\n\nconst LOG = createLogger(\"runtime:ApplicationLifecycleEventService\");\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,0CAA0C,CAAA,CAAA;AAM5D,MAAM,gCAAiC,CAAA;AAAA,EAC1C,UAAA,CAAA;AAAA,EAEA,YAAY,OAAqC,EAAA;AAC7C,IAAM,MAAA,SAAA,GAAY,QAAQ,UAAW,CAAA,SAAA,CAAA;AACrC,IAAM,MAAA,aAAA,GAAgB,QAAQ,cAAe,CAAA,SAAA,CAAA;AAC7C,IAAA,IAAA,CAAK,UAAa,GAAA,SAAA,CAAU,GAAI,CAAA,CAAC,UAAU,KAAU,KAAA;AAAA;AAAA,MAEjD,aAAA,CAAc,KAAK,CAAG,CAAA,SAAA;AAAA,MACtB,QAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AAAA;AAAA,EAGA,mBAAmB,KAA4C,EAAA;AAC3D,IAAA,MAAM,cAAc,MAAM;AACtB,MAAA,QAAQ,KAAO;AAAA,QACX,KAAK,aAAA;AACD,UAAO,OAAA,uBAAA,CAAA;AAAA,QACX,KAAK,aAAA;AACD,UAAO,OAAA,uBAAA,CAAA;AAAA,QACX;AACI,UAAA,MAAM,IAAI,KAAM,CAAA,OAAA,CAAQ,QAAU,EAAA,CAAA,eAAA,EAAkB,KAAK,CAAG,CAAA,CAAA,CAAA,CAAA;AAAA,OACpE;AAAA,KACD,GAAA,CAAA;AACH,IAAA,KAAA,MAAW,CAAC,SAAA,EAAW,QAAQ,CAAA,IAAK,KAAK,UAAY,EAAA;AACjD,MAAI,IAAA;AACA,QAAA,QAAA,CAAS,UAAU,CAAI,IAAA,CAAA;AAAA,eAClB,CAAG,EAAA;AACR,QAAA,GAAA,CAAI,KAAM,CAAA,CAAA,qDAAA,EAAwD,SAAS,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA;AAAA,OACpF;AAAA,KACJ;AAAA,GACJ;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { createEmptyI18n } from \"../i18n\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport {\n createConstructorFactory,\n createFunctionFactory,\n ServiceRepr\n} from \"../service-layer/ServiceRepr\";\nimport { ApiServiceImpl } from \"./ApiServiceImpl\";\nimport { ApplicationContextImpl, ApplicationContextProperties } from \"./ApplicationContextImpl\";\nimport { ApplicationLifecycleEventService } from \"./ApplicationLifecycleEventService\";\n\nexport const RUNTIME_PACKAGE_NAME = \"@open-pioneer/runtime\";\nexport const RUNTIME_API_EXTENSION = \"integration.ApiExtension\";\nexport const RUNTIME_API_SERVICE = \"runtime.ApiService\";\nexport const RUNTIME_APPLICATION_CONTEXT = \"runtime.ApplicationContext\";\nexport const RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE =\n \"runtime.ApplicationLifecycleEventService\";\nexport const RUNTIME_AUTO_START = \"runtime.AutoStart\";\n\nexport type BuiltinPackageProperties = ApplicationContextProperties;\n\n/**\n * Creates the builtin package containing the builtin services.\n *\n * The runtime package should not use services in the `build.config.mjs`\n * for a clean bootstrapping procedure (it will be instantiated without\n * generated application metadata in tests).\n *\n * This function is called as part of the service layer startup.\n * The package produced here is always part of the application.\n */\nexport function createBuiltinPackage(properties: BuiltinPackageProperties): PackageRepr {\n const i18n = createEmptyI18n();\n const apiService = new ServiceRepr({\n name: \"ApiServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApiServiceImpl),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_API_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"providers\",\n interfaceName: RUNTIME_API_EXTENSION,\n all: true\n }\n ]\n });\n const appContext = new ServiceRepr({\n name: \"ApplicationContextImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(\n (options) => new ApplicationContextImpl(options, properties)\n ),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ]\n });\n const lifecycleEventService = new ServiceRepr({\n name: \"ApplicationLifecycleEventServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApplicationLifecycleEventService),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"listeners\",\n interfaceName: \"runtime.ApplicationLifecycleListener\",\n all: true\n }\n ]\n });\n\n return new PackageRepr({\n name: RUNTIME_PACKAGE_NAME,\n services: [apiService, appContext, lifecycleEventService],\n intl: i18n\n });\n}\n"],"names":[],"mappings":";;;;;;;AAaO,MAAM,oBAAuB,GAAA,wBAAA;AAC7B,MAAM,qBAAwB,GAAA,2BAAA;AAC9B,MAAM,mBAAsB,GAAA,qBAAA;AAC5B,MAAM,2BAA8B,GAAA,6BAAA;AACpC,MAAM,2CACT,GAAA,2CAAA;AACG,MAAM,kBAAqB,GAAA,oB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AA,KACJ;AAAA,IACA,YAAc,EAAA;AAAA,MACV;AAAA,QACI,aAAe,EAAA,WAAA;AAAA,QACf,aAAe,EAAA,sCAAA;AAAA,QACf,GAAK,EAAA,IAAA;AAAA,OACT;AAAA,KACJ;AAAA,GACH,CAAA,CAAA;AAED,EAAA,OAAO,IAAI,WAAY,CAAA;AAAA,IACnB,IAAM,EAAA,oBAAA;AAAA,IACN,QAAU,EAAA,CAAC,UAAY,EAAA,UAAA,EAAY,qBAAqB,CAAA;AAAA,IACxD,IAAM,EAAA,IAAA;AAAA,GACT,CAAA,CAAA;AACL;;;;"}
1
+ {"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createEmptyI18n } from \"../i18n\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport {\n createConstructorFactory,\n createFunctionFactory,\n ServiceRepr\n} from \"../service-layer/ServiceRepr\";\nimport { ApiServiceImpl } from \"./ApiServiceImpl\";\nimport { ApplicationContextImpl, ApplicationContextProperties } from \"./ApplicationContextImpl\";\nimport { ApplicationLifecycleEventService } from \"./ApplicationLifecycleEventService\";\n\nexport const RUNTIME_PACKAGE_NAME = \"@open-pioneer/runtime\";\nexport const RUNTIME_API_EXTENSION = \"integration.ApiExtension\";\nexport const RUNTIME_API_SERVICE = \"runtime.ApiService\";\nexport const RUNTIME_APPLICATION_CONTEXT = \"runtime.ApplicationContext\";\nexport const RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE =\n \"runtime.ApplicationLifecycleEventService\";\nexport const RUNTIME_AUTO_START = \"runtime.AutoStart\";\n\nexport type BuiltinPackageProperties = ApplicationContextProperties;\n\n/**\n * Creates the builtin package containing the builtin services.\n *\n * The runtime package should not use services in the `build.config.mjs`\n * for a clean bootstrapping procedure (it will be instantiated without\n * generated application metadata in tests).\n *\n * This function is called as part of the service layer startup.\n * The package produced here is always part of the application.\n */\nexport function createBuiltinPackage(properties: BuiltinPackageProperties): PackageRepr {\n const i18n = createEmptyI18n();\n const apiService = new ServiceRepr({\n name: \"ApiServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApiServiceImpl),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_API_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"providers\",\n interfaceName: RUNTIME_API_EXTENSION,\n all: true\n }\n ]\n });\n const appContext = new ServiceRepr({\n name: \"ApplicationContextImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(\n (options) => new ApplicationContextImpl(options, properties)\n ),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ]\n });\n const lifecycleEventService = new ServiceRepr({\n name: \"ApplicationLifecycleEventServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApplicationLifecycleEventService),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"listeners\",\n interfaceName: \"runtime.ApplicationLifecycleListener\",\n all: true\n }\n ]\n });\n\n return new PackageRepr({\n name: RUNTIME_PACKAGE_NAME,\n services: [apiService, appContext, lifecycleEventService],\n intl: i18n\n });\n}\n"],"names":[],"mappings":";;;;;;;AAaO,MAAM,oBAAuB,GAAA,wBAAA;AAC7B,MAAM,qBAAwB,GAAA,2BAAA;AAC9B,MAAM,mBAAsB,GAAA,qBAAA;AAC5B,MAAM,2BAA8B,GAAA,6BAAA;AACpC,MAAM,2CACT,GAAA,2CAAA;AACG,MAAM,kBAAqB,GAAA,oBAAA;AAc3B,SAAS,qBAAqB,UAAmD,EAAA;AACpF,EAAA,MAAM,OAAO,eAAgB,EAAA,CAAA;AAC7B,EAAM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sCAAA;AAAA,QACf,GAAK,EAAA,IAAA;AAAA,OACT;AAAA,KACJ;AAAA,GACH,CAAA,CAAA;AAED,EAAA,OAAO,IAAI,WAAY,CAAA;AAAA,IACnB,IAAM,EAAA,oBAAA;AAAA,IACN,QAAU,EAAA,CAAC,UAAY,EAAA,UAAA,EAAY,qBAAqB,CAAA;AAAA,IACxD,IAAM,EAAA,IAAA;AAAA,GACT,CAAA,CAAA;AACL;;;;"}
package/errors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sources":["errors.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nexport enum ErrorId {\n // Problems with application metadata\n INVALID_METADATA = \"runtime:invalid-metadata\",\n INVALID_PROPERTY_NAME = \"runtime:invalid-property-name\",\n REQUIRED_PROPERTY = \"runtime:required-property\",\n\n // Application lifecycle\n NOT_MOUNTED = \"runtime:element-not-mounted\",\n UNSUPPORTED_LOCALE = \"runtime:unsupported-locale\",\n CONFIG_RESOLUTION_FAILED = \"runtime:config-resolution-failed\",\n\n // Service layer\n INTERFACE_NOT_FOUND = \"runtime:interface-not-found\",\n AMBIGUOUS_DEPENDENCY = \"runtime:ambiguous-dependency\",\n UNDECLARED_DEPENDENCY = \"runtime:undeclared-dependency\",\n SERVICE_CONSTRUCTION_FAILED = \"runtime:service-construction-failed\",\n SERVICE_DESTRUCTION_FAILED = \"runtime:service-destruction-failed\",\n DUPLICATE_INTERFACE = \"runtime:duplicate-interface\",\n DEPENDENCY_CYCLE = \"runtime:dependency-cycle\",\n\n // Web component API\n DUPLICATE_API_METHODS = \"runtime:duplicate-api-methods\",\n\n // Internal\n INTERNAL = \"runtime:internal-error\"\n}\n"],"names":["ErrorId"],"mappings":"AAEY,IAAA,OAAA,qBAAAA,QAAL,KAAA;AAEH,EAAAA,SAAA,kBAAmB,CAAA,GAAA,0BAAA,CAAA;AACnB,EAAAA,SAAA,uBAAwB,CAAA,GAAA,+BAAA,CAAA;AACxB,EAAAA,SAAA,mBAAoB,CAAA,GAAA,2BAAA,CAAA;AAGpB,EAAAA,SAAA,aAAc,CAAA,GAAA,6BAAA,CAAA;AACd,EAAAA,SAAA,oBAAqB,CAAA,GAAA,4BAAA,CAAA;AACrB,EAAAA,SAAA,0BAA2B,CAAA,GAAA,kCAAA,CAAA;AAG3B,EAAAA,SAAA,qBAAsB,CAAA,GAAA,6BAAA,CAAA;AACtB,EAAAA,SAAA,sBAAuB,CAAA,GAAA,8BAAA,CAAA;AACvB,EAAAA,SAAA,uBAAwB,CAAA,GAAA,+BAAA,CAAA;AACxB,EAAAA,SAAA,6BAA8B,CAAA,GAAA,qCAAA,CAAA;AAC9B,EAAAA,SAAA,4BAA6B,CAAA,GAAA,oCAAA,CAAA;AAC7B,EAAAA,SAAA,qBAAsB,CAAA,GAAA,6BAAA,CAAA;AACtB,EAAAA,SAAA,kBAAmB,CAAA,GAAA,0BAAA,CAAA;AAGnB,EAAAA,SAAA,uBAAwB,CAAA,GAAA,+BAAA,CAAA;AAGxB,EAAAA,SAAA,UAAW,CAAA,GAAA,wBAAA,CAAA;AAxBH,EAAAA,OAAAA,QAAAA,CAAAA;AAAA,CAAA,EAAA,OAAA,IAAA,EAAA;;;;"}
1
+ {"version":3,"file":"errors.js","sources":["errors.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nexport enum ErrorId {\n // Problems with application metadata\n INVALID_METADATA = \"runtime:invalid-metadata\",\n INVALID_PROPERTY_NAME = \"runtime:invalid-property-name\",\n REQUIRED_PROPERTY = \"runtime:required-property\",\n\n // Application lifecycle\n NOT_MOUNTED = \"runtime:element-not-mounted\",\n UNSUPPORTED_LOCALE = \"runtime:unsupported-locale\",\n CONFIG_RESOLUTION_FAILED = \"runtime:config-resolution-failed\",\n\n // Service layer\n INTERFACE_NOT_FOUND = \"runtime:interface-not-found\",\n AMBIGUOUS_DEPENDENCY = \"runtime:ambiguous-dependency\",\n UNDECLARED_DEPENDENCY = \"runtime:undeclared-dependency\",\n SERVICE_CONSTRUCTION_FAILED = \"runtime:service-construction-failed\",\n SERVICE_DESTRUCTION_FAILED = \"runtime:service-destruction-failed\",\n DUPLICATE_INTERFACE = \"runtime:duplicate-interface\",\n DEPENDENCY_CYCLE = \"runtime:dependency-cycle\",\n\n // Web component API\n DUPLICATE_API_METHODS = \"runtime:duplicate-api-methods\",\n\n // Internal\n INTERNAL = \"runtime:internal-error\"\n}\n"],"names":["ErrorId"],"mappings":"AAEY,IAAA,OAAA,qBAAAA,QAAL,KAAA;AAEH,EAAAA,SAAA,kBAAmB,CAAA,GAAA,0BAAA,CAAA;AACnB,EAAAA,SAAA,uBAAwB,CAAA,GAAA,+BAAA,CAAA;AACxB,EAAAA,SAAA,mBAAoB,CAAA,GAAA,2BAAA,CAAA;AAGpB,EAAAA,SAAA,aAAc,CAAA,GAAA,6BAAA,CAAA;AACd,EAAAA,SAAA,oBAAqB,CAAA,GAAA,4BAAA,CAAA;AACrB,EAAAA,SAAA,0BAA2B,CAAA,GAAA,kCAAA,CAAA;AAG3B,EAAAA,SAAA,qBAAsB,CAAA,GAAA,6BAAA,CAAA;AACtB,EAAAA,SAAA,sBAAuB,CAAA,GAAA,8BAAA,CAAA;AACvB,EAAAA,SAAA,uBAAwB,CAAA,GAAA,+BAAA,CAAA;AACxB,EAAAA,SAAA,6BAA8B,CAAA,GAAA,qCAAA,CAAA;AAC9B,EAAAA,SAAA,4BAA6B,CAAA,GAAA,oCAAA,CAAA;AAC7B,EAAAA,SAAA,qBAAsB,CAAA,GAAA,6BAAA,CAAA;AACtB,EAAAA,SAAA,kBAAmB,CAAA,GAAA,0BAAA,CAAA;AAGnB,EAAAA,SAAA,uBAAwB,CAAA,GAAA,+BAAA,CAAA;AAGxB,EAAAA,SAAA,UAAW,CAAA,GAAA,wBAAA,CAAA;AAxBH,EAAAA,OAAAA,QAAAA,CAAAA;AAAA,CAAA,EAAA,OAAA,IAAA,EAAA;;;;"}
package/i18n.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.js","sources":["i18n.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { createIntl, createIntlCache, IntlFormatters, IntlShape } from \"@formatjs/intl\";\nimport { ErrorId } from \"./errors\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ApplicationMetadata } from \"./metadata\";\nconst LOG = createLogger(\"runtime:i18n\");\n\n/**\n * Represents i18n info for the entire application.\n * Currently not exposed to user code.\n */\nexport interface AppI18n {\n /** Chosen locale */\n readonly locale: string;\n\n /** Supported locales from app metadata. */\n readonly supportedLocales: string[];\n\n /** Given the package name, constructs a package i18n instance. */\n createPackageI18n(packageName: string): PackageIntl;\n}\n\n/**\n * Gives access to the package's i18n messages for the current locale.\n *\n * See also https://formatjs.io/docs/intl\n */\nexport type PackageIntl = Pick<IntlShape, \"locale\" | \"timeZone\"> & IntlFormatters<string>;\n\nfunction createPackageIntl(locale: string, messages: Record<string, string>) {\n const cache = createIntlCache();\n return createIntl(\n {\n locale,\n messages\n },\n cache\n );\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<AppI18n> {\n const supportedLocales = 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: ${supportedLocales.join(\n \", \"\n )}) [forcedLocale=${forcedLocale}].`\n );\n }\n\n const { locale, messageLocale } = pickLocale(\n forcedLocale,\n supportedLocales,\n getBrowserLocales()\n );\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 (supportedLocales.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 supportedLocales,\n createPackageI18n(packageName) {\n const packageMessage = messages?.[packageName] ?? {};\n return createPackageIntl(locale, packageMessage);\n }\n };\n}\n\n/** Creates an empty i18n instance, e.g. for tests. */\nexport function createEmptyI18n(locale = \"en\"): PackageIntl {\n return createPackageIntl(locale, {});\n}\n\nexport interface LocalePickResult {\n /** The actual locale (e.g. en-US) for number and date formatting etc. */\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. Exported for tests.\n *\n * @param forcedLocale Optional forced locale (must be satisfied)\n * @param appLocales Locales the app has i18n messages for (e.g. \"en\", \"de\")\n * @param userLocales Locales requested by the user's browser\n */\nexport function pickLocale(\n forcedLocale: string | undefined,\n appLocales: string[],\n userLocales: string[]\n): LocalePickResult {\n const pickImpl = (requestedLocales: string[]): LocalePickResult | undefined => {\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 // Attempt to satisfy forced locale\n if (forcedLocale) {\n const result = 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 = 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 { locale: userLocales[0] ?? \"en\", messageLocale: appLocales[0] ?? \"en\" };\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 */\nfunction 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":";;;;AAMA,MAAM,GAAA,GAAM,aAAa,cAAc,CAAA,CAAA;AAwBvC,SAAS,iBAAA,CAAkB,QAAgB,QAAkC,EAAA;AACzE,EAAA,MAAM,QAAQ,eAAgB,EAAA,CAAA;AAC9B,EAAO,OAAA,UAAA;AAAA,IACH;AAAA,MACI,MAAA;AAAA,MACA,QAAA;AAAA,KACJ;AAAA,IACA,KAAA;AAAA,GACJ,CAAA;AACJ,CAAA;AAKsB,eAAA,QAAA,CAClB,aACA,YACgB,EAAA;AAChB,EAAM,MAAA,gBAAA,GAAmB,WAAa,EAAA,OAAA,IAAW,EAAC,CAAA;AAClD,EAAA,MAAM,cAAc,iBAAkB,EAAA,CAAA;AACtC,EAAI,IAAA,GAAA,CAAI,SAAW,EAAA;AACf,IAAI,GAAA,CAAA,KAAA;AAAA,MACA,gDAAgD,WAAY,CAAA,IAAA;AAAA,QACxD,IAAA;AAAA,yCAC+B,gBAAiB,CAAA,IAAA;AAAA,QAChD,IAAA;AAAA,OACgB,CAAA,gBAAA,EAAA,YAAA,CAAA,EAAA,CAAA;AAAA,KACxB,CAAA;AAAA,GACJ;AAEA,EAAM,MAAA,EAAE,MAAQ,EAAA,aAAA,EAAkB,GAAA,UAAA;AAAA,IAC9B,YAAA;AAAA,IACA,gBAAA;AAAA,IACA,iBAAkB,EAAA;AAAA,GACtB,CAAA;AA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A,CAAA;AAClF,CAAA;AAOA,SAAS,iBAA8B,GAAA;AACnC,EAAA,IAAI,OAAO,SAAU,CAAA,SAAA,IAAa,MAAO,CAAA,SAAA,CAAU,UAAU,MAAQ,EAAA;AACjE,IAAA,OAAO,KAAM,CAAA,IAAA,CAAK,MAAO,CAAA,SAAA,CAAU,SAAS,CAAA,CAAA;AAAA,GAChD;AACA,EAAO,OAAA,CAAC,MAAO,CAAA,SAAA,CAAU,QAAQ,CAAA,CAAA;AACrC;;;;"}
1
+ {"version":3,"file":"i18n.js","sources":["i18n.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createIntl, createIntlCache, IntlFormatters, IntlShape } from \"@formatjs/intl\";\nimport { ErrorId } from \"./errors\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ApplicationMetadata } from \"./metadata\";\nconst LOG = createLogger(\"runtime:i18n\");\n\n/**\n * Represents i18n info for the entire application.\n * Currently not exposed to user code.\n */\nexport interface AppI18n {\n /** Chosen locale */\n readonly locale: string;\n\n /** Supported locales from app metadata. */\n readonly supportedLocales: string[];\n\n /** Given the package name, constructs a package i18n instance. */\n createPackageI18n(packageName: string): PackageIntl;\n}\n\n/**\n * Gives access to the package's i18n messages for the current locale.\n *\n * See also https://formatjs.io/docs/intl\n */\nexport type PackageIntl = Pick<IntlShape, \"locale\" | \"timeZone\"> & IntlFormatters<string>;\n\nfunction createPackageIntl(locale: string, messages: Record<string, string>) {\n const cache = createIntlCache();\n return createIntl(\n {\n locale,\n messages\n },\n cache\n );\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<AppI18n> {\n const supportedLocales = 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: ${supportedLocales.join(\n \", \"\n )}) [forcedLocale=${forcedLocale}].`\n );\n }\n\n const { locale, messageLocale } = pickLocale(\n forcedLocale,\n supportedLocales,\n getBrowserLocales()\n );\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 (supportedLocales.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 supportedLocales,\n createPackageI18n(packageName) {\n const packageMessage = messages?.[packageName] ?? {};\n return createPackageIntl(locale, packageMessage);\n }\n };\n}\n\n/** Creates an empty i18n instance, e.g. for tests. */\nexport function createEmptyI18n(locale = \"en\"): PackageIntl {\n return createPackageIntl(locale, {});\n}\n\nexport interface LocalePickResult {\n /** The actual locale (e.g. en-US) for number and date formatting etc. */\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. Exported for tests.\n *\n * @param forcedLocale Optional forced locale (must be satisfied)\n * @param appLocales Locales the app has i18n messages for (e.g. \"en\", \"de\")\n * @param userLocales Locales requested by the user's browser\n */\nexport function pickLocale(\n forcedLocale: string | undefined,\n appLocales: string[],\n userLocales: string[]\n): LocalePickResult {\n const pickImpl = (requestedLocales: string[]): LocalePickResult | undefined => {\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 // Attempt to satisfy forced locale\n if (forcedLocale) {\n const result = 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 = 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 { locale: userLocales[0] ?? \"en\", messageLocale: appLocales[0] ?? \"en\" };\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 */\nfunction 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":";;;;AAMA,MAAM,GAAA,GAAM,aAAa,cAAc,CAAA,CAAA;AAwBvC,SAAS,iBAAA,CAAkB,QAAgB,QAAkC,EAAA;AACzE,EAAA,MAAM,QAAQ,eAAgB,EAAA,CAAA;AAC9B,EAAO,OAAA,UAAA;AAAA,IACH;AAAA,MACI,MAAA;AAAA,MACA,QAAA;AAAA,KACJ;AAAA,IACA,KAAA;AAAA,GACJ,CAAA;AACJ,CAAA;AAKsB,eAAA,QAAA,CAClB,aACA,YACgB,EAAA;AAChB,EAAM,MAAA,gBAAA,GAAmB,WAAa,EAAA,OAAA,IAAW,EAAC,CAAA;AAClD,EAAA,MAAM,cAAc,iBAAkB,EAAA,CAAA;AACtC,EAAI,IAAA,GAAA,CAAI,SAAW,EAAA;AACf,IAAI,GAAA,CAAA,KAAA;AAAA,MACA,gDAAgD,WAAY,CAAA,IAAA;AAAA,QACxD,IAAA;AAAA,OACH,kCAAkC,gBA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CAAA;AAAA,GACX;AAGA,EAAM,MAAA,eAAA,GAAkB,SAAS,WAAW,CAAA,CAAA;AAC5C,EAAA,IAAI,eAAiB,EAAA;AACjB,IAAO,OAAA,eAAA,CAAA;AAAA,GACX;AAGA,EAAO,OAAA,EAAE,MAAQ,EAAA,WAAA,CAAY,CAAC,CAAA,IAAK,MAAM,aAAe,EAAA,UAAA,CAAW,CAAC,CAAA,IAAK,IAAK,EAAA,CAAA;AAClF,CAAA;AAOA,SAAS,iBAA8B,GAAA;AACnC,EAAA,IAAI,OAAO,SAAU,CAAA,SAAA,IAAa,MAAO,CAAA,SAAA,CAAU,UAAU,MAAQ,EAAA;AACjE,IAAA,OAAO,KAAM,CAAA,IAAA,CAAK,MAAO,CAAA,SAAA,CAAU,SAAS,CAAA,CAAA;AAAA,GAChD;AACA,EAAO,OAAA,CAAC,MAAO,CAAA,SAAA,CAAU,QAAQ,CAAA,CAAA;AACrC;;;;"}
package/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./api";
2
2
  export { type PackageIntl } from "./i18n";
3
- export { type ApplicationElement, type ApplicationElementConstructor, type ApplicationProperties, type ApplicationConfig, type CustomElementOptions, type ConfigContext, type RawApplicationProperties, createCustomElement } from "./CustomElement";
3
+ export { type ApplicationElement, type ApplicationElementConstructor, type ApplicationProperties, type ApplicationConfig, type CustomElementOptions, type ConfigContext, createCustomElement } from "./CustomElement";
4
4
  export * from "./Service";
5
- export * from "./ServiceRegistry";
6
- export * from "./PropertiesRegistry";
5
+ export { type DeclaredService, type AssociatedInterfaceName, type InterfaceNameForServiceType } from "./DeclaredService";
package/index.js CHANGED
@@ -1,3 +1,2 @@
1
- import './i18n.js';
2
1
  export { createCustomElement } from './CustomElement.js';
3
2
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableBox.js","sources":["ObservableBox.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { EventEmitter, Resource } from \"@open-pioneer/core\";\n\nexport interface ObservableBox<T> {\n /** The current value. */\n readonly value: T;\n\n /**\n * Changes the current value.\n *\n * Note that this function is only present during development to facilitate hot reloading.\n */\n setValue?(value: T): void;\n\n /**\n * Register a listener callback that will be invoked\n * when the value changes.\n *\n * Note that this function is only present during development to facilitate hot reloading.\n */\n on?(event: \"changed\", listener: () => void): Resource;\n}\n\n/**\n * Returns a boxed value.\n * In development node, the box value can be changed and observed.\n */\nexport function createBox<T>(value: T): ObservableBox<T> {\n if (import.meta.env.DEV) {\n return new BoxImpl(value);\n } else {\n return {\n value\n };\n }\n}\n\nclass BoxImpl<T> extends EventEmitter<{ changed: void }> implements Required<ObservableBox<T>> {\n value: T;\n\n constructor(value: T) {\n super();\n this.value = value;\n }\n\n setValue(value: T): void {\n this.value = value;\n this.emit(\"changed\");\n }\n}\n"],"names":[],"mappings":";;AA4BO,SAAS,UAAa,KAA4B,EAAA;AACrD,EAAI,IAAA,MAAA,CAAA,IAAA,CAAY,IAAI,GAAK,EAAA;AACrB,IAAO,OAAA,IAAI,QAAQ,KAAK,CAAA,CAAA;AAAA,GACrB,MAAA;AACH,IAAO,OAAA;AAAA,MACH,KAAA;AAAA,KACJ,CAAA;AAAA,GACJ;AACJ,CAAA;AAEA,MAAM,gBAAmB,YAAsE,CAAA;AAAA,EAC3F,KAAA,CAAA;AAAA,EAEA,YAAY,KAAU,EAAA;AAClB,IAAM,KAAA,EAAA,CAAA;AACN,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AAAA,GACjB;AAAA,EAEA,SAAS,KAAgB,EAAA;AACrB,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AACb,IAAA,IAAA,CAAK,KAAK,SAAS,CAAA,CAAA;AAAA,GACvB;AACJ;;;;"}
1
+ {"version":3,"file":"ObservableBox.js","sources":["ObservableBox.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { EventEmitter, Resource } from \"@open-pioneer/core\";\n\nexport interface ObservableBox<T> {\n /** The current value. */\n readonly value: T;\n\n /**\n * Changes the current value.\n *\n * Note that this function is only present during development to facilitate hot reloading.\n */\n setValue?(value: T): void;\n\n /**\n * Register a listener callback that will be invoked\n * when the value changes.\n *\n * Note that this function is only present during development to facilitate hot reloading.\n */\n on?(event: \"changed\", listener: () => void): Resource;\n}\n\n/**\n * Returns a boxed value.\n * In development node, the box value can be changed and observed.\n */\nexport function createBox<T>(value: T): ObservableBox<T> {\n if (import.meta.env.DEV) {\n return new BoxImpl(value);\n } else {\n return {\n value\n };\n }\n}\n\nclass BoxImpl<T> extends EventEmitter<{ changed: void }> implements Required<ObservableBox<T>> {\n value: T;\n\n constructor(value: T) {\n super();\n this.value = value;\n }\n\n setValue(value: T): void {\n this.value = value;\n this.emit(\"changed\");\n }\n}\n"],"names":[],"mappings":";;AA4BO,SAAS,UAAa,KAA4B,EAAA;AACrD,EAAI,IAAA,MAAA,CAAA,IAAA,CAAY,IAAI,GAAK,EAAA;AACrB,IAAO,OAAA,IAAI,QAAQ,KAAK,CAAA,CAAA;AAAA,GACrB,MAAA;AACH,IAAO,OAAA;AAAA,MACH,KAAA;AAAA,KACJ,CAAA;AAAA,GACJ;AACJ,CAAA;AAEA,MAAM,gBAAmB,YAAsE,CAAA;AAAA,EAC3F,KAAA,CAAA;AAAA,EAEA,YAAY,KAAU,EAAA;AAClB,IAAM,KAAA,EAAA,CAAA;AACN,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AAAA,GACjB;AAAA,EAEA,SAAS,KAAgB,EAAA;AACrB,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AACb,IAAA,IAAA,CAAK,KAAK,SAAS,CAAA,CAAA;AAAA,GACvB;AACJ;;;;"}