Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"scripts": {
"dev": "pnpm build --watch",
"build": "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/test/mod.ts src/inspector/mod.ts",
"build:schema": "node ../../packages/misc/bare-compiler/dist/cli.js compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && node ../../packages/misc/bare-compiler/dist/cli.js compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts ",
"build:schema": "node ../../packages/misc/bare-compiler/dist/cli.js compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && node ../../packages/misc/bare-compiler/dist/cli.js compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && node ../../packages/misc/bare-compiler/dist/cli.js compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts",
"check-types": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",
Expand Down
69 changes: 69 additions & 0 deletions packages/core/schemas/actor-persist/v1.bare
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# MARK: Connection
# Represents an event subscription.
type PersistedSubscription struct {
# Event name
eventName: str
}

# Represents a persisted connection to an actor.
type PersistedConnection struct {
# Connection ID
id: str
# Connection token
token: str
# Connection driver type
driver: str
# Connection driver state
driverState: data
# Connection parameters
parameters: data
# Connection state
state: data
# Authentication data
auth: optional<data>
# Active subscriptions
subscriptions: list<PersistedSubscription>
# Last seen timestamp
lastSeen: u64
}

# MARK: Schedule Event
# Represents a generic scheduled event.
type GenericPersistedScheduleEvent struct {
# Action name
action: str
# Arguments for the action
#
# CBOR array
args: optional<data>
}

# Event kind union
type PersistedScheduleEventKind union {
GenericPersistedScheduleEvent
}

# Scheduled event with metadata
type PersistedScheduleEvent struct {
# Event ID
eventId: str
# Timestamp when the event should fire
timestamp: u64
# Event kind
kind: PersistedScheduleEventKind
}

# MARK: Actor
# Represents the persisted state of an actor.
type PersistedActor struct {
# Input data passed to the actor on initialization
input: optional<data>
# Whether the actor has been initialized
hasInitialized: bool
# Actor's state
state: data
# Active connections
connections: list<PersistedConnection>
# Scheduled events
scheduledEvents: list<PersistedScheduleEvent>
}
16 changes: 7 additions & 9 deletions packages/core/schemas/file-system-driver/v1.bare
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

# MARK: Actor State
# Represents the persisted state for an actor on disk.
# Note: createdAt is not persisted; it is derived from the file's birthtime.
type ActorState struct {
id: str
name: str
key: list<str>
persistedData: data
actorId: str
name: str
key: list<str>
persistedData: data
createdAt: u64
}

# MARK: Actor Alarm
# Represents a scheduled alarm for an actor.
# Stored per-actor; the actor id is implied by the filename.
# The timestamp is milliseconds since epoch.
type ActorAlarm struct {
timestamp: uint
actorId: str
timestamp: uint
}

38 changes: 24 additions & 14 deletions packages/core/src/actor/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
#driver: ConnDriver;

public get params(): CP {
return this.__persist.p;
return this.__persist.params;
}

public get auth(): AD {
return this.__persist.a as AD;
return this.__persist.authData as AD;
}

public get driver(): ConnectionDriver {
return this.__persist.d as ConnectionDriver;
return this.__persist.connDriver as ConnectionDriver;
}

public get _stateEnabled() {
Expand All @@ -90,8 +90,8 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
*/
public get state(): CS {
this.#validateStateEnabled();
if (!this.__persist.s) throw new Error("state should exists");
return this.__persist.s;
if (!this.__persist.state) throw new Error("state should exists");
return this.__persist.state;
}

/**
Expand All @@ -101,21 +101,21 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
*/
public set state(value: CS) {
this.#validateStateEnabled();
this.__persist.s = value;
this.__persist.state = value;
}

/**
* Unique identifier for the connection.
*/
public get id(): ConnId {
return this.__persist.i;
return this.__persist.connId;
}

/**
* Token used to authenticate this request.
*/
public get _token(): string {
return this.__persist.t;
return this.__persist.token;
}

/**
Expand All @@ -129,7 +129,7 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
* Timestamp of the last time the connection was seen, i.e. the last time the connection was active and checked for liveness.
*/
public get lastSeen(): number {
return this.__persist.l;
return this.__persist.lastSeen;
}

/**
Expand Down Expand Up @@ -165,7 +165,12 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
* @protected
*/
public _sendMessage(message: CachedSerializer<protocol.ToClient>) {
this.#driver.sendMessage?.(this.#actor, this, this.__persist.ds, message);
this.#driver.sendMessage?.(
this.#actor,
this,
this.__persist.connDriverState,
message,
);
}

/**
Expand Down Expand Up @@ -205,7 +210,12 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
*/
public async disconnect(reason?: string) {
this.#status = "reconnecting";
await this.#driver.disconnect(this.#actor, this, this.__persist.ds, reason);
await this.#driver.disconnect(
this.#actor,
this,
this.__persist.connDriverState,
reason,
);
}

/**
Expand Down Expand Up @@ -233,18 +243,18 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
status: this.#status,
newStatus,

lastSeen: this.__persist.l,
lastSeen: this.__persist.lastSeen,
currentTs: newLastSeen,
});

if (!isConnectionClosed) {
this.__persist.l = newLastSeen;
this.__persist.lastSeen = newLastSeen;
}

this.#status = newStatus;
return {
status: this.#status,
lastSeen: this.__persist.l,
lastSeen: this.__persist.lastSeen,
};
}
}
Loading
Loading