@fadhilp/stateql 0.5.4 → 0.7.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 +91 -23
- package/dist/src/adapters.d.ts +1 -0
- package/dist/src/adapters.js +19 -6
- package/dist/src/cli.js +48 -2
- package/dist/src/connection.d.ts +1 -0
- package/dist/src/connection.js +29 -3
- package/dist/src/index.d.ts +1 -1
- package/dist/src/migrations.js +22 -0
- package/dist/src/mongodb.d.ts +48 -0
- package/dist/src/mongodb.js +868 -0
- package/dist/src/response-data.js +12 -0
- package/dist/src/sql.d.ts +3 -1
- package/dist/src/sql.js +3 -0
- package/dist/src/stateql.d.ts +11 -3
- package/dist/src/stateql.js +730 -154
- package/dist/src/store.d.ts +8 -3
- package/dist/src/store.js +20 -14
- package/dist/src/types.d.ts +103 -2
- package/package.json +3 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseJson } from "./util.js";
|
|
1
2
|
export function sessionData(session) {
|
|
2
3
|
return {
|
|
3
4
|
session_id: session.id,
|
|
@@ -27,8 +28,19 @@ export function operationData(operation) {
|
|
|
27
28
|
state_version_before: operation.state_version_before,
|
|
28
29
|
state_version_after: operation.state_version_after,
|
|
29
30
|
...(operation.replay_of ? { replay_of: operation.replay_of } : {}),
|
|
31
|
+
...(operation.outcome_json === null
|
|
32
|
+
? {}
|
|
33
|
+
: {
|
|
34
|
+
outcome: parseJson(operation.outcome_json, `operation "${operation.id}" outcome`, isMongoWriteOutcome),
|
|
35
|
+
}),
|
|
30
36
|
};
|
|
31
37
|
}
|
|
38
|
+
function isMongoWriteOutcome(value) {
|
|
39
|
+
return Boolean(value) &&
|
|
40
|
+
typeof value === "object" &&
|
|
41
|
+
!Array.isArray(value) &&
|
|
42
|
+
typeof value.acknowledged === "boolean";
|
|
43
|
+
}
|
|
32
44
|
export function transactionData(transaction, statements) {
|
|
33
45
|
return {
|
|
34
46
|
transaction_id: transaction.id,
|
package/dist/src/sql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AST } from "node-sql-parser";
|
|
2
|
-
import type { Driver } from "./types.js";
|
|
2
|
+
import type { Driver, SqlDriver } from "./types.js";
|
|
3
3
|
export type StatementType = "select" | "insert" | "replace" | "update" | "delete" | "create" | "alter" | "drop" | "truncate";
|
|
4
4
|
export interface SqlAnalysis {
|
|
5
5
|
ast: AST;
|
|
@@ -10,4 +10,6 @@ export interface SqlAnalysis {
|
|
|
10
10
|
destructive: boolean;
|
|
11
11
|
ordered: boolean;
|
|
12
12
|
}
|
|
13
|
+
export declare function analyzeSql(sql: string, driver: SqlDriver): SqlAnalysis;
|
|
14
|
+
/** @internal Compatibility for existing connection records during Mongo rollout. */
|
|
13
15
|
export declare function analyzeSql(sql: string, driver: Driver): SqlAnalysis;
|
package/dist/src/sql.js
CHANGED
|
@@ -14,6 +14,9 @@ const SUPPORTED_STATEMENTS = new Set([
|
|
|
14
14
|
"truncate",
|
|
15
15
|
]);
|
|
16
16
|
export function analyzeSql(sql, driver) {
|
|
17
|
+
if (driver === "mongodb") {
|
|
18
|
+
throw new StateQLError("INVALID_SQL", "SQL is not supported for MongoDB connections.");
|
|
19
|
+
}
|
|
17
20
|
const trimmed = sql.trim();
|
|
18
21
|
if (!trimmed)
|
|
19
22
|
throw new StateQLError("INVALID_SQL", "SQL is empty.");
|
package/dist/src/stateql.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActorLinkData, ActorResolutionData, ActorsData, ActorUnlinkData, AliasData, ApplyData, BatchCommand, BatchOptions, CapabilitiesData, CloseSessionData, ColumnsData, CommitTransactionData, ConnectOptions, ConnectionData, CountData, DisconnectData, DoctorData, ExecData, ExecOptions, ExecutionOptions, ExportData, FilterOptions, HistoryData, OperationData, PlanData, PlanOptions, ProfileData, ProfilesData, ProfileOptions, PurgeData, QueryOptions, RemovedProfileData, Response, ResultData, RollbackTransactionData, RowsData, RowsOptions, StateQLActorOptions, StateQLOptions, StateQLSnapshot, StatusData, SessionData, SessionsData, SessionSummaryData, TransactionData } from "./types.js";
|
|
1
|
+
import type { ActorLinkData, ActorResolutionData, ActorsData, ActorUnlinkData, AliasData, ApplyData, BatchCommand, CommandExecutionContext, BatchOptions, CapabilitiesData, CloseSessionData, ColumnsData, CommitTransactionData, ConnectOptions, ConnectionData, CountData, DisconnectData, DoctorData, ExecData, ExecOptions, ExecutionOptions, ExportData, FilterOptions, HistoryData, HistoryOptions, OperationData, PlanData, PlanOptions, ProfileData, ProfilesData, ProfileOptions, MongoExecOptions, MongoPlanOptions, MongoQueryOptions, MongoReadCommand, MongoWriteCommand, PurgeData, QueryOptions, RemovedProfileData, Response, ResultData, RollbackTransactionData, RowsData, RowsOptions, StateQLActorOptions, StateQLOptions, StateQLSnapshot, StatusData, SessionData, SessionsData, SessionSummaryData, TransactionData } from "./types.js";
|
|
2
2
|
export declare class StateQL {
|
|
3
3
|
static forActor(options: StateQLActorOptions): StateQL;
|
|
4
4
|
private readonly store;
|
|
@@ -12,6 +12,7 @@ export declare class StateQL {
|
|
|
12
12
|
private readonly maxResultBytes;
|
|
13
13
|
private readonly timeoutMs;
|
|
14
14
|
private readonly signal?;
|
|
15
|
+
private readonly commandContexts;
|
|
15
16
|
private readonly credentialResolver?;
|
|
16
17
|
private readonly now;
|
|
17
18
|
private closed;
|
|
@@ -38,6 +39,7 @@ export declare class StateQL {
|
|
|
38
39
|
sessionSummary(): Promise<Response<SessionSummaryData>>;
|
|
39
40
|
closeSession(): Promise<Response<CloseSessionData>>;
|
|
40
41
|
query(sql: string, options?: QueryOptions): Promise<Response<ResultData>>;
|
|
42
|
+
mongoQuery(command: MongoReadCommand, options?: MongoQueryOptions): Promise<Response<ResultData>>;
|
|
41
43
|
show(idOrAlias: string): Promise<Response<ResultData>>;
|
|
42
44
|
filter(idOrAlias: string, predicate: string, options?: FilterOptions): Promise<Response<ResultData>>;
|
|
43
45
|
rows(idOrAlias: string, options?: RowsOptions): Promise<Response<RowsData>>;
|
|
@@ -46,6 +48,7 @@ export declare class StateQL {
|
|
|
46
48
|
setAlias(name: string, id: string): Promise<Response<AliasData>>;
|
|
47
49
|
exportResult(idOrAlias: string, output: string, format?: "json" | "jsonl" | "csv"): Promise<Response<ExportData>>;
|
|
48
50
|
exec(sql: string, options?: ExecOptions): Promise<Response<ExecData>>;
|
|
51
|
+
mongoExec(command: MongoWriteCommand, options?: MongoExecOptions): Promise<Response<ExecData>>;
|
|
49
52
|
receipt(id: string): Promise<Response<OperationData>>;
|
|
50
53
|
beginTransaction(isolation?: string): Promise<Response<TransactionData>>;
|
|
51
54
|
transactionStatus(id?: string): Promise<Response<TransactionData>>;
|
|
@@ -53,19 +56,23 @@ export declare class StateQL {
|
|
|
53
56
|
rollbackTransaction(id?: string): Promise<Response<RollbackTransactionData>>;
|
|
54
57
|
inspect(kind: string, table?: string, options?: ExecutionOptions): Promise<Response<unknown>>;
|
|
55
58
|
plan(sql: string, options?: PlanOptions): Promise<Response<PlanData>>;
|
|
59
|
+
mongoPlan(command: MongoWriteCommand, options?: MongoPlanOptions): Promise<Response<PlanData>>;
|
|
56
60
|
apply(planId: string, options?: ExecutionOptions): Promise<Response<ApplyData>>;
|
|
57
|
-
history(limit?: number): Promise<Response<HistoryData>>;
|
|
61
|
+
history(limit?: number, options?: HistoryOptions): Promise<Response<HistoryData>>;
|
|
58
62
|
doctor(): Promise<Response<DoctorData>>;
|
|
59
63
|
purge(scope?: "expired" | "results" | "history" | "all"): Promise<Response<PurgeData>>;
|
|
60
64
|
capabilities(): Promise<Response<CapabilitiesData>>;
|
|
61
|
-
executeCommand(command: BatchCommand): Promise<Response<unknown>>;
|
|
65
|
+
executeCommand(command: BatchCommand, context?: CommandExecutionContext): Promise<Response<unknown>>;
|
|
62
66
|
batch(commands: Iterable<BatchCommand> | AsyncIterable<BatchCommand>, options?: BatchOptions): AsyncGenerator<Response<unknown>>;
|
|
63
67
|
private performExec;
|
|
68
|
+
private performMongoExec;
|
|
64
69
|
private batchFailure;
|
|
65
70
|
private withResult;
|
|
66
71
|
private rejectDuringStagedTransaction;
|
|
67
72
|
private requireResult;
|
|
68
73
|
private requireConnection;
|
|
74
|
+
private requireMongoConnection;
|
|
75
|
+
private rejectMongoSql;
|
|
69
76
|
private requireActiveTransaction;
|
|
70
77
|
private requireSelectedSession;
|
|
71
78
|
private validateActorId;
|
|
@@ -73,6 +80,7 @@ export declare class StateQL {
|
|
|
73
80
|
private resolveConnectionSource;
|
|
74
81
|
private resolveCredential;
|
|
75
82
|
private openAdapter;
|
|
83
|
+
private openMongoAdapter;
|
|
76
84
|
private executionContext;
|
|
77
85
|
private resultData;
|
|
78
86
|
private cacheValid;
|