Skip to content

Commit a292cf5

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

4 files changed

Lines changed: 150 additions & 15 deletions

File tree

components/schema/package.json

Lines changed: 1 addition & 1 deletion
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",

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: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,66 @@ export const UpdateSkuComponentOperationSchema = z.object({
9898
sku: z.string(),
9999
});
100100

101-
export const PublishItemOperationSchema = z.object({
102-
_ref: RefSchema.optional(),
103-
intent: z.literal('item/publish'),
104-
language: z.string().min(1),
105-
includeDescendants: z.boolean().optional(),
106-
itemId: IdSchema.optional(),
107-
resourceIdentifier: ResourceIdentifierSchema.optional(),
108-
});
101+
export const PublishItemOperationSchema = z
102+
.object({
103+
_ref: RefSchema.optional(),
104+
intent: z.literal('item/publish'),
105+
language: z.string().min(1),
106+
includeDescendants: z.boolean().optional(),
107+
itemId: IdSchema.optional(),
108+
resourceIdentifier: ResourceIdentifierSchema.optional(),
109+
})
110+
.superRefine(checkResourceIdentifierOrId);
109111

110112
export const UnPublishItemOperationSchema = PublishItemOperationSchema.omit({ intent: true }).extend({
111113
intent: z.literal('item/unpublish'),
112114
});
113115

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

121162
export type UpdateItemComponentOperation = z.infer<typeof UpdateItemComponentOperationSchema>;
122163
export type UpdateSkuComponentOperation = z.infer<typeof UpdateSkuComponentOperationSchema>;
@@ -135,3 +176,7 @@ export type UpsertFolderOperation = z.infer<typeof UpsertFolderOperationSchema>;
135176
export type CreateProductOperation = z.infer<typeof CreateProductOperationSchema>;
136177
export type UpdateProductOperation = z.infer<typeof UpdateProductOperationSchema>;
137178
export type UpsertProductOperation = z.infer<typeof UpsertProductOperationSchema>;
179+
180+
export type AddItemTreeNodeShortcutsOperation = z.infer<typeof AddItemTreeNodeShortcutsOperationSchema>;
181+
export type AddItemTreeNodeAliasesOperation = z.infer<typeof AddItemTreeNodeAliasesOperationSchema>;
182+
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+
}

0 commit comments

Comments
 (0)