@powersync/service-sync-rules 0.39.0 → 0.41.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/HydratedSyncConfig.d.ts +9 -2
- package/dist/HydratedSyncConfig.js +12 -1
- package/dist/HydratedSyncConfig.js.map +1 -1
- package/dist/HydrationState.d.ts +2 -0
- package/dist/HydrationState.js.map +1 -1
- package/dist/StorageVersion.js +2 -1
- package/dist/StorageVersion.js.map +1 -1
- package/dist/SyncConfig.d.ts +4 -3
- package/dist/SyncConfig.js +10 -11
- package/dist/SyncConfig.js.map +1 -1
- package/dist/TablePattern.d.ts +2 -0
- package/dist/TablePattern.js +18 -1
- package/dist/TablePattern.js.map +1 -1
- package/dist/compiler/bucket_resolver.d.ts +1 -0
- package/dist/compiler/bucket_resolver.js +22 -12
- package/dist/compiler/bucket_resolver.js.map +1 -1
- package/dist/compiler/compatibility.d.ts +38 -9
- package/dist/compiler/compatibility.js +81 -11
- package/dist/compiler/compatibility.js.map +1 -1
- package/dist/compiler/compiler.d.ts +81 -13
- package/dist/compiler/compiler.js +111 -15
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/expression.d.ts +35 -12
- package/dist/compiler/expression.js +49 -13
- package/dist/compiler/expression.js.map +1 -1
- package/dist/compiler/filter.d.ts +4 -4
- package/dist/compiler/filter.js +7 -6
- package/dist/compiler/filter.js.map +1 -1
- package/dist/compiler/ir_to_sync_plan.d.ts +4 -2
- package/dist/compiler/ir_to_sync_plan.js +47 -37
- package/dist/compiler/ir_to_sync_plan.js.map +1 -1
- package/dist/compiler/parser.js +3 -3
- package/dist/compiler/parser.js.map +1 -1
- package/dist/compiler/querier_graph.js +45 -26
- package/dist/compiler/querier_graph.js.map +1 -1
- package/dist/compiler/rows.d.ts +23 -29
- package/dist/compiler/rows.js +83 -59
- package/dist/compiler/rows.js.map +1 -1
- package/dist/compiler/sqlite.d.ts +3 -2
- package/dist/compiler/sqlite.js +33 -3
- package/dist/compiler/sqlite.js.map +1 -1
- package/dist/compiler/table.d.ts +3 -2
- package/dist/compiler/table.js +9 -7
- package/dist/compiler/table.js.map +1 -1
- package/dist/events/CompiledEventSourceQuery.d.ts +51 -0
- package/dist/events/CompiledEventSourceQuery.js +119 -0
- package/dist/events/CompiledEventSourceQuery.js.map +1 -0
- package/dist/events/EventDescriptor.d.ts +26 -0
- package/dist/events/EventDescriptor.js +2 -0
- package/dist/events/EventDescriptor.js.map +1 -0
- package/dist/from_yaml.js +157 -189
- package/dist/from_yaml.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/json_schema.js +1 -1
- package/dist/json_schema.js.map +1 -1
- package/dist/sync_plan/engine/scalar_expression_engine.js +7 -0
- package/dist/sync_plan/engine/scalar_expression_engine.js.map +1 -1
- package/dist/sync_plan/evaluator/bucket_data_source.js +11 -52
- package/dist/sync_plan/evaluator/bucket_data_source.js.map +1 -1
- package/dist/sync_plan/evaluator/index.d.ts +2 -7
- package/dist/sync_plan/evaluator/index.js +6 -7
- package/dist/sync_plan/evaluator/index.js.map +1 -1
- package/dist/sync_plan/evaluator/parameter_evaluator.js +11 -7
- package/dist/sync_plan/evaluator/parameter_evaluator.js.map +1 -1
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.js +2 -2
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.js.map +1 -1
- package/dist/sync_plan/evaluator/row_projection.d.ts +22 -0
- package/dist/sync_plan/evaluator/row_projection.js +71 -0
- package/dist/sync_plan/evaluator/row_projection.js.map +1 -0
- package/dist/sync_plan/evaluator/table_processor_to_sql.d.ts +5 -2
- package/dist/sync_plan/evaluator/table_processor_to_sql.js +10 -0
- package/dist/sync_plan/evaluator/table_processor_to_sql.js.map +1 -1
- package/dist/sync_plan/plan.d.ts +49 -9
- package/dist/sync_plan/plan_equality_serialized.d.ts +12 -2
- package/dist/sync_plan/plan_equality_serialized.js +56 -0
- package/dist/sync_plan/plan_equality_serialized.js.map +1 -1
- package/dist/sync_plan/serialize.d.ts +54 -5
- package/dist/sync_plan/serialize.js +109 -19
- package/dist/sync_plan/serialize.js.map +1 -1
- package/dist/yaml_validation.d.ts +73 -0
- package/dist/yaml_validation.js +140 -0
- package/dist/yaml_validation.js.map +1 -0
- package/package.json +1 -1
- package/schema/sync_rules.json +3 -2
- package/dist/events/SqlEventDescriptor.d.ts +0 -20
- package/dist/events/SqlEventDescriptor.js +0 -51
- package/dist/events/SqlEventDescriptor.js.map +0 -1
- package/dist/events/SqlEventSourceQuery.d.ts +0 -20
- package/dist/events/SqlEventSourceQuery.js +0 -125
- package/dist/events/SqlEventSourceQuery.js.map +0 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { NodeLocation, PGNode } from 'pgsql-ast-parser';
|
|
2
|
-
import {
|
|
2
|
+
import { SqlRuleError } from '../errors.js';
|
|
3
|
+
import { CompiledEventDescriptor, StreamOptions, SyncPlan } from '../sync_plan/plan.js';
|
|
3
4
|
import { SourceSchema } from '../types.js';
|
|
4
5
|
import { StreamResolver } from './bucket_resolver.js';
|
|
5
|
-
import { PointLookup, RowEvaluator } from './rows.js';
|
|
6
|
+
import { EventRowEvaluator, PointLookup, RowEvaluator } from './rows.js';
|
|
6
7
|
import { CommonTableExpression, PreparedSubquery } from './sqlite.js';
|
|
8
|
+
import type { PhysicalSourceResultSet } from './table.js';
|
|
7
9
|
export interface SyncStreamsCompilerOptions {
|
|
8
10
|
/**
|
|
9
11
|
* Used exclusively for linting against the given {@link schema}.
|
|
@@ -19,26 +21,33 @@ export interface SyncStreamsCompilerOptions {
|
|
|
19
21
|
* streams across schema changes.
|
|
20
22
|
*/
|
|
21
23
|
schema?: SourceSchema;
|
|
24
|
+
/**
|
|
25
|
+
* Whether event payload `WHERE` clauses are compiled and applied.
|
|
26
|
+
*
|
|
27
|
+
* This defaults to true. It is disabled for editions that cannot persist compiled event plans and when restoring
|
|
28
|
+
* event SQL that predates those plans, because the legacy evaluator parsed `WHERE` clauses but did not validate or
|
|
29
|
+
* evaluate them.
|
|
30
|
+
*/
|
|
31
|
+
compileEventPayloadFilters?: boolean;
|
|
22
32
|
}
|
|
23
33
|
export interface ParseStreamOptions extends StreamOptions {
|
|
24
34
|
warnOnDangerousParameter: boolean;
|
|
25
35
|
}
|
|
26
36
|
/**
|
|
27
|
-
* State for compiling sync streams.
|
|
37
|
+
* State for compiling sync streams and replication events into a sync plan.
|
|
28
38
|
*
|
|
29
|
-
* The
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* relations. This allows the compiler to efficiently de-duplicate parameters and buckets.
|
|
39
|
+
* The compiler stores a mutable intermediate representation that is essentially a copy of the resulting
|
|
40
|
+
* {@link SyncPlan}. Stream compilation uses JavaScript classes with behavioral equality, while events use plain
|
|
41
|
+
* compiler records. Stream queries and event definitions remain separate within that model.
|
|
33
42
|
*
|
|
34
|
-
*
|
|
43
|
+
* The stream compilation process is as follows: Each data query for a stream is first parsed by
|
|
35
44
|
* {@link StreamQueryParser} into a canonicalized intermediate representation (see that class for details).
|
|
36
45
|
* Then, {@link QuerierGraphBuilder} analyzes a chain of `AND` expressions to identify parameters (as partition keys)
|
|
37
46
|
* and their instantiation, as well as static filters that need to be added to reach row.
|
|
38
47
|
*/
|
|
39
48
|
export declare class SyncStreamsCompiler {
|
|
40
49
|
readonly options: SyncStreamsCompilerOptions;
|
|
41
|
-
readonly output:
|
|
50
|
+
readonly output: SyncPlanCompilerModel;
|
|
42
51
|
private readonly locations;
|
|
43
52
|
constructor(options: SyncStreamsCompilerOptions);
|
|
44
53
|
/**
|
|
@@ -58,7 +67,28 @@ export declare class SyncStreamsCompiler {
|
|
|
58
67
|
* @param options Name, priority and `auto_subscribe` state for the stream.
|
|
59
68
|
*/
|
|
60
69
|
stream(options: ParseStreamOptions): IndividualSyncStreamCompiler;
|
|
70
|
+
/**
|
|
71
|
+
* Compiles the payload queries for a named replication event.
|
|
72
|
+
*
|
|
73
|
+
* Event queries intentionally support a smaller surface than stream queries: They must project and filter a single
|
|
74
|
+
* physical source table and cannot depend on request parameters, joins, subqueries or table-valued functions.
|
|
75
|
+
*/
|
|
76
|
+
event(name: string): IndividualEventCompiler;
|
|
77
|
+
/**
|
|
78
|
+
* @returns A sync plan representing an immutable snapshot of the compiler output.
|
|
79
|
+
*/
|
|
80
|
+
toSyncPlan(): SyncPlan;
|
|
61
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Compiles raw event definitions from legacy sync plans into the current plan representation.
|
|
84
|
+
*
|
|
85
|
+
* All definitions share one compiler to match normal sync-config compilation. Callers should reject fatal errors
|
|
86
|
+
* rather than carrying invalid legacy event evaluators into a {@link SyncPlan}.
|
|
87
|
+
*/
|
|
88
|
+
export declare function compileEventDefinitions(definitions: Readonly<Record<string, readonly string[]>>, options: SyncStreamsCompilerOptions): {
|
|
89
|
+
events: CompiledEventDescriptor[];
|
|
90
|
+
errors: SqlRuleError[];
|
|
91
|
+
};
|
|
62
92
|
/**
|
|
63
93
|
* Utility for compiling a single sync stream.
|
|
64
94
|
*/
|
|
@@ -80,6 +110,12 @@ export interface IndividualSyncStreamCompiler {
|
|
|
80
110
|
*/
|
|
81
111
|
finish(): void;
|
|
82
112
|
}
|
|
113
|
+
export interface IndividualEventCompiler {
|
|
114
|
+
/**
|
|
115
|
+
* Validates and adds one payload query to this event.
|
|
116
|
+
*/
|
|
117
|
+
addSourceQuery(sql: string, errors: ParsingErrorListener): void;
|
|
118
|
+
}
|
|
83
119
|
/**
|
|
84
120
|
* Something reporting errors.
|
|
85
121
|
*
|
|
@@ -106,8 +142,40 @@ export declare class CompiledStreamQueries {
|
|
|
106
142
|
get pointLookups(): PointLookup[];
|
|
107
143
|
canonicalizeEvaluator(evaluator: RowEvaluator): RowEvaluator;
|
|
108
144
|
canonicalizePointLookup(lookup: PointLookup): PointLookup;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Compiler model for one SQL query in a named event's `payloads` list.
|
|
148
|
+
*
|
|
149
|
+
* It binds that query to its single physical source table and contains one row evaluator for each normalized `OR`
|
|
150
|
+
* branch. Within each evaluator, filters determine whether a source row triggers the event, while projected columns
|
|
151
|
+
* determine the payload produced for a matching row.
|
|
152
|
+
*
|
|
153
|
+
* {@link sql} is retained so service-core can dual-write the legacy `eventDescriptors` field for older services during
|
|
154
|
+
* rolling upgrades. The executable plan uses the parsed source table and row evaluators instead.
|
|
155
|
+
*/
|
|
156
|
+
export interface CompiledEventSourceQueryModel {
|
|
157
|
+
sql: string;
|
|
158
|
+
sourceTable: PhysicalSourceResultSet;
|
|
159
|
+
variants: EventRowEvaluator[];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Compiler model for one named entry under `event_definitions`.
|
|
163
|
+
*
|
|
164
|
+
* {@link name} identifies the event exposed to handlers. {@link sourceQueries} represents its complete `payloads`
|
|
165
|
+
* list, which may define how rows from different source tables trigger that event and produce its payload.
|
|
166
|
+
*/
|
|
167
|
+
export interface CompiledEvent {
|
|
168
|
+
name: string;
|
|
169
|
+
sourceQueries: CompiledEventSourceQueryModel[];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Top-level compiler output used to assemble a complete sync plan.
|
|
173
|
+
*
|
|
174
|
+
* Streams and events are sibling sync-config concerns. Keeping their intermediate state separate prevents stream
|
|
175
|
+
* compilation abstractions from acquiring event-specific responsibilities just because both are persisted in one
|
|
176
|
+
* {@link SyncPlan}.
|
|
177
|
+
*/
|
|
178
|
+
export interface SyncPlanCompilerModel {
|
|
179
|
+
readonly streams: CompiledStreamQueries;
|
|
180
|
+
readonly events: CompiledEvent[];
|
|
113
181
|
}
|
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
import { parse } from 'pgsql-ast-parser';
|
|
2
|
+
import { SqlRuleError } from '../errors.js';
|
|
2
3
|
import { DangerousParameterDetector } from './detect_dangerous_parameters.js';
|
|
3
4
|
import { HashSet } from './equality.js';
|
|
4
5
|
import { NodeLocations } from './expression.js';
|
|
6
|
+
import { RowExpression, SingleDependencyExpression } from './filter.js';
|
|
5
7
|
import { CompilerModelToSyncPlan } from './ir_to_sync_plan.js';
|
|
6
8
|
import { StreamQueryParser } from './parser.js';
|
|
7
9
|
import { QuerierGraphBuilder } from './querier_graph.js';
|
|
10
|
+
import { EventRowEvaluator } from './rows.js';
|
|
8
11
|
import { SqlScope } from './scope.js';
|
|
9
12
|
/**
|
|
10
|
-
* State for compiling sync streams.
|
|
13
|
+
* State for compiling sync streams and replication events into a sync plan.
|
|
11
14
|
*
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* relations. This allows the compiler to efficiently de-duplicate parameters and buckets.
|
|
15
|
+
* The compiler stores a mutable intermediate representation that is essentially a copy of the resulting
|
|
16
|
+
* {@link SyncPlan}. Stream compilation uses JavaScript classes with behavioral equality, while events use plain
|
|
17
|
+
* compiler records. Stream queries and event definitions remain separate within that model.
|
|
16
18
|
*
|
|
17
|
-
*
|
|
19
|
+
* The stream compilation process is as follows: Each data query for a stream is first parsed by
|
|
18
20
|
* {@link StreamQueryParser} into a canonicalized intermediate representation (see that class for details).
|
|
19
21
|
* Then, {@link QuerierGraphBuilder} analyzes a chain of `AND` expressions to identify parameters (as partition keys)
|
|
20
22
|
* and their instantiation, as well as static filters that need to be added to reach row.
|
|
21
23
|
*/
|
|
22
24
|
export class SyncStreamsCompiler {
|
|
23
25
|
options;
|
|
24
|
-
output =
|
|
26
|
+
output = {
|
|
27
|
+
streams: new CompiledStreamQueries(),
|
|
28
|
+
events: []
|
|
29
|
+
};
|
|
25
30
|
locations = new NodeLocations();
|
|
26
31
|
constructor(options) {
|
|
27
32
|
this.options = options;
|
|
@@ -94,10 +99,108 @@ export class SyncStreamsCompiler {
|
|
|
94
99
|
}
|
|
95
100
|
};
|
|
96
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Compiles the payload queries for a named replication event.
|
|
104
|
+
*
|
|
105
|
+
* Event queries intentionally support a smaller surface than stream queries: They must project and filter a single
|
|
106
|
+
* physical source table and cannot depend on request parameters, joins, subqueries or table-valued functions.
|
|
107
|
+
*/
|
|
108
|
+
event(name) {
|
|
109
|
+
const event = { name, sourceQueries: [] };
|
|
110
|
+
this.output.events.push(event);
|
|
111
|
+
return {
|
|
112
|
+
addSourceQuery: (sql, errors) => {
|
|
113
|
+
const stmt = tryParse(sql, errors);
|
|
114
|
+
if (stmt == null) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let statementToCompile = stmt;
|
|
118
|
+
if (this.options.compileEventPayloadFilters === false && stmt.type == 'select' && stmt.where != null) {
|
|
119
|
+
errors.report('`WHERE` clauses in legacy event payload queries are ignored. Redeploy this sync config with edition 3 to validate and enable them.', stmt.where, { isWarning: true });
|
|
120
|
+
statementToCompile = { ...stmt, where: undefined };
|
|
121
|
+
}
|
|
122
|
+
const parser = new StreamQueryParser({
|
|
123
|
+
compiler: this,
|
|
124
|
+
originalText: sql,
|
|
125
|
+
locations: this.locations,
|
|
126
|
+
parentScope: new SqlScope({}),
|
|
127
|
+
errors
|
|
128
|
+
});
|
|
129
|
+
const query = parser.parse(statementToCompile);
|
|
130
|
+
if (query == null) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (query.joined.length != 0) {
|
|
134
|
+
errors.report('Event payload queries must SELECT from a single physical source table.', query.span.location);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const variants = [];
|
|
138
|
+
let valid = true;
|
|
139
|
+
for (const variant of query.where.terms) {
|
|
140
|
+
const filters = [];
|
|
141
|
+
for (const term of variant.terms) {
|
|
142
|
+
if (!(term instanceof SingleDependencyExpression) ||
|
|
143
|
+
term.dependsOnConnection ||
|
|
144
|
+
(term.resultSet != null && term.resultSet !== query.sourceTable)) {
|
|
145
|
+
errors.report('Event payload queries cannot depend on request parameters or other tables.', term instanceof SingleDependencyExpression ? term.expression.location.location : term.location);
|
|
146
|
+
valid = false;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
filters.push(new RowExpression(term));
|
|
150
|
+
}
|
|
151
|
+
variants.push(new EventRowEvaluator({
|
|
152
|
+
columns: query.resultColumns,
|
|
153
|
+
syntacticSource: query.sourceTable,
|
|
154
|
+
filters,
|
|
155
|
+
partitionBy: [],
|
|
156
|
+
addedFunctions: []
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
if (valid) {
|
|
160
|
+
event.sourceQueries.push({ sql, sourceTable: query.sourceTable, variants });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @returns A sync plan representing an immutable snapshot of the compiler output.
|
|
167
|
+
*/
|
|
168
|
+
toSyncPlan() {
|
|
169
|
+
const translator = new CompilerModelToSyncPlan();
|
|
170
|
+
return translator.translate(this.output);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Compiles raw event definitions from legacy sync plans into the current plan representation.
|
|
175
|
+
*
|
|
176
|
+
* All definitions share one compiler to match normal sync-config compilation. Callers should reject fatal errors
|
|
177
|
+
* rather than carrying invalid legacy event evaluators into a {@link SyncPlan}.
|
|
178
|
+
*/
|
|
179
|
+
export function compileEventDefinitions(definitions, options) {
|
|
180
|
+
const compiler = new SyncStreamsCompiler(options);
|
|
181
|
+
const errors = [];
|
|
182
|
+
for (const [name, queries] of Object.entries(definitions)) {
|
|
183
|
+
const event = compiler.event(name);
|
|
184
|
+
for (const sql of queries) {
|
|
185
|
+
event.addSourceQuery(sql, {
|
|
186
|
+
report(message, location, reportOptions) {
|
|
187
|
+
const error = new SqlRuleError(message, sql, location);
|
|
188
|
+
error.type = reportOptions?.isWarning ? 'warning' : 'fatal';
|
|
189
|
+
errors.push(error);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return { events: compiler.toSyncPlan().events, errors };
|
|
97
195
|
}
|
|
98
196
|
function tryParse(sql, errors) {
|
|
99
197
|
try {
|
|
100
|
-
const
|
|
198
|
+
const statements = parse(sql, { locationTracking: true });
|
|
199
|
+
if (statements.length != 1) {
|
|
200
|
+
errors.report('Only a single SELECT statement is supported', statements[1]?._location ?? { start: 0, end: sql.length });
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
const [stmt] = statements;
|
|
101
204
|
return stmt;
|
|
102
205
|
}
|
|
103
206
|
catch (e) {
|
|
@@ -132,12 +235,5 @@ export class CompiledStreamQueries {
|
|
|
132
235
|
canonicalizePointLookup(lookup) {
|
|
133
236
|
return this._pointLookups.getOrInsert(lookup)[0];
|
|
134
237
|
}
|
|
135
|
-
/**
|
|
136
|
-
* @returns A sync plan representing an immutable snapshot of this intermediate representation.
|
|
137
|
-
*/
|
|
138
|
-
toSyncPlan() {
|
|
139
|
-
const translator = new CompilerModelToSyncPlan();
|
|
140
|
-
return translator.translate(this);
|
|
141
|
-
}
|
|
142
238
|
}
|
|
143
239
|
//# sourceMappingURL=compiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,EAAqB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,EAAqB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,0BAA0B,EAA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,CAAC;IAED,qBAAqB,CAAC,SAAuB;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,uBAAuB,CAAC,MAAmB;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;CACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Expr, NodeLocation, PGNode } from 'pgsql-ast-parser';
|
|
2
2
|
import { SqlExpression } from '../sync_plan/expression.js';
|
|
3
3
|
import { ConnectionParameterSource } from '../sync_plan/plan.js';
|
|
4
|
-
import {
|
|
4
|
+
import { EqualsIgnoringPrimaryResultSet, TableValuedFunctionEquality } from './compatibility.js';
|
|
5
5
|
import { ParsingErrorListener } from './compiler.js';
|
|
6
|
-
import { StableHasher } from './equality.js';
|
|
6
|
+
import { Equatable, StableHasher } from './equality.js';
|
|
7
7
|
import { SourceResultSet } from './table.js';
|
|
8
8
|
/**
|
|
9
9
|
* An analyzed SQL expression tracking dependencies on non-static data (i.e. rows or connection sources).
|
|
@@ -16,7 +16,7 @@ import { SourceResultSet } from './table.js';
|
|
|
16
16
|
* Once in this form, it's easy to reason about dependencies in expressions (used to later generate parameter match
|
|
17
17
|
* clauses) and to evaluate expressions at runtime (by preparing them as a statement and binding external values).
|
|
18
18
|
*/
|
|
19
|
-
export declare class SyncExpression implements
|
|
19
|
+
export declare class SyncExpression implements EqualsIgnoringPrimaryResultSet {
|
|
20
20
|
#private;
|
|
21
21
|
/**
|
|
22
22
|
* The AST node backing {@link sql}.
|
|
@@ -46,24 +46,47 @@ export declare class SyncExpression implements EqualsIgnoringResultSet {
|
|
|
46
46
|
* We use this to be able to compose expressions, e.g. to possibly merge them.
|
|
47
47
|
*/
|
|
48
48
|
node: SqlExpression<ExpressionInput>, locations: NodeLocations);
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
equalsAssumingSamePrimaryResultSet(other: EqualsIgnoringPrimaryResultSet, tableValued: TableValuedFunctionEquality): boolean;
|
|
50
|
+
assumingSamePrimaryResultSetEqualityHashCode(tableValued: TableValuedFunctionEquality, hasher: StableHasher): void;
|
|
51
51
|
}
|
|
52
|
-
export type ExpressionInput = ColumnInRow | ConnectionParameter;
|
|
53
|
-
|
|
52
|
+
export type ExpressionInput = ColumnInRow | RowMetadata | ConnectionParameter;
|
|
53
|
+
/**
|
|
54
|
+
* An expression input resolved against a row of a result set: either a column value or metadata about the row's
|
|
55
|
+
* source table.
|
|
56
|
+
*/
|
|
57
|
+
export declare abstract class RowReference implements EqualsIgnoringPrimaryResultSet {
|
|
54
58
|
readonly syntacticOrigin: Expr;
|
|
55
59
|
readonly resultSet: SourceResultSet;
|
|
60
|
+
constructor(syntacticOrigin: Expr, resultSet: SourceResultSet);
|
|
61
|
+
abstract equalsAssumingSamePrimaryResultSet(other: EqualsIgnoringPrimaryResultSet, tableValued: TableValuedFunctionEquality): boolean;
|
|
62
|
+
abstract assumingSamePrimaryResultSetEqualityHashCode(tableValued: TableValuedFunctionEquality, hasher: StableHasher): void;
|
|
63
|
+
}
|
|
64
|
+
export declare class ColumnInRow extends RowReference {
|
|
56
65
|
readonly column: string;
|
|
57
66
|
constructor(syntacticOrigin: Expr, resultSet: SourceResultSet, column: string);
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
equalsAssumingSamePrimaryResultSet(other: EqualsIgnoringPrimaryResultSet, tableValued: TableValuedFunctionEquality): boolean;
|
|
68
|
+
assumingSamePrimaryResultSetEqualityHashCode(tableValued: TableValuedFunctionEquality, hasher: StableHasher): void;
|
|
69
|
+
}
|
|
70
|
+
export type RowMetadataKind = 'schema' | 'table_name' | 'table_suffix';
|
|
71
|
+
/**
|
|
72
|
+
* A reference to metadata of the row's source table (`users.schema()`, `users.table_name()` or
|
|
73
|
+
* `users.table_suffix()`) instead of an actual column, resolved against the concrete table a row was
|
|
74
|
+
* replicated from.
|
|
75
|
+
*/
|
|
76
|
+
export declare class RowMetadata extends RowReference {
|
|
77
|
+
readonly kind: RowMetadataKind;
|
|
78
|
+
constructor(syntacticOrigin: Expr, resultSet: SourceResultSet, kind: RowMetadataKind);
|
|
79
|
+
equalsAssumingSamePrimaryResultSet(other: EqualsIgnoringPrimaryResultSet): boolean;
|
|
80
|
+
assumingSamePrimaryResultSetEqualityHashCode(_tableValued: TableValuedFunctionEquality, hasher: StableHasher): void;
|
|
60
81
|
}
|
|
61
|
-
export declare class ConnectionParameter implements
|
|
82
|
+
export declare class ConnectionParameter implements EqualsIgnoringPrimaryResultSet, Equatable {
|
|
62
83
|
readonly syntacticOrigin: Expr;
|
|
63
84
|
readonly source: ConnectionParameterSource;
|
|
64
85
|
constructor(syntacticOrigin: Expr, source: ConnectionParameterSource);
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
equals(other: unknown): boolean;
|
|
87
|
+
buildHash(hasher: StableHasher): void;
|
|
88
|
+
equalsAssumingSamePrimaryResultSet(other: EqualsIgnoringPrimaryResultSet): boolean;
|
|
89
|
+
assumingSamePrimaryResultSetEqualityHashCode(_tableValued: TableValuedFunctionEquality, hasher: StableHasher): void;
|
|
67
90
|
}
|
|
68
91
|
/**
|
|
69
92
|
* Tracks the original source location for translated {@link SqlExpression} nodes.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getLocation } from '../errors.js';
|
|
2
2
|
import { ExpressionToSqlite } from '../sync_plan/expression_to_sql.js';
|
|
3
3
|
import { RecursiveExpressionVisitor } from '../sync_plan/expression_visitor.js';
|
|
4
|
-
import { equalsIgnoringResultSetList } from './compatibility.js';
|
|
5
4
|
/**
|
|
6
5
|
* An analyzed SQL expression tracking dependencies on non-static data (i.e. rows or connection sources).
|
|
7
6
|
*
|
|
@@ -53,14 +52,14 @@ export class SyncExpression {
|
|
|
53
52
|
this.node = node;
|
|
54
53
|
this.locations = locations;
|
|
55
54
|
}
|
|
56
|
-
|
|
55
|
+
equalsAssumingSamePrimaryResultSet(other, tableValued) {
|
|
57
56
|
return (other instanceof SyncExpression &&
|
|
58
57
|
other.sql == this.sql &&
|
|
59
|
-
|
|
58
|
+
tableValued.listEquality.equals(other.instantiation, this.instantiation));
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
assumingSamePrimaryResultSetEqualityHashCode(tableValued, hasher) {
|
|
62
61
|
hasher.addString(this.sql);
|
|
63
|
-
|
|
62
|
+
tableValued.listEquality.hash(hasher, this.instantiation);
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
class FindExternalData extends RecursiveExpressionVisitor {
|
|
@@ -72,20 +71,51 @@ class FindExternalData extends RecursiveExpressionVisitor {
|
|
|
72
71
|
}
|
|
73
72
|
static instance = new FindExternalData();
|
|
74
73
|
}
|
|
75
|
-
|
|
74
|
+
/**
|
|
75
|
+
* An expression input resolved against a row of a result set: either a column value or metadata about the row's
|
|
76
|
+
* source table.
|
|
77
|
+
*/
|
|
78
|
+
export class RowReference {
|
|
76
79
|
syntacticOrigin;
|
|
77
80
|
resultSet;
|
|
78
|
-
|
|
79
|
-
constructor(syntacticOrigin, resultSet, column) {
|
|
81
|
+
constructor(syntacticOrigin, resultSet) {
|
|
80
82
|
this.syntacticOrigin = syntacticOrigin;
|
|
81
83
|
this.resultSet = resultSet;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export class ColumnInRow extends RowReference {
|
|
87
|
+
column;
|
|
88
|
+
constructor(syntacticOrigin, resultSet, column) {
|
|
89
|
+
super(syntacticOrigin, resultSet);
|
|
82
90
|
this.column = column;
|
|
83
91
|
}
|
|
84
|
-
|
|
85
|
-
return other instanceof ColumnInRow &&
|
|
92
|
+
equalsAssumingSamePrimaryResultSet(other, tableValued) {
|
|
93
|
+
return (other instanceof ColumnInRow &&
|
|
94
|
+
other.column == this.column &&
|
|
95
|
+
tableValued.resultSetEquals(other.resultSet, this.resultSet));
|
|
86
96
|
}
|
|
87
|
-
|
|
97
|
+
assumingSamePrimaryResultSetEqualityHashCode(tableValued, hasher) {
|
|
88
98
|
hasher.addString(this.column);
|
|
99
|
+
tableValued.hashResultSet(hasher, this.resultSet);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A reference to metadata of the row's source table (`users.schema()`, `users.table_name()` or
|
|
104
|
+
* `users.table_suffix()`) instead of an actual column, resolved against the concrete table a row was
|
|
105
|
+
* replicated from.
|
|
106
|
+
*/
|
|
107
|
+
export class RowMetadata extends RowReference {
|
|
108
|
+
kind;
|
|
109
|
+
constructor(syntacticOrigin, resultSet, kind) {
|
|
110
|
+
super(syntacticOrigin, resultSet);
|
|
111
|
+
this.kind = kind;
|
|
112
|
+
}
|
|
113
|
+
equalsAssumingSamePrimaryResultSet(other) {
|
|
114
|
+
// Row metadata is always on the primary result set, so no need to hash the result set here.
|
|
115
|
+
return other instanceof RowMetadata && other.kind == this.kind;
|
|
116
|
+
}
|
|
117
|
+
assumingSamePrimaryResultSetEqualityHashCode(_tableValued, hasher) {
|
|
118
|
+
hasher.addString(`table.${this.kind}`);
|
|
89
119
|
}
|
|
90
120
|
}
|
|
91
121
|
export class ConnectionParameter {
|
|
@@ -95,12 +125,18 @@ export class ConnectionParameter {
|
|
|
95
125
|
this.syntacticOrigin = syntacticOrigin;
|
|
96
126
|
this.source = source;
|
|
97
127
|
}
|
|
98
|
-
|
|
128
|
+
equals(other) {
|
|
99
129
|
return other instanceof ConnectionParameter && other.source == this.source;
|
|
100
130
|
}
|
|
101
|
-
|
|
131
|
+
buildHash(hasher) {
|
|
102
132
|
hasher.addString(this.source);
|
|
103
133
|
}
|
|
134
|
+
equalsAssumingSamePrimaryResultSet(other) {
|
|
135
|
+
return this.equals(other);
|
|
136
|
+
}
|
|
137
|
+
assumingSamePrimaryResultSetEqualityHashCode(_tableValued, hasher) {
|
|
138
|
+
return this.buildHash(hasher);
|
|
139
|
+
}
|
|
104
140
|
}
|
|
105
141
|
/**
|
|
106
142
|
* Tracks the original source location for translated {@link SqlExpression} nodes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../src/compiler/expression.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../src/compiler/expression.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAOhF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,cAAc;IAuCd;IACA;IAvCX,IAAI,CAAU;IACd,cAAc,CAA8B;IAE5C;;;;;;OAMG;IACH,IAAI,GAAG;QACL,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACH,IAAI,aAAa;QACf,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,cAAc,CAAC;QAC7B,CAAC;QAED,MAAM,aAAa,GAAsB,EAAE,CAAC;QAC5C,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED;IACE;;;;OAIG;IACM,IAAoC,EACpC,S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kC,CAAC,KAAqC;QACtE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,4CAA4C,CAAC,YAAyC,EAAE,MAAoB;QAC1G,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IACf,aAAa,GAAG,IAAI,GAAG,EAA0C,CAAC;IAE3E,WAAW,CAAC,MAA8B;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACjD,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAS,CAAC,MAAM,EAAE,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeLocation } from 'pgsql-ast-parser';
|
|
2
|
-
import {
|
|
2
|
+
import { EqualsIgnoringPrimaryResultSet, TableValuedFunctionEquality } from './compatibility.js';
|
|
3
3
|
import { StableHasher } from './equality.js';
|
|
4
4
|
import { ExpressionInput, SyncExpression } from './expression.js';
|
|
5
5
|
import { SourceResultSet } from './table.js';
|
|
@@ -21,7 +21,7 @@ export declare function isBaseTerm(value: unknown): value is BaseTerm;
|
|
|
21
21
|
/**
|
|
22
22
|
* A {@link SyncExpression} that only depends on a single result set or connection data.
|
|
23
23
|
*/
|
|
24
|
-
export declare class SingleDependencyExpression implements
|
|
24
|
+
export declare class SingleDependencyExpression implements EqualsIgnoringPrimaryResultSet {
|
|
25
25
|
readonly expression: SyncExpression;
|
|
26
26
|
/**
|
|
27
27
|
* The single result set on which the expression depends on.
|
|
@@ -34,8 +34,8 @@ export declare class SingleDependencyExpression implements EqualsIgnoringResultS
|
|
|
34
34
|
*/
|
|
35
35
|
readonly dependsOnConnection: boolean;
|
|
36
36
|
constructor(expression: SyncExpression | SingleDependencyExpression);
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
equalsAssumingSamePrimaryResultSet(other: EqualsIgnoringPrimaryResultSet, tableValued: TableValuedFunctionEquality): boolean;
|
|
38
|
+
assumingSamePrimaryResultSetEqualityHashCode(tableValued: TableValuedFunctionEquality, hasher: StableHasher): void;
|
|
39
39
|
/**
|
|
40
40
|
* If all inputs have a single dependency, returns either the result set they all depend on or `null` and whether they
|
|
41
41
|
* depend on connection data.
|
package/dist/compiler/filter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expandNodeLocations } from '../errors.js';
|
|
2
|
-
import {
|
|
2
|
+
import { RowReference, SyncExpression } from './expression.js';
|
|
3
3
|
import { BaseSourceResultSet } from './table.js';
|
|
4
4
|
export function isBaseTerm(value) {
|
|
5
5
|
return value instanceof SingleDependencyExpression || value instanceof EqualsClause;
|
|
@@ -35,11 +35,12 @@ export class SingleDependencyExpression {
|
|
|
35
35
|
this.dependsOnConnection = expression.dependsOnConnection;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
return other instanceof SingleDependencyExpression &&
|
|
38
|
+
equalsAssumingSamePrimaryResultSet(other, tableValued) {
|
|
39
|
+
return (other instanceof SingleDependencyExpression &&
|
|
40
|
+
other.expression.equalsAssumingSamePrimaryResultSet(this.expression, tableValued));
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
this.expression.
|
|
42
|
+
assumingSamePrimaryResultSetEqualityHashCode(tableValued, hasher) {
|
|
43
|
+
this.expression.assumingSamePrimaryResultSetEqualityHashCode(tableValued, hasher);
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* If all inputs have a single dependency, returns either the result set they all depend on or `null` and whether they
|
|
@@ -51,7 +52,7 @@ export class SingleDependencyExpression {
|
|
|
51
52
|
let resultSet = null;
|
|
52
53
|
let hasSubscriptionDependency = false;
|
|
53
54
|
for (const dependency of inputs) {
|
|
54
|
-
if (dependency instanceof
|
|
55
|
+
if (dependency instanceof RowReference) {
|
|
55
56
|
if (hasSubscriptionDependency ||
|
|
56
57
|
(resultSet != null && !BaseSourceResultSet.areCompatible(resultSet, dependency.resultSet))) {
|
|
57
58
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/compiler/filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/compiler/filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAmB,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAmB,MAAM,YAAY,CAAC;AAmBlE,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,0BAA0B,IAAI,KAAK,YAAY,YAAY,CAAC;AACtF,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,0BAA0B;IAC5B,UAAU,CAAiB;IACpC;;;;OAIG;IACM,SAAS,CAAyB;IAE3C;;OAEG;IACM,mBAAmB,CAAU;IAEtC,YAAY,UAAuD;QACjE,IAAI,UAAU,YAAY,cAAc,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,0BAA0B,CAAC,uBAAuB,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;YAC7F,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;gBACpB,MAAM,IAAI,sBAAsB,CAAC,4EAA4E,CAAC,CAAC;YACjH,CAAC;YAED,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAA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SAAS,EAAE,yBAAyB,CAAC,CAAC;IAChD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,0BAA0B;IAG3D,YAAY,UAAuD;QACjE,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC7B,MAAM,IAAI,sBAAsB,CAAC,wCAAwC,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,0BAA0B;IAC/D,YAAY,UAAuD;QACjE,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YAC3B,MAAM,IAAI,sBAAsB,CAAC,oCAAoC,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAY;IAEZ;IACA;IAFX,YACW,IAAgC,EAChC,KAAiC;QADjC,SAAI,GAAJ,IAAI,CAA4B;QAChC,UAAK,GAAL,KAAK,CAA4B;IACzC,CAAC;IAEJ,IAAI,QAAQ;QACV,OAAO,mBAAmB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChH,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as plan from '../sync_plan/plan.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { SyncPlanCompilerModel } from './compiler.js';
|
|
3
3
|
export declare class CompilerModelToSyncPlan {
|
|
4
4
|
private static readonly evaluatorHash;
|
|
5
5
|
private mappedObjects;
|
|
@@ -25,11 +25,12 @@ export declare class CompilerModelToSyncPlan {
|
|
|
25
25
|
*/
|
|
26
26
|
private evaluatorsToBuckets;
|
|
27
27
|
private translateStatefulObject;
|
|
28
|
-
translate(source:
|
|
28
|
+
translate(source: SyncPlanCompilerModel): plan.SyncPlan;
|
|
29
29
|
private createBucketSource;
|
|
30
30
|
private translatePartitionKey;
|
|
31
31
|
private translateAddedTableValuedFunctions;
|
|
32
32
|
private translateRowEvaluator;
|
|
33
|
+
private translateRowProjection;
|
|
33
34
|
private translatePointLookup;
|
|
34
35
|
/**
|
|
35
36
|
* @param expression The expression to translate.
|
|
@@ -42,4 +43,5 @@ export declare class CompilerModelToSyncPlan {
|
|
|
42
43
|
private translateStreamResolver;
|
|
43
44
|
private translateExpandingLookup;
|
|
44
45
|
private translateParameterValue;
|
|
46
|
+
private translateCompiledEvent;
|
|
45
47
|
}
|