diff --git a/src/data/common/D2ApiDataStore.ts b/src/data/common/D2ApiDataStore.ts index cb03e4639..eeb304fe2 100644 --- a/src/data/common/D2ApiDataStore.ts +++ b/src/data/common/D2ApiDataStore.ts @@ -63,6 +63,6 @@ export class D2ApiDataStore { } private buildArrayDataStoreKey(keys: string[], namespace: string): DataStoreKey[] { - return keys.map(key => ({ id: [namespace, DataStoreMetadata.NS_SEPARATOR, key].join(""), displayName: key })); + return keys.map(key => ({ id: DataStoreMetadata.generateKeyId(namespace, key), displayName: key })); } } diff --git a/src/data/data-store/DataStoreMetadataD2Repository.ts b/src/data/data-store/DataStoreMetadataD2Repository.ts index 43b1bf45a..569d5f1bd 100644 --- a/src/data/data-store/DataStoreMetadataD2Repository.ts +++ b/src/data/data-store/DataStoreMetadataD2Repository.ts @@ -94,11 +94,11 @@ export class DataStoreMetadataD2Repository implements DataStoreMetadataRepositor const existingRecords = await this.get([{ ...dataStore, keys: [] }]); const existingKeysIds = existingRecords.flatMap(dataStore => { - return dataStore.keys.map(key => `${dataStore.namespace}[NS]${key.id}`); + return dataStore.keys.map(key => DataStoreMetadata.generateKeyId(dataStore.namespace, key.id)); }); const keysIdsToSave = dataStores.flatMap(dataStore => { - return dataStore.keys.map(key => `${dataStore.namespace}[NS]${key.id}`); + return dataStore.keys.map(key => DataStoreMetadata.generateKeyId(dataStore.namespace, key.id)); }); const keysIdsToDelete = existingKeysIds.filter(id => !keysIdsToSave.includes(id)); diff --git a/src/domain/data-store/DataStoreMetadata.ts b/src/domain/data-store/DataStoreMetadata.ts index bd1e41c55..f01a03c01 100644 --- a/src/domain/data-store/DataStoreMetadata.ts +++ b/src/domain/data-store/DataStoreMetadata.ts @@ -133,4 +133,8 @@ export class DataStoreMetadata { .compact() .value(); } + + static generateKeyId(namespace: DataStoreNamespace, keyId: string) { + return [namespace, DataStoreMetadata.NS_SEPARATOR, keyId].join(""); + } }