Backend: DB schema, login API

This commit is contained in:
2024-08-03 15:29:29 +02:00
parent 777038e0b4
commit 903168a565
6 changed files with 288 additions and 33 deletions

View File

@@ -4,11 +4,13 @@ import { Brand as B, pipe } from "effect";
export const AttachmentId = pipe(S.ULID, S.brand("AttachmentId"));
export const PieceId = pipe(S.ULID, S.brand("PieceId"));
export const RequestId = pipe(S.ULID, S.brand("RequestId"));
export const SessionId = pipe(S.NonEmptyString, S.brand("SessionId"));
export const UserId = pipe(S.ULID, S.brand("UserId"));
export type AttachmentId = typeof AttachmentId.Type;
export type PieceId = typeof PieceId.Type;
export type RequestId = typeof RequestId.Type;
export type SessionId = typeof SessionId.Type;
export type UserId = typeof UserId.Type;
export type Sha256 = B.Branded<Uint8Array, "Sha256">;
@@ -31,14 +33,16 @@ export class BooleanFromNumber extends S.transform(
).annotations({ identifier: "BooleanFromNumber" }) { }
export const SystemInformation = S.Struct({
createdBy: UserId,
createdBy: S.Union(UserId, S.Null),
createdAt: S.DateTimeUtc,
modifiedBy: UserId,
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,
@@ -73,6 +77,12 @@ export const Piece = pipe(
S.extend(SystemInformation),
);
export const Session = S.Struct({
sessionId: SessionId,
userId: UserId,
expiresAt: S.DateTimeUtc,
});
export const User = S.Struct({
userId: UserId,
username: S.NonEmptyString,
@@ -83,4 +93,5 @@ export const User = S.Struct({
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;