Skip to content

Commit 14da1a0

Browse files
committed
feat(schema): introduce shortcuts, history and aliases
1 parent 00c377a commit 14da1a0

5 files changed

Lines changed: 151 additions & 10 deletions

File tree

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": "6.5.0",
3+
"version": "6.6.0",
44
"license": "MIT",
55
"repository": {
66
"type": "git",
@@ -35,7 +35,7 @@
3535
},
3636
"dependencies": {
3737
"tslib": "^2.8.1",
38-
"zod": "^4.1.12"
38+
"zod": "^4.3.6"
3939
},
4040
"devDependencies": {
4141
"@tsconfig/node20": "^20.1.6",

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import {
1515
UpdateProductOperationSchema,
1616
UpsertProductOperationSchema,
1717
DeleteItemOperationSchema,
18+
AddItemTreeNodeAliasesOperationSchema,
19+
AddItemTreeNodeShortcutsOperationSchema,
20+
AddItemTreeNodeHistoryOperationSchema,
1821
} from './item';
1922
import {
2023
CreatePieceOperationSchema,
@@ -106,6 +109,10 @@ export const OperationSchema = z.discriminatedUnion('intent', [
106109
CreateTopicOperationSchema,
107110
UpdateTopicOperationSchema,
108111
UpsertTopicOperationSchema,
112+
113+
AddItemTreeNodeAliasesOperationSchema,
114+
AddItemTreeNodeShortcutsOperationSchema,
115+
AddItemTreeNodeHistoryOperationSchema,
109116
]);
110117

111118
export const OperationsSchema = z.object({
@@ -132,6 +139,9 @@ export type {
132139
UpdateItemComponentOperation,
133140
UpdateSkuComponentOperation,
134141
DeleteItemOperation,
142+
AddItemTreeNodeAliasesOperation,
143+
AddItemTreeNodeShortcutsOperation,
144+
AddItemTreeNodeHistoryOperation,
135145
} from './item';
136146

137147
export type {

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,51 @@ export const UnPublishItemOperationSchema = PublishItemOperationSchema.omit({ in
111111
intent: z.literal('item/unpublish'),
112112
});
113113

114-
export const DeleteItemOperationSchema = z.object({
115-
_ref: RefSchema.optional(),
116-
intent: z.literal('item/delete'),
117-
itemId: IdSchema.optional(),
118-
resourceIdentifier: ResourceIdentifierSchema.optional(),
119-
});
114+
export const DeleteItemOperationSchema = z
115+
.object({
116+
_ref: RefSchema.optional(),
117+
intent: z.literal('item/delete'),
118+
itemId: IdSchema.optional(),
119+
resourceIdentifier: ResourceIdentifierSchema.optional(),
120+
})
121+
.superRefine(checkResourceIdentifierOrId);
122+
123+
export const AddItemTreeNodeShortcutsOperationSchema = z
124+
.object({
125+
_ref: RefSchema.optional(),
126+
intent: z.literal('item/paths/addShortcuts'),
127+
itemId: IdSchema.optional(),
128+
resourceIdentifier: ResourceIdentifierSchema.optional(),
129+
shortcuts: z.array(
130+
z.object({
131+
parentId: IdSchema,
132+
position: z.number().int().min(0).optional(),
133+
}),
134+
),
135+
})
136+
.superRefine(checkResourceIdentifierOrId);
137+
138+
export const AddItemTreeNodeAliasesOperationSchema = z
139+
.object({
140+
_ref: RefSchema.optional(),
141+
intent: z.literal('item/paths/addAliases'),
142+
itemId: IdSchema.optional(),
143+
resourceIdentifier: ResourceIdentifierSchema.optional(),
144+
language: z.string().min(1),
145+
paths: z.array(z.string().min(1)),
146+
})
147+
.superRefine(checkResourceIdentifierOrId);
148+
149+
export const AddItemTreeNodeHistoryOperationSchema = z
150+
.object({
151+
_ref: RefSchema.optional(),
152+
intent: z.literal('item/paths/addHistory'),
153+
itemId: IdSchema.optional(),
154+
resourceIdentifier: ResourceIdentifierSchema.optional(),
155+
language: z.string().min(1),
156+
paths: z.array(z.string().min(1)),
157+
})
158+
.superRefine(checkResourceIdentifierOrId);
120159

121160
export type UpdateItemComponentOperation = z.infer<typeof UpdateItemComponentOperationSchema>;
122161
export type UpdateSkuComponentOperation = z.infer<typeof UpdateSkuComponentOperationSchema>;
@@ -135,3 +174,7 @@ export type UpsertFolderOperation = z.infer<typeof UpsertFolderOperationSchema>;
135174
export type CreateProductOperation = z.infer<typeof CreateProductOperationSchema>;
136175
export type UpdateProductOperation = z.infer<typeof UpdateProductOperationSchema>;
137176
export type UpsertProductOperation = z.infer<typeof UpsertProductOperationSchema>;
177+
178+
export type AddItemTreeNodeShortcutsOperation = z.infer<typeof AddItemTreeNodeShortcutsOperationSchema>;
179+
export type AddItemTreeNodeAliasesOperation = z.infer<typeof AddItemTreeNodeAliasesOperationSchema>;
180+
export type AddItemTreeNodeHistoryOperation = z.infer<typeof AddItemTreeNodeHistoryOperationSchema>;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"version": "0.0.1",
3+
"operations": [
4+
{
5+
"_ref": "topA",
6+
"intent": "folder/upsert",
7+
"tree": {
8+
"parentId": "{{ defaults.rootItemId }}"
9+
},
10+
"language": "en",
11+
"shapeIdentifier": "default-folder",
12+
"name": "Top A of my tree for Paths Operations",
13+
"resourceIdentifier": "top-A-of-my-tree-for-paths-operations"
14+
},
15+
{
16+
"_ref": "topB",
17+
"intent": "folder/upsert",
18+
"tree": {
19+
"parentId": "{{ defaults.rootItemId }}"
20+
},
21+
"language": "en",
22+
"shapeIdentifier": "default-folder",
23+
"name": "Top B of my tree for Paths Operations",
24+
"resourceIdentifier": "top-B-of-my-tree-for-paths-operations"
25+
},
26+
{
27+
"_ref": "topC",
28+
"intent": "folder/upsert",
29+
"tree": {
30+
"parentId": "{{ defaults.rootItemId }}"
31+
},
32+
"language": "en",
33+
"shapeIdentifier": "default-folder",
34+
"name": "Top C of my tree for Paths Operations",
35+
"resourceIdentifier": "top-C-of-my-tree-for-paths-operations"
36+
},
37+
{
38+
"intent": "document/upsert",
39+
"tree": {
40+
"parentId": "{{#if topA.id.id}}{{ topA.id.id }}{{else}}{{ topA.id}}{{/if}}"
41+
},
42+
"language": "en",
43+
"shapeIdentifier": "default-document",
44+
"name": "Child of Top A",
45+
"resourceIdentifier": "child-of-top-a"
46+
},
47+
{
48+
"intent": "item/paths/addAliases",
49+
"language": "en",
50+
"resourceIdentifier": "child-of-top-a",
51+
"paths": [
52+
"/fake/top-b-of-my-tree-for-paths-operations/alias-for-child-of-top-a",
53+
"/another-fake/top-b/alias2-for-child-of-top-a"
54+
]
55+
},
56+
{
57+
"intent": "item/paths/addHistory",
58+
"language": "en",
59+
"resourceIdentifier": "child-of-top-a",
60+
"paths": [
61+
"/old-fake/top-b-of-my-tree-for-paths-operations/alias-for-child-of-top-a",
62+
"/old-another-fake/top-b/alias2-for-child-of-top-a"
63+
]
64+
},
65+
{
66+
"intent": "item/paths/addShortcuts",
67+
"resourceIdentifier": "child-of-top-a",
68+
"shortcuts": [
69+
{
70+
"parentId": "{{#if topB.id.id}}{{ topB.id.id }}{{else}}{{ topB.id}}{{/if}}",
71+
"position": 12
72+
},
73+
{
74+
"parentId": "{{#if topC.id.id}}{{ topC.id.id }}{{else}}{{ topC.id}}{{/if}}",
75+
"position": 12
76+
}
77+
]
78+
}
79+
]
80+
}

pnpm-lock.yaml

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)