Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

refactor(server): cleanup no longer used zod schemas (#1048)

Corentin Thomasset988383ea5744
diff --git a/apps/papra-server/src/modules/documents/documents.config.ts b/apps/papra-server/src/modules/documents/documents.config.ts
index 398c9325..6bda5b4d 100644
--- a/apps/papra-server/src/modules/documents/documents.config.ts
+++ b/apps/papra-server/src/modules/documents/documents.config.ts
@@ -2,7 +2,7 @@ import type { ConfigDefinition } from 'figue';
import * as v from 'valibot';
import { booleanishSchema } from '../config/config.schemas';
import { coercedNumberSchema } from '../shared/schemas/number.schemas';
-import { ocrLanguagesSchema, stringCoercedOcrLanguagesSchema } from './documents.schemas.legacy';
+import { ocrLanguagesSchema, stringCoercedOcrLanguagesSchema } from './documents.schemas';
export const documentsConfig = {
deletedDocumentsRetentionDays: {
diff --git a/apps/papra-server/src/modules/documents/documents.schemas.legacy.ts b/apps/papra-server/src/modules/documents/documents.schemas.legacy.ts
deleted file mode 100644
index 43bf19c9..00000000
--- a/apps/papra-server/src/modules/documents/documents.schemas.legacy.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import * as v from 'valibot';
-import { z } from 'zod';
-import { DOCUMENT_ID_REGEX, OCR_LANGUAGES } from './documents.constants';
-
-export const documentIdSchema = z.string().regex(DOCUMENT_ID_REGEX);
-
-export const ocrLanguagesSchema = v.array(v.picklist(OCR_LANGUAGES));
-export const stringCoercedOcrLanguagesSchema = v.pipe(
- v.string(),
- v.transform(value => value.split(',').map(lang => lang.trim())),
- ocrLanguagesSchema,
-);
diff --git a/apps/papra-server/src/modules/documents/documents.schemas.ts b/apps/papra-server/src/modules/documents/documents.schemas.ts
index cb30c69f..011dcb33 100644
--- a/apps/papra-server/src/modules/documents/documents.schemas.ts
+++ b/apps/papra-server/src/modules/documents/documents.schemas.ts
@@ -1,6 +1,6 @@
import * as v from 'valibot';
import { createRegexSchema } from '../shared/schemas/string.schemas';
-import { DOCUMENT_ID_REGEX } from './documents.constants';
+import { DOCUMENT_ID_REGEX, OCR_LANGUAGES } from './documents.constants';
export const documentIdSchema = createRegexSchema(DOCUMENT_ID_REGEX);
@@ -15,3 +15,10 @@ export const updateDocumentBodySchema = v.pipe(
'At least one of \'name\', \'content\', or \'documentDate\' must be provided',
),
);
+
+export const ocrLanguagesSchema = v.array(v.picklist(OCR_LANGUAGES));
+export const stringCoercedOcrLanguagesSchema = v.pipe(
+ v.string(),
+ v.transform(value => value.split(',').map(lang => lang.trim())),
+ ocrLanguagesSchema,
+);
diff --git a/apps/papra-server/src/modules/intake-emails/intake-emails.schemas.legacy.ts b/apps/papra-server/src/modules/intake-emails/intake-emails.schemas.legacy.ts
deleted file mode 100644
index b7acd4da..00000000
--- a/apps/papra-server/src/modules/intake-emails/intake-emails.schemas.legacy.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import { z } from 'zod';
-import { INTAKE_EMAIL_ID_REGEX, RFC_5322_EMAIL_ADDRESS_REGEX } from './intake-emails.constants';
-
-export const permissiveEmailAddressSchema = z.string().regex(RFC_5322_EMAIL_ADDRESS_REGEX);
-
-export const emailInfoSchema = z.object({
- address: permissiveEmailAddressSchema,
- name: z.string().optional(),
-});
-
-export const intakeEmailsIngestionMetaSchema = z.object({
- from: emailInfoSchema,
- to: z.array(emailInfoSchema),
- originalTo: z.array(emailInfoSchema).optional().default([]),
- // cc: z.array(emailInfoSchema).optional(),
- // subject: z.string(),
- // text: z.string().optional(),
- // html: z.string().optional(),
-});
-
-export function parseJson(content: string, ctx: z.RefinementCtx) {
- try {
- return JSON.parse(content);
- } catch (_error) {
- ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid json' });
- return z.never;
- }
-}
-
-export const intakeEmailIdSchema = z.string().regex(INTAKE_EMAIL_ID_REGEX);
-
-export const allowedOriginsSchema = z.array(permissiveEmailAddressSchema.toLowerCase()).optional();
diff --git a/apps/papra-server/src/modules/organizations/organization.schemas.legacy.ts b/apps/papra-server/src/modules/organizations/organization.schemas.legacy.ts
deleted file mode 100644
index e061ddae..00000000
--- a/apps/papra-server/src/modules/organizations/organization.schemas.legacy.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import { z } from 'zod';
-import { ORGANIZATION_ID_REGEX, ORGANIZATION_INVITATION_ID_REGEX, ORGANIZATION_MEMBER_ID_REGEX } from './organizations.constants';
-
-export const organizationIdSchema = z.string().regex(ORGANIZATION_ID_REGEX);
-export const memberIdSchema = z.string().regex(ORGANIZATION_MEMBER_ID_REGEX);
-export const invitationIdSchema = z.string().regex(ORGANIZATION_INVITATION_ID_REGEX);
diff --git a/apps/papra-server/src/modules/organizations/organization.schemas.test.ts b/apps/papra-server/src/modules/organizations/organization.schemas.test.ts
deleted file mode 100644
index a594a57d..00000000
--- a/apps/papra-server/src/modules/organizations/organization.schemas.test.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { describe, expect, test } from 'vitest';
-import { organizationIdSchema } from './organization.schemas.legacy';
-
-describe('organization schemas', () => {
- describe('organizationIdSchema', () => {
- test('an organization id should be a 24 character random string prefixed with "org"', () => {
- expect(organizationIdSchema.safeParse('org_aaaaaaaaaaaaaaaaaaaaaaaa').success).to.eql(true);
- expect(organizationIdSchema.safeParse('org_0aaaaaaaaaaaaaaaaaaaaaa1').success).to.eql(true);
- expect(organizationIdSchema.safeParse('org_000000000000000000000000').success).to.eql(true);
-
- expect(organizationIdSchema.safeParse('org_aaaa').success).to.eql(false);
- expect(organizationIdSchema.safeParse('org').success).to.eql(false);
- expect(organizationIdSchema.safeParse('foo').success).to.eql(false);
- });
- });
-});
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.schemas.legacy.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.schemas.legacy.ts
deleted file mode 100644
index 14684308..00000000
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.schemas.legacy.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import { z } from 'zod';
-import { CONDITION_MATCH_MODES, TAGGING_RULE_ID_REGEX } from './tagging-rules.constants';
-
-export const taggingRuleIdSchema = z.string().regex(TAGGING_RULE_ID_REGEX);
-
-export const conditionMatchModeSchema = z.enum([CONDITION_MATCH_MODES.ALL, CONDITION_MATCH_MODES.ANY]);
diff --git a/apps/papra-server/src/modules/tags/tags.schemas.legacy.ts b/apps/papra-server/src/modules/tags/tags.schemas.legacy.ts
deleted file mode 100644
index be2f4935..00000000
--- a/apps/papra-server/src/modules/tags/tags.schemas.legacy.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { z } from 'zod';
-import { TagColorRegex, tagIdRegex } from './tags.constants';
-
-export const tagIdSchema = z.string().regex(tagIdRegex);
-export const tagColorSchema = z.string().toUpperCase().regex(TagColorRegex, 'Invalid Color format, must be a hex color code like #000000');
diff --git a/apps/papra-server/src/modules/users/users.schemas.legacy.ts b/apps/papra-server/src/modules/users/users.schemas.legacy.ts
deleted file mode 100644
index eac5bb7e..00000000
--- a/apps/papra-server/src/modules/users/users.schemas.legacy.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { z } from 'zod';
-import { USER_ID_REGEX } from './users.constants';
-
-export const userIdSchema = z.string().regex(USER_ID_REGEX);
diff --git a/apps/papra-server/src/modules/webhooks/webhooks.schemas.legacy.ts b/apps/papra-server/src/modules/webhooks/webhooks.schemas.legacy.ts
deleted file mode 100644
index 6f727a66..00000000
--- a/apps/papra-server/src/modules/webhooks/webhooks.schemas.legacy.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { EVENT_NAMES } from '@papra/webhooks';
-import { z } from 'zod';
-import { WEBHOOK_ID_REGEX } from './webhooks.constants';
-
-export const webhookIdSchema = z.string().regex(WEBHOOK_ID_REGEX);
-export const webhookEventSchema = z.enum(EVENT_NAMES);
-export const webhookEventListSchema = z.array(webhookEventSchema).min(1);
-export const webhookSecretSchema = z.string().min(1).max(256);
-export const webhookNameSchema = z.string().min(1).max(128);
-export const webhookUrlSchema = z.string().url().max(2048);