@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.
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceLookup.js","sources":["ServiceLookup.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, isSingleImplementationSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\ninterface Services {\n // The unqualified service implementations (if any).\n unqualified: ServiceRepr[];\n\n // Services indexed by their qualifier (if any).\n byQualifier: Map<string, ServiceRepr>;\n}\n\nexport type ReadonlyServiceLookup = Pick<\n ServiceLookup,\n \"lookup\" | \"lookupOne\" | \"lookupAll\" | \"serviceCount\"\n>;\n\nexport interface Unimplemented {\n type: \"unimplemented\";\n}\n\nexport interface Ambiguous {\n type: \"ambiguous\";\n choices: AmbiguousChoice[];\n}\n\nexport type AmbiguousChoice = [serviceId: string, qualifier: string | undefined];\n\nexport interface Found<T> {\n type: \"found\";\n value: T;\n}\n\nexport type ServiceLookupResult = Unimplemented | Ambiguous | Found<ServiceRepr>;\n\nexport type ServicesLookupResult = Found<ServiceRepr[]>;\n\nexport class ServiceLookup {\n // Service implementations indexed by interface name.\n private services = new Map<string, Services>();\n\n // Total service count\n private _count = 0;\n\n /**\n * Returns the total number of registered services.\n */\n get serviceCount() {\n return this._count;\n }\n\n /**\n * Attempts to register the given service as an implementation of `interfaceName`.\n * Throws if the registration did not complete successfully.\n *\n * All services should be registered before any lookups are attempted.\n */\n register(service: ServiceRepr, { interfaceName, qualifier }: InterfaceSpec): void {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Service '${service.id}' provides invalid interface '${interfaceName}'.`\n );\n }\n if (qualifier != null && !qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Service '${service.id}' uses an invalid qualifier for interface '${interfaceName}': '${qualifier}'.`\n );\n }\n\n const services = this.ensureInterfaceEntry(interfaceName);\n if (!qualifier) {\n services.unqualified.push(service);\n ++this._count;\n return;\n }\n\n const existingQualified = services.byQualifier.get(qualifier);\n if (existingQualified) {\n throw new Error(\n ErrorId.DUPLICATE_INTERFACE,\n `Cannot register '${service.id}' as interface '${interfaceName}' with qualifier '${qualifier}'.` +\n ` The interface is already provided by service '${existingQualified.id}'.` +\n ` You can choose a different qualifier or remove the service to resolve the collision.`\n );\n }\n services.byQualifier.set(qualifier, service);\n ++this._count;\n }\n\n /**\n * Attempts to find the service(s) required by the given reference spec.\n */\n lookup(ref: ReferenceSpec): ServiceLookupResult | ServicesLookupResult {\n if (isSingleImplementationSpec(ref)) {\n return this.lookupOne(ref);\n } else {\n return this.lookupAll(ref.interfaceName);\n }\n }\n\n /**\n * Attempts to find a service implementing the given interface.\n */\n lookupOne({ interfaceName, qualifier }: InterfaceSpec): ServiceLookupResult {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid interface name during service lookup: '${interfaceName}'.`\n );\n }\n if (qualifier != null && !qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid qualifier during service lookup of interface '${interfaceName}': '${qualifier}'.`\n );\n }\n\n const services = this.services.get(interfaceName);\n if (!services) {\n return { type: \"unimplemented\" };\n }\n\n if (!qualifier) {\n // Just pick one, but the choice must be unambiguous.\n const count = services.unqualified.length + services.byQualifier.size;\n if (count > 1) {\n // [serviceId, qualifier] tuples\n const choices: AmbiguousChoice[] = [];\n choices.push(\n ...Array.from(services.byQualifier.entries()).map<AmbiguousChoice>(\n ([qualifier, service]) => [service.id, qualifier]\n )\n );\n choices.push(\n ...services.unqualified.map<AmbiguousChoice>((s) => [s.id, undefined])\n );\n return {\n type: \"ambiguous\",\n choices: choices\n };\n }\n\n const service = services.unqualified[0] ?? first(services.byQualifier);\n if (!service) {\n return { type: \"unimplemented\" };\n }\n return { type: \"found\", value: service };\n }\n\n const service = services.byQualifier.get(qualifier);\n if (!service) {\n return { type: \"unimplemented\" };\n }\n return { type: \"found\", value: service };\n }\n\n /**\n * Returns all services implementing the given interface.\n */\n lookupAll(interfaceName: string): ServicesLookupResult {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid interface name during service lookup: '${interfaceName}'.`\n );\n }\n\n const services = this.services.get(interfaceName);\n if (!services) {\n return { type: \"found\", value: [] };\n }\n\n const deduped = new Set([...services.unqualified, ...services.byQualifier.values()]);\n return {\n type: \"found\",\n value: Array.from(deduped)\n };\n }\n\n private ensureInterfaceEntry(interfaceName: string): Services {\n const services = this.services;\n let entry = services.get(interfaceName);\n if (!entry) {\n entry = {\n unqualified: [],\n byQualifier: new Map()\n };\n services.set(interfaceName, entry);\n }\n return entry;\n }\n}\n\nexport function renderAmbiguousServiceChoices(choices: AmbiguousChoice[], max = 3): string {\n let message = \"\";\n let count = 0;\n for (const [serviceId, qualifier] of choices) {\n if (count) {\n message += \", \";\n }\n\n message += `'${serviceId}'`;\n if (qualifier) {\n message += ` (with qualifier '${qualifier}')`;\n }\n\n if (++count >= max) {\n break;\n }\n }\n\n const remaining = choices.length - count;\n if (remaining > 0) {\n message += ` and ${remaining} more`;\n }\n return message;\n}\n\nfunction first<K, V>(map: Map<K, V>): V | undefined {\n return map.values().next().value;\n}\n"],"names":["qualifier","service"],"mappings":";;;;AAwCO,MAAM,aAAA,CAAc;AAAA;AAAA,EAEf,QAAA,uBAAe,GAAA,EAAsB;AAAA;AAAA,EAGrC,MAAA,GAAS,CAAA;AAAA;AAAA;AAAA;AAAA,EAKjB,IAAI,YAAA,GAAe;AACf,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAA,CAAS,OA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AAS,CAAA,KAAA,CAAA;AAAA,EAChC;AACA,EAAA,OAAO,OAAA;AACX;AAEA,SAAS,MAAY,GAAA,EAA+B;AAChD,EAAA,OAAO,GAAA,CAAI,MAAA,EAAO,CAAE,IAAA,EAAK,CAAE,KAAA;AAC/B;;;;"}
1
+ {"version":3,"file":"ServiceLookup.js","sources":["ServiceLookup.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, isSingleImplementationSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\ninterface Services {\n // The unqualified service implementations (if any).\n unqualified: ServiceRepr[];\n\n // Services indexed by their qualifier (if any).\n byQualifier: Map<string, ServiceRepr>;\n}\n\nexport type ReadonlyServiceLookup = Pick<\n ServiceLookup,\n \"lookup\" | \"lookupOne\" | \"lookupAll\" | \"serviceCount\"\n>;\n\nexport interface Unimplemented {\n type: \"unimplemented\";\n}\n\nexport interface Ambiguous {\n type: \"ambiguous\";\n choices: AmbiguousChoice[];\n}\n\nexport type AmbiguousChoice = [serviceId: string, qualifier: string | undefined];\n\nexport interface Found<T> {\n type: \"found\";\n value: T;\n}\n\nexport type ServiceLookupResult = Unimplemented | Ambiguous | Found<ServiceRepr>;\n\nexport type ServicesLookupResult = Found<ServiceRepr[]>;\n\nexport class ServiceLookup {\n // Service implementations indexed by interface name.\n #services = new Map<string, Services>();\n\n // Total service count\n #count = 0;\n\n /**\n * Returns the total number of registered services.\n */\n get serviceCount() {\n return this.#count;\n }\n\n /**\n * Attempts to register the given service as an implementation of `interfaceName`.\n * Throws if the registration did not complete successfully.\n *\n * All services should be registered before any lookups are attempted.\n */\n register(service: ServiceRepr, { interfaceName, qualifier }: InterfaceSpec): void {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Service '${service.id}' provides invalid interface '${interfaceName}'.`\n );\n }\n if (qualifier != null && !qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Service '${service.id}' uses an invalid qualifier for interface '${interfaceName}': '${qualifier}'.`\n );\n }\n\n const services = this.#ensureInterfaceEntry(interfaceName);\n if (!qualifier) {\n services.unqualified.push(service);\n ++this.#count;\n return;\n }\n\n const existingQualified = services.byQualifier.get(qualifier);\n if (existingQualified) {\n throw new Error(\n ErrorId.DUPLICATE_INTERFACE,\n `Cannot register '${service.id}' as interface '${interfaceName}' with qualifier '${qualifier}'.` +\n ` The interface is already provided by service '${existingQualified.id}'.` +\n ` You can choose a different qualifier or remove the service to resolve the collision.`\n );\n }\n services.byQualifier.set(qualifier, service);\n ++this.#count;\n }\n\n /**\n * Attempts to find the service(s) required by the given reference spec.\n */\n lookup(ref: ReferenceSpec): ServiceLookupResult | ServicesLookupResult {\n if (isSingleImplementationSpec(ref)) {\n return this.lookupOne(ref);\n } else {\n return this.lookupAll(ref.interfaceName);\n }\n }\n\n /**\n * Attempts to find a service implementing the given interface.\n */\n lookupOne({ interfaceName, qualifier }: InterfaceSpec): ServiceLookupResult {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid interface name during service lookup: '${interfaceName}'.`\n );\n }\n if (qualifier != null && !qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid qualifier during service lookup of interface '${interfaceName}': '${qualifier}'.`\n );\n }\n\n const services = this.#services.get(interfaceName);\n if (!services) {\n return { type: \"unimplemented\" };\n }\n\n if (!qualifier) {\n // Just pick one, but the choice must be unambiguous.\n const count = services.unqualified.length + services.byQualifier.size;\n if (count > 1) {\n // [serviceId, qualifier] tuples\n const choices: AmbiguousChoice[] = [];\n choices.push(\n ...Array.from(services.byQualifier.entries()).map<AmbiguousChoice>(\n ([qualifier, service]) => [service.id, qualifier]\n )\n );\n choices.push(\n ...services.unqualified.map<AmbiguousChoice>((s) => [s.id, undefined])\n );\n return {\n type: \"ambiguous\",\n choices: choices\n };\n }\n\n const service = services.unqualified[0] ?? first(services.byQualifier);\n if (!service) {\n return { type: \"unimplemented\" };\n }\n return { type: \"found\", value: service };\n }\n\n const service = services.byQualifier.get(qualifier);\n if (!service) {\n return { type: \"unimplemented\" };\n }\n return { type: \"found\", value: service };\n }\n\n /**\n * Returns all services implementing the given interface.\n */\n lookupAll(interfaceName: string): ServicesLookupResult {\n if (!interfaceName) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n `Invalid interface name during service lookup: '${interfaceName}'.`\n );\n }\n\n const services = this.#services.get(interfaceName);\n if (!services) {\n return { type: \"found\", value: [] };\n }\n\n const deduped = new Set([...services.unqualified, ...services.byQualifier.values()]);\n return {\n type: \"found\",\n value: Array.from(deduped)\n };\n }\n\n #ensureInterfaceEntry(interfaceName: string): Services {\n const services = this.#services;\n let entry = services.get(interfaceName);\n if (!entry) {\n entry = {\n unqualified: [],\n byQualifier: new Map()\n };\n services.set(interfaceName, entry);\n }\n return entry;\n }\n}\n\nexport function renderAmbiguousServiceChoices(choices: AmbiguousChoice[], max = 3): string {\n let message = \"\";\n let count = 0;\n for (const [serviceId, qualifier] of choices) {\n if (count) {\n message += \", \";\n }\n\n message += `'${serviceId}'`;\n if (qualifier) {\n message += ` (with qualifier '${qualifier}')`;\n }\n\n if (++count >= max) {\n break;\n }\n }\n\n const remaining = choices.length - count;\n if (remaining > 0) {\n message += ` and ${remaining} more`;\n }\n return message;\n}\n\nfunction first<K, V>(map: Map<K, V>): V | undefined {\n return map.values().next().value;\n}\n"],"names":["qualifier","service"],"mappings":";;;;AAwCO,MAAM,aAAA,CAAc;AAAA;AAAA,EAEvB,SAAA,uBAAgB,GAAA,EAAsB;AAAA;AAAA,EAGtC,MAAA,GAAS,CAAA;AAAA;AAAA;AAAA;AAAA,EAKT,IAAI,YAAA,GAAe;AACf,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA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EAAG;AACf,IAAA,OAAA,IAAW,QAAQ,SAAS,CAAA,KAAA,CAAA;AAAA,EAChC;AACA,EAAA,OAAO,OAAA;AACX;AAEA,SAAS,MAAY,GAAA,EAA+B;AAChD,EAAA,OAAO,GAAA,CAAI,MAAA,EAAO,CAAE,IAAA,EAAK,CAAE,KAAA;AAC/B;;;;"}
@@ -25,6 +25,7 @@ export interface ServiceReprOptions {
25
25
  * `this.instance` is the actual service instance (when constructed).
26
26
  */
27
27
  export declare class ServiceRepr {
28
+ #private;
28
29
  static create(packageName: string, data: ServiceMetadata, intl: ReadonlyReactive<PackageIntl>, properties?: Record<string, unknown>): ServiceRepr;
29
30
  /** Unique id of this service. Contains the package name and the service name. */
30
31
  readonly id: string;
@@ -40,16 +41,6 @@ export declare class ServiceRepr {
40
41
  readonly dependencies: readonly ServiceDependency[];
41
42
  /** Interfaces provided by the service. */
42
43
  readonly interfaces: readonly Readonly<InterfaceSpec>[];
43
- /** Number of references to this service. */
44
- private _useCount;
45
- /** Service factory to construct an instance. */
46
- private factory;
47
- /** Current state of this service. "constructed" -> instance is available. */
48
- private _state;
49
- /** Service instance, once constructed. */
50
- private _instance;
51
- /** Used in dev mode only. */
52
- private _hmrState;
53
44
  constructor(options: ServiceReprOptions);
54
45
  /** Returns the current service instance or undefined if the service has not been constructed. */
55
46
  get instance(): Service | undefined;
@@ -75,7 +66,7 @@ export declare class ServiceRepr {
75
66
  *
76
67
  * `destroy()` can be invoked once the final `removeRef()` has returned zero.
77
68
  */
78
- create(options: Pick<ServiceOptions, "references" | "referencesMeta">): import("..").ServiceLifecycleHooks;
69
+ create(references: Pick<ServiceOptions, "references" | "referencesMeta">): import("..").ServiceLifecycleHooks;
79
70
  destroy(): void;
80
71
  /**
81
72
  * Adds a use to the service's use count.
@@ -1,16 +1,10 @@
1
1
  import { watchValue } from '@conterra/reactivity-core';
2
- import { createLogger, deprecated, Error, destroyResource } from '@open-pioneer/core';
2
+ import { createLogger, Error, destroyResource, deprecated } from '@open-pioneer/core';
3
3
  import { ErrorId } from '../errors.js';
4
4
  import { IS_SERVICE_FACTORY } from '../Service.js';
5
5
  import { parseReferenceSpec } from './InterfaceSpec.js';
6
6
 
7
7
  const LOG = createLogger("runtime:ServiceRepr");
8
- const intlDeprecation = deprecated({
9
- name: "ServiceOptions.intl",
10
- packageName: "@open-pioneer/runtime",
11
- since: "4.5.1",
12
- alternative: "use currentIntl instead and watch for changes where appropriate"
13
- });
14
8
  class ServiceRepr {
15
9
  static create(packageName, data, intl, properties) {
16
10
  const clazz = data.clazz;
@@ -55,15 +49,17 @@ class ServiceRepr {
55
49
  /** Interfaces provided by the service. */
56
50
  interfaces;
57
51
  /** Number of references to this service. */
58
- _useCount = 0;
52
+ #useCount = 0;
59
53
  /** Service factory to construct an instance. */
60
- factory;
54
+ #factory;
61
55
  /** Current state of this service. "constructed" -> instance is available. */
62
- _state = "not-constructed";
56
+ #state = "not-constructed";
63
57
  /** Service instance, once constructed. */
64
- _instance = void 0;
58
+ #instance = void 0;
65
59
  /** Used in dev mode only. */
66
- _hmrState = void 0;
60
+ #hmrState = void 0;
61
+ /** Lazily initialized deprecation message for this service. */
62
+ #intlDeprecation = void 0;
67
63
  constructor(options) {
68
64
  const {
69
65
  name,
@@ -80,7 +76,7 @@ class ServiceRepr {
80
76
  this.id = `${packageName}::${name}`;
81
77
  this.name = name;
82
78
  this.packageName = packageName;
83
- this.factory = factory;
79
+ this.#factory = factory;
84
80
  this.intl = intl;
85
81
  this.dependencies = dependencies;
86
82
  this.interfaces = interfaces;
@@ -88,21 +84,21 @@ class ServiceRepr {
88
84
  }
89
85
  /** Returns the current service instance or undefined if the service has not been constructed. */
90
86
  get instance() {
91
- return this._instance;
87
+ return this.#instance;
92
88
  }
93
89
  /** Returns the current state of the service. */
94
90
  get state() {
95
- return this._state;
91
+ return this.#state;
96
92
  }
97
93
  /** Returns the current reference count. */
98
94
  get useCount() {
99
- return this._useCount;
95
+ return this.#useCount;
100
96
  }
101
97
  /**
102
98
  * Same as `instance`, but throws when the instance has not been constructed.
103
99
  */
104
100
  getInstanceOrThrow() {
105
- const instance = this._instance;
101
+ const instance = this.#instance;
106
102
  if (!instance) {
107
103
  throw new Error(ErrorId.INTERNAL, "Expected service instance to be present.");
108
104
  }
@@ -113,8 +109,8 @@ class ServiceRepr {
113
109
  * which is currently used to detect cycles.
114
110
  */
115
111
  beforeCreate() {
116
- if (this._state === "not-constructed") {
117
- this._state = "constructing";
112
+ if (this.#state === "not-constructed") {
113
+ this.#state = "constructing";
118
114
  } else {
119
115
  throw new Error(
120
116
  ErrorId.INTERNAL,
@@ -131,31 +127,30 @@ class ServiceRepr {
131
127
  *
132
128
  * `destroy()` can be invoked once the final `removeRef()` has returned zero.
133
129
  */
134
- create(options) {
135
- if (this._state !== "constructing" || this.instance !== void 0) {
130
+ create(references) {
131
+ if (this.#state !== "constructing" || this.instance !== void 0) {
136
132
  throw new Error(
137
133
  ErrorId.INTERNAL,
138
134
  "Inconsistent state: service is not being constructed."
139
135
  );
140
136
  }
141
137
  const intl = this.intl;
142
- const hmrState = this._hmrState = /* @__PURE__ */ createHmrState(this.id, intl);
138
+ const hmrState = this.#hmrState = /* @__PURE__ */ createHmrState(this.id, intl);
143
139
  try {
144
- this._instance = this.factory.create({
145
- ...options,
140
+ const options = createServiceOptions({
141
+ references,
146
142
  properties: this.properties,
147
- get intl() {
148
- intlDeprecation();
149
- if (import.meta.hot) {
150
- hmrState?.onIntlUsed();
151
- }
152
- return intl.value;
143
+ currentIntl: this.intl,
144
+ intlDeprecation: () => {
145
+ const deprecated2 = this.#intlDeprecation ??= createIntlDeprecation(this.id);
146
+ deprecated2();
153
147
  },
154
- currentIntl: this.intl
148
+ hmrState
155
149
  });
156
- this._state = "constructed";
157
- this._useCount = 1;
158
- return this._instance;
150
+ this.#instance = this.#factory.create(options);
151
+ this.#state = "constructed";
152
+ this.#useCount = 1;
153
+ return this.#instance;
159
154
  } catch (e) {
160
155
  throw new Error(
161
156
  ErrorId.SERVICE_CONSTRUCTION_FAILED,
@@ -165,10 +160,10 @@ class ServiceRepr {
165
160
  }
166
161
  }
167
162
  destroy() {
168
- if (this._instance) {
163
+ if (this.#instance) {
169
164
  try {
170
- this.factory.destroy(this._instance);
171
- this._hmrState = destroyResource(this._hmrState);
165
+ this.#factory.destroy(this.#instance);
166
+ this.#hmrState = destroyResource(this.#hmrState);
172
167
  } catch (e) {
173
168
  throw new Error(
174
169
  ErrorId.SERVICE_DESTRUCTION_FAILED,
@@ -177,22 +172,22 @@ class ServiceRepr {
177
172
  );
178
173
  }
179
174
  }
180
- this._instance = void 0;
181
- this._state = "destroyed";
175
+ this.#instance = void 0;
176
+ this.#state = "destroyed";
182
177
  }
183
178
  /**
184
179
  * Adds a use to the service's use count.
185
180
  * References to a service are tracked: it should only be destroyed when it is no longer being used.
186
181
  */
187
182
  addRef() {
188
- return this._useCount += 1;
183
+ return this.#useCount += 1;
189
184
  }
190
185
  /**
191
186
  * Removes a use from the service's use count.
192
187
  * Returns the new use count.
193
188
  */
194
189
  removeRef() {
195
- return this._useCount -= 1;
190
+ return this.#useCount -= 1;
196
191
  }
197
192
  }
198
193
  function createConstructorFactory(clazz) {
@@ -212,28 +207,28 @@ function createFactoryForServiceFactory(facClazz) {
212
207
  return new ServiceFactoryInstanceFactory(facClazz);
213
208
  }
214
209
  class ServiceFactoryInstanceFactory {
215
- constructor(_facClazz) {
216
- this._facClazz = _facClazz;
210
+ #fac = void 0;
211
+ #facClazz;
212
+ constructor(facClazz) {
213
+ this.#facClazz = facClazz;
217
214
  }
218
- _facClazz;
219
- _fac = void 0;
220
215
  create(options) {
221
- const fac = new this._facClazz(options);
216
+ const fac = new this.#facClazz(options);
222
217
  const instance = fac.createService();
223
- this._fac = fac;
218
+ this.#fac = fac;
224
219
  return instance;
225
220
  }
226
221
  destroy(srv) {
227
- if (!this._fac) {
222
+ if (!this.#fac) {
228
223
  throw new Error(
229
224
  ErrorId.INTERNAL,
230
225
  "Inconsistent state: service factory instance is not present."
231
226
  );
232
227
  }
233
228
  try {
234
- this._fac.destroyService?.(srv);
229
+ this.#fac.destroyService?.(srv);
235
230
  } finally {
236
- this._fac = void 0;
231
+ this.#fac = void 0;
237
232
  }
238
233
  }
239
234
  }
@@ -272,6 +267,29 @@ function createHmrState(serviceId, intl) {
272
267
  }
273
268
  return hmrState;
274
269
  }
270
+ function createServiceOptions(options) {
271
+ const { references, properties, currentIntl, intlDeprecation, hmrState } = options;
272
+ return {
273
+ ...references,
274
+ properties,
275
+ get intl() {
276
+ intlDeprecation();
277
+ if (import.meta.hot) {
278
+ hmrState?.onIntlUsed();
279
+ }
280
+ return currentIntl.value;
281
+ },
282
+ currentIntl
283
+ };
284
+ }
285
+ function createIntlDeprecation(serviceId) {
286
+ return deprecated({
287
+ name: `ServiceOptions.intl (used by ${serviceId})`,
288
+ packageName: "@open-pioneer/runtime",
289
+ since: "4.6.0",
290
+ alternative: "use currentIntl instead and watch for changes where appropriate"
291
+ });
292
+ }
275
293
  const SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;
276
294
  function isValidServiceName(name) {
277
295
  return SERVICE_NAME_REGEX.test(name);
@@ -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\nconst intlDeprecation = deprecated({\n name: \"ServiceOptions.intl\",\n packageName: \"@open-pioneer/runtime\",\n since: \"4.5.1\",\n alternative: \"use currentIntl instead and watch for changes where appropriate\"\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 private _useCount = 0;\n\n /** Service factory to construct an instance. */\n private factory: ServiceInstanceFactory;\n\n /** Current state of this service. \"constructed\" -> instance is available. */\n private _state: ServiceState = \"not-constructed\";\n\n /** Service instance, once constructed. */\n private _instance: Service | undefined = undefined;\n\n /** Used in dev mode only. */\n private _hmrState: HmrState | undefined = undefined;\n\n constructor(options: ServiceReprOptions) {\n const {\n name,\n packageName,\n factory,\n intl,\n dependencies = [],\n interfaces = [],\n properties = {}\n } = options;\n if (!isValidServiceName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid service name: '${name}'.`);\n }\n\n this.id = `${packageName}::${name}`;\n this.name = name;\n this.packageName = packageName;\n this.factory = factory;\n this.intl = intl;\n this.dependencies = dependencies;\n this.interfaces = interfaces;\n this.properties = properties;\n }\n\n /** Returns the current service instance or undefined if the service has not been constructed. */\n get instance(): Service | undefined {\n return this._instance;\n }\n\n /** Returns the current state of the service. */\n get state() {\n return this._state;\n }\n\n /** Returns the current reference count. */\n get useCount() {\n return this._useCount;\n }\n\n /**\n * Same as `instance`, but throws when the instance has not been constructed.\n */\n getInstanceOrThrow() {\n const instance = this._instance;\n if (!instance) {\n throw new Error(ErrorId.INTERNAL, \"Expected service instance to be present.\");\n }\n return instance;\n }\n\n /**\n * Called before `create()` to place the service into the `constructing` state,\n * which is currently used to detect cycles.\n */\n beforeCreate() {\n if (this._state === \"not-constructed\") {\n this._state = \"constructing\";\n } else {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is already under construction.\"\n );\n }\n }\n\n /**\n * Instantiates the service by invoking the service constructor\n * with the given `options`.\n *\n * The service's use count is initialized to `1`, so every `create()`\n * should be paired with a `removeRef()`.\n *\n * `destroy()` can be invoked once the final `removeRef()` has returned zero.\n */\n create(options: Pick<ServiceOptions, \"references\" | \"referencesMeta\">) {\n if (this._state !== \"constructing\" || this.instance !== undefined) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is not being constructed.\"\n );\n }\n\n const intl = this.intl;\n const hmrState = (this._hmrState = /*#__PURE__*/ createHmrState(this.id, intl));\n try {\n this._instance = this.factory.create({\n ...options,\n properties: this.properties,\n get intl() {\n intlDeprecation();\n if (import.meta.hot) {\n hmrState?.onIntlUsed();\n }\n return intl.value;\n },\n currentIntl: this.intl\n });\n this._state = \"constructed\";\n this._useCount = 1;\n return this._instance;\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_CONSTRUCTION_FAILED,\n `Failed to create service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n\n destroy() {\n if (this._instance) {\n try {\n this.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 private _fac: ServiceFactory | undefined = undefined;\n\n constructor(private _facClazz: MarkedServiceFactoryConstructor<T>) {}\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\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n}\n"],"names":["name"],"mappings":";;;;;;AAiBA,MAAM,GAAA,GAAM,aAAa,qBAAqB,CAAA;AA0B9C,MAAM,kBAAkB,UAAA,CAAW;AAAA,EAC/B,IAAA,EAAM,qBAA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ACjB,IAAA,IAAI,SAAA,GAAkC,MAAA;AACtC,IAAA,QAAA,GAAW;AAAA,MACP,OAAA,GAAU;AACN,QAAA,SAAA,GAAY,gBAAgB,SAAS,CAAA;AAAA,MACzC,CAAA;AAAA,MAEA,UAAA,GAAa;AACT,QAAA,IAAI,SAAA,EAAW;AACX,UAAA;AAAA,QACJ;AAEA,QAAA,SAAA,GAAY,UAAA;AAAA,UACR,MAAM,IAAA,CAAK,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,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\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,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,iBAAiB;AAAA,SAC3C;AAAA,MACJ;AAAA,KACJ;AACA,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,QAAA,EAAU,GAAA,CAAmB,CAAC,CAAA,KAAM;AACxD,MAAA,OAAO;AAAA,QACH,eAAe,CAAA,CAAE,IAAA;AAAA,QACjB,WAAW,CAAA,CAAE;AAAA,OACjB;AAAA,IACJ,CAAC,CAAA;AACD,IAAA,MAAM,OAAA,GAAU,yBAAyB,KAAK,CAAA;AAC9C,IAAA,OAAO,IAAI,WAAA,CAAY;AAAA,MACnB,IAAA;AAAA,MACA,WAAA;AAAA,MACA,OAAA;AAAA,MAC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,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;;;;"}
@@ -12,16 +12,16 @@ function verifyDependencies(options) {
12
12
  };
13
13
  }
14
14
  class Verifier {
15
- requiredReferences;
16
- items;
17
- serviceLookup = new ServiceLookup();
18
- serviceToGraphItem = /* @__PURE__ */ new Map();
15
+ #requiredReferences;
16
+ #items;
17
+ #serviceLookup = new ServiceLookup();
18
+ #serviceToGraphItem = /* @__PURE__ */ new Map();
19
19
  // Stack of visited nodes
20
- stack = [];
20
+ #stack = [];
21
21
  constructor(options) {
22
- this.requiredReferences = options.requiredReferences ?? [];
22
+ this.#requiredReferences = options.requiredReferences ?? [];
23
23
  const services = options.services ?? [];
24
- const items = this.items = services.map((service) => {
24
+ const items = this.#items = services.map((service) => {
25
25
  return {
26
26
  service,
27
27
  state: "not-visited",
@@ -30,12 +30,12 @@ class Verifier {
30
30
  });
31
31
  for (const item of items) {
32
32
  for (const spec of item.service.interfaces) {
33
- this.registerService(item, spec);
33
+ this.#registerService(item, spec);
34
34
  }
35
35
  }
36
36
  }
37
37
  verify() {
38
- for (const ref of this.requiredReferences) {
38
+ for (const ref of this.#requiredReferences) {
39
39
  let interfaceRef;
40
40
  switch (ref.type) {
41
41
  case "framework":
@@ -49,35 +49,35 @@ class Verifier {
49
49
  };
50
50
  break;
51
51
  }
52
- this.visitReference(interfaceRef);
52
+ this.#visitReference(interfaceRef);
53
53
  }
54
- for (const item of this.items) {
55
- this.visitItem(item, "root");
54
+ for (const item of this.#items) {
55
+ this.#visitItem(item, "root");
56
56
  }
57
57
  }
58
58
  getServiceLookup() {
59
- return this.serviceLookup;
59
+ return this.#serviceLookup;
60
60
  }
61
61
  getComputedDependencies() {
62
62
  return new Map(
63
- this.items.map((item) => {
63
+ this.#items.map((item) => {
64
64
  return [item.service.id, item.dependencies];
65
65
  })
66
66
  );
67
67
  }
68
- visitItem(item, reason) {
69
- const stack = this.stack;
68
+ #visitItem(item, reason) {
69
+ const stack = this.#stack;
70
70
  const state = item.state;
71
71
  if (state === "done") {
72
72
  return;
73
73
  }
74
74
  if (state === "pending") {
75
- this.throwCycleError(item, reason);
75
+ this.#throwCycleError(item, reason);
76
76
  }
77
77
  stack.push([item, reason]);
78
78
  item.state = "pending";
79
79
  for (const dep of item.service.dependencies) {
80
- item.dependencies[dep.referenceName] = this.visitReference({
80
+ item.dependencies[dep.referenceName] = this.#visitReference({
81
81
  type: "service-reference",
82
82
  service: item.service,
83
83
  referenceName: dep.referenceName,
@@ -87,25 +87,25 @@ class Verifier {
87
87
  item.state = "done";
88
88
  stack.pop();
89
89
  }
90
- visitReference(ref) {
91
- const itemOrItems = this.findServices(ref);
90
+ #visitReference(ref) {
91
+ const itemOrItems = this.#findServices(ref);
92
92
  if (Array.isArray(itemOrItems)) {
93
93
  for (const child of itemOrItems) {
94
- this.visitItem(child, ref);
94
+ this.#visitItem(child, ref);
95
95
  }
96
96
  return itemOrItems.map((item) => item.service);
97
97
  } else {
98
- this.visitItem(itemOrItems, ref);
98
+ this.#visitItem(itemOrItems, ref);
99
99
  return itemOrItems.service;
100
100
  }
101
101
  }
102
- registerService(item, spec) {
103
- this.serviceLookup.register(item.service, spec);
104
- this.serviceToGraphItem.set(item.service, item);
102
+ #registerService(item, spec) {
103
+ this.#serviceLookup.register(item.service, spec);
104
+ this.#serviceToGraphItem.set(item.service, item);
105
105
  }
106
- findServices(ref) {
106
+ #findServices(ref) {
107
107
  const spec = ref.value;
108
- const lookupResult = this.serviceLookup.lookup(spec);
108
+ const lookupResult = this.#serviceLookup.lookup(spec);
109
109
  switch (lookupResult.type) {
110
110
  case "unimplemented": {
111
111
  const message = unimplementedInterfaceMessage(ref);
@@ -118,13 +118,13 @@ class Verifier {
118
118
  }
119
119
  const value = lookupResult.value;
120
120
  if (Array.isArray(value)) {
121
- return value.map((service) => this.getGraphItem(service));
121
+ return value.map((service) => this.#getGraphItem(service));
122
122
  } else {
123
- return this.getGraphItem(value);
123
+ return this.#getGraphItem(value);
124
124
  }
125
125
  }
126
- getGraphItem(service) {
127
- const graphItem = this.serviceToGraphItem.get(service);
126
+ #getGraphItem(service) {
127
+ const graphItem = this.#serviceToGraphItem.get(service);
128
128
  if (!graphItem || graphItem.service !== service) {
129
129
  throw new Error(
130
130
  ErrorId.INTERNAL,
@@ -133,8 +133,8 @@ class Verifier {
133
133
  }
134
134
  return graphItem;
135
135
  }
136
- throwCycleError(item, reason) {
137
- const stack = this.stack;
136
+ #throwCycleError(item, reason) {
137
+ const stack = this.#stack;
138
138
  const ownIndex = stack.findIndex((entry) => entry[0] === item);
139
139
  if (ownIndex === -1) {
140
140
  throw new Error(ErrorId.INTERNAL, "Failed to find cycle participant on the stack.");