@open-pioneer/runtime 4.7.0-dev.20260625125130 → 4.7.0-dev.20260713101438
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 +4 -1
- package/app/AppInstance.d.ts +3 -28
- package/app/AppInstance.js +104 -96
- package/app/AppInstance.js.map +1 -1
- package/builtin-services/ApiServiceImpl.d.ts +1 -1
- package/builtin-services/ApiServiceImpl.js +3 -3
- package/builtin-services/ApiServiceImpl.js.map +1 -1
- package/package.json +6 -6
- package/react-integration/PackageContext.d.ts +1 -1
- package/react-integration/PackageContext.js.map +1 -1
- package/react-integration/ReactIntegration.d.ts +1 -9
- package/react-integration/ReactIntegration.js +28 -28
- package/react-integration/ReactIntegration.js.map +1 -1
- package/react-integration/hooks.js +5 -9
- package/react-integration/hooks.js.map +1 -1
- package/service-layer/ServiceLayer.d.ts +1 -20
- package/service-layer/ServiceLayer.js +39 -39
- package/service-layer/ServiceLayer.js.map +1 -1
- package/service-layer/ServiceLookup.d.ts +1 -3
- package/service-layer/ServiceLookup.js +10 -10
- package/service-layer/ServiceLookup.js.map +1 -1
- package/service-layer/ServiceRepr.d.ts +2 -11
- package/service-layer/ServiceRepr.js +68 -50
- package/service-layer/ServiceRepr.js.map +1 -1
- package/service-layer/verifyDependencies.js +33 -33
- package/service-layer/verifyDependencies.js.map +1 -1
|
@@ -10,15 +10,15 @@ import { CustomChakraProvider } from './ChakraProvider.js';
|
|
|
10
10
|
import { PackageContext } from './PackageContext.js';
|
|
11
11
|
|
|
12
12
|
class ReactIntegration {
|
|
13
|
-
rootNode;
|
|
14
|
-
hostNode;
|
|
15
|
-
appRoot;
|
|
16
|
-
reactRoot;
|
|
17
|
-
packageContext;
|
|
18
|
-
locale;
|
|
19
|
-
chakraConfig;
|
|
20
|
-
styles;
|
|
21
|
-
colorMode;
|
|
13
|
+
#rootNode;
|
|
14
|
+
#hostNode;
|
|
15
|
+
#appRoot;
|
|
16
|
+
#reactRoot;
|
|
17
|
+
#packageContext;
|
|
18
|
+
#locale;
|
|
19
|
+
#chakraConfig;
|
|
20
|
+
#styles;
|
|
21
|
+
#colorMode;
|
|
22
22
|
static createForApp(options) {
|
|
23
23
|
const { serviceLayer, packages } = options;
|
|
24
24
|
const packageContext = createPackageContext(serviceLayer, packages);
|
|
@@ -37,35 +37,35 @@ class ReactIntegration {
|
|
|
37
37
|
return new ReactIntegration({ ...options, packageContext });
|
|
38
38
|
}
|
|
39
39
|
constructor(options) {
|
|
40
|
-
this
|
|
41
|
-
this
|
|
42
|
-
this
|
|
43
|
-
this
|
|
44
|
-
this
|
|
45
|
-
this
|
|
46
|
-
this
|
|
47
|
-
this
|
|
48
|
-
this
|
|
40
|
+
this.#rootNode = options.rootNode;
|
|
41
|
+
this.#hostNode = options.hostNode;
|
|
42
|
+
this.#appRoot = options.appRoot;
|
|
43
|
+
this.#reactRoot = createRoot(options.appRoot);
|
|
44
|
+
this.#chakraConfig = options.config;
|
|
45
|
+
this.#packageContext = options.packageContext;
|
|
46
|
+
this.#locale = options.locale;
|
|
47
|
+
this.#styles = options.styles;
|
|
48
|
+
this.#colorMode = options.colorMode;
|
|
49
49
|
}
|
|
50
50
|
render(contentNode) {
|
|
51
|
-
this
|
|
51
|
+
this.#reactRoot.render(
|
|
52
52
|
/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(
|
|
53
53
|
CustomChakraProvider,
|
|
54
54
|
{
|
|
55
|
-
rootNode: this
|
|
56
|
-
hostNode: this
|
|
57
|
-
appRoot: this
|
|
58
|
-
config: this
|
|
59
|
-
locale: this
|
|
60
|
-
styles: this
|
|
61
|
-
colorMode: this
|
|
62
|
-
children: /* @__PURE__ */ jsx(TooltipPropsProvider, { value: { openDelay: 500 }, children: /* @__PURE__ */ jsx(PackageContext.Provider, { value: this
|
|
55
|
+
rootNode: this.#rootNode,
|
|
56
|
+
hostNode: this.#hostNode,
|
|
57
|
+
appRoot: this.#appRoot,
|
|
58
|
+
config: this.#chakraConfig,
|
|
59
|
+
locale: this.#locale,
|
|
60
|
+
styles: this.#styles,
|
|
61
|
+
colorMode: this.#colorMode,
|
|
62
|
+
children: /* @__PURE__ */ jsx(TooltipPropsProvider, { value: { openDelay: 500 }, children: /* @__PURE__ */ jsx(PackageContext.Provider, { value: this.#packageContext, children: contentNode }) })
|
|
63
63
|
}
|
|
64
64
|
) })
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
destroy() {
|
|
68
|
-
this
|
|
68
|
+
this.#reactRoot.unmount();
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
function EmptyComponent() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig, TooltipPropsProvider } from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ReactNode, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"./ChakraProvider\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { ColorModeValue } from \"../api\";\n\nexport interface ReactIntegrationOptions {\n rootNode: RootNode;\n hostNode: HTMLElement;\n appRoot: HTMLDivElement;\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n\n locale: ReadonlyReactive<string>;\n config?: ReadonlyReactive<SystemConfig | undefined>;\n styles: ReadonlyReactive<string>;\n colorMode: ReadonlyReactive<ColorModeValue>;\n}\n\nexport class ReactIntegration {\n private rootNode: RootNode;\n private hostNode: HTMLElement;\n private appRoot: HTMLDivElement;\n private reactRoot: Root;\n private packageContext: PackageContextMethods;\n private locale: ReadonlyReactive<string>;\n private chakraConfig?: ReadonlyReactive<SystemConfig | undefined>;\n private styles: ReadonlyReactive<string>;\n private colorMode: ReadonlyReactive<ColorModeValue>;\n\n static createForApp(options: ReactIntegrationOptions): ReactIntegration {\n const { serviceLayer, packages } = options;\n const packageContext = createPackageContext(serviceLayer, packages);\n return new ReactIntegration({ ...options, packageContext });\n }\n\n static createForErrorScreen(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\">\n ) {\n const throwError = () => {\n throw new Error(ErrorId.INVALID_STATE, \"Hook cannot be used within the error screen.\");\n };\n const packageContext: PackageContextMethods = {\n getIntl: throwError,\n getProperties: throwError,\n getService: throwError,\n getServices: throwError\n };\n return new ReactIntegration({ ...options, packageContext });\n }\n\n private constructor(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\"> & {\n packageContext: PackageContextMethods;\n }\n ) {\n this.rootNode = options.rootNode;\n this.hostNode = options.hostNode;\n this.appRoot = options.appRoot;\n this.reactRoot = createRoot(options.appRoot);\n this.chakraConfig = options.config;\n this.packageContext = options.packageContext;\n this.locale = options.locale;\n this.styles = options.styles;\n this.colorMode = options.colorMode;\n }\n\n render(contentNode: ReactNode) {\n this.reactRoot.render(\n <StrictMode>\n <CustomChakraProvider\n rootNode={this.rootNode}\n hostNode={this.hostNode}\n appRoot={this.appRoot}\n config={this.chakraConfig}\n locale={this.locale}\n styles={this.styles}\n colorMode={this.colorMode}\n >\n {/*TooltipPropsProvider sets shorter `openDelay` for globally all Tooltips (500 ms instead of 1000 ms)*/}\n <TooltipPropsProvider value={{ openDelay: 500 }}>\n <PackageContext.Provider value={this.packageContext}>\n {contentNode}\n </PackageContext.Provider>\n </TooltipPropsProvider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.reactRoot.unmount();\n }\n}\n\nexport function EmptyComponent(): ReactNode {\n return null;\n}\n\nfunction createPackageContext(\n serviceLayer: ServiceLayer,\n packages: Map<string, PackageRepr>\n): PackageContextMethods {\n const getPackage = (packageName: string): PackageRepr => {\n const pkg = packages.get(packageName);\n if (!pkg) {\n throw new Error(\n ErrorId.INTERNAL,\n `Package '${packageName}' was not found in application.`\n );\n }\n return pkg;\n };\n\n const packageContext: PackageContextMethods = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = serviceLayer.getService(packageName, spec);\n if (result.type === \"found\") {\n return result.value.getInstanceOrThrow();\n }\n\n const renderedSpec = renderInterfaceSpec(spec);\n switch (result.type) {\n case \"unimplemented\":\n throw new Error(\n ErrorId.INTERFACE_NOT_FOUND,\n `The UI of package '${packageName}' requested the unimplemented interface ${renderedSpec}.`\n );\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on interface ${renderedSpec}.` +\n ` Add the dependency to the package configuration or remove the usage.`\n );\n case \"ambiguous\": {\n const renderedChoices = renderAmbiguousServiceChoices(result.choices);\n throw new Error(\n ErrorId.AMBIGUOUS_DEPENDENCY,\n `The UI of package '${packageName}' requires the ambiguous interface ${renderedSpec}.` +\n ` Possible choices are: ${renderedChoices}.`\n );\n }\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getServices: (packageName, interfaceName) => {\n const result = serviceLayer.getServices(packageName, interfaceName);\n if (result.type === \"found\") {\n return result.value.map((serviceRepr) => serviceRepr.getInstanceOrThrow());\n }\n\n switch (result.type) {\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on all services implementing interface '${interfaceName}'.` +\n ` Add the dependency (\"all\": true) to the package configuration or remove the usage.`\n );\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getProperties: (packageName) => {\n return getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return getPackage(packageName).intl.value;\n }\n };\n return packageContext;\n}\n\nfunction missingPackageMessage(packageName: string, interfaceName: string) {\n return (\n `Package '${packageName}' was not found in the application's metadata while it attempted to reference the interface '${interfaceName}'. ` +\n `Check that the dependency is declared correctly in the packages that use '${packageName}'.`\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BO,MAAM,gBAAA,CAAiB;AAAA,EAClB,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EAER,OAAO,aAAa,OAAA,EAAoD;AACpE,IAAA,MAAM,EAAE,YAAA,EAAc,QAAA,EAAS,GAAI,OAAA;AACnC,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,YAAA,EAAc,QAAQ,CAAA;AAClE,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEA,OAAO,qBACH,OAAA,EACF;AACE,IAAA,MAAM,aAAa,MAAM;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,aAAA,EAAe,8CAA8C,CAAA;AAAA,IACzF,CAAA;AACA,IAAA,MAAM,cAAA,GAAwC;AAAA,MAC1C,OAAA,EAAS,UAAA;AAAA,MACT,aAAA,EAAe,UAAA;AAAA,MACf,UAAA,EAAY,UAAA;AAAA,MACZ,WAAA,EAAa;AAAA,KACjB;AACA,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEQ,YACJ,OAAA,EAG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A,CAAE,IAAA,CAAK,KAAA;AAAA,IACxC;AAAA,GACJ;AACA,EAAA,OAAO,cAAA;AACX;AAEA,SAAS,qBAAA,CAAsB,aAAqB,aAAA,EAAuB;AACvE,EAAA,OACI,CAAA,SAAA,EAAY,WAAW,CAAA,6FAAA,EAAgG,aAAa,gFACvD,WAAW,CAAA,EAAA,CAAA;AAEhG;;;;"}
|
|
1
|
+
{"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig, TooltipPropsProvider } from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ReactNode, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"./ChakraProvider\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { ColorModeValue } from \"../api\";\n\nexport interface ReactIntegrationOptions {\n rootNode: RootNode;\n hostNode: HTMLElement;\n appRoot: HTMLDivElement;\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n\n locale: ReadonlyReactive<string>;\n config?: ReadonlyReactive<SystemConfig | undefined>;\n styles: ReadonlyReactive<string>;\n colorMode: ReadonlyReactive<ColorModeValue>;\n}\n\nexport class ReactIntegration {\n #rootNode: RootNode;\n #hostNode: HTMLElement;\n #appRoot: HTMLDivElement;\n #reactRoot: Root;\n #packageContext: PackageContextMethods;\n #locale: ReadonlyReactive<string>;\n #chakraConfig?: ReadonlyReactive<SystemConfig | undefined>;\n #styles: ReadonlyReactive<string>;\n #colorMode: ReadonlyReactive<ColorModeValue>;\n\n static createForApp(options: ReactIntegrationOptions): ReactIntegration {\n const { serviceLayer, packages } = options;\n const packageContext = createPackageContext(serviceLayer, packages);\n return new ReactIntegration({ ...options, packageContext });\n }\n\n static createForErrorScreen(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\">\n ) {\n const throwError = () => {\n throw new Error(ErrorId.INVALID_STATE, \"Hook cannot be used within the error screen.\");\n };\n const packageContext: PackageContextMethods = {\n getIntl: throwError,\n getProperties: throwError,\n getService: throwError,\n getServices: throwError\n };\n return new ReactIntegration({ ...options, packageContext });\n }\n\n private constructor(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\"> & {\n packageContext: PackageContextMethods;\n }\n ) {\n this.#rootNode = options.rootNode;\n this.#hostNode = options.hostNode;\n this.#appRoot = options.appRoot;\n this.#reactRoot = createRoot(options.appRoot);\n this.#chakraConfig = options.config;\n this.#packageContext = options.packageContext;\n this.#locale = options.locale;\n this.#styles = options.styles;\n this.#colorMode = options.colorMode;\n }\n\n render(contentNode: ReactNode) {\n this.#reactRoot.render(\n <StrictMode>\n <CustomChakraProvider\n rootNode={this.#rootNode}\n hostNode={this.#hostNode}\n appRoot={this.#appRoot}\n config={this.#chakraConfig}\n locale={this.#locale}\n styles={this.#styles}\n colorMode={this.#colorMode}\n >\n {/*TooltipPropsProvider sets shorter `openDelay` for globally all Tooltips (500 ms instead of 1000 ms)*/}\n <TooltipPropsProvider value={{ openDelay: 500 }}>\n <PackageContext.Provider value={this.#packageContext}>\n {contentNode}\n </PackageContext.Provider>\n </TooltipPropsProvider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.#reactRoot.unmount();\n }\n}\n\nexport function EmptyComponent(): ReactNode {\n return null;\n}\n\nfunction createPackageContext(\n serviceLayer: ServiceLayer,\n packages: Map<string, PackageRepr>\n): PackageContextMethods {\n const getPackage = (packageName: string): PackageRepr => {\n const pkg = packages.get(packageName);\n if (!pkg) {\n throw new Error(\n ErrorId.INTERNAL,\n `Package '${packageName}' was not found in application.`\n );\n }\n return pkg;\n };\n\n const packageContext: PackageContextMethods = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = serviceLayer.getService(packageName, spec);\n if (result.type === \"found\") {\n return result.value.getInstanceOrThrow();\n }\n\n const renderedSpec = renderInterfaceSpec(spec);\n switch (result.type) {\n case \"unimplemented\":\n throw new Error(\n ErrorId.INTERFACE_NOT_FOUND,\n `The UI of package '${packageName}' requested the unimplemented interface ${renderedSpec}.`\n );\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on interface ${renderedSpec}.` +\n ` Add the dependency to the package configuration or remove the usage.`\n );\n case \"ambiguous\": {\n const renderedChoices = renderAmbiguousServiceChoices(result.choices);\n throw new Error(\n ErrorId.AMBIGUOUS_DEPENDENCY,\n `The UI of package '${packageName}' requires the ambiguous interface ${renderedSpec}.` +\n ` Possible choices are: ${renderedChoices}.`\n );\n }\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getServices: (packageName, interfaceName) => {\n const result = serviceLayer.getServices(packageName, interfaceName);\n if (result.type === \"found\") {\n return result.value.map((serviceRepr) => serviceRepr.getInstanceOrThrow());\n }\n\n switch (result.type) {\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on all services implementing interface '${interfaceName}'.` +\n ` Add the dependency (\"all\": true) to the package configuration or remove the usage.`\n );\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getProperties: (packageName) => {\n return getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return getPackage(packageName).intl.value;\n }\n };\n return packageContext;\n}\n\nfunction missingPackageMessage(packageName: string, interfaceName: string) {\n return (\n `Package '${packageName}' was not found in the application's metadata while it attempted to reference the interface '${interfaceName}'. ` +\n `Check that the dependency is declared correctly in the packages that use '${packageName}'.`\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BO,MAAM,gBAAA,CAAiB;AAAA,EAC1B,SAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,aAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EAEA,OAAO,aAAa,OAAA,EAAoD;AACpE,IAAA,MAAM,EAAE,YAAA,EAAc,QAAA,EAAS,GAAI,OAAA;AACnC,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,YAAA,EAAc,QAAQ,CAAA;AAClE,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEA,OAAO,qBACH,OAAA,EACF;AACE,IAAA,MAAM,aAAa,MAAM;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,aAAA,EAAe,8CAA8C,CAAA;AAAA,IACzF,CAAA;AACA,IAAA,MAAM,cAAA,GAAwC;AAAA,MAC1C,OAAA,EAAS,UAAA;AAAA,MACT,aAAA,EAAe,UAAA;AAAA,MACf,UAAA,EAAY,UAAA;AAAA,MACZ,WAAA,EAAa;AAAA,KACjB;AACA,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEQ,YACJ,OAAA,EAGF;AACE,IAAA,IAAA,CAAK,YAAY,OAAA,CAAQ,QAAA;AACzB,IAAA,IAAA,CAAK,YAAY,OAAA,CAAQ,QAAA;AACzB,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,OAAA;AACx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AA,EAAY,WAAW,CAAA,6FAAA,EAAgG,aAAa,gFACvD,WAAW,CAAA,EAAA,CAAA;AAEhG;;;;"}
|
|
@@ -31,15 +31,11 @@ function usePropertiesInternal(packageName) {
|
|
|
31
31
|
function useIntlInternal(packageName) {
|
|
32
32
|
const context = useContext(PackageContext);
|
|
33
33
|
const contextData = checkContext("useIntl", context);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return intl;
|
|
40
|
-
} else {
|
|
41
|
-
return contextData.getIntl(packageName);
|
|
42
|
-
}
|
|
34
|
+
const intl = useReactiveSnapshot(
|
|
35
|
+
() => contextData.getIntl(packageName),
|
|
36
|
+
[packageName, contextData]
|
|
37
|
+
);
|
|
38
|
+
return intl;
|
|
43
39
|
}
|
|
44
40
|
function checkContext(hookName, contextData) {
|
|
45
41
|
if (!contextData) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { useContext, useMemo } from \"react\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API, although they should not be called directly.\n They are imported by code generated during separate package compilation generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\n\n They are also imported by the vite plugin during development and when building an application.\n\n The matching exports are in the neighboring `index.ts`.\n The interfaces of these hooks must remain stable so that already published packages can continue to work in the future.\n\n See also the implementation of @open-pioneer/build-package.\n\n*/\n\nexport interface UseServiceOptions {\n /** An additional qualifier to disambiguate service instances that implement the same interface. */\n qualifier?: string;\n}\n\n/**\n * Returns a service that implements the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServiceInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType;\nexport function useServiceInternal(\n packageName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interfaceName: any,\n options?: UseServiceOptions\n): unknown {\n const context = useContext(PackageContext);\n const service = useMemo(\n () =>\n checkContext(\"useService\", context).getService(\n packageName,\n interfaceName,\n options ?? {}\n ),\n [context, packageName, interfaceName, options]\n );\n return service;\n}\n\n/**\n * Returns all services that implement the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServicesInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType[];\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useServicesInternal(packageName: string, interfaceName: any): unknown[] {\n const context = useContext(PackageContext);\n const services = useMemo(\n () => checkContext(\"useServices\", context).getServices(packageName, interfaceName),\n [context, packageName, interfaceName]\n );\n return services;\n}\n\n/**\n * Returns the properties for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>> {\n const context = useContext(PackageContext);\n return checkContext(\"useProperties\", context).getProperties(packageName);\n}\n\n/**\n * Returns the i18n object for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useIntlInternal(packageName: string): PackageIntl {\n const context = useContext(PackageContext);\n const contextData = checkContext(\"useIntl\", context);\n
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { useContext, useMemo } from \"react\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API, although they should not be called directly.\n They are imported by code generated during separate package compilation generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\n\n They are also imported by the vite plugin during development and when building an application.\n\n The matching exports are in the neighboring `index.ts`.\n The interfaces of these hooks must remain stable so that already published packages can continue to work in the future.\n\n See also the implementation of @open-pioneer/build-package.\n\n*/\n\nexport interface UseServiceOptions {\n /** An additional qualifier to disambiguate service instances that implement the same interface. */\n qualifier?: string;\n}\n\n/**\n * Returns a service that implements the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServiceInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType;\nexport function useServiceInternal(\n packageName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interfaceName: any,\n options?: UseServiceOptions\n): unknown {\n const context = useContext(PackageContext);\n const service = useMemo(\n () =>\n checkContext(\"useService\", context).getService(\n packageName,\n interfaceName,\n options ?? {}\n ),\n [context, packageName, interfaceName, options]\n );\n return service;\n}\n\n/**\n * Returns all services that implement the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServicesInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType[];\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useServicesInternal(packageName: string, interfaceName: any): unknown[] {\n const context = useContext(PackageContext);\n const services = useMemo(\n () => checkContext(\"useServices\", context).getServices(packageName, interfaceName),\n [context, packageName, interfaceName]\n );\n return services;\n}\n\n/**\n * Returns the properties for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>> {\n const context = useContext(PackageContext);\n return checkContext(\"useProperties\", context).getProperties(packageName);\n}\n\n/**\n * Returns the i18n object for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useIntlInternal(packageName: string): PackageIntl {\n const context = useContext(PackageContext);\n const contextData = checkContext(\"useIntl\", context);\n const intl = useReactiveSnapshot(\n () => contextData.getIntl(packageName),\n [packageName, contextData]\n );\n return intl;\n}\n\nfunction checkContext(\n hookName: string,\n contextData: PackageContextMethods | null\n): PackageContextMethods {\n if (!contextData) {\n throw new Error(\n ErrorId.INTERNAL,\n `\"Failed to access package context from '${hookName}': react integration was not set up properly.`\n );\n }\n return contextData;\n}\n"],"names":[],"mappings":";;;;;;AAgDO,SAAS,kBAAA,CACZ,WAAA,EAEA,aAAA,EACA,OAAA,EACO;AACP,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,OAAA,GAAU,OAAA;AAAA,IACZ,MACI,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA,CAAE,UAAA;AAAA,MAChC,WAAA;AAAA,MACA,aAAA;AAAA,MACA,WAAW;AAAC,KAChB;AAAA,IACJ,CAAC,OAAA,EAAS,WAAA,EAAa,aAAA,EAAe,OAAO;AAAA,GACjD;AACA,EAAA,OAAO,OAAA;AACX;AAiBO,SAAS,mBAAA,CAAoB,aAAqB,aAAA,EAA+B;AACpF,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,QAAA,GAAW,OAAA;AAAA,IACb,MAAM,YAAA,CAAa,aAAA,EAAe,OAAO,CAAA,CAAE,WAAA,CAAY,aAAa,aAAa,CAAA;AAAA,IACjF,CAAC,OAAA,EAAS,WAAA,EAAa,aAAa;AAAA,GACxC;AACA,EAAA,OAAO,QAAA;AACX;AAUO,SAAS,sBAAsB,WAAA,EAAwD;AAC1F,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,OAAO,YAAA,CAAa,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,WAAW,CAAA;AAC3E;AAUO,SAAS,gBAAgB,WAAA,EAAkC;AAC9D,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,YAAA,CAAa,SAAA,EAAW,OAAO,CAAA;AACnD,EAAA,MAAM,IAAA,GAAO,mBAAA;AAAA,IACT,MAAM,WAAA,CAAY,OAAA,CAAQ,WAAW,CAAA;AAAA,IACrC,CAAC,aAAa,WAAW;AAAA,GAC7B;AACA,EAAA,OAAO,IAAA;AACX;AAEA,SAAS,YAAA,CACL,UACA,WAAA,EACqB;AACrB,EAAA,IAAI,CAAC,WAAA,EAAa;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,2CAA2C,QAAQ,CAAA,6CAAA;AAAA,KACvD;AAAA,EACJ;AACA,EAAA,OAAO,WAAA;AACX;;;;"}
|
|
@@ -15,12 +15,7 @@ export interface UnknownPackage {
|
|
|
15
15
|
type: "unknown-package";
|
|
16
16
|
}
|
|
17
17
|
export declare class ServiceLayer {
|
|
18
|
-
private
|
|
19
|
-
private requiredServices;
|
|
20
|
-
private serviceLookup;
|
|
21
|
-
private serviceDependencies;
|
|
22
|
-
private declaredDependencies;
|
|
23
|
-
private state;
|
|
18
|
+
#private;
|
|
24
19
|
/**
|
|
25
20
|
* Constructs a new service layer instance.
|
|
26
21
|
* Requires the application's set of packages (from which services are taken)
|
|
@@ -54,18 +49,4 @@ export declare class ServiceLayer {
|
|
|
54
49
|
* @throws if the service layer is not in 'started'.
|
|
55
50
|
*/
|
|
56
51
|
getServices(packageName: string, interfaceName: string): ServicesLookupResult | UndeclaredDependency | UnknownPackage;
|
|
57
|
-
/**
|
|
58
|
-
* Initializes the given service and its dependencies.
|
|
59
|
-
* Dependencies are initialized before the service that requires them.
|
|
60
|
-
*/
|
|
61
|
-
private createService;
|
|
62
|
-
/**
|
|
63
|
-
* Destroys the given service and its dependencies.
|
|
64
|
-
* The dependencies are destroyed after the service.
|
|
65
|
-
*/
|
|
66
|
-
private destroyService;
|
|
67
|
-
/** Undefined -> everything is okay */
|
|
68
|
-
private checkDependency;
|
|
69
|
-
private getReference;
|
|
70
|
-
private getServiceDeps;
|
|
71
52
|
}
|
|
@@ -10,15 +10,15 @@ const UNDECLARED_DEPENDENCY = { type: "undeclared" };
|
|
|
10
10
|
const UNKNOWN_PACKAGE = { type: "unknown-package" };
|
|
11
11
|
class ServiceLayer {
|
|
12
12
|
// All services in the application.
|
|
13
|
-
allServices;
|
|
13
|
+
#allServices;
|
|
14
14
|
// Set of required services. These services and their dependencies will be started.
|
|
15
|
-
requiredServices;
|
|
16
|
-
serviceLookup;
|
|
15
|
+
#requiredServices;
|
|
16
|
+
#serviceLookup;
|
|
17
17
|
// Service id --> Service dependencies
|
|
18
|
-
serviceDependencies;
|
|
18
|
+
#serviceDependencies;
|
|
19
19
|
// Package name --> Interface name --> Declarations
|
|
20
|
-
declaredDependencies;
|
|
21
|
-
state = "not-started";
|
|
20
|
+
#declaredDependencies;
|
|
21
|
+
#state = "not-started";
|
|
22
22
|
/**
|
|
23
23
|
* Constructs a new service layer instance.
|
|
24
24
|
* Requires the application's set of packages (from which services are taken)
|
|
@@ -48,28 +48,28 @@ class ServiceLayer {
|
|
|
48
48
|
services: allServices,
|
|
49
49
|
requiredReferences
|
|
50
50
|
});
|
|
51
|
-
this
|
|
52
|
-
this
|
|
53
|
-
this
|
|
54
|
-
this
|
|
55
|
-
this
|
|
51
|
+
this.#allServices = allServices;
|
|
52
|
+
this.#requiredServices = getRequiredServices(requiredReferences, serviceLookup);
|
|
53
|
+
this.#serviceLookup = serviceLookup;
|
|
54
|
+
this.#serviceDependencies = serviceDependencies;
|
|
55
|
+
this.#declaredDependencies = buildDependencyIndex(packages);
|
|
56
56
|
}
|
|
57
57
|
destroy() {
|
|
58
|
-
for (const service of this
|
|
59
|
-
this
|
|
58
|
+
for (const service of this.#requiredServices) {
|
|
59
|
+
this.#destroyService(service);
|
|
60
60
|
}
|
|
61
|
-
this
|
|
61
|
+
this.#state = "destroyed";
|
|
62
62
|
}
|
|
63
63
|
start() {
|
|
64
|
-
if (this
|
|
64
|
+
if (this.#state !== "not-started") {
|
|
65
65
|
throw new Error(ErrorId.INTERNAL, "Service layer was already started.");
|
|
66
66
|
}
|
|
67
|
-
for (const service of this
|
|
68
|
-
this
|
|
67
|
+
for (const service of this.#requiredServices) {
|
|
68
|
+
this.#createService(service);
|
|
69
69
|
}
|
|
70
|
-
this
|
|
70
|
+
this.#state = "started";
|
|
71
71
|
if (import.meta.env.DEV) {
|
|
72
|
-
const unneededServices = this
|
|
72
|
+
const unneededServices = this.#allServices.filter(
|
|
73
73
|
(service) => service.packageName !== RUNTIME_PACKAGE_NAME && service.state === "not-constructed"
|
|
74
74
|
).map((service) => `'${service.id}'`);
|
|
75
75
|
if (unneededServices.length) {
|
|
@@ -91,16 +91,16 @@ class ServiceLayer {
|
|
|
91
91
|
* @throws if the service layer is not in 'started' state or if no service implements the interface.
|
|
92
92
|
*/
|
|
93
93
|
getService(packageName, spec, options) {
|
|
94
|
-
if (this
|
|
94
|
+
if (this.#state !== "started") {
|
|
95
95
|
throw new Error(ErrorId.INTERNAL, "Service layer is not started.");
|
|
96
96
|
}
|
|
97
97
|
if (!options?.ignoreDeclarationCheck) {
|
|
98
|
-
const checkError = this
|
|
98
|
+
const checkError = this.#checkDependency(packageName, spec);
|
|
99
99
|
if (checkError) {
|
|
100
100
|
return checkError;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
return this
|
|
103
|
+
return this.#serviceLookup.lookupOne(spec);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Returns all services implementing the given interface.
|
|
@@ -112,20 +112,20 @@ class ServiceLayer {
|
|
|
112
112
|
* @throws if the service layer is not in 'started'.
|
|
113
113
|
*/
|
|
114
114
|
getServices(packageName, interfaceName) {
|
|
115
|
-
if (this
|
|
115
|
+
if (this.#state !== "started") {
|
|
116
116
|
throw new Error(ErrorId.INTERNAL, "Service layer is not started.");
|
|
117
117
|
}
|
|
118
|
-
const checkError = this
|
|
118
|
+
const checkError = this.#checkDependency(packageName, { interfaceName, all: true });
|
|
119
119
|
if (checkError) {
|
|
120
120
|
return checkError;
|
|
121
121
|
}
|
|
122
|
-
return this
|
|
122
|
+
return this.#serviceLookup.lookupAll(interfaceName);
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* Initializes the given service and its dependencies.
|
|
126
126
|
* Dependencies are initialized before the service that requires them.
|
|
127
127
|
*/
|
|
128
|
-
createService(service) {
|
|
128
|
+
#createService(service) {
|
|
129
129
|
if (service.state === "constructed") {
|
|
130
130
|
const instance = service.getInstanceOrThrow();
|
|
131
131
|
service.addRef();
|
|
@@ -140,8 +140,8 @@ class ServiceLayer {
|
|
|
140
140
|
const references = {};
|
|
141
141
|
const referencesMeta = {};
|
|
142
142
|
service.beforeCreate();
|
|
143
|
-
for (const [referenceName, serviceDeps] of Object.entries(this
|
|
144
|
-
const [referenceValue, referenceMeta] = this
|
|
143
|
+
for (const [referenceName, serviceDeps] of Object.entries(this.#getServiceDeps(service))) {
|
|
144
|
+
const [referenceValue, referenceMeta] = this.#getReference(serviceDeps);
|
|
145
145
|
references[referenceName] = referenceValue;
|
|
146
146
|
referencesMeta[referenceName] = referenceMeta;
|
|
147
147
|
}
|
|
@@ -152,27 +152,27 @@ class ServiceLayer {
|
|
|
152
152
|
* Destroys the given service and its dependencies.
|
|
153
153
|
* The dependencies are destroyed after the service.
|
|
154
154
|
*/
|
|
155
|
-
destroyService(service) {
|
|
155
|
+
#destroyService(service) {
|
|
156
156
|
if (service.state === "destroyed") {
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
159
|
if (service.removeRef() <= 0) {
|
|
160
160
|
LOG.debug(`Destroying service '${service.id}'`);
|
|
161
161
|
service.destroy();
|
|
162
|
-
for (const serviceDeps of Object.values(this
|
|
162
|
+
for (const serviceDeps of Object.values(this.#getServiceDeps(service))) {
|
|
163
163
|
if (Array.isArray(serviceDeps)) {
|
|
164
164
|
for (const dep of serviceDeps) {
|
|
165
|
-
this
|
|
165
|
+
this.#destroyService(dep);
|
|
166
166
|
}
|
|
167
167
|
} else {
|
|
168
|
-
this
|
|
168
|
+
this.#destroyService(serviceDeps);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
/** Undefined -> everything is okay */
|
|
174
|
-
checkDependency(packageName, spec) {
|
|
175
|
-
const packageEntry = this
|
|
174
|
+
#checkDependency(packageName, spec) {
|
|
175
|
+
const packageEntry = this.#declaredDependencies.get(packageName);
|
|
176
176
|
if (!packageEntry) {
|
|
177
177
|
return UNKNOWN_PACKAGE;
|
|
178
178
|
}
|
|
@@ -189,25 +189,25 @@ class ServiceLayer {
|
|
|
189
189
|
return interfaceEntry.all ? void 0 : UNDECLARED_DEPENDENCY;
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
getReference(ref) {
|
|
192
|
+
#getReference(ref) {
|
|
193
193
|
if (Array.isArray(ref)) {
|
|
194
194
|
const referenceValues = [];
|
|
195
195
|
const referenceMeta2 = [];
|
|
196
196
|
for (const d of ref) {
|
|
197
|
-
const [value, meta] = this
|
|
197
|
+
const [value, meta] = this.#getReference(d);
|
|
198
198
|
referenceValues.push(value);
|
|
199
199
|
referenceMeta2.push(meta);
|
|
200
200
|
}
|
|
201
201
|
return [referenceValues, referenceMeta2];
|
|
202
202
|
}
|
|
203
|
-
const referenceValue = this
|
|
203
|
+
const referenceValue = this.#createService(ref);
|
|
204
204
|
const referenceMeta = {
|
|
205
205
|
serviceId: ref.id
|
|
206
206
|
};
|
|
207
207
|
return [referenceValue, referenceMeta];
|
|
208
208
|
}
|
|
209
|
-
getServiceDeps(service) {
|
|
210
|
-
const dependencies = this
|
|
209
|
+
#getServiceDeps(service) {
|
|
210
|
+
const dependencies = this.#serviceDependencies.get(service.id);
|
|
211
211
|
if (!dependencies) {
|
|
212
212
|
throw new Error(
|
|
213
213
|
ErrorId.INTERNAL,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceLayer.js","sources":["ServiceLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ReferenceMeta } from \"../Service\";\nimport { RUNTIME_PACKAGE_NAME } from \"../builtin-services\";\nimport { ErrorId } from \"../errors\";\nimport {\n InterfaceSpec,\n isAllImplementationsSpec,\n isSingleImplementationSpec,\n ReferenceSpec,\n renderInterfaceSpec\n} from \"./InterfaceSpec\";\nimport { PackageRepr } from \"./PackageRepr\";\nimport { ReadonlyServiceLookup, ServiceLookupResult, ServicesLookupResult } from \"./ServiceLookup\";\nimport { ServiceRepr } from \"./ServiceRepr\";\nimport {\n ComputedServiceDependencies,\n FrameworkDependency,\n UIDependency,\n verifyDependencies\n} from \"./verifyDependencies\";\n\nconst LOG = createLogger(sourceId);\n\nexport type DynamicLookupResult = ServiceLookupResult | UndeclaredDependency;\n\n/**\n * Returned when a dependency is not declared in the package's metadata.\n */\nexport interface UndeclaredDependency {\n type: \"undeclared\";\n}\n\n/**\n * Returned when a package is not found in the application's metadata.\n */\nexport interface UnknownPackage {\n type: \"unknown-package\";\n}\n\nconst UNDECLARED_DEPENDENCY = { type: \"undeclared\" } satisfies UndeclaredDependency;\nconst UNKNOWN_PACKAGE = { type: \"unknown-package\" } satisfies UnknownPackage;\n\ninterface DependencyDeclarations {\n all: boolean;\n unqualified: boolean;\n qualifiers: Set<string>;\n}\n\nexport class ServiceLayer {\n // All services in the application.\n private allServices: ServiceRepr[];\n\n // Set of required services. These services and their dependencies will be started.\n private requiredServices: Set<ServiceRepr>;\n\n private serviceLookup: ReadonlyServiceLookup;\n\n // Service id --> Service dependencies\n private serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n // Package name --> Interface name --> Declarations\n private declaredDependencies;\n private state: \"not-started\" | \"started\" | \"destroyed\" = \"not-started\";\n\n /**\n * Constructs a new service layer instance.\n * Requires the application's set of packages (from which services are taken)\n * and an optional set of forced references (interfaces whose implementing services will be started unconditionally).\n *\n * In its current form, the service layer will start only forced references and references needed by the UI (and their dependencies).\n */\n constructor(packages: readonly PackageRepr[], forcedReferences: ReferenceSpec[] = []) {\n const allServices = packages.map((pkg) => pkg.services).flat();\n const uiDependencies = packages\n .map((pkg) =>\n pkg.uiReferences.map<UIDependency>((dep) => {\n return {\n type: \"ui\",\n packageName: pkg.name,\n ...dep\n };\n })\n )\n .flat();\n const requiredReferences = [\n ...forcedReferences.map<FrameworkDependency>((r) => ({\n type: \"framework\",\n ...r\n })),\n ...uiDependencies\n ];\n const { serviceLookup, serviceDependencies } = verifyDependencies({\n services: allServices,\n requiredReferences: requiredReferences\n });\n\n this.allServices = allServices;\n this.requiredServices = getRequiredServices(requiredReferences, serviceLookup);\n this.serviceLookup = serviceLookup;\n this.serviceDependencies = serviceDependencies;\n this.declaredDependencies = buildDependencyIndex(packages);\n }\n\n destroy() {\n for (const service of this.requiredServices) {\n this.destroyService(service);\n }\n this.state = \"destroyed\";\n }\n\n start() {\n if (this.state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer was already started.\");\n }\n\n for (const service of this.requiredServices) {\n this.createService(service);\n }\n this.state = \"started\";\n\n // Give warnings for unneeded services during development.\n if (import.meta.env.DEV) {\n const unneededServices = this.allServices\n .filter(\n (service) =>\n service.packageName !== RUNTIME_PACKAGE_NAME &&\n service.state === \"not-constructed\"\n )\n .map((service) => `'${service.id}'`);\n if (unneededServices.length) {\n const services = unneededServices.join(\", \");\n LOG.warn(\n `The following services are contained in the application but were not started: ${services}.`\n );\n }\n }\n }\n\n /**\n * Returns a service implementing the given interface.\n * Checks that the given package actually declared a dependency on that interface\n * to enforce coding guidelines.\n *\n * @param packageName the name of the package requesting the import\n * @param spec the interface specifier\n * @param options advanced options to customize lookup\n * @throws if the service layer is not in 'started' state or if no service implements the interface.\n */\n getService(\n packageName: string,\n spec: InterfaceSpec,\n options?: { ignoreDeclarationCheck?: boolean }\n ): ServiceLookupResult | UndeclaredDependency | UnknownPackage {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n if (!options?.ignoreDeclarationCheck) {\n const checkError = this.checkDependency(packageName, spec);\n if (checkError) {\n return checkError;\n }\n }\n\n return this.serviceLookup.lookupOne(spec);\n }\n\n /**\n * Returns all services implementing the given interface.\n * Requires that the dependency on all implementations has been declared in the package.\n *\n * @param packageName the name of the package requesting the import\n * @param interfaceName the interface name\n *\n * @throws if the service layer is not in 'started'.\n */\n getServices(\n packageName: string,\n interfaceName: string\n ): ServicesLookupResult | UndeclaredDependency | UnknownPackage {\n if (this.state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n const checkError = this.checkDependency(packageName, { interfaceName, all: true });\n if (checkError) {\n return checkError;\n }\n return this.serviceLookup.lookupAll(interfaceName);\n }\n\n /**\n * Initializes the given service and its dependencies.\n * Dependencies are initialized before the service that requires them.\n */\n private createService(service: ServiceRepr) {\n if (service.state === \"constructed\") {\n const instance = service.getInstanceOrThrow();\n service.addRef();\n return instance;\n }\n if (service.state === \"constructing\") {\n throw new Error(ErrorId.INTERNAL, \"Cycle during service construction.\");\n }\n if (service.state !== \"not-constructed\") {\n throw new Error(ErrorId.INTERNAL, \"Invalid service state.\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const references: Record<string, any> = {};\n const referencesMeta: Record<string, ReferenceMeta | ReferenceMeta[]> = {};\n\n // Sets state to 'constructing' to detect cycles\n service.beforeCreate();\n\n // Initialize dependencies recursively before creating the current service.\n for (const [referenceName, serviceDeps] of Object.entries(this.getServiceDeps(service))) {\n const [referenceValue, referenceMeta] = this.getReference(serviceDeps);\n references[referenceName] = referenceValue;\n referencesMeta[referenceName] = referenceMeta;\n }\n\n // Sets state to 'constructed' to finish the state transition, useCount is 1.\n LOG.debug(`Creating service '${service.id}'.`);\n return service.create({ references, referencesMeta });\n }\n\n /**\n * Destroys the given service and its dependencies.\n * The dependencies are destroyed after the service.\n */\n private destroyService(service: ServiceRepr) {\n if (service.state === \"destroyed\") {\n return;\n }\n\n // Destroy the service before its dependencies (reverse order\n // compared to construction).\n if (service.removeRef() <= 0) {\n LOG.debug(`Destroying service '${service.id}'`);\n service.destroy();\n\n for (const serviceDeps of Object.values(this.getServiceDeps(service))) {\n if (Array.isArray(serviceDeps)) {\n for (const dep of serviceDeps) {\n this.destroyService(dep);\n }\n } else {\n this.destroyService(serviceDeps);\n }\n }\n }\n }\n\n /** Undefined -> everything is okay */\n private checkDependency(\n packageName: string,\n spec: ReferenceSpec\n ): UnknownPackage | UndeclaredDependency | undefined {\n const packageEntry = this.declaredDependencies.get(packageName);\n if (!packageEntry) {\n return UNKNOWN_PACKAGE;\n }\n\n const interfaceEntry = packageEntry.get(spec.interfaceName);\n if (!interfaceEntry) {\n return UNDECLARED_DEPENDENCY;\n }\n\n if (isSingleImplementationSpec(spec)) {\n if (spec.qualifier == null) {\n return interfaceEntry.unqualified ? undefined : UNDECLARED_DEPENDENCY;\n }\n return interfaceEntry.qualifiers.has(spec.qualifier)\n ? undefined\n : UNDECLARED_DEPENDENCY;\n } else {\n return interfaceEntry.all ? undefined : UNDECLARED_DEPENDENCY;\n }\n }\n\n private getReference(ref: ServiceRepr): [unknown, ReferenceMeta];\n private getReference(ref: ServiceRepr[]): [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]];\n private getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]] {\n if (Array.isArray(ref)) {\n const referenceValues: unknown[] = [];\n const referenceMeta: ReferenceMeta[] = [];\n for (const d of ref) {\n const [value, meta] = this.getReference(d);\n referenceValues.push(value);\n referenceMeta.push(meta);\n }\n return [referenceValues, referenceMeta];\n }\n\n const referenceValue = this.createService(ref);\n const referenceMeta: ReferenceMeta = {\n serviceId: ref.id\n };\n return [referenceValue, referenceMeta];\n }\n\n private getServiceDeps(service: ServiceRepr) {\n const dependencies = this.serviceDependencies.get(service.id);\n if (!dependencies) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find precomputed service dependencies for '${service.id}'.`\n );\n }\n return dependencies;\n }\n}\n\nfunction getRequiredServices(\n requiredReferences: readonly ReferenceSpec[],\n serviceLookup: ReadonlyServiceLookup\n): Set<ServiceRepr> {\n const requiredServices = new Set<ServiceRepr>();\n for (const referenceSpec of requiredReferences) {\n const result = serviceLookup.lookup(referenceSpec);\n if (result.type !== \"found\") {\n // Should be caught by verifier\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find required reference to ${renderInterfaceSpec(referenceSpec)}.`\n );\n }\n if (Array.isArray(result.value)) {\n for (const service of result.value) {\n requiredServices.add(service);\n }\n } else {\n requiredServices.add(result.value);\n }\n }\n return requiredServices;\n}\n\nfunction buildDependencyIndex(packages: readonly PackageRepr[]) {\n // Register declared UI dependencies.\n // This is needed as a lookup structure to that dynamic service lookups\n // can be validated at runtime.\n const index = new Map<string, Map<string, DependencyDeclarations>>();\n for (const pkg of packages) {\n const packageName = pkg.name;\n const packageEntry = new Map<string, DependencyDeclarations>();\n for (const uiReference of pkg.uiReferences) {\n let interfaceEntry = packageEntry.get(uiReference.interfaceName);\n if (!interfaceEntry) {\n interfaceEntry = {\n all: false,\n unqualified: false,\n qualifiers: new Set<string>()\n };\n packageEntry.set(uiReference.interfaceName, interfaceEntry);\n }\n\n if (isAllImplementationsSpec(uiReference)) {\n interfaceEntry.all = true;\n } else if (isSingleImplementationSpec(uiReference)) {\n if (uiReference.qualifier == null) {\n interfaceEntry.unqualified = true;\n } else {\n interfaceEntry.qualifiers.add(uiReference.qualifier);\n }\n } else {\n throw new Error(ErrorId.INTERNAL, `Unexpected implementation spec.`);\n }\n }\n index.set(packageName, packageEntry);\n }\n return index;\n}\n"],"names":["referenceMeta"],"mappings":";;;;;;;AAwBA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAkBjC,MAAM,qBAAA,GAAwB,EAAE,IAAA,EAAM,YAAA,EAAa;AACnD,MAAM,eAAA,GAAkB,EAAE,IAAA,EAAM,iBAAA,EAAkB;AAQ3C,MAAM,YAAA,CAAa;AAAA;AAAA,EAEd,WAAA;AAAA;AAAA,EAGA,gBAAA;AAAA,EAEA,aAAA;AAAA;AAAA,EAGA,mBAAA;AAAA;AAAA,EAGA,oBAAA;AAAA,EACA,KAAA,GAAiD,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASzD,WAAA,CAAY,QAAA,EAAkC,gBAAA,GAAoC,EAAC,EAAG;AAClF,IAAA,MAAM,WAAA,GAAc,SAAS,GAAA,CAAI,CAAC,QAAQ,GAAA,CAAI,QAAQ,EAAE,IAAA,EAAK;AAC7D,IAAA,MAAM,iBAAiB,QAAA,CAClB,GAAA;AAAA,MAAI,CAAC,GAAA,KACF,GAAA,CAAI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AAiB,YAAA,CAAa,GAAA,CAAI,WAAA,CAAY,aAAa,CAAA;AAC/D,MAAA,IAAI,CAAC,cAAA,EAAgB;AACjB,QAAA,cAAA,GAAiB;AAAA,UACb,GAAA,EAAK,KAAA;AAAA,UACL,WAAA,EAAa,KAAA;AAAA,UACb,UAAA,sBAAgB,GAAA;AAAY,SAChC;AACA,QAAA,YAAA,CAAa,GAAA,CAAI,WAAA,CAAY,aAAA,EAAe,cAAc,CAAA;AAAA,MAC9D;AAEA,MAAA,IAAI,wBAAA,CAAyB,WAAW,CAAA,EAAG;AACvC,QAAA,cAAA,CAAe,GAAA,GAAM,IAAA;AAAA,MACzB,CAAA,MAAA,IAAW,0BAAA,CAA2B,WAAW,CAAA,EAAG;AAChD,QAAA,IAAI,WAAA,CAAY,aAAa,IAAA,EAAM;AAC/B,UAAA,cAAA,CAAe,WAAA,GAAc,IAAA;AAAA,QACjC,CAAA,MAAO;AACH,UAAA,cAAA,CAAe,UAAA,CAAW,GAAA,CAAI,WAAA,CAAY,SAAS,CAAA;AAAA,QACvD;AAAA,MACJ,CAAA,MAAO;AACH,QAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,EAAU,CAAA,+BAAA,CAAiC,CAAA;AAAA,MACvE;AAAA,IACJ;AACA,IAAA,KAAA,CAAM,GAAA,CAAI,aAAa,YAAY,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,KAAA;AACX;;;;"}
|
|
1
|
+
{"version":3,"file":"ServiceLayer.js","sources":["ServiceLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ReferenceMeta } from \"../Service\";\nimport { RUNTIME_PACKAGE_NAME } from \"../builtin-services\";\nimport { ErrorId } from \"../errors\";\nimport {\n InterfaceSpec,\n isAllImplementationsSpec,\n isSingleImplementationSpec,\n ReferenceSpec,\n renderInterfaceSpec\n} from \"./InterfaceSpec\";\nimport { PackageRepr } from \"./PackageRepr\";\nimport { ReadonlyServiceLookup, ServiceLookupResult, ServicesLookupResult } from \"./ServiceLookup\";\nimport { ServiceRepr } from \"./ServiceRepr\";\nimport {\n ComputedServiceDependencies,\n FrameworkDependency,\n UIDependency,\n verifyDependencies\n} from \"./verifyDependencies\";\n\nconst LOG = createLogger(sourceId);\n\nexport type DynamicLookupResult = ServiceLookupResult | UndeclaredDependency;\n\n/**\n * Returned when a dependency is not declared in the package's metadata.\n */\nexport interface UndeclaredDependency {\n type: \"undeclared\";\n}\n\n/**\n * Returned when a package is not found in the application's metadata.\n */\nexport interface UnknownPackage {\n type: \"unknown-package\";\n}\n\nconst UNDECLARED_DEPENDENCY = { type: \"undeclared\" } satisfies UndeclaredDependency;\nconst UNKNOWN_PACKAGE = { type: \"unknown-package\" } satisfies UnknownPackage;\n\ninterface DependencyDeclarations {\n all: boolean;\n unqualified: boolean;\n qualifiers: Set<string>;\n}\n\nexport class ServiceLayer {\n // All services in the application.\n #allServices: ServiceRepr[];\n\n // Set of required services. These services and their dependencies will be started.\n #requiredServices: Set<ServiceRepr>;\n\n #serviceLookup: ReadonlyServiceLookup;\n\n // Service id --> Service dependencies\n #serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n // Package name --> Interface name --> Declarations\n #declaredDependencies;\n #state: \"not-started\" | \"started\" | \"destroyed\" = \"not-started\";\n\n /**\n * Constructs a new service layer instance.\n * Requires the application's set of packages (from which services are taken)\n * and an optional set of forced references (interfaces whose implementing services will be started unconditionally).\n *\n * In its current form, the service layer will start only forced references and references needed by the UI (and their dependencies).\n */\n constructor(packages: readonly PackageRepr[], forcedReferences: ReferenceSpec[] = []) {\n const allServices = packages.map((pkg) => pkg.services).flat();\n const uiDependencies = packages\n .map((pkg) =>\n pkg.uiReferences.map<UIDependency>((dep) => {\n return {\n type: \"ui\",\n packageName: pkg.name,\n ...dep\n };\n })\n )\n .flat();\n const requiredReferences = [\n ...forcedReferences.map<FrameworkDependency>((r) => ({\n type: \"framework\",\n ...r\n })),\n ...uiDependencies\n ];\n const { serviceLookup, serviceDependencies } = verifyDependencies({\n services: allServices,\n requiredReferences: requiredReferences\n });\n\n this.#allServices = allServices;\n this.#requiredServices = getRequiredServices(requiredReferences, serviceLookup);\n this.#serviceLookup = serviceLookup;\n this.#serviceDependencies = serviceDependencies;\n this.#declaredDependencies = buildDependencyIndex(packages);\n }\n\n destroy() {\n for (const service of this.#requiredServices) {\n this.#destroyService(service);\n }\n this.#state = \"destroyed\";\n }\n\n start() {\n if (this.#state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer was already started.\");\n }\n\n for (const service of this.#requiredServices) {\n this.#createService(service);\n }\n this.#state = \"started\";\n\n // Give warnings for unneeded services during development.\n if (import.meta.env.DEV) {\n const unneededServices = this.#allServices\n .filter(\n (service) =>\n service.packageName !== RUNTIME_PACKAGE_NAME &&\n service.state === \"not-constructed\"\n )\n .map((service) => `'${service.id}'`);\n if (unneededServices.length) {\n const services = unneededServices.join(\", \");\n LOG.warn(\n `The following services are contained in the application but were not started: ${services}.`\n );\n }\n }\n }\n\n /**\n * Returns a service implementing the given interface.\n * Checks that the given package actually declared a dependency on that interface\n * to enforce coding guidelines.\n *\n * @param packageName the name of the package requesting the import\n * @param spec the interface specifier\n * @param options advanced options to customize lookup\n * @throws if the service layer is not in 'started' state or if no service implements the interface.\n */\n getService(\n packageName: string,\n spec: InterfaceSpec,\n options?: { ignoreDeclarationCheck?: boolean }\n ): ServiceLookupResult | UndeclaredDependency | UnknownPackage {\n if (this.#state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n if (!options?.ignoreDeclarationCheck) {\n const checkError = this.#checkDependency(packageName, spec);\n if (checkError) {\n return checkError;\n }\n }\n\n return this.#serviceLookup.lookupOne(spec);\n }\n\n /**\n * Returns all services implementing the given interface.\n * Requires that the dependency on all implementations has been declared in the package.\n *\n * @param packageName the name of the package requesting the import\n * @param interfaceName the interface name\n *\n * @throws if the service layer is not in 'started'.\n */\n getServices(\n packageName: string,\n interfaceName: string\n ): ServicesLookupResult | UndeclaredDependency | UnknownPackage {\n if (this.#state !== \"started\") {\n throw new Error(ErrorId.INTERNAL, \"Service layer is not started.\");\n }\n\n const checkError = this.#checkDependency(packageName, { interfaceName, all: true });\n if (checkError) {\n return checkError;\n }\n return this.#serviceLookup.lookupAll(interfaceName);\n }\n\n /**\n * Initializes the given service and its dependencies.\n * Dependencies are initialized before the service that requires them.\n */\n #createService(service: ServiceRepr) {\n if (service.state === \"constructed\") {\n const instance = service.getInstanceOrThrow();\n service.addRef();\n return instance;\n }\n if (service.state === \"constructing\") {\n throw new Error(ErrorId.INTERNAL, \"Cycle during service construction.\");\n }\n if (service.state !== \"not-constructed\") {\n throw new Error(ErrorId.INTERNAL, \"Invalid service state.\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const references: Record<string, any> = {};\n const referencesMeta: Record<string, ReferenceMeta | ReferenceMeta[]> = {};\n\n // Sets state to 'constructing' to detect cycles\n service.beforeCreate();\n\n // Initialize dependencies recursively before creating the current service.\n for (const [referenceName, serviceDeps] of Object.entries(this.#getServiceDeps(service))) {\n const [referenceValue, referenceMeta] = this.#getReference(serviceDeps);\n references[referenceName] = referenceValue;\n referencesMeta[referenceName] = referenceMeta;\n }\n\n // Sets state to 'constructed' to finish the state transition, useCount is 1.\n LOG.debug(`Creating service '${service.id}'.`);\n return service.create({ references, referencesMeta });\n }\n\n /**\n * Destroys the given service and its dependencies.\n * The dependencies are destroyed after the service.\n */\n #destroyService(service: ServiceRepr) {\n if (service.state === \"destroyed\") {\n return;\n }\n\n // Destroy the service before its dependencies (reverse order\n // compared to construction).\n if (service.removeRef() <= 0) {\n LOG.debug(`Destroying service '${service.id}'`);\n service.destroy();\n\n for (const serviceDeps of Object.values(this.#getServiceDeps(service))) {\n if (Array.isArray(serviceDeps)) {\n for (const dep of serviceDeps) {\n this.#destroyService(dep);\n }\n } else {\n this.#destroyService(serviceDeps);\n }\n }\n }\n }\n\n /** Undefined -> everything is okay */\n #checkDependency(\n packageName: string,\n spec: ReferenceSpec\n ): UnknownPackage | UndeclaredDependency | undefined {\n const packageEntry = this.#declaredDependencies.get(packageName);\n if (!packageEntry) {\n return UNKNOWN_PACKAGE;\n }\n\n const interfaceEntry = packageEntry.get(spec.interfaceName);\n if (!interfaceEntry) {\n return UNDECLARED_DEPENDENCY;\n }\n\n if (isSingleImplementationSpec(spec)) {\n if (spec.qualifier == null) {\n return interfaceEntry.unqualified ? undefined : UNDECLARED_DEPENDENCY;\n }\n return interfaceEntry.qualifiers.has(spec.qualifier)\n ? undefined\n : UNDECLARED_DEPENDENCY;\n } else {\n return interfaceEntry.all ? undefined : UNDECLARED_DEPENDENCY;\n }\n }\n\n #getReference(ref: ServiceRepr): [unknown, ReferenceMeta];\n #getReference(ref: ServiceRepr[]): [unknown[], ReferenceMeta[]];\n #getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]];\n #getReference(\n ref: ServiceRepr | ServiceRepr[]\n ): [unknown, ReferenceMeta] | [unknown[], ReferenceMeta[]] {\n if (Array.isArray(ref)) {\n const referenceValues: unknown[] = [];\n const referenceMeta: ReferenceMeta[] = [];\n for (const d of ref) {\n const [value, meta] = this.#getReference(d);\n referenceValues.push(value);\n referenceMeta.push(meta);\n }\n return [referenceValues, referenceMeta];\n }\n\n const referenceValue = this.#createService(ref);\n const referenceMeta: ReferenceMeta = {\n serviceId: ref.id\n };\n return [referenceValue, referenceMeta];\n }\n\n #getServiceDeps(service: ServiceRepr) {\n const dependencies = this.#serviceDependencies.get(service.id);\n if (!dependencies) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find precomputed service dependencies for '${service.id}'.`\n );\n }\n return dependencies;\n }\n}\n\nfunction getRequiredServices(\n requiredReferences: readonly ReferenceSpec[],\n serviceLookup: ReadonlyServiceLookup\n): Set<ServiceRepr> {\n const requiredServices = new Set<ServiceRepr>();\n for (const referenceSpec of requiredReferences) {\n const result = serviceLookup.lookup(referenceSpec);\n if (result.type !== \"found\") {\n // Should be caught by verifier\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find required reference to ${renderInterfaceSpec(referenceSpec)}.`\n );\n }\n if (Array.isArray(result.value)) {\n for (const service of result.value) {\n requiredServices.add(service);\n }\n } else {\n requiredServices.add(result.value);\n }\n }\n return requiredServices;\n}\n\nfunction buildDependencyIndex(packages: readonly PackageRepr[]) {\n // Register declared UI dependencies.\n // This is needed as a lookup structure to that dynamic service lookups\n // can be validated at runtime.\n const index = new Map<string, Map<string, DependencyDeclarations>>();\n for (const pkg of packages) {\n const packageName = pkg.name;\n const packageEntry = new Map<string, DependencyDeclarations>();\n for (const uiReference of pkg.uiReferences) {\n let interfaceEntry = packageEntry.get(uiReference.interfaceName);\n if (!interfaceEntry) {\n interfaceEntry = {\n all: false,\n unqualified: false,\n qualifiers: new Set<string>()\n };\n packageEntry.set(uiReference.interfaceName, interfaceEntry);\n }\n\n if (isAllImplementationsSpec(uiReference)) {\n interfaceEntry.all = true;\n } else if (isSingleImplementationSpec(uiReference)) {\n if (uiReference.qualifier == null) {\n interfaceEntry.unqualified = true;\n } else {\n interfaceEntry.qualifiers.add(uiReference.qualifier);\n }\n } else {\n throw new Error(ErrorId.INTERNAL, `Unexpected implementation spec.`);\n }\n }\n index.set(packageName, packageEntry);\n }\n return index;\n}\n"],"names":["referenceMeta"],"mappings":";;;;;;;AAwBA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAkBjC,MAAM,qBAAA,GAAwB,EAAE,IAAA,EAAM,YAAA,EAAa;AACnD,MAAM,eAAA,GAAkB,EAAE,IAAA,EAAM,iBAAA,EAAkB;AAQ3C,MAAM,YAAA,CAAa;AAAA;AAAA,EAEtB,YAAA;AAAA;AAAA,EAGA,iBAAA;AAAA,EAEA,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AAAA,EACvC;AACA,EAAA,OAAO,KAAA;AACX;;;;"}
|
|
@@ -16,8 +16,7 @@ export interface Found<T> {
|
|
|
16
16
|
export type ServiceLookupResult = Unimplemented | Ambiguous | Found<ServiceRepr>;
|
|
17
17
|
export type ServicesLookupResult = Found<ServiceRepr[]>;
|
|
18
18
|
export declare class ServiceLookup {
|
|
19
|
-
private
|
|
20
|
-
private _count;
|
|
19
|
+
#private;
|
|
21
20
|
/**
|
|
22
21
|
* Returns the total number of registered services.
|
|
23
22
|
*/
|
|
@@ -41,6 +40,5 @@ export declare class ServiceLookup {
|
|
|
41
40
|
* Returns all services implementing the given interface.
|
|
42
41
|
*/
|
|
43
42
|
lookupAll(interfaceName: string): ServicesLookupResult;
|
|
44
|
-
private ensureInterfaceEntry;
|
|
45
43
|
}
|
|
46
44
|
export declare function renderAmbiguousServiceChoices(choices: AmbiguousChoice[], max?: number): string;
|
|
@@ -4,14 +4,14 @@ import { isSingleImplementationSpec } from './InterfaceSpec.js';
|
|
|
4
4
|
|
|
5
5
|
class ServiceLookup {
|
|
6
6
|
// Service implementations indexed by interface name.
|
|
7
|
-
services = /* @__PURE__ */ new Map();
|
|
7
|
+
#services = /* @__PURE__ */ new Map();
|
|
8
8
|
// Total service count
|
|
9
|
-
|
|
9
|
+
#count = 0;
|
|
10
10
|
/**
|
|
11
11
|
* Returns the total number of registered services.
|
|
12
12
|
*/
|
|
13
13
|
get serviceCount() {
|
|
14
|
-
return this
|
|
14
|
+
return this.#count;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Attempts to register the given service as an implementation of `interfaceName`.
|
|
@@ -32,10 +32,10 @@ class ServiceLookup {
|
|
|
32
32
|
`Service '${service.id}' uses an invalid qualifier for interface '${interfaceName}': '${qualifier}'.`
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
|
-
const services = this
|
|
35
|
+
const services = this.#ensureInterfaceEntry(interfaceName);
|
|
36
36
|
if (!qualifier) {
|
|
37
37
|
services.unqualified.push(service);
|
|
38
|
-
++this
|
|
38
|
+
++this.#count;
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
const existingQualified = services.byQualifier.get(qualifier);
|
|
@@ -46,7 +46,7 @@ class ServiceLookup {
|
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
services.byQualifier.set(qualifier, service);
|
|
49
|
-
++this
|
|
49
|
+
++this.#count;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Attempts to find the service(s) required by the given reference spec.
|
|
@@ -74,7 +74,7 @@ class ServiceLookup {
|
|
|
74
74
|
`Invalid qualifier during service lookup of interface '${interfaceName}': '${qualifier}'.`
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
|
-
const services = this
|
|
77
|
+
const services = this.#services.get(interfaceName);
|
|
78
78
|
if (!services) {
|
|
79
79
|
return { type: "unimplemented" };
|
|
80
80
|
}
|
|
@@ -117,7 +117,7 @@ class ServiceLookup {
|
|
|
117
117
|
`Invalid interface name during service lookup: '${interfaceName}'.`
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
|
-
const services = this
|
|
120
|
+
const services = this.#services.get(interfaceName);
|
|
121
121
|
if (!services) {
|
|
122
122
|
return { type: "found", value: [] };
|
|
123
123
|
}
|
|
@@ -127,8 +127,8 @@ class ServiceLookup {
|
|
|
127
127
|
value: Array.from(deduped)
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
|
-
ensureInterfaceEntry(interfaceName) {
|
|
131
|
-
const services = this
|
|
130
|
+
#ensureInterfaceEntry(interfaceName) {
|
|
131
|
+
const services = this.#services;
|
|
132
132
|
let entry = services.get(interfaceName);
|
|
133
133
|
if (!entry) {
|
|
134
134
|
entry = {
|