Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (typeof polymorphic == 'object') {
selector = polymorphic.selector || polymorphic.as;
}
// relationName is eventually used as selector if provided and selector not already defined
// it ultimately defaults to 'reference'
selector = selector || relationName || 'reference';
// make sure polymorphic is an object
if (typeof polymorphic !== 'object') {
polymorphic = {};
}
polymorphic.selector = selector;
polymorphic.foreignKey = polymorphic.foreignKey || i8n.camelize(selector + '_id', true); // defaults to {{selector}}Id
polymorphic.discriminator = polymorphic.discriminator || i8n.camelize(selector + '_type', true); // defaults to {{selectorName}}Type
return polymorphic;
}
dissect : function(model)
{
this.nameSingular = inflection.singularize(model.name.toLowerCase());
this.namePlural = inflection.pluralize(model.name.toLowerCase());
this.nameSingularCap = inflection.camelize(this.nameSingular);
this.namePluralCap = inflection.camelize(this.namePlural);
this.fields = model.fields;
var path = "./controllers/" + this.nameSingular + ".js";
if(fs.existsSync(path) && !this.scaffold.config.overwrite)
{
this.scaffold.message('Controller \'' + this.nameSingular + '\' already exists! Use --force-overwrite or -F', ct.MSG_FAILED);
}
else
{
var buf;
switch(this.scaffold.config.httpFramework)
{
case ct.HF_EXPRESS:
.pipe(str => camelize(str, true))
.value()
export const getTypeFromKey = key => camelize(singularize(key));
static addUserScope(scope) {
const currentMethodName = `current${inflection.camelize(scope)}`
ApiMakerDevise[currentMethodName] = function() {
return ApiMakerDevise.current().getCurrentScope(scope)
}
const isSignedInMethodName = `is${inflection.camelize(scope)}SignedIn`
ApiMakerDevise[isSignedInMethodName] = function() {
if (ApiMakerDevise.current().getCurrentScope(scope)) {
return true
}
return false
}
}
function getName (name) {
name = name.toLowerCase()
name = inflection.dasherize(name).replace(/-/g, '_')
name = inflection.camelize(name, true)
return name
}
.pipe(str => camelize(str, true))
.value()
type: typesByName[type.name],
args: {
id: { type: new GraphQLNonNull(GraphQLID) },
},
};
fields[`all${camelize(pluralize(type.name))}`] = {
type: new GraphQLList(typesByName[type.name]),
args: {
page: { type: GraphQLInt },
perPage: { type: GraphQLInt },
sortField: { type: GraphQLString },
sortOrder: { type: GraphQLString },
filter: { type: filterTypesByName[type.name] },
},
};
fields[`_all${camelize(pluralize(type.name))}Meta`] = {
type: listMetadataType,
args: {
page: { type: GraphQLInt },
perPage: { type: GraphQLInt },
filter: { type: filterTypesByName[type.name] },
},
};
return fields;
}, {}),
});
static addUserScope(scope) {
const currentMethodName = `current${inflection.camelize(scope)}`
ApiMakerDevise[currentMethodName] = function() {
return ApiMakerDevise.current().getCurrentScope(scope)
}
const isSignedInMethodName = `is${inflection.camelize(scope)}SignedIn`
ApiMakerDevise[isSignedInMethodName] = function() {
if (ApiMakerDevise.current().getCurrentScope(scope)) {
return true
}
return false
}
}
underscore(update[reservedKeys.type]),
typeInflections[0]), recordTypes) :
update[reservedKeys.type]
if (!ids.some(matchId.bind(this, update)))
throw new ConflictError('Invalid ID.')
if (updateType !== type)
throw new ConflictError('Incorrect type.')
if (reservedKeys.attributes in update)
for (let field in update[reservedKeys.attributes]) {
const value = update[reservedKeys.attributes][field]
if (inflectKeys)
field = inflection.camelize(underscore(field), true)
const fieldDefinition = fields[field] || {}
const fieldType = fieldDefinition[keys.type]
replace[field] = Array.isArray(value) ?
value.map(cast(fieldType, options)) :
castValue(value, fieldType, options)
}
if (reservedKeys.relationships in update)
for (let field of Object.keys(update[reservedKeys.relationships])) {
const value = update[reservedKeys.relationships][field]
if (inflectKeys)
field = inflection.camelize(underscore(field), true)