@open-pioneer/runtime 4.7.0-dev.20260713101438 → 4.7.0-dev.20260727091735
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +176 -175
- package/CustomElement.js +1 -1
- package/CustomElement.js.map +1 -1
- package/DeclaredService.d.ts +1 -1
- package/DeclaredService.js.map +1 -1
- package/Service.js.map +1 -1
- package/app/AppInstance.js +2 -2
- package/app/AppInstance.js.map +1 -1
- package/app/gatherConfig.js.map +1 -1
- package/app/logErrors.js.map +1 -1
- package/builtin-services/ApiServiceImpl.d.ts +1 -1
- package/builtin-services/ApiServiceImpl.js.map +1 -1
- package/builtin-services/ApplicationContextImpl.js.map +1 -1
- package/builtin-services/ApplicationLifecycleEventService.d.ts +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js.map +1 -1
- package/builtin-services/LocaleServiceImpl.js.map +1 -1
- package/builtin-services/NumberParserServiceImpl.js.map +1 -1
- package/builtin-services/ThemeServiceImpl.js.map +1 -1
- package/builtin-services/index.js.map +1 -1
- package/errors.js.map +1 -1
- package/i18n/AppIntl.js.map +1 -1
- package/i18n/PackageIntl.js.map +1 -1
- package/i18n/pick.js.map +1 -1
- package/metadata/ObservableBox.js.map +1 -1
- package/package.json +9 -9
- package/react-integration/ChakraProvider.d.ts +1 -1
- package/react-integration/ChakraProvider.js.map +1 -1
- package/react-integration/ErrorScreen.js.map +1 -1
- package/react-integration/PackageContext.js.map +1 -1
- package/react-integration/ReactIntegration.d.ts +1 -1
- package/react-integration/ReactIntegration.js.map +1 -1
- package/react-integration/hooks.js +1 -1
- package/react-integration/hooks.js.map +1 -1
- package/service-layer/InterfaceSpec.js.map +1 -1
- package/service-layer/PackageRepr.js.map +1 -1
- package/service-layer/ServiceLayer.js.map +1 -1
- package/service-layer/ServiceLookup.js.map +1 -1
- package/service-layer/ServiceRepr.js.map +1 -1
- package/service-layer/verifyDependencies.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceRepr.js","sources":["ServiceRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadonlyReactive, watchValue } from \"@conterra/reactivity-core\";\nimport { createLogger, deprecated, destroyResource, Error, Resource } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { ServiceMetadata } from \"../metadata\";\nimport {\n IS_SERVICE_FACTORY,\n MarkedServiceFactoryConstructor,\n Service,\n ServiceConstructor,\n ServiceFactory,\n ServiceOptions\n} from \"../Service\";\nimport { InterfaceSpec, parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\n\nconst LOG = createLogger(\"runtime:ServiceRepr\");\n\nexport type ServiceState = \"not-constructed\" | \"constructing\" | \"constructed\" | \"destroyed\";\n\nexport type ServiceDependency = ReferenceSpec & { referenceName: string };\n\nexport interface ServiceInstanceFactory {\n create(options: ServiceOptions): Service;\n destroy(srv: Service): void;\n}\n\nexport interface ServiceReprOptions {\n name: string;\n packageName: string;\n factory: ServiceInstanceFactory;\n intl: ReadonlyReactive<PackageIntl>;\n dependencies?: ServiceDependency[];\n interfaces?: InterfaceSpec[];\n properties?: Record<string, unknown>;\n}\n\ninterface HmrState extends Resource {\n /** Called when usage of `serviceOptions.intl` is detected at runtime. */\n onIntlUsed(): void;\n}\n\n/**\n * Represents metadata and state of a service in the runtime.\n * `this.instance` is the actual service instance (when constructed).\n */\nexport class ServiceRepr {\n static create(\n packageName: string,\n data: ServiceMetadata,\n intl: ReadonlyReactive<PackageIntl>,\n properties?: Record<string, unknown>\n ): ServiceRepr {\n const clazz = data.clazz;\n const name = data.name;\n const dependencies = Object.entries(data.references ?? {}).map(\n ([name, referenceMetadata]) => {\n return {\n referenceName: name,\n ...parseReferenceSpec(referenceMetadata)\n };\n }\n );\n const interfaces = data.provides?.map<InterfaceSpec>((i) => {\n return {\n interfaceName: i.name,\n qualifier: i.qualifier\n };\n });\n const factory = createConstructorFactory(clazz);\n return new ServiceRepr({\n name,\n packageName,\n factory,\n intl,\n dependencies,\n interfaces,\n properties\n });\n }\n\n /** Unique id of this service. Contains the package name and the service name. */\n readonly id: string;\n\n /** Name of this service in it's package. */\n readonly name: string;\n\n /** Name of the parent package. */\n readonly packageName: string;\n\n /** Locale-dependant i18n messages. */\n readonly intl: ReadonlyReactive<PackageIntl>;\n\n /** Service properties made available via the service's constructor. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Dependencies required by the service constructor. */\n readonly dependencies: readonly ServiceDependency[];\n\n /** Interfaces provided by the service. */\n readonly interfaces: readonly Readonly<InterfaceSpec>[];\n\n /** Number of references to this service. */\n #useCount = 0;\n\n /** Service factory to construct an instance. */\n #factory: ServiceInstanceFactory;\n\n /** Current state of this service. \"constructed\" -> instance is available. */\n #state: ServiceState = \"not-constructed\";\n\n /** Service instance, once constructed. */\n #instance: Service | undefined = undefined;\n\n /** Used in dev mode only. */\n #hmrState: HmrState | undefined = undefined;\n\n /** Lazily initialized deprecation message for this service. */\n #intlDeprecation: (() => void) | undefined = undefined;\n\n constructor(options: ServiceReprOptions) {\n const {\n name,\n packageName,\n factory,\n intl,\n dependencies = [],\n interfaces = [],\n properties = {}\n } = options;\n if (!isValidServiceName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid service name: '${name}'.`);\n }\n\n this.id = `${packageName}::${name}`;\n this.name = name;\n this.packageName = packageName;\n this.#factory = factory;\n this.intl = intl;\n this.dependencies = dependencies;\n this.interfaces = interfaces;\n this.properties = properties;\n }\n\n /** Returns the current service instance or undefined if the service has not been constructed. */\n get instance(): Service | undefined {\n return this.#instance;\n }\n\n /** Returns the current state of the service. */\n get state() {\n return this.#state;\n }\n\n /** Returns the current reference count. */\n get useCount() {\n return this.#useCount;\n }\n\n /**\n * Same as `instance`, but throws when the instance has not been constructed.\n */\n getInstanceOrThrow() {\n const instance = this.#instance;\n if (!instance) {\n throw new Error(ErrorId.INTERNAL, \"Expected service instance to be present.\");\n }\n return instance;\n }\n\n /**\n * Called before `create()` to place the service into the `constructing` state,\n * which is currently used to detect cycles.\n */\n beforeCreate() {\n if (this.#state === \"not-constructed\") {\n this.#state = \"constructing\";\n } else {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is already under construction.\"\n );\n }\n }\n\n /**\n * Instantiates the service by invoking the service constructor\n * with the given `options`.\n *\n * The service's use count is initialized to `1`, so every `create()`\n * should be paired with a `removeRef()`.\n *\n * `destroy()` can be invoked once the final `removeRef()` has returned zero.\n */\n create(references: Pick<ServiceOptions, \"references\" | \"referencesMeta\">) {\n if (this.#state !== \"constructing\" || this.instance !== undefined) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is not being constructed.\"\n );\n }\n\n const intl = this.intl;\n const hmrState = (this.#hmrState = /*#__PURE__*/ createHmrState(this.id, intl));\n try {\n const options = createServiceOptions({\n references,\n properties: this.properties,\n currentIntl: this.intl,\n intlDeprecation: () => {\n const deprecated = (this.#intlDeprecation ??= createIntlDeprecation(this.id));\n deprecated();\n },\n hmrState\n });\n this.#instance = this.#factory.create(options);\n this.#state = \"constructed\";\n this.#useCount = 1;\n return this.#instance;\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_CONSTRUCTION_FAILED,\n `Failed to create service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n\n destroy() {\n if (this.#instance) {\n try {\n this.#factory.destroy(this.#instance);\n this.#hmrState = destroyResource(this.#hmrState);\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_DESTRUCTION_FAILED,\n `Failed to destroy service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n this.#instance = undefined;\n this.#state = \"destroyed\";\n }\n\n /**\n * Adds a use to the service's use count.\n * References to a service are tracked: it should only be destroyed when it is no longer being used.\n */\n addRef() {\n return (this.#useCount += 1);\n }\n\n /**\n * Removes a use from the service's use count.\n * Returns the new use count.\n */\n removeRef() {\n return (this.#useCount -= 1);\n }\n}\n\nexport function createConstructorFactory<T extends {}>(\n clazz: ServiceConstructor<T> | MarkedServiceFactoryConstructor<T>\n): ServiceInstanceFactory {\n // check if factory is a service factory constructor (has the IS_SERVICE_FACTORY symbol)\n if (IS_SERVICE_FACTORY in clazz) {\n return createFactoryForServiceFactory(clazz);\n }\n // Is a regular service constructor\n return {\n create(options: ServiceOptions<T>) {\n return new clazz(options);\n },\n destroy(instance: Service<T>) {\n instance.destroy?.();\n }\n };\n}\n\nexport function createFactoryForServiceFactory<T extends {}>(\n facClazz: MarkedServiceFactoryConstructor<T>\n): ServiceInstanceFactory {\n return new ServiceFactoryInstanceFactory(facClazz);\n}\n\nclass ServiceFactoryInstanceFactory<T extends {}> implements ServiceInstanceFactory {\n #fac: ServiceFactory | undefined = undefined;\n #facClazz: MarkedServiceFactoryConstructor<T>;\n\n constructor(facClazz: MarkedServiceFactoryConstructor<T>) {\n this.#facClazz = facClazz;\n }\n\n create(options: ServiceOptions<T>) {\n const fac = new this.#facClazz(options);\n const instance = fac.createService();\n this.#fac = fac;\n return instance;\n }\n\n destroy(srv: Service) {\n if (!this.#fac) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service factory instance is not present.\"\n );\n }\n try {\n this.#fac.destroyService?.(srv);\n } finally {\n this.#fac = undefined;\n }\n }\n}\n\nexport function createFunctionFactory(\n create: (options: ServiceOptions) => Service\n): ServiceInstanceFactory {\n return {\n create,\n destroy(srv) {\n srv.destroy?.();\n }\n };\n}\n\n/**\n * Triggers a full page reload if:\n *\n * - We are in development mode (import.meta.hot) AND\n * - The service uses the deprecated `intl` option AND\n * - The messages changes due to a HMR event\n */\nfunction createHmrState(\n serviceId: string,\n intl: ReadonlyReactive<PackageIntl>\n): HmrState | undefined {\n let hmrState: HmrState | undefined;\n if (import.meta.hot) {\n let intlWatch: Resource | undefined = undefined;\n hmrState = {\n destroy() {\n intlWatch = destroyResource(intlWatch);\n },\n\n onIntlUsed() {\n if (intlWatch) {\n return;\n }\n\n intlWatch = watchValue(\n () => intl.value,\n (_newIntl, _, context) => {\n LOG.warn(\n `Service ${serviceId} has used the deprecated 'intl' option but messages have changed.` +\n ` Hot reloading of intl changes is only implemented ` +\n ` with 'currentIntl'.` +\n ` Triggering full reload.`\n );\n context.destroy();\n\n // TODO: Figure out a cleaner way to force vite to reload the application\n // https://github.com/open-pioneer/trails-core-packages/issues/164\n window.location.reload();\n }\n );\n }\n };\n }\n return hmrState;\n}\n\nfunction createServiceOptions(options: {\n references: Pick<ServiceOptions, \"references\" | \"referencesMeta\">;\n properties: Record<string, unknown>;\n currentIntl: ReadonlyReactive<PackageIntl>;\n intlDeprecation: () => void;\n hmrState: HmrState | undefined;\n}) {\n const { references, properties, currentIntl, intlDeprecation, hmrState } = options;\n return {\n ...references,\n properties,\n get intl() {\n intlDeprecation();\n if (import.meta.hot) {\n hmrState?.onIntlUsed();\n }\n return currentIntl.value;\n },\n currentIntl\n };\n}\n\nfunction createIntlDeprecation(serviceId: string) {\n return deprecated({\n name: `ServiceOptions.intl (used by ${serviceId})`,\n packageName: \"@open-pioneer/runtime\",\n since: \"4.6.0\",\n alternative: \"use currentIntl instead and watch for changes where appropriate\"\n });\n}\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n}\n"],"names":["name","deprecated"],"mappings":";;;;;;AAiBA,MAAM,GAAA,GAAM,aAAa,qBAAqB,CAAA;AA8BvC,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,WAAA,EACA,IAAA,EACA,MACA,UAAA,EACW;AACX,IAAA,MAAM,QAAQ,IAAA,CAAK,KAAA;AACnB,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AAClB,IAAA,MAAM,eAAe,MAAA,CAAO,OAAA,CAAQ,KAAK,UAAA,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AAK,KAAA;AAAA,UACX,CAAC,QAAA,EAAU,CAAA,EAAG,OAAA,KAAY;AACtB,YAAA,GAAA,CAAI,IAAA;AAAA,cACA,WAAW,SAAS,CAAA,gKAAA;AAAA,aAIxB;AACA,YAAA,OAAA,CAAQ,OAAA,EAAQ;AAIhB,YAAA,MAAA,CAAO,SAAS,MAAA,EAAO;AAAA,UAC3B;AAAA,SACJ;AAAA,MACJ;AAAA,KACJ;AAAA,EACJ;AACA,EAAA,OAAO,QAAA;AACX;AAEA,SAAS,qBAAqB,OAAA,EAM3B;AACC,EAAA,MAAM,EAAE,UAAA,EAAY,UAAA,EAAY,WAAA,EAAa,eAAA,EAAiB,UAAS,GAAI,OAAA;AAC3E,EAAA,OAAO;AAAA,IACH,GAAG,UAAA;AAAA,IACH,UAAA;AAAA,IACA,IAAI,IAAA,GAAO;AACP,MAAA,eAAA,EAAgB;AAChB,MAAA,IAAI,YAAY,GAAA,EAAK;AACjB,QAAA,QAAA,EAAU,UAAA,EAAW;AAAA,MACzB;AACA,MAAA,OAAO,WAAA,CAAY,KAAA;AAAA,IACvB,CAAA;AAAA,IACA;AAAA,GACJ;AACJ;AAEA,SAAS,sBAAsB,SAAA,EAAmB;AAC9C,EAAA,OAAO,UAAA,CAAW;AAAA,IACd,IAAA,EAAM,gCAAgC,SAAS,CAAA,CAAA,CAAA;AAAA,IAC/C,WAAA,EAAa,uBAAA;AAAA,IACb,KAAA,EAAO,OAAA;AAAA,IACP,WAAA,EAAa;AAAA,GAChB,CAAA;AACL;AAEA,MAAM,kBAAA,GAAqB,gBAAA;AAE3B,SAAS,mBAAmB,IAAA,EAAc;AACtC,EAAA,OAAO,kBAAA,CAAmB,KAAK,IAAI,CAAA;AACvC;;;;"}
|
|
1
|
+
{"version":3,"file":"ServiceRepr.js","sources":["ServiceRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ReadonlyReactive, watchValue } from \"@conterra/reactivity-core\";\nimport { createLogger, deprecated, destroyResource, Error, Resource } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { ServiceMetadata } from \"../metadata\";\nimport {\n IS_SERVICE_FACTORY,\n MarkedServiceFactoryConstructor,\n Service,\n ServiceConstructor,\n ServiceFactory,\n ServiceOptions\n} from \"../Service\";\nimport { InterfaceSpec, parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\n\nconst LOG = createLogger(\"runtime:ServiceRepr\");\n\nexport type ServiceState = \"not-constructed\" | \"constructing\" | \"constructed\" | \"destroyed\";\n\nexport type ServiceDependency = ReferenceSpec & { referenceName: string };\n\nexport interface ServiceInstanceFactory {\n create(options: ServiceOptions): Service;\n destroy(srv: Service): void;\n}\n\nexport interface ServiceReprOptions {\n name: string;\n packageName: string;\n factory: ServiceInstanceFactory;\n intl: ReadonlyReactive<PackageIntl>;\n dependencies?: ServiceDependency[];\n interfaces?: InterfaceSpec[];\n properties?: Record<string, unknown>;\n}\n\ninterface HmrState extends Resource {\n /** Called when usage of `serviceOptions.intl` is detected at runtime. */\n onIntlUsed(): void;\n}\n\n/**\n * Represents metadata and state of a service in the runtime.\n * `this.instance` is the actual service instance (when constructed).\n */\nexport class ServiceRepr {\n static create(\n packageName: string,\n data: ServiceMetadata,\n intl: ReadonlyReactive<PackageIntl>,\n properties?: Record<string, unknown>\n ): ServiceRepr {\n const clazz = data.clazz;\n const name = data.name;\n // oxlint-disable-next-line oxc/no-map-spread\n const dependencies = Object.entries(data.references ?? {}).map(\n ([name, referenceMetadata]) => {\n return {\n referenceName: name,\n ...parseReferenceSpec(referenceMetadata)\n };\n }\n );\n const interfaces = data.provides?.map<InterfaceSpec>((i) => {\n return {\n interfaceName: i.name,\n qualifier: i.qualifier\n };\n });\n const factory = createConstructorFactory(clazz);\n return new ServiceRepr({\n name,\n packageName,\n factory,\n intl,\n dependencies,\n interfaces,\n properties\n });\n }\n\n /** Unique id of this service. Contains the package name and the service name. */\n readonly id: string;\n\n /** Name of this service in it's package. */\n readonly name: string;\n\n /** Name of the parent package. */\n readonly packageName: string;\n\n /** Locale-dependant i18n messages. */\n readonly intl: ReadonlyReactive<PackageIntl>;\n\n /** Service properties made available via the service's constructor. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Dependencies required by the service constructor. */\n readonly dependencies: readonly ServiceDependency[];\n\n /** Interfaces provided by the service. */\n readonly interfaces: readonly Readonly<InterfaceSpec>[];\n\n /** Number of references to this service. */\n #useCount = 0;\n\n /** Service factory to construct an instance. */\n #factory: ServiceInstanceFactory;\n\n /** Current state of this service. \"constructed\" -> instance is available. */\n #state: ServiceState = \"not-constructed\";\n\n /** Service instance, once constructed. */\n #instance: Service | undefined = undefined;\n\n /** Used in dev mode only. */\n #hmrState: HmrState | undefined = undefined;\n\n /** Lazily initialized deprecation message for this service. */\n #intlDeprecation: (() => void) | undefined = undefined;\n\n constructor(options: ServiceReprOptions) {\n const {\n name,\n packageName,\n factory,\n intl,\n dependencies = [],\n interfaces = [],\n properties = {}\n } = options;\n if (!isValidServiceName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid service name: '${name}'.`);\n }\n\n this.id = `${packageName}::${name}`;\n this.name = name;\n this.packageName = packageName;\n this.#factory = factory;\n this.intl = intl;\n this.dependencies = dependencies;\n this.interfaces = interfaces;\n this.properties = properties;\n }\n\n /** Returns the current service instance or undefined if the service has not been constructed. */\n get instance(): Service | undefined {\n return this.#instance;\n }\n\n /** Returns the current state of the service. */\n get state() {\n return this.#state;\n }\n\n /** Returns the current reference count. */\n get useCount() {\n return this.#useCount;\n }\n\n /**\n * Same as `instance`, but throws when the instance has not been constructed.\n */\n getInstanceOrThrow() {\n const instance = this.#instance;\n if (!instance) {\n throw new Error(ErrorId.INTERNAL, \"Expected service instance to be present.\");\n }\n return instance;\n }\n\n /**\n * Called before `create()` to place the service into the `constructing` state,\n * which is currently used to detect cycles.\n */\n beforeCreate() {\n if (this.#state === \"not-constructed\") {\n this.#state = \"constructing\";\n } else {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is already under construction.\"\n );\n }\n }\n\n /**\n * Instantiates the service by invoking the service constructor\n * with the given `options`.\n *\n * The service's use count is initialized to `1`, so every `create()`\n * should be paired with a `removeRef()`.\n *\n * `destroy()` can be invoked once the final `removeRef()` has returned zero.\n */\n create(references: Pick<ServiceOptions, \"references\" | \"referencesMeta\">) {\n if (this.#state !== \"constructing\" || this.instance !== undefined) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is not being constructed.\"\n );\n }\n\n const intl = this.intl;\n const hmrState = (this.#hmrState = /*#__PURE__*/ createHmrState(this.id, intl));\n try {\n const options = createServiceOptions({\n references,\n properties: this.properties,\n currentIntl: this.intl,\n intlDeprecation: () => {\n const deprecated = (this.#intlDeprecation ??= createIntlDeprecation(this.id));\n deprecated();\n },\n hmrState\n });\n this.#instance = this.#factory.create(options);\n this.#state = \"constructed\";\n this.#useCount = 1;\n return this.#instance;\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_CONSTRUCTION_FAILED,\n `Failed to create service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n\n destroy() {\n if (this.#instance) {\n try {\n this.#factory.destroy(this.#instance);\n this.#hmrState = destroyResource(this.#hmrState);\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_DESTRUCTION_FAILED,\n `Failed to destroy service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n this.#instance = undefined;\n this.#state = \"destroyed\";\n }\n\n /**\n * Adds a use to the service's use count.\n * References to a service are tracked: it should only be destroyed when it is no longer being used.\n */\n addRef() {\n return (this.#useCount += 1);\n }\n\n /**\n * Removes a use from the service's use count.\n * Returns the new use count.\n */\n removeRef() {\n return (this.#useCount -= 1);\n }\n}\n\nexport function createConstructorFactory<T extends {}>(\n clazz: ServiceConstructor<T> | MarkedServiceFactoryConstructor<T>\n): ServiceInstanceFactory {\n // check if factory is a service factory constructor (has the IS_SERVICE_FACTORY symbol)\n if (IS_SERVICE_FACTORY in clazz) {\n return createFactoryForServiceFactory(clazz);\n }\n // Is a regular service constructor\n return {\n create(options: ServiceOptions<T>) {\n return new clazz(options);\n },\n destroy(instance: Service<T>) {\n instance.destroy?.();\n }\n };\n}\n\nexport function createFactoryForServiceFactory<T extends {}>(\n facClazz: MarkedServiceFactoryConstructor<T>\n): ServiceInstanceFactory {\n return new ServiceFactoryInstanceFactory(facClazz);\n}\n\nclass ServiceFactoryInstanceFactory<T extends {}> implements ServiceInstanceFactory {\n #fac: ServiceFactory | undefined = undefined;\n #facClazz: MarkedServiceFactoryConstructor<T>;\n\n constructor(facClazz: MarkedServiceFactoryConstructor<T>) {\n this.#facClazz = facClazz;\n }\n\n create(options: ServiceOptions<T>) {\n const fac = new this.#facClazz(options);\n const instance = fac.createService();\n this.#fac = fac;\n return instance;\n }\n\n destroy(srv: Service) {\n if (!this.#fac) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service factory instance is not present.\"\n );\n }\n try {\n this.#fac.destroyService?.(srv);\n } finally {\n this.#fac = undefined;\n }\n }\n}\n\nexport function createFunctionFactory(\n create: (options: ServiceOptions) => Service\n): ServiceInstanceFactory {\n return {\n create,\n destroy(srv) {\n srv.destroy?.();\n }\n };\n}\n\n/**\n * Triggers a full page reload if:\n *\n * - We are in development mode (import.meta.hot) AND\n * - The service uses the deprecated `intl` option AND\n * - The messages changes due to a HMR event\n */\nfunction createHmrState(\n serviceId: string,\n intl: ReadonlyReactive<PackageIntl>\n): HmrState | undefined {\n let hmrState: HmrState | undefined;\n if (import.meta.hot) {\n let intlWatch: Resource | undefined = undefined;\n hmrState = {\n destroy() {\n intlWatch = destroyResource(intlWatch);\n },\n\n onIntlUsed() {\n if (intlWatch) {\n return;\n }\n\n intlWatch = watchValue(\n () => intl.value,\n (_newIntl, _, context) => {\n LOG.warn(\n `Service ${serviceId} has used the deprecated 'intl' option but messages have changed.` +\n ` Hot reloading of intl changes is only implemented ` +\n ` with 'currentIntl'.` +\n ` Triggering full reload.`\n );\n context.destroy();\n\n // TODO: Figure out a cleaner way to force vite to reload the application\n // https://github.com/open-pioneer/trails-core-packages/issues/164\n window.location.reload();\n }\n );\n }\n };\n }\n return hmrState;\n}\n\nfunction createServiceOptions(options: {\n references: Pick<ServiceOptions, \"references\" | \"referencesMeta\">;\n properties: Record<string, unknown>;\n currentIntl: ReadonlyReactive<PackageIntl>;\n intlDeprecation: () => void;\n hmrState: HmrState | undefined;\n}) {\n const { references, properties, currentIntl, intlDeprecation, hmrState } = options;\n return {\n ...references,\n properties,\n get intl() {\n intlDeprecation();\n if (import.meta.hot) {\n hmrState?.onIntlUsed();\n }\n return currentIntl.value;\n },\n currentIntl\n };\n}\n\nfunction createIntlDeprecation(serviceId: string) {\n return deprecated({\n name: `ServiceOptions.intl (used by ${serviceId})`,\n packageName: \"@open-pioneer/runtime\",\n since: \"4.6.0\",\n alternative: \"use currentIntl instead and watch for changes where appropriate\"\n });\n}\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n}\n"],"names":["name","deprecated"],"mappings":";;;;;;AAkBA,MAAM,GAAA,GAAM,aAAa,qBAAqB,CAAA;AA8BvC,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,WAAA,EACA,IAAA,EACA,MACA,UAAA,EACW;AACX,IAAA,MAAM,QAAQ,IAAA,CAAK,KAAA;AACnB,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AAElB,IAAA,MAAM,eAAe,MAAA,CAAO,OAAA,CAAQ,KAAK,UAAA,IAAc,EAAE,CAAA,CAAE,GAAA;AAAA,MACvD,CAAC,CAACA,KAAAA,EAAM,iBAAiB,CAAA,KAAM;AAC3B,QAAA,OAAO;AAAA,UACH,aAAA,EAAeA,KAAAA;AAAA,UACf,GAAG,mBAAmB,iB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,OAAA,EAAQ;AAIhB,YAAA,MAAA,CAAO,SAAS,MAAA,EAAO;AAAA,UAC3B;AAAA,SACJ;AAAA,MACJ;AAAA,KACJ;AAAA,EACJ;AACA,EAAA,OAAO,QAAA;AACX;AAEA,SAAS,qBAAqB,OAAA,EAM3B;AACC,EAAA,MAAM,EAAE,UAAA,EAAY,UAAA,EAAY,WAAA,EAAa,eAAA,EAAiB,UAAS,GAAI,OAAA;AAC3E,EAAA,OAAO;AAAA,IACH,GAAG,UAAA;AAAA,IACH,UAAA;AAAA,IACA,IAAI,IAAA,GAAO;AACP,MAAA,eAAA,EAAgB;AAChB,MAAA,IAAI,YAAY,GAAA,EAAK;AACjB,QAAA,QAAA,EAAU,UAAA,EAAW;AAAA,MACzB;AACA,MAAA,OAAO,WAAA,CAAY,KAAA;AAAA,IACvB,CAAA;AAAA,IACA;AAAA,GACJ;AACJ;AAEA,SAAS,sBAAsB,SAAA,EAAmB;AAC9C,EAAA,OAAO,UAAA,CAAW;AAAA,IACd,IAAA,EAAM,gCAAgC,SAAS,CAAA,CAAA,CAAA;AAAA,IAC/C,WAAA,EAAa,uBAAA;AAAA,IACb,KAAA,EAAO,OAAA;AAAA,IACP,WAAA,EAAa;AAAA,GAChB,CAAA;AACL;AAEA,MAAM,kBAAA,GAAqB,gBAAA;AAE3B,SAAS,mBAAmB,IAAA,EAAc;AACtC,EAAA,OAAO,kBAAA,CAAmB,KAAK,IAAI,CAAA;AACvC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyDependencies.js","sources":["verifyDependencies.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, ReferenceSpec, renderInterfaceSpec } from \"./InterfaceSpec\";\nimport {\n AmbiguousChoice,\n ReadonlyServiceLookup,\n renderAmbiguousServiceChoices,\n ServiceLookup\n} from \"./ServiceLookup\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface DependencyOptions {\n /**\n * All services known to the service layer.\n */\n services?: readonly ServiceRepr[];\n\n /**\n * References that must be satisfied by the services.\n */\n requiredReferences?: readonly RequiredReference[];\n}\n\nexport type RequiredReference = UIDependency | FrameworkDependency;\n\nexport type UIDependency = { type: \"ui\"; packageName: string } & ReferenceSpec;\n\nexport type FrameworkDependency = { type: \"framework\" } & ReferenceSpec;\n\nexport type ComputedServiceDependencies = Record<string, ServiceRepr | ServiceRepr[]>;\n\nexport interface VerifyDependenciesResult {\n /**\n * Precomputed dependencies for every service.\n *\n * Key: service id.\n */\n serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n /**\n * Index structure mapping interface names to service instances.\n */\n serviceLookup: ReadonlyServiceLookup;\n}\n\n/**\n * Visits all services and ensures that their dependencies can be satisfied by each other without a cycle.\n *\n * Throws an error if a cycle is detected or if a required service is never implemented.\n *\n * @returns an object containing the service index and precomputed dependency information\n */\nexport function verifyDependencies(options: DependencyOptions): VerifyDependenciesResult {\n const verifier = new Verifier(options);\n verifier.verify();\n return {\n serviceLookup: verifier.getServiceLookup(),\n serviceDependencies: verifier.getComputedDependencies()\n };\n}\n\ninterface GraphItem {\n state: ItemState;\n service: ServiceRepr;\n dependencies: ComputedServiceDependencies;\n}\n\ntype ItemState = \"not-visited\" | \"pending\" | \"done\";\n\n/** The reason why a graph node is being visited. */\ntype ItemVisitReason = \"root\" | InterfaceReference;\n\ntype InterfaceReference =\n | {\n type: \"framework-reference\";\n value: ReferenceSpec;\n }\n | {\n type: \"ui-reference\";\n packageName: string;\n value: ReferenceSpec;\n }\n | {\n type: \"service-reference\";\n service: ServiceRepr;\n referenceName: string;\n value: ReferenceSpec;\n };\n\nclass Verifier {\n #requiredReferences: readonly RequiredReference[];\n #items: GraphItem[];\n #serviceLookup = new ServiceLookup();\n #serviceToGraphItem = new Map<ServiceRepr, GraphItem>();\n\n // Stack of visited nodes\n #stack: [item: GraphItem, reason: ItemVisitReason][] = [];\n\n constructor(options: DependencyOptions) {\n this.#requiredReferences = options.requiredReferences ?? [];\n const services = options.services ?? [];\n const items = (this.#items = services.map<GraphItem>((service) => {\n return {\n service: service,\n state: \"not-visited\",\n dependencies: {}\n };\n }));\n\n for (const item of items) {\n for (const spec of item.service.interfaces) {\n this.#registerService(item, spec);\n }\n }\n }\n\n verify() {\n for (const ref of this.#requiredReferences) {\n let interfaceRef: InterfaceReference;\n switch (ref.type) {\n case \"framework\":\n interfaceRef = { type: \"framework-reference\", value: ref };\n break;\n case \"ui\":\n interfaceRef = {\n type: \"ui-reference\",\n packageName: ref.packageName,\n value: ref\n };\n break;\n }\n this.#visitReference(interfaceRef);\n }\n for (const item of this.#items) {\n this.#visitItem(item, \"root\");\n }\n }\n\n getServiceLookup() {\n return this.#serviceLookup;\n }\n\n getComputedDependencies() {\n return new Map(\n this.#items.map<[string, ComputedServiceDependencies]>((item) => {\n return [item.service.id, item.dependencies];\n })\n );\n }\n\n #visitItem(item: GraphItem, reason: ItemVisitReason) {\n const stack = this.#stack;\n const state = item.state;\n if (state === \"done\") {\n return; // Item is initialized, cycle impossible\n }\n if (state === \"pending\") {\n this.#throwCycleError(item, reason);\n }\n\n stack.push([item, reason]);\n item.state = \"pending\";\n for (const dep of item.service.dependencies) {\n item.dependencies[dep.referenceName] = this.#visitReference({\n type: \"service-reference\",\n service: item.service,\n referenceName: dep.referenceName,\n value: dep\n });\n }\n item.state = \"done\";\n stack.pop();\n }\n\n #visitReference(ref: InterfaceReference) {\n const itemOrItems = this.#findServices(ref);\n if (Array.isArray(itemOrItems)) {\n for (const child of itemOrItems) {\n this.#visitItem(child, ref);\n }\n return itemOrItems.map((item) => item.service);\n } else {\n this.#visitItem(itemOrItems, ref);\n return itemOrItems.service;\n }\n }\n\n #registerService(item: GraphItem, spec: InterfaceSpec) {\n this.#serviceLookup.register(item.service, spec);\n this.#serviceToGraphItem.set(item.service, item);\n }\n\n #findServices(ref: InterfaceReference): GraphItem | GraphItem[] {\n const spec = ref.value;\n const lookupResult = this.#serviceLookup.lookup(spec);\n switch (lookupResult.type) {\n case \"unimplemented\": {\n const message = unimplementedInterfaceMessage(ref);\n throw new Error(ErrorId.INTERFACE_NOT_FOUND, message);\n }\n case \"ambiguous\": {\n const message = ambiguousInterfaceMessage(ref, lookupResult.choices);\n throw new Error(ErrorId.AMBIGUOUS_DEPENDENCY, message);\n }\n }\n\n const value = lookupResult.value;\n if (Array.isArray(value)) {\n return value.map((service) => this.#getGraphItem(service));\n } else {\n return this.#getGraphItem(value);\n }\n }\n\n #getGraphItem(service: ServiceRepr): GraphItem {\n const graphItem = this.#serviceToGraphItem.get(service);\n if (!graphItem || graphItem.service !== service) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find matching graph item for service '${service.id}'.`\n );\n }\n return graphItem;\n }\n\n #throwCycleError(item: GraphItem, reason: ItemVisitReason) {\n // Find the item on the stack (it must be there because we detected a cycle).\n const stack = this.#stack;\n const ownIndex = stack.findIndex((entry) => entry[0] === item);\n if (ownIndex === -1) {\n throw new Error(ErrorId.INTERNAL, \"Failed to find cycle participant on the stack.\");\n }\n\n const cycleInfo = stack\n .slice(ownIndex)\n .concat([[item, reason]])\n .map<string>((entry, index) => {\n const item = entry[0];\n const reason = index === 0 ? \"root\" : entry[1]; // info before the cycle does not matter\n\n let message = `'${item.service.id}'`;\n if (typeof reason === \"object\") {\n message += ` (${referenceDetail(reason)})`;\n }\n return message;\n });\n throw new Error(\n ErrorId.DEPENDENCY_CYCLE,\n `Detected dependency cycle: ${cycleInfo.join(\" => \")}.`\n );\n }\n}\n\nfunction unimplementedInterfaceMessage(ref: InterfaceReference): string {\n const interfaceText = renderInterfaceSpec(ref.value);\n switch (ref.type) {\n case \"service-reference\":\n return `Service '${ref.service.id}' requires an unimplemented interface ${interfaceText} as dependency '${ref.referenceName}'.`;\n case \"ui-reference\":\n return `The UI of package '${ref.packageName}' requires an unimplemented interface ${interfaceText}.`;\n case \"framework-reference\":\n return `The framework requires an unimplemented interface ${interfaceText}.`;\n }\n}\n\nfunction ambiguousInterfaceMessage(ref: InterfaceReference, choices: AmbiguousChoice[]): string {\n const interfaceText = renderInterfaceSpec(ref.value);\n const serviceChoices = renderAmbiguousServiceChoices(choices);\n\n let message = \"\";\n switch (ref.type) {\n case \"service-reference\":\n message = `Service '${ref.service.id}' requires the ambiguous interface ${interfaceText} as dependency '${ref.referenceName}'.`;\n break;\n case \"ui-reference\":\n message = `The UI of package '${ref.packageName}' requires the ambiguous interface ${interfaceText}.`;\n break;\n case \"framework-reference\":\n message = `The framework requires the ambiguous interface ${interfaceText}.`;\n break;\n }\n message += ` Possible choices are ${serviceChoices}.`;\n return message;\n}\n\nfunction referenceDetail(reason: InterfaceReference) {\n switch (reason.type) {\n case \"service-reference\":\n return `'${reason.referenceName}' providing '${reason.value.interfaceName}'`;\n case \"ui-reference\":\n return `UI of package '${reason.packageName}' requiring '${reason.value.interfaceName}'`;\n case \"framework-reference\":\n return `framework requiring '${reason.value.interfaceName}'`;\n }\n}\n"],"names":["item","reason"],"mappings":";;;;;AAsDO,SAAS,mBAAmB,OAAA,EAAsD;AACrF,EAAA,MAAM,QAAA,GAAW,IAAI,QAAA,CAAS,OAAO,CAAA;AACrC,EAAA,QAAA,CAAS,MAAA,EAAO;AAChB,EAAA,OAAO;AAAA,IACH,aAAA,EAAe,SAAS,gBAAA,EAAiB;AAAA,IACzC,mBAAA,EAAqB,SAAS,uBAAA;AAAwB,GAC1D;AACJ;AA8BA,MAAM,QAAA,CAAS;AAAA,EACX,mBAAA;AAAA,EACA,MAAA;AAAA,EACA,cAAA,GAAiB,IAAI,aAAA,EAAc;AAAA,EACnC,mBAAA,uBAA0B,GAAA,EAA4B;AAAA;AAAA,EAGtD,SAAuD,EAAC;AAAA,EAExD,YAAY,OAAA,EAA4B;AACpC,IAAA,IAAA,CAAK,mBAAA,GAAsB,OAAA,CAAQ,kBAAA,IAAsB,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GAAU,CAAA,mBAAA,EAAsB,GAAA,CAAI,WAAW,CAAA,mCAAA,EAAsC,aAAa,CAAA,CAAA,CAAA;AAClG,MAAA;AAAA,IACJ,KAAK,qBAAA;AACD,MAAA,OAAA,GAAU,kDAAkD,aAAa,CAAA,CAAA,CAAA;AACzE,MAAA;AAAA;AAER,EAAA,OAAA,IAAW,yBAAyB,cAAc,CAAA,CAAA,CAAA;AAClD,EAAA,OAAO,OAAA;AACX;AAEA,SAAS,gBAAgB,MAAA,EAA4B;AACjD,EAAA,QAAQ,OAAO,IAAA;AAAM,IACjB,KAAK,mBAAA;AACD,MAAA,OAAO,IAAI,MAAA,CAAO,aAAa,CAAA,aAAA,EAAgB,MAAA,CAAO,MAAM,aAAa,CAAA,CAAA,CAAA;AAAA,IAC7E,KAAK,cAAA;AACD,MAAA,OAAO,kBAAkB,MAAA,CAAO,WAAW,CAAA,aAAA,EAAgB,MAAA,CAAO,MAAM,aAAa,CAAA,CAAA,CAAA;AAAA,IACzF,KAAK,qBAAA;AACD,MAAA,OAAO,CAAA,qBAAA,EAAwB,MAAA,CAAO,KAAA,CAAM,aAAa,CAAA,CAAA,CAAA;AAAA;AAErE;;;;"}
|
|
1
|
+
{"version":3,"file":"verifyDependencies.js","sources":["verifyDependencies.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, ReferenceSpec, renderInterfaceSpec } from \"./InterfaceSpec\";\nimport {\n AmbiguousChoice,\n ReadonlyServiceLookup,\n renderAmbiguousServiceChoices,\n ServiceLookup\n} from \"./ServiceLookup\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface DependencyOptions {\n /**\n * All services known to the service layer.\n */\n services?: readonly ServiceRepr[];\n\n /**\n * References that must be satisfied by the services.\n */\n requiredReferences?: readonly RequiredReference[];\n}\n\nexport type RequiredReference = UIDependency | FrameworkDependency;\n\nexport type UIDependency = { type: \"ui\"; packageName: string } & ReferenceSpec;\n\nexport type FrameworkDependency = { type: \"framework\" } & ReferenceSpec;\n\nexport type ComputedServiceDependencies = Record<string, ServiceRepr | ServiceRepr[]>;\n\nexport interface VerifyDependenciesResult {\n /**\n * Precomputed dependencies for every service.\n *\n * Key: service id.\n */\n serviceDependencies: Map<string, ComputedServiceDependencies>;\n\n /**\n * Index structure mapping interface names to service instances.\n */\n serviceLookup: ReadonlyServiceLookup;\n}\n\n/**\n * Visits all services and ensures that their dependencies can be satisfied by each other without a cycle.\n *\n * Throws an error if a cycle is detected or if a required service is never implemented.\n *\n * @returns an object containing the service index and precomputed dependency information\n */\nexport function verifyDependencies(options: DependencyOptions): VerifyDependenciesResult {\n const verifier = new Verifier(options);\n verifier.verify();\n return {\n serviceLookup: verifier.getServiceLookup(),\n serviceDependencies: verifier.getComputedDependencies()\n };\n}\n\ninterface GraphItem {\n state: ItemState;\n service: ServiceRepr;\n dependencies: ComputedServiceDependencies;\n}\n\ntype ItemState = \"not-visited\" | \"pending\" | \"done\";\n\n/** The reason why a graph node is being visited. */\ntype ItemVisitReason = \"root\" | InterfaceReference;\n\ntype InterfaceReference =\n | {\n type: \"framework-reference\";\n value: ReferenceSpec;\n }\n | {\n type: \"ui-reference\";\n packageName: string;\n value: ReferenceSpec;\n }\n | {\n type: \"service-reference\";\n service: ServiceRepr;\n referenceName: string;\n value: ReferenceSpec;\n };\n\nclass Verifier {\n #requiredReferences: readonly RequiredReference[];\n #items: GraphItem[];\n #serviceLookup = new ServiceLookup();\n #serviceToGraphItem = new Map<ServiceRepr, GraphItem>();\n\n // Stack of visited nodes\n #stack: [item: GraphItem, reason: ItemVisitReason][] = [];\n\n constructor(options: DependencyOptions) {\n this.#requiredReferences = options.requiredReferences ?? [];\n const services = options.services ?? [];\n const items = (this.#items = services.map<GraphItem>((service) => {\n return {\n service: service,\n state: \"not-visited\",\n dependencies: {}\n };\n }));\n\n for (const item of items) {\n for (const spec of item.service.interfaces) {\n this.#registerService(item, spec);\n }\n }\n }\n\n verify() {\n for (const ref of this.#requiredReferences) {\n let interfaceRef: InterfaceReference;\n switch (ref.type) {\n case \"framework\":\n interfaceRef = { type: \"framework-reference\", value: ref };\n break;\n case \"ui\":\n interfaceRef = {\n type: \"ui-reference\",\n packageName: ref.packageName,\n value: ref\n };\n break;\n }\n this.#visitReference(interfaceRef);\n }\n for (const item of this.#items) {\n this.#visitItem(item, \"root\");\n }\n }\n\n getServiceLookup() {\n return this.#serviceLookup;\n }\n\n getComputedDependencies() {\n return new Map(\n this.#items.map<[string, ComputedServiceDependencies]>((item) => {\n return [item.service.id, item.dependencies];\n })\n );\n }\n\n #visitItem(item: GraphItem, reason: ItemVisitReason) {\n const stack = this.#stack;\n const state = item.state;\n if (state === \"done\") {\n return; // Item is initialized, cycle impossible\n }\n if (state === \"pending\") {\n this.#throwCycleError(item, reason);\n }\n\n stack.push([item, reason]);\n item.state = \"pending\";\n for (const dep of item.service.dependencies) {\n item.dependencies[dep.referenceName] = this.#visitReference({\n type: \"service-reference\",\n service: item.service,\n referenceName: dep.referenceName,\n value: dep\n });\n }\n item.state = \"done\";\n stack.pop();\n }\n\n #visitReference(ref: InterfaceReference) {\n const itemOrItems = this.#findServices(ref);\n if (Array.isArray(itemOrItems)) {\n for (const child of itemOrItems) {\n this.#visitItem(child, ref);\n }\n return itemOrItems.map((item) => item.service);\n } else {\n this.#visitItem(itemOrItems, ref);\n return itemOrItems.service;\n }\n }\n\n #registerService(item: GraphItem, spec: InterfaceSpec) {\n this.#serviceLookup.register(item.service, spec);\n this.#serviceToGraphItem.set(item.service, item);\n }\n\n #findServices(ref: InterfaceReference): GraphItem | GraphItem[] {\n const spec = ref.value;\n const lookupResult = this.#serviceLookup.lookup(spec);\n switch (lookupResult.type) {\n case \"unimplemented\": {\n const message = unimplementedInterfaceMessage(ref);\n throw new Error(ErrorId.INTERFACE_NOT_FOUND, message);\n }\n case \"ambiguous\": {\n const message = ambiguousInterfaceMessage(ref, lookupResult.choices);\n throw new Error(ErrorId.AMBIGUOUS_DEPENDENCY, message);\n }\n }\n\n const value = lookupResult.value;\n if (Array.isArray(value)) {\n return value.map((service) => this.#getGraphItem(service));\n } else {\n return this.#getGraphItem(value);\n }\n }\n\n #getGraphItem(service: ServiceRepr): GraphItem {\n const graphItem = this.#serviceToGraphItem.get(service);\n if (!graphItem || graphItem.service !== service) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find matching graph item for service '${service.id}'.`\n );\n }\n return graphItem;\n }\n\n #throwCycleError(item: GraphItem, reason: ItemVisitReason) {\n // Find the item on the stack (it must be there because we detected a cycle).\n const stack = this.#stack;\n const ownIndex = stack.findIndex((entry) => entry[0] === item);\n if (ownIndex === -1) {\n throw new Error(ErrorId.INTERNAL, \"Failed to find cycle participant on the stack.\");\n }\n\n const cycleInfo = stack\n .slice(ownIndex)\n .concat([[item, reason]])\n .map<string>((entry, index) => {\n const item = entry[0];\n const reason = index === 0 ? \"root\" : entry[1]; // info before the cycle does not matter\n\n let message = `'${item.service.id}'`;\n if (typeof reason === \"object\") {\n message += ` (${referenceDetail(reason)})`;\n }\n return message;\n });\n throw new Error(\n ErrorId.DEPENDENCY_CYCLE,\n `Detected dependency cycle: ${cycleInfo.join(\" => \")}.`\n );\n }\n}\n\nfunction unimplementedInterfaceMessage(ref: InterfaceReference): string {\n const interfaceText = renderInterfaceSpec(ref.value);\n switch (ref.type) {\n case \"service-reference\":\n return `Service '${ref.service.id}' requires an unimplemented interface ${interfaceText} as dependency '${ref.referenceName}'.`;\n case \"ui-reference\":\n return `The UI of package '${ref.packageName}' requires an unimplemented interface ${interfaceText}.`;\n case \"framework-reference\":\n return `The framework requires an unimplemented interface ${interfaceText}.`;\n }\n}\n\nfunction ambiguousInterfaceMessage(ref: InterfaceReference, choices: AmbiguousChoice[]): string {\n const interfaceText = renderInterfaceSpec(ref.value);\n const serviceChoices = renderAmbiguousServiceChoices(choices);\n\n let message = \"\";\n switch (ref.type) {\n case \"service-reference\":\n message = `Service '${ref.service.id}' requires the ambiguous interface ${interfaceText} as dependency '${ref.referenceName}'.`;\n break;\n case \"ui-reference\":\n message = `The UI of package '${ref.packageName}' requires the ambiguous interface ${interfaceText}.`;\n break;\n case \"framework-reference\":\n message = `The framework requires the ambiguous interface ${interfaceText}.`;\n break;\n }\n message += ` Possible choices are ${serviceChoices}.`;\n return message;\n}\n\nfunction referenceDetail(reason: InterfaceReference) {\n switch (reason.type) {\n case \"service-reference\":\n return `'${reason.referenceName}' providing '${reason.value.interfaceName}'`;\n case \"ui-reference\":\n return `UI of package '${reason.packageName}' requiring '${reason.value.interfaceName}'`;\n case \"framework-reference\":\n return `framework requiring '${reason.value.interfaceName}'`;\n }\n}\n"],"names":["item","reason"],"mappings":";;;;;AAuDO,SAAS,mBAAmB,OAAA,EAAsD;AACrF,EAAA,MAAM,QAAA,GAAW,IAAI,QAAA,CAAS,OAAO,CAAA;AACrC,EAAA,QAAA,CAAS,MAAA,EAAO;AAChB,EAAA,OAAO;AAAA,IACH,aAAA,EAAe,SAAS,gBAAA,EAAiB;AAAA,IACzC,mBAAA,EAAqB,SAAS,uBAAA;AAAwB,GAC1D;AACJ;AA8BA,MAAM,QAAA,CAAS;AAAA,EACX,mBAAA;AAAA,EACA,MAAA;AAAA,EACA,cAAA,GAAiB,IAAI,aAAA,EAAc;AAAA,EACnC,mBAAA,uBAA0B,GAAA,EAA4B;AAAA;AAAA,EAGtD,SAAuD,EAAC;AAAA,EAExD,YAAY,OAAA,EAA4B;AACpC,IAAA,IAAA,CAAK,mBAAA,GAAsB,OAAA,CAAQ,kBAAA,IAAsB,EAAC;AAC1D,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,QAAA,IAAY,EAAC;AACtC,IAAA,MAAM,QAAS,IAAA,CAAK,MAAA,GAAS,QAAA,CAAS,GAAA,CAAe,CAAC,OAAA,KAAY;AAC9D,MAAA,OAAO;AAAA,QACH,O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