@open-pioneer/runtime 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/CustomElement.js +335 -0
- package/CustomElement.js.map +1 -0
- package/LICENSE +202 -0
- package/README.md +37 -0
- package/builtin-services/ApiServiceImpl.js +46 -0
- package/builtin-services/ApiServiceImpl.js.map +1 -0
- package/builtin-services/ApplicationContextImpl.js +32 -0
- package/builtin-services/ApplicationContextImpl.js.map +1 -0
- package/builtin-services/ApplicationLifecycleEventService.js +39 -0
- package/builtin-services/ApplicationLifecycleEventService.js.map +1 -0
- package/builtin-services/index.js +76 -0
- package/builtin-services/index.js.map +1 -0
- package/errors.js +21 -0
- package/errors.js.map +1 -0
- package/i18n.js +105 -0
- package/i18n.js.map +1 -0
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/metadata/ObservableBox.js +25 -0
- package/metadata/ObservableBox.js.map +1 -0
- package/metadata/index.js +2 -0
- package/metadata/index.js.map +1 -0
- package/package.json +36 -0
- package/react-integration/PackageContext.js +6 -0
- package/react-integration/PackageContext.js.map +1 -0
- package/react-integration/ReactIntegration.js +92 -0
- package/react-integration/ReactIntegration.js.map +1 -0
- package/react-integration/hooks.js +45 -0
- package/react-integration/hooks.js.map +1 -0
- package/react-integration/index.js +3 -0
- package/react-integration/index.js.map +1 -0
- package/service-layer/InterfaceSpec.js +36 -0
- package/service-layer/InterfaceSpec.js.map +1 -0
- package/service-layer/PackageRepr.js +101 -0
- package/service-layer/PackageRepr.js.map +1 -0
- package/service-layer/ServiceLayer.js +265 -0
- package/service-layer/ServiceLayer.js.map +1 -0
- package/service-layer/ServiceLookup.js +169 -0
- package/service-layer/ServiceLookup.js.map +1 -0
- package/service-layer/ServiceRepr.js +200 -0
- package/service-layer/ServiceRepr.js.map +1 -0
- package/service-layer/verifyDependencies.js +198 -0
- package/service-layer/verifyDependencies.js.map +1 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { Error } from '@open-pioneer/core';
|
|
3
|
+
import { PackageContext } from './PackageContext.js';
|
|
4
|
+
import { ErrorId } from '../errors.js';
|
|
5
|
+
|
|
6
|
+
function useServiceInternal(packageName, interfaceName, options) {
|
|
7
|
+
const context = useContext(PackageContext);
|
|
8
|
+
const service = useMemo(
|
|
9
|
+
() => checkContext("useService", context).getService(
|
|
10
|
+
packageName,
|
|
11
|
+
interfaceName,
|
|
12
|
+
options ?? {}
|
|
13
|
+
),
|
|
14
|
+
[context, packageName, interfaceName, options]
|
|
15
|
+
);
|
|
16
|
+
return service;
|
|
17
|
+
}
|
|
18
|
+
function useServicesInternal(packageName, interfaceName) {
|
|
19
|
+
const context = useContext(PackageContext);
|
|
20
|
+
const services = useMemo(
|
|
21
|
+
() => checkContext("useServices", context).getServices(packageName, interfaceName),
|
|
22
|
+
[context, packageName, interfaceName]
|
|
23
|
+
);
|
|
24
|
+
return services;
|
|
25
|
+
}
|
|
26
|
+
function usePropertiesInternal(packageName) {
|
|
27
|
+
const context = useContext(PackageContext);
|
|
28
|
+
return checkContext("useProperties", context).getProperties(packageName);
|
|
29
|
+
}
|
|
30
|
+
function useIntlInternal(packageName) {
|
|
31
|
+
const context = useContext(PackageContext);
|
|
32
|
+
return checkContext("useIntl", context).getIntl(packageName);
|
|
33
|
+
}
|
|
34
|
+
function checkContext(hookName, contextData) {
|
|
35
|
+
if (!contextData) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
ErrorId.INTERNAL,
|
|
38
|
+
`"Failed to access package context from '${hookName}': react integration was not set up properly.`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return contextData;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { useIntlInternal, usePropertiesInternal, useServiceInternal, useServicesInternal };
|
|
45
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["open-pioneer://external-pioneer-packages/@open-pioneer/runtime/react-integration/hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useContext, useMemo } from \"react\";\nimport { Error } from \"@open-pioneer/core\";\nimport { InterfaceName, ServiceType } from \"../ServiceRegistry\";\nimport { PackageContext as PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\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<Interface extends InterfaceName>(\n packageName: string,\n interfaceName: Interface,\n options?: UseServiceOptions\n): ServiceType<Interface>;\nexport function useServiceInternal(\n packageName: string,\n interfaceName: string,\n options?: UseServiceOptions\n): unknown;\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<Interface extends InterfaceName>(\n packageName: string,\n interfaceName: Interface\n): ServiceType<Interface>[];\nexport function useServicesInternal(packageName: string, interfaceName: string): unknown[];\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":";;;;;AAkDgB,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,CAA2C,wCAAA,EAAA,QAAA,CAAA,6CAAA,CAAA;AAAA,KAC/C,CAAA;AAAA,GACJ;AACA,EAAO,OAAA,WAAA,CAAA;AACX;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Error } from '@open-pioneer/core';
|
|
2
|
+
import { ErrorId } from '../errors.js';
|
|
3
|
+
|
|
4
|
+
function renderInterfaceSpec({ interfaceName, qualifier }) {
|
|
5
|
+
return `'${interfaceName}'` + (qualifier ? ` (qualifier: '${qualifier}')` : "");
|
|
6
|
+
}
|
|
7
|
+
function parseReferenceSpec(metadata) {
|
|
8
|
+
if (!metadata) {
|
|
9
|
+
throw new Error(ErrorId.INVALID_METADATA, "Missing reference metadata.");
|
|
10
|
+
}
|
|
11
|
+
if (metadata.all && metadata.qualifier) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
ErrorId.INVALID_METADATA,
|
|
14
|
+
"References can't use 'qualifier' and 'all' properties at the same time."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
if (metadata.all) {
|
|
18
|
+
return {
|
|
19
|
+
all: true,
|
|
20
|
+
interfaceName: metadata.name
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
interfaceName: metadata.name,
|
|
25
|
+
qualifier: metadata.qualifier
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function isSingleImplementationSpec(spec) {
|
|
29
|
+
return !spec.all;
|
|
30
|
+
}
|
|
31
|
+
function isAllImplementationsSpec(spec) {
|
|
32
|
+
return spec.all === true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { isAllImplementationsSpec, isSingleImplementationSpec, parseReferenceSpec, renderInterfaceSpec };
|
|
36
|
+
//# sourceMappingURL=InterfaceSpec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InterfaceSpec.js","sources":["open-pioneer://external-pioneer-packages/@open-pioneer/runtime/service-layer/InterfaceSpec.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 { 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,CAAI,CAAA,EAAA,aAAA,CAAA,CAAA,CAAA,IAAoB,SAAY,GAAA,CAAA,cAAA,EAAiB,SAAgB,CAAA,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;;;;"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Error } from '@open-pioneer/core';
|
|
2
|
+
import { ErrorId } from '../errors.js';
|
|
3
|
+
import { parseReferenceSpec } from './InterfaceSpec.js';
|
|
4
|
+
import { ServiceRepr } from './ServiceRepr.js';
|
|
5
|
+
|
|
6
|
+
class PackageRepr {
|
|
7
|
+
static create(data, i18n, customProperties) {
|
|
8
|
+
const name = data.name;
|
|
9
|
+
const properties = data.properties ?? {};
|
|
10
|
+
const finalProperties = customizeProperties(name, properties, customProperties);
|
|
11
|
+
const services = Object.entries(data.services ?? {}).map(
|
|
12
|
+
([name2, serviceData]) => {
|
|
13
|
+
if (name2 !== serviceData.name) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
ErrorId.INVALID_METADATA,
|
|
16
|
+
"Invalid metadata: service name mismatch."
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return ServiceRepr.create(data.name, serviceData, i18n, finalProperties);
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
const uiReferences = data.ui?.references?.map((ref) => parseReferenceSpec(ref)) ?? [];
|
|
23
|
+
return new PackageRepr({
|
|
24
|
+
name,
|
|
25
|
+
services,
|
|
26
|
+
uiReferences,
|
|
27
|
+
properties: finalProperties,
|
|
28
|
+
intl: i18n
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Package name */
|
|
32
|
+
name;
|
|
33
|
+
/** Services defined by the package */
|
|
34
|
+
services;
|
|
35
|
+
/** Interfaces required by UI components. */
|
|
36
|
+
uiReferences;
|
|
37
|
+
/** Resolved (perhaps customized) package properties. */
|
|
38
|
+
properties;
|
|
39
|
+
/** Locale-dependant i18n messages. */
|
|
40
|
+
intl;
|
|
41
|
+
constructor(options) {
|
|
42
|
+
const name = options.name;
|
|
43
|
+
if (!isValidPackageName(name)) {
|
|
44
|
+
throw new Error(ErrorId.INTERNAL, `Invalid package name: '${name}'.`);
|
|
45
|
+
}
|
|
46
|
+
this.name = name;
|
|
47
|
+
this.services = options.services ?? [];
|
|
48
|
+
this.uiReferences = options.uiReferences ?? [];
|
|
49
|
+
this.properties = options.properties ?? {};
|
|
50
|
+
this.intl = options.intl;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createPackages(packages, i18n, customProperties) {
|
|
54
|
+
return Object.entries(packages).map(([name, packageMetadata]) => {
|
|
55
|
+
if (name !== packageMetadata.name) {
|
|
56
|
+
throw new Error(ErrorId.INVALID_METADATA, "Invalid metadata: package name mismatch.");
|
|
57
|
+
}
|
|
58
|
+
const packageI18n = i18n.createPackageI18n(name);
|
|
59
|
+
return PackageRepr.create(packageMetadata, packageI18n, customProperties?.[name]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function customizeProperties(packageName, properties, customProperties = {}) {
|
|
63
|
+
const merged = {};
|
|
64
|
+
const required = [];
|
|
65
|
+
for (const [key, propertyMetadata] of Object.entries(properties)) {
|
|
66
|
+
merged[key] = propertyMetadata.value;
|
|
67
|
+
if (propertyMetadata.required) {
|
|
68
|
+
required.push(key);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const [key, value] of Object.entries(customProperties)) {
|
|
72
|
+
if (!hasProperty(merged, key)) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
ErrorId.INVALID_PROPERTY_NAME,
|
|
75
|
+
`Unexpected property name '${key}' for package '${packageName}': the property does not exist.`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
merged[key] = value;
|
|
79
|
+
}
|
|
80
|
+
for (const key of required) {
|
|
81
|
+
const value = merged[key];
|
|
82
|
+
if (value == null) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
ErrorId.REQUIRED_PROPERTY,
|
|
85
|
+
`Package '${packageName}' requires the property '${key}' to be initialized to a non-null value.`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return merged;
|
|
90
|
+
}
|
|
91
|
+
const HAS_PROP = Object.prototype.hasOwnProperty;
|
|
92
|
+
function hasProperty(object, key) {
|
|
93
|
+
return HAS_PROP.call(object, key);
|
|
94
|
+
}
|
|
95
|
+
const NAME_REGEX = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
96
|
+
function isValidPackageName(name) {
|
|
97
|
+
return NAME_REGEX.test(name);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { PackageRepr, createPackages };
|
|
101
|
+
//# sourceMappingURL=PackageRepr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PackageRepr.js","sources":["open-pioneer://external-pioneer-packages/@open-pioneer/runtime/service-layer/PackageRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: con terra GmbH and contributors\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,I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,CAAA,qBAAA;AAAA,QACR,6BAA6B,GAAqB,CAAA,eAAA,EAAA,WAAA,CAAA,+BAAA,CAAA;AAAA,OACtD,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,YAAY,WAAuC,CAAA,yBAAA,EAAA,GAAA,CAAA,wCAAA,CAAA;AAAA,OACvD,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;;;;"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
+
import { ErrorId } from '../errors.js';
|
|
3
|
+
import { verifyDependencies } from './verifyDependencies.js';
|
|
4
|
+
import { isSingleImplementationSpec, renderInterfaceSpec, isAllImplementationsSpec } from './InterfaceSpec.js';
|
|
5
|
+
import { RUNTIME_PACKAGE_NAME } from '../builtin-services/index.js';
|
|
6
|
+
|
|
7
|
+
const LOG = createLogger("runtime:ServiceLayer");
|
|
8
|
+
class ServiceLayer {
|
|
9
|
+
// All services in the application.
|
|
10
|
+
allServices;
|
|
11
|
+
// Set of required services. These services and their dependencies will be started.
|
|
12
|
+
requiredServices;
|
|
13
|
+
serviceLookup;
|
|
14
|
+
// Service id --> Service dependencies
|
|
15
|
+
serviceDependencies;
|
|
16
|
+
// Package name --> Interface name --> Declarations
|
|
17
|
+
declaredDependencies;
|
|
18
|
+
state = "not-started";
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a new service layer instance.
|
|
21
|
+
* Requires the application's set of packages (from which services are taken)
|
|
22
|
+
* and an optional set of forced references (interfaces whose implementing services will be started unconditionally).
|
|
23
|
+
*
|
|
24
|
+
* In its current form, the service layer will start only forced references and references needed by the UI (and their dependencies).
|
|
25
|
+
*/
|
|
26
|
+
constructor(packages, forcedReferences = []) {
|
|
27
|
+
const allServices = packages.map((pkg) => pkg.services).flat();
|
|
28
|
+
const uiDependencies = packages.map(
|
|
29
|
+
(pkg) => pkg.uiReferences.map((dep) => {
|
|
30
|
+
return {
|
|
31
|
+
type: "ui",
|
|
32
|
+
packageName: pkg.name,
|
|
33
|
+
...dep
|
|
34
|
+
};
|
|
35
|
+
})
|
|
36
|
+
).flat();
|
|
37
|
+
const requiredReferences = [
|
|
38
|
+
...forcedReferences.map((r) => ({
|
|
39
|
+
type: "framework",
|
|
40
|
+
...r
|
|
41
|
+
})),
|
|
42
|
+
...uiDependencies
|
|
43
|
+
];
|
|
44
|
+
const { serviceLookup, serviceDependencies } = verifyDependencies({
|
|
45
|
+
services: allServices,
|
|
46
|
+
requiredReferences
|
|
47
|
+
});
|
|
48
|
+
this.allServices = allServices;
|
|
49
|
+
this.requiredServices = getRequiredServices(requiredReferences, serviceLookup);
|
|
50
|
+
this.serviceLookup = serviceLookup;
|
|
51
|
+
this.serviceDependencies = serviceDependencies;
|
|
52
|
+
this.declaredDependencies = buildDependencyIndex(packages);
|
|
53
|
+
}
|
|
54
|
+
destroy() {
|
|
55
|
+
for (const service of this.requiredServices) {
|
|
56
|
+
this.destroyService(service);
|
|
57
|
+
}
|
|
58
|
+
this.state = "destroyed";
|
|
59
|
+
}
|
|
60
|
+
start() {
|
|
61
|
+
if (this.state !== "not-started") {
|
|
62
|
+
throw new Error(ErrorId.INTERNAL, "Service layer was already started.");
|
|
63
|
+
}
|
|
64
|
+
for (const service of this.requiredServices) {
|
|
65
|
+
this.createService(service);
|
|
66
|
+
}
|
|
67
|
+
this.state = "started";
|
|
68
|
+
if (import.meta.env.DEV) {
|
|
69
|
+
const unneededServices = this.allServices.filter(
|
|
70
|
+
(service) => service.packageName !== RUNTIME_PACKAGE_NAME && service.state === "not-constructed"
|
|
71
|
+
).map((service) => `'${service.id}'`);
|
|
72
|
+
if (unneededServices.length) {
|
|
73
|
+
const services = unneededServices.join(", ");
|
|
74
|
+
LOG.warn(
|
|
75
|
+
`The following services are contained in the application but were not started: ${services}.`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns a service implementing the given interface.
|
|
82
|
+
* Checks that the given package actually declared a dependency on that interface
|
|
83
|
+
* to enforce coding guidelines.
|
|
84
|
+
*
|
|
85
|
+
* @param packageName the name of the package requesting the import
|
|
86
|
+
* @param spec the interface specifier
|
|
87
|
+
* @param options advanced options to customize lookup
|
|
88
|
+
* @throws if the service layer is not in 'started' state or if no service implements the interface.
|
|
89
|
+
*/
|
|
90
|
+
getService(packageName, spec, options) {
|
|
91
|
+
if (this.state !== "started") {
|
|
92
|
+
throw new Error(ErrorId.INTERNAL, "Service layer is not started.");
|
|
93
|
+
}
|
|
94
|
+
if (!options?.ignoreDeclarationCheck && !this.isDeclaredDependency(packageName, spec)) {
|
|
95
|
+
return { type: "undeclared" };
|
|
96
|
+
}
|
|
97
|
+
return this.serviceLookup.lookupOne(spec);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns all services implementing the given interface.
|
|
101
|
+
* Requires that the dependency on all implementations has been declared in the package.
|
|
102
|
+
*
|
|
103
|
+
* @param packageName the name of the package requesting the import
|
|
104
|
+
* @param interfaceName the interface name
|
|
105
|
+
*
|
|
106
|
+
* @throws if the service layer is not in 'started'.
|
|
107
|
+
*/
|
|
108
|
+
getServices(packageName, interfaceName) {
|
|
109
|
+
if (this.state !== "started") {
|
|
110
|
+
throw new Error(ErrorId.INTERNAL, "Service layer is not started.");
|
|
111
|
+
}
|
|
112
|
+
if (!this.isDeclaredDependency(packageName, { interfaceName, all: true })) {
|
|
113
|
+
return { type: "undeclared" };
|
|
114
|
+
}
|
|
115
|
+
return this.serviceLookup.lookupAll(interfaceName);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Initializes the given service and its dependencies.
|
|
119
|
+
* Dependencies are initialized before the service that requires them.
|
|
120
|
+
*/
|
|
121
|
+
createService(service) {
|
|
122
|
+
if (service.state === "constructed") {
|
|
123
|
+
const instance = service.getInstanceOrThrow();
|
|
124
|
+
service.addRef();
|
|
125
|
+
return instance;
|
|
126
|
+
}
|
|
127
|
+
if (service.state === "constructing") {
|
|
128
|
+
throw new Error(ErrorId.INTERNAL, "Cycle during service construction.");
|
|
129
|
+
}
|
|
130
|
+
if (service.state !== "not-constructed") {
|
|
131
|
+
throw new Error(ErrorId.INTERNAL, "Invalid service state.");
|
|
132
|
+
}
|
|
133
|
+
const references = {};
|
|
134
|
+
const referencesMeta = {};
|
|
135
|
+
service.beforeCreate();
|
|
136
|
+
for (const [referenceName, serviceDeps] of Object.entries(this.getServiceDeps(service))) {
|
|
137
|
+
const [referenceValue, referenceMeta] = this.getReference(serviceDeps);
|
|
138
|
+
references[referenceName] = referenceValue;
|
|
139
|
+
referencesMeta[referenceName] = referenceMeta;
|
|
140
|
+
}
|
|
141
|
+
LOG.debug(`Creating service '${service.id}'.`);
|
|
142
|
+
return service.create({ references, referencesMeta });
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Destroys the given service and its dependencies.
|
|
146
|
+
* The dependencies are destroyed after the service.
|
|
147
|
+
*/
|
|
148
|
+
destroyService(service) {
|
|
149
|
+
if (service.state === "destroyed") {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (service.removeRef() <= 0) {
|
|
153
|
+
LOG.debug(`Destroying service '${service.id}'`);
|
|
154
|
+
service.destroy();
|
|
155
|
+
}
|
|
156
|
+
for (const serviceDeps of Object.values(this.getServiceDeps(service))) {
|
|
157
|
+
if (Array.isArray(serviceDeps)) {
|
|
158
|
+
for (const dep of serviceDeps) {
|
|
159
|
+
this.destroyService(dep);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
this.destroyService(serviceDeps);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
isDeclaredDependency(packageName, spec) {
|
|
167
|
+
const packageEntry = this.declaredDependencies.get(packageName);
|
|
168
|
+
if (!packageEntry) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
const interfaceEntry = packageEntry.get(spec.interfaceName);
|
|
172
|
+
if (!interfaceEntry) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (isSingleImplementationSpec(spec)) {
|
|
176
|
+
if (spec.qualifier == null) {
|
|
177
|
+
return interfaceEntry.unqualified;
|
|
178
|
+
}
|
|
179
|
+
return interfaceEntry.qualifiers.has(spec.qualifier);
|
|
180
|
+
} else {
|
|
181
|
+
return interfaceEntry.all;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
getReference(ref) {
|
|
185
|
+
if (Array.isArray(ref)) {
|
|
186
|
+
const referenceValues = [];
|
|
187
|
+
const referenceMeta2 = [];
|
|
188
|
+
for (const d of ref) {
|
|
189
|
+
const [value, meta] = this.getReference(d);
|
|
190
|
+
referenceValues.push(value);
|
|
191
|
+
referenceMeta2.push(meta);
|
|
192
|
+
}
|
|
193
|
+
return [referenceValues, referenceMeta2];
|
|
194
|
+
}
|
|
195
|
+
const referenceValue = this.createService(ref);
|
|
196
|
+
const referenceMeta = {
|
|
197
|
+
serviceId: ref.id
|
|
198
|
+
};
|
|
199
|
+
return [referenceValue, referenceMeta];
|
|
200
|
+
}
|
|
201
|
+
getServiceDeps(service) {
|
|
202
|
+
const dependencies = this.serviceDependencies.get(service.id);
|
|
203
|
+
if (!dependencies) {
|
|
204
|
+
throw new Error(
|
|
205
|
+
ErrorId.INTERNAL,
|
|
206
|
+
`Failed to find precomputed service dependencies for '${service.id}'.`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
return dependencies;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function getRequiredServices(requiredReferences, serviceLookup) {
|
|
213
|
+
const requiredServices = /* @__PURE__ */ new Set();
|
|
214
|
+
for (const referenceSpec of requiredReferences) {
|
|
215
|
+
const result = serviceLookup.lookup(referenceSpec);
|
|
216
|
+
if (result.type !== "found") {
|
|
217
|
+
throw new Error(
|
|
218
|
+
ErrorId.INTERNAL,
|
|
219
|
+
`Failed to find required reference to ${renderInterfaceSpec(referenceSpec)}.`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
if (Array.isArray(result.value)) {
|
|
223
|
+
for (const service of result.value) {
|
|
224
|
+
requiredServices.add(service);
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
requiredServices.add(result.value);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return requiredServices;
|
|
231
|
+
}
|
|
232
|
+
function buildDependencyIndex(packages) {
|
|
233
|
+
const index = /* @__PURE__ */ new Map();
|
|
234
|
+
for (const pkg of packages) {
|
|
235
|
+
const packageName = pkg.name;
|
|
236
|
+
const packageEntry = /* @__PURE__ */ new Map();
|
|
237
|
+
for (const uiReference of pkg.uiReferences) {
|
|
238
|
+
let interfaceEntry = packageEntry.get(uiReference.interfaceName);
|
|
239
|
+
if (!interfaceEntry) {
|
|
240
|
+
interfaceEntry = {
|
|
241
|
+
all: false,
|
|
242
|
+
unqualified: false,
|
|
243
|
+
qualifiers: /* @__PURE__ */ new Set()
|
|
244
|
+
};
|
|
245
|
+
packageEntry.set(uiReference.interfaceName, interfaceEntry);
|
|
246
|
+
}
|
|
247
|
+
if (isAllImplementationsSpec(uiReference)) {
|
|
248
|
+
interfaceEntry.all = true;
|
|
249
|
+
} else if (isSingleImplementationSpec(uiReference)) {
|
|
250
|
+
if (uiReference.qualifier == null) {
|
|
251
|
+
interfaceEntry.unqualified = true;
|
|
252
|
+
} else {
|
|
253
|
+
interfaceEntry.qualifiers.add(uiReference.qualifier);
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
throw new Error(ErrorId.INTERNAL, `Unexpected implementation spec.`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
index.set(packageName, packageEntry);
|
|
260
|
+
}
|
|
261
|
+
return index;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export { ServiceLayer };
|
|
265
|
+
//# sourceMappingURL=ServiceLayer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceLayer.js","sources":["open-pioneer://external-pioneer-packages/@open-pioneer/runtime/service-layer/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;AAAA,MACvB,GAAG,gBAAA,CAAiB,GAAyB,CAAA,CAAC,CAAO,MAAA;AAAA,QACjD,IAAM,EAAA,WAAA;AAAA,QACN,GAAG,CAAA;AAAA,OACL,CAAA,CAAA;AAAA,MACF,GAAG,cAAA;AAAA,KACP,CAAA;AACA,IAAA,MAAM,EAAE,aAAA,EAA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