From 9532b883f34cdf2b6b248bbcd2ecc578bb17a943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morel=20Se=CC=81bastien?= Date: Mon, 29 Jul 2024 09:44:00 +0200 Subject: [PATCH] feat(schema): add some types for mass operations --- components/schema/package.json | 2 +- components/schema/src/mass-operation/index.ts | 4 ++++ components/schema/src/mass-operation/item.ts | 23 ++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/components/schema/package.json b/components/schema/package.json index 44d64d82..9ff139f2 100644 --- a/components/schema/package.json +++ b/components/schema/package.json @@ -1,6 +1,6 @@ { "name": "@crystallize/schema", - "version": "1.0.0", + "version": "1.1.0", "license": "MIT", "type": "module", "exports": { diff --git a/components/schema/src/mass-operation/index.ts b/components/schema/src/mass-operation/index.ts index bf1a8f82..de8b31dc 100644 --- a/components/schema/src/mass-operation/index.ts +++ b/components/schema/src/mass-operation/index.ts @@ -1,6 +1,8 @@ import { z } from 'zod'; import { CreateItemOperationSchema, + PublishItemOperationSchema, + UnPublishItemOperationSchema, UpdateCompomentOperationSchema, UpdateItemOperationSchema, UpsertItemOperationSchema, @@ -11,6 +13,8 @@ export const OperationSchema = z.union([ UpdateItemOperationSchema, UpsertItemOperationSchema, UpdateCompomentOperationSchema, + PublishItemOperationSchema, + UnPublishItemOperationSchema, ]); export const OperationsSchema = z.object({ diff --git a/components/schema/src/mass-operation/item.ts b/components/schema/src/mass-operation/item.ts index a54498dc..b9e0f35f 100644 --- a/components/schema/src/mass-operation/item.ts +++ b/components/schema/src/mass-operation/item.ts @@ -18,6 +18,7 @@ export const UpdateItemOperationSchema = CreateItemOperationSchema.omit({ }).merge( z.object({ action: z.literal('update'), + itemId: z.string().min(1), }), ); @@ -27,14 +28,34 @@ export const UpsertItemOperationSchema = UpdateItemOperationSchema.omit({ action }), ); -export const UpdateCompomentOperationSchema = UpdateItemOperationSchema.omit({ action: true, components: true }).merge( +export const UpdateCompomentOperationSchema = UpdateItemOperationSchema.omit({ + action: true, + components: true, + topics: true, +}).merge( z.object({ action: z.literal('updateComponent'), component: ComponentInputSchema, }), ); +export const PublishItemOperationSchema = z.object({ + concern: z.literal('item'), + action: z.literal('publish'), + itemId: z.string().min(1), + language: z.string().min(1), + includeDescendants: z.boolean().optional(), +}); + +export const UnPublishItemOperationSchema = PublishItemOperationSchema.omit({ action: true }).merge( + z.object({ + action: z.literal('unpublish'), + }), +); + export type CreateItemOperation = z.infer; export type UpdateItemOperation = z.infer; export type UpsertItemOperation = z.infer; export type UpdateCompomentOperation = z.infer; +export type PublishItemOperation = z.infer; +export type UnPublishItemOperation = z.infer;