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:
Kevin Ansfield 2022-02-02 18:35:18 +00:00
parent d40740b0ec
commit f73837fba3
18 changed files with 64 additions and 72 deletions

View File

@ -1,8 +1,8 @@
/* eslint-disable camelcase */
import ApplicationSerializer from 'ghost-admin/serializers/application';
export default ApplicationSerializer.extend({
attrs: {
export default class ActionSerializer extends ApplicationSerializer {
attrs = {
createdAtUTC: {key: 'created_at'}
}
});
}

View File

@ -1,9 +1,9 @@
import ApplicationSerializer from './application';
import ApplicationSerializer from 'ghost-admin/serializers/application';
export default ApplicationSerializer.extend({
attrs: {
export default class ApiKeySerializer extends ApplicationSerializer {
attrs = {
lastSeenAtUTC: {key: 'last_seen_at'},
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
}
});
}

View File

@ -1,9 +1,7 @@
import RESTSerializer from '@ember-data/serializer/rest';
import classic from 'ember-classic-decorator';
import {camelize, decamelize, underscore} from '@ember/string';
import {pluralize} from 'ember-inflector';
@classic
export default class Application extends RESTSerializer {
// hacky method for getting access to meta data for single-resource responses
// https://github.com/emberjs/data/pull/4077#issuecomment-200780097

View File

@ -2,12 +2,12 @@
import ApplicationSerializer from 'ghost-admin/serializers/application';
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
attrs: {
export default class EmailRecipientSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
attrs = {
processedAtUTC: {key: 'processed_at'},
deliveredAtUTC: {key: 'delivered_at'},
openedAtUTC: {key: 'opened_at'},
failedAtUTC: {key: 'failed_at'},
email: {embedded: 'always'}
}
});
}

View File

@ -1,10 +1,10 @@
/* eslint-disable camelcase */
import ApplicationSerializer from 'ghost-admin/serializers/application';
export default ApplicationSerializer.extend({
attrs: {
export default class EmailSerializer extends ApplicationSerializer {
attrs = {
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'},
submittedAtUTC: {key: 'submitted_at'}
}
});
}

View File

@ -1,11 +1,11 @@
import ApplicationSerializer from './application';
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
attrs: {
export default class IntegrationSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
attrs = {
apiKeys: {embedded: 'always'},
webhooks: {embedded: 'always'},
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
}
});
}

View File

@ -1,8 +1,8 @@
import ApplicationSerializer from 'ghost-admin/serializers/application';
export default ApplicationSerializer.extend({
attrs: {
export default class InviteSerializer extends ApplicationSerializer {
attrs = {
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
}
});
}

View File

@ -2,20 +2,20 @@
import ApplicationSerializer from './application';
import {pluralize} from 'ember-inflector';
export default ApplicationSerializer.extend({
attrs: {
export default class LabelSerializer extends ApplicationSerializer {
attrs = {
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
},
}
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
delete json.count;
return json;
},
}
// if we use `queryRecord` ensure we grab the first record to avoid
// DS.SERIALIZER.REST.QUERYRECORD-ARRAY-RESPONSE deprecations
@ -29,6 +29,6 @@ export default ApplicationSerializer.extend({
delete payload[plural];
}
}
return this._super(...arguments);
return super.normalizeResponse(...arguments);
}
});
}

View File

@ -2,15 +2,15 @@
import ApplicationSerializer from './application';
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
attrs: {
export default class MemberSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
attrs = {
createdAtUTC: {key: 'created_at'},
labels: {embedded: 'always'},
emailRecipients: {embedded: 'always'}
},
}
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
delete json.stripe;
@ -24,4 +24,4 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
return json;
}
});
}

View File

