@open-pioneer/runtime 4.7.0-dev.20260713101438 → 4.7.0-dev.20260727091735

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +176 -175
  2. package/CustomElement.js +1 -1
  3. package/CustomElement.js.map +1 -1
  4. package/DeclaredService.d.ts +1 -1
  5. package/DeclaredService.js.map +1 -1
  6. package/Service.js.map +1 -1
  7. package/app/AppInstance.js +2 -2
  8. package/app/AppInstance.js.map +1 -1
  9. package/app/gatherConfig.js.map +1 -1
  10. package/app/logErrors.js.map +1 -1
  11. package/builtin-services/ApiServiceImpl.d.ts +1 -1
  12. package/builtin-services/ApiServiceImpl.js.map +1 -1
  13. package/builtin-services/ApplicationContextImpl.js.map +1 -1
  14. package/builtin-services/ApplicationLifecycleEventService.d.ts +1 -1
  15. package/builtin-services/ApplicationLifecycleEventService.js +1 -1
  16. package/builtin-services/ApplicationLifecycleEventService.js.map +1 -1
  17. package/builtin-services/LocaleServiceImpl.js.map +1 -1
  18. package/builtin-services/NumberParserServiceImpl.js.map +1 -1
  19. package/builtin-services/ThemeServiceImpl.js.map +1 -1
  20. package/builtin-services/index.js.map +1 -1
  21. package/errors.js.map +1 -1
  22. package/i18n/AppIntl.js.map +1 -1
  23. package/i18n/PackageIntl.js.map +1 -1
  24. package/i18n/pick.js.map +1 -1
  25. package/metadata/ObservableBox.js.map +1 -1
  26. package/package.json +9 -9
  27. package/react-integration/ChakraProvider.d.ts +1 -1
  28. package/react-integration/ChakraProvider.js.map +1 -1
  29. package/react-integration/ErrorScreen.js.map +1 -1
  30. package/react-integration/PackageContext.js.map +1 -1
  31. package/react-integration/ReactIntegration.d.ts +1 -1
  32. package/react-integration/ReactIntegration.js.map +1 -1
  33. package/react-integration/hooks.js +1 -1
  34. package/react-integration/hooks.js.map +1 -1
  35. package/service-layer/InterfaceSpec.js.map +1 -1
  36. package/service-layer/PackageRepr.js.map +1 -1
  37. package/service-layer/ServiceLayer.js.map +1 -1
  38. package/service-layer/ServiceLookup.js.map +1 -1
  39. package/service-layer/ServiceRepr.js.map +1 -1
  40. package/service-layer/verifyDependencies.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableBox.js","sources":["ObservableBox.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { reactive, Reactive } from \"@conterra/reactivity-core\";\n\nexport interface ObservableBox<T> {\n /** The current value. Reactive. */\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?(newValue: T): void;\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 return new BoxImpl(value);\n}\n\n/** @internal */\nexport function isBox<T>(value: T | ObservableBox<T>): value is ObservableBox<T> {\n return value instanceof BoxImpl;\n}\n\n/** @internal */\nexport function unwrapBox<T>(value: T | ObservableBox<T>): T {\n return isBox(value) ? value.value : value;\n}\n\nclass BoxImpl<T> implements ObservableBox<T> {\n #signal: Reactive<T>;\n\n readonly setValue?: (newValue: T) => void;\n\n constructor(value: T) {\n this.#signal = reactive(value);\n if (import.meta.env.DEV) {\n this.setValue = (newValue) => {\n this.#signal.value = newValue;\n };\n }\n }\n\n get value(): T {\n return this.#signal.value;\n }\n}\n"],"names":[],"mappings":";;AAoBO,SAAS,UAAa,KAAA,EAA4B;AACrD,EAAA,OAAO,IAAI,QAAQ,KAAK,CAAA;AAC5B;AAGO,SAAS,MAAS,KAAA,EAAwD;AAC7E,EAAA,OAAO,KAAA,YAAiB,OAAA;AAC5B;AAGO,SAAS,UAAa,KAAA,EAAgC;AACzD,EAAA,OAAO,KAAA,CAAM,KAAK,CAAA,GAAI,KAAA,CAAM,KAAA,GAAQ,KAAA;AACxC;AAEA,MAAM,OAAA,CAAuC;AAAA,EACzC,OAAA;AAAA,EAES,QAAA;AAAA,EAET,YAAY,KAAA,EAAU;AAClB,IAAA,IAAA,CAAK,OAAA,GAAU,SAAS,KAAK,CAAA;AAC7B,IAAA,IAAI,MAAA,CAAA,IAAA,CAAY,IAAI,GAAA,EAAK;AACrB,MAAA,IAAA,CAAK,QAAA,GAAW,CAAC,QAAA,KAAa;AAC1B,QAAA,IAAA,CAAK,QAAQ,KAAA,GAAQ,QAAA;AAAA,MACzB,CAAA;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,IAAI,KAAA,GAAW;AACX,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACxB;AACJ;;;;"}
1
+ {"version":3,"file":"ObservableBox.js","sources":["ObservableBox.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { reactive, Reactive } from \"@conterra/reactivity-core\";\n\nexport interface ObservableBox<T> {\n /** The current value. Reactive. */\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?(newValue: T): void;\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 return new BoxImpl(value);\n}\n\n/** @internal */\nexport function isBox<T>(value: T | ObservableBox<T>): value is ObservableBox<T> {\n return value instanceof BoxImpl;\n}\n\n/** @internal */\nexport function unwrapBox<T>(value: T | ObservableBox<T>): T {\n return isBox(value) ? value.value : value;\n}\n\nclass BoxImpl<T> implements ObservableBox<T> {\n #signal: Reactive<T>;\n\n readonly setValue?: (newValue: T) => void;\n\n constructor(value: T) {\n this.#signal = reactive(value);\n if (import.meta.env.DEV) {\n this.setValue = (newValue) => {\n this.#signal.value = newValue;\n };\n }\n }\n\n get value(): T {\n return this.#signal.value;\n }\n}\n"],"names":[],"mappings":";;AAqBO,SAAS,UAAa,KAAA,EAA4B;AACrD,EAAA,OAAO,IAAI,QAAQ,KAAK,CAAA;AAC5B;AAGO,SAAS,MAAS,KAAA,EAAwD;AAC7E,EAAA,OAAO,KAAA,YAAiB,OAAA;AAC5B;AAGO,SAAS,UAAa,KAAA,EAAgC;AACzD,EAAA,OAAO,KAAA,CAAM,KAAK,CAAA,GAAI,KAAA,CAAM,KAAA,GAAQ,KAAA;AACxC;AAEA,MAAM,OAAA,CAAuC;AAAA,EACzC,OAAA;AAAA,EAES,QAAA;AAAA,EAET,YAAY,KAAA,EAAU;AAClB,IAAA,IAAA,CAAK,OAAA,GAAU,SAAS,KAAK,CAAA;AAC7B,IAAA,IAAI,MAAA,CAAA,IAAA,CAAY,IAAI,GAAA,EAAK;AACrB,MAAA,IAAA,CAAK,QAAA,GAAW,CAAC,QAAA,KAAa;AAC1B,QAAA,IAAA,CAAK,QAAQ,KAAA,GAAQ,QAAA;AAAA,MACzB,CAAA;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,IAAI,KAAA,GAAW;AACX,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACxB;AACJ;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/runtime",
4
- "version": "4.7.0-dev.20260713101438",
4
+ "version": "4.7.0-dev.20260727091735",
5
5
  "description": "Implements the runtime environment for Open Pioneer Trails apps.",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -14,17 +14,17 @@
14
14
  "directory": "src/packages/runtime"
15
15
  },
16
16
  "dependencies": {
17
+ "@chakra-ui/react": "^3.36.1",
17
18
  "@conterra/reactivity-core": "^0.8.6",
18
- "@formatjs/intl": "^4.1.15",
19
- "@formatjs/intl-localematcher": "^0.8.11",
20
- "@chakra-ui/react": "^3.36.0",
21
19
  "@emotion/cache": "^11.14.0",
22
20
  "@emotion/react": "^11.14.0",
23
- "react": "^19.2.7",
24
- "react-dom": "^19.2.7",
25
- "@open-pioneer/base-theme": "4.7.0-dev.20260713101438",
26
- "@open-pioneer/core": "4.7.0-dev.20260713101438",
27
- "@open-pioneer/reactivity": "4.7.0-dev.20260713101438"
21
+ "@formatjs/intl": "^4.1.17",
22
+ "@formatjs/intl-localematcher": "^0.8.13",
23
+ "react": "^19.2.8",
24
+ "react-dom": "^19.2.8",
25
+ "@open-pioneer/base-theme": "4.7.0-dev.20260727091735",
26
+ "@open-pioneer/reactivity": "4.7.0-dev.20260727091735",
27
+ "@open-pioneer/core": "4.7.0-dev.20260727091735"
28
28
  },
