Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 equality checks for uuid values was buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
JitPackJoyride committed Oct 9, 2023
1 parent 3cf6016 commit 334990f
Showing 1 changed file with 73 additions and 17 deletions.
90 changes: 73 additions & 17 deletions src/edgedb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export const edgedbAdapter = (
User,
(userObj: GlobalDatabaseUserAttributes) => ({
...User["*"],
filter_single: e.op(userObj.id, "=", e.cast(e.uuid, userId)),
filter_single: e.op(
e.cast(e.uuid, userObj.id),
"=",
e.cast(e.uuid, userId)
),
})
);

Expand Down Expand Up @@ -80,7 +84,11 @@ export const edgedbAdapter = (
const keyInsertQuery = e.insert(Key, {
...newKey,
user: e.select(User, (userObj: GlobalDatabaseUserAttributes) => ({
filter_single: e.op(userObj.id, "=", e.cast(e.uuid, result.id)),
filter_single: e.op(
e.cast(e.uuid, userObj.id),
"=",
e.cast(e.uuid, result.id)
),
})),
});
await keyInsertQuery.run(tx);
Expand All @@ -100,7 +108,11 @@ export const edgedbAdapter = (
const query = e.delete(
User,
(userObj: GlobalDatabaseUserAttributes) => ({
filter_single: e.op(userObj.id, "=", e.cast(e.uuid, userId)),
filter_single: e.op(
e.cast(e.uuid, userObj.id),
"=",
e.cast(e.uuid, userId)
),
})
);
await query.run(client);
Expand All @@ -109,7 +121,11 @@ export const edgedbAdapter = (
const query = e.update(
User,
(userObj: GlobalDatabaseUserAttributes) => ({
filter_single: e.op(userObj.id, "=", e.cast(e.uuid, userId)),
filter_single: e.op(
e.cast(e.uuid, userObj.id),
"=",
e.cast(e.uuid, userId)
),
set: partialUser,
})
);
Expand All @@ -126,7 +142,11 @@ export const edgedbAdapter = (
(sessionObj: GlobalDatabaseSessionAttributes) => ({
...Session["*"],
user_id: e.cast(e.uuid, sessionObj.user.id),
filter_single: e.op(sessionObj.id, "=", e.cast(e.uuid, sessionId)),
filter_single: e.op(
e.cast(e.uuid, sessionObj.id),
"=",
e.cast(e.uuid, sessionId)
),
})
);

Expand All @@ -142,7 +162,11 @@ export const edgedbAdapter = (
(sessionObj: GlobalDatabaseSessionAttributes) => ({
...Session["*"],
user_id: e.cast(e.uuid, sessionObj.user.id),
filter: e.op(sessionObj.user.id, "=", e.cast(e.uuid, userId)),
filter: e.op(
e.cast(e.uuid, sessionObj.user.id),
"=",
e.cast(e.uuid, userId)
),
})
);

Expand All @@ -166,7 +190,11 @@ export const edgedbAdapter = (
const query = e.insert(Session, {
...sessionWithoutUserId,
user: e.select(User, (userObj: GlobalDatabaseUserAttributes) => ({
filter_single: e.op(userObj.id, "=", e.cast(e.uuid, user_id)),
filter_single: e.op(
e.cast(e.uuid, userObj.id),
"=",
e.cast(e.uuid, user_id)
),
})),
});
await query.run(client);
Expand All @@ -190,7 +218,11 @@ export const edgedbAdapter = (
const query = e.delete(
Session,
(sessionObj: GlobalDatabaseSessionAttributes) => ({
filter_single: e.op(sessionObj.id, "=", e.cast(e.uuid, sessionId)),
filter_single: e.op(
e.cast(e.uuid, sessionObj.id),
"=",
e.cast(e.uuid, sessionId)
),
})
);

Expand All @@ -204,7 +236,11 @@ export const edgedbAdapter = (
const query = e.delete(
Session,
(sessionObj: GlobalDatabaseSessionAttributes) => ({
filter: e.op(sessionObj.user.id, "=", e.cast(e.uuid, userId)),
filter: e.op(
e.cast(e.uuid, sessionObj.user.id),
"=",
e.cast(e.uuid, userId)
),
})
);

Expand All @@ -218,7 +254,11 @@ export const edgedbAdapter = (
const query = e.update(
Session,
(sessionObj: GlobalDatabaseSessionAttributes) => ({
filter_single: e.op(sessionObj.id, "=", e.cast(e.uuid, sessionId)),
filter_single: e.op(
e.cast(e.uuid, sessionObj.id),
"=",
e.cast(e.uuid, sessionId)
),
set: partialSession,
})
);
Expand All @@ -229,7 +269,7 @@ export const edgedbAdapter = (
const query = e.select(Key, (keyObj: any) => ({
...Key["*"],
user_id: e.cast(e.uuid, keyObj.user.id),
filter_single: e.op(keyObj.key_id, "=", e.cast(e.uuid, keyId)),
filter_single: e.op(keyObj.key_id, "=", keyId),
}));

return await query.run(client);
Expand All @@ -238,7 +278,11 @@ export const edgedbAdapter = (
const query = e.select(Key, (keyObj: any) => ({
...Key["*"],
user_id: e.cast(e.uuid, keyObj.user.id),
filter: e.op(keyObj.user.id, "=", e.cast(e.uuid, userId)),
filter: e.op(
e.cast(e.uuid, keyObj.user.id),
"=",
e.cast(e.uuid, userId)
),
}));

return await query.run(client);
Expand All @@ -250,7 +294,11 @@ export const edgedbAdapter = (
key_id,
...keyWithoutUserId,
user: e.select(User, (userObj: GlobalDatabaseUserAttributes) => ({
filter_single: e.op(userObj.id, "=", e.cast(e.uuid, user_id)),
filter_single: e.op(
e.cast(e.uuid, userObj.id),
"=",
e.cast(e.uuid, user_id)
),
})),
});
await query.run(client);
Expand All @@ -276,21 +324,25 @@ export const edgedbAdapter = (
},
deleteKey: async (keyId) => {
const query = e.delete(Key, (keyObj: { key_id: string }) => ({
filter_single: e.op(keyObj.key_id, "=", e.cast(e.uuid, keyId)),
filter_single: e.op(keyObj.key_id, "=", keyId),
}));

await query.run(client);
},
deleteKeysByUserId: async (userId) => {
const query = e.delete(Key, (keyObj: { user: { id: string } }) => ({
filter: e.op(keyObj.user.id, "=", e.cast(e.uuid, userId)),
filter: e.op(
e.cast(e.uuid, keyObj.user.id),
"=",
e.cast(e.uuid, userId)
),
}));

await query.run(client);
},
updateKey: async (keyId, partialKey) => {
const query = e.update(Key, (keyObj: { key_id: string }) => ({
filter_single: e.op(keyObj.key_id, "=", e.cast(e.uuid, keyId)),
filter_single: e.op(keyObj.key_id, "=", keyId),
set: partialKey,
}));

Expand All @@ -308,7 +360,11 @@ export const edgedbAdapter = (
user: {
...User["*"],
},
filter_single: e.op(sessionObj.id, "=", e.cast(e.uuid, sessionId)),
filter_single: e.op(
e.cast(e.uuid, sessionObj.id),
"=",
e.cast(e.uuid, sessionId)
),
})
);

Expand Down

0 comments on commit 334990f

Please sign in to comment.