Skip to content

feat(query): add method and type #122

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions packages/provider/src/lib/types/Method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export enum Method {

Push = 'push',

Query = 'query',

Random = 'random',

RandomKey = 'randomKey',
Expand Down
14 changes: 14 additions & 0 deletions packages/provider/src/lib/types/Payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,20 @@ export namespace Payload {
value: Value;
}

/**
* The payload for {@link Method.Query}
* @since 1.0.0
*/
export interface Query<Value> extends Payload, KeyPath {
method: Method.Query;

/**
* The built query.
* @since 1.0.0
*/
query: Query<Value>;
}

/**
* The payload for {@link Method.Random}
* @since 1.0.0
Expand Down
38 changes: 38 additions & 0 deletions packages/provider/src/lib/types/Query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
enum Operators {
Equal = 'equal',
NotEqual = 'notEqual',
GreaterThan = 'greaterThan',
GreaterThanOrEqual = 'greaterThanOrEqual',
LessThan = 'lessThan',
LessThanOrEqual = 'lessThanOrEqual',
In = 'in',
NotIn = 'notIn',
Contains = 'contains',
NotContains = 'notContains',
Regex = 'regex'
}

export interface QueryOperators<Value> {
[Operators.Equal]?: Value; // Not equal
[Operators.NotEqual]?: Value; // Not equal
[Operators.GreaterThan]?: Value; // Greater than
[Operators.GreaterThanOrEqual]?: Value; // Greater than or equal
[Operators.LessThan]?: Value; // Less than
[Operators.LessThanOrEqual]?: Value; // Less than or equal
[Operators.In]?: Value[]; // In
[Operators.NotIn]?: Value[]; // Not in
[Operators.Contains]?: Value; // Contains
[Operators.NotContains]?: Value; // Not contains
[Operators.Regex]?: RegExp; // Regex
}

export type QueryOptions<Value> =
| {
[key in keyof Value]: QueryOptions<Value[keyof Value]> | Value;
}
| QueryOperators<Value>;

export interface Query<StoredValue> {
key?: string | QueryOperators<string>;
value?: StoredValue | QueryOptions<StoredValue>;
}
1 change: 1 addition & 0 deletions packages/provider/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export * from './KeyPath';
export * from './MathOperator';
export * from './Method';
export * from './Payload';
export * from './Query';
export * from './Semver';
export * from './Trigger';