-
-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): implement verification records map (#6289)
* refactor(core): implement verificaiton records map implement verification records map * fix(core): fix invalid verification type error fix invalid verificaiton type error * fix(core): update the verification record map update the verification record map * fix(core): update some comments update some comments * refactor(core): polish promise dependency polish promise dependency * fix(core): fix the social/sso syncing profile logic fix the social/sso syncing profile logic * refactor(core): optimize the verification records map optimize the verification records map * fix(core): fix set method of VerificationRecord map fix set method of VerificationRecord map
- Loading branch information
Showing
10 changed files
with
111 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/core/src/routes/experience/classes/verifications/verification-records-map.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @fileoverview | ||
* | ||
* Since `Map` in TS does not support key value type mapping, | ||
* we have to manually define a `setValue` method to ensure correct key will be set | ||
* This class is used to store and manage all the verification records. | ||
* | ||
* Extends the Map class and adds a `setValue` method to ensure the key value type mapping. | ||
*/ | ||
|
||
import { type VerificationType } from '@logto/schemas'; | ||
|
||
import { type VerificationRecord, type VerificationRecordMap } from './index.js'; | ||
|
||
export class VerificationRecordsMap extends Map<VerificationType, VerificationRecord> { | ||
setValue(value: VerificationRecord) { | ||
return super.set(value.type, value); | ||
} | ||
|
||
override get<K extends keyof VerificationRecordMap>( | ||
key: K | ||
): VerificationRecordMap[K] | undefined { | ||
// eslint-disable-next-line no-restricted-syntax | ||
return super.get(key) as VerificationRecordMap[K] | undefined; | ||
} | ||
|
||
override set(): never { | ||
throw new Error('Use `setValue` method to set the value'); | ||
} | ||
|
||
array(): VerificationRecord[] { | ||
return [...this.values()]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters