|
1 | | -import type { H3Event } from 'h3' |
2 | | -import { collectionQueryBuilder } from './internal/query' |
3 | | -import { generateNavigationTree } from './internal/navigation' |
4 | | -import { generateItemSurround } from './internal/surround' |
5 | | -import { generateSearchSections } from './internal/search' |
6 | | -import { fetchQuery } from './internal/api' |
7 | | -import type { Collections, CollectionQueryBuilder, PageCollections, SurroundOptions, SQLOperator, QueryGroupFunction } from '@nuxt/content' |
8 | | - |
9 | | -interface ChainablePromise<T extends keyof PageCollections, R> extends Promise<R> { |
10 | | - where(field: keyof PageCollections[T] | string, operator: SQLOperator, value?: unknown): ChainablePromise<T, R> |
11 | | - andWhere(groupFactory: QueryGroupFunction<PageCollections[T]>): ChainablePromise<T, R> |
12 | | - orWhere(groupFactory: QueryGroupFunction<PageCollections[T]>): ChainablePromise<T, R> |
13 | | - order(field: keyof PageCollections[T], direction: 'ASC' | 'DESC'): ChainablePromise<T, R> |
14 | | -} |
15 | | - |
16 | | -export const queryCollection = <T extends keyof Collections>(event: H3Event, collection: T): CollectionQueryBuilder<Collections[T]> => { |
17 | | - return collectionQueryBuilder<T>(collection, (collection, sql) => fetchQuery(event, collection, sql)) |
18 | | -} |
19 | | - |
20 | | -export function queryCollectionNavigation<T extends keyof PageCollections>(event: H3Event, collection: T, fields?: Array<keyof PageCollections[T]>) { |
21 | | - return chainablePromise(event, collection, qb => generateNavigationTree(qb, fields)) |
22 | | -} |
23 | | - |
24 | | -export function queryCollectionItemSurroundings<T extends keyof PageCollections>(event: H3Event, collection: T, path: string, opts?: SurroundOptions<keyof PageCollections[T]>) { |
25 | | - return chainablePromise(event, collection, qb => generateItemSurround(qb, path, opts)) |
26 | | -} |
27 | | - |
28 | | -export function queryCollectionSearchSections(event: H3Event, collection: keyof Collections, opts?: { ignoredTags: string[] }) { |
29 | | - return chainablePromise(event, collection, qb => generateSearchSections(qb, opts)) |
30 | | -} |
31 | | - |
32 | | -function chainablePromise<T extends keyof PageCollections, Result>(event: H3Event, collection: T, fn: (qb: CollectionQueryBuilder<PageCollections[T]>) => Promise<Result>) { |
33 | | - const queryBuilder = queryCollection(event, collection) |
34 | | - |
35 | | - const chainable: ChainablePromise<T, Result> = { |
36 | | - where(field, operator, value) { |
37 | | - queryBuilder.where(String(field), operator, value) |
38 | | - return chainable |
39 | | - }, |
40 | | - andWhere(groupFactory) { |
41 | | - queryBuilder.andWhere(groupFactory) |
42 | | - return chainable |
43 | | - }, |
44 | | - orWhere(groupFactory) { |
45 | | - queryBuilder.orWhere(groupFactory) |
46 | | - return chainable |
47 | | - }, |
48 | | - order(field, direction) { |
49 | | - queryBuilder.order(String(field), direction) |
50 | | - return chainable |
51 | | - }, |
52 | | - then(onfulfilled, onrejected) { |
53 | | - return fn(queryBuilder).then(onfulfilled, onrejected) |
54 | | - }, |
55 | | - catch(onrejected) { |
56 | | - return this.then(undefined, onrejected) |
57 | | - }, |
58 | | - finally(onfinally) { |
59 | | - return this.then(undefined, undefined).finally(onfinally) |
60 | | - }, |
61 | | - get [Symbol.toStringTag]() { |
62 | | - return 'Promise' |
63 | | - }, |
64 | | - } |
65 | | - |
66 | | - return chainable |
67 | | -} |
| 1 | +import * as server from './server' |
| 2 | +/** |
| 3 | + * `@nuxt/content/nitro` import is deprecated and will be removed in the next major version. |
| 4 | + * Use `@nuxt/content/server` instead. |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @deprecated Import from `@nuxt/content/server` instead |
| 9 | + */ |
| 10 | +export const queryCollection = server.queryCollection |
| 11 | + |
| 12 | +/** |
| 13 | + * @deprecated Import from `@nuxt/content/server` instead |
| 14 | + */ |
| 15 | +export const queryCollectionNavigation = server.queryCollectionNavigation |
| 16 | + |
| 17 | +/** |
| 18 | + * @deprecated Import from `@nuxt/content/server` instead |
| 19 | + */ |
| 20 | +export const queryCollectionItemSurroundings = server.queryCollectionItemSurroundings |
| 21 | + |
| 22 | +/** |
| 23 | + * @deprecated Import from `@nuxt/content/server` instead |
| 24 | + */ |
| 25 | +export const queryCollectionSearchSections = server.queryCollectionSearchSections |
0 commit comments