@stackbit/sdk
Version:
49 lines • 2.57 kB
TypeScript
import { Model } from '../config/config-types';
interface BaseModelQuery {
filePath: string;
}
interface TypedModelQuery extends BaseModelQuery {
type: string | null;
modelTypeKeyPath: string | string[];
}
type ModelQuery = BaseModelQuery | TypedModelQuery;
/**
* Returns a single model matching the `query` describing a content file.
* @see `getModelsByQuery()` for more info.
*
* @param {Object} query A query object to match a model against.
* @param {string} query.filePath The path of the content file relative to the `pagesDir` or `dataDir` folders defined in stackbit.yaml.
* @param {string} [query.type] The type of the data file. For example, can be page's layout that maps to page's model.
* @param {Array|string} [query.modelTypeKeyPath] Used to compare the value of `query.type` with the value of a model at `modelTypeKeyPath`.
* Required if `query.type` is provided.
* @param {Array.<Object>} models Array of stackbit.yaml `models`.
* @return {Object} stackbit.yaml model matching the `query`.
*/
export declare function getModelByQuery(query: ModelQuery, models: Model[]): {
model: Model | null;
error: Error | null;
};
/**
* Returns an array of models matching the `query` describing a content file.
*
* The `query` object is required to have the `filePath` property which is the path
* of the content file relative to the `pagesDir` or `dataDir` folders defined
* in stackbit.yaml.
*
* The `query` object might also contain the `type` and `modelTypeKeyPath`
* properties. When these properties provided, the value of the `type` is
* compared against the value of a model located at the path specified by
* `modelTypeKeyPath`. This is useful, when a folder might contain objects of
* different model types.
*
* @param {Object} query A query object to match models against.
* @param {string} query.filePath The path of the content file relative to the `pagesDir` or `dataDir` folders defined in stackbit.yaml.
* @param {string} [query.type] The type of the data file. For example, can be page's layout that maps to page's model.
* @param {Array|string} [query.modelTypeKeyPath] Used to compare the value of `query.type` with the value of a model at `modelTypeKeyPath`.
* Required if `query.type` is provided.
* @param {Array.<Object>} models Array of stackbit.yaml `models`.
* @return {Array.<Model>} Array of stackbit.yaml models matching the `query`.
*/
export declare function getModelsByQuery(query: ModelQuery, models: Model[]): Model[];
export {};
//# sourceMappingURL=model-matcher.d.ts.map