@cadenza.io/service 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _cadenza_io_core from '@cadenza.io/core';
2
- import { Task, ThrottleTagGetter, Schema, GraphContext, AnyObject, InquiryOptions, TaskResult, GraphRoutine, SchemaDefinition, SignalBroker, InquiryBroker, GraphRunner, GraphRegistry, EmitOptions, CadenzaMode, Intent, TaskOptions, TaskFunction, DebounceOptions, DebounceTask, EphemeralTaskOptions, EphemeralTask } from '@cadenza.io/core';
3
- export { AnyObject, DebounceOptions, DebounceTask, EphemeralTask, EphemeralTaskOptions, GraphRoutine, Task, TaskFunction, TaskOptions, ThrottleTagGetter } from '@cadenza.io/core';
2
+ import { Task, ThrottleTagGetter, Schema, GraphContext, AnyObject, InquiryOptions, TaskResult, GraphRoutine, SchemaDefinition, SignalBroker, InquiryBroker, GraphRunner, GraphRegistry, EmitOptions, CadenzaMode, Intent, TaskOptions, ActorSpec, ActorFactoryOptions, Actor, ActorDefinition, TaskFunction, DebounceOptions, DebounceTask, EphemeralTaskOptions, EphemeralTask } from '@cadenza.io/core';
3
+ export { Actor, ActorConsistencyProfileName, ActorDefinition, ActorFactoryOptions, ActorInvocationOptions, ActorKeyDefinition, ActorKind, ActorLoadPolicy, ActorRuntimeReadGuard, ActorSpec, ActorStateDefinition, ActorStateReducer, ActorStateStore, ActorTaskBindingDefinition, ActorTaskBindingOptions, ActorTaskContext, ActorTaskHandler, ActorTaskMode, ActorWriteContract, AnyObject, DebounceOptions, DebounceTask, EphemeralTask, EphemeralTaskOptions, GraphRoutine, IdempotencyPolicy, RetryPolicy, SessionPolicy, Task, TaskFunction, TaskOptions, ThrottleTagGetter } from '@cadenza.io/core';
4
4
 
5
5
  /**
6
6
  * Represents a task that delegates execution of a routine to a remote system or service.
@@ -22422,6 +22422,8 @@ declare class CadenzaService {
22422
22422
  * @return {void} - This method does not return a value.
22423
22423
  */
22424
22424
  static createMetaDatabaseService(name: string, schema: DatabaseSchemaDefinition, description?: string, options?: ServerOptions & DatabaseOptions): void;
22425
+ static createActor<D extends Record<string, any> = AnyObject, R = AnyObject>(spec: ActorSpec<D, R>, options?: ActorFactoryOptions): Actor<D, R>;
22426
+ static createActorFromDefinition<D extends Record<string, any> = AnyObject, R = AnyObject>(definition: ActorDefinition<D, R>, options?: ActorFactoryOptions<D, R>): Actor<D, R>;
22425
22427
  /**
22426
22428
  * Creates and registers a new task with the provided name, function, and optional details.
22427
22429
  *
@@ -22784,6 +22786,9 @@ declare class RestController {
22784
22786
  static get instance(): RestController;
22785
22787
  private fetchClientDiagnostics;
22786
22788
  private readonly diagnosticsErrorHistoryLimit;
22789
+ private readonly diagnosticsMaxClientEntries;
22790
+ private readonly destroyedDiagnosticsTtlMs;
22791
+ private pruneFetchClientDiagnostics;
22787
22792
  private resolveTransportDiagnosticsOptions;
22788
22793
  private ensureFetchClientDiagnostics;
22789
22794
  private getErrorMessage;
@@ -22813,41 +22818,68 @@ declare class RestController {
22813
22818
  constructor();
22814
22819
  }
22815
22820
 
22821
+ interface TransportDiagnosticErrorEntry {
22822
+ at: string;
22823
+ message: string;
22824
+ }
22825
+ interface SocketClientDiagnosticsState {
22826
+ fetchId: string;
22827
+ serviceName: string;
22828
+ url: string;
22829
+ socketId: string | null;
22830
+ connected: boolean;
22831
+ handshake: boolean;
22832
+ reconnectAttempts: number;
22833
+ connectErrors: number;
22834
+ reconnectErrors: number;
22835
+ socketErrors: number;
22836
+ pendingDelegations: number;
22837
+ pendingTimers: number;
22838
+ destroyed: boolean;
22839
+ lastHandshakeAt: string | null;
22840
+ lastHandshakeError: string | null;
22841
+ lastDisconnectAt: string | null;
22842
+ lastError: string | null;
22843
+ lastErrorAt: number;
22844
+ errorHistory: TransportDiagnosticErrorEntry[];
22845
+ updatedAt: number;
22846
+ }
22816
22847
  /**
22817
- * The `SocketController` class handles the setup and management of a WebSocket server,
22818
- * ensuring secure connections, message handling, and rate-limiting.
22819
- * This class is designed to function as a singleton, providing a unified interface
22820
- * for WebSocket interactions in the application by standardizing the server setup
22821
- * and integrating task-based processing through the `Cadenza` framework.
22848
+ * Socket transport orchestration in the Cadenza primitive ecosystem.
22849
+ *
22850
+ * - setup is signal-triggered
22851
+ * - state/runtime ownership is actor-backed
22852
+ * - dynamic runtime tasks are still allowed for advanced orchestration (ephemeral resolvers etc.)
22822
22853
  */
