Skip to content

Commit

Permalink
refactor method to generate ns keys
Browse files Browse the repository at this point in the history
  • Loading branch information
eperedo committed Aug 9, 2024
1 parent 4032239 commit 36c40cf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/data/common/D2ApiDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
}
4 changes: 2 additions & 2 deletions src/data/data-store/DataStoreMetadataD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions src/domain/data-store/DataStoreMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,8 @@ export class DataStoreMetadata {
.compact()
.value();
}

static generateKeyId(namespace: DataStoreNamespace, keyId: string) {
return [namespace, DataStoreMetadata.NS_SEPARATOR, keyId].join("");
}
}

0 comments on commit 36c40cf

Please sign in to comment.