@cadenza.io/service 2.17.75 → 2.17.77

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.
@@ -1212,39 +1212,12 @@ var ServiceRegistry = class _ServiceRegistry {
1212
1212
  if (trackedInstance?.isFrontend) {
1213
1213
  return true;
1214
1214
  }
1215
- const trackedTransport = this.getRouteableTransport(
1216
- trackedInstance,
1217
- this.useSocket ? "socket" : "rest"
1218
- );
1219
1215
  if (this.deputies.has(serviceName) || this.remoteIntents.has(serviceName) || this.remoteSignals.has(serviceName)) {
1220
- const communicationTypes = Array.from(
1221
- new Set(
1222
- this.deputies.get(serviceName)?.map((d) => d.communicationType) ?? []
1223
- )
1216
+ const connected = this.ensureDependeeClientForInstance(
1217
+ trackedInstance,
1218
+ emit
1224
1219
  );
1225
- if (!communicationTypes.includes("signal") && this.remoteSignals.has(serviceName)) {
1226
- communicationTypes.push("signal");
1227
- }
1228
- if (trackedTransport) {
1229
- const clientCreated = this.hasTransportClientCreated(
1230
- trackedInstance,
1231
- trackedTransport.uuid
1232
- );
1233
- if (!clientCreated) {
1234
- emit("meta.service_registry.dependee_registered", {
1235
- serviceName,
1236
- serviceInstanceId: uuid7,
1237
- serviceTransportId: trackedTransport.uuid,
1238
- serviceOrigin: trackedTransport.origin,
1239
- transportProtocols: trackedTransport.protocols,
1240
- communicationTypes
1241
- });
1242
- this.markTransportClientCreated(
1243
- trackedInstance,
1244
- trackedTransport.uuid
1245
- );
1246
- }
1247
- } else {
1220
+ if (!connected) {
1248
1221
  emit("meta.service_registry.routeable_transport_missing", {
1249
1222
  serviceName,
1250
1223
  serviceInstanceId: uuid7,
@@ -1310,25 +1283,7 @@ var ServiceRegistry = class _ServiceRegistry {
1310
1283
  if (!hasRemoteInterest) {
1311
1284
  return true;
1312
1285
  }
1313
- if (!this.hasTransportClientCreated(ownerInstance, transport.uuid)) {
1314
- const communicationTypes = Array.from(
1315
- new Set(
1316
- this.deputies.get(ownerInstance.serviceName)?.map((descriptor) => descriptor.communicationType) ?? []
1317
- )
1318
- );
1319
- if (!communicationTypes.includes("signal") && this.remoteSignals.has(ownerInstance.serviceName)) {
1320
- communicationTypes.push("signal");
1321
- }
1322
- emit("meta.service_registry.dependee_registered", {
1323
- serviceName: ownerInstance.serviceName,
1324
- serviceInstanceId: ownerInstance.uuid,
1325
- serviceTransportId: transport.uuid,
1326
- serviceOrigin: transport.origin,
1327
- transportProtocols: transport.protocols,
1328
- communicationTypes
1329
- });
1330
- this.markTransportClientCreated(ownerInstance, transport.uuid);
1331
- }
1286
+ this.ensureDependeeClientForInstance(ownerInstance, emit);
1332
1287
  return true;
1333
1288
  },
1334
1289
  "Handles service transport updates independently from instance rows."
@@ -1357,11 +1312,13 @@ var ServiceRegistry = class _ServiceRegistry {
1357
1312
  },
1358
1313
  "Tracks remote dependency instances for runtime heartbeat monitoring."
1359
1314
  ).doOn("meta.service_registry.dependee_registered");
1315
+ const normalizeServiceInstancesFromSync = (ctx) => this.normalizeServiceInstancesFromSync(ctx);
1360
1316
  CadenzaService.createMetaTask("Split service instances", function* (ctx) {
1361
- if (!ctx.serviceInstances) {
1317
+ const serviceInstances = normalizeServiceInstancesFromSync(ctx);
1318
+ if (serviceInstances.length === 0) {
1362
1319
  return;
1363
1320
  }
1364
- for (const serviceInstance of ctx.serviceInstances) {
1321
+ for (const serviceInstance of serviceInstances) {
1365
1322
  yield { serviceInstance };
1366
1323
  }
1367
1324
  }).doOn(
@@ -1409,7 +1366,7 @@ var ServiceRegistry = class _ServiceRegistry {
1409
1366
  ).emits("meta.service_registry.registered_global_signals").doOn("global.meta.cadenza_db.gathered_sync_data");
1410
1367
  this.handleGlobalIntentRegistrationTask = CadenzaService.createMetaTask(
1411
1368
  "Handle global intent registration",
1412
- (ctx) => {
1369
+ (ctx, emit) => {
1413
1370
  const intentToTaskMaps = this.normalizeIntentMaps(ctx);
1414
1371
  const sorted = intentToTaskMaps.sort((a, b) => {
1415
1372
  if (a.deleted && !b.deleted) return -1;
@@ -1425,6 +1382,7 @@ var ServiceRegistry = class _ServiceRegistry {
1425
1382
  name: map.intentName
1426
1383
  });
1427
1384
  this.registerRemoteIntentDeputy(map);
1385
+ this.ensureDependeeClientsForService(map.serviceName, emit);
1428
1386
  }
1429
1387
  return true;
1430
1388
  },
@@ -2850,6 +2808,49 @@ var ServiceRegistry = class _ServiceRegistry {
2850
2808
  }
2851
2809
  return buildTransportClientKey(transport);
2852
2810
  }
2811
+ resolveCommunicationTypesForService(serviceName) {
2812
+ const communicationTypes = Array.from(
2813
+ new Set(
2814
+ this.deputies.get(serviceName)?.map((descriptor) => descriptor.communicationType) ?? []
2815
+ )
2816
+ );
2817
+ if (!communicationTypes.includes("signal") && this.remoteSignals.has(serviceName)) {
2818
+ communicationTypes.push("signal");
2819
+ }
2820
+ return communicationTypes;
2821
+ }
2822
+ ensureDependeeClientForInstance(instance, emit) {
2823
+ if (!instance || instance.uuid === this.serviceInstanceId || instance.isFrontend || !instance.isActive || instance.isNonResponsive || instance.isBlocked) {
2824
+ return false;
2825
+ }
2826
+ if (!this.deputies.has(instance.serviceName) && !this.remoteIntents.has(instance.serviceName) && !this.remoteSignals.has(instance.serviceName)) {
2827
+ return false;
2828
+ }
2829
+ const transport = this.getRouteableTransport(
2830
+ instance,
2831
+ this.useSocket ? "socket" : "rest"
2832
+ );
2833
+ if (!transport || this.hasTransportClientCreated(instance, transport.uuid)) {
2834
+ return false;
2835
+ }
2836
+ emit("meta.service_registry.dependee_registered", {
2837
+ serviceName: instance.serviceName,
2838
+ serviceInstanceId: instance.uuid,
2839
+ serviceTransportId: transport.uuid,
2840
+ serviceOrigin: transport.origin,
2841
+ transportProtocols: transport.protocols,
2842
+ communicationTypes: this.resolveCommunicationTypesForService(
2843
+ instance.serviceName
2844
+ )
2845
+ });
2846
+ this.markTransportClientCreated(instance, transport.uuid);
2847
+ return true;
2848
+ }
2849
+ ensureDependeeClientsForService(serviceName, emit) {
2850
+ for (const instance of this.instances.get(serviceName) ?? []) {
2851
+ this.ensureDependeeClientForInstance(instance, emit);
2852
+ }
2853
+ }
2853
2854
  hasTransportClientCreated(instance, transportId) {
2854
2855
  return (instance.clientCreatedTransportIds ?? []).includes(transportId);
2855
2856
  }