@spooky-sync/core 0.0.1-canary.83 → 0.0.1-canary.84

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/index.js CHANGED
@@ -2455,8 +2455,8 @@ var SyncEngine = class {
2455
2455
  }, "Checking removed records");
2456
2456
  let existingRemoteIds;
2457
2457
  try {
2458
- const [existing] = await this.remote.query("SELECT id FROM $ids", { ids: removed });
2459
- existingRemoteIds = new Set((existing ?? []).map((row) => encodeRecordId(row.id)));
2458
+ const [existing] = await this.remote.query("SELECT VALUE id FROM $ids", { ids: removed });
2459
+ existingRemoteIds = new Set((existing ?? []).filter((id) => id != null).map((id) => encodeRecordId(id)));
2460
2460
  } catch (err) {
2461
2461
  this.logger.warn({
2462
2462
  err,
@@ -3343,8 +3343,8 @@ function parseBackendInfo(raw) {
3343
3343
 
3344
3344
  //#endregion
3345
3345
  //#region src/modules/devtools/index.ts
3346
- const CORE_VERSION = "0.0.1-canary.83";
3347
- const WASM_VERSION = "0.0.1-canary.83";
3346
+ const CORE_VERSION = "0.0.1-canary.84";
3347
+ const WASM_VERSION = "0.0.1-canary.84";
3348
3348
  const SURREAL_VERSION = "3.0.3";
3349
3349
  var DevToolsService = class {
3350
3350
  eventsHistory = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spooky-sync/core",
3
- "version": "0.0.1-canary.83",
3
+ "version": "0.0.1-canary.84",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -59,8 +59,8 @@
59
59
  }
60
60
  },
61
61
  "dependencies": {
62
- "@spooky-sync/query-builder": "0.0.1-canary.83",
63
- "@spooky-sync/ssp-wasm": "0.0.1-canary.83",
62
+ "@spooky-sync/query-builder": "0.0.1-canary.84",
63
+ "@spooky-sync/ssp-wasm": "0.0.1-canary.84",
64
64
  "@surrealdb/wasm": "^3.0.3",
65
65
  "fast-json-patch": "^3.1.1",
66
66
  "loro-crdt": "^1.5.6",
@@ -160,26 +160,30 @@ export class SyncEngine {
160
160
  );
161
161
 
162
162
  // Confirm which of the "removed" ids still exist remotely by selecting the
163
- // records directly: `SELECT id FROM $ids` (the records to fetch ARE the
164
- // FROM target).
163
+ // records directly from the id array (the records ARE the FROM target).
165
164
  //
166
- // We must NOT use `WHERE id IN $ids` here: on SurrealDB v3.1.x, record-id
167
- // matching with `IN` is broken `SELECT id FROM <table> WHERE id IN
168
- // [<recordid>]` returns NO rows even for an existing record (plain-field
169
- // `IN` works; record-id `IN` does not). That made this check report EVERY
170
- // removed id as gone and DELETE live local records (e.g. a freshly-created
171
- // collection vanished mid-session). `SELECT id FROM $ids` matches correctly.
172
- // (The old comment claimed `FROM $ids` returned Internal/0 on v3.0; it works
173
- // on v3.1, and even if it ever errored the catch below skips deletion —
174
- // strictly safer than the silent empty-result the `IN` form produced.)
165
+ // The exact query form matters on SurrealDB v3.x:
166
+ // - `WHERE id IN $ids` is broken: record-id `IN` matches nothing, so every
167
+ // removed id looked gone and live local records got deleted (a fresh
168
+ // collection vanished mid-session). Do NOT use `IN`.
169
+ // - `SELECT id FROM $ids` a FIELD projection over a record-id ARRAY —
170
+ // errors "Specify a database to use" on the deployed engine. The catch
171
+ // below then swallowed it and skipped EVERY deletion, so nothing could be
172
+ // deleted anywhere (games, comments, …). Do NOT project a field over the
173
+ // array. (`SELECT * FROM $ids` works but pulls full records — wasteful.)
174
+ // - `SELECT VALUE id FROM $ids` works: a flat array of ids with a NONE entry
175
+ // for each id that no longer exists. We filter the NONE entries out; the
176
+ // survivors are the ids still present upstream.
175
177
  let existingRemoteIds: Set<string>;
176
178
  try {
177
- const [existing] = await this.remote.query<[{ id: RecordId }[]]>(
178
- 'SELECT id FROM $ids',
179
+ const [existing] = await this.remote.query<[(RecordId | null | undefined)[]]>(
180
+ 'SELECT VALUE id FROM $ids',
179
181
  { ids: removed }
180
182
  );
181
183
  existingRemoteIds = new Set(
182
- (existing ?? []).map((row) => encodeRecordId(row.id))
184
+ (existing ?? [])
185
+ .filter((id): id is RecordId => id != null)
186
+ .map((id) => encodeRecordId(id))
183
187
  );
184
188
  } catch (err) {
185
189
  // Verification failed. Skip deletion entirely — the next sync