@kinotic-ai/core 1.9.1 → 3.0.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 +162 -69
- package/dist/index.d.cts +86 -11
- package/dist/index.d.ts +86 -11
- package/dist/index.js +162 -69
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -64,8 +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,
|
|
69
|
+
receivesContext: () => receivesContext,
|
|
67
70
|
createCRI: () => createCRI,
|
|
68
71
|
createAuthenticatedWebSocketFactory: () => createAuthenticatedWebSocketFactory,
|
|
72
|
+
Zones: () => Zones,
|
|
69
73
|
Version: () => Version,
|
|
70
74
|
TextEventFactory: () => TextEventFactory,
|
|
71
75
|
Sort: () => Sort,
|
|
@@ -95,7 +99,6 @@ __export(exports_src, {
|
|
|
95
99
|
Context: () => Context,
|
|
96
100
|
ConnectionInfo: () => ConnectionInfo,
|
|
97
101
|
ConnectedInfo: () => ConnectedInfo,
|
|
98
|
-
CONTEXT_METADATA_KEY: () => CONTEXT_METADATA_KEY,
|
|
99
102
|
BearerTokenAuthProvider: () => BearerTokenAuthProvider,
|
|
100
103
|
BasicAuthProvider: () => BasicAuthProvider,
|
|
101
104
|
AbstractIterablePage: () => AbstractIterablePage
|
|
@@ -779,73 +782,156 @@ function createDebugLogger(namespace) {
|
|
|
779
782
|
};
|
|
780
783
|
}
|
|
781
784
|
|
|
782
|
-
// packages/core/src/api/KinoticDecorators.ts
|
|
783
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
784
|
-
|
|
785
785
|
// packages/core/src/api/ServiceIdentifier.ts
|
|
786
786
|
class ServiceIdentifier {
|
|
787
787
|
namespace;
|
|
788
788
|
name;
|
|
789
|
+
zones;
|
|
789
790
|
scope;
|
|
790
791
|
version;
|
|
791
|
-
|
|
792
|
-
constructor(namespace, name) {
|
|
792
|
+
_cris = null;
|
|
793
|
+
constructor(namespace, name, zones) {
|
|
793
794
|
this.namespace = namespace;
|
|
794
795
|
this.name = name;
|
|
796
|
+
this.zones = zones;
|
|
795
797
|
}
|
|
796
798
|
qualifiedName() {
|
|
797
|
-
|
|
799
|
+
if (this.zones && this.zones.length > 1) {
|
|
800
|
+
throw new Error(`ServiceIdentifier has ${this.zones.length} zones so there is no single qualifiedName`);
|
|
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;
|
|
798
810
|
}
|
|
799
811
|
cri() {
|
|
800
|
-
|
|
801
|
-
|
|
812
|
+
const cris = this.cris();
|
|
813
|
+
const cri = cris[0];
|
|
814
|
+
if (cris.length !== 1 || !cri) {
|
|
815
|
+
throw new Error(`ServiceIdentifier has ${cris.length} cris so there is no single cri`);
|
|
802
816
|
}
|
|
803
|
-
return
|
|
817
|
+
return cri;
|
|
818
|
+
}
|
|
819
|
+
qualifiedNameFor(zone) {
|
|
820
|
+
const name = this.namespace ? this.namespace + "." + this.name : this.name;
|
|
821
|
+
return zone ? zone + "." + name : name;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// packages/core/src/api/ZoneUtil.ts
|
|
826
|
+
var LABEL = "[a-z0-9]([a-z0-9_-]*[a-z0-9])?";
|
|
827
|
+
var LABEL_PATTERN = new RegExp(`^${LABEL}$`);
|
|
828
|
+
var ZONE_PATTERN = new RegExp(`^${LABEL}(\\.${LABEL})*$`);
|
|
829
|
+
function validateZone(zone) {
|
|
830
|
+
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 or underscores`);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
function validateLabel(label) {
|
|
835
|
+
if (!label || !LABEL_PATTERN.test(label)) {
|
|
836
|
+
throw new Error(`Invalid zone label '${label}'. Labels must be lowercase letters, digits, and interior dashes or underscores`);
|
|
804
837
|
}
|
|
805
838
|
}
|
|
806
839
|
|
|
807
840
|
// packages/core/src/api/KinoticDecorators.ts
|
|
808
|
-
var
|
|
809
|
-
var
|
|
810
|
-
var
|
|
811
|
-
|
|
812
|
-
|
|
841
|
+
var scopeFunctions = new WeakSet;
|
|
842
|
+
var versionRegistry = new WeakMap;
|
|
843
|
+
var zonesRegistry = new WeakMap;
|
|
844
|
+
var contextMarkedFunctions = new WeakSet;
|
|
845
|
+
function findInConstructorChain(registry, constructor) {
|
|
846
|
+
let current = constructor;
|
|
847
|
+
while (current) {
|
|
848
|
+
const value = registry.get(current);
|
|
849
|
+
if (value !== undefined) {
|
|
850
|
+
return value;
|
|
851
|
+
}
|
|
852
|
+
current = Object.getPrototypeOf(current);
|
|
853
|
+
}
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
function resolveScope(instance) {
|
|
857
|
+
let proto = Object.getPrototypeOf(instance);
|
|
858
|
+
while (proto && proto !== Object.prototype) {
|
|
859
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
860
|
+
if (key === "constructor") {
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
864
|
+
if (descriptor?.get && scopeFunctions.has(descriptor.get)) {
|
|
865
|
+
return descriptor.get.call(instance);
|
|
866
|
+
}
|
|
867
|
+
if (typeof descriptor?.value === "function" && scopeFunctions.has(descriptor.value)) {
|
|
868
|
+
return descriptor.value.call(instance);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
proto = Object.getPrototypeOf(proto);
|
|
872
|
+
}
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
function Scope(value, _context) {
|
|
876
|
+
scopeFunctions.add(value);
|
|
813
877
|
}
|
|
814
878
|
function Version(version) {
|
|
815
879
|
if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?$/.test(version)) {
|
|
816
880
|
throw new Error(`Invalid semantic version: ${version}. Must follow X.Y.Z[-optional] format.`);
|
|
817
881
|
}
|
|
818
|
-
return function(
|
|
819
|
-
|
|
882
|
+
return function(value, _context) {
|
|
883
|
+
versionRegistry.set(value, version);
|
|
820
884
|
};
|
|
821
885
|
}
|
|
822
|
-
function
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
886
|
+
function Zones(zones) {
|
|
887
|
+
for (const zone of zones) {
|
|
888
|
+
validateZone(zone);
|
|
889
|
+
}
|
|
890
|
+
return function(value, _context) {
|
|
891
|
+
zonesRegistry.set(value, zones);
|
|
827
892
|
};
|
|
828
893
|
}
|
|
894
|
+
function Context(value, _context) {
|
|
895
|
+
contextMarkedFunctions.add(value);
|
|
896
|
+
}
|
|
897
|
+
function receivesContext(serviceInstance, methodName) {
|
|
898
|
+
const method = serviceInstance[methodName];
|
|
899
|
+
return typeof method === "function" && contextMarkedFunctions.has(method);
|
|
900
|
+
}
|
|
901
|
+
function resolveEffectiveZones(constructor) {
|
|
902
|
+
const declaredZones = findInConstructorChain(zonesRegistry, constructor) ?? Kinotic.defaultZones ?? [];
|
|
903
|
+
const prefix = Kinotic.zonePrefix;
|
|
904
|
+
let effectiveZones;
|
|
905
|
+
if (prefix != null && declaredZones.length > 0) {
|
|
906
|
+
effectiveZones = declaredZones.map((zone) => `${prefix}.${zone}`);
|
|
907
|
+
} else if (prefix != null) {
|
|
908
|
+
effectiveZones = [prefix];
|
|
909
|
+
} else {
|
|
910
|
+
effectiveZones = [...declaredZones];
|
|
911
|
+
}
|
|
912
|
+
for (const zone of effectiveZones) {
|
|
913
|
+
validateZone(zone);
|
|
914
|
+
}
|
|
915
|
+
return effectiveZones;
|
|
916
|
+
}
|
|
829
917
|
function Publish(namespace, name) {
|
|
830
|
-
return function(
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
918
|
+
return function(value, _context) {
|
|
919
|
+
return class extends value {
|
|
920
|
+
constructor(...args) {
|
|
921
|
+
super(...args);
|
|
922
|
+
const zones = resolveEffectiveZones(this.constructor);
|
|
923
|
+
const serviceIdentifier = new ServiceIdentifier(namespace ?? null, name || value.name, zones.length > 0 ? zones : undefined);
|
|
924
|
+
const version = findInConstructorChain(versionRegistry, this.constructor);
|
|
925
|
+
if (version) {
|
|
926
|
+
serviceIdentifier.version = version;
|
|
927
|
+
}
|
|
928
|
+
const scope = resolveScope(this);
|
|
929
|
+
if (scope !== undefined) {
|
|
930
|
+
serviceIdentifier.scope = scope;
|
|
931
|
+
}
|
|
932
|
+
Kinotic.serviceRegistry.register(serviceIdentifier, this);
|
|
843
933
|
}
|
|
844
|
-
Kinotic.serviceRegistry.register(serviceIdentifier, instance);
|
|
845
|
-
return instance;
|
|
846
934
|
};
|
|
847
|
-
newConstructor.prototype = original.prototype;
|
|
848
|
-
return newConstructor;
|
|
849
935
|
};
|
|
850
936
|
}
|
|
851
937
|
|
|
@@ -859,7 +945,7 @@ class ServiceInvocationSupervisor {
|
|
|
859
945
|
returnValueConverter;
|
|
860
946
|
serviceIdentifier;
|
|
861
947
|
serviceInstance;
|
|
862
|
-
|
|
948
|
+
methodSubscriptions = [];
|
|
863
949
|
methodMap;
|
|
864
950
|
constructor(serviceIdentifier, serviceInstance, eventBusService, interceptorProvider, options = {}) {
|
|
865
951
|
if (!serviceIdentifier)
|
|
@@ -896,40 +982,46 @@ class ServiceInvocationSupervisor {
|
|
|
896
982
|
throw new Error("Service already started");
|
|
897
983
|
}
|
|
898
984
|
this.active = true;
|
|
899
|
-
const
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
985
|
+
for (const cri of this.serviceIdentifier.cris()) {
|
|
986
|
+
const criBase = cri.baseResource();
|
|
987
|
+
this.methodSubscriptions.push(this._eventBus.observe(criBase).subscribe({
|
|
988
|
+
next: async (event) => {
|
|
989
|
+
await this.processEvent(event);
|
|
990
|
+
},
|
|
991
|
+
error: (error) => {
|
|
992
|
+
this.log.error("Event listener error", error);
|
|
993
|
+
this.active = false;
|
|
994
|
+
},
|
|
995
|
+
complete: () => {
|
|
996
|
+
this.log.error("Event listener stopped unexpectedly. Setting supervisor inactive.");
|
|
997
|
+
this.active = false;
|
|
998
|
+
}
|
|
999
|
+
}));
|
|
1000
|
+
this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
|
|
1001
|
+
}
|
|
914
1002
|
}
|
|
915
1003
|
stop() {
|
|
916
1004
|
if (!this.active) {
|
|
917
1005
|
throw new Error("Service already stopped");
|
|
918
1006
|
}
|
|
919
1007
|
this.active = false;
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
this.methodSubscription = null;
|
|
1008
|
+
for (const subscription of this.methodSubscriptions) {
|
|
1009
|
+
subscription.unsubscribe();
|
|
923
1010
|
}
|
|
1011
|
+
this.methodSubscriptions = [];
|
|
924
1012
|
this.log.info("ServiceInvocationSupervisor stopped");
|
|
925
1013
|
}
|
|
926
1014
|
buildMethodMap(serviceInstance) {
|
|
927
1015
|
const methodMap = {};
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1016
|
+
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1017
|
+
while (proto && proto !== Object.prototype) {
|
|
1018
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1019
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1020
|
+
if (typeof descriptor?.value === "function" && key !== "constructor" && !methodMap[key]) {
|
|
1021
|
+
methodMap[key] = descriptor.value.bind(serviceInstance);
|
|
1022
|
+
}
|
|
932
1023
|
}
|
|
1024
|
+
proto = Object.getPrototypeOf(proto);
|
|
933
1025
|
}
|
|
934
1026
|
return methodMap;
|
|
935
1027
|
}
|
|
@@ -969,7 +1061,7 @@ class ServiceInvocationSupervisor {
|
|
|
969
1061
|
}
|
|
970
1062
|
const methodName = path;
|
|
971
1063
|
const args = this.argumentResolver.resolveArguments(event);
|
|
972
|
-
const
|
|
1064
|
+
const injectContext = receivesContext(this.serviceInstance, methodName);
|
|
973
1065
|
let context2 = {};
|
|
974
1066
|
const interceptor = this.interceptorProvider();
|
|
975
1067
|
if (interceptor) {
|
|
@@ -981,8 +1073,8 @@ class ServiceInvocationSupervisor {
|
|
|
981
1073
|
return;
|
|
982
1074
|
}
|
|
983
1075
|
}
|
|
984
|
-
|
|
985
|
-
args
|
|
1076
|
+
if (injectContext) {
|
|
1077
|
+
args.push(context2);
|
|
986
1078
|
}
|
|
987
1079
|
const expectedArgsCount = handlerMethod.length;
|
|
988
1080
|
if (args.length !== expectedArgsCount) {
|
|
@@ -1036,7 +1128,7 @@ var import_operators2 = require("rxjs/operators");
|
|
|
1036
1128
|
// packages/core/package.json
|
|
1037
1129
|
var package_default = {
|
|
1038
1130
|
name: "@kinotic-ai/core",
|
|
1039
|
-
version: "
|
|
1131
|
+
version: "3.0.0",
|
|
1040
1132
|
type: "module",
|
|
1041
1133
|
files: [
|
|
1042
1134
|
"dist"
|
|
@@ -1098,7 +1190,6 @@ var package_default = {
|
|
|
1098
1190
|
"@types/debug": "^4.1.13",
|
|
1099
1191
|
debug: "^4.4.3",
|
|
1100
1192
|
"p-tap": "^4.0.0",
|
|
1101
|
-
"reflect-metadata": "^0.2.2",
|
|
1102
1193
|
rxjs: "^7.8.2",
|
|
1103
1194
|
"typescript-optional": "3.0.0-alpha.3",
|
|
1104
1195
|
uuid: "^13.0.0"
|
|
@@ -1166,7 +1257,7 @@ class ServiceRegistry {
|
|
|
1166
1257
|
return new ServiceProxy(serviceIdentifier, this);
|
|
1167
1258
|
}
|
|
1168
1259
|
register(serviceIdentifier, service) {
|
|
1169
|
-
const criString = serviceIdentifier.
|
|
1260
|
+
const criString = serviceIdentifier.cris().map((cri) => cri.raw()).join(", ");
|
|
1170
1261
|
if (!this.supervisors.has(criString)) {
|
|
1171
1262
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1172
1263
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
@@ -1175,7 +1266,7 @@ class ServiceRegistry {
|
|
|
1175
1266
|
}
|
|
1176
1267
|
}
|
|
1177
1268
|
unRegister(serviceIdentifier) {
|
|
1178
|
-
const criString = serviceIdentifier.
|
|
1269
|
+
const criString = serviceIdentifier.cris().map((cri) => cri.raw()).join(", ");
|
|
1179
1270
|
const supervisor = this.supervisors.get(criString);
|
|
1180
1271
|
if (supervisor) {
|
|
1181
1272
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
@@ -1261,6 +1352,8 @@ class ServiceProxy {
|
|
|
1261
1352
|
class KinoticSingleton {
|
|
1262
1353
|
_eventBus;
|
|
1263
1354
|
serviceRegistry;
|
|
1355
|
+
zonePrefix = null;
|
|
1356
|
+
defaultZones = null;
|
|
1264
1357
|
constructor() {
|
|
1265
1358
|
this._eventBus = new EventBus;
|
|
1266
1359
|
this.serviceRegistry = new ServiceRegistry(this._eventBus);
|
package/dist/index.d.cts
CHANGED
|
@@ -454,23 +454,34 @@ 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
|
+
zones?: string[];
|
|
459
460
|
scope?: string;
|
|
460
461
|
version?: string;
|
|
461
|
-
private
|
|
462
|
-
constructor(namespace: string, name: string);
|
|
462
|
+
private _cris;
|
|
463
|
+
constructor(namespace: string | null, name: string, zones?: string[]);
|
|
463
464
|
/**
|
|
464
|
-
* Returns the qualified name
|
|
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
|
|
468
|
+
* @throws if this {@link ServiceIdentifier} has more than one zone and therefore more than
|
|
469
|
+
* one qualified name
|
|
467
470
|
*/
|
|
468
471
|
qualifiedName(): string;
|
|
469
472
|
/**
|
|
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
|
+
/**
|
|
470
478
|
* The {@link CRI} that represents this {@link ServiceIdentifier}
|
|
471
479
|
* @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
|
|
472
482
|
*/
|
|
473
483
|
cri(): CRI;
|
|
484
|
+
private qualifiedNameFor;
|
|
474
485
|
}
|
|
475
486
|
import { Observable as Observable2 } from "rxjs";
|
|
476
487
|
/**
|
|
@@ -581,6 +592,18 @@ interface IKinotic {
|
|
|
581
592
|
serviceRegistry: IServiceRegistry;
|
|
582
593
|
eventBus: IEventBus;
|
|
583
594
|
/**
|
|
595
|
+
* The zone prefix every service published by this client registers under, such as
|
|
596
|
+
* `app.<organizationId>.<applicationId>` for an application or `system` for a platform
|
|
597
|
+
* workload. Must be set from static configuration before service classes are instantiated.
|
|
598
|
+
* When null, services register at un-zoned legacy addresses.
|
|
599
|
+
*/
|
|
600
|
+
zonePrefix: string | null;
|
|
601
|
+
/**
|
|
602
|
+
* The zones applied to published services that carry no {@link Zones} declaration of their
|
|
603
|
+
* own, typically loaded from the project package.json `kinotic.zones` field.
|
|
604
|
+
*/
|
|
605
|
+
defaultZones: string[] | null;
|
|
606
|
+
/**
|
|
584
607
|
* Requests a connection to the given Stomp url
|
|
585
608
|
* @param connectionInfo provides the information needed to connect to the kinoitc server
|
|
586
609
|
* @return Promise containing the result of the initial connection attempt
|
|
@@ -617,6 +640,8 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
617
640
|
* The {@link ServiceRegistry} that is used to manage the services that are available
|
|
618
641
|
*/
|
|
619
642
|
readonly serviceRegistry: ServiceRegistry;
|
|
643
|
+
zonePrefix: string | null;
|
|
644
|
+
defaultZones: string[] | null;
|
|
620
645
|
constructor();
|
|
621
646
|
get eventBus(): IEventBus;
|
|
622
647
|
set eventBus(eventBus: IEventBus);
|
|
@@ -648,11 +673,61 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
648
673
|
* The default {@link IKinotic} instance that can be used to access Kinotic services
|
|
649
674
|
*/
|
|
650
675
|
declare const Kinotic: KinoticSingleton;
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
676
|
+
/**
|
|
677
|
+
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
678
|
+
* specific instance of the service, such as the copy running on a particular node. It is
|
|
679
|
+
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
680
|
+
*/
|
|
681
|
+
declare function Scope(value: Function, _context: ClassGetterDecoratorContext | ClassMethodDecoratorContext): void;
|
|
682
|
+
/**
|
|
683
|
+
* Sets the semantic version a service registers under.
|
|
684
|
+
* @param version the version in X.Y.Z[-optional] format
|
|
685
|
+
*/
|
|
686
|
+
declare function Version(version: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
687
|
+
/**
|
|
688
|
+
* Declares the zones a service is addressable in, relative to this client's trust context: the
|
|
689
|
+
* declared zones are appended to {@link KinoticSingleton#zonePrefix}, so an application's service
|
|
690
|
+
* can never leave its own `app.<organizationId>.<applicationId>` zone. A service declaring
|
|
691
|
+
* multiple zones registers one address per zone. When absent, {@link KinoticSingleton#defaultZones}
|
|
692
|
+
* (typically loaded from the project package.json `kinotic.zones` field) applies.
|
|
693
|
+
* @param zones each zone is one or more dot separated labels of lowercase letters, digits, and
|
|
694
|
+
* interior dashes, e.g. `billing` or `billing.internal`
|
|
695
|
+
*/
|
|
696
|
+
declare function Zones(zones: string[]): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
697
|
+
/**
|
|
698
|
+
* Marks a service method that receives the {@link ServiceContext} produced by the registered
|
|
699
|
+
* {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
|
|
700
|
+
* callers do not pass it, and the platform appends it after the caller-supplied arguments.
|
|
701
|
+
*/
|
|
702
|
+
declare function Context(value: Function, _context: ClassMethodDecoratorContext): void;
|
|
703
|
+
/**
|
|
704
|
+
* Returns whether the given method of a service instance is marked with {@link Context}.
|
|
705
|
+
* @param serviceInstance the service instance to inspect
|
|
706
|
+
* @param methodName the method to look up
|
|
707
|
+
*/
|
|
708
|
+
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
709
|
+
/**
|
|
710
|
+
* 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 Zones}
|
|
712
|
+
* on the same class refine the registration.
|
|
713
|
+
* @param namespace the optional namespace the service is published under
|
|
714
|
+
* @param name the service name, defaults to the class name
|
|
715
|
+
*/
|
|
716
|
+
declare function Publish(namespace?: string | null, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
717
|
+
/**
|
|
718
|
+
* Validates that the given zone satisfies the zone grammar
|
|
719
|
+
* @param zone the zone to validate
|
|
720
|
+
* @throws if the zone is empty or contains anything other than dot separated labels of
|
|
721
|
+
* lowercase letters, digits, and interior dashes or underscores
|
|
722
|
+
*/
|
|
723
|
+
declare function validateZone(zone: string): void;
|
|
724
|
+
/**
|
|
725
|
+
* Validates that the given value is a single zone label
|
|
726
|
+
* @param label the label to validate
|
|
727
|
+
* @throws if the label is empty or is not a single label of lowercase letters, digits, and
|
|
728
|
+
* interior dashes or underscores
|
|
729
|
+
*/
|
|
730
|
+
declare function validateLabel(label: string): void;
|
|
656
731
|
/**
|
|
657
732
|
* A page is a sublist of a list of objects.
|
|
658
733
|
* @author Navid Mitchell
|
|
@@ -1171,4 +1246,4 @@ declare class ParticipantConstants {
|
|
|
1171
1246
|
static readonly PARTICIPANT_TYPE_NODE: string;
|
|
1172
1247
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1173
1248
|
}
|
|
1174
|
-
export { 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,
|
|
1249
|
+
export { validateZone, validateLabel, receivesContext, createCRI, createAuthenticatedWebSocketFactory, Zones, 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,23 +454,34 @@ 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
|
+
zones?: string[];
|
|
459
460
|
scope?: string;
|
|
460
461
|
version?: string;
|
|
461
|
-
private
|
|
462
|
-
constructor(namespace: string, name: string);
|
|
462
|
+
private _cris;
|
|
463
|
+
constructor(namespace: string | null, name: string, zones?: string[]);
|
|
463
464
|
/**
|
|
464
|
-
* Returns the qualified name
|
|
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
|
|
468
|
+
* @throws if this {@link ServiceIdentifier} has more than one zone and therefore more than
|
|
469
|
+
* one qualified name
|
|
467
470
|
*/
|
|
468
471
|
qualifiedName(): string;
|
|
469
472
|
/**
|
|
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
|
+
/**
|
|
470
478
|
* The {@link CRI} that represents this {@link ServiceIdentifier}
|
|
471
479
|
* @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
|
|
472
482
|
*/
|
|
473
483
|
cri(): CRI;
|
|
484
|
+
private qualifiedNameFor;
|
|
474
485
|
}
|
|
475
486
|
import { Observable as Observable2 } from "rxjs";
|
|
476
487
|
/**
|
|
@@ -581,6 +592,18 @@ interface IKinotic {
|
|
|
581
592
|
serviceRegistry: IServiceRegistry;
|
|
582
593
|
eventBus: IEventBus;
|
|
583
594
|
/**
|
|
595
|
+
* The zone prefix every service published by this client registers under, such as
|
|
596
|
+
* `app.<organizationId>.<applicationId>` for an application or `system` for a platform
|
|
597
|
+
* workload. Must be set from static configuration before service classes are instantiated.
|
|
598
|
+
* When null, services register at un-zoned legacy addresses.
|
|
599
|
+
*/
|
|
600
|
+
zonePrefix: string | null;
|
|
601
|
+
/**
|
|
602
|
+
* The zones applied to published services that carry no {@link Zones} declaration of their
|
|
603
|
+
* own, typically loaded from the project package.json `kinotic.zones` field.
|
|
604
|
+
*/
|
|
605
|
+
defaultZones: string[] | null;
|
|
606
|
+
/**
|
|
584
607
|
* Requests a connection to the given Stomp url
|
|
585
608
|
* @param connectionInfo provides the information needed to connect to the kinoitc server
|
|
586
609
|
* @return Promise containing the result of the initial connection attempt
|
|
@@ -617,6 +640,8 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
617
640
|
* The {@link ServiceRegistry} that is used to manage the services that are available
|
|
618
641
|
*/
|
|
619
642
|
readonly serviceRegistry: ServiceRegistry;
|
|
643
|
+
zonePrefix: string | null;
|
|
644
|
+
defaultZones: string[] | null;
|
|
620
645
|
constructor();
|
|
621
646
|
get eventBus(): IEventBus;
|
|
622
647
|
set eventBus(eventBus: IEventBus);
|
|
@@ -648,11 +673,61 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
648
673
|
* The default {@link IKinotic} instance that can be used to access Kinotic services
|
|
649
674
|
*/
|
|
650
675
|
declare const Kinotic: KinoticSingleton;
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
676
|
+
/**
|
|
677
|
+
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
678
|
+
* specific instance of the service, such as the copy running on a particular node. It is
|
|
679
|
+
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
680
|
+
*/
|
|
681
|
+
declare function Scope(value: Function, _context: ClassGetterDecoratorContext | ClassMethodDecoratorContext): void;
|
|
682
|
+
/**
|
|
683
|
+
* Sets the semantic version a service registers under.
|
|
684
|
+
* @param version the version in X.Y.Z[-optional] format
|
|
685
|
+
*/
|
|
686
|
+
declare function Version(version: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
687
|
+
/**
|
|
688
|
+
* Declares the zones a service is addressable in, relative to this client's trust context: the
|
|
689
|
+
* declared zones are appended to {@link KinoticSingleton#zonePrefix}, so an application's service
|
|
690
|
+
* can never leave its own `app.<organizationId>.<applicationId>` zone. A service declaring
|
|
691
|
+
* multiple zones registers one address per zone. When absent, {@link KinoticSingleton#defaultZones}
|
|
692
|
+
* (typically loaded from the project package.json `kinotic.zones` field) applies.
|
|
693
|
+
* @param zones each zone is one or more dot separated labels of lowercase letters, digits, and
|
|
694
|
+
* interior dashes, e.g. `billing` or `billing.internal`
|
|
695
|
+
*/
|
|
696
|
+
declare function Zones(zones: string[]): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
697
|
+
/**
|
|
698
|
+
* Marks a service method that receives the {@link ServiceContext} produced by the registered
|
|
699
|
+
* {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
|
|
700
|
+
* callers do not pass it, and the platform appends it after the caller-supplied arguments.
|
|
701
|
+
*/
|
|
702
|
+
declare function Context(value: Function, _context: ClassMethodDecoratorContext): void;
|
|
703
|
+
/**
|
|
704
|
+
* Returns whether the given method of a service instance is marked with {@link Context}.
|
|
705
|
+
* @param serviceInstance the service instance to inspect
|
|
706
|
+
* @param methodName the method to look up
|
|
707
|
+
*/
|
|
708
|
+
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
709
|
+
/**
|
|
710
|
+
* 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 Zones}
|
|
712
|
+
* on the same class refine the registration.
|
|
713
|
+
* @param namespace the optional namespace the service is published under
|
|
714
|
+
* @param name the service name, defaults to the class name
|
|
715
|
+
*/
|
|
716
|
+
declare function Publish(namespace?: string | null, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
717
|
+
/**
|
|
718
|
+
* Validates that the given zone satisfies the zone grammar
|
|
719
|
+
* @param zone the zone to validate
|
|
720
|
+
* @throws if the zone is empty or contains anything other than dot separated labels of
|
|
721
|
+
* lowercase letters, digits, and interior dashes or underscores
|
|
722
|
+
*/
|
|
723
|
+
declare function validateZone(zone: string): void;
|
|
724
|
+
/**
|
|
725
|
+
* Validates that the given value is a single zone label
|
|
726
|
+
* @param label the label to validate
|
|
727
|
+
* @throws if the label is empty or is not a single label of lowercase letters, digits, and
|
|
728
|
+
* interior dashes or underscores
|
|
729
|
+
*/
|
|
730
|
+
declare function validateLabel(label: string): void;
|
|
656
731
|
/**
|
|
657
732
|
* A page is a sublist of a list of objects.
|
|
658
733
|
* @author Navid Mitchell
|
|
@@ -1171,4 +1246,4 @@ declare class ParticipantConstants {
|
|
|
1171
1246
|
static readonly PARTICIPANT_TYPE_NODE: string;
|
|
1172
1247
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1173
1248
|
}
|
|
1174
|
-
export { 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,
|
|
1249
|
+
export { validateZone, validateLabel, receivesContext, createCRI, createAuthenticatedWebSocketFactory, Zones, 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
|
@@ -678,73 +678,156 @@ function createDebugLogger(namespace) {
|
|
|
678
678
|
};
|
|
679
679
|
}
|
|
680
680
|
|
|
681
|
-
// packages/core/src/api/KinoticDecorators.ts
|
|
682
|
-
import"reflect-metadata";
|
|
683
|
-
|
|
684
681
|
// packages/core/src/api/ServiceIdentifier.ts
|
|
685
682
|
class ServiceIdentifier {
|
|
686
683
|
namespace;
|
|
687
684
|
name;
|
|
685
|
+
zones;
|
|
688
686
|
scope;
|
|
689
687
|
version;
|
|
690
|
-
|
|
691
|
-
constructor(namespace, name) {
|
|
688
|
+
_cris = null;
|
|
689
|
+
constructor(namespace, name, zones) {
|
|
692
690
|
this.namespace = namespace;
|
|
693
691
|
this.name = name;
|
|
692
|
+
this.zones = zones;
|
|
694
693
|
}
|
|
695
694
|
qualifiedName() {
|
|
696
|
-
|
|
695
|
+
if (this.zones && this.zones.length > 1) {
|
|
696
|
+
throw new Error(`ServiceIdentifier has ${this.zones.length} zones so there is no single qualifiedName`);
|
|
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;
|
|
697
706
|
}
|
|
698
707
|
cri() {
|
|
699
|
-
|
|
700
|
-
|
|
708
|
+
const cris = this.cris();
|
|
709
|
+
const cri = cris[0];
|
|
710
|
+
if (cris.length !== 1 || !cri) {
|
|
711
|
+
throw new Error(`ServiceIdentifier has ${cris.length} cris so there is no single cri`);
|
|
701
712
|
}
|
|
702
|
-
return
|
|
713
|
+
return cri;
|
|
714
|
+
}
|
|
715
|
+
qualifiedNameFor(zone) {
|
|
716
|
+
const name = this.namespace ? this.namespace + "." + this.name : this.name;
|
|
717
|
+
return zone ? zone + "." + name : name;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// packages/core/src/api/ZoneUtil.ts
|
|
722
|
+
var LABEL = "[a-z0-9]([a-z0-9_-]*[a-z0-9])?";
|
|
723
|
+
var LABEL_PATTERN = new RegExp(`^${LABEL}$`);
|
|
724
|
+
var ZONE_PATTERN = new RegExp(`^${LABEL}(\\.${LABEL})*$`);
|
|
725
|
+
function validateZone(zone) {
|
|
726
|
+
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 or underscores`);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
function validateLabel(label) {
|
|
731
|
+
if (!label || !LABEL_PATTERN.test(label)) {
|
|
732
|
+
throw new Error(`Invalid zone label '${label}'. Labels must be lowercase letters, digits, and interior dashes or underscores`);
|
|
703
733
|
}
|
|
704
734
|
}
|
|
705
735
|
|
|
706
736
|
// packages/core/src/api/KinoticDecorators.ts
|
|
707
|
-
var
|
|
708
|
-
var
|
|
709
|
-
var
|
|
710
|
-
|
|
711
|
-
|
|
737
|
+
var scopeFunctions = new WeakSet;
|
|
738
|
+
var versionRegistry = new WeakMap;
|
|
739
|
+
var zonesRegistry = new WeakMap;
|
|
740
|
+
var contextMarkedFunctions = new WeakSet;
|
|
741
|
+
function findInConstructorChain(registry, constructor) {
|
|
742
|
+
let current = constructor;
|
|
743
|
+
while (current) {
|
|
744
|
+
const value = registry.get(current);
|
|
745
|
+
if (value !== undefined) {
|
|
746
|
+
return value;
|
|
747
|
+
}
|
|
748
|
+
current = Object.getPrototypeOf(current);
|
|
749
|
+
}
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
function resolveScope(instance) {
|
|
753
|
+
let proto = Object.getPrototypeOf(instance);
|
|
754
|
+
while (proto && proto !== Object.prototype) {
|
|
755
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
756
|
+
if (key === "constructor") {
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
760
|
+
if (descriptor?.get && scopeFunctions.has(descriptor.get)) {
|
|
761
|
+
return descriptor.get.call(instance);
|
|
762
|
+
}
|
|
763
|
+
if (typeof descriptor?.value === "function" && scopeFunctions.has(descriptor.value)) {
|
|
764
|
+
return descriptor.value.call(instance);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
proto = Object.getPrototypeOf(proto);
|
|
768
|
+
}
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
function Scope(value, _context) {
|
|
772
|
+
scopeFunctions.add(value);
|
|
712
773
|
}
|
|
713
774
|
function Version(version) {
|
|
714
775
|
if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?$/.test(version)) {
|
|
715
776
|
throw new Error(`Invalid semantic version: ${version}. Must follow X.Y.Z[-optional] format.`);
|
|
716
777
|
}
|
|
717
|
-
return function(
|
|
718
|
-
|
|
778
|
+
return function(value, _context) {
|
|
779
|
+
versionRegistry.set(value, version);
|
|
719
780
|
};
|
|
720
781
|
}
|
|
721
|
-
function
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
782
|
+
function Zones(zones) {
|
|
783
|
+
for (const zone of zones) {
|
|
784
|
+
validateZone(zone);
|
|
785
|
+
}
|
|
786
|
+
return function(value, _context) {
|
|
787
|
+
zonesRegistry.set(value, zones);
|
|
726
788
|
};
|
|
727
789
|
}
|
|
790
|
+
function Context(value, _context) {
|
|
791
|
+
contextMarkedFunctions.add(value);
|
|
792
|
+
}
|
|
793
|
+
function receivesContext(serviceInstance, methodName) {
|
|
794
|
+
const method = serviceInstance[methodName];
|
|
795
|
+
return typeof method === "function" && contextMarkedFunctions.has(method);
|
|
796
|
+
}
|
|
797
|
+
function resolveEffectiveZones(constructor) {
|
|
798
|
+
const declaredZones = findInConstructorChain(zonesRegistry, constructor) ?? Kinotic.defaultZones ?? [];
|
|
799
|
+
const prefix = Kinotic.zonePrefix;
|
|
800
|
+
let effectiveZones;
|
|
801
|
+
if (prefix != null && declaredZones.length > 0) {
|
|
802
|
+
effectiveZones = declaredZones.map((zone) => `${prefix}.${zone}`);
|
|
803
|
+
} else if (prefix != null) {
|
|
804
|
+
effectiveZones = [prefix];
|
|
805
|
+
} else {
|
|
806
|
+
effectiveZones = [...declaredZones];
|
|
807
|
+
}
|
|
808
|
+
for (const zone of effectiveZones) {
|
|
809
|
+
validateZone(zone);
|
|
810
|
+
}
|
|
811
|
+
return effectiveZones;
|
|
812
|
+
}
|
|
728
813
|
function Publish(namespace, name) {
|
|
729
|
-
return function(
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
814
|
+
return function(value, _context) {
|
|
815
|
+
return class extends value {
|
|
816
|
+
constructor(...args) {
|
|
817
|
+
super(...args);
|
|
818
|
+
const zones = resolveEffectiveZones(this.constructor);
|
|
819
|
+
const serviceIdentifier = new ServiceIdentifier(namespace ?? null, name || value.name, zones.length > 0 ? zones : undefined);
|
|
820
|
+
const version = findInConstructorChain(versionRegistry, this.constructor);
|
|
821
|
+
if (version) {
|
|
822
|
+
serviceIdentifier.version = version;
|
|
823
|
+
}
|
|
824
|
+
const scope = resolveScope(this);
|
|
825
|
+
if (scope !== undefined) {
|
|
826
|
+
serviceIdentifier.scope = scope;
|
|
827
|
+
}
|
|
828
|
+
Kinotic.serviceRegistry.register(serviceIdentifier, this);
|
|
742
829
|
}
|
|
743
|
-
Kinotic.serviceRegistry.register(serviceIdentifier, instance);
|
|
744
|
-
return instance;
|
|
745
830
|
};
|
|
746
|
-
newConstructor.prototype = original.prototype;
|
|
747
|
-
return newConstructor;
|
|
748
831
|
};
|
|
749
832
|
}
|
|
750
833
|
|
|
@@ -758,7 +841,7 @@ class ServiceInvocationSupervisor {
|
|
|
758
841
|
returnValueConverter;
|
|
759
842
|
serviceIdentifier;
|
|
760
843
|
serviceInstance;
|
|
761
|
-
|
|
844
|
+
methodSubscriptions = [];
|
|
762
845
|
methodMap;
|
|
763
846
|
constructor(serviceIdentifier, serviceInstance, eventBusService, interceptorProvider, options = {}) {
|
|
764
847
|
if (!serviceIdentifier)
|
|
@@ -795,40 +878,46 @@ class ServiceInvocationSupervisor {
|
|
|
795
878
|
throw new Error("Service already started");
|
|
796
879
|
}
|
|
797
880
|
this.active = true;
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
881
|
+
for (const cri of this.serviceIdentifier.cris()) {
|
|
882
|
+
const criBase = cri.baseResource();
|
|
883
|
+
this.methodSubscriptions.push(this._eventBus.observe(criBase).subscribe({
|
|
884
|
+
next: async (event) => {
|
|
885
|
+
await this.processEvent(event);
|
|
886
|
+
},
|
|
887
|
+
error: (error) => {
|
|
888
|
+
this.log.error("Event listener error", error);
|
|
889
|
+
this.active = false;
|
|
890
|
+
},
|
|
891
|
+
complete: () => {
|
|
892
|
+
this.log.error("Event listener stopped unexpectedly. Setting supervisor inactive.");
|
|
893
|
+
this.active = false;
|
|
894
|
+
}
|
|
895
|
+
}));
|
|
896
|
+
this.log.info(`ServiceInvocationSupervisor started for ${criBase}`);
|
|
897
|
+
}
|
|
813
898
|
}
|
|
814
899
|
stop() {
|
|
815
900
|
if (!this.active) {
|
|
816
901
|
throw new Error("Service already stopped");
|
|
817
902
|
}
|
|
818
903
|
this.active = false;
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
this.methodSubscription = null;
|
|
904
|
+
for (const subscription of this.methodSubscriptions) {
|
|
905
|
+
subscription.unsubscribe();
|
|
822
906
|
}
|
|
907
|
+
this.methodSubscriptions = [];
|
|
823
908
|
this.log.info("ServiceInvocationSupervisor stopped");
|
|
824
909
|
}
|
|
825
910
|
buildMethodMap(serviceInstance) {
|
|
826
911
|
const methodMap = {};
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
912
|
+
let proto = Object.getPrototypeOf(serviceInstance);
|
|
913
|
+
while (proto && proto !== Object.prototype) {
|
|
914
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
915
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
916
|
+
if (typeof descriptor?.value === "function" && key !== "constructor" && !methodMap[key]) {
|
|
917
|
+
methodMap[key] = descriptor.value.bind(serviceInstance);
|
|
918
|
+
}
|
|
831
919
|
}
|
|
920
|
+
proto = Object.getPrototypeOf(proto);
|
|
832
921
|
}
|
|
833
922
|
return methodMap;
|
|
834
923
|
}
|
|
@@ -868,7 +957,7 @@ class ServiceInvocationSupervisor {
|
|
|
868
957
|
}
|
|
869
958
|
const methodName = path;
|
|
870
959
|
const args = this.argumentResolver.resolveArguments(event);
|
|
871
|
-
const
|
|
960
|
+
const injectContext = receivesContext(this.serviceInstance, methodName);
|
|
872
961
|
let context2 = {};
|
|
873
962
|
const interceptor = this.interceptorProvider();
|
|
874
963
|
if (interceptor) {
|
|
@@ -880,8 +969,8 @@ class ServiceInvocationSupervisor {
|
|
|
880
969
|
return;
|
|
881
970
|
}
|
|
882
971
|
}
|
|
883
|
-
|
|
884
|
-
args
|
|
972
|
+
if (injectContext) {
|
|
973
|
+
args.push(context2);
|
|
885
974
|
}
|
|
886
975
|
const expectedArgsCount = handlerMethod.length;
|
|
887
976
|
if (args.length !== expectedArgsCount) {
|
|
@@ -938,7 +1027,7 @@ import { first, map as map2 } from "rxjs/operators";
|
|
|
938
1027
|
// packages/core/package.json
|
|
939
1028
|
var package_default = {
|
|
940
1029
|
name: "@kinotic-ai/core",
|
|
941
|
-
version: "
|
|
1030
|
+
version: "3.0.0",
|
|
942
1031
|
type: "module",
|
|
943
1032
|
files: [
|
|
944
1033
|
"dist"
|
|
@@ -1000,7 +1089,6 @@ var package_default = {
|
|
|
1000
1089
|
"@types/debug": "^4.1.13",
|
|
1001
1090
|
debug: "^4.4.3",
|
|
1002
1091
|
"p-tap": "^4.0.0",
|
|
1003
|
-
"reflect-metadata": "^0.2.2",
|
|
1004
1092
|
rxjs: "^7.8.2",
|
|
1005
1093
|
"typescript-optional": "3.0.0-alpha.3",
|
|
1006
1094
|
uuid: "^13.0.0"
|
|
@@ -1068,7 +1156,7 @@ class ServiceRegistry {
|
|
|
1068
1156
|
return new ServiceProxy(serviceIdentifier, this);
|
|
1069
1157
|
}
|
|
1070
1158
|
register(serviceIdentifier, service) {
|
|
1071
|
-
const criString = serviceIdentifier.
|
|
1159
|
+
const criString = serviceIdentifier.cris().map((cri) => cri.raw()).join(", ");
|
|
1072
1160
|
if (!this.supervisors.has(criString)) {
|
|
1073
1161
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1074
1162
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
@@ -1077,7 +1165,7 @@ class ServiceRegistry {
|
|
|
1077
1165
|
}
|
|
1078
1166
|
}
|
|
1079
1167
|
unRegister(serviceIdentifier) {
|
|
1080
|
-
const criString = serviceIdentifier.
|
|
1168
|
+
const criString = serviceIdentifier.cris().map((cri) => cri.raw()).join(", ");
|
|
1081
1169
|
const supervisor = this.supervisors.get(criString);
|
|
1082
1170
|
if (supervisor) {
|
|
1083
1171
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
@@ -1163,6 +1251,8 @@ class ServiceProxy {
|
|
|
1163
1251
|
class KinoticSingleton {
|
|
1164
1252
|
_eventBus;
|
|
1165
1253
|
serviceRegistry;
|
|
1254
|
+
zonePrefix = null;
|
|
1255
|
+
defaultZones = null;
|
|
1166
1256
|
constructor() {
|
|
1167
1257
|
this._eventBus = new EventBus;
|
|
1168
1258
|
this.serviceRegistry = new ServiceRegistry(this._eventBus);
|
|
@@ -1464,8 +1554,12 @@ class ParticipantConstants {
|
|
|
1464
1554
|
static CLI_PARTICIPANT_ID = "-42-Kinotic-CLI-42-";
|
|
1465
1555
|
}
|
|
1466
1556
|
export {
|
|
1557
|
+
validateZone,
|
|
1558
|
+
validateLabel,
|
|
1559
|
+
receivesContext,
|
|
1467
1560
|
createCRI,
|
|
1468
1561
|
createAuthenticatedWebSocketFactory,
|
|
1562
|
+
Zones,
|
|
1469
1563
|
Version,
|
|
1470
1564
|
TextEventFactory,
|
|
1471
1565
|
Sort,
|
|
@@ -1495,7 +1589,6 @@ export {
|
|
|
1495
1589
|
Context,
|
|
1496
1590
|
ConnectionInfo,
|
|
1497
1591
|
ConnectedInfo,
|
|
1498
|
-
CONTEXT_METADATA_KEY,
|
|
1499
1592
|
BearerTokenAuthProvider,
|
|
1500
1593
|
BasicAuthProvider,
|
|
1501
1594
|
AbstractIterablePage
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinotic-ai/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -62,7 +62,6 @@
|
|
|
62
62
|
"@types/debug": "^4.1.13",
|
|
63
63
|
"debug": "^4.4.3",
|
|
64
64
|
"p-tap": "^4.0.0",
|
|
65
|
-
"reflect-metadata": "^0.2.2",
|
|
66
65
|
"rxjs": "^7.8.2",
|
|
67
66
|
"typescript-optional": "3.0.0-alpha.3",
|
|
68
67
|
"uuid": "^13.0.0"
|