Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schema): add some types for mass operations #238

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/schema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crystallize/schema",
"version": "1.0.0",
"version": "1.1.0",
"license": "MIT",
"type": "module",
"exports": {
Expand Down
4 changes: 4 additions & 0 deletions components/schema/src/mass-operation/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { z } from 'zod';
import {
CreateItemOperationSchema,
PublishItemOperationSchema,
UnPublishItemOperationSchema,
UpdateCompomentOperationSchema,
UpdateItemOperationSchema,
UpsertItemOperationSchema,
Expand All @@ -11,6 +13,8 @@ export const OperationSchema = z.union([
UpdateItemOperationSchema,
UpsertItemOperationSchema,
UpdateCompomentOperationSchema,
PublishItemOperationSchema,
UnPublishItemOperationSchema,
]);

export const OperationsSchema = z.object({
Expand Down
23 changes: 22 additions & 1 deletion components/schema/src/mass-operation/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const UpdateItemOperationSchema = CreateItemOperationSchema.omit({
}).merge(
z.object({
action: z.literal('update'),
itemId: z.string().min(1),
}),
);

Expand All @@ -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<typeof CreateItemOperationSchema>;
export type UpdateItemOperation = z.infer<typeof UpdateItemOperationSchema>;
export type UpsertItemOperation = z.infer<typeof UpsertItemOperationSchema>;
export type UpdateCompomentOperation = z.infer<typeof UpdateCompomentOperationSchema>;
export type PublishItemOperation = z.infer<typeof PublishItemOperationSchema>;
export type UnPublishItemOperation = z.infer<typeof UnPublishItemOperationSchema>;
Loading