Skip to content

Commit 7f4a5ef

Browse files
committed
feat(schema): _ref and turi management as well as a better working recursive type matching new component signature of core next
1 parent 078d714 commit 7f4a5ef

33 files changed

Lines changed: 8106 additions & 10665 deletions

components/schema/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@crystallize/schema",
3-
"version": "5.3.0",
3+
"version": "6.0.0-beta.0",
44
"license": "MIT",
55
"exports": {
66
"./catalogue": {
@@ -30,7 +30,7 @@
3030
"test": "vitest run"
3131
},
3232
"dependencies": {
33-
"zod": "^4.0.15"
33+
"zod": "^4.1.12"
3434
},
3535
"devDependencies": {
3636
"@tsconfig/node20": "^20.1.6",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { z } from 'zod';
2+
import { RegisterImageInputSchema } from '../pim';
3+
import { RefSchema } from '../shared';
4+
5+
export const RegisterImageOperationSchema = RegisterImageInputSchema.extend({
6+
intent: z.literal('image/register'),
7+
_ref: RefSchema.optional(),
8+
});
9+
10+
export type RegisterImageOperation = z.infer<typeof RegisterImageOperationSchema>;

components/schema/src/mass-operation/customer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,40 @@ import {
55
CreateCustomerGroupInputSchema,
66
UpdateCustomerGroupInputSchema,
77
} from '../pim';
8+
import { RefSchema } from '../shared';
89

910
export const CreateCustomerOperationSchema = CreateCustomerInputSchema.extend({
11+
_ref: RefSchema.optional(),
1012
intent: z.literal('customer/create'),
1113
});
1214
export type CreateCustomerOperation = z.infer<typeof CreateCustomerOperationSchema>;
1315

1416
export const UpdateCustomerOperationSchema = UpdateCustomerInputSchema.extend({
17+
_ref: RefSchema.optional(),
1518
intent: z.literal('customer/update'),
1619
});
1720
export type UpdateCustomerOperation = z.infer<typeof UpdateCustomerOperationSchema>;
1821

1922
export const UpsertCustomerOperationSchema = CreateCustomerInputSchema.extend({
23+
_ref: RefSchema.optional(),
2024
intent: z.literal('customer/upsert'),
2125
});
2226
export type UpsertCustomerOperation = z.infer<typeof UpsertCustomerOperationSchema>;
2327

2428
export const CreateCustomerGroupOperationSchema = CreateCustomerGroupInputSchema.extend({
29+
_ref: RefSchema.optional(),
2530
intent: z.literal('customer/group/create'),
2631
});
2732
export type CreateCustomerGroupOperation = z.infer<typeof CreateCustomerGroupOperationSchema>;
2833

2934
export const UpdateCustomerGroupOperationSchema = UpdateCustomerGroupInputSchema.extend({
35+
_ref: RefSchema.optional(),
3036
intent: z.literal('customer/group/update'),
3137
});
3238
export type UpdateCustomerGroupOperation = z.infer<typeof UpdateCustomerGroupOperationSchema>;
3339

3440
export const UpsertCustomerGroupOperationSchema = CreateCustomerGroupInputSchema.extend({
41+
_ref: RefSchema.optional(),
3542
intent: z.literal('customer/group/upsert'),
3643
});
3744
export type UpsertCustomerGroupOperation = z.infer<typeof UpsertCustomerGroupOperationSchema>;

components/schema/src/mass-operation/index.ts

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import { z } from 'zod';
22

3-
export const LoopingOperationOperationSchema = z.object({
4-
_ref: z.string().optional(),
5-
});
6-
7-
// Helper function to extend any operation schema with base properties
8-
export const withLoopingOperationProperties = <T extends z.ZodRawShape>(schema: z.ZodObject<T>) => {
9-
return LoopingOperationOperationSchema.extend(schema.shape);
10-
};
11-
123
import {
134
PublishItemOperationSchema,
145
UnPublishItemOperationSchema,
@@ -49,50 +40,53 @@ import {
4940
UpsertSubscriptionContractOperationSchema,
5041
} from './subscription-contract.js';
5142

43+
import { RegisterImageOperationSchema } from './asset.js';
44+
5245
export const OperationSchema = z.discriminatedUnion('intent', [
53-
withLoopingOperationProperties(CreateDocumentOperationSchema),
54-
withLoopingOperationProperties(UpdateDocumentOperationSchema),
55-
withLoopingOperationProperties(UpsertDocumentOperationSchema),
46+
CreateDocumentOperationSchema,
47+
UpdateDocumentOperationSchema,
48+
UpsertDocumentOperationSchema,
5649

57-
withLoopingOperationProperties(CreateFolderOperationSchema),
58-
withLoopingOperationProperties(UpdateFolderOperationSchema),
59-
withLoopingOperationProperties(UpsertFolderOperationSchema),
50+
CreateFolderOperationSchema,
51+
UpdateFolderOperationSchema,
52+
UpsertFolderOperationSchema,
6053

61-
withLoopingOperationProperties(CreateProductOperationSchema),
62-
withLoopingOperationProperties(UpdateProductOperationSchema),
63-
withLoopingOperationProperties(UpsertProductOperationSchema),
54+
CreateProductOperationSchema,
55+
UpdateProductOperationSchema,
56+
UpsertProductOperationSchema,
6457

65-
withLoopingOperationProperties(PublishItemOperationSchema),
66-
withLoopingOperationProperties(UnPublishItemOperationSchema),
58+
PublishItemOperationSchema,
59+
UnPublishItemOperationSchema,
6760

68-
withLoopingOperationProperties(UpdateItemComponentOperationSchema),
69-
withLoopingOperationProperties(UpdateSkuComponentOperationSchema),
61+
UpdateItemComponentOperationSchema,
62+
UpdateSkuComponentOperationSchema,
7063

71-
withLoopingOperationProperties(CreateShapeOperationSchema),
72-
withLoopingOperationProperties(UpdateShapeOperationSchema),
73-
withLoopingOperationProperties(UpsertShapeOperationSchema),
64+
CreateShapeOperationSchema,
65+
UpdateShapeOperationSchema,
66+
UpsertShapeOperationSchema,
7467

75-
withLoopingOperationProperties(CreatePieceOperationSchema),
76-
withLoopingOperationProperties(UpdatePieceOperationSchema),
77-
withLoopingOperationProperties(UpsertPieceOperationSchema),
68+
CreatePieceOperationSchema,
69+
UpdatePieceOperationSchema,
70+
UpsertPieceOperationSchema,
7871

79-
withLoopingOperationProperties(ModifyProductVariantStockOperationSchema),
72+
ModifyProductVariantStockOperationSchema,
73+
RegisterImageOperationSchema,
8074

81-
withLoopingOperationProperties(CreateCustomerGroupOperationSchema),
82-
withLoopingOperationProperties(UpdateCustomerGroupOperationSchema),
83-
withLoopingOperationProperties(UpsertCustomerGroupOperationSchema),
75+
CreateCustomerGroupOperationSchema,
76+
UpdateCustomerGroupOperationSchema,
77+
UpsertCustomerGroupOperationSchema,
8478

85-
withLoopingOperationProperties(CreateCustomerOperationSchema),
86-
withLoopingOperationProperties(UpdateCustomerOperationSchema),
87-
withLoopingOperationProperties(UpsertCustomerOperationSchema),
79+
CreateCustomerOperationSchema,
80+
UpdateCustomerOperationSchema,
81+
UpsertCustomerOperationSchema,
8882

89-
withLoopingOperationProperties(RegisterOrderOperationSchema),
90-
withLoopingOperationProperties(UpdateOrderOperationSchema),
91-
withLoopingOperationProperties(UpsertOrderOperationSchema),
83+
RegisterOrderOperationSchema,
84+
UpdateOrderOperationSchema,
85+
UpsertOrderOperationSchema,
9286

93-
withLoopingOperationProperties(CreateSubscriptionContractOperationSchema),
94-
withLoopingOperationProperties(UpdateSubscriptionContractOperationSchema),
95-
withLoopingOperationProperties(UpsertSubscriptionContractOperationSchema),
87+
CreateSubscriptionContractOperationSchema,
88+
UpdateSubscriptionContractOperationSchema,
89+
UpsertSubscriptionContractOperationSchema,
9690
]);
9791

9892
export const OperationsSchema = z.object({
@@ -146,3 +140,7 @@ export type {
146140
UpdateSubscriptionContractOperation,
147141
UpsertSubscriptionContractOperation,
148142
} from './subscription-contract.js';
143+
144+
export type {
145+
RegisterImageOperation
146+
} from './asset.js';

components/schema/src/mass-operation/item.ts

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,89 +8,106 @@ import {
88
UpdateFolderInputSchema,
99
UpdateProductInputSchema,
1010
} from '../pim/index.js';
11-
import { IdSchema } from '../shared/index.js';
11+
import { checkTuriOrId, IdSchema, RefSchema, TURISchema } from '../shared';
1212

1313
export const CreateDocumentOperationSchema = CreateDocumentInputSchema.extend({
14+
_ref: RefSchema.optional(),
1415
intent: z.literal('document/create'),
1516
language: z.string().min(1),
17+
turi: TURISchema.optional(),
1618
});
1719

1820
export const UpdateDocumentOperationSchema = UpdateDocumentInputSchema.extend({
21+
_ref: RefSchema.optional(),
1922
intent: z.literal('document/update'),
20-
itemId: IdSchema,
2123
language: z.string().min(1),
22-
});
24+
itemId: IdSchema.optional(),
25+
turi: TURISchema.optional(),
26+
}).superRefine(checkTuriOrId)
2327

2428
export const UpsertDocumentOperationSchema = CreateDocumentInputSchema.extend({
29+
_ref: RefSchema.optional(),
2530
intent: z.literal('document/upsert'),
2631
language: z.string().min(1),
27-
itemId: IdSchema,
28-
});
32+
itemId: IdSchema.optional(),
33+
turi: TURISchema.optional(),
34+
})
2935

3036
export const CreateFolderOperationSchema = CreateFolderInputSchema.extend({
37+
_ref: RefSchema.optional(),
3138
intent: z.literal('folder/create'),
3239
language: z.string().min(1),
40+
turi: TURISchema.optional(),
3341
});
3442

3543
export const UpdateFolderOperationSchema = UpdateFolderInputSchema.extend({
44+
_ref: RefSchema.optional(),
3645
intent: z.literal('folder/update'),
3746
language: z.string().min(1),
38-
itemId: IdSchema,
39-
});
47+
itemId: IdSchema.optional(),
48+
turi: TURISchema.optional(),
49+
}).superRefine(checkTuriOrId)
4050

