@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,88 @@
|
|
|
1
|
+
import { CompatibilityContext, isEvaluatedParameters, isEvaluatedRow, isEvaluationError, mergeBucketParameterQueriers, mergeDataSources, mergeParameterIndexLookupCreators } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Hydrated sync rules is sync rule definitions along with persisted state. Currently, the persisted state
|
|
4
|
+
* specifically affects bucket names.
|
|
5
|
+
*/
|
|
6
|
+
export class HydratedSyncRules {
|
|
7
|
+
bucketSources = [];
|
|
8
|
+
eventDescriptors = [];
|
|
9
|
+
compatibility = CompatibilityContext.FULL_BACKWARDS_COMPATIBILITY;
|
|
10
|
+
definition;
|
|
11
|
+
innerEvaluateRow;
|
|
12
|
+
innerEvaluateParameterRow;
|
|
13
|
+
constructor(params) {
|
|
14
|
+
const hydrationState = params.createParams.hydrationState;
|
|
15
|
+
this.definition = params.definition;
|
|
16
|
+
this.innerEvaluateRow = mergeDataSources(hydrationState, params.bucketDataSources).evaluateRow;
|
|
17
|
+
this.innerEvaluateParameterRow = mergeParameterIndexLookupCreators(hydrationState, params.bucketParameterIndexLookupCreators).evaluateParameterRow;
|
|
18
|
+
if (params.eventDescriptors) {
|
|
19
|
+
this.eventDescriptors = params.eventDescriptors;
|
|
20
|
+
}
|
|
21
|
+
if (params.compatibility) {
|
|
22
|
+
this.compatibility = params.compatibility;
|
|
23
|
+
}
|
|
24
|
+
this.bucketSources = this.definition.bucketSources.map((source) => source.hydrate(params.createParams));
|
|
25
|
+
}
|
|
26
|
+
// These methods do not depend on hydration, so we can just forward them to the definition.
|
|
27
|
+
getSourceTables() {
|
|
28
|
+
return this.definition.getSourceTables();
|
|
29
|
+
}
|
|
30
|
+
tableTriggersEvent(table) {
|
|
31
|
+
return this.definition.tableTriggersEvent(table);
|
|
32
|
+
}
|
|
33
|
+
tableSyncsData(table) {
|
|
34
|
+
return this.definition.tableSyncsData(table);
|
|
35
|
+
}
|
|
36
|
+
tableSyncsParameters(table) {
|
|
37
|
+
return this.definition.tableSyncsParameters(table);
|
|
38
|
+
}
|
|
39
|
+
applyRowContext(source) {
|
|
40
|
+
return this.definition.applyRowContext(source);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Throws errors.
|
|
44
|
+
*/
|
|
45
|
+
evaluateRow(options) {
|
|
46
|
+
const { results, errors } = this.evaluateRowWithErrors(options);
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
throw new Error(errors[0].error);
|
|
49
|
+
}
|
|
50
|
+
return results;
|
|
51
|
+
}
|
|
52
|
+
evaluateRowWithErrors(options) {
|
|
53
|
+
const rawResults = this.innerEvaluateRow(options);
|
|
54
|
+
const results = rawResults.filter(isEvaluatedRow);
|
|
55
|
+
const errors = rawResults.filter(isEvaluationError);
|
|
56
|
+
return { results, errors };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Throws errors.
|
|
60
|
+
*/
|
|
61
|
+
evaluateParameterRow(table, row) {
|
|
62
|
+
const { results, errors } = this.evaluateParameterRowWithErrors(table, row);
|
|
63
|
+
if (errors.length > 0) {
|
|
64
|
+
throw new Error(errors[0].error);
|
|
65
|
+
}
|
|
66
|
+
return results;
|
|
67
|
+
}
|
|
68
|
+
evaluateParameterRowWithErrors(table, row) {
|
|
69
|
+
const rawResults = this.innerEvaluateParameterRow(table, row);
|
|
70
|
+
const results = rawResults.filter(isEvaluatedParameters);
|
|
71
|
+
const errors = rawResults.filter(isEvaluationError);
|
|
72
|
+
return { results, errors };
|
|
73
|
+
}
|
|
74
|
+
getBucketParameterQuerier(options) {
|
|
75
|
+
const queriers = [];
|
|
76
|
+
const errors = [];
|
|
77
|
+
const pending = { queriers, errors };
|
|
78
|
+
for (const source of this.bucketSources) {
|
|
79
|
+
if ((source.definition.subscribedToByDefault && options.hasDefaultStreams) ||
|
|
80
|
+
source.definition.name in options.streams) {
|
|
81
|
+
source.pushBucketParameterQueriers(pending, options);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const querier = mergeBucketParameterQueriers(queriers);
|
|
85
|
+
return { querier, errors };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=HydratedSyncRules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HydratedSyncRules.js","sourceRoot":"","sources":["../src/HydratedSyncRules.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,oBAAoB,EAMpB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,4BAA4B,EAC5B,gBAAgB,EAChB,iCAAi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A8B,CAC5B,KAA2B,EAC3B,GAAc;QAEd,MAAM,UAAU,GAAgC,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC3F,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,qBAAqB,CAA0B,CAAC;QAClF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,iBAAiB,CAAsB,CAAC;QACzE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAC7B,CAAC;IAED,yBAAyB,CAAC,OAA0B;QAClD,MAAM,QAAQ,GAA6B,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAmB,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QAErC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACxC,IACE,CAAC,MAAM,CAAC,UAAU,CAAC,qBAAqB,IAAI,OAAO,CAAC,iBAAiB,CAAC;gBACtE,MAAM,CAAC,UAAU,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,EACzC,CAAC;gBACD,MAAM,CAAC,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,4BAA4B,CAAC,QAAQ,CAAC,CAAC;QACvD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BucketDataSource, ParameterIndexLookupCreator } from './BucketSource.js';
|
|
2
|
+
export interface BucketDataScope {
|
|
3
|
+
/** The prefix is the bucket name before the parameters. */
|
|
4
|
+
bucketPrefix: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ParameterLookupScope {
|
|
7
|
+
/** The lookup name + queryid is used to reference the parameter lookup record. */
|
|
8
|
+
lookupName: string;
|
|
9
|
+
queryId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hydration state information for a source.
|
|
13
|
+
*
|
|
14
|
+
* This is what keeps track of bucket name and parameter lookup mappings for hydration. This can be used
|
|
15
|
+
* both to re-use mappings across hydrations of different sync rule versions, or to generate new mappings.
|
|
16
|
+
*/
|
|
17
|
+
export interface HydrationState {
|
|
18
|
+
/**
|
|
19
|
+
* Given a bucket data source definition, get the bucket prefix to use for it.
|
|
20
|
+
*/
|
|
21
|
+
getBucketSourceScope(source: BucketDataSource): BucketDataScope;
|
|
22
|
+
/**
|
|
23
|
+
* Given a bucket parameter lookup definition, get the persistence name to use.
|
|
24
|
+
*/
|
|
25
|
+
getParameterIndexLookupScope(source: ParameterIndexLookupCreator): ParameterLookupScope;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* This represents hydration state that performs no transformations.
|
|
29
|
+
*
|
|
30
|
+
* This is the legacy default behavior with no bucket versioning.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_HYDRATION_STATE: HydrationState;
|
|
33
|
+
/**
|
|
34
|
+
* Transforms bucket ids generated when evaluating the row by e.g. encoding version information.
|
|
35
|
+
*
|
|
36
|
+
* Because buckets are recreated on a sync rule redeploy, it makes sense to use different bucket ids (otherwise, clients
|
|
37
|
+
* may run into checksum errors causing a sync to take longer than necessary or breaking progress).
|
|
38
|
+
*
|
|
39
|
+
* So, this transformer receives the original bucket id as generated by defined sync rules, and can prepend a version
|
|
40
|
+
* identifier.
|
|
41
|
+
*
|
|
42
|
+
* Note that this transformation has not been present in older versions of the sync service. To preserve backwards
|
|
43
|
+
* compatibility, sync rules will not use this without an opt-in.
|
|
44
|
+
*/
|
|
45
|
+
export declare function versionedHydrationState(version: number): HydrationState;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This represents hydration state that performs no transformations.
|
|
3
|
+
*
|
|
4
|
+
* This is the legacy default behavior with no bucket versioning.
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_HYDRATION_STATE = {
|
|
7
|
+
getBucketSourceScope(source) {
|
|
8
|
+
return {
|
|
9
|
+
bucketPrefix: source.uniqueName
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
getParameterIndexLookupScope(source) {
|
|
13
|
+
return source.defaultLookupScope;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Transforms bucket ids generated when evaluating the row by e.g. encoding version information.
|
|
18
|
+
*
|
|
19
|
+
* Because buckets are recreated on a sync rule redeploy, it makes sense to use different bucket ids (otherwise, clients
|
|
20
|
+
* may run into checksum errors causing a sync to take longer than necessary or breaking progress).
|
|
21
|
+
*
|
|
22
|
+
* So, this transformer receives the original bucket id as generated by defined sync rules, and can prepend a version
|
|
23
|
+
* identifier.
|
|
24
|
+
*
|
|
25
|
+
* Note that this transformation has not been present in older versions of the sync service. To preserve backwards
|
|
26
|
+
* compatibility, sync rules will not use this without an opt-in.
|
|
27
|
+
*/
|
|
28
|
+
export function versionedHydrationState(version) {
|
|
29
|
+
return {
|
|
30
|
+
getBucketSourceScope(source) {
|
|
31
|
+
return {
|
|
32
|
+
bucketPrefix: `${version}#${source.uniqueName}`
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
getParameterIndexLookupScope(source) {
|
|
36
|
+
// No transformations applied here
|
|
37
|
+
return source.defaultLookupScope;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=HydrationState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HydrationState.js","sourceRoot":"","sources":["../src/HydrationState.ts"],"names":[],"mappings":"AA+BA;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAmB;IACrD,oBAAoB,CAAC,MAAwB;QAC3C,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,UAAU;SAChC,CAAC;IACJ,CAAC;IACD,4BAA4B,CAAC,MAAM;QACjC,OAAO,MAAM,CAAC,kBAAkB,CAAC;IACnC,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,OAAO;QACL,oBAAoB,CAAC,MAAwB;YAC3C,OAAO;gBACL,YAAY,EAAE,GAAG,OAAO,IAAI,MAAM,CAAC,UAAU,EAAE;aAChD,CAAC;QACJ,CAAC;QAED,4BAA4B,CAAC,MAAmC;YAC9D,kCAAkC;YAClC,OAAO,MAAM,CAAC,kBAAkB,CAAC;QACnC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BucketParameterQuerier, PendingQueriers } from './BucketParameterQuerier.js';
|
|
3
|
-
import { BucketSource, BucketSourceType } from './BucketSource.js';
|
|
1
|
+
import { BucketDataSource, BucketSource, BucketSourceType, CreateSourceParams, HydratedBucketSource } from './BucketSource.js';
|
|
4
2
|
import { ColumnDefinition } from './ExpressionType.js';
|
|
5
3
|
import { IdSequence } from './IdSequence.js';
|
|
6
4
|
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
7
5
|
import { SqlDataQuery } from './SqlDataQuery.js';
|
|
8
6
|
import { SqlParameterQuery } from './SqlParameterQuery.js';
|
|
9
|
-
import {
|
|
7
|
+
import { SyncRulesOptions } from './SqlSyncRules.js';
|
|
10
8
|
import { StaticSqlParameterQuery } from './StaticSqlParameterQuery.js';
|
|
11
9
|
import { TablePattern } from './TablePattern.js';
|
|
12
10
|
import { TableValuedFunctionSqlParameterQuery } from './TableValuedFunctionSqlParameterQuery.js';
|
|
13
|
-
import { SqlRuleError } from './errors.js';
|
|
14
11
|
import { CompatibilityContext } from './compatibility.js';
|
|
15
|
-
import {
|
|
12
|
+
import { SqlRuleError } from './errors.js';
|
|
13
|
+
import { EvaluateRowOptions, QueryParseOptions, SourceSchema, UnscopedEvaluationResult } from './types.js';
|
|
16
14
|
export interface QueryParseResult {
|
|
17
15
|
/**
|
|
18
16
|
* True if parsed in some form, even if there are errors.
|
|
@@ -22,10 +20,9 @@ export interface QueryParseResult {
|
|
|
22
20
|
}
|
|
23
21
|
export declare class SqlBucketDescriptor implements BucketSource {
|
|
24
22
|
name: string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
get subscribedToByDefault(): boolean;
|
|
23
|
+
private bucketParametersInternal;
|
|
24
|
+
readonly subscribedToByDefault: boolean;
|
|
25
|
+
private readonly dataSource;
|
|
29
26
|
/**
|
|
30
27
|
* source table -> queries
|
|
31
28
|
*/
|
|
@@ -33,29 +30,18 @@ export declare class SqlBucketDescriptor implements BucketSource {
|
|
|
33
30
|
parameterQueries: SqlParameterQuery[];
|
|
34
31
|
globalParameterQueries: (StaticSqlParameterQuery | TableValuedFunctionSqlParameterQuery)[];
|
|
35
32
|
parameterIdSequence: IdSequence;
|
|
33
|
+
constructor(name: string);
|
|
34
|
+
get type(): BucketSourceType;
|
|
35
|
+
get bucketParameters(): string[];
|
|
36
|
+
get dataSources(): BucketDefinitionDataSource[];
|
|
37
|
+
get parameterIndexLookupCreators(): SqlParameterQuery[];
|
|
38
|
+
get parameterQuerierSources(): (StaticSqlParameterQuery | TableValuedFunctionSqlParameterQuery | SqlParameterQuery)[];
|
|
36
39
|
addDataQuery(sql: string, options: SyncRulesOptions, compatibility: CompatibilityContext): QueryParseResult;
|
|
37
40
|
addParameterQuery(sql: string, options: QueryParseOptions): QueryParseResult;
|
|
38
|
-
evaluateRow(options: EvaluateRowOptions): EvaluationResult[];
|
|
39
|
-
evaluateParameterRow(sourceTable: SourceTableInterface, row: SqliteRow): EvaluatedParametersResult[];
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Use `pushBucketParameterQueriers` instead and merge at the top-level.
|
|
42
|
-
*/
|
|
43
|
-
getBucketParameterQuerier(options: GetQuerierOptions): BucketParameterQuerier;
|
|
44
|
-
pushBucketParameterQueriers(result: PendingQueriers, options: GetQuerierOptions): void;
|
|
45
|
-
getStaticBucketDescriptions(parameters: RequestParameters, reasons: BucketInclusionReason[], transformer: BucketIdTransformer): ResolvedBucket[];
|
|
46
|
-
hasDynamicBucketQueries(): boolean;
|
|
47
|
-
getSourceTables(): Set<TablePattern>;
|
|
48
|
-
private bucketInclusionReason;
|
|
49
|
-
tableSyncsData(table: SourceTableInterface): boolean;
|
|
50
|
-
tableSyncsParameters(table: SourceTableInterface): boolean;
|
|
51
|
-
resolveResultSets(schema: SourceSchema, tables: Record<string, Record<string, ColumnDefinition>>): void;
|
|
52
|
-
debugWriteOutputTables(result: Record<string, {
|
|
53
|
-
query: string;
|
|
54
|
-
}[]>): void;
|
|
55
41
|
debugRepresentation(): {
|
|
56
42
|
name: string;
|
|
57
43
|
type: string;
|
|
58
|
-
bucket_parameters: string[]
|
|
44
|
+
bucket_parameters: string[];
|
|
59
45
|
global_parameter_queries: {
|
|
60
46
|
sql: string;
|
|
61
47
|
}[];
|
|
@@ -70,4 +56,21 @@ export declare class SqlBucketDescriptor implements BucketSource {
|
|
|
70
56
|
columns: string[];
|
|
71
57
|
}[];
|
|
72
58
|
};
|
|
59
|
+
hydrate(params: CreateSourceParams): HydratedBucketSource;
|
|
60
|
+
}
|
|
61
|
+
export declare class BucketDefinitionDataSource implements BucketDataSource {
|
|
62
|
+
private descriptor;
|
|
63
|
+
constructor(descriptor: SqlBucketDescriptor);
|
|
64
|
+
/**
|
|
65
|
+
* For debug use only.
|
|
66
|
+
*/
|
|
67
|
+
get bucketParameters(): string[];
|
|
68
|
+
get uniqueName(): string;
|
|
69
|
+
evaluateRow(options: EvaluateRowOptions): UnscopedEvaluationResult[];
|
|
70
|
+
getSourceTables(): Set<TablePattern>;
|
|
71
|
+
tableSyncsData(table: SourceTableInterface): boolean;
|
|
72
|
+
resolveResultSets(schema: SourceSchema, tables: Record<string, Record<string, ColumnDefinition>>): void;
|
|
73
|
+
debugWriteOutputTables(result: Record<string, {
|
|
74
|
+
query: string;
|
|
75
|
+
}[]>): void;
|
|
73
76
|
}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import { mergeBucketParameterQueriers } from './BucketParameterQuerier.js';
|
|
2
1
|
import { BucketSourceType } from './BucketSource.js';
|
|
3
2
|
import { IdSequence } from './IdSequence.js';
|
|
4
3
|
import { SqlDataQuery } from './SqlDataQuery.js';
|
|
5
4
|
import { SqlParameterQuery } from './SqlParameterQuery.js';
|
|
6
5
|
export class SqlBucketDescriptor {
|
|
7
6
|
name;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
get type() {
|
|
13
|
-
return BucketSourceType.SYNC_RULE;
|
|
14
|
-
}
|
|
15
|
-
get subscribedToByDefault() {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
7
|
+
bucketParametersInternal = null;
|
|
8
|
+
subscribedToByDefault = true;
|
|
9
|
+
dataSource = new BucketDefinitionDataSource(this);
|
|
18
10
|
/**
|
|
19
11
|
* source table -> queries
|
|
20
12
|
*/
|
|
@@ -22,11 +14,29 @@ export class SqlBucketDescriptor {
|
|
|
22
14
|
parameterQueries = [];
|
|
23
15
|
globalParameterQueries = [];
|
|
24
16
|
parameterIdSequence = new IdSequence();
|
|
17
|
+
constructor(name) {
|
|
18
|
+
this.name = name;
|
|
19
|
+
}
|
|
20
|
+
get type() {
|
|
21
|
+
return BucketSourceType.SYNC_RULE;
|
|
22
|
+
}
|
|
23
|
+
get bucketParameters() {
|
|
24
|
+
return this.bucketParametersInternal ?? [];
|
|
25
|
+
}
|
|
26
|
+
get dataSources() {
|
|
27
|
+
return [this.dataSource];
|
|
28
|
+
}
|
|
29
|
+
get parameterIndexLookupCreators() {
|
|
30
|
+
return this.parameterQueries;
|
|
31
|
+
}
|
|
32
|
+
get parameterQuerierSources() {
|
|
33
|
+
return [...this.parameterQueries, ...this.globalParameterQueries];
|
|
34
|
+
}
|
|
25
35
|
addDataQuery(sql, options, compatibility) {
|
|
26
|
-
if (this.
|
|
36
|
+
if (this.bucketParametersInternal == null) {
|
|
27
37
|
throw new Error('Bucket parameters must be defined');
|
|
28
38
|
}
|
|
29
|
-
const dataRows = SqlDataQuery.fromSql(this.
|
|
39
|
+
const dataRows = SqlDataQuery.fromSql(this.bucketParametersInternal, sql, options, compatibility);
|
|
30
40
|
this.dataQueries.push(dataRows);
|
|
31
41
|
return {
|
|
32
42
|
parsed: true,
|
|
@@ -34,12 +44,13 @@ export class SqlBucketDescriptor {
|
|
|
34
44
|
};
|
|
35
45
|
}
|
|
36
46
|
addParameterQuery(sql, options) {
|
|
37
|
-
const parameterQuery = SqlParameterQuery.fromSql(this.name, sql, options, this.parameterIdSequence.nextId());
|
|
38
|
-
if (this.
|
|
39
|
-
this.
|
|
47
|
+
const parameterQuery = SqlParameterQuery.fromSql(this.name, sql, options, this.parameterIdSequence.nextId(), this.dataSource);
|
|
48
|
+
if (this.bucketParametersInternal == null) {
|
|
49
|
+
this.bucketParametersInternal = parameterQuery.bucketParameters;
|
|
40
50
|
}
|
|
41
51
|
else {
|
|
42
|
-
if (new Set([...parameterQuery.bucketParameters, ...this.
|
|
52
|
+
if (new Set([...parameterQuery.bucketParameters, ...this.bucketParametersInternal]).size !=
|
|
53
|
+
this.bucketParametersInternal.length) {
|
|
43
54
|
throw new Error('Bucket parameters must match for each parameter query within a bucket');
|
|
44
55
|
}
|
|
45
56
|
}
|
|
@@ -54,89 +65,83 @@ export class SqlBucketDescriptor {
|
|
|
54
65
|
errors: parameterQuery.errors
|
|
55
66
|
};
|
|
56
67
|
}
|
|
57
|
-
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
debugRepresentation() {
|
|
69
|
+
let all_parameter_queries = [...this.parameterQueries.values()].flat();
|
|
70
|
+
let all_data_queries = [...this.dataQueries.values()].flat();
|
|
71
|
+
return {
|
|
72
|
+
name: this.name,
|
|
73
|
+
type: BucketSourceType[this.type],
|
|
74
|
+
bucket_parameters: this.bucketParameters,
|
|
75
|
+
global_parameter_queries: this.globalParameterQueries.map((q) => {
|
|
76
|
+
return {
|
|
77
|
+
sql: q.sql
|
|
78
|
+
};
|
|
79
|
+
}),
|
|
80
|
+
parameter_queries: all_parameter_queries.map((q) => {
|
|
81
|
+
return {
|
|
82
|
+
sql: q.sql,
|
|
83
|
+
table: q.sourceTable,
|
|
84
|
+
input_parameters: q.inputParameters
|
|
85
|
+
};
|
|
86
|
+
}),
|
|
87
|
+
data_queries: all_data_queries.map((q) => {
|
|
88
|
+
return {
|
|
89
|
+
sql: q.sql,
|
|
90
|
+
table: q.sourceTable,
|
|
91
|
+
columns: q.columnOutputNames()
|
|
92
|
+
};
|
|
93
|
+
})
|
|
94
|
+
};
|
|
66
95
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
96
|
+
hydrate(params) {
|
|
97
|
+
const hydratedParameterQueriers = this.parameterQueries.map((querier) => querier.createParameterQuerierSource(params));
|
|
98
|
+
const hydratedGlobalParameterQueriers = this.globalParameterQueries.map((querier) => querier.createParameterQuerierSource(params));
|
|
99
|
+
return {
|
|
100
|
+
definition: this,
|
|
101
|
+
pushBucketParameterQueriers: (result, options) => {
|
|
102
|
+
for (let querier of hydratedParameterQueriers) {
|
|
103
|
+
querier.pushBucketParameterQueriers(result, options);
|
|
104
|
+
}
|
|
105
|
+
for (let querier of hydratedGlobalParameterQueriers) {
|
|
106
|
+
querier.pushBucketParameterQueriers(result, options);
|
|
107
|
+
}
|
|
72
108
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export class BucketDefinitionDataSource {
|
|
113
|
+
descriptor;
|
|
114
|
+
constructor(descriptor) {
|
|
115
|
+
this.descriptor = descriptor;
|
|
75
116
|
}
|
|
76
117
|
/**
|
|
77
|
-
*
|
|
118
|
+
* For debug use only.
|
|
78
119
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
pushBucketParameterQueriers(result, options) {
|
|
85
|
-
const reasons = [this.bucketInclusionReason()];
|
|
86
|
-
const staticBuckets = this.getStaticBucketDescriptions(options.globalParameters, reasons, options.bucketIdTransformer);
|
|
87
|
-
const staticQuerier = {
|
|
88
|
-
staticBuckets,
|
|
89
|
-
hasDynamicBuckets: false,
|
|
90
|
-
parameterQueryLookups: [],
|
|
91
|
-
queryDynamicBucketDescriptions: async () => []
|
|
92
|
-
};
|
|
93
|
-
result.queriers.push(staticQuerier);
|
|
94
|
-
if (this.parameterQueries.length == 0) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const dynamicQueriers = this.parameterQueries.map((query) => query.getBucketParameterQuerier(options.globalParameters, reasons, options.bucketIdTransformer));
|
|
98
|
-
result.queriers.push(...dynamicQueriers);
|
|
120
|
+
get bucketParameters() {
|
|
121
|
+
return this.descriptor.bucketParameters;
|
|
122
|
+
}
|
|
123
|
+
get uniqueName() {
|
|
124
|
+
return this.descriptor.name;
|
|
99
125
|
}
|
|
100
|
-
|
|
126
|
+
evaluateRow(options) {
|
|
101
127
|
let results = [];
|
|
102
|
-
for (let query of this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
...desc,
|
|
106
|
-
definition: this.name,
|
|
107
|
-
inclusion_reasons: reasons
|
|
108
|
-
});
|
|
128
|
+
for (let query of this.descriptor.dataQueries) {
|
|
129
|
+
if (!query.applies(options.sourceTable)) {
|
|
130
|
+
continue;
|
|
109
131
|
}
|
|
132
|
+
results.push(...query.evaluateRow(options.sourceTable, options.record));
|
|
110
133
|
}
|
|
111
134
|
return results;
|
|
112
135
|
}
|
|
113
|
-
hasDynamicBucketQueries() {
|
|
114
|
-
return this.parameterQueries.length > 0;
|
|
115
|
-
}
|
|
116
136
|
getSourceTables() {
|
|
117
137
|
let result = new Set();
|
|
118
|
-
for (let query of this.
|
|
119
|
-
result.add(query.sourceTable);
|
|
120
|
-
}
|
|
121
|
-
for (let query of this.dataQueries) {
|
|
138
|
+
for (let query of this.descriptor.dataQueries) {
|
|
122
139
|
result.add(query.sourceTable);
|
|
123
140
|
}
|
|
124
|
-
// Note: No physical tables for global_parameter_queries
|
|
125
141
|
return result;
|
|
126
142
|
}
|
|
127
|
-
bucketInclusionReason() {
|
|
128
|
-
return 'default';
|
|
129
|
-
}
|
|
130
143
|
tableSyncsData(table) {
|
|
131
|
-
for (let query of this.dataQueries) {
|
|
132
|
-
if (query.applies(table)) {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
tableSyncsParameters(table) {
|
|
139
|
-
for (let query of this.parameterQueries) {
|
|
144
|
+
for (let query of this.descriptor.dataQueries) {
|
|
140
145
|
if (query.applies(table)) {
|
|
141
146
|
return true;
|
|
142
147
|
}
|
|
@@ -144,12 +149,12 @@ export class SqlBucketDescriptor {
|
|
|
144
149
|
return false;
|
|
145
150
|
}
|
|
146
151
|
resolveResultSets(schema, tables) {
|
|
147
|
-
for (let query of this.dataQueries) {
|
|
152
|
+
for (let query of this.descriptor.dataQueries) {
|
|
148
153
|
query.resolveResultSets(schema, tables);
|
|
149
154
|
}
|
|
150
155
|
}
|
|
151
156
|
debugWriteOutputTables(result) {
|
|
152
|
-
for (let q of this.dataQueries) {
|
|
157
|
+
for (let q of this.descriptor.dataQueries) {
|
|
153
158
|
result[q.table.sqlName] ??= [];
|
|
154
159
|
const r = {
|
|
155
160
|
query: q.sql
|
|
@@ -157,33 +162,5 @@ export class SqlBucketDescriptor {
|
|
|
157
162
|
result[q.table.sqlName].push(r);
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
|
-
debugRepresentation() {
|
|
161
|
-
let all_parameter_queries = [...this.parameterQueries.values()].flat();
|
|
162
|
-
let all_data_queries = [...this.dataQueries.values()].flat();
|
|
163
|
-
return {
|
|
164
|
-
name: this.name,
|
|
165
|
-
type: BucketSourceType[this.type],
|
|
166
|
-
bucket_parameters: this.bucketParameters,
|
|
167
|
-
global_parameter_queries: this.globalParameterQueries.map((q) => {
|
|
168
|
-
return {
|
|
169
|
-
sql: q.sql
|
|
170
|
-
};
|
|
171
|
-
}),
|
|
172
|
-
parameter_queries: all_parameter_queries.map((q) => {
|
|
173
|
-
return {
|
|
174
|
-
sql: q.sql,
|
|
175
|
-
table: q.sourceTable,
|
|
176
|
-
input_parameters: q.inputParameters
|
|
177
|
-
};
|
|
178
|
-
}),
|
|
179
|
-
data_queries: all_data_queries.map((q) => {
|
|
180
|
-
return {
|
|
181
|
-
sql: q.sql,
|
|
182
|
-
table: q.sourceTable,
|
|
183
|
-
columns: q.columnOutputNames()
|
|
184
|
-
};
|
|
185
|
-
})
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
165
|
}
|
|
189
166
|
//# sourceMappingURL=SqlBucketDescriptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlBucketDescriptor.js","sourceRoot":"","sources":["../src/SqlBucketDescriptor.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"SqlBucketDescriptor.js","sourceRoot":"","sources":["../src/SqlBucketDescriptor.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,gBAAgB,EAGjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAkB3D,MAAM,OAAO,mBAAmB;IAC9B,IAAI,CAAS;IACL,wBAAwB,GAAoB,IAAI,CAAC;IAEzC,qBAAqB,GAAY,IAAI,CAAC;IAErC,UAAU,GAAG,IAAI,0BAA0B,CAAC,IAAI,CAAC,CAAC;IAEnE;;OAEG;IACH,WAAW,GAAmB,EAAE,CAAC;IACjC,gBAAgB,GAAwB,EAAE,C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,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,sBAAsB,CAAC,MAA2C;QAChE,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;YAC1C,MAAM,CAAC,CAAC,CAAC,KAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAChC,MAAM,CAAC,GAAG;gBACR,KAAK,EAAE,CAAC,CAAC,GAAG;aACb,CAAC;YAEF,MAAM,CAAC,CAAC,CAAC,KAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;CACF"}
|
package/dist/SqlDataQuery.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { BaseSqlDataQuery, BaseSqlDataQueryOptions } from './BaseSqlDataQuery.js';
|
|
2
|
+
import { CompatibilityContext } from './compatibility.js';
|
|
2
3
|
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
3
4
|
import { SyncRulesOptions } from './SqlSyncRules.js';
|
|
4
|
-
import {
|
|
5
|
-
import { CompatibilityContext } from './compatibility.js';
|
|
5
|
+
import { ParameterMatchClause, UnscopedEvaluationResult, SqliteRow } from './types.js';
|
|
6
6
|
export interface SqlDataQueryOptions extends BaseSqlDataQueryOptions {
|
|
7
7
|
filter: ParameterMatchClause;
|
|
8
8
|
}
|
|
9
9
|
export declare class SqlDataQuery extends BaseSqlDataQuery {
|
|
10
|
-
static fromSql(
|
|
10
|
+
static fromSql(bucketParameters: string[], sql: string, options: SyncRulesOptions, compatibility: CompatibilityContext): SqlDataQuery;
|
|
11
11
|
/**
|
|
12
12
|
* The query WHERE clause.
|
|
13
13
|
*
|
|
@@ -17,5 +17,5 @@ export declare class SqlDataQuery extends BaseSqlDataQuery {
|
|
|
17
17
|
*/
|
|
18
18
|
readonly filter: ParameterMatchClause;
|
|
19
19
|
constructor(options: SqlDataQueryOptions);
|
|
20
|
-
evaluateRow(table: SourceTableInterface, row: SqliteRow
|
|
20
|
+
evaluateRow(table: SourceTableInterface, row: SqliteRow): UnscopedEvaluationResult[];
|
|
21
21
|
}
|
package/dist/SqlDataQuery.js
CHANGED
|
@@ -7,9 +7,9 @@ import { AvailableTable, SqlTools } from './sql_filters.js';
|
|
|
7
7
|
import { checkUnsupportedFeatures, isClauseError } from './sql_support.js';
|
|
8
8
|
import { TablePattern } from './TablePattern.js';
|
|
9
9
|
import { TableQuerySchema } from './TableQuerySchema.js';
|
|
10
|
-
import {
|
|
10
|
+
import { isSelectStatement, serializeBucketParameters } from './utils.js';
|
|
11
11
|
export class SqlDataQuery extends BaseSqlDataQuery {
|
|
12
|
-
static fromSql(
|
|
12
|
+
static fromSql(bucketParameters, sql, options, compatibility) {
|
|
13
13
|
const parsed = parse(sql, { locationTracking: true });
|
|
14
14
|
const schema = options.schema;
|
|
15
15
|
let errors = [];
|
|
@@ -131,7 +131,6 @@ export class SqlDataQuery extends BaseSqlDataQuery {
|
|
|
131
131
|
sql,
|
|
132
132
|
filter,
|
|
133
133
|
columns: q.columns ?? [],
|
|
134
|
-
descriptorName,
|
|
135
134
|
bucketParameters,
|
|
136
135
|
tools,
|
|
137
136
|
errors,
|
|
@@ -150,13 +149,13 @@ export class SqlDataQuery extends BaseSqlDataQuery {
|
|
|
150
149
|
super(options);
|
|
151
150
|
this.filter = options.filter;
|
|
152
151
|
}
|
|
153
|
-
evaluateRow(table, row
|
|
152
|
+
evaluateRow(table, row) {
|
|
154
153
|
return this.evaluateRowWithOptions({
|
|
155
154
|
table,
|
|
156
155
|
row,
|
|
157
|
-
|
|
156
|
+
serializedBucketParameters: (tables) => {
|
|
158
157
|
const bucketParameters = this.filter.filterRow(tables);
|
|
159
|
-
return bucketParameters.map((params) =>
|
|
158
|
+
return bucketParameters.map((params) => serializeBucketParameters(this.bucketParameters, params));
|
|
160
159
|
}
|
|
161
160
|
});
|
|
162
161
|
}
|