ember-native-class-codemod icon indicating copy to clipboard operation
ember-native-class-codemod copied to clipboard

Ember Data not working correctly

Open pzuraq opened this issue 6 years ago • 5 comments

The following file did not transform, and all of the properties seemed to trigger errors:

import { computed } from '@ember/object';
import { gt } from '@ember/object/computed';
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany, belongsTo } from 'ember-data/relationships';
import moment from 'moment';

export default Model.extend({
  isAddon: true,
  name: attr('string'),
  description: attr('string'),
  repositoryUrl: attr('string'),
  latestVersionDate: attr('date'),
  publishedDate: attr('date'),
  license: attr('string'),
  isDeprecated: attr('boolean'),
  note: attr('string'),
  isOfficial: attr('boolean'),
  isCliDependency: attr('boolean'),
  isHidden: attr('boolean'),
  hasInvalidGithubRepo: attr('boolean'),
  score: attr('number'),
  ranking: attr('number'),
  githubUsers: hasMany('github-user'),
  lastMonthDownloads: attr('number'),
  isWip: attr('boolean'),
  isTopDownloaded: attr('boolean'),
  isTopStarred: attr('boolean'),
  demoUrl: attr('string'),
  updatedAt: attr('date'),
  githubStats: belongsTo('github-stats', { async: true }),
  latestAddonVersion: belongsTo('version', { async: true }),
  latestReview: belongsTo('review', { async: true }),
  categories: hasMany('category', { async: true }),
  keywords: hasMany('keyword', { async: true }),
  versions: hasMany('version', { async: true }),
  maintainers: hasMany('maintainer', { async: true }),
  readme: belongsTo('readme', { async: true }),
  hasMoreThan1Contributor: gt('githubUsers.length', 1),
  npmUrl: computed('name', function() {
    return `https://www.npmjs.com/package/${this.get('name')}`;
  }),
  isNewAddon: computed('publishedDate', function() {
    return moment(this.get('publishedDate')).isAfter(moment().subtract(2, 'weeks'));
  })
});

pzuraq avatar Jan 30 '19 17:01 pzuraq

What are the errors? Ideally it should skip the file because the codmods do not handle ember-data https://github.com/ember-codemods/ember-es6-class-codemod#unsupported-types

ssutar avatar Feb 05 '19 07:02 ssutar

Right, the codemod should handle Ember Data since we have decorators for model attributes and relationships.

pzuraq avatar Feb 05 '19 15:02 pzuraq

Yes, but I think thats the decision we took before starting. I think a new codemod ember-data should be created under ember-es6-class-codemod to handle the model attributes and relationships

ssutar avatar Feb 05 '19 17:02 ssutar

I think #72 may help give some context here, we can now wrap all non-standard macros so we can transform classes we previously could not. In the future, this won't even be necessary - once https://github.com/emberjs/ember.js/pull/17548 lands and decorators are supported in Ember itself, all current computed property macros will be decorators, so we can remove any wrapComputed calls.

In the meantime though, it is probably not ideal to have ember-data macros be wrapped each time, so I think we should add them to the transform.

pzuraq avatar Feb 05 '19 17:02 pzuraq

I see that Models are being converted in the current version but the attr transforms and options are removed from the decorators.

Never mind, I was using ember-es6-class-codemod. This works correctly in ember-native-class-codemod.

I think It is confusing when there are two different codemods that do effectively the same thing. One should be marked as deprecated.

Thanks for the great work on this

maxwondercorn avatar Nov 08 '19 17:11 maxwondercorn