@kinotic-ai/core 5.0.0-beta.25 → 5.0.0-beta.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -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
- for (let key of __getOwnPropNames(mod))
24
- if (!__hasOwnProp.call(to, key))
25
- __defProp(to, key, {
26
- get: __accessProp.bind(mod, key),
27
- enumerable: true
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,54 +66,54 @@ var __export = (target, all) => {
64
66
  // packages/core/src/index.ts
65
67
  var exports_src = {};
66
68
  __export(exports_src, {
67
- validateZone: () => validateZone,
68
- validateLabel: () => validateLabel,
69
- scopeOptionalMethodNames: () => scopeOptionalMethodNames,
70
- receivesContext: () => receivesContext,
71
- isAdvertised: () => isAdvertised,
72
- declareServiceDefinitions: () => declareServiceDefinitions,
73
- createCRI: () => createCRI,
74
- buildServerUrl: () => buildServerUrl,
75
- buildBrokerUrl: () => buildBrokerUrl,
76
- Zone: () => Zone,
77
- Version: () => Version,
78
- TextEventFactory: () => TextEventFactory,
79
- Sort: () => Sort,
80
- SessionKeepAliveMode: () => SessionKeepAliveMode,
81
- SessionCredentialsResolver: () => SessionCredentialsResolver,
82
- ServiceRegistry: () => ServiceRegistry,
83
- ServiceIdentifier: () => ServiceIdentifier,
84
- ServerInfo: () => ServerInfo,
85
- ScopeOptional: () => ScopeOptional,
86
- Scope: () => Scope,
87
- RpcError: () => RpcError,
88
- Publish: () => Publish,
89
- ParticipantConstants: () => ParticipantConstants,
90
- Pageable: () => Pageable,
91
- Order: () => Order,
92
- OffsetPageable: () => OffsetPageable,
93
- NullHandling: () => NullHandling,
94
- KinoticSingleton: () => KinoticSingleton,
95
- Kinotic: () => Kinotic,
96
- JsonEventFactory: () => JsonEventFactory,
97
- FunctionalIterablePage: () => FunctionalIterablePage,
98
- EventConstants: () => EventConstants,
99
- EventBus: () => EventBus,
100
- Event: () => Event,
101
- EnvCredentialsResolver: () => EnvCredentialsResolver,
102
- Direction: () => Direction,
103
- DefaultCRI: () => DefaultCRI,
104
- DataSourceUtils: () => DataSourceUtils,
105
- CursorPageable: () => CursorPageable,
106
- CrudServiceProxyFactory: () => CrudServiceProxyFactory,
107
- CrudServiceProxy: () => CrudServiceProxy,
108
- Context: () => Context,
109
- ConnectedInfo: () => ConnectedInfo,
110
- ChainedCredentialsResolver: () => ChainedCredentialsResolver,
111
- BearerCredentialsResolver: () => BearerCredentialsResolver,
112
- BasicCredentialsResolver: () => BasicCredentialsResolver,
69
+ AbstractIterablePage: () => AbstractIterablePage,
113
70
  AuthorizationException: () => AuthorizationException,
114
- AbstractIterablePage: () => AbstractIterablePage
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
115
117
  });
116
118
  module.exports = __toCommonJS(exports_src);
117
119
 
@@ -128,44 +130,44 @@ function buildBrokerUrl(server) {
128
130
  return buildServerUrl(server, "ws") + "/api/v1";
129
131
  }
130
132
  var SessionKeepAliveMode;
131
- ((SessionKeepAliveMode2) => {
132
- SessionKeepAliveMode2["NONE"] = "NONE";
133
- SessionKeepAliveMode2["ACTIVITY"] = "ACTIVITY";
134
- SessionKeepAliveMode2["CONNECTION"] = "CONNECTION";
133
+ ((SessionKeepAliveMode) => {
134
+ SessionKeepAliveMode["NONE"] = "NONE";
135
+ SessionKeepAliveMode["ACTIVITY"] = "ACTIVITY";
136
+ SessionKeepAliveMode["CONNECTION"] = "CONNECTION";
135
137
  })(SessionKeepAliveMode ||= {});
136
138
  // packages/core/src/api/event/IEventBus.ts
137
139
  var EventConstants;
138
- ((EventConstants2) => {
139
- EventConstants2["CONTENT_TYPE_HEADER"] = "content-type";
140
- EventConstants2["CONTENT_LENGTH_HEADER"] = "content-length";
141
- EventConstants2["REPLY_TO_HEADER"] = "reply-to";
142
- EventConstants2["SENDER_HEADER"] = "sender";
143
- EventConstants2["CONNECTED_INFO_HEADER"] = "connected-info";
144
- EventConstants2["SESSION_KEEP_ALIVE_HEADER"] = "session-keep-alive";
145
- EventConstants2["CORRELATION_ID_HEADER"] = "__correlation-id";
146
- EventConstants2["ORIGIN_CRI_HEADER"] = "__origin-cri";
147
- EventConstants2["ERROR_HEADER"] = "error";
148
- EventConstants2["COMPLETE_HEADER"] = "complete";
149
- EventConstants2["CONTROL_HEADER"] = "control";
150
- EventConstants2["CONTROL_VALUE_COMPLETE"] = "complete";
151
- EventConstants2["CONTROL_VALUE_CANCEL"] = "cancel";
152
- EventConstants2["CONTROL_VALUE_SUSPEND"] = "suspend";
153
- EventConstants2["CONTROL_VALUE_RESUME"] = "resume";
154
- EventConstants2["SERVICE_DESTINATION_PREFIX"] = "srv://";
155
- EventConstants2["SERVICE_DESTINATION_SCHEME"] = "srv";
156
- EventConstants2["STREAM_DESTINATION_PREFIX"] = "stream://";
157
- EventConstants2["STREAM_DESTINATION_SCHEME"] = "stream";
158
- EventConstants2["REPLY_DESTINATION_PREFIX"] = "reply://";
159
- EventConstants2["REPLY_DESTINATION_SCHEME"] = "reply";
160
- EventConstants2["CONTENT_JSON"] = "application/json";
161
- EventConstants2["CONTENT_TEXT"] = "text/plain";
162
- EventConstants2["CONTENT_OCTET_STREAM"] = "application/octet-stream";
163
- EventConstants2["TRACEPARENT_HEADER"] = "traceparent";
164
- EventConstants2["TRACESTATE_HEADER"] = "tracestate";
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";
165
167
  })(EventConstants ||= {});
166
168
 
167
169
  // packages/core/src/internal/api/Logger.ts
168
- var import_debug = __toESM(require("debug"));
170
+ var import_debug = __toESM(require("debug"), 1);
169
171
  function createDebugLogger(namespace) {
170
172
  const debugLogger = import_debug.default(namespace);
171
173
  return {
@@ -180,7 +182,7 @@ function createDebugLogger(namespace) {
180
182
  // packages/core/src/internal/api/StompConnectionManager.ts
181
183
  var import_rx_stomp = require("@stomp/rx-stomp");
182
184
  var import_stompjs = require("@stomp/stompjs");
183
- var import_debug2 = __toESM(require("debug"));
185
+ var import_debug2 = __toESM(require("debug"), 1);
184
186
  var import_rxjs = require("rxjs");
185
187
  var import_operators = require("rxjs/operators");
186
188
  var import_uuid = require("uuid");
@@ -248,9 +250,11 @@ class StompConnectionManager {
248
250
  INITIAL_RECONNECT_DELAY = 2000;
249
251
  JITTER_MAX = 5000;
250
252
  MAX_RECONNECT_DELAY = 120000;
253
+ CONNECTION_TIMEOUT = 1e4;
251
254
  connectionAttempts = 0;
252
255
  debugLogger = import_debug2.default("kinotic:stomp");
253
256
  connectionEstablishedSubject = new import_rxjs.Subject;
257
+ connectionAttemptFailedSubject = new import_rxjs.Subject;
254
258
  initialConnectionSuccessful = false;
255
259
  rxStompHasConnected = false;
256
260
  _replyToCri = null;
@@ -266,6 +270,9 @@ class StompConnectionManager {
266
270
  get connectionEstablished() {
267
271
  return this.connectionEstablishedSubject.asObservable();
268
272
  }
273
+ get connectionAttemptFailed() {
274
+ return this.connectionAttemptFailedSubject.asObservable();
275
+ }
269
276
  async activate(options) {
270
277
  if (!options?.server?.host) {
271
278
  throw new Error("No host provided");
@@ -321,13 +328,14 @@ class StompConnectionManager {
321
328
  },
322
329
  heartbeatIncoming: 30000,
323
330
  heartbeatOutgoing: 30000,
331
+ connectionTimeout: this.CONNECTION_TIMEOUT,
324
332
  reconnectDelay: this.INITIAL_RECONNECT_DELAY,
325
333
  maxReconnectDelay: this.MAX_RECONNECT_DELAY,
326
334
  reconnectTimeMode: import_stompjs.ReconnectionTimeMode.EXPONENTIAL,
327
335
  webSocketFactory: usesPreparedSocket ? takePreparedSocket : undefined,
328
336
  beforeConnect: () => {
329
337
  const attempt = this.prepareAttempt(activation, options, server, headerAuth);
330
- const settled = () => new Promise((resolve2) => setTimeout(resolve2, 0));
338
+ const settled = () => new Promise((resolve) => setTimeout(resolve, 0));
331
339
  activation.attempt = attempt.then(settled, settled);
332
340
  return attempt;
333
341
  }
@@ -338,12 +346,8 @@ class StompConnectionManager {
338
346
  };
339
347
  }
340
348
  this.rxStomp.configure(stompConfig);
341
- activation.own(this.rxStomp.webSocketErrors$.subscribe(async (value) => {
349
+ activation.own(this.rxStomp.webSocketErrors$.subscribe((value) => {
342
350
  this.lastWebsocketError = value;
343
- if (!activation.ended && options?.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
344
- this.maxConnectionAttemptsReached = true;
345
- await this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: value ?? undefined }));
346
- }
347
351
  }));
348
352
  activation.own(this.rxStomp.stompErrors$.subscribe(async (frame) => {
349
353
  const stompError = new Error(frame.headers["message"], { cause: frame });
@@ -380,8 +384,17 @@ class StompConnectionManager {
380
384
  }));
381
385
  let previousState = this.rxStomp.connectionState$.getValue();
382
386
  activation.own(this.rxStomp.connectionState$.subscribe((state) => {
383
- if (state === import_rx_stomp.RxStompState.CLOSED && previousState === import_rx_stomp.RxStompState.OPEN && this.activation === activation) {
384
- this.connectionEndedHandler?.(null);
387
+ if (state === import_rx_stomp.RxStompState.CLOSED && this.activation === activation) {
388
+ if (previousState === import_rx_stomp.RxStompState.OPEN) {
389
+ this.connectionEndedHandler?.(null);
390
+ } else if (previousState === import_rx_stomp.RxStompState.CONNECTING) {
391
+ if (options.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
392
+ this.maxConnectionAttemptsReached = true;
393
+ this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
394
+ } else {
395
+ this.connectionAttemptFailedSubject.next();
396
+ }
397
+ }
385
398
  }
386
399
  previousState = state;
387
400
  }));
@@ -407,16 +420,8 @@ class StompConnectionManager {
407
420
  }
408
421
  if (options?.maxConnectionAttempts) {
409
422
  this.connectionAttempts++;
410
- if (this.connectionAttempts > options.maxConnectionAttempts) {
411
- this.maxConnectionAttemptsReached = true;
412
- await this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
413
- return;
414
- } else {
415
- await this.connectionJitterDelay(activation);
416
- }
417
- } else {
418
- await this.connectionJitterDelay(activation);
419
423
  }
424
+ await this.connectionJitterDelay(activation);
420
425
  if (activation.ended) {
421
426
  return;
422
427
  }
@@ -591,6 +596,9 @@ class EventBus {
591
596
  get connectionEstablished() {
592
597
  return this.stompConnectionManager.connectionEstablished;
593
598
  }
599
+ get connectionAttemptFailed() {
600
+ return this.stompConnectionManager.connectionAttemptFailed;
601
+ }
594
602
  isConnectionActive() {
595
603
  return this.stompConnectionManager.active;
596
604
  }
@@ -922,7 +930,7 @@ class Util {
922
930
  }
923
931
 
924
932
  // packages/core/src/api/ServiceRegistry.ts
925
- var import_debug3 = __toESM(require("debug"));
933
+ var import_debug3 = __toESM(require("debug"), 1);
926
934
 
927
935
  // packages/core/src/api/event/DefaultCRI.ts
928
936
  var ZONE_DELIMITER = "~";
@@ -1294,11 +1302,11 @@ function Publish(namespace, name, advertise = false) {
1294
1302
  }
1295
1303
 
1296
1304
  // packages/core/src/internal/api/ServiceInvocationSupervisor.ts
1297
- var import_api2 = __toESM(require("@opentelemetry/api"));
1305
+ var import_api2 = __toESM(require("@opentelemetry/api"), 1);
1298
1306
  // packages/core/package.json
1299
1307
  var package_default = {
1300
1308
  name: "@kinotic-ai/core",
1301
- version: "5.0.0-beta.25",
1309
+ version: "5.0.0-beta.27",
1302
1310
  type: "module",
1303
1311
  files: [
1304
1312
  "dist"
@@ -1722,7 +1730,7 @@ class ServiceInvocationSupervisor {
1722
1730
  }
1723
1731
 
1724
1732
  // packages/core/src/api/ServiceRegistry.ts
1725
- var import_api3 = __toESM(require("@opentelemetry/api"));
1733
+ var import_api3 = __toESM(require("@opentelemetry/api"), 1);
1726
1734
  var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
1727
1735
  var import_operators4 = require("rxjs/operators");
1728
1736
  class JsonEventFactory {
@@ -2171,15 +2179,15 @@ class CursorPageable extends Pageable {
2171
2179
  }
2172
2180
  // packages/core/src/api/crud/Sort.ts
2173
2181
  var Direction;
2174
- ((Direction2) => {
2175
- Direction2["ASC"] = "ASC";
2176
- Direction2["DESC"] = "DESC";
2182
+ ((Direction) => {
2183
+ Direction["ASC"] = "ASC";
2184
+ Direction["DESC"] = "DESC";
2177
2185
  })(Direction ||= {});
2178
2186
  var NullHandling;
2179
- ((NullHandling2) => {
2180
- NullHandling2["NATIVE"] = "NATIVE";
2181
- NullHandling2["NULLS_FIRST"] = "NULLS_FIRST";
2182
- NullHandling2["NULLS_LAST"] = "NULLS_LAST";
2187
+ ((NullHandling) => {
2188
+ NullHandling["NATIVE"] = "NATIVE";
2189
+ NullHandling["NULLS_FIRST"] = "NULLS_FIRST";
2190
+ NullHandling["NULLS_LAST"] = "NULLS_LAST";
2183
2191
  })(NullHandling ||= {});
2184
2192
 
2185
2193
  class Order {
package/dist/index.d.cts CHANGED
@@ -237,6 +237,14 @@ 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, it closed the socket before answering, or it had not
242
+ * answered within 10 seconds of the socket being opened. This
243
+ * covers the attempts of a pending {@link connect} as well as the reconnects after a connection ends.
244
+ * An attempt that ends the connection for good is reported by {@link connectionEnded} instead.
245
+ */
246
+ connectionAttemptFailed: Observable<void>;
247
+ /**
240
248
  * The {@link ServerInfo} used when connecting, if connected or null
241
249
  */
242
250
  serverInfo: ServerInfo | null;
@@ -1332,6 +1340,7 @@ declare class EventBus implements IEventBus {
1332
1340
  constructor();
1333
1341
  get connectionEnded(): Observable3<Error | null>;
1334
1342
  get connectionEstablished(): Observable3<ConnectedInfo>;
1343
+ get connectionAttemptFailed(): Observable3<void>;
1335
1344
  isConnectionActive(): boolean;
1336
1345
  isConnected(): boolean;
1337
1346
  connect(options: ConnectOptions): Promise<ConnectedInfo>;
@@ -1473,4 +1482,4 @@ declare class ParticipantConstants {
1473
1482
  /** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
1474
1483
  static readonly CLI_PARTICIPANT_ID: string;
1475
1484
  }
1476
- export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, declareServiceDefinitions, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceDirectoryEntry, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, ResolvedCredentials, 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, FunctionalIterablePage, EventConstants, EventBus, Event, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AuthorizationException, AbstractIterablePage };
1485
+ 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,14 @@ 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, it closed the socket before answering, or it had not
242
+ * answered within 10 seconds of the socket being opened. This
243
+ * covers the attempts of a pending {@link connect} as well as the reconnects after a connection ends.
244
+ * An attempt that ends the connection for good is reported by {@link connectionEnded} instead.
245
+ */
246
+ connectionAttemptFailed: Observable<void>;
247
+ /**
240
248
  * The {@link ServerInfo} used when connecting, if connected or null
241
249
  */
242
250
  serverInfo: ServerInfo | null;
@@ -1332,6 +1340,7 @@ declare class EventBus implements IEventBus {
1332
1340
  constructor();
1333
1341
  get connectionEnded(): Observable3<Error | null>;
1334
1342
  get connectionEstablished(): Observable3<ConnectedInfo>;
1343
+ get connectionAttemptFailed(): Observable3<void>;
1335
1344
  isConnectionActive(): boolean;
1336
1345
  isConnected(): boolean;
1337
1346
  connect(options: ConnectOptions): Promise<ConnectedInfo>;
@@ -1473,4 +1482,4 @@ declare class ParticipantConstants {
1473
1482
  /** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
1474
1483
  static readonly CLI_PARTICIPANT_ID: string;
1475
1484
  }
1476
- export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, declareServiceDefinitions, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceDirectoryEntry, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, ResolvedCredentials, 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, FunctionalIterablePage, EventConstants, EventBus, Event, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AuthorizationException, AbstractIterablePage };
1485
+ 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
- ((SessionKeepAliveMode2) => {
15
- SessionKeepAliveMode2["NONE"] = "NONE";
16
- SessionKeepAliveMode2["ACTIVITY"] = "ACTIVITY";
17
- SessionKeepAliveMode2["CONNECTION"] = "CONNECTION";
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
- ((EventConstants2) => {
22
- EventConstants2["CONTENT_TYPE_HEADER"] = "content-type";
23
- EventConstants2["CONTENT_LENGTH_HEADER"] = "content-length";
24
- EventConstants2["REPLY_TO_HEADER"] = "reply-to";
25
- EventConstants2["SENDER_HEADER"] = "sender";
26
- EventConstants2["CONNECTED_INFO_HEADER"] = "connected-info";
27
- EventConstants2["SESSION_KEEP_ALIVE_HEADER"] = "session-keep-alive";
28
- EventConstants2["CORRELATION_ID_HEADER"] = "__correlation-id";
29
- EventConstants2["ORIGIN_CRI_HEADER"] = "__origin-cri";
30
- EventConstants2["ERROR_HEADER"] = "error";
31
- EventConstants2["COMPLETE_HEADER"] = "complete";
32
- EventConstants2["CONTROL_HEADER"] = "control";
33
- EventConstants2["CONTROL_VALUE_COMPLETE"] = "complete";
34
- EventConstants2["CONTROL_VALUE_CANCEL"] = "cancel";
35
- EventConstants2["CONTROL_VALUE_SUSPEND"] = "suspend";
36
- EventConstants2["CONTROL_VALUE_RESUME"] = "resume";
37
- EventConstants2["SERVICE_DESTINATION_PREFIX"] = "srv://";
38
- EventConstants2["SERVICE_DESTINATION_SCHEME"] = "srv";
39
- EventConstants2["STREAM_DESTINATION_PREFIX"] = "stream://";
40
- EventConstants2["STREAM_DESTINATION_SCHEME"] = "stream";
41
- EventConstants2["REPLY_DESTINATION_PREFIX"] = "reply://";
42
- EventConstants2["REPLY_DESTINATION_SCHEME"] = "reply";
43
- EventConstants2["CONTENT_JSON"] = "application/json";
44
- EventConstants2["CONTENT_TEXT"] = "text/plain";
45
- EventConstants2["CONTENT_OCTET_STREAM"] = "application/octet-stream";
46
- EventConstants2["TRACEPARENT_HEADER"] = "traceparent";
47
- EventConstants2["TRACESTATE_HEADER"] = "tracestate";
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
@@ -131,9 +131,11 @@ class StompConnectionManager {
131
131
  INITIAL_RECONNECT_DELAY = 2000;
132
132
  JITTER_MAX = 5000;
133
133
  MAX_RECONNECT_DELAY = 120000;
134
+ CONNECTION_TIMEOUT = 1e4;
134
135
  connectionAttempts = 0;
135
136
  debugLogger = debug2("kinotic:stomp");
136
137
  connectionEstablishedSubject = new Subject;
138
+ connectionAttemptFailedSubject = new Subject;
137
139
  initialConnectionSuccessful = false;
138
140
  rxStompHasConnected = false;
139
141
  _replyToCri = null;
@@ -149,6 +151,9 @@ class StompConnectionManager {
149
151
  get connectionEstablished() {
150
152
  return this.connectionEstablishedSubject.asObservable();
151
153
  }
154
+ get connectionAttemptFailed() {
155
+ return this.connectionAttemptFailedSubject.asObservable();
156
+ }
152
157
  async activate(options) {
153
158
  if (!options?.server?.host) {
154
159
  throw new Error("No host provided");
@@ -204,13 +209,14 @@ class StompConnectionManager {
204
209
  },
205
210
  heartbeatIncoming: 30000,
206
211
  heartbeatOutgoing: 30000,
212
+ connectionTimeout: this.CONNECTION_TIMEOUT,
207
213
  reconnectDelay: this.INITIAL_RECONNECT_DELAY,
208
214
  maxReconnectDelay: this.MAX_RECONNECT_DELAY,
209
215
  reconnectTimeMode: ReconnectionTimeMode.EXPONENTIAL,
210
216
  webSocketFactory: usesPreparedSocket ? takePreparedSocket : undefined,
211
217
  beforeConnect: () => {
212
218
  const attempt = this.prepareAttempt(activation, options, server, headerAuth);
213
- const settled = () => new Promise((resolve2) => setTimeout(resolve2, 0));
219
+ const settled = () => new Promise((resolve) => setTimeout(resolve, 0));
214
220
  activation.attempt = attempt.then(settled, settled);
215
221
  return attempt;
216
222
  }
@@ -221,12 +227,8 @@ class StompConnectionManager {
221
227
  };
222
228
  }
223
229
  this.rxStomp.configure(stompConfig);
224
- activation.own(this.rxStomp.webSocketErrors$.subscribe(async (value) => {
230
+ activation.own(this.rxStomp.webSocketErrors$.subscribe((value) => {
225
231
  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
232
  }));
231
233
  activation.own(this.rxStomp.stompErrors$.subscribe(async (frame) => {
232
234
  const stompError = new Error(frame.headers["message"], { cause: frame });
@@ -263,8 +265,17 @@ class StompConnectionManager {
263
265
  }));
264
266
  let previousState = this.rxStomp.connectionState$.getValue();
265
267
  activation.own(this.rxStomp.connectionState$.subscribe((state) => {
266
- if (state === RxStompState.CLOSED && previousState === RxStompState.OPEN && this.activation === activation) {
267
- this.connectionEndedHandler?.(null);
268
+ if (state === RxStompState.CLOSED && this.activation === activation) {
269
+ if (previousState === RxStompState.OPEN) {
270
+ this.connectionEndedHandler?.(null);
271
+ } else if (previousState === RxStompState.CONNECTING) {
272
+ if (options.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
273
+ this.maxConnectionAttemptsReached = true;
274
+ this.failConnection(activation, new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
275
+ } else {
276
+ this.connectionAttemptFailedSubject.next();
277
+ }
278
+ }
268
279
  }
269
280
  previousState = state;
270
281
  }));
@@ -290,16 +301,8 @@ class StompConnectionManager {
290
301
  }
291
302
  if (options?.maxConnectionAttempts) {
292
303
  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
304
  }
305
+ await this.connectionJitterDelay(activation);
303
306
  if (activation.ended) {
304
307
  return;
305
308
  }
@@ -474,6 +477,9 @@ class EventBus {
474
477
  get connectionEstablished() {
475
478
  return this.stompConnectionManager.connectionEstablished;
476
479
  }
480
+ get connectionAttemptFailed() {
481
+ return this.stompConnectionManager.connectionAttemptFailed;
482
+ }
477
483
  isConnectionActive() {
478
484
  return this.stompConnectionManager.active;
479
485
  }
@@ -1181,7 +1187,7 @@ import opentelemetry, { context as context2, propagation as propagation2, trace,
1181
1187
  // packages/core/package.json
1182
1188
  var package_default = {
1183
1189
  name: "@kinotic-ai/core",
1184
- version: "5.0.0-beta.25",
1190
+ version: "5.0.0-beta.27",
1185
1191
  type: "module",
1186
1192
  files: [
1187
1193
  "dist"
@@ -2057,15 +2063,15 @@ class CursorPageable extends Pageable {
2057
2063
  }
2058
2064
  // packages/core/src/api/crud/Sort.ts
2059
2065
  var Direction;
2060
- ((Direction2) => {
2061
- Direction2["ASC"] = "ASC";
2062
- Direction2["DESC"] = "DESC";
2066
+ ((Direction) => {
2067
+ Direction["ASC"] = "ASC";
2068
+ Direction["DESC"] = "DESC";
2063
2069
  })(Direction ||= {});
2064
2070
  var NullHandling;
2065
- ((NullHandling2) => {
2066
- NullHandling2["NATIVE"] = "NATIVE";
2067
- NullHandling2["NULLS_FIRST"] = "NULLS_FIRST";
2068
- NullHandling2["NULLS_LAST"] = "NULLS_LAST";
2071
+ ((NullHandling) => {
2072
+ NullHandling["NATIVE"] = "NATIVE";
2073
+ NullHandling["NULLS_FIRST"] = "NULLS_FIRST";
2074
+ NullHandling["NULLS_LAST"] = "NULLS_LAST";
2069
2075
  })(NullHandling ||= {});
2070
2076
 
2071
2077
  class Order {
@@ -2110,52 +2116,52 @@ class ParticipantConstants {
2110
2116
  static CLI_PARTICIPANT_ID = "-42-Kinotic-CLI-42-";
2111
2117
  }
2112
2118
  export {
2113
- validateZone,
2114
- validateLabel,
2115
- scopeOptionalMethodNames,
2116
- receivesContext,
2117
- isAdvertised,
2118
- declareServiceDefinitions,
2119
- createCRI,
2120
- buildServerUrl,
2121
- buildBrokerUrl,
2122
- Zone,
2123
- Version,
2124
- TextEventFactory,
2125
- Sort,
2126
- SessionKeepAliveMode,
2127
- SessionCredentialsResolver,
2128
- ServiceRegistry,
2129
- ServiceIdentifier,
2130
- ServerInfo,
2131
- ScopeOptional,
2132
- Scope,
2133
- RpcError,
2134
- Publish,
2135
- ParticipantConstants,
2136
- Pageable,
2137
- Order,
2138
- OffsetPageable,
2139
- NullHandling,
2140
- KinoticSingleton,
2141
- Kinotic,
2142
- JsonEventFactory,
2143
- FunctionalIterablePage,
2144
- EventConstants,
2145
- EventBus,
2146
- Event,
2147
- EnvCredentialsResolver,
2148
- Direction,
2149
- DefaultCRI,
2150
- DataSourceUtils,
2151
- CursorPageable,
2152
- CrudServiceProxyFactory,
2153
- CrudServiceProxy,
2154
- Context,
2155
- ConnectedInfo,
2156
- ChainedCredentialsResolver,
2157
- BearerCredentialsResolver,
2158
- BasicCredentialsResolver,
2119
+ AbstractIterablePage,
2159
2120
  AuthorizationException,
2160
- AbstractIterablePage
2121
+ BasicCredentialsResolver,
2122
+ BearerCredentialsResolver,
2123
+ ChainedCredentialsResolver,
2124
+ ConnectedInfo,
2125
+ Context,
2126
+ CrudServiceProxy,
2127
+ CrudServiceProxyFactory,
2128
+ CursorPageable,
2129
+ DataSourceUtils,
2130
+ DefaultCRI,
2131
+ Direction,
2132
+ EnvCredentialsResolver,
2133
+ Event,
2134
+ EventBus,
2135
+ EventConstants,
2136
+ FunctionalIterablePage,
2137
+ JsonEventFactory,
2138
+ Kinotic,
2139
+ KinoticSingleton,
2140
+ NullHandling,
2141
+ OffsetPageable,
2142
+ Order,
2143
+ Pageable,
2144
+ ParticipantConstants,
2145
+ Publish,
2146
+ RpcError,
2147
+ Scope,
2148
+ ScopeOptional,
2149
+ ServerInfo,
2150
+ ServiceIdentifier,
2151
+ ServiceRegistry,
2152
+ SessionCredentialsResolver,
2153
+ SessionKeepAliveMode,
2154
+ Sort,
2155
+ TextEventFactory,
2156
+ Version,
2157
+ Zone,
2158
+ buildBrokerUrl,
2159
+ buildServerUrl,
2160
+ createCRI,
2161
+ declareServiceDefinitions,
2162
+ isAdvertised,
2163
+ receivesContext,
2164
+ scopeOptionalMethodNames,
2165
+ validateLabel,
2166
+ validateZone
2161
2167
  };
@@ -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
- for (let key of __getOwnPropNames(mod))
24
- if (!__hasOwnProp.call(to, key))
25
- __defProp(to, key, {
26
- get: __accessProp.bind(mod, key),
27
- enumerable: true
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.25",
3
+ "version": "5.0.0-beta.27",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"