@fadhilp/stateql 0.3.0 → 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 +6 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/stateql.d.ts +2 -1
- package/dist/src/stateql.js +17 -0
- package/dist/src/types.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -238,9 +238,8 @@ Interrupted commits remain fail-closed; stale `committing` records become
|
|
|
238
238
|
```ts
|
|
239
239
|
import { StateQL } from "@fadhilp/stateql";
|
|
240
240
|
|
|
241
|
-
const stateql =
|
|
241
|
+
const stateql = StateQL.forActor({
|
|
242
242
|
home: "./.stql",
|
|
243
|
-
session: "shared-workspace",
|
|
244
243
|
actor: "pi-session-id",
|
|
245
244
|
timeoutMs: 30_000,
|
|
246
245
|
maxResultBytes: 16 * 1024 * 1024,
|
|
@@ -258,6 +257,11 @@ if (response.ok) {
|
|
|
258
257
|
}
|
|
259
258
|
```
|
|
260
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
|
+
|
|
261
265
|
Membership is managed only through the library API, not batch commands:
|
|
262
266
|
`linkActor(session, actorId)`, `unlinkActor(session, actorId)`,
|
|
263
267
|
`listActors(session)`, and `resolveActor(actorId)`. An existing member must link
|
package/dist/src/index.d.ts
CHANGED
|
@@ -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";
|
package/dist/src/stateql.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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;
|
|
5
6
|
private readonly actorId;
|
package/dist/src/stateql.js
CHANGED
|
@@ -12,6 +12,23 @@ import { compactRows, defaultHome, hash, parseJson, redact, } from "./util.js";
|
|
|
12
12
|
const DEFAULT_SNAPSHOT_HISTORY_LIMIT = 50;
|
|
13
13
|
const MAX_SNAPSHOT_HISTORY_LIMIT = 100;
|
|
14
14
|
export class StateQL {
|
|
15
|
+
static forActor(options) {
|
|
16
|
+
if (!options.actor.trim()) {
|
|
17
|
+
throw new StateQLError("INVALID_COMMAND", "Actor ID is required.");
|
|
18
|
+
}
|
|
19
|
+
const now = options.now ?? (() => new Date());
|
|
20
|
+
const store = new StateStore(options.home ?? defaultHome(), now);
|
|
21
|
+
try {
|
|
22
|
+
const session = store.resolveActor(options.actor);
|
|
23
|
+
if (session)
|
|
24
|
+
return new StateQL({ ...options, session: session.name });
|
|
25
|
+
const { actor, ...legacyOptions } = options;
|
|
26
|
+
return new StateQL({ ...legacyOptions, session: actor });
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
store.close();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
15
32
|
store;
|
|
16
33
|
sessionName;
|
|
17
34
|
actorId;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -98,6 +98,9 @@ export interface StateQLOptions extends ExecutionOptions {
|
|
|
98
98
|
maxResultBytes?: number;
|
|
99
99
|
now?: () => Date;
|
|
100
100
|
}
|
|
101
|
+
export type StateQLActorOptions = Omit<StateQLOptions, "session" | "actor"> & {
|
|
102
|
+
actor: string;
|
|
103
|
+
};
|
|
101
104
|
export interface QueryOptions extends ExecutionOptions {
|
|
102
105
|
params?: SqlParameters;
|
|
103
106
|
cache?: "auto" | "bypass" | "require";
|