@stackbit/cms-core
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -10,2 +10,8 @@ import { Model } from '@stackbit/sdk'; | ||
export declare function getModelFieldForFieldAtPath(document: ContentStoreTypes.Document, model: Model, fieldPath: (string | number)[], modelMap: Record<string, Model>, locale?: string): Field; | ||
export declare function groupModelsByContentSource({ models }: { | ||
models: CSITypes.ModelWithSource[]; | ||
}): Record<string, Record<string, Record<string, Model>>>; | ||
export declare function groupDocumentsByContentSource({ documents }: { | ||
documents: CSITypes.DocumentWithSource[]; | ||
}): Record<string, Record<string, CSITypes.Document[]>>; | ||
//# sourceMappingURL=content-store-utils.d.ts.map |
@@ -6,4 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getModelFieldForFieldAtPath = exports.getDocumentFieldForLocale = exports.getUserContextForSrcType = exports.getContentSourceId = exports.getContentSourceIdForContentSource = void 0; | ||
exports.groupDocumentsByContentSource = exports.groupModelsByContentSource = exports.getModelFieldForFieldAtPath = exports.getDocumentFieldForLocale = exports.getUserContextForSrcType = exports.getContentSourceId = exports.getContentSourceIdForContentSource = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const utils_1 = require("@stackbit/utils"); | ||
function getContentSourceIdForContentSource(contentSource) { | ||
@@ -140,2 +141,20 @@ return getContentSourceId(contentSource.getContentSourceType(), contentSource.getProjectId()); | ||
exports.getModelFieldForFieldAtPath = getModelFieldForFieldAtPath; | ||
function groupModelsByContentSource({ models }) { | ||
const modelMapByContentSource = {}; | ||
for (const model of models) { | ||
const { srcType, srcProjectId, ...rest } = model; | ||
lodash_1.default.set(modelMapByContentSource, [srcType, srcProjectId, model.name], rest); | ||
} | ||
return modelMapByContentSource; | ||
} | ||
exports.groupModelsByContentSource = groupModelsByContentSource; | ||
function groupDocumentsByContentSource({ documents }) { | ||
const documentMapByContentSource = {}; | ||
for (const document of documents) { | ||
const { srcType, srcProjectId, ...rest } = document; | ||
(0, utils_1.append)(documentMapByContentSource, [srcType, srcProjectId], rest); | ||
} | ||
return documentMapByContentSource; | ||
} | ||
exports.groupDocumentsByContentSource = groupDocumentsByContentSource; | ||
//# sourceMappingURL=content-store-utils.js.map |
import { UserCommandSpawner } from '@stackbit/types'; | ||
import { Config, Model } from '@stackbit/sdk'; | ||
import { Config, Model, ImageModel, PresetMap } from '@stackbit/sdk'; | ||
import * as ContentStoreTypes from './content-store-types'; | ||
import { SearchFilter } from './types/search-filter'; | ||
export declare type HandleConfigAssets = <T extends Model>({ models, presets }: { | ||
models?: T[]; | ||
presets?: PresetMap; | ||
}) => Promise<{ | ||
models: T[]; | ||
presets: PresetMap; | ||
}>; | ||
export interface ContentSourceOptions { | ||
@@ -13,3 +20,3 @@ logger: ContentStoreTypes.Logger; | ||
onContentChangeCallback: (contentChanges: ContentStoreTypes.ContentChangeResult) => void; | ||
handleConfigAssets: (config: Config) => Promise<Config>; | ||
handleConfigAssets: HandleConfigAssets; | ||
devAppRestartNeeded?: () => void; | ||
@@ -30,4 +37,6 @@ } | ||
private contentUpdatesWatchTimer; | ||
private rawStackbitConfig; | ||
private presets?; | ||
private stackbitConfig; | ||
private yamlModels; | ||
private configModels; | ||
private presets; | ||
constructor(options: ContentSourceOptions); | ||
@@ -43,3 +52,7 @@ init({ stackbitConfig }: { | ||
* This method is called when contentUpdatesWatchTimer receives timeout. | ||
* It then notifies all content sources to stop watching for content changes. | ||
* This happens when the user is not using the Stackbit app for some time | ||
* but container is not hibernated. | ||
* It then notifies all content sources to stop watching for content | ||
* changes, which in turn stops polling CMS for content changes and helps | ||
* reducing the CMS API usage. | ||
*/ | ||
@@ -69,6 +82,11 @@ private handleTimerTimeout; | ||
}>; | ||
private loadContentSources; | ||
private loadYamlModels; | ||
private mergeConfigModels; | ||
private loadPresets; | ||
private loadAllContentSourcesAndProcessData; | ||
private reloadContentSourcesByIdAndProcessData; | ||
private loadContentSourceData; | ||
private onContentChange; | ||
getModels(): Record<string, Record<string, Record<string, Model>>>; | ||
private processData; | ||
getModels(): Record<string, Record<string, Record<string, Model | ImageModel>>>; | ||
getLocales(): string[]; | ||
@@ -75,0 +93,0 @@ getPresets(): Record<string, any>; |
@@ -10,3 +10,3 @@ "use strict"; | ||
function fetchAndConvertSchema(options) { | ||
return (0, sdk_1.loadConfig)({ dirPath: options.dirPath }).then(({ config, errors }) => { | ||
return (0, sdk_1.loadConfigWithModelsPresetsAndValidate)({ dirPath: options.dirPath }).then(({ config, errors }) => { | ||
if (!config) { | ||
@@ -13,0 +13,0 @@ return { schema: {}, errors }; |
@@ -1,5 +0,5 @@ | ||
import { Model } from '@stackbit/sdk'; | ||
import { ImageModel, Model } from '@stackbit/sdk'; | ||
import { SearchFilter } from '../types/search-filter'; | ||
import { ContentStoreTypes } from '..'; | ||
declare type Schema = Record<string, Record<string, Record<string, Model>>>; | ||
declare type Schema = Record<string, Record<string, Record<string, Model | ImageModel>>>; | ||
export declare const searchDocuments: (data: { | ||
@@ -6,0 +6,0 @@ query?: string; |
@@ -117,3 +117,3 @@ "use strict"; | ||
const model = (_b = (_a = schema === null || schema === void 0 ? void 0 : schema[document.srcType]) === null || _a === void 0 ? void 0 : _a[document.srcProjectId]) === null || _b === void 0 ? void 0 : _b[document.srcModelName]; | ||
if (!model) { | ||
if (!model || model.type === 'image') { | ||
throw new Error(`Can't find model for the ${filter.field}`); | ||
@@ -120,0 +120,0 @@ } |
{ | ||
"name": "@stackbit/cms-core", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "stackbit-dev", | ||
@@ -32,4 +32,4 @@ "main": "dist/index.js", | ||
"@iarna/toml": "^2.2.3", | ||
"@stackbit/sdk": "^0.3.5", | ||
"@stackbit/types": "^0.1.3", | ||
"@stackbit/sdk": "^0.3.6", | ||
"@stackbit/types": "^0.1.4", | ||
"@stackbit/utils": "^0.2.10", | ||
@@ -49,3 +49,3 @@ "chalk": "^4.0.1", | ||
}, | ||
"gitHead": "88cad3911fc80f3241d96daea898c0bea69d59ce" | ||
"gitHead": "627eb38e1d72fe5719347701da240af8b3cc15d7" | ||
} |
import _ from 'lodash'; | ||
import { Model } from '@stackbit/sdk'; | ||
import { append } from '@stackbit/utils'; | ||
import { Field, FieldList, FieldListItems, FieldListProps, FieldObjectProps, FieldSpecificProps } from '@stackbit/types'; | ||
@@ -151,1 +152,19 @@ import * as CSITypes from '@stackbit/types'; | ||
} | ||
export function groupModelsByContentSource({ models }: { models: CSITypes.ModelWithSource[] }): Record<string, Record<string, Record<string, Model>>> { | ||
const modelMapByContentSource: Record<string, Record<string, Record<string, Model>>> = {}; | ||
for (const model of models) { | ||
const { srcType, srcProjectId, ...rest } = model; | ||
_.set(modelMapByContentSource, [srcType, srcProjectId, model.name], rest); | ||
} | ||
return modelMapByContentSource; | ||
} | ||
export function groupDocumentsByContentSource({ documents }: { documents: CSITypes.DocumentWithSource[] }): Record<string, Record<string, CSITypes.Document[]>> { | ||
const documentMapByContentSource: Record<string, Record<string, CSITypes.Document[]>> = {}; | ||
for (const document of documents) { | ||
const { srcType, srcProjectId, ...rest } = document; | ||
append(documentMapByContentSource, [srcType, srcProjectId], rest); | ||
} | ||
return documentMapByContentSource; | ||
} |
import _ from 'lodash'; | ||
import { loadConfig, isListDataModel, Config } from '@stackbit/sdk'; | ||
import { Config, isListDataModel, loadConfigWithModelsPresetsAndValidate } from '@stackbit/sdk'; | ||
export function fetchAndConvertSchema(options: { dirPath: string }): Promise<{ schema: Config; errors: Error[] }> { | ||
return loadConfig({ dirPath: options.dirPath }).then(({ config, errors }) => { | ||
return loadConfigWithModelsPresetsAndValidate({ dirPath: options.dirPath }).then(({ config, errors }) => { | ||
if (!config) { | ||
@@ -7,0 +7,0 @@ return { schema: {} as Config, errors }; |
import _ from 'lodash'; | ||
import { Field, FieldListProps, FieldModelProps, FieldObjectProps, FieldSpecificProps, Model } from '@stackbit/sdk'; | ||
import { Field, FieldListProps, FieldModelProps, FieldObjectProps, FieldSpecificProps, Model, ImageModel } from '@stackbit/sdk'; | ||
import { isLocalizedField } from '@stackbit/types'; | ||
@@ -344,3 +344,3 @@ import * as CSITypes from '@stackbit/types'; | ||
documentFields: Record<string, CSITypes.DocumentField | CSITypes.AssetFileField>, | ||
modelOrObjectField: Model | FieldObjectProps, | ||
modelOrObjectField: Model | FieldObjectProps | ImageModel, | ||
locale?: string | ||
@@ -347,0 +347,0 @@ ): string { |
import _ from 'lodash'; | ||
import { Model } from '@stackbit/sdk'; | ||
import { ImageModel, Model } from '@stackbit/sdk'; | ||
import * as ContentSourceInterface from '@stackbit/types'; | ||
@@ -18,3 +18,3 @@ import { getLocalizedFieldForLocale } from '@stackbit/types'; | ||
type Schema = Record<string, Record<string, Record<string, Model>>>; | ||
type Schema = Record<string, Record<string, Record<string, Model | ImageModel>>>; | ||
@@ -160,3 +160,3 @@ export const searchDocuments = (data: { | ||
const model = schema?.[document.srcType]?.[document.srcProjectId]?.[document.srcModelName]; | ||
if (!model) { | ||
if (!model || model.type === 'image') { | ||
throw new Error(`Can't find model for the ${filter.field}`); | ||
@@ -163,0 +163,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
Sorry, the diff of this file is too big to display
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
626532
107
10932
Updated@stackbit/sdk@^0.3.6
Updated@stackbit/types@^0.1.4