mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Finalized migration of serializers to native class syntax
refs d40740b0ec
- dropped use of `@classic` for auto-converted classes
- switched remaining EmberObject serializers to native classes
This commit is contained in:
parent
d40740b0ec
commit
f73837fba3
18 changed files with 64 additions and 72 deletions
|
@ -1,8 +1,8 @@
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class ActionSerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
createdAtUTC: {key: 'created_at'}
|
createdAtUTC: {key: 'created_at'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class ApiKeySerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
lastSeenAtUTC: {key: 'last_seen_at'},
|
lastSeenAtUTC: {key: 'last_seen_at'},
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'}
|
updatedAtUTC: {key: 'updated_at'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import RESTSerializer from '@ember-data/serializer/rest';
|
import RESTSerializer from '@ember-data/serializer/rest';
|
||||||
import classic from 'ember-classic-decorator';
|
|
||||||
import {camelize, decamelize, underscore} from '@ember/string';
|
import {camelize, decamelize, underscore} from '@ember/string';
|
||||||
import {pluralize} from 'ember-inflector';
|
import {pluralize} from 'ember-inflector';
|
||||||
|
|
||||||
@classic
|
|
||||||
export default class Application extends RESTSerializer {
|
export default class Application extends RESTSerializer {
|
||||||
// hacky method for getting access to meta data for single-resource responses
|
// hacky method for getting access to meta data for single-resource responses
|
||||||
// https://github.com/emberjs/data/pull/4077#issuecomment-200780097
|
// https://github.com/emberjs/data/pull/4077#issuecomment-200780097
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
export default class EmailRecipientSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
||||||
attrs: {
|
attrs = {
|
||||||
processedAtUTC: {key: 'processed_at'},
|
processedAtUTC: {key: 'processed_at'},
|
||||||
deliveredAtUTC: {key: 'delivered_at'},
|
deliveredAtUTC: {key: 'delivered_at'},
|
||||||
openedAtUTC: {key: 'opened_at'},
|
openedAtUTC: {key: 'opened_at'},
|
||||||
failedAtUTC: {key: 'failed_at'},
|
failedAtUTC: {key: 'failed_at'},
|
||||||
email: {embedded: 'always'}
|
email: {embedded: 'always'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class EmailSerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'},
|
updatedAtUTC: {key: 'updated_at'},
|
||||||
submittedAtUTC: {key: 'submitted_at'}
|
submittedAtUTC: {key: 'submitted_at'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from './application';
|
||||||
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
export default class IntegrationSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
||||||
attrs: {
|
attrs = {
|
||||||
apiKeys: {embedded: 'always'},
|
apiKeys: {embedded: 'always'},
|
||||||
webhooks: {embedded: 'always'},
|
webhooks: {embedded: 'always'},
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'}
|
updatedAtUTC: {key: 'updated_at'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class InviteSerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'}
|
updatedAtUTC: {key: 'updated_at'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -2,20 +2,20 @@
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from './application';
|
||||||
import {pluralize} from 'ember-inflector';
|
import {pluralize} from 'ember-inflector';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class LabelSerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'}
|
updatedAtUTC: {key: 'updated_at'}
|
||||||
},
|
}
|
||||||
|
|
||||||
serialize(/*snapshot, options*/) {
|
serialize(/*snapshot, options*/) {
|
||||||
let json = this._super(...arguments);
|
let json = super.serialize(...arguments);
|
||||||
|
|
||||||
// Properties that exist on the model but we don't want sent in the payload
|
// Properties that exist on the model but we don't want sent in the payload
|
||||||
delete json.count;
|
delete json.count;
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
},
|
}
|
||||||
|
|
||||||
// if we use `queryRecord` ensure we grab the first record to avoid
|
// if we use `queryRecord` ensure we grab the first record to avoid
|
||||||
// DS.SERIALIZER.REST.QUERYRECORD-ARRAY-RESPONSE deprecations
|
// DS.SERIALIZER.REST.QUERYRECORD-ARRAY-RESPONSE deprecations
|
||||||
|
@ -29,6 +29,6 @@ export default ApplicationSerializer.extend({
|
||||||
delete payload[plural];
|
delete payload[plural];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._super(...arguments);
|
return super.normalizeResponse(...arguments);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from './application';
|
||||||
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
export default class MemberSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
||||||
attrs: {
|
attrs = {
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
labels: {embedded: 'always'},
|
labels: {embedded: 'always'},
|
||||||
emailRecipients: {embedded: 'always'}
|
emailRecipients: {embedded: 'always'}
|
||||||
},
|
}
|
||||||
|
|
||||||
serialize(/*snapshot, options*/) {
|
serialize(/*snapshot, options*/) {
|
||||||
let json = this._super(...arguments);
|
let json = super.serialize(...arguments);
|
||||||
|
|
||||||
// Properties that exist on the model but we don't want sent in the payload
|
// Properties that exist on the model but we don't want sent in the payload
|
||||||
delete json.stripe;
|
delete json.stripe;
|
||||||
|
@ -24,4 +24,4 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class NotificationSerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
key: {key: 'location'}
|
key: {key: 'location'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import PostSerializer from './post';
|
import PostSerializer from './post';
|
||||||
import classic from 'ember-classic-decorator';
|
|
||||||
|
|
||||||
@classic
|
|
||||||
export default class Page extends PostSerializer {
|
export default class Page extends PostSerializer {
|
||||||
serialize() {
|
serialize() {
|
||||||
let json = super.serialize(...arguments);
|
let json = super.serialize(...arguments);
|
||||||
|
|
|
@ -3,16 +3,16 @@ import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
||||||
import {pluralize} from 'ember-inflector';
|
import {pluralize} from 'ember-inflector';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
export default class PostSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
||||||
// settings for the EmbeddedRecordsMixin.
|
// settings for the EmbeddedRecordsMixin.
|
||||||
attrs: {
|
attrs = {
|
||||||
authors: {embedded: 'always'},
|
authors: {embedded: 'always'},
|
||||||
tags: {embedded: 'always'},
|
tags: {embedded: 'always'},
|
||||||
publishedAtUTC: {key: 'published_at'},
|
publishedAtUTC: {key: 'published_at'},
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'},
|
updatedAtUTC: {key: 'updated_at'},
|
||||||
email: {embedded: 'always'}
|
email: {embedded: 'always'}
|
||||||
},
|
}
|
||||||
|
|
||||||
normalizeSingleResponse(store, primaryModelClass, payload) {
|
normalizeSingleResponse(store, primaryModelClass, payload) {
|
||||||
let root = this.keyForAttribute(primaryModelClass.modelName);
|
let root = this.keyForAttribute(primaryModelClass.modelName);
|
||||||
|
@ -23,15 +23,15 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
||||||
delete payload[pluralizedRoot];
|
delete payload[pluralizedRoot];
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._super(...arguments);
|
return super.normalizeSingleResponse(...arguments);
|
||||||
},
|
}
|
||||||
|
|
||||||
normalizeArrayResponse() {
|
normalizeArrayResponse() {
|
||||||
return this._super(...arguments);
|
return super.normalizeArrayResponse(...arguments);
|
||||||
},
|
}
|
||||||
|
|
||||||
serialize(/*snapshot, options*/) {
|
serialize(/*snapshot, options*/) {
|
||||||
let json = this._super(...arguments);
|
let json = super.serialize(...arguments);
|
||||||
|
|
||||||
// Inserted locally as a convenience.
|
// Inserted locally as a convenience.
|
||||||
delete json.author_id;
|
delete json.author_id;
|
||||||
|
@ -60,4 +60,4 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class ActionSerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'}
|
updatedAtUTC: {key: 'updated_at'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
import classic from 'ember-classic-decorator';
|
|
||||||
import {pluralize} from 'ember-inflector';
|
import {pluralize} from 'ember-inflector';
|
||||||
|
|
||||||
@classic
|
|
||||||
export default class Setting extends ApplicationSerializer {
|
export default class Setting extends ApplicationSerializer {
|
||||||
serializeIntoHash(hash, type, record, options) {
|
serializeIntoHash(hash, type, record, options) {
|
||||||
// Settings API does not want ids
|
// Settings API does not want ids
|
||||||
|
|
|
@ -2,20 +2,20 @@
|
||||||
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
import {pluralize} from 'ember-inflector';
|
import {pluralize} from 'ember-inflector';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class TagSerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'}
|
updatedAtUTC: {key: 'updated_at'}
|
||||||
},
|
}
|
||||||
|
|
||||||
serialize(/*snapshot, options*/) {
|
serialize(/*snapshot, options*/) {
|
||||||
let json = this._super(...arguments);
|
let json = super.serialize(...arguments);
|
||||||
|
|
||||||
// Properties that exist on the model but we don't want sent in the payload
|
// Properties that exist on the model but we don't want sent in the payload
|
||||||
delete json.count;
|
delete json.count;
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
},
|
}
|
||||||
|
|
||||||
// if we use `queryRecord` ensure we grab the first record to avoid
|
// if we use `queryRecord` ensure we grab the first record to avoid
|
||||||
// DS.SERIALIZER.REST.QUERYRECORD-ARRAY-RESPONSE deprecations
|
// DS.SERIALIZER.REST.QUERYRECORD-ARRAY-RESPONSE deprecations
|
||||||
|
@ -29,6 +29,6 @@ export default ApplicationSerializer.extend({
|
||||||
delete payload[plural];
|
delete payload[plural];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._super(...arguments);
|
return super.normalizeResponse(...arguments);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from './application';
|
||||||
import classic from 'ember-classic-decorator';
|
|
||||||
|
|
||||||
@classic
|
|
||||||
export default class Theme extends ApplicationSerializer {
|
export default class Theme extends ApplicationSerializer {
|
||||||
primaryKey = 'name';
|
primaryKey = 'name';
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@ import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||||
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
||||||
import {pluralize} from 'ember-inflector';
|
import {pluralize} from 'ember-inflector';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
export default class UserSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
||||||
attrs: {
|
attrs = {
|
||||||
roles: {embedded: 'always'},
|
roles: {embedded: 'always'},
|
||||||
lastLoginUTC: {key: 'last_seen'},
|
lastLoginUTC: {key: 'last_seen'},
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'}
|
updatedAtUTC: {key: 'updated_at'}
|
||||||
},
|
}
|
||||||
|
|
||||||
extractSingle(store, primaryType, payload) {
|
extractSingle(store, primaryType, payload) {
|
||||||
let root = this.keyForAttribute(primaryType.modelName);
|
let root = this.keyForAttribute(primaryType.modelName);
|
||||||
|
@ -17,8 +17,8 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
||||||
payload[root] = payload[pluralizedRoot][0];
|
payload[root] = payload[pluralizedRoot][0];
|
||||||
delete payload[pluralizedRoot];
|
delete payload[pluralizedRoot];
|
||||||
|
|
||||||
return this._super(...arguments);
|
return super.extractSingle(...arguments);
|
||||||
},
|
}
|
||||||
|
|
||||||
normalizeSingleResponse(store, primaryModelClass, payload) {
|
normalizeSingleResponse(store, primaryModelClass, payload) {
|
||||||
let root = this.keyForAttribute(primaryModelClass.modelName);
|
let root = this.keyForAttribute(primaryModelClass.modelName);
|
||||||
|
@ -29,6 +29,6 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
||||||
delete payload[pluralizedRoot];
|
delete payload[pluralizedRoot];
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._super(...arguments);
|
return super.normalizeSingleResponse(...arguments);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from './application';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default class ActionSerializer extends ApplicationSerializer {
|
||||||
attrs: {
|
attrs = {
|
||||||
lastTriggeredAtUTC: {key: 'last_triggered_at'},
|
lastTriggeredAtUTC: {key: 'last_triggered_at'},
|
||||||
createdAtUTC: {key: 'created_at'},
|
createdAtUTC: {key: 'created_at'},
|
||||||
updatedAtUTC: {key: 'updated_at'}
|
updatedAtUTC: {key: 'updated_at'}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue