@powersync/service-sync-rules 0.29.10 → 0.30.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 +13 -29
- package/dist/SqlSyncRules.js +40 -76
- 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/TablePattern.d.ts +4 -1
- package/dist/TablePattern.js +11 -0
- 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/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 +104 -0
- package/dist/compiler/compiler.js +113 -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 +67 -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/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/request_functions.js.map +1 -1
- package/dist/schema-generators/SchemaGenerator.d.ts +5 -0
- package/dist/schema-generators/SchemaGenerator.js +21 -14
- package/dist/schema-generators/SchemaGenerator.js.map +1 -1
- package/dist/sql_functions.d.ts +2 -1
- 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 +23 -0
- package/dist/sync_plan/evaluator/bucket_data_source.js +137 -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 +7 -0
- package/dist/sync_plan/evaluator/index.js +26 -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 +19 -0
- package/dist/sync_plan/evaluator/parameter_index_lookup_creator.js +62 -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 +15 -0
- package/dist/sync_plan/schema_inference.js +121 -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 +209 -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 +52 -24
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +9 -2
- package/dist/utils.js +26 -3
- package/dist/utils.js.map +1 -1
- package/package.json +4 -3
|
@@ -4,7 +4,7 @@ import { ColumnDefinition } from './ExpressionType.js';
|
|
|
4
4
|
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
5
5
|
import { AvailableTable, SqlTools } from './sql_filters.js';
|
|
6
6
|
import { TablePattern } from './TablePattern.js';
|
|
7
|
-
import {
|
|
7
|
+
import { QueryParameters, QuerySchema, UnscopedEvaluationResult, SourceSchema, SourceSchemaTable, SqliteJsonRow, SqliteRow } from './types.js';
|
|
8
8
|
export interface RowValueExtractor {
|
|
9
9
|
extract(tables: QueryParameters, into: SqliteRow): void;
|
|
10
10
|
getTypes(schema: QuerySchema, into: Record<string, ColumnDefinition>): void;
|
|
@@ -12,8 +12,7 @@ export interface RowValueExtractor {
|
|
|
12
12
|
export interface EvaluateRowOptions {
|
|
13
13
|
table: SourceTableInterface;
|
|
14
14
|
row: SqliteRow;
|
|
15
|
-
|
|
16
|
-
bucketIdTransformer: BucketIdTransformer | null;
|
|
15
|
+
serializedBucketParameters: (params: QueryParameters) => string[];
|
|
17
16
|
}
|
|
18
17
|
export interface BaseSqlDataQueryOptions {
|
|
19
18
|
sourceTable: TablePattern;
|
|
@@ -21,7 +20,6 @@ export interface BaseSqlDataQueryOptions {
|
|
|
21
20
|
sql: string;
|
|
22
21
|
columns: SelectedColumn[];
|
|
23
22
|
extractors: RowValueExtractor[];
|
|
24
|
-
descriptorName: string;
|
|
25
23
|
bucketParameters: string[];
|
|
26
24
|
tools: SqlTools;
|
|
27
25
|
errors?: SqlRuleError[];
|
|
@@ -51,10 +49,6 @@ export declare class BaseSqlDataQuery {
|
|
|
51
49
|
* This may include plain column names, wildcards, and basic expressions.
|
|
52
50
|
*/
|
|
53
51
|
readonly extractors: RowValueExtractor[];
|
|
54
|
-
/**
|
|
55
|
-
* Bucket definition name.
|
|
56
|
-
*/
|
|
57
|
-
readonly descriptorName: string;
|
|
58
52
|
/**
|
|
59
53
|
* Bucket parameter names, without the `bucket.` prefix.
|
|
60
54
|
*
|
|
@@ -78,7 +72,7 @@ export declare class BaseSqlDataQuery {
|
|
|
78
72
|
columns: ColumnDefinition[];
|
|
79
73
|
}[];
|
|
80
74
|
resolveResultSets(schema: SourceSchema, tables: Record<string, Record<string, ColumnDefinition>>): void;
|
|
81
|
-
evaluateRowWithOptions(options:
|
|
75
|
+
evaluateRowWithOptions(options: EvaluateRowOptions): UnscopedEvaluationResult[];
|
|
82
76
|
protected transformRow(tables: QueryParameters): SqliteJsonRow;
|
|
83
77
|
protected getColumnOutputsFor(schemaTable: SourceSchemaTable, output: Record<string, ColumnDefinition>): void;
|
|
84
78
|
}
|
package/dist/BaseSqlDataQuery.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { filterJsonRow } from './utils.js';
|
|
2
|
-
import { castAsText } from './sql_functions.js';
|
|
1
|
+
import { filterJsonRow, idFromData } from './utils.js';
|
|
3
2
|
export class BaseSqlDataQuery {
|
|
4
3
|
/**
|
|
5
4
|
* Source table or table pattern.
|
|
@@ -25,10 +24,6 @@ export class BaseSqlDataQuery {
|
|
|
25
24
|
* This may include plain column names, wildcards, and basic expressions.
|
|
26
25
|
*/
|
|
27
26
|
extractors;
|
|
28
|
-
/**
|
|
29
|
-
* Bucket definition name.
|
|
30
|
-
*/
|
|
31
|
-
descriptorName;
|
|
32
27
|
/**
|
|
33
28
|
* Bucket parameter names, without the `bucket.` prefix.
|
|
34
29
|
*
|
|
@@ -47,7 +42,6 @@ export class BaseSqlDataQuery {
|
|
|
47
42
|
this.sql = options.sql;
|
|
48
43
|
this.columns = options.columns;
|
|
49
44
|
this.extractors = options.extractors;
|
|
50
|
-
this.descriptorName = options.descriptorName;
|
|
51
45
|
this.bucketParameters = options.bucketParameters;
|
|
52
46
|
this.tools = options.tools;
|
|
53
47
|
this.errors = options.errors ?? [];
|
|
@@ -122,24 +116,20 @@ export class BaseSqlDataQuery {
|
|
|
122
116
|
}
|
|
123
117
|
evaluateRowWithOptions(options) {
|
|
124
118
|
try {
|
|
125
|
-
const { table, row,
|
|
119
|
+
const { table, row, serializedBucketParameters } = options;
|
|
126
120
|
const tables = { [this.table.nameInSchema]: this.addSpecialParameters(table, row) };
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// issues when initially testing out sync, for example when the id column is an
|
|
133
|
-
// auto-incrementing integer.
|
|
134
|
-
// If there is no id column, we use a blank id. This will result in the user syncing
|
|
135
|
-
// a single arbitrary row for this table - better than just not being able to sync
|
|
136
|
-
// anything.
|
|
137
|
-
id = castAsText(id) ?? '';
|
|
121
|
+
// Array of _serialized_ parameters, one per output result.
|
|
122
|
+
const resolvedBucketParameters = serializedBucketParameters(tables);
|
|
123
|
+
if (resolvedBucketParameters.length == 0) {
|
|
124
|
+
// Short-circuit: No need to transform the row if there are no matching buckets.
|
|
125
|
+
return [];
|
|
138
126
|
}
|
|
127
|
+
const data = this.transformRow(tables);
|
|
128
|
+
const id = idFromData(data);
|
|
139
129
|
const outputTable = this.getOutputName(table.name);
|
|
140
|
-
return
|
|
130
|
+
return resolvedBucketParameters.map((serializedBucketParameters) => {
|
|
141
131
|
return {
|
|
142
|
-
|
|
132
|
+
serializedBucketParameters,
|
|
143
133
|
table: outputTable,
|
|
144
134
|
id: id,
|
|
145
135
|
data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseSqlDataQuery.js","sourceRoot":"","sources":["../src/BaseSqlDataQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BaseSqlDataQuery.js","sourceRoot":"","sources":["../src/BaseSqlDataQuery.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAwBvD,MAAM,OAAO,gBAAgB;IAC3B;;OAEG;IACM,WAAW,CAAe;IAEnC;;;;OAIG;IACM,KAAK,CAAiB;IAE/B;;OAEG;IACM,GAAG,CAAS;IAErB;;OAEG;IACM,OAAO,CAAmB;IAEnC;;;;OAIG;IACM,UAAU,CAAsB;IAEzC;;;;;O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terLookupScope } from './HydrationState.js';
|
|
2
3
|
import { RequestedStream } from './SqlSyncRules.js';
|
|
3
4
|
import { RequestParameters, SqliteJsonRow, SqliteJsonValue } from './types.js';
|
|
4
5
|
/**
|
|
@@ -17,13 +18,11 @@ export interface BucketParameterQuerier {
|
|
|
17
18
|
/**
|
|
18
19
|
* True if there are dynamic buckets, meaning queryDynamicBucketDescriptions() should be used.
|
|
19
20
|
*
|
|
20
|
-
* If this is false, queryDynamicBucketDescriptions() will always return an empty array
|
|
21
|
-
* and parameterQueryLookups.length == 0.
|
|
21
|
+
* If this is false, queryDynamicBucketDescriptions() will always return an empty array.
|
|
22
22
|
*/
|
|
23
23
|
readonly hasDynamicBuckets: boolean;
|
|
24
|
-
readonly parameterQueryLookups: ParameterLookup[];
|
|
25
24
|
/**
|
|
26
|
-
* These buckets depend on parameter storage, and
|
|
25
|
+
* These buckets depend on parameter storage, and need to be retrieved dynamically for each checkpoint.
|
|
27
26
|
*
|
|
28
27
|
* The ParameterLookupSource should perform the query for the current checkpoint - that is not passed
|
|
29
28
|
* as a parameter.
|
|
@@ -31,6 +30,24 @@ export interface BucketParameterQuerier {
|
|
|
31
30
|
* This includes parameter queries such as:
|
|
32
31
|
*
|
|
33
32
|
* select id as user_id from users where users.id = request.user_id()
|
|
33
|
+
*
|
|
34
|
+
* Implementations can fetch lookup results by invoking {@link ParameterLookupSource.getParameterSets}. A single
|
|
35
|
+
* querier is allowed to invoke that method multiple times. Used {@link ScopedParameterLookup} must be deterministic
|
|
36
|
+
* and only depend on:
|
|
37
|
+
*
|
|
38
|
+
* - static connection data (auth, global request and subscription parameters)
|
|
39
|
+
* - outputs of {@link ParameterLookupSource.getParameterSets} that were invoked earlier but in the same
|
|
40
|
+
* {@link queryDynamicBucketDescriptions} call.
|
|
41
|
+
*
|
|
42
|
+
* In particular, it is invalid to:
|
|
43
|
+
*
|
|
44
|
+
* - keep state in queriers between multiple {@link queryDynamicBucketDescriptions} calls.
|
|
45
|
+
* - pass say the current time as an input when fetching parameter sets, since the implicit dependency on the current
|
|
46
|
+
* time would not get tracked.
|
|
47
|
+
*
|
|
48
|
+
* This allows tracking dependencies when fetching bucket descriptions: Within a single connection (where parameters
|
|
49
|
+
* can't change), this method is invoked on new checkpoints if any of the lookups used in the previous call has
|
|
50
|
+
* changed.
|
|
34
51
|
*/
|
|
35
52
|
queryDynamicBucketDescriptions(source: ParameterLookupSource): Promise<ResolvedBucket[]>;
|
|
36
53
|
}
|
|
@@ -50,7 +67,7 @@ export interface PendingQueriers {
|
|
|
50
67
|
errors: QuerierError[];
|
|
51
68
|
}
|
|
52
69
|
export interface ParameterLookupSource {
|
|
53
|
-
getParameterSets: (lookups:
|
|
70
|
+
getParameterSets: (lookups: ScopedParameterLookup[]) => Promise<SqliteJsonRow[]>;
|
|
54
71
|
}
|
|
55
72
|
export interface QueryBucketDescriptorOptions extends ParameterLookupSource {
|
|
56
73
|
parameters: RequestParameters;
|
|
@@ -61,12 +78,28 @@ export declare function mergeBucketParameterQueriers(queriers: BucketParameterQu
|
|
|
61
78
|
*
|
|
62
79
|
* Other query types are not supported yet.
|
|
63
80
|
*/
|
|
64
|
-
export declare class
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
export declare class ScopedParameterLookup {
|
|
82
|
+
#private;
|
|
83
|
+
readonly values: readonly SqliteJsonValue[];
|
|
84
|
+
/**
|
|
85
|
+
* {@link values} of this lookup encoded via {@link JSONBig}.
|
|
86
|
+
*
|
|
87
|
+
* The result of this getter is cached to avoid re-computing the JSON value for lookups that get reused.
|
|
88
|
+
*/
|
|
89
|
+
get serializedRepresentation(): string;
|
|
90
|
+
static normalized(scope: ParameterLookupScope, lookup: UnscopedParameterLookup): ScopedParameterLookup;
|
|
91
|
+
/**
|
|
92
|
+
* Primarily for test fixtures.
|
|
93
|
+
*/
|
|
94
|
+
static direct(scope: ParameterLookupScope, values: SqliteJsonValue[]): ScopedParameterLookup;
|
|
67
95
|
/**
|
|
68
96
|
*
|
|
69
97
|
* @param values must be pre-normalized (any integer converted into bigint)
|
|
70
98
|
*/
|
|
71
|
-
constructor(
|
|
99
|
+
private constructor();
|
|
100
|
+
}
|
|
101
|
+
export declare class UnscopedParameterLookup {
|
|
102
|
+
readonly lookupValues: SqliteJsonValue[];
|
|
103
|
+
static normalized(values: SqliteJsonValue[]): UnscopedParameterLookup;
|
|
104
|
+
constructor(lookupValues: SqliteJsonValue[]);
|
|
72
105
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { JSONBig } from '@powersync/service-jsonbig';
|
|
1
2
|
import { normalizeParameterValue } from './utils.js';
|
|
2
3
|
export function mergeBucketParameterQueriers(queriers) {
|
|
3
|
-
const parameterQueryLookups = queriers.flatMap((q) => q.parameterQueryLookups);
|
|
4
4
|
return {
|
|
5
5
|
staticBuckets: queriers.flatMap((q) => q.staticBuckets),
|
|
6
|
-
hasDynamicBuckets:
|
|
7
|
-
parameterQueryLookups: parameterQueryLookups,
|
|
6
|
+
hasDynamicBuckets: queriers.findIndex((q) => q.hasDynamicBuckets) != -1,
|
|
8
7
|
async queryDynamicBucketDescriptions(source) {
|
|
9
8
|
let results = [];
|
|
10
9
|
for (let q of queriers) {
|
|
@@ -21,18 +20,42 @@ export function mergeBucketParameterQueriers(queriers) {
|
|
|
21
20
|
*
|
|
22
21
|
* Other query types are not supported yet.
|
|
23
22
|
*/
|
|
24
|
-
export class
|
|
23
|
+
export class ScopedParameterLookup {
|
|
25
24
|
// bucket definition name, parameter query index, ...lookup values
|
|
26
25
|
values;
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
#cachedSerializedForm;
|
|
27
|
+
/**
|
|
28
|
+
* {@link values} of this lookup encoded via {@link JSONBig}.
|
|
29
|
+
*
|
|
30
|
+
* The result of this getter is cached to avoid re-computing the JSON value for lookups that get reused.
|
|
31
|
+
*/
|
|
32
|
+
get serializedRepresentation() {
|
|
33
|
+
return (this.#cachedSerializedForm ??= JSONBig.stringify(this.values));
|
|
34
|
+
}
|
|
35
|
+
static normalized(scope, lookup) {
|
|
36
|
+
return new ScopedParameterLookup([scope.lookupName, scope.queryId, ...lookup.lookupValues]);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Primarily for test fixtures.
|
|
40
|
+
*/
|
|
41
|
+
static direct(scope, values) {
|
|
42
|
+
return new ScopedParameterLookup([scope.lookupName, scope.queryId, ...values.map(normalizeParameterValue)]);
|
|
29
43
|
}
|
|
30
44
|
/**
|
|
31
45
|
*
|
|
32
46
|
* @param values must be pre-normalized (any integer converted into bigint)
|
|
33
47
|
*/
|
|
34
48
|
constructor(values) {
|
|
35
|
-
this.values = values;
|
|
49
|
+
this.values = Object.freeze(values);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class UnscopedParameterLookup {
|
|
53
|
+
lookupValues;
|
|
54
|
+
static normalized(values) {
|
|
55
|
+
return new UnscopedParameterLookup(values.map(normalizeParameterValue));
|
|
56
|
+
}
|
|
57
|
+
constructor(lookupValues) {
|
|
58
|
+
this.lookupValues = lookupValues;
|
|
36
59
|
}
|
|
37
60
|
}
|
|
38
61
|
//# sourceMappingURL=BucketParameterQuerier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BucketParameterQuerier.js","sourceRoot":"","sources":["../src/BucketParameterQuerier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BucketParameterQuerier.js","sourceRoot":"","sources":["../src/BucketParameterQuerier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAKrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AA+ErD,MAAM,UAAU,4BAA4B,CAAC,QAAkC;IAC7E,OAAO;QACL,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;QACvD,iBAAiB,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EA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;IACzB,YAAY,CAAoB;IAEzC,MAAM,CAAC,UAAU,CAAC,MAAyB;QACzC,OAAO,IAAI,uBAAuB,CAAC,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,YAAY,YAA+B;QACzC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF"}
|
package/dist/BucketSource.d.ts
CHANGED
|
@@ -1,36 +1,47 @@
|
|
|
1
1
|
import { PendingQueriers } from './BucketParameterQuerier.js';
|
|
2
2
|
import { ColumnDefinition } from './ExpressionType.js';
|
|
3
|
+
import { HydrationState, ParameterLookupScope } from './HydrationState.js';
|
|
3
4
|
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
4
5
|
import { GetQuerierOptions } from './SqlSyncRules.js';
|
|
5
6
|
import { TablePattern } from './TablePattern.js';
|
|
6
|
-
import { EvaluatedParametersResult, EvaluateRowOptions, EvaluationResult, SourceSchema, SqliteRow } from './types.js';
|
|
7
|
+
import { EvaluatedParametersResult, EvaluateRowOptions, EvaluationResult, UnscopedEvaluationResult, SourceSchema, SqliteRow, UnscopedEvaluatedParametersResult } from './types.js';
|
|
8
|
+
export interface CreateSourceParams {
|
|
9
|
+
hydrationState: HydrationState;
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* - which buckets a given connection has access to.
|
|
13
|
-
*
|
|
14
|
-
* There are two ways to define bucket sources: Via sync rules made up of parameter and data queries, and via stream
|
|
15
|
-
* definitions that only consist of a single query.
|
|
12
|
+
* A BucketSource is a _logical_ bucket or sync stream definition. It is primarily used to group together
|
|
13
|
+
* related BucketDataSource, BucketParameterLookupSource and BucketParameterQuerierSource definitions,
|
|
14
|
+
* for the purpose of subscribing to specific streams. It does not directly define the implementation
|
|
15
|
+
* or replication process.
|
|
16
16
|
*/
|
|
17
17
|
export interface BucketSource {
|
|
18
18
|
readonly name: string;
|
|
19
19
|
readonly type: BucketSourceType;
|
|
20
20
|
readonly subscribedToByDefault: boolean;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
* be associated with.
|
|
22
|
+
* BucketDataSource describing the data in this bucket/stream definition.
|
|
24
23
|
*
|
|
25
|
-
* The
|
|
26
|
-
*
|
|
24
|
+
* The same data source could in theory be present in multiple stream definitions.
|
|
25
|
+
*
|
|
26
|
+
* Sources must _only_ be split into multiple ones if they will result in different buckets being created.
|
|
27
|
+
* Specifically, bucket definitions would always have a single data source, while stream definitions may have
|
|
28
|
+
* one per variant.
|
|
27
29
|
*/
|
|
28
|
-
|
|
30
|
+
readonly dataSources: BucketDataSource[];
|
|
29
31
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
+
* BucketParameterLookupSource describing the parameter tables used in this bucket/stream definition.
|
|
33
|
+
*
|
|
34
|
+
* The same source could in theory be present in multiple stream definitions.
|
|
32
35
|
*/
|
|
33
|
-
|
|
36
|
+
readonly parameterIndexLookupCreators: ParameterIndexLookupCreator[];
|
|
37
|
+
debugRepresentation(): any;
|
|
38
|
+
hydrate(params: CreateSourceParams): HydratedBucketSource;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Internal interface for individual queriers. This is not used on its in the public API directly, apart
|
|
42
|
+
* from in HydratedBucketSource. Everywhere else it is just to standardize the internal functions that we re-use.
|
|
43
|
+
*/
|
|
44
|
+
export interface BucketParameterQuerierSource {
|
|
34
45
|
/**
|
|
35
46
|
* Reports {@link BucketParameterQuerier}s resolving buckets that a specific stream request should have access to.
|
|
36
47
|
*
|
|
@@ -38,18 +49,36 @@ export interface BucketSource {
|
|
|
38
49
|
* @param options Options, including parameters that may affect the buckets loaded by this source.
|
|
39
50
|
*/
|
|
40
51
|
pushBucketParameterQueriers(result: PendingQueriers, options: GetQuerierOptions): void;
|
|
52
|
+
}
|
|
53
|
+
export interface HydratedBucketSource extends BucketParameterQuerierSource {
|
|
54
|
+
readonly definition: BucketSource;
|
|
55
|
+
}
|
|
56
|
+
export type ScopedEvaluateRow = (options: EvaluateRowOptions) => EvaluationResult[];
|
|
57
|
+
export type ScopedEvaluateParameterRow = (sourceTable: SourceTableInterface, row: SqliteRow) => EvaluatedParametersResult[];
|
|
58
|
+
/**
|
|
59
|
+
* Encodes a static definition of a bucket source, as parsed from sync rules or stream definitions.
|
|
60
|
+
*
|
|
61
|
+
* This does not require any "hydration" itself: All results are independent of bucket names.
|
|
62
|
+
* The higher-level HydratedSyncRules will use a HydrationState to generate bucket names.
|
|
63
|
+
*/
|
|
64
|
+
export interface BucketDataSource {
|
|
41
65
|
/**
|
|
42
|
-
*
|
|
43
|
-
* {@link BucketParameterQuerier.hasDynamicBuckets} is true.
|
|
66
|
+
* Unique name of the data source within a sync rules version.
|
|
44
67
|
*
|
|
45
|
-
* This
|
|
68
|
+
* This may be used as the basis for bucketPrefix (or it could be ignored).
|
|
46
69
|
*/
|
|
47
|
-
|
|
70
|
+
readonly uniqueName: string;
|
|
71
|
+
/**
|
|
72
|
+
* For debug use only.
|
|
73
|
+
*/
|
|
74
|
+
readonly bucketParameters: string[];
|
|
48
75
|
getSourceTables(): Set<TablePattern>;
|
|
49
|
-
/** Whether the table possibly affects the buckets resolved by this source. */
|
|
50
|
-
tableSyncsParameters(table: SourceTableInterface): boolean;
|
|
51
|
-
/** Whether the table possibly affects the contents of buckets resolved by this source. */
|
|
52
76
|
tableSyncsData(table: SourceTableInterface): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Given a row as it appears in a table that affects sync data, return buckets, logical table names and transformed
|
|
79
|
+
* data for rows to add to buckets.
|
|
80
|
+
*/
|
|
81
|
+
evaluateRow(options: EvaluateRowOptions): UnscopedEvaluationResult[];
|
|
53
82
|
/**
|
|
54
83
|
* Given a static schema, infer all logical tables and associated columns that appear in buckets defined by this
|
|
55
84
|
* source.
|
|
@@ -60,7 +89,34 @@ export interface BucketSource {
|
|
|
60
89
|
debugWriteOutputTables(result: Record<string, {
|
|
61
90
|
query: string;
|
|
62
91
|
}[]>): void;
|
|
63
|
-
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* This defines how to extract parameter index lookup values from parameter queries or stream subqueries.
|
|
95
|
+
*
|
|
96
|
+
* This is only relevant for parameter queries and subqueries that query tables.
|
|
97
|
+
*/
|
|
98
|
+
export interface ParameterIndexLookupCreator {
|
|
99
|
+
/**
|
|
100
|
+
* lookupName + queryId is used to uniquely identify parameter queries for parameter storage.
|
|
101
|
+
*
|
|
102
|
+
* This defines the default values if no transformations are applied.
|
|
103
|
+
*/
|
|
104
|
+
readonly defaultLookupScope: ParameterLookupScope;
|
|
105
|
+
getSourceTables(): Set<TablePattern>;
|
|
106
|
+
/**
|
|
107
|
+
* Given a row in a source table that affects sync parameters, returns a structure to index which buckets rows should
|
|
108
|
+
* be associated with.
|
|
109
|
+
*
|
|
110
|
+
* The returned {@link UnscopedParameterLookup} can be referenced by {@link pushBucketParameterQueriers} to allow the storage
|
|
111
|
+
* system to find buckets.
|
|
112
|
+
*/
|
|
113
|
+
evaluateParameterRow(sourceTable: SourceTableInterface, row: SqliteRow): UnscopedEvaluatedParametersResult[];
|
|
114
|
+
/** Whether the table possibly affects the buckets resolved by this source. */
|
|
115
|
+
tableSyncsParameters(table: SourceTableInterface): boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface DebugMergedSource extends HydratedBucketSource {
|
|
118
|
+
evaluateRow: ScopedEvaluateRow;
|
|
119
|
+
evaluateParameterRow: ScopedEvaluateParameterRow;
|
|
64
120
|
}
|
|
65
121
|
export declare enum BucketSourceType {
|
|
66
122
|
SYNC_RULE = 0,
|
|
@@ -70,3 +126,16 @@ export type ResultSetDescription = {
|
|
|
70
126
|
name: string;
|
|
71
127
|
columns: ColumnDefinition[];
|
|
72
128
|
};
|
|
129
|
+
export declare function hydrateEvaluateRow(hydrationState: HydrationState, source: BucketDataSource): ScopedEvaluateRow;
|
|
130
|
+
export declare function hydrateEvaluateParameterRow(hydrationState: HydrationState, source: ParameterIndexLookupCreator): ScopedEvaluateParameterRow;
|
|
131
|
+
export declare function mergeDataSources(hydrationState: HydrationState, sources: BucketDataSource[]): {
|
|
132
|
+
evaluateRow: ScopedEvaluateRow;
|
|
133
|
+
};
|
|
134
|
+
export declare function mergeParameterIndexLookupCreators(hydrationState: HydrationState, sources: ParameterIndexLookupCreator[]): {
|
|
135
|
+
evaluateParameterRow: ScopedEvaluateParameterRow;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* For production purposes, we typically need to operate on the different sources separately. However, for debugging,
|
|
139
|
+
* it is useful to have a single merged source that can evaluate everything.
|
|
140
|
+
*/
|
|
141
|
+
export declare function debugHydratedMergedSource(bucketSource: BucketSource, params?: CreateSourceParams): DebugMergedSource;
|
package/dist/BucketSource.js
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
|
+
import { ScopedParameterLookup } from './BucketParameterQuerier.js';
|
|
2
|
+
import { DEFAULT_HYDRATION_STATE } from './HydrationState.js';
|
|
3
|
+
import { isEvaluationError } from './types.js';
|
|
4
|
+
import { buildBucketName } from './utils.js';
|
|
1
5
|
export var BucketSourceType;
|
|
2
6
|
(function (BucketSourceType) {
|
|
3
7
|
BucketSourceType[BucketSourceType["SYNC_RULE"] = 0] = "SYNC_RULE";
|
|
4
8
|
BucketSourceType[BucketSourceType["SYNC_STREAM"] = 1] = "SYNC_STREAM";
|
|
5
9
|
})(BucketSourceType || (BucketSourceType = {}));
|
|
10
|
+
export function hydrateEvaluateRow(hydrationState, source) {
|
|
11
|
+
const scope = hydrationState.getBucketSourceScope(source);
|
|
12
|
+
return (options) => {
|
|
13
|
+
return source.evaluateRow(options).map((result) => {
|
|
14
|
+
if (isEvaluationError(result)) {
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
bucket: buildBucketName(scope, result.serializedBucketParameters),
|
|
19
|
+
id: result.id,
|
|
20
|
+
table: result.table,
|
|
21
|
+
data: result.data
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function hydrateEvaluateParameterRow(hydrationState, source) {
|
|
27
|
+
const scope = hydrationState.getParameterIndexLookupScope(source);
|
|
28
|
+
return (sourceTable, row) => {
|
|
29
|
+
return source.evaluateParameterRow(sourceTable, row).map((result) => {
|
|
30
|
+
if (isEvaluationError(result)) {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
bucketParameters: result.bucketParameters,
|
|
35
|
+
lookup: ScopedParameterLookup.normalized(scope, result.lookup)
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function mergeDataSources(hydrationState, sources) {
|
|
41
|
+
const withScope = sources.map((source) => hydrateEvaluateRow(hydrationState, source));
|
|
42
|
+
return {
|
|
43
|
+
evaluateRow(options) {
|
|
44
|
+
return withScope.flatMap((source) => source(options));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function mergeParameterIndexLookupCreators(hydrationState, sources) {
|
|
49
|
+
const withScope = sources.map((source) => hydrateEvaluateParameterRow(hydrationState, source));
|
|
50
|
+
return {
|
|
51
|
+
evaluateParameterRow(sourceTable, row) {
|
|
52
|
+
return withScope.flatMap((source) => source(sourceTable, row));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* For production purposes, we typically need to operate on the different sources separately. However, for debugging,
|
|
58
|
+
* it is useful to have a single merged source that can evaluate everything.
|
|
59
|
+
*/
|
|
60
|
+
export function debugHydratedMergedSource(bucketSource, params) {
|
|
61
|
+
const hydrationState = params?.hydrationState ?? DEFAULT_HYDRATION_STATE;
|
|
62
|
+
const resolvedParams = { hydrationState };
|
|
63
|
+
const dataSource = mergeDataSources(hydrationState, bucketSource.dataSources);
|
|
64
|
+
const parameterLookupSource = mergeParameterIndexLookupCreators(hydrationState, bucketSource.parameterIndexLookupCreators);
|
|
65
|
+
const hydratedBucketSource = bucketSource.hydrate(resolvedParams);
|
|
66
|
+
return {
|
|
67
|
+
definition: bucketSource,
|
|
68
|
+
evaluateParameterRow: parameterLookupSource.evaluateParameterRow.bind(parameterLookupSource),
|
|
69
|
+
evaluateRow: dataSource.evaluateRow.bind(dataSource),
|
|
70
|
+
pushBucketParameterQueriers: hydratedBucketSource.pushBucketParameterQueriers.bind(hydratedBucketSource)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
6
73
|
//# sourceMappingURL=BucketSource.js.map
|
package/dist/BucketSource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BucketSource.js","sourceRoot":"","sources":["../src/BucketSource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BucketSource.js","sourceRoot":"","sources":["../src/BucketSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,qBAAqB,EACtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAwC,MAAM,qBAAqB,CAAC;AAIpG,OAAO,EAKL,iBAAiB,EAMlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAwI7C,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,iEAAS,CAAA;IACT,qEAAW,CAAA;AACb,CAAC,EAHW,gBAAgB,KAAhB,gBAAgB,QAG3B;AAID,MAAM,UAAU,kBAAkB,CAAC,cAA8B,EAAE,MAAwB;IACzF,MAAM,KAAK,GAAG,cAAc,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,CAAC,OAA2B,EAAsB,EAAE;QACzD,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAChD,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC9B,OAAO,MA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cAA8B,EAC9B,OAAsC;IAEtC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,2BAA2B,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/F,OAAO;QACL,oBAAoB,CAAC,WAAiC,EAAE,GAAc;YACpE,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;QACjE,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,YAA0B,EAAE,MAA2B;IAC/F,MAAM,cAAc,GAAG,MAAM,EAAE,cAAc,IAAI,uBAAuB,CAAC;IACzE,MAAM,cAAc,GAAG,EAAE,cAAc,EAAE,CAAC;IAC1C,MAAM,UAAU,GAAG,gBAAgB,CAAC,cAAc,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;IAC9E,MAAM,qBAAqB,GAAG,iCAAiC,CAC7D,cAAc,EACd,YAAY,CAAC,4BAA4B,CAC1C,CAAC;IACF,MAAM,oBAAoB,GAAG,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAClE,OAAO;QACL,UAAU,EAAE,YAAY;QACxB,oBAAoB,EAAE,qBAAqB,CAAC,oBAAoB,CAAC,IAAI,CAAC,qBAAqB,CAAC;QAC5F,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC;QACpD,2BAA2B,EAAE,oBAAoB,CAAC,2BAA2B,CAAC,IAAI,CAAC,oBAAoB,CAAC;KACzG,CAAC;AACJ,CAAC"}
|
package/dist/ExpressionType.d.ts
CHANGED
|
@@ -5,11 +5,13 @@ export declare const TYPE_INTEGER = 4;
|
|
|
5
5
|
export declare const TYPE_REAL = 8;
|
|
6
6
|
export type SqliteType = 'null' | 'blob' | 'text' | 'integer' | 'real' | 'numeric';
|
|
7
7
|
export type SqliteValueType = 'null' | 'blob' | 'text' | 'integer' | 'real';
|
|
8
|
-
export interface
|
|
9
|
-
name: string;
|
|
8
|
+
export interface ColumnType {
|
|
10
9
|
type: ExpressionType;
|
|
11
10
|
originalType?: string;
|
|
12
11
|
}
|
|
12
|
+
export interface ColumnDefinition extends ColumnType {
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
13
15
|
export declare class ExpressionType {
|
|
14
16
|
readonly typeFlags: number;
|
|
15
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressionType.js","sourceRoot":"","sources":["../src/ExpressionType.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpressionType.js","sourceRoot":"","sources":["../src/ExpressionType.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAe3B,MAAM,OAAO,cAAc;IACT,SAAS,CAAS;IAElC;;OAEG;IACH,MAAM,CAAC,IAAI,GAAG,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;IACpC;;OAEG;IACH,MAAM,CAAC,GAAG,GAAG,IAAI,cAAc,CAAC,SAAS,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAAC,CAAC;IAClF,MAAM,CAAC,IAAI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G,SAAS,CAAC;IAC7B,CAAC;IAED,EAAE,CAAC,KAAqB;QACtB,OAAO,cAAc,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;IAED,GAAG,CAAC,KAAqB;QACvB,OAAO,cAAc,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,SAAS,IAAI,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;IACxG,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC;IACrC,CAAC;;AAGH;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAAC,IAAwB;IACrE,IAAI,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,cAAc,CAAC,IAAI,CAAC;IAC7B,CAAC;IACD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,cAAc,CAAC,OAAO,CAAC;QAChC,KAAK,OAAO;YACV,OAAO,cAAc,CAAC,IAAI,CAAC;QAC7B,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM,CAAC;QACZ,KAAK,KAAK;YACR,OAAO,cAAc,CAAC,OAAO,CAAC;QAChC,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,cAAc,CAAC,IAAI,CAAC;QAC7B;YACE,OAAO,cAAc,CAAC,IAAI,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BucketDataSource, CreateSourceParams, HydratedBucketSource } from './BucketSource.js';
|
|
2
|
+
import { ParameterIndexLookupCreator, CompatibilityContext, EvaluatedParameters, EvaluatedRow, EvaluationError, GetBucketParameterQuerierResult, GetQuerierOptions, SqlEventDescriptor, SqliteInputValue, SqliteValue, SqlSyncRules } from './index.js';
|
|
3
|
+
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
4
|
+
import { EvaluateRowOptions, SqliteRow } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Hydrated sync rules is sync rule definitions along with persisted state. Currently, the persisted state
|
|
7
|
+
* specifically affects bucket names.
|
|
8
|
+
*/
|
|
9
|
+
export declare class HydratedSyncRules {
|
|
10
|
+
bucketSources: HydratedBucketSource[];
|
|
11
|
+
eventDescriptors: SqlEventDescriptor[];
|
|
12
|
+
compatibility: CompatibilityContext;
|
|
13
|
+
readonly definition: SqlSyncRules;
|
|
14
|
+
private readonly innerEvaluateRow;
|
|
15
|
+
private readonly innerEvaluateParameterRow;
|
|
16
|
+
constructor(params: {
|
|
17
|
+
definition: SqlSyncRules;
|
|
18
|
+
createParams: CreateSourceParams;
|
|
19
|
+
bucketDataSources: BucketDataSource[];
|
|
20
|
+
bucketParameterIndexLookupCreators: ParameterIndexLookupCreator[];
|
|
21
|
+
eventDescriptors?: SqlEventDescriptor[];
|
|
22
|
+
compatibility?: CompatibilityContext;
|
|
23
|
+
});
|
|
24
|
+
getSourceTables(): import("./TablePattern.js").TablePattern[];
|
|
25
|
+
tableTriggersEvent(table: SourceTableInterface): boolean;
|
|
26
|
+
tableSyncsData(table: SourceTableInterface): boolean;
|
|
27
|
+
tableSyncsParameters(table: SourceTableInterface): boolean;
|
|
28
|
+
applyRowContext<MaybeToast extends undefined = never>(source: SqliteRow<SqliteInputValue | MaybeToast>): SqliteRow<SqliteValue | MaybeToast>;
|
|
29
|
+
/**
|
|
30
|
+
* Throws errors.
|
|
31
|
+
*/
|
|
32
|
+
evaluateRow(options: EvaluateRowOptions): EvaluatedRow[];
|
|
33
|
+
evaluateRowWithErrors(options: EvaluateRowOptions): {
|
|
34
|
+
results: EvaluatedRow[];
|
|
35
|
+
errors: EvaluationError[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Throws errors.
|
|
39
|
+
*/
|
|
40
|
+
evaluateParameterRow(table: SourceTableInterface, row: SqliteRow): EvaluatedParameters[];
|
|
41
|
+
evaluateParameterRowWithErrors(table: SourceTableInterface, row: SqliteRow): {
|
|
42
|
+
results: EvaluatedParameters[];
|
|
43
|
+
errors: EvaluationError[];
|
|
44
|
+
};
|
|
45
|
+
getBucketParameterQuerier(options: GetQuerierOptions): GetBucketParameterQuerierResult;
|
|
46
|
+
}
|