29
29
  "exports": {
30
30
  "./package.json": "./package.json",
@@ -1,8 +1,8 @@
1
1
  import { SystemConfig } from "@chakra-ui/react";
2
2
  import { ReadonlyReactive } from "@conterra/reactivity-core";
3
3
  import { FC, PropsWithChildren } from "react";
4
- import { RootNode } from "../dom";
5
4
  import { ColorModeValue } from "../api";
5
+ import { RootNode } from "../dom";
6
6
  /** @internal */
7
7
  export type CustomChakraProviderProps = PropsWithChildren<{
8
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ChakraProvider.js","sources":["ChakraProvider.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n ChakraProvider,\n createSystem,\n defaultConfig,\n defineConfig,\n EnvironmentProvider,\n LocaleProvider,\n mergeConfigs,\n SystemConfig,\n SystemStyleObject\n} from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport createCache, { EmotionCache } from \"@emotion/cache\";\nimport { CacheProvider, Global } from \"@emotion/react\";\nimport { config as defaultTrailsConfig } from \"@open-pioneer/base-theme\";\nimport { Error } from \"@open-pioneer/core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { FC, PropsWithChildren, useEffect, useLayoutEffect, useMemo, useState } from \"react\";\nimport { APP_ROOT_CLASS, getBuiltinStyles, getStylesRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { ColorModeValue } from \"../api\";\n\n/** @internal */\nexport type CustomChakraProviderProps = PropsWithChildren<{\n /**\n * Document root node.\n */\n rootNode: RootNode;\n\n /**\n * Web component root.\n *\n * NOTE: undefined for test support only.\n */\n hostNode?: HTMLElement;\n\n /**\n * Application container (react's render target).\n */\n appRoot: HTMLElement;\n\n /**\n * Chakra system config (can be used to provide custom theme).\n */\n config?: ReadonlyReactive<SystemConfig | undefined>;\n\n /**\n * Application locale for chakra's `LocaleProvider`.\n */\n locale?: ReadonlyReactive<string>;\n\n /**\n * Custom color mode value.\n */\n colorMode: ReadonlyReactive<ColorModeValue>;\n\n /**\n * Custom CSS used by the application.\n */\n styles?: ReadonlyReactive<string>;\n}>;\n\nconst APP_ROOT_CSS = `.${APP_ROOT_CLASS}`;\n\n/**\n * Wraps the entire react application and configures chakra-ui (styling etc.).\n *\n * Exported so it can be used from the test-utils package.\n *\n * @internal\n */\nexport const CustomChakraProvider: FC<CustomChakraProviderProps> = ({\n rootNode,\n appRoot,\n hostNode,\n children,\n config,\n locale,\n colorMode,\n styles\n}) => {\n /*\n Setup chakra integration:\n\n 1. Mount styles into the shadow root via emotion\n 2. Use chakra's EnvironmentProvider to tell it about the shadow root context\n 3. Setup global styles correctly (selectors etc.) via chakra's system object\n 4. Render the rest of the application\n */\n\n const systemConfig = useReactiveSnapshot(() => config?.value ?? defaultTrailsConfig, [config]);\n const effectiveLocale = useReactiveSnapshot(() => locale?.value ?? \"en-US\", [locale]);\n\n const system = useMemo(() => {\n const mergedConfig = mergeConfigs(defaultConfig, systemConfig);\n return createSystem(\n mergedConfig,\n\n // https://www.chakra-ui.com/docs/get-started/environments/shadow-dom\n defineConfig({\n preflight: {\n scope: APP_ROOT_CSS\n },\n cssVarsRoot: APP_ROOT_CSS,\n conditions: redirectLightCondition(mergedConfig.conditions),\n globalCss: redirectHtmlProps(mergedConfig.globalCss)\n })\n );\n }, [systemConfig]);\n\n const effectiveColorMode = useReactiveSnapshot(() => colorMode.value, [colorMode]);\n\n useLayoutEffect(() => {\n const classes = appRoot.classList;\n classes.toggle(\"light\", effectiveColorMode === \"light\");\n classes.toggle(\"dark\", effectiveColorMode === \"dark\");\n appRoot.style.colorScheme = effectiveColorMode;\n }, [appRoot, effectiveColorMode]);\n\n const cache = useEmotionCache(rootNode);\n return (\n cache && (\n <CacheProvider value={cache}>\n <EnvironmentProvider\n value={rootNode}\n // Patched property\n portalNode={appRoot}\n >\n <LocaleProvider locale={effectiveLocale}>\n <ChakraProvider value={system}>\n <GlobalStyles rootNode={rootNode} hostNode={hostNode} styles={styles} />\n {children}\n </ChakraProvider>\n </LocaleProvider>\n </EnvironmentProvider>\n </CacheProvider>\n )\n );\n};\n\nfunction GlobalStyles(props: {\n rootNode: RootNode;\n hostNode: HTMLElement | undefined;\n styles: ReadonlyReactive<string> | undefined;\n}) {\n const { rootNode, hostNode, styles } = props;\n const builtinStyles = useMemo(() => {\n const css = getBuiltinStyles(rootNode, hostNode);\n return <Global styles={css} />;\n }, [rootNode, hostNode]);\n const appStyles = useReactiveSnapshot(() => {\n const css = styles?.value;\n return css && <Global styles={css} />;\n }, [styles]);\n return (\n <>\n {builtinStyles}\n {appStyles}\n </>\n );\n}\n\nfunction redirectHtmlProps(\n css: Record<string, SystemStyleObject> | undefined\n): Record<string, SystemStyleObject> {\n const { html, ...rest } = css ?? {};\n if (!html) {\n throw new Error(ErrorId.INTERNAL, \"Expected global rules on html element.\");\n }\n // Take default html styles and apply them to the host element instead\n return {\n ...rest,\n [APP_ROOT_CSS]: html\n };\n}\n\nfunction redirectLightCondition(\n conditions: Record<string, unknown> | undefined\n): Record<string, unknown> {\n // Make sure light mode tokens are applied\n return {\n ...conditions,\n // Before: \":root &, .light &\"\n light: `${APP_ROOT_CSS} &, .light &`\n };\n}\n\nfunction useEmotionCache(rootNode: RootNode): EmotionCache | undefined {\n const stylesRoot = useMemo(() => getStylesRoot(rootNode), [rootNode]);\n\n const [cache, setCache] = useState<EmotionCache | undefined>();\n useEffect(() => {\n const cache = createCache({\n key: \"css\",\n container: stylesRoot\n });\n\n // Disable useless warnings like `The pseudo class \":nth-child\" is potentially unsafe when doing server-side rendering. Try changing it to \":nth-of-type\".`\n // See: https://github.com/emotion-js/emotion/issues/1105#issuecomment-557726922\n cache.compat = true;\n\n setCache(cache);\n return () => {\n setCache(undefined);\n for (const tag of cache.sheet.tags) {\n tag.remove();\n }\n };\n }, [stylesRoot]);\n return cache;\n}\n"],"names":["config","defaultTrailsConfig","cache"],"mappings":";;;;;;;;;;;AAgEA,MAAM,YAAA,GAAe,IAAI,cAAc,CAAA,CAAA;AAShC,MAAM,uBAAsD,CAAC;AAAA,EAChE,QAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,UACAA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA;AACJ,CAAA,KAAM;AAUF,EAAA,MAAM,YAAA,GAAe,oBAAoB,MAAMA,QAAA,EAAQ,SAASC,MAAA,EAAqB,CAACD,QAAM,CAAC,CAAA;AAC7F,EAAA,MAAM,eAAA,GAAkB,oBAAoB,MAAM,MAAA,EAAQ,SAAS,OAAA,EAAS,CAAC,MAAM,CAAC,CAAA;AAEpF,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAM;AACzB,IAAA,MAAM,YAAA,GAAe,YAAA,CAAa,aAAA,EAAe,YAAY,CAAA;AAC7D,IAAA,OAAO,YAAA;AAAA,MACH,YAAA;AAAA;AAAA,MAGA,YAAA,CAAa;AAAA,QACT,SAAA,EAAW;AAAA,UACP,KAAA,EAAO;AAAA,SACX;AAAA,QACA,WAAA,EAAa,YAAA;AAAA,QACb,UAAA,EAAY,sBAAA,CAAuB,YAAA,CAAa,UAAU,CAAA;AAAA,QAC1D,SAAA,EAAW,iBAAA,CAAkB,YAAA,CAAa,SAAS;AAAA,OACtD;AAAA,KACL;AAAA,EACJ,CAAA,EAAG,CAAC,YAAY,CAAC,CAAA;AAEjB,EAAA,MAAM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AID,IAAAA,OAAM,MAAA,GAAS,IAAA;AAEf,IAAA,QAAA,CAASA,MAAK,CAAA;AACd,IAAA,OAAO,MAAM;AACT,MAAA,QAAA,CAAS,MAAS,CAAA;AAClB,MAAA,KAAA,MAAW,GAAA,IAAOA,MAAAA,CAAM,KAAA,CAAM,IAAA,EAAM;AAChC,QAAA,GAAA,CAAI,MAAA,EAAO;AAAA,MACf;AAAA,IACJ,CAAA;AAAA,EACJ,CAAA,EAAG,CAAC,UAAU,CAAC,CAAA;AACf,EAAA,OAAO,KAAA;AACX;;;;"}
1
+ {"version":3,"file":"ChakraProvider.js","sources":["ChakraProvider.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n ChakraProvider,\n createSystem,\n defaultConfig,\n defineConfig,\n EnvironmentProvider,\n LocaleProvider,\n mergeConfigs,\n SystemConfig,\n SystemStyleObject\n} from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport createCache, { EmotionCache } from \"@emotion/cache\";\nimport { CacheProvider, Global } from \"@emotion/react\";\nimport { config as defaultTrailsConfig } from \"@open-pioneer/base-theme\";\nimport { Error } from \"@open-pioneer/core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { FC, PropsWithChildren, useEffect, useLayoutEffect, useMemo, useState } from \"react\";\nimport { ColorModeValue } from \"../api\";\nimport { APP_ROOT_CLASS, getBuiltinStyles, getStylesRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\n\n/** @internal */\nexport type CustomChakraProviderProps = PropsWithChildren<{\n /**\n * Document root node.\n */\n rootNode: RootNode;\n\n /**\n * Web component root.\n *\n * NOTE: undefined for test support only.\n */\n hostNode?: HTMLElement;\n\n /**\n * Application container (react's render target).\n */\n appRoot: HTMLElement;\n\n /**\n * Chakra system config (can be used to provide custom theme).\n */\n config?: ReadonlyReactive<SystemConfig | undefined>;\n\n /**\n * Application locale for chakra's `LocaleProvider`.\n */\n locale?: ReadonlyReactive<string>;\n\n /**\n * Custom color mode value.\n */\n colorMode: ReadonlyReactive<ColorModeValue>;\n\n /**\n * Custom CSS used by the application.\n */\n styles?: ReadonlyReactive<string>;\n}>;\n\nconst APP_ROOT_CSS = `.${APP_ROOT_CLASS}`;\n\n/**\n * Wraps the entire react application and configures chakra-ui (styling etc.).\n *\n * Exported so it can be used from the test-utils package.\n *\n * @internal\n */\nexport const CustomChakraProvider: FC<CustomChakraProviderProps> = ({\n rootNode,\n appRoot,\n hostNode,\n children,\n config,\n locale,\n colorMode,\n styles\n}) => {\n /*\n Setup chakra integration:\n\n 1. Mount styles into the shadow root via emotion\n 2. Use chakra's EnvironmentProvider to tell it about the shadow root context\n 3. Setup global styles correctly (selectors etc.) via chakra's system object\n 4. Render the rest of the application\n */\n\n const systemConfig = useReactiveSnapshot(() => config?.value ?? defaultTrailsConfig, [config]);\n const effectiveLocale = useReactiveSnapshot(() => locale?.value ?? \"en-US\", [locale]);\n\n const system = useMemo(() => {\n const mergedConfig = mergeConfigs(defaultConfig, systemConfig);\n return createSystem(\n mergedConfig,\n\n // https://www.chakra-ui.com/docs/get-started/environments/shadow-dom\n defineConfig({\n preflight: {\n scope: APP_ROOT_CSS\n },\n cssVarsRoot: APP_ROOT_CSS,\n conditions: redirectLightCondition(mergedConfig.conditions),\n globalCss: redirectHtmlProps(mergedConfig.globalCss)\n })\n );\n }, [systemConfig]);\n\n const effectiveColorMode = useReactiveSnapshot(() => colorMode.value, [colorMode]);\n\n useLayoutEffect(() => {\n const classes = appRoot.classList;\n classes.toggle(\"light\", effectiveColorMode === \"light\");\n classes.toggle(\"dark\", effectiveColorMode === \"dark\");\n appRoot.style.colorScheme = effectiveColorMode;\n }, [appRoot, effectiveColorMode]);\n\n const cache = useEmotionCache(rootNode);\n return (\n cache && (\n <CacheProvider value={cache}>\n <EnvironmentProvider\n value={rootNode}\n // Patched property\n portalNode={appRoot}\n >\n <LocaleProvider locale={effectiveLocale}>\n <ChakraProvider value={system}>\n <GlobalStyles rootNode={rootNode} hostNode={hostNode} styles={styles} />\n {children}\n </ChakraProvider>\n </LocaleProvider>\n </EnvironmentProvider>\n </CacheProvider>\n )\n );\n};\n\nfunction GlobalStyles(props: {\n rootNode: RootNode;\n hostNode: HTMLElement | undefined;\n styles: ReadonlyReactive<string> | undefined;\n}) {\n const { rootNode, hostNode, styles } = props;\n const builtinStyles = useMemo(() => {\n const css = getBuiltinStyles(rootNode, hostNode);\n return <Global styles={css} />;\n }, [rootNode, hostNode]);\n const appStyles = useReactiveSnapshot(() => {\n const css = styles?.value;\n return css && <Global styles={css} />;\n }, [styles]);\n return (\n <>\n {builtinStyles}\n {appStyles}\n </>\n );\n}\n\nfunction redirectHtmlProps(\n css: Record<string, SystemStyleObject> | undefined\n): Record<string, SystemStyleObject> {\n const { html, ...rest } = css ?? {};\n if (!html) {\n throw new Error(ErrorId.INTERNAL, \"Expected global rules on html element.\");\n }\n // Take default html styles and apply them to the host element instead\n return {\n ...rest,\n [APP_ROOT_CSS]: html\n };\n}\n\nfunction redirectLightCondition(\n conditions: Record<string, unknown> | undefined\n): Record<string, unknown> {\n // Make sure light mode tokens are applied\n return {\n ...conditions,\n // Before: \":root &, .light &\"\n light: `${APP_ROOT_CSS} &, .light &`\n };\n}\n\nfunction useEmotionCache(rootNode: RootNode): EmotionCache | undefined {\n const stylesRoot = useMemo(() => getStylesRoot(rootNode), [rootNode]);\n\n const [cache, setCache] = useState<EmotionCache | undefined>();\n useEffect(() => {\n const cache = createCache({\n key: \"css\",\n container: stylesRoot\n });\n\n // Disable useless warnings like `The pseudo class \":nth-child\" is potentially unsafe when doing server-side rendering. Try changing it to \":nth-of-type\".`\n // See: https://github.com/emotion-js/emotion/issues/1105#issuecomment-557726922\n cache.compat = true;\n\n setCache(cache);\n return () => {\n setCache(undefined);\n for (const tag of cache.sheet.tags) {\n tag.remove();\n }\n };\n }, [stylesRoot]);\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;AAAA,EACJ,CAAA,EAAG,CAAC,UAAU,CAAC,CAAA;AACf,EAAA,OAAO,KAAA;AACX;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorScreen.js","sources":["ErrorScreen.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Alert, Box, Heading, Text, VStack } from \"@chakra-ui/react\";\nimport { PackageIntl } from \"../i18n\";\n\nconst MESSAGES_DE = {\n \"title\": \"Anwendungsstart fehlgeschlagen\",\n \"alertTitle\": \"Fehler\",\n \"alertDescription\": \"Leider ist beim Start der Anwendung ein Fehler aufgetreten.\",\n\n \"details.title\": \"Fehlerdetails\",\n \"details.inspect\": \"Konsole öffnen, um weitere Details zu sehen.\",\n \"details.errorMessage\": \"Fehler: {message}\"\n};\n\nconst MESSAGES_EN = {\n \"title\": \"Application start failed\",\n \"alertTitle\": \"Error\",\n \"alertDescription\": \"Unfortunately an error occurred during application start.\",\n\n \"details.title\": \"Error details\",\n \"details.inspect\": \"Inspect the console to see more details.\",\n \"details.errorMessage\": \"Error: {message}\"\n};\n\nexport const MESSAGES_BY_LOCALE: Record<\"en\" | \"de\", Record<string, string>> = {\n \"en\": MESSAGES_EN,\n \"de\": MESSAGES_DE\n};\n\nexport function ErrorScreen(props: { intl: PackageIntl; error: Error }) {\n const intl = props.intl;\n return (\n <VStack padding={4} width=\"100%\" height=\"100%\" minWidth=\"350px\" minHeight=\"150px\">\n <Heading>{intl.formatMessage({ id: \"title\" })}</Heading>\n <Alert.Root status=\"error\" size=\"lg\" maxWidth={550} borderRadius=\"4px\" mt={2}>\n <Alert.Indicator />\n <Alert.Content>\n <Alert.Title fontWeight=\"bold\">\n {intl.formatMessage({ id: \"alertTitle\" })}\n </Alert.Title>\n <Alert.Description>\n {intl.formatMessage({ id: \"alertDescription\" })}\n </Alert.Description>\n </Alert.Content>\n </Alert.Root>\n\n {import.meta.env.DEV && (\n <Box\n className=\"error-details\"\n mt={4}\n p={2}\n maxWidth=\"100%\"\n border={\"dotted 2px\"}\n borderColor={\"red.600\"}\n borderRadius={\"4px\"}\n >\n <Text color={\"red.600\"} fontWeight={\"bold\"}>\n {intl.formatMessage({ id: \"details.title\" }) + \":\"}\n </Text>\n <ErrorRenderer {...props} />\n </Box>\n )}\n </VStack>\n );\n}\n\n/**\n * Renders a single error instance.\n */\nfunction ErrorRenderer(props: { error: Error; intl: PackageIntl }) {\n const { error, intl } = props;\n const message = error?.message || \"Unknown\";\n const stackTrace = error?.stack;\n const stackTraceDisplay = stackTrace && (\n <>\n <Box\n p=\"2\"\n mt={1}\n mb={3}\n maxHeight=\"500px\"\n whiteSpace=\"pre\"\n wordBreak=\"keep-all\"\n overflow=\"auto\"\n border=\"1px solid grey\"\n borderRadius=\"4px\"\n color=\"gray.700\"\n fontSize=\"12px\"\n fontFamily=\"monospace\"\n >\n {stackTrace}\n </Box>\n {intl.formatMessage({ id: \"details.inspect\" })}\n </>\n );\n return (\n <Box p={2} className={\"error-screen-stack-trace\"}>\n <Text fontStyle={\"italic\"}>\n {intl.formatMessage({ id: \"details.errorMessage\" }, { message })}\n </Text>\n {stackTraceDisplay}\n </Box>\n );\n}\n"],"names":[],"mappings":";;;AAKA,MAAM,WAAA,GAAc;AAAA,EAChB,OAAA,EAAS,gCAAA;AAAA,EACT,YAAA,EAAc,QAAA;AAAA,EACd,kBAAA,EAAoB,6DAAA;AAAA,EAEpB,eAAA,EAAiB,eAAA;AAAA,EACjB,iBAAA,EAAmB,iDAAA;AAAA,EACnB,sBAAA,EAAwB;AAC5B,CAAA;AAEA,MAAM,WAAA,GAAc;AAAA,EAChB,OAAA,EAAS,0BAAA;AAAA,EACT,YAAA,EAAc,OAAA;AAAA,EACd,kBAAA,EAAoB,2DAAA;AAAA,EAEpB,eAAA,EAAiB,eAAA;AAAA,EACjB,iBAAA,EAAmB,0CAAA;AAAA,EACnB,sBAAA,EAAwB;AAC5B,CAAA;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,EAAA,EAAI,mBAAmB;AAAA,GAAA,EACjD,CAAA;AAEJ,EAAA,uBACI,IAAA,CAAC,GAAA,EAAA,EAAI,CAAA,EAAG,CAAA,EAAG,WAAW,0BAAA,EAClB,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,IAAA,EAAA,EAAK,SAAA,EAAW,QAAA,EACZ,QAAA,EAAA,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,sBAAA,EAAuB,EAAG,EAAE,OAAA,EAAS,CAAA,EACnE,CAAA;AAAA,IACC;AAAA,GAAA,EACL,CAAA;AAER;;;;"}
1
+ {"version":3,"file":"ErrorScreen.js","sources":["ErrorScreen.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Alert, Box, Heading, Text, VStack } from \"@chakra-ui/react\";\nimport { PackageIntl } from \"../i18n\";\n\nconst MESSAGES_DE = {\n \"title\": \"Anwendungsstart fehlgeschlagen\",\n \"alertTitle\": \"Fehler\",\n \"alertDescription\": \"Leider ist beim Start der Anwendung ein Fehler aufgetreten.\",\n\n \"details.title\": \"Fehlerdetails\",\n \"details.inspect\": \"Konsole öffnen, um weitere Details zu sehen.\",\n \"details.errorMessage\": \"Fehler: {message}\"\n};\n\nconst MESSAGES_EN = {\n \"title\": \"Application start failed\",\n \"alertTitle\": \"Error\",\n \"alertDescription\": \"Unfortunately an error occurred during application start.\",\n\n \"details.title\": \"Error details\",\n \"details.inspect\": \"Inspect the console to see more details.\",\n \"details.errorMessage\": \"Error: {message}\"\n};\n\nexport const MESSAGES_BY_LOCALE: Record<\"en\" | \"de\", Record<string, string>> = {\n \"en\": MESSAGES_EN,\n \"de\": MESSAGES_DE\n};\n\nexport function ErrorScreen(props: { intl: PackageIntl; error: Error }) {\n const intl = props.intl;\n return (\n <VStack padding={4} width=\"100%\" height=\"100%\" minWidth=\"350px\" minHeight=\"150px\">\n <Heading>{intl.formatMessage({ id: \"title\" })}</Heading>\n <Alert.Root status=\"error\" size=\"lg\" maxWidth={550} borderRadius=\"4px\" mt={2}>\n <Alert.Indicator />\n <Alert.Content>\n <Alert.Title fontWeight=\"bold\">\n {intl.formatMessage({ id: \"alertTitle\" })}\n </Alert.Title>\n <Alert.Description>\n {intl.formatMessage({ id: \"alertDescription\" })}\n </Alert.Description>\n </Alert.Content>\n </Alert.Root>\n\n {import.meta.env.DEV && (\n <Box\n className=\"error-details\"\n mt={4}\n p={2}\n maxWidth=\"100%\"\n border={\"dotted 2px\"}\n borderColor={\"red.600\"}\n borderRadius={\"4px\"}\n >\n <Text color={\"red.600\"} fontWeight={\"bold\"}>\n {intl.formatMessage({ id: \"details.title\" }) + \":\"}\n </Text>\n <ErrorRenderer {...props} />\n </Box>\n )}\n </VStack>\n );\n}\n\n/**\n * Renders a single error instance.\n */\nfunction ErrorRenderer(props: { error: Error; intl: PackageIntl }) {\n const { error, intl } = props;\n const message = error?.message || \"Unknown\";\n const stackTrace = error?.stack;\n const stackTraceDisplay = stackTrace && (\n <>\n <Box\n p=\"2\"\n mt={1}\n mb={3}\n maxHeight=\"500px\"\n whiteSpace=\"pre\"\n wordBreak=\"keep-all\"\n overflow=\"auto\"\n border=\"1px solid grey\"\n borderRadius=\"4px\"\n color=\"gray.700\"\n fontSize=\"12px\"\n fontFamily=\"monospace\"\n >\n {stackTrace}\n </Box>\n {intl.formatMessage({ id: \"details.inspect\" })}\n </>\n );\n return (\n <Box p={2} className={\"error-screen-stack-trace\"}>\n <Text fontStyle={\"italic\"}>\n {intl.formatMessage({ id: \"details.errorMessage\" }, { message })}\n </Text>\n {stackTraceDisplay}\n </Box>\n );\n}\n"],"names":[],"mappings":";;;AAMA,MAAM,WAAA,GAAc;AAAA,EAChB,OAAA,EAAS,gCAAA;AAAA,EACT,YAAA,EAAc,QAAA;AAAA,EACd,kBAAA,EAAoB,6DAAA;AAAA,EAEpB,eAAA,EAAiB,eAAA;AAAA,EACjB,iBAA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,QACX,SAAA,EAAU,UAAA;AAAA,QACV,QAAA,EAAS,MAAA;AAAA,QACT,MAAA,EAAO,gBAAA;AAAA,QACP,YAAA,EAAa,KAAA;AAAA,QACb,KAAA,EAAM,UAAA;AAAA,QACN,QAAA,EAAS,MAAA;AAAA,QACT,UAAA,EAAW,WAAA;AAAA,QAEV,QAAA,EAAA;AAAA;AAAA,KACL;AAAA,IACC,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,mBAAmB;AAAA,GAAA,EACjD,CAAA;AAEJ,EAAA,uBACI,IAAA,CAAC,GAAA,EAAA,EAAI,CAAA,EAAG,CAAA,EAAG,WAAW,0BAAA,EAClB,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,IAAA,EAAA,EAAK,SAAA,EAAW,QAAA,EACZ,QAAA,EAAA,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,sBAAA,EAAuB,EAAG,EAAE,OAAA,EAAS,CAAA,EACnE,CAAA;AAAA,IACC;AAAA,GAAA,EACL,CAAA;AAER;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PackageContext.js","sources":["PackageContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createContext } from \"react\";\nimport type { PackageIntl } from \"../i18n\";\nimport type { Service } from \"../Service\";\nimport type { UseServiceOptions } from \"./hooks\";\n\nexport interface PackageContextMethods {\n getService: (packageName: string, interfaceName: string, options: UseServiceOptions) => Service;\n getServices: (packageName: string, interfaceName: string) => Service[];\n getProperties: (packageName: string) => Readonly<Record<string, unknown>>;\n\n /**\n * NOTE: Reactive for fine grained i18n changes (during dev for i18n HMR) and for live local changes (also in production).\n */\n getIntl(packageName: string): PackageIntl;\n}\n\nexport const PackageContext = createContext<PackageContextMethods | null>(null);\n"],"names":[],"mappings":";;AAkBO,MAAM,cAAA,GAAiB,cAA4C,IAAI;;;;"}
1
+ {"version":3,"file":"PackageContext.js","sources":["PackageContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from \"react\";\nimport type { PackageIntl } from \"../i18n\";\nimport type { Service } from \"../Service\";\nimport type { UseServiceOptions } from \"./hooks\";\n\nexport interface PackageContextMethods {\n getService: (packageName: string, interfaceName: string, options: UseServiceOptions) => Service;\n getServices: (packageName: string, interfaceName: string) => Service[];\n getProperties: (packageName: string) => Readonly<Record<string, unknown>>;\n\n /**\n * NOTE: Reactive for fine grained i18n changes (during dev for i18n HMR) and for live local changes (also in production).\n */\n getIntl(packageName: string): PackageIntl;\n}\n\nexport const PackageContext = createContext<PackageContextMethods | null>(null);\n"],"names":[],"mappings":";;AAmBO,MAAM,cAAA,GAAiB,cAA4C,IAAI;;;;"}
@@ -1,10 +1,10 @@
1
1
  import { SystemConfig } from "@chakra-ui/react";
2
2
  import { ReadonlyReactive } from "@conterra/reactivity-core";
3
3
  import { ReactNode } from "react";
4
+ import { ColorModeValue } from "../api";
4
5
  import { RootNode } from "../dom";
5
6
  import { PackageRepr } from "../service-layer/PackageRepr";
6
7
  import { ServiceLayer } from "../service-layer/ServiceLayer";
7
- import { ColorModeValue } from "../api";
8
8
  export interface ReactIntegrationOptions {
9
9
  rootNode: RootNode;
10
10
  hostNode: HTMLElement;
@@ -1 +1 @@
1
- {"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig, TooltipPropsProvider } from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ReactNode, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"./ChakraProvider\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { ColorModeValue } from \"../api\";\n\nexport interface ReactIntegrationOptions {\n rootNode: RootNode;\n hostNode: HTMLElement;\n appRoot: HTMLDivElement;\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n\n locale: ReadonlyReactive<string>;\n config?: ReadonlyReactive<SystemConfig | undefined>;\n styles: ReadonlyReactive<string>;\n colorMode: ReadonlyReactive<ColorModeValue>;\n}\n\nexport class ReactIntegration {\n #rootNode: RootNode;\n #hostNode: HTMLElement;\n #appRoot: HTMLDivElement;\n #reactRoot: Root;\n #packageContext: PackageContextMethods;\n #locale: ReadonlyReactive<string>;\n #chakraConfig?: ReadonlyReactive<SystemConfig | undefined>;\n #styles: ReadonlyReactive<string>;\n #colorMode: ReadonlyReactive<ColorModeValue>;\n\n static createForApp(options: ReactIntegrationOptions): ReactIntegration {\n const { serviceLayer, packages } = options;\n const packageContext = createPackageContext(serviceLayer, packages);\n return new ReactIntegration({ ...options, packageContext });\n }\n\n static createForErrorScreen(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\">\n ) {\n const throwError = () => {\n throw new Error(ErrorId.INVALID_STATE, \"Hook cannot be used within the error screen.\");\n };\n const packageContext: PackageContextMethods = {\n getIntl: throwError,\n getProperties: throwError,\n getService: throwError,\n getServices: throwError\n };\n return new ReactIntegration({ ...options, packageContext });\n }\n\n private constructor(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\"> & {\n packageContext: PackageContextMethods;\n }\n ) {\n this.#rootNode = options.rootNode;\n this.#hostNode = options.hostNode;\n this.#appRoot = options.appRoot;\n this.#reactRoot = createRoot(options.appRoot);\n this.#chakraConfig = options.config;\n this.#packageContext = options.packageContext;\n this.#locale = options.locale;\n this.#styles = options.styles;\n this.#colorMode = options.colorMode;\n }\n\n render(contentNode: ReactNode) {\n this.#reactRoot.render(\n <StrictMode>\n <CustomChakraProvider\n rootNode={this.#rootNode}\n hostNode={this.#hostNode}\n appRoot={this.#appRoot}\n config={this.#chakraConfig}\n locale={this.#locale}\n styles={this.#styles}\n colorMode={this.#colorMode}\n >\n {/*TooltipPropsProvider sets shorter `openDelay` for globally all Tooltips (500 ms instead of 1000 ms)*/}\n <TooltipPropsProvider value={{ openDelay: 500 }}>\n <PackageContext.Provider value={this.#packageContext}>\n {contentNode}\n </PackageContext.Provider>\n </TooltipPropsProvider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.#reactRoot.unmount();\n }\n}\n\nexport function EmptyComponent(): ReactNode {\n return null;\n}\n\nfunction createPackageContext(\n serviceLayer: ServiceLayer,\n packages: Map<string, PackageRepr>\n): PackageContextMethods {\n const getPackage = (packageName: string): PackageRepr => {\n const pkg = packages.get(packageName);\n if (!pkg) {\n throw new Error(\n ErrorId.INTERNAL,\n `Package '${packageName}' was not found in application.`\n );\n }\n return pkg;\n };\n\n const packageContext: PackageContextMethods = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = serviceLayer.getService(packageName, spec);\n if (result.type === \"found\") {\n return result.value.getInstanceOrThrow();\n }\n\n const renderedSpec = renderInterfaceSpec(spec);\n switch (result.type) {\n case \"unimplemented\":\n throw new Error(\n ErrorId.INTERFACE_NOT_FOUND,\n `The UI of package '${packageName}' requested the unimplemented interface ${renderedSpec}.`\n );\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on interface ${renderedSpec}.` +\n ` Add the dependency to the package configuration or remove the usage.`\n );\n case \"ambiguous\": {\n const renderedChoices = renderAmbiguousServiceChoices(result.choices);\n throw new Error(\n ErrorId.AMBIGUOUS_DEPENDENCY,\n `The UI of package '${packageName}' requires the ambiguous interface ${renderedSpec}.` +\n ` Possible choices are: ${renderedChoices}.`\n );\n }\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getServices: (packageName, interfaceName) => {\n const result = serviceLayer.getServices(packageName, interfaceName);\n if (result.type === \"found\") {\n return result.value.map((serviceRepr) => serviceRepr.getInstanceOrThrow());\n }\n\n switch (result.type) {\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on all services implementing interface '${interfaceName}'.` +\n ` Add the dependency (\"all\": true) to the package configuration or remove the usage.`\n );\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getProperties: (packageName) => {\n return getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return getPackage(packageName).intl.value;\n }\n };\n return packageContext;\n}\n\nfunction missingPackageMessage(packageName: string, interfaceName: string) {\n return (\n `Package '${packageName}' was not found in the application's metadata while it attempted to reference the interface '${interfaceName}'. ` +\n `Check that the dependency is declared correctly in the packages that use '${packageName}'.`\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BO,MAAM,gBAAA,CAAiB;AAAA,EAC1B,SAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,aAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EAEA,OAAO,aAAa,OAAA,EAAoD;AACpE,IAAA,MAAM,EAAE,YAAA,EAAc,QAAA,EAAS,GAAI,OAAA;AACnC,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,YAAA,EAAc,QAAQ,CAAA;AAClE,IAAA,OAAO,IAAI,gBAAA,CAAiB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,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,qBAAA;AAAA,YACR,CAAA,SAAA,EAAY,WAAW,CAAA,2EAAA,EAA8E,aAAa,CAAA,qFAAA;AAAA,WAEtH;AAAA,QACJ,KAAK,iBAAA;AACD,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,eAAA;AAAA,YACR,qBAAA,CAAsB,aAAa,aAAa;AAAA,WACpD;AAAA;AACR,IACJ,CAAA;AAAA,IACA,aAAA,EAAe,CAAC,WAAA,KAAgB;AAC5B,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,UAAA;AAAA,IACnC,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,WAAA,KAAgB;AACtB,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,IAAA,CAAK,KAAA;AAAA,IACxC;AAAA,GACJ;AACA,EAAA,OAAO,cAAA;AACX;AAEA,SAAS,qBAAA,CAAsB,aAAqB,aAAA,EAAuB;AACvE,EAAA,OACI,CAAA,SAAA,EAAY,WAAW,CAAA,6FAAA,EAAgG,aAAa,gFACvD,WAAW,CAAA,EAAA,CAAA;AAEhG;;;;"}
1
+ {"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SystemConfig, TooltipPropsProvider } from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ReactNode, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { ColorModeValue } from \"../api\";\nimport { RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"./ChakraProvider\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\n\nexport interface ReactIntegrationOptions {\n rootNode: RootNode;\n hostNode: HTMLElement;\n appRoot: HTMLDivElement;\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n\n locale: ReadonlyReactive<string>;\n config?: ReadonlyReactive<SystemConfig | undefined>;\n styles: ReadonlyReactive<string>;\n colorMode: ReadonlyReactive<ColorModeValue>;\n}\n\nexport class ReactIntegration {\n #rootNode: RootNode;\n #hostNode: HTMLElement;\n #appRoot: HTMLDivElement;\n #reactRoot: Root;\n #packageContext: PackageContextMethods;\n #locale: ReadonlyReactive<string>;\n #chakraConfig?: ReadonlyReactive<SystemConfig | undefined>;\n #styles: ReadonlyReactive<string>;\n #colorMode: ReadonlyReactive<ColorModeValue>;\n\n static createForApp(options: ReactIntegrationOptions): ReactIntegration {\n const { serviceLayer, packages } = options;\n const packageContext = createPackageContext(serviceLayer, packages);\n return new ReactIntegration({ ...options, packageContext });\n }\n\n static createForErrorScreen(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\">\n ) {\n const throwError = () => {\n throw new Error(ErrorId.INVALID_STATE, \"Hook cannot be used within the error screen.\");\n };\n const packageContext: PackageContextMethods = {\n getIntl: throwError,\n getProperties: throwError,\n getService: throwError,\n getServices: throwError\n };\n return new ReactIntegration({ ...options, packageContext });\n }\n\n private constructor(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\"> & {\n packageContext: PackageContextMethods;\n }\n ) {\n this.#rootNode = options.rootNode;\n this.#hostNode = options.hostNode;\n this.#appRoot = options.appRoot;\n this.#reactRoot = createRoot(options.appRoot);\n this.#chakraConfig = options.config;\n this.#packageContext = options.packageContext;\n this.#locale = options.locale;\n this.#styles = options.styles;\n this.#colorMode = options.colorMode;\n }\n\n render(contentNode: ReactNode) {\n this.#reactRoot.render(\n <StrictMode>\n <CustomChakraProvider\n rootNode={this.#rootNode}\n hostNode={this.#hostNode}\n appRoot={this.#appRoot}\n config={this.#chakraConfig}\n locale={this.#locale}\n styles={this.#styles}\n colorMode={this.#colorMode}\n >\n {/*TooltipPropsProvider sets shorter `openDelay` for globally all Tooltips (500 ms instead of 1000 ms)*/}\n <TooltipPropsProvider value={{ openDelay: 500 }}>\n <PackageContext.Provider value={this.#packageContext}>\n {contentNode}\n </PackageContext.Provider>\n </TooltipPropsProvider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.#reactRoot.unmount();\n }\n}\n\nexport function EmptyComponent(): ReactNode {\n return null;\n}\n\nfunction createPackageContext(\n serviceLayer: ServiceLayer,\n packages: Map<string, PackageRepr>\n): PackageContextMethods {\n const getPackage = (packageName: string): PackageRepr => {\n const pkg = packages.get(packageName);\n if (!pkg) {\n throw new Error(\n ErrorId.INTERNAL,\n `Package '${packageName}' was not found in application.`\n );\n }\n return pkg;\n };\n\n const packageContext: PackageContextMethods = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = serviceLayer.getService(packageName, spec);\n if (result.type === \"found\") {\n return result.value.getInstanceOrThrow();\n }\n\n const renderedSpec = renderInterfaceSpec(spec);\n switch (result.type) {\n case \"unimplemented\":\n throw new Error(\n ErrorId.INTERFACE_NOT_FOUND,\n `The UI of package '${packageName}' requested the unimplemented interface ${renderedSpec}.`\n );\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on interface ${renderedSpec}.` +\n ` Add the dependency to the package configuration or remove the usage.`\n );\n case \"ambiguous\": {\n const renderedChoices = renderAmbiguousServiceChoices(result.choices);\n throw new Error(\n ErrorId.AMBIGUOUS_DEPENDENCY,\n `The UI of package '${packageName}' requires the ambiguous interface ${renderedSpec}.` +\n ` Possible choices are: ${renderedChoices}.`\n );\n }\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getServices: (packageName, interfaceName) => {\n const result = serviceLayer.getServices(packageName, interfaceName);\n if (result.type === \"found\") {\n return result.value.map((serviceRepr) => serviceRepr.getInstanceOrThrow());\n }\n\n switch (result.type) {\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on all services implementing interface '${interfaceName}'.` +\n ` Add the dependency (\"all\": true) to the package configuration or remove the usage.`\n );\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getProperties: (packageName) => {\n return getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return getPackage(packageName).intl.value;\n }\n };\n return packageContext;\n}\n\nfunction missingPackageMessage(packageName: string, interfaceName: string) {\n return (\n `Package '${packageName}' was not found in the application's metadata while it attempted to reference the interface '${interfaceName}'. ` +\n `Check that the dependency is declared correctly in the packages that use '${packageName}'.`\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA+BO,MAAM,gBAAA,CAAiB;AAAA,EAC1B,SAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,aAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EAEA,OAAO,aAAa,OAAA,EAAoD;AACpE,IAAA,MAAM,EAAE,YAAA,EAAc,QAAA,EAAS,GAAI,OAAA;AACnC,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,YAAA,EAAc,QAAQ,CAAA;AAClE,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEA,OAAO,qBACH,OAAA,EACF;AACE,IAAA,MAAM,aAAa,MAAM;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,OA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A;AACD,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,eAAA;AAAA,YACR,qBAAA,CAAsB,aAAa,aAAa;AAAA,WACpD;AAAA;AACR,IACJ,CAAA;AAAA,IACA,aAAA,EAAe,CAAC,WAAA,KAAgB;AAC5B,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,UAAA;AAAA,IACnC,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,WAAA,KAAgB;AACtB,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,IAAA,CAAK,KAAA;AAAA,IACxC;AAAA,GACJ;AACA,EAAA,OAAO,cAAA;AACX;AAEA,SAAS,qBAAA,CAAsB,aAAqB,aAAA,EAAuB;AACvE,EAAA,OACI,CAAA,SAAA,EAAY,WAAW,CAAA,6FAAA,EAAgG,aAAa,gFACvD,WAAW,CAAA,EAAA,CAAA;AAEhG;;;;"}
@@ -1,8 +1,8 @@
1
1
  import { Error } from '@open-pioneer/core';
2
+ import { useReactiveSnapshot } from '@open-pioneer/reactivity';
2
3
  import { useContext, useMemo } from 'react';
3
4
  import { ErrorId } from '../errors.js';
4
5
  import { PackageContext } from './PackageContext.js';
5
- import { useReactiveSnapshot } from '@open-pioneer/reactivity';
6
6
 
7
7
  function useServiceInternal(packageName, interfaceName, options) {
8
8
  const context = useContext(PackageContext);
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { useContext, useMemo } from \"react\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API, although they should not be called directly.\n They are imported by code generated during separate package compilation generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\n\n They are also imported by the vite plugin during development and when building an application.\n\n The matching exports are in the neighboring `index.ts`.\n The interfaces of these hooks must remain stable so that already published packages can continue to work in the future.\n\n See also the implementation of @open-pioneer/build-package.\n\n*/\n\nexport interface UseServiceOptions {\n /** An additional qualifier to disambiguate service instances that implement the same interface. */\n qualifier?: string;\n}\n\n/**\n * Returns a service that implements the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServiceInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType;\nexport function useServiceInternal(\n packageName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interfaceName: any,\n options?: UseServiceOptions\n): unknown {\n const context = useContext(PackageContext);\n const service = useMemo(\n () =>\n checkContext(\"useService\", context).getService(\n packageName,\n interfaceName,\n options ?? {}\n ),\n [context, packageName, interfaceName, options]\n );\n return service;\n}\n\n/**\n * Returns all services that implement the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServicesInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType[];\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useServicesInternal(packageName: string, interfaceName: any): unknown[] {\n const context = useContext(PackageContext);\n const services = useMemo(\n () => checkContext(\"useServices\", context).getServices(packageName, interfaceName),\n [context, packageName, interfaceName]\n );\n return services;\n}\n\n/**\n * Returns the properties for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>> {\n const context = useContext(PackageContext);\n return checkContext(\"useProperties\", context).getProperties(packageName);\n}\n\n/**\n * Returns the i18n object for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useIntlInternal(packageName: string): PackageIntl {\n const context = useContext(PackageContext);\n const contextData = checkContext(\"useIntl\", context);\n const intl = useReactiveSnapshot(\n () => contextData.getIntl(packageName),\n [packageName, contextData]\n );\n return intl;\n}\n\nfunction checkContext(\n hookName: string,\n contextData: PackageContextMethods | null\n): PackageContextMethods {\n if (!contextData) {\n throw new Error(\n ErrorId.INTERNAL,\n `\"Failed to access package context from '${hookName}': react integration was not set up properly.`\n );\n }\n return contextData;\n}\n"],"names":[],"mappings":";;;;;;AAgDO,SAAS,kBAAA,CACZ,WAAA,EAEA,aAAA,EACA,OAAA,EACO;AACP,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,OAAA,GAAU,OAAA;AAAA,IACZ,MACI,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA,CAAE,UAAA;AAAA,MAChC,WAAA;AAAA,MACA,aAAA;AAAA,MACA,WAAW;AAAC,KAChB;AAAA,IACJ,CAAC,OAAA,EAAS,WAAA,EAAa,aAAA,EAAe,OAAO;AAAA,GACjD;AACA,EAAA,OAAO,OAAA;AACX;AAiBO,SAAS,mBAAA,CAAoB,aAAqB,aAAA,EAA+B;AACpF,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,QAAA,GAAW,OAAA;AAAA,IACb,MAAM,YAAA,CAAa,aAAA,EAAe,OAAO,CAAA,CAAE,WAAA,CAAY,aAAa,aAAa,CAAA;AAAA,IACjF,CAAC,OAAA,EAAS,WAAA,EAAa,aAAa;AAAA,GACxC;AACA,EAAA,OAAO,QAAA;AACX;AAUO,SAAS,sBAAsB,WAAA,EAAwD;AAC1F,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,OAAO,YAAA,CAAa,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,WAAW,CAAA;AAC3E;AAUO,SAAS,gBAAgB,WAAA,EAAkC;AAC9D,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,YAAA,CAAa,SAAA,EAAW,OAAO,CAAA;AACnD,EAAA,MAAM,IAAA,GAAO,mBAAA;AAAA,IACT,MAAM,WAAA,CAAY,OAAA,CAAQ,WAAW,CAAA;AAAA,IACrC,CAAC,aAAa,WAAW;AAAA,GAC7B;AACA,EAAA,OAAO,IAAA;AACX;AAEA,SAAS,YAAA,CACL,UACA,WAAA,EACqB;AACrB,EAAA,IAAI,CAAC,WAAA,EAAa;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,2CAA2C,QAAQ,CAAA,6CAAA;AAAA,KACvD;AAAA,EACJ;AACA,EAAA,OAAO,WAAA;AACX;;;;"}
1
+ {"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { useContext, useMemo } from \"react\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API, although they should not be called directly.\n They are imported by code generated during separate package compilation generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\n\n They are also imported by the vite plugin during development and when building an application.\n\n The matching exports are in the neighboring `index.ts`.\n The interfaces of these hooks must remain stable so that already published packages can continue to work in the future.\n\n See also the implementation of @open-pioneer/build-package.\n\n*/\n\nexport interface UseServiceOptions {\n /** An additional qualifier to disambiguate service instances that implement the same interface. */\n qualifier?: string;\n}\n\n/**\n * Returns a service that implements the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServiceInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType;\nexport function useServiceInternal(\n packageName: string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n interfaceName: any,\n options?: UseServiceOptions\n): unknown {\n const context = useContext(PackageContext);\n const service = useMemo(\n () =>\n checkContext(\"useService\", context).getService(\n packageName,\n interfaceName,\n options ?? {}\n ),\n [context, packageName, interfaceName, options]\n );\n return service;\n}\n\n/**\n * Returns all services that implement the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServicesInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType[];\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useServicesInternal(packageName: string, interfaceName: any): unknown[] {\n const context = useContext(PackageContext);\n const services = useMemo(\n () => checkContext(\"useServices\", context).getServices(packageName, interfaceName),\n [context, packageName, interfaceName]\n );\n return services;\n}\n\n/**\n * Returns the properties for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>> {\n const context = useContext(PackageContext);\n return checkContext(\"useProperties\", context).getProperties(packageName);\n}\n\n/**\n * Returns the i18n object for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useIntlInternal(packageName: string): PackageIntl {\n const context = useContext(PackageContext);\n const contextData = checkContext(\"useIntl\", context);\n const intl = useReactiveSnapshot(\n () => contextData.getIntl(packageName),\n [packageName, contextData]\n );\n return intl;\n}\n\nfunction checkContext(\n hookName: string,\n contextData: PackageContextMethods | null\n): PackageContextMethods {\n if (!contextData) {\n throw new Error(\n ErrorId.INTERNAL,\n `\"Failed to access package context from '${hookName}': react integration was not set up properly.`\n );\n }\n return contextData;\n}\n"],"names":[],"mappings":";;;;;;AAiDO,SAAS,kBAAA,CACZ,WAAA,EAEA,aAAA,EACA,OAAA,EACO;AACP,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,OAAA,GAAU,OAAA;AAAA,IACZ,MACI,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA,CAAE,UAAA;AAAA,MAChC,WAAA;AAAA,MACA,aAAA;AAAA,MACA,WAAW;AAAC,KAChB;AAAA,IACJ,CAAC,OAAA,EAAS,WAAA,EAAa,aAAA,EAAe,OAAO;AAAA,GACjD;AACA,EAAA,OAAO,OAAA;AACX;AAiBO,SAAS,mBAAA,CAAoB,aAAqB,aAAA,EAA+B;AACpF,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,QAAA,GAAW,OAAA;AAAA,IACb,MAAM,YAAA,CAAa,aAAA,EAAe,OAAO,CAAA,CAAE,WAAA,CAAY,aAAa,aAAa,CAAA;AAAA,IACjF,CAAC,OAAA,EAAS,WAAA,EAAa,aAAa;AAAA,GACxC;AACA,EAAA,OAAO,QAAA;AACX;AAUO,SAAS,sBAAsB,WAAA,EAAwD;AAC1F,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,OAAO,YAAA,CAAa,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,WAAW,CAAA;AAC3E;AAUO,SAAS,gBAAgB,WAAA,EAAkC;AAC9D,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,YAAA,CAAa,SAAA,EAAW,OAAO,CAAA;AACnD,EAAA,MAAM,IAAA,GAAO,mBAAA;AAAA,IACT,MAAM,WAAA,CAAY,OAAA,CAAQ,WAAW,CAAA;AAAA,IACrC,CAAC,aAAa,WAAW;AAAA,GAC7B;AACA,EAAA,OAAO,IAAA;AACX;AAEA,SAAS,YAAA,CACL,UACA,WAAA,EACqB;AACrB,EAAA,IAAI,CAAC,WAAA,EAAa;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,2CAA2C,QAAQ,CAAA,6CAAA;AAAA,KACvD;AAAA,EACJ;AACA,EAAA,OAAO,WAAA;AACX;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"InterfaceSpec.js","sources":["InterfaceSpec.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceReferenceMetadata } from \"../metadata\";\n\n/**\n * Describes the implementation of an interface.\n */\nexport interface InterfaceSpec {\n interfaceName: string;\n qualifier?: string | undefined;\n}\n\nexport function renderInterfaceSpec({ interfaceName, qualifier }: InterfaceSpec): string {\n return `'${interfaceName}'` + (qualifier ? ` (qualifier: '${qualifier}')` : \"\");\n}\n\nexport interface SingleImplementationSpec extends InterfaceSpec {\n all?: undefined;\n}\n\nexport interface AllImplementationsSpec extends Pick<InterfaceSpec, \"interfaceName\"> {\n all: true;\n}\n\n/**\n * Describes a reference to one or more implementations of an interface.\n */\nexport type ReferenceSpec = SingleImplementationSpec | AllImplementationsSpec;\n\nexport function parseReferenceSpec(metadata: InterfaceReferenceMetadata): ReferenceSpec {\n if (!metadata) {\n throw new Error(ErrorId.INVALID_METADATA, \"Missing reference metadata.\");\n }\n if (metadata.all && metadata.qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"References can't use 'qualifier' and 'all' properties at the same time.\"\n );\n }\n if (metadata.all) {\n return {\n all: true,\n interfaceName: metadata.name\n };\n }\n return {\n interfaceName: metadata.name,\n qualifier: metadata.qualifier\n };\n}\n\nexport function isSingleImplementationSpec(spec: ReferenceSpec): spec is SingleImplementationSpec {\n return !spec.all;\n}\n\nexport function isAllImplementationsSpec(spec: ReferenceSpec): spec is AllImplementationsSpec {\n return spec.all === true;\n}\n"],"names":[],"mappings":";;;AAcO,SAAS,mBAAA,CAAoB,EAAE,aAAA,EAAe,SAAA,EAAU,EAA0B;AACrF,EAAA,OAAO,IAAI,aAAa,CAAA,CAAA,CAAA,IAAO,SAAA,GAAY,CAAA,cAAA,EAAiB,SAAS,CAAA,EAAA,CAAA,GAAO,EAAA,CAAA;AAChF;AAeO,SAAS,mBAAmB,QAAA,EAAqD;AACpF,EAAA,IAAI,CAAC,QAAA,EAAU;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,gBAAA,EAAkB,6BAA6B,CAAA;AAAA,EAC3E;AACA,EAAA,IAAI,QAAA,CAAS,GAAA,IAAO,QAAA,CAAS,SAAA,EAAW;AACpC,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,gBAAA;AAAA,MACR;AAAA,KACJ;AAAA,EACJ;AACA,EAAA,IAAI,SAAS,GAAA,EAAK;AACd,IAAA,OAAO;AAAA,MACH,GAAA,EAAK,IAAA;AAAA,MACL,eAAe,QAAA,CAAS;AAAA,KAC5B;AAAA,EACJ;AACA,EAAA,OAAO;AAAA,IACH,eAAe,QAAA,CAAS,IAAA;AAAA,IACxB,WAAW,QAAA,CAAS;AAAA,GACxB;AACJ;AAEO,SAAS,2BAA2B,IAAA,EAAuD;AAC9F,EAAA,OAAO,CAAC,IAAA,CAAK,GAAA;AACjB;AAEO,SAAS,yBAAyB,IAAA,EAAqD;AAC1F,EAAA,OAAO,KAAK,GAAA,KAAQ,IAAA;AACxB;;;;"}
1
+ {"version":3,"file":"InterfaceSpec.js","sources":["InterfaceSpec.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceReferenceMetadata } from \"../metadata\";\n\n/**\n * Describes the implementation of an interface.\n */\nexport interface InterfaceSpec {\n interfaceName: string;\n qualifier?: string | undefined;\n}\n\nexport function renderInterfaceSpec({ interfaceName, qualifier }: InterfaceSpec): string {\n return `'${interfaceName}'` + (qualifier ? ` (qualifier: '${qualifier}')` : \"\");\n}\n\nexport interface SingleImplementationSpec extends InterfaceSpec {\n all?: undefined;\n}\n\nexport interface AllImplementationsSpec extends Pick<InterfaceSpec, \"interfaceName\"> {\n all: true;\n}\n\n/**\n * Describes a reference to one or more implementations of an interface.\n */\nexport type ReferenceSpec = SingleImplementationSpec | AllImplementationsSpec;\n\nexport function parseReferenceSpec(metadata: InterfaceReferenceMetadata): ReferenceSpec {\n if (!metadata) {\n throw new Error(ErrorId.INVALID_METADATA, \"Missing reference metadata.\");\n }\n if (metadata.all && metadata.qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"References can't use 'qualifier' and 'all' properties at the same time.\"\n );\n }\n if (metadata.all) {\n return {\n all: true,\n interfaceName: metadata.name\n };\n }\n return {\n interfaceName: metadata.name,\n qualifier: metadata.qualifier\n };\n}\n\nexport function isSingleImplementationSpec(spec: ReferenceSpec): spec is SingleImplementationSpec {\n return !spec.all;\n}\n\nexport function isAllImplementationsSpec(spec: ReferenceSpec): spec is AllImplementationsSpec {\n return spec.all === true;\n}\n"],"names":[],"mappings":";;;AAeO,SAAS,mBAAA,CAAoB,EAAE,aAAA,EAAe,SAAA,EAAU,EAA0B;AACrF,EAAA,OAAO,IAAI,aAAa,CAAA,CAAA,CAAA,IAAO,SAAA,GAAY,CAAA,cAAA,EAAiB,SAAS,CAAA,EAAA,CAAA,GAAO,EAAA,CAAA;AAChF;AAeO,SAAS,mBAAmB,QAAA,EAAqD;AACpF,EAAA,IAAI,CAAC,QAAA,EAAU;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,gBAAA,EAAkB,6BAA6B,CAAA;AAAA,EAC3E;AACA,EAAA,IAAI,QAAA,CAAS,GAAA,IAAO,QAAA,CAAS,SAAA,EAAW;AACpC,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,gBAAA;AAAA,MACR;AAAA,KACJ;AAAA,EACJ;AACA,EAAA,IAAI,SAAS,GAAA,EAAK;AACd,IAAA,OAAO;AAAA,MACH,GAAA,EAAK,IAAA;AAAA,MACL,eAAe,QAAA,CAAS;AAAA,KAC5B;AAAA,EACJ;AACA,EAAA,OAAO;AAAA,IACH,eAAe,QAAA,CAAS,IAAA;AAAA,IACxB,WAAW,QAAA,CAAS;AAAA,GACxB;AACJ;AAEO,SAAS,2BAA2B,IAAA,EAAuD;AAC9F,EAAA,OAAO,CAAC,IAAA,CAAK,GAAA;AACjB;AAEO,SAAS,yBAAyB,IAAA,EAAqD;AAC1F,EAAA,OAAO,KAAK,GAAA,KAAQ,IAAA;AACxB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PackageRepr.js","sources":["PackageRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ApplicationProperties } from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, PackageIntl } from \"../i18n\";\nimport { PackageMetadata, PropertyMetadata } from \"../metadata\";\nimport { parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface PackageReprOptions {\n name: string;\n intl: ReadonlyReactive<PackageIntl>;\n services?: ServiceRepr[];\n uiReferences?: ReferenceSpec[];\n properties?: Record<string, unknown>;\n}\n\nexport class PackageRepr {\n static create(\n data: PackageMetadata,\n intl: ReadonlyReactive<PackageIntl>,\n customProperties?: Record<string, unknown>\n ): PackageRepr {\n const name = data.name;\n const properties = data.properties ?? {};\n const finalProperties = customizeProperties(name, properties, customProperties);\n const services = Object.entries(data.services ?? {}).map<ServiceRepr>(\n ([name, serviceData]) => {\n if (name !== serviceData.name) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"Invalid metadata: service name mismatch.\"\n );\n }\n return ServiceRepr.create(data.name, serviceData, intl, finalProperties);\n }\n );\n const uiReferences = data.ui?.references?.map((ref) => parseReferenceSpec(ref)) ?? [];\n return new PackageRepr({\n name,\n services,\n uiReferences,\n properties: finalProperties,\n intl: intl\n });\n }\n\n /** Package name */\n readonly name: string;\n\n /** Services defined by the package */\n readonly services: readonly ServiceRepr[];\n\n /** Interfaces required by UI components. */\n readonly uiReferences: readonly Readonly<ReferenceSpec>[];\n\n /** Resolved (perhaps customized) package properties. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Locale-dependant i18n messages. */\n readonly intl: ReadonlyReactive<PackageIntl>;\n\n constructor(options: PackageReprOptions) {\n const name = options.name;\n if (!isValidPackageName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid package name: '${name}'.`);\n }\n\n this.name = name;\n this.services = options.services ?? [];\n this.uiReferences = options.uiReferences ?? [];\n this.properties = options.properties ?? {};\n this.intl = options.intl;\n }\n}\n\nexport function createPackages(\n packages: Record<string, PackageMetadata>,\n i18n: AppIntl,\n customProperties?: ApplicationProperties\n) {\n return Object.entries(packages).map<PackageRepr>(([name, packageMetadata]) => {\n if (name !== packageMetadata.name) {\n throw new Error(ErrorId.INVALID_METADATA, \"Invalid metadata: package name mismatch.\");\n }\n\n const packageI18n = i18n.createPackageI18n(name);\n return PackageRepr.create(packageMetadata, packageI18n, customProperties?.[name]);\n });\n}\n\n/**\n * Merges the declared properties of the package with the application-defined\n * custom properties.\n */\nfunction customizeProperties(\n packageName: string,\n properties: Record<string, PropertyMetadata>,\n customProperties: Record<string, unknown> = {}\n) {\n const merged: Record<string, unknown> = {};\n const required: string[] = [];\n for (const [key, propertyMetadata] of Object.entries(properties)) {\n merged[key] = propertyMetadata.value;\n if (propertyMetadata.required) {\n required.push(key);\n }\n }\n\n for (const [key, value] of Object.entries(customProperties)) {\n if (!hasProperty(merged, key)) {\n throw new Error(\n ErrorId.INVALID_PROPERTY_NAME,\n `Unexpected property name '${key}' for package '${packageName}': the property does not exist.`\n );\n }\n merged[key] = value;\n }\n\n for (const key of required) {\n const value = merged[key];\n if (value == null) {\n throw new Error(\n ErrorId.REQUIRED_PROPERTY,\n `Package '${packageName}' requires the property '${key}' to be initialized to a non-null value.`\n );\n }\n }\n\n return merged;\n}\n\nconst HAS_PROP = Object.prototype.hasOwnProperty;\n\nfunction hasProperty(object: unknown, key: string) {\n return HAS_PROP.call(object, key);\n}\n\n// http://json.schemastore.org/package\nconst NAME_REGEX = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/;\n\nfunction isValidPackageName(name: string): boolean {\n return NAME_REGEX.test(name);\n}\n"],"names":["name"],"mappings":";;;;;AAmBO,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,IAAA,EACA,IAAA,EACA,gBAAA,EACW;AACX,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AAClB,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,UAAA,IAAc,EAAC;AACvC,IAAA,MAAM,eAAA,GAAkB,mBAAA,CAAoB,IAAA,EAAM,UAAA,EAAY,gBAAgB,CAAA;AAC9E,IAAA,MAAM,WAAW,MAAA,CAAO,OAAA,CAAQ,KAAK,QAAA,IAAY,EAAE,CAAA,CAAE,GAAA;AAAA,MACjD,CAAC,CAACA,KAAAA,EAAM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,+BAAA;AAAA,OACjE;AAAA,IACJ;AACA,IAAA,MAAA,CAAO,GAAG,CAAA,GAAI,KAAA;AAAA,EAClB;AAEA,EAAA,KAAA,MAAW,OAAO,QAAA,EAAU;AACxB,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,SAAS,IAAA,EAAM;AACf,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,iBAAA;AAAA,QACR,CAAA,SAAA,EAAY,WAAW,CAAA,yBAAA,EAA4B,GAAG,CAAA,wCAAA;AAAA,OAC1D;AAAA,IACJ;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA;AACX;AAEA,MAAM,QAAA,GAAW,OAAO,SAAA,CAAU,cAAA;AAElC,SAAS,WAAA,CAAY,QAAiB,GAAA,EAAa;AAC/C,EAAA,OAAO,QAAA,CAAS,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA;AACpC;AAGA,MAAM,UAAA,GAAa,4DAAA;AAEnB,SAAS,mBAAmB,IAAA,EAAuB;AAC/C,EAAA,OAAO,UAAA,CAAW,KAAK,IAAI,CAAA;AAC/B;;;;"}
1
+ {"version":3,"file":"PackageRepr.js","sources":["PackageRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ApplicationProperties } from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, PackageIntl } from \"../i18n\";\nimport { PackageMetadata, PropertyMetadata } from \"../metadata\";\nimport { parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface PackageReprOptions {\n name: string;\n intl: ReadonlyReactive<PackageIntl>;\n services?: ServiceRepr[];\n uiReferences?: ReferenceSpec[];\n properties?: Record<string, unknown>;\n}\n\nexport class PackageRepr {\n static create(\n data: PackageMetadata,\n intl: ReadonlyReactive<PackageIntl>,\n customProperties?: Record<string, unknown>\n ): PackageRepr {\n const name = data.name;\n const properties = data.properties ?? {};\n const finalProperties = customizeProperties(name, properties, customProperties);\n const services = Object.entries(data.services ?? {}).map<ServiceRepr>(\n ([name, serviceData]) => {\n if (name !== serviceData.name) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"Invalid metadata: service name mismatch.\"\n );\n }\n return ServiceRepr.create(data.name, serviceData, intl, finalProperties);\n }\n );\n const uiReferences = data.ui?.references?.map((ref) => parseReferenceSpec(ref)) ?? [];\n return new PackageRepr({\n name,\n services,\n uiReferences,\n properties: finalProperties,\n intl: intl\n });\n }\n\n /** Package name */\n readonly name: string;\n\n /** Services defined by the package */\n readonly services: readonly ServiceRepr[];\n\n /** Interfaces required by UI components. */\n readonly uiReferences: readonly Readonly<ReferenceSpec>[];\n\n /** Resolved (perhaps customized) package properties. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Locale-dependant i18n messages. */\n readonly intl: ReadonlyReactive<PackageIntl>;\n\n constructor(options: PackageReprOptions) {\n const name = options.name;\n if (!isValidPackageName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid package name: '${name}'.`);\n }\n\n this.name = name;\n this.services = options.services ?? [];\n this.uiReferences = options.uiReferences ?? [];\n this.properties = options.properties ?? {};\n this.intl = options.intl;\n }\n}\n\nexport function createPackages(\n packages: Record<string, PackageMetadata>,\n i18n: AppIntl,\n customProperties?: ApplicationProperties\n) {\n return Object.entries(packages).map<PackageRepr>(([name, packageMetadata]) => {\n if (name !== packageMetadata.name) {\n throw new Error(ErrorId.INVALID_METADATA, \"Invalid metadata: package name mismatch.\");\n }\n\n const packageI18n = i18n.createPackageI18n(name);\n return PackageRepr.create(packageMetadata, packageI18n, customProperties?.[name]);\n });\n}\n\n/**\n * Merges the declared properties of the package with the application-defined\n * custom properties.\n */\nfunction customizeProperties(\n packageName: string,\n properties: Record<string, PropertyMetadata>,\n customProperties: Record<string, unknown> = {}\n) {\n const merged: Record<string, unknown> = {};\n const required: string[] = [];\n for (const [key, propertyMetadata] of Object.entries(properties)) {\n merged[key] = propertyMetadata.value;\n if (propertyMetadata.required) {\n required.push(key);\n }\n }\n\n for (const [key, value] of Object.entries(customProperties)) {\n if (!hasProperty(merged, key)) {\n throw new Error(\n ErrorId.INVALID_PROPERTY_NAME,\n `Unexpected property name '${key}' for package '${packageName}': the property does not exist.`\n );\n }\n merged[key] = value;\n }\n\n for (const key of required) {\n const value = merged[key];\n if (value == null) {\n throw new Error(\n ErrorId.REQUIRED_PROPERTY,\n `Package '${packageName}' requires the property '${key}' to be initialized to a non-null value.`\n );\n }\n }\n\n return merged;\n}\n\nconst HAS_PROP = Object.prototype.hasOwnProperty;\n\nfunction hasProperty(object: unknown, key: string) {\n return HAS_PROP.call(object, key);\n}\n\n// http://json.schemastore.org/package\nconst NAME_REGEX = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/;\n\nfunction isValidPackageName(name: string): boolean {\n return NAME_REGEX.test(name);\n}\n"],"names":["name"],"mappings":";;;;;AAoBO,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,IAAA,EACA,IAAA,EACA,gBAAA,EACW;AACX,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AAClB,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,UAAA,IAAc,EAAC;AACvC,IAAA,MAAM,eAAA,GAAkB,mBAAA,CAAoB,IAAA,EAAM,UAAA,EAAY,gBAAgB,CAAA;AAC9E,IAAA,MAAM,WAAW,MAAA,CAAO,OAAA,CAAQ,KAAK,QAAA,IAAY,EAAE,CAAA,CAAE,GAAA;AAAA,MACjD,CAAC,CAACA,KAAAA,EAAM,WAAW,CAAA,KAAM;AACrB,QAAA,IAAIA,KAAAA,KAAS,YAAY,IAAA,EAAM;AAC3B,UAAA,MAAM,IAAI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EA,EAAA,KAAA,MAAW,OAAO,QAAA,EAAU;AACxB,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,SAAS,IAAA,EAAM;AACf,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,iBAAA;AAAA,QACR,CAAA,SAAA,EAAY,WAAW,CAAA,yBAAA,EAA4B,GAAG,CAAA,wCAAA;AAAA,OAC1D;AAAA,IACJ;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA;AACX;AAEA,MAAM,QAAA,GAAW,OAAO,SAAA,CAAU,cAAA;AAElC,SAAS,WAAA,CAAY,QAAiB,GAAA,EAAa;AAC/C,EAAA,OAAO,QAAA,CAAS,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA;AACpC;AAGA,MAAM,UAAA,GAAa,4DAAA;AAEnB,SAAS,mBAAmB,IAAA,EAAuB;AAC/C,EAAA,OAAO,UAAA,CAAW,KAAK,IAAI,CAAA;AAC/B;;;;"}
@@ -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 { 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 #allServices: ServiceRepr[];\n\n // Set of required services. These services and their dependencies will be started.\n #requiredServices: Set<ServiceRepr>;\n\n #serviceLookup: ReadonlyServiceLookup;\n\n // Service id --> Service dependencies\n #serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n // Package name --> Interface name --> Declarations\n #declaredDependencies;\n #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 #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 #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 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\n /** Undefined -> everything is okay */\n #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 #getReference(ref: ServiceRepr): [unknown, ReferenceMeta];\n #getReference(ref: ServiceRepr[]): [unknown[], ReferenceMeta[]];\n #getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]];\n #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 #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,EAEtB,YAAA;AAAA;AAAA,EAGA,iBAAA;AAAA,EAEA,cAAA;AAAA;AAAA,EAGA,oBAAA;AAAA;AAAA,EAGA,qBAAA;AAAA,EACA,MAAA,GAAkD,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASlD,WAAA,CAAY,QAAA,EAAkC,gBAAA,GAAoC,EAAC,EAAG;AAClF,IAAA,MAAM,WAAA,GAAc,SAAS,GAAA,CAAI,CAAC,QAAQ,GAAA,CAA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xB,IAAA,MAAM,YAAA,uBAAmB,GAAA,EAAoC;AAC7D,IAAA,KAAA,MAAW,WAAA,IAAe,IAAI,YAAA,EAAc;AACxC,MAAA,IAAI,cAAA,GAAiB,YAAA,CAAa,GAAA,CAAI,WAAA,CAAY,aAAa,CAAA;AAC/D,MAAA,IAAI,CAAC,cAAA,EAAgB;AACjB,QAAA,cAAA,GAAiB;AAAA,UACb,GAAA,EAAK,KAAA;AAAA,UACL,WAAA,EAAa,KAAA;AAAA,UACb,UAAA,sBAAgB,GAAA;AAAY,SAChC;AACA,QAAA,YAAA,CAAa,GAAA,CAAI,WAAA,CAAY,aAAA,EAAe,cAAc,CAAA;AAAA,MAC9D;AAEA,MAAA,IAAI,wBAAA,CAAyB,WAAW,CAAA,EAAG;AACvC,QAAA,cAAA,CAAe,GAAA,GAAM,IAAA;AAAA,MACzB,CAAA,MAAA,IAAW,0BAAA,CAA2B,WAAW,CAAA,EAAG;AAChD,QAAA,IAAI,WAAA,CAAY,aAAa,IAAA,EAAM;AAC/B,UAAA,cAAA,CAAe,WAAA,GAAc,IAAA;AAAA,QACjC,CAAA,MAAO;AACH,UAAA,cAAA,CAAe,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\n\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { RUNTIME_PACKAGE_NAME } from \"../builtin-services\";\nimport { ErrorId } from \"../errors\";\nimport { ReferenceMeta } from \"../Service\";\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 #allServices: ServiceRepr[];\n\n // Set of required services. These services and their dependencies will be started.\n #requiredServices: Set<ServiceRepr>;\n\n #serviceLookup: ReadonlyServiceLookup;\n\n // Service id --> Service dependencies\n #serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n // Package name --> Interface name --> Declarations\n #declaredDependencies;\n #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 #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 // oxlint-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 #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 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\n /** Undefined -> everything is okay */\n #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 #getReference(ref: ServiceRepr): [unknown, ReferenceMeta];\n #getReference(ref: ServiceRepr[]): [unknown[], ReferenceMeta[]];\n #getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]];\n #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 #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":";;;;;;;AAyBA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAkBjC,MAAM,qBAAA,GAAwB,EAAE,IAAA,EAAM,YAAA,EAAa;AACnD,MAAM,eAAA,GAAkB,E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AQ,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 +1 @@
1
- {"version":3,"file":"ServiceLookup.js","sources":["ServiceLookup.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, isSingleImplementationSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\ninterface Services {\n // The unqualified service implementations (if any).\n unqualified: ServiceRepr[];\n\n // Services indexed by their qualifier (if any).\n byQualifier: Map<string, ServiceRepr>;\n}\n\nexport type ReadonlyServiceLookup = Pick<\n ServiceLookup,\n \"lookup\" | \"lookupOne\" | \"lookupAll\" | \"serviceCount\"\n>;\n\nexport interface Unimplemented {\n type: \"unimplemented\";\n}\n\nexport interface Ambiguous {\n type: \"ambiguous\";\n choices: AmbiguousChoice[];\n}\n\nexport type AmbiguousChoice = [serviceId: string, qualifier: string | undefined];\n\nexport interface Found<T> {\n type: \"found\";\n value: T;\n}\n\nexport type ServiceLookupResult = Unimplemented | Ambiguous | Found<ServiceRepr>;\n\nexport type ServicesLookupResult = Found<ServiceRepr[]>;\n\nexport class ServiceLookup {\n // Service implementations indexed by interface name.\n #services = new Map<string, Services>();\n\n // Total service count\n #count = 0;\n\n /**\n * Returns the total number of registered services.\n */\n get serviceCount() {\n return this.#count;\n }\n\n /**\n * Attempts to register the given service as an implementation of `interfaceName`.\n * Throws if the registration did not complete successfully.\n *\n * All services should be registered before any lookups are attempted.\n */\n register(service: ServiceRepr, { interfaceName, qualifier }: InterfaceSpec): void {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Service '${service.id}' provides invalid interface '${interfaceName}'.`\n );\n }\n if (qualifier != null && !qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Service '${service.id}' uses an invalid qualifier for interface '${interfaceName}': '${qualifier}'.`\n );\n }\n\n const services = this.#ensureInterfaceEntry(interfaceName);\n if (!qualifier) {\n services.unqualified.push(service);\n ++this.#count;\n return;\n }\n\n const existingQualified = services.byQualifier.get(qualifier);\n if (existingQualified) {\n throw new Error(\n ErrorId.DUPLICATE_INTERFACE,\n `Cannot register '${service.id}' as interface '${interfaceName}' with qualifier '${qualifier}'.` +\n ` The interface is already provided by service '${existingQualified.id}'.` +\n ` You can choose a different qualifier or remove the service to resolve the collision.`\n );\n }\n services.byQualifier.set(qualifier, service);\n ++this.#count;\n }\n\n /**\n * Attempts to find the service(s) required by the given reference spec.\n */\n lookup(ref: ReferenceSpec): ServiceLookupResult | ServicesLookupResult {\n if (isSingleImplementationSpec(ref)) {\n return this.lookupOne(ref);\n } else {\n return this.lookupAll(ref.interfaceName);\n }\n }\n\n /**\n * Attempts to find a service implementing the given interface.\n */\n lookupOne({ interfaceName, qualifier }: InterfaceSpec): ServiceLookupResult {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid interface name during service lookup: '${interfaceName}'.`\n );\n }\n if (qualifier != null && !qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid qualifier during service lookup of interface '${interfaceName}': '${qualifier}'.`\n );\n }\n\n const services = this.#services.get(interfaceName);\n if (!services) {\n return { type: \"unimplemented\" };\n }\n\n if (!qualifier) {\n // Just pick one, but the choice must be unambiguous.\n const count = services.unqualified.length + services.byQualifier.size;\n if (count > 1) {\n // [serviceId, qualifier] tuples\n const choices: AmbiguousChoice[] = [];\n choices.push(\n ...Array.from(services.byQualifier.entries()).map<AmbiguousChoice>(\n ([qualifier, service]) => [service.id, qualifier]\n )\n );\n choices.push(\n ...services.unqualified.map<AmbiguousChoice>((s) => [s.id, undefined])\n );\n return {\n type: \"ambiguous\",\n choices: choices\n };\n }\n\n const service = services.unqualified[0] ?? first(services.byQualifier);\n if (!service) {\n return { type: \"unimplemented\" };\n }\n return { type: \"found\", value: service };\n }\n\n const service = services.byQualifier.get(qualifier);\n if (!service) {\n return { type: \"unimplemented\" };\n }\n return { type: \"found\", value: service };\n }\n\n /**\n * Returns all services implementing the given interface.\n */\n lookupAll(interfaceName: string): ServicesLookupResult {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid interface name during service lookup: '${interfaceName}'.`\n );\n }\n\n const services = this.#services.get(interfaceName);\n if (!services) {\n return { type: \"found\", value: [] };\n }\n\n const deduped = new Set([...services.unqualified, ...services.byQualifier.values()]);\n return {\n type: \"found\",\n value: Array.from(deduped)\n };\n }\n\n #ensureInterfaceEntry(interfaceName: string): Services {\n const services = this.#services;\n let entry = services.get(interfaceName);\n if (!entry) {\n entry = {\n unqualified: [],\n byQualifier: new Map()\n };\n services.set(interfaceName, entry);\n }\n return entry;\n }\n}\n\nexport function renderAmbiguousServiceChoices(choices: AmbiguousChoice[], max = 3): string {\n let message = \"\";\n let count = 0;\n for (const [serviceId, qualifier] of choices) {\n if (count) {\n message += \", \";\n }\n\n message += `'${serviceId}'`;\n if (qualifier) {\n message += ` (with qualifier '${qualifier}')`;\n }\n\n if (++count >= max) {\n break;\n }\n }\n\n const remaining = choices.length - count;\n if (remaining > 0) {\n message += ` and ${remaining} more`;\n }\n return message;\n}\n\nfunction first<K, V>(map: Map<K, V>): V | undefined {\n return map.values().next().value;\n}\n"],"names":["qualifier","service"],"mappings":";;;;AAwCO,MAAM,aAAA,CAAc;AAAA;AAAA,EAEvB,SAAA,uBAAgB,GAAA,EAAsB;AAAA;AAAA,EAGtC,MAAA,GAAS,CAAA;AAAA;AAAA;AAAA;AAAA,EAKT,IAAI,YAAA,GAAe;AACf,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA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EAAG;AACf,IAAA,OAAA,IAAW,QAAQ,SAAS,CAAA,KAAA,CAAA;AAAA,EAChC;AACA,EAAA,OAAO,OAAA;AACX;AAEA,SAAS,MAAY,GAAA,EAA+B;AAChD,EAAA,OAAO,GAAA,CAAI,MAAA,EAAO,CAAE,IAAA,EAAK,CAAE,KAAA;AAC/B;;;;"}
1
+ {"version":3,"file":"ServiceLookup.js","sources":["ServiceLookup.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, isSingleImplementationSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\ninterface Services {\n // The unqualified service implementations (if any).\n unqualified: ServiceRepr[];\n\n // Services indexed by their qualifier (if any).\n byQualifier: Map<string, ServiceRepr>;\n}\n\nexport type ReadonlyServiceLookup = Pick<\n ServiceLookup,\n \"lookup\" | \"lookupOne\" | \"lookupAll\" | \"serviceCount\"\n>;\n\nexport interface Unimplemented {\n type: \"unimplemented\";\n}\n\nexport interface Ambiguous {\n type: \"ambiguous\";\n choices: AmbiguousChoice[];\n}\n\nexport type AmbiguousChoice = [serviceId: string, qualifier: string | undefined];\n\nexport interface Found<T> {\n type: \"found\";\n value: T;\n}\n\nexport type ServiceLookupResult = Unimplemented | Ambiguous | Found<ServiceRepr>;\n\nexport type ServicesLookupResult = Found<ServiceRepr[]>;\n\nexport class ServiceLookup {\n // Service implementations indexed by interface name.\n #services = new Map<string, Services>();\n\n // Total service count\n #count = 0;\n\n /**\n * Returns the total number of registered services.\n */\n get serviceCount() {\n return this.#count;\n }\n\n /**\n * Attempts to register the given service as an implementation of `interfaceName`.\n * Throws if the registration did not complete successfully.\n *\n * All services should be registered before any lookups are attempted.\n */\n register(service: ServiceRepr, { interfaceName, qualifier }: InterfaceSpec): void {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Service '${service.id}' provides invalid interface '${interfaceName}'.`\n );\n }\n if (qualifier != null && !qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Service '${service.id}' uses an invalid qualifier for interface '${interfaceName}': '${qualifier}'.`\n );\n }\n\n const services = this.#ensureInterfaceEntry(interfaceName);\n if (!qualifier) {\n services.unqualified.push(service);\n ++this.#count;\n return;\n }\n\n const existingQualified = services.byQualifier.get(qualifier);\n if (existingQualified) {\n throw new Error(\n ErrorId.DUPLICATE_INTERFACE,\n `Cannot register '${service.id}' as interface '${interfaceName}' with qualifier '${qualifier}'.` +\n ` The interface is already provided by service '${existingQualified.id}'.` +\n ` You can choose a different qualifier or remove the service to resolve the collision.`\n );\n }\n services.byQualifier.set(qualifier, service);\n ++this.#count;\n }\n\n /**\n * Attempts to find the service(s) required by the given reference spec.\n */\n lookup(ref: ReferenceSpec): ServiceLookupResult | ServicesLookupResult {\n if (isSingleImplementationSpec(ref)) {\n return this.lookupOne(ref);\n } else {\n return this.lookupAll(ref.interfaceName);\n }\n }\n\n /**\n * Attempts to find a service implementing the given interface.\n */\n lookupOne({ interfaceName, qualifier }: InterfaceSpec): ServiceLookupResult {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid interface name during service lookup: '${interfaceName}'.`\n );\n }\n if (qualifier != null && !qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid qualifier during service lookup of interface '${interfaceName}': '${qualifier}'.`\n );\n }\n\n const services = this.#services.get(interfaceName);\n if (!services) {\n return { type: \"unimplemented\" };\n }\n\n if (!qualifier) {\n // Just pick one, but the choice must be unambiguous.\n const count = services.unqualified.length + services.byQualifier.size;\n if (count > 1) {\n // [serviceId, qualifier] tuples\n const choices: AmbiguousChoice[] = [];\n choices.push(\n ...Array.from(services.byQualifier.entries()).map<AmbiguousChoice>(\n ([qualifier, service]) => [service.id, qualifier]\n )\n );\n choices.push(\n ...services.unqualified.map<AmbiguousChoice>((s) => [s.id, undefined])\n );\n return {\n type: \"ambiguous\",\n choices: choices\n };\n }\n\n const service = services.unqualified[0] ?? first(services.byQualifier);\n if (!service) {\n return { type: \"unimplemented\" };\n }\n return { type: \"found\", value: service };\n }\n\n const service = services.byQualifier.get(qualifier);\n if (!service) {\n return { type: \"unimplemented\" };\n }\n return { type: \"found\", value: service };\n }\n\n /**\n * Returns all services implementing the given interface.\n */\n lookupAll(interfaceName: string): ServicesLookupResult {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid interface name during service lookup: '${interfaceName}'.`\n );\n }\n\n const services = this.#services.get(interfaceName);\n if (!services) {\n return { type: \"found\", value: [] };\n }\n\n const deduped = new Set([...services.unqualified, ...services.byQualifier.values()]);\n return {\n type: \"found\",\n value: Array.from(deduped)\n };\n }\n\n #ensureInterfaceEntry(interfaceName: string): Services {\n const services = this.#services;\n let entry = services.get(interfaceName);\n if (!entry) {\n entry = {\n unqualified: [],\n byQualifier: new Map()\n };\n services.set(interfaceName, entry);\n }\n return entry;\n }\n}\n\nexport function renderAmbiguousServiceChoices(choices: AmbiguousChoice[], max = 3): string {\n let message = \"\";\n let count = 0;\n for (const [serviceId, qualifier] of choices) {\n if (count) {\n message += \", \";\n }\n\n message += `'${serviceId}'`;\n if (qualifier) {\n message += ` (with qualifier '${qualifier}')`;\n }\n\n if (++count >= max) {\n break;\n }\n }\n\n const remaining = choices.length - count;\n if (remaining > 0) {\n message += ` and ${remaining} more`;\n }\n return message;\n}\n\nfunction first<K, V>(map: Map<K, V>): V | undefined {\n return map.values().next().value;\n}\n"],"names":["qualifier","service"],"mappings":";;;;AAyCO,MAAM,aAAA,CAAc;AAAA;AAAA,EAEvB,SAAA,uBAAgB,GAAA,EAAsB;AAAA;AAAA,EAGtC,MAAA,GAAS,CAAA;AAAA;AAAA;AAAA;AAAA,EAKT,IAAI,YAAA,GAAe;AACf,IAAA,OAAO,IAAA,CAAK,M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