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

docs(Typebox): Schema for allowed query properties #3518

Open
wants to merge 1 commit into
base: dove
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions docs/api/schema/typebox.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const messageQuerySchema = querySyntax(messageQueryProperties)
type MessageQuery = Static<typeof messageQuerySchema>
```

Additional special query properties [that are not already included in the query syntax](../databases/querying.md) like `$ilike` can be added like this:
Additional special query properties [that are not already included in the query syntax](../databases/querying.md) like `$regex` can be added like this:

```ts
import { querySyntax } from '@feathersjs/typebox'
Expand All @@ -108,10 +108,10 @@ const messageQueryProperties = Type.Pick(messageSchema, ['id', 'text', 'createdA
})
const messageQuerySchema = Type.Intersect(
[
// This will additionally allow querying for `{ name: { $ilike: 'Dav%' } }`
// This will additionally allow querying for `{ name: { $regex: 'Dav', $options: 'i' } }`
querySyntax(messageQueryProperties, {
name: {
$ilike: Type.String()
$regex: Type.String(), $options: Type.String()
}
}),
// Add additional query properties here
Expand All @@ -121,6 +121,18 @@ const messageQuerySchema = Type.Intersect(
)
```

Finally, in the class module, add the operators:

```ts
export const getOptions = (app: Application): MongoDBAdapterOptions => {
return {
paginate: app.get('paginate'),
Model: app.get('mongodbClient').then((db) => db.collection('example')),
operators: ['$regex', '$options'] // add the operators
}
}
```

To allow additional query properties outside of the query syntax use the intersection type:

```ts
Expand Down