22823
22854
  declare class SocketController {
22824
22855
  private static _instance;
22825
22856
  static get instance(): SocketController;
22826
- private socketClientDiagnostics;
22827
22857
  private readonly diagnosticsErrorHistoryLimit;
22828
- private resolveTransportDiagnosticsOptions;
22829
- private ensureSocketClientDiagnostics;
22858
+ private readonly diagnosticsMaxClientEntries;
22859
+ private readonly destroyedDiagnosticsTtlMs;
22860
+ private readonly socketServerDefaultKey;
22861
+ private readonly socketServerActor;
22862
+ private readonly socketClientActor;
22863
+ private readonly socketClientDiagnosticsActor;
22864
+ constructor();
22865
+ private registerDiagnosticsTasks;
22866
+ private registerSocketServerTasks;
22867
+ private registerSocketClientTasks;
22868
+ private createInitialSocketServerSessionState;
22869
+ private createInitialSocketClientSessionState;
22870
+ private resolveSocketServerKey;
22871
+ private resolveSocketClientFetchId;
22872
+ private resolveServicePort;
22873
+ private createSocketServerRuntimeHandleFromContext;
22874
+ private destroySocketServerRuntimeHandle;
22875
+ private createSocketClientRuntimeHandle;
22876
+ private destroySocketClientRuntimeHandle;
22877
+ private normalizeCommunicationTypes;
22830
22878
  private getErrorMessage;
22831
- private recordSocketClientError;
22879
+ private pruneDiagnosticsEntries;
22880
+ getSocketClientDiagnosticsEntry(fetchId: string): Promise<SocketClientDiagnosticsState | undefined>;
22881
+ private resolveTransportDiagnosticsOptions;
22832
22882
  private collectSocketTransportDiagnostics;
22833
- /**
22834
- * Constructs the `SocketServer`, setting up a WebSocket server with specific configurations,
22835
- * including connection state recovery, rate limiting, CORS handling, and custom event handling.
22836
- * This class sets up the communication infrastructure for scalable, resilient, and secure WebSocket-based interactions
22837
- * using metadata-driven task execution with `Cadenza`.
22838
- *
22839
- * It provides support for:
22840
- * - Origin-based access control for connections.
22841
- * - Optional payload sanitization.
22842
- * - Configurable rate limiting and behavior on limit breaches (soft/hard disconnects).
22843
- * - Event handlers for connection, handshake, delegation, signaling, status checks, and disconnection.
22844
- *
22845
- * The server can handle both internal and external interactions depending on the provided configurations,
22846
- * and integrates directly with Cadenza's task workflow engine.
22847
- *
22848
- * Initializes the `SocketServer` to be ready for WebSocket communication.
22849
- */
22850
- constructor();
22851
22883
  }
22852
22884
 
