@dinoxx/dinox-cli 2.1.0 → 2.1.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.
- package/dist/powersync/uploader.js +27 -2
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { UpdateType } from '@powersync/common';
|
|
|
3
3
|
import { createTimeoutSignal, mergeAbortSignals } from '../utils/abort.js';
|
|
4
4
|
import { toAuthorizationHeaderValue } from '../utils/authToken.js';
|
|
5
5
|
import { sanitizeForTerminal } from '../utils/terminalSanitization.js';
|
|
6
|
+
import { nowIsoUtc } from '../utils/time.js';
|
|
6
7
|
/**
|
|
7
8
|
* Uploads each PowerSync CRUD transaction as ONE request to the backend v6 batch
|
|
8
9
|
* endpoint (same contract as dinox-electron / dinox-web / dinox-app). The backend
|
|
@@ -23,6 +24,30 @@ const UPLOAD_REQUIRED_INSERT_DEFAULTS_BY_TABLE = new Map([
|
|
|
23
24
|
// PowerSync omits NULL values from PUT payloads, while the backend requires these.
|
|
24
25
|
['c_note_template', { content: '', extra_data: '{}' }],
|
|
25
26
|
]);
|
|
27
|
+
/**
|
|
28
|
+
* CLI 1.x kept star state in `c_note.is_starred`; 2.x, the other clients, and the v6
|
|
29
|
+
* backend use `starred_at`. 1.x operations still queued in the same local database
|
|
30
|
+
* survive the upgrade, and the backend rejects the unknown column, which blocks every
|
|
31
|
+
* later upload. Translate them the same way 2.x writes a star change.
|
|
32
|
+
*/
|
|
33
|
+
function translateLegacyNoteStar(table, values) {
|
|
34
|
+
if (table !== 'c_note' || !Object.prototype.hasOwnProperty.call(values, 'is_starred'))
|
|
35
|
+
return values;
|
|
36
|
+
const { is_starred: legacyStarred, ...rest } = values;
|
|
37
|
+
if (!Object.prototype.hasOwnProperty.call(rest, 'starred_at')) {
|
|
38
|
+
const starred = legacyStarred === 1 || legacyStarred === true || legacyStarred === '1';
|
|
39
|
+
rest.starred_at = starred
|
|
40
|
+
? (typeof rest.updated_at === 'string' && rest.updated_at ? rest.updated_at : nowIsoUtc())
|
|
41
|
+
: null;
|
|
42
|
+
}
|
|
43
|
+
return rest;
|
|
44
|
+
}
|
|
45
|
+
function dropLegacyColumns(table, values) {
|
|
46
|
+
if (!values || table !== 'c_note' || !('is_starred' in values))
|
|
47
|
+
return values;
|
|
48
|
+
const { is_starred: _legacyStarred, ...rest } = values;
|
|
49
|
+
return rest;
|
|
50
|
+
}
|
|
26
51
|
function isRecord(value) {
|
|
27
52
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
28
53
|
}
|
|
@@ -94,9 +119,9 @@ export function toUploadOperation(op) {
|
|
|
94
119
|
type: table,
|
|
95
120
|
id: String(op.id),
|
|
96
121
|
...(op.transactionId !== undefined ? { tx_id: op.transactionId } : {}),
|
|
97
|
-
...(data ? { data: omitColumns(table, data) } : {}),
|
|
122
|
+
...(data ? { data: omitColumns(table, translateLegacyNoteStar(table, data)) } : {}),
|
|
98
123
|
// DELETE needs no base: deletes win (PowerSync default), nothing to compare.
|
|
99
|
-
...(name === 'PATCH' ? compactPreviousValues(op.previousValues) : {}),
|
|
124
|
+
...(name === 'PATCH' ? compactPreviousValues(dropLegacyColumns(table, op.previousValues)) : {}),
|
|
100
125
|
...(op.metadata !== undefined ? { metadata: op.metadata } : {}),
|
|
101
126
|
};
|
|
102
127
|
}
|