@powersync/service-sync-rules 0.29.10 → 0.31.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/BaseSqlDataQuery.d.ts +3 -9
- package/dist/BaseSqlDataQuery.js +11 -21
- package/dist/BaseSqlDataQuery.js.map +1 -1
- package/dist/BucketParameterQuerier.d.ts +42 -9
- package/dist/BucketParameterQuerier.js +30 -7
- package/dist/BucketParameterQuerier.js.map +1 -1
- package/dist/BucketSource.d.ts +94 -25
- package/dist/BucketSource.js +67 -0
- package/dist/BucketSource.js.map +1 -1
- package/dist/ExpressionType.d.ts +4 -2
- package/dist/ExpressionType.js.map +1 -1
- package/dist/HydratedSyncRules.d.ts +46 -0
- package/dist/HydratedSyncRules.js +88 -0
- package/dist/HydratedSyncRules.js.map +1 -0
- package/dist/HydrationState.d.ts +45 -0
- package/dist/HydrationState.js +41 -0
- package/dist/HydrationState.js.map +1 -0
- package/dist/SqlBucketDescriptor.d.ts +31 -28
- package/dist/SqlBucketDescriptor.js +89 -112
- package/dist/SqlBucketDescriptor.js.map +1 -1
- package/dist/SqlDataQuery.d.ts +4 -4
- package/dist/SqlDataQuery.js +5 -6
- package/dist/SqlDataQuery.js.map +1 -1
- package/dist/SqlParameterQuery.d.ts +17 -9
- package/dist/SqlParameterQuery.js +49 -23
- package/dist/SqlParameterQuery.js.map +1 -1
- package/dist/SqlSyncRules.d.ts +11 -53
- package/dist/SqlSyncRules.js +11 -376
- package/dist/SqlSyncRules.js.map +1 -1
- package/dist/StaticSqlParameterQuery.d.ts +13 -3
- package/dist/StaticSqlParameterQuery.js +38 -4
- package/dist/StaticSqlParameterQuery.js.map +1 -1
- package/dist/SyncConfig.d.ts +43 -0
- package/dist/SyncConfig.js +102 -0
- package/dist/SyncConfig.js.map +1 -0
- package/dist/TablePattern.d.ts +22 -4
- package/dist/TablePattern.js +57 -19
- package/dist/TablePattern.js.map +1 -1
- package/dist/TableValuedFunctionSqlParameterQuery.d.ts +14 -4
- package/dist/TableValuedFunctionSqlParameterQuery.js +41 -7
- package/dist/TableValuedFunctionSqlParameterQuery.js.map +1 -1
- package/dist/compatibility.d.ts +7 -0
- package/dist/compatibility.js +34 -0
- package/dist/compatibility.js.map +1 -1
- package/dist/compiler/bucket_resolver.d.ts +70 -0
- package/dist/compiler/bucket_resolver.js +131 -0
- package/dist/compiler/bucket_resolver.js.map +1 -0
- package/dist/compiler/compatibility.d.ts +16 -0
- package/dist/compiler/compatibility.js +12 -0
- package/dist/compiler/compatibility.js.map +1 -0
- package/dist/compiler/compiler.d.ts +110 -0
- package/dist/compiler/compiler.js +130 -0
- package/dist/compiler/compiler.js.map +1 -0
- package/dist/compiler/equality.d.ts +99 -0
- package/dist/compiler/equality.js +284 -0
- package/dist/compiler/equality.js.map +1 -0
- package/dist/compiler/expression.d.ts +77 -0
- package/dist/compiler/expression.js +122 -0
- package/dist/compiler/expression.js.map +1 -0
- package/dist/compiler/filter.d.ts +71 -0
- package/dist/compiler/filter.js +110 -0
- package/dist/compiler/filter.js.map +1 -0
- package/dist/compiler/filter_simplifier.d.ts +26 -0
- package/dist/compiler/filter_simplifier.js +119 -0
- package/dist/compiler/filter_simplifier.js.map +1 -0
- package/dist/compiler/ir_to_sync_plan.d.ts +37 -0
- package/dist/compiler/ir_to_sync_plan.js +163 -0
- package/dist/compiler/ir_to_sync_plan.js.map +1 -0
- package/dist/compiler/parser.d.ts +99 -0
- package/dist/compiler/parser.js +556 -0
- package/dist/compiler/parser.js.map +1 -0
- package/dist/compiler/querier_graph.d.ts +42 -0
- package/dist/compiler/querier_graph.js +365 -0
- package/dist/compiler/querier_graph.js.map +1 -0
- package/dist/compiler/rows.d.ts +113 -0
- package/dist/compiler/rows.js +156 -0
- package/dist/compiler/rows.js.map +1 -0
- package/dist/compiler/scope.d.ts +22 -0
- package/dist/compiler/scope.js +47 -0
- package/dist/compiler/scope.js.map +1 -0
- package/dist/compiler/sqlite.d.ts +77 -0
- package/dist/compiler/sqlite.js +412 -0
- package/dist/compiler/sqlite.js.map +1 -0
- package/dist/compiler/table.d.ts +66 -0
- package/dist/compiler/table.js +67 -0
- package/dist/compiler/table.js.map +1 -0
- package/dist/errors.d.ts +4 -2
- package/dist/errors.js +16 -1
- package/dist/errors.js.map +1 -1
- package/dist/events/SqlEventDescriptor.js +1 -1
- package/dist/events/SqlEventDescriptor.js.map +1 -1
- package/dist/events/SqlEventSourceQuery.d.ts +1 -1
- package/dist/events/SqlEventSourceQuery.js +1 -2
- package/dist/events/SqlEventSourceQuery.js.map +1 -1
- package/dist/from_yaml.d.ts +28 -0
- package/dist/from_yaml.js +411 -0
- package/dist/from_yaml.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/json_schema.js +17 -1
- package/dist/json_schema.js.map +1 -1
- package/dist/request_functions.js.map +1 -1
- package/dist/schema-generators/DartSchemaGenerator.d.ts +3 -3
- package/dist/schema-generators/DartSchemaGenerator.js.map +1 -1
- package/dist/schema-generators/DotNetSchemaGenerator.d.ts +2 -2
- package/dist/schema-generators/DotNetSchemaGenerator.js.map +1 -1
- package/dist/schema-generators/JsLegacySchemaGenerator.d.ts +2 -2
- package/dist/schema-generators/JsLegacySchemaGenerator.js.map +1 -1
- package/dist/schema-generators/KotlinSchemaGenerator.d.ts +2 -2
- package/dist/schema-generators/KotlinSchemaGenerator.js.map +1 -1
- package/dist/schema-generators/RoomSchemaGenerator.d.ts +2 -2
- package/dist/schema-generators/RoomSchemaGenerator.js.map +1 -1
- package/dist/schema-generators/SchemaGenerator.d.ts +8 -3
- package/dist/schema-generators/SchemaGenerator.js +21 -14
- package/dist/schema-generators/SchemaGenerator.js.map +1 -1
- package/dist/schema-generators/SqlSchemaGenerator.d.ts +2 -2
- package/dist/schema-generators/SqlSchemaGenerator.js.map +1 -1
- package/dist/schema-generators/SwiftSchemaGenerator.d.ts +2 -2
- package/dist/schema-generators/SwiftSchemaGenerator.js.map +1 -1
- package/dist/schema-generators/TsSchemaGenerator.d.ts +2 -2
- package/dist/schema-generators/TsSchemaGenerator.js.map +1 -1
- package/dist/sql_functions.d.ts +4 -3
- package/dist/sql_functions.js +1 -1
- package/dist/sql_functions.js.map +1 -1
- package/dist/streams/filter.d.ts +34 -4
- package/dist/streams/filter.js +93 -23
- package/dist/streams/filter.js.map +1 -1
- package/dist/streams/from_sql.js +2 -5
- package/dist/streams/from_sql.js.map +1 -1
- package/dist/streams/parameter.d.ts +7 -6
- package/dist/streams/stream.d.ts +25 -15
- package/dist/streams/stream.js +59 -87
- package/dist/streams/stream.js.map +1 -1
- package/dist/streams/variant.d.ts +14 -21
- package/dist/streams/variant.js +68 -46
- package/dist/streams/variant.js.map +1 -1
- package/dist/sync_plan/engine/javascript.d.ts +6 -0
- package/dist/sync_plan/engine/javascript.js +208 -0
- package/dist/sync_plan/engine/javascript.js.map +1 -0
- package/dist/sync_plan/engine/scalar_expression_engine.d.ts +48 -0
- package/dist/sync_plan/engine/scalar_expression_engine.js +99 -0
- package/dist/sync_plan/engine/scalar_expression_engine.js.map +1 -0
- package/dist/sync_plan/engine/sqlite.d.ts +12 -0
- package/dist/sync_plan/engine/sqlite.js +53 -0
- package/dist/sync_plan/engine/sqlite.js.map +1 -0
- package/dist/sync_plan/evaluator/bucket_data_source.d.ts +24 -0
- package/dist/sync_plan/evaluator/bucket_data_source.js +139 -0
- package/dist/sync_plan/evaluator/bucket_data_source.js.map +1 -0
- package/dist/sync_plan/evaluator/bucket_source.d.ts +19 -0
- package/dist/sync_plan/evaluator/bucket_source.js +145 -0
- package/dist/sync_plan/evaluator/bucket_source.js.map +1 -0
- package/dist/sync_plan/evaluator/index.d.ts +17 -0
- package/dist/sync_plan/evaluator/index.js +32 -0
- package/dist/sync_plan/evaluator/index.js.map +1 -0
- package/dist/sync_plan/evaluator/parameter_evaluator.d.ts +138 -0
- package/dist/sync_plan/evaluator/parameter_evaluator.js +359 -0
- package/dist/sync_plan/evaluator/parameter_evaluator.js.map +1 -0
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.d.ts +20 -0
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.js +64 -0
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.js.map +1 -0
- package/dist/sync_plan/expression.d.ts +109 -0
- package/dist/sync_plan/expression.js +85 -0
- package/dist/sync_plan/expression.js.map +1 -0
- package/dist/sync_plan/expression_to_sql.d.ts +43 -0
- package/dist/sync_plan/expression_to_sql.js +190 -0
- package/dist/sync_plan/expression_to_sql.js.map +1 -0
- package/dist/sync_plan/expression_visitor.d.ts +57 -0
- package/dist/sync_plan/expression_visitor.js +181 -0
- package/dist/sync_plan/expression_visitor.js.map +1 -0
- package/dist/sync_plan/plan.d.ts +196 -0
- package/dist/sync_plan/plan.js +2 -0
- package/dist/sync_plan/plan.js.map +1 -0
- package/dist/sync_plan/schema_inference.d.ts +16 -0
- package/dist/sync_plan/schema_inference.js +123 -0
- package/dist/sync_plan/schema_inference.js.map +1 -0
- package/dist/sync_plan/serialize.d.ts +82 -0
- package/dist/sync_plan/serialize.js +214 -0
- package/dist/sync_plan/serialize.js.map +1 -0
- package/dist/types/custom_sqlite_value.d.ts +1 -1
- package/dist/types.d.ts +72 -29
- package/dist/types.js +30 -5
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +10 -3
- package/dist/utils.js +26 -3
- package/dist/utils.js.map +1 -1
- package/package.json +4 -3
- package/schema/sync_rules.json +19 -3
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { ScopedParameterLookup, UnscopedParameterLookup } from '../../BucketParameterQuerier.js';
|
|
2
|
+
import { cartesianProduct } from '../../streams/utils.js';
|
|
3
|
+
import { isValidParameterValue } from '../../utils.js';
|
|
4
|
+
import { MapSourceVisitor, visitExpr } from '../expression_visitor.js';
|
|
5
|
+
import { mapExternalDataToInstantiation } from '../engine/scalar_expression_engine.js';
|
|
6
|
+
/**
|
|
7
|
+
* Finds bucket parameters for a given request or subscription.
|
|
8
|
+
*
|
|
9
|
+
* In sync streams, queriers are represented as a DAG structure describing how to get from connection data to bucket
|
|
10
|
+
* parameters.
|
|
11
|
+
*
|
|
12
|
+
* As an example, consider the following stream:
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* SELECT projects.* FROM projects
|
|
16
|
+
* INNER JOIN orgs ON orgs.id = projects.org_id
|
|
17
|
+
* WHERE orgs.name = auth.parameter('org')
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* This would partition data into a bucket with a single parameter (grouping by `projects.org_id`). It would also
|
|
21
|
+
* prepare a lookup from `orgs.name` to `orgs.id`.
|
|
22
|
+
*
|
|
23
|
+
* The querier for this would have:
|
|
24
|
+
*
|
|
25
|
+
* 1. A single lookup stage with a single {@link plan.ParameterLookup}. That lookup would have an instantiation
|
|
26
|
+
* reflecting `auth.parameter('org')` as a `request` {@link plan.ParameterValue}.
|
|
27
|
+
* 2. A single {@link plan.StreamQuerier.sourceInstantiation}, a `lookup` {@link plan.ParameterValue} referencing the
|
|
28
|
+
* lookup from step 1.
|
|
29
|
+
*
|
|
30
|
+
* On this prepared evaluator, lookup stages and parameter values are tracked as {@link PreparedExpandingLookup}s and
|
|
31
|
+
* {@link PreparedParameterValue}s, respectively. These correspond to their definitions on sync plans, except that:
|
|
32
|
+
*
|
|
33
|
+
* 1. Instead of being a description of the parameter, they're a JavaScript function that can be invoked to compute
|
|
34
|
+
* parameters.
|
|
35
|
+
* 2. After being called once, we can replace them with a cached value. This enables a partial instantiation, and
|
|
36
|
+
* avoids recomputing everything whenever a parameter lookup changes. In the example stream, we would run and cache
|
|
37
|
+
* the outputs of `auth.parameter('org')` for a given connection. This sub-expression would not get re-evaluated
|
|
38
|
+
* when the `org-name` -> `org.id` lookup changes.
|
|
39
|
+
*
|
|
40
|
+
* For queriers that don't use parameter lookups, e.g. for streams like `SELECT * FROM users WHERE id = auth.user_id()`,
|
|
41
|
+
* the partial instantiation based on connection data happens to be a complete instantiation. We use this when building
|
|
42
|
+
* queriers by indicating that no lookups will be used.
|
|
43
|
+
*/
|
|
44
|
+
export class RequestParameterEvaluators {
|
|
45
|
+
lookupStages;
|
|
46
|
+
parameterValues;
|
|
47
|
+
constructor(
|
|
48
|
+
/**
|
|
49
|
+
* Pending lookup stages, or their cached outputs.
|
|
50
|
+
*/
|
|
51
|
+
lookupStages,
|
|
52
|
+
/**
|
|
53
|
+
* Pending parameter values, or their cached outputs.
|
|
54
|
+
*/
|
|
55
|
+
parameterValues) {
|
|
56
|
+
this.lookupStages = lookupStages;
|
|
57
|
+
this.parameterValues = parameterValues;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns a copy of this instance.
|
|
61
|
+
*
|
|
62
|
+
* Since resolved values are replaced with their instantiation, we need to use closed evaluators before evaluating
|
|
63
|
+
* them on inputs that might change (like parameter lookups).
|
|
64
|
+
*
|
|
65
|
+
* Static data (like connection parameters) can be resolved sooner, and cloning that partially-instantiated evaluator
|
|
66
|
+
* graph essentially forks it. This allows us to cache connection parameters for the lifetime of the connection
|
|
67
|
+
* instead of re-evaluating them on every parameter lookup change.
|
|
68
|
+
*/
|
|
69
|
+
clone() {
|
|
70
|
+
return new RequestParameterEvaluators(this.lookupStages.map((stage) => [...stage]), [...this.parameterValues]);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Evaluates those lookups and parameter values that be evaluated without looking up parameter indexes.
|
|
74
|
+
*
|
|
75
|
+
* This is also used to determine whether a querier is static - if the partial instantiation depending on request data
|
|
76
|
+
* fully resolves the stream, we don't need to lookup any parameters.
|
|
77
|
+
*/
|
|
78
|
+
partiallyInstantiate(input) {
|
|
79
|
+
const helper = new PartialInstantiator(input, this);
|
|
80
|
+
this.lookupStages.forEach((stage, stageIndex) => {
|
|
81
|
+
stage.forEach((_, indexInStage) => helper.expandingLookupSync(stageIndex, indexInStage));
|
|
82
|
+
});
|
|
83
|
+
this.parameterValues.forEach((_, i) => helper.parameterSync(this.parameterValues, i));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolves and caches all lookup stages and parameter values.
|
|
87
|
+
*
|
|
88
|
+
* Because this needs to lookup parameter indexes, it is asynchronous.
|
|
89
|
+
*/
|
|
90
|
+
async instantiate(input) {
|
|
91
|
+
const helper = new FullInstantiator(input, this);
|
|
92
|
+
for (let i = 0; i < this.lookupStages.length; i++) {
|
|
93
|
+
// Within a stage, we can resolve lookups concurrently.
|
|
94
|
+
await Promise.all(this.lookupStages[i].map((_, j) => helper.expandingLookup(i, j)));
|
|
95
|
+
}
|
|
96
|
+
// At this point, all lookups have been resolved and we can synchronously evaluate parameters which might depend on
|
|
97
|
+
// those lookups.
|
|
98
|
+
return helper.resolveInputs(this.parameterValues);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Whether these evaluators are known to not result in any buckets, for instance because parameters are instanted to
|
|
102
|
+
* `NULL` values that aren't equal to anything.
|
|
103
|
+
*
|
|
104
|
+
* This is fairly efficient to compute and can be used to short-circuit further evaluation.
|
|
105
|
+
*/
|
|
106
|
+
isDefinitelyUninstantiable() {
|
|
107
|
+
for (const parameter of this.parameterValues) {
|
|
108
|
+
if (parameter.type != 'cached') {
|
|
109
|
+
return false; // Unknown
|
|
110
|
+
}
|
|
111
|
+
if (parameter.values.length === 0) {
|
|
112
|
+
// Missing parameter.
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
extractFullInstantiation() {
|
|
119
|
+
// All lookup stages need to be resolved, even if they're not used in a parameter. The reason is that queries like
|
|
120
|
+
// `WHERE 'static_value' IN (SELECT name FROM users WHERE id = auth.user_id())` are implemented as lookup stages,
|
|
121
|
+
// so we can't ignore them.
|
|
122
|
+
for (const stage of this.lookupStages) {
|
|
123
|
+
for (const element of stage) {
|
|
124
|
+
if (element.type !== 'cached') {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Outer array represents parameters, inner array represents values for a given parameter.
|
|
130
|
+
const parameters = [];
|
|
131
|
+
for (const parameter of this.parameterValues) {
|
|
132
|
+
if (parameter.type !== 'cached') {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
parameters.push(parameter.values);
|
|
136
|
+
}
|
|
137
|
+
// Transform to array of complete instantiations.
|
|
138
|
+
return [...cartesianProduct(...parameters)];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Prepares evaluators for a description of parameter values obtained from a compiled querier in the sync plan.
|
|
142
|
+
*
|
|
143
|
+
* @param lookupStages The {@link plan.StreamQuerier.lookupStages} of the querier to compile.
|
|
144
|
+
* @param values The {@link plan.StreamQuerier.sourceInstantiation} of the querier to compile.
|
|
145
|
+
* @param input Access to bucket and parameter sources generated for buckets and parameter lookups referenced by the
|
|
146
|
+
* querier.
|
|
147
|
+
*/
|
|
148
|
+
static prepare(lookupStages, values, input) {
|
|
149
|
+
const mappedStages = [];
|
|
150
|
+
const lookupToStage = new Map();
|
|
151
|
+
function mapParameterValue(value) {
|
|
152
|
+
if (value.type == 'request') {
|
|
153
|
+
// Prepare an expression evaluating the expression derived from request data.
|
|
154
|
+
const mapper = mapExternalDataToInstantiation();
|
|
155
|
+
const prepared = input.engine.prepareEvaluator({ filters: [], outputs: [mapper.transform(value.expr)] });
|
|
156
|
+
const instantiation = mapper.instantiation;
|
|
157
|
+
return {
|
|
158
|
+
type: 'request',
|
|
159
|
+
read(request) {
|
|
160
|
+
return prepared.evaluate(parametersForRequest(request, instantiation))[0][0];
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else if (value.type == 'lookup') {
|
|
165
|
+
const stagePosition = lookupToStage.get(value.lookup);
|
|
166
|
+
return { type: 'lookup', lookup: stagePosition, resultIndex: value.resultIndex };
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return { type: 'intersection', values: mapParameterValues(value.values) };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function mapParameterValues(values) {
|
|
173
|
+
return values.map(mapParameterValue);
|
|
174
|
+
}
|
|
175
|
+
for (const stage of lookupStages) {
|
|
176
|
+
const stageIndex = mappedStages.length;
|
|
177
|
+
const mappedStage = [];
|
|
178
|
+
mappedStages.push(mappedStage);
|
|
179
|
+
for (const lookup of stage) {
|
|
180
|
+
const index = mappedStage.length;
|
|
181
|
+
lookupToStage.set(lookup, { stage: stageIndex, index });
|
|
182
|
+
if (lookup.type == 'parameter') {
|
|
183
|
+
mappedStage.push({
|
|
184
|
+
type: 'parameter',
|
|
185
|
+
lookup: input.preparedLookups.get(lookup.lookup),
|
|
186
|
+
instantiation: mapParameterValues(lookup.instantiation)
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
// Create an expression like SELECT <output> FROM table_valued(<functionInputs>) WHERE <filters>
|
|
191
|
+
const mapInputs = mapExternalDataToInstantiation();
|
|
192
|
+
const fn = {
|
|
193
|
+
name: lookup.functionName,
|
|
194
|
+
inputs: lookup.functionInputs.map((e) => mapInputs.transform(e))
|
|
195
|
+
};
|
|
196
|
+
const mapOutputs = new MapSourceVisitor(({ column }) => ({
|
|
197
|
+
function: fn,
|
|
198
|
+
column
|
|
199
|
+
}));
|
|
200
|
+
const prepared = input.engine.prepareEvaluator({
|
|
201
|
+
tableValuedFunctions: [fn],
|
|
202
|
+
outputs: lookup.outputs.map((e) => visitExpr(mapOutputs, e, null)),
|
|
203
|
+
filters: lookup.filters.map((e) => visitExpr(mapOutputs, e, null))
|
|
204
|
+
});
|
|
205
|
+
mappedStage.push({
|
|
206
|
+
type: 'table_valued',
|
|
207
|
+
read(request) {
|
|
208
|
+
return [
|
|
209
|
+
...filterParameterRows(prepared.evaluate(parametersForRequest(request, mapInputs.instantiation)))
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return new RequestParameterEvaluators(mappedStages, mapParameterValues(values));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
class PartialInstantiator {
|
|
220
|
+
input;
|
|
221
|
+
evaluators;
|
|
222
|
+
constructor(input, evaluators) {
|
|
223
|
+
this.input = input;
|
|
224
|
+
this.evaluators = evaluators;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* If possible, evaluates an element in an array of parameter values and replaces the parameter with a marker
|
|
228
|
+
* indicating it as cached.
|
|
229
|
+
*/
|
|
230
|
+
parameterSync(parent, index) {
|
|
231
|
+
const current = parent[index];
|
|
232
|
+
if (current.type === 'cached') {
|
|
233
|
+
return current.values;
|
|
234
|
+
}
|
|
235
|
+
else if (current.type === 'intersection') {
|
|
236
|
+
let intersection = null;
|
|
237
|
+
for (let i = 0; i < current.values.length; i++) {
|
|
238
|
+
const evaluated = this.parameterSync(current.values, i);
|
|
239
|
+
if (evaluated == null) {
|
|
240
|
+
return undefined; // Can't evaluate sub-parameter
|
|
241
|
+
}
|
|
242
|
+
if (intersection == null) {
|
|
243
|
+
intersection = new Set(evaluated);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
// TODO: Remove as any once we can use ES2025 in TypeScript
|
|
247
|
+
intersection = intersection.intersection(new Set(evaluated));
|
|
248
|
+
}
|
|
249
|
+
if (intersection.size == 0) {
|
|
250
|
+
// Empty intersection, we don't even need to evaluate the rest.
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
let values = [];
|
|
255
|
+
if (intersection) {
|
|
256
|
+
values.push(...intersection.keys());
|
|
257
|
+
}
|
|
258
|
+
parent[index] = { type: 'cached', values };
|
|
259
|
+
return values;
|
|
260
|
+
}
|
|
261
|
+
else if (current.type === 'lookup') {
|
|
262
|
+
const resolvedLookup = this.expandingLookupSync(current.lookup.stage, current.lookup.index);
|
|
263
|
+
if (resolvedLookup) {
|
|
264
|
+
const values = resolvedLookup.map((row) => row[current.resultIndex]);
|
|
265
|
+
parent[index] = { type: 'cached', values };
|
|
266
|
+
return values;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else if (current.type === 'request') {
|
|
270
|
+
const value = current.read(this.input.request);
|
|
271
|
+
const values = isValidParameterValue(value) ? [value] : [];
|
|
272
|
+
parent[index] = { type: 'cached', values };
|
|
273
|
+
return values;
|
|
274
|
+
}
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
expandingLookupSync(stage, index) {
|
|
278
|
+
const lookup = this.evaluators.lookupStages[stage][index];
|
|
279
|
+
if (lookup.type == 'table_valued') {
|
|
280
|
+
// We can evaluate this table-valued function already.
|
|
281
|
+
const values = lookup.read(this.input.request);
|
|
282
|
+
this.evaluators.lookupStages[stage][index] = { type: 'cached', values };
|
|
283
|
+
return values;
|
|
284
|
+
}
|
|
285
|
+
else if (lookup.type == 'cached') {
|
|
286
|
+
return lookup.values;
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
class FullInstantiator extends PartialInstantiator {
|
|
292
|
+
*resolveInputs(params) {
|
|
293
|
+
const parameterValues = params.map((_, index) => {
|
|
294
|
+
const cached = this.parameterSync(params, index);
|
|
295
|
+
if (cached == null) {
|
|
296
|
+
// This method is only called for inputs from an earlier stage, which should have been resolved at this point.
|
|
297
|
+
throw new Error('Should have been able to resolve parameter from earlier stage synchronously.');
|
|
298
|
+
}
|
|
299
|
+
return cached;
|
|
300
|
+
});
|
|
301
|
+
yield* cartesianProduct(...parameterValues);
|
|
302
|
+
}
|
|
303
|
+
async expandingLookup(stage, index) {
|
|
304
|
+
const lookup = this.evaluators.lookupStages[stage][index];
|
|
305
|
+
if (lookup.type == 'parameter') {
|
|
306
|
+
const scope = this.input.hydrationState.getParameterIndexLookupScope(lookup.lookup);
|
|
307
|
+
const outputs = await this.input.source.getParameterSets([...this.resolveInputs(lookup.instantiation)].map((instantiation) => ScopedParameterLookup.normalized(scope, UnscopedParameterLookup.normalized(instantiation))));
|
|
308
|
+
// Stream parameters generate an output row like {0: <expr>, 1: <expr>, ...}.
|
|
309
|
+
const values = outputs.map((row) => {
|
|
310
|
+
const length = Object.entries(row).length;
|
|
311
|
+
const asArray = [];
|
|
312
|
+
for (let i = 0; i < length; i++) {
|
|
313
|
+
asArray.push(row[i.toString()]);
|
|
314
|
+
}
|
|
315
|
+
return asArray;
|
|
316
|
+
});
|
|
317
|
+
this.evaluators.lookupStages[stage][index] = { type: 'cached', values };
|
|
318
|
+
return values;
|
|
319
|
+
}
|
|
320
|
+
const other = this.expandingLookupSync(stage, index);
|
|
321
|
+
if (other == null) {
|
|
322
|
+
throw new Error('internal error: Unable to resolve non-parameter lookup synchronously?');
|
|
323
|
+
}
|
|
324
|
+
return other;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
export function isValidParameterValueRow(row) {
|
|
328
|
+
for (const value of row) {
|
|
329
|
+
if (!isValidParameterValue(value)) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
export function parametersForRequest(parameters, values) {
|
|
336
|
+
return values.map((v) => {
|
|
337
|
+
if ('request' in v) {
|
|
338
|
+
switch (v.request) {
|
|
339
|
+
case 'auth':
|
|
340
|
+
return parameters.rawTokenPayload;
|
|
341
|
+
case 'subscription':
|
|
342
|
+
return parameters.rawStreamParameters;
|
|
343
|
+
case 'connection':
|
|
344
|
+
return parameters.rawUserParameters;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
throw new Error('Illegal column reference in request filter');
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
function* filterParameterRows(rows) {
|
|
353
|
+
for (const row of rows) {
|
|
354
|
+
if (isValidParameterValueRow(row)) {
|
|
355
|
+
yield row;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
//# sourceMappingURL=parameter_evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter_evaluator.js","sourceRoot":"","sources":["../../../src/sync_plan/evaluator/parameter_evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAGxH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGvE,OAAO,EACL,8BAA8B,EAG/B,MAAM,uCAAuC,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,0BAA0B;IAK1B;IAIA;IARX;IACE;;OAEG;IACM,YAAyC;IAClD;;OAEG;IACM,eAAyC;QAJzC,iBAAY,GAAZ,YAAY,CAA6B;QAIzC,oBAAe,GAAf,eAAe,CAA0B;IACjD,CAAC;IAEJ;;;;;;;;;OASG;IACH,KAAK;QACH,OAAO,IAAI,0BAA0B,CACnC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAC5C,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAAC,KAAgC;QACnD,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEpD,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YAC9C,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,YAAY,CA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AAqB,CAAC,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAA6B,EAAE,MAAgC;IAClG,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACtB,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;YACnB,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;gBAClB,KAAK,MAAM;oBACT,OAAO,UAAU,CAAC,eAAe,CAAC;gBACpC,KAAK,cAAc;oBACjB,OAAO,UAAU,CAAC,mBAAoB,CAAC;gBACzC,KAAK,YAAY;oBACf,OAAO,UAAU,CAAC,iBAAiB,CAAC;YACxC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,QAAQ,CAAC,CAAC,mBAAmB,CAAC,IAAqB;IACjD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,wBAAwB,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ParameterIndexLookupCreator } from '../../BucketSource.js';
|
|
2
|
+
import { ParameterLookupScope } from '../../HydrationState.js';
|
|
3
|
+
import * as plan from '../plan.js';
|
|
4
|
+
import { StreamEvaluationContext } from './index.js';
|
|
5
|
+
import { TablePattern } from '../../TablePattern.js';
|
|
6
|
+
import { SourceTableInterface } from '../../SourceTableInterface.js';
|
|
7
|
+
import { SqliteRow, UnscopedEvaluatedParametersResult } from '../../types.js';
|
|
8
|
+
export declare class PreparedParameterIndexLookupCreator implements ParameterIndexLookupCreator {
|
|
9
|
+
private readonly source;
|
|
10
|
+
readonly defaultLookupScope: ParameterLookupScope;
|
|
11
|
+
private readonly evaluator;
|
|
12
|
+
private readonly sourceTable;
|
|
13
|
+
private readonly evaluatorInputs;
|
|
14
|
+
private readonly numberOfOutputs;
|
|
15
|
+
private readonly numberOfParameters;
|
|
16
|
+
constructor(source: plan.StreamParameterIndexLookupCreator, { engine, defaultSchema }: StreamEvaluationContext);
|
|
17
|
+
getSourceTables(): Set<TablePattern>;
|
|
18
|
+
evaluateParameterRow(sourceTable: SourceTableInterface, row: SqliteRow): UnscopedEvaluatedParametersResult[];
|
|
19
|
+
tableSyncsParameters(table: SourceTableInterface): boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { mapExternalDataToInstantiation } from '../engine/scalar_expression_engine.js';
|
|
2
|
+
import { isValidParameterValueRow } from './parameter_evaluator.js';
|
|
3
|
+
import { UnscopedParameterLookup } from '../../BucketParameterQuerier.js';
|
|
4
|
+
export class PreparedParameterIndexLookupCreator {
|
|
5
|
+
source;
|
|
6
|
+
defaultLookupScope;
|
|
7
|
+
evaluator;
|
|
8
|
+
sourceTable;
|
|
9
|
+
evaluatorInputs;
|
|
10
|
+
numberOfOutputs;
|
|
11
|
+
numberOfParameters;
|
|
12
|
+
constructor(source, { engine, defaultSchema }) {
|
|
13
|
+
this.source = source;
|
|
14
|
+
this.defaultLookupScope = source.defaultLookupScope;
|
|
15
|
+
const mapExpressions = mapExternalDataToInstantiation();
|
|
16
|
+
const expressions = source.outputs.map((o) => mapExpressions.transform(o));
|
|
17
|
+
this.numberOfOutputs = expressions.length;
|
|
18
|
+
for (const parameter of source.parameters) {
|
|
19
|
+
expressions.push(mapExpressions.transform(parameter.expr));
|
|
20
|
+
}
|
|
21
|
+
this.numberOfParameters = source.parameters.length;
|
|
22
|
+
this.evaluator = engine.prepareEvaluator({
|
|
23
|
+
outputs: expressions,
|
|
24
|
+
filters: source.filters.map((f) => mapExpressions.transform(f))
|
|
25
|
+
});
|
|
26
|
+
this.sourceTable = source.sourceTable.toTablePattern(defaultSchema);
|
|
27
|
+
this.evaluatorInputs = mapExpressions.instantiation;
|
|
28
|
+
}
|
|
29
|
+
getSourceTables() {
|
|
30
|
+
const set = new Set();
|
|
31
|
+
set.add(this.sourceTable);
|
|
32
|
+
return set;
|
|
33
|
+
}
|
|
34
|
+
evaluateParameterRow(sourceTable, row) {
|
|
35
|
+
const results = [];
|
|
36
|
+
if (!this.sourceTable.matches(sourceTable)) {
|
|
37
|
+
return results;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const inputInstantiation = this.evaluatorInputs.map((input) => row[input.column]);
|
|
41
|
+
for (const outputRow of this.evaluator.evaluate(inputInstantiation)) {
|
|
42
|
+
if (!isValidParameterValueRow(outputRow)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const outputs = {};
|
|
46
|
+
for (let i = 0; i < this.numberOfOutputs; i++) {
|
|
47
|
+
outputs[i.toString()] = outputRow[i];
|
|
48
|
+
}
|
|
49
|
+
// source is [...outputs, ...partitionValues]
|
|
50
|
+
const partitionValues = outputRow.splice(this.numberOfOutputs, this.numberOfParameters);
|
|
51
|
+
const lookup = UnscopedParameterLookup.normalized(partitionValues);
|
|
52
|
+
results.push({ lookup, bucketParameters: [outputs] });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
results.push({ error: e.message });
|
|
57
|
+
}
|
|
58
|
+
return results;
|
|
59
|
+
}
|
|
60
|
+
tableSyncsParameters(table) {
|
|
61
|
+
return this.sourceTable.matches(table);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=parameter_index_lookup_creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter_index_lookup_creator.js","sourceRoot":"","sources":["../../../src/sync_plan/evaluator/parameter_index_lookup_creator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,EAA6B,MAAM,uCAAuC,CAAC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,CAAC;YACxD,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,oBAAoB,CAAC,KAA2B;QAC9C,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An enumeration of all scalar SQL expressions supported by the sync service.
|
|
3
|
+
*
|
|
4
|
+
* Note that these expressions can be serialized, and the evaluation of serialized expressions must be stable.
|
|
5
|
+
*
|
|
6
|
+
* The `Data` type parameter encodes what external data references an {@link ExternalData} node may reference: Bucket
|
|
7
|
+
* data sources can only reference row data (e.g. to evaluate filters), while queriers can only reference connection
|
|
8
|
+
* data. Adding the parameter to expressions ensures the entire subtree can only reference expected sources.
|
|
9
|
+
*/
|
|
10
|
+
export type SqlExpression<Data> = ExternalData<Data> | UnaryExpression<Data> | BinaryExpression<Data> | BetweenExpression<Data> | ScalarInExpression<Data> | CaseWhenExpression<Data> | CastExpression<Data> | ScalarFunctionCallExpression<Data> | LiteralExpression;
|
|
11
|
+
/**
|
|
12
|
+
* External data injected into the expression during evaluation.
|
|
13
|
+
*
|
|
14
|
+
* What kinds of external data is allowed depends on the expression. For instance, expressions for bucket data sources
|
|
15
|
+
* may only reference columns in the current row.
|
|
16
|
+
*/
|
|
17
|
+
export type ExternalData<Data> = {
|
|
18
|
+
type: 'data';
|
|
19
|
+
source: Data;
|
|
20
|
+
};
|
|
21
|
+
export type UnaryOperator = 'not' | '+';
|
|
22
|
+
export type UnaryExpression<Data> = {
|
|
23
|
+
type: 'unary';
|
|
24
|
+
operand: SqlExpression<Data>;
|
|
25
|
+
operator: UnaryOperator;
|
|
26
|
+
};
|
|
27
|
+
export type BinaryOperator = 'or' | 'and' | '=' | 'is' | '<' | '<=' | '>' | '>=' | '&' | '|' | '<<' | '>>' | '+' | '-' | '*' | '/' | '%' | '||';
|
|
28
|
+
/**
|
|
29
|
+
* A binary expression in SQLite, `$left $op $right`.
|
|
30
|
+
*
|
|
31
|
+
* Note that the `LIKE`, `GLOB`, `REGEXP` and `MATCH`, `->` and `->>` operators are not represented as binary
|
|
32
|
+
* expressions but rather as the functions SQLite [would call for them](https://www.sqlite.org/lang_expr.html#the_like_glob_regexp_match_and_extract_operators).
|
|
33
|
+
* Also, note that negated operators (e.g. `!=` or `NOT IN`) are represented by wrapping the expression in a unary
|
|
34
|
+
* `NOT`. This makes transformations to DNF easier.
|
|
35
|
+
*/
|
|
36
|
+
export type BinaryExpression<Data> = {
|
|
37
|
+
type: 'binary';
|
|
38
|
+
left: SqlExpression<Data>;
|
|
39
|
+
operator: BinaryOperator;
|
|
40
|
+
right: SqlExpression<Data>;
|
|
41
|
+
};
|
|
42
|
+
export type BetweenExpression<Data> = {
|
|
43
|
+
type: 'between';
|
|
44
|
+
value: SqlExpression<Data>;
|
|
45
|
+
low: SqlExpression<Data>;
|
|
46
|
+
high: SqlExpression<Data>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* An `expr IN ($in0, $in1, ..., $inN)` expression.
|
|
50
|
+
*/
|
|
51
|
+
export type ScalarInExpression<Data> = {
|
|
52
|
+
type: 'scalar_in';
|
|
53
|
+
target: SqlExpression<Data>;
|
|
54
|
+
in: SqlExpression<Data>[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* A `CASE WHEN` expression as supported by SQLite.
|
|
58
|
+
*/
|
|
59
|
+
export type CaseWhenExpression<Data> = {
|
|
60
|
+
type: 'case_when';
|
|
61
|
+
operand?: SqlExpression<Data>;
|
|
62
|
+
whens: {
|
|
63
|
+
when: SqlExpression<Data>;
|
|
64
|
+
then: SqlExpression<Data>;
|
|
65
|
+
}[];
|
|
66
|
+
else?: SqlExpression<Data>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* A `CAST` expression.
|
|
70
|
+
*/
|
|
71
|
+
export type CastExpression<Data> = {
|
|
72
|
+
type: 'cast';
|
|
73
|
+
operand: SqlExpression<Data>;
|
|
74
|
+
cast_as: 'text' | 'numeric' | 'real' | 'integer' | 'blob';
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* A constant literal in SQL.
|
|
78
|
+
*/
|
|
79
|
+
export type LiteralExpression = {
|
|
80
|
+
type: 'lit_null';
|
|
81
|
+
} | {
|
|
82
|
+
type: 'lit_double';
|
|
83
|
+
value: number;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'lit_int';
|
|
86
|
+
/**
|
|
87
|
+
* The integer value as a base 10 string. We don't use the correct `bigint` type to be able to serialize and
|
|
88
|
+
* deserialize with the default JSON implementation.
|
|
89
|
+
*/
|
|
90
|
+
base10: string;
|
|
91
|
+
} | {
|
|
92
|
+
type: 'lit_string';
|
|
93
|
+
value: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* A scalar (non-aggregate, non-window, non-table-valued) function call in SQL.
|
|
97
|
+
*/
|
|
98
|
+
export type ScalarFunctionCallExpression<Data> = {
|
|
99
|
+
type: 'function';
|
|
100
|
+
function: string;
|
|
101
|
+
parameters: SqlExpression<Data>[];
|
|
102
|
+
};
|
|
103
|
+
export type ArgumentCount = number | {
|
|
104
|
+
min: number;
|
|
105
|
+
max?: number;
|
|
106
|
+
mustBeEven?: boolean;
|
|
107
|
+
mustBeOdd?: boolean;
|
|
108
|
+
};
|
|
109
|
+
export declare const supportedFunctions: Record<string, ArgumentCount>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export const supportedFunctions = {
|
|
2
|
+
// https://sqlite.org/lang_corefunc.html#list_of_core_functions
|
|
3
|
+
abs: 1,
|
|
4
|
+
char: { min: 0 },
|
|
5
|
+
coalesce: { min: 2 },
|
|
6
|
+
concat: { min: 1 },
|
|
7
|
+
concat_ws: { min: 2 },
|
|
8
|
+
format: { min: 1 },
|
|
9
|
+
glob: 2,
|
|
10
|
+
hex: 1,
|
|
11
|
+
ifnull: { min: 2 },
|
|
12
|
+
if: { min: 2 },
|
|
13
|
+
iif: { min: 2 },
|
|
14
|
+
instr: 2,
|
|
15
|
+
length: 1,
|
|
16
|
+
// TODO: Establish defaults for case sensitivity, changing escape characters, ICU support.
|
|
17
|
+
// We might just want to remove LIKE support since we don't seem to have it in sql_functions.ts
|
|
18
|
+
like: { min: 2, max: 3 },
|
|
19
|
+
// likelihood: 2,
|
|
20
|
+
// likely: 1,
|
|
21
|
+
lower: 1,
|
|
22
|
+
ltrim: { min: 1, max: 2 },
|
|
23
|
+
max: { min: 2 },
|
|
24
|
+
min: { min: 2 },
|
|
25
|
+
nullif: 2,
|
|
26
|
+
octet_length: 1,
|
|
27
|
+
printf: { min: 1 },
|
|
28
|
+
quote: 1,
|
|
29
|
+
replace: 3,
|
|
30
|
+
round: { min: 1, max: 2 },
|
|
31
|
+
rtrim: { min: 1, max: 2 },
|
|
32
|
+
sign: 1,
|
|
33
|
+
substr: { min: 2, max: 3 },
|
|
34
|
+
substring: { min: 2, max: 3 },
|
|
35
|
+
trim: { min: 1, max: 2 },
|
|
36
|
+
typeof: 1,
|
|
37
|
+
unhex: { min: 1, max: 2 },
|
|
38
|
+
unicode: 1,
|
|
39
|
+
unistr: 1,
|
|
40
|
+
unistr_quote: 1,
|
|
41
|
+
// unlikely: 1,
|
|
42
|
+
upper: 1,
|
|
43
|
+
zeroblob: 1,
|
|
44
|
+
// Scalar functions from https://sqlite.org/json1.html#overview
|
|
45
|
+
// We disallow jsonb functions because they're not implemented in sql_functions.ts and we want to preserve
|
|
46
|
+
// compatibility with that.
|
|
47
|
+
json: 1,
|
|
48
|
+
// jsonb: 1,
|
|
49
|
+
json_array: { min: 0 },
|
|
50
|
+
// jsonb_array: { min: 0 },
|
|
51
|
+
json_array_length: { min: 1, max: 2 },
|
|
52
|
+
json_error_position: 1,
|
|
53
|
+
json_extract: { min: 2 },
|
|
54
|
+
// jsonb_extract: { min: 2 },
|
|
55
|
+
json_insert: { min: 3, mustBeOdd: true },
|
|
56
|
+
// jsonb_insert: { min: 3, mustBeOdd: true },
|
|
57
|
+
json_object: { min: 0, mustBeEven: true },
|
|
58
|
+
// jsonb_object: { min: 0, mustBeEven: true },
|
|
59
|
+
json_patch: 2,
|
|
60
|
+
// jsonb_patch: 2,
|
|
61
|
+
json_pretty: 1,
|
|
62
|
+
json_remove: { min: 2 },
|
|
63
|
+
// jsonb_remove: { min: 2 },
|
|
64
|
+
json_replace: { min: 3, mustBeOdd: true },
|
|
65
|
+
// jsonb_replace: { min: 3, mustBeOdd: true },
|
|
66
|
+
json_set: { min: 3, mustBeOdd: true },
|
|
67
|
+
// jsonb_set: { min: 3, mustBeOdd: true },
|
|
68
|
+
json_type: { min: 1, max: 2 },
|
|
69
|
+
json_valid: { min: 1, max: 2 },
|
|
70
|
+
json_quote: { min: 1 },
|
|
71
|
+
// https://www.sqlite.org/lang_datefunc.html, but we only support datetime and unixepoch
|
|
72
|
+
// TODO: Ensure our support matches the current unixepoch behavior in sql_functions.ts, register as user-defined
|
|
73
|
+
// function to patch default if in doubt.
|
|
74
|
+
unixepoch: { min: 1 },
|
|
75
|
+
datetime: { min: 1 },
|
|
76
|
+
// PowerSync-specific, mentioned in https://docs.powersync.com/sync/rules/supported-sql#functions
|
|
77
|
+
base64: 1,
|
|
78
|
+
json_keys: 1,
|
|
79
|
+
uuid_blob: 1,
|
|
80
|
+
st_asgeojson: 1,
|
|
81
|
+
st_astext: 1,
|
|
82
|
+
st_x: 1,
|
|
83
|
+
st_y: 1
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=expression.js.map
|