@fadhilp/stateql 0.2.2 → 0.3.1

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/README.md CHANGED
@@ -193,7 +193,12 @@ with `as`. Database commands may set `timeout_ms`; otherwise they use the
193
193
  30-second default.
194
194
 
195
195
  State metadata lives under `STQL_HOME`, or the platform data directory when
196
- unset. Set `STQL_SESSION` to select a named session.
196
+ unset. Set `STQL_SESSION` to select a named session and `STQL_ACTOR` to select
197
+ an attached actor for CLI invocations. A session is a shared workspace:
198
+ attached actors reuse its connection, handles, aliases, cache, and
199
+ state version, while plans and staged transactions remain owned by their
200
+ creating actor. Callers that omit `actor` keep the legacy behavior where the
201
+ actor ID is the session name.
197
202
 
198
203
  Read cache entries expire after five minutes; materialized handles expire after
199
204
  24 hours. Expired results and plans are deleted when StateQL next opens. Queries
@@ -233,8 +238,9 @@ Interrupted commits remain fail-closed; stale `committing` records become
233
238
  ```ts
234
239
  import { StateQL } from "@fadhilp/stateql";
235
240
 
236
- const stateql = new StateQL({
241
+ const stateql = StateQL.forActor({
237
242
  home: "./.stql",
243
+ actor: "pi-session-id",
238
244
  timeoutMs: 30_000,
239
245
  maxResultBytes: 16 * 1024 * 1024,
240
246
  });
@@ -250,3 +256,14 @@ if (response.ok) {
250
256
  });
251
257
  }
252
258
  ```
259
+
260
+ `StateQL.forActor(...)` resolves the actor's attached session directly from
261
+ StateQL storage, avoiding a duplicate actor-to-session mapping in integrations.
262
+ On first use, it creates a legacy-compatible session named after the actor.
263
+ Use `new StateQL({ session, actor })` when the session is already known.
264
+
265
+ Membership is managed only through the library API, not batch commands:
266
+ `linkActor(session, actorId)`, `unlinkActor(session, actorId)`,
267
+ `listActors(session)`, and `resolveActor(actorId)`. An existing member must link
268
+ an actor before that actor opens an existing workspace. Integrations should ask
269
+ for user confirmation before changing membership or the shared connection.
package/dist/src/cli.js CHANGED
@@ -49,6 +49,7 @@ const stateql = new StateQL({
49
49
  ...(values["timeout-ms"] === undefined
50
50
  ? {}
51
51
  : { timeoutMs: Number(values["timeout-ms"]) }),
52
+ ...(process.env.STQL_ACTOR ? { actor: process.env.STQL_ACTOR } : {}),
52
53
  signal: abortController.signal,
53
54
  });
54
55
  try {
@@ -1,3 +1,3 @@
1
1
  export { StateQL } from "./stateql.js";
2
2
  export { StateQLError, exitCodeFor } from "./errors.js";
3
- export type { BatchCommand, BatchCommandName, BatchOptions, ConnectOptions, ExecOptions, ExecutionOptions, Failure, FilterOptions, HistoryEntry, PlanOptions, ProfileOptions, QueryOptions, Response, RowsOptions, SqlParameters, StateQLOptions, StateQLSnapshot, Success, } from "./types.js";
3
+ export type { BatchCommand, BatchCommandName, BatchOptions, ConnectOptions, ExecOptions, ExecutionOptions, Failure, FilterOptions, HistoryEntry, PlanOptions, ProfileOptions, QueryOptions, Response, RowsOptions, SqlParameters, StateQLActorOptions, StateQLOptions, StateQLSnapshot, Success, } from "./types.js";
@@ -18,6 +18,7 @@ export function profileData(profile) {
18
18
  export function operationData(operation) {
19
19
  return {
20
20
  operation_id: operation.id,
21
+ actor_id: operation.actor_id,
21
22
  statement_type: operation.statement_type,
22
23
  affected_rows: operation.affected_rows,
23
24
  status: operation.status,
@@ -32,6 +33,7 @@ export function transactionData(transaction, statements) {
32
33
  return {
33
34
  transaction_id: transaction.id,
34
35
  state: transaction.state,
36
+ owner_actor_id: transaction.owner_actor_id,
35
37
  connection_id: transaction.connection_id,
36
38
  statements,
37
39
  pending_writes: transaction.state === "active" ? statements : 0,
@@ -1,7 +1,9 @@
1
- import type { BatchCommand, BatchOptions, ConnectOptions, ExecOptions, ExecutionOptions, FilterOptions, HistoryEntry, PlanOptions, ProfileOptions, QueryOptions, Response, RowsOptions, StateQLOptions, StateQLSnapshot } from "./types.js";
1
+ import type { BatchCommand, BatchOptions, ConnectOptions, ExecOptions, ExecutionOptions, FilterOptions, HistoryEntry, PlanOptions, ProfileOptions, QueryOptions, Response, RowsOptions, StateQLActorOptions, StateQLOptions, StateQLSnapshot } from "./types.js";
2
2
  export declare class StateQL {
3
+ static forActor(options: StateQLActorOptions): StateQL;
3
4
  private readonly store;
4
5
  private readonly sessionName;
6
+ private readonly actorId;
5
7
  private readonly previewRows;
6
8
  private readonly cacheTtlSeconds;
7
9
  private readonly resultTtlSeconds;
@@ -23,6 +25,10 @@ export declare class StateQL {
23
25
  historyLimit?: number;
24
26
  }): StateQLSnapshot;
25
27
  status(): Promise<Response<unknown>>;
28
+ linkActor(session: string, actorId: string): Promise<Response<unknown>>;
29
+ unlinkActor(session: string, actorId: string): Promise<Response<unknown>>;
30
+ listActors(session: string): Promise<Response<unknown>>;
31
+ resolveActor(actorId: string): Promise<Response<unknown>>;
26
32
  startSession(name: string): Promise<Response<unknown>>;
27
33
  listSessions(): Promise<Response<unknown>>;
28
34
  showSession(idOrName?: string): Promise<Response<unknown>>;
@@ -58,6 +64,9 @@ export declare class StateQL {
58
64
  private requireResult;
59
65
  private requireConnection;
60
66
  private requireActiveTransaction;
67
+ private requireSelectedSession;
68
+ private validateActorId;
69
+ private throwMembershipDenied;
61
70
  private executionContext;
62
71
  private resultData;
63
72
  private cacheValid;