-
-
Notifications
You must be signed in to change notification settings - Fork 605
/
pipeline-legacy.ts
31 lines (26 loc) · 976 Bytes
/
pipeline-legacy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { QueryBuilder } from '../../types'
import type { ContentQueryBuilder } from '../../types/query'
import { createPipelineFetcher } from './pipeline'
export function createPipelineFetcherLegacy<T> (getContentsList: () => Promise<T[]>) {
const _pipelineFetcher = createPipelineFetcher(getContentsList)
return async (query: QueryBuilder<T>): Promise<T | T[]> => {
// fetch dir config to match api behavior
if (query.params().first) {
(query as unknown as ContentQueryBuilder<T>).withDirConfig()
}
const params = query.params()
const result = await _pipelineFetcher(query as unknown as ContentQueryBuilder<T>)
if (params.surround) {
// @ts-ignore
return result?.surround
}
if ((result as any)?.dirConfig) {
result.result = {
_path: (result as any).dirConfig?._path,
...(result.result as T),
_dir: (result as any).dirConfig
}
}
return result?.result as T | T[]
}
}