MCPcopy
hub / github.com/dexie/Dexie.js / makePrivate

Method makePrivate

samples/dexie-cloud-todo-app/src/db/TodoList.ts:89–119  ·  view source on GitHub ↗

Moves the list to the private realm and removes all members * * The operation is sync-consistent and will work correctly * whether the todo-list is shared or not while the operation * is performed offline. * * The operation may succeed offline but fail later during sync * if s

()

Source from the content-addressed store, hash-verified

87 * restore the local data to mirror the server state.
88 */
89 async makePrivate() {
90 const tiedRealmId = getTiedRealmId(this.id);
91 const db = this.db;
92 await db.transaction(
93 'rw',
94 [db.todoLists, db.todoItems, db.members, db.realms],
95 async () => {
96 // Move todoItems out of the realm in a sync-consistent operation:
97 await db.todoItems
98 .where({
99 realmId: tiedRealmId,
100 todoListId: this.id,
101 })
102 .modify({
103 realmId: db.cloud.currentUserId,
104 owner: db.cloud.currentUserId,
105 });
106
107 // Move the todoList back into your private realm:
108 await db.todoLists.update(this.id, {
109 realmId: this.db.cloud.currentUserId,
110 owner: this.db.cloud.currentUserId,
111 });
112
113 // Remove all access (Collection.delete() is a sync-consistent operation)
114 await db.members.where('realmId').equals(tiedRealmId).delete();
115 // Delete tied realm
116 await db.realms.delete(tiedRealmId);
117 }
118 );
119 }
120
121 /** Share the todo list with a new person.
122 *

Callers 1

handleUnshareFunction · 0.80

Calls 7

getTiedRealmIdFunction · 0.85
transactionMethod · 0.65
modifyMethod · 0.65
whereMethod · 0.65
updateMethod · 0.65
deleteMethod · 0.65
equalsMethod · 0.65

Tested by

no test coverage detected