@ -1,7 +1,7 @@
import ApplicationSerializer from './application';
import ApplicationSerializer from 'ghost-admin/serializers/application';
export default ApplicationSerializer.extend({
attrs: {
export default class NotificationSerializer extends ApplicationSerializer {
attrs = {
key: {key: 'location'}
}
});
}

View File

@ -1,7 +1,5 @@
import PostSerializer from './post';
import classic from 'ember-classic-decorator';
@classic
export default class Page extends PostSerializer {
serialize() {
let json = super.serialize(...arguments);

View File

@ -3,16 +3,16 @@ import ApplicationSerializer from 'ghost-admin/serializers/application';
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
import {pluralize} from 'ember-inflector';
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
export default class PostSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
// settings for the EmbeddedRecordsMixin.
attrs: {
attrs = {
authors: {embedded: 'always'},
tags: {embedded: 'always'},
publishedAtUTC: {key: 'published_at'},
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'},
email: {embedded: 'always'}
},
}
normalizeSingleResponse(store, primaryModelClass, payload) {
let root = this.keyForAttribute(primaryModelClass.modelName);
@ -23,15 +23,15 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
delete payload[pluralizedRoot];
}
return this._super(...arguments);
},
return super.normalizeSingleResponse(...arguments);
}
normalizeArrayResponse() {
return this._super(...arguments);
},
return super.normalizeArrayResponse(...arguments);
}
serialize(/*snapshot, options*/) {
let json = this._super(...arguments);
let json = super.serialize(...arguments);
// Inserted locally as a convenience.
delete json.author_id;
@ -60,4 +60,4 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
return json;
}
});
}

View File

@ -1,8 +1,8 @@
import ApplicationSerializer from 'ghost-admin/serializers/application';
export default ApplicationSerializer.extend({
attrs: {
export default class ActionSerializer extends ApplicationSerializer {
attrs = {
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
}
});
}

View File

@ -1,8 +1,6 @@
import ApplicationSerializer from 'ghost-admin/serializers/application';
import classic from 'ember-classic-decorator';
import {pluralize} from 'ember-inflector';
@classic
export default class Setting extends ApplicationSerializer {
serializeIntoHash(hash, type, record, options) {
// Settings API does not want ids

View File

@ -2,20 +2,20 @@
import ApplicationSerializer from 'ghost-admin/serializers/application';
import {pluralize} from 'ember-inflector';
export default ApplicationSerializer.extend({
attrs: {
export default class TagSerializer extends ApplicationSerializer {
attrs = {
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
},
}
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
delete json.count;
return json;
},
}
// if we use `queryRecord` ensure we grab the first record to avoid
// DS.SERIALIZER.REST.QUERYRECORD-ARRAY-RESPONSE deprecations
@ -29,6 +29,6 @@ export default ApplicationSerializer.extend({
delete payload[plural];
}
}
return this._super(...arguments);
return super.normalizeResponse(...arguments);
}
});
}

View File

@ -1,7 +1,5 @@
import ApplicationSerializer from './application';
import classic from 'ember-classic-decorator';
@classic
export default class Theme extends ApplicationSerializer {
primaryKey = 'name';
}

View File

@ -2,13 +2,13 @@ import ApplicationSerializer from 'ghost-admin/serializers/application';
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
import {pluralize} from 'ember-inflector';
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
attrs: {
export default class UserSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
attrs = {
roles: {embedded: 'always'},
lastLoginUTC: {key: 'last_seen'},
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
},
}
extractSingle(store, primaryType, payload) {
let root = this.keyForAttribute(primaryType.modelName);
@ -17,8 +17,8 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
payload[root] = payload[pluralizedRoot][0];
delete payload[pluralizedRoot];
return this._super(...arguments);
},
return super.extractSingle(...arguments);
}
normalizeSingleResponse(store, primaryModelClass, payload) {
let root = this.keyForAttribute(primaryModelClass.modelName);
@ -29,6 +29,6 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
delete payload[pluralizedRoot];
}
return this._super(...arguments);
return super.normalizeSingleResponse(...arguments);
}
});
}

View File

@ -1,9 +1,9 @@
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
attrs: {
export default class ActionSerializer extends ApplicationSerializer {
attrs = {
lastTriggeredAtUTC: {key: 'last_triggered_at'},
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
}
});
}