first commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import { z } from 'zod';
|
||||
import { isoDate } from './common';
|
||||
|
||||
/** Ein Freigabe-Eintrag: wer (Subjekt) darf was (Level). */
|
||||
export const aclSubjectType = z.enum(['authority', 'group', 'person']);
|
||||
export type AclSubjectType = z.infer<typeof aclSubjectType>;
|
||||
|
||||
export const aclLevel = z.enum(['read', 'write']);
|
||||
export type AclLevel = z.infer<typeof aclLevel>;
|
||||
|
||||
export const aclEntrySchema = z.object({
|
||||
type: aclSubjectType,
|
||||
id: z.string(), // authority-key | group-id | citizenid
|
||||
label: z.string(), // Anzeigename (Snapshot)
|
||||
level: aclLevel,
|
||||
});
|
||||
export type AclEntry = z.infer<typeof aclEntrySchema>;
|
||||
|
||||
/** Freigabe-Zustand eines Ordners/Dokuments. */
|
||||
export const accessSchema = z.object({
|
||||
public: z.boolean().default(false), // öffentlich lesbar (jeder mit documents.view)
|
||||
acl: z.array(aclEntrySchema).default([]),
|
||||
});
|
||||
export type Access = z.infer<typeof accessSchema>;
|
||||
|
||||
export const docFolderSchema = z.object({
|
||||
id: z.number().int(),
|
||||
name: z.string(),
|
||||
public: z.boolean(),
|
||||
acl: z.array(aclEntrySchema),
|
||||
docCount: z.number().int().default(0),
|
||||
});
|
||||
export type DocFolder = z.infer<typeof docFolderSchema>;
|
||||
|
||||
/** Kurzform für Listen. */
|
||||
export const documentSummarySchema = z.object({
|
||||
id: z.number().int(),
|
||||
reference: z.string(), // DO-2026-07-06-001
|
||||
title: z.string(),
|
||||
folderId: z.number().int().nullable(),
|
||||
public: z.boolean(),
|
||||
acl: z.array(aclEntrySchema),
|
||||
pinned: z.boolean(),
|
||||
canWrite: z.boolean(), // darf der aktuelle Betrachter bearbeiten?
|
||||
authorName: z.string().nullable(),
|
||||
updatedAt: isoDate,
|
||||
});
|
||||
export type DocumentSummary = z.infer<typeof documentSummarySchema>;
|
||||
|
||||
/** Volles Dokument inkl. Rich-Text-Body (HTML aus Tiptap). */
|
||||
export const documentSchema = documentSummarySchema.extend({
|
||||
content: z.string(), // HTML
|
||||
createdAt: isoDate,
|
||||
});
|
||||
export type MdtDocument = z.infer<typeof documentSchema>;
|
||||
|
||||
export const createDocumentSchema = z.object({
|
||||
title: z.string().min(1),
|
||||
content: z.string().default(''),
|
||||
folderId: z.number().int().nullable().default(null),
|
||||
public: z.boolean().default(false),
|
||||
acl: z.array(aclEntrySchema).default([]),
|
||||
});
|
||||
export type CreateDocumentInput = z.infer<typeof createDocumentSchema>;
|
||||
|
||||
export const updateDocumentSchema = z.object({
|
||||
title: z.string().min(1).optional(),
|
||||
content: z.string().optional(),
|
||||
folderId: z.number().int().nullable().optional(),
|
||||
public: z.boolean().optional(),
|
||||
acl: z.array(aclEntrySchema).optional(),
|
||||
pinned: z.boolean().optional(),
|
||||
});
|
||||
export type UpdateDocumentInput = z.infer<typeof updateDocumentSchema>;
|
||||
|
||||
export const createFolderSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
public: z.boolean().default(false),
|
||||
acl: z.array(aclEntrySchema).default([]),
|
||||
});
|
||||
export type CreateFolderInput = z.infer<typeof createFolderSchema>;
|
||||
Reference in New Issue
Block a user