@kinotic-ai/core 5.0.0-beta.24 → 5.0.0-beta.26
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 +192 -116
- package/dist/index.d.cts +58 -3
- package/dist/index.d.ts +58 -3
- package/dist/index.js +178 -104
- package/dist/node/index.cjs +9 -7
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -19,13 +19,15 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
19
19
|
return cached;
|
|
20
20
|
}
|
|
21
21
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
24
|
+
for (let key of __getOwnPropNames(mod))
|
|
25
|
+
if (!__hasOwnProp.call(to, key))
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: __accessProp.bind(mod, key),
|
|
28
|
+
enumerable: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
29
31
|
if (canCache)
|
|
30
32
|
cache.set(mod, to);
|
|
31
33
|
return to;
|
|
@@ -64,53 +66,54 @@ var __export = (target, all) => {
|
|
|
64
66
|
// packages/core/src/index.ts
|
|
65
67
|
var exports_src = {};
|
|
66
68
|
__export(exports_src, {
|
|
67
|
-
|
|
68
|
-
validateLabel: () => validateLabel,
|
|
69
|
-
scopeOptionalMethodNames: () => scopeOptionalMethodNames,
|
|
70
|
-
receivesContext: () => receivesContext,
|
|
71
|
-
isAdvertised: () => isAdvertised,
|
|
72
|
-
createCRI: () => createCRI,
|
|
73
|
-
buildServerUrl: () => buildServerUrl,
|
|
74
|
-
buildBrokerUrl: () => buildBrokerUrl,
|
|
75
|
-
Zone: () => Zone,
|
|
76
|
-
Version: () => Version,
|
|
77
|
-
TextEventFactory: () => TextEventFactory,
|
|
78
|
-
Sort: () => Sort,
|
|
79
|
-
SessionKeepAliveMode: () => SessionKeepAliveMode,
|
|
80
|
-
SessionCredentialsResolver: () => SessionCredentialsResolver,
|
|
81
|
-
ServiceRegistry: () => ServiceRegistry,
|
|
82
|
-
ServiceIdentifier: () => ServiceIdentifier,
|
|
83
|
-
ServerInfo: () => ServerInfo,
|
|
84
|
-
ScopeOptional: () => ScopeOptional,
|
|
85
|
-
Scope: () => Scope,
|
|
86
|
-
RpcError: () => RpcError,
|
|
87
|
-
Publish: () => Publish,
|
|
88
|
-
ParticipantConstants: () => ParticipantConstants,
|
|
89
|
-
Pageable: () => Pageable,
|
|
90
|
-
Order: () => Order,
|
|
91
|
-
OffsetPageable: () => OffsetPageable,
|
|
92
|
-
NullHandling: () => NullHandling,
|
|
93
|
-
KinoticSingleton: () => KinoticSingleton,
|
|
94
|
-
Kinotic: () => Kinotic,
|
|
95
|
-
JsonEventFactory: () => JsonEventFactory,
|
|
96
|
-
FunctionalIterablePage: () => FunctionalIterablePage,
|
|
97
|
-
EventConstants: () => EventConstants,
|
|
98
|
-
EventBus: () => EventBus,
|
|
99
|
-
Event: () => Event,
|
|
100
|
-
EnvCredentialsResolver: () => EnvCredentialsResolver,
|
|
101
|
-
Direction: () => Direction,
|
|
102
|
-
DefaultCRI: () => DefaultCRI,
|
|
103
|
-
DataSourceUtils: () => DataSourceUtils,
|
|
104
|
-
CursorPageable: () => CursorPageable,
|
|
105
|
-
CrudServiceProxyFactory: () => CrudServiceProxyFactory,
|
|
106
|
-
CrudServiceProxy: () => CrudServiceProxy,
|
|
107
|
-
Context: () => Context,
|
|
108
|
-
ConnectedInfo: () => ConnectedInfo,
|
|
109
|
-
ChainedCredentialsResolver: () => ChainedCredentialsResolver,
|
|
110
|
-
BearerCredentialsResolver: () => BearerCredentialsResolver,
|
|
111
|
-
BasicCredentialsResolver: () => BasicCredentialsResolver,
|
|
69
|
+
AbstractIterablePage: () => AbstractIterablePage,
|
|
112
70
|
AuthorizationException: () => AuthorizationException,
|
|
113
|
-
|
|
71
|
+
BasicCredentialsResolver: () => BasicCredentialsResolver,
|
|
72
|
+
BearerCredentialsResolver: () => BearerCredentialsResolver,
|
|
73
|
+
ChainedCredentialsResolver: () => ChainedCredentialsResolver,
|
|
74
|
+
ConnectedInfo: () => ConnectedInfo,
|
|
75
|
+
Context: () => Context,
|
|
76
|
+
CrudServiceProxy: () => CrudServiceProxy,
|
|
77
|
+
CrudServiceProxyFactory: () => CrudServiceProxyFactory,
|
|
78
|
+
CursorPageable: () => CursorPageable,
|
|
79
|
+
DataSourceUtils: () => DataSourceUtils,
|
|
80
|
+
DefaultCRI: () => DefaultCRI,
|
|
81
|
+
Direction: () => Direction,
|
|
82
|
+
EnvCredentialsResolver: () => EnvCredentialsResolver,
|
|
83
|
+
Event: () => Event,
|
|
84
|
+
EventBus: () => EventBus,
|
|
85
|
+
EventConstants: () => EventConstants,
|
|
86
|
+
FunctionalIterablePage: () => FunctionalIterablePage,
|
|
87
|
+
JsonEventFactory: () => JsonEventFactory,
|
|
88
|
+
Kinotic: () => Kinotic,
|
|
89
|
+
KinoticSingleton: () => KinoticSingleton,
|
|
90
|
+
NullHandling: () => NullHandling,
|
|
91
|
+
OffsetPageable: () => OffsetPageable,
|
|
92
|
+
Order: () => Order,
|
|
93
|
+
Pageable: () => Pageable,
|
|
94
|
+
ParticipantConstants: () => ParticipantConstants,
|
|
95
|
+
Publish: () => Publish,
|
|
96
|
+
RpcError: () => RpcError,
|
|
97
|
+
Scope: () => Scope,
|
|
98
|
+
ScopeOptional: () => ScopeOptional,
|
|
99
|
+
ServerInfo: () => ServerInfo,
|
|
100
|
+
ServiceIdentifier: () => ServiceIdentifier,
|
|
101
|
+
ServiceRegistry: () => ServiceRegistry,
|
|
102
|
+
SessionCredentialsResolver: () => SessionCredentialsResolver,
|
|
103
|
+
SessionKeepAliveMode: () => SessionKeepAliveMode,
|
|
104
|
+
Sort: () => Sort,
|
|
105
|
+
TextEventFactory: () => TextEventFactory,
|
|
106
|
+
Version: () => Version,
|
|
107
|
+
Zone: () => Zone,
|
|
108
|
+
buildBrokerUrl: () => buildBrokerUrl,
|
|
109
|
+
buildServerUrl: () => buildServerUrl,
|
|
110
|
+
createCRI: () => createCRI,
|
|
111
|
+
declareServiceDefinitions: () => declareServiceDefinitions,
|
|
112
|
+
isAdvertised: () => isAdvertised,
|
|
113
|
+
receivesContext: () => receivesContext,
|
|
114
|
+
scopeOptionalMethodNames: () => scopeOptionalMethodNames,
|
|
115
|
+
validateLabel: () => validateLabel,
|
|
116
|
+
validateZone: () => validateZone
|
|
114
117
|
});
|
|
115
118
|
module.exports = __toCommonJS(exports_src);
|
|
116
119
|
|
|
@@ -127,44 +130,44 @@ function buildBrokerUrl(server) {
|
|
|
127
130
|
return buildServerUrl(server, "ws") + "/api/v1";
|
|
128
131
|
}
|
|
129
132
|
var SessionKeepAliveMode;
|
|
130
|
-
((
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
((SessionKeepAliveMode) => {
|
|
134
|
+
SessionKeepAliveMode["NONE"] = "NONE";
|
|
135
|
+
SessionKeepAliveMode["ACTIVITY"] = "ACTIVITY";
|
|
136
|
+
SessionKeepAliveMode["CONNECTION"] = "CONNECTION";
|
|
134
137
|
})(SessionKeepAliveMode ||= {});
|
|
135
138
|
// packages/core/src/api/event/IEventBus.ts
|
|
136
139
|
var EventConstants;
|
|
137
|
-
((
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
140
|
+
((EventConstants) => {
|
|
141
|
+
EventConstants["CONTENT_TYPE_HEADER"] = "content-type";
|
|
142
|
+
EventConstants["CONTENT_LENGTH_HEADER"] = "content-length";
|
|
143
|
+
EventConstants["REPLY_TO_HEADER"] = "reply-to";
|
|
144
|
+
EventConstants["SENDER_HEADER"] = "sender";
|
|
145
|
+
EventConstants["CONNECTED_INFO_HEADER"] = "connected-info";
|
|
146
|
+
EventConstants["SESSION_KEEP_ALIVE_HEADER"] = "session-keep-alive";
|
|
147
|
+
EventConstants["CORRELATION_ID_HEADER"] = "__correlation-id";
|
|
148
|
+
EventConstants["ORIGIN_CRI_HEADER"] = "__origin-cri";
|
|
149
|
+
EventConstants["ERROR_HEADER"] = "error";
|
|
150
|
+
EventConstants["COMPLETE_HEADER"] = "complete";
|
|
151
|
+
EventConstants["CONTROL_HEADER"] = "control";
|
|
152
|
+
EventConstants["CONTROL_VALUE_COMPLETE"] = "complete";
|
|
153
|
+
EventConstants["CONTROL_VALUE_CANCEL"] = "cancel";
|
|
154
|
+
EventConstants["CONTROL_VALUE_SUSPEND"] = "suspend";
|
|
155
|
+
EventConstants["CONTROL_VALUE_RESUME"] = "resume";
|
|
156
|
+
EventConstants["SERVICE_DESTINATION_PREFIX"] = "srv://";
|
|
157
|
+
EventConstants["SERVICE_DESTINATION_SCHEME"] = "srv";
|
|
158
|
+
EventConstants["STREAM_DESTINATION_PREFIX"] = "stream://";
|
|
159
|
+
EventConstants["STREAM_DESTINATION_SCHEME"] = "stream";
|
|
160
|
+
EventConstants["REPLY_DESTINATION_PREFIX"] = "reply://";
|
|
161
|
+
EventConstants["REPLY_DESTINATION_SCHEME"] = "reply";
|
|
162
|
+
EventConstants["CONTENT_JSON"] = "application/json";
|
|
163
|
+
EventConstants["CONTENT_TEXT"] = "text/plain";
|
|
164
|
+
EventConstants["CONTENT_OCTET_STREAM"] = "application/octet-stream";
|
|
165
|
+
EventConstants["TRACEPARENT_HEADER"] = "traceparent";
|
|
166
|
+
EventConstants["TRACESTATE_HEADER"] = "tracestate";
|
|
164
167
|
})(EventConstants ||= {});
|
|
165
168
|
|
|
166
169
|
// packages/core/src/internal/api/Logger.ts
|
|
167
|
-
var import_debug = __toESM(require("debug"));
|
|
170
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
168
171
|
function createDebugLogger(namespace) {
|
|
169
172
|
const debugLogger = import_debug.default(namespace);
|
|
170
173
|
return {
|
|
@@ -179,7 +182,7 @@ function createDebugLogger(namespace) {
|
|
|
179
182
|
// packages/core/src/internal/api/StompConnectionManager.ts
|
|
180
183
|
var import_rx_stomp = require("@stomp/rx-stomp");
|
|
181
184
|
var import_stompjs = require("@stomp/stompjs");
|
|
182
|
-
var import_debug2 = __toESM(require("debug"));
|
|
185
|
+
var import_debug2 = __toESM(require("debug"), 1);
|
|
183
186
|
var import_rxjs = require("rxjs");
|
|
184
187
|
var import_operators = require("rxjs/operators");
|
|
185
188
|
var import_uuid = require("uuid");
|
|
@@ -250,6 +253,7 @@ class StompConnectionManager {
|
|
|
250
253
|
connectionAttempts = 0;
|
|
251
254
|
debugLogger = import_debug2.default("kinotic:stomp");
|
|
252
255
|
connectionEstablishedSubject = new import_rxjs.Subject;
|
|
256
|
+
connectionAttemptFailedSubject = new import_rxjs.Subject;
|
|
253
257
|
initialConnectionSuccessful = false;
|
|
254
258
|
rxStompHasConnected = false;
|
|
255
259
|
_replyToCri = null;
|
|
@@ -265,6 +269,9 @@ class StompConnectionManager {
|
|
|
265
269
|
get connectionEstablished() {
|
|
266
270
|
return this.connectionEstablishedSubject.asObservable();
|
|
267
271
|
}
|
|
272
|
+
get connectionAttemptFailed() {
|
|
273
|
+
return this.connectionAttemptFailedSubject.asObservable();
|
|
274
|
+
}
|
|
268
275
|
async activate(options) {
|
|
269
276
|
if (!options?.server?.host) {
|
|
270
277
|
throw new Error("No host provided");
|
|
@@ -326,7 +333,7 @@ class StompConnectionManager {
|
|
|
326
333
|
webSocketFactory: usesPreparedSocket ? takePreparedSocket : undefined,
|
|
327
334
|
beforeConnect: () => {
|
|
328
335
|
const attempt = this.prepareAttempt(activation, options, server, headerAuth);
|
|
329
|
-
const settled = () => new Promise((
|
|
336
|
+
const settled = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
330
337
|
activation.attempt = attempt.then(settled, settled);
|
|
331
338
|
return attempt;
|
|
332
339
|
}
|
|
@@ -337,12 +344,8 @@ class StompConnectionManager {
|
|
|
337
344
|
};
|
|
338
345
|
}
|
|
339
346
|
this.rxStomp.configure(stompConfig);
|
|
340
|
-
activation.own(this.rxStomp.webSocketErrors$.subscribe(
|
|
347
|
+
activation.own(this.rxStomp.webSocketErrors$.subscribe((value) => {
|
|
341
348
|
this.lastWebsocketError = value;
|
|
342
|
-
if (!activation.ended && options?.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
|
|
343
|
-
this.maxConnectionAttemptsReached = true;
|
|
344
|
-
await this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: value ?? undefined }));
|
|
345
|
-
}
|
|
346
349
|
}));
|
|
347
350
|
activation.own(this.rxStomp.stompErrors$.subscribe(async (frame) => {
|
|
348
351
|
const stompError = new Error(frame.headers["message"], { cause: frame });
|
|
@@ -379,8 +382,17 @@ class StompConnectionManager {
|
|
|
379
382
|
}));
|
|
380
383
|
let previousState = this.rxStomp.connectionState$.getValue();
|
|
381
384
|
activation.own(this.rxStomp.connectionState$.subscribe((state) => {
|
|
382
|
-
if (state === import_rx_stomp.RxStompState.CLOSED &&
|
|
383
|
-
|
|
385
|
+
if (state === import_rx_stomp.RxStompState.CLOSED && this.activation === activation) {
|
|
386
|
+
if (previousState === import_rx_stomp.RxStompState.OPEN) {
|
|
387
|
+
this.connectionEndedHandler?.(null);
|
|
388
|
+
} else if (previousState === import_rx_stomp.RxStompState.CONNECTING) {
|
|
389
|
+
if (options.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
|
|
390
|
+
this.maxConnectionAttemptsReached = true;
|
|
391
|
+
this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
|
|
392
|
+
} else {
|
|
393
|
+
this.connectionAttemptFailedSubject.next();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
384
396
|
}
|
|
385
397
|
previousState = state;
|
|
386
398
|
}));
|
|
@@ -406,16 +418,8 @@ class StompConnectionManager {
|
|
|
406
418
|
}
|
|
407
419
|
if (options?.maxConnectionAttempts) {
|
|
408
420
|
this.connectionAttempts++;
|
|
409
|
-
if (this.connectionAttempts > options.maxConnectionAttempts) {
|
|
410
|
-
this.maxConnectionAttemptsReached = true;
|
|
411
|
-
await this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
|
|
412
|
-
return;
|
|
413
|
-
} else {
|
|
414
|
-
await this.connectionJitterDelay(activation);
|
|
415
|
-
}
|
|
416
|
-
} else {
|
|
417
|
-
await this.connectionJitterDelay(activation);
|
|
418
421
|
}
|
|
422
|
+
await this.connectionJitterDelay(activation);
|
|
419
423
|
if (activation.ended) {
|
|
420
424
|
return;
|
|
421
425
|
}
|
|
@@ -590,6 +594,9 @@ class EventBus {
|
|
|
590
594
|
get connectionEstablished() {
|
|
591
595
|
return this.stompConnectionManager.connectionEstablished;
|
|
592
596
|
}
|
|
597
|
+
get connectionAttemptFailed() {
|
|
598
|
+
return this.stompConnectionManager.connectionAttemptFailed;
|
|
599
|
+
}
|
|
593
600
|
isConnectionActive() {
|
|
594
601
|
return this.stompConnectionManager.active;
|
|
595
602
|
}
|
|
@@ -921,7 +928,7 @@ class Util {
|
|
|
921
928
|
}
|
|
922
929
|
|
|
923
930
|
// packages/core/src/api/ServiceRegistry.ts
|
|
924
|
-
var import_debug3 = __toESM(require("debug"));
|
|
931
|
+
var import_debug3 = __toESM(require("debug"), 1);
|
|
925
932
|
|
|
926
933
|
// packages/core/src/api/event/DefaultCRI.ts
|
|
927
934
|
var ZONE_DELIMITER = "~";
|
|
@@ -1293,11 +1300,11 @@ function Publish(namespace, name, advertise = false) {
|
|
|
1293
1300
|
}
|
|
1294
1301
|
|
|
1295
1302
|
// packages/core/src/internal/api/ServiceInvocationSupervisor.ts
|
|
1296
|
-
var import_api2 = __toESM(require("@opentelemetry/api"));
|
|
1303
|
+
var import_api2 = __toESM(require("@opentelemetry/api"), 1);
|
|
1297
1304
|
// packages/core/package.json
|
|
1298
1305
|
var package_default = {
|
|
1299
1306
|
name: "@kinotic-ai/core",
|
|
1300
|
-
version: "5.0.0-beta.
|
|
1307
|
+
version: "5.0.0-beta.26",
|
|
1301
1308
|
type: "module",
|
|
1302
1309
|
files: [
|
|
1303
1310
|
"dist"
|
|
@@ -1366,6 +1373,7 @@ var package_default = {
|
|
|
1366
1373
|
vitest: "^4.1.4"
|
|
1367
1374
|
},
|
|
1368
1375
|
dependencies: {
|
|
1376
|
+
"@kinotic-ai/idl": "workspace:^",
|
|
1369
1377
|
"@opentelemetry/api": "^1.9.1",
|
|
1370
1378
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
1371
1379
|
"@stomp/rx-stomp": "^2.4.0",
|
|
@@ -1720,7 +1728,7 @@ class ServiceInvocationSupervisor {
|
|
|
1720
1728
|
}
|
|
1721
1729
|
|
|
1722
1730
|
// packages/core/src/api/ServiceRegistry.ts
|
|
1723
|
-
var import_api3 = __toESM(require("@opentelemetry/api"));
|
|
1731
|
+
var import_api3 = __toESM(require("@opentelemetry/api"), 1);
|
|
1724
1732
|
var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
1725
1733
|
var import_operators4 = require("rxjs/operators");
|
|
1726
1734
|
class JsonEventFactory {
|
|
@@ -1756,10 +1764,59 @@ class TextEventFactory {
|
|
|
1756
1764
|
return event;
|
|
1757
1765
|
}
|
|
1758
1766
|
}
|
|
1767
|
+
var APPLICATION_SERVICE_DIRECTORY = "app-api~org.kinotic.app.api.services.ApplicationServiceDirectory";
|
|
1768
|
+
var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
|
|
1769
|
+
var declaredDefinitions = new Map;
|
|
1770
|
+
function declareServiceDefinitions(definitions) {
|
|
1771
|
+
for (const definition of definitions) {
|
|
1772
|
+
declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
function qualifiedNameOf(namespace, name) {
|
|
1776
|
+
return namespace ? `${namespace}.${name}` : name;
|
|
1777
|
+
}
|
|
1778
|
+
function servedFunctions(serviceInstance) {
|
|
1779
|
+
const ret = new Set;
|
|
1780
|
+
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1781
|
+
while (proto && proto !== Object.prototype) {
|
|
1782
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1783
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1784
|
+
if (typeof descriptor?.value === "function" && key !== "constructor") {
|
|
1785
|
+
ret.add(key);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
proto = Object.getPrototypeOf(proto);
|
|
1789
|
+
}
|
|
1790
|
+
return [...ret].sort();
|
|
1791
|
+
}
|
|
1792
|
+
function directoryEntryOf(serviceInstance, serviceIdentifier) {
|
|
1793
|
+
let ret = null;
|
|
1794
|
+
const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
|
|
1795
|
+
if (application) {
|
|
1796
|
+
const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
|
|
1797
|
+
const definition = declaredDefinitions.get(qualifiedName);
|
|
1798
|
+
if (definition) {
|
|
1799
|
+
const declared = definition.functions.map((f) => f.name).sort();
|
|
1800
|
+
const served = servedFunctions(serviceInstance);
|
|
1801
|
+
if (declared.join() !== served.join()) {
|
|
1802
|
+
throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1803
|
+
}
|
|
1804
|
+
ret = {
|
|
1805
|
+
applicationId: application[1],
|
|
1806
|
+
zone: serviceIdentifier.zone,
|
|
1807
|
+
version: serviceIdentifier.version ?? null,
|
|
1808
|
+
advertised: isAdvertised(serviceInstance),
|
|
1809
|
+
serviceDefinition: definition
|
|
1810
|
+
};
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
return ret;
|
|
1814
|
+
}
|
|
1759
1815
|
|
|
1760
1816
|
class ServiceRegistry {
|
|
1761
1817
|
_eventBus;
|
|
1762
1818
|
supervisors = new Map;
|
|
1819
|
+
entries = new Map;
|
|
1763
1820
|
contextInterceptor = null;
|
|
1764
1821
|
debugLogger = import_debug3.default("kinotic:serviceRegistry");
|
|
1765
1822
|
constructor(eventBus) {
|
|
@@ -1781,9 +1838,16 @@ class ServiceRegistry {
|
|
|
1781
1838
|
const criString = serviceIdentifier.cri().raw();
|
|
1782
1839
|
if (!this.supervisors.has(criString)) {
|
|
1783
1840
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1841
|
+
const entry = directoryEntryOf(service, serviceIdentifier);
|
|
1784
1842
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
1785
1843
|
this.supervisors.set(criString, supervisor);
|
|
1786
1844
|
supervisor.start();
|
|
1845
|
+
if (entry) {
|
|
1846
|
+
this.entries.set(criString, entry);
|
|
1847
|
+
if (this.eventBus.isConnected()) {
|
|
1848
|
+
this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1787
1851
|
}
|
|
1788
1852
|
}
|
|
1789
1853
|
unRegister(serviceIdentifier) {
|
|
@@ -1793,8 +1857,18 @@ class ServiceRegistry {
|
|
|
1793
1857
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
1794
1858
|
supervisor.stop();
|
|
1795
1859
|
this.supervisors.delete(criString);
|
|
1860
|
+
this.entries.delete(criString);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
async registerEntries() {
|
|
1864
|
+
for (const entry of this.entries.values()) {
|
|
1865
|
+
await this.registerEntry(entry);
|
|
1796
1866
|
}
|
|
1797
1867
|
}
|
|
1868
|
+
async registerEntry(entry) {
|
|
1869
|
+
this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
|
|
1870
|
+
await this.serviceProxy(APPLICATION_SERVICE_DIRECTORY).invoke("register", [entry]);
|
|
1871
|
+
}
|
|
1798
1872
|
registerContextInterceptor(interceptor) {
|
|
1799
1873
|
this.contextInterceptor = interceptor;
|
|
1800
1874
|
}
|
|
@@ -1886,8 +1960,10 @@ class KinoticSingleton {
|
|
|
1886
1960
|
this._eventBus = eventBus;
|
|
1887
1961
|
this.serviceRegistry.eventBus = eventBus;
|
|
1888
1962
|
}
|
|
1889
|
-
connect(options) {
|
|
1890
|
-
|
|
1963
|
+
async connect(options) {
|
|
1964
|
+
const ret = await this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
1965
|
+
await this.serviceRegistry.registerEntries();
|
|
1966
|
+
return ret;
|
|
1891
1967
|
}
|
|
1892
1968
|
disconnect(force) {
|
|
1893
1969
|
return this._eventBus.disconnect(force);
|
|
@@ -2101,15 +2177,15 @@ class CursorPageable extends Pageable {
|
|
|
2101
2177
|
}
|
|
2102
2178
|
// packages/core/src/api/crud/Sort.ts
|
|
2103
2179
|
var Direction;
|
|
2104
|
-
((
|
|
2105
|
-
|
|
2106
|
-
|
|
2180
|
+
((Direction) => {
|
|
2181
|
+
Direction["ASC"] = "ASC";
|
|
2182
|
+
Direction["DESC"] = "DESC";
|
|
2107
2183
|
})(Direction ||= {});
|
|
2108
2184
|
var NullHandling;
|
|
2109
|
-
((
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2185
|
+
((NullHandling) => {
|
|
2186
|
+
NullHandling["NATIVE"] = "NATIVE";
|
|
2187
|
+
NullHandling["NULLS_FIRST"] = "NULLS_FIRST";
|
|
2188
|
+
NullHandling["NULLS_LAST"] = "NULLS_LAST";
|
|
2113
2189
|
})(NullHandling ||= {});
|
|
2114
2190
|
|
|
2115
2191
|
class Order {
|
package/dist/index.d.cts
CHANGED
|
@@ -237,6 +237,13 @@ interface IEventBus {
|
|
|
237
237
|
*/
|
|
238
238
|
connectionEstablished: Observable<ConnectedInfo>;
|
|
239
239
|
/**
|
|
240
|
+
* Emits each time an attempt to connect fails before the server accepts the connection and the client
|
|
241
|
+
* will try again: the server could not be reached, or it closed the socket before answering. This
|
|
242
|
+
* covers the attempts of a pending {@link connect} as well as the reconnects after a connection ends.
|
|
243
|
+
* An attempt that ends the connection for good is reported by {@link connectionEnded} instead.
|
|
244
|
+
*/
|
|
245
|
+
connectionAttemptFailed: Observable<void>;
|
|
246
|
+
/**
|
|
240
247
|
* The {@link ServerInfo} used when connecting, if connected or null
|
|
241
248
|
*/
|
|
242
249
|
serverInfo: ServerInfo | null;
|
|
@@ -647,6 +654,7 @@ interface IServiceRegistry {
|
|
|
647
654
|
*/
|
|
648
655
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
649
656
|
}
|
|
657
|
+
import { ServiceDefinition } from "@kinotic-ai/idl";
|
|
650
658
|
/**
|
|
651
659
|
* An implementation of a {@link IEventFactory} which uses JSON content
|
|
652
660
|
*/
|
|
@@ -660,11 +668,20 @@ declare class TextEventFactory implements IEventFactory {
|
|
|
660
668
|
create(cri: string, args: any[] | null | undefined): IEvent;
|
|
661
669
|
}
|
|
662
670
|
/**
|
|
671
|
+
* Declares the definitions of the project's published services, as `kinotic sync` generates them into the
|
|
672
|
+
* project's ServiceDefinitions module, so every registry registers each service in the platform's service
|
|
673
|
+
* directory with its definition when the service comes online. A definition declared again for a qualified
|
|
674
|
+
* name replaces the one held.
|
|
675
|
+
* @param definitions the generated definitions
|
|
676
|
+
*/
|
|
677
|
+
declare function declareServiceDefinitions(definitions: ServiceDefinition[]): void;
|
|
678
|
+
/**
|
|
663
679
|
* The default implementation of {@link IServiceRegistry}
|
|
664
680
|
*/
|
|
665
681
|
declare class ServiceRegistry implements IServiceRegistry {
|
|
666
682
|
private _eventBus;
|
|
667
683
|
private supervisors;
|
|
684
|
+
private entries;
|
|
668
685
|
private contextInterceptor;
|
|
669
686
|
private debugLogger;
|
|
670
687
|
constructor(eventBus: IEventBus);
|
|
@@ -673,6 +690,14 @@ declare class ServiceRegistry implements IServiceRegistry {
|
|
|
673
690
|
serviceProxy(serviceIdentifier: string): IServiceProxy;
|
|
674
691
|
register(serviceIdentifier: ServiceIdentifier, service: any): void;
|
|
675
692
|
unRegister(serviceIdentifier: ServiceIdentifier): void;
|
|
693
|
+
/**
|
|
694
|
+
* Registers every application service registered so far in the platform's service directory, with the
|
|
695
|
+
* definition the project declared for it, so the directory lists the service and the platform checks
|
|
696
|
+
* requests to it; a service the platform refuses fails the registration. A service registered later is
|
|
697
|
+
* registered in the directory as it registers here.
|
|
698
|
+
*/
|
|
699
|
+
registerEntries(): Promise<void>;
|
|
700
|
+
private registerEntry;
|
|
676
701
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
677
702
|
}
|
|
678
703
|
/**
|
|
@@ -740,8 +765,9 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
740
765
|
get eventBus(): IEventBus;
|
|
741
766
|
set eventBus(eventBus: IEventBus);
|
|
742
767
|
/**
|
|
743
|
-
* Connects to a Kinotic server
|
|
744
|
-
*
|
|
768
|
+
* Connects to a Kinotic server and registers the application services registered so far in the platform's
|
|
769
|
+
* service directory. Every option is optional: absent server fields and credentials resolve from the
|
|
770
|
+
* environment — see {@link ConnectOptions}.
|
|
745
771
|
* @param options overrides for the resolved connection, or nothing to resolve everything
|
|
746
772
|
* @return Promise containing the result of the initial connection attempt
|
|
747
773
|
*/
|
|
@@ -829,6 +855,34 @@ declare function receivesContext(serviceInstance: object, methodName: string): b
|
|
|
829
855
|
* so it appears in directory listings
|
|
830
856
|
*/
|
|
831
857
|
declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
858
|
+
import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
|
|
859
|
+
/**
|
|
860
|
+
* A service of an application as its runtime registers it in the platform's service directory: the application
|
|
861
|
+
* it belongs to, where it is addressed, whether it is advertised, and its definition. The platform owns
|
|
862
|
+
* everything else about the directory's entry, such as the service's liveness.
|
|
863
|
+
*/
|
|
864
|
+
interface ServiceDirectoryEntry {
|
|
865
|
+
/**
|
|
866
|
+
* The application the service belongs to, which its zone names.
|
|
867
|
+
*/
|
|
868
|
+
applicationId: string;
|
|
869
|
+
/**
|
|
870
|
+
* The zone the service is addressed in, the application's or a label under it.
|
|
871
|
+
*/
|
|
872
|
+
zone: string;
|
|
873
|
+
/**
|
|
874
|
+
* The version the service registers under, or null for none.
|
|
875
|
+
*/
|
|
876
|
+
version: string | null;
|
|
877
|
+
/**
|
|
878
|
+
* True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
|
|
879
|
+
*/
|
|
880
|
+
advertised: boolean;
|
|
881
|
+
/**
|
|
882
|
+
* The service's definition: its functions, with the parameters a request carries and what each returns.
|
|
883
|
+
*/
|
|
884
|
+
serviceDefinition: ServiceDefinition2;
|
|
885
|
+
}
|
|
832
886
|
/**
|
|
833
887
|
* Validates that the given zone satisfies the zone grammar
|
|
834
888
|
* @param zone the zone to validate
|
|
@@ -1285,6 +1339,7 @@ declare class EventBus implements IEventBus {
|
|
|
1285
1339
|
constructor();
|
|
1286
1340
|
get connectionEnded(): Observable3<Error | null>;
|
|
1287
1341
|
get connectionEstablished(): Observable3<ConnectedInfo>;
|
|
1342
|
+
get connectionAttemptFailed(): Observable3<void>;
|
|
1288
1343
|
isConnectionActive(): boolean;
|
|
1289
1344
|
isConnected(): boolean;
|
|
1290
1345
|
connect(options: ConnectOptions): Promise<ConnectedInfo>;
|
|
@@ -1426,4 +1481,4 @@ declare class ParticipantConstants {
|
|
|
1426
1481
|
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1427
1482
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1428
1483
|
}
|
|
1429
|
-
export {
|
|
1484
|
+
export { AbstractIterablePage, AuthorizationException, BasicCredentialsResolver, BearerCredentialsResolver, CRI, ChainedCredentialsResolver, ConnectOptions, ConnectedInfo, Context, ContextInterceptor, CredentialsResolver, CrudServiceProxy, CrudServiceProxyFactory, CursorPageable, DataSourceUtils, DefaultCRI, Direction, EnvCredentialsResolver, Event, EventBus, EventConstants, FunctionalIterablePage, ICrudServiceProxy, ICrudServiceProxyFactory, IDataSource, IEditableDataSource, IEvent, IEventBus, IEventFactory, IKinotic, IParticipant, IServiceProxy, IServiceRegistry, IWebSocket, Identifiable, IterablePage, JsonEventFactory, Kinotic, KinoticPlugin, KinoticSingleton, NullHandling, OffsetPageable, Order, Page, Pageable, Participant, ParticipantConstants, Publish, ResolvedCredentials, RpcError, Scope, ScopeOptional, ServerInfo, ServiceContext, ServiceDirectoryEntry, ServiceIdentifier, ServiceRegistry, SessionCredentialsResolver, SessionKeepAliveMode, Sort, TextEventFactory, Version, WebSocketFactory, Zone, buildBrokerUrl, buildServerUrl, createCRI, declareServiceDefinitions, isAdvertised, receivesContext, scopeOptionalMethodNames, validateLabel, validateZone };
|
package/dist/index.d.ts
CHANGED
|
@@ -237,6 +237,13 @@ interface IEventBus {
|
|
|
237
237
|
*/
|
|
238
238
|
connectionEstablished: Observable<ConnectedInfo>;
|
|
239
239
|
/**
|
|
240
|
+
* Emits each time an attempt to connect fails before the server accepts the connection and the client
|
|
241
|
+
* will try again: the server could not be reached, or it closed the socket before answering. This
|
|
242
|
+
* covers the attempts of a pending {@link connect} as well as the reconnects after a connection ends.
|
|
243
|
+
* An attempt that ends the connection for good is reported by {@link connectionEnded} instead.
|
|
244
|
+
*/
|
|
245
|
+
connectionAttemptFailed: Observable<void>;
|
|
246
|
+
/**
|
|
240
247
|
* The {@link ServerInfo} used when connecting, if connected or null
|
|
241
248
|
*/
|
|
242
249
|
serverInfo: ServerInfo | null;
|
|
@@ -647,6 +654,7 @@ interface IServiceRegistry {
|
|
|
647
654
|
*/
|
|
648
655
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
649
656
|
}
|
|
657
|
+
import { ServiceDefinition } from "@kinotic-ai/idl";
|
|
650
658
|
/**
|
|
651
659
|
* An implementation of a {@link IEventFactory} which uses JSON content
|
|
652
660
|
*/
|
|
@@ -660,11 +668,20 @@ declare class TextEventFactory implements IEventFactory {
|
|
|
660
668
|
create(cri: string, args: any[] | null | undefined): IEvent;
|
|
661
669
|
}
|
|
662
670
|
/**
|
|
671
|
+
* Declares the definitions of the project's published services, as `kinotic sync` generates them into the
|
|
672
|
+
* project's ServiceDefinitions module, so every registry registers each service in the platform's service
|
|
673
|
+
* directory with its definition when the service comes online. A definition declared again for a qualified
|
|
674
|
+
* name replaces the one held.
|
|
675
|
+
* @param definitions the generated definitions
|
|
676
|
+
*/
|
|
677
|
+
declare function declareServiceDefinitions(definitions: ServiceDefinition[]): void;
|
|
678
|
+
/**
|
|
663
679
|
* The default implementation of {@link IServiceRegistry}
|
|
664
680
|
*/
|
|
665
681
|
declare class ServiceRegistry implements IServiceRegistry {
|
|
666
682
|
private _eventBus;
|
|
667
683
|
private supervisors;
|
|
684
|
+
private entries;
|
|
668
685
|
private contextInterceptor;
|
|
669
686
|
private debugLogger;
|
|
670
687
|
constructor(eventBus: IEventBus);
|
|
@@ -673,6 +690,14 @@ declare class ServiceRegistry implements IServiceRegistry {
|
|
|
673
690
|
serviceProxy(serviceIdentifier: string): IServiceProxy;
|
|
674
691
|
register(serviceIdentifier: ServiceIdentifier, service: any): void;
|
|
675
692
|
unRegister(serviceIdentifier: ServiceIdentifier): void;
|
|
693
|
+
/**
|
|
694
|
+
* Registers every application service registered so far in the platform's service directory, with the
|
|
695
|
+
* definition the project declared for it, so the directory lists the service and the platform checks
|
|
696
|
+
* requests to it; a service the platform refuses fails the registration. A service registered later is
|
|
697
|
+
* registered in the directory as it registers here.
|
|
698
|
+
*/
|
|
699
|
+
registerEntries(): Promise<void>;
|
|
700
|
+
private registerEntry;
|
|
676
701
|
registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
|
|
677
702
|
}
|
|
678
703
|
/**
|
|
@@ -740,8 +765,9 @@ declare class KinoticSingleton implements IKinotic {
|
|
|
740
765
|
get eventBus(): IEventBus;
|
|
741
766
|
set eventBus(eventBus: IEventBus);
|
|
742
767
|
/**
|
|
743
|
-
* Connects to a Kinotic server
|
|
744
|
-
*
|
|
768
|
+
* Connects to a Kinotic server and registers the application services registered so far in the platform's
|
|
769
|
+
* service directory. Every option is optional: absent server fields and credentials resolve from the
|
|
770
|
+
* environment — see {@link ConnectOptions}.
|
|
745
771
|
* @param options overrides for the resolved connection, or nothing to resolve everything
|
|
746
772
|
* @return Promise containing the result of the initial connection attempt
|
|
747
773
|
*/
|
|
@@ -829,6 +855,34 @@ declare function receivesContext(serviceInstance: object, methodName: string): b
|
|
|
829
855
|
* so it appears in directory listings
|
|
830
856
|
*/
|
|
831
857
|
declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
|
|
858
|
+
import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
|
|
859
|
+
/**
|
|
860
|
+
* A service of an application as its runtime registers it in the platform's service directory: the application
|
|
861
|
+
* it belongs to, where it is addressed, whether it is advertised, and its definition. The platform owns
|
|
862
|
+
* everything else about the directory's entry, such as the service's liveness.
|
|
863
|
+
*/
|
|
864
|
+
interface ServiceDirectoryEntry {
|
|
865
|
+
/**
|
|
866
|
+
* The application the service belongs to, which its zone names.
|
|
867
|
+
*/
|
|
868
|
+
applicationId: string;
|
|
869
|
+
/**
|
|
870
|
+
* The zone the service is addressed in, the application's or a label under it.
|
|
871
|
+
*/
|
|
872
|
+
zone: string;
|
|
873
|
+
/**
|
|
874
|
+
* The version the service registers under, or null for none.
|
|
875
|
+
*/
|
|
876
|
+
version: string | null;
|
|
877
|
+
/**
|
|
878
|
+
* True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
|
|
879
|
+
*/
|
|
880
|
+
advertised: boolean;
|
|
881
|
+
/**
|
|
882
|
+
* The service's definition: its functions, with the parameters a request carries and what each returns.
|
|
883
|
+
*/
|
|
884
|
+
serviceDefinition: ServiceDefinition2;
|
|
885
|
+
}
|
|
832
886
|
/**
|
|
833
887
|
* Validates that the given zone satisfies the zone grammar
|
|
834
888
|
* @param zone the zone to validate
|
|
@@ -1285,6 +1339,7 @@ declare class EventBus implements IEventBus {
|
|
|
1285
1339
|
constructor();
|
|
1286
1340
|
get connectionEnded(): Observable3<Error | null>;
|
|
1287
1341
|
get connectionEstablished(): Observable3<ConnectedInfo>;
|
|
1342
|
+
get connectionAttemptFailed(): Observable3<void>;
|
|
1288
1343
|
isConnectionActive(): boolean;
|
|
1289
1344
|
isConnected(): boolean;
|
|
1290
1345
|
connect(options: ConnectOptions): Promise<ConnectedInfo>;
|
|
@@ -1426,4 +1481,4 @@ declare class ParticipantConstants {
|
|
|
1426
1481
|
/** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
|
|
1427
1482
|
static readonly CLI_PARTICIPANT_ID: string;
|
|
1428
1483
|
}
|
|
1429
|
-
export {
|
|
1484
|
+
export { AbstractIterablePage, AuthorizationException, BasicCredentialsResolver, BearerCredentialsResolver, CRI, ChainedCredentialsResolver, ConnectOptions, ConnectedInfo, Context, ContextInterceptor, CredentialsResolver, CrudServiceProxy, CrudServiceProxyFactory, CursorPageable, DataSourceUtils, DefaultCRI, Direction, EnvCredentialsResolver, Event, EventBus, EventConstants, FunctionalIterablePage, ICrudServiceProxy, ICrudServiceProxyFactory, IDataSource, IEditableDataSource, IEvent, IEventBus, IEventFactory, IKinotic, IParticipant, IServiceProxy, IServiceRegistry, IWebSocket, Identifiable, IterablePage, JsonEventFactory, Kinotic, KinoticPlugin, KinoticSingleton, NullHandling, OffsetPageable, Order, Page, Pageable, Participant, ParticipantConstants, Publish, ResolvedCredentials, RpcError, Scope, ScopeOptional, ServerInfo, ServiceContext, ServiceDirectoryEntry, ServiceIdentifier, ServiceRegistry, SessionCredentialsResolver, SessionKeepAliveMode, Sort, TextEventFactory, Version, WebSocketFactory, Zone, buildBrokerUrl, buildServerUrl, createCRI, declareServiceDefinitions, isAdvertised, receivesContext, scopeOptionalMethodNames, validateLabel, validateZone };
|
package/dist/index.js
CHANGED
|
@@ -11,40 +11,40 @@ function buildBrokerUrl(server) {
|
|
|
11
11
|
return buildServerUrl(server, "ws") + "/api/v1";
|
|
12
12
|
}
|
|
13
13
|
var SessionKeepAliveMode;
|
|
14
|
-
((
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
((SessionKeepAliveMode) => {
|
|
15
|
+
SessionKeepAliveMode["NONE"] = "NONE";
|
|
16
|
+
SessionKeepAliveMode["ACTIVITY"] = "ACTIVITY";
|
|
17
|
+
SessionKeepAliveMode["CONNECTION"] = "CONNECTION";
|
|
18
18
|
})(SessionKeepAliveMode ||= {});
|
|
19
19
|
// packages/core/src/api/event/IEventBus.ts
|
|
20
20
|
var EventConstants;
|
|
21
|
-
((
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
((EventConstants) => {
|
|
22
|
+
EventConstants["CONTENT_TYPE_HEADER"] = "content-type";
|
|
23
|
+
EventConstants["CONTENT_LENGTH_HEADER"] = "content-length";
|
|
24
|
+
EventConstants["REPLY_TO_HEADER"] = "reply-to";
|
|
25
|
+
EventConstants["SENDER_HEADER"] = "sender";
|
|
26
|
+
EventConstants["CONNECTED_INFO_HEADER"] = "connected-info";
|
|
27
|
+
EventConstants["SESSION_KEEP_ALIVE_HEADER"] = "session-keep-alive";
|
|
28
|
+
EventConstants["CORRELATION_ID_HEADER"] = "__correlation-id";
|
|
29
|
+
EventConstants["ORIGIN_CRI_HEADER"] = "__origin-cri";
|
|
30
|
+
EventConstants["ERROR_HEADER"] = "error";
|
|
31
|
+
EventConstants["COMPLETE_HEADER"] = "complete";
|
|
32
|
+
EventConstants["CONTROL_HEADER"] = "control";
|
|
33
|
+
EventConstants["CONTROL_VALUE_COMPLETE"] = "complete";
|
|
34
|
+
EventConstants["CONTROL_VALUE_CANCEL"] = "cancel";
|
|
35
|
+
EventConstants["CONTROL_VALUE_SUSPEND"] = "suspend";
|
|
36
|
+
EventConstants["CONTROL_VALUE_RESUME"] = "resume";
|
|
37
|
+
EventConstants["SERVICE_DESTINATION_PREFIX"] = "srv://";
|
|
38
|
+
EventConstants["SERVICE_DESTINATION_SCHEME"] = "srv";
|
|
39
|
+
EventConstants["STREAM_DESTINATION_PREFIX"] = "stream://";
|
|
40
|
+
EventConstants["STREAM_DESTINATION_SCHEME"] = "stream";
|
|
41
|
+
EventConstants["REPLY_DESTINATION_PREFIX"] = "reply://";
|
|
42
|
+
EventConstants["REPLY_DESTINATION_SCHEME"] = "reply";
|
|
43
|
+
EventConstants["CONTENT_JSON"] = "application/json";
|
|
44
|
+
EventConstants["CONTENT_TEXT"] = "text/plain";
|
|
45
|
+
EventConstants["CONTENT_OCTET_STREAM"] = "application/octet-stream";
|
|
46
|
+
EventConstants["TRACEPARENT_HEADER"] = "traceparent";
|
|
47
|
+
EventConstants["TRACESTATE_HEADER"] = "tracestate";
|
|
48
48
|
})(EventConstants ||= {});
|
|
49
49
|
|
|
50
50
|
// packages/core/src/internal/api/Logger.ts
|
|
@@ -134,6 +134,7 @@ class StompConnectionManager {
|
|
|
134
134
|
connectionAttempts = 0;
|
|
135
135
|
debugLogger = debug2("kinotic:stomp");
|
|
136
136
|
connectionEstablishedSubject = new Subject;
|
|
137
|
+
connectionAttemptFailedSubject = new Subject;
|
|
137
138
|
initialConnectionSuccessful = false;
|
|
138
139
|
rxStompHasConnected = false;
|
|
139
140
|
_replyToCri = null;
|
|
@@ -149,6 +150,9 @@ class StompConnectionManager {
|
|
|
149
150
|
get connectionEstablished() {
|
|
150
151
|
return this.connectionEstablishedSubject.asObservable();
|
|
151
152
|
}
|
|
153
|
+
get connectionAttemptFailed() {
|
|
154
|
+
return this.connectionAttemptFailedSubject.asObservable();
|
|
155
|
+
}
|
|
152
156
|
async activate(options) {
|
|
153
157
|
if (!options?.server?.host) {
|
|
154
158
|
throw new Error("No host provided");
|
|
@@ -210,7 +214,7 @@ class StompConnectionManager {
|
|
|
210
214
|
webSocketFactory: usesPreparedSocket ? takePreparedSocket : undefined,
|
|
211
215
|
beforeConnect: () => {
|
|
212
216
|
const attempt = this.prepareAttempt(activation, options, server, headerAuth);
|
|
213
|
-
const settled = () => new Promise((
|
|
217
|
+
const settled = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
214
218
|
activation.attempt = attempt.then(settled, settled);
|
|
215
219
|
return attempt;
|
|
216
220
|
}
|
|
@@ -221,12 +225,8 @@ class StompConnectionManager {
|
|
|
221
225
|
};
|
|
222
226
|
}
|
|
223
227
|
this.rxStomp.configure(stompConfig);
|
|
224
|
-
activation.own(this.rxStomp.webSocketErrors$.subscribe(
|
|
228
|
+
activation.own(this.rxStomp.webSocketErrors$.subscribe((value) => {
|
|
225
229
|
this.lastWebsocketError = value;
|
|
226
|
-
if (!activation.ended && options?.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
|
|
227
|
-
this.maxConnectionAttemptsReached = true;
|
|
228
|
-
await this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: value ?? undefined }));
|
|
229
|
-
}
|
|
230
230
|
}));
|
|
231
231
|
activation.own(this.rxStomp.stompErrors$.subscribe(async (frame) => {
|
|
232
232
|
const stompError = new Error(frame.headers["message"], { cause: frame });
|
|
@@ -263,8 +263,17 @@ class StompConnectionManager {
|
|
|
263
263
|
}));
|
|
264
264
|
let previousState = this.rxStomp.connectionState$.getValue();
|
|
265
265
|
activation.own(this.rxStomp.connectionState$.subscribe((state) => {
|
|
266
|
-
if (state === RxStompState.CLOSED &&
|
|
267
|
-
|
|
266
|
+
if (state === RxStompState.CLOSED && this.activation === activation) {
|
|
267
|
+
if (previousState === RxStompState.OPEN) {
|
|
268
|
+
this.connectionEndedHandler?.(null);
|
|
269
|
+
} else if (previousState === RxStompState.CONNECTING) {
|
|
270
|
+
if (options.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
|
|
271
|
+
this.maxConnectionAttemptsReached = true;
|
|
272
|
+
this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
|
|
273
|
+
} else {
|
|
274
|
+
this.connectionAttemptFailedSubject.next();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
268
277
|
}
|
|
269
278
|
previousState = state;
|
|
270
279
|
}));
|
|
@@ -290,16 +299,8 @@ class StompConnectionManager {
|
|
|
290
299
|
}
|
|
291
300
|
if (options?.maxConnectionAttempts) {
|
|
292
301
|
this.connectionAttempts++;
|
|
293
|
-
if (this.connectionAttempts > options.maxConnectionAttempts) {
|
|
294
|
-
this.maxConnectionAttemptsReached = true;
|
|
295
|
-
await this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
|
|
296
|
-
return;
|
|
297
|
-
} else {
|
|
298
|
-
await this.connectionJitterDelay(activation);
|
|
299
|
-
}
|
|
300
|
-
} else {
|
|
301
|
-
await this.connectionJitterDelay(activation);
|
|
302
302
|
}
|
|
303
|
+
await this.connectionJitterDelay(activation);
|
|
303
304
|
if (activation.ended) {
|
|
304
305
|
return;
|
|
305
306
|
}
|
|
@@ -474,6 +475,9 @@ class EventBus {
|
|
|
474
475
|
get connectionEstablished() {
|
|
475
476
|
return this.stompConnectionManager.connectionEstablished;
|
|
476
477
|
}
|
|
478
|
+
get connectionAttemptFailed() {
|
|
479
|
+
return this.stompConnectionManager.connectionAttemptFailed;
|
|
480
|
+
}
|
|
477
481
|
isConnectionActive() {
|
|
478
482
|
return this.stompConnectionManager.active;
|
|
479
483
|
}
|
|
@@ -1181,7 +1185,7 @@ import opentelemetry, { context as context2, propagation as propagation2, trace,
|
|
|
1181
1185
|
// packages/core/package.json
|
|
1182
1186
|
var package_default = {
|
|
1183
1187
|
name: "@kinotic-ai/core",
|
|
1184
|
-
version: "5.0.0-beta.
|
|
1188
|
+
version: "5.0.0-beta.26",
|
|
1185
1189
|
type: "module",
|
|
1186
1190
|
files: [
|
|
1187
1191
|
"dist"
|
|
@@ -1250,6 +1254,7 @@ var package_default = {
|
|
|
1250
1254
|
vitest: "^4.1.4"
|
|
1251
1255
|
},
|
|
1252
1256
|
dependencies: {
|
|
1257
|
+
"@kinotic-ai/idl": "workspace:^",
|
|
1253
1258
|
"@opentelemetry/api": "^1.9.1",
|
|
1254
1259
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
1255
1260
|
"@stomp/rx-stomp": "^2.4.0",
|
|
@@ -1643,10 +1648,59 @@ class TextEventFactory {
|
|
|
1643
1648
|
return event;
|
|
1644
1649
|
}
|
|
1645
1650
|
}
|
|
1651
|
+
var APPLICATION_SERVICE_DIRECTORY = "app-api~org.kinotic.app.api.services.ApplicationServiceDirectory";
|
|
1652
|
+
var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
|
|
1653
|
+
var declaredDefinitions = new Map;
|
|
1654
|
+
function declareServiceDefinitions(definitions) {
|
|
1655
|
+
for (const definition of definitions) {
|
|
1656
|
+
declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
function qualifiedNameOf(namespace, name) {
|
|
1660
|
+
return namespace ? `${namespace}.${name}` : name;
|
|
1661
|
+
}
|
|
1662
|
+
function servedFunctions(serviceInstance) {
|
|
1663
|
+
const ret = new Set;
|
|
1664
|
+
let proto = Object.getPrototypeOf(serviceInstance);
|
|
1665
|
+
while (proto && proto !== Object.prototype) {
|
|
1666
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
1667
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
1668
|
+
if (typeof descriptor?.value === "function" && key !== "constructor") {
|
|
1669
|
+
ret.add(key);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
proto = Object.getPrototypeOf(proto);
|
|
1673
|
+
}
|
|
1674
|
+
return [...ret].sort();
|
|
1675
|
+
}
|
|
1676
|
+
function directoryEntryOf(serviceInstance, serviceIdentifier) {
|
|
1677
|
+
let ret = null;
|
|
1678
|
+
const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
|
|
1679
|
+
if (application) {
|
|
1680
|
+
const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
|
|
1681
|
+
const definition = declaredDefinitions.get(qualifiedName);
|
|
1682
|
+
if (definition) {
|
|
1683
|
+
const declared = definition.functions.map((f) => f.name).sort();
|
|
1684
|
+
const served = servedFunctions(serviceInstance);
|
|
1685
|
+
if (declared.join() !== served.join()) {
|
|
1686
|
+
throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
|
|
1687
|
+
}
|
|
1688
|
+
ret = {
|
|
1689
|
+
applicationId: application[1],
|
|
1690
|
+
zone: serviceIdentifier.zone,
|
|
1691
|
+
version: serviceIdentifier.version ?? null,
|
|
1692
|
+
advertised: isAdvertised(serviceInstance),
|
|
1693
|
+
serviceDefinition: definition
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
return ret;
|
|
1698
|
+
}
|
|
1646
1699
|
|
|
1647
1700
|
class ServiceRegistry {
|
|
1648
1701
|
_eventBus;
|
|
1649
1702
|
supervisors = new Map;
|
|
1703
|
+
entries = new Map;
|
|
1650
1704
|
contextInterceptor = null;
|
|
1651
1705
|
debugLogger = debug3("kinotic:serviceRegistry");
|
|
1652
1706
|
constructor(eventBus) {
|
|
@@ -1668,9 +1722,16 @@ class ServiceRegistry {
|
|
|
1668
1722
|
const criString = serviceIdentifier.cri().raw();
|
|
1669
1723
|
if (!this.supervisors.has(criString)) {
|
|
1670
1724
|
this.debugLogger(`Registering service for CRI: ${criString}`);
|
|
1725
|
+
const entry = directoryEntryOf(service, serviceIdentifier);
|
|
1671
1726
|
const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
|
|
1672
1727
|
this.supervisors.set(criString, supervisor);
|
|
1673
1728
|
supervisor.start();
|
|
1729
|
+
if (entry) {
|
|
1730
|
+
this.entries.set(criString, entry);
|
|
1731
|
+
if (this.eventBus.isConnected()) {
|
|
1732
|
+
this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1674
1735
|
}
|
|
1675
1736
|
}
|
|
1676
1737
|
unRegister(serviceIdentifier) {
|
|
@@ -1680,8 +1741,18 @@ class ServiceRegistry {
|
|
|
1680
1741
|
this.debugLogger(`Unregistering service for CRI: ${criString}`);
|
|
1681
1742
|
supervisor.stop();
|
|
1682
1743
|
this.supervisors.delete(criString);
|
|
1744
|
+
this.entries.delete(criString);
|
|
1683
1745
|
}
|
|
1684
1746
|
}
|
|
1747
|
+
async registerEntries() {
|
|
1748
|
+
for (const entry of this.entries.values()) {
|
|
1749
|
+
await this.registerEntry(entry);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
async registerEntry(entry) {
|
|
1753
|
+
this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
|
|
1754
|
+
await this.serviceProxy(APPLICATION_SERVICE_DIRECTORY).invoke("register", [entry]);
|
|
1755
|
+
}
|
|
1685
1756
|
registerContextInterceptor(interceptor) {
|
|
1686
1757
|
this.contextInterceptor = interceptor;
|
|
1687
1758
|
}
|
|
@@ -1773,8 +1844,10 @@ class KinoticSingleton {
|
|
|
1773
1844
|
this._eventBus = eventBus;
|
|
1774
1845
|
this.serviceRegistry.eventBus = eventBus;
|
|
1775
1846
|
}
|
|
1776
|
-
connect(options) {
|
|
1777
|
-
|
|
1847
|
+
async connect(options) {
|
|
1848
|
+
const ret = await this._eventBus.connect(Util.resolveConnectOptions(options));
|
|
1849
|
+
await this.serviceRegistry.registerEntries();
|
|
1850
|
+
return ret;
|
|
1778
1851
|
}
|
|
1779
1852
|
disconnect(force) {
|
|
1780
1853
|
return this._eventBus.disconnect(force);
|
|
@@ -1988,15 +2061,15 @@ class CursorPageable extends Pageable {
|
|
|
1988
2061
|
}
|
|
1989
2062
|
// packages/core/src/api/crud/Sort.ts
|
|
1990
2063
|
var Direction;
|
|
1991
|
-
((
|
|
1992
|
-
|
|
1993
|
-
|
|
2064
|
+
((Direction) => {
|
|
2065
|
+
Direction["ASC"] = "ASC";
|
|
2066
|
+
Direction["DESC"] = "DESC";
|
|
1994
2067
|
})(Direction ||= {});
|
|
1995
2068
|
var NullHandling;
|
|
1996
|
-
((
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2069
|
+
((NullHandling) => {
|
|
2070
|
+
NullHandling["NATIVE"] = "NATIVE";
|
|
2071
|
+
NullHandling["NULLS_FIRST"] = "NULLS_FIRST";
|
|
2072
|
+
NullHandling["NULLS_LAST"] = "NULLS_LAST";
|
|
2000
2073
|
})(NullHandling ||= {});
|
|
2001
2074
|
|
|
2002
2075
|
class Order {
|
|
@@ -2041,51 +2114,52 @@ class ParticipantConstants {
|
|
|
2041
2114
|
static CLI_PARTICIPANT_ID = "-42-Kinotic-CLI-42-";
|
|
2042
2115
|
}
|
|
2043
2116
|
export {
|
|
2044
|
-
|
|
2045
|
-
validateLabel,
|
|
2046
|
-
scopeOptionalMethodNames,
|
|
2047
|
-
receivesContext,
|
|
2048
|
-
isAdvertised,
|
|
2049
|
-
createCRI,
|
|
2050
|
-
buildServerUrl,
|
|
2051
|
-
buildBrokerUrl,
|
|
2052
|
-
Zone,
|
|
2053
|
-
Version,
|
|
2054
|
-
TextEventFactory,
|
|
2055
|
-
Sort,
|
|
2056
|
-
SessionKeepAliveMode,
|
|
2057
|
-
SessionCredentialsResolver,
|
|
2058
|
-
ServiceRegistry,
|
|
2059
|
-
ServiceIdentifier,
|
|
2060
|
-
ServerInfo,
|
|
2061
|
-
ScopeOptional,
|
|
2062
|
-
Scope,
|
|
2063
|
-
RpcError,
|
|
2064
|
-
Publish,
|
|
2065
|
-
ParticipantConstants,
|
|
2066
|
-
Pageable,
|
|
2067
|
-
Order,
|
|
2068
|
-
OffsetPageable,
|
|
2069
|
-
NullHandling,
|
|
2070
|
-
KinoticSingleton,
|
|
2071
|
-
Kinotic,
|
|
2072
|
-
JsonEventFactory,
|
|
2073
|
-
FunctionalIterablePage,
|
|
2074
|
-
EventConstants,
|
|
2075
|
-
EventBus,
|
|
2076
|
-
Event,
|
|
2077
|
-
EnvCredentialsResolver,
|
|
2078
|
-
Direction,
|
|
2079
|
-
DefaultCRI,
|
|
2080
|
-
DataSourceUtils,
|
|
2081
|
-
CursorPageable,
|
|
2082
|
-
CrudServiceProxyFactory,
|
|
2083
|
-
CrudServiceProxy,
|
|
2084
|
-
Context,
|
|
2085
|
-
ConnectedInfo,
|
|
2086
|
-
ChainedCredentialsResolver,
|
|
2087
|
-
BearerCredentialsResolver,
|
|
2088
|
-
BasicCredentialsResolver,
|
|
2117
|
+
AbstractIterablePage,
|
|
2089
2118
|
AuthorizationException,
|
|
2090
|
-
|
|
2119
|
+
BasicCredentialsResolver,
|
|
2120
|
+
BearerCredentialsResolver,
|
|
2121
|
+
ChainedCredentialsResolver,
|
|
2122
|
+
ConnectedInfo,
|
|
2123
|
+
Context,
|
|
2124
|
+
CrudServiceProxy,
|
|
2125
|
+
CrudServiceProxyFactory,
|
|
2126
|
+
CursorPageable,
|
|
2127
|
+
DataSourceUtils,
|
|
2128
|
+
DefaultCRI,
|
|
2129
|
+
Direction,
|
|
2130
|
+
EnvCredentialsResolver,
|
|
2131
|
+
Event,
|
|
2132
|
+
EventBus,
|
|
2133
|
+
EventConstants,
|
|
2134
|
+
FunctionalIterablePage,
|
|
2135
|
+
JsonEventFactory,
|
|
2136
|
+
Kinotic,
|
|
2137
|
+
KinoticSingleton,
|
|
2138
|
+
NullHandling,
|
|
2139
|
+
OffsetPageable,
|
|
2140
|
+
Order,
|
|
2141
|
+
Pageable,
|
|
2142
|
+
ParticipantConstants,
|
|
2143
|
+
Publish,
|
|
2144
|
+
RpcError,
|
|
2145
|
+
Scope,
|
|
2146
|
+
ScopeOptional,
|
|
2147
|
+
ServerInfo,
|
|
2148
|
+
ServiceIdentifier,
|
|
2149
|
+
ServiceRegistry,
|
|
2150
|
+
SessionCredentialsResolver,
|
|
2151
|
+
SessionKeepAliveMode,
|
|
2152
|
+
Sort,
|
|
2153
|
+
TextEventFactory,
|
|
2154
|
+
Version,
|
|
2155
|
+
Zone,
|
|
2156
|
+
buildBrokerUrl,
|
|
2157
|
+
buildServerUrl,
|
|
2158
|
+
createCRI,
|
|
2159
|
+
declareServiceDefinitions,
|
|
2160
|
+
isAdvertised,
|
|
2161
|
+
receivesContext,
|
|
2162
|
+
scopeOptionalMethodNames,
|
|
2163
|
+
validateLabel,
|
|
2164
|
+
validateZone
|
|
2091
2165
|
};
|
package/dist/node/index.cjs
CHANGED
|
@@ -19,13 +19,15 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
19
19
|
return cached;
|
|
20
20
|
}
|
|
21
21
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
24
|
+
for (let key of __getOwnPropNames(mod))
|
|
25
|
+
if (!__hasOwnProp.call(to, key))
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: __accessProp.bind(mod, key),
|
|
28
|
+
enumerable: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
29
31
|
if (canCache)
|
|
30
32
|
cache.set(mod, to);
|
|
31
33
|
return to;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinotic-ai/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.26",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"vitest": "^4.1.4"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
+
"@kinotic-ai/idl": "^5.0.0-beta.5",
|
|
72
73
|
"@opentelemetry/api": "^1.9.1",
|
|
73
74
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
74
75
|
"@stomp/rx-stomp": "^2.4.0",
|