-
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
242 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { expectType } from 'tsd' | ||
import type { InternalTypedDocument, Orama, Results, Schema } from '../../src/types.d.ts' | ||
import { create, insert, search } from '../../src/index.js' | ||
|
||
const movieSchema = { | ||
title: 'string', | ||
year: 'number', | ||
actors: 'string[]', | ||
isFavorite: 'boolean', | ||
stars: 'enum' | ||
} as const | ||
type MovieSchema = Schema<typeof movieSchema> | ||
type MovieDocument = InternalTypedDocument<MovieSchema> | ||
|
||
const movieDBP = create({ | ||
schema: movieSchema, | ||
}) | ||
expectType<Promise<Orama<typeof movieSchema>>>(movieDBP) | ||
const movieDB = await movieDBP | ||
|
||
const idP = insert(movieDB, { | ||
title: 'The Godfather', | ||
year: 1972, | ||
actors: ['Marlon Brando', 'Al Pacino'], | ||
isFavorite: true, | ||
}) | ||
expectType<Promise<string>>(idP) | ||
|
||
const resultP = search(movieDB, { | ||
term: 'godfather', | ||
}) | ||
expectType<Promise<Results<MovieDocument>>>(resultP) | ||
const result = await resultP | ||
expectType<string>(result.hits[0].document.title) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { expectAssignable, expectNotAssignable } from 'tsd' | ||
import type { SearchParams, Orama } from '../../src/types.d.ts' | ||
|
||
const movieSchema = { | ||
title: 'string', | ||
year: 'number', | ||
actors: 'string[]', | ||
isFavorite: 'boolean', | ||
stars: 'enum', | ||
meta: { | ||
foo: 'string' | ||
} | ||
} as const | ||
|
||
// Test search properties type | ||
{ | ||
type MovieSearchParamsProperties = SearchParams<Orama<typeof movieSchema>>['properties'] | ||
|
||
expectAssignable<MovieSearchParamsProperties>('*') | ||
expectAssignable<MovieSearchParamsProperties>(['title']) | ||
expectAssignable<MovieSearchParamsProperties>(['meta.foo']) | ||
expectNotAssignable<MovieSearchParamsProperties>(['meta.unknown']) | ||
expectNotAssignable<MovieSearchParamsProperties>(['unknown']) | ||
|
||
// Test search properties type with unknown schema | ||
{ | ||
type MovieSearchParamsProperties = SearchParams<Orama<any>>['properties'] | ||
expectAssignable<MovieSearchParamsProperties>('*') | ||
expectAssignable<MovieSearchParamsProperties>(['title']) | ||
} | ||
} |
Oops, something went wrong.
545ba4b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
orama-docs – ./
orama-docs.vercel.app
orama-docs-git-main-oramasearch.vercel.app
docs.oramasearch.com
orama-docs-oramasearch.vercel.app