* Converts an `IndexSpecification`, which can be specified in multiple formats, into a * valid `key` for the createIndexes command.
(indexSpec: IndexSpecification)
| 172 | * valid `key` for the createIndexes command. |
| 173 | */ |
| 174 | function constructIndexDescriptionMap(indexSpec: IndexSpecification): Map<string, IndexDirection> { |
| 175 | const key: Map<string, IndexDirection> = new Map(); |
| 176 | |
| 177 | const indexSpecs = |
| 178 | !Array.isArray(indexSpec) || isSingleIndexTuple(indexSpec) ? [indexSpec] : indexSpec; |
| 179 | |
| 180 | // Iterate through array and handle different types |
| 181 | for (const spec of indexSpecs) { |
| 182 | if (typeof spec === 'string') { |
| 183 | key.set(spec, 1); |
| 184 | } else if (Array.isArray(spec)) { |
| 185 | key.set(spec[0], spec[1] ?? 1); |
| 186 | } else if (spec instanceof Map) { |
| 187 | for (const [property, value] of spec) { |
| 188 | key.set(property, value); |
| 189 | } |
| 190 | } else if (isObject(spec)) { |
| 191 | for (const [property, value] of Object.entries(spec)) { |
| 192 | key.set(property, value); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return key; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Receives an index description and returns a modified index description which has had invalid options removed |
no test coverage detected