chore: use structuredClone instead of ember-copy addon (#1634)
This commit is contained in:
1 parent
76147af357
commit
7db1edda1c
11 files changed
+25
-41
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import RESTSerializer from '@ember-data/serializer/rest';
|
||||
import { underscore } from '@ember/string';
|
||||
import { get } from '@ember/object';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
/**
|
||||
* Manages serialization/normalization of data to/from the API.
|
||||
@@ -129,7 +128,7 @@ export default class ApplicationSerializer extends RESTSerializer {
|
||||
);
|
||||
// Copy the data rooted under `items` in the existing payload into the new
|
||||
// payload under the expected root key name.
|
||||
transformedPayload[payloadKey] = copy(payload.items, true);
|
||||
transformedPayload[payloadKey] = structuredClone(payload.items);
|
||||
// Return the result of normalizing the transformed payload.
|
||||
return super.normalizeArrayResponse(
|
||||
store,
|
||||
@@ -156,7 +155,7 @@ export default class ApplicationSerializer extends RESTSerializer {
|
||||
*/
|
||||
normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
|
||||
// Copy payload (mostly to prevent mocking issues)
|
||||
payload = copy(payload, true);
|
||||
payload = structuredClone(payload);
|
||||
// Check for and normalize missing arrays
|
||||
payload = this.normalizeMissingArrays(store, primaryModelClass, payload);
|
||||
// Setup a new payload data structure.
|
||||
@@ -211,7 +210,7 @@ export default class ApplicationSerializer extends RESTSerializer {
|
||||
* @return {Object}
|
||||
*/
|
||||
normalize(typeClass, hash) {
|
||||
let normalizedHash = copy(hash, true);
|
||||
let normalizedHash = structuredClone(hash);
|
||||
const scopeID = get(normalizedHash, 'scope.id');
|
||||
const scopeType = get(normalizedHash, 'scope.type');
|
||||
if (scopeID) normalizedHash.scope.scope_id = scopeID;
|
||||
@@ -300,7 +299,7 @@ export default class ApplicationSerializer extends RESTSerializer {
|
||||
id,
|
||||
requestType
|
||||
) {
|
||||
const newPayload = copy(payload, true);
|
||||
const newPayload = structuredClone(payload);
|
||||
|
||||
primaryModelClass.attributes.forEach((attribute) => {
|
||||
const {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
export default class AuthMethodSerializer extends ApplicationSerializer {
|
||||
// =methods
|
||||
|
||||
@@ -86,7 +84,7 @@ export default class AuthMethodSerializer extends ApplicationSerializer {
|
||||
* @return {Object}
|
||||
*/
|
||||
normalize(typeClass, hash, ...rest) {
|
||||
let normalizedHash = copy(hash, true);
|
||||
let normalizedHash = structuredClone(hash);
|
||||
// switch (normalizedHash.type) {
|
||||
// case 'oidc':
|
||||
// normalizedHash = this.normalizeOIDC(normalizedHash);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
export default class CredentialStoreSerializer extends ApplicationSerializer {
|
||||
/**
|
||||
* @override
|
||||
@@ -39,7 +37,7 @@ export default class CredentialStoreSerializer extends ApplicationSerializer {
|
||||
}
|
||||
|
||||
normalize(typeClass, hash, ...rest) {
|
||||
const normalizedHash = copy(hash, true);
|
||||
const normalizedHash = structuredClone(hash);
|
||||
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
|
||||
// Remove secret fields as we don't track them after being created/updated
|
||||
normalized.data.attributes.token = '';
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
export default class CredentialSerializer extends ApplicationSerializer {
|
||||
/**
|
||||
* @override
|
||||
@@ -33,7 +31,7 @@ export default class CredentialSerializer extends ApplicationSerializer {
|
||||
}
|
||||
|
||||
normalize(typeClass, hash, ...rest) {
|
||||
const normalizedHash = copy(hash, true);
|
||||
const normalizedHash = structuredClone(hash);
|
||||
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
|
||||
// Remove secret fields as we don't track them after being created/updated
|
||||
normalized.data.attributes.password = '';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
const fieldByType = {
|
||||
aws: ['preferred_endpoints', 'filters', 'sync_interval_seconds'],
|
||||
@@ -88,7 +87,7 @@ export default class HostSetSerializer extends ApplicationSerializer {
|
||||
* TODO: remove once API consistently returns arrays.
|
||||
*/
|
||||
normalize(typeClass, hash, ...rest) {
|
||||
const normalizedHash = copy(hash, true);
|
||||
const normalizedHash = structuredClone(hash);
|
||||
|
||||
if (typeof normalizedHash?.attributes?.filters === 'string') {
|
||||
normalizedHash.attributes.filters = [normalizedHash.attributes.filters];
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
export default class ManagedGroupSerializer extends ApplicationSerializer {
|
||||
// =properties
|
||||
|
||||
@@ -21,7 +19,7 @@ export default class ManagedGroupSerializer extends ApplicationSerializer {
|
||||
}
|
||||
|
||||
normalize(typeClass, hash, ...rest) {
|
||||
const normalizedHash = copy(hash, true);
|
||||
const normalizedHash = structuredClone(hash);
|
||||
|
||||
if (normalizedHash?.attributes?.filter) {
|
||||
normalizedHash.attributes.filter_string =
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
/**
|
||||
* Allows development-time toggling of resource permissions via the window
|
||||
* querystring. Pass a JSON object into the query to toggle permissions.
|
||||
@@ -50,7 +48,7 @@ class ToggledCapabilities {
|
||||
*/
|
||||
authorizedActionsFor(field) {
|
||||
if (this.#authorizedActions[field]) {
|
||||
return copy(this.#authorizedActions[field], true);
|
||||
return structuredClone(this.#authorizedActions[field]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
"ember-cli-babel": "^7.26.10",
|
||||
"ember-cli-htmlbars": "^6.1.0",
|
||||
"ember-cli-mirage": "^2.4.0",
|
||||
"ember-copy": "^2.0.1",
|
||||
"ember-data": "~4.4.0",
|
||||
"ember-fetch": "^8.1.1"
|
||||
},
|
||||
|
||||
@@ -2,8 +2,6 @@ import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
|
||||
// =services
|
||||
|
||||
@@ -36,19 +34,25 @@ export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
|
||||
@action
|
||||
edit(authMethod) {
|
||||
if (authMethod.claims_scopes) {
|
||||
authMethod.claims_scopes = copy(authMethod.claims_scopes, true);
|
||||
authMethod.claims_scopes = structuredClone(authMethod.claims_scopes);
|
||||
}
|
||||
if (authMethod.signing_algorithms) {
|
||||
authMethod.signing_algorithms = copy(authMethod.signing_algorithms, true);
|
||||
authMethod.signing_algorithms = structuredClone(
|
||||
authMethod.signing_algorithms
|
||||
);
|
||||
}
|
||||
if (authMethod.allowed_audiences) {
|
||||
authMethod.allowed_audiences = copy(authMethod.allowed_audiences, true);
|
||||
authMethod.allowed_audiences = structuredClone(
|
||||
authMethod.allowed_audiences
|
||||
);
|
||||
}
|
||||
if (authMethod.idp_ca_certs) {
|
||||
authMethod.idp_ca_certs = copy(authMethod.idp_ca_certs, true);
|
||||
authMethod.idp_ca_certs = structuredClone(authMethod.idp_ca_certs);
|
||||
}
|
||||
if (authMethod.account_claim_maps) {
|
||||
authMethod.account_claim_maps = copy(authMethod.account_claim_maps, true);
|
||||
authMethod.account_claim_maps = structuredClone(
|
||||
authMethod.account_claim_maps
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
export default class ScopesScopeHostCatalogsHostCatalogHostSetsHostSetRoute extends Route {
|
||||
// =services
|
||||
|
||||
@@ -33,10 +31,12 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsHostSetRoute exte
|
||||
@action
|
||||
edit(hostSet) {
|
||||
if (hostSet.preferred_endpoints) {
|
||||
hostSet.preferred_endpoints = copy(hostSet.preferred_endpoints, true);
|
||||
hostSet.preferred_endpoints = structuredClone(
|
||||
hostSet.preferred_endpoints
|
||||
);
|
||||
}
|
||||
if (hostSet.filters) {
|
||||
hostSet.filters = copy(hostSet.filters, true);
|
||||
hostSet.filters = structuredClone(hostSet.filters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13559,13 +13559,6 @@ ember-cookies@^0.5.0, ember-cookies@^0.5.2:
|
||||
ember-cli-babel "^7.1.0"
|
||||
ember-getowner-polyfill "^1.1.0 || ^2.0.0"
|
||||
|
||||
ember-copy@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/ember-copy/-/ember-copy-2.0.1.tgz#13192b12a250324bb4a8b4547a680b113f4e3041"
|
||||
integrity sha512-N/XFvZszrzyyX4IcNoeK4mJvIItNuONumhPLqi64T8NDjJkxBj4Pq61rvMkJx/9eZ8alzE4I8vYKOLxT0FvRuQ==
|
||||
dependencies:
|
||||
ember-cli-babel "^7.22.1"
|
||||
|
||||
ember-data@~4.4.0:
|
||||
version "4.4.1"
|
||||
resolved "https://registry.yarnpkg.com/ember-data/-/ember-data-4.4.1.tgz#86e56d55b49986dff8ae1cc98a740c829e53961e"
|
||||
|
||||
Reference in new issue
Block a user