Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getFiles(__dirname + '/../lib', function(err, dir, file) {
let jsFileBase = path.basename(file, path.extname(file)); // Ex: m2o-relation, column etc.
let title = conversion[jsFileBase] || inflection.titleize(jsFileBase); // Ex: M2O Relation, Column etc.
let base = inflection.classify(title.replace(/\s/g, '')); // Ex: M2ORelation, Column etc.
if (dir.match(/util$/) || path.extname(file) !== '.js') return; // Skip util directory and non js files.
// Add page to YAML config.
let configLine = {};
configLine[title] = path.join('api', `${base}.md`);
apiPagesConfig.push(configLine);
let source = path.join(dir, file);
let target = path.join(mdBase, 'api', `${base}.md`);
exec(`jsdoc2md ${source} > ${target}`, puts);
});
args.forEach( function ( arg ){
var tmp = lib.valid_model_prop_name( arg ).split( ':' );
var prop = tmp[ 0 ];
var title = inflection.classify( prop );
code = self._html_show_partial( code, singular, title, prop );
});
getTypeName() {
return `${this.listKey}${inflection.classify(this.path)}Type`;
}
getGqlAuxTypes() {
async fetchOptionData (fieldName) {
const { resource, text, value = '_id' } = this.constructor.fields[fieldName].ajaxOptions
const modelName = inflection.classify(resource)
const ret = await use(`App/Models/${modelName}`).fetchOptions(value, text, {
_id: { $in: this[fieldName] }
}, 1000)
return ret
}
models() {
const preloaded = new Preloaded(this.response)
const models = []
for(const modelType in this.response.data) {
const modelClassName = inflection.classify(modelType.replace(/-/g, "_"))
const modelClass = digg(require("api-maker/models"), modelClassName)
const collectionName = inflection.dasherize(modelClass.modelClassData().collectionName)
for(const modelId of this.response.data[modelType]) {
const modelData = this.response.preloaded[collectionName][modelId]
if (!modelData)
throw new Error(`Couldn't find model data for ${collectionName}(${modelId})`)
const model = new modelClass({
collection: this.collection,
data: modelData,
isNewRecord: false
})
model._readPreloadedRelationships(preloaded)
loadPreloadedModels() {
this.preloaded = {}
for(const preloadedType in this.response.preloaded) {
const modelClassName = inflection.classify(preloadedType.replace(/-/g, "_"))
const modelClass = digg(require("api-maker/models"), modelClassName)
for(const preloadedId in this.response.preloaded[preloadedType]) {
const preloadedData = this.response.preloaded[preloadedType][preloadedId]
const model = new modelClass({data: preloadedData, isNewRecord: false})
if (!this.preloaded[preloadedType])
this.preloaded[preloadedType] = {}
this.preloaded[preloadedType][preloadedId] = model
}
}
for(const modelType in this.preloaded) {
for(const modelId in this.preloaded[modelType]) {
this.preloaded[modelType][modelId]._readPreloadedRelationships(this)
Object.keys(models).forEach(function(key) {
if (key === 'index') {
return;
}
var modelName = inflection.classify(key);
var modelInstance = sequelize.import(modelName , function(sequelize, DataTypes) {
var definition = [modelName].concat(models[key](DataTypes));
return sequelize.define.apply(sequelize, definition);
});
self[modelName] = modelInstance;
});
valid_model_name : function ( model ){
return inflection.classify( _.valid_name( model, regex.has_none_characters ));
},