@kinotic-ai/core 3.1.0 → 5.0.0-beta.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
@@ -67,6 +67,7 @@ __export(exports_src, {
67
67
  validateZone: () => validateZone,
68
68
  validateLabel: () => validateLabel,
69
69
  receivesContext: () => receivesContext,
70
+ isAdvertised: () => isAdvertised,
70
71
  createCRI: () => createCRI,
71
72
  createAuthenticatedWebSocketFactory: () => createAuthenticatedWebSocketFactory,
72
73
  Zone: () => Zone,
@@ -610,12 +611,15 @@ class EventBus {
610
611
  }
611
612
 
612
613
  // packages/core/src/api/ServiceRegistry.ts
613
- var import_debug2 = __toESM(require("debug"));
614
+ var import_debug3 = __toESM(require("debug"));
614
615
 
615
616
  // packages/core/src/api/event/DefaultCRI.ts
617
+ var ZONE_DELIMITER = "~";
618
+
616
619
  class DefaultCRI {
617
620
  _scheme;
618
621
  _scope;
622
+ _zone;
619
623
  _resourceName;
620
624
  _path;
621
625
  _version;
@@ -629,24 +633,42 @@ class DefaultCRI {
629
633
  const parsed = DefaultCRI.parseRaw(rawURC);
630
634
  this._scheme = parsed.scheme;
631
635
  this._scope = parsed.scope;
632
- this._resourceName = parsed.resourceName;
636
+ const [zone, resourceName] = DefaultCRI.splitZone(parsed.resourceName);
637
+ this._zone = zone;
638
+ this._resourceName = resourceName;
633
639
  this._path = parsed.path;
634
640
  this._version = parsed.version;
635
- this._raw = rawURC;
636
641
  } else if (args.length === 5) {
637
642
  const [scheme, scope, resourceName, path, version] = args;
643
+ if (scope && scope.includes("@")) {
644
+ throw new Error(`The scope must not contain '@' but was '${scope}'`);
645
+ }
646
+ if (resourceName.includes("@")) {
647
+ throw new Error(`The resourceName must not contain '@' but was '${resourceName}'`);
648
+ }
638
649
  this._scheme = scheme;
639
- this._scope = scope;
640
- this._resourceName = resourceName;
650
+ this._scope = scope ?? null;
651
+ const [zone, name] = DefaultCRI.splitZone(resourceName);
652
+ this._zone = zone;
653
+ this._resourceName = name;
641
654
  this._path = path;
642
655
  this._version = version;
643
- this._raw = DefaultCRI.buildRaw(scheme, scope, resourceName, path, version);
644
656
  } else {
645
657
  throw new Error("Invalid constructor arguments for DefaultCRI");
646
658
  }
659
+ this._raw = DefaultCRI.buildRaw(this._scheme, this._scope, this._zone, this._resourceName, this._path, this._version);
647
660
  if (!this._scheme || !this._resourceName) {
648
661
  throw new Error(`Invalid CRI: scheme and resourceName are required. Got: ${this._raw}`);
649
662
  }
663
+ if (this._scope !== null && this._scope.includes(ZONE_DELIMITER)) {
664
+ throw new Error(`The scope must not contain '~' but was '${this._scope}'`);
665
+ }
666
+ if (this._resourceName.includes(ZONE_DELIMITER)) {
667
+ throw new Error(`The resourceName must not contain '~' but was '${this._resourceName}'`);
668
+ }
669
+ if (this._resourceName.includes("@") || this._zone !== null && this._zone.includes("@")) {
670
+ throw new Error(`The authority must contain at most one '@' but was '${this._raw}'`);
671
+ }
650
672
  }
651
673
  scheme() {
652
674
  return this._scheme;
@@ -657,6 +679,12 @@ class DefaultCRI {
657
679
  hasScope() {
658
680
  return this._scope !== null;
659
681
  }
682
+ zone() {
683
+ return this._zone;
684
+ }
685
+ hasZone() {
686
+ return this._zone !== null;
687
+ }
660
688
  resourceName() {
661
689
  return this._resourceName;
662
690
  }
@@ -677,6 +705,9 @@ class DefaultCRI {
677
705
  if (this.hasScope()) {
678
706
  result += `${this._scope}@`;
679
707
  }
708
+ if (this.hasZone()) {
709
+ result += `${this._zone}${ZONE_DELIMITER}`;
710
+ }
680
711
  result += this._resourceName;
681
712
  return result;
682
713
  }
@@ -698,6 +729,10 @@ class DefaultCRI {
698
729
  toString() {
699
730
  return this._raw;
700
731
  }
732
+ static splitZone(hostPart) {
733
+ const delimiter = hostPart.indexOf(ZONE_DELIMITER);
734
+ return delimiter >= 0 ? [hostPart.substring(0, delimiter), hostPart.substring(delimiter + 1)] : [null, hostPart];
735
+ }
701
736
  static parseRaw(raw) {
702
737
  const regex = /^([^:]+):\/\/(?:([^@]+)@)?([^\/#]+)(\/[^#]*)?(?:#(.+))?$/;
703
738
  const match = raw.match(regex);
@@ -713,11 +748,14 @@ class DefaultCRI {
713
748
  version: version || null
714
749
  };
715
750
  }
716
- static buildRaw(scheme, scope, resourceName, path, version) {
751
+ static buildRaw(scheme, scope, zone, resourceName, path, version) {
717
752
  let result = `${scheme}://`;
718
753
  if (scope) {
719
754
  result += `${scope}@`;
720
755
  }
756
+ if (zone) {
757
+ result += `${zone}${ZONE_DELIMITER}`;
758
+ }
721
759
  result += resourceName;
722
760
  if (path) {
723
761
  result += `/${path}`;
@@ -766,19 +804,15 @@ class BasicReturnValueConverter {
766
804
  }
767
805
 
768
806
  // packages/core/src/internal/api/Logger.ts
807
+ var import_debug2 = __toESM(require("debug"));
769
808
  function createDebugLogger(namespace) {
770
- let debug2;
771
- try {
772
- debug2 = require("debug")(namespace);
773
- } catch (e) {
774
- debug2 = (...args) => console.debug(`[${namespace}]`, ...args);
775
- }
809
+ const debugLogger = import_debug2.default(namespace);
776
810
  return {
777
- trace: (...args) => debug2("TRACE", ...args),
778
- debug: (...args) => debug2("DEBUG", ...args),
779
- info: (...args) => debug2("INFO", ...args),
780
- warn: (...args) => debug2("WARN", ...args),
781
- error: (...args) => debug2("ERROR", ...args)
811
+ trace: (...args) => debugLogger("TRACE", ...args),
812
+ debug: (...args) => debugLogger("DEBUG", ...args),
813
+ info: (...args) => debugLogger("INFO", ...args),
814
+ warn: (...args) => debugLogger("WARN", ...args),
815
+ error: (...args) => debugLogger("ERROR", ...args)
782
816
  };
783
817
  }
784
818
 
@@ -797,13 +831,19 @@ class ServiceIdentifier {
797
831
  if (namespace != null && namespace.includes("_")) {
798
832
  throw new Error(`The namespace must not contain '_' but was '${namespace}'`);
799
833
  }
834
+ if (name.includes("~")) {
835
+ throw new Error(`The name must not contain '~' but was '${name}'`);
836
+ }
837
+ if (namespace != null && namespace.includes("~")) {
838
+ throw new Error(`The namespace must not contain '~' but was '${namespace}'`);
839
+ }
800
840
  this.namespace = namespace;
801
841
  this.name = name;
802
842
  this.zone = zone;
803
843
  }
804
844
  qualifiedName() {
805
845
  const name = this.namespace ? this.namespace + "." + this.name : this.name;
806
- return this.zone ? this.zone + "." + name : name;
846
+ return this.zone ? this.zone + "~" + name : name;
807
847
  }
808
848
  cri() {
809
849
  if (this._cri == null) {
@@ -832,6 +872,7 @@ function validateLabel(label) {
832
872
  var scopeFunctions = new WeakSet;
833
873
  var versionRegistry = new WeakMap;
834
874
  var zonesRegistry = new WeakMap;
875
+ var advertisedRegistry = new WeakMap;
835
876
  var contextMarkedFunctions = new WeakSet;
836
877
  function findInConstructorChain(registry, constructor) {
837
878
  let current = constructor;
@@ -880,6 +921,9 @@ function Zone(zone) {
880
921
  zonesRegistry.set(value, zone);
881
922
  };
882
923
  }
924
+ function isAdvertised(serviceInstance) {
925
+ return findInConstructorChain(advertisedRegistry, serviceInstance.constructor) === true;
926
+ }
883
927
  function Context(value, _context) {
884
928
  contextMarkedFunctions.add(value);
885
929
  }
@@ -903,8 +947,9 @@ function resolveEffectiveZone(constructor) {
903
947
  }
904
948
  return effectiveZone;
905
949
  }
906
- function Publish(namespace, name) {
950
+ function Publish(namespace, name, advertise = false) {
907
951
  return function(value, _context) {
952
+ advertisedRegistry.set(value, advertise);
908
953
  return class extends value {
909
954
  constructor(...args) {
910
955
  super(...args);
@@ -934,7 +979,7 @@ class ServiceInvocationSupervisor {
934
979
  returnValueConverter;
935
980
  serviceIdentifier;
936
981
  serviceInstance;
937
- methodSubscriptions = [];
982
+ methodSubscription = null;
938
983
  methodMap;
939
984
  constructor(serviceIdentifier, serviceInstance, eventBusService, interceptorProvider, options = {}) {
940
985
  if (!serviceIdentifier)
@@ -972,7 +1017,7 @@ class ServiceInvocationSupervisor {
972
1017
  }
973
1018
  this.active = true;
974
1019
  const criBase = this.serviceIdentifier.cri().baseResource();
975
- this.methodSubscriptions.push(this._eventBus.observe(criBase).subscribe({
1020
+ this.methodSubscription = this._eventBus.observe(criBase).subscribe({
976
1021
  next: async (event) => {
977
1022
  await this.processEvent(event);
978
1023
  },
@@ -984,7 +1029,7 @@ class ServiceInvocationSupervisor {
984
1029
  this.log.error("Event listener stopped unexpectedly. Setting supervisor inactive.");
985
1030
  this.active = false;
986
1031
  }
987
- }));
1032
+ });
988
1033
  this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
989
1034
  }
990
1035
  stop() {
@@ -992,10 +1037,8 @@ class ServiceInvocationSupervisor {
992
1037
  throw new Error("Service already stopped");
993
1038
  }
994
1039
  this.active = false;
995
- for (const subscription of this.methodSubscriptions) {
996
- subscription.unsubscribe();
997
- }
998
- this.methodSubscriptions = [];
1040
+ this.methodSubscription?.unsubscribe();
1041
+ this.methodSubscription = null;
999
1042
  this.log.info("ServiceInvocationSupervisor stopped");
1000
1043
  }
1001
1044
  buildMethodMap(serviceInstance) {
@@ -1115,7 +1158,7 @@ var import_operators2 = require("rxjs/operators");
1115
1158
  // packages/core/package.json
1116
1159
  var package_default = {
1117
1160
  name: "@kinotic-ai/core",
1118
- version: "3.1.0",
1161
+ version: "5.0.0-beta.0",
1119
1162
  type: "module",
1120
1163
  files: [
1121
1164
  "dist"
@@ -1227,7 +1270,7 @@ class ServiceRegistry {
1227
1270
  _eventBus;
1228
1271
  supervisors = new Map;
1229
1272
  contextInterceptor = null;
1230
- debugLogger = import_debug2.default("kinoitc:serviceRegistry");
1273
+ debugLogger = import_debug3.default("kinoitc:serviceRegistry");
1231
1274
  constructor(eventBus) {
1232
1275
  this._eventBus = eventBus;
1233
1276
  }
@@ -1609,8 +1652,12 @@ function createAuthenticatedWebSocketFactory(serverInfo, authProvider) {
1609
1652
  class BasicAuthProvider {
1610
1653
  authHeader;
1611
1654
  constructor(login, passcode) {
1612
- const encoded = Buffer.from(`${login}:${passcode}`).toString("base64");
1613
- this.authHeader = `Basic ${encoded}`;
1655
+ const bytes = new TextEncoder().encode(`${login}:${passcode}`);
1656
+ let binary = "";
1657
+ for (const byte of bytes) {
1658
+ binary += String.fromCharCode(byte);
1659
+ }
1660
+ this.authHeader = `Basic ${btoa(binary)}`;
1614
1661
  }
1615
1662
  getAuthHeaders() {
1616
1663
  return { Authorization: this.authHeader };
package/dist/index.d.cts CHANGED
@@ -338,10 +338,12 @@ interface ContextInterceptor<T extends ServiceContext> {
338
338
  *
339
339
  * Will be in a format as follows where anything surrounded with `[]` is optional:
340
340
  *
341
- * scheme://[scope@]resourceName[/path][#version]
341
+ * scheme://[scope@][zone~]resourceName[/path][#version]
342
342
  *
343
343
  * NOTE: If scope needs to be used to identify a sub-scope, it will follow the form `scope = scope:sub-scope`.
344
344
  *
345
+ * Every part keeps the case it was written with; addresses match by exact string comparison.
346
+ *
345
347
  * This format can have varied meanings based upon the scheme used.
346
348
  *
347
349
  * @author Navid Mitchell
@@ -367,6 +369,23 @@ interface CRI {
367
369
  */
368
370
  hasScope(): boolean;
369
371
  /**
372
+ * The zone this `CRI` is addressed in, or `null` if un-zoned.
373
+ *
374
+ * The zone is the isolation boundary routing is validated against, such as
375
+ * `app.acme-org.orders-app` or `os-api`.
376
+ *
377
+ * For the following CRI, `zone` would be the portion specified by `zone`:
378
+ *
379
+ * `scheme://[scope@][zone~]resourceName/path`
380
+ *
381
+ * @returns a string containing the zone if provided or `null` if not set
382
+ */
383
+ zone(): string | null;
384
+ /**
385
+ * @returns `true` if the `zone` is set
386
+ */
387
+ hasZone(): boolean;
388
+ /**
370
389
  * The name of the resource represented by this `CRI`.
371
390
  *
372
391
  * In the case of a `srv` `CRI`, this will be the service name.
@@ -374,7 +393,7 @@ interface CRI {
374
393
  *
375
394
  * For the following CRI, `resourceName` would be the portion specified by `resourceName`:
376
395
  *
377
- * `scheme://[scope@]resourceName/path`
396
+ * `scheme://[scope@][zone~]resourceName/path`
378
397
  *
379
398
  * @returns the string containing the name of this resource
380
399
  */
@@ -394,7 +413,7 @@ interface CRI {
394
413
  *
395
414
  * For the following CRI, `path` would be the portion specified by `path`:
396
415
  *
397
- * `scheme://[scope@]resourceName/path`
416
+ * `scheme://[scope@][zone~]resourceName/path`
398
417
  *
399
418
  * @returns the path string if provided or `null` if not set
400
419
  */
@@ -406,7 +425,7 @@ interface CRI {
406
425
  /**
407
426
  * Base Resource is a portion of the fully qualified `CRI` containing the following:
408
427
  *
409
- * `scheme://[scope@]resourceName`
428
+ * `scheme://[scope@][zone~]resourceName`
410
429
  *
411
430
  * @returns string containing the baseResource
412
431
  */
@@ -463,7 +482,7 @@ declare class ServiceIdentifier {
463
482
  constructor(namespace: string | null, name: string, zone?: string);
464
483
  /**
465
484
  * 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
485
+ * This is the zone~namespace.name, omitting any part that is not set
467
486
  * @return string containing the qualified name
468
487
  */
469
488
  qualifiedName(): string;
@@ -685,6 +704,11 @@ declare function Version(version: string): (value: Function, _context: ClassDeco
685
704
  */
686
705
  declare function Zone(zone: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
687
706
  /**
707
+ * Returns whether the given service instance's class was published with `advertise` set.
708
+ * @param serviceInstance the service instance to inspect
709
+ */
710
+ declare function isAdvertised(serviceInstance: object): boolean;
711
+ /**
688
712
  * Marks a service method that receives the {@link ServiceContext} produced by the registered
689
713
  * {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
690
714
  * callers do not pass it, and the platform appends it after the caller-supplied arguments.
@@ -702,8 +726,10 @@ declare function receivesContext(serviceInstance: object, methodName: string): b
702
726
  * on the same class refine the registration.
703
727
  * @param namespace the optional namespace the service is published under
704
728
  * @param name the service name, defaults to the class name
729
+ * @param advertise when true the service advertises itself in the platform ServiceDirectory,
730
+ * so it appears in directory listings
705
731
  */
706
- declare function Publish(namespace?: string | null, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
732
+ declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
707
733
  /**
708
734
  * Validates that the given zone satisfies the zone grammar
709
735
  * @param zone the zone to validate
@@ -1087,6 +1113,7 @@ declare class FunctionalIterablePage<T> extends AbstractIterablePage<T> {
1087
1113
  declare class DefaultCRI implements CRI {
1088
1114
  private readonly _scheme;
1089
1115
  private readonly _scope;
1116
+ private readonly _zone;
1090
1117
  private readonly _resourceName;
1091
1118
  private readonly _path;
1092
1119
  private readonly _version;
@@ -1096,6 +1123,8 @@ declare class DefaultCRI implements CRI {
1096
1123
  scheme(): string;
1097
1124
  scope(): string | null;
1098
1125
  hasScope(): boolean;
1126
+ zone(): string | null;
1127
+ hasZone(): boolean;
1099
1128
  resourceName(): string;
1100
1129
  version(): string | null;
1101
1130
  hasVersion(): boolean;
@@ -1106,6 +1135,7 @@ declare class DefaultCRI implements CRI {
1106
1135
  equals(other: any): boolean;
1107
1136
  hashCode(): number;
1108
1137
  toString(): string;
1138
+ private static splitZone;
1109
1139
  private static parseRaw;
1110
1140
  private static buildRaw;
1111
1141
  }
@@ -1236,4 +1266,4 @@ declare class ParticipantConstants {
1236
1266
  static readonly PARTICIPANT_TYPE_NODE: string;
1237
1267
  static readonly CLI_PARTICIPANT_ID: string;
1238
1268
  }
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 };
1269
+ export { validateZone, validateLabel, receivesContext, isAdvertised, 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
@@ -338,10 +338,12 @@ interface ContextInterceptor<T extends ServiceContext> {
338
338
  *
339
339
  * Will be in a format as follows where anything surrounded with `[]` is optional:
340
340
  *
341
- * scheme://[scope@]resourceName[/path][#version]
341
+ * scheme://[scope@][zone~]resourceName[/path][#version]
342
342
  *
343
343
  * NOTE: If scope needs to be used to identify a sub-scope, it will follow the form `scope = scope:sub-scope`.
344
344
  *
345
+ * Every part keeps the case it was written with; addresses match by exact string comparison.
346
+ *
345
347
  * This format can have varied meanings based upon the scheme used.
346
348
  *
347
349
  * @author Navid Mitchell
@@ -367,6 +369,23 @@ interface CRI {
367
369
  */
368
370
  hasScope(): boolean;
369
371
  /**
372
+ * The zone this `CRI` is addressed in, or `null` if un-zoned.
373
+ *
374
+ * The zone is the isolation boundary routing is validated against, such as
375
+ * `app.acme-org.orders-app` or `os-api`.
376
+ *
377
+ * For the following CRI, `zone` would be the portion specified by `zone`:
378
+ *
379
+ * `scheme://[scope@][zone~]resourceName/path`
380
+ *
381
+ * @returns a string containing the zone if provided or `null` if not set
382
+ */
383
+ zone(): string | null;
384
+ /**
385
+ * @returns `true` if the `zone` is set
386
+ */
387
+ hasZone(): boolean;
388
+ /**
370
389
  * The name of the resource represented by this `CRI`.
371
390
  *
372
391
  * In the case of a `srv` `CRI`, this will be the service name.
@@ -374,7 +393,7 @@ interface CRI {
374
393
  *
375
394
  * For the following CRI, `resourceName` would be the portion specified by `resourceName`:
376
395
  *
377
- * `scheme://[scope@]resourceName/path`
396
+ * `scheme://[scope@][zone~]resourceName/path`
378
397
  *
379
398
  * @returns the string containing the name of this resource
380
399
  */
@@ -394,7 +413,7 @@ interface CRI {
394
413
  *
395
414
  * For the following CRI, `path` would be the portion specified by `path`:
396
415
  *
397
- * `scheme://[scope@]resourceName/path`
416
+ * `scheme://[scope@][zone~]resourceName/path`
398
417
  *
399
418
  * @returns the path string if provided or `null` if not set
400
419
  */
@@ -406,7 +425,7 @@ interface CRI {
406
425
  /**
407
426
  * Base Resource is a portion of the fully qualified `CRI` containing the following:
408
427
  *
409
- * `scheme://[scope@]resourceName`
428
+ * `scheme://[scope@][zone~]resourceName`
410
429
  *
411
430
  * @returns string containing the baseResource
412
431
  */
@@ -463,7 +482,7 @@ declare class ServiceIdentifier {
463
482
  constructor(namespace: string | null, name: string, zone?: string);
464
483
  /**
465
484
  * 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
485
+ * This is the zone~namespace.name, omitting any part that is not set
467
486
  * @return string containing the qualified name
468
487
  */
469
488
  qualifiedName(): string;
@@ -685,6 +704,11 @@ declare function Version(version: string): (value: Function, _context: ClassDeco
685
704
  */
686
705
  declare function Zone(zone: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
687
706
  /**
707
+ * Returns whether the given service instance's class was published with `advertise` set.
708
+ * @param serviceInstance the service instance to inspect
709
+ */
710
+ declare function isAdvertised(serviceInstance: object): boolean;
711
+ /**
688
712
  * Marks a service method that receives the {@link ServiceContext} produced by the registered
689
713
  * {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
690
714
  * callers do not pass it, and the platform appends it after the caller-supplied arguments.
@@ -702,8 +726,10 @@ declare function receivesContext(serviceInstance: object, methodName: string): b
702
726
  * on the same class refine the registration.
703
727
  * @param namespace the optional namespace the service is published under
704
728
  * @param name the service name, defaults to the class name
729
+ * @param advertise when true the service advertises itself in the platform ServiceDirectory,
730
+ * so it appears in directory listings
705
731
  */
706
- declare function Publish(namespace?: string | null, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
732
+ declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
707
733
  /**
708
734
  * Validates that the given zone satisfies the zone grammar
709
735
  * @param zone the zone to validate
@@ -1087,6 +1113,7 @@ declare class FunctionalIterablePage<T> extends AbstractIterablePage<T> {
1087
1113
  declare class DefaultCRI implements CRI {
1088
1114
  private readonly _scheme;
1089
1115
  private readonly _scope;
1116
+ private readonly _zone;
1090
1117
  private readonly _resourceName;
1091
1118
  private readonly _path;
1092
1119
  private readonly _version;
@@ -1096,6 +1123,8 @@ declare class DefaultCRI implements CRI {
1096
1123
  scheme(): string;
1097
1124
  scope(): string | null;
1098
1125
  hasScope(): boolean;
1126
+ zone(): string | null;
1127
+ hasZone(): boolean;
1099
1128
  resourceName(): string;
1100
1129
  version(): string | null;
1101
1130
  hasVersion(): boolean;
@@ -1106,6 +1135,7 @@ declare class DefaultCRI implements CRI {
1106
1135
  equals(other: any): boolean;
1107
1136
  hashCode(): number;
1108
1137
  toString(): string;
1138
+ private static splitZone;
1109
1139
  private static parseRaw;
1110
1140
  private static buildRaw;
1111
1141
  }
@@ -1236,4 +1266,4 @@ declare class ParticipantConstants {
1236
1266
  static readonly PARTICIPANT_TYPE_NODE: string;
1237
1267
  static readonly CLI_PARTICIPANT_ID: string;
1238
1268
  }
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 };
1269
+ export { validateZone, validateLabel, receivesContext, isAdvertised, 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
@@ -1,6 +1,3 @@
1
- import { createRequire } from "node:module";
2
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
-
4
1
  // packages/core/src/api/ConnectionInfo.ts
5
2
  class ServerInfo {
6
3
  host;
@@ -506,12 +503,15 @@ class EventBus {
506
503
  }
507
504
 
508
505
  // packages/core/src/api/ServiceRegistry.ts
509
- import debug2 from "debug";
506
+ import debug3 from "debug";
510
507
 
511
508
  // packages/core/src/api/event/DefaultCRI.ts
509
+ var ZONE_DELIMITER = "~";
510
+
512
511
  class DefaultCRI {
513
512
  _scheme;
514
513
  _scope;
514
+ _zone;
515
515
  _resourceName;
516
516
  _path;
517
517
  _version;
@@ -525,24 +525,42 @@ class DefaultCRI {
525
525
  const parsed = DefaultCRI.parseRaw(rawURC);
526
526
  this._scheme = parsed.scheme;
527
527
  this._scope = parsed.scope;
528
- this._resourceName = parsed.resourceName;
528
+ const [zone, resourceName] = DefaultCRI.splitZone(parsed.resourceName);
529
+ this._zone = zone;
530
+ this._resourceName = resourceName;
529
531
  this._path = parsed.path;
530
532
  this._version = parsed.version;
531
- this._raw = rawURC;
532
533
  } else if (args.length === 5) {
533
534
  const [scheme, scope, resourceName, path, version] = args;
535
+ if (scope && scope.includes("@")) {
536
+ throw new Error(`The scope must not contain '@' but was '${scope}'`);
537
+ }
538
+ if (resourceName.includes("@")) {
539
+ throw new Error(`The resourceName must not contain '@' but was '${resourceName}'`);
540
+ }
534
541
  this._scheme = scheme;
535
- this._scope = scope;
536
- this._resourceName = resourceName;
542
+ this._scope = scope ?? null;
543
+ const [zone, name] = DefaultCRI.splitZone(resourceName);
544
+ this._zone = zone;
545
+ this._resourceName = name;
537
546
  this._path = path;
538
547
  this._version = version;
539
- this._raw = DefaultCRI.buildRaw(scheme, scope, resourceName, path, version);
540
548
  } else {
541
549
  throw new Error("Invalid constructor arguments for DefaultCRI");
542
550
  }
551
+ this._raw = DefaultCRI.buildRaw(this._scheme, this._scope, this._zone, this._resourceName, this._path, this._version);
543
552
  if (!this._scheme || !this._resourceName) {
544
553
  throw new Error(`Invalid CRI: scheme and resourceName are required. Got: ${this._raw}`);
545
554
  }
555
+ if (this._scope !== null && this._scope.includes(ZONE_DELIMITER)) {
556
+ throw new Error(`The scope must not contain '~' but was '${this._scope}'`);
557
+ }
558
+ if (this._resourceName.includes(ZONE_DELIMITER)) {
559
+ throw new Error(`The resourceName must not contain '~' but was '${this._resourceName}'`);
560
+ }
561
+ if (this._resourceName.includes("@") || this._zone !== null && this._zone.includes("@")) {
562
+ throw new Error(`The authority must contain at most one '@' but was '${this._raw}'`);
563
+ }
546
564
  }
547
565
  scheme() {
548
566
  return this._scheme;
@@ -553,6 +571,12 @@ class DefaultCRI {
553
571
  hasScope() {
554
572
  return this._scope !== null;
555
573
  }
574
+ zone() {
575
+ return this._zone;
576
+ }
577
+ hasZone() {
578
+ return this._zone !== null;
579
+ }
556
580
  resourceName() {
557
581
  return this._resourceName;
558
582
  }
@@ -573,6 +597,9 @@ class DefaultCRI {
573
597
  if (this.hasScope()) {
574
598
  result += `${this._scope}@`;
575
599
  }
600
+ if (this.hasZone()) {
601
+ result += `${this._zone}${ZONE_DELIMITER}`;
602
+ }
576
603
  result += this._resourceName;
577
604
  return result;
578
605
  }
@@ -594,6 +621,10 @@ class DefaultCRI {
594
621
  toString() {
595
622
  return this._raw;
596
623
  }
624
+ static splitZone(hostPart) {
625
+ const delimiter = hostPart.indexOf(ZONE_DELIMITER);
626
+ return delimiter >= 0 ? [hostPart.substring(0, delimiter), hostPart.substring(delimiter + 1)] : [null, hostPart];
627
+ }
597
628
  static parseRaw(raw) {
598
629
  const regex = /^([^:]+):\/\/(?:([^@]+)@)?([^\/#]+)(\/[^#]*)?(?:#(.+))?$/;
599
630
  const match = raw.match(regex);
@@ -609,11 +640,14 @@ class DefaultCRI {
609
640
  version: version || null
610
641
  };
611
642
  }
612
- static buildRaw(scheme, scope, resourceName, path, version) {
643
+ static buildRaw(scheme, scope, zone, resourceName, path, version) {
613
644
  let result = `${scheme}://`;
614
645
  if (scope) {
615
646
  result += `${scope}@`;
616
647
  }
648
+ if (zone) {
649
+ result += `${zone}${ZONE_DELIMITER}`;
650
+ }
617
651
  result += resourceName;
618
652
  if (path) {
619
653
  result += `/${path}`;
@@ -662,19 +696,15 @@ class BasicReturnValueConverter {
662
696
  }
663
697
 
664
698
  // packages/core/src/internal/api/Logger.ts
699
+ import debug2 from "debug";
665
700
  function createDebugLogger(namespace) {
666
- let debug2;
667
- try {
668
- debug2 = __require("debug")(namespace);
669
- } catch (e) {
670
- debug2 = (...args) => console.debug(`[${namespace}]`, ...args);
671
- }
701
+ const debugLogger = debug2(namespace);
672
702
  return {
673
- trace: (...args) => debug2("TRACE", ...args),
674
- debug: (...args) => debug2("DEBUG", ...args),
675
- info: (...args) => debug2("INFO", ...args),
676
- warn: (...args) => debug2("WARN", ...args),
677
- error: (...args) => debug2("ERROR", ...args)
703
+ trace: (...args) => debugLogger("TRACE", ...args),
704
+ debug: (...args) => debugLogger("DEBUG", ...args),
705
+ info: (...args) => debugLogger("INFO", ...args),
706
+ warn: (...args) => debugLogger("WARN", ...args),
707
+ error: (...args) => debugLogger("ERROR", ...args)
678
708
  };
679
709
  }
680
710
 
@@ -693,13 +723,19 @@ class ServiceIdentifier {
693
723
  if (namespace != null && namespace.includes("_")) {
694
724
  throw new Error(`The namespace must not contain '_' but was '${namespace}'`);
695
725
  }
726
+ if (name.includes("~")) {
727
+ throw new Error(`The name must not contain '~' but was '${name}'`);
728
+ }
729
+ if (namespace != null && namespace.includes("~")) {
730
+ throw new Error(`The namespace must not contain '~' but was '${namespace}'`);
731
+ }
696
732
  this.namespace = namespace;
697
733
  this.name = name;
698
734
  this.zone = zone;
699
735
  }
700
736
  qualifiedName() {
701
737
  const name = this.namespace ? this.namespace + "." + this.name : this.name;
702
- return this.zone ? this.zone + "." + name : name;
738
+ return this.zone ? this.zone + "~" + name : name;
703
739
  }
704
740
  cri() {
705
741
  if (this._cri == null) {
@@ -728,6 +764,7 @@ function validateLabel(label) {
728
764
  var scopeFunctions = new WeakSet;
729
765
  var versionRegistry = new WeakMap;
730
766
  var zonesRegistry = new WeakMap;
767
+ var advertisedRegistry = new WeakMap;
731
768
  var contextMarkedFunctions = new WeakSet;
732
769
  function findInConstructorChain(registry, constructor) {
733
770
  let current = constructor;
@@ -776,6 +813,9 @@ function Zone(zone) {
776
813
  zonesRegistry.set(value, zone);
777
814
  };
778
815
  }
816
+ function isAdvertised(serviceInstance) {
817
+ return findInConstructorChain(advertisedRegistry, serviceInstance.constructor) === true;
818
+ }
779
819
  function Context(value, _context) {
780
820
  contextMarkedFunctions.add(value);
781
821
  }
@@ -799,8 +839,9 @@ function resolveEffectiveZone(constructor) {
799
839
  }
800
840
  return effectiveZone;
801
841
  }
802
- function Publish(namespace, name) {
842
+ function Publish(namespace, name, advertise = false) {
803
843
  return function(value, _context) {
844
+ advertisedRegistry.set(value, advertise);
804
845
  return class extends value {
805
846
  constructor(...args) {
806
847
  super(...args);
@@ -830,7 +871,7 @@ class ServiceInvocationSupervisor {
830
871
  returnValueConverter;
831
872
  serviceIdentifier;
832
873
  serviceInstance;
833
- methodSubscriptions = [];
874
+ methodSubscription = null;
834
875
  methodMap;
835
876
  constructor(serviceIdentifier, serviceInstance, eventBusService, interceptorProvider, options = {}) {
836
877
  if (!serviceIdentifier)
@@ -868,7 +909,7 @@ class ServiceInvocationSupervisor {
868
909
  }
869
910
  this.active = true;
870
911
  const criBase = this.serviceIdentifier.cri().baseResource();
871
- this.methodSubscriptions.push(this._eventBus.observe(criBase).subscribe({
912
+ this.methodSubscription = this._eventBus.observe(criBase).subscribe({
872
913
  next: async (event) => {
873
914
  await this.processEvent(event);
874
915
  },
@@ -880,7 +921,7 @@ class ServiceInvocationSupervisor {
880
921
  this.log.error("Event listener stopped unexpectedly. Setting supervisor inactive.");
881
922
  this.active = false;
882
923
  }
883
- }));
924
+ });
884
925
  this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
885
926
  }
886
927
  stop() {
@@ -888,10 +929,8 @@ class ServiceInvocationSupervisor {
888
929
  throw new Error("Service already stopped");
889
930
  }
890
931
  this.active = false;
891
- for (const subscription of this.methodSubscriptions) {
892
- subscription.unsubscribe();
893
- }
894
- this.methodSubscriptions = [];
932
+ this.methodSubscription?.unsubscribe();
933
+ this.methodSubscription = null;
895
934
  this.log.info("ServiceInvocationSupervisor stopped");
896
935
  }
897
936
  buildMethodMap(serviceInstance) {
@@ -1014,7 +1053,7 @@ import { first, map as map2 } from "rxjs/operators";
1014
1053
  // packages/core/package.json
1015
1054
  var package_default = {
1016
1055
  name: "@kinotic-ai/core",
1017
- version: "3.1.0",
1056
+ version: "5.0.0-beta.0",
1018
1057
  type: "module",
1019
1058
  files: [
1020
1059
  "dist"
@@ -1126,7 +1165,7 @@ class ServiceRegistry {
1126
1165
  _eventBus;
1127
1166
  supervisors = new Map;
1128
1167
  contextInterceptor = null;
1129
- debugLogger = debug2("kinoitc:serviceRegistry");
1168
+ debugLogger = debug3("kinoitc:serviceRegistry");
1130
1169
  constructor(eventBus) {
1131
1170
  this._eventBus = eventBus;
1132
1171
  }
@@ -1508,8 +1547,12 @@ function createAuthenticatedWebSocketFactory(serverInfo, authProvider) {
1508
1547
  class BasicAuthProvider {
1509
1548
  authHeader;
1510
1549
  constructor(login, passcode) {
1511
- const encoded = Buffer.from(`${login}:${passcode}`).toString("base64");
1512
- this.authHeader = `Basic ${encoded}`;
1550
+ const bytes = new TextEncoder().encode(`${login}:${passcode}`);
1551
+ let binary = "";
1552
+ for (const byte of bytes) {
1553
+ binary += String.fromCharCode(byte);
1554
+ }
1555
+ this.authHeader = `Basic ${btoa(binary)}`;
1513
1556
  }
1514
1557
  getAuthHeaders() {
1515
1558
  return { Authorization: this.authHeader };
@@ -1544,6 +1587,7 @@ export {
1544
1587
  validateZone,
1545
1588
  validateLabel,
1546
1589
  receivesContext,
1590
+ isAdvertised,
1547
1591
  createCRI,
1548
1592
  createAuthenticatedWebSocketFactory,
1549
1593
  Zone,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinotic-ai/core",
3
- "version": "3.1.0",
3
+ "version": "5.0.0-beta.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"