mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 21:23:45 +01:00
[editor-core] refine zod schemas for rawTextOperation and rawFileMetadata (#36253)
* [editor-core] gracefully handle no-op TextOperation * [editor-core] add support for legacy url imports * [editor-core] reorder rawFileMetadata entries GitOrigin-RevId: f5c3158def00183d4a60a5b934abd921716e2339
This commit is contained in:
@@ -38,7 +38,7 @@ const rawRetainOp = z.union([
|
||||
const rawScanOp = z.union([rawInsertOp, rawRemoveOp, rawRetainOp])
|
||||
|
||||
const rawTextOperation = z.strictObject({
|
||||
textOperation: z.array(rawScanOp).min(1),
|
||||
textOperation: z.array(rawScanOp),
|
||||
contentHash: z.string().optional(),
|
||||
})
|
||||
|
||||
@@ -151,19 +151,27 @@ const rawBlobHash = z.string().regex(/^[0-9a-f]{40}$/, {
|
||||
message: 'invalid blob hash',
|
||||
})
|
||||
|
||||
// file metadata is the linked-file metadata written by web, the main-file
|
||||
// marker written by the v1 history import, regular file with importedAt,
|
||||
// or an empty object (metadata cleared)
|
||||
const rawFileMetadata = z.union([
|
||||
// doc/clear metadata
|
||||
z.strictObject({}),
|
||||
// regular file v2
|
||||
z.strictObject({
|
||||
importedAt: z.iso.datetime(),
|
||||
}),
|
||||
// linked-file v2
|
||||
rawLinkedFileData,
|
||||
|
||||
// main-file v1
|
||||
z.strictObject({
|
||||
main: z.boolean(),
|
||||
importedAt: z.iso.datetime().optional(),
|
||||
}),
|
||||
// url import v1
|
||||
z.strictObject({
|
||||
importedAt: z.iso.datetime(),
|
||||
agent: z.literal('url'),
|
||||
agentDataId: z.number(),
|
||||
importedAt: z.iso.datetime().optional(),
|
||||
}),
|
||||
z.strictObject({}),
|
||||
])
|
||||
|
||||
const rawHashFileData = z.strictObject({
|
||||
|
||||
@@ -3,9 +3,19 @@ const {
|
||||
rawLinkedFileData,
|
||||
rawFileMetadata,
|
||||
rawRetainOp,
|
||||
rawTextOperation,
|
||||
} = require('../../lib/schemas')
|
||||
|
||||
describe('schemas', function () {
|
||||
describe('rawTextOperation', function () {
|
||||
it('accepts a no-op TextOperation', function () {
|
||||
const result = rawTextOperation.safeParse({
|
||||
textOperation: [],
|
||||
})
|
||||
expect(result.success).to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('rawRetainOp', function () {
|
||||
it('accepts a bare retain length', function () {
|
||||
const result = rawRetainOp.safeParse(5)
|
||||
@@ -203,6 +213,14 @@ describe('schemas', function () {
|
||||
expect(result.success).to.equal(true)
|
||||
})
|
||||
|
||||
it('accepts a legacy v1 url import', function () {
|
||||
const result = rawFileMetadata.safeParse({
|
||||
agent: 'url',
|
||||
agentDataId: 42,
|
||||
})
|
||||
expect(result.success).to.equal(true)
|
||||
})
|
||||
|
||||
it('accepts a legacy v1 main flag with an importedAt timestamp', function () {
|
||||
const result = rawFileMetadata.safeParse({
|
||||
main: true,
|
||||
|
||||
Reference in New Issue
Block a user