@rdlabo/ionic-angular-kit 21.5.5 → 21.5.6

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 CHANGED
@@ -291,7 +291,7 @@ export const appConfig: ApplicationConfig = {
291
291
  // const session = await auth.exchangeCredential();
292
292
  // return {
293
293
  // activate: (lease) => offline.prepareRemoteSession(
294
- // session.userId, session.groupIds, session.subject, lease,
294
+ // session.userId, session.scopeIds, session.subject, lease,
295
295
  // ),
296
296
  // resume: () => offline.resumeRemoteSession(),
297
297
  // };
@@ -310,7 +310,7 @@ export const appConfig: ApplicationConfig = {
310
310
  // return session
311
311
  // ? {
312
312
  // activate: (lease) => offline.prepareRemoteSession(
313
- // session.userId, session.groupIds, session.subject, lease,
313
+ // session.userId, session.scopeIds, session.subject, lease,
314
314
  // ),
315
315
  // resume: () => offline.resumeRemoteSession(),
316
316
  // }
@@ -389,7 +389,7 @@ A fleet-canonical HTTP interceptor with:
389
389
 
390
390
  ### Scoped local replica and outbox (`@rdlabo/ionic-angular-kit/offline`)
391
391
 
392
- The optional `offline` entry point provides a user/group-scoped local replica, durable outbox, authenticated
392
+ The optional `offline` entry point provides a user/partition-scoped local replica, durable outbox, authenticated
393
393
  session boundary, cursor-based delta pull, aggregate-ordered replay, optimistic updates, retry classification, and a
394
394
  read-only request-policy interceptor. Applications provide URL/DTO read policies, a replica puller, and a command
395
395
  executor through `provideOffline(...)`.
@@ -401,8 +401,8 @@ For cold-start offline route access, `OfflineCoordinatorService.activateOfflineS
401
401
  that is bound to a non-null authentication-provider subject. Supplying a currently known subject also rejects a
402
402
  different user on a shared device. It activates local replica writes and durable outbox enqueue, but remote pull and
403
403
  command replay remain disabled until online authentication completes the ordered
404
- `prepareRemoteSession(...)` → publish `remote` → `resumeRemoteSession()` transition. `activateSession(...)` remains
405
- available as a backward-compatible one-step API for callers that do not enforce shared access mode.
404
+ `prepareRemoteSession(...)` → publish `remote` → `resumeRemoteSession()` transition. `activateSession(...)` is
405
+ available as a one-step API for callers that do not enforce shared access mode.
406
406
  Explicit sign-out must first call `KitAuthAccessService.clear()` and then await `clearActiveSession()`. The first
407
407
  step immediately invalidates every in-flight auth lease; the second serializes cleanup after local persistence
408
408
  already in progress and removes the manifest and user replica.
@@ -430,8 +430,9 @@ provideKitAuth(() => ({
430
430
  ordering via `KitRemoteAccessRecovery`. Product code keeps consent, error UI, and credential mapping inside
431
431
  `exchange(context)` (`phase: 'authorize' | 'recover'`, optional route state, lease). Return `null`/`false` to decline
432
432
  without throwing; thrown errors are never swallowed and remain available to the guard's unavailable/denial
433
- classification. The returned identity requires a positive `userId`, non-negative numeric scope ids (including the
434
- current user-scope compatibility value `0`), and a non-empty `authSubject`. The bridge compares that subject before
433
+ classification. The returned identity requires a positive `userId`, non-empty string `scopeIds`, and a non-empty
434
+ `authSubject`. A scope may be a numeric database id serialized as a string or a domain UUID such as an organization
435
+ or venue id. The bridge compares the subject before
435
436
  session activation, immediately before the coordinator commits through a composite lease, and around remote resume.
436
437
  Optional `isIdentityCurrent` can add provider object-identity checks. `onRemoteResumed` receives the identity, phase,
437
438
  route state, and post-grant lease for safe redirects or other product side effects. Default recovery availability
@@ -537,7 +538,7 @@ omitted id would otherwise make the executor interpret the row as a not-yet-crea
537
538
 
538
539
  ```ts
539
540
  await offlineSync.enqueue({
540
- groupId,
541
+ scopeId,
541
542
  aggregateType: 'items',
542
543
  aggregateLocalId: localId,
543
544
  serverId: existingApiItem.id,
@@ -549,13 +550,14 @@ await offlineSync.enqueue({
549
550
 
550
551
  The mapping is immutable and unique inside its effective replica scope. Reassigning one `localId` to another
551
552
  `serverId`, or assigning the same `serverId` to another `localId`, rejects before persistence. Web storage enforces
552
- the same rule transactionally as SQLite's unique indexes: group-scoped entities are unique per user/group/source,
553
- and user-scoped entities are unique per user/source across groups. If an adopted row has no confirmed baseline and
553
+ the same rule transactionally as SQLite's unique indexes: partition-scoped entities are unique per
554
+ user/partition/source, and user-scoped entities are unique per user/source across partitions. If an adopted row has
555
+ no confirmed baseline and
554
556
  its final command is discarded, the local row is removed; the next pull may materialize the authoritative server
555
557
  row again. A row with a confirmed baseline rolls back to that baseline instead.
556
558
 
557
559
  Each synchronization cycle pulls authoritative server deltas before replaying the outbox. Every page carries the
558
- replica schema version/hash and advances a durable user/group cursor in the same transaction as its rows. A schema
560
+ replica schema version/hash and advances a durable user/partition cursor in the same transaction as its rows. A schema
559
561
  mismatch, malformed row, or non-advancing cursor rejects synchronization without advancing that cursor. If a remote
560
562
  revision changed while a local command is pending, the optimistic row remains visible and both row and command move
561
563
  to `conflict`; the new server value is retained as the confirmed baseline.
@@ -584,7 +586,7 @@ import type { Items as ItemSelect } from '@product/hono/db/schema';
584
586
  const itemEntityV2 = defineReplicaEntity<ItemSelect>()({
585
587
  table: 'items',
586
588
  sourceKey: 'items',
587
- scope: 'group',
589
+ scope: 'partition',
588
590
  fields: {
589
591
  id: serverId(),
590
592
  title: text(),
@@ -13,7 +13,7 @@ const IDENTIFIER_PATTERN = /^[a-z][a-z0-9_]*$/;
13
13
  const RESERVED_COLUMN_NAMES = new Set([
14
14
  'local_id',
15
15
  '_offline_user_id',
16
- '_offline_group_id',
16
+ '_offline_scope_id',
17
17
  'server_id',
18
18
  '_offline_confirmed_json',
19
19
  '_offline_server_revision_json',
@@ -154,8 +154,8 @@ function materializeFieldDescriptor(sourceKey, fieldDef) {
154
154
  }
155
155
  function buildCreateTableSql(tableName, scope, fields, hasServerId) {
156
156
  const columnLines = ['local_id TEXT NOT NULL', '_offline_user_id INTEGER NOT NULL'];
157
- if (scope === 'group') {
158
- columnLines.push('_offline_group_id INTEGER NOT NULL');
157
+ if (scope === 'partition') {
158
+ columnLines.push('_offline_scope_id TEXT NOT NULL');
159
159
  }
160
160
  if (hasServerId) {
161
161
  columnLines.push('server_id INTEGER');
@@ -170,7 +170,7 @@ function buildCreateTableSql(tableName, scope, fields, hasServerId) {
170
170
  }
171
171
  const statements = [`CREATE TABLE IF NOT EXISTS ${tableName} (\n ${columnLines.join(',\n ')},\n PRIMARY KEY (local_id)\n)`];
172
172
  if (hasServerId) {
173
- const indexColumns = scope === 'group' ? '_offline_user_id, _offline_group_id, server_id' : '_offline_user_id, server_id';
173
+ const indexColumns = scope === 'partition' ? '_offline_user_id, _offline_scope_id, server_id' : '_offline_user_id, server_id';
174
174
  statements.push(`CREATE UNIQUE INDEX IF NOT EXISTS uq_${tableName}_server_id ON ${tableName} (${indexColumns}) WHERE server_id IS NOT NULL`);
175
175
  }
176
176
  return statements;
@@ -625,7 +625,7 @@ class IonicOfflineRepository {
625
625
  .filter((row) => {
626
626
  if (row.sourceKey !== sourceKey || row.userId !== scope.userId)
627
627
  return false;
628
- return schema.scope === 'group' ? row.groupId === scope.groupId : true;
628
+ return schema.scope === 'partition' ? row.scopeId === scope.scopeId : true;
629
629
  })
630
630
  .map((row) => this.#rowForScope(row, schema, scope))
631
631
  .sort((left, right) => left.localId.localeCompare(right.localId));
@@ -640,7 +640,7 @@ class IonicOfflineRepository {
640
640
  const row = Object.values(rows).find((row) => {
641
641
  if (row.sourceKey !== sourceKey || row.userId !== scope.userId || row.serverId !== serverId)
642
642
  return false;
643
- return schema.scope === 'group' ? row.groupId === scope.groupId : true;
643
+ return schema.scope === 'partition' ? row.scopeId === scope.scopeId : true;
644
644
  });
645
645
  return row ? this.#rowForScope(row, schema, scope) : null;
646
646
  }
@@ -656,7 +656,7 @@ class IonicOfflineRepository {
656
656
  await this.#writes;
657
657
  const commands = await this.#readRecord(OUTBOX_KEY);
658
658
  return Object.values(commands)
659
- .filter((command) => command.userId === scope.userId && command.groupId === scope.groupId)
659
+ .filter((command) => command.userId === scope.userId && command.scopeId === scope.scopeId)
660
660
  .sort(compareOfflineCommands$1);
661
661
  }
662
662
  async getCommandsForUser(userId) {
@@ -701,9 +701,9 @@ class IonicOfflineRepository {
701
701
  await this.#storage.set(METADATA_KEY, { ...metadata, lastUserId: null });
702
702
  }
703
703
  }
704
- async clearGroup(scope) {
704
+ async clearScope(scope) {
705
705
  await this.initialize();
706
- const belongsToGroup = (value) => value.userId === scope.userId && value.groupId === scope.groupId;
706
+ const belongsToGroup = (value) => value.userId === scope.userId && value.scopeId === scope.scopeId;
707
707
  await Promise.all([
708
708
  this.#filterRecord(ROWS_KEY, (value) => {
709
709
  const schema = this.#resolveReplicaEntitySchema(value.sourceKey);
@@ -888,7 +888,7 @@ class IonicOfflineRepository {
888
888
  const schema = this.#resolveReplicaEntitySchema(row.sourceKey);
889
889
  rows[this.#rowKey(row, row.sourceKey, row.localId)] = {
890
890
  ...row,
891
- groupId: schema.scope === 'user' ? 0 : row.groupId,
891
+ scopeId: schema.scope === 'user' ? '' : row.scopeId,
892
892
  values: projectOfflineReplicaValues(schema, row.values),
893
893
  confirmedValues: row.confirmedValues === null ? null : projectOfflineReplicaValues(schema, row.confirmedValues),
894
894
  };
@@ -935,14 +935,14 @@ class IonicOfflineRepository {
935
935
  }
936
936
  #rowKey(scope, sourceKey, localId) {
937
937
  const schema = this.#resolveReplicaEntitySchema(sourceKey);
938
- const partition = schema.scope === 'user' ? 'user' : String(scope.groupId);
938
+ const partition = schema.scope === 'user' ? 'user' : String(scope.scopeId);
939
939
  return `${scope.userId}:${partition}:${sourceKey}:${localId}`;
940
940
  }
941
941
  #rowForScope(row, schema, scope) {
942
- return schema.scope === 'user' ? { ...row, groupId: scope.groupId } : row;
942
+ return schema.scope === 'user' ? { ...row, scopeId: scope.scopeId } : row;
943
943
  }
944
944
  #cursorKey(scope) {
945
- return `${scope.userId}:${scope.groupId}`;
945
+ return `${scope.userId}:${scope.scopeId}`;
946
946
  }
947
947
  #schemaHasServerId(schema) {
948
948
  return schema.fields.some((field) => field.policy === 'serverId');
@@ -965,7 +965,7 @@ class IonicOfflineRepository {
965
965
  if (row.userId !== incoming.userId || row.sourceKey !== incoming.sourceKey || row.serverId !== incoming.serverId) {
966
966
  return false;
967
967
  }
968
- return schema.scope === 'user' || row.groupId === incoming.groupId;
968
+ return schema.scope === 'user' || row.scopeId === incoming.scopeId;
969
969
  });
970
970
  if (collision) {
971
971
  throw new Error(`Offline replica serverId ${String(incoming.serverId)} is already mapped to localId ${collision[1].localId}.`);
@@ -1006,7 +1006,7 @@ class OfflineReplicaPullService {
1006
1006
  this.#assertPullPage(page);
1007
1007
  this.#assertHandshake(page.schemaVersion, page.schemaHash, schemaHash);
1008
1008
  if (page.hasMore && page.nextCursor === cursor) {
1009
- throw new Error(`Offline replica pull cursor did not advance for scope ${scope.userId}:${scope.groupId}.`);
1009
+ throw new Error(`Offline replica pull cursor did not advance for scope ${scope.userId}:${scope.scopeId}.`);
1010
1010
  }
1011
1011
  const scopeCommands = await this.#repository.getCommands(scope);
1012
1012
  const userCommands = this.#repository.getCommandsForUser ? await this.#repository.getCommandsForUser(scope.userId) : scopeCommands;
@@ -1035,7 +1035,7 @@ class OfflineReplicaPullService {
1035
1035
  }
1036
1036
  const acknowledgedCommand = acknowledged[0];
1037
1037
  const acknowledgedScope = acknowledgedCommand
1038
- ? { userId: acknowledgedCommand.userId, groupId: acknowledgedCommand.groupId }
1038
+ ? { userId: acknowledgedCommand.userId, scopeId: acknowledgedCommand.scopeId }
1039
1039
  : scope;
1040
1040
  const acknowledgedRow = acknowledgedCommand
1041
1041
  ? await this.#repository.getReplicaRow(acknowledgedScope, change.sourceKey, acknowledgedCommand.aggregateLocalId)
@@ -1347,7 +1347,7 @@ class OfflineSessionService {
1347
1347
  await this.initialize();
1348
1348
  if (lease && !lease.isCurrent())
1349
1349
  return false;
1350
- const normalizedScopeIds = [...new Set(scopeIds)].sort((a, b) => a - b);
1350
+ const normalizedScopeIds = [...new Set(scopeIds)].sort((a, b) => a.localeCompare(b));
1351
1351
  const previousUserId = await this.#repository.getLastUserId();
1352
1352
  if (lease && !lease.isCurrent())
1353
1353
  return false;
@@ -1364,8 +1364,8 @@ class OfflineSessionService {
1364
1364
  }
1365
1365
  const active = new Set(normalizedScopeIds);
1366
1366
  await Promise.all((previous?.scopeIds ?? [])
1367
- .filter((groupId) => !active.has(groupId))
1368
- .map((groupId) => this.#repository.clearGroup({ userId, groupId })));
1367
+ .filter((scopeId) => !active.has(scopeId))
1368
+ .map((scopeId) => this.#repository.clearScope({ userId, scopeId })));
1369
1369
  if (lease && !lease.isCurrent())
1370
1370
  return false;
1371
1371
  const manifest = {
@@ -1454,7 +1454,7 @@ class OfflineSessionService {
1454
1454
  #sessionFromManifest() {
1455
1455
  const manifest = this.#activeManifest();
1456
1456
  return manifest
1457
- ? { userId: manifest.userId, scopes: manifest.scopeIds.map((groupId) => ({ userId: manifest.userId, groupId })) }
1457
+ ? { userId: manifest.userId, scopes: manifest.scopeIds.map((scopeId) => ({ userId: manifest.userId, scopeId })) }
1458
1458
  : null;
1459
1459
  }
1460
1460
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineSessionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
@@ -1609,7 +1609,7 @@ class OfflineSyncService {
1609
1609
  throw new Error('Cannot enqueue an offline command without an authenticated user');
1610
1610
  const userId = session.userId;
1611
1611
  this.#setActiveUser(userId);
1612
- const scope = { userId, groupId: request.groupId };
1612
+ const scope = { userId, scopeId: request.scopeId };
1613
1613
  this.noteScope(scope);
1614
1614
  const aggregateLocalId = request.aggregateLocalId;
1615
1615
  const normalized = await this.#normalizeEnqueueRequest(scope, request);
@@ -1858,7 +1858,7 @@ class OfflineSyncService {
1858
1858
  });
1859
1859
  }
1860
1860
  async #rowForCommand(command) {
1861
- const scope = { userId: command.userId, groupId: command.groupId };
1861
+ const scope = { userId: command.userId, scopeId: command.scopeId };
1862
1862
  const entityType = this.#entityType(command);
1863
1863
  return this.#repository.getReplicaRow(scope, entityType, command.aggregateLocalId);
1864
1864
  }
@@ -1905,7 +1905,7 @@ class OfflineSyncService {
1905
1905
  const schema = this.#options.replicaSchema.entities.find((entity) => entity.sourceKey === sourceKey);
1906
1906
  if (!schema)
1907
1907
  throw new Error(`Unknown offline replica source key "${sourceKey}".`);
1908
- const partition = schema.scope === 'user' ? 'user' : `group:${command.groupId}`;
1908
+ const partition = schema.scope === 'user' ? 'user' : `partition:${command.scopeId}`;
1909
1909
  return `${command.userId}:${partition}:${sourceKey}:${command.aggregateLocalId}`;
1910
1910
  }
1911
1911
  #failedCommand(command, error) {
@@ -2080,7 +2080,7 @@ class OfflineSyncService {
2080
2080
  return serialized;
2081
2081
  }
2082
2082
  #scopeKey(scope) {
2083
- return `${scope.userId}:${scope.groupId}`;
2083
+ return `${scope.userId}:${scope.scopeId}`;
2084
2084
  }
2085
2085
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineSyncService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
2086
2086
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: OfflineSyncService, providedIn: 'root' }); }
@@ -2289,8 +2289,8 @@ function assertOfflineRemoteIdentity(identity) {
2289
2289
  if (!Number.isSafeInteger(identity.userId) || identity.userId <= 0) {
2290
2290
  throw new Error('Offline remote identity userId must be a positive safe integer.');
2291
2291
  }
2292
- if (!Array.isArray(identity.scopeIds) || identity.scopeIds.some((scopeId) => !Number.isSafeInteger(scopeId) || scopeId < 0)) {
2293
- throw new Error('Offline remote identity scopeIds must contain only non-negative safe integers.');
2292
+ if (!Array.isArray(identity.scopeIds) || identity.scopeIds.some((scopeId) => typeof scopeId !== 'string' || scopeId.length === 0)) {
2293
+ throw new Error('Offline remote identity scopeIds must contain only non-empty strings.');
2294
2294
  }
2295
2295
  if (typeof identity.authSubject !== 'string' || identity.authSubject.length === 0) {
2296
2296
  throw new Error('Offline remote identity authSubject must be a non-empty string.');
@@ -2386,7 +2386,7 @@ const SCHEMA = [
2386
2386
  `CREATE TABLE IF NOT EXISTS offline_sync_commands (
2387
2387
  command_id TEXT PRIMARY KEY,
2388
2388
  user_id INTEGER NOT NULL,
2389
- group_id INTEGER NOT NULL,
2389
+ scope_id TEXT NOT NULL,
2390
2390
  aggregate_type TEXT NOT NULL,
2391
2391
  aggregate_local_id TEXT NOT NULL,
2392
2392
  operation TEXT NOT NULL,
@@ -2401,7 +2401,7 @@ const SCHEMA = [
2401
2401
  last_error_code TEXT
2402
2402
  )`,
2403
2403
  `CREATE INDEX IF NOT EXISTS offline_sync_commands_scope_created
2404
- ON offline_sync_commands (user_id, group_id, created_at)`,
2404
+ ON offline_sync_commands (user_id, scope_id, created_at)`,
2405
2405
  `CREATE TABLE IF NOT EXISTS offline_replica_schema_metadata (
2406
2406
  id INTEGER PRIMARY KEY CHECK (id = 1),
2407
2407
  version INTEGER NOT NULL,
@@ -2409,9 +2409,9 @@ const SCHEMA = [
2409
2409
  )`,
2410
2410
  `CREATE TABLE IF NOT EXISTS offline_replica_cursors (
2411
2411
  user_id INTEGER NOT NULL,
2412
- group_id INTEGER NOT NULL,
2412
+ scope_id TEXT NOT NULL,
2413
2413
  cursor TEXT NOT NULL,
2414
- PRIMARY KEY (user_id, group_id)
2414
+ PRIMARY KEY (user_id, scope_id)
2415
2415
  )`,
2416
2416
  ];
2417
2417
  /** Native iOS/Android repository backed by encrypted `@capacitor-community/sqlite`. */
@@ -2446,9 +2446,9 @@ class SqliteOfflineRepository {
2446
2446
  const schema = this.#resolveReplicaEntitySchema(sourceKey);
2447
2447
  const predicates = ['local_id = ?', '_offline_user_id = ?'];
2448
2448
  const values = [localId, scope.userId];
2449
- if (schema.scope === 'group') {
2450
- predicates.push('_offline_group_id = ?');
2451
- values.push(scope.groupId);
2449
+ if (schema.scope === 'partition') {
2450
+ predicates.push('_offline_scope_id = ?');
2451
+ values.push(scope.scopeId);
2452
2452
  }
2453
2453
  const rows = await this.#query(`SELECT * FROM ${schema.tableName} WHERE ${predicates.join(' AND ')}`, values);
2454
2454
  const row = rows[0];
@@ -2460,9 +2460,9 @@ class SqliteOfflineRepository {
2460
2460
  const schema = this.#resolveReplicaEntitySchema(sourceKey);
2461
2461
  const predicates = ['_offline_user_id = ?'];
2462
2462
  const values = [scope.userId];
2463
- if (schema.scope === 'group') {
2464
- predicates.push('_offline_group_id = ?');
2465
- values.push(scope.groupId);
2463
+ if (schema.scope === 'partition') {
2464
+ predicates.push('_offline_scope_id = ?');
2465
+ values.push(scope.scopeId);
2466
2466
  }
2467
2467
  const rows = await this.#query(`SELECT * FROM ${schema.tableName} WHERE ${predicates.join(' AND ')} ORDER BY local_id ASC`, values);
2468
2468
  return rows.map((row) => this.#replicaRowFromSqliteRow(schema, scope, sourceKey, this.#string(row['local_id']), row));
@@ -2473,9 +2473,9 @@ class SqliteOfflineRepository {
2473
2473
  return null;
2474
2474
  const predicates = ['server_id = ?', '_offline_user_id = ?'];
2475
2475
  const values = [serverId, scope.userId];
2476
- if (schema.scope === 'group') {
2477
- predicates.push('_offline_group_id = ?');
2478
- values.push(scope.groupId);
2476
+ if (schema.scope === 'partition') {
2477
+ predicates.push('_offline_scope_id = ?');
2478
+ values.push(scope.scopeId);
2479
2479
  }
2480
2480
  const rows = await this.#query(`SELECT * FROM ${schema.tableName} WHERE ${predicates.join(' AND ')}`, values);
2481
2481
  const row = rows[0];
@@ -2484,9 +2484,9 @@ class SqliteOfflineRepository {
2484
2484
  return this.#replicaRowFromSqliteRow(schema, scope, sourceKey, this.#string(row['local_id']), row);
2485
2485
  }
2486
2486
  async getReplicaCursor(scope) {
2487
- const rows = await this.#query('SELECT cursor FROM offline_replica_cursors WHERE user_id = ? AND group_id = ?', [
2487
+ const rows = await this.#query('SELECT cursor FROM offline_replica_cursors WHERE user_id = ? AND scope_id = ?', [
2488
2488
  scope.userId,
2489
- scope.groupId,
2489
+ scope.scopeId,
2490
2490
  ]);
2491
2491
  const row = rows[0];
2492
2492
  if (!row)
@@ -2494,7 +2494,7 @@ class SqliteOfflineRepository {
2494
2494
  return { ...scope, cursor: this.#string(row['cursor']) };
2495
2495
  }
2496
2496
  async getCommands(scope) {
2497
- const rows = await this.#query('SELECT * FROM offline_sync_commands WHERE user_id = ? AND group_id = ? ORDER BY created_at ASC, command_id ASC', [scope.userId, scope.groupId]);
2497
+ const rows = await this.#query('SELECT * FROM offline_sync_commands WHERE user_id = ? AND scope_id = ? ORDER BY created_at ASC, command_id ASC', [scope.userId, scope.scopeId]);
2498
2498
  return rows.map((row) => this.#command(row));
2499
2499
  }
2500
2500
  async getCommandsForUser(userId) {
@@ -2523,15 +2523,15 @@ class SqliteOfflineRepository {
2523
2523
  await this.#execute(database, 'UPDATE offline_metadata SET last_user_id = NULL WHERE id = 1 AND last_user_id = ?', [userId]);
2524
2524
  });
2525
2525
  }
2526
- async clearGroup(scope) {
2526
+ async clearScope(scope) {
2527
2527
  await this.#transaction(async (database) => {
2528
- const values = [scope.userId, scope.groupId];
2529
- await this.#execute(database, 'DELETE FROM offline_sync_commands WHERE user_id = ? AND group_id = ?', values);
2530
- await this.#execute(database, 'DELETE FROM offline_replica_cursors WHERE user_id = ? AND group_id = ?', values);
2528
+ const values = [scope.userId, scope.scopeId];
2529
+ await this.#execute(database, 'DELETE FROM offline_sync_commands WHERE user_id = ? AND scope_id = ?', values);
2530
+ await this.#execute(database, 'DELETE FROM offline_replica_cursors WHERE user_id = ? AND scope_id = ?', values);
2531
2531
  for (const entity of this.#options.replicaSchema.entities) {
2532
- if (entity.scope !== 'group')
2532
+ if (entity.scope !== 'partition')
2533
2533
  continue;
2534
- await this.#execute(database, `DELETE FROM ${entity.tableName} WHERE _offline_user_id = ? AND _offline_group_id = ?`, values);
2534
+ await this.#execute(database, `DELETE FROM ${entity.tableName} WHERE _offline_user_id = ? AND _offline_scope_id = ?`, values);
2535
2535
  }
2536
2536
  });
2537
2537
  }
@@ -2671,7 +2671,7 @@ class SqliteOfflineRepository {
2671
2671
  return {
2672
2672
  commandId: this.#string(row['command_id']),
2673
2673
  userId: this.#number(row['user_id']),
2674
- groupId: this.#number(row['group_id']),
2674
+ scopeId: this.#string(row['scope_id']),
2675
2675
  aggregateType: this.#string(row['aggregate_type']),
2676
2676
  aggregateLocalId: this.#string(row['aggregate_local_id']),
2677
2677
  operation: this.#string(row['operation']),
@@ -2688,18 +2688,18 @@ class SqliteOfflineRepository {
2688
2688
  }
2689
2689
  #putCommand(databaseId, command) {
2690
2690
  return this.#execute(databaseId, `INSERT INTO offline_sync_commands
2691
- (command_id, user_id, group_id, aggregate_type, aggregate_local_id, operation, payload_json, optimistic_value_json,
2691
+ (command_id, user_id, scope_id, aggregate_type, aggregate_local_id, operation, payload_json, optimistic_value_json,
2692
2692
  payload_hash, base_revision_json, state, attempts, retry_at, created_at, last_error_code)
2693
2693
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2694
2694
  ON CONFLICT(command_id) DO UPDATE SET
2695
- user_id = excluded.user_id, group_id = excluded.group_id, aggregate_type = excluded.aggregate_type,
2695
+ user_id = excluded.user_id, scope_id = excluded.scope_id, aggregate_type = excluded.aggregate_type,
2696
2696
  aggregate_local_id = excluded.aggregate_local_id, operation = excluded.operation, payload_json = excluded.payload_json,
2697
2697
  optimistic_value_json = excluded.optimistic_value_json, payload_hash = excluded.payload_hash,
2698
2698
  base_revision_json = excluded.base_revision_json, state = excluded.state, attempts = excluded.attempts,
2699
2699
  retry_at = excluded.retry_at, created_at = excluded.created_at, last_error_code = excluded.last_error_code`, [
2700
2700
  command.commandId,
2701
2701
  command.userId,
2702
- command.groupId,
2702
+ command.scopeId,
2703
2703
  command.aggregateType,
2704
2704
  command.aggregateLocalId,
2705
2705
  command.operation,
@@ -2723,7 +2723,7 @@ class SqliteOfflineRepository {
2723
2723
  const values = [
2724
2724
  row.localId,
2725
2725
  row.userId,
2726
- ...(schema.scope === 'group' ? [row.groupId] : []),
2726
+ ...(schema.scope === 'partition' ? [row.scopeId] : []),
2727
2727
  ...(this.#schemaHasServerId(schema) ? [row.serverId] : []),
2728
2728
  confirmedValues === null ? null : JSON.stringify(confirmedValues),
2729
2729
  row.serverRevision == null ? null : JSON.stringify(row.serverRevision),
@@ -2737,22 +2737,22 @@ class SqliteOfflineRepository {
2737
2737
  const schema = this.#resolveReplicaEntitySchema(key.sourceKey);
2738
2738
  const predicates = ['local_id = ?', '_offline_user_id = ?'];
2739
2739
  const values = [key.localId, key.userId];
2740
- if (schema.scope === 'group') {
2741
- predicates.push('_offline_group_id = ?');
2742
- values.push(key.groupId);
2740
+ if (schema.scope === 'partition') {
2741
+ predicates.push('_offline_scope_id = ?');
2742
+ values.push(key.scopeId);
2743
2743
  }
2744
2744
  return this.#execute(databaseId, `DELETE FROM ${schema.tableName} WHERE ${predicates.join(' AND ')}`, values);
2745
2745
  }
2746
2746
  #putReplicaCursor(databaseId, cursor) {
2747
- return this.#execute(databaseId, `INSERT INTO offline_replica_cursors (user_id, group_id, cursor) VALUES (?, ?, ?)
2748
- ON CONFLICT(user_id, group_id) DO UPDATE SET cursor = excluded.cursor`, [cursor.userId, cursor.groupId, cursor.cursor]);
2747
+ return this.#execute(databaseId, `INSERT INTO offline_replica_cursors (user_id, scope_id, cursor) VALUES (?, ?, ?)
2748
+ ON CONFLICT(user_id, scope_id) DO UPDATE SET cursor = excluded.cursor`, [cursor.userId, cursor.scopeId, cursor.cursor]);
2749
2749
  }
2750
2750
  #buildReplicaUpsertStatement(schema) {
2751
2751
  const insertColumns = ['local_id', '_offline_user_id'];
2752
2752
  const updateSets = ['_offline_user_id = excluded._offline_user_id'];
2753
- if (schema.scope === 'group') {
2754
- insertColumns.push('_offline_group_id');
2755
- updateSets.push('_offline_group_id = excluded._offline_group_id');
2753
+ if (schema.scope === 'partition') {
2754
+ insertColumns.push('_offline_scope_id');
2755
+ updateSets.push('_offline_scope_id = excluded._offline_scope_id');
2756
2756
  }
2757
2757
  if (this.#schemaHasServerId(schema)) {
2758
2758
  insertColumns.push('server_id');