fix: additional backwards compat

This commit is contained in:
David Nguyen
2025-10-14 15:19:09 +11:00
parent bddaa5ec66
commit 0eef4cd7e6
32 changed files with 288 additions and 92 deletions

View File

@ -1,5 +1,9 @@
import type { Envelope } from '@prisma/client';
import { EnvelopeType } from '@prisma/client';
import { customAlphabet } from 'nanoid';
import { mapSecondaryIdToDocumentId, mapSecondaryIdToTemplateId } from '../utils/envelope';
export const alphaid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 21);
export { nanoid } from 'nanoid';
@ -29,3 +33,16 @@ type DatabaseIdPrefix =
| 'team_setting';
export const generateDatabaseId = (prefix: DatabaseIdPrefix) => prefixedId(prefix, 16);
export const extractLegacyIds = (envelope: Pick<Envelope, 'type' | 'secondaryId'>) => {
return {
documentId:
envelope.type === EnvelopeType.DOCUMENT
? mapSecondaryIdToDocumentId(envelope.secondaryId)
: null,
templateId:
envelope.type === EnvelopeType.TEMPLATE
? mapSecondaryIdToTemplateId(envelope.secondaryId)
: null,
};
};