4151
export const UpsertFolderOperationSchema = CreateFolderInputSchema.extend({
52+
_ref: RefSchema.optional(),
4253
intent: z.literal('folder/upsert'),
4354
language: z.string().min(1),
44-
itemId: IdSchema,
55+
itemId: IdSchema.optional(),
56+
turi: TURISchema.optional(),
4557
});
4658

4759
export const CreateProductOperationSchema = CreateProductInputSchema.extend({
60+
_ref: RefSchema.optional(),
4861
intent: z.literal('product/create'),
4962
language: z.string().min(1),
63+
turi: TURISchema.optional(),
5064
});
5165

5266
export const UpdateProductOperationSchema = UpdateProductInputSchema.extend({
67+
_ref: RefSchema.optional(),
5368
intent: z.literal('product/update'),
5469
language: z.string().min(1),
55-
itemId: IdSchema,
56-
});
70+
itemId: IdSchema.optional(),
71+
turi: TURISchema.optional(),
72+
}).superRefine(checkTuriOrId)
5773

5874
export const UpsertProductOperationSchema = CreateProductInputSchema.extend({
75+
_ref: RefSchema.optional(),
5976
intent: z.literal('product/upsert'),
6077
language: z.string().min(1),
61-
itemId: IdSchema,
78+
itemId: IdSchema.optional(),
79+
turi: TURISchema.optional(),
6280
});
6381

