(
result: HttpImportResult,
selection: HttpImportSelection = {},
)
| 131 | } |
| 132 | |
| 133 | export function persistHttpImportResult( |
| 134 | result: HttpImportResult, |
| 135 | selection: HttpImportSelection = {}, |
| 136 | ): HttpImportPersistSummary { |
| 137 | const storage = useHttpStorage() |
| 138 | const collections = selectByIndexes( |
| 139 | result.collections, |
| 140 | selection.selectedCollectionIndexes, |
| 141 | ) |
| 142 | const environments = selectByIndexes( |
| 143 | result.environments, |
| 144 | selection.selectedEnvironmentIndexes, |
| 145 | ) |
| 146 | const summary: HttpImportPersistSummary = { |
| 147 | collections: 0, |
| 148 | createdCollectionNames: [], |
| 149 | environments: 0, |
| 150 | folders: 0, |
| 151 | requests: 0, |
| 152 | warnings: [...result.warnings], |
| 153 | } |
| 154 | |
| 155 | for (const collection of collections) { |
| 156 | const root = createUniqueFolder(storage, collection.name, null) |
| 157 | const folderIds = new Map<string, number>() |
| 158 | summary.collections += 1 |
| 159 | summary.folders += 1 |
| 160 | summary.createdCollectionNames.push(root.name) |
| 161 | |
| 162 | for (const folder of collection.folders) { |
| 163 | const parentId |
| 164 | = folder.parentId !== null |
| 165 | ? (folderIds.get(folder.parentId) ?? root.id) |
| 166 | : root.id |
| 167 | const created = createUniqueFolder(storage, folder.name, parentId) |
| 168 | folderIds.set(folder.id, created.id) |
| 169 | summary.folders += 1 |
| 170 | } |
| 171 | |
| 172 | for (const request of collection.requests) { |
| 173 | const folderId |
| 174 | = request.folderId !== null |
| 175 | ? (folderIds.get(request.folderId) ?? root.id) |
| 176 | : root.id |
| 177 | createUniqueRequest(storage, request, folderId) |
| 178 | summary.requests += 1 |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | for (const environment of environments) { |
| 183 | createUniqueEnvironment(storage, environment) |
| 184 | summary.environments += 1 |
| 185 | } |
| 186 | |
| 187 | return summary |
| 188 | } |
no test coverage detected