( definition: SelectorDefinition, args: SelectorQueryArgs )
| 72 | * provides neither. |
| 73 | */ |
| 74 | export async function loadAllSelectorOptions( |
| 75 | definition: SelectorDefinition, |
| 76 | args: SelectorQueryArgs |
| 77 | ): Promise<SelectorOption[]> { |
| 78 | if (definition.fetchList) { |
| 79 | return definition.fetchList(args) |
| 80 | } |
| 81 | |
| 82 | if (definition.fetchPage) { |
| 83 | const items: SelectorOption[] = [] |
| 84 | let cursor: string | undefined |
| 85 | for (let page = 0; page < MAX_LOAD_ALL_PAGES; page++) { |
| 86 | const { items: pageItems, nextCursor } = await definition.fetchPage({ ...args, cursor }) |
| 87 | items.push(...pageItems) |
| 88 | cursor = nextCursor |
| 89 | if (!cursor) break |
| 90 | } |
| 91 | return items |
| 92 | } |
| 93 | |
| 94 | return [] |
| 95 | } |
| 96 | |
| 97 | export function mergeOption(options: SelectorOption[], option?: SelectorOption | null) { |
| 98 | if (!option) return options |
no test coverage detected