@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,131 @@
|
|
|
1
|
+
import { HashSet, StableHasher } from './equality.js';
|
|
2
|
+
import { equalsIgnoringResultSetList, equalsIgnoringResultSetUnordered } from './compatibility.js';
|
|
3
|
+
/**
|
|
4
|
+
* Describes how to resolve a subscription to buckets.
|
|
5
|
+
*/
|
|
6
|
+
export class StreamResolver {
|
|
7
|
+
options;
|
|
8
|
+
requestFilters;
|
|
9
|
+
lookupStages;
|
|
10
|
+
resolvedBucket;
|
|
11
|
+
uniqueName;
|
|
12
|
+
constructor(options, requestFilters, lookupStages, resolvedBucket, uniqueName) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.requestFilters = requestFilters;
|
|
15
|
+
this.lookupStages = lookupStages;
|
|
16
|
+
this.resolvedBucket = resolvedBucket;
|
|
17
|
+
this.uniqueName = uniqueName;
|
|
18
|
+
}
|
|
19
|
+
buildInstantiationHash(hasher) {
|
|
20
|
+
equalsIgnoringResultSetUnordered.hash(hasher, this.requestFilters);
|
|
21
|
+
this.resolvedBucket.buildInstantiationHash(hasher);
|
|
22
|
+
}
|
|
23
|
+
hasIdenticalInstantiation(other) {
|
|
24
|
+
if (other.options != this.options) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (!equalsIgnoringResultSetUnordered.equals(other.requestFilters, this.requestFilters)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return other.resolvedBucket.hasIdenticalInstantiation(this.resolvedBucket);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class ParameterLookup {
|
|
34
|
+
lookup;
|
|
35
|
+
instantiation;
|
|
36
|
+
constructor(lookup, instantiation) {
|
|
37
|
+
this.lookup = lookup;
|
|
38
|
+
this.instantiation = instantiation;
|
|
39
|
+
}
|
|
40
|
+
buildHash(hasher) {
|
|
41
|
+
hasher.addHash(this.lookup.behaviorHashCode);
|
|
42
|
+
hasher.add(...this.instantiation);
|
|
43
|
+
}
|
|
44
|
+
equals(other) {
|
|
45
|
+
return (other instanceof ParameterLookup &&
|
|
46
|
+
other.lookup.behavesIdenticalTo(this.lookup) &&
|
|
47
|
+
StableHasher.defaultListEquality.equals(other.instantiation, this.instantiation));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class EvaluateTableValuedFunction {
|
|
51
|
+
tableValuedFunction;
|
|
52
|
+
outputs;
|
|
53
|
+
filters;
|
|
54
|
+
constructor(tableValuedFunction, outputs, filters) {
|
|
55
|
+
this.tableValuedFunction = tableValuedFunction;
|
|
56
|
+
this.outputs = outputs;
|
|
57
|
+
this.filters = filters;
|
|
58
|
+
}
|
|
59
|
+
buildHash(hasher) {
|
|
60
|
+
this.tableValuedFunction.buildBehaviorHashCode(hasher);
|
|
61
|
+
equalsIgnoringResultSetList.hash(hasher, this.outputs);
|
|
62
|
+
equalsIgnoringResultSetList.hash(hasher, this.filters);
|
|
63
|
+
}
|
|
64
|
+
equals(other) {
|
|
65
|
+
return (other instanceof EvaluateTableValuedFunction &&
|
|
66
|
+
other.tableValuedFunction.behavesIdenticalTo(this.tableValuedFunction) &&
|
|
67
|
+
equalsIgnoringResultSetList.equals(other.outputs, this.outputs) &&
|
|
68
|
+
equalsIgnoringResultSetList.equals(other.filters, this.filters));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class ResolveBucket {
|
|
72
|
+
instantiation;
|
|
73
|
+
evaluators = new HashSet({
|
|
74
|
+
hash: (hasher, value) => value.buildBehaviorHashCode(hasher),
|
|
75
|
+
equals: (a, b) => a.behavesIdenticalTo(b)
|
|
76
|
+
});
|
|
77
|
+
constructor(evaluator, instantiation) {
|
|
78
|
+
this.instantiation = instantiation;
|
|
79
|
+
this.evaluators.add(evaluator);
|
|
80
|
+
}
|
|
81
|
+
buildInstantiationHash(hasher) {
|
|
82
|
+
hasher.add(...this.instantiation);
|
|
83
|
+
}
|
|
84
|
+
hasIdenticalInstantiation(other) {
|
|
85
|
+
return StableHasher.defaultListEquality.equals(other.instantiation, this.instantiation);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A value derived from request data.
|
|
90
|
+
*/
|
|
91
|
+
export class RequestParameterValue {
|
|
92
|
+
expression;
|
|
93
|
+
constructor(expression) {
|
|
94
|
+
this.expression = expression;
|
|
95
|
+
}
|
|
96
|
+
buildHash(hasher) {
|
|
97
|
+
this.expression.assumingSameResultSetEqualityHashCode(hasher);
|
|
98
|
+
}
|
|
99
|
+
equals(other) {
|
|
100
|
+
return other instanceof RequestParameterValue && other.expression.equalsAssumingSameResultSet(this.expression);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export class LookupResultParameterValue {
|
|
104
|
+
resultIndex;
|
|
105
|
+
lookup; // Set lazily
|
|
106
|
+
constructor(resultIndex) {
|
|
107
|
+
this.resultIndex = resultIndex;
|
|
108
|
+
}
|
|
109
|
+
buildHash(hasher) {
|
|
110
|
+
this.lookup?.buildHash(hasher);
|
|
111
|
+
hasher.addHash(this.resultIndex);
|
|
112
|
+
}
|
|
113
|
+
equals(other) {
|
|
114
|
+
return (other instanceof LookupResultParameterValue &&
|
|
115
|
+
other.lookup.equals(this.lookup) &&
|
|
116
|
+
other.resultIndex == this.resultIndex);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export class IntersectionParameterValue {
|
|
120
|
+
inner;
|
|
121
|
+
constructor(inner) {
|
|
122
|
+
this.inner = inner;
|
|
123
|
+
}
|
|
124
|
+
buildHash(hasher) {
|
|
125
|
+
hasher.add(...this.inner);
|
|
126
|
+
}
|
|
127
|
+
equals(other) {
|
|
128
|
+
return (other instanceof IntersectionParameterValue && StableHasher.defaultListEquality.equals(other.inner, this.inner));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=bucket_resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bucket_resolver.js","sourceRoot":"","sources":["../../src/compiler/bucket_resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAMnG;;GAEG;AACH,MAAM,OAAO,cAAc;IAEd;IACA;IACA;IACA;IACA;IALX,YACW,OAAsB,EACtB,cAAmC,EACnC,YAAiC,EACjC,cAA6B,EAC7B,UAAkB;QAJlB,YAAO,GAAP,OAAO,CAAe;QACtB,mBAAc,GAAd,cAAc,CAAqB;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G,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,KAAc;QACnB,OAAO,CACL,KAAK,YAAY,0BAA0B,IAAI,YAAY,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAChH,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Equality, StableHasher } from './equality.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for structures that can be compared for equality in a way that ignores referenced result set.
|
|
4
|
+
*
|
|
5
|
+
* This is primarily used to compare expressions across streams. If we have two streams defined as
|
|
6
|
+
* `SELECT * FROM users WHERE id = ...` , the `id` column would not be equal between those since it references a the
|
|
7
|
+
* logical `users` table added to each individual statement. But if we are in a context where we know the physical table
|
|
8
|
+
* is the same, this allows comparing expressions for equality.
|
|
9
|
+
*/
|
|
10
|
+
export interface EqualsIgnoringResultSet {
|
|
11
|
+
equalsAssumingSameResultSet(other: EqualsIgnoringResultSet): boolean;
|
|
12
|
+
assumingSameResultSetEqualityHashCode(hasher: StableHasher): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const equalsIgnoringResultSet: Equality<EqualsIgnoringResultSet>;
|
|
15
|
+
export declare const equalsIgnoringResultSetList: Equality<Iterable<EqualsIgnoringResultSet>>;
|
|
16
|
+
export declare const equalsIgnoringResultSetUnordered: Equality<Iterable<EqualsIgnoringResultSet>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { listEquality } from './equality.js';
|
|
2
|
+
export const equalsIgnoringResultSet = {
|
|
3
|
+
equals: function (a, b) {
|
|
4
|
+
return a.equalsAssumingSameResultSet(b);
|
|
5
|
+
},
|
|
6
|
+
hash: function (hasher, value) {
|
|
7
|
+
return value.assumingSameResultSetEqualityHashCode(hasher);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export const equalsIgnoringResultSetList = listEquality(equalsIgnoringResultSet);
|
|
11
|
+
export const equalsIgnoringResultSetUnordered = listEquality(equalsIgnoringResultSet);
|
|
12
|
+
//# sourceMappingURL=compatibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility.js","sourceRoot":"","sources":["../../src/compiler/compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,YAAY,EAAgB,MAAM,eAAe,CAAC;AAerE,MAAM,CAAC,MAAM,uBAAuB,GAAsC;IACxE,MAAM,EAAE,UAAU,CAA0B,EAAE,CAA0B;QACtE,OAAO,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,IAAI,EAAE,UAAU,MAAoB,EAAE,KAA8B;QAClE,OAAO,KAAK,CAAC,qCAAqC,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,YAAY,CAAC,uBAAuB,CAAC,CAAC;AACjF,MAAM,CAAC,MAAM,gCAAgC,GAAG,YAAY,CAAC,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { NodeLocation, PGNode } from 'pgsql-ast-parser';
|
|
2
|
+
import { PointLookup, RowEvaluator } from './rows.js';
|
|
3
|
+
import { StreamResolver } from './bucket_resolver.js';
|
|
4
|
+
import { StreamOptions, SyncPlan } from '../sync_plan/plan.js';
|
|
5
|
+
import { PreparedSubquery } from './sqlite.js';
|
|
6
|
+
import { SourceSchema } from '../types.js';
|
|
7
|
+
export interface SyncStreamsCompilerOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Used exclusively for linting against the given {@link schema}.
|
|
10
|
+
*
|
|
11
|
+
* The default schema must not affect compiled sync plans because sync plans can be loaded with different default
|
|
12
|
+
* schemas.
|
|
13
|
+
*/
|
|
14
|
+
defaultSchema?: string;
|
|
15
|
+
/**
|
|
16
|
+
* An optional schema, used exclusively for linting table and column references that can't be resolved in it.
|
|
17
|
+
*
|
|
18
|
+
* Sync streams compile to the same plan regardless of the assumed schema, and it's possible to reuse compiled sync
|
|
19
|
+
* streams across schema changes.
|
|
20
|
+
*/
|
|
21
|
+
schema?: SourceSchema;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* State for compiling sync streams.
|
|
25
|
+
*
|
|
26
|
+
* The output of compiling all sync streams is a {@link SyncPlan}, a declarative description of the sync process that
|
|
27
|
+
* can be serialized to bucket storage. The compiler stores a mutable intermediate representation that is essentially a
|
|
28
|
+
* copy of the sync plan, except that we're using JavaScript classes with methods to compute hash codes and equality
|
|
29
|
+
* relations. This allows the compiler to efficiently de-duplicate parameters and buckets.
|
|
30
|
+
*
|
|
31
|
+
* Overall, the compilation process is as follows: Each data query for a stream is first parsed by
|
|
32
|
+
* {@link StreamQueryParser} into a canonicalized intermediate representation (see that class for details).
|
|
33
|
+
* Then, {@link QuerierGraphBuilder} analyzes a chain of `AND` expressions to identify parameters (as partition keys)
|
|
34
|
+
* and their instantiation, as well as static filters that need to be added to reach row.
|
|
35
|
+
*/
|
|
36
|
+
export declare class SyncStreamsCompiler {
|
|
37
|
+
readonly options: SyncStreamsCompilerOptions;
|
|
38
|
+
readonly output: CompiledStreamQueries;
|
|
39
|
+
private readonly locations;
|
|
40
|
+
constructor(options: SyncStreamsCompilerOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Tries to parse the SQL query as a `SELECT` statement into a form supported for common table expressions.
|
|
43
|
+
*
|
|
44
|
+
* Common table expressions are parsed and validated independently and without a shared scope, meaning that CTEs are
|
|
45
|
+
* not allowed to reference other CTEs. This limitation is deliberate, but we _could_ support it (referenced CTEs
|
|
46
|
+
* would just get inlined into the new CTE by the parser). So we can revisit this and potentially support that in the
|
|
47
|
+
* future.
|
|
48
|
+
*
|
|
49
|
+
* Returns null and reports errors if that fails.
|
|
50
|
+
*/
|
|
51
|
+
commonTableExpression(sql: string, errors: ParsingErrorListener): PreparedSubquery | null;
|
|
52
|
+
/**
|
|
53
|
+
* Utility for compiling a sync stream.
|
|
54
|
+
*
|
|
55
|
+
* @param options Name, priority and `auto_subscribe` state for the stream.
|
|
56
|
+
*/
|
|
57
|
+
stream(options: StreamOptions): IndividualSyncStreamCompiler;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Utility for compiling a single sync stream.
|
|
61
|
+
*/
|
|
62
|
+
export interface IndividualSyncStreamCompiler {
|
|
63
|
+
/**
|
|
64
|
+
* Makes a common table expression prepared through {@link SyncStreamsCompiler.commonTableExpression} available when
|
|
65
|
+
* parsing queries for this stream.
|
|
66
|
+
*/
|
|
67
|
+
registerCommonTableExpression(name: string, cte: PreparedSubquery): void;
|
|
68
|
+
/**
|
|
69
|
+
* Validates and adds a parameter query to this stream.
|
|
70
|
+
*
|
|
71
|
+
* @param sql The SQL query to add.
|
|
72
|
+
* @param errors An error reporter associating source positions with the current SQL source.
|
|
73
|
+
*/
|
|
74
|
+
addQuery(sql: string, errors: ParsingErrorListener): void;
|
|
75
|
+
/**
|
|
76
|
+
* Merges added queries into compatible bucket groups and adds them to the compiled sync plan.
|
|
77
|
+
*/
|
|
78
|
+
finish(): void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Something reporting errors.
|
|
82
|
+
*
|
|
83
|
+
* While sync streams can be made up of multiple SQL statements from different YAML strings, we want to be able to
|
|
84
|
+
* accurately describe the source of an error in YAML when we report it.
|
|
85
|
+
*
|
|
86
|
+
* So, every transformation that might need to report errors receives an instance of this interface which implicitly
|
|
87
|
+
* binds errors to one specific SQL string.
|
|
88
|
+
*/
|
|
89
|
+
export interface ParsingErrorListener {
|
|
90
|
+
report(message: string, location: NodeLocation | PGNode, options?: {
|
|
91
|
+
isWarning: boolean;
|
|
92
|
+
}): void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A mutable collection of resources (row evaluators, point lookups and stream resolvers) created for all streams in a
|
|
96
|
+
* definition file.
|
|
97
|
+
*/
|
|
98
|
+
export declare class CompiledStreamQueries {
|
|
99
|
+
private readonly _evaluators;
|
|
100
|
+
private readonly _pointLookups;
|
|
101
|
+
readonly resolvers: StreamResolver[];
|
|
102
|
+
get evaluators(): RowEvaluator[];
|
|
103
|
+
get pointLookups(): PointLookup[];
|
|
104
|
+
canonicalizeEvaluator(evaluator: RowEvaluator): RowEvaluator;
|
|
105
|
+
canonicalizePointLookup(lookup: PointLookup): PointLookup;
|
|
106
|
+
/**
|
|
107
|
+
* @returns A sync plan representing an immutable snapshot of this intermediate representation.
|
|
108
|
+
*/
|
|
109
|
+
toSyncPlan(): SyncPlan;
|
|
110
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { parse } from 'pgsql-ast-parser';
|
|
2
|
+
import { HashSet } from './equality.js';
|
|
3
|
+
import { CompilerModelToSyncPlan } from './ir_to_sync_plan.js';
|
|
4
|
+
import { QuerierGraphBuilder } from './querier_graph.js';
|
|
5
|
+
import { StreamQueryParser } from './parser.js';
|
|
6
|
+
import { NodeLocations } from './expression.js';
|
|
7
|
+
import { SqlScope } from './scope.js';
|
|
8
|
+
/**
|
|
9
|
+
* State for compiling sync streams.
|
|
10
|
+
*
|
|
11
|
+
* The output of compiling all sync streams is a {@link SyncPlan}, a declarative description of the sync process that
|
|
12
|
+
* can be serialized to bucket storage. The compiler stores a mutable intermediate representation that is essentially a
|
|
13
|
+
* copy of the sync plan, except that we're using JavaScript classes with methods to compute hash codes and equality
|
|
14
|
+
* relations. This allows the compiler to efficiently de-duplicate parameters and buckets.
|
|
15
|
+
*
|
|
16
|
+
* Overall, the compilation process is as follows: Each data query for a stream is first parsed by
|
|
17
|
+
* {@link StreamQueryParser} into a canonicalized intermediate representation (see that class for details).
|
|
18
|
+
* Then, {@link QuerierGraphBuilder} analyzes a chain of `AND` expressions to identify parameters (as partition keys)
|
|
19
|
+
* and their instantiation, as well as static filters that need to be added to reach row.
|
|
20
|
+
*/
|
|
21
|
+
export class SyncStreamsCompiler {
|
|
22
|
+
options;
|
|
23
|
+
output = new CompiledStreamQueries();
|
|
24
|
+
locations = new NodeLocations();
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Tries to parse the SQL query as a `SELECT` statement into a form supported for common table expressions.
|
|
30
|
+
*
|
|
31
|
+
* Common table expressions are parsed and validated independently and without a shared scope, meaning that CTEs are
|
|
32
|
+
* not allowed to reference other CTEs. This limitation is deliberate, but we _could_ support it (referenced CTEs
|
|
33
|
+
* would just get inlined into the new CTE by the parser). So we can revisit this and potentially support that in the
|
|
34
|
+
* future.
|
|
35
|
+
*
|
|
36
|
+
* Returns null and reports errors if that fails.
|
|
37
|
+
*/
|
|
38
|
+
commonTableExpression(sql, errors) {
|
|
39
|
+
const parser = new StreamQueryParser({
|
|
40
|
+
compiler: this,
|
|
41
|
+
originalText: sql,
|
|
42
|
+
locations: this.locations,
|
|
43
|
+
parentScope: new SqlScope({}),
|
|
44
|
+
errors
|
|
45
|
+
});
|
|
46
|
+
const stmt = tryParse(sql, errors);
|
|
47
|
+
if (stmt == null) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return parser.parseAsSubquery(stmt);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Utility for compiling a sync stream.
|
|
54
|
+
*
|
|
55
|
+
* @param options Name, priority and `auto_subscribe` state for the stream.
|
|
56
|
+
*/
|
|
57
|
+
stream(options) {
|
|
58
|
+
const builder = new QuerierGraphBuilder(this, options);
|
|
59
|
+
const rootScope = new SqlScope({});
|
|
60
|
+
return {
|
|
61
|
+
registerCommonTableExpression: (name, cte) => {
|
|
62
|
+
rootScope.registerCommonTableExpression(name, cte);
|
|
63
|
+
},
|
|
64
|
+
addQuery: (sql, errors) => {
|
|
65
|
+
const stmt = tryParse(sql, errors);
|
|
66
|
+
if (stmt == null) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const parser = new StreamQueryParser({
|
|
70
|
+
compiler: this,
|
|
71
|
+
originalText: sql,
|
|
72
|
+
locations: this.locations,
|
|
73
|
+
parentScope: rootScope,
|
|
74
|
+
errors
|
|
75
|
+
});
|
|
76
|
+
const query = parser.parse(stmt);
|
|
77
|
+
if (query) {
|
|
78
|
+
builder.process(query, errors);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
finish: () => builder.finish()
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function tryParse(sql, errors) {
|
|
86
|
+
try {
|
|
87
|
+
const [stmt] = parse(sql, { locationTracking: true });
|
|
88
|
+
return stmt;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
const location = e.token?._location;
|
|
92
|
+
errors.report(e.message, location ?? { start: 0, end: sql.length });
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A mutable collection of resources (row evaluators, point lookups and stream resolvers) created for all streams in a
|
|
98
|
+
* definition file.
|
|
99
|
+
*/
|
|
100
|
+
export class CompiledStreamQueries {
|
|
101
|
+
_evaluators = new HashSet({
|
|
102
|
+
hash: (hasher, value) => value.buildBehaviorHashCode(hasher),
|
|
103
|
+
equals: (a, b) => a.behavesIdenticalTo(b)
|
|
104
|
+
});
|
|
105
|
+
_pointLookups = new HashSet({
|
|
106
|
+
hash: (hasher, value) => value.buildBehaviorHashCode(hasher),
|
|
107
|
+
equals: (a, b) => a.behavesIdenticalTo(b)
|
|
108
|
+
});
|
|
109
|
+
resolvers = [];
|
|
110
|
+
get evaluators() {
|
|
111
|
+
return [...this._evaluators];
|
|
112
|
+
}
|
|
113
|
+
get pointLookups() {
|
|
114
|
+
return [...this._pointLookups];
|
|
115
|
+
}
|
|
116
|
+
canonicalizeEvaluator(evaluator) {
|
|
117
|
+
return this._evaluators.getOrInsert(evaluator)[0];
|
|
118
|
+
}
|
|
119
|
+
canonicalizePointLookup(lookup) {
|
|
120
|
+
return this._pointLookups.getOrInsert(lookup)[0];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @returns A sync plan representing an immutable snapshot of this intermediate representation.
|
|
124
|
+
*/
|
|
125
|
+
toSyncPlan() {
|
|
126
|
+
const translator = new CompilerModelToSyncPlan();
|
|
127
|
+
return translator.translate(this);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAsBtC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,mBAAmB;IAIT;IAHZ,MAAM,GAAG,IAAI,qBAAqB,EAAE,CAAC;IAC7B,SAAS,GAAG,IAAI,aAAa,EAAE,CAAC;IAEjD,YAAqB,OAAmC;QAAnC,YAAO,GAAP,OAAO,CAA4B;IAAG,CAAC;IAE5D;;;;;;;;;OASG;IACH,qBAAqB,CAAC,GAAW,EAAE,MAA4B;QAC7D,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC;YACnC,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,GAAG;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,WAAW,EAAE,IAAI,QAAQ,CAAC,EAAE,CAAC;YAC7B,MAAM;SACP,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,QAAQ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,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;IAED;;OAEG;IACH,UAAU;QACR,MAAM,UAAU,GAAG,IAAI,uBAAuB,EAAE,CAAC;QACjD,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable value-based hashcodes for JavaScript. The sync streams compiler uses hashmaps derived from this to efficiently
|
|
3
|
+
* de-duplicate equivalent expressions and lookups.
|
|
4
|
+
*
|
|
5
|
+
* This is copied from Dart SDK sources, which in turn based the algorithm on Jenkins hash functions.
|
|
6
|
+
*
|
|
7
|
+
* Because hash codes are stable across restarts, they should not be used for untrusted inputs to avoid attacks
|
|
8
|
+
* provoking hash collisions and subpar hashmap performance. The sync rules package only uses these hashes to compile
|
|
9
|
+
* sync streams, but the compiled IR processing source rows does not need these hashes.
|
|
10
|
+
*/
|
|
11
|
+
export declare class StableHasher {
|
|
12
|
+
private static readonly seed;
|
|
13
|
+
private hash;
|
|
14
|
+
addHash(value: number): void;
|
|
15
|
+
reset(): number;
|
|
16
|
+
addString(value: string): void;
|
|
17
|
+
add(...e: Equatable[]): void;
|
|
18
|
+
buildHashCode(): number;
|
|
19
|
+
/**
|
|
20
|
+
* Hashes a value under the given equality implementation.
|
|
21
|
+
*/
|
|
22
|
+
static hashWith<T>(equality: Equality<T>, value: T): number;
|
|
23
|
+
private static readonly hasher;
|
|
24
|
+
/**
|
|
25
|
+
* The default equality for {@link Equatable} types.
|
|
26
|
+
*/
|
|
27
|
+
private static readonly defaultEquality;
|
|
28
|
+
static readonly defaultListEquality: Equality<Iterable<Equatable>>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A generic equality relation on objects.
|
|
32
|
+
*/
|
|
33
|
+
export interface Equality<T> {
|
|
34
|
+
/**
|
|
35
|
+
* Checks whether a and b are equal according to this equality implementation.
|
|
36
|
+
*
|
|
37
|
+
* This must hold the usual properties for equality relations (reflexivity, symmetry and transitivety).
|
|
38
|
+
*/
|
|
39
|
+
equals(a: T, b: T): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Adds a value to a stable hasher.
|
|
42
|
+
*
|
|
43
|
+
* The implementation of hashes must be compatible with {@link equals}, meaning that if values `a` and `b` are equal,
|
|
44
|
+
* they must also generate the same hash. Two distinct values may also generate the same hashcode though.
|
|
45
|
+
*/
|
|
46
|
+
hash(hasher: StableHasher, value: T): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Interface for objects that have a logical default equality.
|
|
50
|
+
*/
|
|
51
|
+
export interface Equatable {
|
|
52
|
+
buildHash(hasher: StableHasher): void;
|
|
53
|
+
equals(other: unknown): boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates an equality operator matching iterables with elements compared by an inner equality.
|
|
57
|
+
*
|
|
58
|
+
* Two iterables are considered equal if they contain the same elements in the same order.
|
|
59
|
+
*/
|
|
60
|
+
export declare function listEquality<E>(equality: Equality<E>): Equality<Iterable<E>>;
|
|
61
|
+
/**
|
|
62
|
+
* Creates an equality operator matching iterables with elements compared by an inner equality.
|
|
63
|
+
*
|
|
64
|
+
* Two iterables are considered equal if they contain the same elements, in any order.
|
|
65
|
+
*/
|
|
66
|
+
export declare function unorderedEquality<E>(equality: Equality<E>): Equality<Iterable<E>>;
|
|
67
|
+
/**
|
|
68
|
+
* A hash map implementation based on a custom {@link Equality}.
|
|
69
|
+
*
|
|
70
|
+
* Like {@link Map}, this implementation also preserves insertion-order.
|
|
71
|
+
*/
|
|
72
|
+
export declare class HashMap<K, V> {
|
|
73
|
+
private readonly equality;
|
|
74
|
+
private readonly map;
|
|
75
|
+
private first;
|
|
76
|
+
private last;
|
|
77
|
+
constructor(equality: Equality<K>);
|
|
78
|
+
private computeHashCode;
|
|
79
|
+
get isEmpty(): boolean;
|
|
80
|
+
get entries(): Iterable<[K, V]>;
|
|
81
|
+
private iterateEntries;
|
|
82
|
+
get(key: K): V | undefined;
|
|
83
|
+
set(key: K, value: V): void;
|
|
84
|
+
setOrUpdate(key: K, updater: (old: V | undefined, oldKey: K | undefined) => V): void;
|
|
85
|
+
putIfAbsent(key: K, ifAbsent: () => V): V;
|
|
86
|
+
private addEntryInBucket;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* An insertion-order preserving hash set implementation based on {@link HashMap}.
|
|
90
|
+
*/
|
|
91
|
+
export declare class HashSet<K> implements Iterable<K> {
|
|
92
|
+
private readonly inner;
|
|
93
|
+
constructor(equality: Equality<K>);
|
|
94
|
+
[Symbol.iterator](): Iterator<K>;
|
|
95
|
+
private entries;
|
|
96
|
+
add(element: K): boolean;
|
|
97
|
+
getOrInsert(element: K): [K, boolean];
|
|
98
|
+
private static readonly sentinel;
|
|
99
|
+
}
|