@kinotic-ai/core 1.9.0 → 2.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 +75 -45
- package/dist/index.d.cts +34 -8
- package/dist/index.d.ts +34 -8
- package/dist/index.js +75 -45
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -64,6 +64,7 @@ var __export = (target, all) => {
|
|
|
64
64
|
// packages/core/src/index.ts
|
|
65
65
|
var exports_src = {};
|
|
66
66
|
__export(exports_src, {
|
|
67
|
+
receivesContext: () => receivesContext,
|
|
67
68
|
createCRI: () => createCRI,
|
|
68
69
|
createAuthenticatedWebSocketFactory: () => createAuthenticatedWebSocketFactory,
|
|
69
70
|
Version: () => Version,
|
|
@@ -95,7 +96,6 @@ __export(exports_src, {
|
|
|
95
96
|
Context: () => Context,
|
|
96
97
|
ConnectionInfo: () => ConnectionInfo,
|
|
97
98
|
ConnectedInfo: () => ConnectedInfo,
|
|
98
|
-
CONTEXT_METADATA_KEY: () => CONTEXT_METADATA_KEY,
|
|
99
99
|
BearerTokenAuthProvider: () => BearerTokenAuthProvider,
|
|
100
100
|
BasicAuthProvider: () => BasicAuthProvider,
|
|
101
101
|
AbstractIterablePage: () => AbstractIterablePage
|
|
@@ -145,6 +145,7 @@ var EventConstants;
|
|
|
145
145
|
EventConstants2["REPLY_DESTINATION_SCHEME"] = "reply";
|
|
146
146
|
EventConstants2["CONTENT_JSON"] = "application/json";
|
|
147
147
|
EventConstants2["CONTENT_TEXT"] = "text/plain";
|
|
148
|
+
EventConstants2["CONTENT_OCTET_STREAM"] = "application/octet-stream";
|
|
148
149
|
EventConstants2["TRACEPARENT_HEADER"] = "traceparent";
|
|
149
150
|
EventConstants2["TRACESTATE_HEADER"] = "tracestate";
|
|
150
151
|
})(EventConstants ||= {});
|
|
@@ -778,9 +779,6 @@ function createDebugLogger(namespace) {
|
|
|
778
779
|
};
|
|
779
780
|
}
|
|
780
781
|
|
|
781
|
-
// packages/core/src/api/KinoticDecorators.ts
|
|
782
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
783
|
-
|
|
784
782
|
// packages/core/src/api/ServiceIdentifier.ts
|
|
785
783
|
class ServiceIdentifier {
|
|
786
784
|
namespace;
|
|
@@ -804,47 +802,74 @@ class ServiceIdentifier {
|
|
|
804
802
|
}
|
|
805
803
|
|
|
806
804
|
// packages/core/src/api/KinoticDecorators.ts
|
|
807
|
-
var
|
|
808
|
-
var
|
|
809
|
-
var
|
|
810
|
-
function
|
|
811
|
-
|
|
805
|
+
var scopeFunctions = new WeakSet;
|
|
806
|
+
var versionRegistry = new WeakMap;
|
|
807
|
+
var contextMarkedFunctions = new WeakSet;
|
|
808
|
+
function findInConstructorChain(registry, constructor) {
|
|
809
|
+
let current = constructor;
|
|
810
|
+
while (current) {
|
|
811
|
+
const value = registry.get(current);
|
|
812
|
+
if (value !== undefined) {
|
|
813
|
+
return value;
|
|
814
|
+
}
|
|
815
|
+
current = Object.getPrototypeOf(current);
|
|
816
|
+
}
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
function resolveScope(instance) {
|
|
820
|
+
let proto = Object.getPrototypeOf(instance);
|
|
821
|
+
while (proto && proto !== Object.prototype) {
|
|
822
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
823
|
+
if (key === "constructor") {
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
827
|
+
if (descriptor?.get && scopeFunctions.has(descriptor.get)) {
|
|
828
|
+
return descriptor.get.call(instance);
|
|
829
|
+
}
|
|
830
|
+
if (typeof descriptor?.value === "function" && scopeFunctions.has(descriptor.value)) {
|
|
831
|
+
return descriptor.value.call(instance);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
proto = Object.getPrototypeOf(proto);
|
|
835
|
+
}
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
function Scope(value, _context) {
|
|
839
|
+
scopeFunctions.add(value);
|
|
812
840
|
}
|
|
813
841
|
function Version(version) {
|
|
814
842
|
if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?$/.test(version)) {
|
|
815
843
|
throw new Error(`Invalid semantic version: ${version}. Must follow X.Y.Z[-optional] format.`);
|
|
816
844
|
}
|
|
817
|
-
return function(
|
|
818
|
-
|
|
845
|
+
return function(value, _context) {
|
|
846
|
+
versionRegistry.set(value, version);
|
|
819
847
|
};
|
|
820
848
|
}
|
|
821
|
-
function Context() {
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
849
|
+
function Context(value, _context) {
|
|
850
|
+
contextMarkedFunctions.add(value);
|
|
851
|
+
}
|
|
852
|
+
function receivesContext(serviceInstance, methodName) {
|
|
853
|
+
const method = serviceInstance[methodName];
|
|
854
|
+
return typeof method === "function" && contextMarkedFunctions.has(method);
|
|
827
855
|
}
|
|
828
856
|
function Publish(namespace, name) {
|
|
829
|
-
return function(
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
857
|
+
return function(value, _context) {
|
|
858
|
+
return class extends value {
|
|
859
|
+
constructor(...args) {
|
|
860
|
+
super(...args);
|
|
861
|
+
const serviceIdentifier = new ServiceIdentifier(namespace, name || value.name);
|
|
862
|
+
const version = findInConstructorChain(versionRegistry, this.constructor);
|
|
863
|
+
if (version) {
|
|
864
|
+
serviceIdentifier.version = version;
|
|
865
|
+
}
|
|
866
|
+
const scope = resolveScope(this);
|
|
867
|
+
if (scope !== undefined) {
|
|
868
|
+
serviceIdentifier.scope = scope;
|
|
869
|
+
}
|
|
870
|
+
Kinotic.serviceRegistry.register(serviceIdentifier, this);
|
|
842
871
|
}
|
|
843
|
-
Kinotic.serviceRegistry.register(serviceIdentifier, instance);
|
|
844
|
-
return instance;
|
|
845
872
|
};
|
|
846
|
-
newConstructor.prototype = original.prototype;
|
|
847
|
-
return newConstructor;
|
|
848
873
|
};
|
|
849
874
|
}
|
|
850
875
|
|
|
@@ -924,11 +949,15 @@ class ServiceInvocationSupervisor {
|
|
|
924
949
|
}
|
|
925
950
|
buildMethodMap(serviceInstance) {
|
|
926
951
|
const methodMap = {};
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
952
|
+
let proto = Object.getPrototypeOf(serviceInstance);
|
|
953
|
+
while (proto && proto !== Object.prototype) {
|
|
954
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
955
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
956
|
+
if (typeof descriptor?.value === "function" && key !== "constructor" && !methodMap[key]) {
|
|
957
|
+
methodMap[key] = descriptor.value.bind(serviceInstance);
|
|
958
|
+
}
|
|
931
959
|
}
|
|
960
|
+
proto = Object.getPrototypeOf(proto);
|
|
932
961
|
}
|
|
933
962
|
return methodMap;
|
|
934
963
|
}
|
|
@@ -968,7 +997,7 @@ class ServiceInvocationSupervisor {
|
|
|
968
997
|
}
|
|
969
998
|
const methodName = path;
|
|
970
999
|
const args = this.argumentResolver.resolveArguments(event);
|
|
971
|
-
const
|
|
1000
|
+
const injectContext = receivesContext(this.serviceInstance, methodName);
|
|
972
1001
|
let context2 = {};
|
|
973
1002
|
const interceptor = this.interceptorProvider();
|
|
974
1003
|
if (interceptor) {
|
|
@@ -980,8 +1009,8 @@ class ServiceInvocationSupervisor {
|
|
|
980
1009
|
return;
|
|
981
1010
|
}
|
|
982
1011
|
}
|
|
983
|
-
|
|
984
|
-
args
|
|
1012
|
+
if (injectContext) {
|
|
1013
|
+
args.push(context2);
|
|
985
1014
|
}
|
|
986
1015
|
const expectedArgsCount = handlerMethod.length;
|
|
987
1016
|
if (args.length !== expectedArgsCount) {
|
|
@@ -1035,7 +1064,7 @@ var import_operators2 = require("rxjs/operators");
|
|
|
1035
1064
|
// packages/core/package.json
|
|
1036
1065
|
var package_default = {
|
|
1037
1066
|
name: "@kinotic-ai/core",
|
|
1038
|
-
version: "
|
|
1067
|
+
version: "2.0.0",
|
|
1039
1068
|
type: "module",
|
|
1040
1069
|
files: [
|
|
1041
1070
|
"dist"
|
|
@@ -1097,7 +1126,6 @@ var package_default = {
|
|
|
1097
1126
|
"@types/debug": "^4.1.13",
|
|
1098
1127
|
debug: "^4.4.3",
|
|
1099
1128
|
"p-tap": "^4.0.0",
|
|
1100
|
-
"reflect-metadata": "^0.2.2",
|
|
1101
1129
|
rxjs: "^7.8.2",
|
|
1102
1130
|
"typescript-optional": "3.0.0-alpha.3",
|
|
1103
1131
|
uuid: "^13.0.0"
|
|
@@ -1240,10 +1268,12 @@ class ServiceProxy {
|
|
|
1240
1268
|
return eventBusToUse.requestStream(event, sendControlEvents).pipe(import_operators2.map((value) => {
|
|
1241
1269
|
const contentType = value.getHeader("content-type" /* CONTENT_TYPE_HEADER */);
|
|
1242
1270
|
if (contentType !== undefined) {
|
|
1243
|
-
if (contentType === "application/json") {
|
|
1271
|
+
if (contentType === "application/json" /* CONTENT_JSON */) {
|
|
1244
1272
|
return JSON.parse(value.getDataString());
|
|
1245
|
-
} else if (contentType === "text/plain") {
|
|
1273
|
+
} else if (contentType === "text/plain" /* CONTENT_TEXT */) {
|
|
1246
1274
|
return value.getDataString();
|
|
1275
|
+
} else if (contentType === "application/octet-stream" /* CONTENT_OCTET_STREAM */) {
|
|
1276
|
+
return value.data.orUndefined();
|
|
1247
1277
|
} else {
|
|
1248
1278
|
throw new Error("Content Type " + contentType + " is not supported");
|
|
1249
1279
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -266,8 +266,7 @@ declare enum EventConstants {
|
|
|
266
266
|
*/
|
|
267
267
|
CORRELATION_ID_HEADER = "__correlation-id",
|
|
268
268
|
/**
|
|
269
|
-
* Origin service CRI the server sends on stream replies so the client can
|
|
270
|
-
* it. The __ prefix persists it across messages.
|
|
269
|
+
* Origin service CRI the server sends on stream replies so the client can route a cancel back to it.
|
|
271
270
|
*/
|
|
272
271
|
ORIGIN_CRI_HEADER = "__origin-cri",
|
|
273
272
|
/**
|
|
@@ -297,6 +296,7 @@ declare enum EventConstants {
|
|
|
297
296
|
REPLY_DESTINATION_SCHEME = "reply",
|
|
298
297
|
CONTENT_JSON = "application/json",
|
|
299
298
|
CONTENT_TEXT = "text/plain",
|
|
299
|
+
CONTENT_OCTET_STREAM = "application/octet-stream",
|
|
300
300
|
/**
|
|
301
301
|
* The traceparent HTTP header field identifies the incoming request in a tracing system. It has four fields:
|
|
302
302
|
*
|
|
@@ -648,11 +648,37 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
648
648
|
* The default {@link IKinotic} instance that can be used to access Kinotic services
|
|
649
649
|
*/
|
|
650
650
|
declare const Kinotic: KinoticSingleton;
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
651
|
+
/**
|
|
652
|
+
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
653
|
+
* specific instance of the service, such as the copy running on a particular node. It is
|
|
654
|
+
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
655
|
+
*/
|
|
656
|
+
declare function Scope(value: Function, _context: ClassGetterDecoratorContext | ClassMethodDecoratorContext): void;
|
|
657
|
+
/**
|
|
658
|
+
* Sets the semantic version a service registers under.
|
|
659
|
+
* @param version the version in X.Y.Z[-optional] format
|
|
660
|
+
*/
|
|
661
|
+
declare function Version(version: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
662
|
+
/**
|
|
663
|
+
* Marks a service method that receives the {@link ServiceContext} produced by the registered
|
|
664
|
+
* {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
|
|
665
|
+
* callers do not pass it, and the platform appends it after the caller-supplied arguments.
|
|
666
|
+
*/
|
|
667
|
+
declare function Context(value: Function, _context: ClassMethodDecoratorContext): void;
|
|
668
|
+
/**
|
|
669
|
+
* Returns whether the given method of a service instance is marked with {@link Context}.
|
|
670
|
+
* @param serviceInstance the service instance to inspect
|
|
671
|
+
* @param methodName the method to look up
|
|
672
|
+
*/
|
|
673
|
+
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
674
|
+
/**
|
|
675
|
+
* Registers each instance of the decorated class with the Kinotic ServiceRegistry under the
|
|
676
|
+
* given namespace. The service name defaults to the class name; {@link Version} and
|
|
677
|
+
* {@link Scope} on the same class refine the registration.
|
|
678
|
+
* @param namespace the namespace the service is published under
|
|
679
|
+
* @param name the service name, defaults to the class name
|
|
680
|
+
*/
|
|
681
|
+
declare function Publish(namespace: string, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
656
682
|
/**
|
|
657
683
|
* A page is a sublist of a list of objects.
|
|
658
684
|
* @author Navid Mitchell
|
|
@@ -1171,4 +1197,4 @@ declare class ParticipantConstants {
|
|
|
1171
1197
|
static readonly PARTICIPANT_TYPE_NODE: string;
|
|
1172
1198
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1173
1199
|
}
|
|
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,
|
|
1200
|
+
export { receivesContext, createCRI, createAuthenticatedWebSocketFactory, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, IAuthProvider, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
|
package/dist/index.d.ts
CHANGED
|
@@ -266,8 +266,7 @@ declare enum EventConstants {
|
|
|
266
266
|
*/
|
|
267
267
|
CORRELATION_ID_HEADER = "__correlation-id",
|
|
268
268
|
/**
|
|
269
|
-
* Origin service CRI the server sends on stream replies so the client can
|
|
270
|
-
* it. The __ prefix persists it across messages.
|
|
269
|
+
* Origin service CRI the server sends on stream replies so the client can route a cancel back to it.
|
|
271
270
|
*/
|
|
272
271
|
ORIGIN_CRI_HEADER = "__origin-cri",
|
|
273
272
|
/**
|
|
@@ -297,6 +296,7 @@ declare enum EventConstants {
|
|
|
297
296
|
REPLY_DESTINATION_SCHEME = "reply",
|
|
298
297
|
CONTENT_JSON = "application/json",
|
|
299
298
|
CONTENT_TEXT = "text/plain",
|
|
299
|
+
CONTENT_OCTET_STREAM = "application/octet-stream",
|
|
300
300
|
/**
|
|
301
301
|
* The traceparent HTTP header field identifies the incoming request in a tracing system. It has four fields:
|
|
302
302
|
*
|
|
@@ -648,11 +648,37 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
648
648
|
* The default {@link IKinotic} instance that can be used to access Kinotic services
|
|
649
649
|
*/
|
|
650
650
|
declare const Kinotic: KinoticSingleton;
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
651
|
+
/**
|
|
652
|
+
* Marks the getter or method that provides the service's scope, which targets requests at one
|
|
653
|
+
* specific instance of the service, such as the copy running on a particular node. It is
|
|
654
|
+
* invoked on each instance when the instance registers with the ServiceRegistry.
|
|
655
|
+
*/
|
|
656
|
+
declare function Scope(value: Function, _context: ClassGetterDecoratorContext | ClassMethodDecoratorContext): void;
|
|
657
|
+
/**
|
|
658
|
+
* Sets the semantic version a service registers under.
|
|
659
|
+
* @param version the version in X.Y.Z[-optional] format
|
|
660
|
+
*/
|
|
661
|
+
declare function Version(version: string): (value: Function, _context: ClassDecoratorContext<any>) => void;
|
|
662
|
+
/**
|
|
663
|
+
* Marks a service method that receives the {@link ServiceContext} produced by the registered
|
|
664
|
+
* {@link ContextInterceptor}. The context parameter MUST be the method's final parameter:
|
|
665
|
+
* callers do not pass it, and the platform appends it after the caller-supplied arguments.
|
|
666
|
+
*/
|
|
667
|
+
declare function Context(value: Function, _context: ClassMethodDecoratorContext): void;
|
|
668
|
+
/**
|
|
669
|
+
* Returns whether the given method of a service instance is marked with {@link Context}.
|
|
670
|
+
* @param serviceInstance the service instance to inspect
|
|
671
|
+
* @param methodName the method to look up
|
|
672
|
+
*/
|
|
673
|
+
declare function receivesContext(serviceInstance: object, methodName: string): boolean;
|
|
674
|
+
/**
|
|
675
|
+
* Registers each instance of the decorated class with the Kinotic ServiceRegistry under the
|
|
676
|
+
* given namespace. The service name defaults to the class name; {@link Version} and
|
|
677
|
+
* {@link Scope} on the same class refine the registration.
|
|
678
|
+
* @param namespace the namespace the service is published under
|
|
679
|
+
* @param name the service name, defaults to the class name
|
|
680
|
+
*/
|
|
681
|
+
declare function Publish(namespace: string, name?: string): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
656
682
|
/**
|
|
657
683
|
* A page is a sublist of a list of objects.
|
|
658
684
|
* @author Navid Mitchell
|
|
@@ -1171,4 +1197,4 @@ declare class ParticipantConstants {
|
|
|
1171
1197
|
static readonly PARTICIPANT_TYPE_NODE: string;
|
|
1172
1198
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1173
1199
|
}
|
|
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,
|
|
1200
|
+
export { receivesContext, createCRI, createAuthenticatedWebSocketFactory, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, ServiceRegistry, ServiceContext, ServerInfo, Scope, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, IAuthProvider, FunctionalIterablePage, EventConstants, EventBus, Event, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, ContextInterceptor, Context, ConnectionInfo, ConnectedInfo, CRI, BearerTokenAuthProvider, BasicAuthProvider, AbstractIterablePage };
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ var EventConstants;
|
|
|
44
44
|
EventConstants2["REPLY_DESTINATION_SCHEME"] = "reply";
|
|
45
45
|
EventConstants2["CONTENT_JSON"] = "application/json";
|
|
46
46
|
EventConstants2["CONTENT_TEXT"] = "text/plain";
|
|
47
|
+
EventConstants2["CONTENT_OCTET_STREAM"] = "application/octet-stream";
|
|
47
48
|
EventConstants2["TRACEPARENT_HEADER"] = "traceparent";
|
|
48
49
|
EventConstants2["TRACESTATE_HEADER"] = "tracestate";
|
|
49
50
|
})(EventConstants ||= {});
|
|
@@ -677,9 +678,6 @@ function createDebugLogger(namespace) {
|
|
|
677
678
|
};
|
|
678
679
|
}
|
|
679
680
|
|
|
680
|
-
// packages/core/src/api/KinoticDecorators.ts
|
|
681
|
-
import"reflect-metadata";
|
|
682
|
-
|
|
683
681
|
// packages/core/src/api/ServiceIdentifier.ts
|
|
684
682
|
class ServiceIdentifier {
|
|
685
683
|
namespace;
|
|
@@ -703,47 +701,74 @@ class ServiceIdentifier {
|
|
|
703
701
|
}
|
|
704
702
|
|
|
705
703
|
// packages/core/src/api/KinoticDecorators.ts
|
|
706
|
-
var
|
|
707
|
-
var
|
|
708
|
-
var
|
|
709
|
-
function
|
|
710
|
-
|
|
704
|
+
var scopeFunctions = new WeakSet;
|
|
705
|
+
var versionRegistry = new WeakMap;
|
|
706
|
+
var contextMarkedFunctions = new WeakSet;
|
|
707
|
+
function findInConstructorChain(registry, constructor) {
|
|
708
|
+
let current = constructor;
|
|
709
|
+
while (current) {
|
|
710
|
+
const value = registry.get(current);
|
|
711
|
+
if (value !== undefined) {
|
|
712
|
+
return value;
|
|
713
|
+
}
|
|
714
|
+
current = Object.getPrototypeOf(current);
|
|
715
|
+
}
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
function resolveScope(instance) {
|
|
719
|
+
let proto = Object.getPrototypeOf(instance);
|
|
720
|
+
while (proto && proto !== Object.prototype) {
|
|
721
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
722
|
+
if (key === "constructor") {
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
726
|
+
if (descriptor?.get && scopeFunctions.has(descriptor.get)) {
|
|
727
|
+
return descriptor.get.call(instance);
|
|
728
|
+
}
|
|
729
|
+
if (typeof descriptor?.value === "function" && scopeFunctions.has(descriptor.value)) {
|
|
730
|
+
return descriptor.value.call(instance);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
proto = Object.getPrototypeOf(proto);
|
|
734
|
+
}
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
function Scope(value, _context) {
|
|
738
|
+
scopeFunctions.add(value);
|
|
711
739
|
}
|
|
712
740
|
function Version(version) {
|
|
713
741
|
if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?$/.test(version)) {
|
|
714
742
|
throw new Error(`Invalid semantic version: ${version}. Must follow X.Y.Z[-optional] format.`);
|
|
715
743
|
}
|
|
716
|
-
return function(
|
|
717
|
-
|
|
744
|
+
return function(value, _context) {
|
|
745
|
+
versionRegistry.set(value, version);
|
|
718
746
|
};
|
|
719
747
|
}
|
|
720
|
-
function Context() {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
748
|
+
function Context(value, _context) {
|
|
749
|
+
contextMarkedFunctions.add(value);
|
|
750
|
+
}
|
|
751
|
+
function receivesContext(serviceInstance, methodName) {
|
|
752
|
+
const method = serviceInstance[methodName];
|
|
753
|
+
return typeof method === "function" && contextMarkedFunctions.has(method);
|
|
726
754
|
}
|
|
727
755
|
function Publish(namespace, name) {
|
|
728
|
-
return function(
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
756
|
+
return function(value, _context) {
|
|
757
|
+
return class extends value {
|
|
758
|
+
constructor(...args) {
|
|
759
|
+
super(...args);
|
|
760
|
+
const serviceIdentifier = new ServiceIdentifier(namespace, name || value.name);
|
|
761
|
+
const version = findInConstructorChain(versionRegistry, this.constructor);
|
|
762
|
+
if (version) {
|
|
763
|
+
serviceIdentifier.version = version;
|
|
764
|
+
}
|
|
765
|
+
const scope = resolveScope(this);
|
|
766
|
+
if (scope !== undefined) {
|
|
767
|
+
serviceIdentifier.scope = scope;
|
|
768
|
+
}
|
|
769
|
+
Kinotic.serviceRegistry.register(serviceIdentifier, this);
|
|
741
770
|
}
|
|
742
|
-
Kinotic.serviceRegistry.register(serviceIdentifier, instance);
|
|
743
|
-
return instance;
|
|
744
771
|
};
|
|
745
|
-
newConstructor.prototype = original.prototype;
|
|
746
|
-
return newConstructor;
|
|
747
772
|
};
|
|
748
773
|
}
|
|
749
774
|
|
|
@@ -823,11 +848,15 @@ class ServiceInvocationSupervisor {
|
|
|
823
848
|
}
|
|
824
849
|
buildMethodMap(serviceInstance) {
|
|
825
850
|
const methodMap = {};
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
851
|
+
let proto = Object.getPrototypeOf(serviceInstance);
|
|
852
|
+
while (proto && proto !== Object.prototype) {
|
|
853
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
854
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
855
|
+
if (typeof descriptor?.value === "function" && key !== "constructor" && !methodMap[key]) {
|
|
856
|
+
methodMap[key] = descriptor.value.bind(serviceInstance);
|
|
857
|
+
}
|
|
830
858
|
}
|
|
859
|
+
proto = Object.getPrototypeOf(proto);
|
|
831
860
|
}
|
|
832
861
|
return methodMap;
|
|
833
862
|
}
|
|
@@ -867,7 +896,7 @@ class ServiceInvocationSupervisor {
|
|
|
867
896
|
}
|
|
868
897
|
const methodName = path;
|
|
869
898
|
const args = this.argumentResolver.resolveArguments(event);
|
|
870
|
-
const
|
|
899
|
+
const injectContext = receivesContext(this.serviceInstance, methodName);
|
|
871
900
|
let context2 = {};
|
|
872
901
|
const interceptor = this.interceptorProvider();
|
|
873
902
|
if (interceptor) {
|
|
@@ -879,8 +908,8 @@ class ServiceInvocationSupervisor {
|
|
|
879
908
|
return;
|
|
880
909
|
}
|
|
881
910
|
}
|
|
882
|
-
|
|
883
|
-
args
|
|
911
|
+
if (injectContext) {
|
|
912
|
+
args.push(context2);
|
|
884
913
|
}
|
|
885
914
|
const expectedArgsCount = handlerMethod.length;
|
|
886
915
|
if (args.length !== expectedArgsCount) {
|
|
@@ -937,7 +966,7 @@ import { first, map as map2 } from "rxjs/operators";
|
|
|
937
966
|
// packages/core/package.json
|
|
938
967
|
var package_default = {
|
|
939
968
|
name: "@kinotic-ai/core",
|
|
940
|
-
version: "
|
|
969
|
+
version: "2.0.0",
|
|
941
970
|
type: "module",
|
|
942
971
|
files: [
|
|
943
972
|
"dist"
|
|
@@ -999,7 +1028,6 @@ var package_default = {
|
|
|
999
1028
|
"@types/debug": "^4.1.13",
|
|
1000
1029
|
debug: "^4.4.3",
|
|
1001
1030
|
"p-tap": "^4.0.0",
|
|
1002
|
-
"reflect-metadata": "^0.2.2",
|
|
1003
1031
|
rxjs: "^7.8.2",
|
|
1004
1032
|
"typescript-optional": "3.0.0-alpha.3",
|
|
1005
1033
|
uuid: "^13.0.0"
|
|
@@ -1142,10 +1170,12 @@ class ServiceProxy {
|
|
|
1142
1170
|
return eventBusToUse.requestStream(event, sendControlEvents).pipe(map2((value) => {
|
|
1143
1171
|
const contentType = value.getHeader("content-type" /* CONTENT_TYPE_HEADER */);
|
|
1144
1172
|
if (contentType !== undefined) {
|
|
1145
|
-
if (contentType === "application/json") {
|
|
1173
|
+
if (contentType === "application/json" /* CONTENT_JSON */) {
|
|
1146
1174
|
return JSON.parse(value.getDataString());
|
|
1147
|
-
} else if (contentType === "text/plain") {
|
|
1175
|
+
} else if (contentType === "text/plain" /* CONTENT_TEXT */) {
|
|
1148
1176
|
return value.getDataString();
|
|
1177
|
+
} else if (contentType === "application/octet-stream" /* CONTENT_OCTET_STREAM */) {
|
|
1178
|
+
return value.data.orUndefined();
|
|
1149
1179
|
} else {
|
|
1150
1180
|
throw new Error("Content Type " + contentType + " is not supported");
|
|
1151
1181
|
}
|
|
@@ -1461,6 +1491,7 @@ class ParticipantConstants {
|
|
|
1461
1491
|
static CLI_PARTICIPANT_ID = "-42-Kinotic-CLI-42-";
|
|
1462
1492
|
}
|
|
1463
1493
|
export {
|
|
1494
|
+
receivesContext,
|
|
1464
1495
|
createCRI,
|
|
1465
1496
|
createAuthenticatedWebSocketFactory,
|
|
1466
1497
|
Version,
|
|
@@ -1492,7 +1523,6 @@ export {
|
|
|
1492
1523
|
Context,
|
|
1493
1524
|
ConnectionInfo,
|
|
1494
1525
|
ConnectedInfo,
|
|
1495
|
-
CONTEXT_METADATA_KEY,
|
|
1496
1526
|
BearerTokenAuthProvider,
|
|
1497
1527
|
BasicAuthProvider,
|
|
1498
1528
|
AbstractIterablePage
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinotic-ai/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.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"
|