style: format addons/api

This commit is contained in:
Susmitha Girumala committed 2020-09-16 14:29:02 -04:00
1 parent e2610d6a90
commit ec870acba8
62 files changed
+590 -521

No files matched your search

+3 -4
View File
@@ -35,13 +35,12 @@ function payloadIsBlank(adapterPayload) {
* @return {object}
*/
function prenormalizeArrayResponse(response) {
return payloadIsBlank(response) ? {items: []} : response;
return payloadIsBlank(response) ? { items: [] } : response;
}
export default class ApplicationAdapter extends RESTAdapter.extend(
AdapterBuildURLMixin
) {
// =attributes
/**
@@ -68,7 +67,7 @@ export default class ApplicationAdapter extends RESTAdapter.extend(
* @param {object} snapshot
* @return {string}
*/
urlSuffix(modelName, id, snapshot={}) {
urlSuffix(modelName, id, snapshot = {}) {
const method = getWithDefault(snapshot, 'adapterOptions.method', '');
return method ? `:${method}` : '';
}
@@ -205,7 +204,7 @@ export default class ApplicationAdapter extends RESTAdapter.extend(
normalizeErrorResponse(/*status, headers, payload*/) {
const errors = super.normalizeErrorResponse(...arguments);
if (isArray(errors)) {
errors.forEach(error => {
errors.forEach((error) => {
switch (Number(error.status)) {
case 401:
error.isUnauthenticated = true;
+6 -6
View File
@@ -2,19 +2,20 @@ import BaseModel from '../../models/base';
import { attr } from '@ember-data/model';
/**
* Account contains all fields related to an account resource
* Account contains all fields related to an account resource
*/
export default class GeneratedAccountModel extends BaseModel {
// =attributes
@attr('string', {
description: 'The type of the resource, to help differentiate schemas'
}) type;
description: 'The type of the resource, to help differentiate schemas',
})
type;
@attr('string', {
description: 'The owning auth method ID.',
}) auth_method_id;
})
auth_method_id;
@attr('string', {
description: 'Optional name for identification purposes',
@@ -42,5 +43,4 @@ export default class GeneratedAccountModel extends BaseModel {
description: 'Current version number of this resource.',
})
version;
}
@@ -5,12 +5,12 @@ import { attr } from '@ember-data/model';
*
*/
export default class GeneratedAuthMethodModel extends BaseModel {
// =attributes
@attr('string', {
description: 'The type of the resource, to help differentiate schemas'
}) type;
description: 'The type of the resource, to help differentiate schemas',
})
type;
@attr('string', {
description: 'Optional name for identification purposes',
@@ -43,5 +43,4 @@ export default class GeneratedAuthMethodModel extends BaseModel {
description: 'Current version number of this resource.',
})
version;
}
+1 -2
View File
@@ -3,7 +3,7 @@ import { attr } from '@ember-data/model';
/**
* Group contains all fields related to a Group resource
*/
*/
export default class GeneratedGroupModel extends BaseModel {
// = attributes
@@ -38,5 +38,4 @@ export default class GeneratedGroupModel extends BaseModel {
description: 'Current version number of this resource.',
})
version;
}
@@ -5,42 +5,47 @@ import { attr } from '@ember-data/model';
* HostCatalog manages Hosts and HostSets
*/
export default class GeneratedHostCatalogModel extends BaseModel {
// =attributes
@attr('string', {
description: 'The type of the resource, to help differentiate schemas'
}) type;
description: 'The type of the resource, to help differentiate schemas',
})
type;
@attr('string', {
description: 'Optional name for identification purposes'
}) name;
description: 'Optional name for identification purposes',
})
name;
@attr('string', {
description: 'Optional user-set description for identification purposes'
}) description;
description: 'Optional user-set description for identification purposes',
})
description;
@attr('date', {
description: 'The time this resource was created\nOutput only.',
readOnly: true
}) created_time;
readOnly: true,
})
created_time;
@attr('date', {
description: 'The time this resource was last updated\nOutput only.',
readOnly: true
}) updated_time;
readOnly: true,
})
updated_time;
@attr('boolean', {
description: 'Whether the catalog is disabled'
}) disabled;
description: 'Whether the catalog is disabled',
})
disabled;
@attr({
description: 'Attributes specific to the catalog type'
}) attributes;
description: 'Attributes specific to the catalog type',
})
attributes;
@attr('number', {
description: 'Current version number of this resource.',
})
version;
}
+20 -15
View File
@@ -5,35 +5,40 @@ import { attr } from '@ember-data/model';
* HostSet is a collection of Hosts created and managed by a HostCatalog
*/
export default class GeneratedHostSetModel extends BaseModel {
// =attributes
@attr('string', {
description: 'The type of the resource, to help differentiate schemas',
readOnly: true
}) type;
readOnly: true,
})
type;
@attr('string', {
description: 'The owning host catalog ID.',
}) host_catalog_id;
})
host_catalog_id;
@attr('string', {
description: 'Optional name for identification purposes'
}) name;
description: 'Optional name for identification purposes',
})
name;
@attr('string', {
description: 'Optional user-set description for identification purposes'
}) description;
description: 'Optional user-set description for identification purposes',
})
description;
@attr('date', {
description: 'The time this resource was created\nOutput only.',
readOnly: true
}) created_time;
readOnly: true,
})
created_time;
@attr('date', {
description: 'The time this resource was last updated\nOutput only.',
readOnly: true
}) updated_time;
readOnly: true,
})
updated_time;
@attr('number', {
description: 'Current version number of this resource.',
@@ -42,7 +47,7 @@ export default class GeneratedHostSetModel extends BaseModel {
@attr('number', {
description: 'The total count of hosts in this host set\nOutput only.',
readOnly: true
}) size;
readOnly: true,
})
size;
}
+17 -13
View File
@@ -5,38 +5,42 @@ import { attr } from '@ember-data/model';
* Host contains all fields related to a Host resource
*/
export default class GeneratedHostModel extends BaseModel {
// =attributes
@attr('string', {
description: 'The type of the resource, to help differentiate schemas'
}) type;
description: 'The type of the resource, to help differentiate schemas',
})
type;
@attr('string', {
description: 'The owning host catalog ID.',
}) host_catalog_id;
})
host_catalog_id;
@attr('string', {
description: 'Optional name for identification purposes'
}) name;
description: 'Optional name for identification purposes',
})
name;
@attr('string', {
description: 'Optional user-set description for identification purposes'
}) description;
description: 'Optional user-set description for identification purposes',
})
description;
@attr('date', {
description: 'The time this resource was created\nOutput only.',
readOnly: true
}) created_time;
readOnly: true,
})
created_time;
@attr('date', {
description: 'The time this resource was last updated\nOutput only.',
readOnly: true
}) updated_time;
readOnly: true,
})
updated_time;
@attr('number', {
description: 'Current version number of this resource.',
})
version;
}
@@ -38,5 +38,4 @@ export default class GeneratedRoleModel extends BaseModel {
description: 'Current version number of this resource.',
})
version;
}
+3 -4
View File
@@ -5,12 +5,12 @@ import { attr } from '@ember-data/model';
*
*/
export default class GeneratedScopeModel extends BaseModel {
// =attributes
@attr('string', {
description: 'The type of the resource'
}) type;
description: 'The type of the resource',
})
type;
@attr('string', {
description: 'Optional name for identification purposes',
@@ -38,5 +38,4 @@ export default class GeneratedScopeModel extends BaseModel {
description: 'Current version number of this resource.',
})
version;
}
+18 -13
View File
@@ -5,34 +5,39 @@ import { attr } from '@ember-data/model';
* Target
*/
export default class GeneratedTargetModel extends BaseModel {
// =attributes
@attr('string', {
description: 'The type of the resource, to help differentiate schemas'
}) type;
description: 'The type of the resource, to help differentiate schemas',
})
type;
@attr('string', {
description: 'Optional name for identification purposes'
}) name;
description: 'Optional name for identification purposes',
})
name;
@attr('string', {
description: 'Optional user-set description for identification purposes'
}) description;
description: 'Optional user-set description for identification purposes',
})
description;
@attr('date', {
description: 'The time this resource was created\nOutput only.',
readOnly: true
}) created_time;
readOnly: true,
})
created_time;
@attr('date', {
description: 'The time this resource was last updated\nOutput only.',
readOnly: true
}) updated_time;
readOnly: true,
})
updated_time;
@attr('boolean', {
description: 'Whether the catalog is disabled'
}) disabled;
description: 'Whether the catalog is disabled',
})
disabled;
@attr('number', {
description: 'Current version number of this resource.',
+1 -1
View File
@@ -3,7 +3,7 @@ import { attr } from '@ember-data/model';
/**
* User contains all fields related to a user resource
*/
*/
export default class GeneratedUserModel extends BaseModel {
// =attributes
+1 -3
View File
@@ -13,7 +13,6 @@ import { get } from '@ember/object';
* uses this mixin to alter generated URLs.
*/
export default Mixin.create({
// =methods
/**
@@ -162,6 +161,5 @@ export default Mixin.create({
*/
urlForDeleteRecord(id, modelName, snapshot) {
return this._buildURL(modelName, id, snapshot);
}
},
});
+4 -6
View File
@@ -2,7 +2,6 @@ import GeneratedAccountModel from '../generated/models/account';
import { fragment } from 'ember-data-model-fragments/attributes';
export default class AccountModel extends GeneratedAccountModel {
/**
* Attributes of this resource, if any, represented as a JSON fragment.
* @type {FragmentAccountAttributesModel}
@@ -19,18 +18,17 @@ export default class AccountModel extends GeneratedAccountModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
setPassword(password, options={ adapterOptions: {} }) {
setPassword(password, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'set-password',
password
password,
};
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
}
-2
View File
@@ -26,7 +26,6 @@ import { get } from '@ember/object';
* 2) Or as an ID: `record.scopeID`.
*/
export default class BaseModel extends Model {
// =relationships
/**
@@ -83,5 +82,4 @@ export default class BaseModel extends Model {
get cannotSave() {
return !this.canSave;
}
}
@@ -2,9 +2,8 @@ import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
export default class FragmentAccountAttributesModel extends Fragment {
@attr('string', {
description: 'The account login name'
}) login_name;
description: 'The account login name',
})
login_name;
}
@@ -2,9 +2,8 @@ import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
export default class FragmentHostAttributesModel extends Fragment {
@attr('string', {
description: 'The address (DNS or IP name) used to reach the host'
}) address;
description: 'The address (DNS or IP name) used to reach the host',
})
address;
}
+6 -6
View File
@@ -2,15 +2,15 @@ import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
export default class FragmentHostSetModel extends Fragment {
// =attributes
@attr('string', {
description: 'ID of the related host set'
}) host_set_id;
description: 'ID of the related host set',
})
host_set_id;
@attr('string', {
description: 'ID of the catalog to which the host set belongs'
}) host_catalog_id;
description: 'ID of the catalog to which the host set belongs',
})
host_catalog_id;
}
@@ -2,19 +2,20 @@ import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
export default class FragmentPrincipal extends Fragment {
// =attributes
@attr('string', {
description: 'ID of the related scope'
}) scope_id;
description: 'ID of the related scope',
})
scope_id;
@attr('string', {
description: 'ID of the related principal (user or group)'
}) principal_id;
description: 'ID of the related principal (user or group)',
})
principal_id;
@attr('string', {
description: 'Type of the related principal (user or group)'
}) type;
description: 'Type of the related principal (user or group)',
})
type;
}
+15 -9
View File
@@ -4,33 +4,39 @@ import { attr } from '@ember-data/model';
import { scopeTypes } from './scope';
export default class FragmentScope extends Fragment {
// =attributes
@attr('string', {
description: 'ID of the related scope'
}) scope_id;
description: 'ID of the related scope',
})
scope_id;
@attr('string', {
description: 'The type of the resource'
}) type;
description: 'The type of the resource',
})
type;
/**
* @type {boolean}
*/
@computed('type')
get isGlobal() { return this.type === scopeTypes.global; }
get isGlobal() {
return this.type === scopeTypes.global;
}
/**
* @type {boolean}
*/
@computed('type')
get isOrg() { return this.type === scopeTypes.org; }
get isOrg() {
return this.type === scopeTypes.org;
}
/**
* @type {boolean}
*/
@computed('type')
get isProject() { return this.type === scopeTypes.project; }
get isProject() {
return this.type === scopeTypes.project;
}
}
+1 -3
View File
@@ -5,12 +5,10 @@ import { attr } from '@ember-data/model';
* Represents an item in an array of strings.
*/
export default class FragmentStringModel extends Fragment {
// =attributes
@attr('string', {
description: 'The value of the string.'
description: 'The value of the string.',
})
value;
}
@@ -2,9 +2,8 @@ import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
export default class FragmentTargetAttributesModel extends Fragment {
@attr('number', {
description: 'The default port a target should use if present.'
}) default_port;
description: 'The default port a target should use if present.',
})
default_port;
}
+12 -13
View File
@@ -4,7 +4,6 @@ import { computed } from '@ember/object';
import { A } from '@ember/array';
export default class GroupModel extends GeneratedGroupModel {
// =attributes
/**
@@ -14,8 +13,9 @@ export default class GroupModel extends GeneratedGroupModel {
@attr({
readOnly: true,
defaultValue: () => A(),
emptyArrayIfMissing: true
}) member_ids;
emptyArrayIfMissing: true,
})
member_ids;
/**
* An array of resolved user instances.
@@ -26,7 +26,7 @@ export default class GroupModel extends GeneratedGroupModel {
@computed('member_ids.[]')
get members() {
return this.member_ids
.map(id => this.store.peekRecord('user', id))
.map((id) => this.store.peekRecord('user', id))
.filter(Boolean);
}
@@ -40,10 +40,10 @@ export default class GroupModel extends GeneratedGroupModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
addMembers(memberIDs, options={ adapterOptions: {} }) {
addMembers(memberIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-members',
memberIDs
memberIDs,
};
// There is no "deep merge" in ES.
// All of this nonsense is here to ensure we get
@@ -52,8 +52,8 @@ export default class GroupModel extends GeneratedGroupModel {
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
@@ -65,10 +65,10 @@ export default class GroupModel extends GeneratedGroupModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
removeMembers(memberIDs, options={ adapterOptions: {} }) {
removeMembers(memberIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'remove-members',
memberIDs
memberIDs,
};
// There is no "deep merge" in ES.
// All of this nonsense is here to ensure we get
@@ -77,8 +77,8 @@ export default class GroupModel extends GeneratedGroupModel {
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
@@ -91,5 +91,4 @@ export default class GroupModel extends GeneratedGroupModel {
removeMember(memberID, options) {
return this.removeMembers([memberID], options);
}
}
+11 -11
View File
@@ -2,7 +2,6 @@ import GeneratedHostSetModel from '../generated/models/host-set';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
export default class HostSetModel extends GeneratedHostSetModel {
// =attributes
/**
@@ -11,8 +10,9 @@ export default class HostSetModel extends GeneratedHostSetModel {
*/
@fragmentArray('fragment-string', {
readOnly: true,
emptyArrayIfMissing: true
}) host_ids;
emptyArrayIfMissing: true,
})
host_ids;
// =methods
@@ -24,17 +24,17 @@ export default class HostSetModel extends GeneratedHostSetModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
addHosts(hostIDs, options={ adapterOptions: {} }) {
addHosts(hostIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-hosts',
hostIDs
hostIDs,
};
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
@@ -46,17 +46,17 @@ export default class HostSetModel extends GeneratedHostSetModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
removeHosts(hostIDs, options={ adapterOptions: {} }) {
removeHosts(hostIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'remove-hosts',
hostIDs
hostIDs,
};
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
-2
View File
@@ -2,11 +2,9 @@ import GeneratedHostModel from '../generated/models/host';
import { fragment } from 'ember-data-model-fragments/attributes';
export default class HostModel extends GeneratedHostModel {
/**
* Attributes of this resource, if any, represented as a JSON fragment.
* @type {FragmentHostAttributesModel}
*/
@fragment('fragment-host-attributes', { defaultValue: {} }) attributes;
}
+14 -15
View File
@@ -2,7 +2,6 @@ import GeneratedRoleModel from '../generated/models/role';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
export default class RoleModel extends GeneratedRoleModel {
// =attributes
/**
@@ -14,14 +13,15 @@ export default class RoleModel extends GeneratedRoleModel {
*/
@fragmentArray('fragment-principal', {
readOnly: true,
emptyArrayIfMissing: true
}) principals;
emptyArrayIfMissing: true,
})
principals;
/**
* Grants is read-only _most_ under normal circumstances. But grants can
* be persisted via a dedicated call to `saveGrants()`.
*/
@fragmentArray('fragment-string', {readOnly: true}) grants;
@fragmentArray('fragment-string', { readOnly: true }) grants;
// =methods
@@ -34,8 +34,8 @@ export default class RoleModel extends GeneratedRoleModel {
return this.save({
adapterOptions: {
method: 'set-grants',
serializeGrants: true
}
serializeGrants: true,
},
});
}
@@ -47,10 +47,10 @@ export default class RoleModel extends GeneratedRoleModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
addPrincipals(principalIDs, options={ adapterOptions: {} }) {
addPrincipals(principalIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-principals',
principalIDs
principalIDs,
};
// There is no "deep merge" in ES.
// All of this nonsense is here to ensure we get
@@ -59,8 +59,8 @@ export default class RoleModel extends GeneratedRoleModel {
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
@@ -72,10 +72,10 @@ export default class RoleModel extends GeneratedRoleModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
removePrincipals(principalIDs, options={ adapterOptions: {} }) {
removePrincipals(principalIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'remove-principals',
principalIDs
principalIDs,
};
// There is no "deep merge" in ES.
// All of this nonsense is here to ensure we get
@@ -84,8 +84,8 @@ export default class RoleModel extends GeneratedRoleModel {
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
@@ -98,5 +98,4 @@ export default class RoleModel extends GeneratedRoleModel {
removePrincipal(principalID, options) {
return this.removePrincipals([principalID], options);
}
}
+1 -3
View File
@@ -4,11 +4,10 @@ import { computed } from '@ember/object';
export const scopeTypes = {
global: 'global',
org: 'org',
project: 'project'
project: 'project',
};
export default class ScopeModel extends GeneratedScopeModel {
// =attributes
/**
@@ -42,5 +41,4 @@ export default class ScopeModel extends GeneratedScopeModel {
set isProject(value) {
if (value) this.type = scopeTypes.project;
}
}
+13 -14
View File
@@ -3,7 +3,6 @@ import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
import { computed } from '@ember/object';
export default class TargetModel extends GeneratedTargetModel {
// =attributes
/**
@@ -17,8 +16,9 @@ export default class TargetModel extends GeneratedTargetModel {
*/
@fragmentArray('fragment-host-set', {
readOnly: true,
emptyArrayIfMissing: true
}) host_sets;
emptyArrayIfMissing: true,
})
host_sets;
/**
* An array of resolved host set and host catalog instances. Model instances
@@ -31,9 +31,9 @@ export default class TargetModel extends GeneratedTargetModel {
return this.host_sets
.map(({ host_set_id, host_catalog_id }) => ({
model: this.store.peekRecord('host-set', host_set_id),
hostCatalog: this.store.peekRecord('host-catalog', host_catalog_id)
hostCatalog: this.store.peekRecord('host-catalog', host_catalog_id),
}))
.filter(hostSetRef => hostSetRef.model !== null);
.filter((hostSetRef) => hostSetRef.model !== null);
}
// =methods
@@ -46,10 +46,10 @@ export default class TargetModel extends GeneratedTargetModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
addHostSets(hostSetIDs, options={ adapterOptions: {} }) {
addHostSets(hostSetIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-host-sets',
hostSetIDs
hostSetIDs,
};
// There is no "deep merge" in ES.
// All of this nonsense is here to ensure we get
@@ -58,8 +58,8 @@ export default class TargetModel extends GeneratedTargetModel {
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
@@ -71,10 +71,10 @@ export default class TargetModel extends GeneratedTargetModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
removeHostSets(hostSetIDs, options={ adapterOptions: {} }) {
removeHostSets(hostSetIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'remove-host-sets',
hostSetIDs
hostSetIDs,
};
// There is no "deep merge" in ES.
// All of this nonsense is here to ensure we get
@@ -83,8 +83,8 @@ export default class TargetModel extends GeneratedTargetModel {
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
...options.adapterOptions,
},
});
}
@@ -97,5 +97,4 @@ export default class TargetModel extends GeneratedTargetModel {
removeHostSet(hostSetID, options) {
return this.removeHostSets([hostSetID], options);
}
}
+2 -3
View File
@@ -1,7 +1,6 @@
import ApplicationSerializer from './application';
export default class AccountSerializer extends ApplicationSerializer {
// =methods
/**
@@ -16,7 +15,8 @@ export default class AccountSerializer extends ApplicationSerializer {
serialize(snapshot) {
const password = snapshot?.adapterOptions?.password;
let serialized = super.serialize(...arguments);
if (password && snapshot?.record?.isNew) serialized.attributes.password = password;
if (password && snapshot?.record?.isNew)
serialized.attributes.password = password;
if (snapshot?.adapterOptions?.method === 'set-password') {
serialized = this.serializeForSetPassword(snapshot, password);
}
@@ -35,5 +35,4 @@ export default class AccountSerializer extends ApplicationSerializer {
password,
};
}
}
+4 -4
View File
@@ -7,7 +7,6 @@ import { copy } from 'ember-copy';
* Manages serialization/normalization of data to/from the API.
*/
export default class ApplicationSerializer extends RESTSerializer {
// =methods
/**
@@ -160,9 +159,11 @@ export default class ApplicationSerializer extends RESTSerializer {
* @return {object}
*/
normalizeMissingArrays(store, primaryModelClass, payload) {
const attrDefs = store._attributesDefinitionFor(primaryModelClass.modelName);
const attrDefs = store._attributesDefinitionFor(
primaryModelClass.modelName
);
if (attrDefs) {
Object.keys(attrDefs).forEach(key => {
Object.keys(attrDefs).forEach((key) => {
if (!payload[key] && attrDefs[key]?.options?.emptyArrayIfMissing) {
payload[key] = [];
}
@@ -187,5 +188,4 @@ export default class ApplicationSerializer extends RESTSerializer {
if (scopeID) normalizedHash.scope.scope_id = scopeID;
return super.normalize(typeClass, normalizedHash);
}
}
@@ -1,7 +1,6 @@
import JSONSerializer from '@ember-data/serializer/json';
export default class FragmentHostSetSerializer extends JSONSerializer {
// =methods
/**
@@ -14,5 +13,4 @@ export default class FragmentHostSetSerializer extends JSONSerializer {
normalize(typeClass, { id: host_set_id, ...obj }) {
return super.normalize(typeClass, { host_set_id, ...obj });
}
}
@@ -1,7 +1,6 @@
import JSONSerializer from '@ember-data/serializer/json';
export default class FragmentPrincipalSerializer extends JSONSerializer {
// =methods
/**
@@ -14,5 +13,4 @@ export default class FragmentPrincipalSerializer extends JSONSerializer {
normalize(typeClass, { id: principal_id, ...obj }) {
return super.normalize(typeClass, { principal_id, ...obj });
}
}
+1 -3
View File
@@ -1,7 +1,6 @@
import ApplicationSerializer from './application';
export default class GroupSerializer extends ApplicationSerializer {
// =methods
/**
@@ -27,8 +26,7 @@ export default class GroupSerializer extends ApplicationSerializer {
serializewithMembers(snapshot, memberIDs) {
return {
version: snapshot.attr('version'),
member_ids: memberIDs
member_ids: memberIDs,
};
}
}
+1 -4
View File
@@ -1,7 +1,6 @@
import ApplicationSerializer from './application';
export default class HostSetSerializer extends ApplicationSerializer {
// =methods
/**
@@ -44,10 +43,8 @@ export default class HostSetSerializer extends ApplicationSerializer {
// TODO: can fragment string normalization be handled generically?
// TODO: host_ids might actually be attributes.host_ids
if (resourceHash.host_ids) {
resourceHash.host_ids =
resourceHash.host_ids.map(value => ({ value }));
resourceHash.host_ids = resourceHash.host_ids.map((value) => ({ value }));
}
return super.normalize(modelClass, resourceHash);
}
}
+9 -8
View File
@@ -2,7 +2,6 @@ import ApplicationSerializer from './application';
import { get } from '@ember/object';
export default class RoleSerializer extends ApplicationSerializer {
// =methods
/**
@@ -20,8 +19,8 @@ export default class RoleSerializer extends ApplicationSerializer {
let serialized = super.serialize(...arguments);
if (serializeGrants) serialized = this.serializeWithGrants(snapshot);
const principalIDs = snapshot?.adapterOptions?.principalIDs;
if (principalIDs) serialized =
this.serializewithPrincipals(snapshot, principalIDs);
if (principalIDs)
serialized = this.serializewithPrincipals(snapshot, principalIDs);
return serialized;
}
@@ -33,7 +32,9 @@ export default class RoleSerializer extends ApplicationSerializer {
serializeWithGrants(snapshot) {
return {
version: snapshot.attr('version'),
grant_strings: snapshot.attr('grants').map(grant => grant.attr('value'))
grant_strings: snapshot
.attr('grants')
.map((grant) => grant.attr('value')),
};
}
@@ -47,7 +48,7 @@ export default class RoleSerializer extends ApplicationSerializer {
serializewithPrincipals(snapshot, principalIDs) {
return {
version: snapshot.attr('version'),
principal_ids: principalIDs
principal_ids: principalIDs,
};
}
@@ -62,10 +63,10 @@ export default class RoleSerializer extends ApplicationSerializer {
normalize(modelClass, resourceHash) {
// TODO: can fragment string normalization be handled generically?
if (resourceHash.grant_strings) {
resourceHash.grants =
resourceHash.grant_strings.map(value => ({ value }));
resourceHash.grants = resourceHash.grant_strings.map((value) => ({
value,
}));
}
return super.normalize(modelClass, resourceHash);
}
}
+3 -5
View File
@@ -1,7 +1,6 @@
import ApplicationSerializer from './application';
export default class TargetSerializer extends ApplicationSerializer {
// =methods
/**
@@ -15,8 +14,8 @@ export default class TargetSerializer extends ApplicationSerializer {
serialize(snapshot) {
let serialized = super.serialize(...arguments);
const hostSetIDs = snapshot?.adapterOptions?.hostSetIDs;
if (hostSetIDs) serialized =
this.serializeWithHostSets(snapshot, hostSetIDs);
if (hostSetIDs)
serialized = this.serializeWithHostSets(snapshot, hostSetIDs);
return serialized;
}
@@ -30,8 +29,7 @@ export default class TargetSerializer extends ApplicationSerializer {
serializeWithHostSets(snapshot, hostSetIDs) {
return {
version: snapshot.attr('version'),
host_set_ids: hostSetIDs
host_set_ids: hostSetIDs,
};
}
}