@graphcommerce/hygraph-cli 7.0.0-canary.13 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +206 -2
- package/Config.graphqls +11 -0
- package/dist/client.js +21 -0
- package/dist/log-functions.js +15 -0
- package/dist/migrateHygraph.js +73 -45
- package/dist/migrationAction.js +127 -0
- package/dist/migrations/graphcommerce5to6.js +100 -0
- package/dist/migrations/{dynamicRow.js → graphcommerce6to7.js} +52 -58
- package/dist/migrations/index.js +18 -0
- package/dist/readSchema.js +58 -0
- package/package.json +16 -13
- package/src/client.ts +25 -0
- package/src/log-functions.ts +12 -0
- package/src/migrateHygraph.ts +62 -49
- package/src/migrationAction.ts +217 -0
- package/src/migrations/graphcommerce5to6.ts +149 -0
- package/src/migrations/graphcommerce6to7.ts +307 -0
- package/src/migrations/index.ts +2 -0
- package/src/readSchema.ts +61 -0
- package/src/types.ts +8 -1
- package/src/migrations/dynamicRow.ts +0 -229
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { loadConfig } from '@graphcommerce/next-config'
|
|
2
|
+
import {
|
|
3
|
+
BatchMigrationCreateModelInput,
|
|
4
|
+
BatchMigrationCreateComponentInput,
|
|
5
|
+
BatchMigrationCreateEnumerationInput,
|
|
6
|
+
BatchMigrationCreateSimpleFieldInput,
|
|
7
|
+
BatchMigrationCreateEnumerableFieldInput,
|
|
8
|
+
BatchMigrationCreateRelationalFieldInput,
|
|
9
|
+
BatchMigrationCreateUnionFieldInput,
|
|
10
|
+
BatchMigrationCreateComponentFieldInput,
|
|
11
|
+
BatchMigrationDeleteComponentInput,
|
|
12
|
+
BatchMigrationDeleteEnumerationInput,
|
|
13
|
+
BatchMigrationDeleteModelInput,
|
|
14
|
+
BatchMigrationUpdateComponentFieldInput,
|
|
15
|
+
BatchMigrationUpdateComponentInput,
|
|
16
|
+
BatchMigrationUpdateEnumerableFieldInput,
|
|
17
|
+
BatchMigrationUpdateEnumerationInput,
|
|
18
|
+
BatchMigrationUpdateModelInput,
|
|
19
|
+
BatchMigrationUpdateRelationalFieldInput,
|
|
20
|
+
BatchMigrationUpdateSimpleFieldInput,
|
|
21
|
+
BatchMigrationUpdateUnionFieldInput,
|
|
22
|
+
BatchMigrationDeleteFieldInput,
|
|
23
|
+
BatchMigrationCreateComponentUnionFieldInput,
|
|
24
|
+
BatchMigrationUpdateComponentUnionFieldInput,
|
|
25
|
+
} from '@hygraph/management-sdk'
|
|
26
|
+
import dotenv from 'dotenv'
|
|
27
|
+
import { initClient } from './client'
|
|
28
|
+
import { graphcommerceLog, capitalize } from './log-functions'
|
|
29
|
+
import { Schema } from './types'
|
|
30
|
+
|
|
31
|
+
dotenv.config()
|
|
32
|
+
const config = loadConfig(process.cwd())
|
|
33
|
+
|
|
34
|
+
export const client = initClient(config, undefined)
|
|
35
|
+
|
|
36
|
+
type AllActions =
|
|
37
|
+
| BatchMigrationCreateModelInput
|
|
38
|
+
| BatchMigrationUpdateModelInput
|
|
39
|
+
| BatchMigrationDeleteModelInput
|
|
40
|
+
| BatchMigrationCreateComponentInput
|
|
41
|
+
| BatchMigrationUpdateComponentInput
|
|
42
|
+
| BatchMigrationDeleteComponentInput
|
|
43
|
+
| BatchMigrationCreateEnumerationInput
|
|
44
|
+
| BatchMigrationUpdateEnumerationInput
|
|
45
|
+
| BatchMigrationDeleteEnumerationInput
|
|
46
|
+
| BatchMigrationCreateSimpleFieldInput // type: SimpleFieldType
|
|
47
|
+
| BatchMigrationUpdateSimpleFieldInput
|
|
48
|
+
| BatchMigrationCreateEnumerableFieldInput
|
|
49
|
+
| BatchMigrationUpdateEnumerableFieldInput
|
|
50
|
+
| BatchMigrationCreateRelationalFieldInput // type: RelationalFieldType
|
|
51
|
+
| BatchMigrationUpdateRelationalFieldInput
|
|
52
|
+
| BatchMigrationCreateUnionFieldInput
|
|
53
|
+
| BatchMigrationUpdateUnionFieldInput
|
|
54
|
+
| BatchMigrationCreateComponentFieldInput
|
|
55
|
+
| BatchMigrationUpdateComponentFieldInput
|
|
56
|
+
| BatchMigrationDeleteFieldInput
|
|
57
|
+
| BatchMigrationCreateComponentUnionFieldInput
|
|
58
|
+
| BatchMigrationUpdateComponentUnionFieldInput
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* This constant is used to assign the right action of the management SDK to the migratioAction
|
|
62
|
+
* function
|
|
63
|
+
*/
|
|
64
|
+
const actionMap = client
|
|
65
|
+
? {
|
|
66
|
+
create: {
|
|
67
|
+
model: (innerprops: BatchMigrationCreateModelInput) => client.createModel(innerprops),
|
|
68
|
+
component: (innerprops: BatchMigrationCreateComponentInput) =>
|
|
69
|
+
client.createComponent(innerprops),
|
|
70
|
+
enumeration: (innerprops: BatchMigrationCreateEnumerationInput) =>
|
|
71
|
+
client.createEnumeration(innerprops),
|
|
72
|
+
simpleField: (innerprops: BatchMigrationCreateSimpleFieldInput) =>
|
|
73
|
+
client.createSimpleField(innerprops),
|
|
74
|
+
enumerableField: (innerprops: BatchMigrationCreateEnumerableFieldInput) =>
|
|
75
|
+
client.createEnumerableField(innerprops),
|
|
76
|
+
componentField: (innerprops: BatchMigrationCreateComponentFieldInput) =>
|
|
77
|
+
client.createComponentField(innerprops),
|
|
78
|
+
relationalField: (innerprops: BatchMigrationCreateRelationalFieldInput) =>
|
|
79
|
+
client.createRelationalField(innerprops),
|
|
80
|
+
unionField: (innerprops: BatchMigrationCreateUnionFieldInput) =>
|
|
81
|
+
client.createUnionField(innerprops),
|
|
82
|
+
componentUnionField: (innerprops: BatchMigrationCreateComponentUnionFieldInput) =>
|
|
83
|
+
client.createComponentUnionField(innerprops),
|
|
84
|
+
},
|
|
85
|
+
update: {
|
|
86
|
+
model: (innerprops: BatchMigrationUpdateModelInput) => client.updateModel(innerprops),
|
|
87
|
+
component: (innerprops: BatchMigrationUpdateComponentInput) =>
|
|
88
|
+
client.updateComponent(innerprops),
|
|
89
|
+
enumeration: (innerprops: BatchMigrationUpdateEnumerationInput) =>
|
|
90
|
+
client.updateEnumeration(innerprops),
|
|
91
|
+
simpleField: (innerprops: BatchMigrationUpdateSimpleFieldInput) =>
|
|
92
|
+
client.updateSimpleField(innerprops),
|
|
93
|
+
enumerableField: (innerprops: BatchMigrationUpdateEnumerableFieldInput) =>
|
|
94
|
+
client.updateEnumerableField(innerprops),
|
|
95
|
+
componentField: (innerprops: BatchMigrationUpdateComponentFieldInput) =>
|
|
96
|
+
client.updateComponentField(innerprops),
|
|
97
|
+
relationalField: (innerprops: BatchMigrationUpdateRelationalFieldInput) =>
|
|
98
|
+
client.updateRelationalField(innerprops),
|
|
99
|
+
unionField: (innerprops: BatchMigrationUpdateUnionFieldInput) =>
|
|
100
|
+
client.updateUnionField(innerprops),
|
|
101
|
+
componentUnionField: (innerprops: BatchMigrationUpdateComponentUnionFieldInput) =>
|
|
102
|
+
client.updateComponentUnionField(innerprops),
|
|
103
|
+
},
|
|
104
|
+
delete: {
|
|
105
|
+
model: (innerprops: BatchMigrationDeleteModelInput) => client.deleteModel(innerprops),
|
|
106
|
+
component: (innerprops: BatchMigrationDeleteComponentInput) =>
|
|
107
|
+
client.deleteComponent(innerprops),
|
|
108
|
+
enumeration: (innerprops: BatchMigrationDeleteEnumerationInput) =>
|
|
109
|
+
client.deleteEnumeration(innerprops),
|
|
110
|
+
simpleField: (innerprops: BatchMigrationDeleteFieldInput) => client.deleteField(innerprops),
|
|
111
|
+
enumerableField: (innerprops: BatchMigrationDeleteFieldInput) =>
|
|
112
|
+
client.deleteField(innerprops),
|
|
113
|
+
componentField: (innerprops: BatchMigrationDeleteFieldInput) =>
|
|
114
|
+
client.deleteField(innerprops),
|
|
115
|
+
relationalField: (innerprops: BatchMigrationDeleteFieldInput) =>
|
|
116
|
+
client.deleteField(innerprops),
|
|
117
|
+
unionField: (innerprops: BatchMigrationDeleteFieldInput) => client.deleteField(innerprops),
|
|
118
|
+
componentUnionField: (innerprops: BatchMigrationDeleteFieldInput) =>
|
|
119
|
+
client.deleteField(innerprops),
|
|
120
|
+
},
|
|
121
|
+
}
|
|
122
|
+
: undefined
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* This function is our variation on the client.migrationAction functions from the hygraph
|
|
126
|
+
* management sdk.
|
|
127
|
+
*
|
|
128
|
+
* MigrationAction() is better suited because it is a single function for all actions. More
|
|
129
|
+
* importantly, if the action fails, because a field with the apiID already exists for instance. it
|
|
130
|
+
* will skip this action but still continue the whole migration, while the management sdk function
|
|
131
|
+
* will bail.
|
|
132
|
+
*
|
|
133
|
+
* It takes the schema as argument, which is always the same.
|
|
134
|
+
*
|
|
135
|
+
* Then it takes the type of schema entity you want to do an action upon, and the action you want to
|
|
136
|
+
* do.
|
|
137
|
+
*
|
|
138
|
+
* The fourth arguments are the props that belong to the action you want to do. For instance, if you
|
|
139
|
+
* want to create a model, you need to pass the props that belong to a model.
|
|
140
|
+
*
|
|
141
|
+
* The last two arguments are optional. If you want to create a field, you need to pass the apiId of
|
|
142
|
+
* the model or component you want to create the field on. If you want to create a field on a
|
|
143
|
+
* component, you also need to pass the parentType, which is either 'model' or 'component'.
|
|
144
|
+
*/
|
|
145
|
+
export const migrationAction = (
|
|
146
|
+
schema: Schema,
|
|
147
|
+
type:
|
|
148
|
+
| 'model'
|
|
149
|
+
| 'component'
|
|
150
|
+
| 'enumeration'
|
|
151
|
+
| 'simpleField'
|
|
152
|
+
| 'componentField'
|
|
153
|
+
| 'enumerableField'
|
|
154
|
+
| 'relationalField'
|
|
155
|
+
| 'unionField'
|
|
156
|
+
| 'componentUnionField',
|
|
157
|
+
action: 'create' | 'update' | 'delete',
|
|
158
|
+
props: AllActions,
|
|
159
|
+
parentApiId?: string,
|
|
160
|
+
parentType?: 'model' | 'component' | 'enumeration',
|
|
161
|
+
) => {
|
|
162
|
+
// Check if the entity already exists
|
|
163
|
+
const alreadyExists = () => {
|
|
164
|
+
switch (type) {
|
|
165
|
+
case 'model':
|
|
166
|
+
return schema.models.some((model) => model.apiId === props.apiId)
|
|
167
|
+
|
|
168
|
+
case 'component':
|
|
169
|
+
return schema.components.some((component) => component.apiId === props.apiId)
|
|
170
|
+
|
|
171
|
+
case 'enumeration':
|
|
172
|
+
return schema.enumerations.some((enumeration) => enumeration.apiId === props.apiId)
|
|
173
|
+
|
|
174
|
+
case 'simpleField':
|
|
175
|
+
case 'enumerableField':
|
|
176
|
+
case 'relationalField':
|
|
177
|
+
case 'unionField':
|
|
178
|
+
case 'componentUnionField': {
|
|
179
|
+
let parent
|
|
180
|
+
switch (parentType) {
|
|
181
|
+
case 'model': {
|
|
182
|
+
parent = schema.models.find((model) => model.apiId === parentApiId)
|
|
183
|
+
break
|
|
184
|
+
}
|
|
185
|
+
case 'component': {
|
|
186
|
+
parent = schema.components.find((component) => component.apiId === parentApiId)
|
|
187
|
+
break
|
|
188
|
+
}
|
|
189
|
+
default:
|
|
190
|
+
return false // or undefined or any other value you want if no match
|
|
191
|
+
}
|
|
192
|
+
return parent?.fields.some((field) => field.apiId === props.apiId)
|
|
193
|
+
}
|
|
194
|
+
default: {
|
|
195
|
+
return false // or undefined or any other value you want if no match
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const actionFunc = actionMap && actionMap[action] && actionMap[action][type]
|
|
201
|
+
|
|
202
|
+
if (!alreadyExists()) {
|
|
203
|
+
if (actionFunc) {
|
|
204
|
+
graphcommerceLog(`${capitalize(action)} ${type} with apiId ${props.apiId}...`)
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
206
|
+
// @ts-ignore | This error is a loss on typescript autocomplete, but the function is called correctly
|
|
207
|
+
actionFunc(props)
|
|
208
|
+
} else {
|
|
209
|
+
graphcommerceLog(`Action ${action} is not supported for ${type}`, 'error')
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
graphcommerceLog(
|
|
213
|
+
`${capitalize(type)} with apiId ${props.apiId} on ${parentApiId} already exists`,
|
|
214
|
+
'warning',
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { RelationalFieldType, SimpleFieldType, VisibilityTypes } from '@hygraph/management-sdk'
|
|
2
|
+
import { migrationAction, client } from '../migrationAction'
|
|
3
|
+
import { Schema } from '../types'
|
|
4
|
+
|
|
5
|
+
export const graphcommerce5to6 = async (schema: Schema) => {
|
|
6
|
+
if (!client) {
|
|
7
|
+
return 0
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// ? ENUMERATIONS
|
|
11
|
+
migrationAction(schema, 'enumeration', 'create', {
|
|
12
|
+
displayName: 'Row Links Variants',
|
|
13
|
+
apiId: 'RowLinksVariants',
|
|
14
|
+
values: [
|
|
15
|
+
{ displayName: 'Inline', apiId: 'Inline' },
|
|
16
|
+
{ displayName: 'Image Label Swiper', apiId: 'ImageLabelSwiper' },
|
|
17
|
+
{ displayName: 'Logo Swiper', apiId: 'LogoSwiper' },
|
|
18
|
+
{ displayName: 'USPS', apiId: 'Usps' },
|
|
19
|
+
],
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
// ? MODEL
|
|
23
|
+
migrationAction(schema, 'model', 'create', {
|
|
24
|
+
apiId: 'RowLinks',
|
|
25
|
+
apiIdPlural: 'RowLinksMultiple',
|
|
26
|
+
displayName: 'Row Links',
|
|
27
|
+
description: 'Row Links is a Row of PageLinks with different variants',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
migrationAction(
|
|
31
|
+
schema,
|
|
32
|
+
'simpleField',
|
|
33
|
+
'create',
|
|
34
|
+
{
|
|
35
|
+
displayName: 'Identity',
|
|
36
|
+
apiId: 'identity',
|
|
37
|
+
description: 'Only used for internal reference',
|
|
38
|
+
type: SimpleFieldType.String,
|
|
39
|
+
isTitle: true,
|
|
40
|
+
isRequired: true,
|
|
41
|
+
isUnique: true,
|
|
42
|
+
modelApiId: 'RowLinks',
|
|
43
|
+
},
|
|
44
|
+
'RowLinks',
|
|
45
|
+
'model',
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
migrationAction(
|
|
49
|
+
schema,
|
|
50
|
+
'enumerableField',
|
|
51
|
+
'create',
|
|
52
|
+
{
|
|
53
|
+
displayName: 'Variant',
|
|
54
|
+
apiId: 'linksVariant',
|
|
55
|
+
parentApiId: 'RowLinks',
|
|
56
|
+
enumerationApiId: 'RowLinksVariants',
|
|
57
|
+
description: 'Different variants for Row Links',
|
|
58
|
+
},
|
|
59
|
+
'RowLinks',
|
|
60
|
+
'model',
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
migrationAction(
|
|
64
|
+
schema,
|
|
65
|
+
'simpleField',
|
|
66
|
+
'create',
|
|
67
|
+
{
|
|
68
|
+
displayName: 'Title',
|
|
69
|
+
apiId: 'title',
|
|
70
|
+
type: SimpleFieldType.String,
|
|
71
|
+
isRequired: true,
|
|
72
|
+
modelApiId: 'RowLinks',
|
|
73
|
+
isLocalized: true,
|
|
74
|
+
},
|
|
75
|
+
'RowLinks',
|
|
76
|
+
'model',
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
migrationAction(
|
|
80
|
+
schema,
|
|
81
|
+
'simpleField',
|
|
82
|
+
'create',
|
|
83
|
+
{
|
|
84
|
+
displayName: 'Copy',
|
|
85
|
+
apiId: 'rowLinksCopy',
|
|
86
|
+
type: SimpleFieldType.Richtext,
|
|
87
|
+
isLocalized: true,
|
|
88
|
+
modelApiId: 'RowLinks',
|
|
89
|
+
},
|
|
90
|
+
'RowLinks',
|
|
91
|
+
'model',
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
migrationAction(
|
|
95
|
+
schema,
|
|
96
|
+
'relationalField',
|
|
97
|
+
'create',
|
|
98
|
+
{
|
|
99
|
+
displayName: 'Links',
|
|
100
|
+
apiId: 'pageLinks',
|
|
101
|
+
modelApiId: 'RowLinks',
|
|
102
|
+
type: RelationalFieldType.Relation,
|
|
103
|
+
reverseField: {
|
|
104
|
+
apiId: 'rowLinks',
|
|
105
|
+
modelApiId: 'PageLink',
|
|
106
|
+
displayName: 'RowLinks',
|
|
107
|
+
visibility: VisibilityTypes.Hidden,
|
|
108
|
+
isList: true,
|
|
109
|
+
},
|
|
110
|
+
visibility: VisibilityTypes.ReadWrite,
|
|
111
|
+
isList: true,
|
|
112
|
+
},
|
|
113
|
+
'RowLinks',
|
|
114
|
+
'model',
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
migrationAction(
|
|
118
|
+
schema,
|
|
119
|
+
'unionField',
|
|
120
|
+
'update',
|
|
121
|
+
{
|
|
122
|
+
apiId: 'content',
|
|
123
|
+
displayName: 'Content',
|
|
124
|
+
modelApiId: 'Page',
|
|
125
|
+
reverseField: {
|
|
126
|
+
modelApiIds: [
|
|
127
|
+
'RowLinks',
|
|
128
|
+
'RowServiceOptions',
|
|
129
|
+
'RowSpecialBanner',
|
|
130
|
+
'RowQuote',
|
|
131
|
+
'RowProduct',
|
|
132
|
+
'RowColumnOne',
|
|
133
|
+
'RowColumnTwo',
|
|
134
|
+
'RowColumnThree',
|
|
135
|
+
'RowHeroBanner',
|
|
136
|
+
'RowBlogContent',
|
|
137
|
+
'RowButtonList',
|
|
138
|
+
'RowContentLinks',
|
|
139
|
+
'RowButtonLinkList',
|
|
140
|
+
],
|
|
141
|
+
// visibility: VisibilityTypes.Hidden, => Currently not supported for updateUnionField | https://github.com/hygraph/management-sdk/issues/34
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
'Page',
|
|
145
|
+
'model',
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
return client.run(true)
|
|
149
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { SimpleFieldType, VisibilityTypes } from '@hygraph/management-sdk'
|
|
2
|
+
import { migrationAction, client } from '../migrationAction'
|
|
3
|
+
import { Schema } from '../types'
|
|
4
|
+
|
|
5
|
+
export const graphcommerce6to7 = async (schema: Schema) => {
|
|
6
|
+
if (!client) {
|
|
7
|
+
return 0
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// ? ENUMERATIONS
|
|
11
|
+
migrationAction(schema, 'enumeration', 'create', {
|
|
12
|
+
displayName: 'Row Column One Variants',
|
|
13
|
+
apiId: 'RowColumnOneVariants',
|
|
14
|
+
values: [
|
|
15
|
+
{ displayName: 'Default', apiId: 'Default' },
|
|
16
|
+
{ displayName: 'Message', apiId: 'Message' },
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
migrationAction(schema, 'enumeration', 'create', {
|
|
21
|
+
displayName: 'Dynamic Row Condition Number Operator',
|
|
22
|
+
apiId: 'DynamicRowConditionNumberOperator',
|
|
23
|
+
values: [
|
|
24
|
+
{ displayName: 'Greater than or equal to', apiId: 'GTE' },
|
|
25
|
+
{ displayName: 'Less than or equal to', apiId: 'LTE' },
|
|
26
|
+
{ displayName: 'Equal to', apiId: 'EQUAL' },
|
|
27
|
+
],
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
migrationAction(schema, 'enumeration', 'create', {
|
|
31
|
+
displayName: 'Dynamic Row Placement',
|
|
32
|
+
apiId: 'DynamicRowPlacement',
|
|
33
|
+
values: [
|
|
34
|
+
{ displayName: 'Before', apiId: 'BEFORE' },
|
|
35
|
+
{ displayName: 'After', apiId: 'AFTER' },
|
|
36
|
+
{ displayName: 'Replace', apiId: 'REPLACE' },
|
|
37
|
+
],
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// ? COMPONENTS
|
|
41
|
+
migrationAction(schema, 'component', 'create', {
|
|
42
|
+
displayName: 'Text',
|
|
43
|
+
apiId: 'ConditionText',
|
|
44
|
+
apiIdPlural: 'ConditionTexts',
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
migrationAction(schema, 'component', 'create', {
|
|
48
|
+
displayName: 'Number',
|
|
49
|
+
apiId: 'ConditionNumber',
|
|
50
|
+
apiIdPlural: 'ConditionNumbers',
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
migrationAction(schema, 'component', 'create', {
|
|
54
|
+
displayName: 'AND',
|
|
55
|
+
apiId: 'ConditionAnd',
|
|
56
|
+
apiIdPlural: 'ConditionAnds',
|
|
57
|
+
description: 'All of these conditions must match',
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
migrationAction(schema, 'component', 'create', {
|
|
61
|
+
displayName: 'OR',
|
|
62
|
+
apiId: 'ConditionOr',
|
|
63
|
+
apiIdPlural: 'ConditionOrs',
|
|
64
|
+
description: 'One of these conditions must match',
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
migrationAction(
|
|
68
|
+
schema,
|
|
69
|
+
'componentUnionField',
|
|
70
|
+
'create',
|
|
71
|
+
{
|
|
72
|
+
displayName: 'Conditions',
|
|
73
|
+
apiId: 'conditions',
|
|
74
|
+
parentApiId: 'ConditionAnd',
|
|
75
|
+
componentApiIds: ['ConditionOr', 'ConditionText', 'ConditionNumber'],
|
|
76
|
+
isList: true,
|
|
77
|
+
},
|
|
78
|
+
'ConditionAnd',
|
|
79
|
+
'component',
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
migrationAction(
|
|
83
|
+
schema,
|
|
84
|
+
'simpleField',
|
|
85
|
+
'create',
|
|
86
|
+
{
|
|
87
|
+
displayName: 'Property',
|
|
88
|
+
apiId: 'property',
|
|
89
|
+
type: SimpleFieldType.String,
|
|
90
|
+
parentApiId: 'ConditionText',
|
|
91
|
+
description:
|
|
92
|
+
'Path to the value of the object being evaluated.\n\nFor products: url_key, category, sku',
|
|
93
|
+
isRequired: true,
|
|
94
|
+
validations: {
|
|
95
|
+
String: {
|
|
96
|
+
matches: {
|
|
97
|
+
flags: ['i', 's'],
|
|
98
|
+
regex: '^[a-z0-9-_.]+$',
|
|
99
|
+
errorMessage: 'Only letters, numbers, dashes (-), underscores (_) or dots allowed (.)',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
'ConditionText',
|
|
105
|
+
'component',
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
migrationAction(
|
|
109
|
+
schema,
|
|
110
|
+
'simpleField',
|
|
111
|
+
'create',
|
|
112
|
+
{
|
|
113
|
+
displayName: 'Value',
|
|
114
|
+
apiId: 'value',
|
|
115
|
+
type: SimpleFieldType.String,
|
|
116
|
+
parentApiId: 'ConditionText',
|
|
117
|
+
isRequired: true,
|
|
118
|
+
},
|
|
119
|
+
'ConditionText',
|
|
120
|
+
'component',
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
migrationAction(
|
|
124
|
+
schema,
|
|
125
|
+
'simpleField',
|
|
126
|
+
'create',
|
|
127
|
+
{
|
|
128
|
+
displayName: 'Property',
|
|
129
|
+
apiId: 'property',
|
|
130
|
+
type: SimpleFieldType.String,
|
|
131
|
+
parentApiId: 'ConditionNumber',
|
|
132
|
+
isRequired: true,
|
|
133
|
+
validations: {
|
|
134
|
+
String: {
|
|
135
|
+
matches: {
|
|
136
|
+
flags: ['i', 's'],
|
|
137
|
+
regex: '^[a-z0-9-_.]+$',
|
|
138
|
+
errorMessage: 'Only letters, numbers, dashes (-), underscores (_) or dots allowed (.)',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
'ConditionNumber',
|
|
144
|
+
'component',
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
migrationAction(
|
|
148
|
+
schema,
|
|
149
|
+
'enumerableField',
|
|
150
|
+
'create',
|
|
151
|
+
{
|
|
152
|
+
displayName: 'Operator',
|
|
153
|
+
apiId: 'operator',
|
|
154
|
+
parentApiId: 'ConditionNumber',
|
|
155
|
+
enumerationApiId: 'DynamicRowConditionNumberOperator',
|
|
156
|
+
isRequired: true,
|
|
157
|
+
},
|
|
158
|
+
'ConditionNumber',
|
|
159
|
+
'component',
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
migrationAction(
|
|
163
|
+
schema,
|
|
164
|
+
'simpleField',
|
|
165
|
+
'create',
|
|
166
|
+
{
|
|
167
|
+
displayName: 'Value',
|
|
168
|
+
apiId: 'value',
|
|
169
|
+
type: SimpleFieldType.Float,
|
|
170
|
+
parentApiId: 'ConditionNumber',
|
|
171
|
+
isRequired: true,
|
|
172
|
+
},
|
|
173
|
+
'ConditionNumber',
|
|
174
|
+
'component',
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
// ? MODEL
|
|
178
|
+
migrationAction(schema, 'model', 'create', {
|
|
179
|
+
displayName: 'Dynamic Row',
|
|
180
|
+
apiId: 'DynamicRow',
|
|
181
|
+
apiIdPlural: 'DynamicRows',
|
|
182
|
+
description:
|
|
183
|
+
'Dynamic rows allow you to add specific Row models to pages based on the properties of the page',
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
migrationAction(
|
|
187
|
+
schema,
|
|
188
|
+
'simpleField',
|
|
189
|
+
'create',
|
|
190
|
+
{
|
|
191
|
+
displayName: 'Internal name',
|
|
192
|
+
apiId: 'internalName',
|
|
193
|
+
description: 'Only used for internal reference',
|
|
194
|
+
type: SimpleFieldType.String,
|
|
195
|
+
isTitle: true,
|
|
196
|
+
isRequired: true,
|
|
197
|
+
isUnique: true,
|
|
198
|
+
modelApiId: 'DynamicRow',
|
|
199
|
+
},
|
|
200
|
+
'DynamicRow',
|
|
201
|
+
'model',
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
migrationAction(
|
|
205
|
+
schema,
|
|
206
|
+
'unionField',
|
|
207
|
+
'create',
|
|
208
|
+
{
|
|
209
|
+
displayName: 'Row',
|
|
210
|
+
apiId: 'row',
|
|
211
|
+
reverseField: {
|
|
212
|
+
modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'],
|
|
213
|
+
apiId: 'dynamicRow',
|
|
214
|
+
displayName: 'DynamicRows',
|
|
215
|
+
visibility: VisibilityTypes.Hidden,
|
|
216
|
+
isList: true,
|
|
217
|
+
},
|
|
218
|
+
parentApiId: 'DynamicRow',
|
|
219
|
+
},
|
|
220
|
+
'DynamicRow',
|
|
221
|
+
'model',
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
migrationAction(
|
|
225
|
+
schema,
|
|
226
|
+
'enumerableField',
|
|
227
|
+
'create',
|
|
228
|
+
{
|
|
229
|
+
displayName: 'Placement',
|
|
230
|
+
apiId: 'placement',
|
|
231
|
+
parentApiId: 'DynamicRow',
|
|
232
|
+
enumerationApiId: 'DynamicRowPlacement',
|
|
233
|
+
description: 'Where will the row be placed relative to the target',
|
|
234
|
+
isRequired: true,
|
|
235
|
+
},
|
|
236
|
+
'DynamicRow',
|
|
237
|
+
'model',
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
migrationAction(
|
|
241
|
+
schema,
|
|
242
|
+
'unionField',
|
|
243
|
+
'create',
|
|
244
|
+
{
|
|
245
|
+
displayName: 'Placement target',
|
|
246
|
+
apiId: 'target',
|
|
247
|
+
description:
|
|
248
|
+
'Optional: When the target is left blank it will place the Dynamic Row on the start or end.',
|
|
249
|
+
reverseField: {
|
|
250
|
+
modelApiIds: [
|
|
251
|
+
'RowQuote',
|
|
252
|
+
'RowLinks',
|
|
253
|
+
'RowColumnOne',
|
|
254
|
+
'RowColumnTwo',
|
|
255
|
+
'RowColumnThree',
|
|
256
|
+
'RowServiceOptions',
|
|
257
|
+
'RowContentLinks',
|
|
258
|
+
'RowButtonLinkList',
|
|
259
|
+
'RowProduct',
|
|
260
|
+
'RowSpecialBanner',
|
|
261
|
+
'RowHeroBanner',
|
|
262
|
+
'RowBlogContent',
|
|
263
|
+
],
|
|
264
|
+
apiId: 'dynamicRowsTarget',
|
|
265
|
+
displayName: 'DynamicRowsTarget',
|
|
266
|
+
visibility: VisibilityTypes.Hidden,
|
|
267
|
+
isList: true,
|
|
268
|
+
},
|
|
269
|
+
parentApiId: 'DynamicRow',
|
|
270
|
+
},
|
|
271
|
+
'DynamicRow',
|
|
272
|
+
'model',
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
migrationAction(
|
|
276
|
+
schema,
|
|
277
|
+
'componentUnionField',
|
|
278
|
+
'create',
|
|
279
|
+
{
|
|
280
|
+
displayName: 'Conditions (OR)',
|
|
281
|
+
apiId: 'conditions',
|
|
282
|
+
parentApiId: 'DynamicRow',
|
|
283
|
+
description: 'One of these conditions must match',
|
|
284
|
+
componentApiIds: ['ConditionAnd', 'ConditionText', 'ConditionNumber'],
|
|
285
|
+
isList: true,
|
|
286
|
+
},
|
|
287
|
+
'DynamicRow',
|
|
288
|
+
'model',
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
// ? Row Column One
|
|
292
|
+
migrationAction(
|
|
293
|
+
schema,
|
|
294
|
+
'enumerableField',
|
|
295
|
+
'create',
|
|
296
|
+
{
|
|
297
|
+
displayName: 'Variant',
|
|
298
|
+
apiId: 'rowColumnOneVariant',
|
|
299
|
+
enumerationApiId: 'RowColumnOneVariants',
|
|
300
|
+
parentApiId: 'RowColumnOne',
|
|
301
|
+
},
|
|
302
|
+
'RowColumnOne',
|
|
303
|
+
'model',
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
return client.run(true)
|
|
307
|
+
}
|