Skip to content

Commit f86ed1a

Browse files
authored
fix(realtime): handle null at convertChangeData (#539)
1 parent 2eaebbc commit f86ed1a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/core/realtime-js/src/lib/transformers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ type Record = {
6060
*/
6161
export const convertChangeData = (
6262
columns: Columns,
63-
record: Record,
63+
record: Record | null,
6464
options: { skipTypes?: string[] } = {}
6565
): Record => {
6666
const skipTypes = options.skipTypes ?? []
6767

68+
if (!record) {
69+
return {}
70+
}
71+
6872
return Object.keys(record).reduce((acc, rec_key) => {
6973
acc[rec_key] = convertColumn(rec_key, columns, record, skipTypes)
7074
return acc

packages/core/realtime-js/test/transformers.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ test('convertChangeData', () => {
4646
),
4747
{ first_name: 'Paul', age: null }
4848
)
49+
50+
assert.deepEqual(
51+
convertChangeData(
52+
[
53+
{ name: 'first_name', type: 'text' },
54+
{ name: 'age', type: 'int4' },
55+
],
56+
null,
57+
{}
58+
),
59+
{}
60+
)
4961
})
5062

5163
test('convertColumn', () => {

0 commit comments

Comments
 (0)