import * as Common from "common"; import * as Function from "common/Function"; import { t } from "elysia"; export interface AccessTokenPayload { readonly aud: string; readonly iss: string; readonly iat: number; readonly nbf: number; readonly exp: number; readonly name: string; readonly oid: Common.UserId; } export interface IdTokenPayload { readonly aud: string; readonly iss: string; readonly iat: number; readonly nbf: number; readonly exp: number; readonly name: string; readonly oid: Common.UserId; readonly roles: readonly string[]; } const brandedString = () => t.Transform(t.String()) .Decode(Function.unsafeCoerce) .Encode(Function.unsafeCoerce); export const Sha256_Hex = brandedString(); export const AttachmentId = brandedString(); export const PieceId = brandedString(); export const RepertoireId = brandedString(); export const RequestId = brandedString(); export const SessionId = brandedString(); export const UserId = brandedString(); const SystemInformation = Object.freeze({ createdBy: t.Nullable(UserId), createdAt: t.String(), modifiedBy: t.Nullable(UserId), modifiedAt: t.Nullable(t.String()), }); const Pagination = Object.freeze({ offset: t.Optional(t.Numeric({ minimum: 0 })), limit: t.Optional(t.Numeric({ minimum: 1, maximum: 100 })), }); export const AccessLog = t.Object({ requestId: RequestId, timestamp: t.String(), method: t.String(), pathname: t.String(), query: t.String(), ip: t.Nullable(t.String()), }); export const Attachment = t.Object({ attachmentId: AttachmentId, pieceId: PieceId, filename: t.String(), sha256: Sha256_Hex, mediaType: t.String(), ...SystemInformation, }); export const Me = t.Object({ userId: UserId, username: t.String(), roles: t.Array(t.String()), }); export const Piece = t.Object({ pieceId: PieceId, name: t.String({ minLength: 1 }), composer: t.Nullable(t.String({ minLength: 1 })), lyricist: t.Nullable(t.String({ minLength: 1 })), arranger: t.Nullable(t.String({ minLength: 1 })), attachments: t.Array(Attachment), ...SystemInformation, }); export const Piece_Post = t.Object({ name: t.String({ minLength: 1 }), composer: t.Nullable(t.String({ minLength: 1 })), lyricist: t.Nullable(t.String({ minLength: 1 })), arranger: t.Nullable(t.String({ minLength: 1 })), }); export const Piece_Query = t.Object({ name: t.Optional(t.String()), author: t.Optional(t.String()), ...Pagination, }); export const Repertoire = t.Object({ repertoireId: RepertoireId, name: t.String(), entries: t.Array(PieceId), ...SystemInformation, }); export const Repertoire_Query = t.Object({ name: t.Optional(t.String()), ...Pagination, }); export const User = t.Object({ userId: UserId, displayName: t.String(), }); export type AccessLog = typeof AccessLog.static; export type Attachment = typeof Attachment.static; export type Me = typeof Me.static; export type Piece = typeof Piece.static; export type Piece_Post = typeof Piece_Post.static; export type Piece_Query = typeof Piece_Query.static; export type Repertoire = typeof Repertoire.static; export type Repertoire_Query = typeof Repertoire_Query.static; export type User = typeof User.static;