@kinotic-ai/core 2.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -64,9 +64,12 @@ var __export = (target, all) => {
64
64
  // packages/core/src/index.ts
65
65
  var exports_src = {};
66
66
  __export(exports_src, {
67
+ validateZone: () => validateZone,
68
+ validateLabel: () => validateLabel,
67
69
  receivesContext: () => receivesContext,
68
70
  createCRI: () => createCRI,
69
71
  createAuthenticatedWebSocketFactory: () => createAuthenticatedWebSocketFactory,
72
+ Zone: () => Zone,
70
73
  Version: () => Version,
71
74
  TextEventFactory: () => TextEventFactory,
72
75
  Sort: () => Sort,
@@ -783,15 +786,24 @@ function createDebugLogger(namespace) {
783
786
  class ServiceIdentifier {
784
787
  namespace;
785
788
  name;
789
+ zone;
786
790
  scope;
787
791
  version;
788
792
  _cri = null;
789
- constructor(namespace, name) {
793
+ constructor(namespace, name, zone) {
794
+ if (name.includes(".")) {
795
+ throw new Error(`The name must not contain '.' but was '${name}'`);
796
+ }
797
+ if (namespace != null && namespace.includes("_")) {
798
+ throw new Error(`The namespace must not contain '_' but was '${namespace}'`);
799
+ }
790
800
  this.namespace = namespace;
791
801
  this.name = name;
802
+ this.zone = zone;
792
803
  }
793
804
  qualifiedName() {
794
- return this.namespace + "." + this.name;
805
+ const name = this.namespace ? this.namespace + "." + this.name : this.name;
806
+ return this.zone ? this.zone + "." + name : name;
795
807
  }
796
808
  cri() {
797
809
  if (this._cri == null) {
@@ -801,9 +813,25 @@ class ServiceIdentifier {
801
813
  }
802
814
  }
803
815
 
816
+ // packages/core/src/api/ZoneUtil.ts
817
+ var LABEL = "[a-z0-9]([a-z0-9-]*[a-z0-9])?";
818
+ var LABEL_PATTERN = new RegExp(`^${LABEL}$`);
819
+ var ZONE_PATTERN = new RegExp(`^${LABEL}(\\.${LABEL})*$`);
820
+ function validateZone(zone) {
821
+ if (!zone || !ZONE_PATTERN.test(zone)) {
822
+ throw new Error(`Invalid zone '${zone}'. Zones must be dot separated labels of lowercase letters, digits, and interior dashes`);
823
+ }
824
+ }
825
+ function validateLabel(label) {
826
+ if (!label || !LABEL_PATTERN.test(label)) {
827
+ throw new Error(`Invalid zone label '${label}'. Labels must be lowercase letters, digits, and interior dashes`);
828
+ }
829
+ }
830
+
804
831
  // packages/core/src/api/KinoticDecorators.ts
805
832
  var scopeFunctions = new WeakSet;
806
833
  var versionRegistry = new WeakMap;
834
+ var zonesRegistry = new WeakMap;
807
835
  var contextMarkedFunctions = new WeakSet;
808
836
  function findInConstructorChain(registry, constructor) {
809
837
  let current = constructor;
@@ -846,6 +874,12 @@ function Version(version) {
846
874
  versionRegistry.set(value, version);
847
875
  };
848
876
  }
877
+ function Zone(zone) {
878
+ validateZone(zone);
879
+ return function(value, _context) {
880
+ zonesRegistry.set(value, zone);
881
+ };
882
+ }
849
883
  function Context(value, _context) {
850
884
  contextMarkedFunctions.add(value);
851
885
  }
@@ -853,12 +887,29 @@ function receivesContext(serviceInstance, methodName) {
853
887
  const method = serviceInstance[methodName];
854
888
  return typeof method === "function" && contextMarkedFunctions.has(method);
855
889
  }
890
+ function resolveEffectiveZone(constructor) {
891
+ const declaredZone = findInConstructorChain(zonesRegistry, constructor) ?? Kinotic.defaultZone;
892
+ const prefix = Kinotic.zonePrefix;
893
+ let effectiveZone;
894
+ if (prefix != null && declaredZone != null) {
895
+ effectiveZone = `${prefix}.${declaredZone}`;
896
+ } else if (prefix != null) {
897
+ effectiveZone = prefix;
898
+ } else {
899
+ effectiveZone = declaredZone ?? null;
900
+ }
901
+ if (effectiveZone != null) {
902
+ validateZone(effectiveZone);
903
+ }
904
+ return effectiveZone;
905
+ }
856
906
  function Publish(namespace, name) {
857
907
  return function(value, _context) {
858
908
  return class extends value {
859
909
  constructor(...args) {
860
910
  super(...args);
861
- const serviceIdentifier = new ServiceIdentifier(namespace, name || value.name);
911
+ const zone = resolveEffectiveZone(this.constructor);
912
+ const serviceIdentifier = new ServiceIdentifier(namespace ?? null, name || value.name, zone ?? undefined);
862
913
  const version = findInConstructorChain(versionRegistry, this.constructor);
863
914
  if (version) {
864
915
  serviceIdentifier.version = version;
@@ -883,7 +934,7 @@ class ServiceInvocationSupervisor {
883
934
  returnValueConverter;
884
935
  serviceIdentifier;
885
936
  serviceInstance;
886
- methodSubscription = null;
937
+ methodSubscriptions = [];
887
938
  methodMap;
888
939
  constructor(serviceIdentifier, serviceInstance, eventBusService, interceptorProvider, options = {}) {
889
940
  if (!serviceIdentifier)
@@ -921,7 +972,7 @@ class ServiceInvocationSupervisor {
921
972
  }
922
973
  this.active = true;
923
974
  const criBase = this.serviceIdentifier.cri().baseResource();
924
- this.methodSubscription = this._eventBus.observe(criBase).subscribe({
975
+ this.methodSubscriptions.push(this._eventBus.observe(criBase).subscribe({
925
976
  next: async (event) => {
926
977
  await this.processEvent(event);
927
978
  },
@@ -933,7 +984,7 @@ class ServiceInvocationSupervisor {
933
984
  this.log.error("Event listener stopped unexpectedly. Setting supervisor inactive.");
934
985
  this.active = false;
935
986
  }
936
- });
987
+ }));
937
988
  this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
938
989
  }
939
990
  stop() {
@@ -941,10 +992,10 @@ class ServiceInvocationSupervisor {
941
992
  throw new Error("Service already stopped");
942
993
  }
943
994
  this.active = false;
944
- if (this.methodSubscription) {
945
- this.methodSubscription.unsubscribe();
946
- this.methodSubscription = null;
995
+ for (const subscription of this.methodSubscriptions) {
996
+ subscription.unsubscribe();
947
997
  }
998
+ this.methodSubscriptions = [];
948
999
  this.log.info("ServiceInvocationSupervisor stopped");
949
1000
  }
950
1001
  buildMethodMap(serviceInstance) {
@@ -1064,7 +1115,7 @@ var import_operators2 = require("rxjs/operators");
1064
1115
  // packages/core/package.json
1065
1116
  var package_default = {
1066
1117
  name: "@kinotic-ai/core",
1067
- version: "2.0.0",
1118
+ version: "3.1.0",
1068
1119
  type: "module",
1069
1120
  files: [
1070
1121
  "dist"
@@ -1288,6 +1339,8 @@ class ServiceProxy {
1288
1339
  class KinoticSingleton {
1289
1340
  _eventBus;
1290
1341
  serviceRegistry;
1342
+ zonePrefix = null;
1343
+ defaultZone = null;
1291
1344
  constructor() {
1292
1345
  this._eventBus = new EventBus;
1293
1346
  this.serviceRegistry = new ServiceRegistry(this._eventBus);
package/dist/index.d.cts CHANGED
@@ -454,15 +454,16 @@ declare function createCRI(scheme: string, scope: string | null, resourceName: s
454
454
  */
455
455
  declare function createCRI(scheme: string, scope: string | null, resourceName: string, path: string | null, version: string | null): CRI;
456
456
  declare class ServiceIdentifier {
457
- namespace: string;
457
+ namespace: string | null;
458
458
  name: string;
459
+ zone?: string;
459
460
  scope?: string;
460
461
  version?: string;
461
462
  private _cri;
462
- constructor(namespace: string, name: string);
463
+ constructor(namespace: string | null, name: string, zone?: string);
463
464
  /**
464
- * Returns the qualified name for this {@link ServiceIdentifier}
465
- * This is the namespace.name
465
+ * Returns the fully qualified name this {@link ServiceIdentifier} is addressed by
466
+ * This is the zone.namespace.name, omitting any part that is not set
466
467
  * @return string containing the qualified name
467
468
  */
468
469
  qualifiedName(): string;
@@ -581,6 +582,18 @@ interface IKinotic {
581
582
  serviceRegistry: IServiceRegistry;
582
583
  eventBus: IEventBus;
583
584
  /**
585
+ * The zone prefix every service published by this client registers under, such as
586
+ * `app.<organizationId>.<applicationId>` for an application or `system` for a platform
587
+ * workload. Must be set from static configuration before service classes are instantiated.
588
+ * When null, services register at un-zoned legacy addresses.
589
+ */
590
+ zonePrefix: string | null;
591
+ /**
592
+ * The zone applied to published services that carry no {@link Zone} declaration of their
593
+ * own, typically loaded from the project package.json `kinotic.zone` field.
594
+ */
595
+ defaultZone: string | null;
596
+ /**
584
597
  * Requests a connection to the given Stomp url
585
598
  * @param connectionInfo provides the information needed to connect to the kinoitc server
586
599
  * @return Promise containing the result of the initial connection attempt
@@ -617,6 +630,8 @@ declare class KinoticSingleton implements IKinotic {
617
630
  * The {@link ServiceRegistry} that is used to manage the services that are available
618
631
  */
619
632
  readonly serviceRegistry: ServiceRegistry;
633
+ zonePrefix: string | null;
634
+ defaultZone: string | null;
620
635
  constructor();
621
636
  get eventBus(): IEventBus;
622
637
  set eventBus(eventBus: IEventBus);
@@ -660,6 +675,16 @@ declare function Scope(value: Function, _context: ClassGetterDecoratorContext |
660
675
  */
661
676
  declare function Version(version: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
662
677
  /**
678
+ * Declares the zone a service is addressable in, relative to this client's trust context: the
679
+ * declared zone is appended to {@link KinoticSingleton#zonePrefix}, so an application's service
680
+ * can never leave its own `app.<organizationId>.<applicationId>` zone. When absent,
681
+ * {@link KinoticSingleton#defaultZone} (typically loaded from the project package.json
682
+ * `kinotic.zone` field) applies.
683
+ * @param zone one or more dot separated labels of lowercase letters, digits, and interior
684
+ * dashes, e.g. `billing` or `billing.internal`
685
+ */
686
+ declare function Zone(zone: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
687
+ /**
663
688
  * Marks a service method that receives the {@link ServiceContext} produced by the registered
664
689
  * {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
665
690
  * callers do not pass it, and the platform appends it after the caller-supplied arguments.
@@ -672,13 +697,27 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
672
697
  */
673
698
  declare function receivesContext(serviceInstance: object, methodName: string): boolean;
674
699
  /**
675
- * Registers each instance of the decorated class with the Kinotic ServiceRegistry under the
676
- * given namespace. The service name defaults to the class name; {@link Version} and
677
- * {@link Scope} on the same class refine the registration.
678
- * @param namespace the namespace the service is published under
700
+ * Registers each instance of the decorated class with the Kinotic ServiceRegistry.
701
+ * The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
702
+ * on the same class refine the registration.
703
+ * @param namespace the optional namespace the service is published under
679
704
  * @param name the service name, defaults to the class name
680
705
  */
681
- declare function Publish(namespace: string, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
706
+ declare function Publish(namespace?: string | null, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
707
+ /**
708
+ * Validates that the given zone satisfies the zone grammar
709
+ * @param zone the zone to validate
710
+ * @throws if the zone is empty or contains anything other than dot separated labels of
711
+ * lowercase letters, digits, and interior dashes
712
+ */
713
+ declare function validateZone(zone: string): void;
714
+ /**
715
+ * Validates that the given value is a single zone label
716
+ * @param label the label to validate
717
+ * @throws if the label is empty or is not a single label of lowercase letters, digits, and
718
+ * interior dashes
719
+ */
720
+ declare function validateLabel(label: string): void;
682
721
  /**
683
722
  * A page is a sublist of a list of objects.
684
723
  * @author Navid Mitchell
@@ -1197,4 +1236,4 @@ declare class ParticipantConstants {
1197
1236
  static readonly PARTICIPANT_TYPE_NODE: string;
1198
1237
  static readonly CLI_PARTICIPANT_ID: string;
1199
1238
  }
1200
- export { receivesContext, createCRI, createAuthenticatedWebSocketFactory, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, IAuthProvider, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
1239
+ export { validateZone, validateLabel, receivesContext, createCRI, createAuthenticatedWebSocketFactory, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, IAuthProvider, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
package/dist/index.d.ts CHANGED
@@ -454,15 +454,16 @@ declare function createCRI(scheme: string, scope: string | null, resourceName: s
454
454
  */
455
455
  declare function createCRI(scheme: string, scope: string | null, resourceName: string, path: string | null, version: string | null): CRI;
456
456
  declare class ServiceIdentifier {
457
- namespace: string;
457
+ namespace: string | null;
458
458
  name: string;
459
+ zone?: string;
459
460
  scope?: string;
460
461
  version?: string;
461
462
  private _cri;
462
- constructor(namespace: string, name: string);
463
+ constructor(namespace: string | null, name: string, zone?: string);
463
464
  /**
464
- * Returns the qualified name for this {@link ServiceIdentifier}
465
- * This is the namespace.name
465
+ * Returns the fully qualified name this {@link ServiceIdentifier} is addressed by
466
+ * This is the zone.namespace.name, omitting any part that is not set
466
467
  * @return string containing the qualified name
467
468
  */
468
469
  qualifiedName(): string;
@@ -581,6 +582,18 @@ interface IKinotic {
581
582
  serviceRegistry: IServiceRegistry;
582
583
  eventBus: IEventBus;
583
584
  /**
585
+ * The zone prefix every service published by this client registers under, such as
586
+ * `app.<organizationId>.<applicationId>` for an application or `system` for a platform
587
+ * workload. Must be set from static configuration before service classes are instantiated.
588
+ * When null, services register at un-zoned legacy addresses.
589
+ */
590
+ zonePrefix: string | null;
591
+ /**
592
+ * The zone applied to published services that carry no {@link Zone} declaration of their
593
+ * own, typically loaded from the project package.json `kinotic.zone` field.
594
+ */
595
+ defaultZone: string | null;
596
+ /**
584
597
  * Requests a connection to the given Stomp url
585
598
  * @param connectionInfo provides the information needed to connect to the kinoitc server
586
599
  * @return Promise containing the result of the initial connection attempt
@@ -617,6 +630,8 @@ declare class KinoticSingleton implements IKinotic {
617
630
  * The {@link ServiceRegistry} that is used to manage the services that are available
618
631
  */
619
632
  readonly serviceRegistry: ServiceRegistry;
633
+ zonePrefix: string | null;
634
+ defaultZone: string | null;
620
635
  constructor();
621
636
  get eventBus(): IEventBus;
622
637
  set eventBus(eventBus: IEventBus);
@@ -660,6 +675,16 @@ declare function Scope(value: Function, _context: ClassGetterDecoratorContext |
660
675
  */
661
676
  declare function Version(version: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
662
677
  /**
678
+ * Declares the zone a service is addressable in, relative to this client's trust context: the
679
+ * declared zone is appended to {@link KinoticSingleton#zonePrefix}, so an application's service
680
+ * can never leave its own `app.<organizationId>.<applicationId>` zone. When absent,
681
+ * {@link KinoticSingleton#defaultZone} (typically loaded from the project package.json
682
+ * `kinotic.zone` field) applies.
683
+ * @param zone one or more dot separated labels of lowercase letters, digits, and interior
684
+ * dashes, e.g. `billing` or `billing.internal`
685
+ */
686
+ declare function Zone(zone: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
687
+ /**
663
688
  * Marks a service method that receives the {@link ServiceContext} produced by the registered
664
689
  * {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
665
690
  * callers do not pass it, and the platform appends it after the caller-supplied arguments.
@@ -672,13 +697,27 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
672
697
  */
673
698
  declare function receivesContext(serviceInstance: object, methodName: string): boolean;
674
699
  /**
675
- * Registers each instance of the decorated class with the Kinotic ServiceRegistry under the
676
- * given namespace. The service name defaults to the class name; {@link Version} and
677
- * {@link Scope} on the same class refine the registration.
678
- * @param namespace the namespace the service is published under
700
+ * Registers each instance of the decorated class with the Kinotic ServiceRegistry.
701
+ * The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
702
+ * on the same class refine the registration.
703
+ * @param namespace the optional namespace the service is published under
679
704
  * @param name the service name, defaults to the class name
680
705
  */
681
- declare function Publish(namespace: string, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
706
+ declare function Publish(namespace?: string | null, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
707
+ /**
708
+ * Validates that the given zone satisfies the zone grammar
709
+ * @param zone the zone to validate
710
+ * @throws if the zone is empty or contains anything other than dot separated labels of
711
+ * lowercase letters, digits, and interior dashes
712
+ */
713
+ declare function validateZone(zone: string): void;
714
+ /**
715
+ * Validates that the given value is a single zone label
716
+ * @param label the label to validate
717
+ * @throws if the label is empty or is not a single label of lowercase letters, digits, and
718
+ * interior dashes
719
+ */
720
+ declare function validateLabel(label: string): void;
682
721
  /**
683
722
  * A page is a sublist of a list of objects.
684
723
  * @author Navid Mitchell
@@ -1197,4 +1236,4 @@ declare class ParticipantConstants {
1197
1236
  static readonly PARTICIPANT_TYPE_NODE: string;
1198
1237
  static readonly CLI_PARTICIPANT_ID: string;
1199
1238
  }
1200
- export { receivesContext, createCRI, createAuthenticatedWebSocketFactory, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, IAuthProvider, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
1239
+ export { validateZone, validateLabel, receivesContext, createCRI, createAuthenticatedWebSocketFactory, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, IAuthProvider, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
package/dist/index.js CHANGED
@@ -682,15 +682,24 @@ function createDebugLogger(namespace) {
682
682
  class ServiceIdentifier {
683
683
  namespace;
684
684
  name;
685
+ zone;
685
686
  scope;
686
687
  version;
687
688
  _cri = null;
688
- constructor(namespace, name) {
689
+ constructor(namespace, name, zone) {
690
+ if (name.includes(".")) {
691
+ throw new Error(`The name must not contain '.' but was '${name}'`);
692
+ }
693
+ if (namespace != null && namespace.includes("_")) {
694
+ throw new Error(`The namespace must not contain '_' but was '${namespace}'`);
695
+ }
689
696
  this.namespace = namespace;
690
697
  this.name = name;
698
+ this.zone = zone;
691
699
  }
692
700
  qualifiedName() {
693
- return this.namespace + "." + this.name;
701
+ const name = this.namespace ? this.namespace + "." + this.name : this.name;
702
+ return this.zone ? this.zone + "." + name : name;
694
703
  }
695
704
  cri() {
696
705
  if (this._cri == null) {
@@ -700,9 +709,25 @@ class ServiceIdentifier {
700
709
  }
701
710
  }
702
711
 
712
+ // packages/core/src/api/ZoneUtil.ts
713
+ var LABEL = "[a-z0-9]([a-z0-9-]*[a-z0-9])?";
714
+ var LABEL_PATTERN = new RegExp(`^${LABEL}$`);
715
+ var ZONE_PATTERN = new RegExp(`^${LABEL}(\\.${LABEL})*$`);
716
+ function validateZone(zone) {
717
+ if (!zone || !ZONE_PATTERN.test(zone)) {
718
+ throw new Error(`Invalid zone '${zone}'. Zones must be dot separated labels of lowercase letters, digits, and interior dashes`);
719
+ }
720
+ }
721
+ function validateLabel(label) {
722
+ if (!label || !LABEL_PATTERN.test(label)) {
723
+ throw new Error(`Invalid zone label '${label}'. Labels must be lowercase letters, digits, and interior dashes`);
724
+ }
725
+ }
726
+
703
727
  // packages/core/src/api/KinoticDecorators.ts
704
728
  var scopeFunctions = new WeakSet;
705
729
  var versionRegistry = new WeakMap;
730
+ var zonesRegistry = new WeakMap;
706
731
  var contextMarkedFunctions = new WeakSet;
707
732
  function findInConstructorChain(registry, constructor) {
708
733
  let current = constructor;
@@ -745,6 +770,12 @@ function Version(version) {
745
770
  versionRegistry.set(value, version);
746
771
  };
747
772
  }
773
+ function Zone(zone) {
774
+ validateZone(zone);
775
+ return function(value, _context) {
776
+ zonesRegistry.set(value, zone);
777
+ };
778
+ }
748
779
  function Context(value, _context) {
749
780
  contextMarkedFunctions.add(value);
750
781
  }
@@ -752,12 +783,29 @@ function receivesContext(serviceInstance, methodName) {
752
783
  const method = serviceInstance[methodName];
753
784
  return typeof method === "function" && contextMarkedFunctions.has(method);
754
785
  }
786
+ function resolveEffectiveZone(constructor) {
787
+ const declaredZone = findInConstructorChain(zonesRegistry, constructor) ?? Kinotic.defaultZone;
788
+ const prefix = Kinotic.zonePrefix;
789
+ let effectiveZone;
790
+ if (prefix != null && declaredZone != null) {
791
+ effectiveZone = `${prefix}.${declaredZone}`;
792
+ } else if (prefix != null) {
793
+ effectiveZone = prefix;
794
+ } else {
795
+ effectiveZone = declaredZone ?? null;
796
+ }
797
+ if (effectiveZone != null) {
798
+ validateZone(effectiveZone);
799
+ }
800
+ return effectiveZone;
801
+ }
755
802
  function Publish(namespace, name) {
756
803
  return function(value, _context) {
757
804
  return class extends value {
758
805
  constructor(...args) {
759
806
  super(...args);
760
- const serviceIdentifier = new ServiceIdentifier(namespace, name || value.name);
807
+ const zone = resolveEffectiveZone(this.constructor);
808
+ const serviceIdentifier = new ServiceIdentifier(namespace ?? null, name || value.name, zone ?? undefined);
761
809
  const version = findInConstructorChain(versionRegistry, this.constructor);
762
810
  if (version) {
763
811
  serviceIdentifier.version = version;
@@ -782,7 +830,7 @@ class ServiceInvocationSupervisor {
782
830
  returnValueConverter;
783
831
  serviceIdentifier;
784
832
  serviceInstance;
785
- methodSubscription = null;
833
+ methodSubscriptions = [];
786
834
  methodMap;
787
835
  constructor(serviceIdentifier, serviceInstance, eventBusService, interceptorProvider, options = {}) {
788
836
  if (!serviceIdentifier)
@@ -820,7 +868,7 @@ class ServiceInvocationSupervisor {
820
868
  }
821
869
  this.active = true;
822
870
  const criBase = this.serviceIdentifier.cri().baseResource();
823
- this.methodSubscription = this._eventBus.observe(criBase).subscribe({
871
+ this.methodSubscriptions.push(this._eventBus.observe(criBase).subscribe({
824
872
  next: async (event) => {
825
873
  await this.processEvent(event);
826
874
  },
@@ -832,7 +880,7 @@ class ServiceInvocationSupervisor {
832
880
  this.log.error("Event listener stopped unexpectedly. Setting supervisor inactive.");
833
881
  this.active = false;
834
882
  }
835
- });
883
+ }));
836
884
  this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
837
885
  }
838
886
  stop() {
@@ -840,10 +888,10 @@ class ServiceInvocationSupervisor {
840
888
  throw new Error("Service already stopped");
841
889
  }
842
890
  this.active = false;
843
- if (this.methodSubscription) {
844
- this.methodSubscription.unsubscribe();
845
- this.methodSubscription = null;
891
+ for (const subscription of this.methodSubscriptions) {
892
+ subscription.unsubscribe();
846
893
  }
894
+ this.methodSubscriptions = [];
847
895
  this.log.info("ServiceInvocationSupervisor stopped");
848
896
  }
849
897
  buildMethodMap(serviceInstance) {
@@ -966,7 +1014,7 @@ import { first, map as map2 } from "rxjs/operators";
966
1014
  // packages/core/package.json
967
1015
  var package_default = {
968
1016
  name: "@kinotic-ai/core",
969
- version: "2.0.0",
1017
+ version: "3.1.0",
970
1018
  type: "module",
971
1019
  files: [
972
1020
  "dist"
@@ -1190,6 +1238,8 @@ class ServiceProxy {
1190
1238
  class KinoticSingleton {
1191
1239
  _eventBus;
1192
1240
  serviceRegistry;
1241
+ zonePrefix = null;
1242
+ defaultZone = null;
1193
1243
  constructor() {
1194
1244
  this._eventBus = new EventBus;
1195
1245
  this.serviceRegistry = new ServiceRegistry(this._eventBus);
@@ -1491,9 +1541,12 @@ class ParticipantConstants {
1491
1541
  static CLI_PARTICIPANT_ID = "-42-Kinotic-CLI-42-";
1492
1542
  }
1493
1543
  export {
1544
+ validateZone,
1545
+ validateLabel,
1494
1546
  receivesContext,
1495
1547
  createCRI,
1496
1548
  createAuthenticatedWebSocketFactory,
1549
+ Zone,
1497
1550
  Version,
1498
1551
  TextEventFactory,
1499
1552
  Sort,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinotic-ai/core",
3
- "version": "2.0.0",
3
+ "version": "3.1.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"