@syncular/server 0.30.5 → 0.30.7
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/README.md +10 -0
- package/dist/context.d.ts +3 -1
- package/dist/handler.js +34 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/pg-executor-pglite.js +7 -1
- package/dist/pull.js +16 -7
- package/dist/push.d.ts +2 -2
- package/dist/push.js +19 -11
- package/dist/readiness.d.ts +1 -1
- package/dist/readiness.js +2 -0
- package/dist/realtime.d.ts +3 -0
- package/dist/realtime.js +23 -4
- package/dist/schema-window.d.ts +7 -0
- package/dist/schema-window.js +46 -0
- package/dist/segment-download.js +3 -1
- package/dist/sqlite-image.js +4 -2
- package/dist/sqlite-segment-store.js +4 -2
- package/dist/sqlite-storage.js +22 -16
- package/dist/storage-errors.d.ts +3 -0
- package/dist/storage-errors.js +15 -0
- package/dist/storage.d.ts +2 -0
- package/package.json +2 -2
- package/src/context.ts +3 -1
- package/src/handler.ts +43 -8
- package/src/index.ts +2 -0
- package/src/pg-executor-pglite.ts +6 -1
- package/src/pull.ts +37 -7
- package/src/push.ts +22 -6
- package/src/readiness.ts +6 -1
- package/src/realtime.ts +48 -4
- package/src/schema-window.ts +72 -0
- package/src/segment-download.ts +5 -1
- package/src/sqlite-image.ts +4 -2
- package/src/sqlite-segment-store.ts +4 -2
- package/src/sqlite-storage.ts +21 -15
- package/src/storage-errors.ts +19 -0
- package/src/storage.ts +2 -0
package/src/sqlite-storage.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { retainRollbackFailure, rollbackAfterError } from './storage-errors';
|
|
1
2
|
import { validateCommitPruneQuery } from './prune';
|
|
2
3
|
import { StorageQueryError } from './storage-errors';
|
|
3
4
|
import type { CommitPruneQuery, CommitPruneResult } from './storage';
|
|
@@ -469,9 +470,8 @@ class SqliteTransaction implements StorageTransaction {
|
|
|
469
470
|
// connection.
|
|
470
471
|
try {
|
|
471
472
|
this.#storage.db.exec('ROLLBACK');
|
|
472
|
-
} catch {
|
|
473
|
-
|
|
474
|
-
// mask it.
|
|
473
|
+
} catch (rollbackError) {
|
|
474
|
+
retainRollbackFailure(error, rollbackError);
|
|
475
475
|
}
|
|
476
476
|
throw error;
|
|
477
477
|
} finally {
|
|
@@ -725,8 +725,9 @@ END`);
|
|
|
725
725
|
}
|
|
726
726
|
this.db.exec('COMMIT');
|
|
727
727
|
} catch (error) {
|
|
728
|
-
|
|
729
|
-
|
|
728
|
+
rollbackAfterError(() => {
|
|
729
|
+
this.db.exec('ROLLBACK');
|
|
730
|
+
}, error);
|
|
730
731
|
}
|
|
731
732
|
});
|
|
732
733
|
}
|
|
@@ -799,8 +800,9 @@ END`);
|
|
|
799
800
|
.run(partition);
|
|
800
801
|
this.db.exec('COMMIT');
|
|
801
802
|
} catch (error) {
|
|
802
|
-
|
|
803
|
-
|
|
803
|
+
rollbackAfterError(() => {
|
|
804
|
+
this.db.exec('ROLLBACK');
|
|
805
|
+
}, error);
|
|
804
806
|
}
|
|
805
807
|
return {
|
|
806
808
|
partition,
|
|
@@ -1002,8 +1004,9 @@ END`);
|
|
|
1002
1004
|
open = false;
|
|
1003
1005
|
return result;
|
|
1004
1006
|
} catch (error) {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
+
rollbackAfterError(() => {
|
|
1008
|
+
if (open) this.db.exec('ROLLBACK');
|
|
1009
|
+
}, error);
|
|
1007
1010
|
} finally {
|
|
1008
1011
|
release();
|
|
1009
1012
|
}
|
|
@@ -1085,8 +1088,9 @@ END`);
|
|
|
1085
1088
|
removedCommits: Number(removed.changes),
|
|
1086
1089
|
};
|
|
1087
1090
|
} catch (error) {
|
|
1088
|
-
|
|
1089
|
-
|
|
1091
|
+
rollbackAfterError(() => {
|
|
1092
|
+
this.db.exec('ROLLBACK');
|
|
1093
|
+
}, error);
|
|
1090
1094
|
}
|
|
1091
1095
|
});
|
|
1092
1096
|
}
|
|
@@ -1202,8 +1206,9 @@ END`);
|
|
|
1202
1206
|
this.db.exec('COMMIT');
|
|
1203
1207
|
return toStoredCheckpoint(row);
|
|
1204
1208
|
} catch (error) {
|
|
1205
|
-
|
|
1206
|
-
|
|
1209
|
+
rollbackAfterError(() => {
|
|
1210
|
+
this.db.exec('ROLLBACK');
|
|
1211
|
+
}, error);
|
|
1207
1212
|
}
|
|
1208
1213
|
});
|
|
1209
1214
|
}
|
|
@@ -1260,8 +1265,9 @@ END`);
|
|
|
1260
1265
|
this.db.exec('COMMIT');
|
|
1261
1266
|
return Number(updated.changes) === 1 ? 'activated' : 'stale';
|
|
1262
1267
|
} catch (error) {
|
|
1263
|
-
|
|
1264
|
-
|
|
1268
|
+
rollbackAfterError(() => {
|
|
1269
|
+
this.db.exec('ROLLBACK');
|
|
1270
|
+
}, error);
|
|
1265
1271
|
}
|
|
1266
1272
|
});
|
|
1267
1273
|
}
|
package/src/storage-errors.ts
CHANGED
|
@@ -150,3 +150,22 @@ export function isD1ConstraintError(error: unknown): boolean {
|
|
|
150
150
|
)
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
|
+
|
|
154
|
+
/** Preserve the operation failure when transaction cleanup also fails. */
|
|
155
|
+
export function retainRollbackFailure(
|
|
156
|
+
error: unknown,
|
|
157
|
+
rollbackError: unknown,
|
|
158
|
+
): void {
|
|
159
|
+
if (error instanceof Error && !('rollbackError' in error)) {
|
|
160
|
+
Object.defineProperty(error, 'rollbackError', { value: rollbackError });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function rollbackAfterError(run: () => void, error: unknown): never {
|
|
165
|
+
try {
|
|
166
|
+
run();
|
|
167
|
+
} catch (rollbackError) {
|
|
168
|
+
retainRollbackFailure(error, rollbackError);
|
|
169
|
+
}
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
package/src/storage.ts
CHANGED
|
@@ -288,6 +288,8 @@ export interface StoredPushResult {
|
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
export interface ClientSubscription {
|
|
291
|
+
/** Codec accepted by the last pull; absent on records written before schema windows. */
|
|
292
|
+
readonly schemaVersion?: number;
|
|
291
293
|
readonly id: string;
|
|
292
294
|
readonly table: string;
|
|
293
295
|
/** Requested scopes of the client's most recent pull (§8.1). */
|