making strides in the device and link domain setup

This commit is contained in:
user
2026-03-27 23:58:06 +02:00
parent 8c45efc92e
commit c7c303a934
17 changed files with 1202 additions and 198 deletions

View File

@@ -0,0 +1,47 @@
import * as v from "valibot";
import { deviceSchema } from "@domains/device/data";
export enum LinkStatus {
ACTIVE = "active",
INACTIVE = "inactive",
EXPIRED = "expired",
REVOKED = "revoked",
}
export const linkStatusSchema = v.picklist(["active", "inactive", "expired", "revoked"]);
export type LinkStatusValue = v.InferOutput<typeof linkStatusSchema>;
export const linkSchema = v.object({
id: v.number(),
token: v.string(),
status: linkStatusSchema,
linkedDeviceId: v.nullable(v.number()),
expiresAt: v.nullable(v.date()),
lastAccessedAt: v.nullable(v.date()),
createdAt: v.date(),
updatedAt: v.date(),
});
export type Link = v.InferOutput<typeof linkSchema>;
export const linkWithDeviceSchema = v.object({
...linkSchema.entries,
device: v.nullable(deviceSchema),
});
export type LinkWithDevice = v.InferOutput<typeof linkWithDeviceSchema>;
export const createLinkSchema = v.object({
token: v.pipe(v.string(), v.minLength(1)),
linkedDeviceId: v.optional(v.nullable(v.number())),
expiresAt: v.optional(v.nullable(v.date())),
});
export type CreateLink = v.InferOutput<typeof createLinkSchema>;
export const updateLinkSchema = v.partial(
v.object({
status: linkStatusSchema,
linkedDeviceId: v.nullable(v.number()),
expiresAt: v.nullable(v.date()),
lastAccessedAt: v.nullable(v.date()),
}),
);
export type UpdateLink = v.InferOutput<typeof updateLinkSchema>;