(query, originalAuthData, newAuthData)
| 13 | // recovery-code array) is sufficient — its removal invalidates the WHERE clause |
| 14 | // for concurrent writers. |
| 15 | export function applyAuthDataOptimisticLock(query, originalAuthData, newAuthData) { |
| 16 | if (!originalAuthData) { |
| 17 | return; |
| 18 | } |
| 19 | for (const provider of Object.keys(newAuthData)) { |
| 20 | const original = originalAuthData[provider]; |
| 21 | if (!original || typeof original !== 'object') { |
| 22 | continue; |
| 23 | } |
| 24 | for (const [field, value] of Object.entries(original)) { |
| 25 | if (!isLockableAuthDataValue(value)) { |
| 26 | continue; |
| 27 | } |
| 28 | if (JSON.stringify(value) !== JSON.stringify(newAuthData[provider]?.[field])) { |
| 29 | query[`authData.${provider}.${field}`] = value; |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | function isLockableAuthDataValue(value) { |
| 36 | if (value === null || value === undefined) { |
no test coverage detected