Skip to content

Commit

Permalink
feat(service-spec-types): index for scrutinizable resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Nov 3, 2023
1 parent 79dac13 commit 49fe58c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/service-spec-types/src/types/database.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promises as fs } from 'fs';
import { gunzipSync } from 'zlib';
import { Database, entityCollection, fieldIndex, stringCmp } from '@cdklabs/tskb';
import { Database, entityCollection, fieldIndex, fieldIndexWithDefault, stringCmp } from '@cdklabs/tskb';
import { IsAugmentedResource, ResourceAugmentation } from './augmentations';
import {
DimensionSet,
Expand All @@ -21,13 +21,15 @@ import {
RegionHasResource,
RegionHasService,
UsesType,
ResourceScrutinyType,
} from './resource';

export function emptyDatabase() {
return new Database(
{
resource: entityCollection<Resource>().index({
cloudFormationType: fieldIndex('cloudFormationType', stringCmp),
scrutinizable: fieldIndexWithDefault('scrutinizable', stringCmp, ResourceScrutinyType.None),
}),
region: entityCollection<Region>().index({
name: fieldIndex('name', stringCmp),
Expand Down
8 changes: 8 additions & 0 deletions packages/@cdklabs/tskb/src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ export function fieldIndex<A extends Entity, P extends keyof A>(
return calculatedIndex((x) => x[propName], comparator);
}

export function fieldIndexWithDefault<A extends Entity, P extends keyof A>(
propName: P,
comparator: sortedMap.Comparator<NonNullable<A[P]>>,
defaultValue: NonNullable<A[P]>,
): EntityIndex<A, A[P]> {
return calculatedIndex((x) => x[propName] ?? defaultValue!, comparator);
}

/**
* An index that is calculated based on a function applied to an entity
*/
Expand Down

0 comments on commit 49fe58c

Please sign in to comment.