@peridotvault/peridotbase-sdk 0.0.0-stage → 0.2.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/dist/sql.d.ts ADDED
@@ -0,0 +1,244 @@
1
+ import { ColumnSpec, ColumnTypeName } from "./values";
2
+ import { ExprNode, RangePredicate } from "./expr";
3
+ /** Scalar functions implemented by the client-side SQL evaluator. */
4
+ export type ScalarFn = "lower" | "upper" | "length" | "round" | "abs" | "trim" | "ltrim" | "rtrim";
5
+ export type SubqueryMode = "scalar" | "exists" | "in" | "notin";
6
+ /** Column reference by name, before schema binding. */
7
+ export type NameExpr = {
8
+ k: "lit";
9
+ value: any;
10
+ } | {
11
+ k: "id";
12
+ name: string;
13
+ side: "new" | "old";
14
+ } | {
15
+ k: "signer";
16
+ } | {
17
+ k: "agg";
18
+ fn: AggregateFn;
19
+ column?: string;
20
+ } | {
21
+ k: "cmp";
22
+ op: "eq" | "ne" | "lt" | "le" | "gt" | "ge";
23
+ a: NameExpr;
24
+ b: NameExpr;
25
+ } | {
26
+ k: "rangep";
27
+ op: RangePredicate;
28
+ a: NameExpr;
29
+ b: NameExpr;
30
+ } | {
31
+ k: "and" | "or";
32
+ a: NameExpr;
33
+ b: NameExpr;
34
+ } | {
35
+ k: "not";
36
+ a: NameExpr;
37
+ } | {
38
+ k: "isnull" | "isnotnull";
39
+ a: NameExpr;
40
+ } | {
41
+ k: "between";
42
+ a: NameExpr;
43
+ low: NameExpr;
44
+ high: NameExpr;
45
+ negated?: boolean;
46
+ } | {
47
+ k: "in";
48
+ a: NameExpr;
49
+ values: NameExpr[];
50
+ negated?: boolean;
51
+ } | {
52
+ k: "arith";
53
+ op: "add" | "sub" | "mul" | "div";
54
+ a: NameExpr;
55
+ b: NameExpr;
56
+ } | {
57
+ k: "case";
58
+ operand?: NameExpr;
59
+ whens: {
60
+ when: NameExpr;
61
+ then: NameExpr;
62
+ }[];
63
+ otherwise?: NameExpr;
64
+ } | {
65
+ k: "coalesce";
66
+ args: NameExpr[];
67
+ } | {
68
+ k: "nullif";
69
+ a: NameExpr;
70
+ b: NameExpr;
71
+ } | {
72
+ k: "cast";
73
+ a: NameExpr;
74
+ type: ColumnTypeName;
75
+ scale?: number;
76
+ maxLen?: number;
77
+ } | {
78
+ k: "func";
79
+ fn: ScalarFn;
80
+ args: NameExpr[];
81
+ } | {
82
+ k: "subquery";
83
+ query: Extract<Statement, {
84
+ kind: "select";
85
+ }>;
86
+ mode: SubqueryMode;
87
+ a?: NameExpr;
88
+ };
89
+ export type OrderByTerm = {
90
+ column: string;
91
+ direction: "asc" | "desc";
92
+ nulls?: "first" | "last";
93
+ };
94
+ export type AggregateFn = "count" | "sum" | "avg" | "min" | "max";
95
+ export type SelectItem = {
96
+ kind: "column";
97
+ name: string;
98
+ alias?: string;
99
+ } | {
100
+ kind: "aggregate";
101
+ fn: AggregateFn;
102
+ column?: string;
103
+ alias?: string;
104
+ filter?: NameExpr;
105
+ } | {
106
+ kind: "expr";
107
+ expr: NameExpr;
108
+ alias: string;
109
+ };
110
+ export type JoinSpec = {
111
+ kind: "inner" | "left" | "right";
112
+ table: string;
113
+ /** Optional table alias, used to qualify columns (`a.id`). */
114
+ alias?: string;
115
+ on: NameExpr;
116
+ };
117
+ export type OnConflictClause = {
118
+ action: "nothing";
119
+ } | {
120
+ action: "update";
121
+ assignments: {
122
+ column: string;
123
+ value: any;
124
+ }[];
125
+ };
126
+ export type TableConstraint = {
127
+ kind: "primaryKey";
128
+ column: string;
129
+ } | {
130
+ kind: "unique";
131
+ column: string;
132
+ } | {
133
+ kind: "compositePrimaryKey";
134
+ columns: string[];
135
+ } | {
136
+ kind: "compositeUnique";
137
+ columns: string[];
138
+ } | {
139
+ kind: "check";
140
+ expr: NameExpr;
141
+ };
142
+ export type Statement = {
143
+ kind: "createDatabase";
144
+ name: string;
145
+ } | {
146
+ kind: "createTable";
147
+ name: string;
148
+ columns: ColumnSpec[];
149
+ constraints: TableConstraint[];
150
+ } | {
151
+ kind: "createIndex";
152
+ name: string;
153
+ table: string;
154
+ column: string;
155
+ columns: string[];
156
+ unique: boolean;
157
+ } | {
158
+ kind: "alterTable";
159
+ table: string;
160
+ addColumns: ColumnSpec[];
161
+ } | {
162
+ kind: "insert";
163
+ table: string;
164
+ columns: string[] | null;
165
+ rows: any[][];
166
+ onConflict?: OnConflictClause;
167
+ returning?: string[] | "*";
168
+ } | {
169
+ kind: "select";
170
+ table: string;
171
+ /** Optional table alias, used to qualify columns (`a.id`). */
172
+ alias?: string;
173
+ columns: string[] | "*";
174
+ selectItems?: SelectItem[];
175
+ join?: JoinSpec;
176
+ groupBy?: string;
177
+ having?: NameExpr;
178
+ where?: NameExpr;
179
+ orderBy?: OrderByTerm[];
180
+ limit?: number;
181
+ offset?: number;
182
+ } | {
183
+ kind: "update";
184
+ table: string;
185
+ assignments: {
186
+ column: string;
187
+ value: any;
188
+ }[];
189
+ where: NameExpr;
190
+ returning?: string[] | "*";
191
+ } | {
192
+ kind: "delete";
193
+ table: string;
194
+ where: NameExpr;
195
+ returning?: string[] | "*";
196
+ } | {
197
+ kind: "createView";
198
+ name: string;
199
+ query: Extract<Statement, {
200
+ kind: "select";
201
+ }>;
202
+ replace?: boolean;
203
+ } | {
204
+ kind: "dropView";
205
+ name: string;
206
+ ifExists?: boolean;
207
+ } | {
208
+ kind: "explain";
209
+ statement: Extract<Statement, {
210
+ kind: "select";
211
+ }>;
212
+ analyze: boolean;
213
+ } | {
214
+ kind: "setOp";
215
+ op: "union" | "unionAll" | "intersect" | "except";
216
+ left: Extract<Statement, {
217
+ kind: "select";
218
+ }>;
219
+ right: Extract<Statement, {
220
+ kind: "select";
221
+ }>;
222
+ } | {
223
+ kind: "with";
224
+ ctes: {
225
+ name: string;
226
+ columns?: string[];
227
+ query: Extract<Statement, {
228
+ kind: "select";
229
+ }>;
230
+ }[];
231
+ body: Statement;
232
+ };
233
+ /** Splits a SQL script into statements and parses each one. */
234
+ export declare function parseSql(sql: string, params?: any[] | Record<string, any>): Statement[];
235
+ /** Parses a single SQL statement. */
236
+ export declare function parseSqlStatement(sql: string, params?: any[] | Record<string, any>): Statement;
237
+ export declare function bindNameExpr(node: NameExpr, columns: ColumnSpec[]): ExprNode;
238
+ /** True when a WHERE clause constrains exactly one column with equality. */
239
+ export declare function equalityTarget(node: NameExpr, tableName: string): {
240
+ column: string;
241
+ value: any;
242
+ } | null;
243
+ /** Unused placeholder to keep the signature easy to evolve. */
244
+ export declare function describeStatement(statement: Statement): string;