@open-pioneer/runtime 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -0
- package/CustomElement.d.ts +5 -11
- package/CustomElement.js +3 -3
- package/CustomElement.js.map +1 -1
- package/DeclaredService.d.ts +52 -0
- package/README.md +2 -2
- package/api.d.ts +4 -10
- package/builtin-services/ApiServiceImpl.js.map +1 -1
- package/builtin-services/ApplicationContextImpl.js.map +1 -1
- package/builtin-services/ApplicationLifecycleEventService.d.ts +2 -2
- package/builtin-services/ApplicationLifecycleEventService.js.map +1 -1
- package/builtin-services/index.js.map +1 -1
- package/errors.js.map +1 -1
- package/i18n.js.map +1 -1
- package/index.d.ts +2 -3
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/metadata/ObservableBox.js.map +1 -1
- package/package.json +4 -3
- package/react-integration/ReactIntegration.d.ts +3 -1
- package/react-integration/ReactIntegration.js +13 -2
- package/react-integration/ReactIntegration.js.map +1 -1
- package/react-integration/hooks.d.ts +3 -5
- package/react-integration/hooks.js.map +1 -1
- package/service-layer/InterfaceSpec.js.map +1 -1
- package/service-layer/PackageRepr.js.map +1 -1
- package/service-layer/ServiceLayer.js.map +1 -1
- package/service-layer/ServiceLookup.js.map +1 -1
- package/service-layer/ServiceRepr.js.map +1 -1
- package/service-layer/verifyDependencies.js.map +1 -1
- package/PropertiesRegistry.d.ts +0 -20
- package/ServiceRegistry.d.ts +0 -26
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/runtime",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@formatjs/intl": "^2.
|
|
7
|
+
"@formatjs/intl": "^2.9.9",
|
|
8
8
|
"react": "^18.2.0",
|
|
9
9
|
"react-dom": "^18.2.0",
|
|
10
|
-
"@open-pioneer/
|
|
10
|
+
"@open-pioneer/base-theme": "^0.2.0",
|
|
11
|
+
"@open-pioneer/chakra-integration": "^1.1.1",
|
|
11
12
|
"@open-pioneer/core": "^1.1.0",
|
|
12
13
|
"@open-pioneer/runtime-react-support": "^1.0.0"
|
|
13
14
|
},
|
|
@@ -6,15 +6,17 @@ export interface ReactIntegrationOptions {
|
|
|
6
6
|
serviceLayer: ServiceLayer;
|
|
7
7
|
rootNode: HTMLDivElement;
|
|
8
8
|
container: Node;
|
|
9
|
+
theme: Record<string, unknown> | undefined;
|
|
9
10
|
}
|
|
10
11
|
export declare class ReactIntegration {
|
|
11
12
|
private containerNode;
|
|
13
|
+
private theme;
|
|
12
14
|
private packages;
|
|
13
15
|
private serviceLayer;
|
|
14
16
|
private root;
|
|
15
17
|
private packageContext;
|
|
16
18
|
constructor(options: ReactIntegrationOptions);
|
|
17
|
-
render(Component: ComponentType
|
|
19
|
+
render(Component: ComponentType): void;
|
|
18
20
|
destroy(): void;
|
|
19
21
|
private getPackage;
|
|
20
22
|
}
|
|
@@ -7,15 +7,18 @@ import { PackageContext } from '@open-pioneer/runtime-react-support';
|
|
|
7
7
|
import { renderInterfaceSpec } from '../service-layer/InterfaceSpec.js';
|
|
8
8
|
import { renderAmbiguousServiceChoices } from '../service-layer/ServiceLookup.js';
|
|
9
9
|
import { CustomChakraProvider } from '@open-pioneer/chakra-integration';
|
|
10
|
+
import { theme } from '@open-pioneer/base-theme';
|
|
10
11
|
|
|
11
12
|
class ReactIntegration {
|
|
12
13
|
containerNode;
|
|
14
|
+
theme;
|
|
13
15
|
packages;
|
|
14
16
|
serviceLayer;
|
|
15
17
|
root;
|
|
16
18
|
packageContext;
|
|
17
19
|
constructor(options) {
|
|
18
20
|
this.containerNode = options.container;
|
|
21
|
+
this.theme = options.theme;
|
|
19
22
|
this.packages = options.packages;
|
|
20
23
|
this.serviceLayer = options.serviceLayer;
|
|
21
24
|
this.root = createRoot(options.rootNode);
|
|
@@ -68,9 +71,17 @@ class ReactIntegration {
|
|
|
68
71
|
}
|
|
69
72
|
};
|
|
70
73
|
}
|
|
71
|
-
render(Component
|
|
74
|
+
render(Component) {
|
|
72
75
|
this.root.render(
|
|
73
|
-
/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(
|
|
76
|
+
/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(
|
|
77
|
+
CustomChakraProvider,
|
|
78
|
+
{
|
|
79
|
+
container: this.containerNode,
|
|
80
|
+
colorMode: "light",
|
|
81
|
+
theme: this.theme ?? theme,
|
|
82
|
+
children: /* @__PURE__ */ jsx(PackageContext.Provider, { value: this.packageContext, children: /* @__PURE__ */ jsx(Component, {}) })
|
|
83
|
+
}
|
|
84
|
+
) })
|
|
74
85
|
);
|
|
75
86
|
}
|
|
76
87
|
destroy() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText:
|
|
1
|
+
{"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ComponentType, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { PackageContext, PackageContextMethods } from \"@open-pioneer/runtime-react-support\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"@open-pioneer/chakra-integration\";\nimport { theme as defaultTrailsTheme } from \"@open-pioneer/base-theme\";\n\nexport interface ReactIntegrationOptions {\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n rootNode: HTMLDivElement;\n container: Node;\n theme: Record<string, unknown> | undefined;\n}\n\nexport class ReactIntegration {\n private containerNode: Node;\n private theme: Record<string, unknown> | undefined;\n private packages: Map<string, PackageRepr>;\n private serviceLayer: ServiceLayer;\n private root: Root;\n private packageContext: PackageContextMethods;\n\n constructor(options: ReactIntegrationOptions) {\n this.containerNode = options.container;\n this.theme = options.theme;\n this.packages = options.packages;\n this.serviceLayer = options.serviceLayer;\n this.root = createRoot(options.rootNode);\n this.packageContext = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = this.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 }\n },\n getServices: (packageName, interfaceName) => {\n const result = this.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 }\n },\n getProperties: (packageName) => {\n return this.getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return this.getPackage(packageName).intl;\n }\n };\n }\n\n render(Component: ComponentType) {\n this.root.render(\n <StrictMode>\n <CustomChakraProvider\n container={this.containerNode}\n colorMode=\"light\"\n theme={this.theme ?? defaultTrailsTheme}\n >\n <PackageContext.Provider value={this.packageContext}>\n <Component />\n </PackageContext.Provider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.root.unmount();\n }\n\n private getPackage(packageName: string): PackageRepr {\n const pkg = this.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"],"names":["options","defaultTrailsTheme"],"mappings":";;;;;;;;;;;AAsBO,MAAM,gBAAiB,CAAA;AAAA,EAClB,aAAA,CAAA;AAAA,EACA,KAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EACA,YAAA,CAAA;AAAA,EACA,IAAA,CAAA;AAAA,EACA,cAAA,CAAA;AAAA,EAER,YAAY,OAAkC,EAAA;AAC1C,IAAA,IAAA,CAAK,gBAAgB,OAAQ,CAAA,SAAA,CAAA;AAC7B,IAAA,IAAA,CAAK,QAAQ,OAAQ,CAAA,KAAA,CAAA;AACrB,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA,CAAA;AACxB,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA,CAAA;AAC5B,IAAK,IAAA,CAAA,IAAA,GAAO,UAAW,CAAA,OAAA,CAAQ,QAAQ,CAAA,CAAA;AACvC,IAAA,IAAA,CAAK,cAAiB,GAAA;AAAA,MAClB,UAAY,EAAA,CAAC,WAAa,EAAA,aAAA,EAAeA,QAAY,KAAA;AACjD,QAAA,MAAM,IAAsB,GAAA,EAAE,aAAe,EAAA,GAAGA,QAAQ,EAAA,CAAA;AACxD,QAAA,MAAM,MAAS,GAAA,IAAA,CAAK,YAAa,CAAA,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C,GAAK,EAAA;AACN,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAQ,CAAA,QAAA;AAAA,QACR,YAAY,WAAW,CAAA,+BAAA,CAAA;AAAA,OAC3B,CAAA;AAAA,KACJ;AACA,IAAO,OAAA,GAAA,CAAA;AAAA,GACX;AACJ;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InterfaceName, ServiceType } from "../ServiceRegistry";
|
|
2
1
|
import { PackageIntl } from "../i18n";
|
|
2
|
+
import { InterfaceNameForServiceType } from "../DeclaredService";
|
|
3
3
|
export interface UseServiceOptions {
|
|
4
4
|
/** An additional qualifier to disambiguate service instances that implement the same interface. */
|
|
5
5
|
qualifier?: string;
|
|
@@ -13,8 +13,7 @@ export interface UseServiceOptions {
|
|
|
13
13
|
*
|
|
14
14
|
* @private
|
|
15
15
|
*/
|
|
16
|
-
export declare function useServiceInternal<
|
|
17
|
-
export declare function useServiceInternal(packageName: string, interfaceName: string, options?: UseServiceOptions): unknown;
|
|
16
|
+
export declare function useServiceInternal<ServiceType = unknown>(packageName: string, interfaceName: InterfaceNameForServiceType<ServiceType>, options?: UseServiceOptions): ServiceType;
|
|
18
17
|
/**
|
|
19
18
|
* Returns all services that implement the given interface.
|
|
20
19
|
* Receives the package name of the importing package as a string.
|
|
@@ -24,8 +23,7 @@ export declare function useServiceInternal(packageName: string, interfaceName: s
|
|
|
24
23
|
*
|
|
25
24
|
* @private
|
|
26
25
|
*/
|
|
27
|
-
export declare function useServicesInternal<
|
|
28
|
-
export declare function useServicesInternal(packageName: string, interfaceName: string): unknown[];
|
|
26
|
+
export declare function useServicesInternal<ServiceType = unknown>(packageName: string, interfaceName: InterfaceNameForServiceType<ServiceType>, options?: UseServiceOptions): ServiceType[];
|
|
29
27
|
/**
|
|
30
28
|
* Returns the properties for the given package.
|
|
31
29
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText:
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useContext, useMemo } from \"react\";\nimport { Error } from \"@open-pioneer/core\";\nimport {\n PackageContext as PackageContext,\n PackageContextMethods\n} from \"@open-pioneer/runtime-react-support\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API.\n They are imported by code generated during separate package generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\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 interfaceName: string,\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[];\nexport function useServicesInternal(packageName: string, interfaceName: string): 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 return checkContext(\"useIntl\", context).getIntl(packageName);\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":";;;;;AAgDgB,SAAA,kBAAA,CACZ,WACA,EAAA,aAAA,EACA,OACO,EAAA;AACP,EAAM,MAAA,OAAA,GAAU,WAAW,cAAc,CAAA,CAAA;AACzC,EAAA,MAAM,OAAU,GAAA,OAAA;AAAA,IACZ,MACI,YAAA,CAAa,YAAc,EAAA,OAAO,CAAE,CAAA,UAAA;AAAA,MAChC,WAAA;AAAA,MACA,aAAA;AAAA,MACA,WAAW,EAAC;AAAA,KAChB;AAAA,IACJ,CAAC,OAAA,EAAS,WAAa,EAAA,aAAA,EAAe,OAAO,CAAA;AAAA,GACjD,CAAA;AACA,EAAO,OAAA,OAAA,CAAA;AACX,CAAA;AAgBgB,SAAA,mBAAA,CAAoB,aAAqB,aAAkC,EAAA;AACvF,EAAM,MAAA,OAAA,GAAU,WAAW,cAAc,CAAA,CAAA;AACzC,EAAA,MAAM,QAAW,GAAA,OAAA;AAAA,IACb,MAAM,YAAa,CAAA,aAAA,EAAe,OAAO,CAAE,CAAA,WAAA,CAAY,aAAa,aAAa,CAAA;AAAA,IACjF,CAAC,OAAS,EAAA,WAAA,EAAa,aAAa,CAAA;AAAA,GACxC,CAAA;AACA,EAAO,OAAA,QAAA,CAAA;AACX,CAAA;AAUO,SAAS,sBAAsB,WAAwD,EAAA;AAC1F,EAAM,MAAA,OAAA,GAAU,WAAW,cAAc,CAAA,CAAA;AACzC,EAAA,OAAO,YAAa,CAAA,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,WAAW,CAAA,CAAA;AAC3E,CAAA;AAUO,SAAS,gBAAgB,WAAkC,EAAA;AAC9D,EAAM,MAAA,OAAA,GAAU,WAAW,cAAc,CAAA,CAAA;AACzC,EAAA,OAAO,YAAa,CAAA,SAAA,EAAW,OAAO,CAAA,CAAE,QAAQ,WAAW,CAAA,CAAA;AAC/D,CAAA;AAEA,SAAS,YAAA,CACL,UACA,WACqB,EAAA;AACrB,EAAA,IAAI,CAAC,WAAa,EAAA;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAQ,CAAA,QAAA;AAAA,MACR,2CAA2C,QAAQ,CAAA,6CAAA,CAAA;AAAA,KACvD,CAAA;AAAA,GACJ;AACA,EAAO,OAAA,WAAA,CAAA;AACX;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InterfaceSpec.js","sources":["InterfaceSpec.ts"],"sourcesContent":["// SPDX-FileCopyrightText:
|
|
1
|
+
{"version":3,"file":"InterfaceSpec.js","sources":["InterfaceSpec.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 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,mBAAoB,CAAA,EAAE,aAAe,EAAA,SAAA,EAAoC,EAAA;AACrF,EAAA,OAAO,IAAI,aAAa,CAAA,CAAA,CAAA,IAAO,SAAY,GAAA,CAAA,cAAA,EAAiB,SAAS,CAAO,EAAA,CAAA,GAAA,EAAA,CAAA,CAAA;AAChF,CAAA;AAeO,SAAS,mBAAmB,QAAqD,EAAA;AACpF,EAAA,IAAI,CAAC,QAAU,EAAA;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,OAAQ,CAAA,gBAAA,EAAkB,6BAA6B,CAAA,CAAA;AAAA,GAC3E;AACA,EAAI,IAAA,QAAA,CAAS,GAAO,IAAA,QAAA,CAAS,SAAW,EAAA;AACpC,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAQ,CAAA,gBAAA;AAAA,MACR,yEAAA;AAAA,KACJ,CAAA;AAAA,GACJ;AACA,EAAA,IAAI,SAAS,GAAK,EAAA;AACd,IAAO,OAAA;AAAA,MACH,GAAK,EAAA,IAAA;AAAA,MACL,eAAe,QAAS,CAAA,IAAA;AAAA,KAC5B,CAAA;AAAA,GACJ;AACA,EAAO,OAAA;AAAA,IACH,eAAe,QAAS,CAAA,IAAA;AAAA,IACxB,WAAW,QAAS,CAAA,SAAA;AAAA,GACxB,CAAA;AACJ,CAAA;AAEO,SAAS,2BAA2B,IAAuD,EAAA;AAC9F,EAAA,OAAO,CAAC,IAAK,CAAA,GAAA,CAAA;AACjB,CAAA;AAEO,SAAS,yBAAyB,IAAqD,EAAA;AAC1F,EAAA,OAAO,KAAK,GAAQ,KAAA,IAAA,CAAA;AACxB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageRepr.js","sources":["PackageRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText:
|
|
1
|
+
{"version":3,"file":"PackageRepr.js","sources":["PackageRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { ApplicationProperties } from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl, AppI18n } 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: PackageIntl;\n services?: ServiceRepr[];\n uiReferences?: ReferenceSpec[];\n properties?: Record<string, unknown>;\n}\n\nexport class PackageRepr {\n static create(\n data: PackageMetadata,\n i18n: 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, i18n, 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: i18n\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: 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: AppI18n,\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":";;;;;AAkBO,MAAM,WAAY,CAAA;AAAA,EACrB,OAAO,MAAA,CACH,IACA,EAAA,IAAA,EACA,gBACW,EAAA;AACX,IAAA,MAAM,OAAO,IAAK,CAAA,IAAA,CAAA;AAClB,IAAM,MAAA,UAAA,GAAa,IAAK,CAAA,UAAA,IAAc,EAAC,CAAA;AACvC,IAAA,MAAM,eAAkB,GAAA,mBAAA,CAAoB,IAAM,EAAA,UAAA,EAAY,gBAAgB,CAAA,CAAA;AAC9E,IAAA,MAAM,WAAW,MAAO,CAAA,OAAA,CAAQ,KAAK,QAAY,IAAA,EAAE,CAAE,CAAA,GAAA;AAAA,MACjD,CAAC,CAACA,KAAM,EAAA,WAAW,CAAM,KAAA;AACrB,QAAIA,IAAAA,KAAAA,KAAS,YAAY,IAAM,EAAA;AAC3B,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAQ,CAAA,gBAAA;AAAA,YACR,0CAAA;AAAA,WACJ,CAAA;AAAA,SACJ;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AA,+BAAA,CAAA;AAAA,OACjE,CAAA;AAAA,KACJ;AACA,IAAA,MAAA,CAAO,GAAG,CAAI,GAAA,KAAA,CAAA;AAAA,GAClB;AAEA,EAAA,KAAA,MAAW,OAAO,QAAU,EAAA;AACxB,IAAM,MAAA,KAAA,GAAQ,OAAO,GAAG,CAAA,CAAA;AACxB,IAAA,IAAI,SAAS,IAAM,EAAA;AACf,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAQ,CAAA,iBAAA;AAAA,QACR,CAAA,SAAA,EAAY,WAAW,CAAA,yBAAA,EAA4B,GAAG,CAAA,wCAAA,CAAA;AAAA,OAC1D,CAAA;AAAA,KACJ;AAAA,GACJ;AAEA,EAAO,OAAA,MAAA,CAAA;AACX,CAAA;AAEA,MAAM,QAAA,GAAW,OAAO,SAAU,CAAA,cAAA,CAAA;AAElC,SAAS,WAAA,CAAY,QAAiB,GAAa,EAAA;AAC/C,EAAO,OAAA,QAAA,CAAS,IAAK,CAAA,MAAA,EAAQ,GAAG,CAAA,CAAA;AACpC,CAAA;AAGA,MAAM,UAAa,GAAA,4DAAA,CAAA;AAEnB,SAAS,mBAAmB,IAAuB,EAAA;AAC/C,EAAO,OAAA,UAAA,CAAW,KAAK,IAAI,CAAA,CAAA;AAC/B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceLayer.js","sources":["ServiceLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { ServiceRepr } from \"./ServiceRepr\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport {\n ComputedServiceDependencies,\n FrameworkDependency,\n UIDependency,\n verifyDependencies\n} from \"./verifyDependencies\";\nimport { PackageRepr } from \"./PackageRepr\";\nimport { ReadonlyServiceLookup, ServiceLookupResult, ServicesLookupResult } from \"./ServiceLookup\";\nimport {\n InterfaceSpec,\n isAllImplementationsSpec,\n isSingleImplementationSpec,\n ReferenceSpec,\n renderInterfaceSpec\n} from \"./InterfaceSpec\";\nimport { ReferenceMeta } from \"../Service\";\nimport { RUNTIME_PACKAGE_NAME } from \"../builtin-services\";\n\nconst LOG = createLogger(\"runtime:ServiceLayer\");\n\nexport type DynamicLookupResult = ServiceLookupResult | UndeclaredDependency;\n\nexport interface UndeclaredDependency {\n type: \"undeclared\";\n}\n\ninterface DependencyDeclarations {\n all: boolean;\n unqualified: boolean;\n qualifiers: Set<string>;\n}\n\nexport class ServiceLayer {\n // All services in the application.\n private allServices: ServiceRepr[];\n\n // Set of required services. These services and their dependencies will be started.\n private requiredServices: Set<ServiceRepr>;\n\n private serviceLookup: ReadonlyServiceLookup;\n\n // Service id --> Service dependencies\n private serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n // Package name --> Interface name --> Declarations\n private declaredDependencies;\n private state: \"not-started\" | \"started\" | \"destroyed\" = \"not-started\";\n\n /**\n * Constructs a new service layer instance.\n * Requires the application's set of packages (from which services are taken)\n * and an optional set of forced references (interfaces whose implementing services will be started unconditionally).\n *\n * In its current form, the service layer will start only forced references and references needed by the UI (and their dependencies).\n */\n constructor(packages: readonly PackageRepr[], forcedReferences: ReferenceSpec[] = []) {\n const allServices = packages.map((pkg) => pkg.services).flat();\n const uiDependencies = packages\n .map((pkg) =>\n pkg.uiReferences.map<UIDependency>((dep) => {\n return {\n type: \"ui\",\n packageName: pkg.name,\n ...dep\n };\n })\n )\n .flat();\n const requiredReferences = [\n ...forcedReferences.map<FrameworkDependency>((r) => ({\n type: \"framework\",\n ...r\n })),\n ...uiDependencies\n ];\n const { serviceLookup, serviceDependencies } = verifyDependencies({\n services: allServices,\n requiredReferences: requiredReferences\n });\n\n this.allServices = allServices;\n this.requiredServices = getRequiredServices(requiredReferences, serviceLookup);\n this.serviceLookup = serviceLookup;\n this.serviceDependencies = serviceDependencies;\n this.declaredDependencies = buildDependencyIndex(packages);\n }\n\n destroy() {\n for (const service of this.requiredServices) {\n this.destroyService(service);\n }\n this.state = \"destroyed\";\n }\n\n start() {\n if (this.state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer was already started.\");\n }\n\n for (const service of this.requiredServices) {\n this.createService(service);\n }\n this.state = \"started\";\n\n // Give warnings for unneeded services during development.\n if (import.meta.env.DEV) {\n const unneededServices = this.allServices\n .filter(\n (service) =>\n service.packageName !== RUNTIME_PACKAGE_NAME &&\n service.state === \"not-constructed\"\n )\n .map((service) => `'${service.id}'`);\n if (unneededServices.length) {\n const services = unneededServices.join(\", \");\n LOG.warn(\n `The following services are contained in the application but were not started: ${services}.`\n );\n }\n }\n }\n\n /**\n * Returns a service implementing the given interface.\n * Checks that the given package actually declared a dependency on that interface\n * to enforce coding guidelines.\n *\n * @param packageName the name of the package requesting the import\n * @param spec the interface specifier\n * @param options advanced options to customize lookup\n * @throws if the service layer is not in 'started' state or if no service implements the interface.\n */\n getService(\n packageName: string,\n spec: InterfaceSpec,\n options?: { ignoreDeclarationCheck?: boolean }\n ): ServiceLookupResult | UndeclaredDependency {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n if (!options?.ignoreDeclarationCheck && !this.isDeclaredDependency(packageName, spec)) {\n return { type: \"undeclared\" };\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 {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n if (!this.isDeclaredDependency(packageName, { interfaceName, all: true })) {\n return { type: \"undeclared\" };\n }\n\n return this.serviceLookup.lookupAll(interfaceName);\n }\n\n /**\n * Initializes the given service and its dependencies.\n * Dependencies are initialized before the service that requires them.\n */\n private createService(service: ServiceRepr) {\n if (service.state === \"constructed\") {\n const instance = service.getInstanceOrThrow();\n service.addRef();\n return instance;\n }\n if (service.state === \"constructing\") {\n throw new Error(ErrorId.INTERNAL, \"Cycle during service construction.\");\n }\n if (service.state !== \"not-constructed\") {\n throw new Error(ErrorId.INTERNAL, \"Invalid service state.\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const references: Record<string, any> = {};\n const referencesMeta: Record<string, ReferenceMeta | ReferenceMeta[]> = {};\n\n // Sets state to 'constructing' to detect cycles\n service.beforeCreate();\n\n // Initialize dependencies recursively before creating the current service.\n for (const [referenceName, serviceDeps] of Object.entries(this.getServiceDeps(service))) {\n const [referenceValue, referenceMeta] = this.getReference(serviceDeps);\n references[referenceName] = referenceValue;\n referencesMeta[referenceName] = referenceMeta;\n }\n\n // Sets state to 'constructed' to finish the state transition, useCount is 1.\n LOG.debug(`Creating service '${service.id}'.`);\n return service.create({ references, referencesMeta });\n }\n\n /**\n * Destroys the given service and its dependencies.\n * The dependencies are destroyed after the service.\n */\n private destroyService(service: ServiceRepr) {\n if (service.state === \"destroyed\") {\n return;\n }\n\n // Destroy the service before its dependencies (reverse order\n // compared to construction).\n if (service.removeRef() <= 0) {\n LOG.debug(`Destroying service '${service.id}'`);\n service.destroy();\n }\n\n for (const serviceDeps of Object.values(this.getServiceDeps(service))) {\n if (Array.isArray(serviceDeps)) {\n for (const dep of serviceDeps) {\n this.destroyService(dep);\n }\n } else {\n this.destroyService(serviceDeps);\n }\n }\n }\n\n private isDeclaredDependency(packageName: string, spec: ReferenceSpec) {\n const packageEntry = this.declaredDependencies.get(packageName);\n if (!packageEntry) {\n return false;\n }\n const interfaceEntry = packageEntry.get(spec.interfaceName);\n if (!interfaceEntry) {\n return false;\n }\n\n if (isSingleImplementationSpec(spec)) {\n if (spec.qualifier == null) {\n return interfaceEntry.unqualified;\n }\n return interfaceEntry.qualifiers.has(spec.qualifier);\n } else {\n return interfaceEntry.all;\n }\n }\n\n private getReference(ref: ServiceRepr): [unknown, ReferenceMeta];\n private getReference(ref: ServiceRepr[]): [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]] {\n if (Array.isArray(ref)) {\n const referenceValues: unknown[] = [];\n const referenceMeta: ReferenceMeta[] = [];\n for (const d of ref) {\n const [value, meta] = this.getReference(d);\n referenceValues.push(value);\n referenceMeta.push(meta);\n }\n return [referenceValues, referenceMeta];\n }\n\n const referenceValue = this.createService(ref);\n const referenceMeta: ReferenceMeta = {\n serviceId: ref.id\n };\n return [referenceValue, referenceMeta];\n }\n\n private getServiceDeps(service: ServiceRepr) {\n const dependencies = this.serviceDependencies.get(service.id);\n if (!dependencies) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find precomputed service dependencies for '${service.id}'.`\n );\n }\n return dependencies;\n }\n}\n\nfunction getRequiredServices(\n requiredReferences: readonly ReferenceSpec[],\n serviceLookup: ReadonlyServiceLookup\n): Set<ServiceRepr> {\n const requiredServices = new Set<ServiceRepr>();\n for (const referenceSpec of requiredReferences) {\n const result = serviceLookup.lookup(referenceSpec);\n if (result.type !== \"found\") {\n // Should be caught by verifier\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find required reference to ${renderInterfaceSpec(referenceSpec)}.`\n );\n }\n if (Array.isArray(result.value)) {\n for (const service of result.value) {\n requiredServices.add(service);\n }\n } else {\n requiredServices.add(result.value);\n }\n }\n return requiredServices;\n}\n\nfunction buildDependencyIndex(packages: readonly PackageRepr[]) {\n // Register declared UI dependencies.\n // This is needed as a lookup structure to that dynamic service lookups\n // can be validated at runtime.\n const index = new Map<string, Map<string, DependencyDeclarations>>();\n for (const pkg of packages) {\n const packageName = pkg.name;\n const packageEntry = new Map<string, DependencyDeclarations>();\n for (const uiReference of pkg.uiReferences) {\n let interfaceEntry = packageEntry.get(uiReference.interfaceName);\n if (!interfaceEntry) {\n interfaceEntry = {\n all: false,\n unqualified: false,\n qualifiers: new Set<string>()\n };\n packageEntry.set(uiReference.interfaceName, interfaceEntry);\n }\n\n if (isAllImplementationsSpec(uiReference)) {\n interfaceEntry.all = true;\n } else if (isSingleImplementationSpec(uiReference)) {\n if (uiReference.qualifier == null) {\n interfaceEntry.unqualified = true;\n } else {\n interfaceEntry.qualifiers.add(uiReference.qualifier);\n }\n } else {\n throw new Error(ErrorId.INTERNAL, `Unexpected implementation spec.`);\n }\n }\n index.set(packageName, packageEntry);\n }\n return index;\n}\n"],"names":["referenceMeta"],"mappings":";;;;;;AAuBA,MAAM,GAAA,GAAM,aAAa,sBAAsB,CAAA,CAAA;AAcxC,MAAM,YAAa,CAAA;AAAA;AAAA,EAEd,WAAA,CAAA;AAAA;AAAA,EAGA,gBAAA,CAAA;AAAA,EAEA,aAAA,CAAA;AAAA;AAAA,EAGA,mBAAA,CAAA;AAAA;AAAA,EAGA,oBAAA,CAAA;AAAA,EACA,KAAiD,GAAA,aAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASzD,WAAY,CAAA,QAAA,EAAkC,gBAAoC,GAAA,EAAI,EAAA;AAClF,IAAM,MAAA,WAAA,GAAc,SAAS,GAAI,CAAA,CAAC,QAAQ,GAAI,CAAA,QAAQ,EAAE,IAAK,EAAA,CAAA;AAC7D,IAAA,MAAM,iBAAiB,QAClB,CAAA,GAAA;AAAA,MAAI,CAAC,GACF,KAAA,GAAA,CAAI,YAAa,CAAA,GAAA,CAAkB,CAAC,GAAQ,KAAA;AACxC,QAAO,OAAA;AAAA,UACH,IAAM,EAAA,IAAA;AAAA,UACN,aAAa,GAAI,CAAA,IAAA;AAAA,UACjB,GAAG,GAAA;AAAA,SACP,CAAA;AAAA,OACH,CAAA;AAAA,MAEJ,IAAK,EAAA,CAAA;AACV,IAAA,MAAM,kBAAqB,GAAA;A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,uBAAmB,GAAoC,EAAA,CAAA;AAC7D,IAAW,KAAA,MAAA,WAAA,IAAe,IAAI,YAAc,EAAA;AACxC,MAAA,IAAI,cAAiB,GAAA,YAAA,CAAa,GAAI,CAAA,WAAA,CAAY,aAAa,CAAA,CAAA;AAC/D,MAAA,IAAI,CAAC,cAAgB,EAAA;AACjB,QAAiB,cAAA,GAAA;AAAA,UACb,GAAK,EAAA,KAAA;AAAA,UACL,WAAa,EAAA,KAAA;AAAA,UACb,UAAA,sBAAgB,GAAY,EAAA;AAAA,SAChC,CAAA;AACA,QAAa,YAAA,CAAA,GAAA,CAAI,WAAY,CAAA,aAAA,EAAe,cAAc,CAAA,CAAA;AAAA,OAC9D;AAEA,MAAI,IAAA,wBAAA,CAAyB,WAAW,CAAG,EAAA;AACvC,QAAA,cAAA,CAAe,GAAM,GAAA,IAAA,CAAA;AAAA,OACzB,MAAA,IAAW,0BAA2B,CAAA,WAAW,CAAG,EAAA;AAChD,QAAI,IAAA,WAAA,CAAY,aAAa,IAAM,EAAA;AAC/B,UAAA,cAAA,CAAe,WAAc,GAAA,IAAA,CAAA;AAAA,SAC1B,MAAA;AACH,UAAe,cAAA,CAAA,UAAA,CAAW,GAAI,CAAA,WAAA,CAAY,SAAS,CAAA,CAAA;AAAA,SACvD;AAAA,OACG,MAAA;AACH,QAAA,MAAM,IAAI,KAAA,CAAM,OAAQ,CAAA,QAAA,EAAU,CAAiC,+BAAA,CAAA,CAAA,CAAA;AAAA,OACvE;AAAA,KACJ;AACA,IAAM,KAAA,CAAA,GAAA,CAAI,aAAa,YAAY,CAAA,CAAA;AAAA,GACvC;AACA,EAAO,OAAA,KAAA,CAAA;AACX;;;;"}
|
|
1
|
+
{"version":3,"file":"ServiceLayer.js","sources":["ServiceLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ServiceRepr } from \"./ServiceRepr\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport {\n ComputedServiceDependencies,\n FrameworkDependency,\n UIDependency,\n verifyDependencies\n} from \"./verifyDependencies\";\nimport { PackageRepr } from \"./PackageRepr\";\nimport { ReadonlyServiceLookup, ServiceLookupResult, ServicesLookupResult } from \"./ServiceLookup\";\nimport {\n InterfaceSpec,\n isAllImplementationsSpec,\n isSingleImplementationSpec,\n ReferenceSpec,\n renderInterfaceSpec\n} from \"./InterfaceSpec\";\nimport { ReferenceMeta } from \"../Service\";\nimport { RUNTIME_PACKAGE_NAME } from \"../builtin-services\";\n\nconst LOG = createLogger(\"runtime:ServiceLayer\");\n\nexport type DynamicLookupResult = ServiceLookupResult | UndeclaredDependency;\n\nexport interface UndeclaredDependency {\n type: \"undeclared\";\n}\n\ninterface DependencyDeclarations {\n all: boolean;\n unqualified: boolean;\n qualifiers: Set<string>;\n}\n\nexport class ServiceLayer {\n // All services in the application.\n private allServices: ServiceRepr[];\n\n // Set of required services. These services and their dependencies will be started.\n private requiredServices: Set<ServiceRepr>;\n\n private serviceLookup: ReadonlyServiceLookup;\n\n // Service id --> Service dependencies\n private serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n // Package name --> Interface name --> Declarations\n private declaredDependencies;\n private state: \"not-started\" | \"started\" | \"destroyed\" = \"not-started\";\n\n /**\n * Constructs a new service layer instance.\n * Requires the application's set of packages (from which services are taken)\n * and an optional set of forced references (interfaces whose implementing services will be started unconditionally).\n *\n * In its current form, the service layer will start only forced references and references needed by the UI (and their dependencies).\n */\n constructor(packages: readonly PackageRepr[], forcedReferences: ReferenceSpec[] = []) {\n const allServices = packages.map((pkg) => pkg.services).flat();\n const uiDependencies = packages\n .map((pkg) =>\n pkg.uiReferences.map<UIDependency>((dep) => {\n return {\n type: \"ui\",\n packageName: pkg.name,\n ...dep\n };\n })\n )\n .flat();\n const requiredReferences = [\n ...forcedReferences.map<FrameworkDependency>((r) => ({\n type: \"framework\",\n ...r\n })),\n ...uiDependencies\n ];\n const { serviceLookup, serviceDependencies } = verifyDependencies({\n services: allServices,\n requiredReferences: requiredReferences\n });\n\n this.allServices = allServices;\n this.requiredServices = getRequiredServices(requiredReferences, serviceLookup);\n this.serviceLookup = serviceLookup;\n this.serviceDependencies = serviceDependencies;\n this.declaredDependencies = buildDependencyIndex(packages);\n }\n\n destroy() {\n for (const service of this.requiredServices) {\n this.destroyService(service);\n }\n this.state = \"destroyed\";\n }\n\n start() {\n if (this.state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer was already started.\");\n }\n\n for (const service of this.requiredServices) {\n this.createService(service);\n }\n this.state = \"started\";\n\n // Give warnings for unneeded services during development.\n if (import.meta.env.DEV) {\n const unneededServices = this.allServices\n .filter(\n (service) =>\n service.packageName !== RUNTIME_PACKAGE_NAME &&\n service.state === \"not-constructed\"\n )\n .map((service) => `'${service.id}'`);\n if (unneededServices.length) {\n const services = unneededServices.join(\", \");\n LOG.warn(\n `The following services are contained in the application but were not started: ${services}.`\n );\n }\n }\n }\n\n /**\n * Returns a service implementing the given interface.\n * Checks that the given package actually declared a dependency on that interface\n * to enforce coding guidelines.\n *\n * @param packageName the name of the package requesting the import\n * @param spec the interface specifier\n * @param options advanced options to customize lookup\n * @throws if the service layer is not in 'started' state or if no service implements the interface.\n */\n getService(\n packageName: string,\n spec: InterfaceSpec,\n options?: { ignoreDeclarationCheck?: boolean }\n ): ServiceLookupResult | UndeclaredDependency {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n if (!options?.ignoreDeclarationCheck && !this.isDeclaredDependency(packageName, spec)) {\n return { type: \"undeclared\" };\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 {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n if (!this.isDeclaredDependency(packageName, { interfaceName, all: true })) {\n return { type: \"undeclared\" };\n }\n\n return this.serviceLookup.lookupAll(interfaceName);\n }\n\n /**\n * Initializes the given service and its dependencies.\n * Dependencies are initialized before the service that requires them.\n */\n private createService(service: ServiceRepr) {\n if (service.state === \"constructed\") {\n const instance = service.getInstanceOrThrow();\n service.addRef();\n return instance;\n }\n if (service.state === \"constructing\") {\n throw new Error(ErrorId.INTERNAL, \"Cycle during service construction.\");\n }\n if (service.state !== \"not-constructed\") {\n throw new Error(ErrorId.INTERNAL, \"Invalid service state.\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const references: Record<string, any> = {};\n const referencesMeta: Record<string, ReferenceMeta | ReferenceMeta[]> = {};\n\n // Sets state to 'constructing' to detect cycles\n service.beforeCreate();\n\n // Initialize dependencies recursively before creating the current service.\n for (const [referenceName, serviceDeps] of Object.entries(this.getServiceDeps(service))) {\n const [referenceValue, referenceMeta] = this.getReference(serviceDeps);\n references[referenceName] = referenceValue;\n referencesMeta[referenceName] = referenceMeta;\n }\n\n // Sets state to 'constructed' to finish the state transition, useCount is 1.\n LOG.debug(`Creating service '${service.id}'.`);\n return service.create({ references, referencesMeta });\n }\n\n /**\n * Destroys the given service and its dependencies.\n * The dependencies are destroyed after the service.\n */\n private destroyService(service: ServiceRepr) {\n if (service.state === \"destroyed\") {\n return;\n }\n\n // Destroy the service before its dependencies (reverse order\n // compared to construction).\n if (service.removeRef() <= 0) {\n LOG.debug(`Destroying service '${service.id}'`);\n service.destroy();\n }\n\n for (const serviceDeps of Object.values(this.getServiceDeps(service))) {\n if (Array.isArray(serviceDeps)) {\n for (const dep of serviceDeps) {\n this.destroyService(dep);\n }\n } else {\n this.destroyService(serviceDeps);\n }\n }\n }\n\n private isDeclaredDependency(packageName: string, spec: ReferenceSpec) {\n const packageEntry = this.declaredDependencies.get(packageName);\n if (!packageEntry) {\n return false;\n }\n const interfaceEntry = packageEntry.get(spec.interfaceName);\n if (!interfaceEntry) {\n return false;\n }\n\n if (isSingleImplementationSpec(spec)) {\n if (spec.qualifier == null) {\n return interfaceEntry.unqualified;\n }\n return interfaceEntry.qualifiers.has(spec.qualifier);\n } else {\n return interfaceEntry.all;\n }\n }\n\n private getReference(ref: ServiceRepr): [unknown, ReferenceMeta];\n private getReference(ref: ServiceRepr[]): [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]] {\n if (Array.isArray(ref)) {\n const referenceValues: unknown[] = [];\n const referenceMeta: ReferenceMeta[] = [];\n for (const d of ref) {\n const [value, meta] = this.getReference(d);\n referenceValues.push(value);\n referenceMeta.push(meta);\n }\n return [referenceValues, referenceMeta];\n }\n\n const referenceValue = this.createService(ref);\n const referenceMeta: ReferenceMeta = {\n serviceId: ref.id\n };\n return [referenceValue, referenceMeta];\n }\n\n private getServiceDeps(service: ServiceRepr) {\n const dependencies = this.serviceDependencies.get(service.id);\n if (!dependencies) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find precomputed service dependencies for '${service.id}'.`\n );\n }\n return dependencies;\n }\n}\n\nfunction getRequiredServices(\n requiredReferences: readonly ReferenceSpec[],\n serviceLookup: ReadonlyServiceLookup\n): Set<ServiceRepr> {\n const requiredServices = new Set<ServiceRepr>();\n for (const referenceSpec of requiredReferences) {\n const result = serviceLookup.lookup(referenceSpec);\n if (result.type !== \"found\") {\n // Should be caught by verifier\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find required reference to ${renderInterfaceSpec(referenceSpec)}.`\n );\n }\n if (Array.isArray(result.value)) {\n for (const service of result.value) {\n requiredServices.add(service);\n }\n } else {\n requiredServices.add(result.value);\n }\n }\n return requiredServices;\n}\n\nfunction buildDependencyIndex(packages: readonly PackageRepr[]) {\n // Register declared UI dependencies.\n // This is needed as a lookup structure to that dynamic service lookups\n // can be validated at runtime.\n const index = new Map<string, Map<string, DependencyDeclarations>>();\n for (const pkg of packages) {\n const packageName = pkg.name;\n const packageEntry = new Map<string, DependencyDeclarations>();\n for (const uiReference of pkg.uiReferences) {\n let interfaceEntry = packageEntry.get(uiReference.interfaceName);\n if (!interfaceEntry) {\n interfaceEntry = {\n all: false,\n unqualified: false,\n qualifiers: new Set<string>()\n };\n packageEntry.set(uiReference.interfaceName, interfaceEntry);\n }\n\n if (isAllImplementationsSpec(uiReference)) {\n interfaceEntry.all = true;\n } else if (isSingleImplementationSpec(uiReference)) {\n if (uiReference.qualifier == null) {\n interfaceEntry.unqualified = true;\n } else {\n interfaceEntry.qualifiers.add(uiReference.qualifier);\n }\n } else {\n throw new Error(ErrorId.INTERNAL, `Unexpected implementation spec.`);\n }\n }\n index.set(packageName, packageEntry);\n }\n return index;\n}\n"],"names":["referenceMeta"],"mappings":";;;;;;AAuBA,MAAM,GAAA,GAAM,aAAa,sBAAsB,CAAA,CAAA;AAcxC,MAAM,YAAa,CAAA;AAAA;AAAA,EAEd,WAAA,CAAA;AAAA;AAAA,EAGA,gBAAA,CAAA;AAAA,EAEA,aAAA,CAAA;AAAA;AAAA,EAGA,mBAAA,CAAA;AAAA;AAAA,EAGA,oBAAA,CAAA;AAAA,EACA,KAAiD,GAAA,aAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASzD,WAAY,CAAA,QAAA,EAAkC,gBAAoC,GAAA,EAAI,EAAA;AAClF,IAAM,MAAA,WAAA,GAAc,SAAS,GAAI,CAAA,CAAC,QAAQ,GAAI,CAAA,QAAQ,EAAE,IAAK,EAAA,CAAA;AAC7D,IAAA,MAAM,iBAAiB,QAClB,CAAA,GAAA;AAAA,MAAI,CAAC,GACF,KAAA,GAAA,CAAI,YAAa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AA;AAAA,GACvC;AACA,EAAO,OAAA,KAAA,CAAA;AACX;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceLookup.js","sources":["ServiceLookup.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\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 private services = new Map<string, Services>();\n\n // Total service count\n private _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 private 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,aAAc,CAAA;AAAA;AAAA,EAEf,QAAA,uBAAe,GAAsB,EAAA,CAAA;AAAA;AAAA,EAGrC,MAAS,GAAA,CAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAKjB,IAAI,YAAe,GAAA;AACf,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAS,CAAA,OAAA,EAAsB,EAAE,aAAA,EAAe,WAAkC,EAAA;AAC9E,IAAA,IAAI,CAAC,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IAAI,SAAW,EAAA;AACX,MAAA,OAAA,IAAW,CAAqB,kBAAA,EAAA,SAAA,CAAA,EAAA,CAAA,CAAA;AAAA,KACpC;AAEA,IAAI,IAAA,EAAE,SAAS,GAAK,EAAA;AAChB,MAAA,MAAA;AAAA,KACJ;AAAA,GACJ;AAEA,EAAM,MAAA,SAAA,GAAY,QAAQ,MAAS,GAAA,KAAA,CAAA;AACnC,EAAA,IAAI,YAAY,CAAG,EAAA;AACf,IAAA,OAAA,IAAW,CAAQ,KAAA,EAAA,SAAA,CAAA,KAAA,CAAA,CAAA;AAAA,GACvB;AACA,EAAO,OAAA,OAAA,CAAA;AACX,CAAA;AAEA,SAAS,MAAY,GAA+B,EAAA;AAChD,EAAA,OAAO,GAAI,CAAA,MAAA,EAAS,CAAA,IAAA,EAAO,CAAA,KAAA,CAAA;AAC/B;;;;"}
|
|
1
|
+
{"version":3,"file":"ServiceLookup.js","sources":["ServiceLookup.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 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 private services = new Map<string, Services>();\n\n // Total service count\n private _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 private 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,aAAc,CAAA;AAAA;AAAA,EAEf,QAAA,uBAAe,GAAsB,EAAA,CAAA;AAAA;AAAA,EAGrC,MAAS,GAAA,CAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAKjB,IAAI,YAAe,GAAA;AACf,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAS,CAAA,OAAA,EAAsB,EAAE,aAAA,EAAe,WAAkC,EAAA;AAC9E,IAAA,IAAI,CAAC,aAAe,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAQ,CAAA,gBAAA;AAAA,QACR,CAAY,SAAA,EAAA,OAAA,CAAQ,EAAE,CAAA,8BAAA,EAAiC,aAAa,CAAA,EAAA,CAAA;AAAA,OACxE,CAAA;AAAA,KACJ;AACA,IAAI,IAAA,SAAA,IAAa,IAAQ,IAAA,CAAC,SAAW,EAAA;AACjC,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAQ,CAAA,gBAAA;AAAA,QACR,YAAY,OAAQ,CAAA,EAAE,CAA8C,2CAAA,EAAA,aAAa,OAAO,SAAS,CAAA,EAAA,CAAA;AAAA,OACrG,CAAA;AAAA,KACJ;AAEA,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,oBAAA,CAAqB,aAAa,CAAA,CAAA;AACxD,IAAA,IAAI,CAAC,SAAW,EAAA;AACZ,MAAS,QAAA,CAAA,WAAA,CAAY,KAAK,OAAO,CAAA,CAAA;AACjC,MAAA,EAAE,IAAK,CAAA,MAAA,CAAA;AACP,MAAA,OAAA;AAAA,KACJ;AAEA,IAAA,MAAM,iBAAoB,GAAA,QAAA,CAAS,WAAY,CAAA,GAAA,CAAI,SAAS,CA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AAA;AAAA,KACrC;AACA,IAAO,OAAA,KAAA,CAAA;AAAA,GACX;AACJ,CAAA;AAEgB,SAAA,6BAAA,CAA8B,OAA4B,EAAA,GAAA,GAAM,CAAW,EAAA;AACvF,EAAA,IAAI,OAAU,GAAA,EAAA,CAAA;AACd,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AACZ,EAAA,KAAA,MAAW,CAAC,SAAA,EAAW,SAAS,CAAA,IAAK,OAAS,EAAA;AAC1C,IAAA,IAAI,KAAO,EAAA;AACP,MAAW,OAAA,IAAA,IAAA,CAAA;AAAA,KACf;AAEA,IAAA,OAAA,IAAW,IAAI,SAAS,CAAA,CAAA,CAAA,CAAA;AACxB,IAAA,IAAI,SAAW,EAAA;AACX,MAAA,OAAA,IAAW,qBAAqB,SAAS,CAAA,EAAA,CAAA,CAAA;AAAA,KAC7C;AAEA,IAAI,IAAA,EAAE,SAAS,GAAK,EAAA;AAChB,MAAA,MAAA;AAAA,KACJ;AAAA,GACJ;AAEA,EAAM,MAAA,SAAA,GAAY,QAAQ,MAAS,GAAA,KAAA,CAAA;AACnC,EAAA,IAAI,YAAY,CAAG,EAAA;AACf,IAAA,OAAA,IAAW,QAAQ,SAAS,CAAA,KAAA,CAAA,CAAA;AAAA,GAChC;AACA,EAAO,OAAA,OAAA,CAAA;AACX,CAAA;AAEA,SAAS,MAAY,GAA+B,EAAA;AAChD,EAAA,OAAO,GAAI,CAAA,MAAA,EAAS,CAAA,IAAA,EAAO,CAAA,KAAA,CAAA;AAC/B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceRepr.js","sources":["ServiceRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { ErrorId } from \"../errors\";\nimport { ServiceMetadata } from \"../metadata\";\nimport { Service, ServiceConstructor, ServiceOptions } from \"../Service\";\nimport { Error } from \"@open-pioneer/core\";\nimport { InterfaceSpec, parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { PackageIntl } from \"../i18n\";\n\nexport type ServiceState = \"not-constructed\" | \"constructing\" | \"constructed\" | \"destroyed\";\n\nexport type ServiceDependency = ReferenceSpec & { referenceName: string };\n\nexport interface ConstructorFactory {\n type: \"class\";\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n clazz: ServiceConstructor<any>;\n}\n\nexport interface FunctionFactory {\n type: \"function\";\n create: (options: ServiceOptions) => Service;\n}\n\nexport type ServiceFactory = ConstructorFactory | FunctionFactory;\n\nexport interface ServiceReprOptions {\n name: string;\n packageName: string;\n factory: ServiceFactory;\n intl: PackageIntl;\n dependencies?: ServiceDependency[];\n interfaces?: InterfaceSpec[];\n properties?: Record<string, unknown>;\n}\n\n/**\n * Represents metadata and state of a service in the runtime.\n * `this.instance` is the actual service instance (when constructed).\n */\nexport class ServiceRepr {\n static create(\n packageName: string,\n data: ServiceMetadata,\n intl: PackageIntl,\n properties?: Record<string, unknown>\n ): ServiceRepr {\n const clazz = data.clazz;\n const name = data.name;\n const dependencies = Object.entries(data.references ?? {}).map(\n ([name, referenceMetadata]) => {\n return {\n referenceName: name,\n ...parseReferenceSpec(referenceMetadata)\n };\n }\n );\n const interfaces = data.provides?.map<InterfaceSpec>((i) => {\n return {\n interfaceName: i.name,\n qualifier: i.qualifier\n };\n });\n const factory: ConstructorFactory = {\n type: \"class\",\n clazz\n };\n return new ServiceRepr({\n name,\n packageName,\n factory,\n intl,\n dependencies,\n interfaces,\n properties\n });\n }\n\n /** Unique id of this service. Contains the package name and the service name. */\n readonly id: string;\n\n /** Name of this service in it's package. */\n readonly name: string;\n\n /** Name of the parent package. */\n readonly packageName: string;\n\n /** Locale-dependant i18n messages. */\n readonly intl: PackageIntl;\n\n /** Service properties made available via the service's constructor. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Dependencies required by the service constructor. */\n readonly dependencies: readonly ServiceDependency[];\n\n /** Interfaces provided by the service. */\n readonly interfaces: readonly Readonly<InterfaceSpec>[];\n\n /** Number of references to this service. */\n private _useCount = 0;\n\n /** Service factory to construct an instance. */\n private factory: ServiceFactory;\n\n /** Current state of this service. \"constructed\" -> instance is available. */\n private _state: ServiceState = \"not-constructed\";\n\n /** Service instance, once constructed. */\n private _instance: Service | undefined = undefined;\n\n constructor(options: ServiceReprOptions) {\n const {\n name,\n packageName,\n factory,\n intl,\n dependencies = [],\n interfaces = [],\n properties = {}\n } = options;\n if (!isValidServiceName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid service name: '${name}'.`);\n }\n\n this.id = `${packageName}::${name}`;\n this.name = name;\n this.packageName = packageName;\n this.factory = factory;\n this.intl = intl;\n this.dependencies = dependencies;\n this.interfaces = interfaces;\n this.properties = properties;\n }\n\n /** Returns the current service instance or undefined if the service has not been constructed. */\n get instance(): Service | undefined {\n return this._instance;\n }\n\n /** Returns the current state of the service. */\n get state() {\n return this._state;\n }\n\n /** Returns the current reference count. */\n get useCount() {\n return this._useCount;\n }\n\n /**\n * Same as `instance`, but throws when the instance has not been constructed.\n */\n getInstanceOrThrow() {\n const instance = this._instance;\n if (!instance) {\n throw new Error(ErrorId.INTERNAL, \"Expected service instance to be present.\");\n }\n return instance;\n }\n\n /**\n * Called before `create()` to place the service into the `constructing` state,\n * which is currently used to detect cycles.\n */\n beforeCreate() {\n if (this._state === \"not-constructed\") {\n this._state = \"constructing\";\n } else {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is already under construction.\"\n );\n }\n }\n\n /**\n * Instantiates the service by invoking the service constructor\n * with the given `options`.\n *\n * The service's use count is initialized to `1`, so every `create()`\n * should be paired with a `removeRef()`.\n *\n * `destroy()` can be invoked once the final `removeRef()` has returned zero.\n */\n create(options: Pick<ServiceOptions, \"references\" | \"referencesMeta\">) {\n if (this._state !== \"constructing\" || this.instance !== undefined) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is not being constructed.\"\n );\n }\n try {\n this._instance = createService(this.factory, {\n ...options,\n properties: this.properties,\n intl: this.intl\n });\n this._state = \"constructed\";\n this._useCount = 1;\n return this._instance;\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_CONSTRUCTION_FAILED,\n `Failed to create service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n\n destroy() {\n if (this._instance) {\n try {\n this._instance.destroy?.();\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_DESTRUCTION_FAILED,\n `Failed to destroy service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n this._instance = undefined;\n this._state = \"destroyed\";\n }\n\n /**\n * Adds a use to the service's use count.\n * References to a service are tracked: it should only be destroyed when it is no longer being used.\n */\n addRef() {\n return (this._useCount += 1);\n }\n\n /**\n * Removes a use from the service's use count.\n * Returns the new use count.\n */\n removeRef() {\n return (this._useCount -= 1);\n }\n}\n\nexport function createConstructorFactory<T extends {}>(\n clazz: ServiceConstructor<T>\n): ConstructorFactory {\n return { type: \"class\", clazz };\n}\n\nexport function createFunctionFactory(\n create: (options: ServiceOptions) => Service\n): FunctionFactory {\n return { type: \"function\", create };\n}\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n}\n\nfunction createService(factory: ServiceFactory, options: ServiceOptions) {\n switch (factory.type) {\n case \"class\":\n return new factory.clazz(options);\n case \"function\":\n return factory.create(options);\n }\n}\n"],"names":["name"],"mappings":";;;;AAwCO,MAAM,WAAY,CAAA;AAAA,EACrB,OAAO,MAAA,CACH,WACA,EAAA,IAAA,EACA,MACA,UACW,EAAA;AACX,IAAA,MAAM,QAAQ,IAAK,CAAA,KAAA,CAAA;AACnB,IAAA,MAAM,OAAO,IAAK,CAAA,IAAA,CAAA;AAClB,IAAA,MAAM,eAAe,MAAO,CAAA,OAAA,CAAQ,KAAK,UAAc,IAAA,EAAE,CAAE,CAAA,GAAA;AAAA,MACvD,CAAC,CAACA,KAAM,EAAA,iBAA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Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ErrorId } from \"../errors\";\nimport { ServiceMetadata } from \"../metadata\";\nimport { Service, ServiceConstructor, ServiceOptions } from \"../Service\";\nimport { Error } from \"@open-pioneer/core\";\nimport { InterfaceSpec, parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { PackageIntl } from \"../i18n\";\n\nexport type ServiceState = \"not-constructed\" | \"constructing\" | \"constructed\" | \"destroyed\";\n\nexport type ServiceDependency = ReferenceSpec & { referenceName: string };\n\nexport interface ConstructorFactory {\n type: \"class\";\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n clazz: ServiceConstructor<any>;\n}\n\nexport interface FunctionFactory {\n type: \"function\";\n create: (options: ServiceOptions) => Service;\n}\n\nexport type ServiceFactory = ConstructorFactory | FunctionFactory;\n\nexport interface ServiceReprOptions {\n name: string;\n packageName: string;\n factory: ServiceFactory;\n intl: PackageIntl;\n dependencies?: ServiceDependency[];\n interfaces?: InterfaceSpec[];\n properties?: Record<string, unknown>;\n}\n\n/**\n * Represents metadata and state of a service in the runtime.\n * `this.instance` is the actual service instance (when constructed).\n */\nexport class ServiceRepr {\n static create(\n packageName: string,\n data: ServiceMetadata,\n intl: PackageIntl,\n properties?: Record<string, unknown>\n ): ServiceRepr {\n const clazz = data.clazz;\n const name = data.name;\n const dependencies = Object.entries(data.references ?? {}).map(\n ([name, referenceMetadata]) => {\n return {\n referenceName: name,\n ...parseReferenceSpec(referenceMetadata)\n };\n }\n );\n const interfaces = data.provides?.map<InterfaceSpec>((i) => {\n return {\n interfaceName: i.name,\n qualifier: i.qualifier\n };\n });\n const factory: ConstructorFactory = {\n type: \"class\",\n clazz\n };\n return new ServiceRepr({\n name,\n packageName,\n factory,\n intl,\n dependencies,\n interfaces,\n properties\n });\n }\n\n /** Unique id of this service. Contains the package name and the service name. */\n readonly id: string;\n\n /** Name of this service in it's package. */\n readonly name: string;\n\n /** Name of the parent package. */\n readonly packageName: string;\n\n /** Locale-dependant i18n messages. */\n readonly intl: PackageIntl;\n\n /** Service properties made available via the service's constructor. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Dependencies required by the service constructor. */\n readonly dependencies: readonly ServiceDependency[];\n\n /** Interfaces provided by the service. */\n readonly interfaces: readonly Readonly<InterfaceSpec>[];\n\n /** Number of references to this service. */\n private _useCount = 0;\n\n /** Service factory to construct an instance. */\n private factory: ServiceFactory;\n\n /** Current state of this service. \"constructed\" -> instance is available. */\n private _state: ServiceState = \"not-constructed\";\n\n /** Service instance, once constructed. */\n private _instance: Service | undefined = undefined;\n\n constructor(options: ServiceReprOptions) {\n const {\n name,\n packageName,\n factory,\n intl,\n dependencies = [],\n interfaces = [],\n properties = {}\n } = options;\n if (!isValidServiceName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid service name: '${name}'.`);\n }\n\n this.id = `${packageName}::${name}`;\n this.name = name;\n this.packageName = packageName;\n this.factory = factory;\n this.intl = intl;\n this.dependencies = dependencies;\n this.interfaces = interfaces;\n this.properties = properties;\n }\n\n /** Returns the current service instance or undefined if the service has not been constructed. */\n get instance(): Service | undefined {\n return this._instance;\n }\n\n /** Returns the current state of the service. */\n get state() {\n return this._state;\n }\n\n /** Returns the current reference count. */\n get useCount() {\n return this._useCount;\n }\n\n /**\n * Same as `instance`, but throws when the instance has not been constructed.\n */\n getInstanceOrThrow() {\n const instance = this._instance;\n if (!instance) {\n throw new Error(ErrorId.INTERNAL, \"Expected service instance to be present.\");\n }\n return instance;\n }\n\n /**\n * Called before `create()` to place the service into the `constructing` state,\n * which is currently used to detect cycles.\n */\n beforeCreate() {\n if (this._state === \"not-constructed\") {\n this._state = \"constructing\";\n } else {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is already under construction.\"\n );\n }\n }\n\n /**\n * Instantiates the service by invoking the service constructor\n * with the given `options`.\n *\n * The service's use count is initialized to `1`, so every `create()`\n * should be paired with a `removeRef()`.\n *\n * `destroy()` can be invoked once the final `removeRef()` has returned zero.\n */\n create(options: Pick<ServiceOptions, \"references\" | \"referencesMeta\">) {\n if (this._state !== \"constructing\" || this.instance !== undefined) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is not being constructed.\"\n );\n }\n try {\n this._instance = createService(this.factory, {\n ...options,\n properties: this.properties,\n intl: this.intl\n });\n this._state = \"constructed\";\n this._useCount = 1;\n return this._instance;\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_CONSTRUCTION_FAILED,\n `Failed to create service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n\n destroy() {\n if (this._instance) {\n try {\n this._instance.destroy?.();\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_DESTRUCTION_FAILED,\n `Failed to destroy service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n this._instance = undefined;\n this._state = \"destroyed\";\n }\n\n /**\n * Adds a use to the service's use count.\n * References to a service are tracked: it should only be destroyed when it is no longer being used.\n */\n addRef() {\n return (this._useCount += 1);\n }\n\n /**\n * Removes a use from the service's use count.\n * Returns the new use count.\n */\n removeRef() {\n return (this._useCount -= 1);\n }\n}\n\nexport function createConstructorFactory<T extends {}>(\n clazz: ServiceConstructor<T>\n): ConstructorFactory {\n return { type: \"class\", clazz };\n}\n\nexport function createFunctionFactory(\n create: (options: ServiceOptions) => Service\n): FunctionFactory {\n return { type: \"function\", create };\n}\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n}\n\nfunction createService(factory: ServiceFactory, options: ServiceOptions) {\n switch (factory.type) {\n case \"class\":\n return new factory.clazz(options);\n case \"function\":\n return factory.create(options);\n }\n}\n"],"names":["name"],"mappings":";;;;AAwCO,MAAM,WAAY,CAAA;AAAA,EACrB,OAAO,MAAA,CACH,WACA,EAAA,IAAA,EACA,MACA,UACW,EAAA;AACX,IAAA,MAAM,QAAQ,IAAK,CAAA,KA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CAAM,OAAO,CAAA,CAAA;AAAA,IACpC,KAAK,UAAA;AACD,MAAO,OAAA,OAAA,CAAQ,OAAO,OAAO,CAAA,CAAA;AAAA,GACrC;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyDependencies.js","sources":["verifyDependencies.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, ReferenceSpec, renderInterfaceSpec } from \"./InterfaceSpec\";\nimport {\n AmbiguousChoice,\n ReadonlyServiceLookup,\n renderAmbiguousServiceChoices,\n ServiceLookup\n} from \"./ServiceLookup\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface DependencyOptions {\n /**\n * All services known to the service layer.\n */\n services?: readonly ServiceRepr[];\n\n /**\n * References that must be satisfied by the services.\n */\n requiredReferences?: readonly RequiredReference[];\n}\n\nexport type RequiredReference = UIDependency | FrameworkDependency;\n\nexport type UIDependency = { type: \"ui\"; packageName: string } & ReferenceSpec;\n\nexport type FrameworkDependency = { type: \"framework\" } & ReferenceSpec;\n\nexport type ComputedServiceDependencies = Record<string, ServiceRepr | ServiceRepr[]>;\n\nexport interface VerifyDependenciesResult {\n /**\n * Precomputed dependencies for every service.\n *\n * Key: service id.\n */\n serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n /**\n * Index structure mapping interface names to service instances.\n */\n serviceLookup: ReadonlyServiceLookup;\n}\n\n/**\n * Visits all services and ensures that their dependencies can be satisfied by each other without a cycle.\n *\n * Throws an error if a cycle is detected or if a required service is never implemented.\n *\n * @returns an object containing the service index and precomputed dependency information\n */\nexport function verifyDependencies(options: DependencyOptions): VerifyDependenciesResult {\n const verifier = new Verifier(options);\n verifier.verify();\n return {\n serviceLookup: verifier.getServiceLookup(),\n serviceDependencies: verifier.getComputedDependencies()\n };\n}\n\ninterface GraphItem {\n state: ItemState;\n service: ServiceRepr;\n dependencies: ComputedServiceDependencies;\n}\n\ntype ItemState = \"not-visited\" | \"pending\" | \"done\";\n\n/** The reason why a graph node is being visited. */\ntype ItemVisitReason = \"root\" | InterfaceReference;\n\ntype InterfaceReference =\n | {\n type: \"framework-reference\";\n value: ReferenceSpec;\n }\n | {\n type: \"ui-reference\";\n packageName: string;\n value: ReferenceSpec;\n }\n | {\n type: \"service-reference\";\n service: ServiceRepr;\n referenceName: string;\n value: ReferenceSpec;\n };\n\nclass Verifier {\n private requiredReferences: readonly RequiredReference[];\n private items: GraphItem[];\n private serviceLookup = new ServiceLookup();\n private serviceToGraphItem = new Map<ServiceRepr, GraphItem>();\n\n // Stack of visited nodes\n private stack: [item: GraphItem, reason: ItemVisitReason][] = [];\n\n constructor(options: DependencyOptions) {\n this.requiredReferences = options.requiredReferences ?? [];\n const services = options.services ?? [];\n const items = (this.items = services.map<GraphItem>((service) => {\n return {\n service: service,\n state: \"not-visited\",\n dependencies: {}\n };\n }));\n\n for (const item of items) {\n for (const spec of item.service.interfaces) {\n this.registerService(item, spec);\n }\n }\n }\n\n verify() {\n for (const ref of this.requiredReferences) {\n let interfaceRef: InterfaceReference;\n switch (ref.type) {\n case \"framework\":\n interfaceRef = { type: \"framework-reference\", value: ref };\n break;\n case \"ui\":\n interfaceRef = {\n type: \"ui-reference\",\n packageName: ref.packageName,\n value: ref\n };\n break;\n }\n this.visitReference(interfaceRef);\n }\n for (const item of this.items) {\n this.visitItem(item, \"root\");\n }\n }\n\n getServiceLookup() {\n return this.serviceLookup;\n }\n\n getComputedDependencies() {\n return new Map(\n this.items.map<[string, ComputedServiceDependencies]>((item) => {\n return [item.service.id, item.dependencies];\n })\n );\n }\n\n private visitItem(item: GraphItem, reason: ItemVisitReason) {\n const stack = this.stack;\n const state = item.state;\n if (state === \"done\") {\n return; // Item is initialized, cycle impossible\n }\n if (state === \"pending\") {\n this.throwCycleError(item, reason);\n }\n\n stack.push([item, reason]);\n item.state = \"pending\";\n for (const dep of item.service.dependencies) {\n item.dependencies[dep.referenceName] = this.visitReference({\n type: \"service-reference\",\n service: item.service,\n referenceName: dep.referenceName,\n value: dep\n });\n }\n item.state = \"done\";\n stack.pop();\n }\n\n private visitReference(ref: InterfaceReference) {\n const itemOrItems = this.findServices(ref);\n if (Array.isArray(itemOrItems)) {\n for (const child of itemOrItems) {\n this.visitItem(child, ref);\n }\n return itemOrItems.map((item) => item.service);\n } else {\n this.visitItem(itemOrItems, ref);\n return itemOrItems.service;\n }\n }\n\n private registerService(item: GraphItem, spec: InterfaceSpec) {\n this.serviceLookup.register(item.service, spec);\n this.serviceToGraphItem.set(item.service, item);\n }\n\n private findServices(ref: InterfaceReference): GraphItem | GraphItem[] {\n const spec = ref.value;\n const lookupResult = this.serviceLookup.lookup(spec);\n switch (lookupResult.type) {\n case \"unimplemented\": {\n const message = unimplementedInterfaceMessage(ref);\n throw new Error(ErrorId.INTERFACE_NOT_FOUND, message);\n }\n case \"ambiguous\": {\n const message = ambiguousInterfaceMessage(ref, lookupResult.choices);\n throw new Error(ErrorId.AMBIGUOUS_DEPENDENCY, message);\n }\n }\n\n const value = lookupResult.value;\n if (Array.isArray(value)) {\n return value.map((service) => this.getGraphItem(service));\n } else {\n return this.getGraphItem(value);\n }\n }\n\n private getGraphItem(service: ServiceRepr): GraphItem {\n const graphItem = this.serviceToGraphItem.get(service);\n if (!graphItem || graphItem.service !== service) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find matching graph item for service '${service.id}'.`\n );\n }\n return graphItem;\n }\n\n private throwCycleError(item: GraphItem, reason: ItemVisitReason) {\n // Find the item on the stack (it must be there because we detected a cycle).\n const stack = this.stack;\n const ownIndex = stack.findIndex((entry) => entry[0] === item);\n if (ownIndex === -1) {\n throw new Error(ErrorId.INTERNAL, \"Failed to find cycle participant on the stack.\");\n }\n\n const cycleInfo = stack\n .slice(ownIndex)\n .concat([[item, reason]])\n .map<string>((entry, index) => {\n const item = entry[0];\n const reason = index === 0 ? \"root\" : entry[1]; // info before the cycle does not matter\n\n let message = `'${item.service.id}'`;\n if (typeof reason === \"object\") {\n message += ` (${referenceDetail(reason)})`;\n }\n return message;\n });\n throw new Error(\n ErrorId.DEPENDENCY_CYCLE,\n `Detected dependency cycle: ${cycleInfo.join(\" => \")}.`\n );\n }\n}\n\nfunction unimplementedInterfaceMessage(ref: InterfaceReference): string {\n const interfaceText = renderInterfaceSpec(ref.value);\n switch (ref.type) {\n case \"service-reference\":\n return `Service '${ref.service.id}' requires an unimplemented interface ${interfaceText} as dependency '${ref.referenceName}'.`;\n case \"ui-reference\":\n return `The UI of package '${ref.packageName}' requires an unimplemented interface ${interfaceText}.`;\n case \"framework-reference\":\n return `The framework requires an unimplemented interface ${interfaceText}.`;\n }\n}\n\nfunction ambiguousInterfaceMessage(ref: InterfaceReference, choices: AmbiguousChoice[]): string {\n const interfaceText = renderInterfaceSpec(ref.value);\n const serviceChoices = renderAmbiguousServiceChoices(choices);\n\n let message = \"\";\n switch (ref.type) {\n case \"service-reference\":\n message = `Service '${ref.service.id}' requires the ambiguous interface ${interfaceText} as dependency '${ref.referenceName}'.`;\n break;\n case \"ui-reference\":\n message = `The UI of package '${ref.packageName}' requires the ambiguous interface ${interfaceText}.`;\n break;\n case \"framework-reference\":\n message = `The framework requires the ambiguous interface ${interfaceText}.`;\n break;\n }\n message += ` Possible choices are ${serviceChoices}.`;\n return message;\n}\n\nfunction referenceDetail(reason: InterfaceReference) {\n switch (reason.type) {\n case \"service-reference\":\n return `'${reason.referenceName}' providing '${reason.value.interfaceName}'`;\n case \"ui-reference\":\n return `UI of package '${reason.packageName}' requiring '${reason.value.interfaceName}'`;\n case \"framework-reference\":\n return `framework requiring '${reason.value.interfaceName}'`;\n }\n}\n"],"names":["item","reason"],"mappings":";;;;;AAsDO,SAAS,mBAAmB,OAAsD,EAAA;AACrF,EAAM,MAAA,QAAA,GAAW,IAAI,QAAA,CAAS,OAAO,CAAA,CAAA;AACrC,EAAA,QAAA,CA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A;AAEA,SAAS,gBAAgB,MAA4B,EAAA;AACjD,EAAA,QAAQ,OAAO,IAAM;AAAA,IACjB,KAAK,mBAAA;AACD,MAAA,OAAO,CAAI,CAAA,EAAA,MAAA,CAAO,aAA6B,CAAA,aAAA,EAAA,MAAA,CAAO,KAAM,CAAA,aAAA,CAAA,CAAA,CAAA,CAAA;AAAA,IAChE,KAAK,cAAA;AACD,MAAA,OAAO,CAAkB,eAAA,EAAA,MAAA,CAAO,WAA2B,CAAA,aAAA,EAAA,MAAA,CAAO,KAAM,CAAA,aAAA,CAAA,CAAA,CAAA,CAAA;AAAA,IAC5E,KAAK,qBAAA;AACD,MAAO,OAAA,CAAA,qBAAA,EAAwB,OAAO,KAAM,CAAA,aAAA,CAAA,CAAA,CAAA,CAAA;AAAA,GACpD;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"verifyDependencies.js","sources":["verifyDependencies.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 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, ReferenceSpec, renderInterfaceSpec } from \"./InterfaceSpec\";\nimport {\n AmbiguousChoice,\n ReadonlyServiceLookup,\n renderAmbiguousServiceChoices,\n ServiceLookup\n} from \"./ServiceLookup\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface DependencyOptions {\n /**\n * All services known to the service layer.\n */\n services?: readonly ServiceRepr[];\n\n /**\n * References that must be satisfied by the services.\n */\n requiredReferences?: readonly RequiredReference[];\n}\n\nexport type RequiredReference = UIDependency | FrameworkDependency;\n\nexport type UIDependency = { type: \"ui\"; packageName: string } & ReferenceSpec;\n\nexport type FrameworkDependency = { type: \"framework\" } & ReferenceSpec;\n\nexport type ComputedServiceDependencies = Record<string, ServiceRepr | ServiceRepr[]>;\n\nexport interface VerifyDependenciesResult {\n /**\n * Precomputed dependencies for every service.\n *\n * Key: service id.\n */\n serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n /**\n * Index structure mapping interface names to service instances.\n */\n serviceLookup: ReadonlyServiceLookup;\n}\n\n/**\n * Visits all services and ensures that their dependencies can be satisfied by each other without a cycle.\n *\n * Throws an error if a cycle is detected or if a required service is never implemented.\n *\n * @returns an object containing the service index and precomputed dependency information\n */\nexport function verifyDependencies(options: DependencyOptions): VerifyDependenciesResult {\n const verifier = new Verifier(options);\n verifier.verify();\n return {\n serviceLookup: verifier.getServiceLookup(),\n serviceDependencies: verifier.getComputedDependencies()\n };\n}\n\ninterface GraphItem {\n state: ItemState;\n service: ServiceRepr;\n dependencies: ComputedServiceDependencies;\n}\n\ntype ItemState = \"not-visited\" | \"pending\" | \"done\";\n\n/** The reason why a graph node is being visited. */\ntype ItemVisitReason = \"root\" | InterfaceReference;\n\ntype InterfaceReference =\n | {\n type: \"framework-reference\";\n value: ReferenceSpec;\n }\n | {\n type: \"ui-reference\";\n packageName: string;\n value: ReferenceSpec;\n }\n | {\n type: \"service-reference\";\n service: ServiceRepr;\n referenceName: string;\n value: ReferenceSpec;\n };\n\nclass Verifier {\n private requiredReferences: readonly RequiredReference[];\n private items: GraphItem[];\n private serviceLookup = new ServiceLookup();\n private serviceToGraphItem = new Map<ServiceRepr, GraphItem>();\n\n // Stack of visited nodes\n private stack: [item: GraphItem, reason: ItemVisitReason][] = [];\n\n constructor(options: DependencyOptions) {\n this.requiredReferences = options.requiredReferences ?? [];\n const services = options.services ?? [];\n const items = (this.items = services.map<GraphItem>((service) => {\n return {\n service: service,\n state: \"not-visited\",\n dependencies: {}\n };\n }));\n\n for (const item of items) {\n for (const spec of item.service.interfaces) {\n this.registerService(item, spec);\n }\n }\n }\n\n verify() {\n for (const ref of this.requiredReferences) {\n let interfaceRef: InterfaceReference;\n switch (ref.type) {\n case \"framework\":\n interfaceRef = { type: \"framework-reference\", value: ref };\n break;\n case \"ui\":\n interfaceRef = {\n type: \"ui-reference\",\n packageName: ref.packageName,\n value: ref\n };\n break;\n }\n this.visitReference(interfaceRef);\n }\n for (const item of this.items) {\n this.visitItem(item, \"root\");\n }\n }\n\n getServiceLookup() {\n return this.serviceLookup;\n }\n\n getComputedDependencies() {\n return new Map(\n this.items.map<[string, ComputedServiceDependencies]>((item) => {\n return [item.service.id, item.dependencies];\n })\n );\n }\n\n private visitItem(item: GraphItem, reason: ItemVisitReason) {\n const stack = this.stack;\n const state = item.state;\n if (state === \"done\") {\n return; // Item is initialized, cycle impossible\n }\n if (state === \"pending\") {\n this.throwCycleError(item, reason);\n }\n\n stack.push([item, reason]);\n item.state = \"pending\";\n for (const dep of item.service.dependencies) {\n item.dependencies[dep.referenceName] = this.visitReference({\n type: \"service-reference\",\n service: item.service,\n referenceName: dep.referenceName,\n value: dep\n });\n }\n item.state = \"done\";\n stack.pop();\n }\n\n private visitReference(ref: InterfaceReference) {\n const itemOrItems = this.findServices(ref);\n if (Array.isArray(itemOrItems)) {\n for (const child of itemOrItems) {\n this.visitItem(child, ref);\n }\n return itemOrItems.map((item) => item.service);\n } else {\n this.visitItem(itemOrItems, ref);\n return itemOrItems.service;\n }\n }\n\n private registerService(item: GraphItem, spec: InterfaceSpec) {\n this.serviceLookup.register(item.service, spec);\n this.serviceToGraphItem.set(item.service, item);\n }\n\n private findServices(ref: InterfaceReference): GraphItem | GraphItem[] {\n const spec = ref.value;\n const lookupResult = this.serviceLookup.lookup(spec);\n switch (lookupResult.type) {\n case \"unimplemented\": {\n const message = unimplementedInterfaceMessage(ref);\n throw new Error(ErrorId.INTERFACE_NOT_FOUND, message);\n }\n case \"ambiguous\": {\n const message = ambiguousInterfaceMessage(ref, lookupResult.choices);\n throw new Error(ErrorId.AMBIGUOUS_DEPENDENCY, message);\n }\n }\n\n const value = lookupResult.value;\n if (Array.isArray(value)) {\n return value.map((service) => this.getGraphItem(service));\n } else {\n return this.getGraphItem(value);\n }\n }\n\n private getGraphItem(service: ServiceRepr): GraphItem {\n const graphItem = this.serviceToGraphItem.get(service);\n if (!graphItem || graphItem.service !== service) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find matching graph item for service '${service.id}'.`\n );\n }\n return graphItem;\n }\n\n private throwCycleError(item: GraphItem, reason: ItemVisitReason) {\n // Find the item on the stack (it must be there because we detected a cycle).\n const stack = this.stack;\n const ownIndex = stack.findIndex((entry) => entry[0] === item);\n if (ownIndex === -1) {\n throw new Error(ErrorId.INTERNAL, \"Failed to find cycle participant on the stack.\");\n }\n\n const cycleInfo = stack\n .slice(ownIndex)\n .concat([[item, reason]])\n .map<string>((entry, index) => {\n const item = entry[0];\n const reason = index === 0 ? \"root\" : entry[1]; // info before the cycle does not matter\n\n let message = `'${item.service.id}'`;\n if (typeof reason === \"object\") {\n message += ` (${referenceDetail(reason)})`;\n }\n return message;\n });\n throw new Error(\n ErrorId.DEPENDENCY_CYCLE,\n `Detected dependency cycle: ${cycleInfo.join(\" => \")}.`\n );\n }\n}\n\nfunction unimplementedInterfaceMessage(ref: InterfaceReference): string {\n const interfaceText = renderInterfaceSpec(ref.value);\n switch (ref.type) {\n case \"service-reference\":\n return `Service '${ref.service.id}' requires an unimplemented interface ${interfaceText} as dependency '${ref.referenceName}'.`;\n case \"ui-reference\":\n return `The UI of package '${ref.packageName}' requires an unimplemented interface ${interfaceText}.`;\n case \"framework-reference\":\n return `The framework requires an unimplemented interface ${interfaceText}.`;\n }\n}\n\nfunction ambiguousInterfaceMessage(ref: InterfaceReference, choices: AmbiguousChoice[]): string {\n const interfaceText = renderInterfaceSpec(ref.value);\n const serviceChoices = renderAmbiguousServiceChoices(choices);\n\n let message = \"\";\n switch (ref.type) {\n case \"service-reference\":\n message = `Service '${ref.service.id}' requires the ambiguous interface ${interfaceText} as dependency '${ref.referenceName}'.`;\n break;\n case \"ui-reference\":\n message = `The UI of package '${ref.packageName}' requires the ambiguous interface ${interfaceText}.`;\n break;\n case \"framework-reference\":\n message = `The framework requires the ambiguous interface ${interfaceText}.`;\n break;\n }\n message += ` Possible choices are ${serviceChoices}.`;\n return message;\n}\n\nfunction referenceDetail(reason: InterfaceReference) {\n switch (reason.type) {\n case \"service-reference\":\n return `'${reason.referenceName}' providing '${reason.value.interfaceName}'`;\n case \"ui-reference\":\n return `UI of package '${reason.packageName}' requiring '${reason.value.interfaceName}'`;\n case \"framework-reference\":\n return `framework requiring '${reason.value.interfaceName}'`;\n }\n}\n"],"names":["item","reason"],"mappings":";;;;;AAsDO,SAAS,mBAAmB,OAAsD,EAAA;AACrF,EAAM,MAAA,QAAA,GAAW,IAAI,QAAA,CAAS,OAAO,CAAA,CAAA;AACrC,EAAA,QAAA,CAAS,MAAO,EAAA,CAAA;AAChB,EAAO,OAAA;AAAA,IACH,aAAA,EAAe,SAAS,gBAAiB,EAAA;AAAA,IACzC,mBAAA,EAAqB,SAAS,uBAAwB,EAAA;AAAA,GAC1D,CAAA;AACJ,CAAA;AA8BA,MAAM,QAAS,CAAA;AAAA,EACH,kBAAA,CAAA;AAAA,EACA,KAAA,CAAA;AAAA,EACA,aAAA,GAAgB,IAAI,aAAc,EAAA,CAAA;AAAA,EAClC,kBAAA,uBAAyB,GAA4B,EAAA,CAAA;AAAA;AAAA,EAGrD,QAAsD,EAAC,CAAA;AAAA,EAE/D,YAAY,OAA4B,EAAA;AACpC,IAAK,IAAA,CAAA,kBAAA,GAAqB,OAAQ,CAAA,kBAAA,IAAsB,EAAC,CAAA;AACzD,IAAM,MAAA,QAAA,GAAW,OAAQ,CAAA,QAAA,IAAY,EAAC,CAAA;AACtC,IAAA,MAAM,QAAS,IAAK,CAAA,KAAA,GAAQ,QAAS,CAAA,GAAA,CAAe,CAAC,OAAY,KAAA;AAC7D,MAAO,OAAA;AAAA,QACH,OAAA;AAAA,QACA,KAAO,EAAA,aAAA;AAAA,QACP,cAAc,EAAC;AAAA,OACnB,CAAA;AAAA,KACH,CAAA,CAAA;AAED,IAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACtB,MAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA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;AACD,MAAA,OAAA,GAAU,CAAsB,mBAAA,EAAA,GAAA,CAAI,WAAW,CAAA,mCAAA,EAAsC,aAAa,CAAA,CAAA,CAAA,CAAA;AAClG,MAAA,MAAA;AAAA,IACJ,KAAK,qBAAA;AACD,MAAA,OAAA,GAAU,kDAAkD,aAAa,CAAA,CAAA,CAAA,CAAA;AACzE,MAAA,MAAA;AAAA,GACR;AACA,EAAA,OAAA,IAAW,yBAAyB,cAAc,CAAA,CAAA,CAAA,CAAA;AAClD,EAAO,OAAA,OAAA,CAAA;AACX,CAAA;AAEA,SAAS,gBAAgB,MAA4B,EAAA;AACjD,EAAA,QAAQ,OAAO,IAAM;AAAA,IACjB,KAAK,mBAAA;AACD,MAAA,OAAO,IAAI,MAAO,CAAA,aAAa,CAAgB,aAAA,EAAA,MAAA,CAAO,MAAM,aAAa,CAAA,CAAA,CAAA,CAAA;AAAA,IAC7E,KAAK,cAAA;AACD,MAAA,OAAO,kBAAkB,MAAO,CAAA,WAAW,CAAgB,aAAA,EAAA,MAAA,CAAO,MAAM,aAAa,CAAA,CAAA,CAAA,CAAA;AAAA,IACzF,KAAK,qBAAA;AACD,MAAO,OAAA,CAAA,qBAAA,EAAwB,MAAO,CAAA,KAAA,CAAM,aAAa,CAAA,CAAA,CAAA,CAAA;AAAA,GACjE;AACJ;;;;"}
|
package/PropertiesRegistry.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Maps a package name to its supported properties.
|
|
3
|
-
*
|
|
4
|
-
* By default, properties for all packages are untyped (as Record<string, unknown>).
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* import "@open-pioneer/runtime";
|
|
10
|
-
* declare module "@open-pioneer/runtime" {
|
|
11
|
-
* interface PropertiesRegistry {
|
|
12
|
-
* // Declares that properties for the "logging" package must
|
|
13
|
-
* // conform to the type on the right when overridden by an app.
|
|
14
|
-
* "logging": Partial<LoggingProperties>
|
|
15
|
-
* }
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export interface PropertiesRegistry {
|
|
20
|
-
}
|