Skip to content

Commit 7447e24

Browse files
committed
Remove ruleId; rename id -> queryId.
1 parent 4c7a8fc commit 7447e24

12 files changed

+62
-90
lines changed

packages/sync-rules/src/BaseSqlDataQuery.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export interface BaseSqlDataQueryOptions {
2222
bucketParameters: string[];
2323
tools: SqlTools;
2424

25-
ruleId: string;
26-
2725
errors?: SqlRuleError[];
2826
}
2927

@@ -73,8 +71,6 @@ export class BaseSqlDataQuery {
7371
*/
7472
private readonly tools: SqlTools;
7573

76-
readonly ruleId: string;
77-
7874
readonly errors: SqlRuleError[];
7975

8076
constructor(options: BaseSqlDataQueryOptions) {
@@ -86,7 +82,6 @@ export class BaseSqlDataQuery {
8682
this.descriptorName = options.descriptorName;
8783
this.bucketParameters = options.bucketParameters;
8884
this.tools = options.tools;
89-
this.ruleId = options.ruleId;
9085
this.errors = options.errors ?? [];
9186
}
9287

packages/sync-rules/src/SqlBucketDescriptor.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ export class SqlBucketDescriptor {
3131
name: string;
3232
bucketParameters?: string[];
3333

34-
constructor(
35-
name: string,
36-
public idSequence: IdSequence
37-
) {
34+
constructor(name: string) {
3835
this.name = name;
3936
}
4037

@@ -51,7 +48,7 @@ export class SqlBucketDescriptor {
5148
if (this.bucketParameters == null) {
5249
throw new Error('Bucket parameters must be defined');
5350
}
54-
const dataRows = SqlDataQuery.fromSql(this.name, this.bucketParameters, sql, options, this.idSequence.nextId());
51+
const dataRows = SqlDataQuery.fromSql(this.name, this.bucketParameters, sql, options);
5552

5653
this.dataQueries.push(dataRows);
5754

packages/sync-rules/src/SqlDataQuery.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ export interface SqlDataQueryOptions extends BaseSqlDataQueryOptions {
1818
}
1919

2020
export class SqlDataQuery extends BaseSqlDataQuery {
21-
static fromSql(
22-
descriptorName: string,
23-
bucketParameters: string[],
24-
sql: string,
25-
options: SyncRulesOptions,
26-
ruleId?: string
27-
) {
21+
static fromSql(descriptorName: string, bucketParameters: string[], sql: string, options: SyncRulesOptions) {
2822
const parsed = parse(sql, { locationTracking: true });
2923
const schema = options.schema;
3024

@@ -172,7 +166,6 @@ export class SqlDataQuery extends BaseSqlDataQuery {
172166
descriptorName,
173167
bucketParameters,
174168
tools,
175-
ruleId: ruleId ?? '',
176169
errors,
177170
extractors
178171
});
@@ -218,8 +211,7 @@ export class SqlDataQuery extends BaseSqlDataQuery {
218211
bucket: bucketId,
219212
table: outputTable,
220213
id: id,
221-
data,
222-
ruleId: this.ruleId
214+
data
223215
} as EvaluationResult;
224216
});
225217
} catch (e) {

packages/sync-rules/src/SqlParameterQuery.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface SqlParameterQueryOptions {
3737
inputParameters: InputParameter[];
3838
expandedInputParameter: InputParameter | undefined;
3939
bucketParameters: string[];
40-
id: string;
40+
queryId: string;
4141
tools: SqlTools;
4242
errors?: SqlRuleError[];
4343
}
@@ -178,7 +178,7 @@ export class SqlParameterQuery {
178178
inputParameters: filter.inputParameters,
179179
expandedInputParameter: expandedParams[0],
180180
bucketParameters,
181-
id: queryId,
181+
queryId,
182182
tools,
183183
errors
184184
});
@@ -263,7 +263,14 @@ export class SqlParameterQuery {
263263
*/
264264
readonly bucketParameters: string[];
265265

266-
readonly id: string;
266+
/**
267+
* Unique identifier for this query within a bucket definition.
268+
*
269+
* Typically auto-generated based on query order.
270+
*
271+
* This is used when persisting lookup values.
272+
*/
273+
readonly queryId: string;
267274
readonly tools: SqlTools;
268275

269276
readonly errors: SqlRuleError[];
@@ -280,7 +287,7 @@ export class SqlParameterQuery {
280287
this.inputParameters = options.inputParameters;
281288
this.expandedInputParameter = options.expandedInputParameter;
282289
this.bucketParameters = options.bucketParameters;
283-
this.id = options.id;
290+
this.queryId = options.queryId;
284291
this.tools = options.tools;
285292
this.errors = options.errors ?? [];
286293
}
@@ -300,7 +307,7 @@ export class SqlParameterQuery {
300307
const filterParameters = this.filter.filterRow(tables);
301308
let result: EvaluatedParametersResult[] = [];
302309
for (let filterParamSet of filterParameters) {
303-
let lookup: SqliteJsonValue[] = [this.descriptorName, this.id];
310+
let lookup: SqliteJsonValue[] = [this.descriptorName, this.queryId];
304311
lookup.push(
305312
...this.inputParameters.map((param) => {
306313
return normalizeParameterValue(param.filteredRowToLookupValue(filterParamSet));
@@ -374,7 +381,7 @@ export class SqlParameterQuery {
374381
*/
375382
getLookups(parameters: RequestParameters): ParameterLookup[] {
376383
if (!this.expandedInputParameter) {
377-
let lookup: SqliteJsonValue[] = [this.descriptorName, this.id];
384+
let lookup: SqliteJsonValue[] = [this.descriptorName, this.queryId];
378385

379386
let valid = true;
380387
lookup.push(
@@ -412,7 +419,7 @@ export class SqlParameterQuery {
412419

413420
return values
414421
.map((expandedValue) => {
415-
let lookup: SqliteJsonValue[] = [this.descriptorName, this.id];
422+
let lookup: SqliteJsonValue[] = [this.descriptorName, this.queryId];
416423
let valid = true;
417424
const normalizedExpandedValue = normalizeParameterValue(expandedValue);
418425
lookup.push(

packages/sync-rules/src/SqlSyncRules.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export interface SyncRulesOptions {
4242
export class SqlSyncRules implements SyncRules {
4343
bucketDescriptors: SqlBucketDescriptor[] = [];
4444
eventDescriptors: SqlEventDescriptor[] = [];
45-
idSequence = new IdSequence();
4645

4746
content: string;
4847

@@ -137,7 +136,7 @@ export class SqlSyncRules implements SyncRules {
137136
const parameters = value.get('parameters', true) as unknown;
138137
const dataQueries = value.get('data', true) as unknown;
139138

140-
const descriptor = new SqlBucketDescriptor(key, rules.idSequence);
139+
const descriptor = new SqlBucketDescriptor(key);
141140

142141
if (parameters instanceof Scalar) {
143142
rules.withScalar(parameters, (q) => {
@@ -180,7 +179,7 @@ export class SqlSyncRules implements SyncRules {
180179
continue;
181180
}
182181

183-
const eventDescriptor = new SqlEventDescriptor(key.toString(), rules.idSequence);
182+
const eventDescriptor = new SqlEventDescriptor(key.toString());
184183
for (let item of payloads.items) {
185184
if (!isScalar(item)) {
186185
rules.errors.push(new YamlError(new Error(`Payload queries for events must be scalar.`)));

packages/sync-rules/src/StaticSqlParameterQuery.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface StaticSqlParameterQueryOptions {
1212
priority: BucketPriority;
1313
descriptorName: string;
1414
bucketParameters: string[];
15-
id: string;
15+
queryId: string;
1616
filter: ParameterValueClause | undefined;
1717
errors?: SqlRuleError[];
1818
}
@@ -84,7 +84,7 @@ export class StaticSqlParameterQuery {
8484
parameterExtractors,
8585
priority: priority ?? DEFAULT_BUCKET_PRIORITY,
8686
filter: isClauseError(filter) ? undefined : filter,
87-
id: queryId,
87+
queryId,
8888
errors
8989
});
9090
if (query.usesDangerousRequestParameters && !options?.accept_potentially_dangerous_queries) {
@@ -124,7 +124,14 @@ export class StaticSqlParameterQuery {
124124
*/
125125
readonly bucketParameters: string[];
126126

127-
readonly id: string;
127+
/**
128+
* Unique identifier for this query within a bucket definition.
129+
*
130+
* Typically auto-generated based on query order.
131+
*
132+
* This is not used directly, but we keep this to match behavior of other parameter queries.
133+
*/
134+
readonly queryId: string;
128135

129136
/**
130137
* The query filter (WHERE clause). Given request parameters, the filter will determine whether or not this query returns a row.
@@ -141,7 +148,7 @@ export class StaticSqlParameterQuery {
141148
this.priority = options.priority;
142149
this.descriptorName = options.descriptorName;
143150
this.bucketParameters = options.bucketParameters;
144-
this.id = options.id;
151+
this.queryId = options.queryId;
145152
this.filter = options.filter;
146153
this.errors = options.errors ?? [];
147154
}

packages/sync-rules/src/TableValuedFunctionSqlParameterQuery.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ export interface TableValuedFunctionSqlParameterQueryOptions {
1919
parameterExtractors: Record<string, ParameterValueClause>;
2020
priority: BucketPriority;
2121
descriptorName: string;
22-
/** _Output_ bucket parameters */
2322
bucketParameters: string[];
24-
id: string;
23+
queryId: string;
2524

2625
filter: ParameterValueClause | undefined;
2726
callClause: ParameterValueClause | undefined;
@@ -107,7 +106,7 @@ export class TableValuedFunctionSqlParameterQuery {
107106
function: functionImpl,
108107
callTableName: callTable,
109108
priority: priority ?? DEFAULT_BUCKET_PRIORITY,
110-
id: queryId,
109+
queryId,
111110
errors
112111
});
113112

@@ -148,7 +147,14 @@ export class TableValuedFunctionSqlParameterQuery {
148147
*/
149148
readonly bucketParameters: string[];
150149

151-
readonly id: string;
150+
/**
151+
* Unique identifier for this query within a bucket definition.
152+
*
153+
* Typically auto-generated based on query order.
154+
*
155+
* This is not used directly, but we keep this to match behavior of other parameter queries.
156+
*/
157+
readonly queryId: string;
152158

153159
/**
154160
* The WHERE clause. This is applied on (request parameters + individual function call result row).
@@ -186,7 +192,7 @@ export class TableValuedFunctionSqlParameterQuery {
186192
this.priority = options.priority;
187193
this.descriptorName = options.descriptorName;
188194
this.bucketParameters = options.bucketParameters;
189-
this.id = options.id;
195+
this.queryId = options.queryId;
190196

191197
this.filter = options.filter;
192198
this.callClause = options.callClause;

packages/sync-rules/src/events/SqlEventDescriptor.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ export class SqlEventDescriptor {
1414
name: string;
1515
sourceQueries: SqlEventSourceQuery[] = [];
1616

17-
constructor(
18-
name: string,
19-
public idSequence: IdSequence
20-
) {
17+
constructor(name: string) {
2118
this.name = name;
2219
}
2320

2421
addSourceQuery(sql: string, options: SyncRulesOptions): QueryParseResult {
25-
const source = SqlEventSourceQuery.fromSql(this.name, sql, options, this.idSequence.nextId());
22+
const source = SqlEventSourceQuery.fromSql(this.name, sql, options);
2623

2724
// Each source query should be for a unique table
2825
const existingSourceQuery = this.sourceQueries.find((q) => q.table == source.table);

packages/sync-rules/src/events/SqlEventSourceQuery.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { isSelectStatement } from '../utils.js';
1313

1414
export type EvaluatedEventSourceRow = {
1515
data: SqliteJsonRow;
16-
ruleId?: string;
1716
};
1817

1918
export type EvaluatedEventRowWithErrors = {
@@ -25,7 +24,7 @@ export type EvaluatedEventRowWithErrors = {
2524
* Defines how a Replicated Row is mapped to source parameters for events.
2625
*/
2726
export class SqlEventSourceQuery extends BaseSqlDataQuery {
28-
static fromSql(descriptor_name: string, sql: string, options: SyncRulesOptions, ruleId: string) {
27+
static fromSql(descriptor_name: string, sql: string, options: SyncRulesOptions) {
2928
const parsed = parse(sql, { locationTracking: true });
3029
const schema = options.schema;
3130

@@ -125,7 +124,6 @@ export class SqlEventSourceQuery extends BaseSqlDataQuery {
125124
extractors: extractors,
126125
tools,
127126
bucketParameters: [],
128-
ruleId: ruleId,
129127
errors: errors
130128
});
131129
}
@@ -141,8 +139,7 @@ export class SqlEventSourceQuery extends BaseSqlDataQuery {
141139
const data = this.transformRow(tables);
142140
return {
143141
result: {
144-
data,
145-
ruleId: this.ruleId
142+
data
146143
},
147144
errors: []
148145
};

packages/sync-rules/src/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ export interface EvaluatedRow {
4444

4545
/** Must be JSON-serializable. */
4646
data: SqliteJsonRow;
47-
48-
/** For debugging purposes only. */
49-
ruleId?: string;
5047
}
5148

5249
export interface EvaluationError {

0 commit comments

Comments
 (0)