Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const idField = relatedModel.fields.id;
if (!idField) {
throw new Error(
`ID_FIELD_NOT_FOUND ${modelName}/${relationName}/${relatedModelName}`
);
}
relation.type = idField.type;
// Create inverse relation, if needed
const { inverse } = relation;
if (inverse !== false) {
let inverseRelation =
inverse == null || inverse === true
? {} // inverse shorthand
: omit(clone(inverse), ['name']);
inverseRelation = addDefaults(inverseRelation, {
model: modelName,
isPlural: true,
isInverse: true,
inverseName: relationName,
});
const idField2 = models[modelName].fields.id;
inverseRelation.type = idField2 ? idField2.type : undefined;
const { isPlural: isInversePlural } = inverseRelation;
const inverseName =
(inverse && inverse.name) ||
(isInversePlural ? pluralize(modelName) : modelName);
const inverseFkName = getFkName(
inverseName,
isInversePlural != null ? isInversePlural : true
);
inverseRelation.fkName = inverseFkName;
const $ = (root, options0, fnMatch0) => {
let options = options0;
let fnMatch = fnMatch0;
if (_.isFunction(options0) || _.isString(options0)) {
options = {};
fnMatch = options0;
}
options = addDefaults(options, {
fIncludeTextElements: false,
fLog: false,
});
if (_.isString(fnMatch)) fnMatch = getMatcher(fnMatch);
return visitElement(root, options, fnMatch);
};
export const buildLogRecord = (options = {}) => addDefaults(options, {
id: 'id1',
hubId: 'hubId1',
version: 3,
fStory: false,
fServer: false,
storyId: 'story1',
t: 0,
src: 'main',
level: 30,
msg: 'Example message',
});
const $ = (root, options0, fnMatch0) => {
let options = options0;
let fnMatch = fnMatch0;
if (isFunction(options0) || isString(options0)) {
options = {};
fnMatch = options0;
}
options = addDefaults(options, {
fIncludeTextElements: false,
fLog: false,
});
if (isString(fnMatch)) fnMatch = getMatcher(fnMatch);
return visitElement(root, options, fnMatch);
};
const create = (userConfig, context) =>
new BrowserExtensionListener(addDefaults(userConfig, DEFAULT_CONFIG), context);
create.requiredCoreVersion = REQUIRED_CORE_VERSION;
const preprocess = (schema0: Schema): ProcessedSchema => {
const schema = addDefaults(cloneDeep(schema0), {
models: {},
authRules: [],
});
addModelDefaults(schema.models);
processIncludes(schema.models);
addFieldDefaults(schema.models);
processRelations(schema.models);
return schema;
};
const create = (userConfig, context) =>
new ParallelConsoleListener(addDefaults(userConfig, DEFAULT_CONFIG), context);
create.requiredCoreVersion = REQUIRED_CORE_VERSION;
function initConfig(): boolean {
_configPath = path.join(_localeDir, 'config.json');
let fMigrated = false;
try {
mainStory.info('db', `Reading file ${chalk.cyan.bold(_configPath)}...`);
fs.statSync(_configPath);
readConfig();
if (_config.dbVersion !== DB_VERSION) {
migrateDatabase(_config.dbVersion);
_config.dbVersion = DB_VERSION;
fMigrated = true;
}
_config = addDefaults(_config, DEFAULT_CONFIG);
saveConfig();
return fMigrated;
} catch (err) {
mainStory.error('db', `Error reading config: ${err.message}`, {
attach: err,
attachLevel: 'trace',
});
_config = DEFAULT_CONFIG;
saveConfig();
return fMigrated;
}
}
const create = (userConfig, context) =>
new WsClientListener(addDefaults(userConfig, DEFAULT_CONFIG), context);
create.requiredCoreVersion = REQUIRED_CORE_VERSION;