@syncular/server 0.81.0 → 0.82.1

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.
@@ -82,10 +82,12 @@ export function prepareAuthoritativeQuery(plan, params, declaredTables, tables)
82
82
  throw new Error('registered query targets an unknown table');
83
83
  if (!table.materialize)
84
84
  throw new Error('registered query targets a non-materialized table');
85
+ // A `json` column reads as its JSON text on every storage: PostgreSQL
86
+ // stores it as JSONB, which its drivers would return parsed.
85
87
  return {
86
88
  start: relation.start,
87
89
  end: relation.end,
88
- text: `(SELECT ${table.columns.map((column) => quoteIdent(column.name)).join(', ')} FROM ${quoteIdent(table.name)} WHERE ${quoteIdent(SYNC_PARTITION_COLUMN)}=?)${relation.alias === undefined ? ` AS ${quoteIdent(table.name)}` : ''}`,
90
+ text: `(SELECT ${table.columns.map((column) => (column.type === 'json' ? `CAST(${quoteIdent(column.name)} AS TEXT) AS ${quoteIdent(column.name)}` : quoteIdent(column.name))).join(', ')} FROM ${quoteIdent(table.name)} WHERE ${quoteIdent(SYNC_PARTITION_COLUMN)}=?)${relation.alias === undefined ? ` AS ${quoteIdent(table.name)}` : ''}`,
89
91
  };
90
92
  });
91
93
  const bound = [];
@@ -57,15 +57,12 @@ function normalizeQueryRows(rows, columns) {
57
57
  throw syncError('operation.query_failed', 'registered query returned an invalid boolean');
58
58
  }
59
59
  break;
60
- case 'json': {
61
- const json = typeof value === 'string' ? value : JSON.stringify(value);
62
- if (json === undefined) {
60
+ case 'json':
61
+ if (typeof value !== 'string') {
63
62
  throw syncError('operation.query_failed', 'registered query returned invalid JSON');
64
63
  }
65
- JSON.parse(json);
66
- normalized[column.name] = json;
64
+ JSON.parse(value);
67
65
  break;
68
- }
69
66
  case 'bytes':
70
67
  case 'crdt': {
71
68
  const bytes = value instanceof Uint8Array