@stackbit/sdk
Advanced tools
Comparing version 0.2.28 to 0.2.29
@@ -326,3 +326,2 @@ "use strict"; | ||
const gitCMS = isGitCMS(config); | ||
let referencedModelNames = []; | ||
lodash_1.default.forEach(models, (model, modelName) => { | ||
@@ -349,4 +348,2 @@ if (!model) { | ||
addMarkdownContentField(model); | ||
// TODO: update schema-editor to not show layout field | ||
addLayoutFieldToPageModel(model, pageLayoutKey); | ||
} | ||
@@ -357,2 +354,13 @@ } | ||
} | ||
if (gitCMS) { | ||
// TODO: do not add pageLayoutKey and objectTypeKey fields to models, | ||
// The content validator should always assume these fields. | ||
// And when new objects created from UI, it should add these fields automatically. | ||
if (utils_1.isPageModel(model)) { | ||
addLayoutFieldToPageModel(model, pageLayoutKey, modelName); | ||
} | ||
else if (utils_1.isDataModel(model) && !utils_1.isListDataModel(model)) { | ||
addObjectTypeKeyField(model, objectTypeKey, modelName); | ||
} | ||
} | ||
if (utils_1.isListDataModel(model)) { | ||
@@ -411,18 +419,4 @@ // 'items.type' of list model defaults to 'string', set it explicitly | ||
} | ||
if (gitCMS) { | ||
referencedModelNames = lodash_1.default.union(referencedModelNames, getReferencedModelNames(field)); | ||
} | ||
}); | ||
}); | ||
lodash_1.default.forEach(referencedModelNames, (modelName) => { | ||
const model = models[modelName]; | ||
// don't add objectTypeKey to page models, they have pageLayoutKey | ||
if (!model || model.type === 'page') { | ||
return; | ||
} | ||
// TODO: update schema-editor to not show type field | ||
// TODO: do not add objectTypeKey field to models, API/container should | ||
// be able to add it automatically when data object or polymorphic nested model is added | ||
addObjectTypeKeyField(model, objectTypeKey, modelName); | ||
}); | ||
return config; | ||
@@ -497,3 +491,6 @@ } | ||
} | ||
function addLayoutFieldToPageModel(model, pageLayoutKey) { | ||
function addLayoutFieldToPageModel(model, pageLayoutKey, modelName) { | ||
if (lodash_1.default.intersection(lodash_1.default.keys(model), ['file', 'folder', 'match', 'exclude']).length === 0 && !lodash_1.default.get(model, 'layout')) { | ||
model.layout = modelName; | ||
} | ||
const modelLayout = lodash_1.default.get(model, 'layout'); | ||
@@ -500,0 +497,0 @@ if (!modelLayout) { |
@@ -16,4 +16,4 @@ "use strict"; | ||
const value = lodash_1.default.map(contentItems, (contentItem) => { | ||
var _a; | ||
const modelName = contentItem.__metadata.modelName; | ||
var _a, _b; | ||
const modelName = (_a = contentItem.__metadata) === null || _a === void 0 ? void 0 : _a.modelName; | ||
if (!modelName) { | ||
@@ -48,4 +48,4 @@ return contentItem; | ||
} | ||
else if (utils_1.isDataModel(model)) { | ||
const objectTypeKey = config.objectTypeKey || 'layout'; | ||
else if (utils_1.isDataModel(model) && !utils_1.isListDataModel(model)) { | ||
const objectTypeKey = config.objectTypeKey || 'type'; | ||
if (!lodash_1.default.find(model.fields, { name: objectTypeKey })) { | ||
@@ -63,3 +63,3 @@ modelSchema = modelSchema.keys({ [objectTypeKey]: joi_1.default.string().valid(model.name) }); | ||
const validationResult = modelSchema.validate(contentItem, validationOptions); | ||
const validationErrors = (_a = validationResult.error) === null || _a === void 0 ? void 0 : _a.details.map((validationError) => { | ||
const validationErrors = (_b = validationResult.error) === null || _b === void 0 ? void 0 : _b.details.map((validationError) => { | ||
var _a; | ||
@@ -66,0 +66,0 @@ return new content_errors_1.ContentValidationError({ |
@@ -64,3 +64,3 @@ "use strict"; | ||
else if (objectType && lodash_1.default.has(model, modelTypeKeyPath)) { | ||
modelGroups.byLayout.push(model); | ||
modelGroups.byType.push(model); | ||
} | ||
@@ -73,3 +73,3 @@ else { | ||
byFile: [], | ||
byLayout: [], | ||
byType: [], | ||
byGlob: [] | ||
@@ -91,8 +91,8 @@ }); | ||
} | ||
const layoutMatchedModels = lodash_1.default.filter(modelMatchGroups.byLayout, (model) => { | ||
const typeMatchedModels = lodash_1.default.filter(modelMatchGroups.byType, (model) => { | ||
const modelType = lodash_1.default.get(model, modelTypeKeyPath); | ||
return objectType === modelType; | ||
}); | ||
if (!lodash_1.default.isEmpty(layoutMatchedModels)) { | ||
return layoutMatchedModels; | ||
if (!lodash_1.default.isEmpty(typeMatchedModels)) { | ||
return typeMatchedModels; | ||
} | ||
@@ -99,0 +99,0 @@ return lodash_1.default.filter(modelMatchGroups.byGlob, (model) => { |
{ | ||
"name": "@stackbit/sdk", | ||
"version": "0.2.28", | ||
"version": "0.2.29", | ||
"description": "Stackbit SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -401,3 +401,2 @@ import path from 'path'; | ||
const gitCMS = isGitCMS(config); | ||
let referencedModelNames: string[] = []; | ||
@@ -431,5 +430,2 @@ _.forEach(models, (model, modelName) => { | ||
addMarkdownContentField(model); | ||
// TODO: update schema-editor to not show layout field | ||
addLayoutFieldToPageModel(model, pageLayoutKey); | ||
} | ||
@@ -440,2 +436,13 @@ } else if (isDataModel(model) && gitCMS) { | ||
if (gitCMS) { | ||
// TODO: do not add pageLayoutKey and objectTypeKey fields to models, | ||
// The content validator should always assume these fields. | ||
// And when new objects created from UI, it should add these fields automatically. | ||
if (isPageModel(model)) { | ||
addLayoutFieldToPageModel(model, pageLayoutKey, modelName); | ||
} else if (isDataModel(model) && !isListDataModel(model)) { | ||
addObjectTypeKeyField(model, objectTypeKey, modelName); | ||
} | ||
} | ||
if (isListDataModel(model)) { | ||
@@ -494,22 +501,5 @@ // 'items.type' of list model defaults to 'string', set it explicitly | ||
} | ||
if (gitCMS) { | ||
referencedModelNames = _.union(referencedModelNames, getReferencedModelNames(field)); | ||
} | ||
}); | ||
}); | ||
_.forEach(referencedModelNames, (modelName) => { | ||
const model = models[modelName]; | ||
// don't add objectTypeKey to page models, they have pageLayoutKey | ||
if (!model || model.type === 'page') { | ||
return; | ||
} | ||
// TODO: update schema-editor to not show type field | ||
// TODO: do not add objectTypeKey field to models, API/container should | ||
// be able to add it automatically when data object or polymorphic nested model is added | ||
addObjectTypeKeyField(model, objectTypeKey, modelName); | ||
}); | ||
return config; | ||
@@ -581,3 +571,6 @@ } | ||
function addLayoutFieldToPageModel(model: any, pageLayoutKey: any) { | ||
function addLayoutFieldToPageModel(model: any, pageLayoutKey: any, modelName: string) { | ||
if (_.intersection(_.keys(model), ['file', 'folder', 'match', 'exclude']).length === 0 && !_.get(model, 'layout')) { | ||
model.layout = modelName; | ||
} | ||
const modelLayout = _.get(model, 'layout'); | ||
@@ -584,0 +577,0 @@ if (!modelLayout) { |
@@ -7,3 +7,3 @@ import Joi from 'joi'; | ||
import { ContentValidationError } from './content-errors'; | ||
import { getModelByName, isConfigModel, isDataModel, isPageModel } from '../utils'; | ||
import { getModelByName, isConfigModel, isDataModel, isListDataModel, isPageModel } from '../utils'; | ||
import { Config } from '../config/config-types'; | ||
@@ -30,3 +30,3 @@ | ||
(contentItem): ContentItem => { | ||
const modelName = contentItem.__metadata.modelName; | ||
const modelName = contentItem.__metadata?.modelName; | ||
if (!modelName) { | ||
@@ -60,4 +60,4 @@ return contentItem; | ||
} | ||
} else if (isDataModel(model)) { | ||
const objectTypeKey = config.objectTypeKey || 'layout'; | ||
} else if (isDataModel(model) && !isListDataModel(model)) { | ||
const objectTypeKey = config.objectTypeKey || 'type'; | ||
if (!_.find(model.fields, { name: objectTypeKey })) { | ||
@@ -64,0 +64,0 @@ modelSchema = modelSchema.keys({ [objectTypeKey]: Joi.string().valid(model.name) }); |
@@ -72,3 +72,3 @@ import micromatch from 'micromatch'; | ||
byFile: Model[]; | ||
byLayout: Model[]; | ||
byType: Model[]; | ||
byGlob: Model[]; | ||
@@ -81,3 +81,3 @@ }, | ||
} else if (objectType && _.has(model, modelTypeKeyPath)) { | ||
modelGroups.byLayout.push(model); | ||
modelGroups.byType.push(model); | ||
} else { | ||
@@ -90,3 +90,3 @@ modelGroups.byGlob.push(model); | ||
byFile: [], | ||
byLayout: [], | ||
byType: [], | ||
byGlob: [] | ||
@@ -111,3 +111,3 @@ } | ||
const layoutMatchedModels = _.filter(modelMatchGroups.byLayout, (model) => { | ||
const typeMatchedModels = _.filter(modelMatchGroups.byType, (model) => { | ||
const modelType = _.get(model, modelTypeKeyPath); | ||
@@ -117,4 +117,4 @@ return objectType === modelType; | ||
if (!_.isEmpty(layoutMatchedModels)) { | ||
return layoutMatchedModels; | ||
if (!_.isEmpty(typeMatchedModels)) { | ||
return typeMatchedModels; | ||
} | ||
@@ -121,0 +121,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
765928
110
13723