@stackbit/sdk 0.3.15-cross-references.0 → 0.3.15

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.
@@ -16,8 +16,7 @@ import {
16
16
  Field,
17
17
  FieldObjectProps,
18
18
  FieldGroupItem,
19
- FieldSpecificProps,
20
- FieldCrossReferenceModel
19
+ FieldSpecificProps
21
20
  } from '@stackbit/types';
22
21
 
23
22
  import { CMS_NAMES, FIELD_TYPES, SSG_NAMES } from './config-consts';
@@ -76,21 +75,6 @@ const validReferenceModelNames = Joi.custom((value, { error, state }) => {
76
75
  errors: { wrap: { label: false } }
77
76
  });
78
77
 
79
- const validCrossReferenceModelNames = Joi.object<FieldCrossReferenceModel>({
80
- modelName: Joi.string().required(),
81
- srcType: Joi.string(),
82
- srcProjectId: Joi.string()
83
- }).custom((allowedModels, { error, state }) => {
84
- // TODO: implement custom validation logic that checks unambiguous model matching
85
- // similar to how config models are matched to content-source models in content-store.ts
86
- return allowedModels;
87
- }).prefs({
88
- messages: {
89
- [documentModelNameErrorCode]: '{{#label}} must reference the name of an existing model of type "page" or "data", got "{{#value}}"'
90
- },
91
- errors: { wrap: { label: false } }
92
- });
93
-
94
78
  const groupNotFoundErrorCode = 'group.not.found';
95
79
  const groupNotObjectModelErrorCode = 'group.not.object.model';
96
80
  const validModelFieldGroups = Joi.string()
@@ -168,7 +152,7 @@ const labelFieldSchema = Joi.custom((value, { error, state }) => {
168
152
  if (!field) {
169
153
  return error(labelFieldNotFoundError);
170
154
  }
171
- if (['object', 'model', 'reference', 'cross-reference', 'list'].includes(field.type)) {
155
+ if (['object', 'model', 'reference', 'list'].includes(field.type)) {
172
156
  return error(labelFieldNotSimple, { fieldType: field.type });
173
157
  }
174
158
  return value;
@@ -445,11 +429,6 @@ const referenceFieldPartialSchema = Joi.object({
445
429
  groups: Joi.array().items(validReferenceFieldGroups)
446
430
  });
447
431
 
448
- const crossReferenceFieldPartialSchema = Joi.object({
449
- type: Joi.string().valid('cross-reference').required(),
450
- models: Joi.array().items(validCrossReferenceModelNames).required()
451
- });
452
-
453
432
  const listItemsSchema = Joi.object({
454
433
  // 'style' and 'list' are not allowed inside lists
455
434
  type: Joi.string()
@@ -462,8 +441,7 @@ const listItemsSchema = Joi.object({
462
441
  { is: 'image', then: imageFieldPartialSchema },
463
442
  { is: 'object', then: objectFieldPartialSchema },
464
443
  { is: 'model', then: modelFieldPartialSchema },
465
- { is: 'reference', then: referenceFieldPartialSchema },
466
- { is: 'cross-reference', then: crossReferenceFieldPartialSchema },
444
+ { is: 'reference', then: referenceFieldPartialSchema }
467
445
  ]
468
446
  });
469
447
 
@@ -489,7 +467,6 @@ const fieldSchema: Joi.ObjectSchema<Field> = fieldCommonPropsSchema.when('.type'
489
467
  { is: 'object', then: objectFieldPartialSchema },
490
468
  { is: 'model', then: modelFieldPartialSchema },
491
469
  { is: 'reference', then: referenceFieldPartialSchema },
492
- { is: 'cross-reference', then: crossReferenceFieldPartialSchema },
493
470
  { is: 'style', then: styleFieldPartialSchema },
494
471
  { is: 'list', then: listFieldPartialSchema }
495
472
  ]
@@ -54,7 +54,6 @@ export {
54
54
  FieldGroupItem,
55
55
  FieldModelProps,
56
56
  FieldReferenceProps,
57
- FieldCrossReferenceProps,
58
57
  StyleProps,
59
58
  FieldStyleProps,
60
59
  FieldListProps,
@@ -21,7 +21,6 @@ import {
21
21
  Model,
22
22
  StyleProps
23
23
  } from '../config/config-types';
24
- import { FieldCrossReferenceProps } from '@stackbit/types';
25
24
 
26
25
  type FieldPath = (string | number)[];
27
26
 
@@ -148,9 +147,6 @@ function joiSchemaForField(field: Field | FieldListItems, config: Config, fieldP
148
147
  case 'reference':
149
148
  fieldSchema = referenceFieldValueSchema(field);
150
149
  break;
151
- case 'cross-reference':
152
- fieldSchema = crossReferenceFieldValueSchema(field);
153
- break;
154
150
  case 'style':
155
151
  fieldSchema = styleFieldValueSchema(field);
156
152
  break;
@@ -254,17 +250,6 @@ function referenceFieldValueSchema(field: FieldReferenceProps): Joi.Schema {
254
250
  return Joi.string();
255
251
  }
256
252
 
257
- function crossReferenceFieldValueSchema(field: FieldCrossReferenceProps): Joi.Schema {
258
- return Joi.alternatives().try(
259
- Joi.string(),
260
- Joi.object({
261
- srcType: Joi.string(),
262
- srcProjectId: Joi.string(),
263
- srcDocumentId: Joi.string()
264
- })
265
- );
266
- }
267
-
268
253
  function listFieldValueSchema(field: FieldListProps, config: Config, fieldPath: FieldPath): Joi.Schema {
269
254
  if (field.items) {
270
255
  const childFieldPath = fieldPath.concat('items');
@@ -14,16 +14,19 @@ import {
14
14
  YamlDataModelList,
15
15
  Field,
16
16
  FieldSpecificProps,
17
+ FieldEnum,
17
18
  FieldEnumProps,
18
19
  FieldList,
19
20
  FieldListItems,
20
21
  FieldListModel,
21
22
  FieldListObject,
22
23
  FieldListReference,
24
+ FieldModel,
23
25
  FieldModelProps,
26
+ FieldObject,
24
27
  FieldObjectProps,
28
+ FieldReference,
25
29
  FieldReferenceProps,
26
- FieldCrossReferenceProps,
27
30
  DataModelList,
28
31
  FieldListProps
29
32
  } from '../config/config-types';
@@ -75,10 +78,6 @@ export function isReferenceField(field: FieldSpecificProps): field is FieldRefer
75
78
  return field.type === 'reference';
76
79
  }
77
80
 
78
- export function isCrossReferenceField(field: FieldSpecificProps): field is FieldCrossReferenceProps {
79
- return field.type === 'cross-reference';
80
- }
81
-
82
81
  export function isCustomModelField(field: FieldSpecificProps, modelsByName: Record<string, Model>) {
83
82
  // custom model field types are deprecated
84
83
  return !FIELD_TYPES.includes(field.type) && _.has(modelsByName, field.type);