Init backend, frontend and DB schema
This commit is contained in:
86
packages/common/src/index.ts
Normal file
86
packages/common/src/index.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { Schema as S } from "@effect/schema";
|
||||
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 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 UserId = typeof UserId.Type;
|
||||
|
||||
export type Sha256 = B.Branded<Uint8Array, "Sha256">;
|
||||
export const Sha256 = pipe(
|
||||
S.Uint8ArrayFromSelf,
|
||||
S.fromBrand(B.refined<Sha256>(
|
||||
(array) => array.byteLength === 32,
|
||||
() => B.error(`Expected Uint8Array to be 32 bytes long`),
|
||||
)),
|
||||
);
|
||||
|
||||
export class BooleanFromNumber extends S.transform(
|
||||
S.Number,
|
||||
S.Boolean,
|
||||
{
|
||||
strict: true,
|
||||
decode: (a) => a !== 0,
|
||||
encode: (i) => i ? 1 : 0,
|
||||
},
|
||||
).annotations({ identifier: "BooleanFromNumber" }) { }
|
||||
|
||||
export const SystemInformation = S.Struct({
|
||||
createdBy: UserId,
|
||||
createdAt: S.DateTimeUtc,
|
||||
modifiedBy: UserId,
|
||||
modifiedAt: S.DateTimeUtc,
|
||||
});
|
||||
|
||||
export type SystemInformation = typeof SystemInformation.Type;
|
||||
|
||||
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 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 User = typeof User.Type;
|
||||
Reference in New Issue
Block a user