-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement method to create a record link token
- Loading branch information
1 parent
e55ac17
commit c455787
Showing
6 changed files
with
32 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** @format */ | ||
|
||
import { RecordLink } from '../../types'; | ||
import { Collection } from './Collection'; | ||
import { ObjectId } from './ObjectId'; | ||
|
||
/** | ||
* @description | ||
* Method to create a **Record Link** token from a Collection and an Id. | ||
* | ||
* @param { string | Collection } collection - the namespace of a Collection or a Collection instance | ||
* @param { ObjectId } recordId | ||
* @returns | ||
*/ | ||
|
||
export const Link = (collection: string | Collection<Record<PropertyKey, unknown>>, recordId: ObjectId): RecordLink => { | ||
let namespace = collection; | ||
|
||
if (collection instanceof Collection && 'namespace' in collection) { | ||
namespace = collection.namespace; | ||
} | ||
|
||
return `${namespace}:${recordId.valueOf()}`; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** @format */ | ||
|
||
export type RecordLink = `${string}:${string}`; |
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