Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typos): collectionQureyBuilder #2953

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/runtime/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Collections, PageCollections, CollectionQueryBuilder, SurroundOptions, SQLOperator, QueryGroupFunction } from '@nuxt/content'
import { collectionQureyBuilder } from './internal/query'
import { collectionQueryBuilder } from './internal/query'
import { measurePerformance } from './internal/performance'
import { generateNavigationTree } from './internal/navigation'
import { generateItemSurround } from './internal/surround'
Expand All @@ -15,7 +15,7 @@ interface ChainablePromise<T extends keyof PageCollections, R> extends Promise<R
}

export const queryCollection = <T extends keyof Collections>(collection: T): CollectionQueryBuilder<Collections[T]> => {
return collectionQureyBuilder<T>(collection, (collection, sql) => executeContentQuery(collection, sql))
return collectionQueryBuilder<T>(collection, (collection, sql) => executeContentQuery(collection, sql))
}

export function queryCollectionNavigation<T extends keyof PageCollections>(collection: T, fields?: Array<keyof PageCollections[T]>) {
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/internal/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const buildGroup = <T extends keyof Collections>(group: CollectionQueryGroup<Col
return conditions.length > 0 ? `(${conditions.join(` ${type} `)})` : ''
}

export const collectionQureyGroup = <T extends keyof Collections>(collection: T): CollectionQueryGroup<Collections[T]> => {
export const collectionQueryGroup = <T extends keyof Collections>(collection: T): CollectionQueryGroup<Collections[T]> => {
const conditions = [] as Array<string>

const query: CollectionQueryGroup<Collections[T]> = {
Expand Down Expand Up @@ -55,12 +55,12 @@ export const collectionQureyGroup = <T extends keyof Collections>(collection: T)
return query
},
andWhere(groupFactory: QueryGroupFunction<Collections[T]>) {
const group = groupFactory(collectionQureyGroup(collection))
const group = groupFactory(collectionQueryGroup(collection))
conditions.push(buildGroup(group, 'AND'))
return query
},
orWhere(groupFactory: QueryGroupFunction<Collections[T]>) {
const group = groupFactory(collectionQureyGroup(collection))
const group = groupFactory(collectionQueryGroup(collection))
conditions.push(buildGroup(group, 'OR'))
return query
},
Expand All @@ -69,7 +69,7 @@ export const collectionQureyGroup = <T extends keyof Collections>(collection: T)
return query
}

export const collectionQureyBuilder = <T extends keyof Collections>(collection: T, fetch: (collection: T, sql: string) => Promise<Collections[T][]>): CollectionQueryBuilder<Collections[T]> => {
export const collectionQueryBuilder = <T extends keyof Collections>(collection: T, fetch: (collection: T, sql: string) => Promise<Collections[T][]>): CollectionQueryBuilder<Collections[T]> => {
const params = {
conditions: [] as Array<string>,
selectedFields: [] as Array<keyof Collections[T]>,
Expand All @@ -85,12 +85,12 @@ export const collectionQureyBuilder = <T extends keyof Collections>(collection:

const query: CollectionQueryBuilder<Collections[T]> = {
andWhere(groupFactory: QueryGroupFunction<Collections[T]>) {
const group = groupFactory(collectionQureyGroup(collection))
const group = groupFactory(collectionQueryGroup(collection))
params.conditions.push(buildGroup(group, 'AND'))
return query
},
orWhere(groupFactory: QueryGroupFunction<Collections[T]>) {
const group = groupFactory(collectionQureyGroup(collection))
const group = groupFactory(collectionQueryGroup(collection))
params.conditions.push(buildGroup(group, 'OR'))
return query
},
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/nitro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Collections, CollectionQueryBuilder, PageCollections, SurroundOptions, SQLOperator, QueryGroupFunction } from '@nuxt/content'
import type { H3Event } from 'h3'
import { collectionQureyBuilder } from './internal/query'
import { collectionQueryBuilder } from './internal/query'
import { generateNavigationTree } from './internal/navigation'
import { generateItemSurround } from './internal/surround'
import { generateSearchSections } from './internal/search'
Expand All @@ -14,7 +14,7 @@ interface ChainablePromise<T extends keyof PageCollections, R> extends Promise<R
}

export const queryCollectionWithEvent = <T extends keyof Collections>(event: H3Event, collection: T): CollectionQueryBuilder<Collections[T]> => {
return collectionQureyBuilder<T>(collection, (collection, sql) => fetchQuery(event, collection, sql))
return collectionQueryBuilder<T>(collection, (collection, sql) => fetchQuery(event, collection, sql))
}

export async function queryCollectionNavigationWithEvent<T extends keyof PageCollections>(event: H3Event, collection: T, fields?: Array<keyof PageCollections[T]>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { collectionQureyBuilder } from '../../src/runtime/internal/query'
import { collectionQueryBuilder } from '../../src/runtime/internal/query'

// Mock tables from manifest
vi.mock('#content/manifest', () => ({
Expand All @@ -12,20 +12,20 @@ vi.mock('#content/manifest', () => ({
const mockFetch = vi.fn().mockResolvedValue(Promise.resolve([{}]))
const mockCollection = 'articles' as never

describe('collectionQureyBuilder', () => {
describe('collectionQueryBuilder', () => {
beforeEach(() => {
mockFetch.mockClear()
})

it('builds a simple select query', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query.all()

expect(mockFetch).toHaveBeenCalledWith('articles', 'SELECT * FROM _articles ORDER BY stem ASC')
})

it('builds query with where clause', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query.where('title', '=', 'Test Article').all()

expect(mockFetch).toHaveBeenCalledWith(
Expand All @@ -35,7 +35,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with multiple where clauses', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query
.where('title', '=', 'Test Article')
.where('published', '=', true)
Expand All @@ -48,7 +48,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with IN operator', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query
.where('category', 'IN', ['news', 'tech'])
.all()
Expand All @@ -60,7 +60,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with BETWEEN operator', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query
.where('date', 'BETWEEN', ['2023-01-01', '2023-12-31'])
.all()
Expand All @@ -72,7 +72,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with selected fields', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query
.select('title', 'date', 'author')
.all()
Expand All @@ -84,7 +84,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with order by', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query
.order('date', 'DESC')
.all()
Expand All @@ -96,7 +96,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with limit without skip', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query
.limit(5)
.all()
Expand All @@ -108,7 +108,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with limit and offset', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query
.limit(10)
.skip(20)
Expand All @@ -121,7 +121,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with first()', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query.first()

expect(mockFetch).toHaveBeenCalledWith(
Expand All @@ -131,7 +131,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds count query', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query.count()

expect(mockFetch).toHaveBeenCalledWith(
Expand All @@ -141,7 +141,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds distinct count query', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query.count('author', true)

expect(mockFetch).toHaveBeenCalledWith(
Expand All @@ -151,7 +151,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with complex where conditions using andWhere', async () => {
const query = collectionQureyBuilder(mockCollection, mockFetch)
const query = collectionQueryBuilder(mockCollection, mockFetch)
await query
.where('published', '=', true)
.andWhere(group => group
Expand All @@ -170,7 +170,7 @@ describe('collectionQureyBuilder', () => {
})

it('builds query with path', async () => {
const query = collectionQureyBuilder('articles' as never, mockFetch)
const query = collectionQueryBuilder('articles' as never, mockFetch)
await query
.path('/blog/my-article')
.all()
Expand Down
Loading