mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat(core-sdk): CB-1990 add mapArray / toArray for ResourceKeyUtils
This commit is contained in:
@@ -45,6 +45,8 @@ export interface ResourceKeyUtils {
|
||||
some: <TKey>(key: ResourceKey<TKey>, predicate: (key: TKey, index: number) => boolean) => boolean;
|
||||
every: <TKey>(key: ResourceKey<TKey>, predicate: (key: TKey, index: number) => boolean) => boolean;
|
||||
map: MapFnc;
|
||||
toArray: <TKey>(key: ResourceKey<TKey>) => TKey[];
|
||||
mapArray: <TKey, TValue>(key: ResourceKey<TKey>, selector: (key: TKey, index: number) => TValue) => TValue[];
|
||||
includes: <TKey>(first: ResourceKey<TKey>, second: ResourceKey<TKey>) => boolean;
|
||||
exclude: <TKey>(first: ResourceKeyList<TKey>, second: ResourceKey<TKey>) => ResourceKeyList<TKey>;
|
||||
join: <TKey>(...keys: Array<ResourceKey<TKey>>) => ResourceKeyList<TKey>;
|
||||
@@ -125,6 +127,13 @@ export const ResourceKeyUtils: ResourceKeyUtils = {
|
||||
return predicate(key, -1);
|
||||
}
|
||||
},
|
||||
toArray<TKey>(key: ResourceKey<TKey>): TKey[] {
|
||||
if (isResourceKeyList(key)) {
|
||||
return key.list;
|
||||
} else {
|
||||
return [key];
|
||||
}
|
||||
},
|
||||
|
||||
map<TKey, TValue>(key: ResourceKey<TKey>, selector: (key: TKey, index: number) => TValue): TValue | TValue[] {
|
||||
if (isResourceKeyList(key)) {
|
||||
@@ -134,6 +143,14 @@ export const ResourceKeyUtils: ResourceKeyUtils = {
|
||||
}
|
||||
},
|
||||
|
||||
mapArray<TKey, TValue>(key: ResourceKey<TKey>, selector: (key: TKey, index: number) => TValue): TValue[] {
|
||||
if (isResourceKeyList(key)) {
|
||||
return key.list.map(selector);
|
||||
} else {
|
||||
return [selector(key, -1)];
|
||||
}
|
||||
},
|
||||
|
||||
includes<TKey>(param: ResourceKey<TKey>, key: ResourceKey<TKey>): boolean {
|
||||
if (isResourceKeyList(param)) {
|
||||
return param.includes(key);
|
||||
|
||||
Reference in New Issue
Block a user