import { Schema as S } from "@effect/schema"; import { AttachmentId, BooleanFromNumber, PieceId, RequestId, SessionId, Sha256, UserId } from "common"; import { Brand as B, pipe } from "effect"; export const SessionData = S.Struct({ userId: UserId, }); export type SessionData = typeof SessionData.Type; export const SystemInformation = S.Struct({ createdBy: S.Union(UserId, S.Null), createdAt: S.DateTimeUtc, modifiedBy: S.Union(UserId, S.Null), modifiedAt: S.DateTimeUtc, }); export type SystemInformation = typeof SystemInformation.Type; // --- TABLES ------------------------------------------------------------------ export const AccessLog = S.Struct({ timestamp: S.DateTimeUtc, requestId: RequestId, method: S.NonEmptyString, pathname: S.NonEmptyString, query: S.parseJson(S.Record({ key: S.String, value: S.String, })), ip: S.Union(S.NonEmptyString, S.Null), }); export const Attachment = pipe( S.Struct({ attachmentId: AttachmentId, pieceId: PieceId, sha256: Sha256, filename: S.NonEmptyString, mediaType: S.NonEmptyString, }), S.extend(SystemInformation), ); export const Piece = pipe( S.Struct({ pieceId: PieceId, name: S.NonEmptyString, composer: S.Union(S.NonEmptyString, S.Null), lyricist: S.Union(S.NonEmptyString, S.Null), arranger: S.Union(S.NonEmptyString, S.Null), }), S.extend(SystemInformation), ); export const Session = pipe( S.Struct({ sessionId: SessionId, expiresAt: S.DateTimeUtc, }), S.extend(SessionData), ); export const User = S.Struct({ userId: UserId, username: S.NonEmptyString, password: S.NonEmptyString, admin: BooleanFromNumber, }); export type AccessLog = typeof AccessLog.Type; export type Attachment = typeof Attachment.Type; export type Piece = typeof Piece.Type; export type Session = typeof Session.Type; export type User = typeof User.Type;