From ecdca8d32b6fa8ade92ddb0db72c70b1854f30d4 Mon Sep 17 00:00:00 2001 From: Damien Guard Date: Thu, 11 Jul 2024 13:04:19 +0100 Subject: [PATCH] Fix Typescript gt/lt/gte/lte defs to allow strings --- docs/content/7.v1/1.getting-started/4.fetching.md | 2 ++ src/types/query.ts | 8 ++++---- test/features/query/match.test.ts | 10 +++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/content/7.v1/1.getting-started/4.fetching.md b/docs/content/7.v1/1.getting-started/4.fetching.md index fce8b17a4..f60b0da44 100644 --- a/docs/content/7.v1/1.getting-started/4.fetching.md +++ b/docs/content/7.v1/1.getting-started/4.fetching.md @@ -76,6 +76,8 @@ const articles = await this.$content('articles').where({ title: { $eq: 'Home' } // $gt const articles = await this.$content('articles').where({ age: { $gt: 18 } }).fetch() +// $lte +const articles = await this.$content('articles').where({ createdDateTime: { $lte: new Date().toISOString() } }).fetch() // $in const articles = await this.$content('articles').where({ name: { $in: ['odin', 'thor'] } }).fetch() ``` diff --git a/src/types/query.ts b/src/types/query.ts index 9ddc25a4a..4e4a6620a 100644 --- a/src/types/query.ts +++ b/src/types/query.ts @@ -124,7 +124,7 @@ export interface ContentQueryBuilderWhere extends Partial { }) }) - describe('Numerical operators', () => { + describe('Less-than/Greater-than operators', () => { test('$gt', () => { expect(match(item, { id: { $gt: 0 } })).toBe(true) expect(match(item, { id: { $gt: 1 } })).toBe(false) + expect(match(item, { category: { $gt: 'c' } })).toBe(true) + expect(match(item, { category: { $gt: 'c1' } })).toBe(false) }) test('$gte', () => { expect(match(item, { id: { $gte: 1 } })).toBe(true) expect(match(item, { id: { $gte: 2 } })).toBe(false) + expect(match(item, { category: { $gte: 'c1' } })).toBe(true) + expect(match(item, { category: { $gte: 'c11' } })).toBe(false) }) test('$lt', () => { expect(match(item, { id: { $lt: 2 } })).toBe(true) expect(match(item, { id: { $lt: 1 } })).toBe(false) + expect(match(item, { category: { $lt: 'c11' } })).toBe(true) + expect(match(item, { category: { $lt: 'c1' } })).toBe(false) }) test('$lte', () => { expect(match(item, { id: { $lte: 1 } })).toBe(true) expect(match(item, { id: { $lte: 0 } })).toBe(false) + expect(match(item, { category: { $lte: 'c1' } })).toBe(true) + expect(match(item, { category: { $lte: 'c' } })).toBe(false) }) })