@powersync/service-sync-rules 0.17.10
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 +67 -0
- package/README.md +3 -0
- package/dist/DartSchemaGenerator.d.ts +12 -0
- package/dist/DartSchemaGenerator.js +39 -0
- package/dist/DartSchemaGenerator.js.map +1 -0
- package/dist/ExpressionType.d.ts +33 -0
- package/dist/ExpressionType.js +61 -0
- package/dist/ExpressionType.js.map +1 -0
- package/dist/IdSequence.d.ts +4 -0
- package/dist/IdSequence.js +9 -0
- package/dist/IdSequence.js.map +1 -0
- package/dist/JsSchemaGenerator.d.ts +12 -0
- package/dist/JsSchemaGenerator.js +42 -0
- package/dist/JsSchemaGenerator.js.map +1 -0
- package/dist/SchemaGenerator.d.ts +14 -0
- package/dist/SchemaGenerator.js +26 -0
- package/dist/SchemaGenerator.js.map +1 -0
- package/dist/SourceTableInterface.d.ts +5 -0
- package/dist/SourceTableInterface.js +2 -0
- package/dist/SourceTableInterface.js.map +1 -0
- package/dist/SqlBucketDescriptor.d.ts +37 -0
- package/dist/SqlBucketDescriptor.js +111 -0
- package/dist/SqlBucketDescriptor.js.map +1 -0
- package/dist/SqlDataQuery.d.ts +39 -0
- package/dist/SqlDataQuery.js +237 -0
- package/dist/SqlDataQuery.js.map +1 -0
- package/dist/SqlParameterQuery.d.ts +43 -0
- package/dist/SqlParameterQuery.js +238 -0
- package/dist/SqlParameterQuery.js.map +1 -0
- package/dist/SqlSyncRules.d.ts +52 -0
- package/dist/SqlSyncRules.js +247 -0
- package/dist/SqlSyncRules.js.map +1 -0
- package/dist/StaticSchema.d.ts +26 -0
- package/dist/StaticSchema.js +61 -0
- package/dist/StaticSchema.js.map +1 -0
- package/dist/StaticSqlParameterQuery.d.ts +24 -0
- package/dist/StaticSqlParameterQuery.js +66 -0
- package/dist/StaticSqlParameterQuery.js.map +1 -0
- package/dist/TablePattern.d.ts +17 -0
- package/dist/TablePattern.js +56 -0
- package/dist/TablePattern.js.map +1 -0
- package/dist/TableQuerySchema.d.ts +9 -0
- package/dist/TableQuerySchema.js +34 -0
- package/dist/TableQuerySchema.js.map +1 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +58 -0
- package/dist/errors.js.map +1 -0
- package/dist/generators.d.ts +6 -0
- package/dist/generators.js +7 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/json_schema.d.ts +3 -0
- package/dist/json_schema.js +48 -0
- package/dist/json_schema.js.map +1 -0
- package/dist/sql_filters.d.ts +91 -0
- package/dist/sql_filters.js +506 -0
- package/dist/sql_filters.js.map +1 -0
- package/dist/sql_functions.d.ts +54 -0
- package/dist/sql_functions.js +773 -0
- package/dist/sql_functions.js.map +1 -0
- package/dist/sql_support.d.ts +22 -0
- package/dist/sql_support.js +213 -0
- package/dist/sql_support.js.map +1 -0
- package/dist/types.d.ts +174 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +45 -0
- package/dist/utils.js +173 -0
- package/dist/utils.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { JSONBig } from '@powersync/service-jsonbig';
|
|
2
|
+
import { parse } from 'pgsql-ast-parser';
|
|
3
|
+
import { SqlRuleError } from './errors.js';
|
|
4
|
+
import { ExpressionType } from './ExpressionType.js';
|
|
5
|
+
import { SqlTools } from './sql_filters.js';
|
|
6
|
+
import { castAsText } from './sql_functions.js';
|
|
7
|
+
import { checkUnsupportedFeatures, isClauseError } from './sql_support.js';
|
|
8
|
+
import { TablePattern } from './TablePattern.js';
|
|
9
|
+
import { filterJsonRow, getBucketId, isSelectStatement } from './utils.js';
|
|
10
|
+
import { TableQuerySchema } from './TableQuerySchema.js';
|
|
11
|
+
export class SqlDataQuery {
|
|
12
|
+
static fromSql(descriptor_name, bucket_parameters, sql, schema) {
|
|
13
|
+
const parsed = parse(sql, { locationTracking: true });
|
|
14
|
+
const rows = new SqlDataQuery();
|
|
15
|
+
if (parsed.length > 1) {
|
|
16
|
+
throw new SqlRuleError('Only a single SELECT statement is supported', sql, parsed[1]?._location);
|
|
17
|
+
}
|
|
18
|
+
const q = parsed[0];
|
|
19
|
+
if (!isSelectStatement(q)) {
|
|
20
|
+
throw new SqlRuleError('Only SELECT statements are supported', sql, q._location);
|
|
21
|
+
}
|
|
22
|
+
rows.errors.push(...checkUnsupportedFeatures(sql, q));
|
|
23
|
+
if (q.from == null || q.from.length != 1 || q.from[0].type != 'table') {
|
|
24
|
+
throw new SqlRuleError('Must SELECT from a single table', sql, q.from?.[0]._location);
|
|
25
|
+
}
|
|
26
|
+
const tableRef = q.from?.[0].name;
|
|
27
|
+
if (tableRef?.name == null) {
|
|
28
|
+
throw new SqlRuleError('Must SELECT from a single table', sql, q.from?.[0]._location);
|
|
29
|
+
}
|
|
30
|
+
const alias = tableRef.alias ?? tableRef.name;
|
|
31
|
+
const sourceTable = new TablePattern(tableRef.schema, tableRef.name);
|
|
32
|
+
let querySchema = undefined;
|
|
33
|
+
if (schema) {
|
|
34
|
+
const tables = schema.getTables(sourceTable);
|
|
35
|
+
if (tables.length == 0) {
|
|
36
|
+
const e = new SqlRuleError(`Table ${sourceTable.schema}.${sourceTable.tablePattern} not found`, sql, q.from?.[0]?._location);
|
|
37
|
+
e.type = 'warning';
|
|
38
|
+
rows.errors.push(e);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
querySchema = new TableQuerySchema(tables, alias);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const where = q.where;
|
|
45
|
+
const tools = new SqlTools({
|
|
46
|
+
table: alias,
|
|
47
|
+
parameter_tables: ['bucket'],
|
|
48
|
+
value_tables: [alias],
|
|
49
|
+
sql,
|
|
50
|
+
schema: querySchema
|
|
51
|
+
});
|
|
52
|
+
const filter = tools.compileWhereClause(where);
|
|
53
|
+
const allParams = new Set([...filter.bucketParameters, ...bucket_parameters.map((p) => `bucket.${p}`)]);
|
|
54
|
+
if ((!filter.error && allParams.size != filter.bucketParameters.length) ||
|
|
55
|
+
allParams.size != bucket_parameters.length) {
|
|
56
|
+
rows.errors.push(new SqlRuleError(`Query must cover all bucket parameters: ${JSONBig.stringify(bucket_parameters)} != ${JSONBig.stringify(filter.bucketParameters)}`, sql, q._location));
|
|
57
|
+
}
|
|
58
|
+
rows.sourceTable = sourceTable;
|
|
59
|
+
rows.table = alias;
|
|
60
|
+
rows.sql = sql;
|
|
61
|
+
rows.filter = filter;
|
|
62
|
+
rows.descriptor_name = descriptor_name;
|
|
63
|
+
rows.bucket_parameters = bucket_parameters;
|
|
64
|
+
rows.columns = q.columns ?? [];
|
|
65
|
+
rows.tools = tools;
|
|
66
|
+
let hasId = false;
|
|
67
|
+
for (let column of q.columns ?? []) {
|
|
68
|
+
const name = tools.getOutputName(column);
|
|
69
|
+
if (name != '*') {
|
|
70
|
+
const clause = tools.compileStaticExtractor(column.expr);
|
|
71
|
+
if (isClauseError(clause)) {
|
|
72
|
+
// Error logged already
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
rows.extractors.push({
|
|
76
|
+
extract: (tables, output) => {
|
|
77
|
+
output[name] = clause.evaluate(tables);
|
|
78
|
+
},
|
|
79
|
+
getTypes(schema, into) {
|
|
80
|
+
into[name] = { name, type: clause.getType(schema) };
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
rows.extractors.push({
|
|
86
|
+
extract: (tables, output) => {
|
|
87
|
+
const row = tables[alias];
|
|
88
|
+
for (let key in row) {
|
|
89
|
+
if (key.startsWith('_')) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
output[key] ?? (output[key] = row[key]);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
getTypes(schema, into) {
|
|
96
|
+
var _a;
|
|
97
|
+
for (let column of schema.getColumns(alias)) {
|
|
98
|
+
into[_a = column.name] ?? (into[_a] = column);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (name == 'id' || name == '*') {
|
|
104
|
+
hasId = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!hasId) {
|
|
108
|
+
rows.errors.push(new SqlRuleError(`Query must return an "id" column`, sql, q.columns?.[0]._location));
|
|
109
|
+
}
|
|
110
|
+
rows.errors.push(...tools.errors);
|
|
111
|
+
return rows;
|
|
112
|
+
}
|
|
113
|
+
constructor() {
|
|
114
|
+
this.extractors = [];
|
|
115
|
+
this.errors = [];
|
|
116
|
+
}
|
|
117
|
+
applies(table) {
|
|
118
|
+
return this.sourceTable?.matches(table);
|
|
119
|
+
}
|
|
120
|
+
addSpecialParameters(table, row) {
|
|
121
|
+
if (this.sourceTable.isWildcard) {
|
|
122
|
+
return {
|
|
123
|
+
...row,
|
|
124
|
+
_table_suffix: this.sourceTable.suffix(table.table)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return row;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
getOutputName(sourceTable) {
|
|
132
|
+
if (this.isUnaliasedWildcard()) {
|
|
133
|
+
// Wildcard without alias - use source
|
|
134
|
+
return sourceTable;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return this.table;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
isUnaliasedWildcard() {
|
|
141
|
+
return this.sourceTable.isWildcard && this.table == this.sourceTable.tablePattern;
|
|
142
|
+
}
|
|
143
|
+
evaluateRow(table, row) {
|
|
144
|
+
try {
|
|
145
|
+
const tables = { [this.table]: this.addSpecialParameters(table, row) };
|
|
146
|
+
const bucketParameters = this.filter.filter(tables);
|
|
147
|
+
const bucketIds = bucketParameters.map((params) => getBucketId(this.descriptor_name, this.bucket_parameters, params));
|
|
148
|
+
const data = this.transformRow(tables);
|
|
149
|
+
let id = data.id;
|
|
150
|
+
if (typeof id != 'string') {
|
|
151
|
+
// While an explicit cast would be better, this covers against very common
|
|
152
|
+
// issues when initially testing out sync, for example when the id column is an
|
|
153
|
+
// auto-incrementing integer.
|
|
154
|
+
// If there is no id column, we use a blank id. This will result in the user syncing
|
|
155
|
+
// a single arbitrary row for this table - better than just not being able to sync
|
|
156
|
+
// anything.
|
|
157
|
+
id = castAsText(id) ?? '';
|
|
158
|
+
}
|
|
159
|
+
const outputTable = this.getOutputName(table.table);
|
|
160
|
+
return bucketIds.map((bucketId) => {
|
|
161
|
+
return {
|
|
162
|
+
bucket: bucketId,
|
|
163
|
+
table: outputTable,
|
|
164
|
+
id: id,
|
|
165
|
+
data,
|
|
166
|
+
ruleId: this.ruleId
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
return [{ error: e.message ?? `Evaluating data query failed` }];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
transformRow(tables) {
|
|
175
|
+
let result = {};
|
|
176
|
+
for (let extractor of this.extractors) {
|
|
177
|
+
extractor.extract(tables, result);
|
|
178
|
+
}
|
|
179
|
+
return filterJsonRow(result);
|
|
180
|
+
}
|
|
181
|
+
columnOutputNames() {
|
|
182
|
+
return this.columns.map((c) => {
|
|
183
|
+
return this.tools.getOutputName(c);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
getColumnOutputs(schema) {
|
|
187
|
+
let result = [];
|
|
188
|
+
if (this.isUnaliasedWildcard()) {
|
|
189
|
+
// Separate results
|
|
190
|
+
for (let schemaTable of schema.getTables(this.sourceTable)) {
|
|
191
|
+
let output = {};
|
|
192
|
+
this.getColumnOutputsFor(schemaTable, output);
|
|
193
|
+
result.push({
|
|
194
|
+
name: this.getOutputName(schemaTable.table),
|
|
195
|
+
columns: Object.values(output)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
// Merged results
|
|
201
|
+
let output = {};
|
|
202
|
+
for (let schemaTable of schema.getTables(this.sourceTable)) {
|
|
203
|
+
this.getColumnOutputsFor(schemaTable, output);
|
|
204
|
+
}
|
|
205
|
+
result.push({
|
|
206
|
+
name: this.table,
|
|
207
|
+
columns: Object.values(output)
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
getColumnOutputsFor(schemaTable, output) {
|
|
213
|
+
const querySchema = {
|
|
214
|
+
getType: (table, column) => {
|
|
215
|
+
if (table == this.table) {
|
|
216
|
+
return schemaTable.getType(column) ?? ExpressionType.NONE;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
// TODO: bucket parameters?
|
|
220
|
+
return ExpressionType.NONE;
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
getColumns: (table) => {
|
|
224
|
+
if (table == this.table) {
|
|
225
|
+
return schemaTable.getColumns();
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
for (let extractor of this.extractors) {
|
|
233
|
+
extractor.getTypes(querySchema, output);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=SqlDataQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlDataQuery.js","sourceRoot":"","sources":["../src/SqlDataQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,KAAK,EAAkB,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAoB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAA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AAM,EAAE,EAAE;gBACzB,IAAI,KAAK,IAAI,IAAI,CAAC,KAAM,EAAE;oBACxB,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC;iBAC3D;qBAAM;oBACL,2BAA2B;oBAC3B,OAAO,cAAc,CAAC,IAAI,CAAC;iBAC5B;YACH,CAAC;YACD,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE;gBACpB,IAAI,KAAK,IAAI,IAAI,CAAC,KAAM,EAAE;oBACxB,OAAO,WAAW,CAAC,UAAU,EAAE,CAAC;iBACjC;qBAAM;oBACL,OAAO,EAAE,CAAC;iBACX;YACH,CAAC;SACF,CAAC;QACF,KAAK,IAAI,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;YACrC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;SACzC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SelectedColumn } from 'pgsql-ast-parser';
|
|
2
|
+
import { EvaluatedParametersResult, ParameterMatchClause, QueryBucketIdOptions, SourceSchema, SqliteJsonRow, SqliteJsonValue, SqliteRow, StaticRowValueClause, SyncParameters } from './types.js';
|
|
3
|
+
import { SqlRuleError } from './errors.js';
|
|
4
|
+
import { SqlTools } from './sql_filters.js';
|
|
5
|
+
import { StaticSqlParameterQuery } from './StaticSqlParameterQuery.js';
|
|
6
|
+
import { TablePattern } from './TablePattern.js';
|
|
7
|
+
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
8
|
+
/**
|
|
9
|
+
* Represents a parameter query, such as:
|
|
10
|
+
*
|
|
11
|
+
* SELECT id as user_id FROM users WHERE users.user_id = token_parameters.user_id
|
|
12
|
+
* SELECT id as user_id, token_parameters.is_admin as is_admin FROM users WHERE users.user_id = token_parameters.user_id
|
|
13
|
+
*/
|
|
14
|
+
export declare class SqlParameterQuery {
|
|
15
|
+
static fromSql(descriptor_name: string, sql: string, schema?: SourceSchema): SqlParameterQuery | StaticSqlParameterQuery;
|
|
16
|
+
sourceTable?: TablePattern;
|
|
17
|
+
table?: string;
|
|
18
|
+
sql?: string;
|
|
19
|
+
columns?: SelectedColumn[];
|
|
20
|
+
lookup_columns?: SelectedColumn[];
|
|
21
|
+
static_columns?: SelectedColumn[];
|
|
22
|
+
lookup_extractors: Record<string, StaticRowValueClause>;
|
|
23
|
+
static_extractors: Record<string, StaticRowValueClause>;
|
|
24
|
+
filter?: ParameterMatchClause;
|
|
25
|
+
descriptor_name?: string;
|
|
26
|
+
/** _Input_ token / user parameters */
|
|
27
|
+
input_parameters?: string[];
|
|
28
|
+
expanded_input_parameter?: string;
|
|
29
|
+
/** _Output_ bucket parameters */
|
|
30
|
+
bucket_parameters?: string[];
|
|
31
|
+
id?: string;
|
|
32
|
+
tools?: SqlTools;
|
|
33
|
+
static_tools?: SqlTools;
|
|
34
|
+
errors: SqlRuleError[];
|
|
35
|
+
constructor();
|
|
36
|
+
applies(table: SourceTableInterface): boolean;
|
|
37
|
+
evaluateParameterRow(row: SqliteRow): EvaluatedParametersResult[];
|
|
38
|
+
transformRows(row: SqliteRow): SqliteRow[];
|
|
39
|
+
resolveBucketIds(bucketParameters: SqliteJsonRow[], parameters: SyncParameters): string[];
|
|
40
|
+
lookupParam(param: string, parameters: SyncParameters): string | number | bigint | null;
|
|
41
|
+
getLookups(parameters: SyncParameters): SqliteJsonValue[][];
|
|
42
|
+
queryBucketIds(options: QueryBucketIdOptions): Promise<string[]>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { parse } from 'pgsql-ast-parser';
|
|
2
|
+
import { SqlRuleError } from './errors.js';
|
|
3
|
+
import { SqlTools } from './sql_filters.js';
|
|
4
|
+
import { StaticSqlParameterQuery } from './StaticSqlParameterQuery.js';
|
|
5
|
+
import { filterJsonRow, getBucketId, isJsonValue, isSelectStatement } from './utils.js';
|
|
6
|
+
import { TablePattern } from './TablePattern.js';
|
|
7
|
+
import { checkUnsupportedFeatures, isClauseError } from './sql_support.js';
|
|
8
|
+
import { TableQuerySchema } from './TableQuerySchema.js';
|
|
9
|
+
/**
|
|
10
|
+
* Represents a parameter query, such as:
|
|
11
|
+
*
|
|
12
|
+
* SELECT id as user_id FROM users WHERE users.user_id = token_parameters.user_id
|
|
13
|
+
* SELECT id as user_id, token_parameters.is_admin as is_admin FROM users WHERE users.user_id = token_parameters.user_id
|
|
14
|
+
*/
|
|
15
|
+
export class SqlParameterQuery {
|
|
16
|
+
static fromSql(descriptor_name, sql, schema) {
|
|
17
|
+
const parsed = parse(sql, { locationTracking: true });
|
|
18
|
+
const rows = new SqlParameterQuery();
|
|
19
|
+
if (parsed.length > 1) {
|
|
20
|
+
throw new SqlRuleError('Only a single SELECT statement is supported', sql, parsed[1]?._location);
|
|
21
|
+
}
|
|
22
|
+
const q = parsed[0];
|
|
23
|
+
if (!isSelectStatement(q)) {
|
|
24
|
+
throw new SqlRuleError('Only SELECT statements are supported', sql, q._location);
|
|
25
|
+
}
|
|
26
|
+
if (q.from == null) {
|
|
27
|
+
// E.g. SELECT token_parameters.user_id as user_id WHERE token_parameters.is_admin
|
|
28
|
+
return StaticSqlParameterQuery.fromSql(descriptor_name, sql, q);
|
|
29
|
+
}
|
|
30
|
+
rows.errors.push(...checkUnsupportedFeatures(sql, q));
|
|
31
|
+
if (q.from.length != 1 || q.from[0].type != 'table') {
|
|
32
|
+
throw new SqlRuleError('Must SELECT from a single table', sql, q.from?.[0]._location);
|
|
33
|
+
}
|
|
34
|
+
const tableRef = q.from?.[0].name;
|
|
35
|
+
if (tableRef?.name == null) {
|
|
36
|
+
throw new SqlRuleError('Must SELECT from a single table', sql, q.from?.[0]._location);
|
|
37
|
+
}
|
|
38
|
+
const alias = q.from?.[0].name.alias ?? tableRef.name;
|
|
39
|
+
if (tableRef.name != alias) {
|
|
40
|
+
rows.errors.push(new SqlRuleError('Table aliases not supported in parameter queries', sql, q.from?.[0]._location));
|
|
41
|
+
}
|
|
42
|
+
const sourceTable = new TablePattern(tableRef.schema, tableRef.name);
|
|
43
|
+
let querySchema = undefined;
|
|
44
|
+
if (schema) {
|
|
45
|
+
const tables = schema.getTables(sourceTable);
|
|
46
|
+
if (tables.length == 0) {
|
|
47
|
+
const e = new SqlRuleError(`Table ${sourceTable.schema}.${sourceTable.tablePattern} not found`, sql, q.from?.[0]?._location);
|
|
48
|
+
e.type = 'warning';
|
|
49
|
+
rows.errors.push(e);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
querySchema = new TableQuerySchema(tables, alias);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const tools = new SqlTools({
|
|
56
|
+
table: alias,
|
|
57
|
+
parameter_tables: ['token_parameters', 'user_parameters'],
|
|
58
|
+
sql,
|
|
59
|
+
supports_expanding_parameters: true,
|
|
60
|
+
schema: querySchema
|
|
61
|
+
});
|
|
62
|
+
const where = q.where;
|
|
63
|
+
const filter = tools.compileWhereClause(where);
|
|
64
|
+
const bucket_parameters = (q.columns ?? []).map((column) => tools.getOutputName(column));
|
|
65
|
+
rows.sourceTable = sourceTable;
|
|
66
|
+
rows.table = alias;
|
|
67
|
+
rows.sql = sql;
|
|
68
|
+
rows.filter = filter;
|
|
69
|
+
rows.descriptor_name = descriptor_name;
|
|
70
|
+
rows.bucket_parameters = bucket_parameters;
|
|
71
|
+
rows.input_parameters = filter.bucketParameters;
|
|
72
|
+
const expandedParams = rows.input_parameters.filter((param) => param.endsWith('[*]'));
|
|
73
|
+
if (expandedParams.length > 1) {
|
|
74
|
+
rows.errors.push(new SqlRuleError('Cannot have multiple array input parameters', sql));
|
|
75
|
+
}
|
|
76
|
+
rows.expanded_input_parameter = expandedParams[0];
|
|
77
|
+
rows.columns = q.columns ?? [];
|
|
78
|
+
rows.static_columns = [];
|
|
79
|
+
rows.lookup_columns = [];
|
|
80
|
+
rows.static_tools = new SqlTools({
|
|
81
|
+
// This is used for values not on the parameter query table - these operate directly on
|
|
82
|
+
// token_parameters or user_parameters.
|
|
83
|
+
table: undefined,
|
|
84
|
+
value_tables: ['token_parameters', 'user_parameters'],
|
|
85
|
+
parameter_tables: [],
|
|
86
|
+
sql
|
|
87
|
+
});
|
|
88
|
+
for (let column of q.columns ?? []) {
|
|
89
|
+
const name = tools.getSpecificOutputName(column);
|
|
90
|
+
if (tools.isTableRef(column.expr)) {
|
|
91
|
+
rows.lookup_columns.push(column);
|
|
92
|
+
const extractor = tools.compileStaticExtractor(column.expr);
|
|
93
|
+
if (isClauseError(extractor)) {
|
|
94
|
+
// Error logged already
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
rows.lookup_extractors[name] = extractor;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
rows.static_columns.push(column);
|
|
101
|
+
const extractor = rows.static_tools.compileStaticExtractor(column.expr);
|
|
102
|
+
if (isClauseError(extractor)) {
|
|
103
|
+
// Error logged already
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
rows.static_extractors[name] = extractor;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
rows.tools = tools;
|
|
110
|
+
rows.errors.push(...tools.errors);
|
|
111
|
+
rows.errors.push(...rows.static_tools.errors);
|
|
112
|
+
return rows;
|
|
113
|
+
}
|
|
114
|
+
constructor() {
|
|
115
|
+
this.lookup_extractors = {};
|
|
116
|
+
this.static_extractors = {};
|
|
117
|
+
this.errors = [];
|
|
118
|
+
}
|
|
119
|
+
applies(table) {
|
|
120
|
+
return this.sourceTable.matches(table);
|
|
121
|
+
}
|
|
122
|
+
evaluateParameterRow(row) {
|
|
123
|
+
const tables = {
|
|
124
|
+
[this.table]: row
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
const filterParameters = this.filter.filter(tables);
|
|
128
|
+
let result = [];
|
|
129
|
+
for (let filterParamSet of filterParameters) {
|
|
130
|
+
let lookup = [this.descriptor_name, this.id];
|
|
131
|
+
lookup.push(...this.input_parameters.map((param) => {
|
|
132
|
+
return filterParamSet[param];
|
|
133
|
+
}));
|
|
134
|
+
const data = this.transformRows(row);
|
|
135
|
+
const role = {
|
|
136
|
+
bucket_parameters: data.map((row) => filterJsonRow(row)),
|
|
137
|
+
lookup: lookup
|
|
138
|
+
};
|
|
139
|
+
result.push(role);
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
return [{ error: e.message ?? `Evaluating parameter query failed` }];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
transformRows(row) {
|
|
148
|
+
const tables = { [this.table]: row };
|
|
149
|
+
let result = {};
|
|
150
|
+
for (let key in this.lookup_extractors) {
|
|
151
|
+
const extractor = this.lookup_extractors[key];
|
|
152
|
+
result[key] = extractor.evaluate(tables);
|
|
153
|
+
}
|
|
154
|
+
return [result];
|
|
155
|
+
}
|
|
156
|
+
resolveBucketIds(bucketParameters, parameters) {
|
|
157
|
+
const tables = { token_parameters: parameters.token_parameters, user_parameters: parameters.user_parameters };
|
|
158
|
+
// Filters have already been applied and gotten us the set of bucketParameters - don't attempt to filter again.
|
|
159
|
+
// We _do_ need to evaluate the output columns here, using a combination of precomputed bucketParameters,
|
|
160
|
+
// and values from token parameters.
|
|
161
|
+
return bucketParameters
|
|
162
|
+
.map((lookup) => {
|
|
163
|
+
let result = {};
|
|
164
|
+
for (let name of this.bucket_parameters) {
|
|
165
|
+
if (name in this.lookup_extractors) {
|
|
166
|
+
result[`bucket.${name}`] = lookup[name];
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
const value = this.static_extractors[name].evaluate(tables);
|
|
170
|
+
if (!isJsonValue(value)) {
|
|
171
|
+
// Not valid - exclude.
|
|
172
|
+
// Should we error instead?
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
result[`bucket.${name}`] = value;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return getBucketId(this.descriptor_name, this.bucket_parameters, result);
|
|
181
|
+
})
|
|
182
|
+
.filter((lookup) => lookup != null);
|
|
183
|
+
}
|
|
184
|
+
lookupParam(param, parameters) {
|
|
185
|
+
const [table, column] = param.split('.');
|
|
186
|
+
const pt = parameters[table];
|
|
187
|
+
return pt?.[column] ?? null;
|
|
188
|
+
}
|
|
189
|
+
getLookups(parameters) {
|
|
190
|
+
if (!this.expanded_input_parameter) {
|
|
191
|
+
let lookup = [this.descriptor_name, this.id];
|
|
192
|
+
lookup.push(...this.input_parameters.map((param) => {
|
|
193
|
+
// Scalar value
|
|
194
|
+
return this.lookupParam(param, parameters);
|
|
195
|
+
}));
|
|
196
|
+
return [lookup];
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
const arrayString = this.lookupParam(this.expanded_input_parameter.substring(0, this.expanded_input_parameter.length - 3), parameters);
|
|
200
|
+
if (arrayString == null || typeof arrayString != 'string') {
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
let values;
|
|
204
|
+
try {
|
|
205
|
+
values = JSON.parse(arrayString);
|
|
206
|
+
if (!Array.isArray(values)) {
|
|
207
|
+
return [];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
return values.map((expandedValue) => {
|
|
214
|
+
let lookup = [this.descriptor_name, this.id];
|
|
215
|
+
lookup.push(...this.input_parameters.map((param) => {
|
|
216
|
+
if (param == this.expanded_input_parameter) {
|
|
217
|
+
// Expand array value
|
|
218
|
+
return expandedValue;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// Scalar value
|
|
222
|
+
return this.lookupParam(param, parameters);
|
|
223
|
+
}
|
|
224
|
+
}));
|
|
225
|
+
return lookup;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async queryBucketIds(options) {
|
|
230
|
+
let lookups = this.getLookups(options.parameters);
|
|
231
|
+
if (lookups.length == 0) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
const parameters = await options.getParameterSets(lookups);
|
|
235
|
+
return this.resolveBucketIds(parameters, options.parameters);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=SqlParameterQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlParameterQuery.js","sourceRoot":"","sources":["../src/SqlParameterQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,kBAAkB,CAAC;AAczD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CACZ,eAAuB,EACvB,GAAW,EACX,MAAqB;QAErB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,MAAM,IAAI,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAErC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACrB,MAAM,IAAI,YAAY,CAAC,6CAA6C,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;SAClG;QACD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAEpB,IAAI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;wBACL,eAAe;wBACf,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;qBAC5C;gBACH,CAAC,CAAC,CACH,CAAC;gBAEF,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA6B;QAChD,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE;YACvB,OAAO,EAAE,CAAC;SACX;QAED,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/D,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Scalar } from 'yaml';
|
|
2
|
+
import { YamlError } from './errors.js';
|
|
3
|
+
import { IdSequence } from './IdSequence.js';
|
|
4
|
+
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
5
|
+
import { QueryParseResult, SqlBucketDescriptor } from './SqlBucketDescriptor.js';
|
|
6
|
+
import { TablePattern } from './TablePattern.js';
|
|
7
|
+
import { EvaluatedParameters, EvaluatedRow, EvaluateRowOptions, EvaluationError, QueryBucketIdOptions, SourceSchema, SqliteRow, SyncParameters, SyncRules } from './types.js';
|
|
8
|
+
export declare class SqlSyncRules implements SyncRules {
|
|
9
|
+
bucket_descriptors: SqlBucketDescriptor[];
|
|
10
|
+
idSequence: IdSequence;
|
|
11
|
+
content: string;
|
|
12
|
+
errors: YamlError[];
|
|
13
|
+
static validate(yaml: string, options?: {
|
|
14
|
+
schema?: SourceSchema;
|
|
15
|
+
}): YamlError[];
|
|
16
|
+
static fromYaml(yaml: string, options?: {
|
|
17
|
+
throwOnError?: boolean;
|
|
18
|
+
schema?: SourceSchema;
|
|
19
|
+
}): SqlSyncRules;
|
|
20
|
+
throwOnError(): void;
|
|
21
|
+
static tokenError(token: any, message: string): YamlError;
|
|
22
|
+
withScalar(scalar: Scalar, cb: (value: string) => QueryParseResult): QueryParseResult;
|
|
23
|
+
constructor(content: string);
|
|
24
|
+
/**
|
|
25
|
+
* Throws errors.
|
|
26
|
+
*/
|
|
27
|
+
evaluateRow(options: EvaluateRowOptions): EvaluatedRow[];
|
|
28
|
+
evaluateRowWithErrors(options: EvaluateRowOptions): {
|
|
29
|
+
results: EvaluatedRow[];
|
|
30
|
+
errors: EvaluationError[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Throws errors.
|
|
34
|
+
*/
|
|
35
|
+
evaluateParameterRow(table: SourceTableInterface, row: SqliteRow): EvaluatedParameters[];
|
|
36
|
+
evaluateParameterRowWithErrors(table: SourceTableInterface, row: SqliteRow): {
|
|
37
|
+
results: EvaluatedParameters[];
|
|
38
|
+
errors: EvaluationError[];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated For testing only.
|
|
42
|
+
*/
|
|
43
|
+
getStaticBucketIds(parameters: SyncParameters): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Note: This can error hard.
|
|
46
|
+
*/
|
|
47
|
+
queryBucketIds(options: QueryBucketIdOptions): Promise<string[]>;
|
|
48
|
+
getSourceTables(): TablePattern[];
|
|
49
|
+
tableSyncsData(table: SourceTableInterface): boolean;
|
|
50
|
+
tableSyncsParameters(table: SourceTableInterface): boolean;
|
|
51
|
+
debugGetOutputTables(): Record<string, any[]>;
|
|
52
|
+
}
|