diff --git a/src/index.ts b/src/index.ts index 11516c72..a15703a9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -269,12 +269,7 @@ export * from './websockets/index.js'; /** * Type utils */ -export type { - UnionOfConst, - ResultOf, - AnyOf, - AnyOfExcept, -} from './typeUtils.js'; +export type { UnionOfConst, ResultOf } from './typeUtils.js'; /** * Custom types diff --git a/src/shortLink/shortLink.ts b/src/shortLink/shortLink.ts index 7e2a10c6..d701c97b 100644 --- a/src/shortLink/shortLink.ts +++ b/src/shortLink/shortLink.ts @@ -1,7 +1,8 @@ -import { AnyOfExcept, UnionOfConst } from '@/typeUtils.js'; +import { UnionOfConst } from '@/typeUtils.js'; -// This const is used to define the allowed Platforms. -// It is used in schema or database enums. +/** + * Represents the allowed platforms for which short links can be generated. + */ export const ShortLinkPlatform = { Builder: 'builder', Player: 'player', @@ -9,21 +10,17 @@ export const ShortLinkPlatform = { } as const; export type ShortLink = { + itemId: string; alias: string; platform: UnionOfConst; - item: { id: string }; - createdAt: string; }; -export type ShortLinkItemId = { - itemId: string; -}; +export type UpdateShortLink = Pick; -export type ShortLinkPayload = Omit & - ShortLinkItemId; -export type ShortLinkPostPayload = ShortLinkPayload; -export type ShortLinkPatchPayload = AnyOfExcept; -export type ShortLinkPutPayload = Omit; export type ShortLinkAvailable = { available: boolean; }; + +export type ShortLinksOfItem = { + [K in (typeof ShortLinkPlatform)[keyof typeof ShortLinkPlatform]]?: ShortLink['alias']; +}; diff --git a/src/typeUtils.ts b/src/typeUtils.ts index e406a638..d15d9b0c 100644 --- a/src/typeUtils.ts +++ b/src/typeUtils.ts @@ -21,25 +21,6 @@ export type ResultOf = { errors: Error[]; }; -// TODO: add usage informations -/** - * This allow to define a type with at least one attribute of T. - */ -export type AnyOf = { - [K in keyof T]: Pick; -}[keyof T]; - -/** - * This allow to define a type with at least one attribute of T that is not a key in E. - * - * The following type add usage informations about: - * `type ShortLinkPatchPayload = AnyOfExcept;` - * - The `itemId` is not allowed. - * - All other attributes of ShortLinkPostPayload are allowed and optional. - * - At least of attribute is required. - */ -export type AnyOfExcept = AnyOf>; - /** * The type is T or null. *