lib/config-parser.js
function handleResourceContext(attrNode, context) {
    let dataSource;
    let lastDataSourceName;

    const errorContext = context.errorContext;

    if (attrNode.resource) {
        if ('subFilters' in attrNode) {
            throw new ImplementationError(
                'Adding subFilters for included sub-resource is not allowed' + context.errorContext
            );
        }
        if ('primaryKey' in attrNode) {
            throw new ImplementationError(
                'Overwriting primaryKey for included sub-resource is not allowed' + context.errorContext
            );
        }
    } else if (!('primaryKey' in attrNode)) {
        throw new ImplementationError('Missing primaryKey' + context.errorContext);
    }

    if (attrNode.dataSources) {
        Object.keys(attrNode.dataSources).forEach(dataSourceName => {
            lastDataSourceName = dataSourceName;
            context.dataSourceAttributes[dataSourceName] = [];

            dataSource = attrNode.dataSources[dataSourceName];

            if (dataSource.inherit) {
                if (!attrNode.resource) {
                    throw new ImplementationError(
                        `DataSource "${dataSourceName}" is defined as "inherit" but has no included resource`
                    );
                }
                context.errorContext = ' in inherit' + errorContext;
                dataSource.inherit = checkWhitelist(dataSource.inherit, ['true', 'inherit', 'replace'], context);
                if (dataSource.inherit === 'true') {
                    dataSource.inherit = 'inherit';
                }
                context.errorContext = errorContext;
            }

            if (!dataSource.type && !dataSource.inherit) {
                throw new ImplementationError(
                    `DataSource "${dataSourceName}" misses "type" option${context.errorContext}`
                );
            }

            if (dataSource.joinParentKey) {
                context.errorContext = ' in joinParentKey' + errorContext;
                dataSource.joinParentKey = parsePrimaryKey(dataSource.joinParentKey, context);
                context.errorContext = errorContext;
            }

            if (dataSource.joinChildKey) {
                context.errorContext = ' in joinChildKey' + errorContext;
                dataSource.joinChildKey = parsePrimaryKey(dataSource.joinChildKey, context);
                context.errorContext = errorContext;
            }
        });
    }

    if (attrNode.joinVia) {
        if (!attrNode.dataSources[attrNode.joinVia]) {
            throw new ImplementationError(`Unknown DataSource "${attrNode.joinVia}" in joinVia` + context.errorContext);
        } else {
            dataSource = attrNode.dataSources[attrNode.joinVia];

            if (!dataSource.joinParentKey) {
                throw new ImplementationError(
                    `DataSource "${lastDataSourceName}" misses "joinParentKey" option` + context.errorContext
                );
            }

            if (!dataSource.joinChildKey) {
                throw new ImplementationError(
                    `DataSource "${lastDataSourceName}" misses "joinChildKey" option` + context.errorContext
                );
            }
        }
    }
}
function handleResourceContext(attrNode, context) {
    let dataSource;
    let lastDataSourceName;

    const errorContext = context.errorContext;

    if (attrNode.resource) {
        if ('subFilters' in attrNode) {
            throw new ImplementationError(
                'Adding subFilters for included sub-resource is not allowed' + context.errorContext
            );
        }
        if ('primaryKey' in attrNode) {
            throw new ImplementationError(
                'Overwriting primaryKey for included sub-resource is not allowed' + context.errorContext
            );
        }
    } else if (!('primaryKey' in attrNode)) {
        throw new ImplementationError('Missing primaryKey' + context.errorContext);
    }

    if (attrNode.dataSources) {
        Object.keys(attrNode.dataSources).forEach(dataSourceName => {
            lastDataSourceName = dataSourceName;
            context.dataSourceAttributes[dataSourceName] = [];

            dataSource = attrNode.dataSources[dataSourceName];

            if (dataSource.inherit) {
                if (!attrNode.resource) {
                    throw new ImplementationError(
                        `DataSource "${dataSourceName}" is defined as "inherit" but has no included resource`
                    );
                }
                context.errorContext = ' in inherit' + errorContext;
                dataSource.inherit = checkWhitelist(dataSource.inherit, ['true', 'inherit', 'replace'], context);
                if (dataSource.inherit === 'true') {
                    dataSource.inherit = 'inherit';
                }
                context.errorContext = errorContext;
            }

            if (!dataSource.type && !dataSource.inherit) {
                throw new ImplementationError(
                    `DataSource "${dataSourceName}" misses "type" option${context.errorContext}`
                );
            }

            if (dataSource.joinParentKey) {
                context.errorContext = ' in joinParentKey' + errorContext;
                dataSource.joinParentKey = parsePrimaryKey(dataSource.joinParentKey, context);
                context.errorContext = errorContext;
            }

            if (dataSource.joinChildKey) {
                context.errorContext = ' in joinChildKey' + errorContext;
                dataSource.joinChildKey = parsePrimaryKey(dataSource.joinChildKey, context);
                context.errorContext = errorContext;
            }
        });
    }

    if (attrNode.joinVia) {
        if (!attrNode.dataSources[attrNode.joinVia]) {
            throw new ImplementationError(`Unknown DataSource "${attrNode.joinVia}" in joinVia` + context.errorContext);
        } else {
            dataSource = attrNode.dataSources[attrNode.joinVia];

            if (!dataSource.joinParentKey) {
                throw new ImplementationError(
                    `DataSource "${lastDataSourceName}" misses "joinParentKey" option` + context.errorContext
                );
            }

            if (!dataSource.joinChildKey) {
                throw new ImplementationError(
                    `DataSource "${lastDataSourceName}" misses "joinChildKey" option` + context.errorContext
                );
            }
        }
    }
}
function handleResourceContext ( attrNode , context ) { let dataSource ; let lastDataSourceName ; const errorContext = context . errorContext ; if ( attrNode . resource ) { if ( 'subFilters' in attrNode ) { throw new ImplementationError ( 'Adding subFilters for included sub-resource is not allowed' + context . errorContext ) ; } if ( 'primaryKey' in attrNode ) { throw new ImplementationError ( 'Overwriting primaryKey for included sub-resource is not allowed' + context . errorContext ) ; } } else if ( ! ( 'primaryKey' in attrNode ) ) { throw new ImplementationError ( 'Missing primaryKey' + context . errorContext ) ; } if ( attrNode . dataSources ) { Object . keys ( attrNode . dataSources ) . forEach ( dataSourceName => { lastDataSourceName = dataSourceName ; context . dataSourceAttributes [ dataSourceName ] = [ ] ; dataSource = attrNode . dataSources [ dataSourceName ] ; if ( dataSource . inherit ) { if ( ! attrNode . resource ) { throw new ImplementationError ( ` ${ dataSourceName } ` ) ; } context . errorContext = ' in inherit' + errorContext ; dataSource . inherit = checkWhitelist ( dataSource . inherit , [ 'true' , 'inherit' , 'replace' ] , context ) ; if ( dataSource . inherit === 'true' ) { dataSource . inherit = 'inherit' ; } context . errorContext = errorContext ; } if ( ! dataSource . type && ! dataSource . inherit ) { throw new ImplementationError ( ` ${ dataSourceName } ${ context . errorContext } ` ) ; } if ( dataSource . joinParentKey ) { context . errorContext = ' in joinParentKey' + errorContext ; dataSource . joinParentKey = parsePrimaryKey ( dataSource . joinParentKey , context ) ; context . errorContext = errorContext ; } if ( dataSource . joinChildKey ) { context . errorContext = ' in joinChildKey' + errorContext ; dataSource . joinChildKey = parsePrimaryKey ( dataSource . joinChildKey , context ) ; context . errorContext = errorContext ; } } ) ; } if ( attrNode . joinVia ) { if ( ! attrNode . dataSources [ attrNode . joinVia ] ) { throw new ImplementationError ( ` ${ attrNode . joinVia } ` + context . errorContext ) ; } else { dataSource = attrNode . dataSources [ attrNode . joinVia ] ; if ( ! dataSource . joinParentKey ) { throw new ImplementationError ( ` ${ lastDataSourceName } ` + context . errorContext ) ; } if ( ! dataSource . joinChildKey ) { throw new ImplementationError ( ` ${ lastDataSourceName } ` + context . errorContext ) ; } } } }
Handle special cases and checks for options in resource context.

@private
Handle special cases and checks for options in resource context .