Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.forEach(column => {
const root = column.name.replace(FK_SUFFIX_REGEX, '');
associations.push({
from: plural(root),
to: table,
type: 'hasMany',
options: {
foreignKey: formatFieldName(column.name),
},
});
associations.push({
from: table,
to: plural(root),
type: 'belongsTo',
options: {
foreignKey: formatFieldName(column.name),
},
});
});
get plural() {
return pluralize.plural(this.name)
}
protected pluralizeModelName(model: CodeGenModel): string {
return plural(model.name);
}
requiredMutations.forEach(method => {
let resourceType = model.type;
if (method.includes('Many')) {
resourceType = plural(resourceType);
}
if (!remote.mutation[`${method}${resourceType}`]) {
throw new Error(
`Missing ${method}${resourceType} mutation in remote schema!`
);
}
});
});
function transformWord(word, toSingular) {
if (pluralize.isPlural(word)) {
return toSingular ? pluralize.singular(word) : word;
}
else {
return toSingular ? word : pluralize.plural(word);
}
}
function optsToArray(item) {
function createConnectorEntity(targetEntity, type) {
switch (type) {
case 'many:many':
var rels = {},
properties = {};
relation = CRUD.entities[targetEntity];
rels[entity.name] = 'many:1\n';
rels[targetEntity] = '1:many\n';
var primaryA = relation.primary;
var primaryB = entity.primary;
properties[primaryA] = properties[primaryB] = int11;
var connector = {
table: pluralize.plural(entity.name) + '_' + pluralize.plural(targetEntity),
name: entity.name + '_' + targetEntity,
primary: 'ID_' + entity.name + '_' + targetEntity,
relations: rels,
properties: properties
};
return outputEntity(connector, true);
}
return targetEntity;
}
export function applyPluralization(name: string, match: string) {
if (match.startsWith('__')) return name;
const isPlural = match.endsWith('s');
return isPlural ? pluralize.plural(name) : pluralize.singular(name);
}
export function crud(options: ICrudOptions): Rule {
const name = strings.dasherize(basename(options.name as Path));
const fullName = join(dirname(options.name as Path), pluralize.plural(name));
const projectPath = options.path || '.';
const path = normalize(join(projectPath as Path, 'src/app', options.name, '..'));
return chain([
schematic('entity', options),
mergeWith(
apply(url('./files'), [
template({
...strings,
name,
fullName,
}),
formatTsFiles(),
move(path),
]),
),
updatePackageJson(projectPath),
util.altMeasurementTerms = _.union(_altMeasurementTerms, _.map(_altMeasurementTerms, function(term) {
return pluralize.plural(term);
})).sort();
public makeSyncResolver(type: string, queryTypeName: string = 'Query') {
const fieldName = graphqlName('sync' + toUpper(plural(type)));
return new AppSync.Resolver({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
DataSourceName: Fn.GetAtt(ModelResourceIDs.ModelTableDataSourceID(type), 'Name'),
FieldName: fieldName,
TypeName: queryTypeName,
RequestMappingTemplate: print(
DynamoDBMappingTemplate.syncItem({
filter: ifElse(ref('context.args.filter'), ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'), nul()),
limit: ref('util.defaultIfNull($ctx.args.limit, 100)'),
lastSync: ref('util.toJson($util.defaultIfNull($ctx.args.lastSync, null))'),
nextToken: ref('util.toJson($util.defaultIfNull($ctx.args.nextToken, null))'),
})
),
ResponseMappingTemplate: print(DynamoDBMappingTemplate.dynamoDBResponse()),
});
}