@fadhilp/stateql 0.2.0 → 0.3.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/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
@@ -235,6 +240,8 @@ import { StateQL } from "@fadhilp/stateql";
235
240
 
236
241
  const stateql = new StateQL({
237
242
  home: "./.stql",
243
+ session: "shared-workspace",
244
+ actor: "pi-session-id",
238
245
  timeoutMs: 30_000,
239
246
  maxResultBytes: 16 * 1024 * 1024,
240
247
  });
@@ -250,3 +257,9 @@ if (response.ok) {
250
257
  });
251
258
  }
252
259
  ```
260
+
261
+ Membership is managed only through the library API, not batch commands:
262
+ `linkActor(session, actorId)`, `unlinkActor(session, actorId)`,
263
+ `listActors(session)`, and `resolveActor(actorId)`. An existing member must link
264
+ an actor before that actor opens an existing workspace. Integrations should ask
265
+ for user confirmation before changing membership or the shared connection.
package/dist/src/cli.js CHANGED
@@ -36,7 +36,7 @@ const parsed = parseArgs({
36
36
  const [command, subcommand, ...rest] = parsed.positionals;
37
37
  const values = parsed.values;
38
38
  if (values.version) {
39
- console.log("0.1.2");
39
+ console.log(packageVersion());
40
40
  process.exit(0);
41
41
  }
42
42
  if (values.help || !command) {
@@ -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 {
@@ -502,7 +503,7 @@ function extractHandle(data) {
502
503
  return undefined;
503
504
  }
504
505
  function helpText() {
505
- return `StateQL 0.1.2
506
+ return `StateQL ${packageVersion()}
506
507
 
507
508
  Usage: stql <command> [arguments] [options]
508
509
 
@@ -523,3 +524,7 @@ Deadline: --timeout-ms N (default: 30000). Ctrl+C cancels database work.
523
524
  Output: --output agent|json|jsonl|text|silent (default: agent).
524
525
  Batch/pipe accept JSON array files or JSONL streams. Stop on first error.`;
525
526
  }
527
+ function packageVersion() {
528
+ const packageJson = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
529
+ return packageJson.version;
530
+ }
@@ -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, PlanOptions, ProfileOptions, QueryOptions, Response, RowsOptions, SqlParameters, StateQLOptions, Success, } from "./types.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";
@@ -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,8 @@
1
- import type { BatchCommand, BatchOptions, ConnectOptions, ExecOptions, ExecutionOptions, FilterOptions, PlanOptions, ProfileOptions, QueryOptions, Response, RowsOptions, StateQLOptions } from "./types.js";
1
+ import type { BatchCommand, BatchOptions, ConnectOptions, ExecOptions, ExecutionOptions, FilterOptions, HistoryEntry, PlanOptions, ProfileOptions, QueryOptions, Response, RowsOptions, StateQLOptions, StateQLSnapshot } from "./types.js";
2
2
  export declare class StateQL {
3
3
  private readonly store;
4
4
  private readonly sessionName;
5
+ private readonly actorId;
5
6
  private readonly previewRows;
6
7
  private readonly cacheTtlSeconds;
7
8
  private readonly resultTtlSeconds;
@@ -19,7 +20,14 @@ export declare class StateQL {
19
20
  showProfile(name: string): Promise<Response<unknown>>;
20
21
  removeProfile(name: string): Promise<Response<unknown>>;
21
22
  disconnect(): Promise<Response<unknown>>;
23
+ snapshot(options?: {
24
+ historyLimit?: number;
25
+ }): StateQLSnapshot;
22
26
  status(): Promise<Response<unknown>>;
27
+ linkActor(session: string, actorId: string): Promise<Response<unknown>>;
28
+ unlinkActor(session: string, actorId: string): Promise<Response<unknown>>;
29
+ listActors(session: string): Promise<Response<unknown>>;
30
+ resolveActor(actorId: string): Promise<Response<unknown>>;
23
31
  startSession(name: string): Promise<Response<unknown>>;
24
32
  listSessions(): Promise<Response<unknown>>;
25
33
  showSession(idOrName?: string): Promise<Response<unknown>>;
@@ -42,7 +50,9 @@ export declare class StateQL {
42
50
  inspect(kind: string, table?: string, options?: ExecutionOptions): Promise<Response<unknown>>;
43
51
  plan(sql: string, options?: PlanOptions): Promise<Response<unknown>>;
44
52
  apply(planId: string, options?: ExecutionOptions): Promise<Response<unknown>>;
45
- history(limit?: number): Promise<Response<unknown>>;
53
+ history(limit?: number): Promise<Response<{
54
+ history: HistoryEntry[];
55
+ }>>;
46
56
  capabilities(): Promise<Response<unknown>>;
47
57
  executeCommand(command: BatchCommand): Promise<Response<unknown>>;
48
58
  batch(commands: Iterable<BatchCommand> | AsyncIterable<BatchCommand>, options?: BatchOptions): AsyncGenerator<Response<unknown>>;
@@ -53,6 +63,9 @@ export declare class StateQL {
53
63
  private requireResult;
54
64
  private requireConnection;
55
65
  private requireActiveTransaction;
66
+ private requireSelectedSession;
67
+ private validateActorId;
68
+ private throwMembershipDenied;
56
69
  private executionContext;
57
70
  private resultData;
58
71
  private cacheValid;