6482
export const UpdateItemComponentOperationSchema = z.object({
83+
_ref: RefSchema.optional(),
6584
intent: z.literal('item/updateComponent/item'),
6685
language: z.string().min(1),
6786
component: ComponentContentInputSchema,
68-
sku: z.never().optional(),
69-
itemId: IdSchema,
70-
});
87+
itemId: IdSchema.optional(),
88+
turi: TURISchema.optional(),
89+
}).superRefine(checkTuriOrId)
7190

72-
export const UpdateSkuComponentOperationSchema = UpdateItemComponentOperationSchema.omit({
73-
intent: true,
74-
itemId: true,
75-
sku: true,
76-
}).extend({
91+
export const UpdateSkuComponentOperationSchema = z.object({
92+
_ref: RefSchema.optional(),
7793
intent: z.literal('item/updateComponent/sku'),
94+
language: z.string().min(1),
95+
component: ComponentContentInputSchema,
7896
sku: z.string(),
79-
itemId: z.never().optional(),
8097
});
8198

8299
export const PublishItemOperationSchema = z.object({
100+
_ref: RefSchema.optional(),
83101
intent: z.literal('item/publish'),
84-
itemId: IdSchema,
85102
language: z.string().min(1),
86103
includeDescendants: z.boolean().optional(),
87-
});
104+
itemId: IdSchema.optional(),
105+
turi: TURISchema.optional(),
106+
})
88107

