Files
outline/server/routes/api/imports/schema.ts
T
Tom Moor ecafd5f32a chore: Update JSON importer to use zip streaming (#12380)
* chore: Update JSON importer to use zip streaming, new importer flow

* chore: Drop teamId from import urlId collision check and remove unused internal-id scaffolding

urlId is globally unique on Document/Collection so the team scope was wrong.
Also removes leftover internal-id generation in JSONAPIImportTask that was
never used in task input/output.

* Restore classes used upstream
2026-05-25 17:03:02 -04:00

81 lines
2.1 KiB
TypeScript

import { z } from "zod";
import { NotionImportInputItemSchema } from "@shared/schema";
import {
CollectionPermission,
ImportableIntegrationService,
IntegrationService,
} from "@shared/types";
import { BaseSchema } from "../schema";
const BaseIdSchema = z.object({
/** Id of the import */
id: z.uuid(),
});
const ImportsSortParamsSchema = z.object({
/** Specifies the attributes by which imports will be sorted in the list. */
sort: z
.string()
.refine((val) => ["createdAt", "updatedAt", "service"].includes(val), {
error: "Invalid sort parameter",
})
.prefault("createdAt"),
/** Specifies the sort order with respect to sort field. */
direction: z
.string()
.optional()
.transform((val) => (val !== "ASC" ? "DESC" : val)),
});
const BaseBodySchema = z.object({
integrationId: z.uuid(),
});
export const ImportsCreateSchema = BaseSchema.extend({
body: z.discriminatedUnion("service", [
BaseBodySchema.extend({
service: z.literal(IntegrationService.Notion),
input: z.array(NotionImportInputItemSchema),
}),
z.object({
service: z.literal(IntegrationService.Markdown),
attachmentId: z.uuid(),
permission: z.enum(CollectionPermission).optional(),
}),
z.object({
service: z.literal(IntegrationService.JSON),
attachmentId: z.uuid(),
permission: z.enum(CollectionPermission).optional(),
}),
]),
});
export type ImportsCreateReq = z.infer<typeof ImportsCreateSchema>;
export const ImportsListSchema = BaseSchema.extend({
body: ImportsSortParamsSchema.extend({
service: z.enum(ImportableIntegrationService).optional(),
}),
});
export type ImportsListReq = z.infer<typeof ImportsListSchema>;
export const ImportsInfoSchema = BaseSchema.extend({
body: BaseIdSchema,
});
export type ImportsInfoReq = z.infer<typeof ImportsInfoSchema>;
export const ImportsDeleteSchema = BaseSchema.extend({
body: BaseIdSchema,
});
export type ImportsDeleteReq = z.infer<typeof ImportsDeleteSchema>;
export const ImportsCancelSchema = BaseSchema.extend({
body: BaseIdSchema,
});
export type ImportsCancelReq = z.infer<typeof ImportsCancelSchema>;