@kinotic-ai/core 3.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 +53 -66
- package/dist/index.d.cts +19 -29
- package/dist/index.d.ts +19 -29
- package/dist/index.js +53 -66
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -69,7 +69,7 @@ __export(exports_src, {
|
|
|
69
69
|
receivesContext: () => receivesContext,
|
|
70
70
|
createCRI: () => createCRI,
|
|
71
71
|
createAuthenticatedWebSocketFactory: () => createAuthenticatedWebSocketFactory,
|
|
72
|
-
|
|
72
|
+
Zone: () => Zone,
|
|
73
73
|
Version: () => Version,
|
|
74
74
|
TextEventFactory: () => TextEventFactory,
|
|
75
75
|
Sort: () => Sort,
|
|
@@ -786,54 +786,45 @@ function createDebugLogger(namespace) {
|
|
|
786
786
|
class ServiceIdentifier {
|
|
787
787
|
namespace;
|
|
788
788
|
name;
|
|
789
|
-
|
|
789
|
+
zone;
|
|
790
790
|
scope;
|
|
791
791
|
version;
|
|
792
|
-
|
|
793
|
-
constructor(namespace, name,
|
|
792
|
+
_cri = null;
|
|
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
|
+
}
|
|
794
800
|
this.namespace = namespace;
|
|
795
801
|
this.name = name;
|
|
796
|
-
this.
|
|
802
|
+
this.zone = zone;
|
|
797
803
|
}
|
|
798
804
|
qualifiedName() {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
802
|
-
return this.qualifiedNameFor(this.zones?.[0]);
|
|
803
|
-
}
|
|
804
|
-
cris() {
|
|
805
|
-
if (this._cris == null) {
|
|
806
|
-
const zones = this.zones && this.zones.length > 0 ? this.zones : [undefined];
|
|
807
|
-
this._cris = zones.map((zone) => createCRI("srv" /* SERVICE_DESTINATION_SCHEME */, this.scope || null, this.qualifiedNameFor(zone), null, this.version || null));
|
|
808
|
-
}
|
|
809
|
-
return this._cris;
|
|
805
|
+
const name = this.namespace ? this.namespace + "." + this.name : this.name;
|
|
806
|
+
return this.zone ? this.zone + "." + name : name;
|
|
810
807
|
}
|
|
811
808
|
cri() {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
if (cris.length !== 1 || !cri) {
|
|
815
|
-
throw new Error(`ServiceIdentifier has ${cris.length} cris so there is no single cri`);
|
|
809
|
+
if (this._cri == null) {
|
|
810
|
+
this._cri = createCRI("srv" /* SERVICE_DESTINATION_SCHEME */, this.scope || null, this.qualifiedName(), null, this.version || null);
|
|
816
811
|
}
|
|
817
|
-
return
|
|
818
|
-
}
|
|
819
|
-
qualifiedNameFor(zone) {
|
|
820
|
-
const name = this.namespace ? this.namespace + "." + this.name : this.name;
|
|
821
|
-
return zone ? zone + "." + name : name;
|
|
812
|
+
return this._cri;
|
|
822
813
|
}
|
|
823
814
|
}
|
|
824
815
|
|
|
825
816
|
// packages/core/src/api/ZoneUtil.ts
|
|
826
|
-
var LABEL = "[a-z0-9]([a-z0-
|
|
817
|
+
var LABEL = "[a-z0-9]([a-z0-9-]*[a-z0-9])?";
|
|
827
818
|
var LABEL_PATTERN = new RegExp(`^${LABEL}$`);
|
|
828
819
|
var ZONE_PATTERN = new RegExp(`^${LABEL}(\\.${LABEL})*$`);
|
|
829
820
|
function validateZone(zone) {
|
|
830
821
|
if (!zone || !ZONE_PATTERN.test(zone)) {
|
|
831
|
-
throw new Error(`Invalid zone '${zone}'. Zones must be dot separated labels of lowercase letters, digits, and interior dashes
|
|
822
|
+
throw new Error(`Invalid zone '${zone}'. Zones must be dot separated labels of lowercase letters, digits, and interior dashes`);
|
|
832
823
|
}
|
|
833
824
|
}
|
|
834
825
|
function validateLabel(label) {
|
|
835
826
|
if (!label || !LABEL_PATTERN.test(label)) {
|
|
836
|
-
throw new Error(`Invalid zone label '${label}'. Labels must be lowercase letters, digits, and interior dashes
|
|
827
|
+
throw new Error(`Invalid zone label '${label}'. Labels must be lowercase letters, digits, and interior dashes`);
|
|
837
828
|
}
|
|
838
829
|
}
|
|
839
830
|
|
|
@@ -883,12 +874,10 @@ function Version(version) {
|
|
|
883
874
|
versionRegistry.set(value, version);
|
|
884
875
|
};
|
|
885
876
|
}
|
|
886
|
-
function
|
|
887
|
-
|
|
888
|
-
validateZone(zone);
|
|
889
|
-
}
|
|
877
|
+
function Zone(zone) {
|
|
878
|
+
validateZone(zone);
|
|
890
879
|
return function(value, _context) {
|
|
891
|
-
zonesRegistry.set(value,
|
|
880
|
+
zonesRegistry.set(value, zone);
|
|
892
881
|
};
|
|
893
882
|
}
|
|
894
883
|
function Context(value, _context) {
|
|
@@ -898,29 +887,29 @@ function receivesContext(serviceInstance, methodName) {
|
|
|
898
887
|
const method = serviceInstance[methodName];
|
|
899
888
|
return typeof method === "function" && contextMarkedFunctions.has(method);
|
|
900
889
|
}
|
|
901
|
-
function
|
|
902
|
-
const
|
|
890
|
+
function resolveEffectiveZone(constructor) {
|
|
891
|
+
const declaredZone = findInConstructorChain(zonesRegistry, constructor) ?? Kinotic.defaultZone;
|
|
903
892
|
const prefix = Kinotic.zonePrefix;
|
|
904
|
-
let
|
|
905
|
-
if (prefix != null &&
|
|
906
|
-
|
|
893
|
+
let effectiveZone;
|
|
894
|
+
if (prefix != null && declaredZone != null) {
|
|
895
|
+
effectiveZone = `${prefix}.${declaredZone}`;
|
|
907
896
|
} else if (prefix != null) {
|
|
908
|
-
|
|
897
|
+
effectiveZone = prefix;
|
|
909
898
|
} else {
|
|
910
|
-
|
|
899
|
+
effectiveZone = declaredZone ?? null;
|
|
911
900
|
}
|
|
912
|
-
|
|
913
|
-
validateZone(
|
|
901
|
+
if (effectiveZone != null) {
|
|
902
|
+
validateZone(effectiveZone);
|
|
914
903
|
}
|
|
915
|
-
return
|
|
904
|
+
return effectiveZone;
|
|
916
905
|
}
|
|
917
906
|
function Publish(namespace, name) {
|
|
918
907
|
return function(value, _context) {
|
|
919
908
|
return class extends value {
|
|
920
909
|
constructor(...args) {
|
|
921
910
|
super(...args);
|
|
922
|
-
const
|
|
923
|
-
const serviceIdentifier = new ServiceIdentifier(namespace ?? null, name || value.name,
|
|
911
|
+
const zone = resolveEffectiveZone(this.constructor);
|
|
912
|
+
const serviceIdentifier = new ServiceIdentifier(namespace ?? null, name || value.name, zone ?? undefined);
|
|
924
913
|
const version = findInConstructorChain(versionRegistry, this.constructor);
|
|
925
914
|
if (version) {
|
|
926
915
|
serviceIdentifier.version = version;
|
|
@@ -982,23 +971,21 @@ class ServiceInvocationSupervisor {
|
|
|
982
971
|
throw new Error("Service already started");
|
|
983
972
|
}
|
|
984
973
|
this.active = true;
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
error
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
|
|
1001
|
-
}
|
|
974
|
+
const criBase = this.serviceIdentifier.cri().baseResource();
|
|
975
|
+
this.methodSubscriptions.push(this._eventBus.observe(criBase).subscribe({
|
|
976
|
+
next: async (event) => {
|
|
977
|
+
await this.processEvent(event);
|
|
978
|
+
},
|
|
979
|
+
error: (error) => {
|
|
980
|
+
this.log.error("Event listener error", error);
|
|
981
|
+
this.active = false;
|
|
982
|
+
},
|
|
983
|
+
complete: () => {
|
|
984
|
+
this.log.error("Event listener stopped unexpectedly. Setting supervisor inactive.");
|
|
985
|
+
this.active = false;
|
|
986
|
+
}
|
|
987
|
+
}));
|
|
988
|
+
this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
|
|
1002
989
|
}
|
|
1003
990
|
stop() {
|
|
1004
991
|
if (!this.active) {
|
|
@@ -1128,7 +1115,7 @@ var import_operators2 = require("rxjs/operators");
|
|
|
1128
1115
|
// packages/core/package.json
|
|
1129
1116
|
var package_default = {
|
|
1130
1117
|
name: "@kinotic-ai/core",
|
|
1131
|
-
version: "3.
|
|
1118
|
+
version: "3.1.0",
|
|
1132
1119
|
type: "module",
|
|
1133
1120
|
files: [
|
|
1134
1121
|
"dist"
|
|
@@ -1257,7 +1244,7 @@ class ServiceRegistry {
|
|
|
1257
1244
|
return new ServiceProxy(serviceIdentifier, this);
|
|
1258
1245
|
}
|
|
1259
1246
|
register(serviceIdentifier, service) {
|
|
1260
|
-
const criString = serviceIdentifier.
|
|
1247
|
+
const criString = serviceIdentifier.cri().raw();
|
|
1261
1248
|
if (!this.supervisors.has(criString)) {
|
|
1262
1249
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1263
1250
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
@@ -1266,7 +1253,7 @@ class ServiceRegistry {
|
|
|
1266
1253
|
}
|
|
1267
1254
|
}
|
|
1268
1255
|
unRegister(serviceIdentifier) {
|
|
1269
|
-
const criString = serviceIdentifier.
|
|
1256
|
+
const criString = serviceIdentifier.cri().raw();
|
|
1270
1257
|
const supervisor = this.supervisors.get(criString);
|
|
1271
1258
|
if (supervisor) {
|
|
1272
1259
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
@@ -1353,7 +1340,7 @@ class KinoticSingleton {
|
|
|
1353
1340
|
_eventBus;
|
|
1354
1341
|
serviceRegistry;
|
|
1355
1342
|
zonePrefix = null;
|
|
1356
|
-
|
|
1343
|
+
defaultZone = null;
|
|
1357
1344
|
constructor() {
|
|
1358
1345
|
this._eventBus = new EventBus;
|
|
1359
1346
|
this.serviceRegistry = new ServiceRegistry(this._eventBus);
|
package/dist/index.d.cts
CHANGED
|
@@ -456,32 +456,22 @@ declare function createCRI(scheme: string, scope: string | null, resourceName: s
|
|
|
456
456
|
declare class ServiceIdentifier {
|
|
457
457
|
namespace: string | null;
|
|
458
458
|
name: string;
|
|
459
|
-
|
|
459
|
+
zone?: string;
|
|
460
460
|
scope?: string;
|
|
461
461
|
version?: string;
|
|
462
|
-
private
|
|
463
|
-
constructor(namespace: string | null, name: string,
|
|
462
|
+
private _cri;
|
|
463
|
+
constructor(namespace: string | null, name: string, zone?: string);
|
|
464
464
|
/**
|
|
465
465
|
* Returns the fully qualified name this {@link ServiceIdentifier} is addressed by
|
|
466
466
|
* This is the zone.namespace.name, omitting any part that is not set
|
|
467
467
|
* @return string containing the qualified name
|
|
468
|
-
* @throws if this {@link ServiceIdentifier} has more than one zone and therefore more than
|
|
469
|
-
* one qualified name
|
|
470
468
|
*/
|
|
471
469
|
qualifiedName(): string;
|
|
472
470
|
/**
|
|
473
|
-
* The {@link CRI}s this {@link ServiceIdentifier} is addressable by, one per zone
|
|
474
|
-
* @return the cris for this {@link ServiceIdentifier}, never empty
|
|
475
|
-
*/
|
|
476
|
-
cris(): CRI[];
|
|
477
|
-
/**
|
|
478
471
|
* The {@link CRI} that represents this {@link ServiceIdentifier}
|
|
479
472
|
* @return the cri for this {@link ServiceIdentifier}
|
|
480
|
-
* @throws if this {@link ServiceIdentifier} has more than one zone and therefore more than
|
|
481
|
-
* one cri
|
|
482
473
|
*/
|
|
483
474
|
cri(): CRI;
|
|
484
|
-
private qualifiedNameFor;
|
|
485
475
|
}
|
|
486
476
|
import { Observable as Observable2 } from "rxjs";
|
|
487
477
|
/**
|
|
@@ -599,10 +589,10 @@ interface IKinotic {
|
|
|
599
589
|
*/
|
|
600
590
|
zonePrefix: string | null;
|
|
601
591
|
/**
|
|
602
|
-
* The
|
|
603
|
-
* own, typically loaded from the project package.json `kinotic.
|
|
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.
|
|
604
594
|
*/
|
|
605
|
-
|
|
595
|
+
defaultZone: string | null;
|
|
606
596
|
/**
|
|
607
597
|
* Requests a connection to the given Stomp url
|
|
608
598
|
* @param connectionInfo provides the information needed to connect to the kinoitc server
|
|
@@ -641,7 +631,7 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
641
631
|
*/
|
|
642
632
|
readonly serviceRegistry: ServiceRegistry;
|
|
643
633
|
zonePrefix: string | null;
|
|
644
|
-
|
|
634
|
+
defaultZone: string | null;
|
|
645
635
|
constructor();
|
|
646
636
|
get eventBus(): IEventBus;
|
|
647
637
|
set eventBus(eventBus: IEventBus);
|
|
@@ -685,15 +675,15 @@ declare function Scope(value: Function, _context: ClassGetterDecoratorContext |
|
|
|
685
675
|
*/
|
|
686
676
|
declare function Version(version: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
687
677
|
/**
|
|
688
|
-
* Declares the
|
|
689
|
-
* declared
|
|
690
|
-
* can never leave its own `app.<organizationId>.<applicationId>` zone.
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
* @param
|
|
694
|
-
*
|
|
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`
|
|
695
685
|
*/
|
|
696
|
-
declare function
|
|
686
|
+
declare function Zone(zone: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
697
687
|
/**
|
|
698
688
|
* Marks a service method that receives the {@link ServiceContext} produced by the registered
|
|
699
689
|
* {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
|
|
@@ -708,7 +698,7 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
|
|
|
708
698
|
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
709
699
|
/**
|
|
710
700
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
711
|
-
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link
|
|
701
|
+
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
712
702
|
* on the same class refine the registration.
|
|
713
703
|
* @param namespace the optional namespace the service is published under
|
|
714
704
|
* @param name the service name, defaults to the class name
|
|
@@ -718,14 +708,14 @@ declare function Publish(namespace?: string | null, name?: string): <T extends n
|
|
|
718
708
|
* Validates that the given zone satisfies the zone grammar
|
|
719
709
|
* @param zone the zone to validate
|
|
720
710
|
* @throws if the zone is empty or contains anything other than dot separated labels of
|
|
721
|
-
* lowercase letters, digits, and interior dashes
|
|
711
|
+
* lowercase letters, digits, and interior dashes
|
|
722
712
|
*/
|
|
723
713
|
declare function validateZone(zone: string): void;
|
|
724
714
|
/**
|
|
725
715
|
* Validates that the given value is a single zone label
|
|
726
716
|
* @param label the label to validate
|
|
727
717
|
* @throws if the label is empty or is not a single label of lowercase letters, digits, and
|
|
728
|
-
* interior dashes
|
|
718
|
+
* interior dashes
|
|
729
719
|
*/
|
|
730
720
|
declare function validateLabel(label: string): void;
|
|
731
721
|
/**
|
|
@@ -1246,4 +1236,4 @@ declare class ParticipantConstants {
|
|
|
1246
1236
|
static readonly PARTICIPANT_TYPE_NODE: string;
|
|
1247
1237
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1248
1238
|
}
|
|
1249
|
-
export { validateZone, validateLabel, receivesContext, createCRI, createAuthenticatedWebSocketFactory,
|
|
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
|
@@ -456,32 +456,22 @@ declare function createCRI(scheme: string, scope: string | null, resourceName: s
|
|
|
456
456
|
declare class ServiceIdentifier {
|
|
457
457
|
namespace: string | null;
|
|
458
458
|
name: string;
|
|
459
|
-
|
|
459
|
+
zone?: string;
|
|
460
460
|
scope?: string;
|
|
461
461
|
version?: string;
|
|
462
|
-
private
|
|
463
|
-
constructor(namespace: string | null, name: string,
|
|
462
|
+
private _cri;
|
|
463
|
+
constructor(namespace: string | null, name: string, zone?: string);
|
|
464
464
|
/**
|
|
465
465
|
* Returns the fully qualified name this {@link ServiceIdentifier} is addressed by
|
|
466
466
|
* This is the zone.namespace.name, omitting any part that is not set
|
|
467
467
|
* @return string containing the qualified name
|
|
468
|
-
* @throws if this {@link ServiceIdentifier} has more than one zone and therefore more than
|
|
469
|
-
* one qualified name
|
|
470
468
|
*/
|
|
471
469
|
qualifiedName(): string;
|
|
472
470
|
/**
|
|
473
|
-
* The {@link CRI}s this {@link ServiceIdentifier} is addressable by, one per zone
|
|
474
|
-
* @return the cris for this {@link ServiceIdentifier}, never empty
|
|
475
|
-
*/
|
|
476
|
-
cris(): CRI[];
|
|
477
|
-
/**
|
|
478
471
|
* The {@link CRI} that represents this {@link ServiceIdentifier}
|
|
479
472
|
* @return the cri for this {@link ServiceIdentifier}
|
|
480
|
-
* @throws if this {@link ServiceIdentifier} has more than one zone and therefore more than
|
|
481
|
-
* one cri
|
|
482
473
|
*/
|
|
483
474
|
cri(): CRI;
|
|
484
|
-
private qualifiedNameFor;
|
|
485
475
|
}
|
|
486
476
|
import { Observable as Observable2 } from "rxjs";
|
|
487
477
|
/**
|
|
@@ -599,10 +589,10 @@ interface IKinotic {
|
|
|
599
589
|
*/
|
|
600
590
|
zonePrefix: string | null;
|
|
601
591
|
/**
|
|
602
|
-
* The
|
|
603
|
-
* own, typically loaded from the project package.json `kinotic.
|
|
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.
|
|
604
594
|
*/
|
|
605
|
-
|
|
595
|
+
defaultZone: string | null;
|
|
606
596
|
/**
|
|
607
597
|
* Requests a connection to the given Stomp url
|
|
608
598
|
* @param connectionInfo provides the information needed to connect to the kinoitc server
|
|
@@ -641,7 +631,7 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
641
631
|
*/
|
|
642
632
|
readonly serviceRegistry: ServiceRegistry;
|
|
643
633
|
zonePrefix: string | null;
|
|
644
|
-
|
|
634
|
+
defaultZone: string | null;
|
|
645
635
|
constructor();
|
|
646
636
|
get eventBus(): IEventBus;
|
|
647
637
|
set eventBus(eventBus: IEventBus);
|
|
@@ -685,15 +675,15 @@ declare function Scope(value: Function, _context: ClassGetterDecoratorContext |
|
|
|
685
675
|
*/
|
|
686
676
|
declare function Version(version: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
687
677
|
/**
|
|
688
|
-
* Declares the
|
|
689
|
-
* declared
|
|
690
|
-
* can never leave its own `app.<organizationId>.<applicationId>` zone.
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
* @param
|
|
694
|
-
*
|
|
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`
|
|
695
685
|
*/
|
|
696
|
-
declare function
|
|
686
|
+
declare function Zone(zone: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
697
687
|
/**
|
|
698
688
|
* Marks a service method that receives the {@link ServiceContext} produced by the registered
|
|
699
689
|
* {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
|
|
@@ -708,7 +698,7 @@ declare function Context(value: Function, _context: ClassMethodDecoratorContext)
|
|
|
708
698
|
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
709
699
|
/**
|
|
710
700
|
* Registers each instance of the decorated class with the Kinotic ServiceRegistry.
|
|
711
|
-
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link
|
|
701
|
+
* The service name defaults to the class name; {@link Version}, {@link Scope}, and {@link Zone}
|
|
712
702
|
* on the same class refine the registration.
|
|
713
703
|
* @param namespace the optional namespace the service is published under
|
|
714
704
|
* @param name the service name, defaults to the class name
|
|
@@ -718,14 +708,14 @@ declare function Publish(namespace?: string | null, name?: string): <T extends n
|
|
|
718
708
|
* Validates that the given zone satisfies the zone grammar
|
|
719
709
|
* @param zone the zone to validate
|
|
720
710
|
* @throws if the zone is empty or contains anything other than dot separated labels of
|
|
721
|
-
* lowercase letters, digits, and interior dashes
|
|
711
|
+
* lowercase letters, digits, and interior dashes
|
|
722
712
|
*/
|
|
723
713
|
declare function validateZone(zone: string): void;
|
|
724
714
|
/**
|
|
725
715
|
* Validates that the given value is a single zone label
|
|
726
716
|
* @param label the label to validate
|
|
727
717
|
* @throws if the label is empty or is not a single label of lowercase letters, digits, and
|
|
728
|
-
* interior dashes
|
|
718
|
+
* interior dashes
|
|
729
719
|
*/
|
|
730
720
|
declare function validateLabel(label: string): void;
|
|
731
721
|
/**
|
|
@@ -1246,4 +1236,4 @@ declare class ParticipantConstants {
|
|
|
1246
1236
|
static readonly PARTICIPANT_TYPE_NODE: string;
|
|
1247
1237
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1248
1238
|
}
|
|
1249
|
-
export { validateZone, validateLabel, receivesContext, createCRI, createAuthenticatedWebSocketFactory,
|
|
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,54 +682,45 @@ function createDebugLogger(namespace) {
|
|
|
682
682
|
class ServiceIdentifier {
|
|
683
683
|
namespace;
|
|
684
684
|
name;
|
|
685
|
-
|
|
685
|
+
zone;
|
|
686
686
|
scope;
|
|
687
687
|
version;
|
|
688
|
-
|
|
689
|
-
constructor(namespace, name,
|
|
688
|
+
_cri = null;
|
|
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
|
+
}
|
|
690
696
|
this.namespace = namespace;
|
|
691
697
|
this.name = name;
|
|
692
|
-
this.
|
|
698
|
+
this.zone = zone;
|
|
693
699
|
}
|
|
694
700
|
qualifiedName() {
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
return this.qualifiedNameFor(this.zones?.[0]);
|
|
699
|
-
}
|
|
700
|
-
cris() {
|
|
701
|
-
if (this._cris == null) {
|
|
702
|
-
const zones = this.zones && this.zones.length > 0 ? this.zones : [undefined];
|
|
703
|
-
this._cris = zones.map((zone) => createCRI("srv" /* SERVICE_DESTINATION_SCHEME */, this.scope || null, this.qualifiedNameFor(zone), null, this.version || null));
|
|
704
|
-
}
|
|
705
|
-
return this._cris;
|
|
701
|
+
const name = this.namespace ? this.namespace + "." + this.name : this.name;
|
|
702
|
+
return this.zone ? this.zone + "." + name : name;
|
|
706
703
|
}
|
|
707
704
|
cri() {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
if (cris.length !== 1 || !cri) {
|
|
711
|
-
throw new Error(`ServiceIdentifier has ${cris.length} cris so there is no single cri`);
|
|
705
|
+
if (this._cri == null) {
|
|
706
|
+
this._cri = createCRI("srv" /* SERVICE_DESTINATION_SCHEME */, this.scope || null, this.qualifiedName(), null, this.version || null);
|
|
712
707
|
}
|
|
713
|
-
return
|
|
714
|
-
}
|
|
715
|
-
qualifiedNameFor(zone) {
|
|
716
|
-
const name = this.namespace ? this.namespace + "." + this.name : this.name;
|
|
717
|
-
return zone ? zone + "." + name : name;
|
|
708
|
+
return this._cri;
|
|
718
709
|
}
|
|
719
710
|
}
|
|
720
711
|
|
|
721
712
|
// packages/core/src/api/ZoneUtil.ts
|
|
722
|
-
var LABEL = "[a-z0-9]([a-z0-
|
|
713
|
+
var LABEL = "[a-z0-9]([a-z0-9-]*[a-z0-9])?";
|
|
723
714
|
var LABEL_PATTERN = new RegExp(`^${LABEL}$`);
|
|
724
715
|
var ZONE_PATTERN = new RegExp(`^${LABEL}(\\.${LABEL})*$`);
|
|
725
716
|
function validateZone(zone) {
|
|
726
717
|
if (!zone || !ZONE_PATTERN.test(zone)) {
|
|
727
|
-
throw new Error(`Invalid zone '${zone}'. Zones must be dot separated labels of lowercase letters, digits, and interior dashes
|
|
718
|
+
throw new Error(`Invalid zone '${zone}'. Zones must be dot separated labels of lowercase letters, digits, and interior dashes`);
|
|
728
719
|
}
|
|
729
720
|
}
|
|
730
721
|
function validateLabel(label) {
|
|
731
722
|
if (!label || !LABEL_PATTERN.test(label)) {
|
|
732
|
-
throw new Error(`Invalid zone label '${label}'. Labels must be lowercase letters, digits, and interior dashes
|
|
723
|
+
throw new Error(`Invalid zone label '${label}'. Labels must be lowercase letters, digits, and interior dashes`);
|
|
733
724
|
}
|
|
734
725
|
}
|
|
735
726
|
|
|
@@ -779,12 +770,10 @@ function Version(version) {
|
|
|
779
770
|
versionRegistry.set(value, version);
|
|
780
771
|
};
|
|
781
772
|
}
|
|
782
|
-
function
|
|
783
|
-
|
|
784
|
-
validateZone(zone);
|
|
785
|
-
}
|
|
773
|
+
function Zone(zone) {
|
|
774
|
+
validateZone(zone);
|
|
786
775
|
return function(value, _context) {
|
|
787
|
-
zonesRegistry.set(value,
|
|
776
|
+
zonesRegistry.set(value, zone);
|
|
788
777
|
};
|
|
789
778
|
}
|
|
790
779
|
function Context(value, _context) {
|
|
@@ -794,29 +783,29 @@ function receivesContext(serviceInstance, methodName) {
|
|
|
794
783
|
const method = serviceInstance[methodName];
|
|
795
784
|
return typeof method === "function" && contextMarkedFunctions.has(method);
|
|
796
785
|
}
|
|
797
|
-
function
|
|
798
|
-
const
|
|
786
|
+
function resolveEffectiveZone(constructor) {
|
|
787
|
+
const declaredZone = findInConstructorChain(zonesRegistry, constructor) ?? Kinotic.defaultZone;
|
|
799
788
|
const prefix = Kinotic.zonePrefix;
|
|
800
|
-
let
|
|
801
|
-
if (prefix != null &&
|
|
802
|
-
|
|
789
|
+
let effectiveZone;
|
|
790
|
+
if (prefix != null && declaredZone != null) {
|
|
791
|
+
effectiveZone = `${prefix}.${declaredZone}`;
|
|
803
792
|
} else if (prefix != null) {
|
|
804
|
-
|
|
793
|
+
effectiveZone = prefix;
|
|
805
794
|
} else {
|
|
806
|
-
|
|
795
|
+
effectiveZone = declaredZone ?? null;
|
|
807
796
|
}
|
|
808
|
-
|
|
809
|
-
validateZone(
|
|
797
|
+
if (effectiveZone != null) {
|
|
798
|
+
validateZone(effectiveZone);
|
|
810
799
|
}
|
|
811
|
-
return
|
|
800
|
+
return effectiveZone;
|
|
812
801
|
}
|
|
813
802
|
function Publish(namespace, name) {
|
|
814
803
|
return function(value, _context) {
|
|
815
804
|
return class extends value {
|
|
816
805
|
constructor(...args) {
|
|
817
806
|
super(...args);
|
|
818
|
-
const
|
|
819
|
-
const serviceIdentifier = new ServiceIdentifier(namespace ?? null, name || value.name,
|
|
807
|
+
const zone = resolveEffectiveZone(this.constructor);
|
|
808
|
+
const serviceIdentifier = new ServiceIdentifier(namespace ?? null, name || value.name, zone ?? undefined);
|
|
820
809
|
const version = findInConstructorChain(versionRegistry, this.constructor);
|
|
821
810
|
if (version) {
|
|
822
811
|
serviceIdentifier.version = version;
|
|
@@ -878,23 +867,21 @@ class ServiceInvocationSupervisor {
|
|
|
878
867
|
throw new Error("Service already started");
|
|
879
868
|
}
|
|
880
869
|
this.active = true;
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
error
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
|
|
897
|
-
}
|
|
870
|
+
const criBase = this.serviceIdentifier.cri().baseResource();
|
|
871
|
+
this.methodSubscriptions.push(this._eventBus.observe(criBase).subscribe({
|
|
872
|
+
next: async (event) => {
|
|
873
|
+
await this.processEvent(event);
|
|
874
|
+
},
|
|
875
|
+
error: (error) => {
|
|
876
|
+
this.log.error("Event listener error", error);
|
|
877
|
+
this.active = false;
|
|
878
|
+
},
|
|
879
|
+
complete: () => {
|
|
880
|
+
this.log.error("Event listener stopped unexpectedly. Setting supervisor inactive.");
|
|
881
|
+
this.active = false;
|
|
882
|
+
}
|
|
883
|
+
}));
|
|
884
|
+
this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
|
|
898
885
|
}
|
|
899
886
|
stop() {
|
|
900
887
|
if (!this.active) {
|
|
@@ -1027,7 +1014,7 @@ import { first, map as map2 } from "rxjs/operators";
|
|
|
1027
1014
|
// packages/core/package.json
|
|
1028
1015
|
var package_default = {
|
|
1029
1016
|
name: "@kinotic-ai/core",
|
|
1030
|
-
version: "3.
|
|
1017
|
+
version: "3.1.0",
|
|
1031
1018
|
type: "module",
|
|
1032
1019
|
files: [
|
|
1033
1020
|
"dist"
|
|
@@ -1156,7 +1143,7 @@ class ServiceRegistry {
|
|
|
1156
1143
|
return new ServiceProxy(serviceIdentifier, this);
|
|
1157
1144
|
}
|
|
1158
1145
|
register(serviceIdentifier, service) {
|
|
1159
|
-
const criString = serviceIdentifier.
|
|
1146
|
+
const criString = serviceIdentifier.cri().raw();
|
|
1160
1147
|
if (!this.supervisors.has(criString)) {
|
|
1161
1148
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1162
1149
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
@@ -1165,7 +1152,7 @@ class ServiceRegistry {
|
|
|
1165
1152
|
}
|
|
1166
1153
|
}
|
|
1167
1154
|
unRegister(serviceIdentifier) {
|
|
1168
|
-
const criString = serviceIdentifier.
|
|
1155
|
+
const criString = serviceIdentifier.cri().raw();
|
|
1169
1156
|
const supervisor = this.supervisors.get(criString);
|
|
1170
1157
|
if (supervisor) {
|
|
1171
1158
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
@@ -1252,7 +1239,7 @@ class KinoticSingleton {
|
|
|
1252
1239
|
_eventBus;
|
|
1253
1240
|
serviceRegistry;
|
|
1254
1241
|
zonePrefix = null;
|
|
1255
|
-
|
|
1242
|
+
defaultZone = null;
|
|
1256
1243
|
constructor() {
|
|
1257
1244
|
this._eventBus = new EventBus;
|
|
1258
1245
|
this.serviceRegistry = new ServiceRegistry(this._eventBus);
|
|
@@ -1559,7 +1546,7 @@ export {
|
|
|
1559
1546
|
receivesContext,
|
|
1560
1547
|
createCRI,
|
|
1561
1548
|
createAuthenticatedWebSocketFactory,
|
|
1562
|
-
|
|
1549
|
+
Zone,
|
|
1563
1550
|
Version,
|
|
1564
1551
|
TextEventFactory,
|
|
1565
1552
|
Sort,
|