Skip to content

Latest commit

 

History

History
573 lines (453 loc) · 20.9 KB

README.md

File metadata and controls

573 lines (453 loc) · 20.9 KB

em-to-ed

Usage

npx github:patocallaghan/em-to-ed-codemod em-to-ed path/of/files/ or/some**/*glob.js

Input / Output


default-values

Input (default-values.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import JsonType from 'embercom/models/types/json';

//eslint-disable-next-line intercom/no-ember-model
export default IntercomModel.extend({
  someBoolean: attr(Boolean, { defaultValue: true }),
  someString: attr(String, { defaultValue: 'user' }),
  avatar_emoji: attr(String, { defaultValue: DEFAULT_EMOJI }),
  someArray: attr(Array, { defaultValue: [] }),
  someJson: attr(JsonType, { defaultValue: {} }),
});

Output (default-values.output.js):

import DS from 'ember-data';

export default DS.Model.extend({
  someBoolean: DS.attr('boolean', { defaultValue: true }),
  someString: DS.attr('string', { defaultValue: 'user' }),
  avatar_emoji: DS.attr('string', { defaultValue: DEFAULT_EMOJI }),
  someArray: DS.attr('array', { defaultValue: () => [] }),
  someJson: DS.attr({ defaultValue: () => ({}) }),
});

ember-model-configuration

Input (ember-model-configuration.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';

export default IntercomModel.extend({
  someValue: attr(),
}).reopenClass({
  adapter: ConversationPartRESTAdapter.create(),
  camelizeKeys: true,
  collectionKey: 'conversation_parts',
  primaryKey: 'id',
  primaryKey: 'app_id',
  rootKey: '',
  url: '/ember/conversation_parts',
  urlSuffix: '.json',
});

Output (ember-model-configuration.output.js):

import DS from 'ember-data';

export default DS.Model.extend({
  someValue: DS.attr(),
}).reopenClass({
  // CODE MIGRATION HINT: This model had a custom `adapter` defined so it may contain functionality which does not come out of the box in Ember Data. Visit the docs at https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#migrating-custom-ember-model-configuration-to-ember-data to see how to address this issue.
  adapter: ConversationPartRESTAdapter.create(),

  // CODE MIGRATION HINT: This model had a `collectionKey` defined so its payload will not automatically map to Ember Data. Visit the docs at https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#migrating-custom-ember-model-configuration-to-ember-data to see how to address this issue.
  collectionKey: 'conversation_parts',

  // CODE MIGRATION HINT: This model had a custom `primaryKey` defined so you may need configure this in an Ember Data serializer. Visit the docs at https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#migrating-custom-ember-model-configuration-to-ember-data to see how to address this issue.
  primaryKey: 'app_id',

  // CODE MIGRATION HINT: This model had a custom `url` defined so its URL may not automatically map to Ember Data's. Visit the docs at https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#migrating-custom-ember-model-configuration-to-ember-data to see how to address this issue.
  url: '/ember/conversation_parts',

  // CODE MIGRATION HINT: This model had a custom `urlSuffix` defined so you may need to configure this in an Ember Data serializer. Visit the docs at https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#migrating-custom-ember-model-configuration-to-ember-data to see how to address this issue.
  urlSuffix: '.json',
});

get-ember-data-store

Input (get-ember-data-store.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { getEmberDataStore } from 'embercom/lib/container-lookup';

export default IntercomModel.extend({
  someFunction() {
    let store = getEmberDataStore();
    store.pushPayload({ 'logs-settings': [{ id: '12' }] });
  },
  solutions: computed(function() {
    let store = getEmberDataStore();

    store.pushPayload('solution', { solutions: solutionsFixture });

    return store.peekAll('solution');
  }).volatile(),
  products: attr({
    serialize(products) {
      return products.map(p => p.serialize());
    },
    deserialize(products = []) {
      let store = getEmberDataStore();

      store.pushPayload('product', { products });

      return store.peekAll('product');
    },
  }),
});

Output (get-ember-data-store.output.js):

import DS from 'ember-data';
import { getEmberDataStore } from 'embercom/lib/container-lookup';

export default DS.Model.extend({
  someFunction() {
    this.store.pushPayload({ 'logs-settings': [{ id: '12' }] });
  },
  solutions: computed(function() {
    this.store.pushPayload('solution', { solutions: solutionsFixture });

    return this.store.peekAll('solution');
  }).volatile(),
  products: DS.attr({
    // CODE MIGRATION HINT: Ember Data does not support having the serialize/deserialize hooks as part of `DS.attr`. https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#deserializeserialize.
    serialize(products) {
      return products.map(p => p.serialize());
    },
    // CODE MIGRATION HINT: Ember Data does not support having the serialize/deserialize hooks as part of `DS.attr`. https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#deserializeserialize.
    deserialize(products = []) {
      this.store.pushPayload('product', { products });

      return this.store.peekAll('product');
    },
  }),
});

get-ember-data-store__reopen-class

Input (get-ember-data-store__reopen-class.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { getEmberDataStore } from 'embercom/lib/container-lookup';

export default IntercomModel.extend({}).reopenClass({
  someFunction() {
    let store = getEmberDataStore();
    store.pushPayload({ 'logs-settings': [{ id: '12' }] });
  },
});

Output (get-ember-data-store__reopen-class.output.js):

import DS from 'ember-data';
import { getEmberDataStore } from 'embercom/lib/container-lookup';

export default DS.Model.extend({}).reopenClass({
  someFunction() {
    let store = getEmberDataStore();
    store.pushPayload({ 'logs-settings': [{ id: '12' }] });
  },
});

get-ember-data-store__reopen-class__other-usage

Input (get-ember-data-store__reopen-class__other-usage.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { getEmberDataStore } from 'embercom/lib/container-lookup';

export default IntercomModel.extend({
  otherFunction() {
    let store = getEmberDataStore();
    store.pushPayload({ 'logs-settings': [{ id: '12' }] });
  },
}).reopenClass({
  someFunction() {
    let store = getEmberDataStore();
    store.pushPayload({ 'logs-settings': [{ id: '12' }] });
  },
});

Output (get-ember-data-store__reopen-class__other-usage.output.js):

import DS from 'ember-data';
import { getEmberDataStore } from 'embercom/lib/container-lookup';

export default DS.Model.extend({
  otherFunction() {
    this.store.pushPayload({ 'logs-settings': [{ id: '12' }] });
  },
}).reopenClass({
  someFunction() {
    let store = getEmberDataStore();
    store.pushPayload({ 'logs-settings': [{ id: '12' }] });
  },
});

intercom-model

Input (intercom-model.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';

export default IntercomModel.extend({});

Output (intercom-model.output.js):

import DS from 'ember-data';

export default DS.Model.extend({});

model-attr

Input (model-attr.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { attr } from 'ember-model';

export default IntercomModel.extend({
  my_prop: attr(),
});

Output (model-attr.output.js):

import DS from 'ember-data';

export default DS.Model.extend({
  my_prop: DS.attr(),
});

model-belongs-to__keys-dont-match

Input (model-belongs-to__keys-dont-match.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { belongsTo } from 'ember-model';
import Tag from 'embercom/models/tag';
import Admin from 'embercom/models/admin';
import User from 'embercom/models/user';

export default IntercomModel.extend({
  tag: belongsTo(Tag, { key: 'tag_id', embedded: true }),
  admin: belongsTo(Admin, { key: 'admin_id', embedded: false }),
  user: belongsTo(User, { key: 'user_id' }),
});

Output (model-belongs-to__keys-dont-match.output.js):

import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
import DS from 'ember-data';
import Tag from 'embercom/models/tag';
import Admin from 'embercom/models/admin';
import User from 'embercom/models/user';

export default DS.Model.extend({
  tag_id: DS.attr('ember-model-belongs-to', { modelClass: Tag, embedded: true }),
  tag: alias('tag_id'),

  admin_id: DS.attr(),
  admin: computed('admin_id', function() {
    return Admin.find(this.admin_id);
  }),

  user_id: DS.attr(),
  user: computed('user_id', function() {
    return User.find(this.user_id);
  }),
});

model-belongs-to__keys-dont-match__existing-computed-object-imports

Input (model-belongs-to__keys-dont-match__existing-computed-object-imports.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { belongsTo } from 'ember-model';
import Tag from 'embercom/models/tag';
import Admin from 'embercom/models/admin';
import { application, computed } from '@ember/object';
import { or } from '@ember/object/computed';

export default IntercomModel.extend({
  tag: belongsTo(Tag, { key: 'tag_id', embedded: true }),
  admin: belongsTo(Admin, { key: 'admin_id', embedded: false }),
});

Output (model-belongs-to__keys-dont-match__existing-computed-object-imports.output.js):

import DS from 'ember-data';
import Tag from 'embercom/models/tag';
import Admin from 'embercom/models/admin';
import { application, computed } from '@ember/object';
import { or, alias } from '@ember/object/computed';

export default DS.Model.extend({
  tag_id: DS.attr('ember-model-belongs-to', { modelClass: Tag, embedded: true }),
  tag: alias('tag_id'),

  admin_id: DS.attr(),
  admin: computed('admin_id', function() {
    return Admin.find(this.admin_id);
  }),
});

model-belongs-to__keys-match

Input (model-belongs-to__keys-match.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { belongsTo } from 'ember-model';
import Tag from 'embercom/models/tag';
import Admin from 'embercom/models/admin';
import User from 'embercom/models/user';

export default IntercomModel.extend({
  tag: belongsTo(Tag, { key: 'tag', embedded: true }),
  admin: belongsTo(Admin, { key: 'admin', embedded: false }),
  user: belongsTo(User, { key: 'user' }),
});

Output (model-belongs-to__keys-match.output.js):

import DS from 'ember-data';
import Tag from 'embercom/models/tag';
import Admin from 'embercom/models/admin';
import User from 'embercom/models/user';

export default DS.Model.extend({
  tag: DS.attr('ember-model-belongs-to', { modelClass: Tag, embedded: true }),
  admin: DS.attr('ember-model-belongs-to', { modelClass: Admin, embedded: false }),
  user: DS.attr('ember-model-belongs-to', { modelClass: User, embedded: false }),
});

model-has-many__keys-dont-match

Input (model-has-many__keys-dont-match.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { hasMany } from 'ember-model';
import Permission from 'embercom/models/permission';
import User from 'embercom/models/user';
import Team from 'embercom/models/team';
import ExternalProfile from 'embercom/models/external-profile';

export default IntercomModel.extend({
  availablePermissions: hasMany(Permission, { key: 'available_roles', embedded: true }),
  users: hasMany(User, { key: 'user_ids', embedded: false }),
  team: hasMany(Team, { key: 'team_ids' }),
  externalProfile: hasMany(ExternalProfile),
});

Output (model-has-many__keys-dont-match.output.js):

import { alias } from '@ember/object/computed';
import DS from 'ember-data';
import Permission from 'embercom/models/permission';
import User from 'embercom/models/user';
import Team from 'embercom/models/team';
import ExternalProfile from 'embercom/models/external-profile';

export default DS.Model.extend({
  available_roles: DS.attr('ember-model-has-many', { modelClass: Permission, embedded: true }),
  availablePermissions: alias('available_roles'),

  // CODE MIGRATION HINT: This is an async Ember Model `hasMany` relationship and due to ambiguity it can't be automatically migrated. See the following docs for advice on how to migrate this relationship https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#updating-hasmany-relationships
  users: hasMany(User, { key: 'user_ids', embedded: false }),

  // CODE MIGRATION HINT: This is an async Ember Model `hasMany` relationship and due to ambiguity it can't be automatically migrated. See the following docs for advice on how to migrate this relationship https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#updating-hasmany-relationships
  team: hasMany(Team, { key: 'team_ids' }),

  // CODE MIGRATION HINT: This is an async Ember Model `hasMany` relationship and due to ambiguity it can't be automatically migrated. See the following docs for advice on how to migrate this relationship https://github.com/intercom/embercom/wiki/Converting-a-model-from-ember-model-to-ember-data#updating-hasmany-relationships
  externalProfile: hasMany(ExternalProfile),
});

model-has-many__keys-match

Input (model-has-many__keys-match.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { hasMany } from 'ember-model';
import Tag from 'embercom/models/tag';

export default IntercomModel.extend({
  tags: hasMany(Tag, { key: 'tags', embedded: true }),
});

Output (model-has-many__keys-match.output.js):

import DS from 'ember-data';
import Tag from 'embercom/models/tag';

export default DS.Model.extend({
  tags: DS.attr('ember-model-has-many', { modelClass: Tag, embedded: true }),
});

reopen-class__no-properties

Input (reopen-class__no-properties.input.js):

import PredefinedSegmentIconMap from 'embercom/models/data/predefined-segment-icon-map';
import IntercomModel from 'embercom/models/types/intercom-model';

let SegmentModel = IntercomModel.extend({}).reopenClass(PredefinedSegmentIconMap);

export default SegmentModel;

Output (reopen-class__no-properties.output.js):

import PredefinedSegmentIconMap from 'embercom/models/data/predefined-segment-icon-map';
import DS from 'ember-data';

let SegmentModel = DS.Model.extend({}).reopenClass(PredefinedSegmentIconMap);

export default SegmentModel;

reopen-class__simple-adapter

Input (reopen-class__simple-adapter.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import RestAdapter from 'embercom/models/adapters/rest-adapter';

export default IntercomModel.extend({}).reopenClass({
  adapter: RestAdapter.create(),
});

Output (reopen-class__simple-adapter.output.js):

import DS from 'ember-data';

export default DS.Model.extend({}).reopenClass({});

strip-id

Input (strip-id.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import JsonType from 'embercom/models/types/json';

export default IntercomModel.extend({
  id: attr(),
  someBoolean: attr(Boolean),
});

Output (strip-id.output.js):

import DS from 'ember-data';

export default DS.Model.extend({
  someBoolean: DS.attr('boolean'),
});

transform-types

Input (transform-types.input.js):

import IntercomModel from 'embercom/models/types/intercom-model';
import { attr } from 'ember-model';
import JsonType from 'embercom/models/types/json';

export default IntercomModel.extend({
  emptyTransform: attr(),
  someJson: attr(JsonType),
  someArray: attr(Array),
  someBoolean: attr(Boolean),
  someNumber: attr(Number),
  someString: attr(String),
});

Output (transform-types.output.js):

import DS from 'ember-data';

export default DS.Model.extend({
  emptyTransform: DS.attr(),
  someJson: DS.attr(),
  someArray: DS.attr('array'),
  someBoolean: DS.attr('boolean'),
  someNumber: DS.attr('number'),
  someString: DS.attr('string'),
});