22853
22885
  /**
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _cadenza_io_core from '@cadenza.io/core';
2
- import { Task, ThrottleTagGetter, Schema, GraphContext, AnyObject, InquiryOptions, TaskResult, GraphRoutine, SchemaDefinition, SignalBroker, InquiryBroker, GraphRunner, GraphRegistry, EmitOptions, CadenzaMode, Intent, TaskOptions, TaskFunction, DebounceOptions, DebounceTask, EphemeralTaskOptions, EphemeralTask } from '@cadenza.io/core';
3
- export { AnyObject, DebounceOptions, DebounceTask, EphemeralTask, EphemeralTaskOptions, GraphRoutine, Task, TaskFunction, TaskOptions, ThrottleTagGetter } from '@cadenza.io/core';
2
+ import { Task, ThrottleTagGetter, Schema, GraphContext, AnyObject, InquiryOptions, TaskResult, GraphRoutine, SchemaDefinition, SignalBroker, InquiryBroker, GraphRunner, GraphRegistry, EmitOptions, CadenzaMode, Intent, TaskOptions, ActorSpec, ActorFactoryOptions, Actor, ActorDefinition, TaskFunction, DebounceOptions, DebounceTask, EphemeralTaskOptions, EphemeralTask } from '@cadenza.io/core';
3
+ export { Actor, ActorConsistencyProfileName, ActorDefinition, ActorFactoryOptions, ActorInvocationOptions, ActorKeyDefinition, ActorKind, ActorLoadPolicy, ActorRuntimeReadGuard, ActorSpec, ActorStateDefinition, ActorStateReducer, ActorStateStore, ActorTaskBindingDefinition, ActorTaskBindingOptions, ActorTaskContext, ActorTaskHandler, ActorTaskMode, ActorWriteContract, AnyObject, DebounceOptions, DebounceTask, EphemeralTask, EphemeralTaskOptions, GraphRoutine, IdempotencyPolicy, RetryPolicy, SessionPolicy, Task, TaskFunction, TaskOptions, ThrottleTagGetter } from '@cadenza.io/core';
4
4
 
5
5
  /**
6
6
  * Represents a task that delegates execution of a routine to a remote system or service.
@@ -22422,6 +22422,8 @@ declare class CadenzaService {
22422
22422
  * @return {void} - This method does not return a value.
22423
22423
  */
22424
22424
  static createMetaDatabaseService(name: string, schema: DatabaseSchemaDefinition, description?: string, options?: ServerOptions & DatabaseOptions): void;
22425
+ static createActor<D extends Record<string, any> = AnyObject, R = AnyObject>(spec: ActorSpec<D, R>, options?: ActorFactoryOptions): Actor<D, R>;
22426
+ static createActorFromDefinition<D extends Record<string, any> = AnyObject, R = AnyObject>(definition: ActorDefinition<D, R>, options?: ActorFactoryOptions<D, R>): Actor<D, R>;
22425
22427
  /**
22426
22428
  * Creates and registers a new task with the provided name, function, and optional details.
22427
22429
  *
@@ -22784,6 +22786,9 @@ declare class RestController {
22784
22786
  static get instance(): RestController;
22785
22787
  private fetchClientDiagnostics;
22786
22788
  private readonly diagnosticsErrorHistoryLimit;
22789
+ private readonly diagnosticsMaxClientEntries;
22790
+ private readonly destroyedDiagnosticsTtlMs;
22791
+ private pruneFetchClientDiagnostics;
22787
22792
  private resolveTransportDiagnosticsOptions;
22788
22793
  private ensureFetchClientDiagnostics;
22789
22794
  private getErrorMessage;
@@ -22813,41 +22818,68 @@ declare class RestController {
22813
22818
  constructor();
22814
22819
  }
22815
22820
 
22821
+ interface TransportDiagnosticErrorEntry {
22822
+ at: string;
22823
+ message: string;
22824
+ }
22825
+ interface SocketClientDiagnosticsState {
22826
+ fetchId: string;
22827
+ serviceName: string;
22828
+ url: string;
22829
+ socketId: string | null;
22830
+ connected: boolean;
22831
+ handshake: boolean;
22832
+ reconnectAttempts: number;
22833
+ connectErrors: number;
22834
+ reconnectErrors: number;
22835
+ socketErrors: number;
22836
+ pendingDelegations: number;
22837
+ pendingTimers: number;
22838
+ destroyed: boolean;
22839
+ lastHandshakeAt: string | null;
22840
+ lastHandshakeError: string | null;
22841
+ lastDisconnectAt: string | null;
22842
+ lastError: string | null;
22843
+ lastErrorAt: number;
22844
+ errorHistory: TransportDiagnosticErrorEntry[];
22845
+ updatedAt: number;
22846
+ }
22816
22847
  /**
22817
- * The `SocketController` class handles the setup and management of a WebSocket server,
22818
- * ensuring secure connections, message handling, and rate-limiting.
22819
- * This class is designed to function as a singleton, providing a unified interface
22820
- * for WebSocket interactions in the application by standardizing the server setup
22821
- * and integrating task-based processing through the `Cadenza` framework.
22848
+ * Socket transport orchestration in the Cadenza primitive ecosystem.
22849
+ *
22850
+ * - setup is signal-triggered
22851
+ * - state/runtime ownership is actor-backed
22852
+ * - dynamic runtime tasks are still allowed for advanced orchestration (ephemeral resolvers etc.)
22822
22853
  */
