@hygraph/cli 0.0.11 → 0.0.12
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/dist/cli.js +532 -120
- package/dist/define.d.ts +91 -16
- package/dist/define2.js +88 -20
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3223,11 +3223,16 @@ const SchemaDefinitionDocument = new TypedDocumentString(`
|
|
|
3223
3223
|
apiId
|
|
3224
3224
|
__typename
|
|
3225
3225
|
}
|
|
3226
|
+
systemModels: models(includeSystemModels: true) {
|
|
3227
|
+
apiId
|
|
3228
|
+
__typename
|
|
3229
|
+
}
|
|
3226
3230
|
models(includeSystemModels: false) {
|
|
3227
3231
|
apiId
|
|
3228
3232
|
fields(includeHiddenFields: true, includeApiOnlyFields: true) {
|
|
3229
3233
|
apiId
|
|
3230
3234
|
... on RelationalField {
|
|
3235
|
+
isVariantEnabled
|
|
3231
3236
|
relationalFieldRules {
|
|
3232
3237
|
connections {
|
|
3233
3238
|
min
|
|
@@ -3754,12 +3759,16 @@ function isRename(change) {
|
|
|
3754
3759
|
* value or a node is counted too, although Hygraph refuses it while entries
|
|
3755
3760
|
* hold the value or a node of the subtree. A union
|
|
3756
3761
|
* update that drops a member deletes that member's content, a union
|
|
3757
|
-
* reference's update that drops a model deletes that model's field back,
|
|
3758
|
-
*
|
|
3759
|
-
* entries.
|
|
3762
|
+
* reference's update that drops a model deletes that model's field back, a
|
|
3763
|
+
* rich text update that drops an embedded model deletes the embeds of its
|
|
3764
|
+
* entries, and turning a field's variants off deletes its variant values.
|
|
3760
3765
|
*/
|
|
3761
3766
|
function isDestructive(change) {
|
|
3762
|
-
return change.action === "delete" || dropsUnionMember(change) || dropsEmbed(change);
|
|
3767
|
+
return change.action === "delete" || dropsUnionMember(change) || dropsEmbed(change) || dropsVariants(change);
|
|
3768
|
+
}
|
|
3769
|
+
/** A field update that turns variants off: Hygraph deletes its variant values. */
|
|
3770
|
+
function dropsVariants(change) {
|
|
3771
|
+
return change.resource === "field" && change.action === "update" && change.kind !== "unsupported" && change.changes.variantEnabled?.to === false;
|
|
3763
3772
|
}
|
|
3764
3773
|
/**
|
|
3765
3774
|
* An asset field update that makes it required. It is not destructive, but
|
|
@@ -5775,6 +5784,7 @@ function createSimpleField({ parent, migrationValue }, field) {
|
|
|
5775
5784
|
isTitle: field.title,
|
|
5776
5785
|
visibility: field.visibility,
|
|
5777
5786
|
visibilityCondition: field.visibilityCondition,
|
|
5787
|
+
isVariantEnabled: field.variantEnabled,
|
|
5778
5788
|
initialValue: jsonValue(field.initialValue),
|
|
5779
5789
|
position: field.position
|
|
5780
5790
|
};
|
|
@@ -5794,7 +5804,7 @@ function createSimpleField({ parent, migrationValue }, field) {
|
|
|
5794
5804
|
}
|
|
5795
5805
|
/** Only the attributes that change are sent. A rename is `newApiId`. */
|
|
5796
5806
|
function updateSimpleField(change) {
|
|
5797
|
-
const { apiId, formRenderer, displayName, description, required, unique, localized, title, visibility, visibilityCondition, initialValue, position, validations, slug, embeds, actions } = change.changes;
|
|
5807
|
+
const { apiId, formRenderer, displayName, description, required, unique, localized, title, visibility, visibilityCondition, variantEnabled, initialValue, position, validations, slug, embeds, actions } = change.changes;
|
|
5798
5808
|
const input = {
|
|
5799
5809
|
apiId: change.apiId,
|
|
5800
5810
|
parentApiId: change.parent
|
|
@@ -5812,6 +5822,7 @@ function updateSimpleField(change) {
|
|
|
5812
5822
|
if (title) input.isTitle = title.to;
|
|
5813
5823
|
if (visibility) input.visibility = visibility.to;
|
|
5814
5824
|
if (visibilityCondition) input.visibilityCondition = visibilityCondition.to;
|
|
5825
|
+
if (variantEnabled) input.isVariantEnabled = variantEnabled.to;
|
|
5815
5826
|
if (initialValue) input.initialValue = jsonValue(initialValue.to);
|
|
5816
5827
|
if (position) input.position = position.to;
|
|
5817
5828
|
if (validations) input.validations = validations.to === null ? null : validationsInput(change.kind, validations.to);
|
|
@@ -5841,6 +5852,7 @@ function createEnumerableField({ parent, migrationValue }, field) {
|
|
|
5841
5852
|
isTitle: field.title,
|
|
5842
5853
|
visibility: field.visibility,
|
|
5843
5854
|
visibilityCondition: field.visibilityCondition,
|
|
5855
|
+
isVariantEnabled: field.variantEnabled,
|
|
5844
5856
|
initialValue: jsonValue(field.initialValue),
|
|
5845
5857
|
position: field.position
|
|
5846
5858
|
};
|
|
@@ -5853,7 +5865,7 @@ function createEnumerableField({ parent, migrationValue }, field) {
|
|
|
5853
5865
|
* creates the field instead.
|
|
5854
5866
|
*/
|
|
5855
5867
|
function updateEnumerableField(change) {
|
|
5856
|
-
const { apiId, displayName, description, required, unique, title, visibility, visibilityCondition, initialValue, position } = change.changes;
|
|
5868
|
+
const { apiId, displayName, description, required, unique, title, visibility, visibilityCondition, variantEnabled, initialValue, position } = change.changes;
|
|
5857
5869
|
const input = {
|
|
5858
5870
|
apiId: change.apiId,
|
|
5859
5871
|
parentApiId: change.parent
|
|
@@ -5866,6 +5878,7 @@ function updateEnumerableField(change) {
|
|
|
5866
5878
|
if (title) input.isTitle = title.to;
|
|
5867
5879
|
if (visibility) input.visibility = visibility.to;
|
|
5868
5880
|
if (visibilityCondition) input.visibilityCondition = visibilityCondition.to;
|
|
5881
|
+
if (variantEnabled) input.isVariantEnabled = variantEnabled.to;
|
|
5869
5882
|
if (initialValue) input.initialValue = jsonValue(initialValue.to);
|
|
5870
5883
|
if (position) input.position = position.to;
|
|
5871
5884
|
if (change.migrationValue !== void 0) input.migrationValue = enumerationMigrationValue(change.migrationValue);
|
|
@@ -5891,6 +5904,7 @@ function createTaxonomyField({ parent, migrationValue }, field) {
|
|
|
5891
5904
|
isUnique: field.unique,
|
|
5892
5905
|
visibility: field.visibility,
|
|
5893
5906
|
visibilityCondition: field.visibilityCondition,
|
|
5907
|
+
isVariantEnabled: field.variantEnabled,
|
|
5894
5908
|
initialValue: jsonValue(field.initialValue),
|
|
5895
5909
|
position: field.position
|
|
5896
5910
|
};
|
|
@@ -5903,7 +5917,7 @@ function createTaxonomyField({ parent, migrationValue }, field) {
|
|
|
5903
5917
|
* instead.
|
|
5904
5918
|
*/
|
|
5905
5919
|
function updateTaxonomyField(change) {
|
|
5906
|
-
const { apiId, displayName, description, required, unique, visibility, visibilityCondition, initialValue, position } = change.changes;
|
|
5920
|
+
const { apiId, displayName, description, required, unique, visibility, visibilityCondition, variantEnabled, initialValue, position } = change.changes;
|
|
5907
5921
|
const input = {
|
|
5908
5922
|
apiId: change.apiId,
|
|
5909
5923
|
parentApiId: change.parent
|
|
@@ -5915,6 +5929,7 @@ function updateTaxonomyField(change) {
|
|
|
5915
5929
|
if (unique) input.isUnique = unique.to;
|
|
5916
5930
|
if (visibility) input.visibility = visibility.to;
|
|
5917
5931
|
if (visibilityCondition) input.visibilityCondition = visibilityCondition.to;
|
|
5932
|
+
if (variantEnabled) input.isVariantEnabled = variantEnabled.to;
|
|
5918
5933
|
if (initialValue) input.initialValue = jsonValue(initialValue.to);
|
|
5919
5934
|
if (position) input.position = position.to;
|
|
5920
5935
|
if (change.migrationValue !== void 0) input.migrationValue = taxonomyMigrationValue(change.migrationValue);
|
|
@@ -5939,6 +5954,7 @@ function createComponentField({ parent }, field) {
|
|
|
5939
5954
|
isRequired: field.required,
|
|
5940
5955
|
visibility: field.visibility,
|
|
5941
5956
|
visibilityCondition: field.visibilityCondition,
|
|
5957
|
+
isVariantEnabled: field.variantEnabled,
|
|
5942
5958
|
position: field.position
|
|
5943
5959
|
};
|
|
5944
5960
|
}
|
|
@@ -5948,7 +5964,7 @@ function createComponentField({ parent }, field) {
|
|
|
5948
5964
|
* field instead.
|
|
5949
5965
|
*/
|
|
5950
5966
|
function updateComponentField(change) {
|
|
5951
|
-
const { apiId, displayName, description, required, visibility, visibilityCondition, position } = change.changes;
|
|
5967
|
+
const { apiId, displayName, description, required, visibility, visibilityCondition, variantEnabled, position } = change.changes;
|
|
5952
5968
|
const input = {
|
|
5953
5969
|
apiId: change.apiId,
|
|
5954
5970
|
parentApiId: change.parent
|
|
@@ -5959,6 +5975,7 @@ function updateComponentField(change) {
|
|
|
5959
5975
|
if (required) input.isRequired = required.to;
|
|
5960
5976
|
if (visibility) input.visibility = visibility.to;
|
|
5961
5977
|
if (visibilityCondition) input.visibilityCondition = visibilityCondition.to;
|
|
5978
|
+
if (variantEnabled) input.isVariantEnabled = variantEnabled.to;
|
|
5962
5979
|
if (position) input.position = position.to;
|
|
5963
5980
|
return input;
|
|
5964
5981
|
}
|
|
@@ -5973,6 +5990,7 @@ function createComponentUnionField({ parent }, field) {
|
|
|
5973
5990
|
isList: field.list,
|
|
5974
5991
|
visibility: field.visibility,
|
|
5975
5992
|
visibilityCondition: field.visibilityCondition,
|
|
5993
|
+
isVariantEnabled: field.variantEnabled,
|
|
5976
5994
|
position: field.position
|
|
5977
5995
|
};
|
|
5978
5996
|
}
|
|
@@ -5983,7 +6001,7 @@ function createComponentUnionField({ parent }, field) {
|
|
|
5983
6001
|
* instead.
|
|
5984
6002
|
*/
|
|
5985
6003
|
function updateComponentUnionField(change) {
|
|
5986
|
-
const { apiId, displayName, description, components, visibilityCondition, position } = change.changes;
|
|
6004
|
+
const { apiId, displayName, description, components, visibilityCondition, variantEnabled, position } = change.changes;
|
|
5987
6005
|
const input = {
|
|
5988
6006
|
apiId: change.apiId,
|
|
5989
6007
|
parentApiId: change.parent
|
|
@@ -5993,6 +6011,7 @@ function updateComponentUnionField(change) {
|
|
|
5993
6011
|
if (description) input.description = description.to;
|
|
5994
6012
|
if (components) input.componentApiIds = components.to;
|
|
5995
6013
|
if (visibilityCondition) input.visibilityCondition = visibilityCondition.to;
|
|
6014
|
+
if (variantEnabled) input.isVariantEnabled = variantEnabled.to;
|
|
5996
6015
|
if (position) input.position = position.to;
|
|
5997
6016
|
return input;
|
|
5998
6017
|
}
|
|
@@ -6025,6 +6044,7 @@ function createReferenceOneWayField({ parent }, field) {
|
|
|
6025
6044
|
isList: field.list,
|
|
6026
6045
|
visibility: field.visibility,
|
|
6027
6046
|
visibilityCondition: field.visibilityCondition,
|
|
6047
|
+
isVariantEnabled: field.variantEnabled,
|
|
6028
6048
|
relationalFieldRules: field.rules,
|
|
6029
6049
|
position: field.position,
|
|
6030
6050
|
reverseField: {
|
|
@@ -6054,6 +6074,7 @@ function createReferenceTwoWayField({ parent, partner }, field) {
|
|
|
6054
6074
|
isList: field.list,
|
|
6055
6075
|
visibility: field.visibility,
|
|
6056
6076
|
visibilityCondition: field.visibilityCondition,
|
|
6077
|
+
isVariantEnabled: field.variantEnabled,
|
|
6057
6078
|
relationalFieldRules: field.rules,
|
|
6058
6079
|
position: field.position,
|
|
6059
6080
|
reverseField: {
|
|
@@ -6088,6 +6109,7 @@ function createAssetField({ parent, partner }, field) {
|
|
|
6088
6109
|
isRequired: field.required,
|
|
6089
6110
|
visibility: field.visibility,
|
|
6090
6111
|
visibilityCondition: field.visibilityCondition,
|
|
6112
|
+
isVariantEnabled: field.variantEnabled,
|
|
6091
6113
|
position: field.position,
|
|
6092
6114
|
reverseField: partner === void 0 ? {
|
|
6093
6115
|
apiId: hidden,
|
|
@@ -6115,7 +6137,7 @@ function createAssetField({ parent, partner }, field) {
|
|
|
6115
6137
|
* diff deletes and creates the field instead.
|
|
6116
6138
|
*/
|
|
6117
6139
|
function updateRelationalField(change) {
|
|
6118
|
-
const { apiId, displayName, description, required, visibility, visibilityCondition, position, rules } = change.changes;
|
|
6140
|
+
const { apiId, displayName, description, required, visibility, visibilityCondition, variantEnabled, position, rules } = change.changes;
|
|
6119
6141
|
const input = {
|
|
6120
6142
|
apiId: change.apiId,
|
|
6121
6143
|
parentApiId: change.parent
|
|
@@ -6126,6 +6148,7 @@ function updateRelationalField(change) {
|
|
|
6126
6148
|
if (required) input.isRequired = required.to;
|
|
6127
6149
|
if (visibility) input.visibility = visibility.to;
|
|
6128
6150
|
if (visibilityCondition) input.visibilityCondition = visibilityCondition.to;
|
|
6151
|
+
if (variantEnabled) input.isVariantEnabled = variantEnabled.to;
|
|
6129
6152
|
if (position) input.position = position.to;
|
|
6130
6153
|
if (rules) input.relationalFieldRules = rules.to;
|
|
6131
6154
|
return input;
|
|
@@ -6157,6 +6180,7 @@ function createUnionField({ parent, members = [], memberName }, field) {
|
|
|
6157
6180
|
isList: field.list,
|
|
6158
6181
|
visibility: field.visibility,
|
|
6159
6182
|
visibilityCondition: field.visibilityCondition,
|
|
6183
|
+
isVariantEnabled: field.variantEnabled,
|
|
6160
6184
|
relationalFieldRules: field.rules,
|
|
6161
6185
|
position: field.position,
|
|
6162
6186
|
reverseField: first === void 0 ? { modelApiIds: field.to } : {
|
|
@@ -6180,7 +6204,7 @@ function createUnionField({ parent, members = [], memberName }, field) {
|
|
|
6180
6204
|
* member's field only, a rename included.
|
|
6181
6205
|
*/
|
|
6182
6206
|
function updateUnionField(change) {
|
|
6183
|
-
const { apiId, displayName, description, visibility, visibilityCondition, position, rules, to } = change.changes;
|
|
6207
|
+
const { apiId, displayName, description, visibility, visibilityCondition, variantEnabled, position, rules, to } = change.changes;
|
|
6184
6208
|
const input = {
|
|
6185
6209
|
apiId: change.apiId,
|
|
6186
6210
|
parentApiId: change.parent
|
|
@@ -6190,6 +6214,7 @@ function updateUnionField(change) {
|
|
|
6190
6214
|
if (description) input.description = description.to;
|
|
6191
6215
|
if (visibility) input.visibility = visibility.to;
|
|
6192
6216
|
if (visibilityCondition) input.visibilityCondition = visibilityCondition.to;
|
|
6217
|
+
if (variantEnabled) input.isVariantEnabled = variantEnabled.to;
|
|
6193
6218
|
if (position) input.position = position.to;
|
|
6194
6219
|
if (rules) input.relationalFieldRules = rules.to;
|
|
6195
6220
|
if (to) input.reverseField = {
|
|
@@ -6814,7 +6839,12 @@ function renderFieldChange(change, width, colors) {
|
|
|
6814
6839
|
case "update": {
|
|
6815
6840
|
if (unsupportedFieldMove(change)) return [` ${colors.yellow(`~ ${op}`)} ${subject} ${colors.dim(change.type)}`, ...renderAttributes(change.changes, colors)];
|
|
6816
6841
|
const { apiId, headers, args, ...attributes } = change.changes;
|
|
6817
|
-
const warning =
|
|
6842
|
+
const warning = [
|
|
6843
|
+
dropsUnionMember(change) && "deletes the content of the members it drops",
|
|
6844
|
+
dropsEmbed(change) && "deletes the embeds of the models it drops",
|
|
6845
|
+
dropsVariants(change) && "deletes the field's variant values",
|
|
6846
|
+
makesAssetRequired(change) && "API creates must set it; entries without an asset may fail to read"
|
|
6847
|
+
].filter((text) => text !== false).map((text) => ` ${colors.yellow(`⚠ ${text}`)}`).join("");
|
|
6818
6848
|
const rows = Object.entries(attributes).flatMap(([attribute, each]) => each === void 0 ? [] : [changeRow(attribute, each)]);
|
|
6819
6849
|
if (headers) rows.push(keyedChanges("headers", headerEntries(headers.from), headerEntries(headers.to)));
|
|
6820
6850
|
if (args) rows.push(keyedChanges("args", args.from.map((arg) => [arg.apiId, JSON.stringify(arg)]), args.to.map((arg) => [arg.apiId, JSON.stringify(arg)])));
|
|
@@ -12855,6 +12885,7 @@ const colorFieldSchema = strictObject({
|
|
|
12855
12885
|
title: literal(false),
|
|
12856
12886
|
visibility: fieldVisibilitySchema,
|
|
12857
12887
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
12888
|
+
variantEnabled: boolean(),
|
|
12858
12889
|
initialValue: colorValueSchema,
|
|
12859
12890
|
migrationValue: colorValueSchema,
|
|
12860
12891
|
renamedFrom: string$1().nullable()
|
|
@@ -12879,6 +12910,7 @@ const locationFieldSchema = strictObject({
|
|
|
12879
12910
|
title: literal(false),
|
|
12880
12911
|
visibility: fieldVisibilitySchema,
|
|
12881
12912
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
12913
|
+
variantEnabled: boolean(),
|
|
12882
12914
|
initialValue: locationValueSchema,
|
|
12883
12915
|
migrationValue: locationValueSchema,
|
|
12884
12916
|
renamedFrom: string$1().nullable()
|
|
@@ -12900,6 +12932,7 @@ const richTextFieldSchema = strictObject({
|
|
|
12900
12932
|
title: literal(false),
|
|
12901
12933
|
visibility: fieldVisibilitySchema,
|
|
12902
12934
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
12935
|
+
variantEnabled: boolean(),
|
|
12903
12936
|
initialValue: richTextValuesSchema,
|
|
12904
12937
|
migrationValue: richTextValuesSchema,
|
|
12905
12938
|
embeds: array(custom((value) => typeof value === "function")).nullable(),
|
|
@@ -13280,7 +13313,8 @@ const fieldAttributes = {
|
|
|
13280
13313
|
list: boolean(),
|
|
13281
13314
|
required: boolean(),
|
|
13282
13315
|
visibility: fieldVisibilitySchema,
|
|
13283
|
-
visibilityCondition: visibilityConditionSchema.nullable()
|
|
13316
|
+
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
13317
|
+
variantEnabled: boolean()
|
|
13284
13318
|
};
|
|
13285
13319
|
const stringFormRendererSchema = _enum([
|
|
13286
13320
|
"GCMS_SINGLE_LINE",
|
|
@@ -13307,7 +13341,8 @@ const referenceUnionMemberFieldSchema$1 = strictObject({
|
|
|
13307
13341
|
kind: literal("referenceUnionMember"),
|
|
13308
13342
|
to: string$1(),
|
|
13309
13343
|
reverse: string$1(),
|
|
13310
|
-
required: literal(false)
|
|
13344
|
+
required: literal(false),
|
|
13345
|
+
variantEnabled: literal(false)
|
|
13311
13346
|
});
|
|
13312
13347
|
const remoteFieldArgSchema = strictObject({
|
|
13313
13348
|
apiId: string$1(),
|
|
@@ -13316,6 +13351,21 @@ const remoteFieldArgSchema = strictObject({
|
|
|
13316
13351
|
list: boolean()
|
|
13317
13352
|
});
|
|
13318
13353
|
const remoteFieldMethodSchema = _enum(["GET", "POST"]);
|
|
13354
|
+
const dateAttributes = {
|
|
13355
|
+
...fieldAttributes,
|
|
13356
|
+
unique: boolean(),
|
|
13357
|
+
localized: boolean(),
|
|
13358
|
+
title: boolean(),
|
|
13359
|
+
initialValue: union([string$1(), array(string$1())]).nullable()
|
|
13360
|
+
};
|
|
13361
|
+
const numberAttributes = {
|
|
13362
|
+
...fieldAttributes,
|
|
13363
|
+
unique: boolean(),
|
|
13364
|
+
localized: boolean(),
|
|
13365
|
+
title: boolean(),
|
|
13366
|
+
initialValue: union([number(), array(number())]).nullable(),
|
|
13367
|
+
validations: numberValidationRulesSchema.nullable()
|
|
13368
|
+
};
|
|
13319
13369
|
const fieldSchema$1 = discriminatedUnion("kind", [
|
|
13320
13370
|
strictObject({
|
|
13321
13371
|
...fieldAttributes,
|
|
@@ -13337,12 +13387,12 @@ const fieldSchema$1 = discriminatedUnion("kind", [
|
|
|
13337
13387
|
slug: slugSettingsSchema.nullable()
|
|
13338
13388
|
}),
|
|
13339
13389
|
strictObject({
|
|
13340
|
-
...
|
|
13341
|
-
kind:
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
|
|
13345
|
-
|
|
13390
|
+
...dateAttributes,
|
|
13391
|
+
kind: literal("date")
|
|
13392
|
+
}),
|
|
13393
|
+
strictObject({
|
|
13394
|
+
...dateAttributes,
|
|
13395
|
+
kind: literal("dateTime")
|
|
13346
13396
|
}),
|
|
13347
13397
|
strictObject({
|
|
13348
13398
|
...fieldAttributes,
|
|
@@ -13361,13 +13411,12 @@ const fieldSchema$1 = discriminatedUnion("kind", [
|
|
|
13361
13411
|
initialValue: union([string$1(), array(string$1())]).nullable()
|
|
13362
13412
|
}),
|
|
13363
13413
|
strictObject({
|
|
13364
|
-
...
|
|
13365
|
-
kind:
|
|
13366
|
-
|
|
13367
|
-
|
|
13368
|
-
|
|
13369
|
-
|
|
13370
|
-
validations: numberValidationRulesSchema.nullable()
|
|
13414
|
+
...numberAttributes,
|
|
13415
|
+
kind: literal("int")
|
|
13416
|
+
}),
|
|
13417
|
+
strictObject({
|
|
13418
|
+
...numberAttributes,
|
|
13419
|
+
kind: literal("float")
|
|
13371
13420
|
}),
|
|
13372
13421
|
strictObject({
|
|
13373
13422
|
...fieldAttributes,
|
|
@@ -13449,7 +13498,8 @@ const fieldSchema$1 = discriminatedUnion("kind", [
|
|
|
13449
13498
|
forwardClientHeaders: boolean(),
|
|
13450
13499
|
cacheTTLSeconds: number(),
|
|
13451
13500
|
args: array(remoteFieldArgSchema),
|
|
13452
|
-
visibilityCondition: _null()
|
|
13501
|
+
visibilityCondition: _null(),
|
|
13502
|
+
variantEnabled: literal(false)
|
|
13453
13503
|
})
|
|
13454
13504
|
]);
|
|
13455
13505
|
const fieldRefSchema = strictObject({
|
|
@@ -13518,6 +13568,7 @@ const changeSchema = discriminatedUnion("resource", [
|
|
|
13518
13568
|
title: attributeChangeSchema(boolean()),
|
|
13519
13569
|
visibility: attributeChangeSchema(fieldVisibilitySchema),
|
|
13520
13570
|
visibilityCondition: attributeChangeSchema(visibilityConditionSchema.nullable()),
|
|
13571
|
+
variantEnabled: attributeChangeSchema(boolean()),
|
|
13521
13572
|
initialValue: attributeChangeSchema(initialValueSchema),
|
|
13522
13573
|
position: attributeChangeSchema(number()),
|
|
13523
13574
|
validations: attributeChangeSchema(union([stringValidationRulesSchema$1, numberValidationRulesSchema]).nullable()),
|
|
@@ -13729,6 +13780,7 @@ const simpleFieldShape = {
|
|
|
13729
13780
|
isUnique: boolean().nullish(),
|
|
13730
13781
|
isLocalized: boolean().nullish(),
|
|
13731
13782
|
isTitle: boolean().nullish(),
|
|
13783
|
+
isVariantEnabled: boolean().nullish(),
|
|
13732
13784
|
visibility: fieldVisibilitySchema.nullish(),
|
|
13733
13785
|
initialValue: string$1().nullish(),
|
|
13734
13786
|
position: number(),
|
|
@@ -13744,6 +13796,7 @@ const createReferenceFieldSchema = object$1({
|
|
|
13744
13796
|
description: string$1().nullish(),
|
|
13745
13797
|
isList: boolean().nullish(),
|
|
13746
13798
|
isRequired: boolean().nullish(),
|
|
13799
|
+
isVariantEnabled: boolean().nullish(),
|
|
13747
13800
|
visibility: fieldVisibilitySchema.nullish(),
|
|
13748
13801
|
position: number(),
|
|
13749
13802
|
visibilityCondition: liveVisibilityConditionSchema.nullish(),
|
|
@@ -13762,6 +13815,7 @@ const createReferenceTwoWayFieldSchema = object$1({
|
|
|
13762
13815
|
description: string$1().nullish(),
|
|
13763
13816
|
isList: boolean().nullish(),
|
|
13764
13817
|
isRequired: boolean().nullish(),
|
|
13818
|
+
isVariantEnabled: boolean().nullish(),
|
|
13765
13819
|
visibility: fieldVisibilitySchema.nullish(),
|
|
13766
13820
|
position: number(),
|
|
13767
13821
|
visibilityCondition: liveVisibilityConditionSchema.nullish(),
|
|
@@ -13881,6 +13935,7 @@ function convertCreateAssetFieldToIR(input, components) {
|
|
|
13881
13935
|
required: field.isRequired ?? false,
|
|
13882
13936
|
visibility: field.visibility ?? "READ_WRITE",
|
|
13883
13937
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
13938
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
13884
13939
|
...!oneWay && { reverse: field.reverseField.apiId }
|
|
13885
13940
|
}
|
|
13886
13941
|
};
|
|
@@ -13900,7 +13955,8 @@ function convertCreateAssetFieldToIR(input, components) {
|
|
|
13900
13955
|
list: back.isList ?? true,
|
|
13901
13956
|
required: false,
|
|
13902
13957
|
visibility: back.visibility ?? "READ_WRITE",
|
|
13903
|
-
visibilityCondition: null
|
|
13958
|
+
visibilityCondition: null,
|
|
13959
|
+
variantEnabled: false
|
|
13904
13960
|
}
|
|
13905
13961
|
}];
|
|
13906
13962
|
}
|
|
@@ -13937,6 +13993,7 @@ function convertCreateBooleanFieldToIR(input) {
|
|
|
13937
13993
|
title: field.isTitle ?? false,
|
|
13938
13994
|
visibility: field.visibility ?? "READ_WRITE",
|
|
13939
13995
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
13996
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
13940
13997
|
initialValue: parseValue({
|
|
13941
13998
|
apiId: field.apiId,
|
|
13942
13999
|
list
|
|
@@ -13981,6 +14038,7 @@ function convertCreateColorFieldToIR(input) {
|
|
|
13981
14038
|
title: false,
|
|
13982
14039
|
visibility: field.visibility ?? "READ_WRITE",
|
|
13983
14040
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14041
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
13984
14042
|
initialValue: parseValue({
|
|
13985
14043
|
apiId: field.apiId,
|
|
13986
14044
|
list
|
|
@@ -14023,6 +14081,7 @@ const baseShape = {
|
|
|
14023
14081
|
displayName: string$1(),
|
|
14024
14082
|
description: string$1().nullish(),
|
|
14025
14083
|
isList: boolean().nullish(),
|
|
14084
|
+
isVariantEnabled: boolean().nullish(),
|
|
14026
14085
|
visibility: fieldVisibilitySchema.nullish(),
|
|
14027
14086
|
position: number(),
|
|
14028
14087
|
visibilityCondition: liveVisibilityConditionSchema.nullish()
|
|
@@ -14076,7 +14135,8 @@ function attributes$3(field) {
|
|
|
14076
14135
|
position: field.position,
|
|
14077
14136
|
list: field.isList ?? false,
|
|
14078
14137
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14079
|
-
visibilityCondition: convertVisibilityCondition(field.visibilityCondition)
|
|
14138
|
+
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14139
|
+
variantEnabled: field.isVariantEnabled ?? false
|
|
14080
14140
|
};
|
|
14081
14141
|
}
|
|
14082
14142
|
//#endregion
|
|
@@ -14112,6 +14172,7 @@ function convertCreateDateFieldToIR(input) {
|
|
|
14112
14172
|
title: field.isTitle ?? false,
|
|
14113
14173
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14114
14174
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14175
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
14115
14176
|
initialValue: parseValue({
|
|
14116
14177
|
apiId: field.apiId,
|
|
14117
14178
|
list
|
|
@@ -14188,6 +14249,7 @@ function convertCreateEnumerableFieldToIR(input) {
|
|
|
14188
14249
|
title: field.isTitle ?? false,
|
|
14189
14250
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14190
14251
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14252
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
14191
14253
|
initialValue: parseValue({
|
|
14192
14254
|
apiId: field.apiId,
|
|
14193
14255
|
list
|
|
@@ -14232,6 +14294,7 @@ function convertCreateJsonFieldToIR(input) {
|
|
|
14232
14294
|
title: false,
|
|
14233
14295
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14234
14296
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14297
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
14235
14298
|
initialValue: parseValue({
|
|
14236
14299
|
apiId: field.apiId,
|
|
14237
14300
|
list
|
|
@@ -14276,6 +14339,7 @@ function convertCreateLocationFieldToIR(input) {
|
|
|
14276
14339
|
title: false,
|
|
14277
14340
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14278
14341
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14342
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
14279
14343
|
initialValue: parseValue({
|
|
14280
14344
|
apiId: field.apiId,
|
|
14281
14345
|
list
|
|
@@ -14352,6 +14416,7 @@ function convertCreateNumberFieldToIR(input) {
|
|
|
14352
14416
|
title: field.isTitle ?? false,
|
|
14353
14417
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14354
14418
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14419
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
14355
14420
|
initialValue: parseValue({
|
|
14356
14421
|
apiId: field.apiId,
|
|
14357
14422
|
list
|
|
@@ -14401,7 +14466,8 @@ function convertCreateReferenceOneWayFieldToIR(input, models) {
|
|
|
14401
14466
|
list: field.isList ?? false,
|
|
14402
14467
|
required: false,
|
|
14403
14468
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14404
|
-
visibilityCondition: convertVisibilityCondition(field.visibilityCondition)
|
|
14469
|
+
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14470
|
+
variantEnabled: field.isVariantEnabled ?? false
|
|
14405
14471
|
}
|
|
14406
14472
|
};
|
|
14407
14473
|
}
|
|
@@ -14437,7 +14503,8 @@ function convertCreateReferenceTwoWayFieldToIR(input, models, partners) {
|
|
|
14437
14503
|
list: field.isList ?? false,
|
|
14438
14504
|
required: false,
|
|
14439
14505
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14440
|
-
visibilityCondition: convertVisibilityCondition(field.visibilityCondition)
|
|
14506
|
+
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14507
|
+
variantEnabled: field.isVariantEnabled ?? false
|
|
14441
14508
|
}
|
|
14442
14509
|
}, {
|
|
14443
14510
|
parentApiId: reverse.modelApiId,
|
|
@@ -14453,7 +14520,8 @@ function convertCreateReferenceTwoWayFieldToIR(input, models, partners) {
|
|
|
14453
14520
|
list: reverse.isList ?? false,
|
|
14454
14521
|
required: false,
|
|
14455
14522
|
visibility: reverse.visibility ?? "READ_WRITE",
|
|
14456
|
-
visibilityCondition: convertVisibilityCondition(partner?.visibilityCondition)
|
|
14523
|
+
visibilityCondition: convertVisibilityCondition(partner?.visibilityCondition),
|
|
14524
|
+
variantEnabled: partner?.isVariantEnabled ?? false
|
|
14457
14525
|
}
|
|
14458
14526
|
}];
|
|
14459
14527
|
}
|
|
@@ -14516,6 +14584,7 @@ function convertCreateRemoteFieldToIR(input) {
|
|
|
14516
14584
|
required: field.isRequired ?? false,
|
|
14517
14585
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14518
14586
|
visibilityCondition: null,
|
|
14587
|
+
variantEnabled: false,
|
|
14519
14588
|
source: config.remoteSourcePrefix,
|
|
14520
14589
|
type: field.type,
|
|
14521
14590
|
returnType: config.returnTypeApiId,
|
|
@@ -14679,6 +14748,7 @@ function convertCreateRichTextFieldToIR(input, models) {
|
|
|
14679
14748
|
title: false,
|
|
14680
14749
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14681
14750
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14751
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
14682
14752
|
initialValue: isEmptyRichText(initialValue) ? null : initialValue,
|
|
14683
14753
|
embeds: field.embedsEnabled === true ? (field.embeddableModels ?? []).toSorted() : null,
|
|
14684
14754
|
actions: richTextActions(field.formConfig?.actions ?? null)
|
|
@@ -14781,6 +14851,7 @@ function convertCreateStringFieldToIR(input) {
|
|
|
14781
14851
|
title: field.isTitle ?? false,
|
|
14782
14852
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14783
14853
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14854
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
14784
14855
|
initialValue: parseValue({
|
|
14785
14856
|
apiId: field.apiId,
|
|
14786
14857
|
list
|
|
@@ -14896,6 +14967,7 @@ function convertCreateTaxonomyFieldToIR(input) {
|
|
|
14896
14967
|
unique: field.isUnique ?? false,
|
|
14897
14968
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14898
14969
|
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
14970
|
+
variantEnabled: field.isVariantEnabled ?? false,
|
|
14899
14971
|
initialValue: parseValue({
|
|
14900
14972
|
apiId: field.apiId,
|
|
14901
14973
|
list
|
|
@@ -14915,6 +14987,7 @@ const createReferenceUnionFieldSchema = object$1({
|
|
|
14915
14987
|
displayName: string$1(),
|
|
14916
14988
|
description: string$1().nullish(),
|
|
14917
14989
|
isList: boolean().nullish(),
|
|
14990
|
+
isVariantEnabled: boolean().nullish(),
|
|
14918
14991
|
visibility: fieldVisibilitySchema.nullish(),
|
|
14919
14992
|
position: number(),
|
|
14920
14993
|
visibilityCondition: liveVisibilityConditionSchema.nullish(),
|
|
@@ -14984,7 +15057,8 @@ function convertCreateReferenceUnionFieldToIR(input, models, components, lookup)
|
|
|
14984
15057
|
list: field.isList ?? false,
|
|
14985
15058
|
required: false,
|
|
14986
15059
|
visibility: field.visibility ?? "READ_WRITE",
|
|
14987
|
-
visibilityCondition: convertVisibilityCondition(field.visibilityCondition)
|
|
15060
|
+
visibilityCondition: convertVisibilityCondition(field.visibilityCondition),
|
|
15061
|
+
variantEnabled: field.isVariantEnabled ?? false
|
|
14988
15062
|
}
|
|
14989
15063
|
};
|
|
14990
15064
|
if (!onModel) return [owner];
|
|
@@ -15007,7 +15081,8 @@ function convertCreateReferenceUnionFieldToIR(input, models, components, lookup)
|
|
|
15007
15081
|
list: member.isList,
|
|
15008
15082
|
required: false,
|
|
15009
15083
|
visibility: member.visibility,
|
|
15010
|
-
visibilityCondition: convertVisibilityCondition(member.visibilityCondition)
|
|
15084
|
+
visibilityCondition: convertVisibilityCondition(member.visibilityCondition),
|
|
15085
|
+
variantEnabled: false
|
|
15011
15086
|
}
|
|
15012
15087
|
});
|
|
15013
15088
|
}
|
|
@@ -15200,9 +15275,11 @@ function parse$2(operation, schema, input) {
|
|
|
15200
15275
|
* reference there; the other side of any other relation on Asset is an
|
|
15201
15276
|
* unsupported field. Fields on QueryModel, remote fields only, go on
|
|
15202
15277
|
* `query` the same way, which is there and exported with no fields too.
|
|
15203
|
-
*
|
|
15204
|
-
*
|
|
15205
|
-
*
|
|
15278
|
+
* Fields on Segment go on `segment`, there only with fields: whether live
|
|
15279
|
+
* has Segment without them is `readLiveEnvironment`'s to say. Every other op,
|
|
15280
|
+
* `createLocale` and `createStage` included, and fields on anything but a
|
|
15281
|
+
* model, a component, Asset, QueryModel or Segment, are skipped until the
|
|
15282
|
+
* IR has a place for them. A two-way
|
|
15206
15283
|
* relation's other side takes its rules and condition from `partners`,
|
|
15207
15284
|
* which `schemaDefinition` leaves out, and a union's members
|
|
15208
15285
|
* their apiIds and settings from `unions`: `schemaDefinition` gives the
|
|
@@ -15230,7 +15307,12 @@ function convertSchemaDefinitionToIR(ops, partners = /* @__PURE__ */ new Map(),
|
|
|
15230
15307
|
apiId: "QueryModel",
|
|
15231
15308
|
fields: {}
|
|
15232
15309
|
};
|
|
15310
|
+
const segment = {
|
|
15311
|
+
apiId: "Segment",
|
|
15312
|
+
fields: {}
|
|
15313
|
+
};
|
|
15233
15314
|
const parents = new Map([
|
|
15315
|
+
[segment.apiId, segment],
|
|
15234
15316
|
...[...models, ...components].map((parent) => [parent.apiId, parent]),
|
|
15235
15317
|
[asset.apiId, asset],
|
|
15236
15318
|
[query.apiId, query]
|
|
@@ -15290,12 +15372,13 @@ function convertSchemaDefinitionToIR(ops, partners = /* @__PURE__ */ new Map(),
|
|
|
15290
15372
|
components: components.toSorted(byApiId$1),
|
|
15291
15373
|
models: models.toSorted(byApiId$1),
|
|
15292
15374
|
asset,
|
|
15293
|
-
query
|
|
15375
|
+
query,
|
|
15376
|
+
...Object.keys(segment.fields).length > 0 && { segment }
|
|
15294
15377
|
};
|
|
15295
15378
|
}
|
|
15296
15379
|
/**
|
|
15297
|
-
* Puts the field on its model, component, Asset or
|
|
15298
|
-
* anything else is skipped.
|
|
15380
|
+
* Puts the field on its model, component, Asset, QueryModel or Segment. A
|
|
15381
|
+
* field on anything else is skipped.
|
|
15299
15382
|
*/
|
|
15300
15383
|
function addField(parents, live) {
|
|
15301
15384
|
const parent = parents.get(live.parentApiId);
|
|
@@ -15389,7 +15472,7 @@ var LiveSchemaFailure = class extends Failure {};
|
|
|
15389
15472
|
* locales and stages come from the same request's `contentModel`, and a
|
|
15390
15473
|
* two-way relation's other side without its rules and condition, and a
|
|
15391
15474
|
* union's members with the first one's settings, so they come from its
|
|
15392
|
-
* `models`.
|
|
15475
|
+
* `models`. Whether Segment exists comes from its system models.
|
|
15393
15476
|
*/
|
|
15394
15477
|
async function readLiveEnvironment(target, fetch) {
|
|
15395
15478
|
if (isEmpty(target.token)) throw new LiveSchemaFailure(`target "${target.name}" has no token`);
|
|
@@ -15406,7 +15489,8 @@ async function readLiveEnvironment(target, fetch) {
|
|
|
15406
15489
|
}
|
|
15407
15490
|
const { environment } = extractProject(result.viewer, target);
|
|
15408
15491
|
const unions = unionLookup(environment.contentModel.models);
|
|
15409
|
-
const live = convertSchemaDefinitionToIR(environment.schemaDefinition, partnerLookup(environment.contentModel.models), unions);
|
|
15492
|
+
const { segment, ...live } = convertSchemaDefinitionToIR(environment.schemaDefinition, partnerLookup(environment.contentModel.models), unions);
|
|
15493
|
+
const hasSegment = environment.contentModel.systemModels.some((model) => model.__typename === "SegmentModel");
|
|
15410
15494
|
const components = new Set(environment.contentModel.components.map(({ apiId }) => apiId));
|
|
15411
15495
|
return {
|
|
15412
15496
|
environmentId: environment.id,
|
|
@@ -15416,6 +15500,10 @@ async function readLiveEnvironment(target, fetch) {
|
|
|
15416
15500
|
locales: convertLocalesToIR(environment.contentModel.locales),
|
|
15417
15501
|
stages: convertStagesToIR(environment.contentModel.stages),
|
|
15418
15502
|
...live,
|
|
15503
|
+
...hasSegment && { segment: segment ?? {
|
|
15504
|
+
apiId: "Segment",
|
|
15505
|
+
fields: {}
|
|
15506
|
+
} },
|
|
15419
15507
|
components: live.components.filter(({ apiId }) => components.has(apiId))
|
|
15420
15508
|
}
|
|
15421
15509
|
};
|
|
@@ -15424,7 +15512,8 @@ async function readLiveEnvironment(target, fetch) {
|
|
|
15424
15512
|
function partnerLookup(models) {
|
|
15425
15513
|
return new Map(models.flatMap((model) => model.fields.flatMap((field) => field.__typename === "RelationalField" ? [[`${model.apiId}.${field.apiId}`, {
|
|
15426
15514
|
relationalFieldRules: field.relationalFieldRules,
|
|
15427
|
-
visibilityCondition: liveCondition(field.visibilityCondition)
|
|
15515
|
+
visibilityCondition: liveCondition(field.visibilityCondition),
|
|
15516
|
+
isVariantEnabled: field.isVariantEnabled
|
|
15428
15517
|
}]] : [])));
|
|
15429
15518
|
}
|
|
15430
15519
|
/** Every union's id, and every union member's settings, by `Model.field`. */
|
|
@@ -15739,6 +15828,12 @@ const messages = {
|
|
|
15739
15828
|
["model.apiIdReserved"]: (apiId) => `"${apiId}" is the apiId of a model Hygraph provides.`,
|
|
15740
15829
|
["systemModel.duplicate"]: (call) => `${call} is listed more than once in models.`,
|
|
15741
15830
|
["systemModel.fieldRequired"]: (apiId, field) => `Field "${field}" on ${apiId} is required. Hygraph refuses a required field on a model it provides.`,
|
|
15831
|
+
["systemModel.fieldVariantEnabled"]: (apiId, field) => `Field "${field}" on ${apiId} has variants. Only fields of your models can have them.`,
|
|
15832
|
+
["systemModel.fieldApiIdTaken"]: (apiId, field) => `Field "${field}" on ${apiId} has the apiId of one of Hygraph's own fields on ${apiId}.`,
|
|
15833
|
+
["systemModel.fieldType"]: (apiId, field) => `Field "${field}" on ${apiId} is of a type ${apiId} does not take. It takes text, rich text, number, date, boolean, JSON, color, location, enumeration and taxonomy fields.`,
|
|
15834
|
+
["systemModel.segmentMissing"]: "Segment has fields, but Hygraph has no Segment yet and no field of your models has variants. Hygraph adds Segment with the first field that has variants.",
|
|
15835
|
+
["systemModel.segmentNotYet"]: "Segment is in models, but Hygraph has no Segment yet and no field of your models has variants. The plan leaves Segment alone until Hygraph adds it with the first field that has variants.",
|
|
15836
|
+
["systemModel.fieldLocalized"]: (apiId, field) => `Field "${field}" on ${apiId} is localized. Fields on ${apiId} have one value for every locale.`,
|
|
15742
15837
|
["systemModel.fieldUnion"]: (apiId, field) => `Field "${field}" on ${apiId} is a component union. Hygraph refuses one on a model it provides.`,
|
|
15743
15838
|
["systemModel.fieldReferenceTwoWay"]: (apiId, field) => `Field "${field}" on ${apiId} is a two-way reference. A two-way reference on ${apiId} is the field back of an asset field, which assetReverseField declares.`,
|
|
15744
15839
|
["systemModel.fieldNotRemote"]: (field) => `Field "${field}" on Query is not a remote field. Hygraph takes only remote fields on Query.`,
|
|
@@ -15875,6 +15970,11 @@ const messages = {
|
|
|
15875
15970
|
["field.referenceUnionMemberOnComponent"]: (field) => `Field "${field}" is a union member on a component. Only models have them.`,
|
|
15876
15971
|
["field.unionOwnerMissing"]: (field, owner) => `Field "${field}" names "${owner}" as its union, which is not a union reference listing this model with this field as its field back.`,
|
|
15877
15972
|
["field.requiredNotVisible"]: (field, visibility) => `Field "${field}" is required and ${visibility}, so editors cannot fill it in.`,
|
|
15973
|
+
["field.variantEnabledUnique"]: (field) => `Field "${field}" is unique and has variants. Hygraph refuses variants on a unique field.`,
|
|
15974
|
+
["field.variantEnabledOnComponent"]: (field, component) => `Field "${field}" on component "${component}" has variants. Only fields of a model can have them.`,
|
|
15975
|
+
["field.variantEnabledBaseField"]: (field, base) => `Field "${field}" has variants and a condition on "${base}", which has none. Hygraph needs the field a condition is on to have variants too.`,
|
|
15976
|
+
["field.variantComponentRequired"]: (model, field) => `Component field "${field}" on ${model} will be required and have variants. Hygraph does not copy the component into the variants existing entries have, so they start without it.`,
|
|
15977
|
+
["field.variantEnabledBothSides"]: (field, partner) => `Field "${field}" and its partner "${partner}" both have variants. Only one side of a two-way reference can have them.`,
|
|
15878
15978
|
["field.assetReverseInvalid"]: (field, reverse) => `Field "${field}" gets the field "${reverse}" on Asset, which is not a valid apiId.`,
|
|
15879
15979
|
["field.richTextEmbedsEmpty"]: (field) => `Field "${field}" has embeds, but names no model to embed.`,
|
|
15880
15980
|
["field.richTextEmbedDuplicate"]: (field, model) => `Field "${field}" lists model "${model}" more than once in embeds.`,
|
|
@@ -15884,8 +15984,8 @@ const messages = {
|
|
|
15884
15984
|
["field.richTextRequiredList"]: (field) => `Field "${field}" is a required list, which Hygraph refuses on rich text.`,
|
|
15885
15985
|
["field.assetReverseFieldMissing"]: (parent, field) => `Asset field "${field}" on ${parent} does not name its field back on Asset.`,
|
|
15886
15986
|
["field.assetReverseFieldOnComponent"]: (parent, field) => `Asset field "${field}" on component ${parent} names a field back. A component's field back is hidden, and the CLI names it.`,
|
|
15887
|
-
["field.assetSystemAssetMissing"]: (parent, field, back) => `Asset field "${field}" on ${parent} has its field back "${back}" on Asset, and models does not list system.asset.`,
|
|
15888
|
-
["field.assetFieldBackMissing"]: (parent, field, back) => `Asset field "${field}" on ${parent} names its field back "${back}", which system.asset does not list.`,
|
|
15987
|
+
["field.assetSystemAssetMissing"]: (parent, field, back) => `Asset field "${field}" on ${parent} has its field back "${back}" on Asset, and models does not list system.model.asset.`,
|
|
15988
|
+
["field.assetFieldBackMissing"]: (parent, field, back) => `Asset field "${field}" on ${parent} names its field back "${back}", which system.model.asset does not list.`,
|
|
15889
15989
|
["field.assetFieldBackPartner"]: (back, partner, problem) => `Field back "${back}" on Asset names ${partner}, which ${problem}.`,
|
|
15890
15990
|
["field.assetReverseFieldNotOnAsset"]: (parent, field) => `Field "${field}" on ${parent} is an assetReverseField. A field back is on Asset only.`,
|
|
15891
15991
|
["field.assetReverseFieldChanged"]: (parent, field, from, to) => `Asset field "${field}" on ${parent} has the field back "${from}" on Asset, and the config names "${to}".`,
|
|
@@ -15938,9 +16038,15 @@ const fixes = {
|
|
|
15938
16038
|
["model.invalidRenamedFrom"]: "Use the apiId the model has in Hygraph right now: an uppercase letter, then letters, digits and underscores only, up to 64 characters.",
|
|
15939
16039
|
["model.renamedFromMatchesApiId"]: "Set renamedFrom to the apiId the model has in Hygraph right now, or remove it.",
|
|
15940
16040
|
["model.noTitleField"]: "Set title: true on the field Studio should show entries by, such as a name or a heading.",
|
|
15941
|
-
["model.apiIdReserved"]: "Use another apiId. To add fields to Asset or
|
|
16041
|
+
["model.apiIdReserved"]: "Use another apiId. To add fields to Asset, Query or Segment, put system.model.asset({ fields }), system.model.query({ fields }) or system.model.segment({ fields }) in models.",
|
|
15942
16042
|
["systemModel.duplicate"]: "List it once, with all your fields on it.",
|
|
15943
16043
|
["systemModel.fieldRequired"]: "Set required: false.",
|
|
16044
|
+
["systemModel.fieldVariantEnabled"]: "Set variantEnabled: false.",
|
|
16045
|
+
["systemModel.fieldType"]: "Use one of the types it takes, or put the field on a model of yours.",
|
|
16046
|
+
["systemModel.fieldApiIdTaken"]: "Use another apiId. Hygraph's own fields are never listed in fields.",
|
|
16047
|
+
["systemModel.fieldLocalized"]: "Set localized: false.",
|
|
16048
|
+
["systemModel.segmentNotYet"]: "Set variantEnabled: true on a field of one of your models, or remove system.model.segment() from models until one has variants.",
|
|
16049
|
+
["systemModel.segmentMissing"]: "Set variantEnabled: true on a field of one of your models, or leave Segment's fields out until one has variants.",
|
|
15944
16050
|
["systemModel.fieldUnion"]: "Use a component field, or put the union on a model of yours.",
|
|
15945
16051
|
["systemModel.fieldReferenceTwoWay"]: "Use define.field.assetReverseField with the same apiId, displayName, to and reverse, and no list or rules.",
|
|
15946
16052
|
["systemModel.fieldNotRemote"]: "Use define.field.remote, or put the field on a model of yours.",
|
|
@@ -16077,6 +16183,11 @@ const fixes = {
|
|
|
16077
16183
|
["field.referenceUnionMemberOnComponent"]: "Move the union reference and its field back to models, or remove the field back.",
|
|
16078
16184
|
["field.unionOwnerMissing"]: "Add this model to the union's to and set its reverse to this field's apiId, or remove this field.",
|
|
16079
16185
|
["field.requiredNotVisible"]: "Set required: false, or make the field READ_WRITE or READ_ONLY.",
|
|
16186
|
+
["field.variantEnabledUnique"]: "Set unique: false or variantEnabled: false.",
|
|
16187
|
+
["field.variantEnabledOnComponent"]: "Set variantEnabled: false, or move the field to a model.",
|
|
16188
|
+
["field.variantEnabledBaseField"]: "Set variantEnabled: true on the field the condition is on, or variantEnabled: false on this one.",
|
|
16189
|
+
["field.variantEnabledBothSides"]: "Set variantEnabled: false on one of the two.",
|
|
16190
|
+
["field.variantComponentRequired"]: "Fill in the component in each existing variant after the apply.",
|
|
16080
16191
|
["field.assetReverseInvalid"]: "Use a valid field apiId, and keep it and its model's or component's apiId within 64 characters together: shorten either one if they are too long.",
|
|
16081
16192
|
["field.richTextEmbedsEmpty"]: "List at least one model in embeds, or remove embeds to turn them off.",
|
|
16082
16193
|
["field.richTextEmbedDuplicate"]: "List each model once in embeds.",
|
|
@@ -16084,13 +16195,13 @@ const fixes = {
|
|
|
16084
16195
|
["field.richTextEmbedComponent"]: "List only models in embeds. To hold a component, use define.field.component.",
|
|
16085
16196
|
["field.richTextUniqueEmbeds"]: "Remove unique, or remove embeds.",
|
|
16086
16197
|
["field.richTextRequiredList"]: "Remove required, or set list: false.",
|
|
16087
|
-
["field.assetReverseFieldMissing"]: (parent, field, back) => `Set reverse: "${back}" on the field, and add its field back to system.asset's fields: ${fieldBack(parent, field, back)}.`,
|
|
16198
|
+
["field.assetReverseFieldMissing"]: (parent, field, back) => `Set reverse: "${back}" on the field, and add its field back to system.model.asset's fields: ${fieldBack(parent, field, back)}.`,
|
|
16088
16199
|
["field.assetReverseFieldOnComponent"]: "Remove reverse.",
|
|
16089
|
-
["field.assetSystemAssetMissing"]: (parent, field, back) => `Add const Asset = system.asset({ fields: [${fieldBack(parent, field, back)}] }) to models.`,
|
|
16090
|
-
["field.assetFieldBackMissing"]: (parent, field, back) => `Add ${fieldBack(parent, field, back)} to system.asset's fields, at the end for a new field.`,
|
|
16200
|
+
["field.assetSystemAssetMissing"]: (parent, field, back) => `Add const Asset = system.model.asset({ fields: [${fieldBack(parent, field, back)}] }) to models.`,
|
|
16201
|
+
["field.assetFieldBackMissing"]: (parent, field, back) => `Add ${fieldBack(parent, field, back)} to system.model.asset's fields, at the end for a new field.`,
|
|
16091
16202
|
["field.assetFieldBackPartner"]: "Point it at the asset field that names it in reverse: to is that field's model, and reverse is its apiId.",
|
|
16092
|
-
["field.assetReverseFieldNotOnAsset"]: "Move it to system.asset's fields, or use define.field.referenceTwoWay on a model.",
|
|
16093
|
-
["field.assetReverseFieldChanged"]: (_parent, _field, from) => `To rename the field back, set renamedFrom: "${from}" on it in system.asset. Otherwise set reverse back to "${from}".`,
|
|
16203
|
+
["field.assetReverseFieldNotOnAsset"]: "Move it to system.model.asset's fields, or use define.field.referenceTwoWay on a model.",
|
|
16204
|
+
["field.assetReverseFieldChanged"]: (_parent, _field, from) => `To rename the field back, set renamedFrom: "${from}" on it in system.model.asset. Otherwise set reverse back to "${from}".`,
|
|
16094
16205
|
["change.modelMissing"]: "An earlier change deletes or renames it. Plan against the current environment, and rename a model from one place only.",
|
|
16095
16206
|
["change.embedsReplaced"]: "Create the new models in one apply. Then change embeds and delete the old models in the next.",
|
|
16096
16207
|
["change.componentMissing"]: "An earlier change deletes or renames it. Plan against the current environment, and rename a component from one place only.",
|
|
@@ -16553,6 +16664,7 @@ function validateReferenceModelReferences(parent, fields, models) {
|
|
|
16553
16664
|
* is this field. Hygraph makes both in one create, so a pair the config
|
|
16554
16665
|
* gives only half of, or two halves that disagree, has nothing to create.
|
|
16555
16666
|
* A `to` the environment does not have is `field.referenceModelMissing`.
|
|
16667
|
+
* Only one side of a pair can have variants.
|
|
16556
16668
|
*/
|
|
16557
16669
|
function validateReferenceTwoWayPartners(parent, fields, models) {
|
|
16558
16670
|
const validations = [];
|
|
@@ -16592,6 +16704,9 @@ function validateReferenceTwoWayPartners(parent, fields, models) {
|
|
|
16592
16704
|
if (partnerTarget !== `${parent.apiId}.${field.apiId}`) {
|
|
16593
16705
|
const code = "field.referencePartnerMismatch";
|
|
16594
16706
|
report(code, field.apiId, "reverse", messages[code](field.apiId, partnerName, partnerTarget));
|
|
16707
|
+
} else if (field.variantEnabled && partner.variantEnabled && `${parent.apiId}.${field.apiId}` < partnerName) {
|
|
16708
|
+
const code = "field.variantEnabledBothSides";
|
|
16709
|
+
report(code, field.apiId, "variantEnabled", messages[code](field.apiId, partnerName));
|
|
16595
16710
|
}
|
|
16596
16711
|
}
|
|
16597
16712
|
return validations;
|
|
@@ -17451,7 +17566,8 @@ function validateTypeOptions(parent, field) {
|
|
|
17451
17566
|
/**
|
|
17452
17567
|
* A condition's base must be another field of the same model that holds one
|
|
17453
17568
|
* value, and Studio does not let a required, a hidden or an API-only field
|
|
17454
|
-
* have one. The server checks none of this; Studio's form does.
|
|
17569
|
+
* have one. The server checks none of this; Studio's form does. A field
|
|
17570
|
+
* with variants needs a base with variants, which the server checks.
|
|
17455
17571
|
*/
|
|
17456
17572
|
function validateConditions(parent, fields) {
|
|
17457
17573
|
const byApiId = new Map(fields.map((field) => [field.apiId, field]));
|
|
@@ -17491,6 +17607,13 @@ function validateConditions(parent, fields) {
|
|
|
17491
17607
|
fix: fixes["field.conditionBaseList"]
|
|
17492
17608
|
});
|
|
17493
17609
|
else validations.push(...validateConditionValue(parent, field, base));
|
|
17610
|
+
if (field.variantEnabled && isConditionBase(base) && !base.variantEnabled) validations.push({
|
|
17611
|
+
code: "field.variantEnabledBaseField",
|
|
17612
|
+
severity: "error",
|
|
17613
|
+
path: fieldPath(parent, field.apiId, "variantEnabled"),
|
|
17614
|
+
message: messages["field.variantEnabledBaseField"](field.apiId, condition.baseField),
|
|
17615
|
+
fix: fixes["field.variantEnabledBaseField"]
|
|
17616
|
+
});
|
|
17494
17617
|
if (field.visibility === "HIDDEN" || field.visibility === "API_ONLY") validations.push({
|
|
17495
17618
|
code: "field.conditionNotVisible",
|
|
17496
17619
|
severity: "error",
|
|
@@ -17548,6 +17671,8 @@ function validateOptions(parent, field) {
|
|
|
17548
17671
|
});
|
|
17549
17672
|
};
|
|
17550
17673
|
if (field.required && (field.visibility === "HIDDEN" || field.visibility === "API_ONLY")) report("field.requiredNotVisible", "required", messages["field.requiredNotVisible"](field.apiId, field.visibility));
|
|
17674
|
+
if (field.variantEnabled && "unique" in field && field.unique) report("field.variantEnabledUnique", "variantEnabled", messages["field.variantEnabledUnique"](field.apiId));
|
|
17675
|
+
if (field.variantEnabled && parent.kind === "component") report("field.variantEnabledOnComponent", "variantEnabled", messages["field.variantEnabledOnComponent"](field.apiId, parent.apiId));
|
|
17551
17676
|
const title = "title" in field && field.title;
|
|
17552
17677
|
if (title && field.list) report("field.titleOnList", "title", messages["field.titleOnList"](field.apiId));
|
|
17553
17678
|
if (title && (field.visibility === "HIDDEN" || field.visibility === "API_ONLY")) report("field.titleNotVisible", "title", messages["field.titleNotVisible"](field.apiId, field.visibility));
|
|
@@ -17567,9 +17692,10 @@ function validateOptions(parent, field) {
|
|
|
17567
17692
|
/**
|
|
17568
17693
|
* What Asset can tell about itself: its fields, as a model's are checked,
|
|
17569
17694
|
* and what Hygraph refuses on a model it provides. A required field and a
|
|
17570
|
-
* component union fail the whole migration.
|
|
17571
|
-
*
|
|
17572
|
-
*
|
|
17695
|
+
* component union fail the whole migration. Studio does not let a field
|
|
17696
|
+
* on Asset have variants. A two-way reference on Asset is a field back,
|
|
17697
|
+
* which `assetReverseField` declares. There is no title check: Studio
|
|
17698
|
+
* shows assets by their file.
|
|
17573
17699
|
*/
|
|
17574
17700
|
function validateSystemAsset(asset) {
|
|
17575
17701
|
const parent = {
|
|
@@ -17577,33 +17703,45 @@ function validateSystemAsset(asset) {
|
|
|
17577
17703
|
apiId: asset.apiId
|
|
17578
17704
|
};
|
|
17579
17705
|
const validations = validateFields(parent, asset.fields);
|
|
17580
|
-
for (const field of asset.fields)
|
|
17581
|
-
|
|
17582
|
-
|
|
17583
|
-
|
|
17584
|
-
|
|
17585
|
-
|
|
17586
|
-
|
|
17587
|
-
|
|
17588
|
-
|
|
17589
|
-
|
|
17590
|
-
|
|
17591
|
-
|
|
17592
|
-
|
|
17593
|
-
|
|
17594
|
-
|
|
17595
|
-
|
|
17596
|
-
|
|
17597
|
-
|
|
17598
|
-
|
|
17599
|
-
|
|
17600
|
-
|
|
17601
|
-
|
|
17602
|
-
|
|
17603
|
-
|
|
17604
|
-
|
|
17605
|
-
|
|
17606
|
-
|
|
17706
|
+
for (const field of asset.fields) {
|
|
17707
|
+
if (field.__typename === "ComponentUnionField") {
|
|
17708
|
+
const code = "systemModel.fieldUnion";
|
|
17709
|
+
validations.push({
|
|
17710
|
+
code,
|
|
17711
|
+
severity: "error",
|
|
17712
|
+
path: fieldPath(parent, field.apiId, "components"),
|
|
17713
|
+
message: messages[code](asset.apiId, field.apiId),
|
|
17714
|
+
fix: fixes[code]
|
|
17715
|
+
});
|
|
17716
|
+
} else if (field.__typename === "ReferenceTwoWayField") {
|
|
17717
|
+
const code = "systemModel.fieldReferenceTwoWay";
|
|
17718
|
+
validations.push({
|
|
17719
|
+
code,
|
|
17720
|
+
severity: "error",
|
|
17721
|
+
path: fieldPath(parent, field.apiId, "to"),
|
|
17722
|
+
message: messages[code](asset.apiId, field.apiId),
|
|
17723
|
+
fix: fixes[code]
|
|
17724
|
+
});
|
|
17725
|
+
} else if (field.__typename !== "UnsupportedField" && field.required) {
|
|
17726
|
+
const code = "systemModel.fieldRequired";
|
|
17727
|
+
validations.push({
|
|
17728
|
+
code,
|
|
17729
|
+
severity: "error",
|
|
17730
|
+
path: fieldPath(parent, field.apiId, "required"),
|
|
17731
|
+
message: messages[code](asset.apiId, field.apiId),
|
|
17732
|
+
fix: fixes[code]
|
|
17733
|
+
});
|
|
17734
|
+
}
|
|
17735
|
+
if (field.__typename !== "UnsupportedField" && field.variantEnabled) {
|
|
17736
|
+
const code = "systemModel.fieldVariantEnabled";
|
|
17737
|
+
validations.push({
|
|
17738
|
+
code,
|
|
17739
|
+
severity: "error",
|
|
17740
|
+
path: fieldPath(parent, field.apiId, "variantEnabled"),
|
|
17741
|
+
message: messages[code](asset.apiId, field.apiId),
|
|
17742
|
+
fix: fixes[code]
|
|
17743
|
+
});
|
|
17744
|
+
}
|
|
17607
17745
|
}
|
|
17608
17746
|
return validations;
|
|
17609
17747
|
}
|
|
@@ -17637,6 +17775,66 @@ function validateSystemQuery(query) {
|
|
|
17637
17775
|
return validations;
|
|
17638
17776
|
}
|
|
17639
17777
|
//#endregion
|
|
17778
|
+
//#region src/define/system/segment.validation.ts
|
|
17779
|
+
/**
|
|
17780
|
+
* The field types Segment takes. Keyed by `SegmentModelField`'s, so the
|
|
17781
|
+
* compiler refuses a type missing here or one it does not take.
|
|
17782
|
+
*/
|
|
17783
|
+
const SEGMENT_FIELD_TYPES = {
|
|
17784
|
+
BooleanField: true,
|
|
17785
|
+
SingleLineField: true,
|
|
17786
|
+
MultilineField: true,
|
|
17787
|
+
MarkdownField: true,
|
|
17788
|
+
SlugField: true,
|
|
17789
|
+
RichTextField: true,
|
|
17790
|
+
IntField: true,
|
|
17791
|
+
FloatField: true,
|
|
17792
|
+
DateField: true,
|
|
17793
|
+
DateTimeField: true,
|
|
17794
|
+
JsonField: true,
|
|
17795
|
+
ColorField: true,
|
|
17796
|
+
LocationField: true,
|
|
17797
|
+
EnumerationField: true,
|
|
17798
|
+
TaxonomyField: true,
|
|
17799
|
+
UnsupportedField: true
|
|
17800
|
+
};
|
|
17801
|
+
/** Hygraph's own fields on Segment, which yours cannot take the apiIds of. */
|
|
17802
|
+
const SEGMENT_OWN_FIELDS = /* @__PURE__ */ new Set(["name", "description"]);
|
|
17803
|
+
/**
|
|
17804
|
+
* What Segment can tell about itself: its fields, as a model's are
|
|
17805
|
+
* checked, and what Hygraph refuses on it. The server refuses a union and
|
|
17806
|
+
* a required field but for a taxonomy field, which this refuses too;
|
|
17807
|
+
* Studio offers no other type, a localized field or variants. There is no title check: Hygraph's name field is the title.
|
|
17808
|
+
*/
|
|
17809
|
+
function validateSystemSegment(segment) {
|
|
17810
|
+
const parent = {
|
|
17811
|
+
kind: "model",
|
|
17812
|
+
apiId: segment.apiId
|
|
17813
|
+
};
|
|
17814
|
+
const validations = validateFields(parent, segment.fields);
|
|
17815
|
+
const report = (code, field, attribute) => {
|
|
17816
|
+
validations.push({
|
|
17817
|
+
code,
|
|
17818
|
+
severity: "error",
|
|
17819
|
+
path: fieldPath(parent, field.apiId, attribute),
|
|
17820
|
+
message: messages[code](segment.apiId, field.apiId),
|
|
17821
|
+
fix: fixes[code]
|
|
17822
|
+
});
|
|
17823
|
+
};
|
|
17824
|
+
for (const field of segment.fields) {
|
|
17825
|
+
if (SEGMENT_OWN_FIELDS.has(field.apiId)) report("systemModel.fieldApiIdTaken", field, "apiId");
|
|
17826
|
+
if (!Object.hasOwn(SEGMENT_FIELD_TYPES, field.__typename)) {
|
|
17827
|
+
report("systemModel.fieldType", field, "apiId");
|
|
17828
|
+
continue;
|
|
17829
|
+
}
|
|
17830
|
+
if (field.__typename === "UnsupportedField") continue;
|
|
17831
|
+
if (field.required) report("systemModel.fieldRequired", field, "required");
|
|
17832
|
+
if ("localized" in field && field.localized) report("systemModel.fieldLocalized", field, "localized");
|
|
17833
|
+
if (field.variantEnabled) report("systemModel.fieldVariantEnabled", field, "variantEnabled");
|
|
17834
|
+
}
|
|
17835
|
+
return validations;
|
|
17836
|
+
}
|
|
17837
|
+
//#endregion
|
|
17640
17838
|
//#region src/define/resources/component.validation.ts
|
|
17641
17839
|
/**
|
|
17642
17840
|
* What a component can tell about itself, its fields included. Whether its
|
|
@@ -18188,8 +18386,9 @@ function nodePath(taxonomy, node) {
|
|
|
18188
18386
|
//#region src/define/resources/environment.validation.ts
|
|
18189
18387
|
/** The call that lists each model Hygraph provides, as the config writes it. */
|
|
18190
18388
|
const SYSTEM_MODEL_CALLS = {
|
|
18191
|
-
SystemAsset: "system.asset()",
|
|
18192
|
-
SystemQuery: "system.query()"
|
|
18389
|
+
SystemAsset: "system.model.asset()",
|
|
18390
|
+
SystemQuery: "system.model.query()",
|
|
18391
|
+
SystemSegment: "system.model.segment()"
|
|
18193
18392
|
};
|
|
18194
18393
|
/**
|
|
18195
18394
|
* What only the whole environment can tell: whether two resources collide,
|
|
@@ -18199,10 +18398,11 @@ const SYSTEM_MODEL_CALLS = {
|
|
|
18199
18398
|
* by prefix. Models, components, enumerations and
|
|
18200
18399
|
* taxonomies share one apiId namespace; locales and stages each have their
|
|
18201
18400
|
* own. Display names are unique per kind. `Asset`, `QueryModel` and
|
|
18202
|
-
* `Query` are Hygraph's: a model of yours cannot take any of them
|
|
18203
|
-
*
|
|
18401
|
+
* `Query` are Hygraph's: a model of yours cannot take any of them. Nor
|
|
18402
|
+
* can it take `Segment` once Hygraph needs its own: when `system.model.segment`
|
|
18403
|
+
* is listed or a field has variants. Each `system.*` model is listed once. An asset field
|
|
18204
18404
|
* on a model or on Asset names its field back on Asset, which
|
|
18205
|
-
* `system.asset` lists as an `assetReverseField`.
|
|
18405
|
+
* `system.model.asset` lists as an `assetReverseField`.
|
|
18206
18406
|
*
|
|
18207
18407
|
* Runs over the models as declared, before conversion, so every report
|
|
18208
18408
|
* points at the config the user wrote.
|
|
@@ -18215,7 +18415,7 @@ function validateEnvironment(environment) {
|
|
|
18215
18415
|
validations.push(...validateStages(environment.stages));
|
|
18216
18416
|
const systemApiIds = /* @__PURE__ */ new Set();
|
|
18217
18417
|
for (const model of environment.systemModels) {
|
|
18218
|
-
validations.push(...
|
|
18418
|
+
validations.push(...validateSystemModel(model));
|
|
18219
18419
|
if (systemApiIds.has(model.apiId)) {
|
|
18220
18420
|
const code = "systemModel.duplicate";
|
|
18221
18421
|
validations.push({
|
|
@@ -18228,13 +18428,14 @@ function validateEnvironment(environment) {
|
|
|
18228
18428
|
}
|
|
18229
18429
|
systemApiIds.add(model.apiId);
|
|
18230
18430
|
}
|
|
18431
|
+
const needsSegment = environment.systemModels.some((model) => model.__typename === "SystemSegment") || environment.models.some((model) => model.fields.some((field) => field.__typename !== "UnsupportedField" && field.variantEnabled));
|
|
18231
18432
|
for (const model of environment.models) {
|
|
18232
18433
|
validations.push(...validateModel(model));
|
|
18233
18434
|
if ([
|
|
18234
18435
|
"Asset",
|
|
18235
18436
|
"QueryModel",
|
|
18236
18437
|
"Query"
|
|
18237
|
-
].includes(model.apiId)) {
|
|
18438
|
+
].includes(model.apiId) || model.apiId === "Segment" && needsSegment) {
|
|
18238
18439
|
const code = "model.apiIdReserved";
|
|
18239
18440
|
validations.push({
|
|
18240
18441
|
code,
|
|
@@ -18397,6 +18598,13 @@ function validateEnvironment(environment) {
|
|
|
18397
18598
|
}
|
|
18398
18599
|
return validations;
|
|
18399
18600
|
}
|
|
18601
|
+
function validateSystemModel(model) {
|
|
18602
|
+
switch (model.__typename) {
|
|
18603
|
+
case "SystemAsset": return validateSystemAsset(model);
|
|
18604
|
+
case "SystemQuery": return validateSystemQuery(model);
|
|
18605
|
+
case "SystemSegment": return validateSystemSegment(model);
|
|
18606
|
+
}
|
|
18607
|
+
}
|
|
18400
18608
|
//#endregion
|
|
18401
18609
|
//#region src/diff/resources/component.ts
|
|
18402
18610
|
/**
|
|
@@ -18881,13 +19089,49 @@ function diffFields(from, to, migrationValues = /* @__PURE__ */ new Map(), pairs
|
|
|
18881
19089
|
const move = moveUnsupportedField(parent, fromField, field, afterDeletes);
|
|
18882
19090
|
if (move) changes.updates.push(move);
|
|
18883
19091
|
}
|
|
18884
|
-
changes.updates = changes.updates.toSorted(byApiId$1);
|
|
19092
|
+
changes.updates = variantsInOrder(changes.updates.toSorted(byApiId$1), fromFields, to.fields);
|
|
18885
19093
|
return changes;
|
|
18886
19094
|
}
|
|
18887
19095
|
/**
|
|
18888
|
-
* The
|
|
18889
|
-
*
|
|
18890
|
-
*
|
|
19096
|
+
* The updates with a condition's base field turning variants on before
|
|
19097
|
+
* the fields whose condition names it, and turning them off after: the
|
|
19098
|
+
* server refuses a field with variants whose base has none. Otherwise in
|
|
19099
|
+
* the order given.
|
|
19100
|
+
*/
|
|
19101
|
+
function variantsInOrder(updates, from, to) {
|
|
19102
|
+
const turning = (on) => new Set(updates.flatMap((update) => update.kind !== "unsupported" && update.changes.variantEnabled?.to === on ? [update.apiId] : []));
|
|
19103
|
+
const on = turning(true);
|
|
19104
|
+
const off = turning(false);
|
|
19105
|
+
const before = /* @__PURE__ */ new Map();
|
|
19106
|
+
const runsFirst = (apiId, first) => before.set(apiId, [...before.get(apiId) ?? [], first]);
|
|
19107
|
+
for (const update of updates) {
|
|
19108
|
+
const fromBase = conditionBase(from[update.apiId]);
|
|
19109
|
+
const toBase = conditionBase(to[update.apiId]);
|
|
19110
|
+
if (fromBase !== void 0 && off.has(fromBase)) runsFirst(fromBase, update.apiId);
|
|
19111
|
+
if (toBase !== void 0 && on.has(toBase)) runsFirst(update.apiId, toBase);
|
|
19112
|
+
}
|
|
19113
|
+
const byApiId = new Map(updates.map((update) => [update.apiId, update]));
|
|
19114
|
+
const ordered = [];
|
|
19115
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
19116
|
+
const visit = (update) => {
|
|
19117
|
+
if (ordered.includes(update) || visiting.has(update.apiId)) return;
|
|
19118
|
+
visiting.add(update.apiId);
|
|
19119
|
+
for (const apiId of before.get(update.apiId) ?? []) {
|
|
19120
|
+
const first = byApiId.get(apiId);
|
|
19121
|
+
if (first) visit(first);
|
|
19122
|
+
}
|
|
19123
|
+
ordered.push(update);
|
|
19124
|
+
};
|
|
19125
|
+
updates.forEach(visit);
|
|
19126
|
+
return ordered;
|
|
19127
|
+
}
|
|
19128
|
+
function conditionBase(field) {
|
|
19129
|
+
return field === void 0 || field.kind === "unsupported" ? void 0 : field.visibilityCondition?.baseField;
|
|
19130
|
+
}
|
|
19131
|
+
/**
|
|
19132
|
+
* The rules, condition and variants of a two-way side its partner's create
|
|
19133
|
+
* makes, as an update after the creates: the create takes none of them for
|
|
19134
|
+
* the partner. `null` when it has none.
|
|
18891
19135
|
*/
|
|
18892
19136
|
function partnerSettings(parent, field) {
|
|
18893
19137
|
if (field.kind !== "referenceTwoWay") return null;
|
|
@@ -18900,6 +19144,10 @@ function partnerSettings(parent, field) {
|
|
|
18900
19144
|
from: null,
|
|
18901
19145
|
to: field.visibilityCondition
|
|
18902
19146
|
};
|
|
19147
|
+
if (field.variantEnabled) changes.variantEnabled = {
|
|
19148
|
+
from: false,
|
|
19149
|
+
to: true
|
|
19150
|
+
};
|
|
18903
19151
|
return Object.keys(changes).length === 0 ? null : {
|
|
18904
19152
|
action: "update",
|
|
18905
19153
|
resource: "field",
|
|
@@ -19062,6 +19310,10 @@ function diffField(from, to) {
|
|
|
19062
19310
|
from: from.visibilityCondition,
|
|
19063
19311
|
to: to.visibilityCondition
|
|
19064
19312
|
};
|
|
19313
|
+
if (from.variantEnabled !== to.variantEnabled) changes.variantEnabled = {
|
|
19314
|
+
from: from.variantEnabled,
|
|
19315
|
+
to: to.variantEnabled
|
|
19316
|
+
};
|
|
19065
19317
|
if (from.kind === "componentUnion" && to.kind === "componentUnion" && hashJSON(from.components) !== hashJSON(to.components)) changes.components = {
|
|
19066
19318
|
from: from.components,
|
|
19067
19319
|
to: to.components
|
|
@@ -19638,6 +19890,15 @@ function diffEnvironment({ from, to, intents = {
|
|
|
19638
19890
|
});
|
|
19639
19891
|
}
|
|
19640
19892
|
if (to.query) pushFields(renamed.query ?? null, to.query);
|
|
19893
|
+
const segmentCreates = [];
|
|
19894
|
+
const segmentConditions = [];
|
|
19895
|
+
if (to.segment) {
|
|
19896
|
+
const creates = fieldCreates.length;
|
|
19897
|
+
const conditions = fieldConditions.length;
|
|
19898
|
+
pushFields(renamed.segment ?? null, to.segment);
|
|
19899
|
+
segmentCreates.push(...fieldCreates.splice(creates));
|
|
19900
|
+
segmentConditions.push(...fieldConditions.splice(conditions));
|
|
19901
|
+
}
|
|
19641
19902
|
const fromComponents = new Map(renamed.components.map((component) => [component.apiId, component]));
|
|
19642
19903
|
const toComponentApiIds = new Set(to.components.map((component) => component.apiId));
|
|
19643
19904
|
const deletedComponents = renamed.components.filter((component) => !toComponentApiIds.has(component.apiId));
|
|
@@ -19715,6 +19976,8 @@ function diffEnvironment({ from, to, intents = {
|
|
|
19715
19976
|
...fieldCreates.map((change) => withFieldBack(change, to)),
|
|
19716
19977
|
...memberAdds,
|
|
19717
19978
|
...fieldConditions,
|
|
19979
|
+
...segmentCreates,
|
|
19980
|
+
...segmentConditions,
|
|
19718
19981
|
...embeds.afterModelCreates
|
|
19719
19982
|
];
|
|
19720
19983
|
}
|
|
@@ -19732,7 +19995,9 @@ function diffEnvironment({ from, to, intents = {
|
|
|
19732
19995
|
* Both places keep a move right: positions count after the field deletes,
|
|
19733
19996
|
* and the model deletes renumber no other model's fields. A field whose
|
|
19734
19997
|
* embeds were all deleted and that embeds a created model goes after the
|
|
19735
|
-
* creates, which `validateChangeSet` refuses.
|
|
19998
|
+
* creates, which `validateChangeSet` refuses. A moved update's variants
|
|
19999
|
+
* stay in an update of their own among the field updates, in the order
|
|
20000
|
+
* `variantsInOrder` gave them.
|
|
19736
20001
|
*/
|
|
19737
20002
|
function orderEmbeds(changes, deleted, created) {
|
|
19738
20003
|
const order = {
|
|
@@ -19741,10 +20006,31 @@ function orderEmbeds(changes, deleted, created) {
|
|
|
19741
20006
|
afterModelCreates: []
|
|
19742
20007
|
};
|
|
19743
20008
|
for (const change of changes) {
|
|
19744
|
-
|
|
19745
|
-
|
|
19746
|
-
|
|
19747
|
-
|
|
20009
|
+
if (change.resource !== "field" || change.action !== "update" || change.kind !== "richText") {
|
|
20010
|
+
order.updates.push(change);
|
|
20011
|
+
continue;
|
|
20012
|
+
}
|
|
20013
|
+
const { embeds, variantEnabled, ...rest } = change.changes;
|
|
20014
|
+
const moveTo = (embeds?.to ?? []).some((apiId) => created.has(apiId)) ? order.afterModelCreates : (embeds?.from ?? []).some((apiId) => deleted.has(apiId)) ? order.beforeModelDeletes : void 0;
|
|
20015
|
+
if (moveTo === void 0) order.updates.push(change);
|
|
20016
|
+
else if (variantEnabled === void 0) moveTo.push(change);
|
|
20017
|
+
else {
|
|
20018
|
+
moveTo.push({
|
|
20019
|
+
...change,
|
|
20020
|
+
changes: {
|
|
20021
|
+
...rest,
|
|
20022
|
+
embeds
|
|
20023
|
+
}
|
|
20024
|
+
});
|
|
20025
|
+
order.updates.push({
|
|
20026
|
+
action: "update",
|
|
20027
|
+
resource: "field",
|
|
20028
|
+
parent: change.parent,
|
|
20029
|
+
apiId: change.apiId,
|
|
20030
|
+
kind: change.kind,
|
|
20031
|
+
changes: { variantEnabled }
|
|
20032
|
+
});
|
|
20033
|
+
}
|
|
19748
20034
|
}
|
|
19749
20035
|
return order;
|
|
19750
20036
|
}
|
|
@@ -20057,7 +20343,7 @@ function applyEnumerationValueRenames(from, intents) {
|
|
|
20057
20343
|
renames
|
|
20058
20344
|
};
|
|
20059
20345
|
}
|
|
20060
|
-
/** Every model, component and
|
|
20346
|
+
/** Every model, component, Asset and Segment with `map` applied to each of its fields. */
|
|
20061
20347
|
function mapFields(from, map) {
|
|
20062
20348
|
const mapParent = (parent) => ({
|
|
20063
20349
|
...parent,
|
|
@@ -20066,7 +20352,8 @@ function mapFields(from, map) {
|
|
|
20066
20352
|
return {
|
|
20067
20353
|
models: from.models.map(mapParent),
|
|
20068
20354
|
components: from.components.map(mapParent),
|
|
20069
|
-
...from.asset && { asset: mapParent(from.asset) }
|
|
20355
|
+
...from.asset && { asset: mapParent(from.asset) },
|
|
20356
|
+
...from.segment && { segment: mapParent(from.segment) }
|
|
20070
20357
|
};
|
|
20071
20358
|
}
|
|
20072
20359
|
/**
|
|
@@ -20227,7 +20514,8 @@ function applyFieldRenames(from, intents) {
|
|
|
20227
20514
|
...from,
|
|
20228
20515
|
models: from.models.map(renameFields),
|
|
20229
20516
|
components: from.components.map(renameFields),
|
|
20230
|
-
...from.asset && { asset: renameFields(from.asset) }
|
|
20517
|
+
...from.asset && { asset: renameFields(from.asset) },
|
|
20518
|
+
...from.segment && { segment: renameFields(from.segment) }
|
|
20231
20519
|
};
|
|
20232
20520
|
const parents = mapFields(renamed, (field) => {
|
|
20233
20521
|
switch (field.kind) {
|
|
@@ -20710,6 +20998,10 @@ function validateUnsupportedFields({ from, to, intents, unsupportedPairs = [], u
|
|
|
20710
20998
|
kind: "model",
|
|
20711
20999
|
parent: to.query
|
|
20712
21000
|
}] : [],
|
|
21001
|
+
...to.segment ? [{
|
|
21002
|
+
kind: "model",
|
|
21003
|
+
parent: to.segment
|
|
21004
|
+
}] : [],
|
|
20713
21005
|
...to.components.map((parent) => ({
|
|
20714
21006
|
kind: "component",
|
|
20715
21007
|
parent
|
|
@@ -20887,6 +21179,10 @@ function liveParent(from, intents, parent) {
|
|
|
20887
21179
|
["QueryModel", from.query ?? {
|
|
20888
21180
|
apiId: "QueryModel",
|
|
20889
21181
|
fields: {}
|
|
21182
|
+
}],
|
|
21183
|
+
["Segment", from.segment ?? {
|
|
21184
|
+
apiId: "Segment",
|
|
21185
|
+
fields: {}
|
|
20890
21186
|
}]
|
|
20891
21187
|
]);
|
|
20892
21188
|
const rename = intents.renames.find((each) => (each.resource === "model" || each.resource === "component") && each.apiId === parent);
|
|
@@ -20894,6 +21190,52 @@ function liveParent(from, intents, parent) {
|
|
|
20894
21190
|
return parents.get(parent);
|
|
20895
21191
|
}
|
|
20896
21192
|
/**
|
|
21193
|
+
* Hygraph adds Segment with the first field that has variants, and keeps
|
|
21194
|
+
* it. Live without Segment has no such field yet, so one of your models
|
|
21195
|
+
* needs one in this plan. Without it, your fields on Segment are an error,
|
|
21196
|
+
* and Segment listed without fields, which plans nothing, a warning.
|
|
21197
|
+
*/
|
|
21198
|
+
function validateSegment({ from, to }) {
|
|
21199
|
+
if (from.segment !== void 0 || to.segment === void 0 || to.models.some((model) => Object.values(model.fields).some((field) => field.kind !== "unsupported" && field.variantEnabled))) return [];
|
|
21200
|
+
const empty = Object.keys(to.segment.fields).length === 0;
|
|
21201
|
+
const code = empty ? "systemModel.segmentNotYet" : "systemModel.segmentMissing";
|
|
21202
|
+
return [{
|
|
21203
|
+
code,
|
|
21204
|
+
severity: empty ? "warning" : "error",
|
|
21205
|
+
path: ["models", "Segment"],
|
|
21206
|
+
message: messages[code],
|
|
21207
|
+
fix: fixes[code]
|
|
21208
|
+
}];
|
|
21209
|
+
}
|
|
21210
|
+
/**
|
|
21211
|
+
* A component field that becomes required with variants, by either change.
|
|
21212
|
+
* Hygraph copies a required field's values into the variants of existing
|
|
21213
|
+
* entries, but not a component's, so those variants start without it.
|
|
21214
|
+
* The field and its model are looked up live under the apiIds they have
|
|
21215
|
+
* before the plan's renames.
|
|
21216
|
+
*/
|
|
21217
|
+
function validateVariantComponents({ from, to, intents }) {
|
|
21218
|
+
return to.models.flatMap((model) => Object.values(model.fields).flatMap((field) => {
|
|
21219
|
+
const rename = intents.fieldRenames.find((each) => each.parent === model.apiId && each.apiId === field.apiId);
|
|
21220
|
+
const fields = liveParent(from, intents, model.apiId)?.fields ?? {};
|
|
21221
|
+
const before = fields[field.apiId] ?? (rename === void 0 ? void 0 : fields[rename.renamedFrom]);
|
|
21222
|
+
if (field.kind !== "component" || !field.required || !field.variantEnabled || before?.kind !== "component" || before.required && before.variantEnabled) return [];
|
|
21223
|
+
const code = "field.variantComponentRequired";
|
|
21224
|
+
return [{
|
|
21225
|
+
code,
|
|
21226
|
+
severity: "warning",
|
|
21227
|
+
path: [
|
|
21228
|
+
"models",
|
|
21229
|
+
model.apiId,
|
|
21230
|
+
"fields",
|
|
21231
|
+
field.apiId
|
|
21232
|
+
],
|
|
21233
|
+
message: messages[code](model.apiId, field.apiId),
|
|
21234
|
+
fix: fixes[code]
|
|
21235
|
+
}];
|
|
21236
|
+
}));
|
|
21237
|
+
}
|
|
21238
|
+
/**
|
|
20897
21239
|
* Whether every change can be applied at its point of the migration. Plays
|
|
20898
21240
|
* the change set through in order against `from`: a delete or update needs
|
|
20899
21241
|
* its locale, model, component or enumeration to still exist, a create or
|
|
@@ -20910,6 +21252,7 @@ function validateChangeSet({ from, changes }) {
|
|
|
20910
21252
|
const models = new Map(from.models.map((model) => [model.apiId, model]));
|
|
20911
21253
|
const components = new Map(from.components.map((component) => [component.apiId, component]));
|
|
20912
21254
|
const componentApiIds = new Set(components.keys());
|
|
21255
|
+
let segment = from.segment !== void 0;
|
|
20913
21256
|
const enumerations = new Map(from.enumerations.map((enumeration) => [enumeration.apiId, enumeration]));
|
|
20914
21257
|
const taxonomies = new Map(from.taxonomies.map((taxonomy) => [taxonomy.apiId, {
|
|
20915
21258
|
apiId: taxonomy.apiId,
|
|
@@ -21005,7 +21348,8 @@ function validateChangeSet({ from, changes }) {
|
|
|
21005
21348
|
validateComponentsUsed(change);
|
|
21006
21349
|
validateModelReferenced(change);
|
|
21007
21350
|
validateModelsEmbedded(change);
|
|
21008
|
-
if (
|
|
21351
|
+
if (turnsVariantsOn(change) && models.has(change.parent)) segment = true;
|
|
21352
|
+
if (change.parent === "Asset" || change.parent === "QueryModel" || change.parent === "Segment" && segment || models.has(change.parent) || components.has(change.parent)) break;
|
|
21009
21353
|
const onComponent = componentApiIds.has(change.parent);
|
|
21010
21354
|
report(onComponent ? "change.componentMissing" : "change.modelMissing", [
|
|
21011
21355
|
onComponent ? "components" : "models",
|
|
@@ -21282,6 +21626,10 @@ function applyUpdate(model, change) {
|
|
|
21282
21626
|
function text(entry, params) {
|
|
21283
21627
|
return typeof entry === "string" ? entry : entry(...params);
|
|
21284
21628
|
}
|
|
21629
|
+
/** A field create or update that gives the field variants. */
|
|
21630
|
+
function turnsVariantsOn(change) {
|
|
21631
|
+
return change.action === "create" ? change.field.variantEnabled : change.action === "update" && change.kind !== "unsupported" && change.changes.variantEnabled?.to === true;
|
|
21632
|
+
}
|
|
21285
21633
|
//#endregion
|
|
21286
21634
|
//#region src/validations/render.ts
|
|
21287
21635
|
/**
|
|
@@ -21307,6 +21655,7 @@ const assetFieldSchema = strictObject({
|
|
|
21307
21655
|
required: boolean(),
|
|
21308
21656
|
visibility: fieldVisibilitySchema,
|
|
21309
21657
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21658
|
+
variantEnabled: boolean(),
|
|
21310
21659
|
reverse: string$1().nullable(),
|
|
21311
21660
|
renamedFrom: string$1().nullable()
|
|
21312
21661
|
});
|
|
@@ -21323,6 +21672,7 @@ const assetReverseFieldSchema = strictObject({
|
|
|
21323
21672
|
required: literal(false),
|
|
21324
21673
|
visibility: fieldVisibilitySchema,
|
|
21325
21674
|
visibilityCondition: _null(),
|
|
21675
|
+
variantEnabled: literal(false),
|
|
21326
21676
|
renamedFrom: string$1().nullable()
|
|
21327
21677
|
});
|
|
21328
21678
|
//#endregion
|
|
@@ -21339,6 +21689,7 @@ const booleanFieldSchema = strictObject({
|
|
|
21339
21689
|
title: boolean(),
|
|
21340
21690
|
visibility: fieldVisibilitySchema,
|
|
21341
21691
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21692
|
+
variantEnabled: boolean(),
|
|
21342
21693
|
initialValue: union([boolean(), array(boolean())]).nullable(),
|
|
21343
21694
|
migrationValue: union([boolean(), array(boolean())]).nullable(),
|
|
21344
21695
|
renamedFrom: string$1().nullable()
|
|
@@ -21357,6 +21708,7 @@ const componentFieldSchema = strictObject({
|
|
|
21357
21708
|
required: boolean(),
|
|
21358
21709
|
visibility: fieldVisibilitySchema,
|
|
21359
21710
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21711
|
+
variantEnabled: boolean(),
|
|
21360
21712
|
renamedFrom: string$1().nullable()
|
|
21361
21713
|
});
|
|
21362
21714
|
const componentUnionFieldSchema = strictObject({
|
|
@@ -21369,6 +21721,7 @@ const componentUnionFieldSchema = strictObject({
|
|
|
21369
21721
|
required: literal(false),
|
|
21370
21722
|
visibility: fieldVisibilitySchema,
|
|
21371
21723
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21724
|
+
variantEnabled: boolean(),
|
|
21372
21725
|
renamedFrom: string$1().nullable()
|
|
21373
21726
|
});
|
|
21374
21727
|
//#endregion
|
|
@@ -21386,6 +21739,7 @@ const dateFieldShape = {
|
|
|
21386
21739
|
title: boolean(),
|
|
21387
21740
|
visibility: fieldVisibilitySchema,
|
|
21388
21741
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21742
|
+
variantEnabled: boolean(),
|
|
21389
21743
|
initialValue: dateValueSchema,
|
|
21390
21744
|
migrationValue: dateValueSchema,
|
|
21391
21745
|
renamedFrom: string$1().nullable()
|
|
@@ -21428,6 +21782,7 @@ const enumerationFieldSchema = strictObject({
|
|
|
21428
21782
|
title: boolean(),
|
|
21429
21783
|
visibility: fieldVisibilitySchema,
|
|
21430
21784
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21785
|
+
variantEnabled: boolean(),
|
|
21431
21786
|
initialValue: enumerationValueSchema,
|
|
21432
21787
|
migrationValue: enumerationValueSchema,
|
|
21433
21788
|
renamedFrom: string$1().nullable()
|
|
@@ -21447,6 +21802,7 @@ const jsonFieldSchema = strictObject({
|
|
|
21447
21802
|
title: literal(false),
|
|
21448
21803
|
visibility: fieldVisibilitySchema,
|
|
21449
21804
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21805
|
+
variantEnabled: boolean(),
|
|
21450
21806
|
initialValue: jsonValueSchema,
|
|
21451
21807
|
migrationValue: jsonValueSchema,
|
|
21452
21808
|
renamedFrom: string$1().nullable()
|
|
@@ -21474,6 +21830,7 @@ const numberFieldShape = {
|
|
|
21474
21830
|
title: boolean(),
|
|
21475
21831
|
visibility: fieldVisibilitySchema,
|
|
21476
21832
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21833
|
+
variantEnabled: boolean(),
|
|
21477
21834
|
initialValue: numberValueSchema,
|
|
21478
21835
|
migrationValue: numberValueSchema,
|
|
21479
21836
|
validations: strictObject({
|
|
@@ -21507,6 +21864,7 @@ const referenceOneWayFieldSchema = strictObject({
|
|
|
21507
21864
|
}) }).nullable(),
|
|
21508
21865
|
visibility: fieldVisibilitySchema,
|
|
21509
21866
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21867
|
+
variantEnabled: boolean(),
|
|
21510
21868
|
renamedFrom: string$1().nullable()
|
|
21511
21869
|
});
|
|
21512
21870
|
//#endregion
|
|
@@ -21527,6 +21885,7 @@ const referenceTwoWayFieldSchema = strictObject({
|
|
|
21527
21885
|
}) }).nullable(),
|
|
21528
21886
|
visibility: fieldVisibilitySchema,
|
|
21529
21887
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21888
|
+
variantEnabled: boolean(),
|
|
21530
21889
|
renamedFrom: string$1().nullable()
|
|
21531
21890
|
});
|
|
21532
21891
|
//#endregion
|
|
@@ -21547,6 +21906,7 @@ const referenceUnionFieldSchema = strictObject({
|
|
|
21547
21906
|
}) }).nullable(),
|
|
21548
21907
|
visibility: fieldVisibilitySchema,
|
|
21549
21908
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21909
|
+
variantEnabled: boolean(),
|
|
21550
21910
|
renamedFrom: string$1().nullable()
|
|
21551
21911
|
});
|
|
21552
21912
|
//#endregion
|
|
@@ -21562,6 +21922,7 @@ const referenceUnionMemberFieldSchema = strictObject({
|
|
|
21562
21922
|
required: literal(false),
|
|
21563
21923
|
visibility: fieldVisibilitySchema,
|
|
21564
21924
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
21925
|
+
variantEnabled: literal(false),
|
|
21565
21926
|
renamedFrom: string$1().nullable()
|
|
21566
21927
|
});
|
|
21567
21928
|
//#endregion
|
|
@@ -21631,6 +21992,7 @@ const remoteFieldSchema = strictObject({
|
|
|
21631
21992
|
required: boolean(),
|
|
21632
21993
|
visibility: fieldVisibilitySchema,
|
|
21633
21994
|
visibilityCondition: _null(),
|
|
21995
|
+
variantEnabled: literal(false),
|
|
21634
21996
|
renamedFrom: string$1().nullable()
|
|
21635
21997
|
});
|
|
21636
21998
|
//#endregion
|
|
@@ -21663,6 +22025,7 @@ const stringFieldShape = {
|
|
|
21663
22025
|
title: boolean(),
|
|
21664
22026
|
visibility: fieldVisibilitySchema,
|
|
21665
22027
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
22028
|
+
variantEnabled: boolean(),
|
|
21666
22029
|
initialValue: textValueSchema,
|
|
21667
22030
|
migrationValue: textValueSchema,
|
|
21668
22031
|
validations: stringValidationRulesSchema.nullable(),
|
|
@@ -21732,6 +22095,7 @@ const fieldSchema = discriminatedUnion("__typename", [
|
|
|
21732
22095
|
unique: boolean(),
|
|
21733
22096
|
visibility: fieldVisibilitySchema,
|
|
21734
22097
|
visibilityCondition: visibilityConditionSchema.nullable(),
|
|
22098
|
+
variantEnabled: boolean(),
|
|
21735
22099
|
initialValue: taxonomyValueSchema,
|
|
21736
22100
|
migrationValue: taxonomyValueSchema,
|
|
21737
22101
|
renamedFrom: string$1().nullable()
|
|
@@ -21770,6 +22134,13 @@ const systemQuerySchema = strictObject({
|
|
|
21770
22134
|
fields: array(fieldSchema)
|
|
21771
22135
|
});
|
|
21772
22136
|
//#endregion
|
|
22137
|
+
//#region src/define/system/segment.zod.ts
|
|
22138
|
+
const systemSegmentSchema = strictObject({
|
|
22139
|
+
__typename: literal("SystemSegment"),
|
|
22140
|
+
apiId: literal("Segment"),
|
|
22141
|
+
fields: array(fieldSchema)
|
|
22142
|
+
});
|
|
22143
|
+
//#endregion
|
|
21773
22144
|
//#region src/define/resources/component.zod.ts
|
|
21774
22145
|
const componentSchema = strictObject({
|
|
21775
22146
|
__typename: literal("Component"),
|
|
@@ -21812,7 +22183,11 @@ const environmentSchema = strictObject({
|
|
|
21812
22183
|
remoteSources: array(remoteSourceSchema),
|
|
21813
22184
|
components: array(componentSchema),
|
|
21814
22185
|
models: array(modelSchema),
|
|
21815
|
-
systemModels: array(union([
|
|
22186
|
+
systemModels: array(union([
|
|
22187
|
+
systemAssetSchema,
|
|
22188
|
+
systemQuerySchema,
|
|
22189
|
+
systemSegmentSchema
|
|
22190
|
+
]))
|
|
21816
22191
|
});
|
|
21817
22192
|
//#endregion
|
|
21818
22193
|
//#region src/define/resources/target.zod.ts
|
|
@@ -22064,6 +22439,11 @@ async function computePlan(target, fetch, { rotateSecrets = [] } = {}) {
|
|
|
22064
22439
|
to: desired,
|
|
22065
22440
|
intents
|
|
22066
22441
|
}), `the fields back on Asset do not match the asset fields,`);
|
|
22442
|
+
const segmentValidations = validateSegment({
|
|
22443
|
+
from: live,
|
|
22444
|
+
to: desired
|
|
22445
|
+
});
|
|
22446
|
+
maybeRefuse(segmentValidations, `Segment's fields cannot be planned against ${target.environment},`);
|
|
22067
22447
|
const diffed = diffEnvironment({
|
|
22068
22448
|
from: live,
|
|
22069
22449
|
to: desired,
|
|
@@ -22090,7 +22470,15 @@ async function computePlan(target, fetch, { rotateSecrets = [] } = {}) {
|
|
|
22090
22470
|
}),
|
|
22091
22471
|
environmentId,
|
|
22092
22472
|
secretValues: secretValues(desired, secrets),
|
|
22093
|
-
warnings: [
|
|
22473
|
+
warnings: [
|
|
22474
|
+
...[...configValidations, ...segmentValidations].filter((validation) => validation.severity === "warning"),
|
|
22475
|
+
...validateVariantComponents({
|
|
22476
|
+
from: live,
|
|
22477
|
+
to: desired,
|
|
22478
|
+
intents
|
|
22479
|
+
}),
|
|
22480
|
+
...warnings
|
|
22481
|
+
]
|
|
22094
22482
|
};
|
|
22095
22483
|
}
|
|
22096
22484
|
/** Below the plan: what is worth a look but does not stop it. */
|
|
@@ -22235,7 +22623,7 @@ async function prepare(target, { config, options, colors, planFiles, write }) {
|
|
|
22235
22623
|
const file = planFiles?.get(target.name);
|
|
22236
22624
|
const artifact = file === void 0 ? void 0 : readPlanFile(file);
|
|
22237
22625
|
if (artifact !== void 0) refuseUnsendableOAuthSecrets(unmaskSecrets(artifact.changes, oAuthSecretValues(oAuthSecrets(target.apply))));
|
|
22238
|
-
const { plan: fresh, environmentId, secretValues } = await computePlan(target, void 0, { rotateSecrets: artifact ? sentOAuthSecrets(artifact.changes) : options.rotateSecret });
|
|
22626
|
+
const { plan: fresh, environmentId, secretValues, warnings } = await computePlan(target, void 0, { rotateSecrets: artifact ? sentOAuthSecrets(artifact.changes) : options.rotateSecret });
|
|
22239
22627
|
let plan = fresh;
|
|
22240
22628
|
if (file !== void 0 && artifact !== void 0) {
|
|
22241
22629
|
const refusals = verifyPlan(artifact, fresh);
|
|
@@ -22251,6 +22639,7 @@ async function prepare(target, { config, options, colors, planFiles, write }) {
|
|
|
22251
22639
|
config,
|
|
22252
22640
|
colors
|
|
22253
22641
|
}));
|
|
22642
|
+
if (warnings.length > 0) write(renderWarnings(warnings, colors));
|
|
22254
22643
|
if (plan.changes.length === 0) return;
|
|
22255
22644
|
if (plan.summary.destructive > 0 && options.prune !== true) throw new ApplyRefusal(renderDestructiveRefusal(plan.summary, colors));
|
|
22256
22645
|
refuseUnsendableOAuthSecrets(unmaskSecrets(plan.changes, secretValues));
|
|
@@ -22628,6 +23017,7 @@ function fieldOptions(field, defaults) {
|
|
|
22628
23017
|
["title", !("title" in field) || field.title === defaults.title ? void 0 : String(field.title)],
|
|
22629
23018
|
["visibility", field.visibility === defaults.visibility ? void 0 : string(field.visibility)],
|
|
22630
23019
|
["visibilityCondition", field.visibilityCondition === null ? void 0 : printCondition(field.visibilityCondition)],
|
|
23020
|
+
["variantEnabled", field.variantEnabled === defaults.variantEnabled ? void 0 : String(field.variantEnabled)],
|
|
22631
23021
|
["initialValue", field.initialValue === null ? void 0 : JSON.stringify(field.initialValue)]
|
|
22632
23022
|
];
|
|
22633
23023
|
}
|
|
@@ -22646,7 +23036,8 @@ function referenceOptions(field, referenced) {
|
|
|
22646
23036
|
["list", field.list === FIELD_DEFAULTS.list ? void 0 : String(field.list)],
|
|
22647
23037
|
["required", field.required === FIELD_DEFAULTS.required ? void 0 : String(field.required)],
|
|
22648
23038
|
["visibility", field.visibility === FIELD_DEFAULTS.visibility ? void 0 : string(field.visibility)],
|
|
22649
|
-
["visibilityCondition", field.visibilityCondition === null ? void 0 : printCondition(field.visibilityCondition)]
|
|
23039
|
+
["visibilityCondition", field.visibilityCondition === null ? void 0 : printCondition(field.visibilityCondition)],
|
|
23040
|
+
["variantEnabled", field.variantEnabled === FIELD_DEFAULTS.variantEnabled ? void 0 : String(field.variantEnabled)]
|
|
22650
23041
|
];
|
|
22651
23042
|
}
|
|
22652
23043
|
/** A condition with the value its base field's type takes. */
|
|
@@ -22800,17 +23191,33 @@ function printStage(stage) {
|
|
|
22800
23191
|
}
|
|
22801
23192
|
//#endregion
|
|
22802
23193
|
//#region src/export/resources/system.ts
|
|
22803
|
-
/** `const Asset = system.asset({ fields: [...] });`, your fields only. */
|
|
23194
|
+
/** `const Asset = system.model.asset({ fields: [...] });`, your fields only. */
|
|
22804
23195
|
function printSystemAsset(asset) {
|
|
22805
|
-
return `const Asset = system.asset(${object([["fields", printFields(asset.apiId, asset.fields, printAssetModelField)]])});`;
|
|
23196
|
+
return `const Asset = system.model.asset(${object([["fields", printFields(asset.apiId, asset.fields, printAssetModelField)]])});`;
|
|
22806
23197
|
}
|
|
22807
23198
|
/**
|
|
22808
|
-
* `const Query = system.query({ fields: [...] });`. Its remote fields read
|
|
23199
|
+
* `const Query = system.model.query({ fields: [...] });`. Its remote fields read
|
|
22809
23200
|
* their headers as `QUERY_<FIELD>_<HEADER>`, after the name Studio shows.
|
|
22810
23201
|
*/
|
|
22811
23202
|
function printSystemQuery(query) {
|
|
22812
|
-
return `const Query = system.query(${object([["fields", printFields("Query", query.fields)]])});`;
|
|
23203
|
+
return `const Query = system.model.query(${object([["fields", printFields("Query", query.fields)]])});`;
|
|
23204
|
+
}
|
|
23205
|
+
/** `const Segment = system.model.segment({ fields: [...] });`, your fields only. */
|
|
23206
|
+
function printSystemSegment(segment) {
|
|
23207
|
+
return `const Segment = system.model.segment(${object([["fields", printFields(segment.apiId, segment.fields)]])});`;
|
|
22813
23208
|
}
|
|
23209
|
+
/**
|
|
23210
|
+
* Segment as a comment, for an environment Hygraph has not added it to
|
|
23211
|
+
* yet, so the config shows where it goes once a field has variants.
|
|
23212
|
+
*/
|
|
23213
|
+
const SEGMENT_NOT_YET = [
|
|
23214
|
+
"// Segment (the audiences for variants) does not exist in this project yet.",
|
|
23215
|
+
"// To add fields to it:",
|
|
23216
|
+
"// 1. Give a field of one of your models variantEnabled: true.",
|
|
23217
|
+
"// 2. Uncomment the line below and add Segment to models.",
|
|
23218
|
+
"// Both can go in the same plan.",
|
|
23219
|
+
"// const Segment = system.model.segment({ fields: [] });"
|
|
23220
|
+
].join("\n");
|
|
22814
23221
|
//#endregion
|
|
22815
23222
|
//#region src/export/resources/taxonomy.ts
|
|
22816
23223
|
/**
|
|
@@ -22856,10 +23263,11 @@ const NO_QUERY_FIELDS = {
|
|
|
22856
23263
|
* The config a user commits: one const per enumeration, then per
|
|
22857
23264
|
* taxonomy, per remote source, per component and per model, in IR
|
|
22858
23265
|
* order, then Asset and Query, also with no fields of yours, so the first
|
|
22859
|
-
* asset field only adds its field back there. Then
|
|
22860
|
-
*
|
|
22861
|
-
*
|
|
22862
|
-
* loads, never
|
|
23266
|
+
* asset field only adds its field back there. Then Segment, as a comment
|
|
23267
|
+
* while live has none. Then the environment that lists them with every
|
|
23268
|
+
* locale and stage written inline, and the target as the default export.
|
|
23269
|
+
* The token is read from HYGRAPH_TOKEN when the config loads, never
|
|
23270
|
+
* written.
|
|
22863
23271
|
*/
|
|
22864
23272
|
async function printConfig(target, environment) {
|
|
22865
23273
|
return formatSource([
|
|
@@ -22871,6 +23279,7 @@ async function printConfig(target, environment) {
|
|
|
22871
23279
|
...environment.models.map(printModel),
|
|
22872
23280
|
printSystemAsset(environment.asset ?? NO_ASSET_FIELDS),
|
|
22873
23281
|
printSystemQuery(environment.query ?? NO_QUERY_FIELDS),
|
|
23282
|
+
environment.segment ? printSystemSegment(environment.segment) : SEGMENT_NOT_YET,
|
|
22874
23283
|
printEnvironment(environment),
|
|
22875
23284
|
printTarget(target)
|
|
22876
23285
|
].join("\n\n"));
|
|
@@ -22880,9 +23289,10 @@ async function printConfig(target, environment) {
|
|
|
22880
23289
|
* every stage in its live order, also when Draft and Published are the only
|
|
22881
23290
|
* ones, so the config shows where a new stage goes. `enumerations`,
|
|
22882
23291
|
* `taxonomies`, `remoteSources` and `components` are left out when there
|
|
22883
|
-
* are none, their default. `models` ends with Asset and
|
|
23292
|
+
* are none, their default. `models` ends with Asset, Query and Segment,
|
|
23293
|
+
* when live has it.
|
|
22884
23294
|
*/
|
|
22885
|
-
function printEnvironment({ locales, stages, enumerations, taxonomies, remoteSources, components, models, asset }) {
|
|
23295
|
+
function printEnvironment({ locales, stages, enumerations, taxonomies, remoteSources, components, models, asset, segment }) {
|
|
22886
23296
|
const list = (resources) => `[${resources.map((resource) => resource.apiId).join(", ")}]`;
|
|
22887
23297
|
return `const environment = define.environment({ ${[
|
|
22888
23298
|
`locales: [${locales.map(printLocale).join(", ")}]`,
|
|
@@ -22894,7 +23304,8 @@ function printEnvironment({ locales, stages, enumerations, taxonomies, remoteSou
|
|
|
22894
23304
|
`models: ${list([
|
|
22895
23305
|
...models,
|
|
22896
23306
|
asset ?? NO_ASSET_FIELDS,
|
|
22897
|
-
{ apiId: "Query" }
|
|
23307
|
+
{ apiId: "Query" },
|
|
23308
|
+
...segment ? [segment] : []
|
|
22898
23309
|
])}`
|
|
22899
23310
|
].join(", ")} });`;
|
|
22900
23311
|
}
|
|
@@ -23038,8 +23449,9 @@ const RESOURCE_STARTS = [
|
|
|
23038
23449
|
[/^const (\w+) = define\.enumeration\(/, (name) => `enumeration ${name}`],
|
|
23039
23450
|
[/^const (\w+) = define\.taxonomy\(/, (name) => `taxonomy ${name}`],
|
|
23040
23451
|
[/^const (\w+)RemoteSource = define\.(?:graphql|rest)RemoteSource\(/, (prefix) => `remote source ${prefix}`],
|
|
23041
|
-
[/^const \w+ = system\.asset\(/, () => "system.asset"],
|
|
23042
|
-
[/^const \w+ = system\.query\(/, () => "system.query"],
|
|
23452
|
+
[/^const \w+ = system\.model\.asset\(/, () => "system.model.asset"],
|
|
23453
|
+
[/^const \w+ = system\.model\.query\(/, () => "system.model.query"],
|
|
23454
|
+
[/^const \w+ = system\.model\.segment\(/, () => "system.model.segment"],
|
|
23043
23455
|
[/^const environment = define\.environment\(/, () => "environment"],
|
|
23044
23456
|
[/^export default define\.target\(/, () => "target"]
|
|
23045
23457
|
];
|