@stackbit/sdk
Advanced tools
Comparing version 0.2.26 to 0.2.27
@@ -18,6 +18,6 @@ import { ConfigError, ConfigLoadError, ConfigValidationError } from './config-errors'; | ||
export interface TempConfigLoaderResult { | ||
config?: Record<string, unknown>; | ||
config?: Record<string, any>; | ||
errors: ConfigLoadError[]; | ||
} | ||
export declare function loadConfig({ dirPath, modelsSource }: ConfigLoaderOptions): Promise<ConfigLoaderResult>; | ||
export declare function validateAndNormalizeConfig(config: any, externalModels?: Model[]): NormalizedValidationResult; | ||
export declare function validateAndNormalizeConfig(config: Record<string, any>, externalModels?: Model[]): NormalizedValidationResult; |
@@ -84,11 +84,11 @@ "use strict"; | ||
try { | ||
const { config, error } = await loadConfigFromStackbitYaml(dirPath); | ||
if (error) { | ||
return { errors: [error] }; | ||
const stackbitYamlResult = await loadConfigFromStackbitYaml(dirPath); | ||
if (stackbitYamlResult.error) { | ||
return { errors: [stackbitYamlResult.error] }; | ||
} | ||
const { models: modelsFromFiles, errors: fileModelsErrors } = await loadModelsFromFiles(dirPath, config); | ||
const mergedModels = mergeConfigModelsWithModelsFromFiles((_a = config.models) !== null && _a !== void 0 ? _a : {}, modelsFromFiles); | ||
const { models: modelsFromFiles, errors: fileModelsErrors } = await loadModelsFromFiles(dirPath, stackbitYamlResult.config); | ||
const mergedModels = mergeConfigModelsWithModelsFromFiles((_a = stackbitYamlResult.config.models) !== null && _a !== void 0 ? _a : {}, modelsFromFiles); | ||
return { | ||
config: { | ||
...config, | ||
...stackbitYamlResult.config, | ||
models: mergedModels | ||
@@ -175,5 +175,6 @@ }, | ||
async function loadModelsFromExternalSource(config, dirPath, modelsSource) { | ||
modelsSource = lodash_1.default.get(config, 'modelsSource', modelsSource); | ||
modelsSource = lodash_1.default.assign({}, modelsSource, config.modelSource); | ||
const sourceType = lodash_1.default.get(modelsSource, 'type', 'files'); | ||
if (sourceType === 'files') { | ||
// we already loaded models from files inside loadModelsFromFiles function | ||
return { models: [], errors: [] }; | ||
@@ -180,0 +181,0 @@ } |
{ | ||
"name": "@stackbit/sdk", | ||
"version": "0.2.26", | ||
"version": "0.2.27", | ||
"description": "Stackbit SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -50,3 +50,3 @@ import path from 'path'; | ||
export interface TempConfigLoaderResult { | ||
config?: Record<string, unknown>; | ||
config?: Record<string, any>; | ||
errors: ConfigLoadError[]; | ||
@@ -79,3 +79,3 @@ } | ||
export function validateAndNormalizeConfig(config: any, externalModels?: Model[]): NormalizedValidationResult { | ||
export function validateAndNormalizeConfig(config: Record<string, any>, externalModels?: Model[]): NormalizedValidationResult { | ||
// extend config models having the "extends" property | ||
@@ -114,14 +114,14 @@ // this must be done before any validation as some properties like | ||
try { | ||
const { config, error } = await loadConfigFromStackbitYaml(dirPath); | ||
if (error) { | ||
return { errors: [error] }; | ||
const stackbitYamlResult = await loadConfigFromStackbitYaml(dirPath); | ||
if (stackbitYamlResult.error) { | ||
return { errors: [stackbitYamlResult.error] }; | ||
} | ||
const { models: modelsFromFiles, errors: fileModelsErrors } = await loadModelsFromFiles(dirPath, config); | ||
const { models: modelsFromFiles, errors: fileModelsErrors } = await loadModelsFromFiles(dirPath, stackbitYamlResult.config); | ||
const mergedModels = mergeConfigModelsWithModelsFromFiles(config.models ?? {}, modelsFromFiles); | ||
const mergedModels = mergeConfigModelsWithModelsFromFiles(stackbitYamlResult.config.models ?? {}, modelsFromFiles); | ||
return { | ||
config: { | ||
...config, | ||
...stackbitYamlResult.config, | ||
models: mergedModels | ||
@@ -138,3 +138,3 @@ }, | ||
type StackbitYamlConfigResult = { config: any; error?: undefined } | { config?: undefined; error: ConfigLoadError }; | ||
type StackbitYamlConfigResult = { config: Record<string, any>; error?: never } | { config?: never; error: ConfigLoadError }; | ||
@@ -159,3 +159,3 @@ async function loadConfigFromStackbitYaml(dirPath: string): Promise<StackbitYamlConfigResult> { | ||
async function loadModelsFromFiles(dirPath: string, config: any): Promise<{ models: Record<string, any>; errors: ConfigLoadError[] }> { | ||
async function loadModelsFromFiles(dirPath: string, config: Record<string, any>): Promise<{ models: Record<string, any>; errors: ConfigLoadError[] }> { | ||
const modelsSource = _.get(config, 'modelsSource', {}); | ||
@@ -225,9 +225,10 @@ const sourceType = _.get(modelsSource, 'type', 'files'); | ||
async function loadModelsFromExternalSource( | ||
config: any, | ||
config: Record<string, any>, | ||
dirPath: string, | ||
modelsSource?: ModelsSource | ||
): Promise<{ models: Model[]; errors: ConfigLoadError[] }> { | ||
modelsSource = _.get(config, 'modelsSource', modelsSource); | ||
modelsSource = _.assign({}, modelsSource, config.modelSource); | ||
const sourceType = _.get(modelsSource, 'type', 'files'); | ||
if (sourceType === 'files') { | ||
// we already loaded models from files inside loadModelsFromFiles function | ||
return { models: [], errors: [] }; | ||
@@ -234,0 +235,0 @@ } else if (sourceType === 'contentful') { |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
771837
13730
1