89-
export const UnPublishItemOperationSchema = PublishItemOperationSchema.omit({ intent: true }).merge(
90-
z.object({
91-
intent: z.literal('item/unpublish'),
92-
}),
93-
);
108+
export const UnPublishItemOperationSchema = PublishItemOperationSchema.omit({ intent: true }).extend({
109+
intent: z.literal('item/unpublish')
110+
})
94111

95112
export type UpdateItemComponentOperation = z.infer<typeof UpdateItemComponentOperationSchema>;
96113
export type UpdateSkuComponentOperation = z.infer<typeof UpdateSkuComponentOperationSchema>;
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import { z } from 'zod';
22
import { UpdateOrderInputSchema, RegisterOrderInputSchema } from '../pim';
3+
import { checkTuriOrId, RefSchema, TURISchema } from '../shared';
34

45
export const RegisterOrderOperationSchema = RegisterOrderInputSchema.extend({
6+
_ref: RefSchema.optional(),
57
intent: z.literal('order/register'),
8+
turi: TURISchema.optional(),
69
});
710
export type RegisterOrderOperation = z.infer<typeof RegisterOrderOperationSchema>;
811

9-
export const UpdateOrderOperationSchema = UpdateOrderInputSchema.extend({
12+
export const UpdateOrderOperationSchema = UpdateOrderInputSchema.omit({ id: true }).extend({
13+
_ref: RefSchema.optional(),
1014
intent: z.literal('order/update'),
11-
});
15+
id: UpdateOrderInputSchema.shape.id.optional(),
16+
turi: TURISchema.optional(),
17+
}).superRefine(checkTuriOrId)
18+
1219
export type UpdateOrderOperation = z.infer<typeof UpdateOrderOperationSchema>;
1320

1421
export const UpsertOrderOperationSchema = RegisterOrderInputSchema.omit({
1522
pipelines: true,
1623
}).extend({
24+
_ref: RefSchema.optional(),
1725
intent: z.literal('order/upsert'),
18-
id: UpdateOrderOperationSchema.shape.id.optional(),
26+
id: UpdateOrderInputSchema.shape.id.optional(),
27+
turi: TURISchema.optional(),
1928
});
29+
2030
export type UpsertOrderOperation = z.infer<typeof UpsertOrderOperationSchema>;

components/schema/src/mass-operation/product-variant.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { z } from 'zod';
22
import { ModifyProductVariantStockInputSchema } from '../pim';
3+
import { RefSchema } from '../shared';
34

45
export const ModifyProductVariantStockOperationSchema = ModifyProductVariantStockInputSchema.extend({
6+
_ref: RefSchema.optional(),
57
intent: z.literal('product/variant/stock/modify'),
68
});
79

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
import { z } from 'zod';
22
import { CreatePieceInputSchema, CreateShapeInputSchema, UpdateShapeInputSchema } from '../pim/shapes/index.js';
3+
import { RefSchema } from '../shared/index.js';
34

45
export const CreateShapeOperationSchema = CreateShapeInputSchema.extend({
6+
_ref: RefSchema.optional(),
57
intent: z.literal('shape/create'),
68
});
79
export type CreateShapeOperation = z.infer<typeof CreateShapeOperationSchema>;
810

911
export const UpdateShapeOperationSchema = UpdateShapeInputSchema.extend({
12+
_ref: RefSchema.optional(),
1013
intent: z.literal('shape/update'),
1114
});
1215
export type UpdateShapeOperation = z.infer<typeof UpdateShapeOperationSchema>;
1316

1417
export const UpsertShapeOperationSchema = CreateShapeOperationSchema.extend({
18+
_ref: RefSchema.optional(),
1519
intent: z.literal('shape/upsert'),
1620
});
1721
export type UpsertShapeOperation = z.infer<typeof UpsertShapeOperationSchema>;
1822

1923
export const CreatePieceOperationSchema = CreatePieceInputSchema.extend({
24+
_ref: RefSchema.optional(),
2025
intent: z.literal('piece/create'),
2126
});
2227
export type CreatePieceOperation = z.infer<typeof CreatePieceOperationSchema>;
2328

2429
export const UpdatePieceOperationSchema = CreatePieceInputSchema.extend({
30+
_ref: RefSchema.optional(),
2531
intent: z.literal('piece/update'),
2632
});
2733
export type UpdatePieceOperation = z.infer<typeof UpdatePieceOperationSchema>;
2834

2935
export const UpsertPieceOperationSchema = CreatePieceInputSchema.extend({
36+
_ref: RefSchema.optional(),
3037
intent: z.literal('piece/upsert'),
3138
});
3239
export type UpsertPieceOperation = z.infer<typeof UpsertPieceOperationSchema>;

0 commit comments

Comments
 (0)