sqlql 0.1.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/LICENSE +21 -0
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/index.cjs +613 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +304 -0
- package/dist/index.d.mts +304 -0
- package/dist/index.mjs +559 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +28 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
declare namespace planning_d_exports {
|
|
2
|
+
export { AggregateExpression, AggregateItem, AggregateRequest, AggregateStep, AndPredicate, ColumnRef, ColumnValue, ComparisonOperator, ComparisonPredicate, CteBinding, CteStep, ExplainDecision, ExplainResult, Expression, FilterStep, FromSource, InPredicate, JoinSpec, JoinStep, LiteralValue, MutationIR, NotPredicate, NullPredicate, OrPredicate, OrderByTerm, PlanStep, PlanStepBase, Predicate, ProjectStep, QueryCapabilities, QueryIR, QueryPlan, ResolverContext, ResolverRegistry, Row, RowSet, ScalarValue, ScanRequest, ScanStep, SelectItem, TableResolver, defineTableResolver };
|
|
3
|
+
}
|
|
4
|
+
type ScalarValue = string | number | boolean | null;
|
|
5
|
+
type ComparisonOperator = "=" | "!=" | ">" | ">=" | "<" | "<=";
|
|
6
|
+
interface ColumnRef {
|
|
7
|
+
table: string;
|
|
8
|
+
column: string;
|
|
9
|
+
}
|
|
10
|
+
interface LiteralValue {
|
|
11
|
+
kind: "literal";
|
|
12
|
+
value: ScalarValue;
|
|
13
|
+
}
|
|
14
|
+
interface ColumnValue {
|
|
15
|
+
kind: "column";
|
|
16
|
+
ref: ColumnRef;
|
|
17
|
+
}
|
|
18
|
+
type Expression = ColumnValue | LiteralValue;
|
|
19
|
+
interface ComparisonPredicate {
|
|
20
|
+
kind: "comparison";
|
|
21
|
+
operator: ComparisonOperator;
|
|
22
|
+
left: Expression;
|
|
23
|
+
right: Expression;
|
|
24
|
+
}
|
|
25
|
+
interface InPredicate {
|
|
26
|
+
kind: "in";
|
|
27
|
+
left: Expression;
|
|
28
|
+
values: ScalarValue[];
|
|
29
|
+
}
|
|
30
|
+
interface NullPredicate {
|
|
31
|
+
kind: "null_check";
|
|
32
|
+
expression: Expression;
|
|
33
|
+
negated: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface AndPredicate {
|
|
36
|
+
kind: "and";
|
|
37
|
+
predicates: Predicate[];
|
|
38
|
+
}
|
|
39
|
+
interface OrPredicate {
|
|
40
|
+
kind: "or";
|
|
41
|
+
predicates: Predicate[];
|
|
42
|
+
}
|
|
43
|
+
interface NotPredicate {
|
|
44
|
+
kind: "not";
|
|
45
|
+
predicate: Predicate;
|
|
46
|
+
}
|
|
47
|
+
type Predicate = ComparisonPredicate | InPredicate | NullPredicate | AndPredicate | OrPredicate | NotPredicate;
|
|
48
|
+
interface SelectItem {
|
|
49
|
+
expression: Expression;
|
|
50
|
+
alias?: string;
|
|
51
|
+
}
|
|
52
|
+
interface OrderByTerm {
|
|
53
|
+
expression: Expression;
|
|
54
|
+
direction: "asc" | "desc";
|
|
55
|
+
}
|
|
56
|
+
interface JoinSpec {
|
|
57
|
+
type: "inner" | "left";
|
|
58
|
+
sourceTable: string;
|
|
59
|
+
sourceAlias?: string;
|
|
60
|
+
on: Predicate;
|
|
61
|
+
}
|
|
62
|
+
interface AggregateExpression {
|
|
63
|
+
function: "count" | "sum" | "avg" | "min" | "max";
|
|
64
|
+
argument?: Expression;
|
|
65
|
+
distinct?: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface AggregateItem {
|
|
68
|
+
alias: string;
|
|
69
|
+
expression: AggregateExpression;
|
|
70
|
+
}
|
|
71
|
+
interface CteBinding {
|
|
72
|
+
name: string;
|
|
73
|
+
query: QueryIR;
|
|
74
|
+
recursive?: boolean;
|
|
75
|
+
}
|
|
76
|
+
interface FromSource {
|
|
77
|
+
table: string;
|
|
78
|
+
alias?: string;
|
|
79
|
+
}
|
|
80
|
+
interface QueryIR {
|
|
81
|
+
ctes?: CteBinding[];
|
|
82
|
+
from: FromSource;
|
|
83
|
+
joins?: JoinSpec[];
|
|
84
|
+
select: SelectItem[];
|
|
85
|
+
where?: Predicate;
|
|
86
|
+
groupBy?: Expression[];
|
|
87
|
+
aggregates?: AggregateItem[];
|
|
88
|
+
orderBy?: OrderByTerm[];
|
|
89
|
+
limit?: number;
|
|
90
|
+
offset?: number;
|
|
91
|
+
}
|
|
92
|
+
interface MutationIR {
|
|
93
|
+
type: "insert" | "update" | "delete";
|
|
94
|
+
table: string;
|
|
95
|
+
}
|
|
96
|
+
interface QueryCapabilities {
|
|
97
|
+
filterOperators: ComparisonOperator[];
|
|
98
|
+
filterableColumns: string[];
|
|
99
|
+
sortableColumns: string[];
|
|
100
|
+
maxLimit: number;
|
|
101
|
+
requiresLimit: boolean;
|
|
102
|
+
supportsOr: boolean;
|
|
103
|
+
supportsNot: boolean;
|
|
104
|
+
supportsAggregates: boolean;
|
|
105
|
+
supportsCtes: boolean;
|
|
106
|
+
supportsRecursiveCtes: boolean;
|
|
107
|
+
}
|
|
108
|
+
interface ScanRequest {
|
|
109
|
+
table: string;
|
|
110
|
+
alias?: string;
|
|
111
|
+
projection: ColumnRef[];
|
|
112
|
+
predicate?: Predicate;
|
|
113
|
+
orderBy?: OrderByTerm[];
|
|
114
|
+
limit?: number;
|
|
115
|
+
offset?: number;
|
|
116
|
+
}
|
|
117
|
+
interface AggregateRequest {
|
|
118
|
+
table: string;
|
|
119
|
+
alias?: string;
|
|
120
|
+
predicate?: Predicate;
|
|
121
|
+
groupBy: Expression[];
|
|
122
|
+
aggregates: AggregateItem[];
|
|
123
|
+
orderBy?: OrderByTerm[];
|
|
124
|
+
limit?: number;
|
|
125
|
+
}
|
|
126
|
+
type Row = Record<string, unknown>;
|
|
127
|
+
interface RowSet {
|
|
128
|
+
rows: Row[];
|
|
129
|
+
}
|
|
130
|
+
interface ResolverContext {
|
|
131
|
+
requestId: string;
|
|
132
|
+
actorId?: string;
|
|
133
|
+
}
|
|
134
|
+
interface TableResolver<TContext extends ResolverContext = ResolverContext> {
|
|
135
|
+
table: string;
|
|
136
|
+
capabilities: QueryCapabilities;
|
|
137
|
+
scan: (request: ScanRequest, context: TContext) => Promise<RowSet>;
|
|
138
|
+
aggregate?: (request: AggregateRequest, context: TContext) => Promise<RowSet>;
|
|
139
|
+
}
|
|
140
|
+
interface ResolverRegistry<TContext extends ResolverContext = ResolverContext> {
|
|
141
|
+
getResolver: (table: string) => TableResolver<TContext> | undefined;
|
|
142
|
+
}
|
|
143
|
+
interface PlanStepBase {
|
|
144
|
+
id: string;
|
|
145
|
+
dependsOn: string[];
|
|
146
|
+
}
|
|
147
|
+
interface ScanStep extends PlanStepBase {
|
|
148
|
+
kind: "scan";
|
|
149
|
+
table: string;
|
|
150
|
+
resolver: string;
|
|
151
|
+
request: ScanRequest;
|
|
152
|
+
pushdown: {
|
|
153
|
+
predicate: boolean;
|
|
154
|
+
projection: boolean;
|
|
155
|
+
orderBy: boolean;
|
|
156
|
+
limit: boolean;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
interface FilterStep extends PlanStepBase {
|
|
160
|
+
kind: "filter";
|
|
161
|
+
predicate: Predicate;
|
|
162
|
+
}
|
|
163
|
+
interface JoinStep extends PlanStepBase {
|
|
164
|
+
kind: "join";
|
|
165
|
+
join: JoinSpec;
|
|
166
|
+
}
|
|
167
|
+
interface AggregateStep extends PlanStepBase {
|
|
168
|
+
kind: "aggregate";
|
|
169
|
+
request: AggregateRequest;
|
|
170
|
+
}
|
|
171
|
+
interface ProjectStep extends PlanStepBase {
|
|
172
|
+
kind: "project";
|
|
173
|
+
select: SelectItem[];
|
|
174
|
+
}
|
|
175
|
+
interface CteStep extends PlanStepBase {
|
|
176
|
+
kind: "cte";
|
|
177
|
+
binding: CteBinding;
|
|
178
|
+
strategy: "inline" | "materialize";
|
|
179
|
+
}
|
|
180
|
+
type PlanStep = ScanStep | FilterStep | JoinStep | AggregateStep | ProjectStep | CteStep;
|
|
181
|
+
interface QueryPlan {
|
|
182
|
+
rootStepId: string;
|
|
183
|
+
steps: PlanStep[];
|
|
184
|
+
}
|
|
185
|
+
interface ExplainDecision {
|
|
186
|
+
stepId: string;
|
|
187
|
+
decision: string;
|
|
188
|
+
}
|
|
189
|
+
interface ExplainResult {
|
|
190
|
+
query: QueryIR;
|
|
191
|
+
plan: QueryPlan;
|
|
192
|
+
decisions: ExplainDecision[];
|
|
193
|
+
}
|
|
194
|
+
declare function defineTableResolver<TContext extends ResolverContext = ResolverContext>(resolver: TableResolver<TContext>): TableResolver<TContext>;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region ../core/src/index.d.ts
|
|
197
|
+
type SqlScalarType = "text" | "integer" | "boolean" | "timestamp";
|
|
198
|
+
type TableColumns = Record<string, SqlScalarType>;
|
|
199
|
+
interface SchemaQueryDefaults {
|
|
200
|
+
filterable: "all" | string[];
|
|
201
|
+
sortable: "all" | string[];
|
|
202
|
+
maxRows: number | null;
|
|
203
|
+
}
|
|
204
|
+
interface TableQueryOverrides {
|
|
205
|
+
filterable?: "all" | string[];
|
|
206
|
+
sortable?: "all" | string[];
|
|
207
|
+
maxRows?: number | null;
|
|
208
|
+
}
|
|
209
|
+
interface TableDefinition {
|
|
210
|
+
columns: TableColumns;
|
|
211
|
+
query?: TableQueryOverrides;
|
|
212
|
+
}
|
|
213
|
+
interface SchemaDefinition {
|
|
214
|
+
defaults?: {
|
|
215
|
+
query?: Partial<SchemaQueryDefaults>;
|
|
216
|
+
};
|
|
217
|
+
tables: Record<string, TableDefinition>;
|
|
218
|
+
}
|
|
219
|
+
declare const DEFAULT_QUERY_BEHAVIOR: SchemaQueryDefaults;
|
|
220
|
+
declare function defineSchema<TSchema extends SchemaDefinition>(schema: TSchema): TSchema;
|
|
221
|
+
declare function getTable(schema: SchemaDefinition, tableName: string): TableDefinition;
|
|
222
|
+
declare function resolveTableQueryBehavior(schema: SchemaDefinition, tableName: string): SchemaQueryDefaults;
|
|
223
|
+
type ScanFilterOperator = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in";
|
|
224
|
+
interface FilterClauseBase {
|
|
225
|
+
column: string;
|
|
226
|
+
op: ScanFilterOperator;
|
|
227
|
+
}
|
|
228
|
+
interface ScalarFilterClause extends FilterClauseBase {
|
|
229
|
+
op: "eq" | "neq" | "gt" | "gte" | "lt" | "lte";
|
|
230
|
+
value: unknown;
|
|
231
|
+
}
|
|
232
|
+
interface SetFilterClause extends FilterClauseBase {
|
|
233
|
+
op: "in";
|
|
234
|
+
values: unknown[];
|
|
235
|
+
}
|
|
236
|
+
type ScanFilterClause = ScalarFilterClause | SetFilterClause;
|
|
237
|
+
interface ScanOrderBy {
|
|
238
|
+
column: string;
|
|
239
|
+
direction: "asc" | "desc";
|
|
240
|
+
}
|
|
241
|
+
interface TableScanRequest {
|
|
242
|
+
table: string;
|
|
243
|
+
alias?: string;
|
|
244
|
+
select: string[];
|
|
245
|
+
where?: ScanFilterClause[];
|
|
246
|
+
orderBy?: ScanOrderBy[];
|
|
247
|
+
limit?: number;
|
|
248
|
+
offset?: number;
|
|
249
|
+
}
|
|
250
|
+
interface TableLookupRequest {
|
|
251
|
+
table: string;
|
|
252
|
+
alias?: string;
|
|
253
|
+
key: string;
|
|
254
|
+
values: unknown[];
|
|
255
|
+
select: string[];
|
|
256
|
+
where?: ScanFilterClause[];
|
|
257
|
+
}
|
|
258
|
+
type AggregateFunction = "count" | "sum" | "avg" | "min" | "max";
|
|
259
|
+
interface TableAggregateMetric {
|
|
260
|
+
fn: AggregateFunction;
|
|
261
|
+
column?: string;
|
|
262
|
+
as: string;
|
|
263
|
+
distinct?: boolean;
|
|
264
|
+
}
|
|
265
|
+
interface TableAggregateRequest {
|
|
266
|
+
table: string;
|
|
267
|
+
alias?: string;
|
|
268
|
+
where?: ScanFilterClause[];
|
|
269
|
+
groupBy?: string[];
|
|
270
|
+
metrics: TableAggregateMetric[];
|
|
271
|
+
limit?: number;
|
|
272
|
+
}
|
|
273
|
+
type QueryRow = Record<string, unknown>;
|
|
274
|
+
interface TableMethods<TContext = unknown> {
|
|
275
|
+
scan: (request: TableScanRequest, context: TContext) => Promise<QueryRow[]>;
|
|
276
|
+
lookup?: (request: TableLookupRequest, context: TContext) => Promise<QueryRow[]>;
|
|
277
|
+
aggregate?: (request: TableAggregateRequest, context: TContext) => Promise<QueryRow[]>;
|
|
278
|
+
}
|
|
279
|
+
type TableMethodsMap<TContext = unknown> = Record<string, TableMethods<TContext>>;
|
|
280
|
+
declare function defineTableMethods<TContext, TMethods extends TableMethodsMap<TContext>>(methods: TMethods): TMethods;
|
|
281
|
+
interface SqlDdlOptions {
|
|
282
|
+
ifNotExists?: boolean;
|
|
283
|
+
}
|
|
284
|
+
declare function toSqlDDL(schema: SchemaDefinition, options?: SqlDdlOptions): string;
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region ../sql/src/index.d.ts
|
|
287
|
+
interface SqlQuery {
|
|
288
|
+
text: string;
|
|
289
|
+
}
|
|
290
|
+
interface PlannedQuery {
|
|
291
|
+
source: string;
|
|
292
|
+
selectAll: boolean;
|
|
293
|
+
}
|
|
294
|
+
interface QueryInput<TContext> {
|
|
295
|
+
schema: SchemaDefinition;
|
|
296
|
+
methods: TableMethodsMap<TContext>;
|
|
297
|
+
context: TContext;
|
|
298
|
+
sql: string;
|
|
299
|
+
}
|
|
300
|
+
declare function parseSql(query: SqlQuery, schema: SchemaDefinition): PlannedQuery;
|
|
301
|
+
declare function query<TContext>(input: QueryInput<TContext>): Promise<QueryRow[]>;
|
|
302
|
+
//#endregion
|
|
303
|
+
export { AggregateFunction, DEFAULT_QUERY_BEHAVIOR, FilterClauseBase, PlannedQuery, QueryInput, QueryRow, ScalarFilterClause, ScanFilterClause, ScanFilterOperator, ScanOrderBy, SchemaDefinition, SchemaQueryDefaults, SetFilterClause, SqlDdlOptions, SqlQuery, SqlScalarType, TableAggregateMetric, TableAggregateRequest, TableColumns, TableDefinition, TableLookupRequest, TableMethods, TableMethodsMap, TableQueryOverrides, TableScanRequest, defineSchema, defineTableMethods, getTable, parseSql, planning_d_exports as planning, query, resolveTableQueryBehavior, toSqlDDL };
|
|
304
|
+
//# sourceMappingURL=index.d.mts.map
|