making strides in the device and link domain setup
This commit is contained in:
47
packages/logic/domains/link/data.ts
Normal file
47
packages/logic/domains/link/data.ts
Normal 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>;
|
||||
Reference in New Issue
Block a user