@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,22 @@
|
|
|
1
|
+
import { SyntacticResultSetSource } from './table.js';
|
|
2
|
+
import { ParsingErrorListener } from './compiler.js';
|
|
3
|
+
import { PreparedSubquery } from './sqlite.js';
|
|
4
|
+
/**
|
|
5
|
+
* Utilities for resolving references in SQL statements where multiple tables are in scope.
|
|
6
|
+
*
|
|
7
|
+
* Tables are added to the scope when processing `FROM` clauses.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SqlScope {
|
|
10
|
+
readonly parent?: SqlScope;
|
|
11
|
+
private readonly nameToResultSet;
|
|
12
|
+
private readonly commonTableExpressions;
|
|
13
|
+
constructor(options: {
|
|
14
|
+
parent?: SqlScope;
|
|
15
|
+
});
|
|
16
|
+
get rootScope(): SqlScope;
|
|
17
|
+
get resultSets(): SyntacticResultSetSource[];
|
|
18
|
+
registerResultSet(errors: ParsingErrorListener, name: string, source: SyntacticResultSetSource): void;
|
|
19
|
+
resolveResultSetForReference(name: string): SyntacticResultSetSource | undefined;
|
|
20
|
+
registerCommonTableExpression(name: string, subquery: PreparedSubquery): void;
|
|
21
|
+
resolveCommonTableExpression(name: string): PreparedSubquery | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for resolving references in SQL statements where multiple tables are in scope.
|
|
3
|
+
*
|
|
4
|
+
* Tables are added to the scope when processing `FROM` clauses.
|
|
5
|
+
*/
|
|
6
|
+
export class SqlScope {
|
|
7
|
+
parent;
|
|
8
|
+
nameToResultSet = new Map();
|
|
9
|
+
commonTableExpressions = new Map();
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.parent = options.parent;
|
|
12
|
+
}
|
|
13
|
+
get rootScope() {
|
|
14
|
+
let maybeRoot = this;
|
|
15
|
+
while (maybeRoot.parent) {
|
|
16
|
+
maybeRoot = maybeRoot.parent;
|
|
17
|
+
}
|
|
18
|
+
return maybeRoot;
|
|
19
|
+
}
|
|
20
|
+
get resultSets() {
|
|
21
|
+
return [...this.nameToResultSet.values()];
|
|
22
|
+
}
|
|
23
|
+
registerResultSet(errors, name, source) {
|
|
24
|
+
const lower = name.toLowerCase();
|
|
25
|
+
if (this.nameToResultSet.has(lower)) {
|
|
26
|
+
errors.report(`Table with name ${name} already exists in scope`, source.origin);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.nameToResultSet.set(lower, source);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
resolveResultSetForReference(name) {
|
|
34
|
+
return this.nameToResultSet.get(name.toLowerCase()) ?? this.parent?.resolveResultSetForReference(name);
|
|
35
|
+
}
|
|
36
|
+
registerCommonTableExpression(name, subquery) {
|
|
37
|
+
this.commonTableExpressions.set(name.toLowerCase(), subquery);
|
|
38
|
+
}
|
|
39
|
+
resolveCommonTableExpression(name) {
|
|
40
|
+
const inThisScope = this.commonTableExpressions.get(name.toLowerCase());
|
|
41
|
+
if (inThisScope) {
|
|
42
|
+
return inThisScope;
|
|
43
|
+
}
|
|
44
|
+
return this.parent ? this.parent.resolveCommonTableExpression(name) : null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/compiler/scope.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACV,MAAM,CAAY;IACV,eAAe,GAAG,IAAI,GAAG,EAAoC,CAAC;IAC9D,sBAAsB,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE9E,YAAY,OAA8B;QACxC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,IAAI,SAAS;QACX,IAAI,SAAS,GAAa,IAAI,CAAC;QAC/B,OAAO,SAAS,CAAC,MAAM,EAAE,CAAC;YACxB,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;QAC/B,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,iBAAiB,CAAC,MAA4B,EAAE,IAAY,EAAE,MAAgC;QAC5F,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACpC,MAAM,CAAC,MAAM,CAAC,mBAAmB,IAAI,0BAA0B,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YAChF,OAAO;QACT,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,4BAA4B,CAAC,IAAY;QACvC,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,4BAA4B,CAAC,IAAI,CAAC,CAAC;IACzG,CAAC;IAED,6BAA6B,CAAC,IAAY,EAAE,QAA0B;QACpE,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;IAChE,CAAC;IAED,4BAA4B,CAAC,IAAY;QACvC,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QACxE,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7E,CAAC;CACF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Expr, ExprRef, nil, SelectFromStatement } from 'pgsql-ast-parser';
|
|
2
|
+
import { ExpressionInput, NodeLocations, SyncExpression } from './expression.js';
|
|
3
|
+
import { SqlExpression } from '../sync_plan/expression.js';
|
|
4
|
+
import { ParsingErrorListener } from './compiler.js';
|
|
5
|
+
import { SourceResultSet, SyntacticResultSetSource } from './table.js';
|
|
6
|
+
import { SqlScope } from './scope.js';
|
|
7
|
+
export interface ResolvedSubqueryExpression {
|
|
8
|
+
filters: SqlExpression<ExpressionInput>[];
|
|
9
|
+
output: SqlExpression<ExpressionInput>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A prepared subquery or common table expression.
|
|
13
|
+
*/
|
|
14
|
+
export interface PreparedSubquery {
|
|
15
|
+
/**
|
|
16
|
+
* Columns selected by the query, indexed by their name.
|
|
17
|
+
*/
|
|
18
|
+
resultColumns: Record<string, SqlExpression<ExpressionInput>>;
|
|
19
|
+
/**
|
|
20
|
+
* Tables the subquery selects from.
|
|
21
|
+
*/
|
|
22
|
+
tables: Map<SyntacticResultSetSource, SourceResultSet>;
|
|
23
|
+
/**
|
|
24
|
+
* Filters affecting the subquery.
|
|
25
|
+
*/
|
|
26
|
+
where: SqlExpression<ExpressionInput> | null;
|
|
27
|
+
}
|
|
28
|
+
export interface PostgresToSqliteOptions {
|
|
29
|
+
readonly originalText: string;
|
|
30
|
+
readonly scope: SqlScope;
|
|
31
|
+
readonly errors: ParsingErrorListener;
|
|
32
|
+
readonly locations: NodeLocations;
|
|
33
|
+
/**
|
|
34
|
+
* Attempt to resolve a table name in scope, returning the resolved result set.
|
|
35
|
+
*
|
|
36
|
+
* Should report an error if resolving the table failed, using `node` as the source location for the error.
|
|
37
|
+
*/
|
|
38
|
+
resolveTableName(node: ExprRef, name: string | nil): SourceResultSet | PreparedSubquery | null;
|
|
39
|
+
/**
|
|
40
|
+
* Generates a table alias for synthetic subqueries like those generated to desugar `IN` expressions to `json_each`
|
|
41
|
+
* subqueries.
|
|
42
|
+
*/
|
|
43
|
+
generateTableAlias(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Turns the given subquery into a join added to the main `FROM` section.
|
|
46
|
+
*
|
|
47
|
+
* Returns the parsed subquery expression, or null if resolving the subquery failed. In that case, this method should
|
|
48
|
+
* report an error.
|
|
49
|
+
*/
|
|
50
|
+
joinSubqueryExpression(expr: SelectFromStatement): ResolvedSubqueryExpression | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validates and lowers a Postgres expression into a scalar SQL expression.
|
|
54
|
+
*
|
|
55
|
+
* Unsupported Postgres features are reported as errors.
|
|
56
|
+
*/
|
|
57
|
+
export declare class PostgresToSqlite {
|
|
58
|
+
private readonly options;
|
|
59
|
+
constructor(options: PostgresToSqliteOptions);
|
|
60
|
+
translateExpression(source: Expr): SyncExpression;
|
|
61
|
+
private translateNodeWithLocation;
|
|
62
|
+
private translateToNode;
|
|
63
|
+
private invalidExpression;
|
|
64
|
+
private translateInExpression;
|
|
65
|
+
private desugarInValues;
|
|
66
|
+
private desugarInSubquery;
|
|
67
|
+
/**
|
|
68
|
+
* Desugar `$left IN $right`, where `$right` is a scalar expression. This is not valid SQL, but in PowerSync we
|
|
69
|
+
* interpret that as `left IN (SELECT value FROM json_each(right))`.
|
|
70
|
+
*/
|
|
71
|
+
private desugarInScalar;
|
|
72
|
+
/**
|
|
73
|
+
* Desugar `$left IN cteName` to `$left IN (SELECT cteName.onlyColumn FROM cteName)`.
|
|
74
|
+
*/
|
|
75
|
+
private desugarInCte;
|
|
76
|
+
private translateRequestParameter;
|
|
77
|
+
}
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { CAST_TYPES } from '../sql_functions.js';
|
|
2
|
+
import { ColumnInRow, ConnectionParameter, SyncExpression } from './expression.js';
|
|
3
|
+
import { supportedFunctions } from '../sync_plan/expression.js';
|
|
4
|
+
import { BaseSourceResultSet, PhysicalSourceResultSet } from './table.js';
|
|
5
|
+
/**
|
|
6
|
+
* Validates and lowers a Postgres expression into a scalar SQL expression.
|
|
7
|
+
*
|
|
8
|
+
* Unsupported Postgres features are reported as errors.
|
|
9
|
+
*/
|
|
10
|
+
export class PostgresToSqlite {
|
|
11
|
+
options;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
translateExpression(source) {
|
|
16
|
+
return new SyncExpression(this.translateNodeWithLocation(source), this.options.locations);
|
|
17
|
+
}
|
|
18
|
+
translateNodeWithLocation(expr) {
|
|
19
|
+
const translated = this.translateToNode(expr);
|
|
20
|
+
this.options.locations.sourceForNode.set(translated, expr);
|
|
21
|
+
return translated;
|
|
22
|
+
}
|
|
23
|
+
translateToNode(expr) {
|
|
24
|
+
switch (expr.type) {
|
|
25
|
+
case 'null':
|
|
26
|
+
return { type: 'lit_null' };
|
|
27
|
+
case 'boolean':
|
|
28
|
+
return { type: 'lit_int', base10: expr.value ? '1' : '0' };
|
|
29
|
+
case 'string':
|
|
30
|
+
return { type: 'lit_string', value: expr.value };
|
|
31
|
+
case 'numeric': {
|
|
32
|
+
return { type: 'lit_double', value: expr.value };
|
|
33
|
+
}
|
|
34
|
+
case 'integer': {
|
|
35
|
+
// JavaScript does not have a number type that can represent SQLite ints, so we try to reuse the source.
|
|
36
|
+
if (expr._location) {
|
|
37
|
+
return {
|
|
38
|
+
type: 'lit_int',
|
|
39
|
+
base10: this.options.originalText.substring(expr._location.start, expr._location.end)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return { type: 'lit_int', base10: expr.value.toString() };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
case 'ref': {
|
|
47
|
+
const resultSet = this.options.resolveTableName(expr, expr.table?.name);
|
|
48
|
+
if (resultSet == null) {
|
|
49
|
+
// resolveTableName will have logged an error, transform with a bogus value to keep going.
|
|
50
|
+
return { type: 'lit_null' };
|
|
51
|
+
}
|
|
52
|
+
if (expr.name == '*') {
|
|
53
|
+
return this.invalidExpression(expr, '* columns are not supported here');
|
|
54
|
+
}
|
|
55
|
+
// If this references something from a source table, warn if that column doesn't exist.
|
|
56
|
+
if (resultSet instanceof PhysicalSourceResultSet && resultSet.schemaTablesForWarnings.length) {
|
|
57
|
+
let columnExistsInAnySourceTable = false;
|
|
58
|
+
for (const table of resultSet.schemaTablesForWarnings) {
|
|
59
|
+
if (table.getColumn(expr.name) != null) {
|
|
60
|
+
columnExistsInAnySourceTable = true;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!columnExistsInAnySourceTable) {
|
|
65
|
+
this.options.errors.report('Column not found.', expr, { isWarning: true });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (resultSet instanceof BaseSourceResultSet) {
|
|
69
|
+
// This is an actual result set.
|
|
70
|
+
const instantiation = new ColumnInRow(expr, resultSet, expr.name);
|
|
71
|
+
return {
|
|
72
|
+
type: 'data',
|
|
73
|
+
source: instantiation
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Resolved to a subquery, inline the reference.
|
|
78
|
+
const expression = resultSet.resultColumns[expr.name];
|
|
79
|
+
if (expression == null) {
|
|
80
|
+
return this.invalidExpression(expr, 'Column not found in subquery.');
|
|
81
|
+
}
|
|
82
|
+
return expression;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
case 'parameter':
|
|
86
|
+
return this.invalidExpression(expr, 'SQL parameters are not allowed. Use parameter functions instead: https://docs.powersync.com/usage/sync-streams#accessing-parameters');
|
|
87
|
+
case 'substring': {
|
|
88
|
+
const mappedArgs = [this.translateNodeWithLocation(expr.value)];
|
|
89
|
+
if (expr.from) {
|
|
90
|
+
mappedArgs.push(this.translateNodeWithLocation(expr.from));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
mappedArgs.push({ type: 'lit_int', base10: '1' });
|
|
94
|
+
}
|
|
95
|
+
if (expr.for) {
|
|
96
|
+
mappedArgs.push(this.translateNodeWithLocation(expr.for));
|
|
97
|
+
}
|
|
98
|
+
return { type: 'function', function: 'substr', parameters: mappedArgs };
|
|
99
|
+
}
|
|
100
|
+
case 'call': {
|
|
101
|
+
const schemaName = expr.function.schema;
|
|
102
|
+
const source = schemaName === 'auth' || schemaName === 'subscription' || schemaName === 'connection' ? schemaName : null;
|
|
103
|
+
if (schemaName) {
|
|
104
|
+
if (source) {
|
|
105
|
+
return this.translateRequestParameter(source, expr);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return this.invalidExpression(expr.function, 'Invalid schema in function name');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (expr.distinct != null || expr.orderBy != null || expr.filter != null || expr.over != null) {
|
|
112
|
+
return this.invalidExpression(expr.function, 'DISTINCT, ORDER BY, FILTER and OVER clauses are not supported');
|
|
113
|
+
}
|
|
114
|
+
const functionName = expr.function.name.toLowerCase();
|
|
115
|
+
const forbiddenReason = forbiddenFunctions[functionName];
|
|
116
|
+
if (forbiddenReason) {
|
|
117
|
+
return this.invalidExpression(expr.function, `Forbidden call: ${forbiddenReason}`);
|
|
118
|
+
}
|
|
119
|
+
let allowedArgs = supportedFunctions[functionName];
|
|
120
|
+
if (allowedArgs == null) {
|
|
121
|
+
return this.invalidExpression(expr.function, 'Unknown function');
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (typeof allowedArgs == 'number') {
|
|
125
|
+
allowedArgs = { min: allowedArgs, max: allowedArgs };
|
|
126
|
+
}
|
|
127
|
+
const actualArgs = expr.args.length;
|
|
128
|
+
if (actualArgs < allowedArgs.min) {
|
|
129
|
+
this.options.errors.report(`Expected at least ${allowedArgs.min} arguments`, expr);
|
|
130
|
+
}
|
|
131
|
+
else if (allowedArgs.max && actualArgs > allowedArgs.max) {
|
|
132
|
+
this.options.errors.report(`Expected at most ${allowedArgs.max} arguments`, expr);
|
|
133
|
+
}
|
|
134
|
+
else if (allowedArgs.mustBeEven && actualArgs % 2 == 1) {
|
|
135
|
+
this.options.errors.report(`Expected an even amount of arguments`, expr);
|
|
136
|
+
}
|
|
137
|
+
else if (allowedArgs.mustBeOdd && actualArgs % 2 == 0) {
|
|
138
|
+
this.options.errors.report(`Expected an odd amount of arguments`, expr);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
type: 'function',
|
|
143
|
+
function: functionName,
|
|
144
|
+
parameters: expr.args.map((a) => this.translateNodeWithLocation(a))
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
case 'binary': {
|
|
148
|
+
if (expr.op === 'IN' || expr.op === 'NOT IN') {
|
|
149
|
+
return this.translateInExpression(expr);
|
|
150
|
+
}
|
|
151
|
+
const left = this.translateNodeWithLocation(expr.left);
|
|
152
|
+
const right = this.translateNodeWithLocation(expr.right);
|
|
153
|
+
if (expr.op === 'LIKE') {
|
|
154
|
+
// We don't support LIKE in the old bucket definition system, and want to make sure we're clear about ICU,
|
|
155
|
+
// case sensitivity and changing the escape character first. TODO: Support later.
|
|
156
|
+
this.options.errors.report('LIKE expressions are not currently supported.', expr);
|
|
157
|
+
return { type: 'function', function: 'like', parameters: [left, right] };
|
|
158
|
+
}
|
|
159
|
+
else if (expr.op === 'NOT LIKE') {
|
|
160
|
+
return {
|
|
161
|
+
type: 'unary',
|
|
162
|
+
operator: 'not',
|
|
163
|
+
operand: { type: 'function', function: 'like', parameters: [left, right] }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
else if (expr.op === '!=') {
|
|
167
|
+
return {
|
|
168
|
+
type: 'unary',
|
|
169
|
+
operator: 'not',
|
|
170
|
+
operand: { type: 'binary', left, right, operator: '=' }
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const supported = supportedBinaryOperators[expr.op];
|
|
174
|
+
if (supported == null) {
|
|
175
|
+
return this.invalidExpression(expr, 'Unsupported binary operator');
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return { type: 'binary', left, right, operator: supported };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
case 'unary': {
|
|
182
|
+
let not = false;
|
|
183
|
+
let rightHandSideOfIs;
|
|
184
|
+
switch (expr.op) {
|
|
185
|
+
case '-':
|
|
186
|
+
return this.invalidExpression(expr, 'Unary minus is not currently supported');
|
|
187
|
+
case '+':
|
|
188
|
+
return { type: 'unary', operator: expr.op, operand: this.translateNodeWithLocation(expr.operand) };
|
|
189
|
+
case 'NOT':
|
|
190
|
+
return { type: 'unary', operator: 'not', operand: this.translateNodeWithLocation(expr.operand) };
|
|
191
|
+
case 'IS NOT NULL':
|
|
192
|
+
not = true;
|
|
193
|
+
case 'IS NULL': // fallthrough
|
|
194
|
+
rightHandSideOfIs = { type: 'lit_null' };
|
|
195
|
+
break;
|
|
196
|
+
case 'IS NOT TRUE':
|
|
197
|
+
not = true;
|
|
198
|
+
case 'IS TRUE': // fallthrough
|
|
199
|
+
rightHandSideOfIs = { type: 'lit_int', base10: '1' };
|
|
200
|
+
break;
|
|
201
|
+
case 'IS NOT FALSE': // fallthrough
|
|
202
|
+
not = true;
|
|
203
|
+
case 'IS FALSE':
|
|
204
|
+
rightHandSideOfIs = { type: 'lit_int', base10: '0' };
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
const mappedIs = {
|
|
208
|
+
type: 'binary',
|
|
209
|
+
left: this.translateNodeWithLocation(expr.operand),
|
|
210
|
+
operator: 'is',
|
|
211
|
+
right: rightHandSideOfIs
|
|
212
|
+
};
|
|
213
|
+
return not ? { type: 'unary', operator: 'not', operand: mappedIs } : mappedIs;
|
|
214
|
+
}
|
|
215
|
+
case 'cast': {
|
|
216
|
+
const to = expr.to?.name?.toLowerCase();
|
|
217
|
+
if (to == null || !CAST_TYPES.has(to)) {
|
|
218
|
+
return this.invalidExpression(expr.to, 'Invalid SQLite cast');
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
return { type: 'cast', operand: this.translateNodeWithLocation(expr.operand), cast_as: to };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
case 'ternary': {
|
|
225
|
+
const between = {
|
|
226
|
+
type: 'between',
|
|
227
|
+
value: this.translateNodeWithLocation(expr.value),
|
|
228
|
+
low: this.translateNodeWithLocation(expr.lo),
|
|
229
|
+
high: this.translateNodeWithLocation(expr.hi)
|
|
230
|
+
};
|
|
231
|
+
return expr.op === 'BETWEEN' ? between : { type: 'unary', operator: 'not', operand: between };
|
|
232
|
+
}
|
|
233
|
+
case 'case': {
|
|
234
|
+
return {
|
|
235
|
+
type: 'case_when',
|
|
236
|
+
operand: expr.value ? this.translateNodeWithLocation(expr.value) : undefined,
|
|
237
|
+
whens: expr.whens.map((when) => ({
|
|
238
|
+
when: this.translateNodeWithLocation(when.when),
|
|
239
|
+
then: this.translateNodeWithLocation(when.value)
|
|
240
|
+
})),
|
|
241
|
+
else: expr.else ? this.translateNodeWithLocation(expr.else) : undefined
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
case 'member': {
|
|
245
|
+
const operand = this.translateNodeWithLocation(expr.operand);
|
|
246
|
+
return {
|
|
247
|
+
type: 'function',
|
|
248
|
+
function: expr.op,
|
|
249
|
+
parameters: [
|
|
250
|
+
operand,
|
|
251
|
+
typeof expr.member == 'number'
|
|
252
|
+
? { type: 'lit_int', base10: expr.member.toString() }
|
|
253
|
+
: { type: 'lit_string', value: expr.member }
|
|
254
|
+
]
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
case 'select':
|
|
258
|
+
case 'union':
|
|
259
|
+
case 'union all':
|
|
260
|
+
case 'with':
|
|
261
|
+
case 'with recursive':
|
|
262
|
+
// Should have been desugared.
|
|
263
|
+
return this.invalidExpression(expr, 'Invalid position for subqueries. Subqueries are only supported in WHERE clauses.');
|
|
264
|
+
default:
|
|
265
|
+
return this.invalidExpression(expr, 'This expression is not supported by PowerSync');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
invalidExpression(source, message) {
|
|
269
|
+
this.options.errors.report(message, source);
|
|
270
|
+
return { type: 'lit_null' };
|
|
271
|
+
}
|
|
272
|
+
translateInExpression(expr) {
|
|
273
|
+
const negated = expr.op === 'NOT IN';
|
|
274
|
+
const right = expr.right;
|
|
275
|
+
if (right.type == 'select') {
|
|
276
|
+
return this.desugarInSubquery(negated, expr, right);
|
|
277
|
+
}
|
|
278
|
+
else if (right.type == 'array') {
|
|
279
|
+
return this.desugarInValues(negated, expr.left, right.expressions);
|
|
280
|
+
}
|
|
281
|
+
else if (right.type == 'call' && right.function.name.toLowerCase() == 'row') {
|
|
282
|
+
return this.desugarInValues(negated, expr.left, right.args);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
if (right.type == 'ref' && right.table == null) {
|
|
286
|
+
const cte = this.options.scope.resolveCommonTableExpression(right.name);
|
|
287
|
+
if (cte) {
|
|
288
|
+
// Something of the form x IN $cte.
|
|
289
|
+
return this.desugarInCte(negated, expr, right.name, cte);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return this.desugarInScalar(negated, expr, right);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
desugarInValues(negated, left, right) {
|
|
296
|
+
const scalarIn = {
|
|
297
|
+
type: 'scalar_in',
|
|
298
|
+
target: this.translateNodeWithLocation(left),
|
|
299
|
+
in: right.map((e) => this.translateNodeWithLocation(e))
|
|
300
|
+
};
|
|
301
|
+
return negated ? { type: 'unary', operator: 'not', operand: scalarIn } : scalarIn;
|
|
302
|
+
}
|
|
303
|
+
desugarInSubquery(negated, binary, right) {
|
|
304
|
+
const left = binary.left;
|
|
305
|
+
const resolved = this.options.joinSubqueryExpression(right);
|
|
306
|
+
if (resolved == null) {
|
|
307
|
+
// An error would have been logged.
|
|
308
|
+
return { type: 'lit_null' };
|
|
309
|
+
}
|
|
310
|
+
let replacement = {
|
|
311
|
+
type: 'binary',
|
|
312
|
+
operator: '=',
|
|
313
|
+
left: this.translateNodeWithLocation(left),
|
|
314
|
+
right: resolved.output
|
|
315
|
+
};
|
|
316
|
+
this.options.locations.sourceForNode.set(replacement, binary);
|
|
317
|
+
replacement = resolved.filters.reduce((left, right) => ({ type: 'binary', operator: 'and', left, right }), replacement);
|
|
318
|
+
if (negated) {
|
|
319
|
+
replacement = { type: 'unary', operator: 'not', operand: replacement };
|
|
320
|
+
}
|
|
321
|
+
return replacement;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Desugar `$left IN $right`, where `$right` is a scalar expression. This is not valid SQL, but in PowerSync we
|
|
325
|
+
* interpret that as `left IN (SELECT value FROM json_each(right))`.
|
|
326
|
+
*/
|
|
327
|
+
desugarInScalar(negated, binary, right) {
|
|
328
|
+
const name = this.options.generateTableAlias();
|
|
329
|
+
return this.desugarInSubquery(negated, binary, {
|
|
330
|
+
type: 'select',
|
|
331
|
+
columns: [{ expr: { type: 'ref', name: 'value', table: { name } } }],
|
|
332
|
+
from: [{ type: 'call', function: { name: 'json_each' }, args: [right], alias: { name } }]
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Desugar `$left IN cteName` to `$left IN (SELECT cteName.onlyColumn FROM cteName)`.
|
|
337
|
+
*/
|
|
338
|
+
desugarInCte(negated, binary, cteName, cte) {
|
|
339
|
+
const columns = Object.keys(cte.resultColumns);
|
|
340
|
+
if (columns.length != 1) {
|
|
341
|
+
return this.invalidExpression(binary.right, 'Common-table expression must return a single column');
|
|
342
|
+
}
|
|
343
|
+
const name = columns[0];
|
|
344
|
+
return this.desugarInSubquery(negated, binary, {
|
|
345
|
+
type: 'select',
|
|
346
|
+
columns: [{ expr: { type: 'ref', name, table: { name: cteName } } }],
|
|
347
|
+
from: [{ type: 'table', name: { name: cteName } }]
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
translateRequestParameter(source, expr) {
|
|
351
|
+
const parameter = new ConnectionParameter(expr, source);
|
|
352
|
+
const replacement = {
|
|
353
|
+
type: 'data',
|
|
354
|
+
source: parameter
|
|
355
|
+
};
|
|
356
|
+
this.options.locations.sourceForNode.set(replacement, expr.function);
|
|
357
|
+
switch (expr.function.name.toLowerCase()) {
|
|
358
|
+
case 'parameters':
|
|
359
|
+
return replacement;
|
|
360
|
+
case 'parameter':
|
|
361
|
+
// Desugar .param(x) into .parameters() ->> '$.' || x
|
|
362
|
+
if (expr.args.length == 1) {
|
|
363
|
+
return {
|
|
364
|
+
type: 'function',
|
|
365
|
+
function: '->>',
|
|
366
|
+
parameters: [replacement, this.translateNodeWithLocation(expr.args[0])]
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
return this.invalidExpression(expr.function, 'Expected a single argument here');
|
|
371
|
+
}
|
|
372
|
+
case 'user_id':
|
|
373
|
+
if (source == 'auth') {
|
|
374
|
+
// Desugar auth.user_id() into auth.parameters() ->> '$.sub'
|
|
375
|
+
return {
|
|
376
|
+
type: 'function',
|
|
377
|
+
function: '->>',
|
|
378
|
+
parameters: [replacement, { type: 'lit_string', value: '$.sub' }]
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
return this.invalidExpression(expr.function, '.user_id() is only available on auth schema');
|
|
383
|
+
}
|
|
384
|
+
default:
|
|
385
|
+
return this.invalidExpression(expr.function, 'Unknown request function');
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const supportedBinaryOperators = {
|
|
390
|
+
OR: 'or',
|
|
391
|
+
AND: 'and',
|
|
392
|
+
'=': '=',
|
|
393
|
+
'<': '<',
|
|
394
|
+
'>': '>',
|
|
395
|
+
'<=': '<=',
|
|
396
|
+
'>=': '>=',
|
|
397
|
+
'&': '&',
|
|
398
|
+
'|': '|',
|
|
399
|
+
'<<': '<<',
|
|
400
|
+
'>>': '>>',
|
|
401
|
+
'+': '+',
|
|
402
|
+
'-': '-',
|
|
403
|
+
'*': '*',
|
|
404
|
+
'/': '/',
|
|
405
|
+
'%': '%',
|
|
406
|
+
'||': '||'
|
|
407
|
+
};
|
|
408
|
+
const forbiddenFunctions = {
|
|
409
|
+
random: 'Sync definitions must be deterministic.',
|
|
410
|
+
randomBlob: 'Sync definitions must be deterministic.'
|
|
411
|
+
};
|
|
412
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/compiler/sqlite.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAA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,EAAE,GAAG;IACR,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,MAAM,kBAAkB,GAA2B;IACjD,MAAM,EAAE,yCAAyC;IACjD,UAAU,EAAE,yCAAyC;CACtD,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { PGNode } from 'pgsql-ast-parser';
|
|
2
|
+
import { RequestExpression } from './filter.js';
|
|
3
|
+
import { StableHasher } from './equality.js';
|
|
4
|
+
import { ImplicitSchemaTablePattern, SourceSchemaTable } from '../index.js';
|
|
5
|
+
/**
|
|
6
|
+
* A result set that a query stream selects from.
|
|
7
|
+
*
|
|
8
|
+
* Instances of this class represent result sets that have been added as a source set to a query, e.g. through a `FROM`
|
|
9
|
+
* clause.
|
|
10
|
+
*
|
|
11
|
+
* Different instances of this class always refer to distinct result sets, even if the source table pattern is
|
|
12
|
+
* identical. For instance, a query may join the same table multiple times. This would result in two
|
|
13
|
+
* {@link PhysicalSourceResultSet} sources with the same {@link PhysicalSourceResultSet.tablePattern} that are still
|
|
14
|
+
* distinct.
|
|
15
|
+
*/
|
|
16
|
+
export type SourceResultSet = PhysicalSourceResultSet | RequestTableValuedResultSet;
|
|
17
|
+
/**
|
|
18
|
+
* The syntactic sources of a {@link SourceResultSet} being added to a table.
|
|
19
|
+
*/
|
|
20
|
+
export declare class SyntacticResultSetSource {
|
|
21
|
+
readonly origin: PGNode;
|
|
22
|
+
readonly explicitName: string | null;
|
|
23
|
+
constructor(origin: PGNode, explicitName: string | null);
|
|
24
|
+
}
|
|
25
|
+
export declare abstract class BaseSourceResultSet {
|
|
26
|
+
readonly source: SyntacticResultSetSource;
|
|
27
|
+
constructor(source: SyntacticResultSetSource);
|
|
28
|
+
abstract get description(): string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A {@link SourceResultSet} selecting rows from a table in the source database.
|
|
32
|
+
*
|
|
33
|
+
* The primary result set of streams must be of this type. Also, indexed lookups can only operate on this type.
|
|
34
|
+
*/
|
|
35
|
+
export declare class PhysicalSourceResultSet extends BaseSourceResultSet {
|
|
36
|
+
readonly tablePattern: ImplicitSchemaTablePattern;
|
|
37
|
+
/**
|
|
38
|
+
* Source tables that the {@link tablePattern} resolves to in the static schema context used when compiling sync
|
|
39
|
+
* streams.
|
|
40
|
+
*
|
|
41
|
+
* This information must only be used to generate analysis warnings, e.g. for column references that don't exist in
|
|
42
|
+
* resolved tables. It must not affect how sync streams are compiled, as that is always schema-independent.
|
|
43
|
+
*/
|
|
44
|
+
readonly schemaTablesForWarnings: SourceSchemaTable[];
|
|
45
|
+
constructor(tablePattern: ImplicitSchemaTablePattern, source: SyntacticResultSetSource,
|
|
46
|
+
/**
|
|
47
|
+
* Source tables that the {@link tablePattern} resolves to in the static schema context used when compiling sync
|
|
48
|
+
* streams.
|
|
49
|
+
*
|
|
50
|
+
* This information must only be used to generate analysis warnings, e.g. for column references that don't exist in
|
|
51
|
+
* resolved tables. It must not affect how sync streams are compiled, as that is always schema-independent.
|
|
52
|
+
*/
|
|
53
|
+
schemaTablesForWarnings: SourceSchemaTable[]);
|
|
54
|
+
get description(): string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A {@link SourceResultSet} applying a table-valued function with inputs that exclusively depend on request data.
|
|
58
|
+
*/
|
|
59
|
+
export declare class RequestTableValuedResultSet extends BaseSourceResultSet {
|
|
60
|
+
readonly tableValuedFunctionName: string;
|
|
61
|
+
readonly parameters: RequestExpression[];
|
|
62
|
+
constructor(tableValuedFunctionName: string, parameters: RequestExpression[], source: SyntacticResultSetSource);
|
|
63
|
+
get description(): string;
|
|
64
|
+
buildBehaviorHashCode(hasher: StableHasher): void;
|
|
65
|
+
behavesIdenticalTo(other: RequestTableValuedResultSet): boolean;
|
|
66
|
+
}
|