22823
22854
  declare class SocketController {
22824
22855
  private static _instance;
22825
22856
  static get instance(): SocketController;
22826
- private socketClientDiagnostics;
22827
22857
  private readonly diagnosticsErrorHistoryLimit;
22828
- private resolveTransportDiagnosticsOptions;
22829
- private ensureSocketClientDiagnostics;
22858
+ private readonly diagnosticsMaxClientEntries;
22859
+ private readonly destroyedDiagnosticsTtlMs;
22860
+ private readonly socketServerDefaultKey;
22861
+ private readonly socketServerActor;
22862
+ private readonly socketClientActor;
22863
+ private readonly socketClientDiagnosticsActor;
22864
+ constructor();
22865
+ private registerDiagnosticsTasks;
22866
+ private registerSocketServerTasks;
22867
+ private registerSocketClientTasks;
22868
+ private createInitialSocketServerSessionState;
22869
+ private createInitialSocketClientSessionState;
22870
+ private resolveSocketServerKey;
22871
+ private resolveSocketClientFetchId;
22872
+ private resolveServicePort;
22873
+ private createSocketServerRuntimeHandleFromContext;
22874
+ private destroySocketServerRuntimeHandle;
22875
+ private createSocketClientRuntimeHandle;
22876
+ private destroySocketClientRuntimeHandle;
22877
+ private normalizeCommunicationTypes;
22830
22878
  private getErrorMessage;
22831
- private recordSocketClientError;
22879
+ private pruneDiagnosticsEntries;
22880
+ getSocketClientDiagnosticsEntry(fetchId: string): Promise<SocketClientDiagnosticsState | undefined>;
22881
+ private resolveTransportDiagnosticsOptions;
22832
22882
  private collectSocketTransportDiagnostics;
22833
- /**
22834
- * Constructs the `SocketServer`, setting up a WebSocket server with specific configurations,
22835
- * including connection state recovery, rate limiting, CORS handling, and custom event handling.
22836
- * This class sets up the communication infrastructure for scalable, resilient, and secure WebSocket-based interactions
22837
- * using metadata-driven task execution with `Cadenza`.
22838
- *
22839
- * It provides support for:
22840
- * - Origin-based access control for connections.
22841
- * - Optional payload sanitization.
22842
- * - Configurable rate limiting and behavior on limit breaches (soft/hard disconnects).
22843
- * - Event handlers for connection, handshake, delegation, signaling, status checks, and disconnection.
22844
- *
22845
- * The server can handle both internal and external interactions depending on the provided configurations,
22846
- * and integrates directly with Cadenza's task workflow engine.
22847
- *
22848
- * Initializes the `SocketServer` to be ready for WebSocket communication.
22849
- */
22850
- constructor();
22851
22883
  }
22852
22884
 
22853
22885
  /**