Skip to content

Commit d187144

Browse files
committed
Update rules schema
1 parent 71ca65c commit d187144

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

packages/sync-rules/src/SqlSyncRules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ export class SqlSyncRules implements SyncRules {
227227
...options,
228228
accept_potentially_dangerous_queries,
229229
priority: rules.parsePriority(value),
230-
default: value.get('default', true)?.value == true
230+
auto_subscribe: value.get('auto_subscribe', true)?.value == true
231231
};
232232

233233
const data = value.get('query', true) as unknown;
234234
if (data instanceof Scalar) {
235235
rules.withScalar(data, (q) => {
236-
const [parsed, errors] = syncStreamFromSql(key, q, options);
236+
const [parsed, errors] = syncStreamFromSql(key, q, queryOptions);
237237
rules.bucketSources.push(parsed);
238238
return {
239239
parsed: true,

packages/sync-rules/src/json_schema.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ export const syncRulesSchema: ajvModule.Schema = {
4949
}
5050
}
5151
},
52+
streams: {
53+
type: 'object',
54+
description: 'List of stream definitions',
55+
examples: [{ user_details: { query: 'select * from users where id = auth.user_id()' } }],
56+
patternProperties: {
57+
'.*': {
58+
type: 'object',
59+
required: ['data'],
60+
examples: [{ data: ['select * from mytable'] }],
61+
properties: {
62+
accept_potentially_dangerous_queries: {
63+
description: 'If true, disables warnings on potentially dangerous queries',
64+
type: 'boolean'
65+
},
66+
auto_subscribe: {
67+
description: 'Whether clients will subscribe to this stream by default.',
68+
type: 'boolean'
69+
},
70+
priority: {
71+
description: 'Priority for the bucket (lower values indicate higher priority).',
72+
type: 'integer'
73+
},
74+
query: {
75+
description: 'The SQL query defining content to sync in this stream.',
76+
type: 'string'
77+
}
78+
}
79+
}
80+
}
81+
},
5282
event_definitions: {
5383
type: 'object',
5484
description: 'Record of sync replication event definitions',
@@ -79,7 +109,7 @@ export const syncRulesSchema: ajvModule.Schema = {
79109
}
80110
}
81111
},
82-
required: ['bucket_definitions'],
112+
required: [],
83113
additionalProperties: false
84114
} as const;
85115

packages/sync-rules/src/streams/from_sql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SyncStreamCompiler {
9393
this.descriptorName,
9494
new BaseSqlDataQuery(this.compileDataQuery(tools, query, alias, sourceTable))
9595
);
96-
stream.subscribedToByDefault = this.options.default ?? false;
96+
stream.subscribedToByDefault = this.options.auto_subscribe ?? false;
9797
if (filter.isValid(tools)) {
9898
stream.variants = filter.compileVariants(this.descriptorName);
9999
}

packages/sync-rules/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface QueryParseOptions extends SyncRulesOptions {
1919
}
2020

2121
export interface StreamParseOptions extends QueryParseOptions {
22-
default?: boolean;
22+
auto_subscribe?: boolean;
2323
}
2424

2525
export interface EvaluatedParameters {

0 commit comments

Comments
 (0)