fix: change removeReferences() to also remove origin

In addition remove unwanted side effects from the function
This commit is contained in:
Roman Klopsch
2019-07-04 14:05:19 +02:00
committed by Rainer Killinger
parent 24f28346bf
commit ded221c175
2 changed files with 9 additions and 7 deletions

View File

@@ -26,6 +26,7 @@
"@types/uuid": "3.4.5", "@types/uuid": "3.4.5",
"cli-progress": "2.1.1", "cli-progress": "2.1.1",
"commander": "2.20.0", "commander": "2.20.0",
"fast-clone": "1.5.13",
"moment": "2.24.0", "moment": "2.24.0",
"request": "2.88.0", "request": "2.88.0",
"traverse": "0.6.6", "traverse": "0.6.6",

View File

@@ -25,12 +25,13 @@ import {
SCThingUpdateResponse, SCThingUpdateResponse,
SCThingUpdateRoute, SCThingUpdateRoute,
} from '@openstapps/core'; } from '@openstapps/core';
import clone = require('fast-clone');
import * as moment from 'moment'; import * as moment from 'moment';
import {Bulk} from './bulk'; import {Bulk} from './bulk';
import {Client} from './client'; import {Client} from './client';
import {EmptyBulkError, NamespaceNotDefinedError} from './errors'; import {EmptyBulkError, NamespaceNotDefinedError} from './errors';
const V5_VERSION = 0x50; const V5_VERSION = 0x50;
/* tslint:disable:no-var-requires */ /* tslint:disable:no-var-requires */
/** /**
@@ -91,15 +92,15 @@ export class ConnectorClient extends Client {
* @param thing Thing to remove references from * @param thing Thing to remove references from
*/ */
static removeReferences<THING extends SCThings>(thing: THING): SCAssociatedThingWithoutReferences<THING> { static removeReferences<THING extends SCThings>(thing: THING): SCAssociatedThingWithoutReferences<THING> {
/* tslint:disable:no-any */
const thingWithoutReferences: any = { // tslint:disable-next-line:no-any
...{}, const thingWithoutReferences = clone<any>(thing);
...thing,
}; delete thingWithoutReferences.origin;
/* tslint:enable:no-any */
// iterate over all properties // iterate over all properties
for (const key in thingWithoutReferences) { for (const key in thingWithoutReferences) {
/* istanbul ignore if */ /* istanbul ignore if */
if (!thingWithoutReferences.hasOwnProperty(key)) { if (!thingWithoutReferences.hasOwnProperty(key)) {
continue; continue;