Skip to content

Commit f400b0f

Browse files
authored
Allow null as stream parameter (#357)
* Allow `null` as stream parameter * Additional test
1 parent a2b8bb0 commit f400b0f

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

.changeset/yellow-knives-behave.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@powersync/service-core': patch
3+
'@powersync/service-image': patch
4+
---
5+
6+
Protocol: Allow `null` as stream parameter.

packages/service-core/src/util/protocol-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as t from 'ts-codec';
2-
import { BucketDescription, BucketPriority, SqliteJsonRow } from '@powersync/service-sync-rules';
2+
import { BucketPriority, SqliteJsonRow } from '@powersync/service-sync-rules';
33
import { JsonContainer } from '@powersync/service-jsonbig';
44

55
export const BucketRequest = t.object({
@@ -24,7 +24,7 @@ export const RequestedStreamSubscription = t.object({
2424
/**
2525
* An optional dictionary of parameters to pass to this specific stream.
2626
*/
27-
parameters: t.record(t.any).optional(),
27+
parameters: t.union(t.record(t.any), t.Null),
2828
/**
2929
* Set when the client wishes to re-assign a different priority to this stream.
3030
*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { StreamingSyncRequest } from '@/index.js';
2+
import { schema } from '@powersync/lib-services-framework';
3+
import { describe, test, expect, it } from 'vitest';
4+
5+
describe('protocol types', () => {
6+
describe('StreamingSyncRequest', () => {
7+
const validator = schema.createTsCodecValidator(StreamingSyncRequest, { allowAdditional: true });
8+
9+
test('with streams', () => {
10+
expect(
11+
validator.validate({
12+
buckets: [],
13+
include_checksum: true,
14+
raw_data: true,
15+
binary_data: true,
16+
client_id: '0da33a94-c140-4b42-b3b3-a1df3b1352a3',
17+
parameters: {},
18+
streams: {
19+
include_defaults: true,
20+
subscriptions: [{ stream: 'does_not_exist', parameters: null, override_priority: null }]
21+
}
22+
} as any)
23+
).toMatchObject({ valid: true });
24+
});
25+
26+
test('does not allow missing parameters', () => {
27+
expect(
28+
validator.validate({
29+
buckets: [],
30+
include_checksum: true,
31+
raw_data: true,
32+
binary_data: true,
33+
client_id: '0da33a94-c140-4b42-b3b3-a1df3b1352a3',
34+
parameters: {},
35+
streams: {
36+
include_defaults: true,
37+
subscriptions: [{ stream: 'a', override_priority: null }]
38+
}
39+
} as any)
40+
).toMatchObject({ valid: false });
41+
});
42+
});
43+
});

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { BucketInclusionReason, BucketPriority, DEFAULT_BUCKET_PRIORITY } from '
33
import { BucketParameterQuerier, PendingQueriers } from '../BucketParameterQuerier.js';
44
import { BucketSource, BucketSourceType, ResultSetDescription } from '../BucketSource.js';
55
import { ColumnDefinition } from '../ExpressionType.js';
6-
import { CompatibilityContext } from '../compatibility.js';
76
import { SourceTableInterface } from '../SourceTableInterface.js';
87
import { GetQuerierOptions, RequestedStream } from '../SqlSyncRules.js';
98
import { TablePattern } from '../TablePattern.js';
@@ -17,7 +16,6 @@ import {
1716
SqliteRow,
1817
TableRow
1918
} from '../types.js';
20-
import { applyRowContext } from '../utils.js';
2119
import { StreamVariant } from './variant.js';
2220

2321
export class SyncStream implements BucketSource {

0 commit comments

Comments
 (0)