@fadhilp/stateql 0.1.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.
@@ -0,0 +1,245 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import type { Column, Driver, Row, SqlParameters, StateConfidence } from "./types.js";
3
+ export interface SessionRecord {
4
+ id: string;
5
+ name: string;
6
+ status: string;
7
+ active_connection_id: string | null;
8
+ active_transaction_id: string | null;
9
+ created_at: string;
10
+ updated_at: string;
11
+ }
12
+ export interface ConnectionRecord {
13
+ id: string;
14
+ session_id: string;
15
+ name: string;
16
+ driver: Driver;
17
+ database_name: string;
18
+ source: string;
19
+ secret_env: string | null;
20
+ read_only: number;
21
+ version: number;
22
+ created_at: string;
23
+ }
24
+ export interface ProfileRecord {
25
+ name: string;
26
+ target: string | null;
27
+ secret_env: string | null;
28
+ read_only: number;
29
+ created_at: string;
30
+ updated_at: string;
31
+ }
32
+ export interface ResultRecord {
33
+ id: string;
34
+ session_id: string;
35
+ connection_id: string;
36
+ fingerprint: string;
37
+ sql: string;
38
+ parameters: string;
39
+ rows_json: string;
40
+ columns_json: string;
41
+ row_count: number;
42
+ state_version: string;
43
+ state_signature: string;
44
+ state_confidence: StateConfidence;
45
+ expires_at: string;
46
+ created_at: string;
47
+ }
48
+ export interface OperationRecord {
49
+ id: string;
50
+ session_id: string;
51
+ connection_id: string;
52
+ fingerprint: string;
53
+ sql: string;
54
+ parameters: string;
55
+ statement_type: string;
56
+ affected_rows: number | null;
57
+ status: string;
58
+ transaction_id: string | null;
59
+ replay_of: string | null;
60
+ idempotency_key: string | null;
61
+ state_version_before: string;
62
+ state_version_after: string | null;
63
+ created_at: string;
64
+ }
65
+ export interface TransactionRecord {
66
+ id: string;
67
+ session_id: string;
68
+ connection_id: string;
69
+ state: string;
70
+ isolation_level: string;
71
+ start_version: string;
72
+ created_at: string;
73
+ ended_at: string | null;
74
+ }
75
+ export interface PlanRecord {
76
+ id: string;
77
+ session_id: string;
78
+ connection_id: string;
79
+ sql: string;
80
+ parameters: string;
81
+ statement_type: string;
82
+ state_version: string;
83
+ state_signature: string;
84
+ destructive: number;
85
+ allow_unbounded: number;
86
+ allow_destructive: number;
87
+ expires_at: string;
88
+ applied_operation_id: string | null;
89
+ created_at: string;
90
+ }
91
+ export interface HistoryRecord {
92
+ id: string;
93
+ timestamp: string;
94
+ session_id: string;
95
+ command: string;
96
+ handle: string | null;
97
+ executed: number;
98
+ cached: number;
99
+ success: number;
100
+ error_code: string | null;
101
+ }
102
+ export declare class StateStore {
103
+ private readonly now;
104
+ readonly db: DatabaseSync;
105
+ constructor(home: string, now: () => Date);
106
+ close(): void;
107
+ nextId(prefix: string): string;
108
+ ensureSession(name?: string): SessionRecord;
109
+ createSession(name: string): SessionRecord;
110
+ getSession(idOrName: string): SessionRecord | undefined;
111
+ listSessions(): SessionRecord[];
112
+ closeSession(sessionId: string): void;
113
+ addProfile(input: {
114
+ name: string;
115
+ target?: string;
116
+ secretEnv?: string;
117
+ readOnly: boolean;
118
+ }): ProfileRecord;
119
+ getProfile(name: string): ProfileRecord | undefined;
120
+ listProfiles(): ProfileRecord[];
121
+ removeProfile(name: string): boolean;
122
+ addConnection(input: {
123
+ sessionId: string;
124
+ name: string;
125
+ driver: Driver;
126
+ databaseName: string;
127
+ source: string;
128
+ secretEnv?: string;
129
+ readOnly: boolean;
130
+ }): ConnectionRecord;
131
+ getConnection(id: string): ConnectionRecord | undefined;
132
+ activeConnection(session: SessionRecord): ConnectionRecord | undefined;
133
+ disconnect(sessionId: string): void;
134
+ bumpVersion(connectionId: string): string;
135
+ saveResult(input: {
136
+ sessionId: string;
137
+ connectionId: string;
138
+ fingerprint: string;
139
+ sql: string;
140
+ parameters: SqlParameters;
141
+ rows: Row[];
142
+ columns: Column[];
143
+ stateVersion: string;
144
+ stateSignature: string;
145
+ stateConfidence: StateConfidence;
146
+ expiresAt: string;
147
+ }): ResultRecord;
148
+ findResult(fingerprint: string): ResultRecord | undefined;
149
+ getResult(idOrAlias: string, sessionId?: string): ResultRecord | undefined;
150
+ resultRows(result: ResultRecord): Row[];
151
+ resultColumns(result: ResultRecord): Column[];
152
+ setAlias(sessionId: string, name: string, resultId: string): void;
153
+ saveOperation(input: {
154
+ sessionId: string;
155
+ connectionId: string;
156
+ fingerprint: string;
157
+ sql: string;
158
+ parameters: SqlParameters;
159
+ statementType: string;
160
+ affectedRows?: number;
161
+ status: string;
162
+ transactionId?: string;
163
+ replayOf?: string;
164
+ idempotencyKey?: string;
165
+ stateVersionBefore: string;
166
+ stateVersionAfter?: string;
167
+ }): OperationRecord;
168
+ getOperation(id: string): OperationRecord | undefined;
169
+ findDuplicateOperation(input: {
170
+ connectionId: string;
171
+ fingerprint: string;
172
+ idempotencyKey?: string;
173
+ }): OperationRecord | undefined;
174
+ reserveOperation(input: {
175
+ sessionId: string;
176
+ connectionId: string;
177
+ fingerprint: string;
178
+ sql: string;
179
+ parameters: SqlParameters;
180
+ statementType: string;
181
+ status: "executing" | "pending";
182
+ transactionId?: string;
183
+ replay: boolean;
184
+ idempotencyKey?: string;
185
+ stateVersionBefore: string;
186
+ }): {
187
+ operation?: OperationRecord;
188
+ previous?: OperationRecord;
189
+ };
190
+ finishOperation(operationId: string, affectedRows: number, stateVersion: string): OperationRecord;
191
+ failOperation(operationId: string): void;
192
+ markOperationOutcomeUnknown(operationId: string): void;
193
+ createTransaction(input: {
194
+ sessionId: string;
195
+ connectionId: string;
196
+ isolation: string;
197
+ startVersion: string;
198
+ }): TransactionRecord;
199
+ getTransaction(id: string): TransactionRecord | undefined;
200
+ transactionOperations(transactionId: string): OperationRecord[];
201
+ markTransactionCommitting(transactionId: string): boolean;
202
+ markTransactionOutcomeUnknown(transactionId: string, sessionId: string): void;
203
+ finishTransaction(transactionId: string, sessionId: string, state: "committed" | "rolled_back" | "failed"): void;
204
+ commitTransactionMetadata(input: {
205
+ transactionId: string;
206
+ sessionId: string;
207
+ connectionId: string;
208
+ operations: Array<{
209
+ id: string;
210
+ affectedRows: number;
211
+ }>;
212
+ }): string;
213
+ savePlan(input: {
214
+ sessionId: string;
215
+ connectionId: string;
216
+ sql: string;
217
+ parameters: SqlParameters;
218
+ statementType: string;
219
+ stateVersion: string;
220
+ stateSignature: string;
221
+ destructive: boolean;
222
+ allowUnbounded: boolean;
223
+ allowDestructive: boolean;
224
+ expiresAt: string;
225
+ }): PlanRecord;
226
+ getPlan(id: string): PlanRecord | undefined;
227
+ markPlanApplied(planId: string, operationId: string): void;
228
+ addHistory(input: {
229
+ sessionId: string;
230
+ command: string;
231
+ handle?: string;
232
+ executed: boolean;
233
+ cached: boolean;
234
+ success: boolean;
235
+ errorCode?: string;
236
+ id?: string;
237
+ }): HistoryRecord;
238
+ history(sessionId: string, limit: number): HistoryRecord[];
239
+ recentOperations(sessionId: string, limit: number): OperationRecord[];
240
+ knownResults(sessionId: string, limit: number): Array<ResultRecord & {
241
+ alias: string | null;
242
+ }>;
243
+ private recoverStaleCommittingTransactions;
244
+ private migrate;
245
+ }