-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datasource-customizer): implement gmail-style search (#780)
- Loading branch information
1 parent
5aaa5f7
commit 3ad8ed8
Showing
70 changed files
with
7,523 additions
and
478 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
version: '2' # required to adjust maintainability checks | ||
version: "2" # required to adjust maintainability checks | ||
|
||
checks: | ||
method-complexity: | ||
enabled: true | ||
config: | ||
threshold: 10 | ||
exclude_patterns: | ||
- 'packages/_example/' | ||
- '**/test/' | ||
- "packages/_example/" | ||
- "**/test/" | ||
- "packages/datasource-customizer/src/decorators/search/generated-parser/*.ts" |
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,3 @@ | ||
module.exports = { | ||
ignorePatterns: ['src/decorators/search/generated-parser/**/*'], | ||
}; |
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
45 changes: 45 additions & 0 deletions
45
packages/datasource-customizer/src/decorators/search/Query.g4
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,45 @@ | ||
// | ||
// This file contains the description of the supported syntax for search queries. | ||
// It is used by the ANTLR parser generator to generate the parser. | ||
// To support additional syntax, this file must be updated and the parser regenerated. | ||
// It requires antlr4-tools to be installed on your machine | ||
// | ||
grammar Query; | ||
|
||
query: (and | or | queryToken | parenthesized) EOF; | ||
|
||
parenthesized: PARENS_OPEN (or | and) PARENS_CLOSE; | ||
PARENS_OPEN: '(' ' '*; | ||
PARENS_CLOSE: ' '* ')'; | ||
|
||
// OR is a bit different because of operator precedence | ||
or: (and | queryToken | parenthesized) (SEPARATOR OR SEPARATOR (and | queryToken | parenthesized))+; | ||
OR: 'OR'; | ||
|
||
and: (queryToken | parenthesized) (SEPARATOR (AND SEPARATOR)? (queryToken | parenthesized))+; | ||
AND: 'AND'; | ||
|
||
queryToken: (quoted | negated | propertyMatching | word); | ||
|
||
|
||
quoted: SINGLE_QUOTED | DOUBLE_QUOTED; | ||
SINGLE_QUOTED: '\'' SINGLE_QUOTED_CONTENT '\'' | '\'' '\''; | ||
fragment SINGLE_QUOTED_CONTENT:~[']*; | ||
DOUBLE_QUOTED: '"' DOUBLE_QUOTED_CONTENT '"' | '"' '"'; | ||
fragment DOUBLE_QUOTED_CONTENT: ~["]*; | ||
negated: NEGATION (word | quoted | propertyMatching); | ||
NEGATION: '-'; | ||
propertyMatching: name ':' value; | ||
name: TOKEN; | ||
value: word | quoted; | ||
word: TOKEN; | ||
TOKEN: ONE_CHAR_TOKEN | TWO_CHARS_TOKEN | MULTIPLE_CHARS_TOKEN; | ||
fragment ONE_CHAR_TOKEN: ~[\r\n :\-()]; | ||
fragment TWO_CHARS_TOKEN: ~[\r\n :\-(]~[\r\n :)]; | ||
fragment MULTIPLE_CHARS_TOKEN:~[\r\n :\-(]~[\r\n :]+~[\r\n :)]; | ||
SEPARATOR: SPACING+ | EOF; | ||
SPACING: [\r\n ]; |
42 changes: 42 additions & 0 deletions
42
packages/datasource-customizer/src/decorators/search/collection-search-context.ts
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,42 @@ | ||
import { Caller, Collection, ConditionTree } from '@forestadmin/datasource-toolkit'; | ||
|
||
import CollectionCustomizationContext from '../../context/collection-context'; | ||
import { TCollectionName, TColumnName, TSchema } from '../../templates'; | ||
|
||
export type SearchOptions< | ||
S extends TSchema = TSchema, | ||
N extends TCollectionName<S> = TCollectionName<S>, | ||
> = { | ||
/** | ||
* Include fields from the first level of relations | ||
*/ | ||
extended?: boolean; | ||
/** | ||
* Remove these fields from the default search fields | ||
*/ | ||
excludeFields?: Array<TColumnName<S, N>>; | ||
/** | ||
* Add these fields to the default search fields | ||
*/ | ||
includeFields?: Array<TColumnName<S, N>>; | ||
/** | ||
* Replace the list of default searched field by these fields | ||
*/ | ||
onlyFields?: Array<TColumnName<S, N>>; | ||
}; | ||
|
||
export default class CollectionSearchContext< | ||
S extends TSchema = TSchema, | ||
N extends TCollectionName<S> = TCollectionName<S>, | ||
> extends CollectionCustomizationContext<S, N> { | ||
constructor( | ||
collection: Collection, | ||
caller: Caller, | ||
public readonly generateSearchFilter: ( | ||
searchText: string, | ||
options?: SearchOptions<S, N>, | ||
) => ConditionTree, | ||
) { | ||
super(collection, caller); | ||
} | ||
} |
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
Oops, something went wrong.