Skip to content

Commit

Permalink
feat(schema): add piece create/update/upsert mass operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Dec 11, 2024
1 parent ca359a3 commit 72df974
Show file tree
Hide file tree
Showing 5 changed files with 612 additions and 475 deletions.
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": "3.0.1",
"version": "3.0.2",
"license": "MIT",
"exports": {
"./pim": {
Expand Down
29 changes: 25 additions & 4 deletions components/schema/src/mass-operation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,33 @@ import {
UpdateItemOperationSchema,
UpsertItemOperationSchema,
} from './item.js';
import { CreateShapeOperationSchema, UpdateShapeOperationSchema, UpsertShapeOperationSchema } from './shape.js';
import {
CreatePieceOperationSchema,
CreateShapeOperationSchema,
UpdatePieceOperationSchema,
UpdateShapeOperationSchema,
UpsertPieceOperationSchema,
UpsertShapeOperationSchema,
} from './shape.js';

export const OperationSchema = z.discriminatedUnion('intent', [
CreateItemOperationSchema,
UpdateItemOperationSchema,
UpsertItemOperationSchema,

PublishItemOperationSchema,
UnPublishItemOperationSchema,

UpdateItemComponentOperationSchema,
UpdateSkuComponentOperationSchema,

CreateShapeOperationSchema,
UpdateShapeOperationSchema,
UpsertShapeOperationSchema,

CreatePieceOperationSchema,
UpdatePieceOperationSchema,
UpsertPieceOperationSchema,
]);

export const OperationsSchema = z.object({
Expand All @@ -34,12 +48,19 @@ export type Operation = z.infer<typeof OperationSchema>;
export type Operations = z.infer<typeof OperationsSchema>;
export type {
CreateItemOperation,
UpdateItemOperation,
UpsertItemOperation,
PublishItemOperation,
UnPublishItemOperation,
UpdateItemComponentOperation,
UpdateSkuComponentOperation,
UpdateItemOperation,
UpsertItemOperation,
} from './item.js';

export type { CreateShapeOperation, UpdateShapeOperation, UpsertShapeOperation } from './shape.js';
export type {
CreateShapeOperation,
UpdateShapeOperation,
UpsertShapeOperation,
CreatePieceOperation,
UpdatePieceOperation,
UpsertPieceOperation,
} from './shape.js';
17 changes: 16 additions & 1 deletion components/schema/src/mass-operation/shape.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod';
import { CreateShapeInputSchema, UpdateShapeInputSchema } from '../pim/shape/index.js';
import { CreatePieceInputSchema, CreateShapeInputSchema, UpdateShapeInputSchema } from '../pim/shape/index.js';

export const CreateShapeOperationSchema = CreateShapeInputSchema.extend({
intent: z.literal('shape/create'),
Expand All @@ -15,3 +15,18 @@ export const UpsertShapeOperationSchema = CreateShapeOperationSchema.extend({
intent: z.literal('shape/upsert'),
});
export type UpsertShapeOperation = z.infer<typeof UpsertShapeOperationSchema>;

export const CreatePieceOperationSchema = CreatePieceInputSchema.extend({
intent: z.literal('piece/create'),
});
export type CreatePieceOperation = z.infer<typeof CreatePieceOperationSchema>;

export const UpdatePieceOperationSchema = CreatePieceInputSchema.extend({
intent: z.literal('piece/update'),
});
export type UpdatePieceOperation = z.infer<typeof UpdatePieceOperationSchema>;

export const UpsertPieceOperationSchema = CreatePieceInputSchema.extend({
intent: z.literal('piece/upsert'),
});
export type UpsertPieceOperation = z.infer<typeof UpsertPieceOperationSchema>;
21 changes: 15 additions & 6 deletions components/schema/src/pim/shape/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,38 @@ import { z } from 'zod';
import { ItemTypeEnum, KeyValuePairInputSchema } from '../../shared/index.js';
import { ComponentDefinitionInputSchema, ComponentDefinitionSchema } from '../components/component-definition.js';

export const UpdateShapeInputSchema = z.object({
export const CreatePieceInputSchema = z.object({
identifier: z.string().min(2).max(64),
name: z.string().min(1),
meta: KeyValuePairInputSchema.optional().nullable(),
components: z.array(ComponentDefinitionInputSchema).optional().nullable(),
});

export const UpdatePieceInputSchema = CreatePieceInputSchema;

export const UpdateShapeInputSchema = CreatePieceInputSchema.extend({
meta: KeyValuePairInputSchema.optional().nullable(),
variantComponents: z.array(ComponentDefinitionInputSchema).optional().nullable(),
});

export const CreateShapeInputSchema = UpdateShapeInputSchema.extend({
type: ItemTypeEnum,
});

export const BasicShapeSchema = z.object({
export const PieceSchema = z.object({
identifier: z.string().min(2).max(64),
name: z.string().min(1),
type: ItemTypeEnum,
components: z.array(ComponentDefinitionSchema).optional(),
});

export const ShapeSchema = BasicShapeSchema.extend({
components: z.array(ComponentDefinitionSchema).optional(),
export const ShapeSchema = PieceSchema.extend({
type: ItemTypeEnum,
variantComponents: z.array(ComponentDefinitionSchema).optional(),
});

export type CreateShapeInput = z.infer<typeof UpdateShapeInputSchema>;
export type UpdateShapeInput = z.infer<typeof UpdateShapeInputSchema>;
export type CreatePieceInput = z.infer<typeof CreatePieceInputSchema>;
export type UpdatePieceInput = z.infer<typeof UpdatePieceInputSchema>;

export type Shape = z.infer<typeof ShapeSchema>;
export type Piece = z.infer<typeof PieceSchema>;
Loading

0 comments on commit 72df974

Please sign in to comment.