From b2ef136685c4c27d2a54228395e9008d5f63c07c Mon Sep 17 00:00:00 2001 From: DanCodes Date: Sat, 29 Oct 2022 14:16:51 +0100 Subject: [PATCH 1/6] feat(query): add method and type --- packages/provider/src/lib/types/Method.ts | 2 ++ packages/provider/src/lib/types/Payload.ts | 14 ++++++++++++++ packages/provider/src/lib/types/Query.ts | 15 +++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 packages/provider/src/lib/types/Query.ts diff --git a/packages/provider/src/lib/types/Method.ts b/packages/provider/src/lib/types/Method.ts index a5db416e..3f02e362 100644 --- a/packages/provider/src/lib/types/Method.ts +++ b/packages/provider/src/lib/types/Method.ts @@ -43,6 +43,8 @@ export enum Method { Push = 'push', + Query = 'query', + Random = 'random', RandomKey = 'randomKey', diff --git a/packages/provider/src/lib/types/Payload.ts b/packages/provider/src/lib/types/Payload.ts index 5e76bcc1..19b9b94d 100644 --- a/packages/provider/src/lib/types/Payload.ts +++ b/packages/provider/src/lib/types/Payload.ts @@ -482,6 +482,20 @@ export namespace Payload { value: Value; } + /** + * The payload for {@link Method.Query} + * @since 1.0.0 + */ + export interface Query extends Payload, KeyPath { + method: Method.Query; + + /** + * The built query. + * @since 1.0.0 + */ + query: Query; + } + /** * The payload for {@link Method.Random} * @since 1.0.0 diff --git a/packages/provider/src/lib/types/Query.ts b/packages/provider/src/lib/types/Query.ts new file mode 100644 index 00000000..95960579 --- /dev/null +++ b/packages/provider/src/lib/types/Query.ts @@ -0,0 +1,15 @@ +export interface QueryOptions { + ne: Value; + gt: Value; + gte: Value; + lt: Value; + lte: Value; + in: Value[]; + nin: Value[]; + regex: RegExp; +} + +export interface Query { + key: string | QueryOptions; + value: StoredValue | QueryOptions; +} From c4c80c104c3e59c87d2cf52e2bb1a49fcbbd9d77 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Sat, 29 Oct 2022 14:27:40 +0100 Subject: [PATCH 2/6] fix(query): change interface --- packages/provider/src/lib/types/Query.ts | 26 +++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/provider/src/lib/types/Query.ts b/packages/provider/src/lib/types/Query.ts index 95960579..cdc135c0 100644 --- a/packages/provider/src/lib/types/Query.ts +++ b/packages/provider/src/lib/types/Query.ts @@ -1,15 +1,21 @@ export interface QueryOptions { - ne: Value; - gt: Value; - gte: Value; - lt: Value; - lte: Value; - in: Value[]; - nin: Value[]; - regex: RegExp; + ne?: Value; + gt?: Value; + gte?: Value; + lt?: Value; + lte?: Value; + in?: Value[]; + nin?: Value[]; + regex?: RegExp; } +export interface QueryOptionsValue extends QueryOptions { + path?: []; +} + +// TODO: Need Nova's ts expertise to match type of Value with the path specified + export interface Query { - key: string | QueryOptions; - value: StoredValue | QueryOptions; + key?: string | QueryOptions; + value?: StoredValue | QueryOptionsValue; } From d754e6f969125b922a1b47d2e836e293c0ce729d Mon Sep 17 00:00:00 2001 From: DanCodes Date: Sat, 29 Oct 2022 14:52:46 +0100 Subject: [PATCH 3/6] fix(query): change types to be recursive --- packages/provider/src/lib/types/Query.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/provider/src/lib/types/Query.ts b/packages/provider/src/lib/types/Query.ts index cdc135c0..aa26e3ae 100644 --- a/packages/provider/src/lib/types/Query.ts +++ b/packages/provider/src/lib/types/Query.ts @@ -1,4 +1,4 @@ -export interface QueryOptions { +export interface QueryOperators { ne?: Value; gt?: Value; gte?: Value; @@ -9,13 +9,13 @@ export interface QueryOptions { regex?: RegExp; } -export interface QueryOptionsValue extends QueryOptions { - path?: []; -} - -// TODO: Need Nova's ts expertise to match type of Value with the path specified +export type QueryOptions = + | { + [key in keyof Value]: QueryOptions | Value; + } + | QueryOperators; export interface Query { - key?: string | QueryOptions; - value?: StoredValue | QueryOptionsValue; + key?: string | QueryOperators; + value?: StoredValue | QueryOptions; } From 111fe014b0471e45d99711bcb706859cf4cb1273 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Sat, 29 Oct 2022 14:56:45 +0100 Subject: [PATCH 4/6] chore(query): document query operators --- packages/provider/src/lib/types/Query.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/provider/src/lib/types/Query.ts b/packages/provider/src/lib/types/Query.ts index aa26e3ae..f638c9f3 100644 --- a/packages/provider/src/lib/types/Query.ts +++ b/packages/provider/src/lib/types/Query.ts @@ -1,12 +1,12 @@ export interface QueryOperators { - ne?: Value; - gt?: Value; - gte?: Value; - lt?: Value; - lte?: Value; - in?: Value[]; - nin?: Value[]; - regex?: RegExp; + ne?: Value; // Not equal + gt?: Value; // Greater than + gte?: Value; // Greater than or equal to + lt?: Value; // Less than + lte?: Value; // Less than or equal to + in?: Value[]; // In array + nin?: Value[]; // Not in array + regex?: RegExp; // Regular expression } export type QueryOptions = From 66bccf7b06f452e5950abc34accc76bfd4b74574 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Sat, 29 Oct 2022 15:23:23 +0100 Subject: [PATCH 5/6] chore(query): refactor operators to enum --- packages/provider/src/lib/types/Query.ts | 33 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/provider/src/lib/types/Query.ts b/packages/provider/src/lib/types/Query.ts index f638c9f3..f48febed 100644 --- a/packages/provider/src/lib/types/Query.ts +++ b/packages/provider/src/lib/types/Query.ts @@ -1,12 +1,29 @@ +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 { - ne?: Value; // Not equal - gt?: Value; // Greater than - gte?: Value; // Greater than or equal to - lt?: Value; // Less than - lte?: Value; // Less than or equal to - in?: Value[]; // In array - nin?: Value[]; // Not in array - regex?: RegExp; // Regular expression + [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 = From 37cc374f906af3afcb69c1b8c953c3b115166013 Mon Sep 17 00:00:00 2001 From: DanCodes Date: Sun, 30 Oct 2022 18:27:12 +0000 Subject: [PATCH 6/6] chore(query): export types --- packages/provider/src/lib/types/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/provider/src/lib/types/index.ts b/packages/provider/src/lib/types/index.ts index 6116a66e..dae6e909 100644 --- a/packages/provider/src/lib/types/index.ts +++ b/packages/provider/src/lib/types/index.ts @@ -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';